| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace ghs\controllers;
- use bizGhs\live\classes\LiveOrderClass;
- use bizGhs\product\classes\ProductClass;
- use common\components\dateUtil;
- use common\components\stringUtil;
- use common\components\util;
- use Yii;
- class LiveOrderController extends BaseController
- {
- //走播单列表 ssh 20241003
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $staffId = $get['staffId'] ?? 0;
- $searchContent = $get['searchContent'] ?? '';
- $where = [];
- $where['mainId'] = $this->mainId;
- if (!empty($staffId)) {
- $where['staffId'] = $staffId;
- }
- if (!empty($searchContent)) {
- if (stringUtil::isLetter($searchContent)) {
- $where['py'] = ['like', $searchContent];
- } else {
- $where['name'] = ['like', $searchContent];
- }
- }
- $searchTime = $get['searchTime'] ?? '';
- if (!empty($searchTime)) {
- $startTime = $get['startTime'] ?? '';
- $endTime = $get['endTime'] ?? '';
- $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
- $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
- }
- $respond = LiveOrderClass::getOrderList($where);
- util::success($respond);
- }
- //添加订单 ssh 20241003
- public function actionAddOrder()
- {
- $post = Yii::$app->request->post();
- $itemId = $post['itemId'] ?? 0;
- if (empty($itemId)) {
- util::fail('请选花材');
- }
- $product = ProductClass::getById($itemId, true);
- if (empty($product)) {
- util::fail('没有找到花材');
- }
- if ($product->mainId != $this->mainId) {
- util::fail('不是你的花材');
- }
- $selectCustom = $post['selectCustom'] ?? '';
- if (empty($selectCustom)) {
- util::fail('没有客户');
- }
- $arr = json_decode($selectCustom, true);
- if (empty($arr) || is_array($arr) == false) {
- util::fail('没有客户信息');
- }
- $mainId = $this->mainId;
- $hasItem = LiveOrderClass::getByCondition(['mainId' => $mainId, 'itemId' => $itemId, 'switchOrder' => 0], true);
- if (!empty($hasItem)) {
- util::fail('这个花材已添加过');
- }
- $has = [];
- $customList = [];
- foreach ($arr as $key => $info) {
- $customId = $info['customId'] ?? 0;
- if (isset($has[$customId])) {
- util::fail('重复的客户');
- }
- $has[$customId] = 1;
- $customName = $info['customName'] ?? '';
- $num = $info['num'] ?? 0;
- $price = $info['price'] ?? 0;
- $customList[] = ['customId' => $customId, 'customName' => $customName, 'num' => $num, 'price' => $price];
- }
- $staff = $this->shopAdmin;
- $staffId = $staff->id ?? 0;
- $staffName = $staff->name ?? '';
- $params = ['product' => $product, 'customList' => $customList, 'staffId' => $staffId, 'staffName' => $staffName];
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- LiveOrderClass::addOrder($params, $mainId);
- $transaction->commit();
- util::complete('创建成功');
- } catch (\Exception $e) {
- Yii::info("操作失败原因:" . $e->getMessage());
- $transaction->rollBack();
- util::fail('操作失败');
- }
- }
- }
|