commit
db01c4735e
@ -8,6 +8,9 @@ use app\admin\lists\store_order\StoreOrderLists;
|
||||
use app\admin\lists\store_order\StoreRefundOrderLists;
|
||||
use app\admin\logic\store_order\StoreOrderLogic;
|
||||
use app\admin\validate\store_order\StoreOrderValidate;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\logic\PayNotifyLogic;
|
||||
use app\common\model\store_order\StoreOrder;
|
||||
|
||||
|
||||
/**
|
||||
@ -101,5 +104,53 @@ class StoreOrderController extends BaseAdminController
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款逻辑
|
||||
* @return \support\Response
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function refund()
|
||||
{
|
||||
$params = (new StoreOrderValidate())->goCheck('refund');
|
||||
$detail = StoreOrder::where('order_id',$params['order_id'])->findOrEmpty();
|
||||
if(empty($detail)){
|
||||
return $this->fail('无该订单请检查');
|
||||
}
|
||||
//微信支付
|
||||
if(in_array($detail['pay_type'],[PayEnum::WECHAT_PAY_MINI,PayEnum::WECHAT_PAY_BARCODE])){
|
||||
$money = (int)bcmul($detail['pay_price'],100);
|
||||
$refund = (new \app\common\logic\store_order\StoreOrderLogic())
|
||||
->refund($params['order_id'],$money,$money);
|
||||
if($refund){
|
||||
$arr = [
|
||||
'amount'=>[
|
||||
'refund'=>$money
|
||||
]
|
||||
];
|
||||
PayNotifyLogic::refund($params['order_id'],$arr);
|
||||
return $this->success();
|
||||
}
|
||||
}
|
||||
//余额支付 采购款支付
|
||||
if (in_array($detail['pay_type'] ,[PayEnum::BALANCE_PAY,PayEnum::PURCHASE_FUNDS])){
|
||||
$money = bcmul($detail['pay_price'],100);
|
||||
$arr = [
|
||||
'amount'=>[
|
||||
'refund'=>$money
|
||||
]
|
||||
];
|
||||
PayNotifyLogic::refund($params['order_id'],$arr);
|
||||
return $this->success();
|
||||
|
||||
}
|
||||
//现金支付
|
||||
if($detail['pay_type'] = PayEnum::CASH_PAY){
|
||||
PayNotifyLogic::cash_refund($params['order_id']);
|
||||
return $this->success();
|
||||
}
|
||||
//支付包支付
|
||||
|
||||
return $this->fail('退款失败');
|
||||
}
|
||||
|
||||
}
|
@ -58,7 +58,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
$query->whereIn('status', $status);
|
||||
}
|
||||
})
|
||||
->field(['id', 'store_id', 'staff_id', 'order_id', 'paid', 'pay_price', 'pay_time', 'pay_type', 'status', 'uid'])
|
||||
->field(['id', 'store_id', 'staff_id', 'order_id', 'paid', 'pay_price', 'pay_time', 'pay_type', 'status', 'uid','refund_status'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function ($item) {
|
||||
|
@ -20,6 +20,7 @@ class StoreOrderValidate extends BaseValidate
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'order_id' => 'require',
|
||||
];
|
||||
|
||||
|
||||
@ -29,8 +30,17 @@ class StoreOrderValidate extends BaseValidate
|
||||
*/
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
'order_id' => '订单编号',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return StoreOrderValidate
|
||||
*/
|
||||
public function sceneRefund()
|
||||
{
|
||||
return $this->only(['order_id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
|
@ -107,6 +107,6 @@ class AddressLogic extends BaseLogic
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return UserAddress::field('id,real_name,phone,province,city,area,street,village,brigade,detail,is_default')->where($params)->findOrEmpty()->toArray();
|
||||
return UserAddress::field('id,real_name,phone,province,city,area,street,village,brigade,detail,is_default')->where('id',$params['address_id'])->findOrEmpty()->toArray();
|
||||
}
|
||||
}
|
||||
|
@ -62,6 +62,11 @@ class OrderEnum
|
||||
*/
|
||||
const RECEIVED_GOODS = 2;
|
||||
|
||||
/**
|
||||
* @RECEIVED_BACK 已退款
|
||||
*/
|
||||
const RECEIVED_BACK = 4;
|
||||
|
||||
/**
|
||||
* @WAIT_EVALUATION 待评价
|
||||
*/
|
||||
@ -184,6 +189,7 @@ class OrderEnum
|
||||
self::WAIT_RECEIVING => '待收货',
|
||||
self::RETURN_SUCCESS => '退货成功',
|
||||
self::ALREADY_REFUND => '已退款',
|
||||
self::RECEIVED_BACK => '已退款',
|
||||
];
|
||||
if ($value === true) {
|
||||
return $data;
|
||||
|
@ -6,10 +6,12 @@ use app\api\logic\order\OrderLogic;
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\enum\user\UserShipEnum;
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\model\dict\DictType;
|
||||
use app\common\model\finance\PayNotifyLog;
|
||||
use app\common\model\pay\PayNotify;
|
||||
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_order\StoreOrder;
|
||||
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
||||
@ -264,10 +266,72 @@ class PayNotifyLogic extends BaseLogic
|
||||
$order->refund_reason_time = time();
|
||||
$order->refund_num += 1;
|
||||
$order->save();
|
||||
//日志记录
|
||||
//加用户余额,采购款, 日志记录 加数量
|
||||
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();
|
||||
$capitalFlowDao = new CapitalFlowLogic($user);
|
||||
if($order['pay_type'] == PayEnum::BALANCE_PAY){//用户余额
|
||||
$user->now_money = bcadd($user->now_money, $deal_money, 2);
|
||||
$user->save();
|
||||
//增加数量
|
||||
self::addStock($order['id']);
|
||||
//退款
|
||||
$capitalFlowDao->userIncome('system_balance_back', 'system_back', $order['id'], $deal_money);
|
||||
}
|
||||
if($order['pay_type'] == PayEnum::PURCHASE_FUNDS){//采购款
|
||||
$user->purchase_funds = bcadd($user->purchase_funds, $deal_money, 2);
|
||||
$user->save();
|
||||
//增加数量
|
||||
self::addStock($order['id']);
|
||||
//退款
|
||||
$capitalFlowDao->userIncome('system_purchase_back', 'system_back', $order['id'], $deal_money);
|
||||
}
|
||||
|
||||
}
|
||||
//微信日志
|
||||
|
||||
|
||||
self::addStock($order['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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 充值
|
||||
*/
|
||||
@ -765,4 +829,35 @@ class PayNotifyLogic extends BaseLogic
|
||||
|
||||
(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