parent
6620161689
commit
87618c742a
|
|
@ -14,9 +14,32 @@ class ExchangeQuotaDao extends BaseDao{
|
|||
protected function getModel(): string{
|
||||
return ExchangeQuota::class;
|
||||
}
|
||||
/**
|
||||
* Common: 公共查询模型
|
||||
* Author: wu-hui
|
||||
* Time: 2024/02/03 10:02
|
||||
* @param array $params
|
||||
* @return ExchangeQuota
|
||||
*/
|
||||
public function searchModel(array $params){
|
||||
$quotaType = $params['quota_type'] ?? 1;// 存在指定类型则使用指定类型,否则使用默认类型(默认酒卡)
|
||||
$quotaType = in_array((int)$quotaType,[1,2]) ? $quotaType : 1;// 类型非法,使用默认类型
|
||||
|
||||
|
||||
|
||||
return (new ExchangeQuota())
|
||||
->where('quota_type', $quotaType)
|
||||
->when(isset($params['id']) && $params['id'] !== '',function($query) use ($params){
|
||||
$query->where('id', (int)$params['id']);
|
||||
})
|
||||
->when(isset($params['uid']) && $params['uid'] !== '',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');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -14,9 +14,44 @@ class ExchangeQuotaRecordDao extends BaseDao{
|
|||
protected function getModel(): string{
|
||||
return ExchangeQuotaRecord::class;
|
||||
}
|
||||
/**
|
||||
* Common: 公共搜索模型
|
||||
* Author: wu-hui
|
||||
* Time: 2024/02/03 10:39
|
||||
* @param array $params
|
||||
* @return ExchangeQuotaRecord
|
||||
*/
|
||||
public function searchModel(array $params){
|
||||
$quotaType = $params['quota_type'] ?? 1;// 存在指定类型则使用指定类型,否则使用默认类型(默认酒卡)
|
||||
$quotaType = in_array((int)$quotaType,[1,2]) ? $quotaType : 1;// 类型非法,使用默认类型
|
||||
|
||||
|
||||
|
||||
return (new ExchangeQuotaRecord())
|
||||
->where('quota_type', $quotaType)
|
||||
->when(isset($params['id']) && $params['id'] !== '',function($query) use ($params){
|
||||
$query->where('id', (int)$params['id']);
|
||||
})
|
||||
->when(isset($params['uid']) && $params['uid'] !== '',function($query) use ($params){
|
||||
$query->where('uid', (int)$params['uid']);
|
||||
})
|
||||
->when(isset($params['order_id']) && $params['order_id'] !== '',function($query) use ($params){
|
||||
$query->where('order_id', (int)$params['order_id']);
|
||||
})
|
||||
->when(isset($params['change_type']) && $params['change_type'] !== '',function($query) use ($params){
|
||||
$query->where('change_type', (int)$params['change_type']);
|
||||
})
|
||||
->when(isset($params['source']) && $params['source'] !== '',function($query) use ($params){
|
||||
$query->where('source', (int)$params['source']);
|
||||
})
|
||||
->when(isset($params['order_product_id']) && $params['order_product_id'] !== '',function($query) use ($params){
|
||||
$query->where('order_product_id', (int)$params['order_product_id']);
|
||||
})
|
||||
->with([
|
||||
'user' => function($query){
|
||||
$query->field('uid,nickname,avatar')->bind(['nickname','avatar']);
|
||||
},
|
||||
])
|
||||
->order('create_time DESC,id DESC');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -388,6 +388,7 @@ class GroupDataRepository extends BaseRepository
|
|||
Elm::number('price','优惠价')->required()->col(12)->min(0),
|
||||
Elm::number('sort','排序')->col(12)->min(0),
|
||||
Elm::number('quota','赠送酒卡额度')->required()->col(12)->min(0),
|
||||
Elm::number('vegetable_quota','赠送菜卡额度')->required()->col(12)->min(0),
|
||||
Elm::switches('status','是否显示')
|
||||
->activeValue(1)
|
||||
->inactiveValue(0)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,18 @@ class ExchangeQuotaRecordRepository extends BaseRepository{
|
|||
public function __construct(ExchangeQuotaRecordDao $dao){
|
||||
$this->dao = $dao;
|
||||
}
|
||||
/**
|
||||
* Common: 公共搜索模型
|
||||
* Author: wu-hui
|
||||
* Time: 2024/02/03 10:33
|
||||
* @param $search
|
||||
* @return \app\common\model\user\ExchangeQuotaRecord
|
||||
*/
|
||||
public function searchModel($search){
|
||||
return $this->dao->searchModel($search);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Common: 获取信息列表
|
||||
* Author: wu-hui
|
||||
|
|
@ -25,16 +37,7 @@ class ExchangeQuotaRecordRepository extends BaseRepository{
|
|||
* @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');
|
||||
$query = $this->dao->searchModel($params);
|
||||
$count = $query->count();
|
||||
$list = $query->page($page,$limit)->select();
|
||||
|
||||
|
|
|
|||
|
|
@ -17,14 +17,26 @@ class ExchangeQuotaRepository extends BaseRepository{
|
|||
public function __construct(ExchangeQuotaDao $dao){
|
||||
$this->dao = $dao;
|
||||
}
|
||||
/**
|
||||
* Common: 公共查询模型
|
||||
* Author: wu-hui
|
||||
* Time: 2024/02/03 9:53
|
||||
* @param $search
|
||||
* @return mixed
|
||||
*/
|
||||
public function searchModel($search){
|
||||
return $this->dao->searchModel($search);
|
||||
}
|
||||
|
||||
/**
|
||||
* Common: 获取统计信息
|
||||
* Author: wu-hui
|
||||
* Time: 2024/01/11 9:51
|
||||
* @param $params
|
||||
* @return array
|
||||
*/
|
||||
public function getStat():array{
|
||||
$model = $this->dao->getSearch([]);
|
||||
public function getStat($params):array{
|
||||
$model = $this->dao->searchModel($params);
|
||||
return [
|
||||
'sum_total_quota' => $model->sum('total_quota'),// 平台总额度
|
||||
'sum_use_quota' => $model->sum('use_quota'),// 平台已使用额度
|
||||
|
|
@ -46,16 +58,7 @@ class ExchangeQuotaRepository extends BaseRepository{
|
|||
* @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');
|
||||
$query = $this->dao->searchModel($params);
|
||||
$count = $query->count();
|
||||
$list = $query->page($page,$limit)->select();
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@ class ExchangeQuota extends BaseController
|
|||
* @return mixed
|
||||
*/
|
||||
public function quotaTitle(){
|
||||
$statInfo = app()->make(ExchangeQuotaRepository::class)->getStat();
|
||||
$params = $this->request->params(['quota_type']);
|
||||
$statInfo = app()->make(ExchangeQuotaRepository::class)->getStat($params);
|
||||
|
||||
$data = [
|
||||
['className' => 'el-icon-coin','count' => $statInfo['sum_total_quota'],'field' => '分','name' => '平台总额度'],
|
||||
|
|
@ -42,7 +43,7 @@ class ExchangeQuota extends BaseController
|
|||
*/
|
||||
public function quotaList(){
|
||||
[$page, $limit] = $this->getPage();
|
||||
$params = $this->request->params(['uid']);
|
||||
$params = $this->request->params(['uid','quota_type']);
|
||||
|
||||
$data = app()->make(ExchangeQuotaRepository::class)->getList((array)$params,(int)$page,(int)$limit);
|
||||
|
||||
|
|
@ -56,7 +57,7 @@ class ExchangeQuota extends BaseController
|
|||
*/
|
||||
public function quotaRecordList(){
|
||||
[$page, $limit] = $this->getPage();
|
||||
$params = $this->request->params(['uid']);
|
||||
$params = $this->request->params(['uid','quota_type']);
|
||||
|
||||
$data = app()->make(ExchangeQuotaRecordRepository::class)->getList((array)$params,(int)$page,(int)$limit);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ namespace app\listener\exchangeQuota;
|
|||
use app\common\model\user\ExchangeQuota;
|
||||
use app\common\model\user\ExchangeQuotaRecord;
|
||||
use app\common\repositories\store\order\StoreRefundProductRepository;
|
||||
use app\common\repositories\user\ExchangeQuotaRecordRepository;
|
||||
use app\common\repositories\user\ExchangeQuotaRepository;
|
||||
use think\facade\Log;
|
||||
|
||||
|
||||
|
|
@ -32,13 +34,14 @@ class OrderAgreeRefundEvent{
|
|||
if((int)$refundProductInfo['refund_num'] <= 0) continue;
|
||||
$refundRate = (float)sprintf("%.2f",(int)$refundProductInfo['refund_num'] / (int)$refundProductInfo['product']['product_num'] * 100);
|
||||
// 计算减少额度
|
||||
$sum = (float)ExchangeQuotaRecord::where('order_product_id',$refundProductInfo['order_product_id'])
|
||||
->where('change_type',1)
|
||||
->sum('change_quantity');
|
||||
$sum = (float)app()->make(ExchangeQuotaRecordRepository::class)->searchModel([
|
||||
'order_product_id' => $refundProductInfo['order_product_id'],
|
||||
'change_type' => 1
|
||||
])->sum('change_quantity');
|
||||
$refundQuota = (float)sprintf("%.2f",$sum * $refundRate / 100);
|
||||
if($refundQuota > 0){
|
||||
// 修改用户持有信息
|
||||
$userHoldInfo = ExchangeQuota::where('uid',$refund['uid'])->findOrEmpty();
|
||||
$userHoldInfo = app()->make(ExchangeQuotaRepository::class)->searchModel(['uid'=>$refund['uid']])->findOrEmpty();
|
||||
$changeFront = (float)$userHoldInfo->surplus_quota;
|
||||
$userHoldInfo->total_quota -= (float)$refundQuota;// 总额度
|
||||
$userHoldInfo->surplus_quota -= (float)$refundQuota;// 剩余额度
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use app\common\model\user\User;
|
|||
use app\common\repositories\marketing\AgentBrokerageRepository;
|
||||
use app\common\repositories\system\merchant\MerchantRepository;
|
||||
use app\common\repositories\user\ExchangePickupPointRepository;
|
||||
use app\common\repositories\user\ExchangeQuotaRepository;
|
||||
use think\facade\Log;
|
||||
|
||||
class OrderPaySuccessEvent{
|
||||
|
|
@ -48,7 +49,7 @@ class OrderPaySuccessEvent{
|
|||
// 支付成功 - 赠送酒卡额度
|
||||
public function orderPaySuccessHandle($groupOrder):bool{
|
||||
// 获取用户当前持有
|
||||
$userHoldInfo = ExchangeQuota::where('uid',$groupOrder->uid)->findOrEmpty();
|
||||
$userHoldInfo = app()->make(ExchangeQuotaRepository::class)->searchModel(['uid'=>$groupOrder->uid])->findOrEmpty();
|
||||
if((int)$userHoldInfo->uid <= 0) $userHoldInfo->uid = $groupOrder->uid;
|
||||
$exchangeQuotaMultiple = (int)systemConfig('exchange_quota_multiple');
|
||||
// 循环处理单个商品
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ namespace app\listener\exchangeQuota;
|
|||
|
||||
use app\common\model\user\ExchangeQuota;
|
||||
use app\common\model\user\ExchangeQuotaRecord;
|
||||
use app\common\repositories\user\ExchangeQuotaRecordRepository;
|
||||
use app\common\repositories\user\ExchangeQuotaRepository;
|
||||
use think\facade\Log;
|
||||
|
||||
|
||||
|
|
@ -16,18 +18,22 @@ class OrderTakeEvent{
|
|||
$order = $data['order'];
|
||||
// Log::info('订单进入待评价 - 酒卡额度相关处理 - 开始: '.var_export(['order_id' => $order->order_id,'uid' => $order->uid],1));
|
||||
# 获取变更记录 条件:order_id=当前订单id、变更类型=增加
|
||||
$sum = (float)ExchangeQuotaRecord::where('order_id',$order->order_id)
|
||||
->where('change_type',1)
|
||||
->where('source',0) // 仅查询购买赠送 进行解冻
|
||||
->sum('change_quantity');
|
||||
$refundSum = (float)ExchangeQuotaRecord::where('order_id',$order->order_id)
|
||||
->where('change_type',0)
|
||||
->where('source',1) // 仅查询订单退款 减少内容
|
||||
->sum('change_quantity');
|
||||
$sum = (float)app()->make(ExchangeQuotaRecordRepository::class)
|
||||
->searchModel([
|
||||
'order_id' => $order->order_id,
|
||||
'change_type' => 1,
|
||||
'source' => 0,// 仅查询购买赠送 进行解冻
|
||||
])->sum('change_quantity');
|
||||
$refundSum = (float)app()->make(ExchangeQuotaRecordRepository::class)
|
||||
->searchModel([
|
||||
'order_id' => $order->order_id,
|
||||
'change_type' => 0,
|
||||
'source' => 1,// 仅查询订单退款 减少内容
|
||||
])->sum('change_quantity');
|
||||
// 剩余数量 解冻
|
||||
$surplusQuota = (float)sprintf("%.2f",$sum - $refundSum);
|
||||
if($surplusQuota > 0){
|
||||
$hold = ExchangeQuota::where('uid',$order->uid)->findOrEmpty();
|
||||
$hold = app()->make(ExchangeQuotaRepository::class)->searchModel(['uid'=>$order->uid])->findOrEmpty();
|
||||
$freezeQuota = sprintf("%.2f",$hold->freeze_quota - $surplusQuota);
|
||||
$hold->freeze_quota = $freezeQuota < 0 ? 0 : $freezeQuota;
|
||||
$hold->save();
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ use app\common\model\store\order\StoreOrder;
|
|||
use app\common\model\user\ExchangeQuota;
|
||||
use app\common\model\user\ExchangeQuotaRecord;
|
||||
use app\common\repositories\store\order\StoreOrderRepository;
|
||||
use app\common\repositories\user\ExchangeQuotaRecordRepository;
|
||||
use app\common\repositories\user\ExchangeQuotaRepository;
|
||||
use think\facade\Log;
|
||||
|
||||
|
||||
|
|
@ -20,14 +22,17 @@ class OrderVerifyEvent{
|
|||
// 判断:如果存在上级id 则使用上级id
|
||||
$orderId = $order->main_id > 0 ? $order->main_id : $order->order_id;
|
||||
# 获取变更记录 条件:order_id=当前订单id、变更类型=增加
|
||||
$sum = (float)ExchangeQuotaRecord::where('order_id',$orderId)
|
||||
->where('change_type',1)
|
||||
->where('source',0) // 仅查询购买赠送 进行解冻
|
||||
->sum('change_quantity');
|
||||
$refundSum = (float)ExchangeQuotaRecord::where('order_id',$orderId)
|
||||
->where('change_type',0)
|
||||
->where('source',1) // 仅查询订单退款 减少内容
|
||||
->sum('change_quantity');
|
||||
$sum = (float)app()->make(ExchangeQuotaRecordRepository::class)->searchModel([
|
||||
'order_id' => $orderId,
|
||||
'change_type' => 1,
|
||||
'source' => 0,// 仅查询购买赠送 进行解冻
|
||||
])->sum('change_quantity');
|
||||
$refundSum = (float)app()->make(ExchangeQuotaRecordRepository::class)
|
||||
->searchModel([
|
||||
'order_id' => $orderId,
|
||||
'change_type' => 0,
|
||||
'source' => 1,// 仅查询订单退款 减少内容
|
||||
])->sum('change_quantity');
|
||||
// 剩余数量 解冻
|
||||
$surplusQuota = (float)sprintf("%.2f",$sum - $refundSum);
|
||||
if($surplusQuota > 0){
|
||||
|
|
@ -37,7 +42,7 @@ class OrderVerifyEvent{
|
|||
$rate = (float)sprintf("%.2f",$currentTotalNum / $totalNum * 100);
|
||||
$surplusQuota = (float)sprintf("%.2f",$surplusQuota * $rate / 100);
|
||||
// 解冻操作
|
||||
$hold = ExchangeQuota::where('uid',$order->uid)->findOrEmpty();
|
||||
$hold = app()->make(ExchangeQuotaRepository::class)->searchModel(['uid'=>$order->uid])->findOrEmpty();
|
||||
$freezeQuota = sprintf("%.2f",$hold->freeze_quota - $surplusQuota);
|
||||
$hold->freeze_quota = $freezeQuota < 0 ? 0 : $freezeQuota;
|
||||
$hold->save();
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ use app\common\model\marketing\Agent;
|
|||
use app\common\model\marketing\AgentBrokerage;
|
||||
use app\common\model\store\service\StoreService;
|
||||
use app\common\model\system\merchant\Merchant;
|
||||
use app\common\model\user\ExchangeQuota;
|
||||
use app\common\model\user\ExchangeQuotaRecord;
|
||||
use app\common\repositories\user\ExchangeQuotaRepository;
|
||||
use think\facade\Log;
|
||||
|
||||
|
||||
|
|
@ -36,12 +36,12 @@ class OrderVipPayEvent{
|
|||
// 'uid' => $order->uid ?? '',
|
||||
// 'order_info' => $order->order_info ?? ''
|
||||
// ],1));
|
||||
|
||||
// 赠送数量
|
||||
$insertData = [];
|
||||
// 酒卡赠送处理
|
||||
$giveNum = (float)$vipInfo['quota'] ?? 0;
|
||||
if((float)$giveNum > 0){
|
||||
// 获取用户当前持有
|
||||
$userHoldInfo = ExchangeQuota::where('uid',$order->uid )->findOrEmpty();
|
||||
$userHoldInfo = app()->make(ExchangeQuotaRepository::class)->searchModel(['uid'=>$order->uid])->findOrEmpty();
|
||||
if((int)$userHoldInfo->uid <= 0) $userHoldInfo->uid = $order->uid;
|
||||
// 赠送
|
||||
$changeFront = (float)$userHoldInfo->surplus_quota;
|
||||
|
|
@ -60,9 +60,40 @@ class OrderVipPayEvent{
|
|||
'change_after' => (float)$userHoldInfo->surplus_quota,
|
||||
'remark' => "购买会员卡赠送",
|
||||
'source' => 3,
|
||||
'quota_type' => 1,
|
||||
];
|
||||
ExchangeQuotaRecord::insertAll($insertData);
|
||||
}
|
||||
// 菜卡赠送处理
|
||||
$giveNum = (float)$vipInfo['vegetable_quota'] ?? 0;
|
||||
if((float)$giveNum > 0){
|
||||
// 获取用户当前持有
|
||||
$userHoldInfo = app()->make(ExchangeQuotaRepository::class)
|
||||
->searchModel(['uid' => $order->uid,'quota_type' => 2])
|
||||
->findOrEmpty();
|
||||
if((int)$userHoldInfo->uid <= 0) $userHoldInfo->uid = $order->uid;
|
||||
// 赠送
|
||||
$changeFront = (float)$userHoldInfo->surplus_quota;
|
||||
$userHoldInfo->total_quota += (float)$giveNum;// 总额度
|
||||
$userHoldInfo->surplus_quota += (float)$giveNum;// 剩余额度
|
||||
$userHoldInfo->quota_type = 2;// 额度类型
|
||||
$userHoldInfo->save();
|
||||
// 记录
|
||||
$insertData[] = [
|
||||
'uid' => $order->uid,
|
||||
'product_id' => 0,
|
||||
'order_id' => $order->order_id,
|
||||
'order_product_id' => 0,
|
||||
'change_type' => 1,
|
||||
'change_quantity' => (float)$giveNum,
|
||||
'change_front' => $changeFront,
|
||||
'change_after' => (float)$userHoldInfo->surplus_quota,
|
||||
'remark' => "购买会员卡赠送",
|
||||
'source' => 3,
|
||||
'quota_type' => 2,
|
||||
];
|
||||
}
|
||||
|
||||
if(count($insertData) > 0) ExchangeQuotaRecord::insertAll($insertData);
|
||||
}
|
||||
// 会员卡开通成功 - 分佣操作
|
||||
private function agentBrokerageHandle($order, $vipInfo){
|
||||
|
|
|
|||
Loading…
Reference in New Issue