WorkController.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. WorkService::GoodsCreateFinish($post);
  88. $transaction->commit();
  89. util::complete();
  90. } catch (\Exception $e) {
  91. $transaction->rollBack();
  92. Yii::error("失败原因:" . $e->getMessage());
  93. util::fail('操作失败');
  94. }
  95. }
  96. //包括工单和用材信息 ssh 20220319
  97. public function actionFullInfo()
  98. {
  99. $get = Yii::$app->request->get();
  100. $id = $get['id'] ?? 0;
  101. $work = WorkClass::getById($id, true);
  102. WorkClass::valid($work, $this->mainId);
  103. $workItem = WorkItemClass::getWorkAllItem($work);
  104. $goods = [];
  105. $goodsId = $work->goodsId ?? 0;
  106. if (!empty($goodsId)) {
  107. $goods = GoodsClass::getGoodsInfo($goodsId);
  108. }
  109. $work = $work->attributes;
  110. $shortCover = $work['cover'] ?? '';
  111. $work['shortCover'] = $shortCover;
  112. $work['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  113. $work['bigCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  114. $work['smallCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  115. util::success(['info' => $work, 'item' => $workItem, 'goods' => $goods]);
  116. }
  117. //取消 ssh 20220320
  118. public function actionCancel()
  119. {
  120. $get = Yii::$app->request->get();
  121. $id = $get['id'] ?? 0;
  122. $work = WorkClass::getById($id, true);
  123. WorkClass::valid($work, $this->mainId);
  124. WorkClass::cancel($work);
  125. util::complete();
  126. }
  127. //完成工单 ssh 20220319
  128. public function actionFinish()
  129. {
  130. $post = Yii::$app->request->post();
  131. $workId = $post['id'] ?? 0;
  132. $connection = Yii::$app->db;//事务处理
  133. $transaction = $connection->beginTransaction();
  134. try {
  135. $work = WorkClass::getById($workId, true);
  136. WorkClass::valid($work, $this->mainId);
  137. if ($work->status == 1) {
  138. util::fail('工单已完成');
  139. }
  140. if ($work->status == 2) {
  141. util::fail('工单已取消');
  142. }
  143. //花材未锁定,需要锁定并扣库存
  144. if ($work->stockLock == 0) {
  145. WorkClass::lock($work);
  146. }
  147. WorkClass::finish($work);
  148. $transaction->commit();
  149. util::complete();
  150. } catch (\Exception $e) {
  151. $transaction->rollBack();
  152. Yii::error("失败原因:" . $e->getMessage());
  153. util::fail('操作失败');
  154. }
  155. }
  156. //打印
  157. public function actionPrint()
  158. {
  159. util::complete();
  160. }
  161. }