增加:运营中心增加缴费退款申请记录

This commit is contained in:
wuhui_zzw 2024-07-11 16:47:48 +08:00
parent 799cacdac9
commit 7f5e005d84
11 changed files with 360 additions and 16 deletions

View File

@ -0,0 +1,51 @@
<?php
namespace app\common\dao\common;
use app\common\dao\BaseDao;
use app\common\model\common\PayRecordRefund;
class PayRecordRefundDao extends BaseDao{
protected function getModel(): string{
return PayRecordRefund::class;
}
/**
* Common: 公共搜索查询
* Author: wu-hui
* Time: 2024/07/11 15:17
* @param array $params
* @return PayRecordRefund
*/
public function searchList(array $params){
return (new PayRecordRefund())
->when(isset($params['id']) && $params['id'] !== '',function($query) use ($params){
$query->where('id', (int)$params['id']);
})
->when(isset($params['pay_record_id']) && $params['pay_record_id'] !== '',function($query) use ($params){
$query->where('pay_record_id', (int)$params['pay_record_id']);
})
->when(isset($params['status']) && $params['status'] !== '',function($query) use ($params){
$query->where('status', (int)$params['status']);
})
->with([
'user' => function($query){
$query->field('uid,nickname,real_name,avatar,phone');
},
'payRecord' => function($query){
$query->field('id,uid,object_id,money,pay_type,pay_time,pay_status')
->with([
'agent' => function($query){
$query->field('id,uid,contact_name,contact_phone,agent_type')->append(['agent_type_text']);
}
]);
},
])
->order('create_time DESC,id DESC');
}
}

View File

@ -55,9 +55,9 @@ class StoreGroupOrderDao extends BaseDao
$query->where('paid',$where['paid']);
})
->when($isWithGoods == 1,function($query) use ($where){
$query->whereNotIn('activity_type',[30,31,32,33,34,37,38]);
$query->whereNotIn('activity_type',[30,31,32,33,34,37,38,51]);
},function($query) use ($where){
$query->whereNotIn('activity_type',[30,31,32,33,34,35,37,38]);
$query->whereNotIn('activity_type',[30,31,32,33,34,35,37,38,51]);
})
->when(isset($where['paid']) && $where['paid'] !== '',function($query) use ($where){
$query->where('paid',$where['paid']);

View File

@ -0,0 +1,27 @@
<?php
namespace app\common\model\common;
use app\common\model\BaseModel;
use app\common\model\user\User;
class PayRecordRefund extends BaseModel{
public static function tablePk(): string{
return 'id';
}
public static function tableName(): string{
return 'pay_record_refund';
}
public function payRecord(){
return $this->hasOne(PayRecord::class, 'id', 'pay_record_id');
}
public function user(){
return $this->hasOne(User::class, 'uid', 'uid');
}
}

View File

@ -0,0 +1,48 @@
<?php
namespace app\common\repositories\common;
use app\common\dao\common\PayRecordRefundDao;
use app\common\repositories\BaseRepository;
class PayRecordRefundRepository extends BaseRepository{
protected $dao;
public function __construct(PayRecordRefundDao $dao){
$this->dao = $dao;
}
/**
* Common: 公共查询模型
* Author: wu-hui
* Time: 2024/07/11 15:18
* @param $search
* @return \app\common\model\common\PayRecordRefund
*/
public function getSearchModel($search){
return $this->dao->searchList($search);
}
/**
* Common: 获取列表信息
* Author: wu-hui
* Time: 2024/07/11 15:18
* @param array $params
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $params,int $page,int $limit):array{
$query = $this->dao->searchList($params);
$count = $query->count();
$list = $query->page($page,$limit)->select();
return compact('count','list');
}
}

View File

@ -5,7 +5,11 @@ namespace app\common\repositories\common;
use app\common\dao\common\PayRecordDao;
use app\common\repositories\BaseRepository;
use app\common\repositories\store\order\StoreGroupOrderRepository;
use app\common\repositories\store\order\StoreOrderCreateRepository;
use crmeb\services\LockService;
use think\exception\ValidateException;
use think\facade\Db;
class PayRecordRepository extends BaseRepository{
@ -43,12 +47,62 @@ class PayRecordRepository extends BaseRepository{
return compact('count','list');
}
/**
* Common: 获取单条信息
* Author: wu-hui
* Time: 2024/07/11 10:51
* @param $uid
* @param $objectId
* @param $payType
* @return array
*/
public function getSingleInfo($uid, $objectId, $payType){
$info = $this->getSearchModel([
'uid' => $uid,
'object_id' => $objectId,// 对象角色id
'pay_type' => $payType,// 缴费类型1=运营中心-定金,2=运营中心-尾款,3=运营中心-保证金
])
->findOrEmpty()
->toArray();
return $info ?? [];
}
/**
* Common: 生成订单
* Author: wu-hui
* Time: 2024/07/11 11:57
* @param array $params
* @param int $payRecordId
* @param int $groupOrderId
* @return mixed
*/
public function createOrder(array $params,int $payRecordId, int $groupOrderId = 0){
return Db::transaction(function() use ($params, $payRecordId, $groupOrderId){
$payMoney = (float)($params['money'] ?? 0);
$userInfo = $params['user_info'] ?? [];
// 判断:是否需要支付
if($payMoney > 0 && $groupOrderId <= 0){
// 订单生成
$groupOrder = app()
->make(LockService::class)
->exec('online_order.create',function() use ($payMoney,$userInfo){
return app()
->make(StoreOrderCreateRepository::class)
->onlinePayment('',['money'=>$payMoney],$userInfo, 51);
});
// 记录订单id
$this->dao->update($payRecordId,[
'group_order_id' => $groupOrder->group_order_id
]);
}else if($groupOrderId > 0){
$groupOrder = app()->make(StoreGroupOrderRepository::class)->getWhere(['group_order_id' => $groupOrderId]);
}else{
throw new ValidateException('订单生成失败!');
}
return $groupOrder;
});
}
}

View File

@ -186,6 +186,9 @@ class StoreOrderRepository extends BaseRepository
}else if($groupOrder['activity_type'] == 38){
$data['title'] = '配送商缴费';
$data['mark'] = $user->nickname.'使用余额支付' . floatval($groupOrder['pay_price']) . '元';
}else if($groupOrder['activity_type'] == 51){
$data['title'] = '账单缴费';
$data['mark'] = $user->nickname.'使用余额支付' . floatval($groupOrder['pay_price']) . '元';
}
$userBillRepository->decBill($user['uid'], 'now_money', 'pay_product', $data);
@ -290,7 +293,7 @@ class StoreOrderRepository extends BaseRepository
app()->make(ProductAssistSetRepository::class)->changStatus($order->orderProduct[0]['activity_id']);
}
if ($order->order_type == 1 && $order->status != 10) $order->verify_code = $this->verifyCode();
if (!in_array($order->activity_type,[30,31,32,33,34,37,38]) && $order->orderProduct[0]->product->type == 2) {
if (!in_array($order->activity_type,[30,31,32,33,34,37,38,51]) && $order->orderProduct[0]->product->type == 2) {
$order->status = 3;//2; todo 订单进入待评价改为已完成
$order->delivery_type = 6;
$order->delivery_name = '自动发货';
@ -298,7 +301,7 @@ class StoreOrderRepository extends BaseRepository
$isPoints = true;
}
// 判断:是否为在线买单、酒道馆补差价 在线买单,订单支付则订单完成
if(in_array($order->activity_type,[30,31,32,33,34,37,38])){
if(in_array($order->activity_type,[30,31,32,33,34,37,38,51])){
$order->status = 3;
}

View File

@ -2,6 +2,9 @@
namespace app\controller\admin\marketing;
use app\common\model\common\PayRecord;
use app\common\model\common\PayRecordRefund;
use app\common\repositories\common\PayRecordRefundRepository;
use app\common\repositories\common\PayRecordRepository;
use app\common\repositories\marketing\AgentApplyRepository;
use app\common\repositories\marketing\AgentBrokerageRepository;
@ -422,6 +425,45 @@ class Agent extends BaseController{
return app('json')->success($data);
}
/**
* Common: 获取缴费退款申请记录
* Author: wu-hui
* Time: 2024/07/11 16:06
* @return mixed
*/
public function payRecordRefund(){
[$page, $limit] = $this->getPage();
$params = $this->request->params(['pay_type']);
if($params['pay_type'] == '') $params['pay_type'] = [1,2,3];
$data = app()->make(PayRecordRefundRepository::class)->getList((array)$params,(int)$page,(int)$limit);
return app('json')->success($data);
}
/**
* Common: 缴费退款申请审核
* Author: wu-hui
* Time: 2024/07/11 16:43
* @return mixed
*/
public function payRecordRefundExamine(){
// 参数获取
$params = $this->request->params(['id', 'status']);
$status = (int)($params['status'] ?? 0);
// 审核
if($status == 1){
$info = app()->make(PayRecordRefundRepository::class)->getSearchModel(['id'=>$params['id']])->findOrEmpty()->toArray();
// 修改退款申请状态
PayRecordRefund::update([
'status' => $status,
'refund_time' => date("Y-m-d H:i:s")
],['id' => $params['id']]);
// 修改缴费记录
PayRecord::update(['pay_status' => 3,'refund_time' => date("Y-m-d H:i:s")],['id' => $info['pay_record_id']]);
}
return app('json')->success('success');
}
}

View File

@ -0,0 +1,98 @@
<?php
namespace app\controller\api\marketing\agent;
use app\common\model\common\PayRecordRefund;
use app\common\repositories\common\PayRecordRepository;
use crmeb\basic\BaseController;
use think\App;
/**
* Common: 运营中心 - 缴费账单
* Author: wu-hui
* Time: 2024/07/09 17:55
* Class PayRecord
* @package app\controller\api\marketing\agent
*/
class PayRecord extends BaseController{
protected $repository;
public function __construct(App $app, PayRecordRepository $repository){
parent::__construct($app);
$this->repository = $repository;
}
/**
* Common: 获取信息
* Author: wu-hui
* Time: 2024/07/11 10:52
* @return mixed
*/
public function getInfo(){
// 参数获取
$agentId = $this->request->param('agent_id', 0);
$uid = $this->request->uid();
// 信息获取
$data = [
'deposit' => $this->repository->getSingleInfo($uid, $agentId, 1),
'arrears' => $this->repository->getSingleInfo($uid, $agentId, 2),
'earnest_money' => $this->repository->getSingleInfo($uid, $agentId, 3)
];
return app('json')->success($data);
}
/**
* Common: 账单缴费
* Author: wu-hui
* Time: 2024/07/11 13:33
* @return mixed
*/
public function pay(){
// 参数获取
$id = $this->request->param('id', 0);
// 信息获取
$info = $this->repository->getSearchModel(['id' => $id])->findOrEmpty()->toArray();
$groupOrderId = (int)($info['group_order_id'] ?? 0);
$params['uid'] = $this->request->uid();
$params['user_info'] = $this->request->userInfo();
$params['is_app'] = $this->request->isApp();
$params['pay_type'] = '';
$params['money'] = (float)$info['money'];
$groupOrder = $this->repository->createOrder($params, (int)$id,(int) $groupOrderId);
return app('json')->success([
'group_order_id' => $groupOrder->group_order_id,
'pay_price' => $groupOrder->pay_price,
]);
}
/**
* Common: 申请退款
* Author: wu-hui
* Time: 2024/07/11 14:36
* @return mixed
*/
public function refund(){
// 参数获取
$params = $this->request->params([
['id', 0],
'reason',
]);
$info = $this->repository->getSearchModel(['id' => $params['id']])->findOrEmpty()->toArray();
// 增加申请信息
PayRecordRefund::create([
'uid' => $info['uid'],
'pay_record_id' => $params['id'],
'apply_time' => date("Y-m-d H:i:s"),
'reason' => $params['reason'],
'pay_type' => $info['pay_type']
]);
// 修改缴费信息
$this->repository->update($params['id'],['pay_status' => 2]);
return app('json')->success('success');
}
}

View File

@ -2,6 +2,7 @@
namespace app\listener\exchangeQuota;
use app\common\model\common\PayRecord;
use app\common\model\marketing\activity\Record;
use app\common\model\marketing\agent\AgentDelivery;
use app\common\model\system\merchant\Merchant;
@ -75,6 +76,13 @@ class OrderPaySuccessEvent{
AgentDelivery::update(['status' => 1],['order_id' => (int)$orderInfo->order_id]);
}
break;
// 缴费订单
case 51:
PayRecord::update([
'pay_status' => 1,
'pay_time' => date('Y-m-d H:i:s',time())
],['group_order_id' => $groupOrder->group_order_id]);
break;
// 其他订单
default:
$this->orderPaySuccessHandle($groupOrder);
@ -86,7 +94,8 @@ class OrderPaySuccessEvent{
'group_order_id' => $groupOrder->group_order_id
]);
}
}catch(\Exception $e){
}
catch(\Exception $e){
$data = [
'uid' => $groupOrder->uid,
'group_order_id' => $groupOrder->group_order_id,
@ -112,7 +121,9 @@ class OrderPaySuccessEvent{
// 共创股东加入
case 37:$title = '支付成功 - 共创股东加入';break;
// 配送商缴费支付成功
case 38:$title = '支付成功 - 配送商缴费支付成功';break;
case 38:$title = '支付成功 - 配送商缴费';break;
// 缴费订单
case 51:$title = '支付成功 - 缴费订单';break;
}
Log::info($title . ' - 错误: '.var_export($data,1));
}
@ -449,8 +460,6 @@ class OrderPaySuccessEvent{
return true;
}
/**
* Common: 赠送惠民积分处理
* Author: wu-hui
@ -497,4 +506,5 @@ class OrderPaySuccessEvent{
return true;
}
}

View File

@ -509,12 +509,16 @@ Route::group(function () {
'_alias' => '佣金明细',
]);
// 缴费记录
Route::get('commission_list','commissionList')->name('systemMarketingAgentCommissionList')->option([
'_alias' => '佣金明细',
]);
Route::get('pay_record','payRecord')->name('systemMarketingAgentPayRecord')->option([
'_alias' => '缴费记录',
]);
Route::get('pay_record_refund','payRecordRefund')->name('systemMarketingAgentPayRecordRefund')->option([
'_alias' => '缴费退款记录',
]);
Route::get('pay_record_refund_examine','payRecordRefundExamine')->name('systemMarketingAgentPayRecordRefundExamine')->option([
'_alias' => '缴费退款审核',
]);
})->prefix('admin.marketing.Agent/')->option([
'_path' => '/marketing/agent/list',

View File

@ -437,6 +437,13 @@ Route::group('api/', function () {
Route::get('delivery/payment_record', 'Delivery/paymentRecord');// 缴费记录
Route::get('delivery/mer_list', 'Delivery/merList');// 绑定商户
Route::post('delivery/allocation_order', 'Delivery/allocationOrder');// 分配缴费记录
// 缴费账单
Route::get('pay_record/get_info', 'PayRecord/getInfo');// 账单信息
Route::post('pay_record/pay', 'PayRecord/pay');// 账单缴费
Route::post('pay_record/refund', 'PayRecord/refund');// 申请退款
})->prefix('api.marketing.agent.');
// 供应商相关
Route::group('supplier', function () {