|
|
@@ -3,6 +3,7 @@
|
|
|
namespace hd\controllers;
|
|
|
|
|
|
use bizHd\pd\classes\PdGoodsClass;
|
|
|
+use bizHd\pd\classes\PdGoodsDetailClass;
|
|
|
use Yii;
|
|
|
use common\components\util;
|
|
|
|
|
|
@@ -24,84 +25,55 @@ class PdGoodsController extends BaseController
|
|
|
}
|
|
|
|
|
|
//订单详情
|
|
|
- public function actionDetail()
|
|
|
+ public function actionGetInfo()
|
|
|
{
|
|
|
- $orderSn = Yii::$app->request->get('orderSn', '');
|
|
|
- $orderData = PdGoodsClass::getOrderDetail($orderSn, $this->shopId);
|
|
|
- util::success($orderData);
|
|
|
- }
|
|
|
-
|
|
|
- //盘点确认
|
|
|
- public function actionCreateOrder()
|
|
|
- {
|
|
|
- $post = Yii::$app->request->post();
|
|
|
- $post['sjId'] = $this->sjId;
|
|
|
- $post['shopId'] = $this->shopId;
|
|
|
- $post['adminId'] = $this->adminId;
|
|
|
- $this->saveOrder($post, false, false);
|
|
|
- }
|
|
|
-
|
|
|
- //盘点存草稿
|
|
|
- public function actionCreateDraft()
|
|
|
- {
|
|
|
- $post = Yii::$app->request->post();
|
|
|
- $post['sjId'] = $this->sjId;
|
|
|
- $post['shopId'] = $this->shopId;
|
|
|
- $post['adminId'] = $this->adminId;
|
|
|
-
|
|
|
- $this->saveOrder($post, true, false);
|
|
|
- }
|
|
|
-
|
|
|
- //编辑草稿 ,继续保存草稿
|
|
|
- public function actionUpdateDraft()
|
|
|
- {
|
|
|
- $post = Yii::$app->request->post();
|
|
|
- $post['sjId'] = $this->sjId;
|
|
|
- $post['shopId'] = $this->shopId;
|
|
|
- $post['adminId'] = $this->adminId;
|
|
|
- $orderSn = $post['orderSn'] ?? '';
|
|
|
- $orderData = PdGoodsClass::orderExist($orderSn, $this->shopId);
|
|
|
- if ($orderData['status'] != PdGoodsClass::STATUS_DRAFT) {
|
|
|
- util::fail("订单不存在");
|
|
|
+ $get = Yii::$app->request->get();
|
|
|
+ $orderSn = $get['orderSn'] ?? '';
|
|
|
+ $info = PdGoodsClass::getByCondition(['orderSn' => $orderSn], true);
|
|
|
+ if (empty($info) || $info->mainId != $this->mainId) {
|
|
|
+ util::fail('没有找到盘点记录');
|
|
|
}
|
|
|
- $this->saveOrder($post, true, true);
|
|
|
-
|
|
|
+ $detail = PdGoodsDetailClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
|
|
|
+ $data = ['info' => $info, 'goodsList' => $detail];
|
|
|
+ util::success($data);
|
|
|
}
|
|
|
|
|
|
- //编辑草稿, 确认
|
|
|
- public function actionUpdateOrder()
|
|
|
+ //创建盘点 ssh 20230302
|
|
|
+ public function actionCreateOrder()
|
|
|
{
|
|
|
$post = Yii::$app->request->post();
|
|
|
$post['sjId'] = $this->sjId;
|
|
|
$post['shopId'] = $this->shopId;
|
|
|
+ $staff = $this->shopAdmin;
|
|
|
$post['adminId'] = $this->adminId;
|
|
|
- $orderSn = $post['orderSn'] ?? '';
|
|
|
- $orderData = PdGoodsClass::orderExist($orderSn, $this->shopId);
|
|
|
- if ($orderData['status'] != PdGoodsClass::STATUS_DRAFT) {
|
|
|
- util::fail("订单不存在");
|
|
|
- }
|
|
|
- $this->saveOrder($post, false, true);
|
|
|
- }
|
|
|
-
|
|
|
- protected function saveOrder($post, $draft = false, $update = false)
|
|
|
- {
|
|
|
- $ghsItemInfo = $post['itemInfo'] ?? '';
|
|
|
- if (empty($ghsItemInfo)) {
|
|
|
+ $post['staffName'] = $staff->name ?? '';
|
|
|
+ $post['mainId'] = $this->mainId;
|
|
|
+ $goodsItemInfo = $post['goodsInfo'] ?? '';
|
|
|
+ if (empty($goodsItemInfo)) {
|
|
|
util::fail('请选择花材');
|
|
|
}
|
|
|
- $ghsItemInfo = json_decode($ghsItemInfo, true);
|
|
|
- if (!is_array($ghsItemInfo)) {
|
|
|
- util::fail('花材格式不正确');
|
|
|
+ $goodsItemInfo = json_decode($goodsItemInfo, true);
|
|
|
+ if (!is_array($goodsItemInfo)) {
|
|
|
+ util::fail('商品格式错误');
|
|
|
}
|
|
|
- foreach ($ghsItemInfo as $key => $item) {
|
|
|
+ foreach ($goodsItemInfo as $key => $item) {
|
|
|
//如果盘点数是99999则转为0
|
|
|
- if (isset($item['bigNum']) && $item['bigNum'] == 99999) {
|
|
|
- $ghsItemInfo[$key]['bigNum'] = 0;
|
|
|
+ if (isset($item['num']) && $item['num'] == 99999) {
|
|
|
+ $goodsItemInfo[$key]['num'] = 0;
|
|
|
}
|
|
|
}
|
|
|
- $post['itemInfo'] = $ghsItemInfo;
|
|
|
- PdGoodsClass::opOrder($post, $draft, $update);
|
|
|
- util::complete();
|
|
|
+ $post['goodsInfo'] = $goodsItemInfo;
|
|
|
+ $connection = Yii::$app->db;
|
|
|
+ $transaction = $connection->beginTransaction();
|
|
|
+ try {
|
|
|
+ PdGoodsClass::createPd($post);
|
|
|
+ $transaction->commit();
|
|
|
+ util::complete();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ $transaction->rollBack();
|
|
|
+ Yii::info("操作原因:" . $e->getMessage());
|
|
|
+ util::fail('操作失败');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|