WorkController.php 6.4 KB

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