LiveOrderController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\custom\classes\CustomClass;
  4. use bizGhs\live\classes\LiveOrderClass;
  5. use bizGhs\live\classes\LiveOrderCustomClass;
  6. use bizGhs\product\classes\ProductClass;
  7. use common\components\dateUtil;
  8. use common\components\stringUtil;
  9. use common\components\util;
  10. use Yii;
  11. class LiveOrderController extends BaseController
  12. {
  13. //转换成订单 ssh 20241006
  14. public function actionConvertOrder()
  15. {
  16. $mainId = $this->mainId;
  17. $cacheKey = 'live_order_' . $mainId;
  18. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  19. if (!empty($has)) {
  20. util::fail('已经在转换了');
  21. }
  22. $list = LiveOrderClass::getAllByCondition(['mainId' => $mainId,'switchOrder'=>0], null, '*', null, true);
  23. if (empty($list)) {
  24. util::fail('没有记录需要转换');
  25. }
  26. $arr = [];
  27. foreach ($list as $live) {
  28. $addTime = $live->addTime;
  29. $date = date("Y-m-d", strtotime($addTime));
  30. $arr[$date] = 1;
  31. }
  32. if (count($arr) > 1) {
  33. util::fail('有记录不是同一天的');
  34. }
  35. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 180, 1]);
  36. util::success('提交成功,3分钟后查看订单');
  37. }
  38. //走播单列表 ssh 20241003
  39. public function actionList()
  40. {
  41. $get = Yii::$app->request->get();
  42. $staffId = $get['staffId'] ?? 0;
  43. $switchOrder = $get['switchOrder'] ?? -1;
  44. $searchContent = $get['searchContent'] ?? '';
  45. $where = [];
  46. $where['mainId'] = $this->mainId;
  47. if (!empty($staffId)) {
  48. $where['staffId'] = $staffId;
  49. }
  50. if (!empty($searchContent)) {
  51. if (stringUtil::isLetter($searchContent)) {
  52. $where['itemPy'] = ['like', $searchContent];
  53. } else {
  54. $where['itemName'] = ['like', $searchContent];
  55. }
  56. }
  57. if ($switchOrder > -1) {
  58. $where['switchOrder'] = $switchOrder;
  59. }
  60. $searchTime = $get['searchTime'] ?? '';
  61. if (!empty($searchTime)) {
  62. $startTime = $get['startTime'] ?? '';
  63. $endTime = $get['endTime'] ?? '';
  64. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  65. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  66. }
  67. $respond = LiveOrderClass::getOrderList($where);
  68. util::success($respond);
  69. }
  70. //添加订单 ssh 20241003
  71. public function actionAddOrder()
  72. {
  73. $post = Yii::$app->request->post();
  74. $itemId = $post['itemId'] ?? 0;
  75. if (empty($itemId)) {
  76. util::fail('请选花材');
  77. }
  78. $product = ProductClass::getById($itemId, true);
  79. if (empty($product)) {
  80. util::fail('没有找到花材');
  81. }
  82. if ($product->mainId != $this->mainId) {
  83. util::fail('不是你的花材');
  84. }
  85. $selectCustom = $post['selectCustom'] ?? '';
  86. if (empty($selectCustom)) {
  87. util::fail('没有客户');
  88. }
  89. $arr = json_decode($selectCustom, true);
  90. if (empty($arr) || is_array($arr) == false) {
  91. util::fail('没有客户信息');
  92. }
  93. $mainId = $this->mainId;
  94. $hasItem = LiveOrderClass::getByCondition(['mainId' => $mainId, 'itemId' => $itemId, 'switchOrder' => 0], true);
  95. if (!empty($hasItem)) {
  96. util::fail('这个花材已添加过');
  97. }
  98. $has = [];
  99. $customList = [];
  100. foreach ($arr as $key => $info) {
  101. $customId = $info['customId'] ?? 0;
  102. if (isset($has[$customId])) {
  103. util::fail('重复的客户');
  104. }
  105. $has[$customId] = 1;
  106. $customName = $info['customName'] ?? '';
  107. $num = $info['num'] ?? 0;
  108. $price = $info['price'] ?? 0;
  109. $customList[] = ['customId' => $customId, 'customName' => $customName, 'num' => $num, 'price' => $price];
  110. }
  111. $staff = $this->shopAdmin;
  112. $staffId = $staff->id ?? 0;
  113. $staffName = $staff->name ?? '';
  114. $params = ['product' => $product, 'customList' => $customList, 'staffId' => $staffId, 'staffName' => $staffName];
  115. $connection = Yii::$app->db;
  116. $transaction = $connection->beginTransaction();
  117. try {
  118. LiveOrderClass::addOrder($params, $mainId);
  119. $transaction->commit();
  120. util::complete('创建成功');
  121. } catch (\Exception $e) {
  122. Yii::info("操作失败原因:" . $e->getMessage());
  123. $transaction->rollBack();
  124. util::fail('操作失败');
  125. }
  126. }
  127. //获取明细 ssh 20241005
  128. public function actionGetDetail()
  129. {
  130. $get = Yii::$app->request->get();
  131. $id = $get['id'] ?? 0;
  132. $live = LiveOrderClass::getById($id, true);
  133. if (empty($live)) {
  134. util::fail('没有找到记录');
  135. }
  136. if ($live->mainId != $this->mainId) {
  137. util::fail('不是你的记录');
  138. }
  139. $orderSn = $live->orderSn ?? '';
  140. $customList = LiveOrderCustomClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  141. util::success(['customList' => $customList, 'info' => $live]);
  142. }
  143. //添加客户 ssh 20241005
  144. public function actionAddCustom()
  145. {
  146. $post = Yii::$app->request->post();
  147. $id = $post['id'] ?? 0;
  148. $customId = $post['customId'] ?? 0;
  149. $custom = CustomClass::getById($customId, true);
  150. if (empty($custom)) {
  151. util::fail('没有找到客户');
  152. }
  153. if ($custom->ownMainId != $this->mainId) {
  154. util::fail('不是你的客户');
  155. }
  156. $num = $post['num'] ?? 0;
  157. $price = $post['price'] ?? 0;
  158. $live = LiveOrderClass::getById($id, true);
  159. if (empty($live)) {
  160. util::fail('没有找到记录');
  161. }
  162. if ($live->mainId != $this->mainId) {
  163. util::fail('不是你的记录');
  164. }
  165. if ($live->switchOrder == 1) {
  166. util::fail('已转订单,不能添加');
  167. }
  168. $params = ['num' => $num, 'price' => $price];
  169. LiveOrderClass::addCustom($params, $custom, $live);
  170. util::complete('添加成功');
  171. }
  172. //删除客户 ssh 20241005
  173. public function actionDelCustom()
  174. {
  175. $get = Yii::$app->request->get();
  176. $id = $get['id'] ?? 0;
  177. $customId = $get['customId'] ?? 0;
  178. $custom = CustomClass::getById($customId, true);
  179. if (empty($custom)) {
  180. util::fail('没有找到客户');
  181. }
  182. if ($custom->ownMainId != $this->mainId) {
  183. util::fail('不是你的客户');
  184. }
  185. $live = LiveOrderClass::getById($id, true);
  186. if (empty($live)) {
  187. util::fail('没有找到记录');
  188. }
  189. if ($live->mainId != $this->mainId) {
  190. util::fail('不是你的记录');
  191. }
  192. if ($live->switchOrder == 1) {
  193. util::fail('已转订单,不能删除');
  194. }
  195. LiveOrderClass::delCustom($custom, $live);
  196. util::complete('添加成功');
  197. }
  198. //更新客户 ssh 20241005
  199. public function actionUpdateCustom()
  200. {
  201. $post = Yii::$app->request->post();
  202. $id = $post['id'] ?? 0;
  203. $customList = $post['customList'] ?? 0;
  204. $customData = json_decode($customList, true);
  205. if (empty($customData)) {
  206. util::fail('没有客户信息');
  207. }
  208. $live = LiveOrderClass::getById($id, true);
  209. if (empty($live)) {
  210. util::fail('没有找到记录');
  211. }
  212. if ($live->mainId != $this->mainId) {
  213. util::fail('不是你的记录');
  214. }
  215. if ($live->switchOrder == 1) {
  216. util::fail('已转订单,不能删除');
  217. }
  218. LiveOrderClass::updateCustom($customData, $live);
  219. util::complete('修改成功');
  220. }
  221. public function actionPrintOrder()
  222. {
  223. $get = Yii::$app->request->get();
  224. $id = $get['id'] ?? 0;
  225. $live = LiveOrderClass::getById($id, true);
  226. if (empty($live)) {
  227. util::fail('没有找到');
  228. }
  229. if ($live->mainId != $this->mainId) {
  230. util::fail('不是你的');
  231. }
  232. $orderSn = $live->orderSn ?? '';
  233. $liveCustomList = LiveOrderCustomClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  234. if (empty($liveCustomList)) {
  235. util::fail('没有客户预订');
  236. }
  237. $ids = array_column($liveCustomList, 'customId');
  238. $customList = CustomClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
  239. $table = [];
  240. foreach ($liveCustomList as $liveCustom) {
  241. $customId = $liveCustom['customId'] ?? 0;
  242. $currentName = $liveCustom['customName'] ?? '';
  243. $num = $liveCustom['num'] ?? '';
  244. $customInfo = $customList[$customId] ?? [];
  245. $seatSn = $customInfo['seatSn'] ?? '';
  246. $table[] = [
  247. 'name' => $currentName,
  248. 'num' => $num,
  249. 'seatSn' => $seatSn,
  250. 'remark' => '',
  251. ];
  252. }
  253. $addTime = $live->addTime;
  254. $itemName = $live->itemName ?? '';
  255. $time = date("Y-m-d", strtotime($addTime));
  256. $title = $time . ' ' . $itemName;
  257. $a4Print = [
  258. 'table' => $table,
  259. 'title' => $title,
  260. ];
  261. $info['printData'] = $a4Print;
  262. $template = '{"panels":[{"index":0,"name":1,"height":297,"width":210,"paperHeader":49.5,"paperFooter":780,"printElements":[{"options":{"left":30,"top":53,"height":52,"width":538,"field":"table","coordinateSync":false,"widthHeightSync":false,"fontSize":16,"lineHeight":30,"tableBorder":"border","tableHeaderBorder":"border","tableHeaderCellBorder":"border","tableHeaderFontWeight":"bold","right":567.25,"bottom":110.24609375,"vCenter":298.25,"hCenter":82.24609375,"textAlign":"center","columns":[[{"width":107.90432245461145,"title":"货位","field":"seatSn","checked":true,"columnId":"seatSn","fixed":false,"rowspan":1,"colspan":1,"align":"center","halign":"center","vAlign":"middle","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":186.15171514242957,"title":"客户名称","field":"name","checked":true,"columnId":"name","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":103.10001880877743,"title":"数量","field":"num","checked":true,"columnId":"num","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":140.84394359418155,"title":"备注","field":"remark","checked":true,"columnId":"remark","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":93.32065807548679,"title":"日期","field":"shortTime","checked":false,"columnId":"shortTime","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":74.09275968851016,"title":"库存","field":"stock","checked":false,"columnId":"stock","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":276,"title":"金额\n","field":"amount","checked":false,"columnId":"amount","fixed":false,"rowspan":1,"colspan":1,"tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":100,"title":"","field":"","checked":false,"columnId":"","fixed":false,"rowspan":1,"colspan":1},{"width":100,"title":"","field":"","checked":false,"columnId":"","fixed":false,"rowspan":1,"colspan":1}]]},"printElementType":{"title":"空白表格","type":"table","editable":true,"columnDisplayEditable":true,"columnDisplayIndexEditable":true,"columnTitleEditable":true,"columnResizable":true,"columnAlignEditable":true,"isEnableEditField":true,"isEnableContextMenu":true,"isEnableInsertRow":true,"isEnableDeleteRow":true,"isEnableInsertColumn":true,"isEnableDeleteColumn":true,"isEnableMergeCell":true}},{"options":{"left":12,"top":786,"height":49,"width":49},"printElementType":{"title":"html","type":"html"}},{"options":{"left":392.5,"top":785,"height":13,"width":199,"title":"销花宝提供技术支持","textAlign":"center","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":590.74609375,"bottom":801.25,"vCenter":491.24609375,"hCenter":794.75},"printElementType":{"title":"自定义文本","type":"text"}},{"options":{"left":67.5,"top":18,"height":35,"width":455,"title":"文本","right":522.5,"bottom":53,"vCenter":295,"hCenter":35.5,"field":"title","testData":"纯彩 15280215347","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":19.5,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}}],"paperNumberLeft":565.5,"paperNumberTop":819,"paperNumberContinue":true,"watermarkOptions":{"content":"vue-plugin-hiprint","rotate":25,"timestamp":true,"format":"YYYY-MM-DD HH:mm"},"panelLayoutOptions":{}}]}';
  263. $info['template'] = $template;
  264. $live->printOrder = 1;
  265. $live->save();
  266. util::success($info);
  267. }
  268. //修改创建时间 ssh 20241006
  269. public function actionChangeDate()
  270. {
  271. $get = Yii::$app->request->get();
  272. $id = $get['id'] ?? 0;
  273. $live = LiveOrderClass::getById($id, true);
  274. if (empty($live)) {
  275. util::fail('没有找到');
  276. }
  277. if ($live->mainId != $this->mainId) {
  278. util::fail('不是你的');
  279. }
  280. $flag = $get['flag'] ?? 0;
  281. $addTime = $live->addTime;
  282. if ($flag == 0) {
  283. $time = strtotime($addTime) - 86400;
  284. } else {
  285. $time = strtotime($addTime) + 86400;
  286. }
  287. $newDate = date("Y-m-d H:i:s", $time);
  288. $live->addTime = $newDate;
  289. $live->save();
  290. util::complete('修改成功');
  291. }
  292. }