WorkItemClass.php 7.1 KB

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