| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace ghs\controllers;
- use biz\ghs\classes\GhsClass;
- use bizGhs\order\classes\PurchaseOrderClass;
- use bizGhs\product\classes\ProductClass;
- use common\components\util;
- use Yii;
- class PurchaseOrderController extends BaseController
- {
- //新增采购订单
- public function actionCreateOrder()
- {
- $post = Yii::$app->request->post();
- $post['sjId'] = $this->sjId;
- $post['shopId'] = $this->shopId;
- $post['adminId'] = $this->adminId;
- $ghsItemInfo = $post['itemInfo'] ?? '';
- if (empty($ghsItemInfo)) {
- util::fail('请选择花材');
- }
- $ghsItemInfo = json_decode($ghsItemInfo, true); // [{productId:0,itemPrice:1,bigNum:1,smallNum:0}]
- if (!is_array($ghsItemInfo)) {
- util::fail('花材格式不正确');
- }
- //合并
- $ghsItemInfo = PurchaseOrderClass::mergeItemInfo($ghsItemInfo);
- //判断花材格式,是否属于当前门店
- ProductClass::valid($ghsItemInfo, $this->shopId);
- //获取供应商信息
- $ghsId = $post['ghsId'];
- if (empty($ghsId)) {
- util::fail("请选择供应商");
- }
- $ghsInfo = GhsClass::getGhsInfo($ghsId);
- GhsClass::valid($ghsInfo, $this->shopId);
- $post['ghsInfo'] = json_encode($ghsInfo);
- //判断花材里的信息
- //判定重量
- $weight = 0;
- foreach ($ghsItemInfo as $v) {
- $bigNum = $v['bigNum'] ?? 0;
- $productId = $v['productId'] ?? 0;
- $smallNum = $v['smallNum'] ?? 0;
- if (!isset($v['itemPrice'])) {
- util::fail('采购价格不能为空');
- }
- if (!$productId) {
- util::fail('花材不存在');
- }
- if ($bigNum <= 0 && $smallNum <= 0) {
- util::fail('花材数量不能为0');
- }
- if (getenv('YII_ENV', 'local') == 'production') {
- $currentWeight = $v['weight'] ?? 0;
- } else {
- $currentWeight = 0.6;
- }
- $weight = bcadd($weight, $currentWeight, 2);
- }
- if ($weight <= 0) {
- util::fail('请填写重量');
- }
- $post['itemInfo'] = $ghsItemInfo;
- $post['debt'] = PurchaseOrderClass::DEBT_YES;
- $order = PurchaseOrderClass::addOrder($post);
- if ($order) {
- util::success($order);
- }
- util::fail();
- }
- //订单列表
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $orderStatus = $get['status'] ?? '';
- if ($orderStatus) {
- $where['status'] = $orderStatus;
- }
- $where['sjId'] = $this->sjId;
- $where['shopId'] = $this->shopId;
- $data = PurchaseOrderClass::getOrderList($where);
- //状态统计
- $statData = PurchaseOrderClass::statNum($this->shopId);
- $data = array_merge($data, $statData);
- util::success($data);
- }
- //订单详情
- public function actionDetail()
- {
- $orderSn = Yii::$app->request->get('orderSn', '');
- $orderData = PurchaseOrderClass::getOrderDetail($orderSn, $this->shopId);
- util::success($orderData);
- }
- }
|