init commit
This commit is contained in:
71
application/api/model/wdsxh/activity/Activity.php
Normal file
71
application/api/model/wdsxh/activity/Activity.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\api\model\wdsxh\activity;
|
||||
|
||||
use app\api\model\wdsxh\Base;
|
||||
use app\common\model\wdsxh\points\UserWechatPointsLog;
|
||||
|
||||
/**
|
||||
* Class Activity
|
||||
* Desc 活动模型
|
||||
* Create on 2024/3/11 16:29
|
||||
* Create by wangyafang
|
||||
*/
|
||||
class Activity extends Base
|
||||
{
|
||||
// 表名
|
||||
protected $name = 'wdsxh_activity';
|
||||
|
||||
// 自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = false;
|
||||
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = false;
|
||||
protected $updateTime = false;
|
||||
protected $deleteTime = false;
|
||||
|
||||
protected static function init()
|
||||
{
|
||||
self::afterUpdate(function ($row) {
|
||||
// 仅当活动状态变更为"已结束"且开启积分功能时才发放积分
|
||||
if ($row['points_status'] == 1) {
|
||||
// 获取所有已审核通过的报名用户
|
||||
$activityApplyList = (new ActivityApply())
|
||||
->where('activity_id', $row['id'])
|
||||
->where('state', '2')
|
||||
->select();
|
||||
|
||||
if (empty($activityApplyList)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 遍历所有报名用户,为每个用户发放积分
|
||||
foreach ($activityApplyList as $activityApplyObj) {
|
||||
// 检查是否已经发放过积分,避免重复插入
|
||||
$existLog = UserWechatPointsLog::where('activity_id', $row['id'])
|
||||
->where('wechat_id', $activityApplyObj['wechat_id'])
|
||||
->where('source', 1)
|
||||
->where('memo', '参加活动')
|
||||
->find();
|
||||
|
||||
// 如果未发放过,则发放积分
|
||||
if (!$existLog) {
|
||||
UserWechatPointsLog::activity(1, $activityApplyObj, $row, '参加活动');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user