|
|
@@ -4,6 +4,7 @@ namespace bizHd\purchase\classes;
|
|
|
|
|
|
use biz\ghs\classes\GhsClass;
|
|
|
use biz\ghs\models\Ghs;
|
|
|
+use biz\shop\classes\ShopClass;
|
|
|
use biz\shop\models\Shop;
|
|
|
use bizGhs\admin\classes\AdminClass;
|
|
|
use bizGhs\custom\classes\CustomClass;
|
|
|
@@ -13,6 +14,7 @@ use bizGhs\product\classes\ProductClass;
|
|
|
use bizGhs\order\classes\OrderClass;
|
|
|
use common\components\dict;
|
|
|
use common\components\orderSn;
|
|
|
+use common\components\stringUtil;
|
|
|
use common\components\util;
|
|
|
use bizHd\base\classes\BaseClass;
|
|
|
|
|
|
@@ -40,7 +42,6 @@ class PurchaseClass extends BaseClass
|
|
|
$orderSn = orderSn::getPurchaseSn();
|
|
|
$data['orderSn'] = $orderSn;
|
|
|
$prePrice = 0;
|
|
|
- $actPrice = 0;
|
|
|
|
|
|
$data['sendTimeWant'] = date("Y-m-d") . ' ' . $data['sendTime'];
|
|
|
unset($data['sendTime']);
|
|
|
@@ -61,31 +62,31 @@ class PurchaseClass extends BaseClass
|
|
|
$smallNum = 0; //总共多少支
|
|
|
foreach ($productList as $key => $product) {
|
|
|
|
|
|
- $bigNum += $product['bigNum']??0;
|
|
|
- $smallNum += $product['smallNum']??0;
|
|
|
+ $bigNum += $product['bigNum'] ?? 0;
|
|
|
+ $smallNum += $product['smallNum'] ?? 0;
|
|
|
$productList[$key]['orderSn'] = $orderSn;
|
|
|
$productId = $product['productId'];
|
|
|
- $ratio = $productData[$productId]['ratio']??0;
|
|
|
- $itemId = $productData[$productId]['itemId']??0;
|
|
|
- $rank = $productData[$productId]['rank']??'B';// 花材级别
|
|
|
- $stock = $productData[$productId]['stock']??0;//当时库存
|
|
|
- $stockFormat= ProductClass::formatStock($stock,$ratio);
|
|
|
+ $ratio = $productData[$productId]['ratio'] ?? 0;
|
|
|
+ $itemId = $productData[$productId]['itemId'] ?? 0;
|
|
|
+ $rank = $productData[$productId]['rank'] ?? 'B';// 花材级别
|
|
|
+ $stock = $productData[$productId]['stock'] ?? 0;//当时库存
|
|
|
+ $stockFormat = ProductClass::formatStock($stock, $ratio);
|
|
|
|
|
|
- $itemNum = ProductClass::mergeItemNum($product['bigNum'],$product['smallNum'],$ratio);//采购数量
|
|
|
+ $itemNum = ProductClass::mergeItemNum($product['bigNum'], $product['smallNum'], $ratio);//采购数量
|
|
|
$price = $productData[$productId]['price']; //卖的单价
|
|
|
- $sellPrice = bcmul($itemNum,$price,2); //采购总价
|
|
|
+ $sellPrice = bcmul($itemNum, $price, 2); //采购总价
|
|
|
$itemInfo = [
|
|
|
- 'itemName'=> $productData[$productId]['name']??'',//花材名称
|
|
|
- 'itemCover'=> $productData[$productId]['cover']??'',//花材图片
|
|
|
- 'bigNum'=> $product['bigNum']??0,//采购数量(大单位)
|
|
|
- 'smallNum'=> $product['smallNum']??0,//采购数量(小单位)
|
|
|
- 'bigNumStock'=> $stockFormat['bigNum'],// 当时库存大单位数
|
|
|
- 'smallNumStock'=> $stockFormat['smallNum'],//当时库存 小单位数
|
|
|
- 'itemUnit'=> $ratio?2:1,//单位
|
|
|
- 'ratio'=>$ratio,// 比例
|
|
|
- 'rank'=>$rank,// 花材级别
|
|
|
- 'bigUnit'=> $productData[$productId]['bigUnit'],//大单位名称 扎
|
|
|
- 'smallUnit'=> $productData[$productId]['smallUnit'],//小单位名称 支
|
|
|
+ 'itemName' => $productData[$productId]['name'] ?? '',//花材名称
|
|
|
+ 'itemCover' => $productData[$productId]['cover'] ?? '',//花材图片
|
|
|
+ 'bigNum' => $product['bigNum'] ?? 0,//采购数量(大单位)
|
|
|
+ 'smallNum' => $product['smallNum'] ?? 0,//采购数量(小单位)
|
|
|
+ 'bigNumStock' => $stockFormat['bigNum'],// 当时库存大单位数
|
|
|
+ 'smallNumStock' => $stockFormat['smallNum'],//当时库存 小单位数
|
|
|
+ 'itemUnit' => $ratio ? 2 : 1,//单位
|
|
|
+ 'ratio' => $ratio,// 比例
|
|
|
+ 'rank' => $rank,// 花材级别
|
|
|
+ 'bigUnit' => $productData[$productId]['bigUnit'],//大单位名称 扎
|
|
|
+ 'smallUnit' => $productData[$productId]['smallUnit'],//小单位名称 支
|
|
|
];
|
|
|
|
|
|
$productList[$key]['itemInfo'] = json_encode($itemInfo);
|
|
|
@@ -94,9 +95,9 @@ class PurchaseClass extends BaseClass
|
|
|
$productList[$key]['price'] = $price;
|
|
|
$productList[$key]['ratio'] = $ratio;
|
|
|
$productList[$key]['totalPrice'] = $sellPrice;
|
|
|
- $prePrice = bcadd($prePrice,$sellPrice,2);
|
|
|
+ $prePrice = bcadd($prePrice, $sellPrice, 2);
|
|
|
}
|
|
|
- $prePrice = bcadd($prePrice,$data['sendCost'],2);
|
|
|
+ $prePrice = bcadd($prePrice, $data['sendCost'], 2);
|
|
|
$actPrice = $prePrice;
|
|
|
$data['prePrice'] = $prePrice;
|
|
|
$data['actPrice'] = $actPrice;
|
|
|
@@ -107,7 +108,6 @@ class PurchaseClass extends BaseClass
|
|
|
util::fail('请选择花材');
|
|
|
}
|
|
|
|
|
|
-
|
|
|
PurchaseItemClass::batchAdd($productList);
|
|
|
|
|
|
//供货商增加订单
|
|
|
@@ -116,6 +116,9 @@ class PurchaseClass extends BaseClass
|
|
|
util::fail('没有找到供货商');
|
|
|
}
|
|
|
$ghs = GhsClass::getGhsInfo($ghsId);
|
|
|
+ if (empty($ghs)) {
|
|
|
+ util::fail('还是没有找到供货商');
|
|
|
+ }
|
|
|
$ghsSjId = $ghs['sjId'] ?? 0;
|
|
|
$ghsShopId = $ghs['shopId'] ?? 0;
|
|
|
$getType = $data['getType'] ?? 0;
|
|
|
@@ -123,7 +126,28 @@ class PurchaseClass extends BaseClass
|
|
|
|
|
|
$custom = CustomClass::getByCondition(['ownSjId' => $ghsSjId, 'sjId' => $hdSjId, 'shopId' => $hdShopId]);
|
|
|
if (empty($custom)) {
|
|
|
- util::fail('没有找到客户');
|
|
|
+ $hdShop = ShopClass::getShopInfo($hdShopId);
|
|
|
+ $name = $hdShop['shopName'] ?? '';
|
|
|
+ $py = stringUtil::py($name);
|
|
|
+ $mobile = $hdShop['mobile'];
|
|
|
+ $customData = [
|
|
|
+ 'sjId' => $hdSjId,
|
|
|
+ 'shopId' => $hdShopId,
|
|
|
+ 'ownSjId' => $ghsSjId,
|
|
|
+ 'name' => $name,
|
|
|
+ 'py' => $py,
|
|
|
+ 'mobile' => $mobile,
|
|
|
+ 'city' => $shop['city'] ?? '',
|
|
|
+ 'dist' => $shop['dist'] ?? '',
|
|
|
+ 'address' => $shop['address'] ?? '',
|
|
|
+ 'fullAddress' => $shop['fullAddress'] ?? '',
|
|
|
+ 'long' => $shop['long'] ?? '',
|
|
|
+ 'lat' => $shop['lat'] ?? '',
|
|
|
+ ];
|
|
|
+ $custom = CustomClass::addCustom($customData);
|
|
|
+ }
|
|
|
+ if (empty($custom)) {
|
|
|
+ util::fail('还是没有找到客户');
|
|
|
}
|
|
|
$customId = $custom['id'] ?? 0;
|
|
|
$customName = $custom['name'] ?? '';
|
|
|
@@ -195,18 +219,18 @@ class PurchaseClass extends BaseClass
|
|
|
$orderSn = $val['orderSn'];
|
|
|
$orderItem = PurchaseItemClass::getOrderItemDetail($orderSn);
|
|
|
$itemData = [];
|
|
|
- if($orderItem) {
|
|
|
+ if ($orderItem) {
|
|
|
foreach ($orderItem as $v) {
|
|
|
- $info = json_decode($v['itemInfo'],true);
|
|
|
+ $info = json_decode($v['itemInfo'], true);
|
|
|
$tmp = $info;
|
|
|
$tmp['cover'] = self::groupImg($info['itemCover']);
|
|
|
unset($v['itemInfo']);
|
|
|
//兼容 旧数据,没有 rank (花材等级 默认给B)
|
|
|
- if(!isset($tmp['rank'])){
|
|
|
- $tmp['rank']= 'B';
|
|
|
+ if (!isset($tmp['rank'])) {
|
|
|
+ $tmp['rank'] = 'B';
|
|
|
}
|
|
|
$tmp['name'] = $tmp['itemName'];
|
|
|
- $tmp = array_merge($tmp,$v);
|
|
|
+ $tmp = array_merge($tmp, $v);
|
|
|
$itemData[] = $tmp;
|
|
|
}
|
|
|
}
|