master
lion 4 weeks ago
parent 6a82bc34a1
commit cec50e36b7

@ -185,7 +185,13 @@ class UserController extends CommonController
if ($validator->fails()) {
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
}
$isVip = VipCustomer::where('mobile', $all['mobile'])->where('status', 1)->exists();
$mobile = trim((string) $all['mobile']);
$query = VipCustomer::where('mobile', $mobile)->where('status', 1);
$nameIn = isset($all['name']) ? trim((string) $all['name']) : '';
if ($nameIn !== '') {
$query->where('name', $nameIn);
}
$isVip = $query->exists();
return $this->success(['is_vip' => $isVip ? 1 : 0]);
}

@ -240,12 +240,14 @@ class VisitController extends CommonController
if ($mobile === '') {
$mobile = trim((string)(optional(User::find($this->getUserId()))->mobile ?? ''));
}
$isVip = $mobile !== '' && VipCustomer::where('mobile', $mobile)->where('status', 1)->exists();
$visitType = (int) $all['type'];
$isVipCustomer = $mobile !== '' && VipCustomer::where('mobile', $mobile)->where('status', 1)->exists();
// 仅 VIP 访客预约type=4且在名单中免答题普通/施工/物流1/2/3一律需测验
$isVipWatchOnly = ($visitType === 4) && $isVipCustomer;
$payload = $detail->toArray();
$payload['is_vip'] = $isVip ? 1 : 0;
// VIP仅观看资料不参与问答非 VIP必须答题
$payload['quiz_required'] = $isVip ? 0 : 1;
$payload['is_vip'] = $isVipWatchOnly ? 1 : 0;
$payload['quiz_required'] = $isVipWatchOnly ? 0 : 1;
return $this->success($payload);
}
@ -314,13 +316,29 @@ class VisitController extends CommonController
public function askLog()
{
$type = request('type');
// 按「访客类型」分别记录type=1/2/3 各自一条有效学习过期后需重新学习并答题VIP 为仅观看记录)
$log = StudyLog::where('type', $type)->where('user_id', $this->getUserId())->orderBy('id', 'desc')->first();
if ($type === null || $type === '') {
return $this->fail([ResponseCode::ERROR_PARAMETER, '类型必填']);
}
$idcard = trim((string) request('idcard', ''));
$query = StudyLog::where('type', $type);
// 与 idcard-check 一致:有证件号时按「类型+证件」取最新一条,避免仅删证件维度记录后仍被 user_id 旧数据命中
if ($idcard !== '') {
$query->where('idcard', $idcard);
} else {
$query->where('user_id', $this->getUserId());
}
$log = $query->orderBy('id', 'desc')->first();
if (empty($log)) {
return $this->fail([ResponseCode::ERROR_BUSINESS, '未学习']);
}
$diff = Carbon::parse($log->created_at)->diffInDays(Carbon::now());
if ($diff > $log->expire_day) {
$expireDay = (int) ($log->expire_day ?? 0);
if ($expireDay <= 0) {
$expireDay = 180;
}
if ($diff > $expireDay) {
return $this->fail([ResponseCode::ERROR_BUSINESS, '学习已过期,请重新学习']);
}
return $this->success("学习有效中");
@ -349,8 +367,8 @@ class VisitController extends CommonController
public function askSave()
{
$all = request()->all();
$type = $all['type'] ?? null;
if ($type === null || $type === '') {
$type = isset($all['type']) ? (int) $all['type'] : null;
if ($type === null || $type === 0) {
return $this->fail([ResponseCode::ERROR_PARAMETER, '类型必填']);
}
@ -363,7 +381,8 @@ class VisitController extends CommonController
if ($mobile === '') {
$mobile = trim((string)(optional(User::find($this->getUserId()))->mobile ?? ''));
}
$isVip = $mobile !== '' && VipCustomer::where('mobile', $mobile)->where('status', 1)->exists();
$isVipCustomer = $mobile !== '' && VipCustomer::where('mobile', $mobile)->where('status', 1)->exists();
$isVipWatchOnly = ($type === 4) && $isVipCustomer;
// 有效期以资料配置为准(天),不信任客户端篡改
$expireDay = $study->expire_day;
@ -379,7 +398,7 @@ class VisitController extends CommonController
$all['content'] = json_decode($all['content'], true);
}
if ($isVip) {
if ($isVipWatchOnly) {
$all['watch_only'] = 1;
$all['ask'] = [];
$all['content'] = $all['content'] ?? [];
@ -393,6 +412,7 @@ class VisitController extends CommonController
$model = new StudyLog();
$all['user_id'] = $this->getUserId();
$all['type'] = $type;
$model->fill($all);
$model->save();

@ -2,7 +2,7 @@
namespace App\Models;
class StudyLog extends CommonModel
class StudyLog extends SoftDeletesModel
{
protected $guarded = ['id'];

Loading…
Cancel
Save