WorkItemClass.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. namespace bizHd\work\classes;
  3. use biz\stock\classes\StockClass;
  4. use bizGhs\order\classes\StockWastageOrderClass;
  5. use bizGhs\product\classes\ProductClass;
  6. use bizHd\order\classes\OrderGoodsClass;
  7. use common\components\arrayUtil;
  8. use common\components\dict;
  9. use common\components\imgUtil;
  10. use common\components\orderSn;
  11. use common\components\util;
  12. use Yii;
  13. use bizHd\base\classes\BaseClass;
  14. class WorkItemClass extends BaseClass
  15. {
  16. public static $baseFile = '\bizHd\work\models\WorkItem';
  17. public static function valid($item, $mainId)
  18. {
  19. if (empty($item)) {
  20. util::fail('没有找到数据');
  21. }
  22. if (isset($item->mainId) == false || $item->mainId != $mainId) {
  23. util::fail('没有权限');
  24. }
  25. }
  26. //报损处理 ssh 20220425
  27. public static function wastage($work)
  28. {
  29. $workSn = $work->workSn ?? '';
  30. $mainId = $work->mainId ?? 0;
  31. $sjId = $work->sjId ?? 0;
  32. $shopId = $work->shopId ?? 0;
  33. $staffId = $work->staffId ?? 0;
  34. $staffName = $work->staffName ?? '';
  35. $itemList = self::getAllByCondition(['workSn' => $workSn], null, '*', null, true);
  36. $product = [];
  37. if (!empty($itemList)) {
  38. foreach ($itemList as $key => $item) {
  39. $wastNum = $item->wastNum ?? 0;
  40. $wastUnitType = $item->wastUnitType ?? 0;
  41. $mainId = $item->mainId ?? 0;
  42. if ($wastNum > 0) {
  43. $ptItemId = $item->ptItemId ?? 0;
  44. $productId = $item->itemId ?? 0;
  45. $bigNum = $wastUnitType == 0 ? $wastNum : 0;
  46. $smallNum = $wastUnitType == 0 ? 0 : $wastNum;
  47. $product[] = [
  48. 'productId' => $productId,
  49. 'bigNum' => $bigNum,
  50. 'smallNum' => $smallNum,
  51. 'classId' => -1,
  52. 'itemId' => $ptItemId,
  53. ];
  54. }
  55. }
  56. }
  57. if (empty($product)) {
  58. return true;
  59. }
  60. $data = [];
  61. $data['product'] = $product;
  62. $data['status'] = StockWastageOrderClass::STATUS_COMPLETE;
  63. $orderSn = orderSn::getGhsStockWastageSn();
  64. $data['orderSn'] = $orderSn;
  65. $data['sjId'] = $sjId;
  66. $data['shopId'] = $shopId;
  67. $data['shopAdminId'] = $staffId;
  68. $data['shopAdminName'] = $staffName;
  69. $data['bigNum'] = 0;
  70. $data['smallNum'] = 0;
  71. $data['remark'] = '制作单报损';
  72. $data['mainId'] = $mainId;
  73. $data['type'] = StockWastageOrderClass::WASTAGE_TYPE_WORK;
  74. $data['targetId'] = $work->id ?? 0;
  75. $data['ptStyle'] = dict::getDict('ptStyle', 'hd');
  76. StockWastageOrderClass::addOrder($data);
  77. }
  78. //取消锁定,释放库存 ssh 20220320
  79. public static function cancelLock($work)
  80. {
  81. //没有锁定,直接返回
  82. if ($work->stockLock == 0) {
  83. return true;
  84. }
  85. $workSn = $work->workSn ?? '';
  86. $sjId = $work->sjId ?? 0;
  87. $shopId = $work->shopId ?? 0;
  88. $num = $work->num ?? 0;
  89. $itemList = self::getAllByCondition(['workSn' => $workSn], null, '*', null, true);
  90. if (!empty($itemList)) {
  91. foreach ($itemList as $key => $item) {
  92. //库存回滚
  93. $unitType = $item->unitType ?? 0;
  94. $itemId = $item->itemId ?? 0;
  95. $itemNum = $item->num ?? 0;
  96. $currentNum = bcmul($itemNum, $num);
  97. if ($currentNum > 0) {
  98. OrderGoodsClass::consumeItemByMakeGoodsCancel($workSn, $sjId, $shopId, $itemId, $currentNum, $unitType);
  99. }
  100. }
  101. }
  102. $work->stockLock = 0;
  103. $work->save();
  104. }
  105. //修改用材 ssh 20220320
  106. public static function modifyItem($work, $product)
  107. {
  108. $ids = array_column($product, 'productId');
  109. if (empty($ids)) {
  110. util::fail('请选择花材哦');
  111. }
  112. $info = ProductClass::getByIds($ids, null, 'id');
  113. $sjId = $work->sjId ?? 0;
  114. $shopId = $work->shopId ?? 0;
  115. $mainId = $work->mainId ?? 0;
  116. $workSn = $work->workSn ?? '';
  117. WorkItemClass::deleteByCondition(['workSn' => $workSn]);
  118. foreach ($product as $key => $val) {
  119. $id = $val['productId'] ?? 0;
  120. $num = $val['num'] ?? 0;
  121. $unitType = $val['unitType'] ?? 0;
  122. $unitPrice = $val['unitPrice'] ?? 0;
  123. $name = $info[$id]['name'] ?? '';
  124. $cover = $info[$id]['cover'] ?? '';
  125. $ptItemId = $info[$id]['itemId'] ?? 0;
  126. $unitCost = $info[$id]['cost'] ?? 0;
  127. $ratio = $info[$id]['ratio'] ?? 0;
  128. $bigName = $info[$id]['bigUnit'] ?? '';
  129. $smallName = $info[$id]['smallUnit'] ?? '';
  130. if ($unitType == dict::getDict('unitType', 'big')) {
  131. $count = $num;
  132. $cost = bcmul($unitCost, $num, 2);
  133. $unitName = $bigName;
  134. } else {
  135. $count = bcdiv($num, $ratio, 2);
  136. $cost = bcmul($unitCost, $count, 2);
  137. $unitName = $smallName;
  138. }
  139. $workData = [
  140. 'name' => $name,
  141. 'cover' => $cover,
  142. 'workSn' => $workSn,
  143. 'itemId' => $id,
  144. 'ptItemId' => $ptItemId,
  145. 'sjId' => $sjId,
  146. 'shopId' => $shopId,
  147. 'mainId' => $mainId,
  148. 'num' => $num,
  149. 'unitType' => $unitType,
  150. 'unitName' => $unitName,
  151. 'count' => $count,
  152. 'unitCost' => $unitCost,
  153. 'cost' => $cost,
  154. 'ratio' => $ratio,
  155. 'bigName' => $bigName,
  156. 'smallName' => $smallName,
  157. 'unitPrice' => $unitPrice,
  158. ];
  159. WorkItemClass::add($workData);
  160. }
  161. }
  162. //锁定用材 ssh 20220320
  163. public static function lock($work)
  164. {
  165. $workSn = $work->workSn ?? '';
  166. $sjId = $work->sjId ?? 0;
  167. $shopId = $work->shopId ?? 0;
  168. $stockLock = $work->stockLock ?? 0;
  169. if ($stockLock == 1) {
  170. util::fail('库存已锁定了');
  171. }
  172. $list = self::getAllByCondition(['workSn' => $workSn], null, '*', null, true);
  173. if (empty($list)) {
  174. util::fail('没有花材');
  175. }
  176. $bigNum = 0;
  177. $smallNum = 0;
  178. $workNum = $work->num;
  179. foreach ($list as $key => $item) {
  180. $unitType = $item->unitType ?? 0;
  181. $num = $item->num ?? 0;
  182. $itemId = $item->itemId ?? 0;
  183. //减库存
  184. $totalNum = bcmul($workNum, $num);
  185. OrderGoodsClass::consumeItemByMakeGoods($workSn, $sjId, $shopId, $itemId, $totalNum, $unitType);
  186. }
  187. $work->bigNum = $bigNum;
  188. $work->smallNum = $smallNum;
  189. $work->stockLock = 1;
  190. $work->save();
  191. }
  192. //获取制作单的所有花材信息 ssh 20220320
  193. public static function getWorkAllItem($work)
  194. {
  195. $workSn = $work->workSn ?? '';
  196. $list = self::getAllByCondition(['workSn' => $workSn], null, '*');
  197. if (empty($list)) {
  198. return $list;
  199. }
  200. return self::groupInfo($list);
  201. }
  202. //组合信息
  203. public static function groupInfo($list)
  204. {
  205. if (empty($list)) {
  206. return $list;
  207. }
  208. foreach ($list as $key => $val) {
  209. $shortCover = $val['cover'] ?? '';
  210. $cover = imgUtil::groupImg('');
  211. $bigCover = imgUtil::groupImg('');
  212. if (!empty($shortCover)) {
  213. $cover = self::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_110,w_110";
  214. $bigCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  215. }
  216. $list[$key]['cover'] = $cover;
  217. $list[$key]['bigCover'] = $bigCover;
  218. $list[$key]['shortCover'] = $shortCover;
  219. }
  220. return $list;
  221. }
  222. }