WorkController.php 11 KB

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