PurchaseItemClass.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace bizHd\purchase\classes;
  3. use bizHd\cg\classes\AcceptClass;
  4. use bizHd\merchant\classes\ShopClass;
  5. use bizHd\product\classes\ProductClass;
  6. use common\components\dict;
  7. use common\components\orderSn;
  8. use common\components\stringUtil;
  9. use common\components\util;
  10. use Yii;
  11. use bizHd\base\classes\BaseClass;
  12. use bizGhs\stock\classes\StockRecordClass;
  13. class PurchaseItemClass extends BaseClass
  14. {
  15. public static $baseFile = '\bizHd\purchase\models\PurchaseItem';
  16. public static function acceptItem($cgId, $ptItemId, $num)
  17. {
  18. $cg = PurchaseClass::getById($cgId, true);
  19. if (empty($cg)) {
  20. util::fail('没有采购信息');
  21. }
  22. $cgOrderSn = $cg->orderSn ?? '';
  23. $shopId = $cg->shopId ?? 0;
  24. $shop = ShopClass::getById($shopId, true);
  25. if (empty($shop)) {
  26. util::fail('没有找到采购门店信息');
  27. }
  28. $pfShopId = $shop->pfShopId ?? 0;
  29. if (!empty($pfShopId)) {
  30. util::fail('客户有批发店,不能直接赠送');
  31. }
  32. $sjId = $cg->sjId ?? 0;
  33. $mainId = $cg->mainId ?? 0;
  34. $targetId = $cg->id ?? 0;
  35. $cgItemList = PurchaseItemClass::getAllByCondition(['orderSn' => $cgOrderSn], null, '*', null, true);
  36. if (empty($cgItemList)) {
  37. util::fail('没有采购信息哦');
  38. }
  39. $targetSonId = 0;
  40. $productId = 0;
  41. $selectInfo = null;
  42. foreach ($cgItemList as $cgItem) {
  43. $currentPtItemId = $cgItem->itemId ?? 0;
  44. $currentId = $cgItem->id ?? 0;
  45. if ($currentPtItemId == $ptItemId) {
  46. $targetSonId = $currentId;
  47. $productId = $cgItem->productId ?? 0;
  48. $selectInfo = $cgItem;
  49. }
  50. }
  51. if (empty($selectInfo)) {
  52. util::fail('没有采购信息');
  53. }
  54. $selectInfo->acceptNum = bcadd($selectInfo->acceptNum, $num);
  55. $selectInfo->save();
  56. if (empty($productId)) {
  57. util::fail('没有找到采购的花材信息');
  58. }
  59. $product = ProductClass::getById($productId, true);
  60. if (empty($product)) {
  61. util::fail('没有花材信息');
  62. }
  63. $orderSn = orderSn::getAcceptSn();
  64. $accData = [
  65. 'orderSn' => $orderSn,
  66. 'mainId' => $mainId,
  67. 'productId' => $productId,
  68. 'name' => $product->name ?? '',
  69. 'cover' => $product->cover ?? '',
  70. 'ratio' => $product->ratio ?? 20,
  71. 'ratioType' => $product->ratioType ?? 0,
  72. 'ptItemId' => $ptItemId,
  73. 'giveNum' => $num,
  74. 'targetId' => $targetId,
  75. 'targetSonId' => $targetSonId,
  76. 'customId' => $cg->customId ?? 0,
  77. 'ghsId' => $cg->ghsId ?? 0,
  78. 'ghsName' => $cg->ghsName ?? '',
  79. 'ghsAvatar' => $cg->ghsAvatar ?? '',
  80. 'ghsMobile' => $cg->ghsMobile ?? '',
  81. ];
  82. $ac = AcceptClass::add($accData, true);
  83. $stockInfo = \bizGhs\product\classes\ProductClass::addStock($productId, $num, 0);
  84. $oldStock = $stockInfo['oldStock'];
  85. $newStock = $stockInfo['newStock'];
  86. $stockItem = [[
  87. 'productId' => $productId,
  88. 'itemId' => $ptItemId,
  89. 'itemNum' => $num,
  90. 'oldStock' => $oldStock,
  91. 'itemStock' => $oldStock,
  92. 'newStock' => $newStock,
  93. 'bigNum' => $num,
  94. 'smallNum' => 0,
  95. ]];
  96. $stockData = [];
  97. $stockData['shopId'] = $shopId;
  98. $stockData['relateName'] = '';
  99. $stockData['ptStyle'] = dict::getDict('ptStyle', 'hd');
  100. $stockData['orderSn'] = $orderSn;
  101. $stockData['sjId'] = $sjId;
  102. $stockData['itemInfo'] = $stockItem;
  103. $stockData['relateName'] = $cg->ghsName;
  104. StockRecordClass::addRecordByOrder($stockData, StockRecordClass::STOCK_RECORD_TYPE_ACCEPT);
  105. return $ac;
  106. }
  107. public static function getOrderItemDetail($orderSn)
  108. {
  109. return self::getAllByCondition(['orderSn' => $orderSn], 'id ASC', '*');
  110. }
  111. }