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

赠送优惠券

@@ -85,6 +85,8 @@ class CenterController extends HomeBaseController @@ -85,6 +85,8 @@ class CenterController extends HomeBaseController
85 } 85 }
86 $post['id'] = session('user.id'); 86 $post['id'] = session('user.id');
87 if (Db::name('user')->update($post)) { 87 if (Db::name('user')->update($post)) {
  88 + give_as_a_present(session('user.id'), '完善信息赠送');
  89 + Db::name('user')->update(['id'=>session('user.id'), 'is_perfect'=>1]);
88 echo json_encode(['data' => '更改成功', 'code' => 20000]); 90 echo json_encode(['data' => '更改成功', 'code' => 20000]);
89 exit(); 91 exit();
90 } else { 92 } else {
@@ -1918,3 +1918,21 @@ function anti_analysis($lat, $lng) @@ -1918,3 +1918,21 @@ function anti_analysis($lat, $lng)
1918 return $tmpInfo; //返回json对象 1918 return $tmpInfo; //返回json对象
1919 } 1919 }
1920 1920
  1921 +//赠送优惠券
  1922 +function give_as_a_present($user_id, $name)
  1923 +{
  1924 + $is_perfect = Db::name('user')->where(['id' => $user_id])->value('is_perfect');
  1925 + if ($is_perfect == 0) {
  1926 + $data = Db::name('gift')->where(['id' => 1])->find();
  1927 + $present = [
  1928 + 'user_id' => $user_id,
  1929 + 'discount_coupon_name' => $name,
  1930 + 'overflow' => $data['overflow'],
  1931 + 'reduce' => $data['reduce'],
  1932 + 'deadline' => time() + 30 * 24 * 3600,
  1933 + 'status' => 1
  1934 + ];
  1935 + Db::name('discount_coupon')->insert($present);
  1936 + }
  1937 +}
  1938 +