InitController.php 34 KB

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