|
|
@@ -28,14 +28,13 @@ class CgRefundService extends BaseService
|
|
|
public static $baseFile = '\bizHd\cg\classes\CgRefundClass';
|
|
|
|
|
|
//新增退款
|
|
|
- public static function addRefund($post, $order)
|
|
|
+ public static function addRefund($post, $cg)
|
|
|
{
|
|
|
- $purchaseId = $order->purchaseId;
|
|
|
- $cg = PurchaseClass::getLockById($purchaseId);
|
|
|
- if (empty($cg)) {
|
|
|
- util::fail('没有找到采购订单');
|
|
|
- }
|
|
|
+
|
|
|
+ $cgId = $cg->id ?? 0;
|
|
|
$mainId = $cg->mainId ?? 0;
|
|
|
+ $shopId = $cg->shopId ?? 0;
|
|
|
+ $sjId = $cg->sjId ?? 0;
|
|
|
$payWay = $cg->payWay;
|
|
|
$cg->refund = PurchaseClass::REFUND_YES;
|
|
|
$cg->save();
|
|
|
@@ -47,14 +46,10 @@ class CgRefundService extends BaseService
|
|
|
}
|
|
|
}
|
|
|
$refundOrderSn = orderSn::getCgRefundSn();
|
|
|
- $post['cgId'] = $cg->id;
|
|
|
$refundPrice = $post['price'] ?? 0;
|
|
|
if (is_numeric($refundPrice) == false || $refundPrice < 0) {
|
|
|
util::fail('退款金额有问题');
|
|
|
}
|
|
|
- $post['refundPrice'] = $refundPrice;
|
|
|
-
|
|
|
- $shopId = $cg->shopId ?? 0;
|
|
|
$shop = ShopClass::getLockById($shopId);
|
|
|
if (empty($shop)) {
|
|
|
util::fail('没有找到门店');
|
|
|
@@ -63,9 +58,9 @@ class CgRefundService extends BaseService
|
|
|
$data = [];
|
|
|
$data['status'] = CgRefundClass::STATUS_COMPLETE;
|
|
|
$data['orderSn'] = $refundOrderSn;
|
|
|
- $data['shopId'] = $cg->shopId;
|
|
|
+ $data['shopId'] = $shopId;
|
|
|
$data['mainId'] = $mainId;
|
|
|
- $data['sjId'] = $cg->sjId;
|
|
|
+ $data['sjId'] = $sjId;
|
|
|
$data['shopAdminId'] = $cg->shopAdminId;
|
|
|
$data['shopAdminName'] = $cg->shopAdminName;
|
|
|
$data['cgId'] = $cg->id;
|
|
|
@@ -74,41 +69,55 @@ class CgRefundService extends BaseService
|
|
|
$data['refundPrice'] = $refundPrice;
|
|
|
$data['remark'] = $post['remark'];
|
|
|
|
|
|
- $ghsItemInfo = $post['product'] ?? '';
|
|
|
-
|
|
|
- $data['bigNum'] = $sumNum['bigNum'] ?? 0;// 总的大单位数量 总共多少扎
|
|
|
- $data['smallNum'] = $sumNum['smallNum'] ?? 0; //总的小单位数量 总共多少支
|
|
|
-
|
|
|
- //写入订单表
|
|
|
+ //花材列表结构
|
|
|
+ // [{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎'}] productId 花材id num 退货数 unitType 大小单位0大1小 unitPrice 售价 unitName单位名称
|
|
|
+ $productList = $post['product'] ?? '';
|
|
|
+ $bigNum = 0;
|
|
|
+ $smallNum = 0;
|
|
|
+ foreach ($productList as $current) {
|
|
|
+ $unitType = $current['unitType'] ?? dict::getDict('unitType', 'big');
|
|
|
+ $num = $current['num'] ?? 0;
|
|
|
+ if ($unitType == dict::getDict('unitType', 'big')) {
|
|
|
+ $bigNum = bcadd($bigNum, $num);
|
|
|
+ } else {
|
|
|
+ $smallNum = bcadd($smallNum, $num);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $data['bigNum'] = $bigNum;
|
|
|
+ $data['smallNum'] = $smallNum;
|
|
|
$cgRefund = CgRefundClass::add($data, true);
|
|
|
|
|
|
if ($refundType == CgRefundClass::REFUND_TYPE_MONEY_GOOD) {
|
|
|
-
|
|
|
-
|
|
|
- foreach ($ghsItemInfo as $k => $v) {
|
|
|
- $ghsItemInfo[$k]['productId'] = $v['hdProductId'];
|
|
|
+ if (empty($productList)) {
|
|
|
+ util::fail('没有找到花材哦!');
|
|
|
}
|
|
|
- //退货,减库存
|
|
|
- foreach ($ghsItemInfo as $k => $v) {
|
|
|
- $stockInfo = ProductClass::decreaseStock($v['hdProductId'], $v['bigNum'], $v['smallNum']);
|
|
|
- $ghsItemInfo[$k]['oldStock'] = $stockInfo['oldStock'];
|
|
|
- $ghsItemInfo[$k]['newStock'] = $stockInfo['newStock'];
|
|
|
+ foreach ($productList as $info) {
|
|
|
+ $unitType = $info['unitType'] ?? 0;
|
|
|
+ $num = $info['num'] ?? 0;
|
|
|
+ $unitPrice = $info['unitPrice'] ?? 0;
|
|
|
+
|
|
|
+ $refundData = [];
|
|
|
+ $productId = $info['productId'] ?? 0;
|
|
|
+ $ptItemId = $info['ptItemId'] ?? 0;
|
|
|
+ $refundData['orderSn'] = $refundOrderSn;
|
|
|
+ $refundData['itemId'] = $ptItemId;
|
|
|
+ $refundData['productId'] = $productId;
|
|
|
+ $refundData['name'] = $info['name'] ?? '';
|
|
|
+ $refundData['cover'] = $info['cover'] ?? '';
|
|
|
+ $refundData['itemCost'] = $info['cost'] ?? 0;
|
|
|
+ $refundData['ratio'] = $info['ratio'] ?? 0;
|
|
|
+ $refundData['mainId'] = $mainId;
|
|
|
+ $refundData['shopId'] = $shopId;
|
|
|
+ $refundData['sjId'] = $sjId;
|
|
|
+ $refundData['xhNum'] = $num;
|
|
|
+ $refundData['xhUnitName'] = 0;
|
|
|
+ $refundData['xhUnitType'] = $unitType;
|
|
|
+ $refundData['xhUnitPrice'] = $unitPrice;
|
|
|
+ $refundData['xhPrice'] = 0;
|
|
|
+ CgRefundItemClass::addData($refundData);
|
|
|
}
|
|
|
-
|
|
|
- $cgOrderSn = $cg->orderSn ?? '';
|
|
|
- $cgItemList = PurchaseItemClass::getAllByCondition(['orderSn' => $cgOrderSn], null, '*', 'productId');
|
|
|
-
|
|
|
- $batchData = CgRefundClass::groupOrderItem($ghsItemInfo, $refundOrderSn, $cgItemList);
|
|
|
- CgRefundItemClass::batchAddOrderItem($batchData);
|
|
|
-
|
|
|
- $orderData = CgRefundClass::getOrderDetail($refundOrderSn, $cg->shopId);
|
|
|
- $orderData['shopId'] = $data['shopId'];
|
|
|
- //写流水
|
|
|
- StockRecordClass::addRecordByOrder($orderData, StockRecordClass::STOCK_RECORD_TYPE_REFUND);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-
|
|
|
//门店总收入增加
|
|
|
$currentTotalIncome = bcadd($shop->totalIncome, $refundPrice, 2);
|
|
|
$shop->totalIncome = $currentTotalIncome;
|
|
|
@@ -162,7 +171,7 @@ class CgRefundService extends BaseService
|
|
|
|
|
|
if (isset($return['return_code']) == false || $return['return_code'] != 'SUCCESS') {
|
|
|
$msg = $return['return_msg'] ?? '';
|
|
|
- Yii::info("退款失败 cgId:{$purchaseId} msg:{$msg}");
|
|
|
+ Yii::info("退款失败 cgId:{$cgId} msg:{$msg}");
|
|
|
util::fail('退款失败');
|
|
|
}
|
|
|
$wxRefundId = $return['refund_id'] ?? '';
|