InitController.php 6.7 KB

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