InitController.php 32 KB

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