WorkController.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. if ($mtAlone == 1) {
  56. $where['fromType'] = ['in', [1, 2, 3]];
  57. }
  58. }
  59. if (isset($get['sn']) && !empty($get['sn']) && is_numeric($get['sn'])) {
  60. $where['sn'] = $get['sn'];
  61. }
  62. if (isset($get['thirdSn']) && !empty($get['thirdSn']) && is_numeric($get['thirdSn'])) {
  63. $where['thirdSn'] = $get['thirdSn'];
  64. }
  65. $list = WorkClass::getWorkList($where);
  66. $list['today'] = date("Y-m-d");
  67. util::success($list);
  68. }
  69. //锁定用材 ssh 20220320
  70. public function actionLock()
  71. {
  72. $get = Yii::$app->request->get();
  73. $id = $get['id'] ?? 0;
  74. $work = WorkClass::getById($id, true);
  75. WorkClass::valid($work, $this->mainId);
  76. WorkItemClass::lock($work);
  77. util::complete();
  78. }
  79. //新建制作单 ssh 20220319
  80. public function actionCreate()
  81. {
  82. $post = Yii::$app->request->post();
  83. $post['mainId'] = $this->mainId ?? 0;
  84. $post['sjId'] = $this->sjId ?? 0;
  85. $post['shopId'] = $this->shopId ?? 0;
  86. $orderSn = orderSn::getWorkSn();
  87. $post['workSn'] = $orderSn;
  88. $post['staffId'] = $this->shopAdminId;
  89. $post['staffName'] = $this->shopAdmin->name;
  90. $post['name'] = isset($post['name']) && !empty($post['name']) ? $post['name'] : '花束';
  91. $post['cover'] = isset($post['cover']) && !empty($post['cover']) ? $post['cover'] : 'default-img.png';
  92. $connection = Yii::$app->db;
  93. $transaction = $connection->beginTransaction();
  94. try {
  95. $product = $post['product'] ?? '';
  96. $post['product'] = [];
  97. if (!empty($product)) {
  98. $arr = json_decode($product, true);
  99. if (!empty($arr)) {
  100. $post['product'] = $arr;
  101. }
  102. }
  103. $post['num'] = isset($post['num']) && $post['num'] > 0 ? $post['num'] : 1;
  104. $catId = $post['catId'] ?? 0;
  105. $cat = CategoryClass::getById($catId, true);
  106. if ($cat->mainId != $this->mainId) {
  107. util::fail('请选择你自己的分类');
  108. }
  109. $post['catName'] = $cat->categoryName ?? '';
  110. $main = $this->main;
  111. $work = WorkClass::createFinish($post, $main);
  112. $transaction->commit();
  113. $complete = $post['complete'] ?? 0;
  114. if ($complete == 1) {
  115. WorkClass::print($work, $this->shop, false);
  116. }
  117. util::success($work);
  118. } catch (\Exception $e) {
  119. $transaction->rollBack();
  120. Yii::error("失败原因:" . $e->getMessage());
  121. util::fail('操作失败');
  122. }
  123. }
  124. //商品新建制作 ssh 20220320
  125. public function actionGoodsCreate()
  126. {
  127. $post = Yii::$app->request->post();
  128. $post['mainId'] = $this->mainId ?? 0;
  129. $post['sjId'] = $this->sjId ?? 0;
  130. $post['shopId'] = $this->shopId ?? 0;
  131. $connection = Yii::$app->db;
  132. $transaction = $connection->beginTransaction();
  133. try {
  134. $goodsJson = $post['goods'] ?? '';
  135. $goods = json_decode($goodsJson, true);
  136. if (empty($goods)) {
  137. util::fail('没有找到商品');
  138. }
  139. $post['goods'] = $goods;
  140. $main = $this->main;
  141. WorkClass::goodsCreateFinish($post, $main);
  142. $transaction->commit();
  143. util::complete();
  144. } catch (\Exception $e) {
  145. $transaction->rollBack();
  146. Yii::error("失败原因:" . $e->getMessage());
  147. util::fail('操作失败');
  148. }
  149. }
  150. //包括制作单和用材信息 ssh 20220319
  151. public function actionFullInfo()
  152. {
  153. $get = Yii::$app->request->get();
  154. $id = $get['id'] ?? 0;
  155. $work = WorkClass::getById($id, true);
  156. WorkClass::valid($work, $this->mainId);
  157. $workItem = WorkItemClass::getWorkAllItem($work);
  158. $goods = [];
  159. $goodsId = $work->goodsId ?? 0;
  160. if (!empty($goodsId)) {
  161. $goods = GoodsClass::getGoodsInfo($goodsId);
  162. }
  163. $work = $work->attributes;
  164. $shortCover = $work['cover'] ?? '';
  165. $work['shortCover'] = $shortCover;
  166. $work['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  167. $work['bigCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  168. $work['smallCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  169. $today = date("Y-m-d");
  170. util::success(['info' => $work, 'item' => $workItem, 'goods' => $goods, 'today' => $today]);
  171. }
  172. //取消 ssh 20220320
  173. public function actionCancel()
  174. {
  175. $get = Yii::$app->request->get();
  176. $id = $get['id'] ?? 0;
  177. $work = WorkClass::getById($id, true);
  178. WorkClass::valid($work, $this->mainId);
  179. WorkClass::cancel($work);
  180. util::complete();
  181. }
  182. //完成制作单 ssh 20220319
  183. public function actionFinish()
  184. {
  185. $post = Yii::$app->request->post();
  186. $workId = $post['id'] ?? 0;
  187. $connection = Yii::$app->db;//事务处理
  188. $transaction = $connection->beginTransaction();
  189. try {
  190. $work = WorkClass::getById($workId, true);
  191. WorkClass::valid($work, $this->mainId);
  192. if ($work->status == 1) {
  193. util::fail('制作单已完成');
  194. }
  195. if ($work->status == 2) {
  196. util::fail('制作单已取消');
  197. }
  198. //花材未锁定,需要锁定并扣库存
  199. if ($work->stockLock == 0) {
  200. $itemList = $post['itemList'] ?? '';
  201. if (!empty($itemList)) {
  202. $product = json_decode($itemList, true);
  203. if (!empty($product)) {
  204. WorkItemClass::modifyItem($work, $product);
  205. WorkItemClass::lock($work);
  206. }
  207. }
  208. }
  209. WorkClass::finish($work);
  210. $transaction->commit();
  211. WorkClass::print($work, $this->shop, false);
  212. util::complete();
  213. } catch (\Exception $e) {
  214. $transaction->rollBack();
  215. Yii::error("失败原因:" . $e->getMessage());
  216. util::fail('操作失败');
  217. }
  218. }
  219. }