InitController.php 33 KB

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