WorkItemClass.php 9.3 KB

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