WorkController.php 6.8 KB

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