WorkController.php 4.7 KB

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