格式化代码

This commit is contained in:
liaofei 2019-11-19 14:31:53 +08:00
parent 42f74a3c79
commit 84f81ab7e4
37 changed files with 1149 additions and 1084 deletions

View File

@ -15,8 +15,6 @@ use crmeb\services\MiniProgramService;
use crmeb\services\UtilService; use crmeb\services\UtilService;
use crmeb\services\WechatService; use crmeb\services\WechatService;
use crmeb\services\FormBuilder as Form; use crmeb\services\FormBuilder as Form;
use crmeb\services\HookService;
use crmeb\subscribes\OrderSubscribe;
use app\admin\model\order\StoreOrderStatus; use app\admin\model\order\StoreOrderStatus;
use app\admin\model\ump\StorePink; use app\admin\model\ump\StorePink;
use app\admin\model\user\User; use app\admin\model\user\User;

View File

@ -9,7 +9,6 @@ namespace app\admin\model\wechat;
use app\admin\model\system\SystemConfig; use app\admin\model\system\SystemConfig;
use crmeb\traits\ModelTrait; use crmeb\traits\ModelTrait;
use crmeb\basic\BaseModel; use crmeb\basic\BaseModel;
use crmeb\services\HookService;
use crmeb\services\UtilService; use crmeb\services\UtilService;
use crmeb\services\WechatService; use crmeb\services\WechatService;
use think\facade\Route as Url; use think\facade\Route as Url;

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;
@ -56,7 +57,8 @@ class NoticeRepositories
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;
@ -72,7 +74,7 @@ class NoticeRepositories
$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());
} }

View File

@ -8,7 +8,6 @@
namespace crmeb\services; namespace crmeb\services;
/** /**
* 错误码统一存放类 * 错误码统一存放类
* Class ApiErrorCode * Class ApiErrorCode

View File

@ -1,4 +1,5 @@
<?php <?php
namespace crmeb\services; namespace crmeb\services;
use app\models\store\StoreBargain; use app\models\store\StoreBargain;

View File

@ -10,7 +10,8 @@ namespace crmeb\services;
class ExportService class ExportService
{ {
public static function exportCsv($list,$filename,$header = [],$br = '_'){ public static function exportCsv($list, $filename, $header = [], $br = '_')
{
$tableStr = count($header) > 0 ? '"' . implode('","', $header) . '"' . PHP_EOL : ''; $tableStr = count($header) > 0 ? '"' . implode('","', $header) . '"' . PHP_EOL : '';
$tableStr .= self::tidyCsvStr($list, str_repeat($br, 99)); $tableStr .= self::tidyCsvStr($list, str_repeat($br, 99));
ob_end_clean(); ob_end_clean();

View File

@ -506,6 +506,8 @@ class FileService
{ {
$handle = @opendir($dir);//打开指定目录 $handle = @opendir($dir);//打开指定目录
$directory_count = 0; $directory_count = 0;
$total_size = 0;
$file_cout = 0;
while (FALSE !== ($file_path = readdir($handle))) while (FALSE !== ($file_path = readdir($handle)))
{ {
if($file_path != "." && $file_path != "..") if($file_path != "." && $file_path != "..")

View File

@ -27,7 +27,8 @@ class FormBuilder extends Form
* str 自定义 * str 自定义
* @return $this * @return $this
*/ */
public static function make_post_form($title,array $field,$url,$jscallback = 2){ public static function make_post_form($title, array $field, $url, $jscallback = 2)
{
$form = Form::create($url);//提交地址 $form = Form::create($url);//提交地址
$form->setMethod('POST');//提交方式 $form->setMethod('POST');//提交方式
$form->components($field);//表单字段 $form->components($field);//表单字段

View File

@ -4,6 +4,7 @@
* @author: xaboy<365615158@qq.com> * @author: xaboy<365615158@qq.com>
* @day: 2017/11/23 * @day: 2017/11/23
*/ */
namespace crmeb\services; namespace crmeb\services;
class HttpService class HttpService

View File

@ -17,6 +17,7 @@ class JsonService
{ {
exit(json_encode(compact('code', 'msg', 'data', 'count'))); exit(json_encode(compact('code', 'msg', 'data', 'count')));
} }
public static function successlayui($count = 0, $data = [], $msg = '') public static function successlayui($count = 0, $data = [], $msg = '')
{ {
if (is_array($count)) { if (is_array($count)) {
@ -29,6 +30,7 @@ class JsonService
} }
return self::result(0, $msg, $data, $count); return self::result(0, $msg, $data, $count);
} }
public static function successful($msg = 'ok', $data = [], $status = 200) public static function successful($msg = 'ok', $data = [], $status = 200)
{ {
if (false == is_string($msg)) { if (false == is_string($msg)) {

View File

@ -11,7 +11,6 @@ use crmeb\repositories\PaymentRepositories;
use EasyWeChat\Foundation\Application; use EasyWeChat\Foundation\Application;
use EasyWeChat\Payment\Order; use EasyWeChat\Payment\Order;
use think\facade\Route as Url; use think\facade\Route as Url;
use crmeb\services\HookService;
use crmeb\interfaces\ProviderInterface; use crmeb\interfaces\ProviderInterface;
use app\models\store\StoreOrder as StoreOrderRoutineModel; use app\models\store\StoreOrder as StoreOrderRoutineModel;
use app\models\user\UserRecharge; use app\models\user\UserRecharge;
@ -324,7 +323,6 @@ class MiniProgramService implements ProviderInterface
$staff = self::staffService(); $staff = self::staffService();
$staff = is_callable($message) ? $staff->message($message()) : $staff->message($message); $staff = is_callable($message) ? $staff->message($message()) : $staff->message($message);
$res = $staff->to($to)->send(); $res = $staff->to($to)->send();
HookService::afterListen('wechat_staff_to',compact('to','message'),$res);
return $res; return $res;
} }

View File

@ -1,4 +1,5 @@
<?php <?php
namespace crmeb\services; namespace crmeb\services;
use crmeb\services\JsonService as Json; use crmeb\services\JsonService as Json;
@ -51,13 +52,15 @@ class PHPExcelService
'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER 'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER
] ]
); );
/** /**
*初始化PHPExcel类 *初始化PHPExcel类
* @param $data array() * @param $data array()
* @param $fun function() * @param $fun function()
* return * return
*/ */
private static function initialize($data,$fun){ private static function initialize($data, $fun)
{
self::$PHPExcel = new \PHPExcel(); self::$PHPExcel = new \PHPExcel();
if ($fun !== null && is_callable($fun)) { if ($fun !== null && is_callable($fun)) {
self::$styleArray = $fun(); self::$styleArray = $fun();
@ -65,14 +68,17 @@ class PHPExcelService
if (!is_array($data)) exit(Json::fail('data 为数组')); if (!is_array($data)) exit(Json::fail('data 为数组'));
self::$data = $data; self::$data = $data;
} }
/** /**
*设置字体格式 *设置字体格式
* @param $title string 必选 * @param $title string 必选
* return string * return string
*/ */
public static function setUtf8($title){ public static function setUtf8($title)
{
return iconv('utf-8', 'gb2312', $title); return iconv('utf-8', 'gb2312', $title);
} }
/** /**
* *
* execl数据导出 * execl数据导出
@ -115,12 +121,14 @@ class PHPExcelService
return $this; return $this;
} }
/** /**
* 保存表格数据,并下载 * 保存表格数据,并下载
* @param * @param
* @return * @return
*/ */
public function ExcelSave(){ public function ExcelSave()
{
$objWriter = \PHPExcel_IOFactory::createWriter(self::$PHPExcel, 'Excel2007'); $objWriter = \PHPExcel_IOFactory::createWriter(self::$PHPExcel, 'Excel2007');
$filename = self::$title . '--' . time() . '.xlsx'; $filename = self::$title . '--' . time() . '.xlsx';
ob_end_clean(); ob_end_clean();
@ -152,6 +160,7 @@ class PHPExcelService
} }
return new self; return new self;
} }
/** /**
* 设置标题 * 设置标题
* @param $title string || array ['title'=>'','name'=>'','info'=>[]] * @param $title string || array ['title'=>'','name'=>'','info'=>[]]
@ -160,7 +169,8 @@ class PHPExcelService
* @param $funName function($style,$A,$A2) 自定义设置头部样式 * @param $funName function($style,$A,$A2) 自定义设置头部样式
* @return $this * @return $this
*/ */
public function setExcelTile($title='',$Name='',$info=[],$funName=null){ public function setExcelTile($title = '', $Name = '', $info = [], $funName = null)
{
//设置参数 //设置参数
if (is_array($title)) { if (is_array($title)) {
if (isset($title['title'])) $title = $title['title']; if (isset($title['title'])) $title = $title['title'];
@ -211,12 +221,14 @@ class PHPExcelService
return $this; return $this;
} }
/** /**
* 设置第二行标题内容 * 设置第二行标题内容
* @param $info array (['name'=>'','site'=>'','phone'=>123] || ['我是表名','我是地址','我是手机号码'] ) || string 自定义 * @param $info array (['name'=>'','site'=>'','phone'=>123] || ['我是表名','我是地址','我是手机号码'] ) || string 自定义
* @return string * @return string
*/ */
private static function setCellInfo($info){ private static function setCellInfo($info)
{
$content = ['操作者:', '导出日期:' . date('Y-m-d', time()), '地址:', '电话:']; $content = ['操作者:', '导出日期:' . date('Y-m-d', time()), '地址:', '电话:'];
if (is_array($info) && !empty($info)) { if (is_array($info) && !empty($info)) {
if (isset($info['name'])) { if (isset($info['name'])) {

View File

@ -10,8 +10,8 @@ namespace crmeb\services;
* @Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) * @Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
* @updated 2015-08-26 * @updated 2015-08-26
*/ */
class PHPTreeService{ class PHPTreeService
{
protected static $config = array( protected static $config = array(
/* 主键 */ /* 主键 */
'primary_key' => 'id', 'primary_key' => 'id',
@ -32,19 +32,22 @@ class PHPTreeService{
/* 层次暂存 */ /* 层次暂存 */
protected static $level = array(); protected static $level = array();
/** /**
* @name 生成树形结构 * @name 生成树形结构
* @param array 二维数组 * @param array 二维数组
* @return mixed 多维数组 * @return mixed 多维数组
*/ */
public static function makeTree($data,$options=array() ){ public static function makeTree($data, $options = array())
{
$dataset = self::buildData($data, $options); $dataset = self::buildData($data, $options);
$r = self::makeTreeCore(0, $dataset, 'normal'); $r = self::makeTreeCore(0, $dataset, 'normal');
return $r; return $r;
} }
/* 生成线性结构, 便于HTML输出, 参数同上 */ /* 生成线性结构, 便于HTML输出, 参数同上 */
public static function makeTreeForHtml($data,$options=array()){ public static function makeTreeForHtml($data, $options = array())
{
$dataset = self::buildData($data, $options); $dataset = self::buildData($data, $options);
$r = self::makeTreeCore(0, $dataset, 'linear'); $r = self::makeTreeCore(0, $dataset, 'linear');
@ -52,7 +55,8 @@ class PHPTreeService{
} }
/* 格式化数据, 私有方法 */ /* 格式化数据, 私有方法 */
private static function buildData($data,$options){ private static function buildData($data, $options)
{
$config = array_merge(self::$config, $options); $config = array_merge(self::$config, $options);
self::$config = $config; self::$config = $config;
extract($config); extract($config);
@ -71,16 +75,12 @@ class PHPTreeService{
private static function makeTreeCore($index, $data, $type = 'linear') private static function makeTreeCore($index, $data, $type = 'linear')
{ {
extract(self::$config); extract(self::$config);
foreach($data[$index] as $id=>$item) foreach ($data[$index] as $id => $item) {
{
if ($type == 'normal') { if ($type == 'normal') {
if(isset($data[$id])) if (isset($data[$id])) {
{
$item[$expanded_key] = self::$config['expanded']; $item[$expanded_key] = self::$config['expanded'];
$item[$children_key] = self::makeTreeCore($id, $data, $type); $item[$children_key] = self::makeTreeCore($id, $data, $type);
} } else {
else
{
$item[$leaf_key] = true; $item[$leaf_key] = true;
} }
$r[] = $item; $r[] = $item;

View File

@ -15,12 +15,16 @@ class QrcodeService
/** /**
* 获取临时二维码 单个 * 获取临时二维码 单个
* */ * */
public static function getTemporaryQrcode($type,$id){ public static function getTemporaryQrcode($type, $id)
{
return QrcodeModel::getTemporaryQrcode($type, $id)->toArray(); return QrcodeModel::getTemporaryQrcode($type, $id)->toArray();
}/** }
/**
* 获取永久二维码 单个 * 获取永久二维码 单个
* */ * */
public static function getForeverQrcode($type,$id){ public static function getForeverQrcode($type, $id)
{
return QrcodeModel::getForeverQrcode($type, $id)->toArray(); return QrcodeModel::getForeverQrcode($type, $id)->toArray();
} }

View File

@ -1,4 +1,5 @@
<?php <?php
namespace crmeb\services; namespace crmeb\services;
/** /**

View File

@ -20,13 +20,6 @@ class SystemConfigService
const CACHE_SYSTEM = 'system_config'; const CACHE_SYSTEM = 'system_config';
public static $ProtectedKey = [
'wechat_appid', 'wechat_appsecret', 'wechat_token', 'wechat_encodingaeskey', 'wechat_encode',
'pay_weixin_mchid', 'pay_weixin_client_cert', 'pay_weixin_client_key', 'pay_weixin_key', 'pay_weixin_open',
'routine_appId', 'routine_appsecret',
'pay_routine_mchid', 'pay_routine_key', 'pay_routine_client_cert', 'pay_routine_client_key', 'pay_weixin_open'
];
/** /**
* 初始化 * 初始化
*/ */

View File

@ -1,4 +1,5 @@
<?php <?php
namespace crmeb\services; namespace crmeb\services;
class UpgradeService extends FileService class UpgradeService extends FileService
@ -25,35 +26,45 @@ class UpgradeService extends FileService
protected static $Isauth = 'index.php/admin/server.upgrade_api/isauth.html'; protected static $Isauth = 'index.php/admin/server.upgrade_api/isauth.html';
//相隔付 //相隔付
private static $seperater = "{&&}"; private static $seperater = "{&&}";
//更新网址信息 //更新网址信息
public function snyweninfo($serverweb){ public function snyweninfo($serverweb)
{
return self::request_post(self::$UpdateWeBinfo, $serverweb); return self::request_post(self::$UpdateWeBinfo, $serverweb);
} }
//判断是否有权限 返回1有权限0无权限 //判断是否有权限 返回1有权限0无权限
public function isauth(){ public function isauth()
{
return self::request_post(self::$Isauth); return self::request_post(self::$Isauth);
} }
/* /*
*获取ip token 生成当前时间和过期时间 *获取ip token 生成当前时间和过期时间
* @param string ip * @param string ip
* @param int $valid_peroid 过期周期 15 * @param int $valid_peroid 过期周期 15
*/ */
public static function get_token($ip='',$valid_peroid=1296000){ public static function get_token($ip = '', $valid_peroid = 1296000)
{
$request = app('request'); $request = app('request');
if (empty($ip)) $ip = $request->ip(); if (empty($ip)) $ip = $request->ip();
$to_ken = $request->domain() . self::$seperater . $ip . self::$seperater . time() . self::$seperater . (time() + $valid_peroid) . self::$seperater; $to_ken = $request->domain() . self::$seperater . $ip . self::$seperater . time() . self::$seperater . (time() + $valid_peroid) . self::$seperater;
$token = self::enCode($to_ken); $token = self::enCode($to_ken);
return $token; return $token;
} }
private static function getRet($msg,$code=400){
private static function getRet($msg, $code = 400)
{
return ['msg' => $msg, 'code' => $code]; return ['msg' => $msg, 'code' => $code];
} }
/** /**
* *
* @param string $url * @param string $url
* @param array $post_data * @param array $post_data
*/ */
public static function start(){ public static function start()
{
$pach = app()->getRootPath() . 'version'; $pach = app()->getRootPath() . 'version';
$request = app('request'); $request = app('request');
if (!file_exists($pach)) return self::getRet($pach . '升级文件丢失,请联系管理员'); if (!file_exists($pach)) return self::getRet($pach . '升级文件丢失,请联系管理员');
@ -73,7 +84,9 @@ class UpgradeService extends FileService
} }
return self::getRet('获取失败'); return self::getRet('获取失败');
} }
public static function getVersion(){
public static function getVersion()
{
$pach = app()->getRootPath() . '.version'; $pach = app()->getRootPath() . '.version';
if (!file_exists($pach)) return self::getRet($pach . '升级文件丢失,请联系管理员'); if (!file_exists($pach)) return self::getRet($pach . '升级文件丢失,请联系管理员');
$version = @file($pach); $version = @file($pach);
@ -85,20 +98,21 @@ class UpgradeService extends FileService
} }
return self::getRet($arr, 200); return self::getRet($arr, 200);
} }
/** /**
* 模拟post进行url请求 * 模拟post进行url请求
* @param string $url * @param string $url
* @param array $post_data * @param array $post_data
*/ */
public static function request_post($url = '', $post_data = array()) { public static function request_post($url = '', $post_data = array())
{
if (strstr($url, 'http') === false) $url = self::$domain . $url; if (strstr($url, 'http') === false) $url = self::$domain . $url;
if (empty($url)) { if (empty($url)) {
return false; return false;
} }
if (!isset($post_data['token'])) $post_data['token'] = self::get_token(); if (!isset($post_data['token'])) $post_data['token'] = self::get_token();
$o = ""; $o = "";
foreach ( $post_data as $k => $v ) foreach ($post_data as $k => $v) {
{
$o .= "$k=" . urlencode($v) . "&"; $o .= "$k=" . urlencode($v) . "&";
} }
$post_data = substr($o, 0, -1); $post_data = substr($o, 0, -1);
@ -118,6 +132,7 @@ class UpgradeService extends FileService
} }
return $data; return $data;
} }
/** /**
* 验证远程文件是否存在 以及下载 * 验证远程文件是否存在 以及下载
* @param string $url 文件路径 * @param string $url 文件路径
@ -134,12 +149,10 @@ class UpgradeService extends FileService
$result = curl_exec($curl); $result = curl_exec($curl);
$found = false; $found = false;
// 如果请求没有发送失败 // 如果请求没有发送失败
if ($result !== false) if ($result !== false) {
{
// 再检查http响应码是否为200 // 再检查http响应码是否为200
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($statusCode == 200) if ($statusCode == 200) {
{
curl_close($curl); curl_close($curl);
$fileservice = new self; $fileservice = new self;
@ -154,13 +167,15 @@ class UpgradeService extends FileService
curl_close($curl); curl_close($curl);
return $found; return $found;
} }
/** /**
* 通用加密 * 通用加密
* @param String $string 需要加密的字串 * @param String $string 需要加密的字串
* @param String $skey 加密EKY * @param String $skey 加密EKY
* @return String * @return String
*/ */
private static function enCode($string = '', $skey = 'fb') { private static function enCode($string = '', $skey = 'fb')
{
$skey = array_reverse(str_split($skey)); $skey = array_reverse(str_split($skey));
$strArr = str_split(base64_encode($string)); $strArr = str_split(base64_encode($string));
$strCount = count($strArr); $strCount = count($strArr);
@ -169,12 +184,14 @@ class UpgradeService extends FileService
} }
return str_replace('=', 'O0O0O', join('', $strArr)); return str_replace('=', 'O0O0O', join('', $strArr));
} }
/** /**
* 去除回车去取空格去除换行去除tab * 去除回车去取空格去除换行去除tab
* @param String $str 需要去除的字串 * @param String $str 需要去除的字串
* @return String * @return String
*/ */
public static function replace($str){ public static function replace($str)
{
return trim(str_replace(array("\r", "\n", "\t"), '', $str)); return trim(str_replace(array("\r", "\n", "\t"), '', $str));
} }
} }

View File

@ -254,7 +254,8 @@ class UploadService
* @param bool $isData 是否真实获取图片信息 * @param bool $isData 是否真实获取图片信息
* @return array * @return array
*/ */
public static function getImageHeaders(string $url,$type = 1,$isData = true){ public static function getImageHeaders(string $url, $type = 1, $isData = true)
{
stream_context_set_default([ stream_context_set_default([
'ssl' => [ 'ssl' => [
'verify_peer' => false, 'verify_peer' => false,
@ -284,8 +285,7 @@ class UploadService
{ {
$file = request()->file($fileName); $file = request()->file($fileName);
if (!$file) return '上传文件不存在!'; if (!$file) return '上传文件不存在!';
if ($this->autoValidate) if ($this->autoValidate) {
{
try { try {
validate([$fileName => $this->imageValidate])->check([$fileName => $file]); validate([$fileName => $this->imageValidate])->check([$fileName => $file]);
} catch (ValidateException $e) { } catch (ValidateException $e) {
@ -421,8 +421,7 @@ class UploadService
if (strtolower($extension) == 'php' || !$extension) if (strtolower($extension) == 'php' || !$extension)
return self::setError('上传文件非法!'); return self::setError('上传文件非法!');
$file = request()->file($fileName); $file = request()->file($fileName);
if ($this->autoValidate) if ($this->autoValidate) {
{
try { try {
validate([$fileName => $this->imageValidate])->check([$fileName => $file]); validate([$fileName => $this->imageValidate])->check([$fileName => $file]);
} catch (ValidateException $e) { } catch (ValidateException $e) {

View File

@ -67,7 +67,8 @@ class UtilService
return $p; return $p;
} }
public static function encrypt($string, $operation = false, $key = '', $expiry = 0) { public static function encrypt($string, $operation = false, $key = '', $expiry = 0)
{
// 动态密匙长度,相同的明文会生成不同密文就是依靠动态密匙 // 动态密匙长度,相同的明文会生成不同密文就是依靠动态密匙
$ckey_length = 6; $ckey_length = 6;
@ -202,6 +203,7 @@ class UtilService
} }
return $list; return $list;
} }
/** /**
* 分级返回多维数组 * 分级返回多维数组
* @param $data * @param $data
@ -227,6 +229,7 @@ class UtilService
} }
/**分级返回下级所有分类ID /**分级返回下级所有分类ID
* @param $data * @param $data
* @param string $children * @param string $children
@ -293,7 +296,8 @@ class UtilService
* @param $card * @param $card
* @return bool * @return bool
*/ */
public static function setCard($card){ public static function setCard($card)
{
$city = [11 => "北京", 12 => "天津", 13 => "河北", 14 => "山西", 15 => "内蒙古", 21 => "辽宁", 22 => "吉林", 23 => "黑龙江 ", 31 => "上海", 32 => "江苏", 33 => "浙江", 34 => "安徽", 35 => "福建", 36 => "江西", 37 => "山东", 41 => "河南", 42 => "湖北 ", 43 => "湖南", 44 => "广东", 45 => "广西", 46 => "海南", 50 => "重庆", 51 => "四川", 52 => "贵州", 53 => "云南", 54 => "西藏 ", 61 => "陕西", 62 => "甘肃", 63 => "青海", 64 => "宁夏", 65 => "新疆", 71 => "台湾", 81 => "香港", 82 => "澳门", 91 => "国外 "]; $city = [11 => "北京", 12 => "天津", 13 => "河北", 14 => "山西", 15 => "内蒙古", 21 => "辽宁", 22 => "吉林", 23 => "黑龙江 ", 31 => "上海", 32 => "江苏", 33 => "浙江", 34 => "安徽", 35 => "福建", 36 => "江西", 37 => "山东", 41 => "河南", 42 => "湖北 ", 43 => "湖南", 44 => "广东", 45 => "广西", 46 => "海南", 50 => "重庆", 51 => "四川", 52 => "贵州", 53 => "云南", 54 => "西藏 ", 61 => "陕西", 62 => "甘肃", 63 => "青海", 64 => "宁夏", 65 => "新疆", 71 => "台湾", 81 => "香港", 82 => "澳门", 91 => "国外 "];
$tip = ""; $tip = "";
$match = "/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/"; $match = "/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/";
@ -316,8 +320,7 @@ class UtilService
$sum = 0; $sum = 0;
$ai = 0; $ai = 0;
$wi = 0; $wi = 0;
for ($i = 0; $i < 17; $i++) for ($i = 0; $i < 17; $i++) {
{
$ai = $card[$i]; $ai = $card[$i];
$wi = $factor[$i]; $wi = $factor[$i];
$sum += $ai * $wi; $sum += $ai * $wi;
@ -342,7 +345,8 @@ class UtilService
* @return array|bool|string * @return array|bool|string
* @throws \Exception * @throws \Exception
*/ */
public static function setShareMarketingPoster($data = array(), $path){ public static function setShareMarketingPoster($data = array(), $path)
{
$config = array( $config = array(
'text' => array( 'text' => array(
array( array(
@ -443,7 +447,8 @@ class UtilService
* @return array|bool|string * @return array|bool|string
* @throws \Exception * @throws \Exception
*/ */
public static function setSharePoster($config = array(), $path){ public static function setSharePoster($config = array(), $path)
{
$imageDefault = array( $imageDefault = array(
'left' => 0, 'left' => 0,
'top' => 0, 'top' => 0,
@ -544,8 +549,11 @@ class UtilService
public static function setHttpType($url, $type = 0) public static function setHttpType($url, $type = 0)
{ {
$domainTop = substr($url, 0, 5); $domainTop = substr($url, 0, 5);
if($type){ if($domainTop == 'https') $url = 'http'.substr($url,5,strlen($url)); } if ($type) {
else{ if($domainTop != 'https') $url = 'https:'.substr($url,5,strlen($url)); } if ($domainTop == 'https') $url = 'http' . substr($url, 5, strlen($url));
} else {
if ($domainTop != 'https') $url = 'https:' . substr($url, 5, strlen($url));
}
return $url; return $url;
} }
@ -673,7 +681,8 @@ class UtilService
* @param string $avatar * @param string $avatar
* @return bool|string * @return bool|string
*/ */
public static function setImageBase64($avatar = '',$timeout=9){ public static function setImageBase64($avatar = '', $timeout = 9)
{
try { try {
$url = parse_url($avatar); $url = parse_url($avatar);
$url = $url['host']; $url = $url['host'];

View File

@ -593,7 +593,6 @@ class WechatService
$staff = self::staffService(); $staff = self::staffService();
$staff = is_callable($message) ? $staff->message($message()) : $staff->message($message); $staff = is_callable($message) ? $staff->message($message()) : $staff->message($message);
$res = $staff->to($to)->send(); $res = $staff->to($to)->send();
HookService::afterListen('wechat_staff_to',compact('to','message'),$res);
return $res; return $res;
} }

View File

@ -58,7 +58,8 @@ class WechatTemplateService implements ProviderInterface
//砍价成功 //砍价成功
const BARGAIN_SUCCESS = 'OPENTM410292733'; const BARGAIN_SUCCESS = 'OPENTM410292733';
public static function getConstants($code='') { public static function getConstants($code = '')
{
$oClass = new \ReflectionClass(__CLASS__); $oClass = new \ReflectionClass(__CLASS__);
$stants = $oClass->getConstants(); $stants = $oClass->getConstants();
if ($code) return isset($stants[$code]) ? $stants[$code] : ''; if ($code) return isset($stants[$code]) ? $stants[$code] : '';

View File

@ -3,13 +3,17 @@
namespace crmeb\services; namespace crmeb\services;
use app\models\system\Cache as CacheModel; use app\models\system\Cache as CacheModel;
use crmeb\interfaces\ProviderInterface;
use crmeb\traits\LogicTrait;
/** /**
* Class YLYService * Class YLYService
* @package crmeb\services * @package crmeb\services
*/ */
class YLYService extends HttpService class YLYService extends HttpService implements ProviderInterface
{ {
use LogicTrait;
/** /**
* 开发者创建的应用的应用ID * 开发者创建的应用的应用ID
* @var string * @var string
@ -58,11 +62,11 @@ class YLYService extends HttpService
*/ */
protected $apiUrl = 'https://open-api.10ss.net/'; protected $apiUrl = 'https://open-api.10ss.net/';
/**
* 本类实例化句柄 public function register($congig = [])
* @var {
*/
protected static $instance; }
/** /**
* YLYService constructor. * YLYService constructor.
@ -77,20 +81,11 @@ class YLYService extends HttpService
$this->getAccessToken(); $this->getAccessToken();
} }
/**
* 实例化本类
* @return YLYService
*/
public static function getInstance()
{
if(is_null(self::$instance)) self::$instance = new self();
return self::$instance;
}
/** /**
* 获取AccessToken * 获取AccessToken
* */ * */
protected function getAccessToken(){ protected function getAccessToken()
{
$token = CacheModel::getDbCache('YLY_access_token'); $token = CacheModel::getDbCache('YLY_access_token');
if (!$token) { if (!$token) {
$request = self::postRequest($this->apiUrl . 'oauth/oauth', [ $request = self::postRequest($this->apiUrl . 'oauth/oauth', [
@ -116,7 +111,8 @@ class YLYService extends HttpService
* 生成UUID4 * 生成UUID4
* @return string * @return string
*/ */
protected function createUuid() { protected function createUuid()
{
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff), return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff),
mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)); mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
} }
@ -169,7 +165,8 @@ class YLYService extends HttpService
* @param array $product 订单详情 * @param array $product 订单详情
* @return $this * @return $this
*/ */
public function setContent(string $name,array $orderInfo,array $product){ public function setContent(string $name, array $orderInfo, array $product)
{
$timeYmd = date('Y-m-d', time()); $timeYmd = date('Y-m-d', time());
$timeHis = date('H:i:s', time()); $timeHis = date('H:i:s', time());
$goodsStr = '<table><tr><td>商品名称</td><td>数量</td><td>单价</td><td>金额</td></tr>'; $goodsStr = '<table><tr><td>商品名称</td><td>数量</td><td>单价</td><td>金额</td></tr>';
@ -212,8 +209,8 @@ CONTENT;
return $this->content; return $this->content;
} }
protected function __clone() protected function __destruct()
{ {
// TODO: Implement __clone() method. // TODO: Implement __destruct() method.
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
namespace crmeb\services\storage; namespace crmeb\services\storage;
use crmeb\services\SystemConfigService; use crmeb\services\SystemConfigService;
@ -32,7 +33,8 @@ class COS
* @return null|Client * @return null|Client
* @throws \Exception * @throws \Exception
*/ */
protected static function autoInfo(){ protected static function autoInfo()
{
if (($storageRegion = Cache::get('storageRegion')) && ($storageName = Cache::get('storageName')) && ($uploadUrl = Cache::get('uploadUrl')) && ($accessKey = Cache::get('accessKey')) && ($secretKey = Cache::get('secretKey'))) { if (($storageRegion = Cache::get('storageRegion')) && ($storageName = Cache::get('storageName')) && ($uploadUrl = Cache::get('uploadUrl')) && ($accessKey = Cache::get('accessKey')) && ($secretKey = Cache::get('secretKey'))) {
self::$accessKey = $accessKey; self::$accessKey = $accessKey;
self::$secretKey = $secretKey; self::$secretKey = $secretKey;
@ -71,7 +73,8 @@ class COS
* @param string $filename * @param string $filename
* @return string * @return string
*/ */
public static function uploadImage($filename = 'image'){ public static function uploadImage($filename = 'image')
{
$request = app('request'); $request = app('request');
$file = $request->file($filename); $file = $request->file($filename);
$filePath = $file->getRealPath(); $filePath = $file->getRealPath();
@ -95,7 +98,8 @@ class COS
* @param $content * @param $content
* @return string * @return string
*/ */
public static function uploadImageStream($key, $content){ public static function uploadImageStream($key, $content)
{
try { try {
self::autoInfo(); self::autoInfo();
return [self::$uploadUrl . $key, self::$auth->putObject([ return [self::$uploadUrl . $key, self::$auth->putObject([
@ -113,7 +117,8 @@ class COS
* @param $key * @param $key
* @return mixed * @return mixed
*/ */
public static function delete($key){ public static function delete($key)
{
try { try {
self::autoInfo(); self::autoInfo();
return self::$auth->deleteObject([ return self::$auth->deleteObject([

View File

@ -1,4 +1,5 @@
<?php <?php
namespace crmeb\services\storage; namespace crmeb\services\storage;
use crmeb\services\SystemConfigService; use crmeb\services\SystemConfigService;
@ -30,7 +31,8 @@ class OSS
* @return null|OssClient * @return null|OssClient
* @throws \OSS\Core\OssException * @throws \OSS\Core\OssException
*/ */
protected static function autoInfo(){ protected static function autoInfo()
{
if (($storageName = Cache::get('storageName')) && ($uploadUrl = Cache::get('uploadUrl')) && ($accessKey = Cache::get('accessKey')) && ($secretKey = Cache::get('secretKey'))) { if (($storageName = Cache::get('storageName')) && ($uploadUrl = Cache::get('uploadUrl')) && ($accessKey = Cache::get('accessKey')) && ($secretKey = Cache::get('secretKey'))) {
self::$accessKey = $accessKey; self::$accessKey = $accessKey;
self::$secretKey = $secretKey; self::$secretKey = $secretKey;
@ -61,7 +63,8 @@ class OSS
* @param string $filename * @param string $filename
* @return string * @return string
*/ */
public static function uploadImage($filename = 'image'){ public static function uploadImage($filename = 'image')
{
$request = app('request'); $request = app('request');
$file = $request->file($filename); $file = $request->file($filename);
$filePath = $file->getRealPath(); $filePath = $file->getRealPath();
@ -81,7 +84,8 @@ class OSS
* @param $content * @param $content
* @return string * @return string
*/ */
public static function uploadImageStream($key, $content){ public static function uploadImageStream($key, $content)
{
try { try {
self::autoInfo(); self::autoInfo();
return self::$auth->putObject(self::$storageName, $key, $content); return self::$auth->putObject(self::$storageName, $key, $content);
@ -95,7 +99,8 @@ class OSS
* @param $key * @param $key
* @return mixed * @return mixed
*/ */
public static function delete($key){ public static function delete($key)
{
try { try {
self::autoInfo(); self::autoInfo();
return self::$auth->deleteObject(self::$storageName, $key); return self::$auth->deleteObject(self::$storageName, $key);

View File

@ -1,4 +1,5 @@
<?php <?php
namespace crmeb\services\storage; namespace crmeb\services\storage;
use crmeb\services\SystemConfigService; use crmeb\services\SystemConfigService;
@ -28,13 +29,13 @@ class Qiniu
protected static $storageName; protected static $storageName;
/** /**
* TODO 初始化 * TODO 初始化
* @return null|Auth * @return null|Auth
* @throws \Exception * @throws \Exception
*/ */
protected static function autoInfo(){ protected static function autoInfo()
{
if (($storageName = Cache::get('storageName')) && ($uploadUrl = Cache::get('uploadUrl')) && ($accessKey = Cache::get('accessKey')) && ($secretKey = Cache::get('secretKey'))) { if (($storageName = Cache::get('storageName')) && ($uploadUrl = Cache::get('uploadUrl')) && ($accessKey = Cache::get('accessKey')) && ($secretKey = Cache::get('secretKey'))) {
self::$accessKey = $accessKey; self::$accessKey = $accessKey;
self::$secretKey = $secretKey; self::$secretKey = $secretKey;
@ -61,7 +62,8 @@ class Qiniu
* TODO 获取上传图片视频token和domain * TODO 获取上传图片视频token和domain
* @return array * @return array
*/ */
public static function getToKenAndDomainI(){ public static function getToKenAndDomainI()
{
$token = self::autoInfo()->uploadToken(self::$storageName); $token = self::autoInfo()->uploadToken(self::$storageName);
$domain = self::$uploadUrl; $domain = self::$uploadUrl;
$fileName = md5(rand(1000, 9999) . date('YmdHis') . rand(0, 9999)); $fileName = md5(rand(1000, 9999) . date('YmdHis') . rand(0, 9999));
@ -74,7 +76,8 @@ class Qiniu
* @return array * @return array
* @throws \Exception * @throws \Exception
*/ */
public static function uploadImage($filename = 'image'){ public static function uploadImage($filename = 'image')
{
$request = app('request'); $request = app('request');
$file = $request->file($filename); $file = $request->file($filename);
$filePath = $file->getRealPath(); $filePath = $file->getRealPath();
@ -96,7 +99,8 @@ class Qiniu
* @return array|string * @return array|string
* @throws \Exception * @throws \Exception
*/ */
public static function uploadImageStream($key, $content){ public static function uploadImageStream($key, $content)
{
$token = self::autoInfo()->uploadToken(self::$storageName, $key); $token = self::autoInfo()->uploadToken(self::$storageName, $key);
try { try {
$uploadMgr = new UploadManager(); $uploadMgr = new UploadManager();
@ -114,7 +118,8 @@ class Qiniu
* @param int $time 图片链接最后的访问时间 * @param int $time 图片链接最后的访问时间
* @return array * @return array
*/ */
public static function imageUrl($key, $type = '', $imageUrl = '', $time = 0){ public static function imageUrl($key, $type = '', $imageUrl = '', $time = 0)
{
return ['code' => 200, 'name' => $key, 'dir' => self::$uploadUrl . $key, 'thumb_path' => self::$uploadUrl . $key, 'time' => time()]; return ['code' => 200, 'name' => $key, 'dir' => self::$uploadUrl . $key, 'thumb_path' => self::$uploadUrl . $key, 'time' => time()];
// $imageValue = !strlen(trim($type)) ? self::$uploadUrl.$key : self::$uploadUrl.$key.self::getType($type); // $imageValue = !strlen(trim($type)) ? self::$uploadUrl.$key : self::$uploadUrl.$key.self::getType($type);
// if($time > time() && !strlen(trim($imageUrl))) return ['code'=>100,'dir'=>$imageUrl,'thumb_path'=>$imageUrl,'time'=>$time]; // if($time > time() && !strlen(trim($imageUrl))) return ['code'=>100,'dir'=>$imageUrl,'thumb_path'=>$imageUrl,'time'=>$time];
@ -127,7 +132,8 @@ class Qiniu
* @param $imageType * @param $imageType
* @return string * @return string
*/ */
public static function getType($imageType){ public static function getType($imageType)
{
$type = ''; $type = '';
switch ($imageType) { switch ($imageType) {
case "8x6": case "8x6":
@ -143,7 +149,8 @@ class Qiniu
* @param $bucket * @param $bucket
* @return mixed * @return mixed
*/ */
public static function delete($key){ public static function delete($key)
{
$bucketManager = new BucketManager(self::autoInfo(), new Config()); $bucketManager = new BucketManager(self::autoInfo(), new Config());
return $bucketManager->delete(self::$storageName, $key); return $bucketManager->delete(self::$storageName, $key);
} }

View File

@ -1,7 +1,9 @@
<?php <?php
namespace crmeb\subscribes; namespace crmeb\subscribes;
use think\facade\Db; use think\facade\Db;
/** /**
* 素材消息事件 * 素材消息事件
* Class MaterialSubscribe * Class MaterialSubscribe

View File

@ -1,4 +1,5 @@
<?php <?php
namespace crmeb\subscribes; namespace crmeb\subscribes;
use app\admin\model\wechat\WechatMessage; use app\admin\model\wechat\WechatMessage;
@ -42,7 +43,8 @@ class MessageSubscribe
$data['reflectnum'] = UserExtract::where('status', 0)->count();//提现 $data['reflectnum'] = UserExtract::where('status', 0)->count();//提现
$data['msgcount'] = intval($data['ordernum']) + intval($data['inventory']) + intval($data['commentnum']) + intval($data['reflectnum']); $data['msgcount'] = intval($data['ordernum']) + intval($data['inventory']) + intval($data['commentnum']) + intval($data['reflectnum']);
ChannelService::instance()->send('ADMIN_NEW_PUSH', $data); ChannelService::instance()->send('ADMIN_NEW_PUSH', $data);
}catch (\Exception $e){} } catch (\Exception $e) {
}
} }
/** /**
@ -101,6 +103,7 @@ class MessageSubscribe
Log::error('短信下发事件发生系统错误,错误原因:' . $e->getMessage()); Log::error('短信下发事件发生系统错误,错误原因:' . $e->getMessage());
} }
} }
/** /**
* 发送短信 * 发送短信
* @param boolean $switch 发送开关 * @param boolean $switch 发送开关
@ -228,6 +231,7 @@ class MessageSubscribe
$this->send(true, $userInfo->phone, compact('admin_name', 'order_id'), 'ADMIN_RETURN_GOODS_CODE', '用户退款管理员发送短信通知失败,订单号为:' . $storeInfo->order_id); $this->send(true, $userInfo->phone, compact('admin_name', 'order_id'), 'ADMIN_RETURN_GOODS_CODE', '用户退款管理员发送短信通知失败,订单号为:' . $storeInfo->order_id);
}); });
} }
/** /**
* 提取管理员权限 * 提取管理员权限
* @param callable $callable 回调函数 * @param callable $callable 回调函数

View File

@ -136,6 +136,7 @@ class OrderSubscribe
try { try {
//向后台发送新订单消息 //向后台发送新订单消息
ChannelService::instance()->send('NEW_ORDER', ['order_id' => $order['order_id']]); ChannelService::instance()->send('NEW_ORDER', ['order_id' => $order['order_id']]);
}catch (\Throwable $e){} } catch (\Throwable $e) {
}
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
namespace crmeb\subscribes; namespace crmeb\subscribes;
/** /**
@ -30,7 +31,8 @@ class ProductSubscribe
* 用户操作产品添加事件 用户点赞产品 用户收藏产品 * 用户操作产品添加事件 用户点赞产品 用户收藏产品
* @param $event * @param $event
*/ */
public function onStoreProductUserOperationConfirmAfter($event){ public function onStoreProductUserOperationConfirmAfter($event)
{
list($category, $productId, $relationType, $uid) = $event; list($category, $productId, $relationType, $uid) = $event;
//$category 产品类型 //$category 产品类型
//$productId 产品编号 //$productId 产品编号
@ -42,7 +44,8 @@ class ProductSubscribe
* 用户操作产品取消事件 用户取消点赞产品 用户取消收藏产品 * 用户操作产品取消事件 用户取消点赞产品 用户取消收藏产品
* @param $event * @param $event
*/ */
public function onStoreProductUserOperationCancelAfter($event){ public function onStoreProductUserOperationCancelAfter($event)
{
list($category, $productId, $relationType, $uid) = $event; list($category, $productId, $relationType, $uid) = $event;
//$category 产品类型 //$category 产品类型
//$productId 产品编号 //$productId 产品编号

View File

@ -1,8 +1,10 @@
<?php <?php
namespace crmeb\subscribes; namespace crmeb\subscribes;
use app\admin\model\system\SystemAdmin; use app\admin\model\system\SystemAdmin;
use app\admin\model\system\SystemLog; use app\admin\model\system\SystemLog;
/** /**
* 后台系统事件 * 后台系统事件
* Class SystemSubscribe * Class SystemSubscribe

View File

@ -1,4 +1,5 @@
<?php <?php
namespace crmeb\subscribes; namespace crmeb\subscribes;
use app\admin\model\system\SystemAttachment; use app\admin\model\system\SystemAttachment;
@ -26,6 +27,7 @@ class TaskSubscribe
public function onTask_2() public function onTask_2()
{ {
} }
/** /**
* 6秒钟执行的方法 * 6秒钟执行的方法
*/ */

View File

@ -72,10 +72,8 @@ 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);
} }
} }
@ -90,7 +88,7 @@ trait LogicTrait
{ {
$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;
@ -109,6 +107,7 @@ trait LogicTrait
self::$instance = new self(); self::$instance = new self();
self::$instance->setConfig($config); self::$instance->setConfig($config);
self::$instance->registerProviders(); self::$instance->registerProviders();
if (method_exists(self::$instance, 'bool'))
self::$instance->bool(); self::$instance->bool();
} }
return self::$instance; return self::$instance;
@ -152,8 +151,7 @@ trait LogicTrait
$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])) && isset($this->propsRule[$attribute])) {
{
$propsRuleValeu = $this->propsRule[$attribute]; $propsRuleValeu = $this->propsRule[$attribute];
$type = $propsRuleValeu[1] ?? 'string'; $type = $propsRuleValeu[1] ?? 'string';
$callable = $propsRuleValeu[2] ?? null; $callable = $propsRuleValeu[2] ?? null;