WorkController.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\goods\classes\CategoryClass;
  4. use bizHd\goods\classes\GoodsClass;
  5. use bizHd\work\classes\WorkClass;
  6. use bizHd\work\classes\WorkItemClass;
  7. use bizHd\work\services\WorkService;
  8. use common\components\imgUtil;
  9. use common\components\orderSn;
  10. use common\components\util;
  11. use Yii;
  12. class WorkController extends BaseController
  13. {
  14. public $guestAccess = [];
  15. //工单列表 ssh 20220319
  16. public function actionList()
  17. {
  18. $get = Yii::$app->request->get();
  19. $where = [];
  20. $where['mainId'] = $this->mainId;
  21. if (isset($get['status']) && $get['status'] >= 0) {
  22. $status = $get['status'];
  23. $where['status'] = $status;
  24. }
  25. $list = WorkClass::getWorkList($where);
  26. util::success($list);
  27. }
  28. //锁定用材 ssh 20220320
  29. public function actionLock()
  30. {
  31. $get = Yii::$app->request->get();
  32. $id = $get['id'] ?? 0;
  33. $work = WorkClass::getById($id, true);
  34. WorkClass::valid($work, $this->mainId);
  35. WorkItemClass::lock($work);
  36. util::complete();
  37. }
  38. //新建工单 ssh 20220319
  39. public function actionCreate()
  40. {
  41. $post = Yii::$app->request->post();
  42. $post['mainId'] = $this->mainId ?? 0;
  43. $post['sjId'] = $this->sjId ?? 0;
  44. $post['shopId'] = $this->shopId ?? 0;
  45. $orderSn = orderSn::getWorkSn();
  46. $post['workSn'] = $orderSn;
  47. $post['staffId'] = $this->shopAdminId;
  48. $post['staffName'] = $this->shopAdmin->name;
  49. $post['name'] = isset($post['name']) && !empty($post['name']) ? $post['name'] : '花束';
  50. $connection = Yii::$app->db;
  51. $transaction = $connection->beginTransaction();
  52. try {
  53. $product = $post['product'] ?? '';
  54. $post['product'] = [];
  55. if (!empty($product)) {
  56. $arr = json_decode($product, true);
  57. if (!empty($arr)) {
  58. $post['product'] = $arr;
  59. }
  60. }
  61. $post['num'] = isset($post['num']) && $post['num'] > 0 ? $post['num'] : 1;
  62. $catId = $post['catId'] ?? 0;
  63. $cat = CategoryClass::getById($catId, true);
  64. if ($cat->mainId != $this->mainId) {
  65. util::fail('请选择你自己的分类');
  66. }
  67. $post['catName'] = $cat->categoryName ?? '';
  68. $work = WorkService::createFinish($post);
  69. $transaction->commit();
  70. util::success($work);
  71. } catch (\Exception $e) {
  72. $transaction->rollBack();
  73. Yii::error("失败原因:" . $e->getMessage());
  74. util::fail('操作失败');
  75. }
  76. }
  77. //成品新建制作 ssh 20220320
  78. public function actionGoodsCreate()
  79. {
  80. $post = Yii::$app->request->post();
  81. $post['mainId'] = $this->mainId ?? 0;
  82. $post['sjId'] = $this->sjId ?? 0;
  83. $post['shopId'] = $this->shopId ?? 0;
  84. $connection = Yii::$app->db;
  85. $transaction = $connection->beginTransaction();
  86. try {
  87. $goodsJson = $post['goods'] ?? '';
  88. $goods = json_decode($goodsJson, true);
  89. if (empty($goods)) {
  90. util::fail('没有找到成品');
  91. }
  92. $post['goods'] = $goods;
  93. $work = WorkClass::goodsCreateFinish($post);
  94. $transaction->commit();
  95. util::success(['work' => $work]);
  96. } catch (\Exception $e) {
  97. $transaction->rollBack();
  98. Yii::error("失败原因:" . $e->getMessage());
  99. util::fail('操作失败');
  100. }
  101. }
  102. //包括工单和用材信息 ssh 20220319
  103. public function actionFullInfo()
  104. {
  105. $get = Yii::$app->request->get();
  106. $id = $get['id'] ?? 0;
  107. $work = WorkClass::getById($id, true);
  108. WorkClass::valid($work, $this->mainId);
  109. $workItem = WorkItemClass::getWorkAllItem($work);
  110. $goods = [];
  111. $goodsId = $work->goodsId ?? 0;
  112. if (!empty($goodsId)) {
  113. $goods = GoodsClass::getGoodsInfo($goodsId);
  114. }
  115. $work = $work->attributes;
  116. $shortCover = $work['cover'] ?? '';
  117. $work['shortCover'] = $shortCover;
  118. $work['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  119. $work['bigCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  120. $work['smallCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  121. util::success(['info' => $work, 'item' => $workItem, 'goods' => $goods]);
  122. }
  123. //取消 ssh 20220320
  124. public function actionCancel()
  125. {
  126. $get = Yii::$app->request->get();
  127. $id = $get['id'] ?? 0;
  128. $work = WorkClass::getById($id, true);
  129. WorkClass::valid($work, $this->mainId);
  130. WorkClass::cancel($work);
  131. util::complete();
  132. }
  133. //完成工单 ssh 20220319
  134. public function actionFinish()
  135. {
  136. $post = Yii::$app->request->post();
  137. $workId = $post['id'] ?? 0;
  138. $connection = Yii::$app->db;//事务处理
  139. $transaction = $connection->beginTransaction();
  140. try {
  141. $work = WorkClass::getById($workId, true);
  142. WorkClass::valid($work, $this->mainId);
  143. if ($work->status == 1) {
  144. util::fail('工单已完成');
  145. }
  146. if ($work->status == 2) {
  147. util::fail('工单已取消');
  148. }
  149. //花材未锁定,需要锁定并扣库存
  150. if ($work->stockLock == 0) {
  151. WorkClass::lock($work);
  152. }
  153. WorkClass::finish($work);
  154. $transaction->commit();
  155. util::complete();
  156. } catch (\Exception $e) {
  157. $transaction->rollBack();
  158. Yii::error("失败原因:" . $e->getMessage());
  159. util::fail('操作失败');
  160. }
  161. }
  162. //打印
  163. public function actionPrint()
  164. {
  165. util::complete();
  166. }
  167. }