WorkController.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php
  2. namespace hd\controllers;
  3. use biz\shop\classes\ShopExtClass;
  4. use bizHd\goods\classes\CategoryClass;
  5. use bizHd\goods\classes\GoodsClass;
  6. use bizHd\order\classes\OrderClass;
  7. use bizHd\work\classes\WorkClass;
  8. use bizHd\work\classes\WorkItemClass;
  9. use common\components\dict;
  10. use common\components\imgUtil;
  11. use common\components\orderSn;
  12. use common\components\util;
  13. use Yii;
  14. class WorkController extends BaseController
  15. {
  16. public $guestAccess = [];
  17. //根据订单id查询制作单信息 ssh 20220625
  18. public function actionGetInfoByOrderId()
  19. {
  20. $orderId = Yii::$app->request->get('orderId', 0);
  21. $order = OrderClass::getById($orderId, true);
  22. OrderClass::valid($order, $this->mainId);
  23. $info = WorkClass::getByCondition(['orderId' => $orderId], true);
  24. if (empty($info)) {
  25. util::fail('没有找到');
  26. }
  27. util::success(['info' => $info]);
  28. }
  29. //打印制作单 ssh 20220601
  30. public function actionPrint()
  31. {
  32. $get = Yii::$app->request->get();
  33. $id = $get['id'] ?? 0;
  34. $work = WorkClass::getById($id, true);
  35. WorkClass::valid($work, $this->mainId);
  36. WorkClass::print($work, $this->shop);
  37. util::complete();
  38. }
  39. //制作单列表 ssh 20220319
  40. public function actionList()
  41. {
  42. $get = Yii::$app->request->get();
  43. $where = [];
  44. $where['mainId'] = $this->mainId;
  45. if (isset($get['status']) && $get['status'] >= 0) {
  46. $status = $get['status'];
  47. $where['status'] = $status;
  48. }
  49. if (isset($get['fromType']) && is_numeric($get['fromType'])) {
  50. $where['fromType'] = $get['fromType'];
  51. } else {
  52. $shopId = $this->shopId;
  53. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  54. $mtAlone = $ext->mtAlone ?? 0;
  55. $isCashier = $get['isCashier'] ?? 0;
  56. if ($mtAlone == 1 && $isCashier == 1) {
  57. $where['fromType'] = ['in', [1, 2, 3]];
  58. }
  59. }
  60. if (isset($get['sn']) && !empty($get['sn']) && is_numeric($get['sn'])) {
  61. $where['sn'] = $get['sn'];
  62. }
  63. if (isset($get['thirdSn']) && !empty($get['thirdSn']) && is_numeric($get['thirdSn'])) {
  64. $where['thirdSn'] = $get['thirdSn'];
  65. }
  66. $list = WorkClass::getWorkList($where);
  67. $list['today'] = date("Y-m-d");
  68. util::success($list);
  69. }
  70. //锁定用材 ssh 20220320
  71. public function actionLock()
  72. {
  73. $get = Yii::$app->request->get();
  74. $id = $get['id'] ?? 0;
  75. $work = WorkClass::getById($id, true);
  76. WorkClass::valid($work, $this->mainId);
  77. WorkItemClass::lock($work);
  78. util::complete();
  79. }
  80. //新建制作单 ssh 20220319
  81. public function actionCreate()
  82. {
  83. $post = Yii::$app->request->post();
  84. $post['mainId'] = $this->mainId ?? 0;
  85. $post['sjId'] = $this->sjId ?? 0;
  86. $post['shopId'] = $this->shopId ?? 0;
  87. $orderSn = orderSn::getWorkSn();
  88. $post['workSn'] = $orderSn;
  89. $post['staffId'] = $this->shopAdminId;
  90. $post['staffName'] = $this->shopAdmin->name;
  91. $post['name'] = isset($post['name']) && !empty($post['name']) ? $post['name'] : '花束';
  92. $post['cover'] = isset($post['cover']) && !empty($post['cover']) ? $post['cover'] : 'default-img.png';
  93. $connection = Yii::$app->db;
  94. $transaction = $connection->beginTransaction();
  95. try {
  96. $product = $post['product'] ?? '';
  97. $post['product'] = [];
  98. if (!empty($product)) {
  99. $arr = json_decode($product, true);
  100. if (!empty($arr)) {
  101. $post['product'] = $arr;
  102. }
  103. }
  104. $post['num'] = isset($post['num']) && $post['num'] > 0 ? $post['num'] : 1;
  105. $catId = $post['catId'] ?? 0;
  106. $cat = CategoryClass::getById($catId, true);
  107. if ($cat->mainId != $this->mainId) {
  108. util::fail('请选择你自己的分类');
  109. }
  110. $post['catName'] = $cat->categoryName ?? '';
  111. $main = $this->main;
  112. $work = WorkClass::createFinish($post, $main);
  113. $transaction->commit();
  114. $complete = $post['complete'] ?? 0;
  115. if ($complete == 1) {
  116. WorkClass::print($work, $this->shop, false);
  117. }
  118. util::success($work);
  119. } catch (\Exception $e) {
  120. $transaction->rollBack();
  121. Yii::error("失败原因:" . $e->getMessage());
  122. util::fail('操作失败');
  123. }
  124. }
  125. //商品新建制作 ssh 20220320
  126. public function actionGoodsCreate()
  127. {
  128. $post = Yii::$app->request->post();
  129. $post['mainId'] = $this->mainId ?? 0;
  130. $post['sjId'] = $this->sjId ?? 0;
  131. $post['shopId'] = $this->shopId ?? 0;
  132. $connection = Yii::$app->db;
  133. $transaction = $connection->beginTransaction();
  134. try {
  135. $goodsJson = $post['goods'] ?? '';
  136. $goods = json_decode($goodsJson, true);
  137. if (empty($goods)) {
  138. util::fail('没有找到商品');
  139. }
  140. $post['goods'] = $goods;
  141. $main = $this->main;
  142. WorkClass::goodsCreateFinish($post, $main);
  143. $transaction->commit();
  144. util::complete();
  145. } catch (\Exception $e) {
  146. $transaction->rollBack();
  147. Yii::error("失败原因:" . $e->getMessage());
  148. util::fail('操作失败');
  149. }
  150. }
  151. //包括制作单和用材信息 ssh 20220319
  152. public function actionFullInfo()
  153. {
  154. $get = Yii::$app->request->get();
  155. $id = $get['id'] ?? 0;
  156. $work = WorkClass::getById($id, true);
  157. WorkClass::valid($work, $this->mainId);
  158. $workItem = WorkItemClass::getWorkAllItem($work);
  159. $goods = [];
  160. $goodsId = $work->goodsId ?? 0;
  161. if (!empty($goodsId)) {
  162. $goods = GoodsClass::getGoodsInfo($goodsId);
  163. }
  164. $work = $work->attributes;
  165. $shortCover = $work['cover'] ?? '';
  166. $work['shortCover'] = $shortCover;
  167. $work['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  168. $work['bigCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  169. $work['smallCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  170. $today = date("Y-m-d");
  171. util::success(['info' => $work, 'item' => $workItem, 'goods' => $goods, 'today' => $today]);
  172. }
  173. //取消 ssh 20220320
  174. public function actionCancel()
  175. {
  176. $get = Yii::$app->request->get();
  177. $id = $get['id'] ?? 0;
  178. $work = WorkClass::getById($id, true);
  179. WorkClass::valid($work, $this->mainId);
  180. WorkClass::cancel($work);
  181. util::complete();
  182. }
  183. //完成制作单 ssh 20220319
  184. public function actionFinish()
  185. {
  186. $post = Yii::$app->request->post();
  187. $workId = $post['id'] ?? 0;
  188. $connection = Yii::$app->db;//事务处理
  189. $transaction = $connection->beginTransaction();
  190. try {
  191. $work = WorkClass::getById($workId, true);
  192. WorkClass::valid($work, $this->mainId);
  193. if ($work->status == 1) {
  194. util::fail('制作单已完成');
  195. }
  196. if ($work->status == 2) {
  197. util::fail('制作单已取消');
  198. }
  199. //花材未锁定,需要锁定并扣库存
  200. if ($work->stockLock == 0) {
  201. $itemList = $post['itemList'] ?? '';
  202. if (!empty($itemList)) {
  203. $product = json_decode($itemList, true);
  204. if (!empty($product)) {
  205. WorkItemClass::modifyItem($work, $product);
  206. WorkItemClass::lock($work);
  207. }
  208. }
  209. }
  210. WorkClass::finish($work);
  211. $transaction->commit();
  212. WorkClass::print($work, $this->shop, false);
  213. util::complete();
  214. } catch (\Exception $e) {
  215. $transaction->rollBack();
  216. Yii::error("失败原因:" . $e->getMessage());
  217. util::fail('操作失败');
  218. }
  219. }
  220. }