WorkController.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\goods\classes\CategoryClass;
  4. use bizHd\goods\classes\GoodsClass;
  5. use bizHd\order\classes\OrderClass;
  6. use bizHd\work\classes\WorkClass;
  7. use bizHd\work\classes\WorkItemClass;
  8. use common\components\dict;
  9. use common\components\imgUtil;
  10. use common\components\orderSn;
  11. use common\components\util;
  12. use Yii;
  13. class WorkController extends BaseController
  14. {
  15. public $guestAccess = [];
  16. //根据订单id查询制作单信息 ssh 20220625
  17. public function actionGetInfoByOrderId()
  18. {
  19. $orderId = Yii::$app->request->get('orderId', 0);
  20. $order = OrderClass::getById($orderId, true);
  21. OrderClass::valid($order, $this->mainId);
  22. $info = WorkClass::getByCondition(['orderId' => $orderId], true);
  23. if (empty($info)) {
  24. util::fail('没有找到');
  25. }
  26. util::success(['info' => $info]);
  27. }
  28. //打印制作单 ssh 20220601
  29. public function actionPrint()
  30. {
  31. $get = Yii::$app->request->get();
  32. $id = $get['id'] ?? 0;
  33. $work = WorkClass::getById($id, true);
  34. WorkClass::valid($work, $this->mainId);
  35. WorkClass::print($work, $this->shop);
  36. util::complete();
  37. }
  38. //制作单列表 ssh 20220319
  39. public function actionList()
  40. {
  41. $get = Yii::$app->request->get();
  42. $where = [];
  43. $where['mainId'] = $this->mainId;
  44. if (isset($get['status']) && $get['status'] >= 0) {
  45. $status = $get['status'];
  46. $where['status'] = $status;
  47. }
  48. if (isset($get['fromType']) && is_numeric($get['fromType'])) {
  49. $where['fromType'] = $get['fromType'];
  50. }
  51. if (isset($get['searchType'])) {
  52. if ($get['searchType'] == 0) {
  53. util::fail('暂不支持名称搜索');
  54. } elseif ($get['searchType'] == 1) {
  55. if (!empty($get['name'])) {
  56. if (!is_numeric($get['name'])) {
  57. util::fail('编号必须是数字');
  58. }
  59. $where['sn'] = $get['name'];
  60. }
  61. }
  62. }
  63. if (isset($get['sn']) && !empty($get['sn']) && is_numeric($get['sn'])) {
  64. $where['sn'] = $get['sn'];
  65. }
  66. if (isset($get['thirdSn']) && !empty($get['thirdSn']) && is_numeric($get['thirdSn'])) {
  67. $where['thirdSn'] = $get['thirdSn'];
  68. }
  69. $list = WorkClass::getWorkList($where);
  70. $list['today'] = date("Y-m-d");
  71. util::success($list);
  72. }
  73. //锁定用材 ssh 20220320
  74. public function actionLock()
  75. {
  76. $get = Yii::$app->request->get();
  77. $id = $get['id'] ?? 0;
  78. $work = WorkClass::getById($id, true);
  79. WorkClass::valid($work, $this->mainId);
  80. WorkItemClass::lock($work);
  81. util::complete();
  82. }
  83. //新建制作单 ssh 20220319
  84. public function actionCreate()
  85. {
  86. $post = Yii::$app->request->post();
  87. $post['mainId'] = $this->mainId ?? 0;
  88. $post['sjId'] = $this->sjId ?? 0;
  89. $post['shopId'] = $this->shopId ?? 0;
  90. $orderSn = orderSn::getWorkSn();
  91. $post['workSn'] = $orderSn;
  92. $post['staffId'] = $this->shopAdminId;
  93. $post['staffName'] = $this->shopAdmin->name;
  94. $post['name'] = isset($post['name']) && !empty($post['name']) ? $post['name'] : '花束';
  95. $post['cover'] = isset($post['cover']) && !empty($post['cover']) ? $post['cover'] : 'default-img.png';
  96. $connection = Yii::$app->db;
  97. $transaction = $connection->beginTransaction();
  98. try {
  99. $product = $post['product'] ?? '';
  100. $post['product'] = [];
  101. if (!empty($product)) {
  102. $arr = json_decode($product, true);
  103. if (!empty($arr)) {
  104. $post['product'] = $arr;
  105. }
  106. }
  107. $post['num'] = isset($post['num']) && $post['num'] > 0 ? $post['num'] : 1;
  108. $catId = $post['catId'] ?? 0;
  109. $cat = CategoryClass::getById($catId, true);
  110. if ($cat->mainId != $this->mainId) {
  111. util::fail('请选择你自己的分类');
  112. }
  113. $post['catName'] = $cat->categoryName ?? '';
  114. $main = $this->main;
  115. $work = WorkClass::createFinish($post, $main);
  116. $transaction->commit();
  117. $complete = $post['complete'] ?? 0;
  118. if ($complete == 1) {
  119. WorkClass::print($work, $this->shop, false);
  120. }
  121. util::success($work);
  122. } catch (\Exception $e) {
  123. $transaction->rollBack();
  124. Yii::error("失败原因:" . $e->getMessage());
  125. util::fail('操作失败');
  126. }
  127. }
  128. //商品新建制作 ssh 20220320
  129. public function actionGoodsCreate()
  130. {
  131. $post = Yii::$app->request->post();
  132. $post['mainId'] = $this->mainId ?? 0;
  133. $post['sjId'] = $this->sjId ?? 0;
  134. $post['shopId'] = $this->shopId ?? 0;
  135. $connection = Yii::$app->db;
  136. $transaction = $connection->beginTransaction();
  137. try {
  138. $goodsJson = $post['goods'] ?? '';
  139. $goods = json_decode($goodsJson, true);
  140. if (empty($goods)) {
  141. util::fail('没有找到商品');
  142. }
  143. $post['goods'] = $goods;
  144. $main = $this->main;
  145. WorkClass::goodsCreateFinish($post, $main);
  146. $transaction->commit();
  147. util::complete();
  148. } catch (\Exception $e) {
  149. $transaction->rollBack();
  150. Yii::error("失败原因:" . $e->getMessage());
  151. util::fail('操作失败');
  152. }
  153. }
  154. //包括制作单和用材信息 ssh 20220319
  155. public function actionFullInfo()
  156. {
  157. $get = Yii::$app->request->get();
  158. $id = $get['id'] ?? 0;
  159. $work = WorkClass::getById($id, true);
  160. WorkClass::valid($work, $this->mainId);
  161. $workItem = WorkItemClass::getWorkAllItem($work);
  162. $goods = [];
  163. $goodsId = $work->goodsId ?? 0;
  164. if (!empty($goodsId)) {
  165. $goods = GoodsClass::getGoodsInfo($goodsId);
  166. }
  167. $work = $work->attributes;
  168. $shortCover = $work['cover'] ?? '';
  169. $work['shortCover'] = $shortCover;
  170. $work['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  171. $work['bigCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  172. $work['smallCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  173. $today = date("Y-m-d");
  174. util::success(['info' => $work, 'item' => $workItem, 'goods' => $goods, 'today' => $today]);
  175. }
  176. //取消 ssh 20220320
  177. public function actionCancel()
  178. {
  179. $get = Yii::$app->request->get();
  180. $id = $get['id'] ?? 0;
  181. $work = WorkClass::getById($id, true);
  182. WorkClass::valid($work, $this->mainId);
  183. WorkClass::cancel($work);
  184. util::complete();
  185. }
  186. //完成制作单 ssh 20220319
  187. public function actionFinish()
  188. {
  189. $post = Yii::$app->request->post();
  190. $workId = $post['id'] ?? 0;
  191. $connection = Yii::$app->db;//事务处理
  192. $transaction = $connection->beginTransaction();
  193. try {
  194. $work = WorkClass::getById($workId, true);
  195. WorkClass::valid($work, $this->mainId);
  196. if ($work->status == 1) {
  197. util::fail('制作单已完成');
  198. }
  199. if ($work->status == 2) {
  200. util::fail('制作单已取消');
  201. }
  202. //花材未锁定,需要锁定并扣库存
  203. if ($work->stockLock == 0) {
  204. $itemList = $post['itemList'] ?? '';
  205. if (!empty($itemList)) {
  206. $product = json_decode($itemList, true);
  207. if (!empty($product)) {
  208. WorkItemClass::modifyItem($work, $product);
  209. WorkItemClass::lock($work);
  210. }
  211. }
  212. }
  213. WorkClass::finish($work);
  214. $transaction->commit();
  215. WorkClass::print($work, $this->shop, false);
  216. util::complete();
  217. } catch (\Exception $e) {
  218. $transaction->rollBack();
  219. Yii::error("失败原因:" . $e->getMessage());
  220. util::fail('操作失败');
  221. }
  222. }
  223. }