LiveOrderController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\live\classes\LiveOrderClass;
  4. use bizGhs\product\classes\ProductClass;
  5. use common\components\dateUtil;
  6. use common\components\stringUtil;
  7. use common\components\util;
  8. use Yii;
  9. class LiveOrderController extends BaseController
  10. {
  11. //走播单列表 ssh 20241003
  12. public function actionList()
  13. {
  14. $get = Yii::$app->request->get();
  15. $staffId = $get['staffId'] ?? 0;
  16. $switchOrder = $get['switchOrder'] ?? -1;
  17. $searchContent = $get['searchContent'] ?? '';
  18. $where = [];
  19. $where['mainId'] = $this->mainId;
  20. if (!empty($staffId)) {
  21. $where['staffId'] = $staffId;
  22. }
  23. if (!empty($searchContent)) {
  24. if (stringUtil::isLetter($searchContent)) {
  25. $where['itemPy'] = ['like', $searchContent];
  26. } else {
  27. $where['itemName'] = ['like', $searchContent];
  28. }
  29. }
  30. if ($switchOrder > -1) {
  31. $where['switchOrder'] = $switchOrder;
  32. }
  33. $searchTime = $get['searchTime'] ?? '';
  34. if (!empty($searchTime)) {
  35. $startTime = $get['startTime'] ?? '';
  36. $endTime = $get['endTime'] ?? '';
  37. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  38. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  39. }
  40. $respond = LiveOrderClass::getOrderList($where);
  41. util::success($respond);
  42. }
  43. //添加订单 ssh 20241003
  44. public function actionAddOrder()
  45. {
  46. $post = Yii::$app->request->post();
  47. $itemId = $post['itemId'] ?? 0;
  48. if (empty($itemId)) {
  49. util::fail('请选花材');
  50. }
  51. $product = ProductClass::getById($itemId, true);
  52. if (empty($product)) {
  53. util::fail('没有找到花材');
  54. }
  55. if ($product->mainId != $this->mainId) {
  56. util::fail('不是你的花材');
  57. }
  58. $selectCustom = $post['selectCustom'] ?? '';
  59. if (empty($selectCustom)) {
  60. util::fail('没有客户');
  61. }
  62. $arr = json_decode($selectCustom, true);
  63. if (empty($arr) || is_array($arr) == false) {
  64. util::fail('没有客户信息');
  65. }
  66. $mainId = $this->mainId;
  67. $hasItem = LiveOrderClass::getByCondition(['mainId' => $mainId, 'itemId' => $itemId, 'switchOrder' => 0], true);
  68. if (!empty($hasItem)) {
  69. util::fail('这个花材已添加过');
  70. }
  71. $has = [];
  72. $customList = [];
  73. foreach ($arr as $key => $info) {
  74. $customId = $info['customId'] ?? 0;
  75. if (isset($has[$customId])) {
  76. util::fail('重复的客户');
  77. }
  78. $has[$customId] = 1;
  79. $customName = $info['customName'] ?? '';
  80. $num = $info['num'] ?? 0;
  81. $price = $info['price'] ?? 0;
  82. $customList[] = ['customId' => $customId, 'customName' => $customName, 'num' => $num, 'price' => $price];
  83. }
  84. $staff = $this->shopAdmin;
  85. $staffId = $staff->id ?? 0;
  86. $staffName = $staff->name ?? '';
  87. $params = ['product' => $product, 'customList' => $customList, 'staffId' => $staffId, 'staffName' => $staffName];
  88. $connection = Yii::$app->db;
  89. $transaction = $connection->beginTransaction();
  90. try {
  91. LiveOrderClass::addOrder($params, $mainId);
  92. $transaction->commit();
  93. util::complete('创建成功');
  94. } catch (\Exception $e) {
  95. Yii::info("操作失败原因:" . $e->getMessage());
  96. $transaction->rollBack();
  97. util::fail('操作失败');
  98. }
  99. }
  100. }