WorkController.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. $work = WorkClass::createFinish($post, $main);
  81. $transaction->commit();
  82. WorkClass::print($work, $this->shop, false);
  83. util::success($work);
  84. } catch (\Exception $e) {
  85. $transaction->rollBack();
  86. Yii::error("失败原因:" . $e->getMessage());
  87. util::fail('操作失败');
  88. }
  89. }
  90. //商品新建制作 ssh 20220320
  91. public function actionGoodsCreate()
  92. {
  93. $post = Yii::$app->request->post();
  94. $post['mainId'] = $this->mainId ?? 0;
  95. $post['sjId'] = $this->sjId ?? 0;
  96. $post['shopId'] = $this->shopId ?? 0;
  97. $connection = Yii::$app->db;
  98. $transaction = $connection->beginTransaction();
  99. try {
  100. $goodsJson = $post['goods'] ?? '';
  101. $goods = json_decode($goodsJson, true);
  102. if (empty($goods)) {
  103. util::fail('没有找到商品');
  104. }
  105. $post['goods'] = $goods;
  106. $main = $this->main;
  107. WorkClass::goodsCreateFinish($post, $main);
  108. $transaction->commit();
  109. util::complete();
  110. } catch (\Exception $e) {
  111. $transaction->rollBack();
  112. Yii::error("失败原因:" . $e->getMessage());
  113. util::fail('操作失败');
  114. }
  115. }
  116. //包括制作单和用材信息 ssh 20220319
  117. public function actionFullInfo()
  118. {
  119. $get = Yii::$app->request->get();
  120. $id = $get['id'] ?? 0;
  121. $work = WorkClass::getById($id, true);
  122. WorkClass::valid($work, $this->mainId);
  123. $workItem = WorkItemClass::getWorkAllItem($work);
  124. $goods = [];
  125. $goodsId = $work->goodsId ?? 0;
  126. if (!empty($goodsId)) {
  127. $goods = GoodsClass::getGoodsInfo($goodsId);
  128. }
  129. $work = $work->attributes;
  130. $shortCover = $work['cover'] ?? '';
  131. $work['shortCover'] = $shortCover;
  132. $work['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  133. $work['bigCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  134. $work['smallCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  135. $today = date("Y-m-d");
  136. util::success(['info' => $work, 'item' => $workItem, 'goods' => $goods, 'today' => $today]);
  137. }
  138. //取消 ssh 20220320
  139. public function actionCancel()
  140. {
  141. $get = Yii::$app->request->get();
  142. $id = $get['id'] ?? 0;
  143. $work = WorkClass::getById($id, true);
  144. WorkClass::valid($work, $this->mainId);
  145. WorkClass::cancel($work);
  146. util::complete();
  147. }
  148. //完成制作单 ssh 20220319
  149. public function actionFinish()
  150. {
  151. $post = Yii::$app->request->post();
  152. $workId = $post['id'] ?? 0;
  153. $connection = Yii::$app->db;//事务处理
  154. $transaction = $connection->beginTransaction();
  155. try {
  156. $work = WorkClass::getById($workId, true);
  157. WorkClass::valid($work, $this->mainId);
  158. if ($work->status == 1) {
  159. util::fail('制作单已完成');
  160. }
  161. if ($work->status == 2) {
  162. util::fail('制作单已取消');
  163. }
  164. //花材未锁定,需要锁定并扣库存
  165. if ($work->stockLock == 0) {
  166. WorkClass::lock($work);
  167. }
  168. WorkClass::finish($work);
  169. $transaction->commit();
  170. util::complete();
  171. } catch (\Exception $e) {
  172. $transaction->rollBack();
  173. Yii::error("失败原因:" . $e->getMessage());
  174. util::fail('操作失败');
  175. }
  176. }
  177. }