Sfoglia il codice sorgente

Merge branch 'master' of http://git.huxiukeji.com/lizhen/xiaoshan

Panda 4 mesi fa
parent
commit
0c20cc3ba6

+ 2 - 2
addons/shopro/controller/Pay.php

@@ -130,7 +130,7 @@ class Pay extends Common
         // 微信公众号,小程序支付,必须有 openid
         if ($payment == 'wechat') {
             if (in_array($platform, ['WechatOfficialAccount', 'WechatMiniProgram'])) {
-                $openid = $user->wechat_openid;
+                $openid = $user->mini_openid;
                 if (isset($openid) && $openid) {
                     // 如果传的有 openid
                     $order_data['payer']['openid'] = $openid;
@@ -173,7 +173,7 @@ class Pay extends Common
         ];
         if ($payment == 'wechat') {
             if (in_array($platform, ['WechatOfficialAccount', 'WechatMiniProgram'])) {
-                $params['openid'] = $user->wechat_openid;
+                $params['openid'] = $user->mini_openid;
             }
         }
 

+ 2 - 1
application/admin/lang/zh-cn/user/user.php

@@ -38,5 +38,6 @@ return [
     'Idcard_status 1'  => '审核通过',
     'Idcard_status 2'  => '审核驳回',
     'Idcard_status 3'  => '被取消',
-    'Wechat_openid'    => '微信openid'
+    'Mini_openid'      => '小程序微信openid',
+    'App_openid'       => 'APP微信openid'
 ];

+ 4 - 0
application/admin/model/shopro/order/Order.php

@@ -174,6 +174,10 @@ class Order extends Common
         if (isset($ext['refund_time']) && $ext['refund_time']) {
             $ext['refund_date'] = date('Y-m-d H:i:s', $ext['refund_time']);
         }
+
+        //订单支付到期倒计时秒数
+        $ext['expired_second']   = isset($ext['expired_time']) ? $ext['expired_time'] - time() : 0;
+
         return $ext;
     }
 

+ 1 - 6
application/admin/view/user/user/add.html

@@ -152,12 +152,7 @@
 
         </div>
     </div>
-    <div class="form-group">
-        <label class="control-label col-xs-12 col-sm-2">{:__('Wechat_openid')}:</label>
-        <div class="col-xs-12 col-sm-8">
-            <input id="c-wechat_openid" class="form-control" name="row[wechat_openid]" type="text">
-        </div>
-    </div>
+
     <div class="form-group layer-footer">
         <label class="control-label col-xs-12 col-sm-2"></label>
         <div class="col-xs-12 col-sm-8">

+ 1 - 6
application/admin/view/user/user/edit.html

@@ -152,12 +152,7 @@
 
         </div>
     </div>
-    <div class="form-group">
-        <label class="control-label col-xs-12 col-sm-2">{:__('Wechat_openid')}:</label>
-        <div class="col-xs-12 col-sm-8">
-            <input id="c-wechat_openid" class="form-control" name="row[wechat_openid]" type="text" value="{$row.wechat_openid|htmlentities}">
-        </div>
-    </div>
+
     <div class="form-group layer-footer">
         <label class="control-label col-xs-12 col-sm-2"></label>
         <div class="col-xs-12 col-sm-8">

+ 29 - 13
application/api/controller/User.php

@@ -13,7 +13,7 @@ use app\common\library\Wechat;
  */
 class User extends Api
 {
-    protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'third'];
+    protected $noNeedLogin = ['login','mobilelogin','register','wechatlogin','bindmobile','resetpwd'];
     protected $noNeedRight = '*';
 
     public function _initialize()
@@ -131,6 +131,8 @@ class User extends Api
         if(!$code){
             $this->error(__('Invalid parameters'));
         }
+        $from = input('from','app');
+        $field = $from == 'app' ? 'app_openid' : 'mini_openid';
         //微信
         $wechat = new Wechat();
         $wxuserinfo = $wechat->getAccessToken($code);
@@ -138,14 +140,15 @@ class User extends Api
         if(!$wxuserinfo){
             $this->error('openid获取失败');
         }
-        if(!is_array($wxuserinfo) || !isset($wxuserinfo['openid'])){
+        if(!is_array($wxuserinfo) || !isset($wxuserinfo['openid']) || !isset($wxuserinfo['unionid'])){
             $this->error('openid获取失败');
         }
 
         $openid = $wxuserinfo['openid'];
+        $unionid = $wxuserinfo['unionid'];
 
         //检查用户
-        $user = Db::name('user')->where('wechat_openid',$openid)->find();
+        $user = Db::name('user')->where('unionid',$unionid)->find();
         if ($user) {
             if ($user['status'] == -1) {
                 $this->error('账户已注销');
@@ -153,6 +156,12 @@ class User extends Api
             if ($user['status'] != 1) {
                 $this->error(__('Account is locked'));
             }
+
+            /*$update = [
+                $field     => $openid,//应该就只有mini支付时用
+            ];
+            Db::name('user')->where('id',$user['id'])->update($update);*/
+
             //如果已经有账号则直接登录
             $ret = $this->auth->direct($user['id']);
 
@@ -168,15 +177,17 @@ class User extends Api
         } else {
             //记录code和openid,绑定手机号的时候更新openid
             $wechatCodeData = [
-                'code' => $code,
-                'openid' => $openid,
+                'code'       => $code,
+                'openid'     => $openid,
+                'unionid'    => $unionid,
+                'from'       => $from,
                 'createtime' => time(),
             ];
-            $wechatCode = Db::name('wechat_code')->where(['openid'=>$openid])->find();
+            $wechatCode = Db::name('wechat_code')->where(['unionid'=>$unionid,'from'=>$from])->find();
             if (empty($wechatCode)) {
                 Db::name('wechat_code')->insertGetId($wechatCodeData);
             } else {
-                Db::name('wechat_code')->where(['openid'=>$openid])->update($wechatCodeData);
+                Db::name('wechat_code')->where(['unionid'=>$unionid,'from'=>$from])->update($wechatCodeData);
             }
 
             //直接返回
@@ -201,6 +212,9 @@ class User extends Api
         $captcha = input('captcha');
         $code = input('code');
 
+        $from = input('from','app');
+        $field = $from == 'app' ? 'app_openid' : 'mini_openid';
+
         if (!$mobile || !$captcha || !$code) {
             $this->error(__('Invalid parameters'));
         }
@@ -221,7 +235,7 @@ class User extends Api
         }
 
         //检查appid绑定的用户
-        $user = Db::name('user')->where('wechat_openid',$wechatCode['openid'])->find();
+        $user = Db::name('user')->where('unionid',$wechatCode['unionid'])->find();
         if ($user) {
             if ($user['status'] == -1) {
                 $this->error('账户已注销');
@@ -239,17 +253,18 @@ class User extends Api
         $where['mobile'] = $mobile;
         $userData = Db::name('user')->where($where)->find();//老用户
         if (!empty($userData)) {
-            if (empty($userData['wechat_openid'])) {
-                Db::name('user')->where('id',$userData['id'])->update(['wechat_openid' => $wechatCode['openid']]);//老用户更新openid
+            if (empty($userData['unionid'])) {
+                Db::name('user')->where('id',$userData['id'])->update([$field => $wechatCode['openid'],'unionid' => $wechatCode['unionid']]);//老用户更新openid
             } else {
-                if ($userData['wechat_openid'] != $wechatCode['openid']) {
+                if ($userData['unionid'] != $wechatCode['unionid']) {
                     $this->error('该手机号已被其他用户绑定');
                 }
             }
             $ret = $this->auth->direct($userData['id']);
         } else {
             $extend = [
-                'wechat_openid' => $wechatCode['openid'],
+                $field    => $wechatCode['openid'],
+                'unionid' => $wechatCode['unionid'],
             ];
             $ret = $this->auth->register('', '','', $mobile, $extend);
         }
@@ -286,7 +301,8 @@ class User extends Api
         $data = [
             'status' => -1,
             'mobile' => 'close_'.$this->auth->mobile,
-            'wechat_openid' => 'close_'.$this->auth->wechat_openid,
+            'app_openid' => 'close_'.$this->auth->app_openid,
+            'mini_openid' => 'close_'.$this->auth->mini_openid,
 //            'ios_user_id' => 'close_'.$this->auth->ios_user_id,
         ];
         Db::name('user')->where('id',$this->auth->id)->update($data);

+ 0 - 1
public/assets/js/backend/user/user.js

@@ -51,7 +51,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {field: 'token', title: __('Token'), operate: 'LIKE'},
                         {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"0":__('Status 0'),"-1":__('Status -1')}, formatter: Table.api.formatter.status},
                         {field: 'idcard_status', title: __('Idcard_status'), searchList: {"-1":__('Idcard_status -1'),"0":__('Idcard_status 0'),"1":__('Idcard_status 1'),"2":__('Idcard_status 2'),"3":__('Idcard_status 3')}, formatter: Table.api.formatter.status},
-                        {field: 'wechat_openid', title: __('Wechat_openid'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                         {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                     ]
                 ]