'ID', 'mall_id' => '商城ID', 'user_id' => '会员ID', 'total_reward' => '总奖励', 'apply_num' => '申请次数', 'success_num' => '打卡成功次数', 'status' => '状态[0禁用 1启用 -1删除]', 'created_at' => '创建时间', 'updated_at' => '修改时间', ]; } /** * 关联用户 * @Author: lun * @DateTime: 2023/7/26 0026 9:43 * @Copyright: copyright (c) 2021 广东七件事集团 * @return \yii\db\ActiveQuery */ public function getUser() { return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,mobile,nickname,avatar_url'); } /** * 赠送奖励 * @Author: lun * @DateTime: 2023/7/26 0026 15:25 * @Copyright: copyright (c) 2021 广东七件事集团 * @param $apply * @throws Exception */ public static function giveReward($apply) { // 获取配置信息 $config = Yii::$app->services->setting->addons->get($apply['mall_id'], 'Clockin', 'basic'); // 获取当前用户信息 $model = self::findOne(['user_id' => $apply['user_id'], 'status' => StatusEnum::ENABLED]); if (empty($model)) { $model = new self(); $model->loadDefaultValues(); $model->mall_id = $apply['mall_id']; $model->user_id = $apply['user_id']; } // 计算可得积分 $reward_score = 0; $reward_limit = $config['reward_limit']??0; $reward_score = $apply['reward']; if (!empty($config['reward_limit']) && $model->total_reward + $apply['reward'] > $config['reward_limit']) { $reward_score = $config['reward_limit'] - $model->total_reward; $model->total_reward = $config['reward_limit']; } else { $model->total_reward += $reward_score; } if($reward_score>0&&empty($config['is_reward'])) throw new \Exception('奖励未开启'); if ($apply['is_pass'] == 1) $model->success_num += 1; if (!$model->save()) throw new Exception($model->getErrorMessage()); // 增加积分 if (!empty($reward_score)) { // 增加奖励记录 ClockinRewardLog::addLog($apply, $reward_score); $insert_wallet[] = [ 'mall_id' => $apply['mall_id'], 'user_id' => $apply['user_id'], 'is_frozen' => false, 'wallet_type' => 'score', 'money' => $reward_score, 'desc' => '打卡奖励', 'source_table' => '', 'source_table_id' => 0, 'from_type' => 'Clockin', 'capital_type' => 'give', ]; $res = UserWalletService::batchHandleByQueue($insert_wallet); if (empty($res)) throw new \Exception('打卡插入钱包队列:' . UserWalletService::getStaticError()); } return ['reward_score'=>$reward_score,'reward_limit'=>$reward_limit]; } }