作者 何书鹏
1 个管道 的构建 通过 耗费 5 秒

api更新

@@ -125,7 +125,27 @@ @@ -125,7 +125,27 @@
125 <div class="form-group"> 125 <div class="form-group">
126 <label class="control-label col-xs-12 col-sm-2">充值积分每分需多少元:</label> 126 <label class="control-label col-xs-12 col-sm-2">充值积分每分需多少元:</label>
127 <div class="col-xs-12 col-sm-8"> 127 <div class="col-xs-12 col-sm-8">
128 - <input id="c-score_price" class="form-control" name="row[score_recharge_price]" type="number" value="{$row.score_recharge_price}"> 128 + <input id="c-score_recharge_price" class="form-control" name="row[score_recharge_price]" type="number" value="{$row.score_recharge_price}">
  129 + </div>
  130 + </div>
  131 + <div class="form-group">
  132 + <label class="control-label col-xs-12 col-sm-2">客服二维码:</label>
  133 + <div class="col-xs-12 col-sm-8">
  134 + <div class="input-group">
  135 + <input id="c-service_qrcode" class="form-control" size="35" name="row[service_qrcode]" type="text" value="{$row.service_qrcode}">
  136 + <div class="input-group-addon no-border no-padding">
  137 + <span><button type="button" id="plupload-service_qrcode" class="btn btn-danger plupload" data-input-id="c-service_qrcode" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="false" data-preview-id="p-service_qrcode"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
  138 + <span><button type="button" id="fachoose-service_qrcode" class="btn btn-primary fachoose" data-input-id="c-service_qrcode" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
  139 + </div>
  140 + <span class="msg-box n-right"></span>
  141 + </div>
  142 + <ul class="row list-inline plupload-preview" id="p-service_qrcode"></ul>
  143 + </div>
  144 + </div>
  145 + <div class="form-group">
  146 + <label class="control-label col-xs-12 col-sm-2">客服电话:</label>
  147 + <div class="col-xs-12 col-sm-8">
  148 + <input id="c-service_phone" class="form-control" name="row[service_phone]" type="text" value="{$row.service_phone}">
129 </div> 149 </div>
130 </div> 150 </div>
131 <div class="form-group layer-footer"> 151 <div class="form-group layer-footer">
@@ -799,6 +799,11 @@ class Company extends Api @@ -799,6 +799,11 @@ class Company extends Api
799 // 创建订单 799 // 创建订单
800 $model = new PackageOrder; 800 $model = new PackageOrder;
801 $model->add($this->auth->getUser(), $param['pay_type']); 801 $model->add($this->auth->getUser(), $param['pay_type']);
  802 + // 零元直接支付成功
  803 + if($model['pay_price'] <= 0){
  804 + (new Notify)->notifyPackageZero($model['order_sn'],$model['pay_price'],$param['pay_type']);
  805 + $this->success('成功',[]);
  806 + }
802 //回调链接 807 //回调链接
803 $notifyurl = $this->request->root(true) . '/mobile/notify/notifyPackage/paytype/' . $param['pay_type']; 808 $notifyurl = $this->request->root(true) . '/mobile/notify/notifyPackage/paytype/' . $param['pay_type'];
804 $model['pay_price'] = 0.01; //测试金额 809 $model['pay_price'] = 0.01; //测试金额
@@ -434,6 +434,28 @@ class Course extends Api @@ -434,6 +434,28 @@ class Course extends Api
434 } 434 }
435 435
436 /** 436 /**
  437 + * @ApiTitle (联系客服)
  438 + * @ApiSummary (联系客服)
  439 + * @ApiMethod (POST)
  440 + *
  441 + * @ApiReturn({
  442 + "code": 1,
  443 + "msg": "成功",
  444 + "time": "1606961557",
  445 + "data": {
  446 + "service_qrcode": "http://qizhibang.brotop.cn/uploads/20200811/b9bbd60dcacbcb649579155f63b62558.png", //客服二维码
  447 + "service_phone": "0311-28907" //客服电话
  448 + }
  449 + })
  450 + */
  451 + public function service()
  452 + {
  453 + $config = Db::name('mobile_config')->where('id',1)->field('service_qrcode,service_phone')->find();
  454 + $config['service_qrcode'] = !empty($config['service_qrcode']) ? cdnurl($config['service_qrcode'],true) : '';
  455 + $this->success('成功', $config);
  456 + }
  457 +
  458 + /**
437 * @ApiTitle (购买预览) 459 * @ApiTitle (购买预览)
438 * @ApiSummary (购买预览) 460 * @ApiSummary (购买预览)
439 * @ApiMethod (POST) 461 * @ApiMethod (POST)
@@ -507,6 +529,11 @@ class Course extends Api @@ -507,6 +529,11 @@ class Course extends Api
507 // 创建订单 529 // 创建订单
508 $model = new CourseOrder; 530 $model = new CourseOrder;
509 $model->add($this->auth->getUser(), $order, $param['pay_type']); 531 $model->add($this->auth->getUser(), $order, $param['pay_type']);
  532 + // 零元直接支付成功
  533 + if($model['pay_price'] <= 0){
  534 + (new Notify)->notifyCourseZero($model['order_sn'],$model['pay_price'],$param['pay_type']);
  535 + $this->success('成功',[]);
  536 + }
510 //回调链接 537 //回调链接
511 $notifyurl = $this->request->root(true) . '/mobile/notify/notifyCourse/paytype/' . $param['pay_type']; 538 $notifyurl = $this->request->root(true) . '/mobile/notify/notifyCourse/paytype/' . $param['pay_type'];
512 $model['pay_price'] = 0.01; //测试金额 539 $model['pay_price'] = 0.01; //测试金额
@@ -25,7 +25,7 @@ class Notify extends Api @@ -25,7 +25,7 @@ class Notify extends Api
25 } 25 }
26 26
27 /** 27 /**
28 - * 课程 28 + * 课程---------------------------------------------------------------------
29 */ 29 */
30 public function notifyCourse() 30 public function notifyCourse()
31 { 31 {
@@ -39,7 +39,38 @@ class Notify extends Api @@ -39,7 +39,38 @@ class Notify extends Api
39 try { 39 try {
40 $payamount = $paytype == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100; 40 $payamount = $paytype == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100;
41 $out_trade_no = $data['out_trade_no']; 41 $out_trade_no = $data['out_trade_no'];
  42 + // 处理订单
  43 + $this->handleCourseOrder($out_trade_no,$payamount,$paytype);
  44 + } catch (Exception $e) {
  45 + }
  46 + echo $pay->success();
  47 + }
42 48
  49 + /**
  50 + * 课程-零元支付
  51 + */
  52 + public function notifyCourseZero($out_trade_no,$payamount,$paytype)
  53 + {
  54 + Db::startTrans();
  55 + try {
  56 + $this->handleCourseOrder($out_trade_no,$payamount,$paytype);
  57 + Db::commit();
  58 + } catch (\think\exception\PDOException $e) {
  59 + Db::rollback();
  60 + $this->error($e->getMessage());
  61 + return false;
  62 + } catch (\think\Exception $e) {
  63 + Db::rollback();
  64 + $this->error($e->getMessage());
  65 + return false;
  66 + }
  67 + return true;
  68 + }
  69 +
  70 + /**
  71 + * 课程-处理订单
  72 + */
  73 + private function handleCourseOrder($out_trade_no,$payamount,$paytype){
43 // 处理订单逻辑 74 // 处理订单逻辑
44 $order = CourseOrder::get(['order_sn'=>$out_trade_no,'pay_price'=>$payamount,'pay_type'=>$paytype]); 75 $order = CourseOrder::get(['order_sn'=>$out_trade_no,'pay_price'=>$payamount,'pay_type'=>$paytype]);
45 if($order && $order['pay_status'] != '1'){ 76 if($order && $order['pay_status'] != '1'){
@@ -47,13 +78,11 @@ class Notify extends Api @@ -47,13 +78,11 @@ class Notify extends Api
47 // 学习人数加1 78 // 学习人数加1
48 Db::name('mobile_course')->where('id',$order['course_id'])->setInc('study_num_real'); 79 Db::name('mobile_course')->where('id',$order['course_id'])->setInc('study_num_real');
49 } 80 }
50 - } catch (Exception $e) {  
51 - }  
52 - echo $pay->success(); 81 + return true;
53 } 82 }
54 83
55 /** 84 /**
56 - * 密卷 85 + * 密卷-----------------------------------------------------------------------
57 */ 86 */
58 public function notifySecret() 87 public function notifySecret()
59 { 88 {
@@ -68,6 +97,38 @@ class Notify extends Api @@ -68,6 +97,38 @@ class Notify extends Api
68 $payamount = $paytype == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100; 97 $payamount = $paytype == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100;
69 $out_trade_no = $data['out_trade_no']; 98 $out_trade_no = $data['out_trade_no'];
70 99
  100 + //处理订单
  101 + $this->handleSecretOrder($out_trade_no,$payamount,$paytype);
  102 + } catch (Exception $e) {
  103 + }
  104 + echo $pay->success();
  105 + }
  106 +
  107 + /**
  108 + * 密卷-零元支付
  109 + */
  110 + public function notifySecretZero($out_trade_no,$payamount,$paytype)
  111 + {
  112 + Db::startTrans();
  113 + try {
  114 + $this->handleSecretOrder($out_trade_no,$payamount,$paytype);
  115 + Db::commit();
  116 + } catch (\think\exception\PDOException $e) {
  117 + Db::rollback();
  118 + $this->error($e->getMessage());
  119 + return false;
  120 + } catch (\think\Exception $e) {
  121 + Db::rollback();
  122 + $this->error($e->getMessage());
  123 + return false;
  124 + }
  125 + return true;
  126 + }
  127 +
  128 + /**
  129 + * 密卷-处理订单
  130 + */
  131 + private function handleSecretOrder($out_trade_no,$payamount,$paytype){
71 // 处理订单逻辑 132 // 处理订单逻辑
72 $order = SecretOrder::get(['order_sn'=>$out_trade_no,'pay_price'=>$payamount,'pay_type'=>$paytype]); 133 $order = SecretOrder::get(['order_sn'=>$out_trade_no,'pay_price'=>$payamount,'pay_type'=>$paytype]);
73 if($order && $order['pay_status'] != '1'){ 134 if($order && $order['pay_status'] != '1'){
@@ -75,13 +136,11 @@ class Notify extends Api @@ -75,13 +136,11 @@ class Notify extends Api
75 // 购买量加1 136 // 购买量加1
76 Db::name('mobile_secret')->where('id',$order['course_id'])->setInc('buy_num_real'); 137 Db::name('mobile_secret')->where('id',$order['course_id'])->setInc('buy_num_real');
77 } 138 }
78 - } catch (Exception $e) {  
79 - }  
80 - echo $pay->success(); 139 + return true;
81 } 140 }
82 141
83 /** 142 /**
84 - * 积分 143 + * 积分----------------------------------------------------------------------
85 */ 144 */
86 public function notifyScore() 145 public function notifyScore()
87 { 146 {
@@ -96,6 +155,38 @@ class Notify extends Api @@ -96,6 +155,38 @@ class Notify extends Api
96 $payamount = $paytype == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100; 155 $payamount = $paytype == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100;
97 $out_trade_no = $data['out_trade_no']; 156 $out_trade_no = $data['out_trade_no'];
98 157
  158 + // 处理订单
  159 + $this->handleScoreOrder($out_trade_no,$payamount,$paytype);
  160 + } catch (Exception $e) {
  161 + }
  162 + echo $pay->success();
  163 + }
  164 +
  165 + /**
  166 + * 积分-零元支付
  167 + */
  168 + public function notifyScoreZero($out_trade_no,$payamount,$paytype)
  169 + {
  170 + Db::startTrans();
  171 + try {
  172 + $this->handleScoreOrder($out_trade_no,$payamount,$paytype);
  173 + Db::commit();
  174 + } catch (\think\exception\PDOException $e) {
  175 + Db::rollback();
  176 + $this->error($e->getMessage());
  177 + return false;
  178 + } catch (\think\Exception $e) {
  179 + Db::rollback();
  180 + $this->error($e->getMessage());
  181 + return false;
  182 + }
  183 + return true;
  184 + }
  185 +
  186 + /**
  187 + * 积分-处理订单
  188 + */
  189 + private function handleScoreOrder($out_trade_no,$payamount,$paytype){
99 // 处理订单逻辑 190 // 处理订单逻辑
100 $order = ScoreOrder::get(['order_sn'=>$out_trade_no,'pay_price'=>$payamount,'pay_type'=>$paytype]); 191 $order = ScoreOrder::get(['order_sn'=>$out_trade_no,'pay_price'=>$payamount,'pay_type'=>$paytype]);
101 if($order && $order['pay_status'] != '1'){ 192 if($order && $order['pay_status'] != '1'){
@@ -103,13 +194,11 @@ class Notify extends Api @@ -103,13 +194,11 @@ class Notify extends Api
103 // 增加积分 194 // 增加积分
104 \app\common\model\User::score($order['score'],$order['user_id'],'充值积分'); 195 \app\common\model\User::score($order['score'],$order['user_id'],'充值积分');
105 } 196 }
106 - } catch (Exception $e) {  
107 - }  
108 - echo $pay->success(); 197 + return true;
109 } 198 }
110 199
111 /** 200 /**
112 - * 企业套餐 201 + * 企业套餐---------------------------------------------------------------------
113 */ 202 */
114 public function notifyPackage() 203 public function notifyPackage()
115 { 204 {
@@ -125,6 +214,38 @@ class Notify extends Api @@ -125,6 +214,38 @@ class Notify extends Api
125 $out_trade_no = $data['out_trade_no']; 214 $out_trade_no = $data['out_trade_no'];
126 215
127 // 处理订单逻辑 216 // 处理订单逻辑
  217 + $this->handlePackageOrder($out_trade_no,$payamount,$paytype);
  218 + } catch (Exception $e) {
  219 + }
  220 + echo $pay->success();
  221 + }
  222 +
  223 + /**
  224 + * 企业套餐-零元支付
  225 + */
  226 + public function notifyPackageZero($out_trade_no,$payamount,$paytype)
  227 + {
  228 + Db::startTrans();
  229 + try {
  230 + $this->handlePackageOrder($out_trade_no,$payamount,$paytype);
  231 + Db::commit();
  232 + } catch (\think\exception\PDOException $e) {
  233 + Db::rollback();
  234 + $this->error($e->getMessage());
  235 + return false;
  236 + } catch (\think\Exception $e) {
  237 + Db::rollback();
  238 + $this->error($e->getMessage());
  239 + return false;
  240 + }
  241 + return true;
  242 + }
  243 +
  244 + /**
  245 + * 企业套餐-处理订单
  246 + */
  247 + private function handlePackageOrder($out_trade_no,$payamount,$paytype){
  248 + // 处理订单逻辑
128 $order = PackageOrder::get(['order_sn'=>$out_trade_no,'pay_price'=>$payamount,'pay_type'=>$paytype]); 249 $order = PackageOrder::get(['order_sn'=>$out_trade_no,'pay_price'=>$payamount,'pay_type'=>$paytype]);
129 if($order && $order['pay_status'] != '1'){ 250 if($order && $order['pay_status'] != '1'){
130 $order->save(['pay_status'=>'1','pay_time'=>time()]); 251 $order->save(['pay_status'=>'1','pay_time'=>time()]);
@@ -133,9 +254,7 @@ class Notify extends Api @@ -133,9 +254,7 @@ class Notify extends Api
133 Db::name('mobile_package')->where('id',$v['package_id'])->setInc('buy_num_real'); 254 Db::name('mobile_package')->where('id',$v['package_id'])->setInc('buy_num_real');
134 } 255 }
135 } 256 }
136 - } catch (Exception $e) {  
137 - }  
138 - echo $pay->success(); 257 + return true;
139 } 258 }
140 259
141 /** 260 /**
@@ -311,6 +311,11 @@ class Secret extends Api @@ -311,6 +311,11 @@ class Secret extends Api
311 // 创建订单 311 // 创建订单
312 $model = new SecretOrder; 312 $model = new SecretOrder;
313 $model->add($this->auth->getUser(), $order, $param['pay_type']); 313 $model->add($this->auth->getUser(), $order, $param['pay_type']);
  314 + // 零元直接支付成功
  315 + if($model['pay_price'] <= 0){
  316 + (new Notify)->notifySecretZero($model['order_sn'],$model['pay_price'],$param['pay_type']);
  317 + $this->success('成功',[]);
  318 + }
314 //回调链接 319 //回调链接
315 $notifyurl = $this->request->root(true) . '/mobile/notify/notifySecret/paytype/' . $param['pay_type']; 320 $notifyurl = $this->request->root(true) . '/mobile/notify/notifySecret/paytype/' . $param['pay_type'];
316 $model['pay_price'] = 0.01; //测试金额 321 $model['pay_price'] = 0.01; //测试金额
@@ -19,7 +19,7 @@ class Sms extends Api @@ -19,7 +19,7 @@ class Sms extends Api
19 * 发送验证码 19 * 发送验证码
20 * 20 *
21 * @param string $mobile 手机号 21 * @param string $mobile 手机号
22 - * @param string $event 事件名称:register=注册,resetpwd=忘记密码,changemobile1=修改手机号第一步,changemobile2=修改手机号第二步,changepwd=修改密码 22 + * @param string $event 事件名称:register=注册,resetpwd=忘记密码,changemobile1=修改手机号第一步,changemobile2=修改手机号第二步,changepwd=修改密码,bind=绑定第三方
23 */ 23 */
24 public function send() 24 public function send()
25 { 25 {
@@ -48,6 +48,12 @@ class Sms extends Api @@ -48,6 +48,12 @@ class Sms extends Api
48 } elseif (in_array($event, ['changepwd', 'resetpwd', 'changemobile1']) && !$userinfo) { 48 } elseif (in_array($event, ['changepwd', 'resetpwd', 'changemobile1']) && !$userinfo) {
49 //未注册 49 //未注册
50 $this->error(__('未注册')); 50 $this->error(__('未注册'));
  51 + } elseif ($event == 'bind' && $userinfo) {
  52 + $third = Db::name('user_third')->where('user_id',$userinfo['id'])->where('platform','wechat')->find();
  53 + if($third){
  54 + //被绑定
  55 + $this->error(__('该手机号已绑定微信'));
  56 + }
51 } 57 }
52 } 58 }
53 $ret = $this->getCode($mobile, null, $event); 59 $ret = $this->getCode($mobile, null, $event);
@@ -38,7 +38,7 @@ use Endroid\QrCode\QrCode; @@ -38,7 +38,7 @@ use Endroid\QrCode\QrCode;
38 */ 38 */
39 class User extends Api 39 class User extends Api
40 { 40 {
41 - protected $noNeedLogin = ['registerUser','agreementUser','registerCompany','agreementCompany','agreementPrivacy','login','resetpwd','exam','noLogin','problemList','problemInfo']; 41 + protected $noNeedLogin = ['registerUser','agreementUser','registerCompany','agreementCompany','agreementPrivacy','login','thirdLogin','thirdBindMobile','resetpwd','exam','noLogin','problemList','problemInfo'];
42 protected $noNeedRight = ['*']; 42 protected $noNeedRight = ['*'];
43 43
44 public function _initialize() 44 public function _initialize()
@@ -321,11 +321,12 @@ class User extends Api @@ -321,11 +321,12 @@ class User extends Api
321 'code':'1', 321 'code':'1',
322 'msg':'返回成功', 322 'msg':'返回成功',
323 "data": { 323 "data": {
  324 + "bind_mobile": 是否已绑定手机号码0=否1=是,
324 "token": 用户token 325 "token": 用户token
325 } 326 }
326 }) 327 })
327 */ 328 */
328 - public function userThird() { 329 + public function thirdLogin() {
329 $param = $this->request->param(); 330 $param = $this->request->param();
330 $validate = new Validate([ 331 $validate = new Validate([
331 'nickname' => 'require', 332 'nickname' => 'require',
@@ -339,19 +340,21 @@ class User extends Api @@ -339,19 +340,21 @@ class User extends Api
339 $this->error($validate->getError()); 340 $this->error($validate->getError());
340 } 341 }
341 // 判断用户是否已绑定该openid 342 // 判断用户是否已绑定该openid
  343 + $bind_mobile = 0;
342 $time = time(); 344 $time = time();
343 $ip = request()->ip(); 345 $ip = request()->ip();
344 $third = UserThird::where('openid',$param['openid'])->find(); 346 $third = UserThird::where('openid',$param['openid'])->find();
345 - Db::startTrans();  
346 if($third) { 347 if($third) {
  348 + $user = \app\common\model\User::get($third['user_id']);
  349 + if($user){
  350 + Db::startTrans();
347 // 修改第三方信息 351 // 修改第三方信息
348 - $result = UserThird::where('id',$third['id'])->update([ 352 + $result = $third->save([
349 'openname' => $param['nickname'], 353 'openname' => $param['nickname'],
350 'logintime'=>$time 354 'logintime'=>$time
351 ]); 355 ]);
352 // 修改用户信息 356 // 修改用户信息
353 - $user = \app\common\model\User::get($third['user_id']);  
354 - if(!empty($param['nickname']) && empty($user['nickname'])){ 357 + if(empty($user['nickname'])){
355 $user->nickname = $param['nickname']; 358 $user->nickname = $param['nickname'];
356 } 359 }
357 if(!empty($param['avatar']) && (empty($user['image']) || stripos($user['image'], 'http') !== false)){ 360 if(!empty($param['avatar']) && (empty($user['image']) || stripos($user['image'], 'http') !== false)){
@@ -366,22 +369,17 @@ class User extends Api @@ -366,22 +369,17 @@ class User extends Api
366 $results = $user->save(); 369 $results = $user->save();
367 // 登录 370 // 登录
368 $login = $this->auth->direct($third['user_id']); 371 $login = $this->auth->direct($third['user_id']);
  372 + if(!$result || !$results || !$login) {
  373 + Db::rollback();
  374 + $this->error('授权登录失败');
  375 + }
  376 + Db::commit();
  377 + $bind_mobile = 1;
  378 + $token = $this->auth->getToken();
  379 + }
369 } else { 380 } else {
370 - // 添加用户信息  
371 - $result = \app\common\model\User::create([  
372 - 'nickname' => $param['nickname'],  
373 - 'sex' => $param['gender'] == 2 ? 0 : $param['gender'],  
374 - 'image' => $param['avatar'],  
375 - 'status' => 'normal',  
376 - 'jointime' => $time,  
377 - 'joinip' => $ip,  
378 - 'logintime' => $time,  
379 - 'loginip' => $ip,  
380 - 'prevtime' => $time  
381 - ]);  
382 // 添加第三方信息 381 // 添加第三方信息
383 - $results = UserThird::create([  
384 - 'user_id' => $result['id'], 382 + $result = UserThird::create([
385 'openname' => $param['nickname'], 383 'openname' => $param['nickname'],
386 'platform' => 'wechat', 384 'platform' => 'wechat',
387 'openid' => $param['openid'], 385 'openid' => $param['openid'],
@@ -390,15 +388,169 @@ class User extends Api @@ -390,15 +388,169 @@ class User extends Api
390 'logintime' => $time, 388 'logintime' => $time,
391 'unionid' => $param['unionid'], 389 'unionid' => $param['unionid'],
392 ]); 390 ]);
393 - // 登录  
394 - $login = $this->auth->direct($result['id']);  
395 - }  
396 - if(!$result || !$results || !$login) { 391 + if(!$result) {
397 Db::rollback(); 392 Db::rollback();
398 $this->error('授权登录失败'); 393 $this->error('授权登录失败');
399 } 394 }
  395 + }
400 Db::commit(); 396 Db::commit();
401 - $this->success('成功',['token'=>$this->auth->getToken()]); 397 + $this->success('成功',['bind_mobile'=>$bind_mobile,'token'=>empty($token)?'':$token]);
  398 + }
  399 +
  400 + /**
  401 + * 绑定手机号
  402 + * @ApiWeigh (91)
  403 + *
  404 + * @ApiTitle (第三方登录-绑定手机号)
  405 + * @ApiSummary (第三方登录-绑定手机号)
  406 + * @ApiMethod (POST)
  407 + *
  408 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  409 + * @ApiParams (name="mobile", type="integer", required=true, description="手机号码")
  410 + * @ApiParams (name="code", type="integer", required=true, description="验证码")
  411 + * @ApiParams (name="openid", type="integer", required=true, description="第三方登录返回的唯一识别数据")
  412 + * @ApiParams (name="nickname", type="integer", required=true, description="第三方账号昵称")
  413 + * @ApiParams (name="avatar", type="integer", required=false, description="第三方账号头像")
  414 + * @ApiParams (name="gender", type="integer", required=false, description="第三方性别")
  415 + *
  416 + * @ApiReturn ({
  417 + 'code':'1',
  418 + 'msg':'返回成功',
  419 + "data": {
  420 + "token": 用户token,
  421 + "is_password": 是否设置密码(0,否;1,是)
  422 + }
  423 + })
  424 + */
  425 + public function thirdBindMobile() {
  426 + if($this->request->isPost()) {
  427 + $param = $this->request->param();
  428 + $validate = new Validate([
  429 + 'mobile' => 'require',
  430 + 'code' => 'require|number|length:4',
  431 + 'openid' => 'require',
  432 + ]);
  433 + $validate->message([
  434 + 'mobile.require' => '请输入您的手机号!',
  435 + 'code.require' => '请输入数字验证码!',
  436 + 'code.number' => '请输入正确的数字验证码!',
  437 + 'code.length' => '数字验证码长度错误!',
  438 + 'openid.require' => '缺少参数openid!',
  439 + ]);
  440 + if (!$validate->check($param)) {
  441 + $this->error($validate->getError());
  442 + }
  443 + if (!Sms::check($param['mobile'], $param['code'], 'bind')) {
  444 + $this->error(__('Captcha is incorrect'));
  445 + }
  446 + // 判断用户是否已绑定该openid
  447 + $third = UserThird::where('openid',$param['openid'])->find();
  448 + if($third) {
  449 + $user_model = new \app\common\model\User();
  450 + $user = $user_model->get($third['user_id']);
  451 + Db::startTrans();
  452 + if($user) {
  453 + $this->error('已绑定手机号');
  454 + }
  455 + // 判断是否存在该手机号
  456 + $user = $user_model->where('mobile',$param['mobile'])->find();
  457 + $ip = request()->ip();
  458 + $time = time();
  459 + if(!$user) {
  460 + $user_insert = [
  461 + 'username' => $param['mobile'],
  462 + 'nickname' => $param['nickname'],
  463 + 'image' => empty($param['avatar']) ? '/assets/img/avatar.png' : $param['avatar'],
  464 + 'sex' => isset($param['gender']) && $param['gender'] == 0 ? 2 : 1,
  465 + 'mobile' => $param['mobile'],
  466 + 'jointime' => $time,
  467 + 'joinip' => $ip,
  468 + 'logintime' => $time,
  469 + 'loginip' => $ip,
  470 + 'prevtime' => $time,
  471 + 'status' => 'normal',
  472 + ];
  473 + $results = $user_model->isUpdate(false)->save($user_insert);
  474 + $this->auth->direct($user_model['id']);
  475 + $is_password = 0;
  476 + } else {
  477 + // 判断手机号是否已经绑定第三方
  478 + $third_user_data = UserThird::where('user_id',$user['id'])
  479 + ->where('platform','wechat')
  480 + ->find();
  481 + if($third_user_data) {
  482 + Db::rollback();
  483 + $this->error('该手机号已绑定微信');
  484 + }
  485 + // 修改用户信息
  486 + if(empty($user['nickname'])){
  487 + $user->nickname = $param['nickname'];
  488 + }
  489 + if(!empty($param['avatar']) && (empty($user['image']) || stripos($user['image'], 'http') !== false)){
  490 + $user->image = $param['avatar'];
  491 + }
  492 + if(!empty($param['gender']) && !isset($user['sex'])){
  493 + $user->sex = $param['gender'] == 2 ? 0 : $param['gender'];
  494 + }
  495 + $user->loginip = $ip;
  496 + $user->logintime = $time;
  497 + $user->updatetime = $time;
  498 + $results = $user->save();
  499 + $this->auth->direct($user['id']);
  500 + $is_password = $user['password'] ? 1 : 0;
  501 + }
  502 + $result = $third->save([
  503 + 'logintime' => $time,
  504 + 'user_id' => $user['id'],
  505 + ]);
  506 + if(!$result || !$results) {
  507 + Db::rollback();
  508 + $this->error('第三方绑定失败');
  509 + }
  510 + Db::commit();
  511 + // 生成token
  512 + $token = $this->auth->getToken();
  513 + $this->success('绑定成功',['token'=>$token,'is_password'=>$is_password]);
  514 + }
  515 + }
  516 + }
  517 +
  518 + /**
  519 + * 第三方登录-设置密码
  520 + * @ApiWeigh (91)
  521 + *
  522 + * @param string $password 密码
  523 + * @param string $confirm_password 确认密码
  524 + * @param string $mobile 手机号
  525 + * @param string $code 验证码
  526 + */
  527 + public function thirdPassword()
  528 + {
  529 + $password = $this->request->request('password');
  530 + $confirm_password = $this->request->request('confirm_password');
  531 + $mobile = $this->request->request('mobile');
  532 + $code = $this->request->request('code');
  533 + if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
  534 + $this->error(__('Mobile is incorrect'));
  535 + }
  536 + if ($confirm_password != $password) {
  537 + $this->error(__('密码与确认密码不一致'));
  538 + }
  539 + $ret = Sms::check($mobile, $code, 'bind');
  540 + if (!$ret) {
  541 + $this->error(__('Captcha is incorrect'));
  542 + }
  543 + if ($this->auth->password) {
  544 + $this->error('已设置过密码');
  545 + }
  546 + $salt = Random::alnum();
  547 + $password = $this->auth->getEncryptPassword($password, $salt);
  548 + $user_model = new \app\common\model\User();
  549 + $result = $user_model->update(['id' => $this->auth->id, 'password' => $password, 'salt' => $salt]);
  550 + if (!$result) {
  551 + $this->error('密码设置失败');
  552 + }
  553 + $this->success('密码设置成功');
402 } 554 }
403 555
404 /** 556 /**
@@ -1240,6 +1392,11 @@ class User extends Api @@ -1240,6 +1392,11 @@ class User extends Api
1240 } 1392 }
1241 // 创建订单 1393 // 创建订单
1242 $model->add($this->auth->getUser(), $order, $param['pay_type']); 1394 $model->add($this->auth->getUser(), $order, $param['pay_type']);
  1395 + // 零元直接支付成功
  1396 + if($model['pay_price'] <= 0){
  1397 + (new Notify)->notifyScoreZero($model['order_sn'],$model['pay_price'],$param['pay_type']);
  1398 + $this->success('成功',[]);
  1399 + }
1243 //回调链接 1400 //回调链接
1244 $notifyurl = $this->request->root(true) . '/mobile/notify/notifyScore/paytype/' . $param['pay_type']; 1401 $notifyurl = $this->request->root(true) . '/mobile/notify/notifyScore/paytype/' . $param['pay_type'];
1245 $model['pay_price'] = 0.01; //测试金额 1402 $model['pay_price'] = 0.01; //测试金额
@@ -80,7 +80,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin @@ -80,7 +80,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
80 {field: 'expirationtime', title: __('有效期'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime}, 80 {field: 'expirationtime', title: __('有效期'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
81 {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {normal: __('Normal'), hidden: __('Hidden')}}, 81 {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {normal: __('Normal'), hidden: __('Hidden')}},
82 {field: 'mobile', title: __('注册手机号')}, 82 {field: 'mobile', title: __('注册手机号')},
83 - {field: 'group_id', title: __('角色'), searchList: {"0":"普通用户","1":"公司用户"},formatter: Table.api.formatter.flag}, 83 + {field: 'group_id', title: __('角色'), searchList: {"0":"普通用户","1":"企业管理员"},formatter: Table.api.formatter.flag},
84 {field: 'createtime', title: __('注册时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true}, 84 {field: 'createtime', title: __('注册时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
85 {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} 85 {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
86 ] 86 ]
此 diff 太大无法显示。