InitController.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. namespace console\controllers;
  3. use biz\admin\classes\AdminClass;
  4. use biz\item\classes\UnitClass;
  5. use biz\product\classes\ProductClass;
  6. use biz\shop\classes\ShopClass;
  7. use bizGhs\custom\classes\CustomClass;
  8. use bizGhs\ghs\classes\GhsClass;
  9. use bizGhs\order\classes\PurchaseOrderClass;
  10. use bizGhs\order\classes\PurchaseOrderItemClass;
  11. use bizGhs\order\classes\StockInOrderClass;
  12. use bizGhs\order\classes\StockOutOrderClass;
  13. use bizGhs\order\classes\StockOutOrderItemClass;
  14. use bizGhs\stock\classes\OnStockRecordClass;
  15. use bizHd\purchase\classes\PurchaseClass;
  16. use bizHd\purchase\classes\PurchaseItemClass;
  17. use yii\console\Controller;
  18. class InitController extends Controller
  19. {
  20. //在路上库存 ssh 20231218
  21. public function actionOnStock()
  22. {
  23. ini_set('memory_limit', '2045M');
  24. set_time_limit(0);
  25. ProductClass::updateByCondition(['id>' => 0], ['onStock' => 0]);
  26. $cgList = PurchaseOrderClass::getAllByCondition(['status' => 3], null, '*', null, true);
  27. if (!empty($cgList)) {
  28. foreach ($cgList as $key => $cg) {
  29. $orderSn = $cg->orderSn ?? '';
  30. $sjId = $cg->sjId ?? 0;
  31. $shopId = $cg->shopId ?? 0;
  32. $mainId = $cg->mainId ?? 0;
  33. $ghsName = $cg->ghsName ?? '';
  34. $itemList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  35. if (!empty($itemList)) {
  36. foreach ($itemList as $info) {
  37. $productId = $info->productId ?? 0;
  38. $itemId = $info->itemId ?? 0;
  39. $num = $info->itemNum ?? 0;
  40. $product = ProductClass::getLockById($productId);
  41. //增加路上库存
  42. $onRecord = [];
  43. $onRecord['sjId'] = $sjId;
  44. $onRecord['shopId'] = $shopId;
  45. $onRecord['mainId'] = $mainId;
  46. $onRecord['orderSn'] = $orderSn;
  47. $onRecord['productId'] = $productId;
  48. $onRecord['itemId'] = $itemId;
  49. $onRecord['relateName'] = $ghsName;
  50. $onRecord['itemNum'] = $num;
  51. $oldOnStock = $product->onStock ?? 0;
  52. $onRecord['oldStock'] = $oldOnStock;
  53. $newOnStock = bcadd($oldOnStock, $num);
  54. $onRecord['newStock'] = $newOnStock;
  55. $onRecord['ptStyle'] = 2;
  56. OnStockRecordClass::addPurchaseOrderRecord($onRecord);
  57. \bizGhs\product\classes\ProductClass::addOnStockByItemNum($productId, $num);
  58. }
  59. }
  60. }
  61. }
  62. }
  63. public function actionLsOnStock()
  64. {
  65. ini_set('memory_limit', '2045M');
  66. set_time_limit(0);
  67. $cgList = PurchaseClass::getAllByCondition(['status' => 3], null, '*', null, true);
  68. if (!empty($cgList)) {
  69. foreach ($cgList as $key => $cg) {
  70. $orderSn = $cg->orderSn ?? '';
  71. $sjId = $cg->sjId ?? 0;
  72. $shopId = $cg->shopId ?? 0;
  73. $mainId = $cg->mainId ?? 0;
  74. $ghsName = $cg->ghsName ?? '';
  75. $itemList = PurchaseItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  76. if (!empty($itemList)) {
  77. foreach ($itemList as $val) {
  78. $productId = $val->productId ?? 0;
  79. $itemId = $val->itemId ?? 0;
  80. $num = $val->xhNum ?? 0;
  81. $product = ProductClass::getLockById($productId);
  82. if (empty($product)) {
  83. util::fail('没有找到花材呢');
  84. }
  85. //增加路上库存
  86. $onRecord = [];
  87. $onRecord['sjId'] = $sjId;
  88. $onRecord['shopId'] = $shopId;
  89. $onRecord['mainId'] = $mainId;
  90. $onRecord['orderSn'] = $orderSn;
  91. $onRecord['productId'] = $productId;
  92. $onRecord['itemId'] = $itemId;
  93. $onRecord['relateName'] = $ghsName;
  94. $onRecord['itemNum'] = $num;
  95. $oldOnStock = $product->onStock ?? 0;
  96. $onRecord['oldStock'] = $oldOnStock;
  97. $newOnStock = bcadd($oldOnStock, $num);
  98. $onRecord['newStock'] = $newOnStock;
  99. $onRecord['ptStyle'] = 1;
  100. OnStockRecordClass::addPurchaseOrderRecord($onRecord);
  101. \bizGhs\product\classes\ProductClass::addOnStockByItemNum($productId, $num);
  102. }
  103. }
  104. }
  105. }
  106. }
  107. public function actionCustom()
  108. {
  109. $list = CustomClass::getAllByCondition(['isHd' => 0], null, '*', null, true);
  110. if (!empty($list)) {
  111. foreach ($list as $custom) {
  112. $custom->level = 0;
  113. $custom->save();
  114. $ghsId = $custom->ghsId;
  115. $ghs = GhsClass::getById($ghsId, true);
  116. if (!empty($ghs)) {
  117. $ghs->giveLevel = 0;
  118. $ghs->save();
  119. echo 'customId:' . $custom->id . ' ghsId:' . $ghsId . "\n";
  120. }
  121. }
  122. }
  123. }
  124. public function actionOut()
  125. {
  126. ini_set('memory_limit', '2045M');
  127. set_time_limit(0);
  128. $list = StockOutOrderClass::getAllByCondition(['addTime>' => '2022-11-10 00:00:00'], null, '*', null, true);
  129. if (empty($list)) {
  130. return false;
  131. }
  132. foreach ($list as $out) {
  133. $orderSn = $out->orderSn ?? '';
  134. $inOrderSn = $out->inOrderSn ?? '';
  135. $in = StockInOrderClass::getByCondition(['orderSn' => $inOrderSn], true);
  136. if (empty($in)) {
  137. echo $orderSn . " 没有找到入库记录\n";
  138. }
  139. $itemList = StockOutOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  140. $totalCost = 0;
  141. if (!empty($itemList)) {
  142. foreach ($itemList as $item) {
  143. $itemNum = $item->itemNum ?? 0;
  144. $itemPrice = $item->itemPrice ?? 0;
  145. $current = bcmul($itemNum, $itemPrice, 2);
  146. $totalCost = bcadd($totalCost, $current, 2);
  147. }
  148. }
  149. $in->price = $totalCost;
  150. $in->save();
  151. $out->price = $totalCost;
  152. $out->save();
  153. echo $orderSn . " 总成本{$totalCost}\n";
  154. }
  155. }
  156. }