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

赠送优惠券

@@ -139,7 +139,11 @@ class IndexController extends HomeBaseController @@ -139,7 +139,11 @@ class IndexController extends HomeBaseController
139 $tel = $request->param('tel'); 139 $tel = $request->param('tel');
140 if (Db::name('user')->where(['id' => $user_id])->value('is_first') == 1) { 140 if (Db::name('user')->where(['id' => $user_id])->value('is_first') == 1) {
141 Db::name('user')->update(['id' => $user_id, 'tel' => $tel, 'is_first' => 0]); 141 Db::name('user')->update(['id' => $user_id, 'tel' => $tel, 'is_first' => 0]);
142 - echo json_encode(['msg'=>'绑定成功']); 142 + $is_first = Db::name('user')->where(['id' => session('user.id')])->value('is_first');
  143 + if ($is_first == 1) {
  144 + give_as_a_present($user_id, '首次下单赠送');
  145 + }
  146 + echo json_encode(['msg' => '绑定成功']);
143 //领取优惠券 147 //领取优惠券
144 exit(); 148 exit();
145 } 149 }
@@ -85,8 +85,11 @@ class CenterController extends HomeBaseController @@ -85,8 +85,11 @@ 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 + $is_perfect = Db::name('user')->where(['id' => session('user.id')])->value('is_perfect');
  89 + if ($is_perfect == 0) {
88 give_as_a_present(session('user.id'), '完善信息赠送'); 90 give_as_a_present(session('user.id'), '完善信息赠送');
89 - Db::name('user')->update(['id'=>session('user.id'), 'is_perfect'=>1]); 91 + }
  92 + Db::name('user')->update(['id' => session('user.id'), 'is_perfect' => 1]);
90 echo json_encode(['data' => '更改成功', 'code' => 20000]); 93 echo json_encode(['data' => '更改成功', 'code' => 20000]);
91 exit(); 94 exit();
92 } else { 95 } else {
@@ -1921,8 +1921,6 @@ function anti_analysis($lat, $lng) @@ -1921,8 +1921,6 @@ function anti_analysis($lat, $lng)
1921 //赠送优惠券 1921 //赠送优惠券
1922 function give_as_a_present($user_id, $name) 1922 function give_as_a_present($user_id, $name)
1923 { 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(); 1924 $data = Db::name('gift')->where(['id' => 1])->find();
1927 $present = [ 1925 $present = [
1928 'user_id' => $user_id, 1926 'user_id' => $user_id,
@@ -1933,6 +1931,5 @@ function give_as_a_present($user_id, $name) @@ -1933,6 +1931,5 @@ function give_as_a_present($user_id, $name)
1933 'status' => 1 1931 'status' => 1
1934 ]; 1932 ];
1935 Db::name('discount_coupon')->insert($present); 1933 Db::name('discount_coupon')->insert($present);
1936 - }  
1937 } 1934 }
1938 1935