LiveOrderController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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 20241003
  14. public function actionList()
  15. {
  16. $get = Yii::$app->request->get();
  17. $staffId = $get['staffId'] ?? 0;
  18. $switchOrder = $get['switchOrder'] ?? -1;
  19. $searchContent = $get['searchContent'] ?? '';
  20. $where = [];
  21. $where['mainId'] = $this->mainId;
  22. if (!empty($staffId)) {
  23. $where['staffId'] = $staffId;
  24. }
  25. if (!empty($searchContent)) {
  26. if (stringUtil::isLetter($searchContent)) {
  27. $where['itemPy'] = ['like', $searchContent];
  28. } else {
  29. $where['itemName'] = ['like', $searchContent];
  30. }
  31. }
  32. if ($switchOrder > -1) {
  33. $where['switchOrder'] = $switchOrder;
  34. }
  35. $searchTime = $get['searchTime'] ?? '';
  36. if (!empty($searchTime)) {
  37. $startTime = $get['startTime'] ?? '';
  38. $endTime = $get['endTime'] ?? '';
  39. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  40. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  41. }
  42. $respond = LiveOrderClass::getOrderList($where);
  43. util::success($respond);
  44. }
  45. //添加订单 ssh 20241003
  46. public function actionAddOrder()
  47. {
  48. $post = Yii::$app->request->post();
  49. $itemId = $post['itemId'] ?? 0;
  50. if (empty($itemId)) {
  51. util::fail('请选花材');
  52. }
  53. $product = ProductClass::getById($itemId, true);
  54. if (empty($product)) {
  55. util::fail('没有找到花材');
  56. }
  57. if ($product->mainId != $this->mainId) {
  58. util::fail('不是你的花材');
  59. }
  60. $selectCustom = $post['selectCustom'] ?? '';
  61. if (empty($selectCustom)) {
  62. util::fail('没有客户');
  63. }
  64. $arr = json_decode($selectCustom, true);
  65. if (empty($arr) || is_array($arr) == false) {
  66. util::fail('没有客户信息');
  67. }
  68. $mainId = $this->mainId;
  69. $hasItem = LiveOrderClass::getByCondition(['mainId' => $mainId, 'itemId' => $itemId, 'switchOrder' => 0], true);
  70. if (!empty($hasItem)) {
  71. util::fail('这个花材已添加过');
  72. }
  73. $has = [];
  74. $customList = [];
  75. foreach ($arr as $key => $info) {
  76. $customId = $info['customId'] ?? 0;
  77. if (isset($has[$customId])) {
  78. util::fail('重复的客户');
  79. }
  80. $has[$customId] = 1;
  81. $customName = $info['customName'] ?? '';
  82. $num = $info['num'] ?? 0;
  83. $price = $info['price'] ?? 0;
  84. $customList[] = ['customId' => $customId, 'customName' => $customName, 'num' => $num, 'price' => $price];
  85. }
  86. $staff = $this->shopAdmin;
  87. $staffId = $staff->id ?? 0;
  88. $staffName = $staff->name ?? '';
  89. $params = ['product' => $product, 'customList' => $customList, 'staffId' => $staffId, 'staffName' => $staffName];
  90. $connection = Yii::$app->db;
  91. $transaction = $connection->beginTransaction();
  92. try {
  93. LiveOrderClass::addOrder($params, $mainId);
  94. $transaction->commit();
  95. util::complete('创建成功');
  96. } catch (\Exception $e) {
  97. Yii::info("操作失败原因:" . $e->getMessage());
  98. $transaction->rollBack();
  99. util::fail('操作失败');
  100. }
  101. }
  102. //获取明细 ssh 20241005
  103. public function actionGetDetail()
  104. {
  105. $get = Yii::$app->request->get();
  106. $id = $get['id'] ?? 0;
  107. $live = LiveOrderClass::getById($id, true);
  108. if (empty($live)) {
  109. util::fail('没有找到记录');
  110. }
  111. if ($live->mainId != $this->mainId) {
  112. util::fail('不是你的记录');
  113. }
  114. $orderSn = $live->orderSn ?? '';
  115. $customList = LiveOrderCustomClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  116. util::success(['customList' => $customList, 'info' => $live]);
  117. }
  118. //添加客户 ssh 20241005
  119. public function actionAddCustom()
  120. {
  121. $post = Yii::$app->request->post();
  122. $id = $post['id'] ?? 0;
  123. $customId = $post['customId'] ?? 0;
  124. $custom = CustomClass::getById($customId, true);
  125. if (empty($custom)) {
  126. util::fail('没有找到客户');
  127. }
  128. if ($custom->ownMainId != $this->mainId) {
  129. util::fail('不是你的客户');
  130. }
  131. $num = $post['num'] ?? 0;
  132. $price = $post['price'] ?? 0;
  133. $live = LiveOrderClass::getById($id, true);
  134. if (empty($live)) {
  135. util::fail('没有找到记录');
  136. }
  137. if ($live->mainId != $this->mainId) {
  138. util::fail('不是你的记录');
  139. }
  140. if ($live->switchOrder == 1) {
  141. util::fail('已转订单,不能添加');
  142. }
  143. $params = ['num' => $num, 'price' => $price];
  144. LiveOrderClass::addCustom($params, $custom, $live);
  145. util::complete('添加成功');
  146. }
  147. //删除客户 ssh 20241005
  148. public function actionDelCustom()
  149. {
  150. $get = Yii::$app->request->get();
  151. $id = $get['id'] ?? 0;
  152. $customId = $get['customId'] ?? 0;
  153. $custom = CustomClass::getById($customId, true);
  154. if (empty($custom)) {
  155. util::fail('没有找到客户');
  156. }
  157. if ($custom->ownMainId != $this->mainId) {
  158. util::fail('不是你的客户');
  159. }
  160. $live = LiveOrderClass::getById($id, true);
  161. if (empty($live)) {
  162. util::fail('没有找到记录');
  163. }
  164. if ($live->mainId != $this->mainId) {
  165. util::fail('不是你的记录');
  166. }
  167. if ($live->switchOrder == 1) {
  168. util::fail('已转订单,不能删除');
  169. }
  170. LiveOrderClass::delCustom($custom, $live);
  171. util::complete('添加成功');
  172. }
  173. //更新客户 ssh 20241005
  174. public function actionUpdateCustom()
  175. {
  176. $post = Yii::$app->request->post();
  177. $id = $post['id'] ?? 0;
  178. $customList = $post['customList'] ?? 0;
  179. $customData = json_decode($customList, true);
  180. if (empty($customData)) {
  181. util::fail('没有客户信息');
  182. }
  183. $live = LiveOrderClass::getById($id, true);
  184. if (empty($live)) {
  185. util::fail('没有找到记录');
  186. }
  187. if ($live->mainId != $this->mainId) {
  188. util::fail('不是你的记录');
  189. }
  190. if ($live->switchOrder == 1) {
  191. util::fail('已转订单,不能删除');
  192. }
  193. LiveOrderClass::updateCustom($customData, $live);
  194. util::complete('修改成功');
  195. }
  196. public function actionPrintOrder()
  197. {
  198. $get = Yii::$app->request->get();
  199. $id = $get['id'] ?? 0;
  200. $live = LiveOrderClass::getById($id, true);
  201. if (empty($live)) {
  202. util::fail('没有找到');
  203. }
  204. if ($live->mainId != $this->mainId) {
  205. util::fail('不是你的');
  206. }
  207. $orderSn = $live->orderSn ?? '';
  208. $liveCustomList = LiveOrderCustomClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  209. if (empty($customList)) {
  210. util::fail('没有客户预订');
  211. }
  212. $ids = array_column($liveCustomList, 'customId');
  213. $customList = CustomClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
  214. $table = [];
  215. foreach ($liveCustomList as $liveCustom) {
  216. $customId = $liveCustom['customId'] ?? 0;
  217. $currentName = $liveCustom['customName'] ?? '';
  218. $num = $liveCustom['num'] ?? '';
  219. $customInfo = $customList[$customId] ?? [];
  220. $seatSn = $customInfo['seatSn'] ?? '';
  221. $table[] = [
  222. 'name' => $currentName,
  223. 'num' => $num,
  224. 'seatSn' => $seatSn,
  225. 'remark' => '',
  226. ];
  227. }
  228. $a4Print = [
  229. 'table' => $table,
  230. 'title' => '销售单',
  231. ];
  232. $info['printData'] = $a4Print;
  233. $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":188.91632245461145,"title":"名称","field":"name","checked":true,"columnId":"name","fixed":false,"rowspan":1,"colspan":1,"align":"center","halign":"center","vAlign":"middle","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":105.15171514242958,"title":"预订数","field":"num","checked":true,"columnId":"num","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":103.08801880877742,"title":"确认数","field":"confirmNum","checked":true,"columnId":"confirmNum","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":94.5,"top":18,"height":35,"width":373,"title":"文本","right":467.5,"bottom":53,"vCenter":281,"hCenter":35.5,"field":"title","testData":"纯彩 15280215347","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":14,"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":{}}]}';
  234. $info['template'] = $template;
  235. util::success($info);
  236. }
  237. }