|
|
@@ -13,6 +13,7 @@ use bizGhs\order\traits\OrderTrait;
|
|
|
use bizGhs\stock\services\StockRecordService;
|
|
|
use bizGhs\product\classes\ProductClass;
|
|
|
use common\components\dict;
|
|
|
+use common\components\imgUtil;
|
|
|
use common\components\orderSn;
|
|
|
use common\components\util;
|
|
|
use Yii;
|
|
|
@@ -52,30 +53,39 @@ class PurchaseOrderClass extends BaseClass
|
|
|
$data['status'] = self::PURCHASE_ORDER_STATUS_COMPLETE;
|
|
|
$orderSn = orderSn::getGhsPurchaseSn();
|
|
|
$data['orderSn'] = $orderSn;
|
|
|
- //数据结构 [{itemId:0,bigNum:0,smallNum:0,productId:1.0,itemPrice:1,weight:1}]
|
|
|
+ //数据结构 [{itemId:0,bigNum:0,smallNum:0,productId:12,itemPrice:1,weight:1}]
|
|
|
$ghsItemInfo = $data['itemInfo'];
|
|
|
$ghsItemInfo = self::mergeItemInfo($ghsItemInfo);
|
|
|
- //计算出总共多少扎,多少支
|
|
|
- $bigNum = 0; //总共多少扎
|
|
|
- $smallNum = 0; //总共多少支
|
|
|
+ //总共多少扎
|
|
|
+ $bigNum = 0;
|
|
|
+ //总共多少支
|
|
|
+ $smallNum = 0;
|
|
|
$totalItemPrice = 0;
|
|
|
- //花材中总重量
|
|
|
$totalWeight = 0;
|
|
|
$ghsItemInfoMap = [];
|
|
|
- if (!empty($ghsItemInfo)) {
|
|
|
- foreach ($ghsItemInfo as $v) {
|
|
|
- $bigNum += $v['bigNum'] ?? 0;
|
|
|
- $smallNum += $v['smallNum'] ?? 0;
|
|
|
- $totalItemPrice = bcadd($totalItemPrice, $v['itemPrice'], 2);
|
|
|
- $ghsItemInfoMap[$v['productId']] = $v;
|
|
|
- if (getenv('YII_ENV') == 'production') {
|
|
|
- $weight = $v['weight'] ?? 0;
|
|
|
- } else {
|
|
|
- $weight = $v['weight'] ?? 0;
|
|
|
- }
|
|
|
- $totalWeight = bcadd($totalWeight, $weight, 2);
|
|
|
+
|
|
|
+ $productIds = array_column($ghsItemInfo, 'productId');
|
|
|
+ $productIds = array_unique(array_filter($productIds));
|
|
|
+ $productList = ProductClass::getByIds($productIds, null, 'id');
|
|
|
+
|
|
|
+ foreach ($ghsItemInfo as $v) {
|
|
|
+ if (isset($v['bigNum']) == false || $v['bigNum'] <= 0) {
|
|
|
+ util::fail('请填写数量');
|
|
|
}
|
|
|
+ if (isset($v['itemPrice']) == false || $v['itemPrice'] <= 0) {
|
|
|
+ util::fail('请填写价格');
|
|
|
+ }
|
|
|
+ $bigNum += $v['bigNum'] ?? 0;
|
|
|
+ $smallNum += $v['smallNum'] ?? 0;
|
|
|
+ $currentTotalPrice = bcmul($v['bigNum'], $v['itemPrice'], 2);
|
|
|
+ $totalItemPrice = bcadd($totalItemPrice, $currentTotalPrice, 2);
|
|
|
+ $ghsItemInfoMap[$v['productId']] = $v;
|
|
|
+ $currentProductId = $v['productId'] ?? 0;
|
|
|
+ $currentWeight = $productList[$currentProductId]['weight'] ?? 0;
|
|
|
+ $weight = bcmul($currentWeight, $v['bigNum'], 2);
|
|
|
+ $totalWeight = bcadd($totalWeight, $weight, 2);
|
|
|
}
|
|
|
+
|
|
|
$data['bigNum'] = $bigNum;
|
|
|
$data['smallNum'] = $smallNum;
|
|
|
$data['price'] = $totalItemPrice;
|
|
|
@@ -99,7 +109,6 @@ class PurchaseOrderClass extends BaseClass
|
|
|
|
|
|
//提货费和本地运费
|
|
|
$paidPrice = bcadd($localCharge, $pickCharge, 2);
|
|
|
-
|
|
|
$yfPayWay = $data['yfPayWay'] ?? self::YF_PAY_WAY_JF;
|
|
|
//打包费
|
|
|
$currentPrice = bcadd($totalItemPrice, $packingCharge, 2);
|
|
|
@@ -126,9 +135,7 @@ class PurchaseOrderClass extends BaseClass
|
|
|
$currentPrice = $modifyPrice;
|
|
|
}
|
|
|
}
|
|
|
- //实付款
|
|
|
$data['actPrice'] = $currentPrice;
|
|
|
- //实付款,扣除平台补贴
|
|
|
$data['realPrice'] = $currentPrice;
|
|
|
$data['paidPrice'] = $paidPrice;
|
|
|
|
|
|
@@ -150,12 +157,10 @@ class PurchaseOrderClass extends BaseClass
|
|
|
$data['cgStyle'] = dict::getDict('cgStyle', 'ghs');
|
|
|
$order = self::add($data);
|
|
|
|
|
|
- //采购支出
|
|
|
-
|
|
|
//组装详情表数据
|
|
|
$batchData = self::groupOrderItem($ghsItemInfo, $orderSn);
|
|
|
|
|
|
- //现在暂时点击确定,完成 加库存
|
|
|
+ //加库存
|
|
|
foreach ($batchData as $currentKey => $v) {
|
|
|
$itemId = $v['itemId'];
|
|
|
$productId = $v['productId'];
|
|
|
@@ -173,31 +178,24 @@ class PurchaseOrderClass extends BaseClass
|
|
|
//加库存
|
|
|
ProductClass::addStockByItemNum($productId, $v['itemNum']);
|
|
|
|
|
|
- //单位采购价=总的采购价/扎数
|
|
|
- $unitCgPrice = 0;
|
|
|
- if ($v['itemNum'] > 0) {
|
|
|
- $unitCgPrice = bcdiv($v['itemPrice'], $v['itemNum'], 2);
|
|
|
- }
|
|
|
- //2021-06-11 修改每扎运费计算
|
|
|
- $itemInfoTmp = json_decode($v['itemInfo'], true);
|
|
|
- //花材的重量
|
|
|
- $productWeight = $itemInfoTmp['itemWeight'] ?? 0;
|
|
|
+ //单位采购价
|
|
|
+ $unitCgPrice = $v['itemPrice'] ?? 0;
|
|
|
+ $productWeight = $productList[$productId]['weight'] ?? 0;
|
|
|
$unitFreight = bcmul($avgKgWeight, $productWeight, 2);
|
|
|
$unitCost = bcadd($unitCgPrice, $unitFreight, 2);
|
|
|
- //2021.6.21 成本价改为四舍五入取整数
|
|
|
+ //成本价四舍五入取整数
|
|
|
$unitCost = round($unitCost);
|
|
|
-
|
|
|
- $batchData[$currentKey]['bigPrice'] = $unitCgPrice;
|
|
|
$batchData[$currentKey]['bigFreight'] = $unitFreight;
|
|
|
|
|
|
- //采购之后全部变成自动调价
|
|
|
+ $currentCover = $productList[$productId]['cover'] ?? '';
|
|
|
+ $currentName = $productList[$productId]['name'] ?? '';
|
|
|
+ $batchData[$currentKey]['cover'] = $currentCover;
|
|
|
+ $batchData[$currentKey]['name'] = $currentName;
|
|
|
+
|
|
|
$product = ProductClass::getLockById($productId);
|
|
|
$product->cost = $unitCost;
|
|
|
$product->priceLabel = ProductClass::PRICE_LABEL_AUTO;
|
|
|
$product->save();
|
|
|
-
|
|
|
- //触发自动调价 2021.4.26 linqh
|
|
|
- //ProductClass::autoPriceById($productId);
|
|
|
}
|
|
|
|
|
|
//写入详情表
|
|
|
@@ -316,19 +314,12 @@ class PurchaseOrderClass extends BaseClass
|
|
|
util::fail('订单不存在');
|
|
|
}
|
|
|
$orderInfo = PurchaseOrderItemClass::getOrderItemDetail($orderSn);
|
|
|
- $itemData = [];
|
|
|
if ($orderInfo) {
|
|
|
- foreach ($orderInfo as $v) {
|
|
|
- $info = json_decode($v['itemInfo'], true);
|
|
|
- $tmp = $info;
|
|
|
- $tmp['itemCover'] = self::groupImg($info['itemCover']);
|
|
|
- unset($v['itemInfo']);
|
|
|
- //兼容 旧数据,没有 rank (花材等级 默认给B)
|
|
|
- if (!isset($tmp['rank'])) {
|
|
|
- $tmp['rank'] = 'B';
|
|
|
- }
|
|
|
- $tmp = array_merge($tmp, $v);
|
|
|
- $itemData[] = $tmp;
|
|
|
+ foreach ($orderInfo as $key => $val) {
|
|
|
+ $shortCover = $val['cover'] ?? '';
|
|
|
+ $orderInfo[$key]['ShortCover'] = $shortCover;
|
|
|
+ $orderInfo[$key]['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
|
|
|
+ $orderInfo[$key]['bigCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";;
|
|
|
}
|
|
|
}
|
|
|
$orderData = self::groupAdmin($orderData);
|
|
|
@@ -340,7 +331,7 @@ class PurchaseOrderClass extends BaseClass
|
|
|
$orderData['supplierMobile'] = $ghsInfo['mobile'] ?? '';
|
|
|
$orderData['supplierAddress'] = $ghsInfo['address'] ?? '';
|
|
|
$orderData['debtAmount'] = $ghsInfo['debtAmount'] ?? 0;
|
|
|
- $orderData['itemInfo'] = $itemData;
|
|
|
+ $orderData['itemInfo'] = $orderInfo;
|
|
|
$orderData['statusName'] = self::getStatusName($orderData['status']);
|
|
|
|
|
|
return $orderData;
|
|
|
@@ -350,37 +341,18 @@ class PurchaseOrderClass extends BaseClass
|
|
|
public static function groupOrderItem($ghsItemInfo, $orderSn)
|
|
|
{
|
|
|
$productData = self::getProductMapData($ghsItemInfo);
|
|
|
- //写入详情表
|
|
|
$batchData = [];
|
|
|
foreach ($ghsItemInfo as $v) {
|
|
|
$tmp = [];
|
|
|
$productId = $v['productId'];
|
|
|
$itemId = $productData[$productId]['itemId'];
|
|
|
- $rank = $productData[$productId]['rank'] ?? 'B';// 花材级别
|
|
|
$tmp['orderSn'] = $orderSn;
|
|
|
$tmp['itemId'] = $itemId;
|
|
|
$tmp['productId'] = $v['productId'];
|
|
|
- $ratio = $productData[$productId]['ratio'] ?? 0;
|
|
|
$tmp['itemStock'] = $productData[$productId]['stock'] ?? 0;//当时库存
|
|
|
- $tmp['itemNum'] = ProductClass::mergeItemNum($v['bigNum'], $v['smallNum'], $ratio);// 采购数量
|
|
|
- $tmp['itemPrice'] = $v['itemPrice']; //采购价格
|
|
|
- $stockFormat = ProductClass::formatStock($tmp['itemStock'], $ratio); // 库存总单位数量转大小单位的数量
|
|
|
- $itemInfo = [
|
|
|
- 'itemName' => $productData[$productId]['name'] ?? '',//花材名称
|
|
|
- 'itemCover' => $productData[$productId]['cover'] ?? '',//花材图片
|
|
|
- 'bigNum' => $v['bigNum'] ?? 0,//采购数量(大单位)
|
|
|
- 'smallNum' => $v['smallNum'] ?? 0,//采购数量(小单位)
|
|
|
- 'bigNumStock' => $stockFormat['bigNum'],// 当时库存大单位数
|
|
|
- 'smallNumStock' => $stockFormat['smallNum'],//当时库存 小单位数
|
|
|
- 'itemUnit' => $ratio ? 2 : 1,//单位
|
|
|
- 'ratio' => $ratio,// 比例
|
|
|
- 'rank' => $rank,// 花材级别
|
|
|
- 'bigUnit' => $productData[$productId]['bigUnit'],//大单位名称 扎
|
|
|
- 'smallUnit' => $productData[$productId]['smallUnit'],//小单位名称 支
|
|
|
- 'purchaseWeight' => $v['weight'] ?? 0, //采购重量
|
|
|
- 'itemWeight' => $productData[$productId]['weight'] ?? 0,
|
|
|
- ];
|
|
|
- $tmp['itemInfo'] = json_encode($itemInfo);
|
|
|
+ $tmp['itemNum'] = $v['bigNum'];
|
|
|
+ $tmp['bigPrice'] = $v['itemPrice'];
|
|
|
+ $tmp['totalPrice'] = bcmul($v['itemPrice'], $tmp['itemNum'], 2);
|
|
|
$batchData[] = $tmp;
|
|
|
}
|
|
|
return $batchData;
|