feat: add channel code integral reward

This commit is contained in:
danaisuiyuan
2026-05-21 06:46:18 +08:00
parent ab65147b82
commit 673a19b3f7
8 changed files with 95 additions and 10 deletions

View File

@@ -51,8 +51,7 @@ class Clear extends AuthController
public function delete_log() public function delete_log()
{ {
$this->services->deleteLog(); $this->services->deleteLog();
return $this->success('数据缓存刷新成功!'); return $this->success('系统日志清除成功!');
} }
} }

View File

@@ -14,6 +14,7 @@ use app\jobs\user\UserJob;
use app\jobs\user\UserMoneyJob; use app\jobs\user\UserMoneyJob;
use app\jobs\user\UserSpreadJob; use app\jobs\user\UserSpreadJob;
use app\services\community\CommunityUserServices; use app\services\community\CommunityUserServices;
use app\services\other\QrcodeServices;
use app\services\user\UserBillServices; use app\services\user\UserBillServices;
use app\services\user\UserServices; use app\services\user\UserServices;
use crmeb\interfaces\ListenerInterface; use crmeb\interfaces\ListenerInterface;
@@ -51,6 +52,7 @@ class Register implements ListenerInterface
UserSpreadJob::dispatch([$uid, $spreadUid]); UserSpreadJob::dispatch([$uid, $spreadUid]);
} }
if ($is_new) { if ($is_new) {
$this->giveChannelCodeIntegral($uid, $userInfo);
//修改用户会员卡激活状态 //修改用户会员卡激活状态
UserJob::dispatchDo('setUserLevel', [$uid]); UserJob::dispatchDo('setUserLevel', [$uid]);
if (app()->make(UserServices::class)->getUserOnlyTrashedCount($uid)) { if (app()->make(UserServices::class)->getUserOnlyTrashedCount($uid)) {
@@ -75,4 +77,49 @@ class Register implements ListenerInterface
event('notice.notice', [['spreadUid' => $spread_uid, 'user_type' => $userInfo['user_type'], 'nickname' => $userInfo['nickname']], 'bind_spread_uid']); event('notice.notice', [['spreadUid' => $spread_uid, 'user_type' => $userInfo['user_type'], 'nickname' => $userInfo['nickname']], 'bind_spread_uid']);
} }
} }
/**
* 新用户扫指定分销员小程序码后赠送积分,一名新用户仅在注册事件中尝试一次。
*/
protected function giveChannelCodeIntegral(int $uid, array $userInfo): void
{
if (!$uid || !(int)sys_config('channel_code_integral_status', 0)) {
return;
}
$agentUid = (int)sys_config('channel_code_agent_uid', 0);
$integral = (int)sys_config('channel_code_give_integral', 0);
$qrcodeId = (int)($userInfo['spread_qrcode_id'] ?? 0);
if (!$agentUid || $integral <= 0 || !$qrcodeId) {
return;
}
/** @var QrcodeServices $qrcodeServices */
$qrcodeServices = app()->make(QrcodeServices::class);
$qrcodeInfo = $qrcodeServices->get($qrcodeId);
if (!$qrcodeInfo || (int)$qrcodeInfo['third_id'] !== $agentUid || ($qrcodeInfo['third_type'] ?? '') !== 'spread_routine') {
return;
}
/** @var UserBillServices $userBillServices */
$userBillServices = app()->make(UserBillServices::class);
if ($userBillServices->count(['uid' => $uid, 'type' => 'channel_code_add'])) {
return;
}
/** @var UserServices $userServices */
$userServices = app()->make(UserServices::class);
$balance = (int)$userServices->value(['uid' => $uid], 'integral');
$newBalance = $balance + $integral;
$userServices->bcInc($uid, 'integral', (string)$integral, 'uid', 0);
$userBillServices->income(
'channel_code_give_integral',
$uid,
$integral,
$newBalance,
$qrcodeId,
0,
'扫码渠道码赠送' . $integral . '积分'
);
}
} }

View File

@@ -1629,7 +1629,8 @@ class SystemConfigServices extends BaseServices implements ServeConfigInterface
$data = $this->getConfigAllField([ $data = $this->getConfigAllField([
'integral_ratio_status', 'integral_ratio', 'integral_max_type', 'integral_max_num', 'integral_max_rate', 'order_give_integral', 'integral_effective_status', 'integral_ratio_status', 'integral_ratio', 'integral_max_type', 'integral_max_num', 'integral_max_rate', 'order_give_integral', 'integral_effective_status',
'integral_effective_time', 'next_clear_month_time', 'next_clear_quarter_time', 'next_clear_year_time', 'integral_frozen' 'integral_effective_time', 'next_clear_month_time', 'next_clear_quarter_time', 'next_clear_year_time', 'integral_frozen',
'channel_code_integral_status', 'channel_code_agent_uid', 'channel_code_give_integral'
]); ]);
/** @var UserIntegralServices $userIntergralServices */ /** @var UserIntegralServices $userIntergralServices */
@@ -1650,6 +1651,10 @@ class SystemConfigServices extends BaseServices implements ServeConfigInterface
])->options($this->getOptions($data['integral_max_type']['parameter'])) ])->options($this->getOptions($data['integral_max_type']['parameter']))
])->info($data['integral_ratio_status']['desc']), ])->info($data['integral_ratio_status']['desc']),
Build::inputNum('order_give_integral', $data['order_give_integral']['info'], $data['order_give_integral']['value'])->info($data['order_give_integral']['desc'])->min(0), Build::inputNum('order_give_integral', $data['order_give_integral']['info'], $data['order_give_integral']['value'])->info($data['order_give_integral']['desc'])->min(0),
Build::switch('channel_code_integral_status', $data['channel_code_integral_status']['info'], (int)$data['channel_code_integral_status']['value'])
->falseValue('关闭', 0)->trueValue('开启', 1)->info($data['channel_code_integral_status']['desc']),
Build::inputNum('channel_code_agent_uid', $data['channel_code_agent_uid']['info'], $data['channel_code_agent_uid']['value'])->info($data['channel_code_agent_uid']['desc'])->min(0),
Build::inputNum('channel_code_give_integral', $data['channel_code_give_integral']['info'], $data['channel_code_give_integral']['value'])->info($data['channel_code_give_integral']['desc'])->min(0),
Build::radio('integral_effective_status', $data['integral_effective_status']['info'], $data['integral_effective_status']['value']) Build::radio('integral_effective_status', $data['integral_effective_status']['info'], $data['integral_effective_status']['value'])
->info($data['integral_effective_status']['desc'])->control(1, [ ->info($data['integral_effective_status']['desc'])->control(1, [
Build::radio('integral_effective_time', $data['integral_effective_time']['info'], $data['integral_effective_time']['value']) Build::radio('integral_effective_time', $data['integral_effective_time']['info'], $data['integral_effective_time']['value'])

View File

@@ -20,7 +20,10 @@ class ClearServices extends BaseServices
*/ */
protected function delDirAndFile($dirName) protected function delDirAndFile($dirName)
{ {
$list = glob($dirName . '*'); if (!is_dir($dirName)) {
return;
}
$list = glob($dirName . '*') ?: [];
foreach ($list as $file) { foreach ($list as $file) {
if (is_dir($file)) if (is_dir($file))
$this->delDirAndFile($file . DS); $this->delDirAndFile($file . DS);

View File

@@ -135,6 +135,14 @@ class UserBillServices extends BaseServices
'status' => 1, 'status' => 1,
'pm' => 1 'pm' => 1
], ],
'channel_code_give_integral' => [
'title' => '渠道码赠送积分',
'category' => 'integral',
'type' => 'channel_code_add',
'mark' => '扫码渠道码赠送{%num%}积分',
'status' => 1,
'pm' => 1
],
'level_give_integral' => [ 'level_give_integral' => [
'title' => '会员卡激活赠送积分', 'title' => '会员卡激活赠送积分',
'category' => 'integral', 'category' => 'integral',

View File

@@ -376,7 +376,9 @@ class UserServices extends BaseServices
// 用户注册成功事件 // 用户注册成功事件
$userInfo = array_merge($res->toArray(), [ $userInfo = array_merge($res->toArray(), [
'unionid' => $user['unionid'] ?? '' 'unionid' => $user['unionid'] ?? '',
'spread_qrcode_id' => (int)($user['spread_qrcode_id'] ?? 0),
'spread_qrcode_type' => $user['spread_qrcode_type'] ?? ''
]); ]);
event('user.register', [$userInfo, true, $spreadUid]); event('user.register', [$userInfo, true, $spreadUid]);

View File

@@ -275,6 +275,8 @@ class RoutineServices extends BaseServices
$info = $qrcode->get((int)$routine['spread_code']); $info = $qrcode->get((int)$routine['spread_code']);
if ($info) { if ($info) {
$spread_uid = $info['third_id']; $spread_uid = $info['third_id'];
$routineInfo['spread_qrcode_id'] = (int)$info['id'];
$routineInfo['spread_qrcode_type'] = $info['third_type'] ?? '';
} }
} }
return [$routine['openid'] ?? '', $routineInfo, $spread_uid, $routine['login_type'] ?? 'routine', 'routine']; return [$routine['openid'] ?? '', $routineInfo, $spread_uid, $routine['login_type'] ?? 'routine', 'routine'];

View File

@@ -69,6 +69,9 @@
<template slot-scope="{ row }" slot="agentLevel"> <template slot-scope="{ row }" slot="agentLevel">
<div>{{ row.agentLevel ? row.agentLevel.name : "--" }}</div> <div>{{ row.agentLevel ? row.agentLevel.name : "--" }}</div>
</template> </template>
<template slot-scope="{ row }" slot="xcxCode">
<a @click="showXcxCode(row)">查看</a>
</template>
<template slot-scope="{ row, index }" slot="right"> <template slot-scope="{ row, index }" slot="right">
<a @click="promoters(row, 'man', 2)">推广人</a> <a @click="promoters(row, 'man', 2)">推广人</a>
<Divider type="vertical" /> <Divider type="vertical" />
@@ -268,11 +271,6 @@ export default {
slot: "nickname", slot: "nickname",
minWidth: 150, minWidth: 150,
}, },
{
title: "推广用户数量",
key: "spread_count",
minWidth: 125,
},
{ {
title: "订单数量", title: "订单数量",
key: "order_count", key: "order_count",
@@ -308,6 +306,16 @@ export default {
key: "new_money", key: "new_money",
minWidth: 105, minWidth: 105,
}, },
{
title: "小程序推广码",
slot: "xcxCode",
minWidth: 120,
},
{
title: "推广用户数量",
key: "spread_count",
minWidth: 125,
},
{ {
title: "上级推广人", title: "上级推广人",
key: "spread_name", key: "spread_name",
@@ -542,9 +550,20 @@ export default {
spreadQR(row) { spreadQR(row) {
this.modals = true; this.modals = true;
this.rows = row; this.rows = row;
this.code_src = "";
this.code_xcx = "";
this.code_h5 = "";
// this.getWeChat(row); // this.getWeChat(row);
// this.getXcx(row); // this.getXcx(row);
}, },
showXcxCode(row) {
this.modals = true;
this.rows = row;
this.code_src = "";
this.code_xcx = "";
this.code_h5 = "";
this.getXcx();
},
// 公众号推广二维码 // 公众号推广二维码
getWeChat() { getWeChat() {
this.spinShow = true; this.spinShow = true;