添加:在线买单记录查看列表

添加:在线买单支付成功后赠送兑换积分
添加:兑换积分持有信息
This commit is contained in:
wuhui_zzw 2024-01-12 17:45:50 +08:00
parent 62336133ff
commit 3a37efbc2b
9 changed files with 336 additions and 4 deletions

View File

@ -0,0 +1,23 @@
<?php
namespace app\common\dao\user;
use app\common\dao\BaseDao;
use app\common\model\user\ExchangeIntegralRecord;
class ExchangeIntegralRecordDao extends BaseDao{
protected function getModel(): string{
return ExchangeIntegralRecord::class;
}
}

View File

@ -0,0 +1,47 @@
<?php
namespace app\common\model\user;
use app\common\model\BaseModel;
/**
* Common: 用户兑换积分变更记录
* Author: wu-hui
* Time: 2024/01/12 17:23
* Class ExchangeIntegralRecord
* @package app\common\model\user
*/
class ExchangeIntegralRecord extends BaseModel
{
/**
* @return string
* @author xaboy
* @day 2020-03-30
*/
public static function tablePk(): string
{
return 'id';
}
/**
* @return string
* @author xaboy
* @day 2020-03-30
*/
public static function tableName(): string
{
return 'exchange_integral_record';
}
public function user()
{
return $this->hasOne(User::class, 'uid', 'uid');
}
}

View File

@ -2443,4 +2443,54 @@ class StoreOrderRepository extends BaseRepository
if (!$order) return null;
return $order;
}
/**
* Common: 在线买单 - 统计
* Author: wu-hui
* Time: 2024/01/12 16:54
* @return array
*/
public function getOnlineOrderStat():array{
$model = $this->dao->getSearch([])->where('activity_type',30);
return [
'total_pay_price' => $model->sum('pay_price'),// 总买单金额
'total_people_num' => $model->count('uid'),// 参与人数
];
}
/**
* Common: 在线买单 - 记录列表获取
* Author: wu-hui
* Time: 2024/01/12 17:01
* @param array $params
* @param int $page
* @param int $limit
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getOnlineOrderList(array $params,int $page,int $limit):array{
$query = $this->dao->getSearch([])
->when((int)$params['uid'] > 0,function($query) use ($params){
$query->where('uid', (int)$params['uid']);
})
->when((int)$params['mer_id'] > 0,function($query) use ($params){
$query->where('mer_id', (int)$params['mer_id']);
})
->with([
'user' => function($query){
$query->field('uid,nickname,avatar')->bind(['nickname','avatar']);
},
'merchant' => function($query){
$query->field('mer_id,mer_name,mer_avatar')->bind(['mer_name','mer_avatar']);
},
])
->order('create_time DESC,order_id DESC');
$count = $query->count();
$list = $query->page($page,$limit)->select();
return compact('count','list');
}
}

View File

@ -0,0 +1,50 @@
<?php
namespace app\common\repositories\user;
use app\common\dao\user\ExchangeIntegralRecordDao;
use app\common\repositories\BaseRepository;
class ExchangeIntegralRecordRepository extends BaseRepository{
protected $dao;
public function __construct(ExchangeIntegralRecordDao $dao){
$this->dao = $dao;
}
/**
* Common: 获取信息列表
* Author: wu-hui
* Time: 2024/01/12 17:25
* @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->getSearch([])
->when((int)$params['uid'] > 0,function($query) use ($params){
$query->where('uid', (int)$params['uid']);
})
->with([
'user' => function($query){
$query->field('uid,nickname,avatar')->bind(['nickname','avatar']);
}
])
->order('create_time DESC,id DESC');
$count = $query->count();
$list = $query->page($page,$limit)->select();
return compact('count','list');
}
}

View File

@ -208,4 +208,41 @@ class Order extends BaseController
$data = $this->repository->childrenList($id, 0);
return app('json')->success($data);
}
/**
* Common: 在线买单 - 统计信息
* Author: wu-hui
* Time: 2024/01/12 16:58
* @return mixed
*/
public function onlineTitle(){
$statInfo = $this->repository->getOnlineOrderStat();
$data = [
['className' => 'el-icon-coin','count' => $statInfo['total_pay_price'],'field' => '元','name' => '总金额'],
['className' => 'el-icon-coin','count' => $statInfo['total_people_num'],'field' => '元','name' => '买单次数'],
];
return app('json')->success($data);
}
/**
* Common: 在线买单 - 信息列表
* Author: wu-hui
* Time: 2024/01/12 17:01
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function onlineList(){
[$page, $limit] = $this->getPage();
$params = $this->request->params(['uid','mer_id']);
$data = $this->repository->getOnlineOrderList((array)$params,(int)$page,(int)$limit);
return app('json')->success($data);
}
}

View File

@ -2,9 +2,11 @@
namespace app\controller\admin\user;
use app\common\repositories\user\ExchangeIntegralRecordRepository;
use app\common\repositories\user\ExchangeQuotaRecordRepository;
use app\common\repositories\user\ExchangeQuotaRepository;
use crmeb\basic\BaseController;
use app\common\model\user\User;
class ExchangeQuota extends BaseController
@ -59,5 +61,62 @@ class ExchangeQuota extends BaseController
}
/**
* Common: 兑换积分 - 统计
* Author: wu-hui
* Time: 2024/01/12 17:38
* @return mixed
*/
public function integralTitle(){
$model = new User();
$data = [
['className' => 'el-icon-coin','count' => $model->sum('exchange_integral'),'field' => '分','name' => '总兑换积分'],
];
return app('json')->success($data);
}
/**
* Common: 兑换积分 - 额度持有信息
* Author: wu-hui
* Time: 2024/01/12 17:39
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function integralList(){
[$page, $limit] = $this->getPage();
$params = $this->request->params(['uid']);
$query = (new User())
->when((int)$params['uid'] > 0,function($query) use ($params){
$query->where('uid', (int)$params['uid']);
})
->where('exchange_integral','>',0)
->order('create_time DESC,uid DESC');
$count = $query->count();
$list = $query->page($page,$limit)->select();
return app('json')->success(compact('count','list'));
}
/**
* Common: 兑换积分 - 变更记录
* Author: wu-hui
* Time: 2024/01/12 17:40
* @return mixed
*/
public function integralRecordList(){
[$page, $limit] = $this->getPage();
$params = $this->request->params(['uid']);
$data = app()->make(ExchangeIntegralRecordRepository::class)->getList((array)$params,(int)$page,(int)$limit);
return app('json')->success($data);
}
}

View File

@ -2,8 +2,10 @@
namespace app\listener\exchangeQuota;
use app\common\model\user\ExchangeIntegralRecord;
use app\common\model\user\ExchangeQuota;
use app\common\model\user\ExchangeQuotaRecord;
use app\common\model\user\User;
use think\facade\Log;
class OrderPaySuccessEvent{
@ -13,7 +15,13 @@ class OrderPaySuccessEvent{
$groupOrder = $groupOrder['groupOrder'];
try{
// Log::info('支付成功 - 赠送兑换额度 - 开始: '.var_export(['uid'=>$groupOrder->uid,'group_order_id'=>$groupOrder->group_order_id],1));
$this->orderPaySuccessHandle($groupOrder);
if($groupOrder->activity_type == 30){
// 在线支付订单
$this->giveExchangeIntegral($groupOrder);
}else{
// 其他订单
$this->orderPaySuccessHandle($groupOrder);
}
}catch(\Exception $e){
$data = [
@ -62,6 +70,36 @@ class OrderPaySuccessEvent{
return true;
}
// 支付成功 - 赠送兑换积分
public function giveExchangeIntegral($groupOrder){
// 获取用户当前持有
$userHoldInfo = User::where('uid',$groupOrder->uid)->findOrEmpty();
// 循环处理单个商品
$insertData = [];
foreach($groupOrder->orderList as $orderInfo){
// 赠送 支付的金额=赠送的兑换积分
$changeFront = (float)$userHoldInfo->exchange_integral;
$userHoldInfo->exchange_integral += (float)$orderInfo->pay_price;// 总额度
// 记录
$insertData[] = [
'uid' => $orderInfo->uid,
'product_id' => $orderInfo->product_id ?? 0,
'order_id' => $orderInfo->order_id ?? 0,
'order_product_id' => $orderInfo->order_product_id ?? 0,
'change_type' => 1,
'change_quantity' => (float)$orderInfo->pay_price,
'change_front' => $changeFront,
'change_after' => (float)$userHoldInfo->exchange_integral,
'remark' => "消费赠送兑换积分",
];
}
// 修改用户持有
$userHoldInfo->save();
// 记录兑换额度信息
if(count($insertData) > 0) ExchangeIntegralRecord::insertAll($insertData);
return true;
}

View File

@ -427,6 +427,7 @@ Route::group(function () {
]);
// 兑换额度
Route::group('user/exchange_quota', function () {
// 兑换额度相关
Route::get('quota_title','.ExchangeQuota/quotaTitle')->name('systemUserExchangeQuotaTitle')->option([
'_alias' => '额度统计',
]);
@ -436,6 +437,19 @@ Route::group(function () {
Route::get('quota_record_list', '.ExchangeQuota/quotaRecordList')->name('systemUserExchangeQuotaRecordList')->option([
'_alias' => '额度变更记录',
]);
// 兑换积分相关
Route::get('integral_title','.ExchangeQuota/integralTitle')->name('systemUserExchangeIntegralTitle')->option([
'_alias' => '额度统计',
]);
Route::get('integral_list', '.ExchangeQuota/integralList')->name('systemUserExchangeIntegralList')->option([
'_alias' => '额度持有信息',
]);
Route::get('integral_record_list', '.ExchangeQuota/integralRecordList')->name('systemUserExchangeIntegralRecordList')->option([
'_alias' => '额度变更记录',
]);

View File

@ -37,7 +37,6 @@ Route::group(function () {
'_path' => '/promoter/orderList',
'_auth' => true,
])->append(['is_spread' => 1]);
Route::group('order', function () {
Route::get('lst', 'Order/getAllList')->name('systemOrderLst')->option([
'_alias' => '列表',
@ -81,7 +80,6 @@ Route::group(function () {
],
]
]);
Route::group('order', function () {
Route::get('take_title', 'Order/takeTitle')->name('systemOrderTakeStat')->option([
@ -97,7 +95,6 @@ Route::group(function () {
'_path' => '/order/cancellation',
'_auth' => true,
]);
Route::group('order', function () {
Route::get('refund/lst', 'RefundOrder/getAllList')->name('systemRefundOrderLst')->option([
'_alias' => '列表',
@ -124,6 +121,23 @@ Route::group(function () {
]
]);
Route::group('order', function () {
Route::get('online_title', 'Order/onlineTitle')->name('systemOrderOnlineTitle')->option([
'_alias' => '在线买单统计',
]);
Route::get('online_list', 'Order/onlineList')->name('systemOrderOnlineList')->option([
'_alias' => '在线买单列表',
]);
})->prefix('admin.order.')->option([
'_path' => '/order/onlinePay',
'_auth' => true,
]);
})->middleware(AllowOriginMiddleware::class)
->middleware(AdminTokenMiddleware::class, true)