Bläddra i källkod

Merge branch 'master' of http://git.liuniu946.com/zxhxx/red

Kirin 2 år sedan
förälder
incheckning
6defcc8a6a

+ 50 - 2
application/admin/controller/Category.php

@@ -5,6 +5,10 @@ namespace app\admin\controller;
 use app\common\controller\Backend;
 use app\common\model\Category as CategoryModel;
 use fast\Tree;
+use think\Db;
+use think\Exception;
+use think\exception\PDOException;
+use think\exception\ValidateException;
 
 /**
  * 分类管理
@@ -28,7 +32,7 @@ class Category extends Backend
         $this->model = model('app\common\model\Category');
 
         $tree = Tree::instance();
-        $tree->init(collection($this->model->order('weigh desc,id desc')->select())->toArray(), 'pid');
+        $tree->init(collection($this->model->where('cid', 'in', [0, $this->auth->getUserInfo()['cid']])->order('weigh desc,id desc')->select())->toArray(), 'pid');
         $this->categorylist = $tree->getTreeList($tree->getTreeArray(0), 'name');
         $categorydata = [0 => ['type' => 'all', 'name' => __('None')]];
         foreach ($this->categorylist as $k => $v) {
@@ -100,7 +104,45 @@ class Category extends Backend
         if ($this->request->isPost()) {
             $this->token();
         }
-        return parent::add();
+        if ($this->request->isPost()) {
+            $params = $this->request->post("row/a");
+            if ($params) {
+                $params = $this->preExcludeFields($params);
+
+                if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
+                    $params[$this->dataLimitField] = $this->auth->id;
+                }
+                $result = false;
+                Db::startTrans();
+                try {
+                    //是否采用模型验证
+                    if ($this->modelValidate) {
+                        $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
+                        $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
+                        $this->model->validateFailException(true)->validate($validate);
+                    }
+                    $params['cid'] = $this->auth->getUserInfo()['cid'];
+                    $result = $this->model->allowField(true)->save($params);
+                    Db::commit();
+                } catch (ValidateException $e) {
+                    Db::rollback();
+                    $this->error($e->getMessage());
+                } catch (PDOException $e) {
+                    Db::rollback();
+                    $this->error($e->getMessage());
+                } catch (Exception $e) {
+                    Db::rollback();
+                    $this->error($e->getMessage());
+                }
+                if ($result !== false) {
+                    $this->success();
+                } else {
+                    $this->error(__('No rows were inserted'));
+                }
+            }
+            $this->error(__('Parameter %s can not be empty', ''));
+        }
+        return $this->view->fetch();
     }
 
     /**
@@ -112,6 +154,12 @@ class Category extends Backend
         if (!$row) {
             $this->error(__('No Results were found'));
         }
+        if ($row['cid'] == 0 && $this->auth->getUserInfo()['cid'] != 0) {
+            $this->error(__('You have no permission'));
+        }
+        if ($row['cid'] != $this->auth->getUserInfo()['cid']) {
+            $this->error(__('You have no permission'));
+        }
         $adminIds = $this->getDataLimitAdminIds();
         if (is_array($adminIds)) {
             if (!in_array($row[$this->dataLimitField], $adminIds)) {

+ 42 - 37
application/api/controller/Donate.php

@@ -1,7 +1,9 @@
 <?php
+
 namespace app\api\controller;
+
 use app\common\controller\Api;
-use app\common\model\{Category,Donate as DonateModel};
+use app\common\model\{Category, Donate as DonateModel};
 use liuniu\IdentityCard;
 use liuniu\UtilService;
 use think\Request;
@@ -9,62 +11,65 @@ use think\Request;
 class Donate extends Api
 {
     protected $noNeedRight = ['*'];
+
     public function apply(Request $request)
     {
         $where = UtilService::postMore(
             [
-                ['cid',$this->cid],
-                ['user_id',$this->auth->getUserinfo()['id']],
-                ['full_name',''],
-                ['sex',0],
-                ['birthday',date("Y-m-d")],
-                ['id_card',''],
-                ['vocation',''],
-                ['education',0],
-                ['category_ids',0],
-                ['tel',''],
-                ['mobile',''],
-                ['executor',''],
-                ['executor_relation',''],
-                ['executor_id_card',''],
-                ['executor_tel',''],
-                ['executor_mobile',''],
-            ],$request
+                ['cid', $this->cid],
+                ['user_id', $this->auth->getUserinfo()['id']],
+                ['full_name', ''],
+                ['sex', 0],
+                ['birthday', date("Y-m-d")],
+                ['id_card', ''],
+                ['vocation', ''],
+                ['education', 0],
+                ['category_ids', 0],
+                ['tel', ''],
+                ['mobile', ''],
+                ['executor', ''],
+                ['executor_relation', ''],
+                ['executor_id_card', ''],
+                ['executor_tel', ''],
+                ['executor_mobile', ''],
+            ], $request
         );
-        if($where['full_name']=='')$this->error('姓名不能为空');
-        if(!IdentityCard::isValid($where['id_card']))$this->error('身份证号不正确!');
-        if($where['vocation']=='')$this->error('职业不能为空');
-        if($where['category_ids']=='')$this->error('捐献类型不能空');
-        if($where['executor_relation']=='')$this->error('执行人关系');
-        if(!preg_match("/^1\d{10}$/", $where['mobile'])) $this->error('手机号不对');
-        if(!preg_match("/^1\d{10}$/", $where['executor_mobile'])) $this->error('执行人移动电话不对');
-        if(!IdentityCard::isValid($where['executor_id_card']))$this->error('执行人身份证号不正确!');
+        if ($where['full_name'] == '') $this->error('姓名不能为空');
+        if (!IdentityCard::isValid($where['id_card'])) $this->error('身份证号不正确!');
+        if ($where['vocation'] == '') $this->error('职业不能为空');
+        if ($where['category_ids'] == '') $this->error('捐献类型不能空');
+        if ($where['executor_relation'] == '') $this->error('执行人关系');
+        if (!preg_match("/^1\d{10}$/", $where['mobile'])) $this->error('手机号不对');
+        if (!preg_match("/^1\d{10}$/", $where['executor_mobile'])) $this->error('执行人移动电话不对');
+        if (!IdentityCard::isValid($where['executor_id_card'])) $this->error('执行人身份证号不正确!');
         $this->success(DonateModel::create($where));
     }
 
     public function ify(Request $request)
     {
-        $this->success('获取成功',Category::getCategoryArray('donate'));
+        $this->success('获取成功', Category::getCategoryArray('donate'));
     }
+
     public function lst(Request $request)
     {
         $where = UtilService::getMore(
             [
-                ['cid',$this->cid],
-                ['user_id',$this->auth->getUserinfo()['id']],
-                ['page',1],
-                ['limit',10],
-                ['status',-2],
+                ['cid', $this->cid],
+                ['user_id', $this->auth->getUserinfo()['id']],
+                ['page', 1],
+                ['limit', 10],
+                ['status', -2],
             ]
         );
-        return $this->success('获取成功',DonateModel::lst($where));
+        return $this->success('获取成功', DonateModel::lst($where));
     }
+
     public function view()
     {
-        $id = input('id',0);
-        if($id==0) $this->error('参数错误!');
+        $id = input('id', 0);
+        if ($id == 0) $this->error('参数错误!');
         $rs = DonateModel::info($id);
-        if(!$rs)$this->error(HelpModel::getErrorInfo());
-        return $this->success('获取成功',$rs);
+        if (!$rs) $this->error(HelpModel::getErrorInfo());
+        return $this->success('获取成功', $rs);
     }
 }

+ 29 - 24
application/api/controller/Index.php

@@ -29,10 +29,10 @@ class Index extends Api
     public function index()
     {
         $banner = Ads::getbanner($this->cid);
-        $bottom_menu = Menu::lst($this->cid,29);
-        $menu = Menu::lst($this->cid,30);
-        $all_ash = Config::where('name','all_ash')->value('value');
-        $this->success('获取成功',compact('banner','bottom_menu','menu','all_ash'));
+        $bottom_menu = Menu::lst($this->cid, 29);
+        $menu = Menu::lst($this->cid, 30);
+        $all_ash = Config::where('name', 'all_ash')->value('value');
+        $this->success('获取成功', compact('banner', 'bottom_menu', 'menu', 'all_ash'));
     }
 
     /**
@@ -41,54 +41,59 @@ class Index extends Api
     public function company()
     {
 
-        $rs = Company::where('id',$this->cid)->field('company_name,company_tel,sys_appid,wechat_appid,wechat_share_image,wechat_qrcode_image,routine_appid,share_title,share_info,wx_open_appid')->find();
+        $rs = Company::where('id', $this->cid)->field('company_name,company_tel,sys_appid,wechat_appid,wechat_share_image,wechat_qrcode_image,routine_appid,share_title,share_info,wx_open_appid')->find();
 
-        if($rs) {
+        if ($rs) {
             $rs = $rs->toArray();
-            $rs['all_ash'] = Config::where('name','all_ash')->value('value');
+            $rs['all_ash'] = Config::where('name', 'all_ash')->value('value');
             $this->success('获取成功', $rs);
         }
     }
+
     public function wxconfig()
     {
-        $this->success('获取成功',json_decode(WechatService::jsSdk(input('url'),$this->cid),true));
+        $this->success('获取成功', json_decode(WechatService::jsSdk(input('url'), $this->cid), true));
     }
+
     public function geocoder(Request $request)
     {
-        list($latitude,$longitude) = UtilService::getMore(
+        list($latitude, $longitude) = UtilService::getMore(
             [
-                ['latitude',''],
-                ['longitude',''],
-            ],$request,true
+                ['latitude', ''],
+                ['longitude', ''],
+            ], $request, true
         );
-        if($latitude=='' || $longitude=='') $this->error('请先获取定位');
-        $url = sprintf("https://apis.map.qq.com/ws/geocoder/v1/?location=%s,%s&key=VYZBZ-P2TRG-RMIQ3-ITAIN-2DKBK-CKFQQ",$latitude,$longitude);
+        if ($latitude == '' || $longitude == '') $this->error('请先获取定位');
+        $url = sprintf("https://apis.map.qq.com/ws/geocoder/v1/?location=%s,%s&key=VYZBZ-P2TRG-RMIQ3-ITAIN-2DKBK-CKFQQ", $latitude, $longitude);
         $rs = file_get_contents($url);
-        $this->success('获取成功',json_decode($rs,true));
+        $this->success('获取成功', json_decode($rs, true));
     }
+
     public function MiniScheme(Request $request)
     {
         $param = UtilService::postMore(
             [
-                ['path',''],
-                ['query',''],
-            ],$request
+                ['path', ''],
+                ['query', ''],
+            ], $request
         );
-        $this->success(UtilService::getMiniScheme($this->cid,$param));
+        $this->success(UtilService::getMiniScheme($this->cid, $param));
     }
+
     public function Minilink(Request $request)
     {
         $param = UtilService::postMore(
             [
-                ['path',''],
-                ['query',''],
-            ],$request
+                ['path', ''],
+                ['query', ''],
+            ], $request
         );
-        $this->success(UtilService::getMiniLink($this->cid,$param));
+        $this->success(UtilService::getMiniLink($this->cid, $param));
     }
+
     public function test()
     {
-        $params= json_decode('["oH3Q06tuUH-yzGX0r-FM2V6ucNYA",{"openid":"oH3Q06tuUH-yzGX0r-FM2V6ucNYA","nickname":"\u4e0d\u6253\u81ea\u62db","sex":0,"language":"","city":"","province":"","country":"","headimgurl":"https:\/\/thirdwx.qlogo.cn\/mmopen\/vi_32\/AoXC8Dwxrsic913iaUibZgQcRMLCiaDg6T95xqe7KBXl0frpvV9z3UpKrhPxylxytVZyaCBFaiaJV8qR00BuIZG8X9w\/132","subscribe":0,"cid":2},0,1]',true);
+        $params = json_decode('["oH3Q06tuUH-yzGX0r-FM2V6ucNYA",{"openid":"oH3Q06tuUH-yzGX0r-FM2V6ucNYA","nickname":"\u4e0d\u6253\u81ea\u62db","sex":0,"language":"","city":"","province":"","country":"","headimgurl":"https:\/\/thirdwx.qlogo.cn\/mmopen\/vi_32\/AoXC8Dwxrsic913iaUibZgQcRMLCiaDg6T95xqe7KBXl0frpvV9z3UpKrhPxylxytVZyaCBFaiaJV8qR00BuIZG8X9w\/132","subscribe":0,"cid":2},0,1]', true);
 
         Hook::exec("\\app\admin\\behavior\\User", "WechatOauth", $params);
         $user = User::where('id', UserRelation::openidToUid("oH3Q06tuUH-yzGX0r-FM2V6ucNYA", 'openid'))->find();

+ 61 - 53
application/api/controller/Lave.php

@@ -1,7 +1,9 @@
 <?php
+
 namespace app\api\controller;
+
 use app\common\controller\Api;
-use app\common\model\{Category,Lave as LaveModel};
+use app\common\model\{Category, Lave as LaveModel};
 use liuniu\repositories\LaveRepository;
 use liuniu\UtilService;
 use think\Request;
@@ -10,91 +12,96 @@ class Lave extends Api
 {
     protected $noNeedLogin = ['*'];
     protected $noNeedRight = ['*'];
+
     public function lst(Request $request)
     {
         $where = UtilService::getMore(
             [
-                ['page',1],
-                ['limit',10],
-                ['cid',$this->cid],
-                ['paid',1],
-                ['category_id',0],
-                ['order',''],
-                ['key',''],
-            ],$request
+                ['page', 1],
+                ['limit', 10],
+                ['cid', $this->cid],
+                ['paid', 1],
+                ['category_id', 0],
+                ['order', ''],
+                ['key', ''],
+            ], $request
         );
-        $this->success('获取成功',LaveModel::lst($where));
+        $this->success('获取成功', LaveModel::lst($where));
     }
+
     public function ify()
     {
-        $this->success('获取成功',Category::getCategoryArray('lave'));
+        $this->success('获取成功', Category::getCategoryArray('lave', null, $this->cid));
     }
+
     public function create(Request $request)
     {
         $where = UtilService::postMore(
             [
-                ['cid',$this->cid],
-                ['user_id',$this->auth->getUserinfo()['id']],
-                ['order_name',''],
-                ['category_id',0],
-                ['amount',0],
-                ['name',''],
-                ['contact',''],
-                ['tel',0],
-                ['address',''],
-                ['is_open','0'],
-                ['is_ticket','0'],
-                ['pay_type','0'],
-                ['type','0'],
-                ['help_id',0],
-                ['from','weixin'],
-            ],$request
+                ['cid', $this->cid],
+                ['user_id', $this->auth->getUserinfo()['id']],
+                ['order_name', ''],
+                ['category_id', 0],
+                ['amount', 0],
+                ['name', ''],
+                ['contact', ''],
+                ['tel', 0],
+                ['address', ''],
+                ['is_open', '0'],
+                ['is_ticket', '0'],
+                ['pay_type', '0'],
+                ['type', '0'],
+                ['help_id', 0],
+                ['from', 'weixin'],
+            ], $request
         );
         $where1 = $where;
         unset($where1['from']);
         $where1['order_id'] = LaveModel::getNewOrderId();
-        if(cache('lave_'.$where['user_id']))  $this->error('正在处理中');
-        @file_put_contents("lave.txt",json_encode($where1));
+        if (cache('lave_' . $where['user_id'])) $this->error('正在处理中');
+        @file_put_contents("lave.txt", json_encode($where1));
         $order = LaveModel::create($where1);
-        cache('lave_'.$where['user_id'],'1',10);
-        if(!$order) $this->error(LaveModel::getErrorInfo());
+        cache('lave_' . $where['user_id'], '1', 10);
+        if (!$order) $this->error(LaveModel::getErrorInfo());
         $orderId = $order['order_id'];
         $info = compact('orderId');
         if ($orderId) {
             $orderInfo = LaveModel::where('order_id', $orderId)->find();
             if (!$orderInfo || !isset($orderInfo['paid'])) $this->error('支付订单不存在!');
-            if ($orderInfo['paid'])  $this->error('支付已支付!');
+            if ($orderInfo['paid']) $this->error('支付已支付!');
             try {
                 if ($where['from'] == 'routine') {
-                    $jsConfig = LaveRepository::jsPay($this->cid,$orderId); //创建订单jspay
+                    $jsConfig = LaveRepository::jsPay($this->cid, $orderId); //创建订单jspay
                 } else if ($where['from'] == 'weixinh5') {
-                    $jsConfig = LaveRepository::h5Pay($this->cid,$orderId);
+                    $jsConfig = LaveRepository::h5Pay($this->cid, $orderId);
                 } else {
-                    $jsConfig  = LaveRepository::wxPay($this->cid,$orderId);
+                    $jsConfig = LaveRepository::wxPay($this->cid, $orderId);
                 }
             } catch (\Exception $e) {
-                return $this->error( $e->getMessage());
+                return $this->error($e->getMessage());
             }
             $info['jsConfig'] = $jsConfig;
 
-                return $this->success('订单创建成功',$info);
+            return $this->success('订单创建成功', $info);
 
         } else $this->error(LaveModel::getErrorInfo());
     }
-    public function mylst(Request  $request)
+
+    public function mylst(Request $request)
     {
         $where = UtilService::getMore(
             [
-                ['page',1],
-                ['limit',10],
-                ['cid',$this->cid],
-                ['user_id',$this->auth->getUserinfo()['id']],
-                ['paid',-1],
-                ['category_id',0],
-            ],$request
+                ['page', 1],
+                ['limit', 10],
+                ['cid', $this->cid],
+                ['user_id', $this->auth->getUserinfo()['id']],
+                ['paid', -1],
+                ['category_id', 0],
+            ], $request
         );
-        $this->success('获取成功',LaveModel::lst($where));
+        $this->success('获取成功', LaveModel::lst($where));
     }
+
     /**
      * 订单支付
      * @param Request $request
@@ -107,10 +114,10 @@ class Lave extends Api
             ['paytype', '0'],
             ['from', 'weixin']
         ], $request, true);
-        if (!$uni)  $this->error('参数错误!');
-        $order = LaveModel::where('cid',$this->cid)->where('order_id',$uni)->find();
+        if (!$uni) $this->error('参数错误!');
+        $order = LaveModel::where('cid', $this->cid)->where('order_id', $uni)->find();
         if (!$order)
-           $this->error('订单不存在!');
+            $this->error('订单不存在!');
         if ($order['paid'])
             $this->error('该订单已支付!');
         $order['pay_type'] = $paytype; //重新支付选择支付方式
@@ -118,20 +125,21 @@ class Lave extends Api
             case '0':
                 try {
                     if ($from == 'routine') {
-                        $jsConfig = LaveRepository::jsPay($this->cid,$order); //订单列表发起支付
+                        $jsConfig = LaveRepository::jsPay($this->cid, $order); //订单列表发起支付
                     } else if ($from == 'weixinh5') {
-                        $jsConfig = LaveRepository::h5Pay($this->cid,$order);
+                        $jsConfig = LaveRepository::h5Pay($this->cid, $order);
                     } else {
-                        $jsConfig = LaveRepository::wxPay($this->cid,$order);
+                        $jsConfig = LaveRepository::wxPay($this->cid, $order);
                     }
                 } catch (\Exception $e) {
                     $this->error($e->getMessage());
                 }
-                $this->success('获取成功',$jsConfig);
+                $this->success('获取成功', $jsConfig);
                 break;
         }
         return $this->error('支付方式错误');
     }
 
 }
+
 ?>

+ 74 - 70
application/api/controller/Rescue.php

@@ -1,5 +1,7 @@
 <?php
+
 namespace app\api\controller;
+
 use app\common\controller\Api;
 use app\common\model\Sos;
 use app\common\model\SosBill;
@@ -8,131 +10,133 @@ use liuniu\UtilService;
 use liuniu\WechatTempleService;
 use think\Request;
 use \app\common\model\Rescue as RescueModel;
+
 class Rescue extends Api
 {
     protected $noNeedRight = ['*'];
 
     public function index(Request $request)
     {
-        List($page,$limit,$latitude,$longitude) = UtilService::getMore(
+        list($page, $limit, $latitude, $longitude) = UtilService::getMore(
             [
-                ['page',1],
-                ['limit',10],
-                ['latitude',''],
-                ['longitude',''],
+                ['page', 1],
+                ['limit', 10],
+                ['latitude', ''],
+                ['longitude', ''],
             ],
-            $request,true
+            $request, true
         );
-        if($latitude=='' || $longitude=='') $this->error('请先获取定位');
-        return $this->success('获取成功',RescueModel::lst($this->cid,$latitude,$longitude,$page,$limit,$this->auth->getUserinfo()['id'],1,1));
+        if ($latitude == '' || $longitude == '') $this->error('请先获取定位');
+        return $this->success('获取成功', RescueModel::lst($this->cid, $latitude, $longitude, $page, $limit, $this->auth->getUserinfo()['id'], 1, 1));
     }
+
     public function create(Request $request)
     {
         $where = UtilService::postMore(
             [
-                ['name',''],
-                ['phone',''],
-                ['institution_id',0],
-                ['volunteer_id',0],
-                ['address',''],
-                ['latitude',''],
-                ['longitude',''],
-                ['certificateimage',''],
-            ],$request
+                ['name', ''],
+                ['phone', ''],
+                ['institution_id', 0],
+                ['volunteer_id', 0],
+                ['address', ''],
+                ['latitude', ''],
+                ['longitude', ''],
+                ['certificateimage', ''],
+            ], $request
         );
-        if($where['name']=='')$this->error('姓名不能为空');
-        if($where['phone']=='')$this->error('电话不能为空');
-        if($where['address']=='')$this->error('地址信息不能为空');
-        if($where['certificateimage']=='')$this->error('证书不能为空');
+        if ($where['name'] == '') $this->error('姓名不能为空');
+        if ($where['phone'] == '') $this->error('电话不能为空');
+        if ($where['address'] == '') $this->error('地址信息不能为空');
+        if ($where['certificateimage'] == '') $this->error('证书不能为空');
 
         $where['cid'] = $this->cid;
-        $where['user_id'] =  $this->auth->getUserinfo()['id'];
-        if(RescueModel::where('user_id',$where['user_id'])->where('status','>',-1)->find()) $this->error('已经存,不能重复申请');
-        if(!RescueModel::create1($where))
-        {
+        $where['user_id'] = $this->auth->getUserinfo()['id'];
+        if (RescueModel::where('user_id', $where['user_id'])->where('status', '>', -1)->find()) $this->error('已经存,不能重复申请');
+        if (!RescueModel::create1($where)) {
             $this->error(RescueModel::getErrorInfo());
         }
         $this->success('创建成功');
     }
+
     public function applylst(Request $request)
     {
-        return $this->success('获取成功',RescueModel::lst($this->cid,'','',1,10,$this->auth->getUserinfo()['id'],-2));
+        return $this->success('获取成功', RescueModel::lst($this->cid, '', '', 1, 10, $this->auth->getUserinfo()['id'], -2));
     }
+
     public function sos_create(Request $request)
     {
         $where = UtilService::postMore(
             [
-                ['mobile',''],
-                ['address',''],
-                ['latitude',''],
-                ['longitude',''],
-                ['rescuers_id',0],
-                ['rescuers_user_id',0],
-                ['from','weixin'],
-                ['re_url',''],
-            ],$request
+                ['mobile', ''],
+                ['address', ''],
+                ['latitude', ''],
+                ['longitude', ''],
+                ['rescuers_id', 0],
+                ['rescuers_user_id', 0],
+                ['from', 'weixin'],
+                ['re_url', ''],
+            ], $request
         );
-        if($where['rescuers_id']==0) $this->error('选择救授人员');
-        if($where['latitude']=='' || $where['longitude']=='') $this->error('请先获取定位');
+        if ($where['rescuers_id'] == 0) $this->error('选择救授人员');
+        if ($where['latitude'] == '' || $where['longitude'] == '') $this->error('请先获取定位');
         $where['user_id'] = $this->auth->getUserinfo()['id'];
         $where['cid'] = $this->cid;
-        if(Sos::sos_create($where)) $this->success('创建成功');
+        if (Sos::sos_create($where)) $this->success('创建成功');
         $this->error(Sos::getErrorInfo());
 
 
     }
+
     public function lst(Request $request)
     {
         $where = UtilService::getMore(
             [
-                ['page',1],
-                ['limit',10],
-                ['type',0],
-                ['status',-3],
-                ['latitude',''],
-                ['longitude',''],
+                ['page', 1],
+                ['limit', 10],
+                ['type', 0],
+                ['status', -3],
+                ['latitude', ''],
+                ['longitude', ''],
             ],
             $request
         );
-        $where['user_id'] = 0;$where['rescue_id']=0;
-        if($where['type']==0)
-        {
-            $where['user_id']= $this->auth->getUserinfo()['id'];
-        }
-        else
-        {
-            $where['rescuers_user_id']=  $this->auth->getUserinfo()['id'];
+        $where['user_id'] = 0;
+        $where['rescue_id'] = 0;
+        if ($where['type'] == 0) {
+            $where['user_id'] = $this->auth->getUserinfo()['id'];
+        } else {
+            $where['rescuers_user_id'] = $this->auth->getUserinfo()['id'];
         }
-        return $this->success('获取成功',SosBill::lst($where));
+        return $this->success('获取成功', SosBill::lst($where));
     }
+
     public function setstatus(Request $request)
     {
         $where = UtilService::postMore(
             [
-                ['status',1],
-                ['process_remark',''],
-                ['from','weixin'],
-                ['re_url',''],
+                ['status', 1],
+                ['process_remark', ''],
+                ['from', 'weixin'],
+                ['re_url', ''],
 
-            ],$request
+            ], $request
         );
         $where['processtime'] = time();
         $where1 = $where;
         unset($where1['from']);
         unset($where1['re_url']);
-        SosBill::where('id',input('id',0))->update($where1);
-        $info = SosBill::find(input('id',0));
-        switch (intval($where['status']))
-        {
+        SosBill::where('id', input('id', 0))->update($where1);
+        $info = SosBill::find(input('id', 0));
+        switch (intval($where['status'])) {
             case  1:
                 $temp = WechatTempleService::SUPPAORTER_REPLY;
-                $res_user = RescueModel::where('user_id',$this->auth->getUserinfo()['id'])->find();
+                $res_user = RescueModel::where('user_id', $this->auth->getUserinfo()['id'])->find();
                 $data['first'] = "你发起求救已受理,救员者正在赶来";
                 $data['keyword1'] = $res_user['phone'];
                 $data['keyword2'] = $res_user['address'];
                 $data['keyword3'] = date("Y-m-d H:i:s");
-                $data['remark'] =$where['process_remark'];
-                $rs = WechatTempleService::sendTemplate($this->cid,UserRelation::userIdToOpenId($info['user_id']),$temp,$data,$where['re_url']);
+                $data['remark'] = $where['process_remark'];
+                $rs = WechatTempleService::sendTemplate($this->cid, UserRelation::userIdToOpenId($info['user_id']), $temp, $data, $where['re_url']);
                 break;
             case -1:
                 $temp = WechatTempleService::REQUEXST_REFUSE;
@@ -140,18 +144,18 @@ class Rescue extends Api
                 $data['keyword1'] = $where['process_remark'];
                 $data['keyword2'] = date("Y-m-d H:i:s");
                 $data['keyword3'] = "求救";
-                $data['remark'] ="";
-                $rs = WechatTempleService::sendTemplate($this->cid,UserRelation::userIdToOpenId($info['user_id']),$temp,$data,$where['re_url']);
+                $data['remark'] = "";
+                $rs = WechatTempleService::sendTemplate($this->cid, UserRelation::userIdToOpenId($info['user_id']), $temp, $data, $where['re_url']);
                 break;
         }
         $this->success('处理完成');
     }
+
     public function sos_del(Request $request)
     {
         $id = input('id');
-        if(SosBill::where('sos_id',$id)->where('status','<',1)->find())
-        {
-            SosBill::where('sos_id',$id)->where('status','<',1)->delete();
+        if (SosBill::where('sos_id', $id)->where('status', '<', 1)->find()) {
+            SosBill::where('sos_id', $id)->where('status', '<', 1)->delete();
             $this->success('删除成功');
         }
         $this->error('已删除或已接受');

+ 34 - 31
application/api/controller/Volunteer.php

@@ -1,5 +1,7 @@
 <?php
+
 namespace app\api\controller;
+
 use app\common\controller\Api;
 use liuniu\UtilService;
 use think\Exception;
@@ -9,52 +11,53 @@ use app\common\model\Volunteer as VolunteerModel;
 class Volunteer extends Api
 {
     protected $noNeedRight = ['*'];
+
     public function apply(Request $request)
     {
         $where = UtilService::postMore(
             [
-                ['name',''],
-                ['phone',''],
-                ['sex',0],
-                ['birth',''],
-                ['image',''],
-                ['certificateimage',''],
-                ['email',''],
-                ['address',''],
-                ['work',''],
-                ['specialty',''],
-                ['education',0],
-                ['is_vol',0],
-                ['is_experience',0],
-                ['start_hour',7],
-                ['end_hour',22],
-                ['work_week','1'],
-                ['taste',''],
-                ['taste_title',''],
-                ['speciali',''],
-                ['speciali_title',''],
-            ],$request
+                ['name', ''],
+                ['phone', ''],
+                ['sex', 0],
+                ['birth', ''],
+                ['image', ''],
+                ['certificateimage', ''],
+                ['email', ''],
+                ['address', ''],
+                ['work', ''],
+                ['specialty', ''],
+                ['education', 0],
+                ['is_vol', 0],
+                ['is_experience', 0],
+                ['start_hour', 7],
+                ['end_hour', 22],
+                ['work_week', '1'],
+                ['taste', ''],
+                ['taste_title', ''],
+                ['speciali', ''],
+                ['speciali_title', ''],
+            ], $request
         );
-        if($where['name']=='')$this->error('姓名不能为空');
-        if($where['phone']=='')$this->error('电话不能为空');
-        if($where['address']=='')$this->error('地址信息不能为空');
-        if($where['image']=='')$this->error('照片不能为空');
-        if($where['birth']=='')$this->error('生日不能为空');
+        if ($where['name'] == '') $this->error('姓名不能为空');
+        if ($where['phone'] == '') $this->error('电话不能为空');
+        if ($where['address'] == '') $this->error('地址信息不能为空');
+        if ($where['image'] == '') $this->error('照片不能为空');
+        if ($where['birth'] == '') $this->error('生日不能为空');
         $where['cid'] = $this->cid;
-        $where['user_id'] =  $this->auth->getUserinfo()['id'];
-        if(VolunteerModel::where('user_id',$where['user_id'])->where('status','>',-1)->find()) $this->error('已经存,不能重复申请');
+        $where['user_id'] = $this->auth->getUserinfo()['id'];
+        if (VolunteerModel::where('user_id', $where['user_id'])->where('status', '>', -1)->find()) $this->error('已经存,不能重复申请');
         try {
             if (!VolunteerModel::create($where)) {
                 $this->error(VolunteerModel::getErrorInfo());
             }
             $this->success('创建成功');
-        }catch (Exception $e)
-        {
+        } catch (Exception $e) {
             $this->error($e->getMessage());
         }
     }
+
     public function lst()
     {
-        $this->success('获取成功',VolunteerModel::where('cid',$this->cid)->where('user_id',$this->auth->getUserinfo()['id'])->select());
+        $this->success('获取成功', VolunteerModel::where('cid', $this->cid)->where('user_id', $this->auth->getUserinfo()['id'])->select());
     }
 }

+ 16 - 3
application/common/model/Category.php

@@ -68,21 +68,34 @@ class Category extends Model
 
     /**
      * 读取分类列表
-     * @param string $type   指定类型
+     * @param string $type 指定类型
      * @param string $status 指定状态
      * @return array
      */
-    public static function getCategoryArray($type = null, $status = null)
+    public static function getCategoryArray($type = null, $status = null, $cid = 0)
     {
-        $list = collection(self::where(function ($query) use ($type, $status) {
+        $list = collection(self::where(function ($query) use ($type, $status, $cid) {
             if (!is_null($type)) {
                 $query->where('type', '=', $type);
             }
             if (!is_null($status)) {
                 $query->where('status', '=', $status);
             }
+            $query->where('cid', '=', $cid);
         })->order('weigh', 'desc')->select())->toArray();
 
+        if (count($list) <= 0) {
+            $list = collection(self::where(function ($query) use ($type, $status, $cid) {
+                if (!is_null($type)) {
+                    $query->where('type', '=', $type);
+                }
+                if (!is_null($status)) {
+                    $query->where('status', '=', $status);
+                }
+                $query->where('cid', '=', 0);
+            })->order('weigh', 'desc')->select())->toArray();
+        }
+
         return $list;
     }
 }

+ 21 - 20
application/common/model/Lave.php

@@ -32,7 +32,6 @@ class Lave extends BaseModel
     ];
 
 
-
     public function getIsOpenList()
     {
         return ['0' => __('Is_open 0'), '1' => __('Is_open 1')];
@@ -109,27 +108,29 @@ class Lave extends BaseModel
     {
         return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
     }
+
     public static function lst($where)
     {
         $model = new self;
         $xwhere = null;
         $order = "id desc";
-        if(isset($where['cid']) && $where['cid']>0)  $xwhere['cid'] = $where['cid'];
-        if(isset($where['user_id']) && $where['user_id']>0)  $xwhere['user_id'] = $where['user_id'];
-        if(isset($where['category_id']) && $where['category_id']>0) $xwhere['category_id'] = $where['category_id'];
-        if(isset($where['paid']) && $where['paid']>-1) $xwhere['paid'] = $where['paid'];
-        if(isset($where['help_id']) && $where['help_id']>-1) $xwhere['help_id'] = $where['help_id'];
-        if(isset($where['order']) && $where['order']!='') $order = $where['order'];
-        if(isset($where['key']) && $where['key']!='') $xwhere['name|contact|tel'] = ['like',"%{$where['key']}%"];
-        $data = $model->where($xwhere)->order($order)->page($where['page'],$where['limit'])->select();
+        if (isset($where['cid']) && $where['cid'] > 0) $xwhere['cid'] = $where['cid'];
+        if (isset($where['user_id']) && $where['user_id'] > 0) $xwhere['user_id'] = $where['user_id'];
+        if (isset($where['category_id']) && $where['category_id'] > 0) $xwhere['category_id'] = $where['category_id'];
+        if (isset($where['paid']) && $where['paid'] > -1) $xwhere['paid'] = $where['paid'];
+        if (isset($where['help_id']) && $where['help_id'] > -1) $xwhere['help_id'] = $where['help_id'];
+        if (isset($where['order']) && $where['order'] != '') $order = $where['order'];
+        if (isset($where['key']) && $where['key'] != '') $xwhere['name|contact|tel'] = ['like', "%{$where['key']}%"];
+        $data = $model->where($xwhere)->order($order)->page($where['page'], $where['limit'])->select();
         $count = $model->where($xwhere)->count();
-        return compact('count','data');
+        return compact('count', 'data');
     }
+
     public static function lave_create($where)
     {
         try {
             if ($where['cid'] == 0 || $where['user_id'] == 0 || $where['amount'] <= 0 || empty($where['name']) || empty($where['tel'])) return self::setErrorInfo('请核对信息');
-            if($where['type']==1 && $where['contact']=='') return self::setErrorInfo('请核对信息');
+            if ($where['type'] == 1 && $where['contact'] == '') return self::setErrorInfo('请核对信息');
             $where['order_id'] = self::getNewOrderId();
             $rs = self::create($where);
             return $rs;
@@ -137,6 +138,7 @@ class Lave extends BaseModel
             return self::setErrorInfo($e->getMessage());
         }
     }
+
     public static function getNewOrderId()
     {
         do {
@@ -146,18 +148,17 @@ class Lave extends BaseModel
         } while (self::where(['order_id' => $orderId])->find());
         return $orderId;
     }
-    public static function paySuccess($cid,$order_id)
+
+    public static function paySuccess($cid, $order_id)
     {
-        $max_sn = self::where('cid',$cid)->order('SN DESC')->value('SN');
-        if($max_sn) {
-            $no = intval(explode("_", $max_sn)[1])+1;
-        }
-        else
-        {
+        $max_sn = self::where('cid', $cid)->order('SN DESC')->value('SN');
+        if ($max_sn) {
+            $no = intval(explode("_", $max_sn)[1]) + 1;
+        } else {
             $no = 1;
         }
-        $SN = $cid."_".str_pad($no,8,'0',STR_PAD_LEFT);
-        $res = self::where('order_id', $order_id)->where('cid',$cid)->update(['paid' => 1, 'paytime' => time(),"SN"=>$SN]);//订单改为支付
+        $SN = $cid . "_" . str_pad($no, 8, '0', STR_PAD_LEFT);
+        $res = self::where('order_id', $order_id)->where('cid', $cid)->update(['paid' => 1, 'paytime' => time(), "SN" => $SN]);//订单改为支付
         return false !== $res;
     }
 

+ 56 - 55
extend/liuniu/WechatService.php

@@ -1,4 +1,5 @@
 <?php
+
 namespace liuniu;
 
 use app\admin\model\Company;
@@ -20,7 +21,7 @@ class WechatService
 
     public static function options($cid)
     {
-        $info = Company::where('id',$cid)->find();
+        $info = Company::where('id', $cid)->find();
         $config = [
             'app_id' => isset($info['wechat_appid']) ? trim($info['wechat_appid']) : '',
             'secret' => isset($info['wechat_appsecret']) ? trim($info['wechat_appsecret']) : '',
@@ -38,13 +39,14 @@ class WechatService
                 'key' => trim($info['pay_weixin_key']),
                 'cert_path' => realpath('.' . $info['pay_weixin_client_certfile']),
                 'key_path' => realpath('.' . $info['pay_weixin_client_keyfile']),
-                'notify_url' => Request::instance()->domain(). "/api/wechat/notify/".$cid
+                'notify_url' => Request::instance()->domain() . "/api/wechat/notify/" . $cid
             ];
-            $config = array_merge($config,$config1);
+            $config = array_merge($config, $config1);
         }
         return $config;
     }
-    public static function application($cache = false,$cid=0)
+
+    public static function application($cache = false, $cid = 0)
     {
         (self::$instance[$cid] === null || $cache === true) && (self::$instance[$cid] = Factory::officialAccount(self::options($cid)));
         return self::$instance[$cid];
@@ -56,14 +58,15 @@ class WechatService
      * @param int $cid
      * @return \EasyWeChat\Payment\Application|mixed
      */
-    public static function payment($cache = false,$cid=0)
+    public static function payment($cache = false, $cid = 0)
     {
         (self::$app[$cid] === null || $cache === true) && (self::$app[$cid] = Factory::payment(self::options($cid)));
         return self::$app[$cid];
     }
-    public static function serve($cid=0): Response
+
+    public static function serve($cid = 0): Response
     {
-        $wechat = self::application(true,$cid);
+        $wechat = self::application(true, $cid);
         $server = $wechat->server;
         self::hook($server);
         $response = $server->serve();
@@ -115,10 +118,10 @@ class WechatService
                     }
                     break;
                 case 'text':
-                    @file_put_contents("tt.txt",'1');
+                    @file_put_contents("tt.txt", '1');
                     $response = self::textMessage('绑定推荐人失败');
-                    @file_put_contents("tt.txt",'2',8);
-                    @file_put_contents("tt.txt",json_encode($response),8);
+                    @file_put_contents("tt.txt", '2', 8);
+                    @file_put_contents("tt.txt", json_encode($response), 8);
                     break;
                     $response = WechatReply::reply($message->Content);
                     break;
@@ -164,27 +167,27 @@ class WechatService
      * 上传永久素材接口
      * @return \EasyWeChat\Material\Material
      */
-    public static function materialService($cid=0)
+    public static function materialService($cid = 0)
     {
-        return self::application(false,$cid)->material;
+        return self::application(false, $cid)->material;
     }
 
     /**
      * 上传临时素材接口
      * @return \EasyWeChat\Material\Temporary
      */
-    public static function materialTemporaryService($cid=0)
+    public static function materialTemporaryService($cid = 0)
     {
-        return self::application(false,$cid)->media;
+        return self::application(false, $cid)->media;
     }
 
     /**
      * 用户接口
      * @return \EasyWeChat\User\User
      */
-    public static function userService($cid=0)
+    public static function userService($cid = 0)
     {
-        return self::application(false,$cid)->user;
+        return self::application(false, $cid)->user;
     }
 
 
@@ -193,45 +196,45 @@ class WechatService
      * @param null $to
      * @param null $message
      */
-    public static function staffService($cid=0)
+    public static function staffService($cid = 0)
     {
-        return self::application(false,$cid)->staff;
+        return self::application(false, $cid)->staff;
     }
 
     /**
      * 微信公众号菜单接口
      * @return \EasyWeChat\Menu\Menu
      */
-    public static function menuService($cid=0)
+    public static function menuService($cid = 0)
     {
-        return self::application(false,$cid)->menu;
+        return self::application(false, $cid)->menu;
     }
 
     /**
      * 微信二维码生成接口
      * @return \EasyWeChat\QRCode\QRCode
      */
-    public static function qrcodeService($cid=0)
+    public static function qrcodeService($cid = 0)
     {
-        return self::application(false,$cid)->qrcode;
+        return self::application(false, $cid)->qrcode;
     }
 
     /**
      * 微信永久二维码生成接口 小于10万个
      * @return \EasyWeChat\QRCode\QRCode
      */
-    public static function qrcodeForeverService($sceneValue,$cid=0)
+    public static function qrcodeForeverService($sceneValue, $cid = 0)
     {
-        return self::application(false,$cid)->qrcode->forever($sceneValue);
+        return self::application(false, $cid)->qrcode->forever($sceneValue);
     }
 
     /**
      * 微信临时二维码生成接口 30天有效期
      * @return \EasyWeChat\QRCode\QRCode
      */
-    public static function qrcodeTempService($sceneValue, $expireSeconds = 2592000,$cid=0)
+    public static function qrcodeTempService($sceneValue, $expireSeconds = 2592000, $cid = 0)
     {
-        return self::application(false,$cid)->qrcode->temporary($sceneValue, $expireSeconds);
+        return self::application(false, $cid)->qrcode->temporary($sceneValue, $expireSeconds);
 
     }
 
@@ -239,30 +242,30 @@ class WechatService
      * 短链接生成接口
      * @return \EasyWeChat\Url\Url
      */
-    public static function urlService($cid=0)
+    public static function urlService($cid = 0)
     {
-        return self::application(false,$cid)->url;
+        return self::application(false, $cid)->url;
     }
 
     /**
      * 用户授权
      * @return \Overtrue\Socialite\Providers\WeChatProvider
      */
-    public static function oauthService($cid=0)
+    public static function oauthService($cid = 0)
     {
-        return self::application(false,$cid)->oauth;
+        return self::application(false, $cid)->oauth;
     }
 
     /**
      * 模板消息接口
      * @return \EasyWeChat\Notice\Notice
      */
-    public static function noticeService($cid=0)
+    public static function noticeService($cid = 0)
     {
-        return self::application(false,$cid)->template_message;
+        return self::application(false, $cid)->template_message;
     }
 
-    public static function sendTemplate($openid, $templateId, array $data, $url = null,$cid=0)
+    public static function sendTemplate($openid, $templateId, array $data, $url = null, $cid = 0)
     {
         $notice = self::noticeService($cid);
         return $notice->send([
@@ -274,10 +277,9 @@ class WechatService
     }
 
 
-
-    public static function userTagService($cid=0)
+    public static function userTagService($cid = 0)
     {
-        return self::application(false,$cid)->user_tag;
+        return self::application(false, $cid)->user_tag;
     }
 
     /**
@@ -292,28 +294,26 @@ class WechatService
      * @param array $options
      * @return Order
      */
-    public static function paymentOrder($openid, $out_trade_no, $total_fee, $attach, $body, $detail = '', $trade_type = 'JSAPI', $options = [],$cid=0)
+    public static function paymentOrder($openid, $out_trade_no, $total_fee, $attach, $body, $detail = '', $trade_type = 'JSAPI', $options = [], $cid = 0)
     {
         $total_fee = bcmul($total_fee, 100, 0);
-        $order = array_merge(compact('out_trade_no', 'total_fee', 'attach', 'body', 'detail', 'trade_type','openid'), $options);
+        $order = array_merge(compact('out_trade_no', 'total_fee', 'attach', 'body', 'detail', 'trade_type', 'openid'), $options);
         if ($order['detail'] == '') unset($order['detail']);
 
-        $result = self::payment(false,$cid)->order->unify(
-           $order
+        $result = self::payment(false, $cid)->order->unify(
+            $order
         );
         return $result;
     }
 
 
-
-
     /**
      * 使用商户订单号退款
      * @param $orderNo
      * @param $opt
      */
 
-    public static function payOrderRefund($cid,$orderNo, array $opt)
+    public static function payOrderRefund($cid, $orderNo, array $opt)
     {
         if (!isset($opt['pay_price'])) exception('缺少pay_price');
         $totalFee = floatval(bcmul($opt['pay_price'], 100, 0));
@@ -327,7 +327,7 @@ class WechatService
         REFUND_SOURCE_RECHARGE_FUNDS---可用余额退款*/
         $refundAccount = isset($opt['refund_account']) ? $opt['refund_account'] : 'REFUND_SOURCE_UNSETTLED_FUNDS';
         try {
-            $res = self::payment('false',$cid)->byOutTradeNumber($orderNo,$refundNo,$totalFee,$refundFee,['refund_desc'=>$refundReason]);
+            $res = self::payment('false', $cid)->byOutTradeNumber($orderNo, $refundNo, $totalFee, $refundFee, ['refund_desc' => $refundReason]);
             if ($res->return_code == 'FAIL') exception('退款失败:' . $res->return_msg);
             if (isset($res->err_code)) exception('退款失败:' . $res->err_code_des);
         } catch (\Exception $e) {
@@ -341,16 +341,16 @@ class WechatService
      */
     public static function handleNotify($cid)
     {
-        $response  = self::payment(true,$cid)->handlePaidNotify(function ($notify, $successful) use($cid){
+        $response = self::payment(true, $cid)->handlePaidNotify(function ($notify, $successful) use ($cid) {
             if ($successful && isset($notify['out_trade_no'])) {
                 if (isset($notify['attach']) && $notify['attach']) {
                     if (($count = strpos($notify['out_trade_no'], '_')) !== false) {
                         $notify['out_trade_no'] = substr($notify['out_trade_no'], $count + 1);
                     }
-                    $params = [$cid,$notify['out_trade_no']];
-                    Hook::exec("\\liuniu\\repositories\\PaymentRepositories","wechat".ucfirst($notify['attach']),$params);
+                    $params = [$cid, $notify['out_trade_no']];
+                    Hook::exec("\\liuniu\\repositories\\PaymentRepositories", "wechat" . ucfirst($notify['attach']), $params);
                 }
-                $data = ['eventkey' => 'notify', 'command' => '', 'refreshtime' => time(), 'openid' => $notify['openid'],'message'=>json_encode($notify)];
+                $data = ['eventkey' => 'notify', 'command' => '', 'refreshtime' => time(), 'openid' => $notify['openid'], 'message' => json_encode($notify)];
                 $wechatContext = WechatContext::create($data, true);
                 return true;
             }
@@ -362,29 +362,30 @@ class WechatService
      * jsSdk
      * @return \EasyWeChat\Js\Js
      */
-    public static function jsService($cid=0)
+    public static function jsService($cid = 0)
     {
-        return self::payment(false,$cid)->jssdk;
+        return self::payment(false, $cid)->jssdk;
     }
 
-    public static function WeixinJSBridge($cid,$prepayId)
+    public static function WeixinJSBridge($cid, $prepayId)
     {
         $json = self::jsService($cid)->bridgeConfig($prepayId);
         return $json;
     }
 
-    public static function jspay($cid,$prepayId)
+    public static function jspay($cid, $prepayId)
     {
         $json = self::jsService($cid)->sdkConfig($prepayId);
         return $json;
     }
-    public static function jsSdk($url = '',$cid=0)
+
+    public static function jsSdk($url = '', $cid = 0)
     {
         $apiList = ['editAddress', 'openAddress', 'updateTimelineShareData', 'updateAppMessageShareData', 'onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo', 'onMenuShareQZone', 'startRecord', 'stopRecord', 'onVoiceRecordEnd', 'playVoice', 'pauseVoice', 'stopVoice', 'onVoicePlayEnd', 'uploadVoice', 'downloadVoice', 'chooseImage', 'previewImage', 'uploadImage', 'downloadImage', 'translateVoice', 'getNetworkType', 'openLocation', 'getLocation', 'hideOptionMenu', 'showOptionMenu', 'hideMenuItems', 'showMenuItems', 'hideAllNonBaseMenuItem', 'showAllNonBaseMenuItem', 'closeWindow', 'scanQRCode', 'chooseWXPay', 'openProductSpecificView', 'addCard', 'chooseCard', 'openCard'];
         $jsService = self::jsService($cid);
         if ($url) $jsService->setUrl($url);
         try {
-            return $jsService->buildConfig($apiList,false);
+            return $jsService->buildConfig($apiList, false);
         } catch (\Exception $e) {
             // var_dump($e->getMessage());
             return '{}';
@@ -501,7 +502,7 @@ class WechatService
      * @param array|string $openid
      * @return \EasyWeChat\Support\Collection
      */
-    public static function getUserInfo($cid,$openid)
+    public static function getUserInfo($cid, $openid)
     {
         $userService = self::userService($cid);
         $userInfo = is_array($openid) ? $userService->select($openid) : $userService->get($openid);

+ 11 - 8
extend/liuniu/repositories/LaveRepository.php

@@ -1,5 +1,7 @@
 <?php
+
 namespace liuniu\repositories;
+
 use app\common\model\Lave as LaveModel;
 use app\common\model\UserRelation;
 use liuniu\MiniProgramService;
@@ -14,7 +16,7 @@ class LaveRepository
      * @return array|string
      * @throws Exception
      */
-    public static function wxpay($cid,$orderId,$field="order_id")
+    public static function wxpay($cid, $orderId, $field = "order_id")
     {
         if (is_string($orderId))
             $orderInfo = LaveModel::where($field, $orderId)->find();
@@ -24,8 +26,8 @@ class LaveRepository
         if ($orderInfo['paid']) exception('支付已支付!');
         if ($orderInfo['amount'] <= 0) exception('该支付无需支付!');
         $openid = UserRelation::userIdToOpenId($orderInfo['user_id']);
-        $rs = WechatService::paymentOrder($openid, $orderInfo['order_id'], $orderInfo['amount'],"lave", $orderInfo['order_name'],'', 'JSAPI', [],$cid);
-        return WechatService::jspay($cid,$rs['prepay_id']);
+        $rs = WechatService::paymentOrder($openid, $orderInfo['order_id'], $orderInfo['amount'], "lave", $orderInfo['order_name'], '', 'JSAPI', [], $cid);
+        return WechatService::jspay($cid, $rs['prepay_id']);
 
     }
 
@@ -39,7 +41,7 @@ class LaveRepository
      * @throws DbException
      * @throws Exception
      */
-    public static function jsPay($cid,$orderId, $field = 'order_id')
+    public static function jsPay($cid, $orderId, $field = 'order_id')
     {
         if (is_string($orderId))
             $orderInfo = LaveModel::where($field, $orderId)->find();
@@ -48,13 +50,14 @@ class LaveRepository
         if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
         if ($orderInfo['paid']) exception('支付已支付!');
         if ($orderInfo['amount'] <= 0) exception('该支付无需支付!');
-        $openid = UserRelation::userIdToOpenId($orderInfo['user_id'],'routine_openid');
+        $openid = UserRelation::userIdToOpenId($orderInfo['user_id'], 'routine_openid');
         $bodyContent = $orderInfo['intention'];
         $site_name = sys_config('site_name');
         if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
-        return MiniProgramService::paymentOrder($openid, $orderInfo['order_id'], $orderInfo['money'], 'lave', $orderInfo['order_name'],'','',[],$cid);
+        return MiniProgramService::paymentOrder($openid, $orderInfo['order_id'], $orderInfo['money'], 'lave', $orderInfo['order_name'], '', '', [], $cid);
 
     }
+
     /**
      * 微信h5支付
      * @param $orderId
@@ -62,7 +65,7 @@ class LaveRepository
      * @return array|string
      * @throws Exception
      */
-    public static function h5Pay($cid,$orderId, $field = 'order_id')
+    public static function h5Pay($cid, $orderId, $field = 'order_id')
     {
         if (is_string($orderId))
             $orderInfo = Donate::where($field, $orderId)->find();
@@ -74,6 +77,6 @@ class LaveRepository
         $bodyContent = $orderInfo['intention'];
         $site_name = sys_config('site_name');
         if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
-        return WechatService::payment(false,$cid)->paymentOrder(null, $orderInfo['order_id'], $orderInfo['amount'],"lave", $orderInfo['order_name'],'', 'MWEB', [],$cid);
+        return WechatService::payment(false, $cid)->paymentOrder(null, $orderInfo['order_id'], $orderInfo['amount'], "lave", $orderInfo['order_name'], '', 'MWEB', [], $cid);
     }
 }

+ 9 - 7
extend/liuniu/repositories/PaymentRepositories.php

@@ -1,5 +1,7 @@
 <?php
+
 namespace liuniu\repositories;
+
 use app\common\model\Lave;
 use app\common\model\OrderLevel;
 
@@ -52,7 +54,6 @@ class PaymentRepositories
     }
 
 
-
     /**
      * 捐款支付成功之后
      * @param string|null $order_id 订单id
@@ -60,14 +61,15 @@ class PaymentRepositories
      */
     public static function wechatLave($event)
     {
-        list($cid,$order_id) = $event;
+        list($cid, $order_id) = $event;
         try {
-            if (Lave::where(['cid'=>$cid,'order_id' => $order_id, 'paid' => 1])->find()) return true;
-            return Lave::paySuccess($cid,$order_id);
+            if (Lave::where(['cid' => $cid, 'order_id' => $order_id, 'paid' => 1])->find()) return true;
+            return Lave::paySuccess($cid, $order_id);
         } catch (\Exception $e) {
             return false;
         }
     }
+
     /**
      * 捐款支付成功之后
      * @param string|null $order_id 订单id
@@ -75,10 +77,10 @@ class PaymentRepositories
      */
     public static function wechatLevel($event)
     {
-        list($cid,$order_id) = $event;
+        list($cid, $order_id) = $event;
         try {
-            if (OrderLevel::where(['cid'=>$cid,'order_id' => $order_id, 'paid' => 1])->find()) return true;
-            return OrderLevel::paySuccess($cid,$order_id);
+            if (OrderLevel::where(['cid' => $cid, 'order_id' => $order_id, 'paid' => 1])->find()) return true;
+            return OrderLevel::paySuccess($cid, $order_id);
         } catch (\Exception $e) {
             return false;
         }