InitController.php 38 KB

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