WorkController.php 11 KB

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