WorkController.php 6.0 KB

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