|
|
@@ -8,8 +8,11 @@ use biz\pt\classes\PtYeChangeClass;
|
|
|
use biz\shop\classes\ShopCapitalClass;
|
|
|
use biz\shop\classes\ShopClass;
|
|
|
use biz\shop\classes\ShopYeChangeClass;
|
|
|
+use bizGhs\product\classes\ProductClass;
|
|
|
+use bizGhs\stock\classes\StockRecordClass;
|
|
|
use bizHd\base\services\BaseService;
|
|
|
use bizHd\cg\classes\CgRefundClass;
|
|
|
+use bizHd\cg\classes\CgRefundItemClass;
|
|
|
use bizHd\purchase\classes\PurchaseClass;
|
|
|
use bizHd\stat\classes\StatIncomeClass;
|
|
|
use bizHd\wx\classes\WxOpenClass;
|
|
|
@@ -36,7 +39,7 @@ class CgRefundService extends BaseService
|
|
|
util::fail('第三方支付订单号没有找到');
|
|
|
}
|
|
|
$refundOrderSn = orderSn::getCgRefundSn();
|
|
|
- $post['orderSn'] = $refundOrderSn;
|
|
|
+ //$post['orderSn'] = $refundOrderSn;
|
|
|
$post['cgId'] = $cg->id;
|
|
|
$refundPrice = $post['price'] ?? 0;
|
|
|
if (is_numeric($refundPrice) == false || $refundPrice < 0) {
|
|
|
@@ -44,13 +47,61 @@ class CgRefundService extends BaseService
|
|
|
}
|
|
|
$post['refundPrice'] = $refundPrice;
|
|
|
//创建退款单
|
|
|
- $cgRefund = CgRefundClass::add($post, true);
|
|
|
+ //$cgRefund = CgRefundClass::add($post, true);
|
|
|
|
|
|
$shopId = $cg->shopId ?? 0;
|
|
|
$shop = ShopClass::getLockById($shopId);
|
|
|
if (empty($shop)) {
|
|
|
util::fail('没有找到门店');
|
|
|
}
|
|
|
+
|
|
|
+ //--------start-----花材处理逻辑 linqh 2021.6.28------
|
|
|
+ $ghsItemInfo = $post['product'] ?? '';
|
|
|
+ $data = [];
|
|
|
+ $data['status'] = CgRefundClass::STATUS_COMPLETE;
|
|
|
+ $data['orderSn'] = $refundOrderSn;
|
|
|
+ $data['shopId'] = $cg->shopId;
|
|
|
+ $data['sjId'] = $cg->sjId;
|
|
|
+ $data['shopAdminId'] = $cg->shopAdminId;
|
|
|
+ $data['shopAdminName'] = $cg->shopAdminName;
|
|
|
+ $data['cgId'] = $cg->id;
|
|
|
+ $data['refundType'] = $post['refundType'];
|
|
|
+ $data['refundPrice'] = $refundPrice;
|
|
|
+ $data['remark'] = $post['remark'];
|
|
|
+
|
|
|
+ if ($ghsItemInfo) {
|
|
|
+ $ghsItemInfo = CgRefundClass::mergeItemInfo($ghsItemInfo);
|
|
|
+ $sumNum = CgRefundClass::sumNumByItemInfo($ghsItemInfo);
|
|
|
+ }
|
|
|
+ $data['bigNum'] = $sumNum['bigNum'] ?? 0;// 总的大单位数量 总共多少扎
|
|
|
+ $data['smallNum'] = $sumNum['smallNum'] ?? 0; //总的小单位数量 总共多少支
|
|
|
+
|
|
|
+ //写入订单表
|
|
|
+ $cgRefund = CgRefundClass::add($data, true);
|
|
|
+ if($ghsItemInfo){
|
|
|
+ //写入cgRefundItem, 转hdProductId
|
|
|
+ $ghsItemInfo = ProductClass::toggleProductList($ghsItemInfo, $cg->shopId, $cg->sjId);
|
|
|
+ //将hdProductId =》productId
|
|
|
+ foreach ($ghsItemInfo as $k=>$v){
|
|
|
+ $ghsItemInfo[$k]['productId'] =$v['hdProductId'];
|
|
|
+ }
|
|
|
+ //退货,减库存
|
|
|
+ foreach ($ghsItemInfo as $k=>$v){
|
|
|
+ $stockInfo = ProductClass::decreaseStock($v['hdProductId'], $v['bigNum'], $v['smallNum']);
|
|
|
+ $ghsItemInfo[$k]['oldStock'] = $stockInfo['oldStock'];
|
|
|
+ $ghsItemInfo[$k]['newStock'] = $stockInfo['newStock'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $batchData = CgRefundClass::groupOrderItem($ghsItemInfo, $refundOrderSn);
|
|
|
+ CgRefundItemClass::batchAddOrderItem($batchData);
|
|
|
+
|
|
|
+ $orderData = CgRefundClass::getOrderDetail($refundOrderSn, $cg->shopId);
|
|
|
+ $orderData['shopId'] = $data['shopId'];
|
|
|
+ //写流水
|
|
|
+ StockRecordClass::addRecordByOrder($orderData, StockRecordClass::STOCK_RECORD_TYPE_REFUND);
|
|
|
+
|
|
|
+ }
|
|
|
+ //--------end-----花材处理逻辑 linqh 2021.6.28------
|
|
|
//门店总收入增加
|
|
|
$currentTotalIncome = bcadd($shop->totalIncome, $refundPrice, 2);
|
|
|
$shop->totalIncome = $currentTotalIncome;
|