liaofei 6 лет назад
Родитель
Сommit
08142b4c84

+ 15 - 17
crmeb/app/common.php

@@ -100,33 +100,32 @@ if (!function_exists('make_path')) {
      */
     function make_path($path, int $type = 2, bool $force = false)
     {
-        $path =  DS.ltrim(rtrim($path));
-        switch ($type){
+        $path = DS . ltrim(rtrim($path));
+        switch ($type) {
             case 1:
-                $path .= DS.date('Y');
+                $path .= DS . date('Y');
                 break;
             case 2:
-                $path .=  DS.date('Y').DS.date('m');
+                $path .= DS . date('Y') . DS . date('m');
                 break;
             case 3:
-                $path .=  DS.date('Y').DS.date('m').DS.date('d');
+                $path .= DS . date('Y') . DS . date('m') . DS . date('d');
                 break;
         }
-        try{
-            if (is_dir(app()->getRootPath().'public'.DS.'uploads'.$path) == true || mkdir(app()->getRootPath().'public'.DS.'uploads'.$path, 0777, true) == true) {
-                return trim(str_replace(DS, '/',$path),'.');
-            }else return '';
-        }catch (\Exception $e){
-            if($force)
+        try {
+            if (is_dir(app()->getRootPath() . 'public' . DS . 'uploads' . $path) == true || mkdir(app()->getRootPath() . 'public' . DS . 'uploads' . $path, 0777, true) == true) {
+                return trim(str_replace(DS, '/', $path), '.');
+            } else return '';
+        } catch (\Exception $e) {
+            if ($force)
                 throw new \Exception($e->getMessage());
-            return '无法创建文件夹,请检查您的上传目录权限:' . app()->getRootPath() . 'public' . DS . 'uploads' . DS. 'attach' . DS;
+            return '无法创建文件夹,请检查您的上传目录权限:' . app()->getRootPath() . 'public' . DS . 'uploads' . DS . 'attach' . DS;
         }
 
     }
 }
 
-if(!function_exists('sysConfig'))
-{
+if (!function_exists('sysConfig')) {
     /**
      * 获取系统单个配置
      * @param string $name
@@ -134,15 +133,14 @@ if(!function_exists('sysConfig'))
      */
     function sysConfig(string $name)
     {
-        if(empty($name))
+        if (empty($name))
             return null;
 
         return app('sysConfig')->get($name);
     }
 }
 
-if(!function_exists('sysData'))
-{
+if (!function_exists('sysData')) {
     /**
      * 获取系统单个配置
      * @param string $name

+ 65 - 60
crmeb/app/models/routine/RoutineTemplate.php

@@ -1,5 +1,6 @@
 <?php
-namespace  app\models\routine;
+
+namespace app\models\routine;
 
 use crmeb\utils\Template;
 use app\models\store\StoreOrder;
@@ -36,21 +37,21 @@ class RoutineTemplate
      * @param int $isGive
      * @return bool
      */
-    public static function sendOrderPostage($order,$isGive=0)
+    public static function sendOrderPostage($order, $isGive = 0)
     {
-        if($isGive){
-            $data['keyword1'] =  $order['order_id'];
-            $data['keyword2'] =  $order['delivery_name'];
-            $data['keyword3'] =  $order['delivery_id'];
-            $data['keyword4'] =  date('Y-m-d H:i:s',time());
-            $data['keyword5'] =  '您的商品已经发货请注意查收';
-            return self::sendOut('ORDER_POSTAGE_SUCCESS',$order['uid'],$data);
-        }else{
-            $data['keyword1'] =  $order['order_id'];
-            $data['keyword2'] =  $order['delivery_name'];
-            $data['keyword3'] =  $order['delivery_id'];
-            $data['keyword4'] =  date('Y-m-d H:i:s',time());
-            return self::sendOut('ORDER_DELIVER_SUCCESS',$order['uid'],$data);
+        if ($isGive) {
+            $data['keyword1'] = $order['order_id'];
+            $data['keyword2'] = $order['delivery_name'];
+            $data['keyword3'] = $order['delivery_id'];
+            $data['keyword4'] = date('Y-m-d H:i:s', time());
+            $data['keyword5'] = '您的商品已经发货请注意查收';
+            return self::sendOut('ORDER_POSTAGE_SUCCESS', $order['uid'], $data);
+        } else {
+            $data['keyword1'] = $order['order_id'];
+            $data['keyword2'] = $order['delivery_name'];
+            $data['keyword3'] = $order['delivery_id'];
+            $data['keyword4'] = date('Y-m-d H:i:s', time());
+            return self::sendOut('ORDER_DELIVER_SUCCESS', $order['uid'], $data);
         }
     }
 
@@ -61,30 +62,32 @@ class RoutineTemplate
      */
     public static function sendOrderRefundSuccess($order = array())
     {
-        if(!$order) return false;
-        $data['keyword1'] =  $order['order_id'];
-        $data['keyword2'] =  date('Y-m-d H:i:s',time());
-        $data['keyword3'] =  $order['pay_price'];
-        if($order['pay_type'] == 'yue') $data['keyword4'] =  '余额支付';
-        else if($order['pay_type'] == 'weixin') $data['keyword4'] =  '微信支付';
-        else if($order['pay_type'] == 'offline') $data['keyword4'] =  '线下支付';
+        if (!$order) return false;
+        $data['keyword1'] = $order['order_id'];
+        $data['keyword2'] = date('Y-m-d H:i:s', time());
+        $data['keyword3'] = $order['pay_price'];
+        if ($order['pay_type'] == 'yue') $data['keyword4'] = '余额支付';
+        else if ($order['pay_type'] == 'weixin') $data['keyword4'] = '微信支付';
+        else if ($order['pay_type'] == 'offline') $data['keyword4'] = '线下支付';
         $data['keyword5']['value'] = '已成功退款';
-        return self::sendOut('ORDER_REFUND_SUCCESS',$order['uid'],$data);
+        return self::sendOut('ORDER_REFUND_SUCCESS', $order['uid'], $data);
     }
+
     /**
      * 用户申请退款给管理员发送消息
      * @param array $order
      * @param string $refundReasonWap
      * @param array $adminList
      */
-    public static function sendOrderRefundStatus($order = array(),$refundReasonWap = '',$adminList = array()){
-        $data['keyword1'] =  $order['order_id'];
-        $data['keyword2'] =  $refundReasonWap;
-        $data['keyword3'] =  date('Y-m-d H:i:s',time());
-        $data['keyword4'] =  $order['pay_price'];
-        $data['keyword5'] =  '原路返回';
-        foreach ($adminList as $uid){
-            self::sendOut('ORDER_REFUND_STATUS',$uid,$data);
+    public static function sendOrderRefundStatus($order = array(), $refundReasonWap = '', $adminList = array())
+    {
+        $data['keyword1'] = $order['order_id'];
+        $data['keyword2'] = $refundReasonWap;
+        $data['keyword3'] = date('Y-m-d H:i:s', time());
+        $data['keyword4'] = $order['pay_price'];
+        $data['keyword5'] = '原路返回';
+        foreach ($adminList as $uid) {
+            self::sendOut('ORDER_REFUND_STATUS', $uid, $data);
         }
     }
 
@@ -95,14 +98,15 @@ class RoutineTemplate
      * @param int $bargainUserId
      * @return bool
      */
-    public static function sendBargainSuccess($bargain = array(),$bargainUser  = array(),$bargainUserId = 0){
-        $data['keyword1'] =  $bargain['title'];
-        $data['keyword2'] =  $bargainUser['bargain_price'];
-        $data['keyword3'] =  $bargainUser['bargain_price_min'];
-        $data['keyword4'] =  $bargainUser['price'];
-        $data['keyword5'] =  $bargainUser['bargain_price_min'];
-        $data['keyword6'] =  '恭喜您,已经砍到最低价了';
-        return self::sendOut('BARGAIN_SUCCESS',$bargainUser['uid'],$data);
+    public static function sendBargainSuccess($bargain = array(), $bargainUser = array(), $bargainUserId = 0)
+    {
+        $data['keyword1'] = $bargain['title'];
+        $data['keyword2'] = $bargainUser['bargain_price'];
+        $data['keyword3'] = $bargainUser['bargain_price_min'];
+        $data['keyword4'] = $bargainUser['price'];
+        $data['keyword5'] = $bargainUser['bargain_price_min'];
+        $data['keyword6'] = '恭喜您,已经砍到最低价了';
+        return self::sendOut('BARGAIN_SUCCESS', $bargainUser['uid'], $data);
     }
 
     /**
@@ -114,42 +118,43 @@ class RoutineTemplate
      * @throws \think\db\exception\ModelNotFoundException
      * @throws \think\exception\DbException
      */
-    public static function sendOrderSuccess($formId = '',$orderId = ''){
-        if($orderId == '') return ;
-        $order = StoreOrder::where('order_id',$orderId)->find();
-        $data['keyword1'] =  $orderId;
-        $data['keyword2'] =  date('Y-m-d H:i:s',time());
-        $data['keyword3'] =  '已支付';
-        $data['keyword4'] =  $order['pay_price'];
-        if($order['pay_type'] == 'yue') $data['keyword5'] =  '余额支付';
-        else if($order['pay_type'] == 'weixin') $data['keyword5'] =  '微信支付';
-        return self::sendOut('ORDER_PAY_SUCCESS',$order['uid'],$data,$formId,'/pages/order_details/index?order_id='.$orderId);
+    public static function sendOrderSuccess($formId = '', $orderId = '')
+    {
+        if ($orderId == '') return;
+        $order = StoreOrder::where('order_id', $orderId)->find();
+        $data['keyword1'] = $orderId;
+        $data['keyword2'] = date('Y-m-d H:i:s', time());
+        $data['keyword3'] = '已支付';
+        $data['keyword4'] = $order['pay_price'];
+        if ($order['pay_type'] == 'yue') $data['keyword5'] = '余额支付';
+        else if ($order['pay_type'] == 'weixin') $data['keyword5'] = '微信支付';
+        return self::sendOut('ORDER_PAY_SUCCESS', $order['uid'], $data, $formId, '/pages/order_details/index?order_id=' . $orderId);
     }
 
     /**
      * 发送模板消息
-     * @param string  $TempCode 模板消息常量名称
+     * @param string $TempCode 模板消息常量名称
      * @param int $uid 用户uid
      * @param array $data 模板内容
      * @param string $formId formId
      * @param string $link 跳转链接
      * @return bool
      */
-    public static function sendOut($TempCode,$uid=null,$data=null,$formId = '',$link='')
+    public static function sendOut($TempCode, $uid = null, $data = null, $formId = '', $link = '')
     {
-        try{
+        try {
             $openid = WechatUser::uidToOpenid($uid);
-            if(!$openid) return false;
-            if(!$formId){
-                $form= RoutineFormId::getFormIdOne($uid,true);
-                if(!$form) return false;
-                if(isset($form['id'])) RoutineFormId::where('id',$form['id'])->delete();
-            }else{
-                $form['form_id']=$formId;
+            if (!$openid) return false;
+            if (!$formId) {
+                $form = RoutineFormId::getFormIdOne($uid, true);
+                if (!$form) return false;
+                if (isset($form['id'])) RoutineFormId::where('id', $form['id'])->delete();
+            } else {
+                $form['form_id'] = $formId;
             }
             return Template::instance()->routine()->setTemplateUrl($link)->setTemplateOpenId($openid)
                 ->setTemplateData($data)->setTemplateFormId($form['form_id'])->setTemplateCode($TempCode)->send();
-        }catch (\Exception $e){
+        } catch (\Exception $e) {
             return false;
         }
     }

+ 1 - 1
crmeb/config/database.php

@@ -57,7 +57,7 @@ return [
             // Query类
             'query'           => '',
             // 是否需要断线重连
-            'break_reconnect' => false,
+            'break_reconnect' => true,
         ],
 
         // 更多的数据库配置信息

+ 32 - 30
crmeb/crmeb/repositories/NoticeRepositories.php

@@ -4,6 +4,7 @@
  * User: xurongyao <763569752@qq.com>
  * Date: 2019/11/13 4:52 PM
  */
+
 namespace crmeb\repositories;
 
 use app\models\user\WechatUser;
@@ -26,59 +27,60 @@ class NoticeRepositories
      * @param $order
      * @param $formId
      */
-    public static function noticeOrderPaySuccess($order,$formId)
+    public static function noticeOrderPaySuccess($order, $formId)
     {
-        $wechatUser = WechatUser::where('uid',$order['uid'])->field('openid','routine_openid')->find();
-        if($wechatUser){
+        $wechatUser = WechatUser::where('uid', $order['uid'])->field(['openid', 'routine_openid'])->find();
+        if ($wechatUser) {
             $openid = $wechatUser['openid'];
             $routineOpenid = $wechatUser['routine_openid'];
-            try{
-                if($openid){//公众号发送模板消息
-                    WechatTemplateService::sendTemplate($openid,WechatTemplateService::ORDER_PAY_SUCCESS, [
-                        'first'=>'亲,您购买的商品已支付成功',
-                        'keyword1'=>$order['order_id'],
-                        'keyword2'=>$order['pay_price'],
-                        'remark'=>'点击查看订单详情'
-                    ],Route::buildUrl('order/detail/'.$order['order_id'])->suffix('')->domain(true)->build());
+            try {
+                if ($openid && in_array($order['is_channel'],[0,2])) {//公众号发送模板消息
+                    WechatTemplateService::sendTemplate($openid, WechatTemplateService::ORDER_PAY_SUCCESS, [
+                        'first' => '亲,您购买的商品已支付成功',
+                        'keyword1' => $order['order_id'],
+                        'keyword2' => $order['pay_price'],
+                        'remark' => '点击查看订单详情'
+                    ], Route::buildUrl('order/detail/' . $order['order_id'])->suffix('')->domain(true)->build());
                     //订单支付成功后给客服发送模版消息
                     WechatTemplateService::sendAdminNoticeTemplate([
-                        'first'=>"亲,您有一个新订单 \n订单号:{$order['order_id']}",
-                        'keyword1'=>'新订单',
-                        'keyword2'=>'已支付',
-                        'keyword3'=>date('Y/m/d H:i',time()),
-                        'remark'=>'请及时处理'
+                        'first' => "亲,您有一个新订单 \n订单号:{$order['order_id']}",
+                        'keyword1' => '新订单',
+                        'keyword2' => '已支付',
+                        'keyword3' => date('Y/m/d H:i', time()),
+                        'remark' => '请及时处理'
                     ]);
                     //订单支付成功后给客服发送客服消息
                     CustomerRepository::sendOrderPaySuccessCustomerService($order, 1);
-                }else if($routineOpenid){//小程序发送模板消息
+                } else if ($routineOpenid && in_array($order['is_channel'],[1,2])) {//小程序发送模板消息
                     RoutineTemplate::sendOrderSuccess($formId, $order['order_id']);
                     //订单支付成功后给客服发送客服消息
                     CustomerRepository::sendOrderPaySuccessCustomerService($order, 0);
                 }
 
-            }catch (\Exception $e){}
+            } catch (\Exception $e) {
+            }
         }
         //打印小票
-        $switch = sysConfig('pay_success_printing_switch') ? true : false ;
-        if($switch){
-            try{
-                $order['cart_id'] = is_string($order['cart_id']) ? json_decode($order['cart_id'],true) : $order['cart_id'];
-                $cartInfo = StoreOrderCartInfo::whereIn('cart_id',$order['cart_id'])->field('cart_info')->select();
+        $switch = sysConfig('pay_success_printing_switch') ? true : false;
+        if ($switch) {
+            try {
+                $order['cart_id'] = is_string($order['cart_id']) ? json_decode($order['cart_id'], true) : $order['cart_id'];
+                $cartInfo = StoreOrderCartInfo::whereIn('cart_id', $order['cart_id'])->field('cart_info')->select();
                 $cartInfo = count($cartInfo) ? $cartInfo->toArray() : [];
-                $product  = [];
-                foreach ($cartInfo as $item){
+                $product = [];
+                foreach ($cartInfo as $item) {
                     $value = is_string($item['cart_info']) ? json_decode($item['cart_info']) : $item['cart_info'];
                     $value['productInfo']['store_name'] = $value['productInfo']['store_name'] ?? "";
-                    $value['productInfo']['store_name'] = StoreOrderCartInfo::getSubstrUTf8($value['productInfo']['store_name'],10,'UTF-8','');
+                    $value['productInfo']['store_name'] = StoreOrderCartInfo::getSubstrUTf8($value['productInfo']['store_name'], 10, 'UTF-8', '');
                     $product[] = $value;
                 }
-                YLYService::getInstance()->setContent(sysConfig('site_name'),is_object($order) ? $order->toArray() : $order,$product)->orderPrinting();
-            }catch (\Exception $e){
-                Log::error('小票打印出现错误,错误原因:'.$e->getMessage());
+                YLYService::instance()->setContent(sysConfig('site_name'), is_object($order) ? $order->toArray() : $order, $product)->orderPrinting();
+            } catch (\Exception $e) {
+                Log::error('小票打印出现错误,错误原因:' . $e->getMessage());
             }
         }
         //短信通知 下发用户支付成功 下发管理员支付通知
-        event('ShortMssageSend',[$order['order_id'],['PaySuccess','AdminPaySuccess']]);
+        event('ShortMssageSend', [$order['order_id'], ['PaySuccess', 'AdminPaySuccess']]);
 
     }
 }

+ 1 - 1
crmeb/crmeb/services/workerman/WorkermanHandle.php

@@ -25,7 +25,7 @@ class WorkermanHandle
             ]);
         }
 
-        $session = app('session',[],true);
+        $session = app('session', [], true);
         $session->setId($sessionId);
         $session->init();
 

+ 1 - 1
crmeb/crmeb/services/workerman/chat/ChatHandle.php

@@ -64,7 +64,7 @@ class ChatHandle
         if (!$to_uid) return $response->send('err_tip', ['msg' => '用户不存在']);
         if ($to_uid == $uid) return $response->send('err_tip', ['msg' => '不能和自己聊天']);
         if (!in_array($msn_type, [1, 2, 3, 4])) return $response->send('err_tip', ['msg' => '格式错误']);
-        $msn = htmlspecialchars($msn);
+        $msn = trim(strip_tags(str_replace(["\n", "\t", "\r", " ", "&nbsp;"], '', htmlspecialchars_decode($msn))));
         $data = compact('to_uid', 'msn_type', 'msn', 'uid');
         $data['add_time'] = time();
         $connections = $this->service->user();

+ 41 - 56
crmeb/crmeb/traits/LogicTrait.php

@@ -29,35 +29,19 @@ trait LogicTrait
      * @param $params 参数
      * @return mixed
      */
-    public static function __callStatic($method,$params)
+    public static function __callStatic($method, $params)
     {
-        return call_user_func_array([self::$instance,$method],$params);
-    }
-
-    /**
-     * 执行本类的方法
-     * @param string $carryoutname 方法名
-     * @return boolean
-     * */
-    public static function CarryOut($carryoutname)
-    {
-        $methords = get_class_methods(self::class);
-        if(!in_array($carryoutname,$methords)) return false;
-        try{
-            return (new self)->$carryoutname();
-        }catch (\Exception $e){
-            return false;
-        }
+        return call_user_func_array([self::$instance, $method], $params);
     }
 
     /**
      * 配置参数
      * @param array $config
      */
-    protected function setConfig(array $config=[])
+    protected function setConfig(array $config = [])
     {
         foreach ($config as $key => $value) {
-            $this->set($this->items,$key, $value);
+            $this->set($this->items, $key, $value);
         }
     }
 
@@ -88,11 +72,9 @@ trait LogicTrait
      */
     protected function registerProviders()
     {
-        if (property_exists($this,'providers'))
-        {
-            foreach ($this->providers as $key=>$provider)
-            {
-                $this->register(new $provider(),$key);
+        if (property_exists($this, 'providers')) {
+            foreach ($this->providers as $key => $provider) {
+                $this->register(new $provider(), $key);
             }
         }
     }
@@ -102,14 +84,14 @@ trait LogicTrait
      * @param object $pimple
      * @return $this
      * */
-    protected function register($pimple,$key)
+    protected function register($pimple, $key)
     {
-        $response=$pimple->register($this->items);
-        if(is_array($response)) {
-            list($key,$provider)=$response;
-            $this->$key= $provider;
-        }else if(is_string($key)){
-            $this->$key= $pimple;
+        $response = $pimple->register($this->items);
+        if (is_array($response)) {
+            [$key, $provider] = $response;
+            $this->$key = $provider;
+        } else if (is_string($key)) {
+            $this->$key = $pimple;
         }
         return $this;
     }
@@ -119,13 +101,14 @@ trait LogicTrait
      * @param array $config
      * @return $this
      * */
-    public static function instance($config=[])
+    public static function instance($config = [])
     {
-        if(is_null(self::$instance)) {
+        if (is_null(self::$instance)) {
             self::$instance = new self();
             self::$instance->setConfig($config);
             self::$instance->registerProviders();
-            self::$instance->bool();
+            if (method_exists(self::$instance, 'bool'))
+                self::$instance->bool();
         }
         return self::$instance;
     }
@@ -160,36 +143,38 @@ trait LogicTrait
      * @param $ages
      * @return $this
      */
-    public function __call($method,$ages)
+    public function __call($method, $ages)
     {
-        $keys = array_keys($this->providers);
-        $propsRuleKeys = property_exists($this,'propsRule') ? array_keys($this->propsRule) : [];
-        if (strstr($method,'set') !== false) {
-            $attribute = lcfirst(str_replace('set','',$method));
-            if (property_exists($this,$attribute)
-                && in_array($attribute,$propsRuleKeys)
-                && isset($this->propsRule[$attribute]))
-            {
+        $keys = property_exists($this, 'providers') ? array_keys($this->providers) : [];
+        $propsRuleKeys = property_exists($this, 'propsRule') ? array_keys($this->propsRule) : [];
+        if (strstr($method, 'set') !== false) {
+            $attribute = lcfirst(str_replace('set', '', $method));
+            if (property_exists($this, $attribute) && in_array($attribute, $propsRuleKeys)) {
                 $propsRuleValeu = $this->propsRule[$attribute];
-                $type           = $propsRuleValeu[1] ?? 'string';
-                $callable       = $propsRuleValeu[2] ?? null;
-                if ($type == 'callable' && $callable) {
-                    $callable = $propsRuleValeu[2];
-                    if (method_exists($this,$callable))
-                        $ages[0] = $this->{$callable}($ages[0],$ages[1] ?? '');
-
-                } else if($type) {
-                    $ages[0] = $this->toType($ages[0],$type) ?? null;
+                $valeu = null;
+                if (is_array($propsRuleValeu)) {
+                    $type = $propsRuleValeu[1] ?? 'string';
+                    $callable = $propsRuleValeu[2] ?? null;
+                    if ($type == 'callable' && $callable) {
+                        $callable = $propsRuleValeu[2];
+                        if (method_exists($this, $callable))
+                            $ages[0] = $this->{$callable}($ages[0], $ages[1] ?? '');
+
+                    } else if ($type) {
+                        $ages[0] = $this->toType($ages[0], $type) ?? null;
+                    }
+                } else {
+                    $valeu = $propsRuleValeu;
                 }
 
-                $this->{$attribute} = $ages[0];
+                $this->{$attribute} = $ages[0] ?? $valeu;
                 return $this;
             }
-        } else if(in_array($method,$keys)) {
+        } else if (in_array($method, $keys)) {
             $this->sendType = $method;
             return $this;
         } else {
-            throw new AuthException('Method does not exist:'.$method);
+            throw new AuthException('Method does not exist:' . $method);
         }
     }
 }