|
|
@@ -312,7 +312,58 @@ class User extends AuthController
|
|
|
return Json::fail('赠送失败');
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ public static function login_give_level($uid = 0,$level_id=0)
|
|
|
+ {
|
|
|
+ if (!$uid) return Json::fail('缺少参数');
|
|
|
+// list($level_id) = Util::postMore([
|
|
|
+// ['level_id', 0],
|
|
|
+// ], $this->request, true);
|
|
|
+ //查询当前选择的会员等级
|
|
|
+ $systemLevel = SystemUserLevel::where(['is_show' => 1, 'is_del' => 0, 'id' => $level_id])->find();
|
|
|
+ if (!$systemLevel) return Json::fail('您选择赠送的会员等级不存在!');
|
|
|
+ //检查是否拥有此会员等级
|
|
|
+ $level = UserLevel::where(['uid' => $uid, 'level_id' => $level_id, 'is_del' => 0])->field('valid_time,is_forever')->find();
|
|
|
+ if ($level) if (!$level['is_forever'] && time() < $level['valid_time']) return Json::fail('此用户已有该会员等级,无法再次赠送');
|
|
|
+ //设置会员过期时间
|
|
|
+ $add_valid_time = (int)$systemLevel->valid_date * 86400;
|
|
|
+ UserModel::commitTrans();
|
|
|
+ try {
|
|
|
+ //保存会员信息
|
|
|
+ $res = UserLevel::create([
|
|
|
+ 'is_forever' => $systemLevel->is_forever,
|
|
|
+ 'status' => 1,
|
|
|
+ 'is_del' => 0,
|
|
|
+ 'grade' => $systemLevel->grade,
|
|
|
+ 'uid' => $uid,
|
|
|
+ 'add_time' => time(),
|
|
|
+ 'level_id' => $level_id,
|
|
|
+ 'discount' => $systemLevel->discount,
|
|
|
+ 'valid_time' => $systemLevel->discount ? $add_valid_time + time() : 0,
|
|
|
+ 'mark' => '尊敬的用户【' . UserModel::where('uid', $uid)->value('nickname') . '】在' . date('Y-m-d H:i:s', time()) . '赠送会员等级成为' . $systemLevel['name'] . '会员',
|
|
|
+ ]);
|
|
|
+ //提取等级任务并记录完成情况
|
|
|
+ $levelIds = [$level_id];
|
|
|
+ $lowGradeLevelIds = SystemUserLevel::where('grade', '<', $systemLevel->grade)->where(['is_show' => 1, 'is_del' => 0])->column('id', 'id');
|
|
|
+ if (count($lowGradeLevelIds)) $levelIds = array_merge($levelIds, $lowGradeLevelIds);
|
|
|
+ $taskIds = SystemUserTask::where('level_id', 'in', $levelIds)->column('id', 'id');
|
|
|
+ $inserValue = [];
|
|
|
+ foreach ($taskIds as $id) {
|
|
|
+ $inserValue[] = ['uid' => $uid, 'task_id' => $id, 'status' => 1, 'add_time' => time()];
|
|
|
+ }
|
|
|
+ $res = $res && UserModel::where('uid', $uid)->update(['level' => $level_id]);
|
|
|
+ if ($inserValue) $res && UserTaskFinish::insertAll($inserValue);
|
|
|
+ if ($res) {
|
|
|
+ UserModel::commitTrans();
|
|
|
+ return Json::successful('赠送成功');
|
|
|
+ } else {
|
|
|
+ UserModel::rollbackTrans();
|
|
|
+ return Json::successful('赠送失败');
|
|
|
+ }
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ UserModel::rollbackTrans();
|
|
|
+ return Json::fail('赠送失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
/*
|
|
|
* 清除会员等级
|
|
|
* @param int $uid
|