| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace hd\controllers;
- use bizHd\pd\classes\PdGoodsClass;
- use bizHd\pd\classes\PdGoodsDetailClass;
- use Yii;
- use common\components\util;
- class PdGoodsController extends BaseController
- {
- //订单列表 ssh 20230302
- 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 = PdGoodsClass::getPdList($where);
- util::success($list);
- }
- //订单详情
- public function actionGetInfo()
- {
- $get = Yii::$app->request->get();
- $orderSn = $get['orderSn'] ?? '';
- $info = PdGoodsClass::getByCondition(['orderSn' => $orderSn], true);
- if (empty($info) || $info->mainId != $this->mainId) {
- util::fail('没有找到盘点记录');
- }
- $detail = PdGoodsDetailClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- $data = ['info' => $info, 'goodsList' => $detail];
- util::success($data);
- }
- //创建盘点 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;
- $post['staffName'] = $staff->name ?? '';
- $post['mainId'] = $this->mainId;
- $goodsItemInfo = $post['goodsInfo'] ?? '';
- if (empty($goodsItemInfo)) {
- util::fail('请选择花材');
- }
- $goodsItemInfo = json_decode($goodsItemInfo, true);
- if (!is_array($goodsItemInfo)) {
- util::fail('商品格式错误');
- }
- foreach ($goodsItemInfo as $key => $item) {
- //如果盘点数是99999则转为0
- if (isset($item['num']) && $item['num'] == 99999) {
- $goodsItemInfo[$key]['num'] = 0;
- }
- }
- $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('操作失败');
- }
- }
- }
|