现金退款相关
This commit is contained in:
parent
f010d54c7a
commit
f1e807ab29
@ -116,7 +116,7 @@ class StoreOrderController extends BaseAdminController
|
|||||||
if(empty($detail)){
|
if(empty($detail)){
|
||||||
return $this->fail('无该订单请检查');
|
return $this->fail('无该订单请检查');
|
||||||
}
|
}
|
||||||
|
// d($detail);
|
||||||
//微信支付
|
//微信支付
|
||||||
if(in_array($detail['pay_type'],[PayEnum::WECHAT_PAY_MINI,PayEnum::WECHAT_PAY_BARCODE])){
|
if(in_array($detail['pay_type'],[PayEnum::WECHAT_PAY_MINI,PayEnum::WECHAT_PAY_BARCODE])){
|
||||||
$money = (int)bcmul($detail['pay_price'],100);
|
$money = (int)bcmul($detail['pay_price'],100);
|
||||||
@ -144,6 +144,11 @@ class StoreOrderController extends BaseAdminController
|
|||||||
return $this->success();
|
return $this->success();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//现金支付
|
||||||
|
if($detail['pay_type'] = PayEnum::CASH_PAY){
|
||||||
|
PayNotifyLogic::cash_refund($params['order_id']);
|
||||||
|
return $this->success();
|
||||||
|
}
|
||||||
//支付包支付
|
//支付包支付
|
||||||
|
|
||||||
return $this->fail('退款失败');
|
return $this->fail('退款失败');
|
||||||
|
@ -6,10 +6,12 @@ use app\api\logic\order\OrderLogic;
|
|||||||
use app\common\enum\OrderEnum;
|
use app\common\enum\OrderEnum;
|
||||||
use app\common\enum\PayEnum;
|
use app\common\enum\PayEnum;
|
||||||
use app\common\enum\user\UserShipEnum;
|
use app\common\enum\user\UserShipEnum;
|
||||||
|
use app\common\enum\YesNoEnum;
|
||||||
use app\common\model\dict\DictType;
|
use app\common\model\dict\DictType;
|
||||||
use app\common\model\finance\PayNotifyLog;
|
use app\common\model\finance\PayNotifyLog;
|
||||||
use app\common\model\pay\PayNotify;
|
use app\common\model\pay\PayNotify;
|
||||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
|
use app\common\model\store_cash_finance_flow\StoreCashFinanceFlow;
|
||||||
use app\common\model\store_finance_flow\StoreFinanceFlow;
|
use app\common\model\store_finance_flow\StoreFinanceFlow;
|
||||||
use app\common\model\store_order\StoreOrder;
|
use app\common\model\store_order\StoreOrder;
|
||||||
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
||||||
@ -266,13 +268,14 @@ class PayNotifyLogic extends BaseLogic
|
|||||||
$order->save();
|
$order->save();
|
||||||
//加用户余额,采购款, 日志记录 加数量
|
//加用户余额,采购款, 日志记录 加数量
|
||||||
if (in_array($order['pay_type'],[PayEnum::BALANCE_PAY,PayEnum::PURCHASE_FUNDS])){
|
if (in_array($order['pay_type'],[PayEnum::BALANCE_PAY,PayEnum::PURCHASE_FUNDS])){
|
||||||
|
$deal_money = bcdiv($extra['amount']['refund'], 100, 2);
|
||||||
$user = User::where('id', $order['uid'])->findOrEmpty();
|
$user = User::where('id', $order['uid'])->findOrEmpty();
|
||||||
if($order['pay_type'] == PayEnum::BALANCE_PAY){
|
if($order['pay_type'] == PayEnum::BALANCE_PAY){
|
||||||
$user->now_money = bcadd($user->now_money, $extra['amount']['refund'], 2);
|
$user->now_money = bcadd($user->now_money, $deal_money, 2);
|
||||||
$user->save();
|
$user->save();
|
||||||
}
|
}
|
||||||
if($order['pay_type'] == PayEnum::PURCHASE_FUNDS){
|
if($order['pay_type'] == PayEnum::PURCHASE_FUNDS){
|
||||||
$user->purchase_funds = bcadd($user->purchase_funds, $extra['amount']['refund'], 2);
|
$user->purchase_funds = bcadd($user->purchase_funds, $deal_money, 2);
|
||||||
$user->save();
|
$user->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,6 +284,40 @@ class PayNotifyLogic extends BaseLogic
|
|||||||
// self::afterPay($order,$extra['transaction_id']);
|
// self::afterPay($order,$extra['transaction_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 现金退款相关
|
||||||
|
* @param $orderSn
|
||||||
|
* @param $extra
|
||||||
|
* @return true
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
*/
|
||||||
|
public static function cash_refund($orderSn, $extra = [])
|
||||||
|
{
|
||||||
|
$order = StoreOrder::where('order_id', $orderSn)->findOrEmpty();
|
||||||
|
if ($order->isEmpty() || $order->status == OrderEnum::REFUND_PAY) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
$order->refund_status = OrderEnum::REFUND_STATUS_FINISH;
|
||||||
|
$order->refund_price = $order->pay_price;
|
||||||
|
$order->refund_reason_time = time();
|
||||||
|
$order->refund_num += 1;
|
||||||
|
$order->save();
|
||||||
|
//日志记录
|
||||||
|
$model = new StoreCashFinanceFlow();
|
||||||
|
$model->store_id = $order['store_id']??0;
|
||||||
|
$model->cash_price = $order->pay_price;
|
||||||
|
$model->receivable = $order->pay_price;
|
||||||
|
$model->remark = '退款';
|
||||||
|
$model->type = 1;
|
||||||
|
$model->status = YesNoEnum::YES;
|
||||||
|
$model->save();
|
||||||
|
//增加数量
|
||||||
|
self::addStock($order['id']);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 充值
|
* 充值
|
||||||
*/
|
*/
|
||||||
@ -778,4 +815,35 @@ class PayNotifyLogic extends BaseLogic
|
|||||||
|
|
||||||
(new StoreBranchProduct())->saveAll($updateData);
|
(new StoreBranchProduct())->saveAll($updateData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加库存
|
||||||
|
* @param $oid
|
||||||
|
* @return void
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
*/
|
||||||
|
public static function addStock($oid)
|
||||||
|
{
|
||||||
|
$updateData = [];
|
||||||
|
$goods_list = StoreOrderCartInfo::where('oid', $oid)->select()->toArray();
|
||||||
|
foreach ($goods_list as $v) {
|
||||||
|
$StoreBranchProduct = StoreBranchProduct::where(
|
||||||
|
[
|
||||||
|
'store_id' => $v['store_id'],
|
||||||
|
'product_id' => $v['product_id'],
|
||||||
|
]
|
||||||
|
)->withTrashed()->find();
|
||||||
|
if ($StoreBranchProduct) {
|
||||||
|
$updateData[] = [
|
||||||
|
'id' => $StoreBranchProduct['id'],
|
||||||
|
'stock' => $StoreBranchProduct['stock'] + $v['cart_num'],
|
||||||
|
// 'sales' => ['inc', $v['cart_num']]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(new StoreBranchProduct())->saveAll($updateData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user