|
|
@@ -28,15 +28,9 @@ class CgRefundService extends BaseService
|
|
|
|
|
|
public static $baseFile = '\bizHd\cg\classes\CgRefundClass';
|
|
|
|
|
|
- public static function createRefund()
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
//新增退款
|
|
|
public static function addRefund($post, $cg)
|
|
|
{
|
|
|
-
|
|
|
$cgId = $cg->id ?? 0;
|
|
|
$mainId = $cg->mainId ?? 0;
|
|
|
$shopId = $cg->shopId ?? 0;
|
|
|
@@ -74,7 +68,7 @@ class CgRefundService extends BaseService
|
|
|
$data['refundType'] = $refundType;
|
|
|
$data['refundPrice'] = $refundPrice;
|
|
|
$data['remark'] = $post['remark'];
|
|
|
- $data['status'] = CgRefundClass::STATUS_COMPLETE;
|
|
|
+ $data['status'] = CgRefundClass::STATUS_UN_COMPLETE;
|
|
|
|
|
|
//花材列表结构
|
|
|
// [{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎'}] productId 花材id num 退货数 unitType 大小单位0大1小 unitPrice 售价 unitName单位名称
|
|
|
@@ -133,209 +127,6 @@ class CgRefundService extends BaseService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //门店总收入增加
|
|
|
- $currentTotalIncome = bcadd($main->totalIncome, $refundPrice, 2);
|
|
|
- $main->totalIncome = $currentTotalIncome;
|
|
|
- $main->save();
|
|
|
-
|
|
|
- $currentType = dict::getDict('capitalType', 'cgRefund', 'id');
|
|
|
-
|
|
|
- //记录总的退款金额
|
|
|
- $currentTkPrice = bcadd($cg->tkPrice, $refundPrice, 2);
|
|
|
- $cg->tkPrice = $currentTkPrice;
|
|
|
- $cg->refund = PurchaseClass::REFUND_YES;
|
|
|
- $cg->save();
|
|
|
-
|
|
|
- $ghsId = $cg->ghsId;
|
|
|
- $ghs = GhsClass::getLockById($ghsId);
|
|
|
- if (empty($ghs)) {
|
|
|
- util::fail('没有找到供货商');
|
|
|
- }
|
|
|
- $ghsName = $ghs->name ?? '';
|
|
|
-
|
|
|
- if ($onlinePay == dict::getDict('onlinePay', 'yes')) {
|
|
|
- if ($payWay == dict::getDict('payWay', 'wxPay')) {
|
|
|
-
|
|
|
- //微信收款的原路退回
|
|
|
- ini_set('date.timezone', 'Asia/Shanghai');
|
|
|
- $wx = Yii::getAlias("@vendor/wxPayApi_v3.0.10");
|
|
|
- require_once($wx . '/lib/WxPay.Api.php');
|
|
|
- require_once($wx . '/example/WxPay.Config.php');
|
|
|
-
|
|
|
- $totalFee = $cg->book == 1 ? $cg->bookPrice * 100 : $cg->orderPrice * 100;
|
|
|
- $refundFee = $refundPrice * 100;
|
|
|
-
|
|
|
- $merchantExt = WxOpenClass::getWxInfo();
|
|
|
- $mid = $merchantExt['wxPayMerchantId'] ?? '';
|
|
|
- $appId = $merchantExt['miniAppId'] ?? '';
|
|
|
- $key = $merchantExt['wxPayKey'] ?? '';
|
|
|
-
|
|
|
- $input = new \WxPayRefund();
|
|
|
- $input->SetTransaction_id($transaction_id);
|
|
|
- $input->SetTotal_fee($totalFee);
|
|
|
- $input->SetRefund_fee($refundFee);
|
|
|
- $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-refund-callback/');
|
|
|
-
|
|
|
- $config = new \WxPayConfig();
|
|
|
- $config->SetAppId($appId);
|
|
|
- $config->SetMerchantId($mid);
|
|
|
- $config->SetKey($key);
|
|
|
-
|
|
|
- $input->SetOut_refund_no($refundOrderSn);
|
|
|
- $input->SetOp_user_id($mid);
|
|
|
- $return = \WxPayApi::refund($config, $input);
|
|
|
- if (isset($return['return_code']) == false || $return['return_code'] != 'SUCCESS' || isset($return['result_code']) == false || $return['result_code'] != 'SUCCESS') {
|
|
|
- $msg = $return['return_msg'] ?? '';
|
|
|
- $err_code_des = $return['err_code_des'] ?? '';
|
|
|
- Yii::info("退款失败 cgId:{$cgId} msg:{$msg}");
|
|
|
- Yii::info($err_code_des);
|
|
|
- Yii::info('微信退款返回信息:' . json_encode($return));
|
|
|
- util::fail('退款操作失败');
|
|
|
- }
|
|
|
- $wxRefundId = $return['refund_id'] ?? '';
|
|
|
- $cgRefund->thirdRefundNo = $wxRefundId;
|
|
|
- $cgRefund->save();
|
|
|
-
|
|
|
- $cg->refundPrice = $refundPrice;
|
|
|
- $currentActPrice = bcsub($cg->actPrice, $refundPrice, 2);
|
|
|
- if ($currentActPrice < 0) {
|
|
|
- util::fail('可退款金额不足!!');
|
|
|
- }
|
|
|
- $cg->actPrice = $currentActPrice;
|
|
|
- $currentRealPrice = bcsub($cg->realPrice, $refundPrice, 2);
|
|
|
- if ($currentRealPrice < 0) {
|
|
|
- util::fail('可退款金额不足,请排查。');
|
|
|
- }
|
|
|
- $cg->realPrice = $currentRealPrice;
|
|
|
- $cg->save();
|
|
|
-
|
|
|
- //发起退款通知
|
|
|
- //$customName = $order->customName ?? '';
|
|
|
- //noticeUtil::push("商家正在给{$customName}退款{$refundPrice}元", '15280215347');
|
|
|
-
|
|
|
- } else {
|
|
|
- util::fail('此支付方式暂不支持退款');
|
|
|
- }
|
|
|
- } else {
|
|
|
- if ($payWay == dict::getDict('payWay', 'debtPay')) {
|
|
|
-
|
|
|
- $clearId = $cg->clearId ?? 0;
|
|
|
- if (!empty($clearId)) {
|
|
|
- util::fail('订单已经结帐,无法再发起退款');
|
|
|
- }
|
|
|
-
|
|
|
- $cg->refundPrice = $refundPrice;
|
|
|
-
|
|
|
- $currentActPrice = bcsub($cg->actPrice, $refundPrice, 2);
|
|
|
- if ($currentActPrice < 0) {
|
|
|
- util::fail('可退款金额不足');
|
|
|
- }
|
|
|
- $cg->actPrice = $currentActPrice;
|
|
|
-
|
|
|
- $currentRealPrice = bcsub($cg->realPrice, $refundPrice, 2);
|
|
|
- if ($currentRealPrice < 0) {
|
|
|
- util::fail('可退款金额不足,请排查');
|
|
|
- }
|
|
|
- $cg->realPrice = $currentRealPrice;
|
|
|
-
|
|
|
- $currentRemainDebt = bcsub($cg->remainDebtPrice, $refundPrice, 2);
|
|
|
- if ($currentRemainDebt < 0) {
|
|
|
- util::fail('可退款金额不足哦');
|
|
|
- }
|
|
|
- if ($currentRemainDebt == 0) {
|
|
|
- $cg->debt = PurchaseClass::DEBT_NO;
|
|
|
- }
|
|
|
- $cg->remainDebtPrice = $currentRemainDebt;
|
|
|
- $cg->save();
|
|
|
-
|
|
|
- //门店应付总款减少
|
|
|
- $currentMayPay = bcsub($main->mayPay, $refundPrice, 2);
|
|
|
- if ($currentMayPay < 0) {
|
|
|
- //noticeUtil::push("应付款有问题! {$main->mayPay} {$refundPrice}", '15280215347');
|
|
|
- //util::fail('应付款有问题!');
|
|
|
- }
|
|
|
- $main->mayPay = $currentMayPay;
|
|
|
- $main->save();
|
|
|
-
|
|
|
- //应付供货商款减少
|
|
|
- \bizHd\ghs\classes\GhsClass::refundDebtAmountReduce($ghs, $cgRefund, $cg);
|
|
|
-
|
|
|
- } elseif ($payWay == dict::getDict('payWay', 'balancePay')) {
|
|
|
-
|
|
|
- util::fail('余额支付暂不支持退款');
|
|
|
-
|
|
|
- //采购单总金额还要减去退款
|
|
|
- $cg->refundPrice = $refundPrice;
|
|
|
- $currentActPrice = bcsub($cg->actPrice, $refundPrice, 2);
|
|
|
- if ($currentActPrice < 0) {
|
|
|
- util::fail('退款金额有问题!');
|
|
|
- }
|
|
|
- $cg->actPrice = $currentActPrice;
|
|
|
- $currentRealPrice = bcsub($cg->realPrice, $refundPrice, 2);
|
|
|
- if ($currentRealPrice < 0) {
|
|
|
- util::fail('退款金额有问题,请排查');
|
|
|
- }
|
|
|
- $cg->realPrice = $currentRealPrice;
|
|
|
- $cg->save();
|
|
|
-
|
|
|
- //门店余额增加
|
|
|
- ShopClass::cgRefundAddBalance($main, $shop, $refundPrice, $cgRefund, $ghs);
|
|
|
-
|
|
|
- } elseif ($payWay == dict::getDict('payWay', 'cash')) {
|
|
|
- $cg->refundPrice = $refundPrice;
|
|
|
- $currentActPrice = bcsub($cg->actPrice, $refundPrice, 2);
|
|
|
- if ($currentActPrice < 0) {
|
|
|
- util::fail('可退款金额不足...');
|
|
|
- }
|
|
|
- $cg->actPrice = $currentActPrice;
|
|
|
- $currentRealPrice = bcsub($cg->realPrice, $refundPrice, 2);
|
|
|
- if ($currentRealPrice < 0) {
|
|
|
- util::fail('可退款金额不足,请确认');
|
|
|
- }
|
|
|
- $cg->realPrice = $currentRealPrice;
|
|
|
- $cg->save();
|
|
|
- } else {
|
|
|
- //其它线下退款直接完成
|
|
|
- $cg->refundPrice = $refundPrice;
|
|
|
- $currentActPrice = bcsub($cg->actPrice, $refundPrice, 2);
|
|
|
- if ($currentActPrice < 0) {
|
|
|
- util::fail('可退款金额不足...');
|
|
|
- }
|
|
|
- $cg->actPrice = $currentActPrice;
|
|
|
- $currentRealPrice = bcsub($cg->realPrice, $refundPrice, 2);
|
|
|
- if ($currentRealPrice < 0) {
|
|
|
- util::fail('可退款金额不足,请确认');
|
|
|
- }
|
|
|
- $cg->realPrice = $currentRealPrice;
|
|
|
- $cg->save();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $sjId = $cg->sjId ?? 0;
|
|
|
- $shopId = $cg->shopId ?? 0;
|
|
|
- $event = "采购退款({$ghsName})";
|
|
|
- $capitalData = [
|
|
|
- 'capitalType' => $currentType,
|
|
|
- 'io' => 1,
|
|
|
- 'totalIncome' => $currentTotalIncome,
|
|
|
- 'payWay' => 0,
|
|
|
- 'amount' => $refundPrice,
|
|
|
- 'sjId' => $sjId,
|
|
|
- 'shopId' => $shopId,
|
|
|
- 'event' => $event,
|
|
|
- 'mainId' => $mainId,
|
|
|
- ];
|
|
|
- ShopCapitalClass::addCapital($capitalData);
|
|
|
-
|
|
|
- //每天每月收入
|
|
|
- StatIncomeClass::updateOrInsert($main, $shop, $refundPrice);
|
|
|
-
|
|
|
- //微信付款的不需要通知,微信官方会通知
|
|
|
- if ($payWay != dict::getDict('payWay', 'wxPay')) {
|
|
|
- //微信通知退款成功
|
|
|
- WxMessageClass::cgRefundInform($shop, $cg, $refundPrice);
|
|
|
- }
|
|
|
-
|
|
|
return $cgRefund;
|
|
|
|
|
|
}
|