WorkController.php 5.1 KB

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