|
|
@@ -9,6 +9,7 @@ use common\components\util;
|
|
|
use Yii;
|
|
|
use bizGhs\base\classes\BaseClass;
|
|
|
use bizGhs\order\traits\OrderTrait;
|
|
|
+
|
|
|
class CheckOrderClass extends BaseClass
|
|
|
{
|
|
|
use OrderTrait;
|
|
|
@@ -22,22 +23,22 @@ class CheckOrderClass extends BaseClass
|
|
|
];
|
|
|
|
|
|
//2021.1.22 linqh 操作订单 添加/保存草稿/草稿编辑保存: 区别在添加是立即改库存和记录流水记录,而保存草稿是只保存订单信息
|
|
|
- public static function opOrder($data,$draft=false,$update=false)
|
|
|
+ public static function opOrder($data, $draft = false, $update = false)
|
|
|
{
|
|
|
$sjId = $data['sjId'];
|
|
|
$shopId = $data['shopId'];
|
|
|
- $adminId = $data['adminId']??0;
|
|
|
- if($draft){
|
|
|
+ $adminId = $data['adminId'] ?? 0;
|
|
|
+ if ($draft) {
|
|
|
//保存草稿
|
|
|
$data['status'] = self::STATUS_DRAFT;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
//确定保存
|
|
|
$data['status'] = self::STATUS_COMPLETE;
|
|
|
}
|
|
|
- if($update){
|
|
|
+ if ($update) {
|
|
|
$orderSn = $data['orderSn'];
|
|
|
- }else{
|
|
|
- $orderSn =orderSn::getGhsCheckSn();
|
|
|
+ } else {
|
|
|
+ $orderSn = orderSn::getGhsCheckSn();
|
|
|
}
|
|
|
|
|
|
$data['orderSn'] = $orderSn;
|
|
|
@@ -49,38 +50,34 @@ class CheckOrderClass extends BaseClass
|
|
|
$data['smallNum'] = $sumNum['smallNum']; //总的小单位数量 总共多少支
|
|
|
$connection = Yii::$app->db;
|
|
|
$transaction = $connection->beginTransaction();
|
|
|
- try{
|
|
|
- if($update){
|
|
|
- //删除 ?? 是否合理,暂时先这样处理
|
|
|
- self::deleteByCondition(['orderSn'=>$orderSn]);
|
|
|
+ try {
|
|
|
+ if ($update) {
|
|
|
+ //更新先删除数据
|
|
|
+ self::deleteByCondition(['orderSn' => $orderSn]);
|
|
|
+ CheckOrderItemClass::deleteByCondition(['orderSn' => $orderSn]);
|
|
|
}
|
|
|
$order = self::add($data);
|
|
|
//写入详情表
|
|
|
- $batchData = self::groupOrderItem($ghsItemInfo,$orderSn);
|
|
|
- if($update){
|
|
|
- //先删除
|
|
|
- CheckOrderItemClass::deleteByCondition(['orderSn'=>$orderSn]);
|
|
|
- }
|
|
|
+ $batchData = self::groupOrderItem($ghsItemInfo, $orderSn);
|
|
|
CheckOrderItemClass::batchAddOrderItem($batchData);
|
|
|
- if($draft===false){
|
|
|
- //非草稿
|
|
|
+ if ($draft === false) {
|
|
|
//盘点完成完成,直接将库存中的数量改为当时盘点的数量
|
|
|
- foreach ($batchData as $v){
|
|
|
+ foreach ($batchData as $v) {
|
|
|
$productId = $v['productId'];
|
|
|
//修改库存数量
|
|
|
$key = ProductClass::LOCK_STOCK . '_' . $productId;
|
|
|
$lock = util::lock($key);
|
|
|
if (!$lock) {
|
|
|
- util::fail("系统繁忙中,请稍后再试!");
|
|
|
+ util::fail("系统繁忙,请稍后再试");
|
|
|
}
|
|
|
$productData = ProductClass::getById($productId);
|
|
|
- ProductClass::updateStockById($productId,$v['itemNum'],$adminId);
|
|
|
+ ProductClass::updateStockById($productId, $v['itemNum'], $adminId);
|
|
|
//上架
|
|
|
if ($v['itemNum'] > 0 && $productData['status'] == 2) {
|
|
|
ProductClass::changeStatus($productId, 1);
|
|
|
}
|
|
|
//下架
|
|
|
- if ($v['itemNum'] <= 0 && $productData['status'] == 1){
|
|
|
+ if ($v['itemNum'] <= 0 && $productData['status'] == 1) {
|
|
|
ProductClass::changeStatus($productId, 2);
|
|
|
}
|
|
|
util::unlock($key);
|
|
|
@@ -93,16 +90,16 @@ class CheckOrderClass extends BaseClass
|
|
|
$record['productId'] = $productId;
|
|
|
$record['itemNum'] = $v['profitLossNum'];//盈亏数
|
|
|
$record['oldStock'] = $productData['stock'];
|
|
|
- $record['newStock'] = $v['itemNum']; //新库存直接等于盘点的数量
|
|
|
+ $record['newStock'] = $v['itemNum']; //新库存直接等于盘点的数量
|
|
|
StockRecordService::addCheckOrderRecord($record);
|
|
|
}
|
|
|
}
|
|
|
$transaction->commit();
|
|
|
return $order;
|
|
|
|
|
|
- }catch (\Exception $exception){
|
|
|
+ } catch (\Exception $exception) {
|
|
|
$transaction->rollBack();
|
|
|
- util::fail('保存失败'.$exception->getMessage());
|
|
|
+ util::fail('保存失败' . $exception->getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -122,9 +119,9 @@ class CheckOrderClass extends BaseClass
|
|
|
|
|
|
//2021.1.22 订单详情
|
|
|
//获取订单详情信息 lqh 2021.1.20
|
|
|
- public static function getOrderDetail($orderSn,$shopId)
|
|
|
+ public static function getOrderDetail($orderSn, $shopId)
|
|
|
{
|
|
|
- $orderData = self::orderExist($orderSn,$shopId);
|
|
|
+ $orderData = self::orderExist($orderSn, $shopId);
|
|
|
$orderInfo = CheckOrderItemClass::getOrderItemDetail($orderSn);
|
|
|
$itemData = [];
|
|
|
|
|
|
@@ -132,19 +129,19 @@ class CheckOrderClass extends BaseClass
|
|
|
$sjId = $orderData['sjId'];
|
|
|
$itemIdClassIdMap = ProductClass::getItemIdClassIdMap($sjId);
|
|
|
|
|
|
- if($orderInfo) {
|
|
|
+ if ($orderInfo) {
|
|
|
foreach ($orderInfo as $v) {
|
|
|
- $info = json_decode($v['itemInfo'],true);
|
|
|
+ $info = json_decode($v['itemInfo'], true);
|
|
|
$tmp = $info;
|
|
|
$tmp['itemCover'] = self::groupImg($info['itemCover']);
|
|
|
unset($v['itemInfo']);
|
|
|
- if(!isset($tmp['rank'])){
|
|
|
- $tmp['rank']= 'B';
|
|
|
+ if (!isset($tmp['rank'])) {
|
|
|
+ $tmp['rank'] = 'B';
|
|
|
}
|
|
|
|
|
|
- $tmp = array_merge($tmp,$v);
|
|
|
+ $tmp = array_merge($tmp, $v);
|
|
|
$tmp['id'] = $v['productId'];
|
|
|
- $tmp['classId'] = $itemIdClassIdMap[$v['itemId']]??0;
|
|
|
+ $tmp['classId'] = $itemIdClassIdMap[$v['itemId']] ?? 0;
|
|
|
$itemData[] = $tmp;
|
|
|
}
|
|
|
}
|
|
|
@@ -155,21 +152,21 @@ class CheckOrderClass extends BaseClass
|
|
|
}
|
|
|
|
|
|
//2021.1.22 linqh 判断订单号是否存在
|
|
|
- public static function orderExist($orderSn,$shopId)
|
|
|
+ public static function orderExist($orderSn, $shopId)
|
|
|
{
|
|
|
$where = [
|
|
|
- 'orderSn'=>$orderSn,
|
|
|
- 'shopId'=>$shopId,
|
|
|
+ 'orderSn' => $orderSn,
|
|
|
+ 'shopId' => $shopId,
|
|
|
];
|
|
|
$orderData = self::getByCondition($where);
|
|
|
- if(!$orderData) {
|
|
|
+ if (!$orderData) {
|
|
|
util::fail('订单不存在');
|
|
|
}
|
|
|
return $orderData;
|
|
|
}
|
|
|
|
|
|
// 组装 orderItem linqh 2021.1.25
|
|
|
- public static function groupOrderItem($ghsItemInfo,$orderSn)
|
|
|
+ public static function groupOrderItem($ghsItemInfo, $orderSn)
|
|
|
{
|
|
|
$productData = self::getProductMapData($ghsItemInfo);
|
|
|
// $itemIds = array_column($productData,'itemId');
|
|
|
@@ -177,35 +174,35 @@ class CheckOrderClass extends BaseClass
|
|
|
//$itemData = array_column($itemData, NULL, 'id');
|
|
|
//写入详情表
|
|
|
$batchData = [];
|
|
|
- foreach($ghsItemInfo as $v){
|
|
|
+ foreach ($ghsItemInfo as $v) {
|
|
|
$tmp = [];
|
|
|
$productId = $v['productId'];
|
|
|
$itemId = $productData[$productId]['itemId'];
|
|
|
- $rank = $productData[$productId]['rank']??'B';// 花材级别
|
|
|
+ $rank = $productData[$productId]['rank'] ?? 'B';// 花材级别
|
|
|
$tmp['orderSn'] = $orderSn;
|
|
|
$tmp['itemId'] = $itemId;
|
|
|
$tmp['productId'] = $v['productId'];
|
|
|
- $unitNum = $productData[$productId]['ratio']??0;
|
|
|
- $tmp['itemStock'] = $productData[$productId]['stock']??0;//当时库存
|
|
|
- $tmp['itemNum'] = ProductClass::mergeItemNum($v['bigNum'],$v['smallNum'],$unitNum);// 盘点数量
|
|
|
- $tmp['itemPrice'] =$productData[$productId]['price']??0; //当时售卖的价格
|
|
|
- $tmp['itemCost'] =$productData[$productId]['cost']??0; //当时成本的价格
|
|
|
- $tmp['profitLossNum'] = bcsub( $tmp['itemNum'],$tmp['itemStock'],2); //盈亏数 = 盘点数-当时库存数
|
|
|
- $stockFormat= ProductClass::formatStock($tmp['itemStock'],$unitNum); // 库存总单位数量转大小单位的数量
|
|
|
+ $unitNum = $productData[$productId]['ratio'] ?? 0;
|
|
|
+ $tmp['itemStock'] = $productData[$productId]['stock'] ?? 0;//当时库存
|
|
|
+ $tmp['itemNum'] = ProductClass::mergeItemNum($v['bigNum'], $v['smallNum'], $unitNum);// 盘点数量
|
|
|
+ $tmp['itemPrice'] = $productData[$productId]['price'] ?? 0; //当时售卖的价格
|
|
|
+ $tmp['itemCost'] = $productData[$productId]['cost'] ?? 0; //当时成本的价格
|
|
|
+ $tmp['profitLossNum'] = bcsub($tmp['itemNum'], $tmp['itemStock'], 2); //盈亏数 = 盘点数-当时库存数
|
|
|
+ $stockFormat = ProductClass::formatStock($tmp['itemStock'], $unitNum); // 库存总单位数量转大小单位的数量
|
|
|
$itemInfo = [
|
|
|
- 'itemName'=> $productData[$productId]['name']??'',//花材名称
|
|
|
- 'itemCover'=> $productData[$productId]['cover']??'',//花材图片
|
|
|
- 'bigNum'=> $v['bigNum']??0,//数量(大单位)
|
|
|
- 'smallNum'=> $v['smallNum']??0,//数量(小单位)
|
|
|
- 'bigNumStock'=> $stockFormat['bigNum'],// 当时库存大单位数
|
|
|
- 'smallNumStock'=> $stockFormat['smallNum'],//当时库存 小单位数
|
|
|
- 'bigNumProfitLoss'=>bcsub($v['bigNum'],$stockFormat['bigNum']),//大单位的盈亏
|
|
|
- 'smallNumProfitLoss'=>bcsub($v['smallNum'],$stockFormat['smallNum']),//小单位的盈亏
|
|
|
- 'itemUnit'=> $unitNum?2:1,//单位
|
|
|
- 'ratio'=>$unitNum,// 比例
|
|
|
- 'rank'=>$rank,// 花材级别
|
|
|
- 'bigUnit'=> $productData[$productId]['bigUnit'],//大单位名称 扎
|
|
|
- 'smallUnit'=> $productData[$productId]['smallUnit'],//小单位名称 支
|
|
|
+ 'itemName' => $productData[$productId]['name'] ?? '',//花材名称
|
|
|
+ 'itemCover' => $productData[$productId]['cover'] ?? '',//花材图片
|
|
|
+ 'bigNum' => $v['bigNum'] ?? 0,//数量(大单位)
|
|
|
+ 'smallNum' => $v['smallNum'] ?? 0,//数量(小单位)
|
|
|
+ 'bigNumStock' => $stockFormat['bigNum'],// 当时库存大单位数
|
|
|
+ 'smallNumStock' => $stockFormat['smallNum'],//当时库存 小单位数
|
|
|
+ 'bigNumProfitLoss' => bcsub($v['bigNum'], $stockFormat['bigNum']),//大单位的盈亏
|
|
|
+ 'smallNumProfitLoss' => bcsub($v['smallNum'], $stockFormat['smallNum']),//小单位的盈亏
|
|
|
+ 'itemUnit' => $unitNum ? 2 : 1,//单位
|
|
|
+ 'ratio' => $unitNum,// 比例
|
|
|
+ 'rank' => $rank,// 花材级别
|
|
|
+ 'bigUnit' => $productData[$productId]['bigUnit'],//大单位名称 扎
|
|
|
+ 'smallUnit' => $productData[$productId]['smallUnit'],//小单位名称 支
|
|
|
];
|
|
|
$tmp['itemInfo'] = json_encode($itemInfo);
|
|
|
$batchData[] = $tmp;
|
|
|
@@ -226,7 +223,7 @@ class CheckOrderClass extends BaseClass
|
|
|
// 获取状态码名称
|
|
|
public static function getStatusName($status)
|
|
|
{
|
|
|
- return self::$statusMap[$status]??'';
|
|
|
+ return self::$statusMap[$status] ?? '';
|
|
|
}
|
|
|
|
|
|
}
|