InitController.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. <?php
  2. namespace console\controllers;
  3. use biz\admin\classes\AdminClass;
  4. use biz\admin\classes\AdminRoleClass;
  5. use biz\product\classes\XjClass;
  6. use biz\pt\classes\PtYeChangeClass;
  7. use biz\recharge\classes\RechargeClass;
  8. use biz\shop\classes\MainClass;
  9. use biz\shop\classes\ShopAdminClass;
  10. use biz\shop\classes\ShopClass;
  11. use biz\shop\classes\ShopYeChangeClass;
  12. use biz\sj\classes\CashClass;
  13. use biz\sj\classes\SjClass;
  14. use biz\stat\classes\StatCgClass;
  15. use biz\stat\classes\StatCgGhsClass;
  16. use biz\stat\classes\StatCgGhsMonthClass;
  17. use biz\stat\classes\StatCgMonthClass;
  18. use biz\stat\classes\StatOrderCountClass;
  19. use biz\stat\classes\StatOutClass;
  20. use biz\stat\classes\StatOutMonthClass;
  21. use biz\stat\classes\StatPdAddClass;
  22. use biz\stat\classes\StatPdAddMonthClass;
  23. use biz\stat\classes\StatPdSubClass;
  24. use biz\stat\classes\StatPdSubMonthClass;
  25. use biz\stat\classes\StatRefundClass;
  26. use biz\stat\classes\StatRefundMonthClass;
  27. use biz\stat\classes\StatSaleClass;
  28. use biz\stat\classes\StatSaleMonthClass;
  29. use biz\stat\classes\StatStockInClass;
  30. use biz\stat\classes\StatStockInMonthClass;
  31. use biz\stat\classes\StatStockOutClass;
  32. use biz\stat\classes\StatStockOutMonthClass;
  33. use biz\stat\classes\StatWastClass;
  34. use biz\stat\classes\StatWastMonthClass;
  35. use bizGhs\cg\classes\CgClass;
  36. use bizGhs\clear\classes\ClearClass;
  37. use bizGhs\clear\models\Clear;
  38. use bizGhs\custom\classes\CustomClass;
  39. use bizGhs\item\classes\ItemClass;
  40. use bizGhs\item\classes\ItemClassClass;
  41. use bizGhs\order\classes\CheckOrderClass;
  42. use bizGhs\order\classes\OrderClass;
  43. use bizGhs\order\classes\OrderItemClass;
  44. use bizGhs\order\classes\RefundOrderClass;
  45. use bizGhs\order\classes\RefundOrderItemClass;
  46. use bizGhs\order\classes\StockWastageOrderClass;
  47. use bizGhs\order\classes\StockWastageOrderItemClass;
  48. use bizGhs\stat\classes\StatYjClass;
  49. use bizGhs\stat\classes\StatYjMonthClass;
  50. use bizHd\cg\classes\CgRefundClass;
  51. use bizHd\cg\classes\CgRefundItemClass;
  52. use bizHd\ghs\classes\GhsClass;
  53. use bizHd\goods\classes\CategoryClass;
  54. use bizHd\goods\classes\GoodsCategoryClass;
  55. use bizHd\goods\classes\GoodsClass;
  56. use bizHd\goods\classes\GoodsSettingClass;
  57. use bizHd\order\classes\OrderGoodsClass;
  58. use bizHd\order\models\Order;
  59. use bizHd\purchase\classes\PurchaseClass;
  60. use bizHd\purchase\classes\PurchaseItemClass;
  61. use bizHd\saas\classes\FestRiseClass;
  62. use bizHd\stat\classes\StatOrderClass;
  63. use bizHd\stat\classes\StatOrderMonthClass;
  64. use bizHd\stat\classes\StatUserClass;
  65. use bizHd\stat\classes\StatUserMonthClass;
  66. use bizHd\stat\classes\StatVisitClass;
  67. use bizHd\stat\classes\StatVisitMonthClass;
  68. use bizHd\user\classes\UserClass;
  69. use common\components\dict;
  70. use common\components\stringUtil;
  71. use Yii;
  72. use yii\console\Controller;
  73. class InitController extends Controller
  74. {
  75. //花店订单脚本
  76. public function actionHdOrder()
  77. {
  78. $query = new \yii\db\Query();
  79. $query->from(Order::tableName());
  80. $query->where(['mainId' => 742]);
  81. foreach ($query->batch() as $batchOrder) {
  82. foreach ($batchOrder as $order) {
  83. $addTime = $order['addTime'] ?? '';
  84. $goodsPrice = $order['goodsPrice'] ?? 0;
  85. $goodsPrice = floatval($goodsPrice);
  86. $sendCost = $order['sendCost'] ?? 0;
  87. $sendCost = floatval($sendCost);
  88. $labourCost = $order['labourCost'] ?? 0;
  89. $labourCost = floatval($labourCost);
  90. $discountAmount = $order['discountAmount'] ?? 0;
  91. $discountAmount = floatval($discountAmount);
  92. $orderPrice = $order['orderPrice'] ?? 0;
  93. $orderPrice = floatval($orderPrice);
  94. $total = bcadd($goodsPrice, $sendCost, 2);
  95. $total = bcadd($total, $labourCost, 2);
  96. $final = bcsub($total, $discountAmount, 2);
  97. $final = floatval($final);
  98. $actPrice = $order['actPrice'] ?? 0;
  99. $orderSn = $order['orderSn'] ?? '';
  100. if ($final != $orderPrice) {
  101. echo "订单号:{$orderSn} {$addTime} \n";
  102. echo "===\n";
  103. $itemList = \bizHd\order\classes\OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  104. if (!empty($itemList)) {
  105. foreach ($itemList as $item) {
  106. echo $item['name'] . " " . $item['num'] . "X" . $item['unitPrice'] . " " . $item['price'] . "\n";
  107. }
  108. }
  109. $goodsList = OrderGoodsClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  110. if (!empty($goodsList)) {
  111. foreach ($goodsList as $goods) {
  112. echo $goods['name'] . " " . $goods['num'] . "X" . $goods['unitPrice'] . " " . $goods['price'] . "\n";
  113. }
  114. }
  115. echo "===\n";
  116. echo "商品总和:{$goodsPrice} \n 运费:{$sendCost} \n人工包装费:{$labourCost} \n合计:{$total} \n优惠:{$discountAmount}\n 订单金额:{$orderPrice} \n 实付金额:{$actPrice}\n\n\n\n\n";
  117. }
  118. }
  119. }
  120. }
  121. //花材菜单 ./yii init/menu
  122. public function actionMenu()
  123. {
  124. $sql = "ALTER TABLE xhGhsItemClass ADD shopId INT NOT NULL DEFAULT 0 COMMENT '门店id' AFTER sjId;";
  125. Yii::$app->db->createCommand($sql)->execute();
  126. $sql = "ALTER TABLE xhAdminRole ADD shopId INT NOT NULL DEFAULT 0 COMMENT '门店id' AFTER `sjId`;";
  127. Yii::$app->db->createCommand($sql)->execute();
  128. $list = SjClass::getAllByCondition(['id>' => 0], null, '*', null, true);
  129. if (!empty($list)) {
  130. foreach ($list as $sj) {
  131. $sjId = $sj->id ?? 0;
  132. if (empty($sjId)) {
  133. continue;
  134. }
  135. $shopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  136. if (empty($shopList)) {
  137. continue;
  138. }
  139. //补花材
  140. $classList = ItemClassClass::getAllByCondition(['sjId' => $sjId], null, '*');
  141. if (!empty($classList)) {
  142. foreach ($shopList as $shop) {
  143. $shopId = $shop->id ?? 0;
  144. foreach ($classList as $class) {
  145. $classId = $class['id'] ?? 0;
  146. $name = $class['name'] ?? '';
  147. $inTurn = $class['inTurn'] ?? '';
  148. $isDefault = $class['isDefault'] ?? 0;
  149. $data = [
  150. 'shopId' => $shopId,
  151. 'sjId' => $sjId,
  152. 'name' => $name,
  153. 'inTurn' => $inTurn,
  154. 'isDefault' => $isDefault,
  155. ];
  156. $r = ItemClassClass::add($data, true);
  157. $newId = $r->id ?? 0;
  158. ItemClass::updateByCondition(['shopId' => $shopId, 'classId' => $classId], ['classId' => $newId]);
  159. }
  160. }
  161. }
  162. //补角色
  163. $roleList = AdminRoleClass::getAllByCondition(['sjId' => $sjId], null, '*');
  164. if (!empty($roleList)) {
  165. foreach ($shopList as $shop) {
  166. $shopId = $shop->id ?? 0;
  167. foreach ($roleList as $role) {
  168. $roleName = $role['roleName'] ?? '';
  169. $roleId = $role['id'] ?? 0;
  170. $roleData = [
  171. 'shopId' => $shopId,
  172. 'sjId' => $sjId,
  173. 'roleName' => $roleName,
  174. ];
  175. $new = AdminRoleClass::add($roleData, true);
  176. $newId = $new->id ?? 0;
  177. ShopAdminClass::updateByCondition(['shopId' => $shopId, 'roleId' => $roleId], ['roleId' => $newId]);
  178. }
  179. }
  180. }
  181. }
  182. }
  183. }
  184. //初始化 ./yii init/main
  185. public function actionMain()
  186. {
  187. ini_set('memory_limit', '2045M');
  188. set_time_limit(0);
  189. //基地批发商
  190. $jdShopList = ShopClass::getAllByCondition(['ptStyle' => dict::getDict('ptStyle', 'kmGhs')], 'default DESC', '*', null, true);
  191. if (!empty($jdShopList)) {
  192. foreach ($jdShopList as $jdShop) {
  193. $main = MainClass::add(['id' => null], true);
  194. $mainId = $main->id ?? 0;
  195. if (empty($mainId)) {
  196. echo "mainId没有生成 \n";
  197. exit();
  198. }
  199. $jdShop->mainId = $mainId;
  200. $jdShop->save();
  201. }
  202. }
  203. //批发商
  204. $pfShopList = ShopClass::getAllByCondition(['ptStyle' => dict::getDict('ptStyle', 'ghs')], 'default DESC', '*', null, true);
  205. if (!empty($pfShopList)) {
  206. foreach ($pfShopList as $pfShop) {
  207. $pfShopId = $pfShop->id ?? 0;
  208. $main = MainClass::add(['id' => null], true);
  209. $mainId = $main->id ?? 0;
  210. if (empty($mainId)) {
  211. echo "mainId没有生成 \n";
  212. exit();
  213. }
  214. $pfShop->mainId = $mainId;
  215. $pfShop->save();
  216. //将shop资产信息迁移到main
  217. self::migration($main, $pfShop);
  218. //员工数据迁移到currentGhsShopId,删除零售和基地供应商的管理员信息
  219. $staffList = ShopAdminClass::getAllByCondition(['shopId' => $pfShopId], null, '*');
  220. if (!empty($staffList)) {
  221. foreach ($staffList as $staff) {
  222. $pfAdminId = $staff['adminId'] ?? 0;
  223. $pfAdmin = AdminClass::getById($pfAdminId, true);
  224. if (!empty($pfAdmin)) {
  225. if (empty($pfAdmin->currentGhsShopId)) {
  226. $pfAdmin->currentGhsShopId = $pfShopId;
  227. $pfAdmin->ghsMiniOpenId = $pfAdmin->miniOpenId ?? '';
  228. $pfAdmin->miniOpenId = '';
  229. $pfAdmin->currentShopId = 0;
  230. $pfAdmin->save();
  231. }
  232. } else {
  233. echo "没有找到shopId:{$pfShopId}批发店的员工\n";
  234. }
  235. $staffMobile = $staff['mobile'] ?? '';
  236. //删除和批发店用一样手机号的 零售和基地供应商 员工
  237. if (!empty($staffMobile)) {
  238. $h = AdminClass::getAllByCondition(['mobile' => $staffMobile, 'style' => dict::getDict('ptStyle', 'hd')], null, '*', null, true);
  239. if (!empty($h)) {
  240. foreach ($h as $he) {
  241. $currentAdminId = $he->id ?? 0;
  242. ShopAdminClass::deleteByCondition(['adminId' => $currentAdminId]);
  243. $he->delete();
  244. }
  245. }
  246. $j = AdminClass::getAllByCondition(['mobile' => $staffMobile, 'style' => dict::getDict('ptStyle', 'kmGhs')], null, '*', null, true);
  247. if (!empty($j)) {
  248. foreach ($j as $je) {
  249. $currentAdminId = $je->id ?? 0;
  250. ShopAdminClass::deleteByCondition(['adminId' => $currentAdminId]);
  251. $je->delete();
  252. }
  253. }
  254. }
  255. }
  256. }
  257. //花材和分类,零售和批发都有,单独拎出来
  258. ItemClass::updateByCondition(['shopId' => $pfShopId], ['mainId' => $mainId]);
  259. ItemClassClass::updateByCondition(['shopId' => $pfShopId], ['mainId' => $mainId]);
  260. self::setCommon($pfShopId, $mainId);
  261. self::setGhs($pfShopId, $mainId);
  262. }
  263. }
  264. //零售
  265. $lsShopList = ShopClass::getAllByCondition(['ptStyle' => dict::getDict('ptStyle', 'hd')], 'default DESC', '*', null, true);
  266. if (!empty($lsShopList)) {
  267. foreach ($lsShopList as $lsShop) {
  268. $main = MainClass::add(['id' => null], true);
  269. $mainId = $main->id ?? 0;
  270. if (empty($mainId)) {
  271. echo "mainId没有生成 \n";
  272. exit();
  273. }
  274. $lsShop->mainId = $mainId;
  275. $lsShop->save();
  276. $lsShopId = $lsShop->id ?? 0;
  277. $lsSjId = $lsShop->sjId ?? 0;
  278. //将shop资产信息迁移到main
  279. self::migration($main, $lsShop);
  280. $staffList = ShopAdminClass::getAllByCondition(['shopId' => $lsShopId], null, '*');
  281. if (!empty($staffList)) {
  282. foreach ($staffList as $staff) {
  283. $adminId = $staff['adminId'] ?? 0;
  284. $admin = AdminClass::getById($adminId, true);
  285. if (!empty($admin)) {
  286. if (empty($admin->currentShopId)) {
  287. $admin->currentShopId = $lsShopId;
  288. $admin->save();
  289. }
  290. }
  291. }
  292. }
  293. //花材和分类,零售和批发都有,单独拎出来
  294. ItemClass::updateByCondition(['shopId' => $lsShopId], ['mainId' => $mainId]);
  295. ItemClassClass::updateByCondition(['shopId' => $lsShopId], ['mainId' => $mainId]);
  296. self::setCommon($lsShopId, $mainId);
  297. self::setHd($lsSjId, $lsShopId, $mainId);
  298. }
  299. }
  300. //清除零售商城相关的数据
  301. $sql = "TRUNCATE xhUser;TRUNCATE xhCustom;truncate xhUserAsset;";
  302. Yii::$app->db->createCommand($sql)->execute();
  303. $sql = "UPDATE xhOrder SET customId=0,customName='',alipayId=0;";
  304. Yii::$app->db->createCommand($sql)->execute();
  305. //补已经存在花店的默认客户
  306. $lsShopList = ShopClass::getAllByCondition(['ptStyle' => dict::getDict('ptStyle', 'hd')], null, '*', null, true);
  307. if (!empty($lsShopList)) {
  308. foreach ($lsShopList as $lsShop) {
  309. $mobile = $lsShop->mobile ?? 0;
  310. if (empty($mobile) || stringUtil::isMobile($mobile) == false) {
  311. continue;
  312. }
  313. $user = UserClass::replaceUser(['mobile' => $mobile]);
  314. $custom = \bizHd\custom\classes\CustomClass::replaceCustom($lsShop, $user);
  315. $customId = $custom->id ?? 0;
  316. $lsShop->defaultCustomId = $customId;
  317. $lsShop->save();
  318. }
  319. }
  320. //欠款字段迁移
  321. $sql = 'UPDATE xhGhsOrder SET debtPrice=actPrice,remainDebtPrice=actPrice WHERE debt=1';
  322. Yii::$app->db->createCommand($sql)->execute();
  323. $sql = 'UPDATE xhCg SET debtPrice=actPrice,remainDebtPrice=actPrice WHERE debt=1;';
  324. Yii::$app->db->createCommand($sql)->execute();
  325. $map = [];
  326. $allShop = ShopClass::getAllByCondition(['id>' => 0], null, '*', null, true);
  327. if (!empty($allShop)) {
  328. foreach ($allShop as $single) {
  329. $mainId = $single->mainId ?? 0;
  330. $shopId = $single->id ?? 0;
  331. $map[$shopId] = $mainId;
  332. }
  333. }
  334. //供应商的销售单 和 零售的退款单,老字段数据要迁到新字段数据上
  335. $ghsSaleRefund = [];
  336. $hdCgRefund = [];
  337. $refundList = RefundOrderClass::getAllByCondition(['id>' => 0], null, '*', null, true);
  338. if (!empty($refundList)) {
  339. foreach ($refundList as $key => $refund) {
  340. $orderSn = $refund->orderSn ?? '';
  341. $relateOrderSn = $refund->relateOrderSn ?? '';
  342. $shopId = $refund->shopId ?? 0;
  343. $mainId = $map[$shopId] ?? 0;
  344. $refund->mainId = $mainId;
  345. $refund->save();
  346. if (empty($orderSn)) {
  347. continue;
  348. }
  349. $refundItemList = RefundOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  350. if (!empty($refundItemList)) {
  351. foreach ($refundItemList as $refundItem) {
  352. $refundItem->xhNum = floatval($refundItem->itemNum);
  353. $refundItem->xhUnitName = '扎';
  354. $refundItem->xhUnitType = 0;
  355. $refundItem->xhUnitPrice = $refundItem->itemPrice;
  356. $refundItem->xhPrice = bcmul($refundItem->itemPrice, $refundItem->itemNum, 2);
  357. $refundItem->mainId = $mainId;
  358. $refundItem->save();
  359. $productId = $refundItem->productId ?? 0;
  360. $ghsSaleRefund[$relateOrderSn][$productId] = floatval($refundItem->itemNum);
  361. }
  362. }
  363. }
  364. }
  365. $cgRefundList = CgRefundClass::getAllByCondition(['id>' => 0], null, '*', null, true);
  366. if (!empty($cgRefundList)) {
  367. foreach ($cgRefundList as $cgRefund) {
  368. $orderSn = $cgRefund->orderSn ?? '';
  369. $cgId = $cgRefund->cgId ?? 0;
  370. $shopId = $cgRefund->shopId ?? 0;
  371. $mainId = $map[$shopId] ?? 0;
  372. $cgRefund->mainId = $mainId;
  373. $cgRefund->save();
  374. if (empty($orderSn)) {
  375. continue;
  376. }
  377. $cgRefundItemList = CgRefundItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  378. if (!empty($cgRefundItemList)) {
  379. foreach ($cgRefundItemList as $cgItem) {
  380. $cgItem->xhNum = floatval($cgItem->itemNum);
  381. $cgItem->xhUnitName = '扎';
  382. $cgItem->xhUnitType = 0;
  383. $cgItem->xhUnitPrice = $cgItem->itemPrice;
  384. $cgItem->xhPrice = bcmul($cgItem->itemPrice, $cgItem->itemNum, 2);
  385. $cgItem->mainId = $mainId;
  386. $cgItem->save();
  387. $productId = $cgItem->productId ?? 0;
  388. $hdCgRefund[$cgId][$productId] = floatval($cgItem->itemNum);
  389. }
  390. }
  391. }
  392. }
  393. //供应商的销售单 和 零售的采购单,老字段数据要迁到新字段数据上
  394. $orderList = OrderClass::getAllByCondition(['id>' => 0], null, '*', null, true);
  395. if (!empty($orderList)) {
  396. foreach ($orderList as $order) {
  397. $orderSn = $order->orderSn ?? '';
  398. if (empty($orderSn)) {
  399. continue;
  400. }
  401. $order->orderPrice = bcadd($order->prePrice, $order->discountAmount, 2);
  402. $order->save();
  403. $orderItemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  404. if (!empty($orderItemList)) {
  405. foreach ($orderItemList as $orderItem) {
  406. $productId = $orderItem->productId ?? 0;
  407. $refundNum = $ghsSaleRefund[$orderSn][$productId] ?? 0;
  408. $bigNum = $orderItem->bigNum ?? 0;
  409. $smallNum = $orderItem->smallNum ?? 0;
  410. $unitPrice = $orderItem->unitPrice ?? 0;
  411. $smallUnitPrice = $orderItem->smallUnitPrice ?? 0;
  412. if ($bigNum > 0) {
  413. $xhUnitType = 0;
  414. $xhUnitName = '扎';
  415. $xhNum = $bigNum;
  416. $xhUnitPrice = $unitPrice;
  417. } else {
  418. $xhUnitType = 1;
  419. $xhUnitName = '支';
  420. $xhNum = $smallNum;
  421. $xhUnitPrice = $smallUnitPrice;
  422. }
  423. $orderItem->xhNum = $xhNum;
  424. $orderItem->xhUnitName = $xhUnitName;
  425. $orderItem->xhUnitType = $xhUnitType;
  426. $orderItem->xhUnitPrice = $xhUnitPrice;
  427. $orderItem->xhPrice = bcmul($xhNum, $xhUnitPrice, 2);
  428. $orderItem->xhPreNum = 0;
  429. $orderItem->xhPreUnitName = 0;
  430. $orderItem->xhPreUnitType = 0;
  431. $orderItem->xhPreUnitPrice = 0;
  432. $orderItem->xhPrePrice = 0;
  433. //refundNum 已退货数量
  434. $orderItem->refundNum = $refundNum;
  435. $orderItem->save();
  436. }
  437. }
  438. }
  439. }
  440. $cgList = PurchaseClass::getAllByCondition(['id>' => 0], null, '*', null, true);
  441. if (!empty($cgList)) {
  442. foreach ($cgList as $cg) {
  443. $orderSn = $cg->orderSn ?? '';
  444. $cgId = $cg->id ?? 0;
  445. if (empty($orderSn)) {
  446. continue;
  447. }
  448. $cg->orderPrice = bcsub($cg->prePrice, $cg->discountAmount, 2);
  449. $cg->save();
  450. $cgItemList = PurchaseItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  451. if (!empty($cgItemList)) {
  452. foreach ($cgItemList as $cgItem) {
  453. $productId = $cgItem->productId ?? 0;
  454. $refundNum = $hdCgRefund[$cgId][$productId] ?? 0;
  455. if (floor($cgItem->itemNum) == $cgItem->itemNum) {
  456. $xhNum = $cgItem->itemNum;
  457. $xhUnitType = 0;
  458. $xhUnitName = '扎';
  459. $xhUnitPrice = $cgItem->price;
  460. $xhPrice = $cgItem->totalPrice;
  461. } else {
  462. $xhUnitType = 1;
  463. $xhUnitName = '支';
  464. $xhNum = bcmul($cgItem->ratio, $cgItem->itemNum);
  465. $xhUnitPrice = $cgItem->smallPrice;
  466. $xhPrice = $cgItem->totalPrice;
  467. }
  468. $cgItem->xhNum = $xhNum;
  469. $cgItem->xhUnitName = $xhUnitName;
  470. $cgItem->xhUnitType = $xhUnitType;
  471. $cgItem->xhUnitPrice = $xhUnitPrice;
  472. $cgItem->xhPrice = $xhPrice;
  473. $cgItem->refundNum = $refundNum;
  474. $cgItem->save();
  475. }
  476. }
  477. }
  478. }
  479. //将平台花材的散客加价设置为8,花店加价设置为6,同行加价设置为4
  480. $sql = 'UPDATE `xhPtItem` SET `skAddPrice`=8,`addPrice`=6,`hjAddPrice`=4;';
  481. Yii::$app->db->createCommand($sql)->execute();
  482. self::migrationDel();
  483. //客户和供应商的中央化
  484. self::ghsCustomMain($map);
  485. }
  486. //客户和供应商的中央化 ssh 20220506
  487. public static function ghsCustomMain($map)
  488. {
  489. $customList = CustomClass::getAllByCondition(['id>' => 0], null, '*', null, true);
  490. if (!empty($customList)) {
  491. foreach ($customList as $custom) {
  492. $shopId = $custom->shopId ?? 0;
  493. $mainId = $map[$shopId] ?? 0;
  494. $custom->mainId = $mainId;
  495. $ownShopId = $custom->ownShopId ?? 0;
  496. $ownMainId = $map[$ownShopId] ?? 0;
  497. $custom->ownMainId = $ownMainId;
  498. $custom->save();
  499. }
  500. }
  501. $ghsList = GhsClass::getAllByCondition(['id>' => 0], null, '*', null, true);
  502. foreach ($ghsList as $ghs) {
  503. $shopId = $ghs->shopId ?? 0;
  504. $mainId = $map[$shopId] ?? 0;
  505. $ghs->mainId = $mainId;
  506. $ownShopId = $ghs->ownShopId ?? 0;
  507. $ownMainId = $map[$ownShopId] ?? 0;
  508. $ghs->ownMainId = $ownMainId;
  509. $ghs->save();
  510. }
  511. }
  512. public static function setCommon($shopId, $mainId)
  513. {
  514. ShopAdminClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  515. CashClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  516. AdminRoleClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  517. CheckOrderClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  518. StatPdAddClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  519. StatPdAddMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  520. StatPdSubClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  521. StatPdSubMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  522. StatWastClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  523. StatWastMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  524. }
  525. public static function setGhs($shopId, $mainId)
  526. {
  527. StatSaleClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  528. StatSaleMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  529. StatUserClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  530. StatUserMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  531. StatVisitClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  532. StatVisitMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  533. StatOutClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  534. StatOutMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  535. PtYeChangeClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  536. ShopYeChangeClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  537. RechargeClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  538. StatYjClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  539. StatYjMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  540. StatOrderClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  541. StatOrderMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  542. StatOrderCountClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  543. RefundOrderClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  544. //采购统计
  545. StatCgClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  546. StatCgMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  547. StatCgGhsClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  548. StatCgGhsMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  549. CustomClass::updateByCondition(['ownShopId' => $shopId], ['ownMainId' => $mainId]);
  550. StatStockOutClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  551. StatStockOutMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  552. StatStockInClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  553. StatStockInMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  554. StatRefundClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  555. StatRefundMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  556. CgClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  557. XjClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  558. //报损中央化
  559. StockWastageOrderClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  560. $wastageList = StockWastageOrderClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  561. if (!empty($wastageList)) {
  562. foreach ($wastageList as $wastage) {
  563. $wastageOrderSn = $wastage->orderSn ?? 0;
  564. StockWastageOrderItemClass::updateByCondition(['orderSn' => $wastageOrderSn], ['mainId' => $mainId]);
  565. }
  566. }
  567. }
  568. public static function setHd($sjId, $shopId, $mainId)
  569. {
  570. GoodsClass::updateByCondition(['sjId' => $sjId], ['mainId' => $mainId]);
  571. GoodsCategoryClass::updateByCondition(['sjId' => $sjId], ['mainId' => $mainId]);
  572. CategoryClass::updateByCondition(['sjId' => $sjId], ['mainId' => $mainId]);
  573. GoodsSettingClass::updateByCondition(['sjId' => $sjId], ['mainId' => $mainId]);
  574. FestRiseClass::updateByCondition(['sjId' => $sjId], ['mainId' => $mainId]);
  575. GhsClass::updateByCondition(['ownShopId' => $shopId], ['ownMainId' => $mainId]);
  576. PurchaseClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
  577. }
  578. public static function migration($main, $shop)
  579. {
  580. //shop数据迁移到main,保存之后请在migrationDel()增加对应字段!!!!!!
  581. $main->balance = $shop->balance ?? 0;
  582. $main->freezeBalance = $shop->freezeBalance ?? 0;
  583. $main->txBalance = $shop->txBalance ?? 0;
  584. $main->fixBalance = $shop->fixBalance ?? 0;
  585. $main->totalRecharge = $shop->totalRecharge ?? 0;
  586. $main->totalIncome = $shop->totalIncome ?? 0;
  587. $main->totalExpend = $shop->totalExpend ?? 0;
  588. $main->totalPurchase = $shop->totalPurchase ?? 0;
  589. $main->totalItem = $shop->totalItem ?? 0;
  590. $main->totalSale = $shop->totalSale ?? 0;
  591. $main->totalStockIn = $shop->totalStockIn ?? 0;
  592. $main->totalStockOut = $shop->totalStockOut ?? 0;
  593. $main->totalRefund = $shop->totalRefund ?? 0;
  594. $main->totalWast = $shop->totalWast ?? 0;
  595. $main->totalPdSub = $shop->totalPdSub ?? 0;
  596. $main->totalPdAdd = $shop->totalPdAdd ?? 0;
  597. $main->totalPurchaseOrder = $shop->totalPurchaseOrder ?? 0;
  598. $main->totalUser = $shop->totalUser ?? 0;
  599. $main->totalVisit = $shop->totalVisit ?? 0;
  600. $main->totalView = $shop->totalView ?? 0;
  601. $main->cashName = $shop->cashName ?? '';
  602. $main->cashAccount = $shop->cashAccount ?? '';
  603. $main->cashBank = $shop->cashBank ?? '';
  604. $main->cgUnPay = $shop->cgUnPay ?? 0;
  605. $main->cgUnSend = $shop->cgUnSend ?? 0;
  606. $main->cgSending = $shop->cgSending ?? 0;
  607. $main->cgFinish = $shop->cgFinish ?? 0;
  608. $main->cgCancel = $shop->cgCancel ?? 0;
  609. $main->mayGatheringNum = $shop->mayGatheringNum ?? 0;
  610. $main->mayGathering = $shop->mayGathering ?? 0;
  611. $main->mayPay = $shop->mayPay ?? 0;
  612. $main->mayPayNum = $shop->mayPayNum ?? 0;
  613. $main->totalOrder = $shop->totalOrder ?? 0;
  614. $main->totalOrderNum = $shop->totalOrderNum ?? 0;
  615. $main->finishOrder = $shop->finishOrder ?? 0;
  616. $main->unPayOrder = $shop->unPayOrder ?? 0;
  617. $main->unSendOrder = $shop->unSendOrder ?? 0;
  618. $main->sendingOrder = $shop->sendingOrder ?? 0;
  619. $main->cancelOrder = $shop->cancelOrder ?? 0;
  620. $main->save();
  621. }
  622. //迁移完成之后删除xhShop对应字段
  623. public static function migrationDel()
  624. {
  625. $sql = "ALTER TABLE `xhShop` DROP COLUMN `balance`;";
  626. Yii::$app->db->createCommand($sql)->execute();
  627. $sql = "ALTER TABLE `xhShop` DROP COLUMN `freezeBalance`;";
  628. Yii::$app->db->createCommand($sql)->execute();
  629. $sql = "ALTER TABLE `xhShop` DROP COLUMN `txBalance`;";
  630. Yii::$app->db->createCommand($sql)->execute();
  631. $sql = "ALTER TABLE `xhShop` DROP COLUMN `fixBalance`;";
  632. Yii::$app->db->createCommand($sql)->execute();
  633. $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalRecharge`;";
  634. Yii::$app->db->createCommand($sql)->execute();
  635. $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalIncome`;";
  636. Yii::$app->db->createCommand($sql)->execute();
  637. $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalExpend`;";
  638. Yii::$app->db->createCommand($sql)->execute();
  639. $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalPurchase`;";
  640. Yii::$app->db->createCommand($sql)->execute();
  641. $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalItem`;";
  642. Yii::$app->db->createCommand($sql)->execute();
  643. $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalSale`;";
  644. Yii::$app->db->createCommand($sql)->execute();
  645. $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalStockIn`;";
  646. Yii::$app->db->createCommand($sql)->execute();
  647. $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalStockOut`;";
  648. Yii::$app->db->createCommand($sql)->execute();
  649. $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalRefund`;";
  650. Yii::$app->db->createCommand($sql)->execute();
  651. $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalWast`;";
  652. Yii::$app->db->createCommand($sql)->execute();
  653. $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalPdSub`;";
  654. Yii::$app->db->createCommand($sql)->execute();
  655. $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalPdAdd`;";
  656. Yii::$app->db->createCommand($sql)->execute();
  657. $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalPurchaseOrder`;";
  658. Yii::$app->db->createCommand($sql)->execute();
  659. $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalUser`;";
  660. Yii::$app->db->createCommand($sql)->execute();
  661. $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalVisit`;";
  662. Yii::$app->db->createCommand($sql)->execute();
  663. $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalView`;";
  664. Yii::$app->db->createCommand($sql)->execute();
  665. $sql = "ALTER TABLE `xhShop` DROP COLUMN `cashName`;";
  666. Yii::$app->db->createCommand($sql)->execute();
  667. $sql = "ALTER TABLE `xhShop` DROP COLUMN `cashAccount`;";
  668. Yii::$app->db->createCommand($sql)->execute();
  669. $sql = "ALTER TABLE `xhShop` DROP COLUMN `cashBank`;";
  670. Yii::$app->db->createCommand($sql)->execute();
  671. $sql = "ALTER TABLE `xhShop` DROP COLUMN `cgUnPay`;";
  672. Yii::$app->db->createCommand($sql)->execute();
  673. $sql = "ALTER TABLE `xhShop` DROP COLUMN `cgUnSend`;";
  674. Yii::$app->db->createCommand($sql)->execute();
  675. $sql = "ALTER TABLE `xhShop` DROP COLUMN `cgSending`;";
  676. Yii::$app->db->createCommand($sql)->execute();
  677. $sql = "ALTER TABLE `xhShop` DROP COLUMN `cgFinish`;";
  678. Yii::$app->db->createCommand($sql)->execute();
  679. $sql = "ALTER TABLE `xhShop` DROP COLUMN `cgCancel`;";
  680. Yii::$app->db->createCommand($sql)->execute();
  681. $sql = "ALTER TABLE `xhShop` DROP COLUMN `mayGathering`;";
  682. Yii::$app->db->createCommand($sql)->execute();
  683. $sql = "ALTER TABLE `xhShop` DROP COLUMN `mayGatheringNum`;";
  684. Yii::$app->db->createCommand($sql)->execute();
  685. $sql = "ALTER TABLE `xhShop` DROP COLUMN `mayPay`;";
  686. Yii::$app->db->createCommand($sql)->execute();
  687. $sql = "ALTER TABLE `xhShop` DROP COLUMN `mayPayNum`;";
  688. Yii::$app->db->createCommand($sql)->execute();
  689. $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalOrder`;";
  690. Yii::$app->db->createCommand($sql)->execute();
  691. $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalOrderNum`;";
  692. Yii::$app->db->createCommand($sql)->execute();
  693. $sql = "ALTER TABLE `xhShop` DROP COLUMN `finishOrder`;";
  694. Yii::$app->db->createCommand($sql)->execute();
  695. $sql = "ALTER TABLE `xhShop` DROP COLUMN `unPayOrder`;";
  696. Yii::$app->db->createCommand($sql)->execute();
  697. $sql = "ALTER TABLE `xhShop` DROP COLUMN `unSendOrder`;";
  698. Yii::$app->db->createCommand($sql)->execute();
  699. $sql = "ALTER TABLE `xhShop` DROP COLUMN `sendingOrder`;";
  700. Yii::$app->db->createCommand($sql)->execute();
  701. $sql = "ALTER TABLE `xhShop` DROP COLUMN `cancelOrder`;";
  702. Yii::$app->db->createCommand($sql)->execute();
  703. }
  704. //结账单补数据
  705. public function actionClear()
  706. {
  707. $query = new \yii\db\Query();
  708. $query->from(Clear::tableName());
  709. $query->where(['>', 'id', 0]);
  710. $query->orderBy('addTime ASC');
  711. foreach ($query->batch() as $clearBatch) {
  712. $batchGhsId = array_column($clearBatch, 'ghsId');
  713. $batchCustomId = array_column($clearBatch, 'customId');
  714. $batchGhsId = array_unique(array_filter($batchGhsId));
  715. $batchCustomId = array_unique(array_filter($batchCustomId));
  716. $customInfo = CustomClass::getByIds($batchCustomId, null, 'id');
  717. $ghsInfo = GhsClass::getByIds($batchGhsId, null, 'id');
  718. foreach ($clearBatch as $clear) {
  719. $id = $clear['id'];
  720. $clearStyle = $clear['clearStyle'] ?? 1;
  721. if ($clearStyle != dict::getDict('clearStyle', 'gys2KmGys')) {
  722. $customId = $clear['customId'] ?? 0;
  723. $ghsId = $clear['ghsId'] ?? 0;
  724. $customShopId = $customInfo[$customId]['shopId'] ?? 0;
  725. $ghsShopId = $ghsInfo[$ghsId]['shopId'] ?? 0;
  726. $params = ['customShopId' => $customShopId, 'ghsShopId' => $ghsShopId];
  727. ClearClass::updateById($id, $params);
  728. } else {
  729. $currentGhsId = $clear['ghsId'] ?? 0;
  730. if (empty($currentGhsId)) {
  731. echo "出现空的ghsId clearId:{$id} \n";
  732. continue;
  733. }
  734. $currentGhs = GhsClass::getById($currentGhsId, true);
  735. $currentCustomId = $currentGhs->customId ?? 0;
  736. $currentCustom = CustomClass::getById($currentCustomId, true);
  737. $customShopId = $currentCustom->shopId ?? 0;
  738. $ghsShopId = $currentGhs->shopId ?? 0;
  739. $params = ['customShopId' => $customShopId, 'customId' => $currentCustomId, 'ghsShopId' => $ghsShopId];
  740. ClearClass::updateById($id, $params);
  741. }
  742. }
  743. }
  744. }
  745. }