| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- namespace ghs\controllers;
- use bizGhs\order\classes\OrderClass;
- use bizGhs\order\classes\OrderItemClass;
- use bizGhs\order\services\OrderItemService;
- use bizGhs\order\services\OrderService;
- use bizGhs\product\classes\ProductClass;
- use common\components\imgUtil;
- use common\components\util;
- use Yii;
- class OrderItemController extends BaseController
- {
- public $guestAccess = [];
- //赠送花材 ssh 20230411
- public function actionGiveItem()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'] ?? 0;
- $num = $post['num'] ?? 0;
- if (is_numeric($num) == false || $num <= 0) {
- util::fail('请填写赠送数量');
- }
- $orderItem = OrderItemClass::getById($id, true);
- if (empty($orderItem)) {
- util::fail('没有找到花材');
- }
- if ($orderItem->mainId != $this->mainId) {
- util::fail('没有权限操作');
- }
- $connection = Yii::$app->db;//事务处理
- $transaction = $connection->beginTransaction();
- try {
- $staff = $this->shopAdmin;
- $staffName = $staff->name ?? '';
- $staffId = $staff->id ?? 0;
- $data = ['shopId' => $this->shopId, 'sjId' => $this->sjId, 'staffName' => $staffName, 'staffId' => $staffId];
- $respond = OrderItemService::giveProduct($data, $orderItem, $num);
- $transaction->commit();
- util::success(['info' => $respond], '赠送成功');
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::info("赠送出错了:" . $e->getMessage());
- util::fail('出错了');
- }
- }
- //重选花材 ssh 2021.3.2
- public function actionReset()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'] ?? 0;
- $product = $post['product'] ?? '[]';
- $product = json_decode($product, true);
- //检查花材是否都是同家门店的
- ProductClass::valid($product, $this->mainId);
- $info = OrderService::getOrderInfo($id);
- OrderClass::valid($info, $this->shopId);
- //添加修改花材
- $orderSn = $info['orderSn'] ?? '';
- OrderItemClass::replaceItem($orderSn, $product);
- util::complete();
- }
- //修改花材时获取订单花材和花材基本信息的组合 ssh 20210809
- public function actionGetOrderProduct()
- {
- $id = Yii::$app->request->get('id', 0);
- $order = OrderClass::getById($id, true);
- OrderClass::valid($order, $this->shopId);
- $orderSn = $order->orderSn ?? '';
- $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', 'productId');
- $ids = array_column($itemList, 'productId');
- if (empty($ids)) {
- util::fail('没有找到花材');
- }
- $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
- if (empty($productList)) {
- util::fail('没有找到花材信息');
- }
- foreach ($productList as $key => $product) {
- $productId = $product['id'] ?? 0;
- $currentItem = $itemList[$productId] ?? [];
- $bigCount = $currentItem['bigNum'] ?? 0;
- $smallCount = $currentItem['smallNum'] ?? 0;
- $userPrice = $currentItem['userPrice'] ?? 0;
- $productList[$key]['bigCount'] = $bigCount;
- $productList[$key]['smallCount'] = $smallCount;
- $productList[$key]['userPrice'] = $userPrice;
- $cover = imgUtil::groupImg($product['cover']);
- $productList[$key]['cover'] = $cover;
- $bigPrice = $product['unitPrice'] ?? 0;
- $smallPrice = $product['smallUnitPrice'] ?? 0;
- $productList[$key]['bigPrice'] = $bigPrice;
- $productList[$key]['smallPrice'] = $smallPrice;
- $productList[$key]['cover'] = $cover;
- }
- util::success(['productList' => array_values($productList)]);
- }
- //根据花材id取订单列表 ssh 20211011
- public function actionGetOrderInfoList()
- {
- $get = Yii::$app->request->get();
- $productId = $get['productId'] ?? 0;
- $product = ProductClass::getById($productId, true);
- ProductClass::check($product, $this->mainId);
- $where = ['productId' => $productId];
- $respond = OrderItemClass::getOrderInfoList($where);
- util::success($respond);
- }
- }
|