LiveOrderController.php 3.5 KB

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