修改数据库配置

This commit is contained in:
liaofei 2019-11-28 18:42:19 +08:00
parent 8875a1e82b
commit 08142b4c84
7 changed files with 155 additions and 165 deletions

View File

@ -100,33 +100,32 @@ if (!function_exists('make_path')) {
*/ */
function make_path($path, int $type = 2, bool $force = false) function make_path($path, int $type = 2, bool $force = false)
{ {
$path = DS.ltrim(rtrim($path)); $path = DS . ltrim(rtrim($path));
switch ($type){ switch ($type) {
case 1: case 1:
$path .= DS.date('Y'); $path .= DS . date('Y');
break; break;
case 2: case 2:
$path .= DS.date('Y').DS.date('m'); $path .= DS . date('Y') . DS . date('m');
break; break;
case 3: case 3:
$path .= DS.date('Y').DS.date('m').DS.date('d'); $path .= DS . date('Y') . DS . date('m') . DS . date('d');
break; break;
} }
try{ try {
if (is_dir(app()->getRootPath().'public'.DS.'uploads'.$path) == true || mkdir(app()->getRootPath().'public'.DS.'uploads'.$path, 0777, true) == true) { 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),'.'); return trim(str_replace(DS, '/', $path), '.');
}else return ''; } else return '';
}catch (\Exception $e){ } catch (\Exception $e) {
if($force) if ($force)
throw new \Exception($e->getMessage()); 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 * @param string $name
@ -134,15 +133,14 @@ if(!function_exists('sysConfig'))
*/ */
function sysConfig(string $name) function sysConfig(string $name)
{ {
if(empty($name)) if (empty($name))
return null; return null;
return app('sysConfig')->get($name); return app('sysConfig')->get($name);
} }
} }
if(!function_exists('sysData')) if (!function_exists('sysData')) {
{
/** /**
* 获取系统单个配置 * 获取系统单个配置
* @param string $name * @param string $name

View File

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

View File

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

View File

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

View File

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

View File

@ -64,7 +64,7 @@ class ChatHandle
if (!$to_uid) return $response->send('err_tip', ['msg' => '用户不存在']); if (!$to_uid) return $response->send('err_tip', ['msg' => '用户不存在']);
if ($to_uid == $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' => '格式错误']); 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 = compact('to_uid', 'msn_type', 'msn', 'uid');
$data['add_time'] = time(); $data['add_time'] = time();
$connections = $this->service->user(); $connections = $this->service->user();

View File

@ -29,35 +29,19 @@ trait LogicTrait
* @param $params 参数 * @param $params 参数
* @return mixed * @return mixed
*/ */
public static function __callStatic($method,$params) public static function __callStatic($method, $params)
{ {
return call_user_func_array([self::$instance,$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;
}
} }
/** /**
* 配置参数 * 配置参数
* @param array $config * @param array $config
*/ */
protected function setConfig(array $config=[]) protected function setConfig(array $config = [])
{ {
foreach ($config as $key => $value) { 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() protected function registerProviders()
{ {
if (property_exists($this,'providers')) if (property_exists($this, 'providers')) {
{ foreach ($this->providers as $key => $provider) {
foreach ($this->providers as $key=>$provider) $this->register(new $provider(), $key);
{
$this->register(new $provider(),$key);
} }
} }
} }
@ -102,14 +84,14 @@ trait LogicTrait
* @param object $pimple * @param object $pimple
* @return $this * @return $this
* */ * */
protected function register($pimple,$key) protected function register($pimple, $key)
{ {
$response=$pimple->register($this->items); $response = $pimple->register($this->items);
if(is_array($response)) { if (is_array($response)) {
list($key,$provider)=$response; [$key, $provider] = $response;
$this->$key= $provider; $this->$key = $provider;
}else if(is_string($key)){ } else if (is_string($key)) {
$this->$key= $pimple; $this->$key = $pimple;
} }
return $this; return $this;
} }
@ -119,13 +101,14 @@ trait LogicTrait
* @param array $config * @param array $config
* @return $this * @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 = new self();
self::$instance->setConfig($config); self::$instance->setConfig($config);
self::$instance->registerProviders(); self::$instance->registerProviders();
self::$instance->bool(); if (method_exists(self::$instance, 'bool'))
self::$instance->bool();
} }
return self::$instance; return self::$instance;
} }
@ -160,36 +143,38 @@ trait LogicTrait
* @param $ages * @param $ages
* @return $this * @return $this
*/ */
public function __call($method,$ages) public function __call($method, $ages)
{ {
$keys = array_keys($this->providers); $keys = property_exists($this, 'providers') ? array_keys($this->providers) : [];
$propsRuleKeys = property_exists($this,'propsRule') ? array_keys($this->propsRule) : []; $propsRuleKeys = property_exists($this, 'propsRule') ? array_keys($this->propsRule) : [];
if (strstr($method,'set') !== false) { if (strstr($method, 'set') !== false) {
$attribute = lcfirst(str_replace('set','',$method)); $attribute = lcfirst(str_replace('set', '', $method));
if (property_exists($this,$attribute) if (property_exists($this, $attribute) && in_array($attribute, $propsRuleKeys)) {
&& in_array($attribute,$propsRuleKeys)
&& isset($this->propsRule[$attribute]))
{
$propsRuleValeu = $this->propsRule[$attribute]; $propsRuleValeu = $this->propsRule[$attribute];
$type = $propsRuleValeu[1] ?? 'string'; $valeu = null;
$callable = $propsRuleValeu[2] ?? null; if (is_array($propsRuleValeu)) {
if ($type == 'callable' && $callable) { $type = $propsRuleValeu[1] ?? 'string';
$callable = $propsRuleValeu[2]; $callable = $propsRuleValeu[2] ?? null;
if (method_exists($this,$callable)) if ($type == 'callable' && $callable) {
$ages[0] = $this->{$callable}($ages[0],$ages[1] ?? ''); $callable = $propsRuleValeu[2];
if (method_exists($this, $callable))
$ages[0] = $this->{$callable}($ages[0], $ages[1] ?? '');
} else if($type) { } else if ($type) {
$ages[0] = $this->toType($ages[0],$type) ?? null; $ages[0] = $this->toType($ages[0], $type) ?? null;
}
} else {
$valeu = $propsRuleValeu;
} }
$this->{$attribute} = $ages[0]; $this->{$attribute} = $ages[0] ?? $valeu;
return $this; return $this;
} }
} else if(in_array($method,$keys)) { } else if (in_array($method, $keys)) {
$this->sendType = $method; $this->sendType = $method;
return $this; return $this;
} else { } else {
throw new AuthException('Method does not exist'.$method); throw new AuthException('Method does not exist' . $method);
} }
} }
} }