| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- //损耗
- namespace ghs\controllers;
- use common\components\dict;
- use Yii;
- use bizGhs\order\classes\StockWastageOrderClass;
- use common\components\util;
- use bizGhs\product\classes\ProductClass;
- //已中央化
- class WastageController extends BaseController
- {
- //新增损耗
- public function actionCreateOrder()
- {
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('超管才能报损');
- }
- $post = Yii::$app->request->post();
- $post['shopId'] = $this->shopId;
- $post['sjId'] = $this->sjId;
- $post['mainId'] = $this->mainId;
- $post['shopAdminId'] = $this->shopAdminId;
- $shopAdmin = $this->shopAdmin;
- $adminName = $shopAdmin['name'] ?? '';
- $post['shopAdminName'] = $adminName;
- $productJson = $post['product'] ?? '';
- if (empty($productJson)) {
- util::fail('请选择花材');
- }
- $productList = json_decode($productJson, true);
- if (empty($productList)) {
- util::fail('请选择花材');
- }
- //有unitType数据,说明是收银台传过来的数据,转换成和手机端结构一致
- $hasUnitType = array_column($productList, 'unitType');
- if (!empty($hasUnitType)) {
- $newProductList = [];
- foreach ($productList as $key => $val) {
- $unitType = $val['unitType'] ?? 0;
- $bigNum = 0;
- $smallNum = 0;
- $num = $val['num'] ?? 0;
- $id = $val['productId'] ?? 0;
- if ($unitType == dict::getDict('unitType', 'big')) {
- $bigNum = $num;
- } else {
- $smallNum = $num;
- }
- $newProductList[] = ['productId' => $id, 'bigNum' => $bigNum, 'smallNum' => $smallNum, 'classId' => 0, 'itemId' => 0];
- }
- $productList = $newProductList;
- }
- foreach ($productList as $v) {
- $bigNum = $v['bigNum'] ?? 0;
- $smallNum = $v['smallNum'] ?? 0;
- if ($bigNum <= 0 && $smallNum <= 0) {
- util::fail('花材数量不能为0');
- }
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- //判断花材有效性
- ProductClass::valid($productList, $this->mainId);
- $post['product'] = $productList;
- $return = StockWastageOrderClass::addOrder($post, $this->shop, true);
- $transaction->commit();
- util::success($return);
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::info("报损失败原因:" . $e->getMessage());
- util::fail('报损保存失败');
- }
- }
- //列表
- public function actionList()
- {
- $where = [];
- $where['mainId'] = $this->mainId;
- $list = StockWastageOrderClass::getOrderList($where);
- util::success($list);
- }
- public function actionDetail()
- {
- $orderSn = Yii::$app->request->get('orderSn', '');
- $orderData = StockWastageOrderClass::getOrderDetail($orderSn, $this->mainId);
- util::success($orderData);
- }
- }
|