steelxu 3 jaren geleden
bovenliggende
commit
6741cf3323

+ 92 - 0
application/common/model/memodel.php

@@ -0,0 +1,92 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: sicilon_IT
+ * Date: 2019/12/7
+ * Time: 11:11
+ */
+
+namespace  app\common\model;
+use think\Model;
+
+
+class memodel extends Model{
+  // private $me_tabel;
+    protected $table = 't_wxuser';
+
+//   public function initialize(){
+//       //echo "in";
+//       $this->me_tabel=model("tEquipmentMe");
+//       echo 'init';
+//   }
+
+    public function saveme($userinfo){
+        $r_id=$this->allowField(true)->save($userinfo);
+        return $r_id;
+    }
+
+    public function getinfobyopenid($openid){
+        $record=$this->where("open_id",$openid)->find();
+        return $record;
+    }
+
+    public function updatetelbyoopenid($openid,$tel){
+        $r_id=$this->where("open_id",$openid)->update(['tel'=>$tel]);
+        return $r_id;
+    }
+
+    public function insopenid($insinfo){
+
+        $r_id=$this->isUpdate(false)->save($insinfo);
+
+        return $this->id;
+    }
+    /*
+     * 20200226
+     * steelxu5
+     * 增加了根据openid更新信息的
+     */
+
+    public function updateinfobyopenid($openid,$arr){
+        $r_id=$this->where("open_id",$openid)->update($arr);
+        return $r_id;
+    }
+
+    /*
+     * 20200401
+     * 根据ID获取呢称
+     */
+
+    public function selnamebyid($id){
+        $where_arr['id']=$id;
+        $cinfo=$this->where($where_arr)->find();
+        return $cinfo;
+    }
+
+    /*
+     * 20200927
+     * 根据UNIONID获取信息,openid,uid
+     */
+    public function selinfobyunionid($unionid){
+        $where_arr['union_id']=$unionid;
+        $cinfo=$this->where($where_arr)->field('id,open_id')->find();
+        return $cinfo;
+    }
+    /*
+     * 20200927
+     * 根据openid 更新unionid
+     */
+    public function updunionidbyopenid($openid,$unionid){
+        $this->where("open_id",$openid)->update(['union_id'=>$unionid]);
+    }
+
+    /*
+     * 20200928
+     * 根据unionid 获取openid
+     */
+    public function selopenidbyunionid($unionid){
+        $rec=$this->where("union_id",$unionid)->field('id,open_id')->find();
+        return $rec['open_id'];
+    }
+
+} 

+ 31 - 0
application/index/controller/Fileoper.php

@@ -76,4 +76,35 @@ class Fileoper extends Controller
             $this->error($file->getError());
         }
     }
+
+    public function upQuestionsWrite()
+    {
+        log::info($_FILES);
+        $this->filterfiletype();
+        // 获取表单上传文件
+        $file = request()->file('file');
+        $domainpath = 'https://' . $_SERVER['HTTP_HOST'] . '/Uploads/';
+
+        if (empty($file)) {
+            $this->error('请选择上传文件');
+        }
+        // 移动到框架应用根目录/public/uploads/ 目录下
+        $info = $file->move(ROOT_PATH . 'public' . DS . 'Uploads');
+
+        //如果不清楚文件上传的具体键名,可以直接打印$info来查看
+        //获取文件(文件名),$info->getFilename()  ***********不同之处,笔记笔记哦
+        //获取文件(日期/文件名),$info->getSaveName()  **********不同之处,笔记笔记哦
+        $filename = $info->getSaveName(); //在测试的时候也可以直接打印文件名称来查看
+        if ($filename) {
+            //$this->success('文件上传成功!');
+            $imageUrl = $domainpath . $filename;
+            $r_upload['code'] = '200';
+            $r_upload['resultData'] = $imageUrl;
+            //不转义反斜杠
+            return json_encode($r_upload, 320);
+        } else {
+            // 上传失败获取错误信息
+            $this->error($file->getError());
+        }
+    }
 }

+ 263 - 0
application/index/controller/Me.php

@@ -0,0 +1,263 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: sicilon_IT
+ * Date: 2019/12/7
+ * Time: 16:12
+ */
+
+namespace app\index\controller;
+use app\common\model\memodel;
+use think\Controller;
+
+//extends controller 为什么不能继承
+class Me  extends Controller{
+   public function add(){
+      //获取参数
+//       $userinfo['address']=('post.address');
+//       $userinfo['avatar_url']=I('post.avatarUrl');
+//       $userinfo['city']=I('post.city');
+//       $userinfo['company']=I('post.company');
+//       $userinfo['county']=I('post.county');
+//       $userinfo['gender']=I('post.gender');
+//       $userinfo['id']=I('post.id');
+//       $userinfo['nick_name']=I('post.nickName');
+//       $userinfo['open_id']=I('post.openid');
+//       $userinfo['province']=I('post.province');
+//       $userinfo['tel']=I('post.tel');
+//       $userinfo['union_id']=I('post.unionId');
+       //验证部分
+      $userinfo = request() -> param();
+       $userinfo['open_id']=$userinfo['openId'];
+       $userinfo['avatar_url']=$userinfo['avatarUrl'];
+       $userinfo['nick_name']=$userinfo['nickName'];
+       $userinfo['create_date']=date('Y-m-d H:i:s',time());
+      // $userinfo['nick_name']=$userinfo['nickName'];
+       //var_dump($userinfo);
+        //openid为空,返回403
+       //修改一下,文档中说自动处理了大写转成下划线加小写字母
+       if (!$userinfo['openId']){
+           //return
+           $add_res['code']='403';
+           return json($add_res);
+       }
+       $metabel=new memodel();
+       //先根据open_id判断是否存在,这个以后应当放到logic中
+       $u_info=$metabel->getinfobyopenid($userinfo['open_id']);
+
+       if (!$u_info){
+           //如果为空就新增
+           $id=$metabel->saveme($userinfo);
+           $Resultdata['id']=$id;
+           //存储之后再查询
+           $new_info=$metabel->getinfobyopenid($userinfo['open_id']);
+           $add_res['code']='200';
+           $add_res['resultData']=$new_info;
+           return json($add_res);
+       }else{
+           //如果有,就另一个处理逻辑,判断是否有电话,没有电话就返回
+           //返回数据,前端判断
+            if (!$u_info['tel']){
+                //看传参中是否有手机,如果有,加上,再返回数据,如果没有,直接返回
+                if (array_key_exists('tel',$userinfo)){
+                    //传参中有,则更新操作
+                    //tel是另外一个接口,此处后来应该修改
+                }else{
+                    //传参中也没有手机,直接返回
+                    $add_res['code']='200';
+                    $add_res['resultData']=$u_info;
+                    return json($add_res);
+                }
+            }else{
+                $add_res['code']='200';
+                $add_res['resultData']=$u_info;
+                return json($add_res);
+            }
+
+
+
+       }
+
+
+   }
+    //更新手机号用
+    public function updatemetel(){
+        $userinfo = request() -> param();
+       // var_dump($userinfo);
+        if ($userinfo['tel']){
+            //有手机号,继续
+            $metabel=new memodel();
+            $openid='';
+            if(array_key_exists('open_id',$userinfo)){
+                $openid=$userinfo['open_id'];
+            }else{
+                $openid=$userinfo['openid'];
+            }
+            $metabel->updatetelbyoopenid($openid,$userinfo['tel']);
+            $u_info=$metabel->getinfobyopenid($openid);
+            $u_info['openid']=$u_info['open_id'];
+            $u_info['openId']=$u_info['open_id'];
+            $update_res['code']='200';
+            $update_res['resultData']=$u_info;;
+        }else{
+            //无手机号,返回错误
+            $update_res['code']='400';
+        }
+        return json($update_res);
+    }
+
+    /*
+     * 20200221
+     * steelxu
+     * 只存入openid的
+     */
+
+    public function samplelogin(){
+        //
+        $userinfo = request() -> param();
+        $openid=$userinfo['openId'];
+        $mtable=new memodel();
+        $rinfo=$mtable->getinfobyopenid($openid);
+        if (!$rinfo){
+            $insinfo['open_id']=$openid;
+            //2010303
+            $insinfo['create_date']=date('Y-m-d H:i:s');
+            $insinfo['create_pin']=rand(0,1);
+            //
+            $rid=$mtable->insopenid($insinfo);
+            if (array_key_exists('unionid',$userinfo)){
+                $unionid=$userinfo['unionid'];
+                $mtable->updunionidbyopenid($openid,$unionid);
+            }
+            $Resultdata['id']=$rid;
+            $Resultdata['openId']=$openid;
+            $Resultdata['openid']=$openid;
+            $Resultdata['create_pin']=$insinfo['create_pin'];
+        }else{
+            $Resultdata=$rinfo;
+            $Resultdata['openId']=$rinfo['open_id'];
+            $Resultdata['openid']=$rinfo['open_id'];
+            $Resultdata['create_pin']=$rinfo['create_pin'];
+
+        }
+        $res_r['code']=200;
+        $res_r['resultData']=$Resultdata;
+        return json($res_r);
+    }
+
+    public function updateme(){
+
+        //验证部分
+        $userinfo = request() -> param();
+        if (array_key_exists('unionid',$userinfo)){
+            $userinfo['union_id']=$userinfo['unionId'];
+        }
+        $userinfo['open_id']=$userinfo['openId'];
+        $userinfo['avatar_url']=$userinfo['avatarUrl'];
+        $userinfo['nick_name']=$userinfo['nickName'];
+        $userinfo['create_date']=date('Y-m-d H:i:s',time());
+        // $userinfo['nick_name']=$userinfo['nickName'];
+        //var_dump($userinfo);
+        //openid为空,返回403
+        //修改一下,文档中说自动处理了大写转成下划线加小写字母
+        if (!$userinfo['openId']){
+            //return
+            $add_res['code']='403';
+            return json($add_res);
+        }
+        $metabel=new memodel();
+        //先根据open_id判断是否存在,这个以后应当放到logic中
+        $u_info=$metabel->getinfobyopenid($userinfo['open_id']);
+
+        if (!$u_info){
+            //如果为空就新增
+            $id=$metabel->saveme($userinfo);
+            $Resultdata['id']=$id;
+            //存储之后再查询
+            $new_info=$metabel->getinfobyopenid($userinfo['open_id']);
+            $new_info['openid']=$new_info['open_id'];
+            $new_info['openId']=$new_info['open_id'];
+            $add_res['code']='200';
+            $add_res['resultData']=$new_info;
+
+            return json($add_res);
+        }else{
+            //如果已经有open_id,则判断是否授权了union_id,进行二级登录
+            if (!$u_info['nick_name']){
+                //数据表中无姓名,则未授权姓名,传参中有姓名,则更新后返回
+                if (array_key_exists('unionId',$userinfo)){
+                    $update_arr['union_id']=$userinfo['unionId'];
+                    $update_arr['avatar_url']=$userinfo['avatarUrl'];
+                    $update_arr['nick_name']=$userinfo['nickName'];
+                    $update_arr['gender']=$userinfo['gender'];
+                    $update_arr['province']=$userinfo['province'];
+                    $update_arr['city']=$userinfo['city'];
+                    $update_arr['country']=$userinfo['country'];
+
+                    $update_arr['create_date']=date('Y-m-d H:i:s',time());
+                    $metabel->updateinfobyopenid($userinfo['open_id'],$update_arr);
+                    //重新获取,返回
+                    $u_info=$metabel->getinfobyopenid($userinfo['open_id']);
+                    $u_info['openid']=$u_info['open_id'];
+                    $u_info['openId']=$u_info['open_id'];
+                    $add_res['code']='200';
+                    $add_res['resultData']=$u_info;
+                    return json($add_res);
+
+                }else{
+                    //无姓名,则更新直接返回,不影响使用,但下个功能不能使用
+                    $update_arr['avatar_url']=$userinfo['avatarUrl'];
+                    $update_arr['nick_name']=$userinfo['nickName'];
+                    $update_arr['gender']=$userinfo['gender'];
+                    $update_arr['province']=$userinfo['province'];
+                    $update_arr['city']=$userinfo['city'];
+                    $update_arr['country']=$userinfo['country'];
+
+                    $update_arr['create_date']=date('Y-m-d H:i:s',time());
+                    $metabel->updateinfobyopenid($userinfo['open_id'],$update_arr);
+                    //重新获取,返回
+                    $u_info=$metabel->getinfobyopenid($userinfo['open_id']);
+                    $u_info['openid']=$u_info['open_id'];
+                    $u_info['openId']=$u_info['open_id'];
+                    $add_res['code']='200';
+                    $add_res['resultData']=$u_info;
+                    return json($add_res);
+                }
+
+            }else{
+                //数据表中有姓名,则判断有无电话,进行三级登录
+                //如果有,就另一个处理逻辑,判断是否有电话,没有电话就返回
+                //返回数据,前端判断
+
+                if (!$u_info['tel']){
+                    //看传参中是否有手机,如果有,加上,再返回数据,如果没有,直接返回,目前不强制登录手机,
+                    if (array_key_exists('tel',$userinfo)){
+                        //传参中有,则更新操作
+                        //tel是另外一个接口,此处后来应该修改
+                    }else{
+                        //传参中也没有手机,直接返回
+                        $u_info['openid']=$u_info['open_id'];
+                        $u_info['openId']=$u_info['open_id'];
+                        $add_res['code']='200';
+                        $add_res['resultData']=$u_info;
+                        return json($add_res);
+                    }
+                }else{
+                    //数据表中有手机,说明手机号已授权,直接返回
+                    $u_info['openid']=$u_info['open_id'];
+                    $u_info['openId']=$u_info['open_id'];
+                    $add_res['code']='200';
+                    $add_res['resultData']=$u_info;
+                    return json($add_res);
+                }
+            }
+
+
+
+
+        }
+
+
+    }
+
+} 

+ 1 - 1
application/index/logic/paylogic.php

@@ -46,7 +46,7 @@ class paylogic extends baselogic
         $data = $result['data'];
         $openid = $data['openid'];
         $aid = $data['aid'];
-        $totalfee = bcmul($data['total_fee'], 100, 0);
+        $totalfee = bcmul($data['total_fee'], 1, 0);
 
         $m_a = new appointmentmodel();
         $where = [

+ 7 - 7
application/index/logic/wechatlogic.php

@@ -52,10 +52,10 @@ class wechatlogic extends baselogic
     public function getselfwxconfig()
     {
         $config = [
-            //'appid' => 'wx47d6be96fb2d466c',
-            //'appSecret' => 'c0252b0cea090a1f3fb41ea7c71d55d6',
-            'appid' => 'wxcacf6eb6e7478e29',
-            'appSecret' => '3722c3f95df0569498a0e32ae6e85153',
+            'appid' => 'wx47d6be96fb2d466c',
+            'appSecret' => 'c0252b0cea090a1f3fb41ea7c71d55d6',
+           // 'appid' => 'wxcacf6eb6e7478e29',
+          //  'appSecret' => '3722c3f95df0569498a0e32ae6e85153',
         ];
         return $config;
     }
@@ -69,8 +69,8 @@ class wechatlogic extends baselogic
     public function getpayconfig()
     {
         $config = [
-            'mchid' => '1616316171', //零散务工工会
-            'key' => 'WaterCat20211001ShuiMaoGongJiang', //商户号key
+            'mchid' => '1629313620', //宁泰医院
+            'key' => 'Ntyy123456Ntyy123456Ntyy12345678', //商户号key
         ];
         return $config;
     }
@@ -151,7 +151,7 @@ class wechatlogic extends baselogic
         }
         $logfail = array_key_exists('errcode', $wxResult);
         if ($logfail) {
-            return backarr(0, 'error', $logfail['errmsg']);
+            return backarr(0, 'error', $wxResult['errmsg']);
         }
         $openid = $wxResult['openid'];
         $data = ['openid' => $openid];