LiveOrderController.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. }