WorkController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <?php
  2. namespace hd\controllers;
  3. use biz\shop\classes\ShopExtClass;
  4. use bizHd\goods\classes\CategoryClass;
  5. use bizHd\goods\classes\GoodsClass;
  6. use bizHd\order\classes\OrderClass;
  7. use bizHd\work\classes\WorkClass;
  8. use bizHd\work\classes\WorkItemClass;
  9. use common\components\dict;
  10. use common\components\imgUtil;
  11. use common\components\mtUtil;
  12. use common\components\orderSn;
  13. use common\components\util;
  14. use Shishaoqi\MeituanFlashPurchase\Application;
  15. use Yii;
  16. class WorkController extends BaseController
  17. {
  18. public $guestAccess = [];
  19. public function actionNeedWork()
  20. {
  21. $get = Yii::$app->request->get();
  22. $id = $get['id'] ?? 0;
  23. $order = OrderClass::getById($id, true);
  24. if (empty($order)) {
  25. util::fail('没有订单');
  26. }
  27. $mainId = $this->mainId;
  28. if ($order->mainId != $mainId) {
  29. util::fail('不是你的订单');
  30. }
  31. if ($order->hasWork == 1) {
  32. util::fail('已经通知制作了');
  33. }
  34. $main = $this->main;
  35. WorkClass::needWork($order, $main);
  36. $has = WorkClass::getByCondition(['orderId' => $id], true);
  37. if (!empty($has)) {
  38. $shopExt = ShopExtClass::getByCondition(['shopId' => $this->shopId], true);
  39. ShopExtClass::newWorkRemind($shopExt, $order);
  40. $order->hasWork = 1;
  41. $order->save();
  42. util::complete('通知成功');
  43. }
  44. util::fail('通知失败');
  45. }
  46. //根据订单id查询制作单信息 ssh 20220625
  47. public function actionGetInfoByOrderId()
  48. {
  49. $orderId = Yii::$app->request->get('orderId', 0);
  50. $order = OrderClass::getById($orderId, true);
  51. OrderClass::valid($order, $this->mainId);
  52. $info = WorkClass::getByCondition(['orderId' => $orderId], true);
  53. if (empty($info)) {
  54. util::fail('没有找到');
  55. }
  56. util::success(['info' => $info, 'order' => $order]);
  57. }
  58. //打印制作单 ssh 20220601
  59. public function actionPrint()
  60. {
  61. $get = Yii::$app->request->get();
  62. $id = $get['id'] ?? 0;
  63. $work = WorkClass::getById($id, true);
  64. WorkClass::valid($work, $this->mainId);
  65. WorkClass::print($work, $this->shop, true);
  66. util::complete();
  67. }
  68. //制作单列表 ssh 20220319
  69. public function actionList()
  70. {
  71. $get = Yii::$app->request->get();
  72. $where = [];
  73. $where['mainId'] = $this->mainId;
  74. $str = $get['sh'] ?? '';
  75. if ($str == 'yes') {
  76. $where['sh'] = 1;
  77. } else {
  78. $where['sh'] = 0;
  79. if (isset($get['fromType']) && is_numeric($get['fromType'])) {
  80. $where['fromType'] = $get['fromType'];
  81. } else {
  82. $shopId = $this->shopId;
  83. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  84. $mtAlone = $ext->mtAlone ?? 0;
  85. $isCashier = $get['isCashier'] ?? 0;
  86. if ($mtAlone == 1 && $isCashier == 1) {
  87. $where['fromType'] = ['in', [0, 1, 2, 3]];
  88. }
  89. }
  90. }
  91. if (isset($get['sendNum']) && !empty($get['sendNum']) && is_numeric($get['sendNum'])) {
  92. $where['sendNum'] = $get['sendNum'];
  93. }
  94. if (isset($get['thirdSn']) && !empty($get['thirdSn']) && is_numeric($get['thirdSn'])) {
  95. $where['thirdSn'] = $get['thirdSn'];
  96. }
  97. if (isset($get['status']) && $get['status'] >= 0) {
  98. $status = $get['status'];
  99. $where['status'] = $status;
  100. }
  101. $list = WorkClass::getWorkList($where);
  102. util::success($list);
  103. }
  104. //锁定用材 ssh 20220320
  105. public function actionLock()
  106. {
  107. $get = Yii::$app->request->get();
  108. $id = $get['id'] ?? 0;
  109. $work = WorkClass::getById($id, true);
  110. WorkClass::valid($work, $this->mainId);
  111. WorkItemClass::lock($work);
  112. util::complete();
  113. }
  114. //新建制作单 ssh 20220319
  115. public function actionCreate()
  116. {
  117. util::fail('请联系管理员');
  118. $post = Yii::$app->request->post();
  119. $post['mainId'] = $this->mainId ?? 0;
  120. $post['sjId'] = $this->sjId ?? 0;
  121. $post['shopId'] = $this->shopId ?? 0;
  122. $orderSn = orderSn::getWorkSn();
  123. $mainId = $this->mainId;
  124. $post['workSn'] = $orderSn;
  125. if (!empty($post['staffId'])) {
  126. $staffId = $post['staffId'];
  127. $staffName = $post['staffName'] ?? '';
  128. } else {
  129. $staffId = $this->shopAdminId;
  130. $staffName = $this->shopAdmin->name;
  131. }
  132. $post['staffId'] = $staffId;
  133. $post['staffName'] = $staffName;
  134. $post['name'] = !empty($post['name']) ? $post['name'] : '花束';
  135. $post['cover'] = !empty($post['cover']) ? $post['cover'] : 'default-img.png';
  136. $post['reachDate'] = date("Y-m-d");
  137. $connection = Yii::$app->db;
  138. $transaction = $connection->beginTransaction();
  139. try {
  140. //去掉花束所用的花材,没有意义,不考虑花束用了多少花材
  141. $post['product'] = [];
  142. $post['num'] = isset($post['num']) && $post['num'] > 0 ? $post['num'] : 1;
  143. $default = CategoryClass::getByCondition(['mainId' => $mainId, 'flower' => 1, 'default' => 1], true);
  144. if (empty($default)) {
  145. $catData = [
  146. 'mainId' => $mainId,
  147. 'sjId' => $this->sjId,
  148. 'shopId' => $this->shopId,
  149. 'default' => 1,
  150. 'flower' => 1,
  151. 'categoryName' => '未分类',
  152. 'inTurn' => 0,
  153. 'status' => 0,
  154. ];
  155. $default = CategoryClass::add($catData, true);
  156. }
  157. $catId = $default->id ?? 0;
  158. if (empty($catId)) {
  159. util::fail('没有找到分类');
  160. }
  161. $post['catId'] = $catId;
  162. $post['catName'] = $cat->categoryName ?? '';
  163. $main = $this->main;
  164. $work = WorkClass::createFinish($post, $main);
  165. $transaction->commit();
  166. $complete = $post['complete'] ?? 0;
  167. $print = $post['print'] ?? 1;
  168. if ($complete == 1 && $print == 1) {
  169. WorkClass::print($work, $this->shop, false);
  170. }
  171. util::success($work);
  172. } catch (\Exception $e) {
  173. $transaction->rollBack();
  174. Yii::error("失败原因:" . $e->getMessage());
  175. util::fail('操作失败');
  176. }
  177. }
  178. //商品新建制作 ssh 20220320
  179. public function actionGoodsCreate()
  180. {
  181. $post = Yii::$app->request->post();
  182. $post['mainId'] = $this->mainId ?? 0;
  183. $post['sjId'] = $this->sjId ?? 0;
  184. $post['shopId'] = $this->shopId ?? 0;
  185. $connection = Yii::$app->db;
  186. $transaction = $connection->beginTransaction();
  187. try {
  188. $goodsJson = $post['goods'] ?? '';
  189. $goods = json_decode($goodsJson, true);
  190. if (empty($goods)) {
  191. util::fail('没有找到商品');
  192. }
  193. $post['goods'] = $goods;
  194. $main = $this->main;
  195. WorkClass::goodsCreateFinish($post, $main);
  196. $transaction->commit();
  197. util::complete();
  198. } catch (\Exception $e) {
  199. $transaction->rollBack();
  200. Yii::error("失败原因:" . $e->getMessage());
  201. util::fail('操作失败');
  202. }
  203. }
  204. //包括制作单和用材信息 ssh 20220319
  205. public function actionFullInfo()
  206. {
  207. $get = Yii::$app->request->get();
  208. $id = $get['id'] ?? 0;
  209. $work = WorkClass::getById($id, true);
  210. WorkClass::valid($work, $this->mainId);
  211. $workItem = WorkItemClass::getWorkAllItem($work);
  212. $goods = [];
  213. $goodsId = $work->goodsId ?? 0;
  214. if (!empty($goodsId)) {
  215. $params = [];
  216. $shop = $this->shop;
  217. //这边传的是空的,有影响,后面要解决,请搜索关键词 work_if_need_custom
  218. $custom = [];
  219. $goods = GoodsClass::getGoodsInfo($goodsId, $shop, $custom, $params);
  220. }
  221. $work = $work->attributes;
  222. $shortCover = $work['cover'] ?? '';
  223. $work['shortCover'] = $shortCover;
  224. $work['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  225. $work['bigCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_1000,w_1000";
  226. $work['smallCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  227. $today = date("Y-m-d");
  228. $tomorrow = date("Y-m-d", strtotime('+1 day'));
  229. $work['today'] = $today;
  230. $work['tomorrow'] = $tomorrow;
  231. $addTime = $work['addTime'] ?? 0;
  232. $currentTime = strtotime($addTime) + 60;
  233. $diffTime = bcsub($currentTime, time());
  234. $beginCount = $diffTime > 0 ? $diffTime : 0;
  235. $work['beginCount'] = $beginCount;
  236. util::success(['info' => $work, 'item' => $workItem, 'goods' => $goods]);
  237. }
  238. //取消 ssh 20220320
  239. public function actionCancel()
  240. {
  241. $get = Yii::$app->request->get();
  242. $id = $get['id'] ?? 0;
  243. $work = WorkClass::getById($id, true);
  244. WorkClass::valid($work, $this->mainId);
  245. WorkClass::cancel($work);
  246. util::complete();
  247. }
  248. //完成制作单 ssh 20220319
  249. public function actionFinish()
  250. {
  251. $post = Yii::$app->request->post();
  252. $workId = $post['id'] ?? 0;
  253. $connection = Yii::$app->db;
  254. $transaction = $connection->beginTransaction();
  255. try {
  256. $work = WorkClass::getById($workId, true);
  257. WorkClass::valid($work, $this->mainId);
  258. if ($work->status == 1) {
  259. util::fail('制作单已完成');
  260. }
  261. if ($work->status == 2) {
  262. util::fail('制作单已取消');
  263. }
  264. $staffId = $post['staffId'] ?? 0;
  265. if (empty($staffId)) {
  266. util::fail('请选择制作人');
  267. }
  268. $staffName = $post['staffName'] ?? '';
  269. $staffData = ['staffId' => $staffId, 'staffName' => $staffName];
  270. WorkClass::finish($work, $staffData);
  271. $transaction->commit();
  272. //美团的暂时不打小票
  273. if ($work->fromType != 4) {
  274. WorkClass::print($work, $this->shop, false);
  275. }
  276. $msg = '已完成';
  277. util::complete($msg);
  278. } catch (\Exception $e) {
  279. $transaction->rollBack();
  280. Yii::error("失败原因:" . $e->getMessage());
  281. util::fail('操作失败');
  282. }
  283. }
  284. }