WorkClass.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <?php
  2. namespace bizHd\work\classes;
  3. use biz\shop\classes\ShopExtClass;
  4. use biz\stat\classes\StatWorkCountClass;
  5. use bizHd\goods\classes\CategoryClass;
  6. use bizHd\goods\classes\GoodsCategoryClass;
  7. use bizHd\goods\classes\GoodsClass;
  8. use bizHd\goods\classes\GoodsItemClass;
  9. use bizHd\order\classes\OrderClass;
  10. use bizHd\order\classes\OrderGoodsClass;
  11. use bizHd\shop\classes\ShopClass;
  12. use bizHd\stat\classes\StatWorkCatClass;
  13. use common\components\dict;
  14. use common\components\imgUtil;
  15. use common\components\noticeUtil;
  16. use common\components\orderSn;
  17. use common\components\printUtil;
  18. use common\components\util;
  19. use bizHd\base\classes\BaseClass;
  20. use Shishaoqi\MeituanFlashPurchase\Application;
  21. class WorkClass extends BaseClass
  22. {
  23. public static $baseFile = '\bizHd\work\models\Work';
  24. const STATUS_UN_COMPLETE = 0;
  25. const STATUS_COMPLETE = 1;
  26. const STATUS_CANCEL = 2;
  27. //创建制作单 ssh 20220618
  28. public static function addWork($data, $main)
  29. {
  30. $catId = $data['catId'] ?? 0;
  31. if (empty($catId)) {
  32. util::fail('没有选择分类');
  33. }
  34. $catName = $data['catName'] ?? '';
  35. $num = $data['num'] ?? 0;
  36. $workNum = 1;
  37. StatWorkCatClass::replace($main, $catId, $catName, $workNum, $num);
  38. return self::add($data, true);
  39. }
  40. //打印工单 ssh 20220601
  41. public static function print($work, $shop, $mustPrint = true)
  42. {
  43. $orderSn = $work->orderSn ?? '';
  44. if (!empty($orderSn)) {
  45. $order = OrderClass::getByCondition(['orderSn' => $orderSn], true);
  46. if (empty($order)) {
  47. util::fail('没有找到订单');
  48. }
  49. OrderClass::onlinePrint($order, false, 'make');
  50. } else {
  51. $shopId = $shop->id ?? 0;
  52. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  53. $printLabelSn = $work->fromType == 4 ? $ext->mtPrintLabelSn : $ext->makePrintLabelSn;
  54. noticeUtil::push("打印1:" . $printLabelSn, '15280215347');
  55. if (empty($printLabelSn)) {
  56. if ($mustPrint) {
  57. util::fail('请设置标签打印机');
  58. }
  59. } else {
  60. $p = new printUtil($printLabelSn);
  61. $workSn = $work->workSn ?? '';
  62. $workItemList = WorkClass::getAllByCondition(['workSn' => $workSn], null, '*', null, true);
  63. if (!empty($workItemList)) {
  64. foreach ($workItemList as $item) {
  65. $goodsSn = $item->goodsSn ?? '';
  66. if (empty($goodsSn)) {
  67. continue;
  68. }
  69. $flag = [];
  70. if ($item->fromType == 2) {
  71. $flag[] = '商城';
  72. } elseif ($item->fromType == 4) {
  73. $flag[] = '美团';
  74. } elseif ($item->fromType == 1) {
  75. $flag[] = '门店';
  76. } else {
  77. if (isset($item->staffName) && !empty($item->staffName)) {
  78. $flag[] = $item->staffName;
  79. }
  80. }
  81. if (isset($item->bookName) && !empty($item->bookName)) {
  82. $flag[] = $item->bookName;
  83. }
  84. if (isset($item->sn) && !empty($item->sn)) {
  85. $flag[] = $item->sn;
  86. }
  87. $flagString = implode(" ", $flag);
  88. $num = $item->num ?? 1;
  89. $name = $item->name ?? '';
  90. $content = '<TEXT x="360" y="30" font="12" w="2" h="2" r="90">' . $name . '</TEXT>';
  91. $content .= '<BC128 x="260" y="30" h="80" s="1" r="90" n="5" w="12">' . $goodsSn . '</BC128>';
  92. $content .= '<TEXT x="60" y="30" font="12" w="2" h="2" r="90">' . $flagString . '</TEXT>';
  93. $p->times = $num;
  94. $p->printLabelMsg($content);
  95. }
  96. }
  97. }
  98. }
  99. }
  100. public static function goodsCreateFinish($data, $main)
  101. {
  102. $goods = $data['goods'] ?? '';
  103. $remark = $data['remark'] ?? '';
  104. $sjId = $data['sjId'] ?? 0;
  105. $shopId = $data['shopId'] ?? 0;
  106. $mainId = $data['mainId'] ?? 0;
  107. $hasReachTime = $data['hasReachTime'] ?? 0;
  108. $reachPeriod = $data['reachPeriod'] ?? 0;
  109. $reachDate = $data['reachDate'] ?? '0000-00-00';
  110. $bookName = $data['bookName'] ?? '';
  111. $staffName = $data['staffName'] ?? '';
  112. $staffId = $data['staffId'] ?? 0;
  113. $orderPrice = $data['orderPrice'] ?? 0;
  114. $orderDebtPrice = $data['orderDebtPrice'] ?? 0;
  115. $sendType = $data['sendType'] ?? 0;
  116. $fromType = $data['fromType'] ?? 1;
  117. $thirdSn = $data['thirdSn'] ?? '';
  118. $cardInfo = $data['cardInfo'] ?? '';
  119. $anonymity = $data['anonymity'] ?? 0;
  120. $ids = array_column($goods, 'productId');
  121. $info = GoodsClass::getByIds($ids, null, 'id');
  122. foreach ($goods as $key => $val) {
  123. $goodsId = $val['productId'] ?? 0;
  124. $name = $info[$goodsId]['name'] ?? '';
  125. $goodsSn = $info[$goodsId]['sn'] ?? '';
  126. $setItemNum = $info[$goodsId]['setItemNum'] ?? 0;
  127. $workNum = $val['num'] ?? 0;
  128. $cover = isset($info[$goodsId]['cover']) && !empty($info[$goodsId]['cover']) ? $info[$goodsId]['cover'] : 'hhb_small.png';
  129. $product = [];
  130. $goodsItem = GoodsItemClass::getAllByCondition(['goodsId' => $goodsId], null, '*');
  131. if (!empty($goodsItem)) {
  132. foreach ($goodsItem as $one) {
  133. $itemId = $one['itemId'] ?? 0;
  134. $unitType = $one['unitType'] ?? 0;
  135. $num = $one['num'] ?? 0;
  136. $product[] = [
  137. 'productId' => $itemId,
  138. 'num' => $num,
  139. 'unitType' => $unitType,
  140. ];
  141. }
  142. }
  143. $goodsCat = GoodsCategoryClass::getByCondition(['gId' => $goodsId], true);
  144. $catId = $goodsCat->cId ?? 0;
  145. $catName = '';
  146. if (!empty($catId)) {
  147. $cat = CategoryClass::getById($catId, true);
  148. $catName = $cat->categoryName ?? '';
  149. }
  150. $workSn = orderSn::getWorkSn();
  151. $flowerNum = $info[$goodsId]['flowerNum'] ?? 0;
  152. $orderSn = $data['orderSn'] ?? '';
  153. $orderId = $data['orderId'] ?? 0;
  154. $current = [
  155. 'name' => $name,
  156. 'num' => $workNum,
  157. 'cover' => $cover,
  158. 'remark' => $remark,
  159. 'catId' => $catId,
  160. 'catName' => $catName,
  161. 'product' => $product,
  162. 'goodsId' => $goodsId,
  163. 'goodsSn' => $goodsSn,
  164. 'sjId' => $sjId,
  165. 'shopId' => $shopId,
  166. 'mainId' => $mainId,
  167. 'workSn' => $workSn,
  168. 'flowerNum' => $flowerNum,
  169. 'orderSn' => $orderSn,
  170. 'orderId' => $orderId,
  171. 'hasReachTime' => $hasReachTime,
  172. 'reachDate' => $reachDate,
  173. 'reachPeriod' => $reachPeriod,
  174. 'setItemNum' => $setItemNum,
  175. 'bookName' => $bookName,
  176. 'staffName' => $staffName,
  177. 'staffId' => $staffId,
  178. 'orderPrice' => $orderPrice,
  179. 'orderDebtPrice' => $orderDebtPrice,
  180. 'fromType' => $fromType,
  181. 'sendType' => $sendType,
  182. 'thirdSn' => $thirdSn,
  183. 'cardInfo' => $cardInfo,
  184. 'anonymity' => $anonymity,
  185. ];
  186. self::createFinish($current, $main);
  187. }
  188. }
  189. public static function createFinish($data, $main)
  190. {
  191. $setItemNum = $data['setItemNum'] ?? 0;
  192. unset($data['setItemNum']);
  193. $data['flowerNum'] = isset($data['flowerNum']) && is_numeric($data['flowerNum']) ? $data['flowerNum'] : 0;
  194. $data['sn'] = StatWorkCountClass::addOrder($main);
  195. $work = WorkClass::addWork($data, $main);
  196. $product = $data['product'] ?? [];
  197. $complete = $data['complete'] ?? 0;
  198. if (!empty($product)) {
  199. $mainId = $main->id ?? 0;
  200. $hd = dict::getDict('ptStyle', 'hd');
  201. $shop = ShopClass::getByCondition(['mainId' => $mainId, 'ptStyle' => $hd], true);
  202. $stockModel = $shop->stockModel ?? 0;
  203. //库存管理管到支 并且 商品的花材数量设置ok,则制作单自动锁定并扣库存 或者 收银台直接完成花材的情况
  204. if (($stockModel == 1 && $setItemNum == 1) || $complete == 1) {
  205. //修改用材
  206. WorkItemClass::modifyItem($work, $product);
  207. //锁定库存
  208. WorkItemClass::lock($work);
  209. } else {
  210. //库存管理,管到扎,不再自动扣库存,并且清空花材
  211. $workSn = $work->workSn ?? '';
  212. WorkItemClass::deleteByCondition(['workSn' => $workSn]);
  213. }
  214. }
  215. if ($complete == 1 && !empty($product)) {
  216. //直接完成
  217. WorkClass::finish($work);
  218. }
  219. return $work;
  220. }
  221. //取消制作单
  222. public static function cancel($work)
  223. {
  224. if ($work->status == self::STATUS_COMPLETE) {
  225. util::fail('制作单已完成');
  226. }
  227. if ($work->status == self::STATUS_CANCEL) {
  228. util::fail('制作单已取消');
  229. }
  230. if (isset($work->orderSn) && !empty($work->orderSn)) {
  231. util::fail('本制作单有订单,请通过订单取消');
  232. }
  233. //取消锁定,释放库存
  234. WorkItemClass::cancelLock($work);
  235. $work->status = self::STATUS_CANCEL;
  236. $work->save();
  237. }
  238. //完成制作单 ssh 20220320
  239. public static function finish($work)
  240. {
  241. $work->status = self::STATUS_COMPLETE;
  242. $work->save();
  243. WorkItemClass::wastage($work);
  244. $fromType = $work->fromType ?? 0;
  245. if ($fromType == dict::getDict('fromType', 'mt')) {
  246. $currentTime = time();
  247. $addTime = $work->addTime;
  248. $createTime = strtotime($addTime);
  249. $diffTime = bcsub($currentTime, $createTime);
  250. if ($diffTime < 60) {
  251. util::fail('美团单请1分钟后开始制作');
  252. }
  253. }
  254. $num = $work->num ?? 0;
  255. $mainId = $work->mainId ?? 0;
  256. $workSn = $work->workSn ?? '';
  257. $workId = $work->id ?? 0;
  258. $sjId = $work->sjId ?? 0;
  259. $shopId = $work->shopId ?? 0;
  260. $goodsId = $work->goodsId ?? 0;
  261. $bigNum = $work->bigNum ?? 0;
  262. $smallNum = $work->smallNum ?? 0;
  263. $flowerNum = $work->flowerNum ?? 0;
  264. //没有商品生成商品
  265. if (empty($goodsId)) {
  266. $name = $work->name ?? '';
  267. $catId = $work->catId ?? 0;
  268. $cover = $work->cover ?? '';
  269. $shopImg = [$cover];
  270. $date = date("Y-m-d H:i:s");
  271. $goodsData = [
  272. 'shopImg' => $shopImg,
  273. 'mainId' => $mainId,
  274. 'cover' => $cover,
  275. 'name' => $name,
  276. 'content' => '',
  277. 'createTime' => $date,
  278. 'sjId' => $sjId,
  279. 'mainId' => $mainId,
  280. 'shopId' => $shopId,
  281. 'bigNum' => $bigNum,
  282. 'smallNum' => $smallNum,
  283. 'workId' => $workId,
  284. 'workSn' => $workSn,
  285. 'flower' => 1,
  286. 'flowerNum' => $flowerNum,
  287. 'status' => 0,
  288. ];
  289. if (!empty($catId)) {
  290. $goodsData['catIds'] = [$catId];
  291. }
  292. $goods = GoodsClass::addGoods($goodsData, $work);
  293. $goodsId = $goods->id ?? 0;
  294. $sn = $goods->sn ?? '';
  295. $work->goodsSn = $sn;
  296. $work->goodsId = $goodsId;
  297. $work->save();
  298. }
  299. //库存增加
  300. $staffName = $work->staffName ?? '';
  301. OrderGoodsClass::addGoodsStockByMakeGoods($workSn, $sjId, $shopId, $mainId, $goodsId, $num, $staffName);
  302. }
  303. //验证制作单 ssh 20220319
  304. public static function valid($work, $mainId)
  305. {
  306. if (empty($work)) {
  307. util::fail('没有找到制作单');
  308. }
  309. if (isset($work->mainId) == false || $work->mainId != $mainId) {
  310. util::fail('没有权限');
  311. }
  312. return true;
  313. }
  314. //工单列表 ssh 20220606
  315. public static function getWorkList($where)
  316. {
  317. $order = 'addTime DESC';
  318. if (isset($where['status'])) {
  319. if ($where['status'] == 0) {
  320. $order = 'hasReachTime DESC,reachDate ASC,reachPeriod ASC,addTime DESC';
  321. }
  322. if ($where['status'] == 1) {
  323. $order = 'hasReachTime DESC,reachDate DESC,reachPeriod DESC,addTime DESC';
  324. }
  325. }
  326. $data = self::getList('*', $where, $order);
  327. $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
  328. if (empty($list)) {
  329. return $data;
  330. }
  331. $data['list'] = self::groupBaseInfo($list);
  332. return $data;
  333. }
  334. public static function groupBaseInfo($list)
  335. {
  336. if (empty($list)) {
  337. return $list;
  338. }
  339. $today = date("Y-m-d");
  340. $tomorrow = date("Y-m-d", strtotime('+1 day'));
  341. foreach ($list as $key => $val) {
  342. $shortCover = $val['cover'] ?? '';
  343. $cover = imgUtil::getPrefix() . 'hhb_small.png';
  344. $bigCover = imgUtil::getPrefix() . 'hhb_small.png';
  345. if (!empty($shortCover)) {
  346. $parse = parse_url(self::groupImg($shortCover));
  347. if (empty($parse['query'])) {
  348. $cover = self::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_110,w_110";
  349. } else {
  350. $cover = self::groupImg($shortCover);
  351. }
  352. $bigCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  353. }
  354. $list[$key]['cover'] = $cover;
  355. $list[$key]['bigCover'] = $bigCover;
  356. $list[$key]['shortCover'] = $shortCover;
  357. $list[$key]['today'] = $today;
  358. $list[$key]['tomorrow'] = $tomorrow;
  359. }
  360. return $list;
  361. }
  362. }