LiveOrderController.php 4.3 KB

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