WorkController.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. $connection = Yii::$app->db;
  49. $transaction = $connection->beginTransaction();
  50. try {
  51. $product = $post['product'] ?? '';
  52. $post['product'] = [];
  53. if (!empty($product)) {
  54. $arr = json_decode($product, true);
  55. if (!empty($arr)) {
  56. $post['product'] = $arr;
  57. }
  58. }
  59. WorkService::createFinish($post);
  60. $transaction->commit();
  61. util::complete();
  62. } catch (\Exception $e) {
  63. $transaction->rollBack();
  64. Yii::error("失败原因:" . $e->getMessage());
  65. util::fail('操作失败');
  66. }
  67. }
  68. //成品新建制作 ssh 20220320
  69. public function actionGoodsCreate()
  70. {
  71. $post = Yii::$app->request->post();
  72. $post['mainId'] = $this->mainId ?? 0;
  73. $post['sjId'] = $this->sjId ?? 0;
  74. $post['shopId'] = $this->shopId ?? 0;
  75. $connection = Yii::$app->db;
  76. $transaction = $connection->beginTransaction();
  77. try {
  78. WorkService::GoodsCreateFinish($post);
  79. $transaction->commit();
  80. util::complete();
  81. } catch (\Exception $e) {
  82. $transaction->rollBack();
  83. Yii::error("失败原因:" . $e->getMessage());
  84. util::fail('操作失败');
  85. }
  86. }
  87. //包括工单和用材信息 ssh 20220319
  88. public function actionFullInfo()
  89. {
  90. $get = Yii::$app->request->get();
  91. $id = $get['id'] ?? 0;
  92. $work = WorkClass::getById($id, true);
  93. WorkClass::valid($work, $this->mainId);
  94. $workItem = WorkItemClass::getWorkAllItem($work);
  95. $goods = [];
  96. $goodsId = $work->goodsId ?? 0;
  97. if (!empty($goodsId)) {
  98. $goods = GoodsClass::getGoodsInfo($goodsId);
  99. }
  100. $work = $work->attributes;
  101. $shortCover = $work['cover'] ?? '';
  102. $work['shortCover'] = $shortCover;
  103. $work['cover'] = imgUtil::groupImg($shortCover);
  104. util::success(['info' => $work, 'item' => $workItem, 'goods' => $goods]);
  105. }
  106. //取消 ssh 20220320
  107. public function actionCancel()
  108. {
  109. $get = Yii::$app->request->get();
  110. $id = $get['id'] ?? 0;
  111. $work = WorkClass::getById($id, true);
  112. WorkClass::valid($work, $this->mainId);
  113. WorkClass::cancel($work);
  114. util::complete();
  115. }
  116. //完成工单 ssh 20220319
  117. public function actionFinish()
  118. {
  119. $post = Yii::$app->request->post();
  120. $workId = $post['id'] ?? 0;
  121. $connection = Yii::$app->db;//事务处理
  122. $transaction = $connection->beginTransaction();
  123. try {
  124. $work = WorkClass::getById($workId, true);
  125. WorkClass::valid($work, $this->mainId);
  126. if ($work->status == 1) {
  127. util::fail('工单已完成');
  128. }
  129. if ($work->status == 2) {
  130. util::fail('工单已取消');
  131. }
  132. //花材未锁定,需要锁定并扣库存
  133. if ($work->stockLock == 0) {
  134. WorkClass::lock($work);
  135. }
  136. WorkClass::finish($work);
  137. $transaction->commit();
  138. util::complete();
  139. } catch (\Exception $e) {
  140. $transaction->rollBack();
  141. Yii::error("失败原因:" . $e->getMessage());
  142. util::fail('操作失败');
  143. }
  144. }
  145. //打印
  146. public function actionPrint()
  147. {
  148. util::complete();
  149. }
  150. }