作者 lihan
1 个管道 的构建 通过 耗费 1 秒

赠送优惠券

... ... @@ -85,6 +85,8 @@ class CenterController extends HomeBaseController
}
$post['id'] = session('user.id');
if (Db::name('user')->update($post)) {
give_as_a_present(session('user.id'), '完善信息赠送');
Db::name('user')->update(['id'=>session('user.id'), 'is_perfect'=>1]);
echo json_encode(['data' => '更改成功', 'code' => 20000]);
exit();
} else {
... ...
... ... @@ -1918,3 +1918,21 @@ function anti_analysis($lat, $lng)
return $tmpInfo; //返回json对象
}
//赠送优惠券
function give_as_a_present($user_id, $name)
{
$is_perfect = Db::name('user')->where(['id' => $user_id])->value('is_perfect');
if ($is_perfect == 0) {
$data = Db::name('gift')->where(['id' => 1])->find();
$present = [
'user_id' => $user_id,
'discount_coupon_name' => $name,
'overflow' => $data['overflow'],
'reduce' => $data['reduce'],
'deadline' => time() + 30 * 24 * 3600,
'status' => 1
];
Db::name('discount_coupon')->insert($present);
}
}
... ...