| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- <?php
- namespace ghs\controllers;
- use bizGhs\order\classes\CheckOrderClass;
- use bizGhs\product\classes\ProductClass;
- use Yii;
- use common\components\util;
- class CheckOrderController extends BaseController
- {
- //订单列表 ssh 2021.1.14
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $orderStatus = isset($get['status']) ? $get['status'] : '';
- $where = [];
- $where['shopId'] = $this->shopId;
- if (!empty($orderStatus)) {
- $where['status'] = $orderStatus;
- }
- $list = CheckOrderClass::getOrderList($where);
- util::success($list);
- }
- //订单详情 2021.1.22 lqh
- public function actionDetail()
- {
- $orderSn = Yii::$app->request->get('orderSn', '');
- $orderData = CheckOrderClass::getOrderDetail($orderSn, $this->shopId);
- util::success($orderData);
- }
- //分配库存 ssh 20230720
- public function actionSendStock()
- {
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('超管才能盘点');
- }
- $post = Yii::$app->request->post();
- $motherId = $post['motherId'] ?? 0;
- $mother = ProductClass::getById($motherId, true);
- if (empty($mother) || $mother->mainId != $this->mainId) {
- util::fail('无法操作');
- }
- $motherName = $mother->name ?? '';
- $ghsItemInfo = $post['itemInfo'] ?? '';
- if (empty($ghsItemInfo)) {
- util::fail('请选择花材');
- }
- $itemList = json_decode($ghsItemInfo, true);
- if (empty($itemList)) {
- util::fail('没有花材');
- }
- $totalNum = 0;
- foreach ($itemList as $key => $item) {
- $currentNum = $item['bigNum'] ?? 0;
- $totalNum = bcadd($totalNum, $currentNum, 2);
- }
- if ($totalNum > $mother->stock) {
- util::fail($motherName . "不足{$totalNum}扎");
- }
- $motherBigNum = bcsub($mother->stock, $totalNum, 2);
- $motherBigNum = floatval($motherBigNum);
- $ids = array_column($itemList, 'productId');
- $infoList = ProductClass::getByIds($ids, null, 'id');
- if (!empty($infoList)) {
- foreach ($itemList as $itemKey => $itemVal) {
- $productId = $itemVal['productId'] ?? 0;
- $bigNum = $itemVal['bigNum'] ?? 0;
- $addBigNum = $infoList[$productId]['stock'] ?? 0;
- $newBigNum = bcadd($bigNum, $addBigNum, 2);
- $itemList[$itemKey]['bigNum'] = $newBigNum;
- }
- }
- $itemList[] = ['productId' => $motherId, 'bigNum' => $motherBigNum, 'smallNum' => 0];
- $newJson = json_encode($itemList);
- $post['itemInfo'] = $newJson;
- $post['sjId'] = $this->sjId;
- $post['shopId'] = $this->shopId;
- $post['adminId'] = $this->adminId;
- $post['mainId'] = $this->mainId;
- $this->saveOrder($post, false, false);
- }
- //盘点确认 lqh 2021.1.22
- public function actionCreateOrder()
- {
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('超管才能盘点');
- }
- $post = Yii::$app->request->post();
- $post['sjId'] = $this->sjId;
- $post['shopId'] = $this->shopId;
- $post['adminId'] = $this->adminId;
- $post['mainId'] = $this->mainId;
- $this->saveOrder($post, false, false);
- }
- //盘点存草稿 lqh 2021.1.22
- public function actionCreateDraft()
- {
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('超管才能操作');
- }
- $post = Yii::$app->request->post();
- $post['sjId'] = $this->sjId;
- $post['shopId'] = $this->shopId;
- $post['adminId'] = $this->adminId;
- //ssh 20210827
- util::fail('草稿功能取消');
- $this->saveOrder($post, true, false);
- }
- //编辑草稿 ,继续保存草稿
- public function actionUpdateDraft()
- {
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('超管才能操作');
- }
- $post = Yii::$app->request->post();
- $post['sjId'] = $this->sjId;
- $post['shopId'] = $this->shopId;
- $post['adminId'] = $this->adminId;
- $orderSn = $post['orderSn'] ?? '';
- $orderData = CheckOrderClass::orderExist($orderSn, $this->shopId);
- if ($orderData['status'] != CheckOrderClass::STATUS_DRAFT) {
- util::fail("订单不存在");
- }
- $this->saveOrder($post, true, true);
- }
- //编辑草稿, 确认
- public function actionUpdateOrder()
- {
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('超管才能操作');
- }
- $post = Yii::$app->request->post();
- $post['sjId'] = $this->sjId;
- $post['shopId'] = $this->shopId;
- $post['mainId'] = $this->mainId;
- $post['adminId'] = $this->adminId;
- $orderSn = $post['orderSn'] ?? '';
- $orderData = CheckOrderClass::orderExist($orderSn, $this->shopId);
- if ($orderData['status'] != CheckOrderClass::STATUS_DRAFT) {
- util::fail("订单不存在");
- }
- $this->saveOrder($post, false, true);
- }
- protected function saveOrder($post, $draft = false, $update = false)
- {
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('超管才能操作');
- }
- $ghsItemInfo = $post['itemInfo'] ?? '';
- if (empty($ghsItemInfo)) {
- util::fail('请选择花材');
- }
- //数据格式 [{productId:0,bigNum:1,smallNum:0}]
- $ghsItemInfo = json_decode($ghsItemInfo, true);
- if (!is_array($ghsItemInfo)) {
- util::fail('花材格式不正确');
- }
- //判断花材格式,是否属于当前门店
- ProductClass::valid($ghsItemInfo, $this->mainId);
- foreach ($ghsItemInfo as $key => $item) {
- //如果盘点数是99999则转为0
- if (isset($item['bigNum']) && $item['bigNum'] == 99999) {
- $ghsItemInfo[$key]['bigNum'] = 0;
- }
- }
- $post['itemInfo'] = $ghsItemInfo;
- if ($update === true) {
- //编辑
- $order = CheckOrderClass::opOrder($post, $draft, $update);
- } else {
- $order = CheckOrderClass::opOrder($post, $draft, $update);
- }
- if ($order) {
- util::success($order);
- }
- util::fail();
- }
- }
|