1
This commit is contained in:
parent
36b4c5eac5
commit
f55e4a9550
240
app/common.php
240
app/common.php
@ -2,16 +2,18 @@
|
|||||||
/**
|
/**
|
||||||
* 应用公共函数库文件
|
* 应用公共函数库文件
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use think\facade\Request;
|
use think\facade\Request;
|
||||||
use hema\wechat\Driver as Wechat;
|
use hema\wechat\Driver as Wechat;
|
||||||
use app\common\model\User as UserModel;
|
use app\common\model\User as UserModel;
|
||||||
use app\common\model\Setting as SettingModel;
|
use app\common\model\Setting as SettingModel;
|
||||||
use app\common\model\food\ShopClerk as ShopClerkModel;
|
use app\common\model\food\ShopClerk as ShopClerkModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成数字验证码
|
* 生成数字验证码
|
||||||
*/
|
*/
|
||||||
if (!function_exists('is_json')) {
|
if (!function_exists('is_json')) {
|
||||||
function is_json($string)
|
function is_json($string)
|
||||||
{
|
{
|
||||||
json_decode($string);
|
json_decode($string);
|
||||||
return (json_last_error() == JSON_ERROR_NONE);
|
return (json_last_error() == JSON_ERROR_NONE);
|
||||||
@ -21,11 +23,11 @@ if (!function_exists('is_json')) {
|
|||||||
* 生成数字验证码
|
* 生成数字验证码
|
||||||
*/
|
*/
|
||||||
if (!function_exists('get_captcha')) {
|
if (!function_exists('get_captcha')) {
|
||||||
function get_captcha($length=4)
|
function get_captcha($length = 4)
|
||||||
{
|
{
|
||||||
$str = '';
|
$str = '';
|
||||||
for($n=0;$n<$length;$n++){
|
for ($n = 0; $n < $length; $n++) {
|
||||||
$str .= (string)rand(0,9);
|
$str .= (string)rand(0, 9);
|
||||||
}
|
}
|
||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
@ -34,16 +36,16 @@ if (!function_exists('get_captcha')) {
|
|||||||
* json_encode
|
* json_encode
|
||||||
*/
|
*/
|
||||||
if (!function_exists('hema_json')) {
|
if (!function_exists('hema_json')) {
|
||||||
function hema_json($data)
|
function hema_json($data)
|
||||||
{
|
{
|
||||||
return json_encode($data,JSON_UNESCAPED_UNICODE);
|
return json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 验证手机号是否正确
|
* 验证手机号是否正确
|
||||||
*/
|
*/
|
||||||
if (!function_exists('is_phone')) {
|
if (!function_exists('is_phone')) {
|
||||||
function is_phone($phone)
|
function is_phone($phone)
|
||||||
{
|
{
|
||||||
if (!is_numeric($phone)) {
|
if (!is_numeric($phone)) {
|
||||||
return false;
|
return false;
|
||||||
@ -88,6 +90,7 @@ function base_url()
|
|||||||
}
|
}
|
||||||
return $baseUrl;
|
return $baseUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前域名
|
* 获取当前域名
|
||||||
*/
|
*/
|
||||||
@ -96,6 +99,7 @@ function domain()
|
|||||||
$request = Request::instance();
|
$request = Request::instance();
|
||||||
return $request->host();
|
return $request->host();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前uploads目录访问地址
|
* 获取当前uploads目录访问地址
|
||||||
*/
|
*/
|
||||||
@ -103,6 +107,7 @@ function uploads_url()
|
|||||||
{
|
{
|
||||||
return base_url() . 'uploads/';
|
return base_url() . 'uploads/';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前的应用名称
|
* 获取当前的应用名称
|
||||||
*/
|
*/
|
||||||
@ -110,6 +115,7 @@ function app_name()
|
|||||||
{
|
{
|
||||||
return app('http')->getName();
|
return app('http')->getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取web根目录
|
* 获取web根目录
|
||||||
*/
|
*/
|
||||||
@ -122,6 +128,7 @@ function web_path()
|
|||||||
}
|
}
|
||||||
return $webPath;
|
return $webPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前url的子目录路径
|
* 获取当前url的子目录路径
|
||||||
*/
|
*/
|
||||||
@ -135,32 +142,34 @@ function root_url()
|
|||||||
}
|
}
|
||||||
return $rootUrl;
|
return $rootUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清空缓存目录
|
* 清空缓存目录
|
||||||
*/
|
*/
|
||||||
function deldir($path)
|
function deldir($path)
|
||||||
{
|
{
|
||||||
//如果是目录则继续
|
//如果是目录则继续
|
||||||
if(is_dir($path)){
|
if (is_dir($path)) {
|
||||||
//扫描一个文件夹内的所有文件夹和文件并返回数组
|
//扫描一个文件夹内的所有文件夹和文件并返回数组
|
||||||
$p = scandir($path);
|
$p = scandir($path);
|
||||||
foreach($p as $val){
|
foreach ($p as $val) {
|
||||||
//排除目录中的.和..
|
//排除目录中的.和..
|
||||||
if($val !="." && $val !=".."){
|
if ($val != "." && $val != "..") {
|
||||||
//如果是目录则递归子目录,继续操作
|
//如果是目录则递归子目录,继续操作
|
||||||
if(is_dir($path.$val)){
|
if (is_dir($path . $val)) {
|
||||||
//子目录中操作删除文件夹和文件
|
//子目录中操作删除文件夹和文件
|
||||||
deldir($path.$val.'/');
|
deldir($path . $val . '/');
|
||||||
//目录清空后删除空文件夹
|
//目录清空后删除空文件夹
|
||||||
@rmdir($path.$val.'/');
|
@rmdir($path . $val . '/');
|
||||||
}else{
|
} else {
|
||||||
//如果是文件直接删除
|
//如果是文件直接删除
|
||||||
unlink($path.$val);
|
unlink($path . $val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下划线转驼峰
|
* 下划线转驼峰
|
||||||
*/
|
*/
|
||||||
@ -169,6 +178,7 @@ function camelize($uncamelized_words, $separator = '_')
|
|||||||
$uncamelized_words = $separator . str_replace($separator, " ", strtolower($uncamelized_words));
|
$uncamelized_words = $separator . str_replace($separator, " ", strtolower($uncamelized_words));
|
||||||
return ltrim(str_replace(" ", "", ucwords($uncamelized_words)), $separator);
|
return ltrim(str_replace(" ", "", ucwords($uncamelized_words)), $separator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 驼峰转下划线
|
* 驼峰转下划线
|
||||||
*/
|
*/
|
||||||
@ -176,6 +186,7 @@ function uncamelize($camelCaps, $separator = '_')
|
|||||||
{
|
{
|
||||||
return strtolower(preg_replace('/([a-z])([A-Z])/', "$1" . $separator . "$2", $camelCaps));
|
return strtolower(preg_replace('/([a-z])([A-Z])/', "$1" . $separator . "$2", $camelCaps));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 隐藏手机号中间四位 13012345678 -> 130****5678
|
* 隐藏手机号中间四位 13012345678 -> 130****5678
|
||||||
* @param string $phone 手机号
|
* @param string $phone 手机号
|
||||||
@ -222,7 +233,7 @@ if (!function_exists('format_time')) {
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 将时间戳转换为日期时间
|
* 将时间戳转换为日期时间
|
||||||
* @param int $time 时间戳
|
* @param int $time 时间戳
|
||||||
* @param string $format 日期时间格式
|
* @param string $format 日期时间格式
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@ -290,12 +301,12 @@ if (!function_exists('convert_left_slash')) {
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 将xml转为array
|
* 将xml转为array
|
||||||
*/
|
*/
|
||||||
if (!function_exists('_xml_to_arr')) {
|
if (!function_exists('_xml_to_arr')) {
|
||||||
function _xml_to_arr($xml)
|
function _xml_to_arr($xml)
|
||||||
{
|
{
|
||||||
$res = @simplexml_load_string ( $xml,NULL, LIBXML_NOCDATA );
|
$res = @simplexml_load_string($xml, NULL, LIBXML_NOCDATA);
|
||||||
$res = json_decode ( json_encode ( $res), true );
|
$res = json_decode(json_encode($res), true);
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -320,6 +331,7 @@ function array_merge_multiple($array1, $array2)
|
|||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断是否为自定义索引数组
|
* 判断是否为自定义索引数组
|
||||||
*/
|
*/
|
||||||
@ -336,13 +348,13 @@ if (!function_exists('is_assoc')) {
|
|||||||
if (!function_exists('arr_sort')) {
|
if (!function_exists('arr_sort')) {
|
||||||
function arr_sort(array $data, string $field, string $order = 'desc')
|
function arr_sort(array $data, string $field, string $order = 'desc')
|
||||||
{
|
{
|
||||||
foreach($data as $val){
|
foreach ($data as $val) {
|
||||||
$key_arrays[]=$val[$field];
|
$key_arrays[] = $val[$field];
|
||||||
}
|
}
|
||||||
if($order == 'desc'){
|
if ($order == 'desc') {
|
||||||
array_multisort($key_arrays,SORT_DESC,SORT_NUMERIC,$data);
|
array_multisort($key_arrays, SORT_DESC, SORT_NUMERIC, $data);
|
||||||
}else{
|
} else {
|
||||||
array_multisort($key_arrays,SORT_ASC,SORT_NUMERIC,$data);
|
array_multisort($key_arrays, SORT_ASC, SORT_NUMERIC, $data);
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
@ -365,9 +377,9 @@ if (!function_exists('array_sort')) {
|
|||||||
}
|
}
|
||||||
reset($key_value);
|
reset($key_value);
|
||||||
foreach ($key_value as $k => $v) {
|
foreach ($key_value as $k => $v) {
|
||||||
if(is_int($k)){
|
if (is_int($k)) {
|
||||||
$new_array[] = $arr[$k];
|
$new_array[] = $arr[$k];
|
||||||
}else{
|
} else {
|
||||||
$new_array[$k] = $arr[$k];
|
$new_array[$k] = $arr[$k];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -380,26 +392,23 @@ if (!function_exists('array_sort')) {
|
|||||||
*keyid 需要判断是否重复的项目
|
*keyid 需要判断是否重复的项目
|
||||||
*/
|
*/
|
||||||
if (!function_exists('array_repeat')) {
|
if (!function_exists('array_repeat')) {
|
||||||
function array_repeat($array,$keyid)
|
function array_repeat($array, $keyid)
|
||||||
{
|
{
|
||||||
$array =array_values($array);
|
$array = array_values($array);
|
||||||
//提取需要判断的项目变成一维数组
|
//提取需要判断的项目变成一维数组
|
||||||
$a = array_tq($array,$keyid);
|
$a = array_tq($array, $keyid);
|
||||||
|
|
||||||
//去除一维数组重复值
|
//去除一维数组重复值
|
||||||
$a =array_unique($a);
|
$a = array_unique($a);
|
||||||
//提取二维数组项目值
|
//提取二维数组项目值
|
||||||
foreach($array[0] AS$key=>$value)
|
foreach ($array[0] AS $key => $value) {
|
||||||
{
|
$akey[] = $key;
|
||||||
$akey[] =$key;
|
|
||||||
}
|
}
|
||||||
//重新拼接二维数组
|
//重新拼接二维数组
|
||||||
foreach($akey AS$key=>$value)
|
foreach ($akey AS $key => $value) {
|
||||||
{
|
$b = array_tq($array, $value);
|
||||||
$b = array_tq($array,$value);
|
foreach ($a AS $key2 => $value2) {
|
||||||
foreach($a AS$key2=>$value2)
|
$c[$key2][$value] = $b[$key2];
|
||||||
{
|
|
||||||
$c[$key2][$value] =$b[$key2];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $c;
|
return $c;
|
||||||
@ -407,10 +416,9 @@ if (!function_exists('array_repeat')) {
|
|||||||
}
|
}
|
||||||
//提取二维数组项目
|
//提取二维数组项目
|
||||||
if (!function_exists('array_tq')) {
|
if (!function_exists('array_tq')) {
|
||||||
function array_tq($array, $aval="")
|
function array_tq($array, $aval = "")
|
||||||
{
|
{
|
||||||
foreach($array AS $key => $value)
|
foreach ($array AS $key => $value) {
|
||||||
{
|
|
||||||
$result[] = $value[$aval];
|
$result[] = $value[$aval];
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
@ -419,29 +427,29 @@ if (!function_exists('array_tq')) {
|
|||||||
/**
|
/**
|
||||||
* POST请求
|
* POST请求
|
||||||
* @param [type] $url [description]
|
* @param [type] $url [description]
|
||||||
* @param array $data [description]
|
* @param array $data [description]
|
||||||
* @param array $headers [description]
|
* @param array $headers [description]
|
||||||
* @return [type] [description]
|
* @return [type] [description]
|
||||||
*/
|
*/
|
||||||
if (!function_exists('http_post')) {
|
if (!function_exists('http_post')) {
|
||||||
function http_post($url,$data = array(),$headers=array())
|
function http_post($url, $data = array(), $headers = array())
|
||||||
{
|
{
|
||||||
$curl = curl_init();
|
$curl = curl_init();
|
||||||
if( count($headers) >= 1 ){
|
if (count($headers) >= 1) {
|
||||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||||
}
|
}
|
||||||
curl_setopt($curl, CURLOPT_URL, $url);
|
curl_setopt($curl, CURLOPT_URL, $url);
|
||||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||||||
|
|
||||||
if (count($data) >= 1 AND !isset($data['media'])){
|
if (count($data) >= 1 AND !isset($data['media'])) {
|
||||||
$data = json_encode($data,JSON_UNESCAPED_UNICODE);
|
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||||
}elseif(count($data) == 0){
|
} elseif (count($data) == 0) {
|
||||||
$data = '{}';
|
$data = '{}';
|
||||||
}
|
}
|
||||||
curl_setopt($curl, CURLOPT_POST, 1);
|
curl_setopt($curl, CURLOPT_POST, 1);
|
||||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||||
|
|
||||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||||
$output = curl_exec($curl);
|
$output = curl_exec($curl);
|
||||||
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||||
@ -515,10 +523,10 @@ if (!function_exists('get_guid_v4')) {
|
|||||||
* 商户管理员 - 账户资金变动提醒 - 公众号
|
* 商户管理员 - 账户资金变动提醒 - 公众号
|
||||||
*/
|
*/
|
||||||
if (!function_exists('sand_account_change_msg')) {
|
if (!function_exists('sand_account_change_msg')) {
|
||||||
function sand_account_change_msg($title,$pay,$surplus,$user_id,$applet_id = 0)
|
function sand_account_change_msg($title, $pay, $surplus, $user_id, $applet_id = 0)
|
||||||
{
|
{
|
||||||
$webtplmsg = SettingModel::getItem('webtplmsg',$applet_id); //获取模板消息编号
|
$webtplmsg = SettingModel::getItem('webtplmsg', $applet_id); //获取模板消息编号
|
||||||
if(empty($webtplmsg['balance'])){
|
if (empty($webtplmsg['balance'])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
$foodhelp = get_addons_config('foodhelp'); //获取商家助手小程序
|
$foodhelp = get_addons_config('foodhelp'); //获取商家助手小程序
|
||||||
@ -539,15 +547,15 @@ if (!function_exists('sand_account_change_msg')) {
|
|||||||
'color' => '#173177'
|
'color' => '#173177'
|
||||||
],
|
],
|
||||||
'keyword2' => [
|
'keyword2' => [
|
||||||
'value' => '¥'.$pay.'元',//交易金额
|
'value' => '¥' . $pay . '元',//交易金额
|
||||||
'color' => '#173177'
|
'color' => '#173177'
|
||||||
],
|
],
|
||||||
'keyword3' => [
|
'keyword3' => [
|
||||||
'value' => date('Y/m/d H:i:s',time()),//交易时间
|
'value' => date('Y/m/d H:i:s', time()),//交易时间
|
||||||
'color' => '#173177'
|
'color' => '#173177'
|
||||||
],
|
],
|
||||||
'keyword4' => [
|
'keyword4' => [
|
||||||
'value' => '¥'.$surplus.'元',//账户余额
|
'value' => '¥' . $surplus . '元',//账户余额
|
||||||
'color' => '#173177'
|
'color' => '#173177'
|
||||||
],
|
],
|
||||||
'remark' => [
|
'remark' => [
|
||||||
@ -556,18 +564,18 @@ if (!function_exists('sand_account_change_msg')) {
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
return send_wechat_msg($msg,$user_id);
|
return send_wechat_msg($msg, $user_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商户管理员 - 申请受理通知 - 公众号
|
* 商户管理员 - 申请受理通知 - 公众号
|
||||||
*/
|
*/
|
||||||
if (!function_exists('sand_apply_msg')) {
|
if (!function_exists('sand_apply_msg')) {
|
||||||
function sand_apply_msg($name,$title,$user_id,$applet_id = 0)
|
function sand_apply_msg($name, $title, $user_id, $applet_id = 0)
|
||||||
{
|
{
|
||||||
$webtplmsg = SettingModel::getItem('webtplmsg',$applet_id); //获取模板消息编号
|
$webtplmsg = SettingModel::getItem('webtplmsg', $applet_id); //获取模板消息编号
|
||||||
if(empty($webtplmsg['apply'])){
|
if (empty($webtplmsg['apply'])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
$foodhelp = get_addons_config('foodhelp'); //获取商家助手小程序
|
$foodhelp = get_addons_config('foodhelp'); //获取商家助手小程序
|
||||||
@ -592,7 +600,7 @@ if (!function_exists('sand_apply_msg')) {
|
|||||||
'color' => '#173177'
|
'color' => '#173177'
|
||||||
],
|
],
|
||||||
'keyword3' => [
|
'keyword3' => [
|
||||||
'value' => date('Y/m/d H:i:s',time()),//时间
|
'value' => date('Y/m/d H:i:s', time()),//时间
|
||||||
'color' => '#173177'
|
'color' => '#173177'
|
||||||
],
|
],
|
||||||
'remark' => [
|
'remark' => [
|
||||||
@ -601,18 +609,18 @@ if (!function_exists('sand_apply_msg')) {
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
return send_wechat_msg($msg,$user_id);
|
return send_wechat_msg($msg, $user_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商户管理员 - 申请状态更新通知 - 公众号
|
* 商户管理员 - 申请状态更新通知 - 公众号
|
||||||
*/
|
*/
|
||||||
if (!function_exists('sand_examine_msg')) {
|
if (!function_exists('sand_examine_msg')) {
|
||||||
function sand_examine_msg($id,$title,$status,$user_id,$applet_id=0)
|
function sand_examine_msg($id, $title, $status, $user_id, $applet_id = 0)
|
||||||
{
|
{
|
||||||
$webtplmsg = SettingModel::getItem('webtplmsg',$applet_id); //获取模板消息编号
|
$webtplmsg = SettingModel::getItem('webtplmsg', $applet_id); //获取模板消息编号
|
||||||
if(empty($webtplmsg['examine'])){
|
if (empty($webtplmsg['examine'])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
$foodhelp = get_addons_config('foodhelp'); //获取商家助手小程序
|
$foodhelp = get_addons_config('foodhelp'); //获取商家助手小程序
|
||||||
@ -637,7 +645,7 @@ if (!function_exists('sand_examine_msg')) {
|
|||||||
'color' => '#173177'
|
'color' => '#173177'
|
||||||
],
|
],
|
||||||
'keyword3' => [
|
'keyword3' => [
|
||||||
'value' => date('Y/m/d H:i:s',time()),//申请时间
|
'value' => date('Y/m/d H:i:s', time()),//申请时间
|
||||||
'color' => '#173177'
|
'color' => '#173177'
|
||||||
],
|
],
|
||||||
'keyword4' => [
|
'keyword4' => [
|
||||||
@ -650,17 +658,17 @@ if (!function_exists('sand_examine_msg')) {
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
return send_wechat_msg($msg,$user_id);
|
return send_wechat_msg($msg, $user_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 商户管理员 - 试用申请成功通知 - 公众号
|
* 商户管理员 - 试用申请成功通知 - 公众号
|
||||||
*/
|
*/
|
||||||
if (!function_exists('sand_testing_msg')) {
|
if (!function_exists('sand_testing_msg')) {
|
||||||
function sand_testing_msg($title,$time,$user_id,$applet_id = 0)
|
function sand_testing_msg($title, $time, $user_id, $applet_id = 0)
|
||||||
{
|
{
|
||||||
$webtplmsg = SettingModel::getItem('webtplmsg',$applet_id); //获取模板消息编号
|
$webtplmsg = SettingModel::getItem('webtplmsg', $applet_id); //获取模板消息编号
|
||||||
if(empty($webtplmsg['testing'])){
|
if (empty($webtplmsg['testing'])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
$foodhelp = get_addons_config('foodhelp'); //获取商家助手小程序
|
$foodhelp = get_addons_config('foodhelp'); //获取商家助手小程序
|
||||||
@ -681,7 +689,7 @@ if (!function_exists('sand_testing_msg')) {
|
|||||||
'color' => '#173177'
|
'color' => '#173177'
|
||||||
],
|
],
|
||||||
'keyword2' => [
|
'keyword2' => [
|
||||||
'value' => date('Y/m/d H:i:s',$time),//有效期至
|
'value' => date('Y/m/d H:i:s', $time),//有效期至
|
||||||
'color' => '#173177'
|
'color' => '#173177'
|
||||||
],
|
],
|
||||||
'remark' => [
|
'remark' => [
|
||||||
@ -690,17 +698,17 @@ if (!function_exists('sand_testing_msg')) {
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
return send_wechat_msg($msg,$user_id);
|
return send_wechat_msg($msg, $user_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 商户骑手 - 抢单提醒 - 公众号
|
* 商户骑手 - 抢单提醒 - 公众号
|
||||||
*/
|
*/
|
||||||
if (!function_exists('sand_grab_msg')) {
|
if (!function_exists('sand_grab_msg')) {
|
||||||
function sand_grab_msg($order,$applet_id = 0)
|
function sand_grab_msg($order, $applet_id = 0)
|
||||||
{
|
{
|
||||||
$webtplmsg = SettingModel::getItem('webtplmsg',$applet_id); //获取模板消息编号
|
$webtplmsg = SettingModel::getItem('webtplmsg', $applet_id); //获取模板消息编号
|
||||||
if(empty($webtplmsg['grab'])){
|
if (empty($webtplmsg['grab'])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
$foodhelp = get_addons_config('foodhelp'); //获取商家助手小程序
|
$foodhelp = get_addons_config('foodhelp'); //获取商家助手小程序
|
||||||
@ -739,10 +747,10 @@ if (!function_exists('sand_grab_msg')) {
|
|||||||
]
|
]
|
||||||
];
|
];
|
||||||
$model = new ShopClerkModel;
|
$model = new ShopClerkModel;
|
||||||
$clerk = $model->getAll($order['shop_id'],30);
|
$clerk = $model->getAll($order['shop_id'], 30);
|
||||||
for($n=0;$n<sizeof($clerk);$n++){
|
for ($n = 0; $n < sizeof($clerk); $n++) {
|
||||||
if($clerk[$n]['user_id'] > 0){
|
if ($clerk[$n]['user_id'] > 0) {
|
||||||
send_wechat_msg($msg,$clerk[$n]['user_id']);
|
send_wechat_msg($msg, $clerk[$n]['user_id']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -751,10 +759,10 @@ if (!function_exists('sand_grab_msg')) {
|
|||||||
* 商户店长 - 退款申请通知 - 公众号
|
* 商户店长 - 退款申请通知 - 公众号
|
||||||
*/
|
*/
|
||||||
if (!function_exists('sand_refund_msg')) {
|
if (!function_exists('sand_refund_msg')) {
|
||||||
function sand_refund_msg($order,$applet_id = 0)
|
function sand_refund_msg($order, $applet_id = 0)
|
||||||
{
|
{
|
||||||
$webtplmsg = SettingModel::getItem('webtplmsg',$applet_id); //获取模板消息编号
|
$webtplmsg = SettingModel::getItem('webtplmsg', $applet_id); //获取模板消息编号
|
||||||
if(empty($webtplmsg['refund'])){
|
if (empty($webtplmsg['refund'])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
$foodhelp = get_addons_config('foodhelp'); //获取商家助手小程序
|
$foodhelp = get_addons_config('foodhelp'); //获取商家助手小程序
|
||||||
@ -779,11 +787,11 @@ if (!function_exists('sand_refund_msg')) {
|
|||||||
'color' => '#173177'
|
'color' => '#173177'
|
||||||
],
|
],
|
||||||
'keyword3' => [
|
'keyword3' => [
|
||||||
'value' => '¥'.$order['refund_price'].'元',//退款金额
|
'value' => '¥' . $order['refund_price'] . '元',//退款金额
|
||||||
'color' => '#173177'
|
'color' => '#173177'
|
||||||
],
|
],
|
||||||
'keyword4' => [
|
'keyword4' => [
|
||||||
'value' => date('Y/m/d H:i:s',time()),//退款时间
|
'value' => date('Y/m/d H:i:s', time()),//退款时间
|
||||||
'color' => '#173177'
|
'color' => '#173177'
|
||||||
],
|
],
|
||||||
'remark' => [
|
'remark' => [
|
||||||
@ -793,10 +801,10 @@ if (!function_exists('sand_refund_msg')) {
|
|||||||
]
|
]
|
||||||
];
|
];
|
||||||
$model = new ShopClerkModel;
|
$model = new ShopClerkModel;
|
||||||
$clerk = $model->getAll($order['shop_id'],20);
|
$clerk = $model->getAll($order['shop_id'], 20);
|
||||||
for($n=0;$n<sizeof($clerk);$n++){
|
for ($n = 0; $n < sizeof($clerk); $n++) {
|
||||||
if($clerk[$n]['user_id'] > 0){
|
if ($clerk[$n]['user_id'] > 0) {
|
||||||
send_wechat_msg($msg,$clerk[$n]['user_id']);
|
send_wechat_msg($msg, $clerk[$n]['user_id']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -805,18 +813,18 @@ if (!function_exists('sand_refund_msg')) {
|
|||||||
* 商户店长 新订单提醒模板消息 - 公众号
|
* 商户店长 新订单提醒模板消息 - 公众号
|
||||||
*/
|
*/
|
||||||
if (!function_exists('sand_new_order_msg')) {
|
if (!function_exists('sand_new_order_msg')) {
|
||||||
function sand_new_order_msg($order,$applet_id = 0)
|
function sand_new_order_msg($order, $applet_id = 0)
|
||||||
{
|
{
|
||||||
$webtplmsg = SettingModel::getItem('webtplmsg',$applet_id); //获取模板消息编号
|
$webtplmsg = SettingModel::getItem('webtplmsg', $applet_id); //获取模板消息编号
|
||||||
if(empty($webtplmsg['new_order'])){
|
if (empty($webtplmsg['new_order'])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
$foodhelp = get_addons_config('foodhelp'); //获取商家助手小程序
|
$foodhelp = get_addons_config('foodhelp'); //获取商家助手小程序
|
||||||
if($order['order_mode']['value']==30){
|
if ($order['order_mode']['value'] == 30) {
|
||||||
$title = '自取';
|
$title = '自取';
|
||||||
}elseif($order['order_mode']['value']==20){
|
} elseif ($order['order_mode']['value'] == 20) {
|
||||||
$title = '外卖';
|
$title = '外卖';
|
||||||
}else{
|
} else {
|
||||||
$title = '堂食';
|
$title = '堂食';
|
||||||
}
|
}
|
||||||
$msg = [
|
$msg = [
|
||||||
@ -828,7 +836,7 @@ if (!function_exists('sand_new_order_msg')) {
|
|||||||
],
|
],
|
||||||
'data' => [
|
'data' => [
|
||||||
'first' => [
|
'first' => [
|
||||||
'value' => '收到一个新的'.$title.'订单',
|
'value' => '收到一个新的' . $title . '订单',
|
||||||
'color' => '#173177'
|
'color' => '#173177'
|
||||||
],
|
],
|
||||||
'keyword1' => [
|
'keyword1' => [
|
||||||
@ -836,7 +844,7 @@ if (!function_exists('sand_new_order_msg')) {
|
|||||||
'color' => '#173177'
|
'color' => '#173177'
|
||||||
],
|
],
|
||||||
'keyword2' => [
|
'keyword2' => [
|
||||||
'value' => '¥'.$order['pay_price'].'元',
|
'value' => '¥' . $order['pay_price'] . '元',
|
||||||
'color' => '#173177'
|
'color' => '#173177'
|
||||||
],
|
],
|
||||||
'keyword3' => [
|
'keyword3' => [
|
||||||
@ -850,10 +858,10 @@ if (!function_exists('sand_new_order_msg')) {
|
|||||||
]
|
]
|
||||||
];
|
];
|
||||||
$model = new ShopClerkModel;
|
$model = new ShopClerkModel;
|
||||||
$clerk = $model->getAll($order['shop_id'],20);
|
$clerk = $model->getAll($order['shop_id'], 20);
|
||||||
for($n=0;$n<sizeof($clerk);$n++){
|
for ($n = 0; $n < sizeof($clerk); $n++) {
|
||||||
if($clerk[$n]['user_id'] > 0){
|
if ($clerk[$n]['user_id'] > 0) {
|
||||||
send_wechat_msg($msg,$clerk[$n]['user_id']);
|
send_wechat_msg($msg, $clerk[$n]['user_id']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -862,12 +870,12 @@ if (!function_exists('sand_new_order_msg')) {
|
|||||||
* 发布模板消息 - 公众号
|
* 发布模板消息 - 公众号
|
||||||
*/
|
*/
|
||||||
if (!function_exists('send_wechat_msg')) {
|
if (!function_exists('send_wechat_msg')) {
|
||||||
function send_wechat_msg($msg, $user_id, $applet_id=0)
|
function send_wechat_msg($msg, $user_id, $applet_id = 0)
|
||||||
{
|
{
|
||||||
$user = UserModel::get($user_id);
|
$user = UserModel::get($user_id);
|
||||||
$msg['touser'] = $user['open_id'];
|
$msg['touser'] = $user['open_id'];
|
||||||
$wx = new Wechat;
|
$wx = new Wechat;
|
||||||
$wx->sendWechatMsg($applet_id,$msg);
|
$wx->sendWechatMsg($applet_id, $msg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -875,7 +883,7 @@ if (!function_exists('copydirs')) {
|
|||||||
/**
|
/**
|
||||||
* 复制文件夹
|
* 复制文件夹
|
||||||
* @param string $source 源文件夹
|
* @param string $source 源文件夹
|
||||||
* @param string $dest 目标文件夹
|
* @param string $dest 目标文件夹
|
||||||
*/
|
*/
|
||||||
function copydirs($source, $dest)
|
function copydirs($source, $dest)
|
||||||
{
|
{
|
||||||
@ -890,7 +898,7 @@ if (!function_exists('copydirs')) {
|
|||||||
) {
|
) {
|
||||||
if ($item->isDir()) {
|
if ($item->isDir()) {
|
||||||
$sontDir = $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName();
|
$sontDir = $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName();
|
||||||
|
|
||||||
if (!is_dir($sontDir)) {
|
if (!is_dir($sontDir)) {
|
||||||
mkdir($sontDir, 0777, true);
|
mkdir($sontDir, 0777, true);
|
||||||
}
|
}
|
||||||
@ -903,8 +911,8 @@ if (!function_exists('copydirs')) {
|
|||||||
if (!function_exists('rmdirs')) {
|
if (!function_exists('rmdirs')) {
|
||||||
/**
|
/**
|
||||||
* 删除文件夹
|
* 删除文件夹
|
||||||
* @param string $dirname 目录
|
* @param string $dirname 目录
|
||||||
* @param bool $withself 是否删除自身
|
* @param bool $withself 是否删除自身
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function rmdirs($dirname, $withself = true)
|
function rmdirs($dirname, $withself = true)
|
||||||
@ -934,7 +942,7 @@ function write_log($values, $dir)
|
|||||||
if (is_array($values))
|
if (is_array($values))
|
||||||
$values = print_r($values, true);
|
$values = print_r($values, true);
|
||||||
// 日志内容
|
// 日志内容
|
||||||
$content = '[' . date('Y-m-d H:i:s') . ']' . PHP_EOL . $values . PHP_EOL . PHP_EOL;
|
$content = '[' . date('Y-m-d H:i:s') . ']' . PHP_EOL . json_encode($values, 256) . PHP_EOL . PHP_EOL;
|
||||||
try {
|
try {
|
||||||
// 文件路径
|
// 文件路径
|
||||||
$filePath = $dir . '/logs/';
|
$filePath = $dir . '/logs/';
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -7,9 +7,9 @@ use app\applet\model\User as UserModel;
|
|||||||
use app\common\model\Setting;
|
use app\common\model\Setting;
|
||||||
use app\common\model\Applet;
|
use app\common\model\Applet;
|
||||||
use app\common\model\Wechat;
|
use app\common\model\Wechat;
|
||||||
use Requests;
|
|
||||||
use think\facade\Cache;
|
use think\facade\Cache;
|
||||||
use hema\Http;
|
use hema\Http;
|
||||||
|
use think\facade\Db;
|
||||||
|
|
||||||
class Index
|
class Index
|
||||||
{
|
{
|
||||||
@ -29,62 +29,65 @@ class Index
|
|||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (isset($_GET['echostr'])) {
|
if (isset($_GET['echostr'])) {
|
||||||
echo $_GET["echostr"];
|
echo $_GET["echostr"];
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//接收微信推送数据
|
//接收微信推送数据
|
||||||
$nonce = empty ($_GET ['nonce']) ? "" : trim($_GET ['nonce']);
|
$data = file_get_contents('php://input');
|
||||||
$signature = empty ($_GET['signature']) ? "" : trim($_GET ['signature']);
|
|
||||||
$timeStamp = empty ($_GET ['timestamp']) ? "" : trim($_GET ['timestamp']);
|
|
||||||
$msg_signature = empty ($_GET['msg_signature']) ? "" : trim($_GET ['msg_signature']);
|
|
||||||
$encryptMsg = file_get_contents('php://input');
|
|
||||||
|
|
||||||
write_log($encryptMsg, __DIR__);
|
// $data = simplexml_load_string($data, "SimpleXMLElement", LIBXML_NOCDATA);
|
||||||
|
if (!empty($data)) {
|
||||||
die('success');
|
$data = json_decode($data, true);
|
||||||
|
if (!empty($data)) {
|
||||||
|
//首次关注
|
||||||
$pc = new WxBizMsgCrypt();//创建解密类
|
|
||||||
$msg = '';
|
|
||||||
$errCode = $pc->decryptMsg($msg_signature, $timeStamp, $nonce, $encryptMsg, $msg);
|
|
||||||
if ($errCode == 0) {
|
|
||||||
$data = _xml_to_arr($msg); //XML转换为数组
|
|
||||||
|
|
||||||
//首次关注公众号
|
|
||||||
if ($data['MsgType'] == 'event') {
|
|
||||||
if ($data['Event'] == 'subscribe') {
|
if ($data['Event'] == 'subscribe') {
|
||||||
$wx = new Driver;
|
$user = Db::name('food_user')->where('open_id', $data['FromUserName'])->value('is_new');
|
||||||
if ($wechat_user = $wx->getWechatUserInfo($data['FromUserName'], 10001)) {
|
if ($user !== 1) {
|
||||||
//用户操作
|
//不是新关注
|
||||||
$model = new UserModel;
|
die('success');
|
||||||
if ($user = $model->subscribe($wechat_user, $this->wechat['applet_id'])) {
|
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
//返回文本提醒
|
|
||||||
$wx->sendServiceMsg([
|
//插入一条新用户数据
|
||||||
'type' => 'text',
|
$data = [
|
||||||
'content' => $wx->getError()
|
'open_id' => $data['FromUserName'],
|
||||||
], $data['FromUserName'], $this->wechat['applet_id']);
|
'platform' => 10,
|
||||||
}
|
'applet_id' => 10001,
|
||||||
//是否设置了关注回复
|
'create_time' => time()
|
||||||
if ($subscribe = SettingModel::getItem('subscribe', $this->wechat['applet_id'])) {
|
];
|
||||||
$this->replyMsg($subscribe, $data);//回复信息
|
Db::name('food_user')->insert($data);
|
||||||
|
//发送公众号消息
|
||||||
|
|
||||||
|
$wx = new Driver;
|
||||||
|
$access_token = $wx->getAccessToken(10001);
|
||||||
|
$url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' . $access_token;
|
||||||
|
$queryarr = [
|
||||||
|
'msgtype' => 'news',
|
||||||
|
'news' => [
|
||||||
|
'articles' => [
|
||||||
|
'title' => '您有一张新的优惠券,请及时领取',
|
||||||
|
'picurl' => '',
|
||||||
|
'url' => 'https://www.baidu.com',
|
||||||
|
'description' => '黄辛一新人优惠,首次关注赠送优惠券'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
$queryarr['touser'] = $data['FromUserName'];
|
||||||
|
Http::post($url, hema_json($queryarr));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
die('success');
|
die('success');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user