feat: move miniapp server project
This commit is contained in:
parent
4a940f28ba
commit
96d9063b13
178 changed files with 9699 additions and 5044 deletions
1
app/.htaccess
Normal file
1
app/.htaccess
Normal file
|
|
@ -0,0 +1 @@
|
|||
deny from all
|
||||
249
app/Act1AdminBaseController.php
Normal file
249
app/Act1AdminBaseController.php
Normal file
|
|
@ -0,0 +1,249 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app;
|
||||
|
||||
use think\App;
|
||||
use think\exception\ValidateException;
|
||||
use think\Validate;
|
||||
use app\exceptions\ParamsValidateException;
|
||||
use app\exceptions\NotLoginException;
|
||||
use app\exceptions\NoAccessException;
|
||||
use think\facade\Log;
|
||||
use think\exception\ErrorException;
|
||||
|
||||
/**
|
||||
* 控制器基础类
|
||||
*/
|
||||
abstract class Act1AdminBaseController
|
||||
{
|
||||
protected $user_id = null;
|
||||
protected $user_info = null;
|
||||
protected $check_actions = [];
|
||||
/**
|
||||
* Request实例
|
||||
* @var \think\Request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* 应用实例
|
||||
* @var \think\App
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* 是否批量验证
|
||||
* @var bool
|
||||
*/
|
||||
protected $batchValidate = false;
|
||||
|
||||
/**
|
||||
* 控制器中间件
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [];
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @access public
|
||||
* @param App $app 应用对象
|
||||
*/
|
||||
public function __construct(App $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->request = $this->app->request;
|
||||
|
||||
// 参数校验
|
||||
$this->valid_params();
|
||||
// 控制器初始化
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
// 初始化
|
||||
protected function initialize()
|
||||
{
|
||||
$action_name = $this->request->action();
|
||||
$this->log_notice(['请求参数', $this->request->param(false)], '记录动作', 'action-log:' . $action_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证数据
|
||||
* @access protected
|
||||
* @param array $data 数据
|
||||
* @param string|array $validate 验证器名或者验证规则数组
|
||||
* @param array $message 提示信息
|
||||
* @param bool $batch 是否批量验证
|
||||
* @return array|string|true
|
||||
* @throws ValidateException
|
||||
*/
|
||||
protected function validate(array $data, $validate, array $message = [], bool $batch = false)
|
||||
{
|
||||
if (is_array($validate)) {
|
||||
$v = new Validate();
|
||||
$v->rule($validate);
|
||||
} else {
|
||||
if (strpos($validate, '.')) {
|
||||
// 支持场景
|
||||
[$validate, $scene] = explode('.', $validate);
|
||||
}
|
||||
$class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);
|
||||
$v = new $class();
|
||||
if (!empty($scene)) {
|
||||
$v->scene($scene);
|
||||
}
|
||||
}
|
||||
|
||||
$v->message($message);
|
||||
|
||||
// 是否批量验证
|
||||
if ($batch || $this->batchValidate) {
|
||||
$v->batch(true);
|
||||
}
|
||||
$result = $v->failException(false)->check($data);
|
||||
if (!$result) {
|
||||
throw new ParamsValidateException($v->getError());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function valid_params()
|
||||
{
|
||||
|
||||
$is_logined = false;
|
||||
$cookie_user_id = cookie('act_admin_id');
|
||||
if (!empty($cookie_user_id)) {
|
||||
if ($cookie_user_id) {
|
||||
$cookie_user_id = \a_decode($cookie_user_id);
|
||||
if ($cookie_user_id) {
|
||||
$cookie_user_id_sp = explode('|', $cookie_user_id);
|
||||
//查看是否有这个用户
|
||||
$admin = D('act1_user')->where(array('id' => $cookie_user_id_sp[0], 'deleted' => 0, 'role'=> 'admin'))->find();
|
||||
if (!empty($admin)) {
|
||||
$is_logined = true;
|
||||
$this->user_id = $cookie_user_id_sp[0];
|
||||
$this->user_info = $admin;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->user_id = null;
|
||||
}
|
||||
|
||||
|
||||
$request = $this->app->request;
|
||||
$action_name = $request->action();
|
||||
if(isset($this->not_check_action_login) && (in_array($action_name, $this->not_check_action_login) || in_array('*', $this->not_check_action_login))) {
|
||||
// if($action_name == 'login' || $action_name == 'login_id' || $action_name == 'get_code') {
|
||||
//
|
||||
}else {
|
||||
if ($is_logined) {
|
||||
//logined
|
||||
} else {
|
||||
//not login
|
||||
throw new NotLoginException();
|
||||
}
|
||||
}
|
||||
// 判断是否需要校验接口权限
|
||||
if (array_key_exists($action_name, $this->role_actions ?? [])) {
|
||||
//判断是否登录了
|
||||
if ($is_logined && $this->user_info) {
|
||||
//logined
|
||||
$roles = explode(',', $this->user_info['role'] ?? '');
|
||||
$is_allow = false;
|
||||
foreach ($roles as $role) {
|
||||
foreach ($this->role_actions[$action_name] as $one) {
|
||||
if ($one == $role) {
|
||||
$is_allow = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$is_allow) {
|
||||
throw new NoAccessException();
|
||||
}
|
||||
} else {
|
||||
//no access
|
||||
throw new NoAccessException();
|
||||
}
|
||||
}
|
||||
//没有列举出来的action也不校验登录
|
||||
//带#的action_name是不校验是否登录,但是要校验参数
|
||||
if (array_key_exists($action_name, $this->check_actions)) {
|
||||
//判断是否登录了
|
||||
if ($is_logined) {
|
||||
//logined
|
||||
} else {
|
||||
//not login
|
||||
throw new NotLoginException();
|
||||
}
|
||||
}
|
||||
//校验参数
|
||||
$checks = array();
|
||||
if (array_key_exists($action_name, $this->check_actions)) {
|
||||
$checks = $this->check_actions[$action_name];
|
||||
}
|
||||
if (array_key_exists('#' . $action_name, $this->check_actions)) {
|
||||
$checks = $this->check_actions['#' . $action_name];
|
||||
}
|
||||
|
||||
if (!empty($checks)) {
|
||||
$valid_rule = [];
|
||||
$valid_msg = [];
|
||||
$valid_data = [];
|
||||
foreach ($checks as $k => $v) {
|
||||
if (\substr($k, 0, 1) === '#') {
|
||||
$k = \substr($k, 1);
|
||||
if (!isset($v[0])) {
|
||||
$v[] = '';
|
||||
}
|
||||
} else {
|
||||
if (isset($v[0])) {
|
||||
if (strpos($v[0], 'require') === false) {
|
||||
$v[0] = 'require|' . $v[0];
|
||||
}
|
||||
} else {
|
||||
$v[] = 'require';
|
||||
}
|
||||
}
|
||||
$valid_data[$k] = input($k . '');
|
||||
$valid_rule[$k] = $v[0];
|
||||
if (count($v) > 1) {
|
||||
$msg = $v[1];
|
||||
foreach ($msg as $k1 => $v1) {
|
||||
$valid_msg[$k . '.' . $k1] = $k . $v1;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->validate($valid_data, $valid_rule, $valid_msg);
|
||||
}
|
||||
}
|
||||
|
||||
protected function log_notice($any, $msg = '', $tag = 'log_notice')
|
||||
{
|
||||
if ($any instanceof ErrorException || $any instanceof Exception) {
|
||||
$str = c_formate_exception($any);
|
||||
} else {
|
||||
$str = json_encode($any, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
Log::write('[' . $this->className . ']' . '[' . $tag . ']' . '[' . $msg . ']' . '[' . $str . '][WHO:' . $this->user_id . ']', 'NOTICE');
|
||||
}
|
||||
protected function log_warn($any, $msg = '', $tag = 'log_warn')
|
||||
{
|
||||
if ($any instanceof ErrorException || $any instanceof Exception) {
|
||||
$str = c_formate_exception($any);
|
||||
} else {
|
||||
$str = json_encode($any, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
Log::write('[' . $this->className . ']' . '[' . $tag . ']' . '[' . $msg . ']' . '[' . json_encode($any, JSON_UNESCAPED_UNICODE) . '][WHO:' . $this->user_id . ']', 'WARN');
|
||||
}
|
||||
protected function log_error($any, $msg = '', $tag = 'log_error')
|
||||
{
|
||||
if ($any instanceof ErrorException || $any instanceof Exception) {
|
||||
$str = c_formate_exception($any);
|
||||
} else {
|
||||
$str = json_encode($any, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
Log::write('[' . $this->className . ']' . '[' . $tag . ']' . '[' . $msg . ']' . '[' . json_encode($any, JSON_UNESCAPED_UNICODE) . '][WHO:' . $this->user_id . ']', 'ERROR');
|
||||
}
|
||||
}
|
||||
224
app/Act1Controller.php
Normal file
224
app/Act1Controller.php
Normal file
|
|
@ -0,0 +1,224 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app;
|
||||
|
||||
use think\App;
|
||||
use think\exception\ValidateException;
|
||||
use think\Validate;
|
||||
use app\exceptions\ParamsValidateException;
|
||||
use app\exceptions\NotLoginException;
|
||||
use think\facade\Log;
|
||||
use think\exception\ErrorException;
|
||||
|
||||
/**
|
||||
* 控制器基础类
|
||||
*/
|
||||
abstract class Act1Controller
|
||||
{
|
||||
protected $user_id = null;
|
||||
protected $user_info = null;
|
||||
protected $check_actions = [];
|
||||
protected $className = 'ACTION_NOT_SET';
|
||||
/**
|
||||
* Request实例
|
||||
* @var \think\Request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* 应用实例
|
||||
* @var \think\App
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* 是否批量验证
|
||||
* @var bool
|
||||
*/
|
||||
protected $batchValidate = false;
|
||||
|
||||
/**
|
||||
* 控制器中间件
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [];
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @access public
|
||||
* @param App $app 应用对象
|
||||
*/
|
||||
public function __construct(App $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->request = $this->app->request;
|
||||
|
||||
// 参数校验
|
||||
$this->valid_params();
|
||||
// 控制器初始化
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
// 初始化
|
||||
protected function initialize()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证数据
|
||||
* @access protected
|
||||
* @param array $data 数据
|
||||
* @param string|array $validate 验证器名或者验证规则数组
|
||||
* @param array $message 提示信息
|
||||
* @param bool $batch 是否批量验证
|
||||
* @return array|string|true
|
||||
* @throws ValidateException
|
||||
*/
|
||||
protected function validate(array $data, $validate, array $message = [], bool $batch = false)
|
||||
{
|
||||
if (is_array($validate)) {
|
||||
$v = new Validate();
|
||||
$v->rule($validate);
|
||||
} else {
|
||||
if (strpos($validate, '.')) {
|
||||
// 支持场景
|
||||
[$validate, $scene] = explode('.', $validate);
|
||||
}
|
||||
$class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);
|
||||
$v = new $class();
|
||||
if (!empty($scene)) {
|
||||
$v->scene($scene);
|
||||
}
|
||||
}
|
||||
|
||||
$v->message($message);
|
||||
|
||||
// 是否批量验证
|
||||
if ($batch || $this->batchValidate) {
|
||||
$v->batch(true);
|
||||
}
|
||||
$result = $v->failException(false)->check($data);
|
||||
if (!$result) {
|
||||
throw new ParamsValidateException($v->getError());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected function valid_params()
|
||||
{
|
||||
|
||||
$is_logined = false;
|
||||
$cookie_act_user_id = cookie('act_user_id');
|
||||
if (!empty($cookie_act_user_id)) {
|
||||
if ($cookie_act_user_id) {
|
||||
$cookie_act_user_id = \a_decode($cookie_act_user_id);
|
||||
if ($cookie_act_user_id) {
|
||||
$cookie_act_user_id_sp = explode('|', $cookie_act_user_id);
|
||||
//查看是否有这个用户
|
||||
// c_debug($cookie_user_id_sp[0]);
|
||||
// if($cookie_user_id_sp[0] == 3){
|
||||
// $cookie_user_id_sp[0] = 13;
|
||||
// }
|
||||
$db_user = D('act1_user');
|
||||
$user = $db_user->where(array('id' => $cookie_act_user_id_sp[0]))->find();
|
||||
if (!empty($user)) {
|
||||
$is_logined = true;
|
||||
$this->act_user_id = $cookie_act_user_id_sp[0];
|
||||
$this->act_user_info = $user;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->act_user_id = null;
|
||||
$this->act_user_info = null;
|
||||
}
|
||||
|
||||
|
||||
$request = $this->app->request;
|
||||
$action_name = $request->action();
|
||||
//没有列举出来的action也不校验登录
|
||||
//带#的action_name是不校验是否登录,但是要校验参数
|
||||
if (array_key_exists($action_name, $this->check_actions)) {
|
||||
//判断是否登录了
|
||||
if ($is_logined) {
|
||||
//logined
|
||||
} else {
|
||||
//not login
|
||||
throw new NotLoginException();
|
||||
}
|
||||
}
|
||||
//校验参数
|
||||
$checks = array();
|
||||
if (array_key_exists($action_name, $this->check_actions)) {
|
||||
$checks = $this->check_actions[$action_name];
|
||||
}
|
||||
if (array_key_exists('#' . $action_name, $this->check_actions)) {
|
||||
$checks = $this->check_actions['#' . $action_name];
|
||||
}
|
||||
// echo json_encode($checks);
|
||||
if (!empty($checks)) {
|
||||
$valid_rule = [];
|
||||
$valid_msg = [];
|
||||
$valid_data = [];
|
||||
foreach ($checks as $k => $v) {
|
||||
if (\substr($k, 0, 1) === '#') {
|
||||
$k = \substr($k, 1);
|
||||
if (!isset($v[0])) {
|
||||
$v = [];
|
||||
}
|
||||
} else {
|
||||
if (isset($v[0])) {
|
||||
if (strpos($v[0], 'require') === false) {
|
||||
$v[0] = 'require|' . $v[0];
|
||||
}
|
||||
} else {
|
||||
$v[] = 'require';
|
||||
}
|
||||
}
|
||||
if(empty($v)){
|
||||
continue;
|
||||
}
|
||||
$valid_data[$k] = input($k . '');
|
||||
$valid_rule[$k] = $v[0];
|
||||
if (count($v) > 1) {
|
||||
$msg = $v[1];
|
||||
foreach ($msg as $k1 => $v1) {
|
||||
$valid_msg[$k . '.' . $k1] = $k . $v1;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->validate($valid_data, $valid_rule, $valid_msg);
|
||||
}
|
||||
}
|
||||
|
||||
protected function log_notice($any, $msg = '', $tag = 'log_notice')
|
||||
{
|
||||
if ($any instanceof ErrorException || $any instanceof Exception) {
|
||||
$str = c_formate_exception($any);
|
||||
} else {
|
||||
$str = json_encode($any, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
Log::write('[' . $this->className . ']' . '[' . $tag . ']' . '[' . $msg . ']' . '[' . $str . ']', 'NOTICE');
|
||||
}
|
||||
protected function log_warn($any, $msg = '', $tag = 'log_warn')
|
||||
{
|
||||
if ($any instanceof ErrorException || $any instanceof Exception) {
|
||||
$str = c_formate_exception($any);
|
||||
} else {
|
||||
$str = json_encode($any, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
Log::write('[' . $this->className . ']' . '[' . $tag . ']' . '[' . $msg . ']' . '[' . json_encode($any, JSON_UNESCAPED_UNICODE) . ']', 'WARN');
|
||||
}
|
||||
protected function log_error($any, $msg = '', $tag = 'log_error')
|
||||
{
|
||||
if ($any instanceof ErrorException || $any instanceof Exception) {
|
||||
$str = c_formate_exception($any);
|
||||
} else {
|
||||
$str = json_encode($any, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
Log::write('[' . $this->className . ']' . '[' . $tag . ']' . '[' . $msg . ']' . '[' . json_encode($any, JSON_UNESCAPED_UNICODE) . ']', 'ERROR');
|
||||
}
|
||||
}
|
||||
250
app/AdminBaseController.php
Normal file
250
app/AdminBaseController.php
Normal file
|
|
@ -0,0 +1,250 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app;
|
||||
|
||||
use think\App;
|
||||
use think\exception\ValidateException;
|
||||
use think\Validate;
|
||||
use app\exceptions\ParamsValidateException;
|
||||
use app\exceptions\NotLoginException;
|
||||
use app\exceptions\NoAccessException;
|
||||
use think\facade\Log;
|
||||
use think\exception\ErrorException;
|
||||
|
||||
/**
|
||||
* 控制器基础类
|
||||
*/
|
||||
abstract class AdminBaseController
|
||||
{
|
||||
protected $user_id = null;
|
||||
protected $user_info = null;
|
||||
protected $check_actions = [];
|
||||
/**
|
||||
* Request实例
|
||||
* @var \think\Request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* 应用实例
|
||||
* @var \think\App
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* 是否批量验证
|
||||
* @var bool
|
||||
*/
|
||||
protected $batchValidate = false;
|
||||
|
||||
/**
|
||||
* 控制器中间件
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [];
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @access public
|
||||
* @param App $app 应用对象
|
||||
*/
|
||||
public function __construct(App $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->request = $this->app->request;
|
||||
|
||||
// 参数校验
|
||||
$this->valid_params();
|
||||
// 控制器初始化
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
// 初始化
|
||||
protected function initialize()
|
||||
{
|
||||
$action_name = $this->request->action();
|
||||
$this->log_notice(['请求参数', $this->request->param(false)], '记录动作', 'action-log:' . $action_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证数据
|
||||
* @access protected
|
||||
* @param array $data 数据
|
||||
* @param string|array $validate 验证器名或者验证规则数组
|
||||
* @param array $message 提示信息
|
||||
* @param bool $batch 是否批量验证
|
||||
* @return array|string|true
|
||||
* @throws ValidateException
|
||||
*/
|
||||
protected function validate(array $data, $validate, array $message = [], bool $batch = false)
|
||||
{
|
||||
if (is_array($validate)) {
|
||||
$v = new Validate();
|
||||
$v->rule($validate);
|
||||
} else {
|
||||
if (strpos($validate, '.')) {
|
||||
// 支持场景
|
||||
[$validate, $scene] = explode('.', $validate);
|
||||
}
|
||||
$class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);
|
||||
$v = new $class();
|
||||
if (!empty($scene)) {
|
||||
$v->scene($scene);
|
||||
}
|
||||
}
|
||||
|
||||
$v->message($message);
|
||||
|
||||
// 是否批量验证
|
||||
if ($batch || $this->batchValidate) {
|
||||
$v->batch(true);
|
||||
}
|
||||
$result = $v->failException(false)->check($data);
|
||||
if (!$result) {
|
||||
throw new ParamsValidateException($v->getError());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function valid_params()
|
||||
{
|
||||
|
||||
$is_logined = false;
|
||||
$cookie_user_id = cookie('admin_id');
|
||||
if (!empty($cookie_user_id)) {
|
||||
if ($cookie_user_id) {
|
||||
$cookie_user_id = \a_decode($cookie_user_id);
|
||||
if ($cookie_user_id) {
|
||||
$cookie_user_id_sp = explode('|', $cookie_user_id);
|
||||
//查看是否有这个用户
|
||||
$admin = D('admin')->where(array('id' => $cookie_user_id_sp[0], 'deleted' => 0))->find();
|
||||
if (!empty($admin)) {
|
||||
// $user = D('gzh_auth')->where(array('id' => $merchant['gzh_auth_id']))->find();
|
||||
$is_logined = true;
|
||||
$this->user_id = $cookie_user_id_sp[0];
|
||||
$this->user_info = $admin;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->user_id = null;
|
||||
}
|
||||
|
||||
|
||||
$request = $this->app->request;
|
||||
$action_name = $request->action();
|
||||
if(isset($this->not_check_action_login) && (in_array($action_name, $this->not_check_action_login) || in_array('*', $this->not_check_action_login))) {
|
||||
// if($action_name == 'login' || $action_name == 'login_id' || $action_name == 'get_code') {
|
||||
//
|
||||
}else {
|
||||
if ($is_logined) {
|
||||
//logined
|
||||
} else {
|
||||
//not login
|
||||
throw new NotLoginException();
|
||||
}
|
||||
}
|
||||
// 判断是否需要校验接口权限
|
||||
if (array_key_exists($action_name, $this->role_actions ?? [])) {
|
||||
//判断是否登录了
|
||||
if ($is_logined && $this->user_info) {
|
||||
//logined
|
||||
$roles = explode(',', $this->user_info['role'] ?? '');
|
||||
$is_allow = false;
|
||||
foreach ($roles as $role) {
|
||||
foreach ($this->role_actions[$action_name] as $one) {
|
||||
if ($one == $role) {
|
||||
$is_allow = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$is_allow) {
|
||||
throw new NoAccessException();
|
||||
}
|
||||
} else {
|
||||
//no access
|
||||
throw new NoAccessException();
|
||||
}
|
||||
}
|
||||
//没有列举出来的action也不校验登录
|
||||
//带#的action_name是不校验是否登录,但是要校验参数
|
||||
if (array_key_exists($action_name, $this->check_actions)) {
|
||||
//判断是否登录了
|
||||
if ($is_logined) {
|
||||
//logined
|
||||
} else {
|
||||
//not login
|
||||
throw new NotLoginException();
|
||||
}
|
||||
}
|
||||
//校验参数
|
||||
$checks = array();
|
||||
if (array_key_exists($action_name, $this->check_actions)) {
|
||||
$checks = $this->check_actions[$action_name];
|
||||
}
|
||||
if (array_key_exists('#' . $action_name, $this->check_actions)) {
|
||||
$checks = $this->check_actions['#' . $action_name];
|
||||
}
|
||||
|
||||
if (!empty($checks)) {
|
||||
$valid_rule = [];
|
||||
$valid_msg = [];
|
||||
$valid_data = [];
|
||||
foreach ($checks as $k => $v) {
|
||||
if (\substr($k, 0, 1) === '#') {
|
||||
$k = \substr($k, 1);
|
||||
if (!isset($v[0])) {
|
||||
$v[] = '';
|
||||
}
|
||||
} else {
|
||||
if (isset($v[0])) {
|
||||
if (strpos($v[0], 'require') === false) {
|
||||
$v[0] = 'require|' . $v[0];
|
||||
}
|
||||
} else {
|
||||
$v[] = 'require';
|
||||
}
|
||||
}
|
||||
$valid_data[$k] = input($k . '');
|
||||
$valid_rule[$k] = $v[0];
|
||||
if (count($v) > 1) {
|
||||
$msg = $v[1];
|
||||
foreach ($msg as $k1 => $v1) {
|
||||
$valid_msg[$k . '.' . $k1] = $k . $v1;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->validate($valid_data, $valid_rule, $valid_msg);
|
||||
}
|
||||
}
|
||||
|
||||
protected function log_notice($any, $msg = '', $tag = 'log_notice')
|
||||
{
|
||||
if ($any instanceof ErrorException || $any instanceof Exception) {
|
||||
$str = c_formate_exception($any);
|
||||
} else {
|
||||
$str = json_encode($any, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
Log::write('[' . $this->className . ']' . '[' . $tag . ']' . '[' . $msg . ']' . '[' . $str . '][WHO:' . $this->user_id . ']', 'NOTICE');
|
||||
}
|
||||
protected function log_warn($any, $msg = '', $tag = 'log_warn')
|
||||
{
|
||||
if ($any instanceof ErrorException || $any instanceof Exception) {
|
||||
$str = c_formate_exception($any);
|
||||
} else {
|
||||
$str = json_encode($any, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
Log::write('[' . $this->className . ']' . '[' . $tag . ']' . '[' . $msg . ']' . '[' . json_encode($any, JSON_UNESCAPED_UNICODE) . '][WHO:' . $this->user_id . ']', 'WARN');
|
||||
}
|
||||
protected function log_error($any, $msg = '', $tag = 'log_error')
|
||||
{
|
||||
if ($any instanceof ErrorException || $any instanceof Exception) {
|
||||
$str = c_formate_exception($any);
|
||||
} else {
|
||||
$str = json_encode($any, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
Log::write('[' . $this->className . ']' . '[' . $tag . ']' . '[' . $msg . ']' . '[' . json_encode($any, JSON_UNESCAPED_UNICODE) . '][WHO:' . $this->user_id . ']', 'ERROR');
|
||||
}
|
||||
}
|
||||
11
app/AppCache.php
Normal file
11
app/AppCache.php
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace app;
|
||||
|
||||
use think\facade\Cache;
|
||||
|
||||
|
||||
class AppCache
|
||||
{
|
||||
|
||||
}
|
||||
23
app/AppService.php
Normal file
23
app/AppService.php
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app;
|
||||
|
||||
use think\Service;
|
||||
|
||||
/**
|
||||
* 应用服务类
|
||||
*/
|
||||
class AppService extends Service
|
||||
{
|
||||
public function register()
|
||||
{
|
||||
// 服务注册
|
||||
}
|
||||
|
||||
public function boot()
|
||||
{
|
||||
// 服务启动
|
||||
}
|
||||
}
|
||||
228
app/BaseController.php
Normal file
228
app/BaseController.php
Normal file
|
|
@ -0,0 +1,228 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app;
|
||||
|
||||
use think\App;
|
||||
use think\exception\ValidateException;
|
||||
use think\Validate;
|
||||
use app\exceptions\ParamsValidateException;
|
||||
use app\exceptions\NotLoginException;
|
||||
use think\facade\Log;
|
||||
use think\exception\ErrorException;
|
||||
|
||||
/**
|
||||
* 控制器基础类
|
||||
*/
|
||||
abstract class BaseController
|
||||
{
|
||||
protected $user_id = null;
|
||||
protected $user_info = null;
|
||||
protected $check_actions = [];
|
||||
protected $className = 'ACTION_NOT_SET';
|
||||
/**
|
||||
* Request实例
|
||||
* @var \think\Request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* 应用实例
|
||||
* @var \think\App
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* 是否批量验证
|
||||
* @var bool
|
||||
*/
|
||||
protected $batchValidate = false;
|
||||
|
||||
/**
|
||||
* 控制器中间件
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [];
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @access public
|
||||
* @param App $app 应用对象
|
||||
*/
|
||||
public function __construct(App $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->request = $this->app->request;
|
||||
|
||||
// 参数校验
|
||||
$this->valid_params();
|
||||
// 控制器初始化
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
// 初始化
|
||||
protected function initialize()
|
||||
{
|
||||
if(isset($this->ignore_log_params) && $this->ignore_log_params) return;
|
||||
$action_name = $this->request->action();
|
||||
$this->log_notice(['请求参数', $this->request->param(false)], '记录动作', 'action-log:' . $action_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证数据
|
||||
* @access protected
|
||||
* @param array $data 数据
|
||||
* @param string|array $validate 验证器名或者验证规则数组
|
||||
* @param array $message 提示信息
|
||||
* @param bool $batch 是否批量验证
|
||||
* @return array|string|true
|
||||
* @throws ValidateException
|
||||
*/
|
||||
protected function validate(array $data, $validate, array $message = [], bool $batch = false)
|
||||
{
|
||||
if (is_array($validate)) {
|
||||
$v = new Validate();
|
||||
$v->rule($validate);
|
||||
} else {
|
||||
if (strpos($validate, '.')) {
|
||||
// 支持场景
|
||||
[$validate, $scene] = explode('.', $validate);
|
||||
}
|
||||
$class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);
|
||||
$v = new $class();
|
||||
if (!empty($scene)) {
|
||||
$v->scene($scene);
|
||||
}
|
||||
}
|
||||
|
||||
$v->message($message);
|
||||
|
||||
// 是否批量验证
|
||||
if ($batch || $this->batchValidate) {
|
||||
$v->batch(true);
|
||||
}
|
||||
$result = $v->failException(false)->check($data);
|
||||
if (!$result) {
|
||||
throw new ParamsValidateException($v->getError());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected function valid_params()
|
||||
{
|
||||
|
||||
$is_logined = false;
|
||||
$cookie_user_id = cookie('user_id');
|
||||
if (!empty($cookie_user_id)) {
|
||||
if ($cookie_user_id) {
|
||||
$cookie_user_id = \a_decode($cookie_user_id);
|
||||
if ($cookie_user_id) {
|
||||
$cookie_user_id_sp = explode('|', $cookie_user_id);
|
||||
//查看是否有这个用户
|
||||
// c_debug($cookie_user_id_sp[0]);
|
||||
// if($cookie_user_id_sp[0] == 3){
|
||||
// $cookie_user_id_sp[0] = 13;
|
||||
// }
|
||||
$db_user = D('user');
|
||||
$user = $db_user->where(array('id' => $cookie_user_id_sp[0]))->find();
|
||||
if (!empty($user)) {
|
||||
$is_logined = true;
|
||||
$this->user_id = $cookie_user_id_sp[0];
|
||||
$this->user_info = $user;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// $is_logined = true;
|
||||
// $this->user_id = 1;
|
||||
// $this->user_info = [];
|
||||
}
|
||||
|
||||
|
||||
$request = $this->app->request;
|
||||
$action_name = $request->action();
|
||||
//没有列举出来的action也不校验登录
|
||||
//带#的action_name是不校验是否登录,但是要校验参数
|
||||
if (array_key_exists($action_name, $this->check_actions)) {
|
||||
//判断是否登录了
|
||||
if ($is_logined) {
|
||||
//logined
|
||||
} else {
|
||||
//not login
|
||||
throw new NotLoginException();
|
||||
}
|
||||
}
|
||||
//校验参数
|
||||
$checks = array();
|
||||
if (array_key_exists($action_name, $this->check_actions)) {
|
||||
$checks = $this->check_actions[$action_name];
|
||||
}
|
||||
if (array_key_exists('#' . $action_name, $this->check_actions)) {
|
||||
$checks = $this->check_actions['#' . $action_name];
|
||||
}
|
||||
// echo json_encode($checks);
|
||||
if (!empty($checks)) {
|
||||
$valid_rule = [];
|
||||
$valid_msg = [];
|
||||
$valid_data = [];
|
||||
foreach ($checks as $k => $v) {
|
||||
if (\substr($k, 0, 1) === '#') {
|
||||
$k = \substr($k, 1);
|
||||
if (!isset($v[0])) {
|
||||
$v = [];
|
||||
}
|
||||
} else {
|
||||
if (isset($v[0])) {
|
||||
if (strpos($v[0], 'require') === false) {
|
||||
$v[0] = 'require|' . $v[0];
|
||||
}
|
||||
} else {
|
||||
$v[] = 'require';
|
||||
}
|
||||
}
|
||||
if(empty($v)){
|
||||
continue;
|
||||
}
|
||||
$valid_data[$k] = input($k . '');
|
||||
$valid_rule[$k] = $v[0];
|
||||
if (count($v) > 1) {
|
||||
$msg = $v[1];
|
||||
foreach ($msg as $k1 => $v1) {
|
||||
$valid_msg[$k . '.' . $k1] = $k . $v1;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->validate($valid_data, $valid_rule, $valid_msg);
|
||||
}
|
||||
}
|
||||
|
||||
protected function log_notice($any, $msg = '', $tag = 'log_notice')
|
||||
{
|
||||
if ($any instanceof ErrorException || $any instanceof Exception) {
|
||||
$str = c_formate_exception($any);
|
||||
} else {
|
||||
$str = json_encode($any, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
Log::write('[' . $this->className . ']' . '[' . $tag . ']' . '[' . $msg . ']' . '[' . $str . ']', 'NOTICE');
|
||||
}
|
||||
protected function log_warn($any, $msg = '', $tag = 'log_warn')
|
||||
{
|
||||
if ($any instanceof ErrorException || $any instanceof Exception) {
|
||||
$str = c_formate_exception($any);
|
||||
} else {
|
||||
$str = json_encode($any, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
Log::write('[' . $this->className . ']' . '[' . $tag . ']' . '[' . $msg . ']' . '[' . json_encode($any, JSON_UNESCAPED_UNICODE) . ']', 'WARN');
|
||||
}
|
||||
protected function log_error($any, $msg = '', $tag = 'log_error')
|
||||
{
|
||||
if ($any instanceof ErrorException || $any instanceof Exception) {
|
||||
$str = c_formate_exception($any);
|
||||
} else {
|
||||
$str = json_encode($any, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
Log::write('[' . $this->className . ']' . '[' . $tag . ']' . '[' . $msg . ']' . '[' . json_encode($any, JSON_UNESCAPED_UNICODE) . ']', 'ERROR');
|
||||
}
|
||||
}
|
||||
31
app/Constant.php
Normal file
31
app/Constant.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace app;
|
||||
|
||||
class Constant
|
||||
{
|
||||
public static $CACHE_ACCESS_TOKEN = 'CACHE_ACCESS_TOKEN';
|
||||
public static $ORDER_S_PTR = 'ORDER_S_PTR';
|
||||
public static $ORDER_PAY_STAUS = [
|
||||
"init" => [
|
||||
"text" => "待支付",
|
||||
"value" => "init"
|
||||
],
|
||||
"payed" => [
|
||||
"text" => "已支付",
|
||||
"value" => "payed"
|
||||
],
|
||||
"cancel" => [
|
||||
"text" => "已取消",
|
||||
"value" => "cancel"
|
||||
],
|
||||
"need_refund" => [
|
||||
"text" => "待退款",
|
||||
"value" => "need_refund"
|
||||
],
|
||||
"refund" => [
|
||||
"text" => "已退款",
|
||||
"value" => "refund"
|
||||
]
|
||||
];
|
||||
}
|
||||
109
app/ExceptionHandle.php
Normal file
109
app/ExceptionHandle.php
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
namespace app;
|
||||
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\exception\Handle;
|
||||
use think\exception\HttpException;
|
||||
use think\exception\HttpResponseException;
|
||||
use think\exception\ValidateException;
|
||||
use think\Response;
|
||||
use Throwable;
|
||||
use think\facade\Env;
|
||||
use think\facade\Config;
|
||||
use think\facade\Log;
|
||||
use think\facade\Cache;
|
||||
use app\Constant;
|
||||
use app\exceptions\ParamsValidateException;
|
||||
use app\exceptions\NotLoginException;
|
||||
use app\exceptions\NoAccessException;
|
||||
|
||||
/**
|
||||
* 应用异常处理类
|
||||
*/
|
||||
class ExceptionHandle extends Handle
|
||||
{
|
||||
/**
|
||||
* 不需要记录信息(日志)的异常类列表
|
||||
* @var array
|
||||
*/
|
||||
protected $ignoreReport = [
|
||||
HttpException::class,
|
||||
HttpResponseException::class,
|
||||
ModelNotFoundException::class,
|
||||
DataNotFoundException::class,
|
||||
ValidateException::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* 记录异常信息(包括日志或者其它方式记录)
|
||||
*
|
||||
* @access public
|
||||
* @param Throwable $exception
|
||||
* @return void
|
||||
*/
|
||||
public function report(Throwable $exception): void
|
||||
{
|
||||
// 使用内置的方式记录异常日志
|
||||
parent::report($exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @access public
|
||||
* @param \think\Request $request
|
||||
* @param Throwable $e
|
||||
* @return Response
|
||||
*/
|
||||
public function render($request, Throwable $e): Response
|
||||
{
|
||||
// 添加自定义异常处理机制
|
||||
$trace_id = 'error-trace-id-' . time() . '-' . rand(1000, 9999);
|
||||
|
||||
$handle_flag = false;
|
||||
if ($e instanceof HttpException && $e->getStatusCode() === 404) {
|
||||
//$resp = Response::create(json_encode(ajaxFail($e->getMessage(), -1003, null, true)));
|
||||
$resp = ajaxFail($e->getMessage(), -1003);
|
||||
$handle_flag = true;
|
||||
$e = [];
|
||||
}
|
||||
if ($e instanceof ParamsValidateException) {
|
||||
$resp = ajaxFail('参数' . $e->getMessage(), -1002);
|
||||
$handle_flag = true;
|
||||
if (Config::get('app.APP_DEBUG')) {
|
||||
$e = '参数' . $e->getMessage() . ' request_uri:' . $_SERVER['REQUEST_URI'];
|
||||
}else{
|
||||
$e = [];
|
||||
}
|
||||
}
|
||||
if ($e instanceof NotLoginException) {
|
||||
$resp = ajaxFail("未登录或登录超时", -1000);
|
||||
$handle_flag = true;
|
||||
$e = [];
|
||||
}
|
||||
if ($e instanceof NoAccessException) {
|
||||
$resp = ajaxFail("权限不足,拒绝操作", -1003);
|
||||
$handle_flag = true;
|
||||
$e = [];
|
||||
}
|
||||
if ($e != []) {
|
||||
$txt = sprintf("异常信息(" . $trace_id . "): %s \r\n", $e);
|
||||
Log::write($txt, 'ERROR');
|
||||
}
|
||||
|
||||
if ($handle_flag) {
|
||||
$resp->contentType('application/json');
|
||||
return $resp;
|
||||
}
|
||||
if (!Config::get('app.APP_DEBUG')) {
|
||||
$resp = ajaxFail("系统异常", -1001, $trace_id);
|
||||
$resp->contentType('application/json');
|
||||
return $resp;
|
||||
}
|
||||
|
||||
// 其他错误交给系统处理
|
||||
return parent::render($request, $e);
|
||||
}
|
||||
}
|
||||
8
app/Request.php
Normal file
8
app/Request.php
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
namespace app;
|
||||
|
||||
// 应用请求对象类
|
||||
class Request extends \think\Request
|
||||
{
|
||||
|
||||
}
|
||||
1279
app/common.php
Normal file
1279
app/common.php
Normal file
File diff suppressed because it is too large
Load diff
430
app/controller/Admin.php
Normal file
430
app/controller/Admin.php
Normal file
|
|
@ -0,0 +1,430 @@
|
|||
<?php
|
||||
|
||||
namespace app\controller;
|
||||
|
||||
use think\App;
|
||||
use app\AdminBaseController;
|
||||
use think\facade\Log;
|
||||
use think\exception\ValidateException;
|
||||
use app\AppCache;
|
||||
use think\facade\Cache;
|
||||
use app\Constant;
|
||||
use Exception;
|
||||
use think\facade\Config;
|
||||
|
||||
class Admin extends AdminBaseController
|
||||
{
|
||||
function __construct(
|
||||
App $app
|
||||
) {
|
||||
$this->className = 'V1';
|
||||
$this->not_check_action_login = [
|
||||
'test',
|
||||
'login',
|
||||
'login_id',
|
||||
'get_code'
|
||||
];
|
||||
parent::__construct($app);
|
||||
}
|
||||
|
||||
public function test() {
|
||||
json_decode('asdfasdf','');
|
||||
return ajaxSuccess(json_last_error());
|
||||
// return ajaxSuccess($this->user_info);
|
||||
}
|
||||
public function order_list($current = 1, $pageSize = 10, $order_no = '', $pay_time = '', $buy_type = '', $status = '',$phone='',$name='',$from_user_name='',$create_time=[], $export=0)
|
||||
{
|
||||
$user_ids = [];
|
||||
if($from_user_name){
|
||||
$list_user = D('user')->where('real_name','LIKE', '%'.$from_user_name.'%')->select();
|
||||
foreach ($list_user as $one) {
|
||||
$user_ids[] = $one['id'];
|
||||
}
|
||||
}
|
||||
$model = D('orderx');
|
||||
$where = [
|
||||
'deleted' => 0,
|
||||
];
|
||||
$model = $model->where($where);
|
||||
if ($order_no) {
|
||||
$model = $model->where('order_no', 'LIKE', '%' . $order_no . '%');
|
||||
}
|
||||
if ($phone) {
|
||||
$model = $model->where('phone', 'LIKE', '%' . $phone . '%');
|
||||
}
|
||||
if ($name) {
|
||||
$model = $model->where('name', 'LIKE', '%' . $name . '%');
|
||||
}
|
||||
if ($pay_time) {
|
||||
$model = $model->whereBetween('pay_time', [$pay_time . ' 00:00:00', $pay_time . ' 23:59:59']);
|
||||
}
|
||||
if ($buy_type) {
|
||||
$model = $model->where('buy_type', $buy_type);
|
||||
}
|
||||
if ($status) {
|
||||
$model = $model->where('status', $status);
|
||||
}else{
|
||||
$model = $model->where('status', '<>', 'cancel');
|
||||
}
|
||||
if($from_user_name){
|
||||
$model = $model->where('from_user_id','in',$user_ids);
|
||||
}
|
||||
if($create_time && count($create_time) == 2) {
|
||||
$model->where('create_time' ,'>=' ,$create_time[0] . ':00:00:00');
|
||||
$model->where('create_time' ,'<=' ,$create_time[1] . '23:59:59');
|
||||
}
|
||||
$total = 0;
|
||||
if($export != 1) {
|
||||
$total = $model->count();
|
||||
$model->page($current, $pageSize);
|
||||
}
|
||||
$_list = $model->order('id DESC')->select();
|
||||
//
|
||||
$list = [];
|
||||
foreach ($_list as $one) {
|
||||
$user_info = D('user')->where(['id' => $one['from_user_id']])->find();
|
||||
$one['from_user_name'] = $user_info['real_name'] ?: '';
|
||||
// $one['phone'] = $user_info['phone'];
|
||||
$list[] = $one;
|
||||
}
|
||||
if($export == 1) {
|
||||
header('Content-Disposition: attachment; filename=订单列表'. time() . '.xls');
|
||||
header('Content-Encoding: UTF-8');
|
||||
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8");
|
||||
echo '<table>';
|
||||
$row = [
|
||||
'订单号','支付金额',
|
||||
'支付状态','类型','用户名','用户手机号',
|
||||
'订单时间','支付时间',
|
||||
// '退款时间','退款金额',
|
||||
'分销员','分销员id'
|
||||
];
|
||||
$v = '<tr><td>' . join("</td><td>", $row) . "</td></tr>";
|
||||
echo iconv("UTF-8", "GB2312//IGNORE", $v);
|
||||
foreach ($list as $row) {
|
||||
$t = [];
|
||||
$t[] = $row['order_no'];
|
||||
$t[] = round($row['price']/100,2);
|
||||
|
||||
$t[] = Constant::$ORDER_PAY_STAUS[$row['status']]['text'] ?? $row['status'];
|
||||
$t[] = $row['buy_type'];
|
||||
$t[] = $row['name'];
|
||||
$t[] = '\'' . $row['phone'];
|
||||
|
||||
$t[] = $row['create_time'];
|
||||
$t[] = $row['pay_time'];
|
||||
|
||||
$t[] = $row['refund_time'];
|
||||
// $t[] = round($row['refund_money']/100,2);
|
||||
// $t[] = round($row['refund_inner_money']/100,2);
|
||||
$t[] = $row['from_user_name'];
|
||||
$t[] = $row['from_user_id'];
|
||||
|
||||
$v ='<tr><td>' . join("</td><td>", $t) . "</td></tr>";
|
||||
echo iconv("UTF-8", "GB2312//IGNORE", $v);
|
||||
}
|
||||
echo '</table>';
|
||||
}
|
||||
else {
|
||||
return ajaxSuccessPage($list, $current, $pageSize, $total);
|
||||
}
|
||||
}
|
||||
public function change_share($id,$is_share) {
|
||||
D('user')->where(['id'=>$id])->update(['is_share'=>$is_share]);
|
||||
return ajaxSuccess();
|
||||
}
|
||||
public function member_list($current = 1, $pageSize = 10, $is_share='', $real_name='', $create_time=[], $export = 0,$has_phone=0)
|
||||
{
|
||||
$model = D('user');
|
||||
$where = [
|
||||
'deleted' => 0,
|
||||
];
|
||||
$model = $model->where($where);
|
||||
if ($real_name) {
|
||||
$model = $model->where('real_name', 'LIKE', '%' . $real_name . '%');
|
||||
}
|
||||
if($is_share !== '') {
|
||||
$model->where(['is_share'=>$is_share]);
|
||||
}
|
||||
if($create_time && count($create_time) == 2) {
|
||||
$model->where('create_time' ,'>=' ,$create_time[0]);
|
||||
$model->where('create_time' ,'<=' ,$create_time[1]);
|
||||
}
|
||||
$total = $model->count();
|
||||
if($export == 0) {
|
||||
$model->page($current, $pageSize);
|
||||
}
|
||||
$_list = $model->order('id DESC')->select();
|
||||
$list = [];
|
||||
foreach ($_list as $one) {
|
||||
$list[] = $one;
|
||||
}
|
||||
if($export == 0) {
|
||||
return ajaxSuccessPage(c_filter_property_list($list, ['openid','union_id','session_key','sms_code','deleted'], true), $current, $pageSize, $total);
|
||||
}
|
||||
else {
|
||||
// header('Content-Disposition: attachment; filename=会员列表'. time() . '.xlsx');
|
||||
// header('Content-Encoding: UTF-8');
|
||||
// header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8");
|
||||
// echo '<table>';
|
||||
// $row = [
|
||||
// '内部编号','手机号','姓名/昵称',
|
||||
// '剩余金额','剩余积分','等级积分',
|
||||
// '会员号','性别','出生年月','自评等级','注册时间'
|
||||
// ];
|
||||
// $v = '<tr><td>' . join("</td><td>", $row) . "</td></tr>";
|
||||
// echo iconv("UTF-8", "GB2312//IGNORE", $v);
|
||||
// foreach ($list as $row) {
|
||||
// $t = [];
|
||||
// $t[] = $row['id'];
|
||||
// $t[] = '\'' . $row['phone'];
|
||||
// $t[] = $row['nick_name2'];
|
||||
|
||||
// $t[] = round($row['money']/100,2);
|
||||
// $t[] = $row['score'];
|
||||
// $t[] = $row['level_score'];
|
||||
|
||||
// $t[] = $row['user_no'];
|
||||
// $t[] = $row['gender2'] == 0 ? '女' :'男';
|
||||
// $t[] = $row['birth_ym'];
|
||||
|
||||
// $t[] = $row['self_level'];
|
||||
// $t[] = $row['create_time'];
|
||||
// $v ='<tr><td>' . join("</td><td>", $t) . "</td></tr>";
|
||||
// echo iconv("UTF-8", "GB2312//IGNORE", $v);
|
||||
// }
|
||||
// echo '</table>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function banner_save($id='', $title='',$img='',$action_type='',$action_item='') {
|
||||
if($id){
|
||||
D('banner')->where(['id'=>$id])->update([
|
||||
'title'=> $title,
|
||||
'img'=>$img,
|
||||
'action_type'=>$action_type,
|
||||
'action_item'=>$action_item,
|
||||
]);
|
||||
}else{
|
||||
D('banner')->insert([
|
||||
'title'=> $title,
|
||||
'img'=>$img,
|
||||
'action_type'=>$action_type,
|
||||
'action_item'=>$action_item,
|
||||
'create_time'=>c_now(),
|
||||
]);
|
||||
}
|
||||
return ajaxSuccess();
|
||||
}
|
||||
public function banner_list($title='',$current = 1, $pageSize = 10) {
|
||||
$model = D('banner');
|
||||
$where = ['deleted' => 0];
|
||||
if ($title) {
|
||||
$model->where("title LIKE '%" . $title . "%'");
|
||||
}
|
||||
$model = $model->where($where);
|
||||
$total = $model->count();
|
||||
$list = $model->page($current, $pageSize)->order('id DESC')->select();
|
||||
return ajaxSuccessPage($list, $current, $pageSize, $total);
|
||||
}
|
||||
public function banner_del($id=0) {
|
||||
D('banner')->where(['id' => $id])->update(['deleted' => 1]);
|
||||
return ajaxSuccess();
|
||||
}
|
||||
|
||||
public function banner_detail($id=0) {
|
||||
$one = D('banner')->where(['id' => $id,'deleted'=>0])->find();
|
||||
return ajaxSuccess($one);
|
||||
}
|
||||
|
||||
//news_admin
|
||||
public function news_admin_save($id=0, $title='',$content='',$imgs='',$poster=''){
|
||||
$data = [
|
||||
'title'=>$title,
|
||||
'admin_id'=>$this->user_id,
|
||||
'poster'=> $poster,
|
||||
'imgs'=>$imgs,
|
||||
'content'=>$content,
|
||||
];
|
||||
if($id){
|
||||
D('news')->where(['id'=>$id])->update($data);
|
||||
}else{
|
||||
$data['create_time'] = c_now();
|
||||
D('news')->insert($data);
|
||||
}
|
||||
return ajaxSuccess();
|
||||
}
|
||||
public function news_admin_del($id=0) {
|
||||
D('news')->where(['id' => $id])->update(['deleted' => 1]);
|
||||
return ajaxSuccess();
|
||||
}
|
||||
// public function news_admin_recommend($id=0,$recommend=0) {
|
||||
// D('news_admin')->where(['id' => $id])->update(['recommend' => $recommend,'recommend_time'=>c_now()]);
|
||||
// return ajaxSuccess();
|
||||
// }
|
||||
// public function news_admin_banner($id=0,$banner=0) {
|
||||
// D('news_admin')->where(['id' => $id])->update(['banner' => $banner,'banner_time'=>c_now()]);
|
||||
// return ajaxSuccess();
|
||||
// }
|
||||
|
||||
public function news_admin_detail($id=''){
|
||||
$detail = D('news')->where(['id'=>$id,'deleted'=>0])->find();
|
||||
$user = D('admin')->where(['id'=>$detail['admin_id']])->find();
|
||||
$user = c_filter_property($user,['name','id']);
|
||||
|
||||
return ajaxSuccess([
|
||||
'detail'=>$detail,
|
||||
'user'=>$user,
|
||||
]);
|
||||
}
|
||||
|
||||
public function news_admin_list($current = 1, $pageSize = 10,$title='') {
|
||||
$model = D('news');
|
||||
$where = ['deleted' => 0];
|
||||
if ($title) {
|
||||
$model->where("title LIKE '%" . $title . "%'");
|
||||
}
|
||||
$model = $model->where($where);
|
||||
$total = $model->count();
|
||||
$list = $model->page($current, $pageSize)->order('id DESC')->select();
|
||||
return ajaxSuccessPage($list, $current, $pageSize, $total);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
public function dashborad() {
|
||||
$re=[];
|
||||
$re['today_order_nums'] = D('orderx')->where(['status'=>'payed','deleted'=>0])->where('create_time', '>=', date('Y-m-d', time()) . ' 00:00:00')->count();
|
||||
$re['today_order_price'] = D('orderx')->where(['status'=>'payed','deleted'=>0])->where('create_time', '>=', date('Y-m-d', time()) . ' 00:00:00')->sum('price');
|
||||
$re['all_order_nums'] = D('orderx')->where(['status'=>'payed','deleted'=>0])->count();
|
||||
$re['all_order_price'] = D('orderx')->where(['status'=>'payed','deleted'=>0])->sum('price');
|
||||
return ajaxSuccess($re);
|
||||
}
|
||||
|
||||
public function user_save($data) {
|
||||
$data = c_filter_property($data, [
|
||||
'id', 'name',
|
||||
'username', 'role',
|
||||
'status', 'password',
|
||||
]);
|
||||
|
||||
$in_admin = D('admin')->where(['deleted' => 0, 'username' => $data['username']])->find();
|
||||
|
||||
if (!empty($in_admin) && $in_admin['id'] != ($data['id'] ?? '')) {
|
||||
return ajaxFail('用户名已存在,请更换', -1);
|
||||
}
|
||||
|
||||
$_data = [];
|
||||
$_data = array_merge($_data, $data);
|
||||
$this->log_notice($_data, 'user_save', 'user_save');
|
||||
if ($_data['password'] ?? '') {
|
||||
$_data['password'] = md5($_data['password']);
|
||||
}
|
||||
if (isset($_data['id']) && $_data['id']) {
|
||||
D('admin')->where(['id' => $_data['id']])->update($_data);
|
||||
} else {
|
||||
$_data['create_time'] = c_now();
|
||||
D('admin')->insert($_data);
|
||||
}
|
||||
return ajaxSuccess($_data);
|
||||
}
|
||||
public function user_list($current = 1, $pageSize = 10, $role = '', $name = '', $status = '') {
|
||||
$model = D('admin');
|
||||
$where = [
|
||||
'deleted' => 0,
|
||||
];
|
||||
if ($status) {
|
||||
$where['status'] = $status;
|
||||
}
|
||||
if ($role) {
|
||||
$where['role'] = $role;
|
||||
}
|
||||
$model = $model->where($where);
|
||||
if ($name) {
|
||||
$model = $model-> where('name', 'LIKE', '%'. $name. '%');
|
||||
}
|
||||
$total = $model->count();
|
||||
$list = $model->page($current, $pageSize)->order('id DESC')->select();
|
||||
return ajaxSuccessPage(c_filter_property_list($list, ['password', 'deleted'], true), $current, $pageSize, $total);
|
||||
}
|
||||
|
||||
public function upload() {
|
||||
$file = request()->file('file');
|
||||
if ($file) {
|
||||
try {
|
||||
// validate([
|
||||
// 'file' => [
|
||||
// 'fileSize' => (50 * 1024 * 1024),
|
||||
// 'fileExt' => ['png', 'jpg', 'xls', 'xlsx', 'pdf', 'doc', 'docx', 'odf'],
|
||||
// ]
|
||||
// ])->check(['file' => $file]);
|
||||
$savename = \think\facade\Filesystem::disk('public')->putFile(date('Y-m-d'), $file, 'md5');
|
||||
return ajaxSuccess([
|
||||
'path' => '/uploads/' . (str_replace('\\', '/', $savename)),
|
||||
]);
|
||||
} catch (ValidateException $e) {
|
||||
// 上传失败获取错误信息
|
||||
return ajaxFail($e->getMessage(), -2);
|
||||
}
|
||||
}
|
||||
|
||||
return ajaxFail('未选择上传文件,请重试', -3);
|
||||
}
|
||||
public function change_passwd($new_passwd){
|
||||
D('admin')->where(['id'=>$this->user_id])->update(['password'=>md5($new_passwd)]);
|
||||
return ajaxSuccess();
|
||||
}
|
||||
public function login_id($id) {
|
||||
$user = D('admin')->where(['id' => $id, 'deleted' => 0, 'status' => 'stay'])->find();
|
||||
$cookie_id = a_encode($user['id'] . '|' . time(), Config::get('app.ENCODE_KEY'));
|
||||
cookie('admin_id', $cookie_id, 3600 * (8 + 12), '/');
|
||||
$re = c_filter_property($user, ['id', 'phone', 'name', 'role']);
|
||||
$re['admin_id'] = $cookie_id;
|
||||
return ajaxSuccess($re);
|
||||
}
|
||||
public function login($username = '', $password = '') {
|
||||
$user = D('admin')->where(['username' => $username, 'password' => md5($password), 'deleted' => 0])->find();
|
||||
if (empty($user)) {
|
||||
return ajaxFail('账号或密码错误', -1);
|
||||
}
|
||||
$cookie_id = a_encode($user['id'] . '|' . time(), Config::get('app.ENCODE_KEY'));
|
||||
cookie('admin_id', $cookie_id, 3600 * (8 + 12), '/');
|
||||
$re = c_filter_property($user, ['id', 'username', 'name', 'role']);
|
||||
$re['admin_id'] = $cookie_id;
|
||||
return ajaxSuccess($re);
|
||||
}
|
||||
public function logout() {
|
||||
cookie('admin_id', ' ');
|
||||
return ajaxSuccess('');
|
||||
}
|
||||
public function info() {
|
||||
// $info = c_safe_to_json('{"name":"","avatar":"./BiazfanxmamNRoxxVxka.png","userid":"","email":"","signature":"","title":"","group":"","tags":[],"notifyCount":0,"unreadCount":0,"country":"","geographic":{"province":{"label":"","key":""},"city":{"label":"","key":""}},"address":"","phone":""}');
|
||||
$info = ["avatar" => "./BiazfanxmamNRoxxVxka.png"];
|
||||
$user = $this->user_info;
|
||||
// print_r($user);
|
||||
// print_r($info);
|
||||
// print_r($this->user_id);
|
||||
$info['name'] = $user['name'];
|
||||
$info['userid'] = $user['id'];
|
||||
$info['phone'] = '';
|
||||
$info['role'] = $user['role'];
|
||||
return ajaxSuccess($info);
|
||||
}
|
||||
public function all_enums() {
|
||||
$all_enums = D('config')->select();
|
||||
$re = ['$all_enums'=>$all_enums];
|
||||
foreach ($all_enums as $one) {
|
||||
$re[$one['k']] = c_safe_to_json($one['v'], $one['v']);
|
||||
}
|
||||
$user_list = D('admin')->where(['deleted' => 0])->select();
|
||||
$re['admin_list'] = c_filter_property_list($user_list, ['id', 'name', 'role', 'username']);
|
||||
//
|
||||
return ajaxSuccess($re);
|
||||
}
|
||||
public function enum_save($value = '', $type = '') {
|
||||
D('config')->where(['k' => $type])->update(['v' => $value]);
|
||||
return ajaxSuccess($value);
|
||||
}
|
||||
|
||||
}
|
||||
24
app/controller/Index.php
Normal file
24
app/controller/Index.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace app\controller;
|
||||
|
||||
use think\App;
|
||||
use app\BaseController;
|
||||
use think\facade\Env;
|
||||
|
||||
class Index extends BaseController
|
||||
{
|
||||
function __construct(App $app)
|
||||
{
|
||||
$this->check_actions = [
|
||||
'#index' => []
|
||||
];
|
||||
parent::__construct($app);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$re = intval('y12') - 1;
|
||||
return ajaxSuccess($re);
|
||||
}
|
||||
}
|
||||
230
app/controller/Sys.php
Normal file
230
app/controller/Sys.php
Normal file
|
|
@ -0,0 +1,230 @@
|
|||
<?php
|
||||
|
||||
namespace app\controller;
|
||||
|
||||
use think\App;
|
||||
use app\BaseController;
|
||||
use Exception;
|
||||
use think\facade\Cache;
|
||||
use app\Constant;
|
||||
use think\facade\Config;
|
||||
use think\facade\Db;
|
||||
use app\service\ToolService;
|
||||
|
||||
class Sys extends BaseController
|
||||
{
|
||||
protected $service_tool = null;
|
||||
function __construct(
|
||||
App $app,
|
||||
ToolService $toolService
|
||||
) {
|
||||
$this->service_tool = $toolService;
|
||||
$this->className = 'api.Sys';
|
||||
$this->ignore_log_params = true;
|
||||
parent::__construct($app);
|
||||
}
|
||||
|
||||
/*
|
||||
# if ! pgrep -f zhihuitb_test > /dev/null; then
|
||||
# echo "zhihuitb_test stoped, to start";
|
||||
# nohup sh ./zhihuitb_test.sh > /dev/null 2>&1 &
|
||||
# else
|
||||
# echo "zhihuitb_test.sh runing";
|
||||
# fi
|
||||
|
||||
*/
|
||||
// 通用分割
|
||||
public function auto_deal_type_SegmentHDCommonImage() {
|
||||
$list = D('orders')->where(['deal_type' => 'SegmentHDCommonImage', 'deleted' => 0, 'status' => 'payed'])->where('deal_status', 'IN', ['init', 'ing'])->order('id ASC')->limit(2)->select();
|
||||
print_r($list);
|
||||
foreach ($list as $one) {
|
||||
if ($one['deal_status'] == 'ing') continue;
|
||||
if ($one['deal_status'] == 'init') {
|
||||
D('orders')->where(['id' => $one['id']])->update(['deal_status' => 'ing']);
|
||||
$deal_params = c_safe_to_json($one['deal_params']);
|
||||
$root_dir = root_path();
|
||||
$filepath = $root_dir . 'public' . $deal_params['path'];
|
||||
$imageUrl = $this->service_tool->tongYongFenGe($filepath);
|
||||
if ($imageUrl) {
|
||||
D('orders')->where(['id' => $one['id']])->update(['deal_result' => $imageUrl, 'deal_status' => 'done']);
|
||||
} else {
|
||||
D('orders')->where(['id' => $one['id']])->update(['deal_status' => 'fail']);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($list) == 0) {
|
||||
echo 'No Task';
|
||||
}
|
||||
}
|
||||
|
||||
// VIP 购买
|
||||
public function auto_deal_type_vip() {
|
||||
$list = D('orders')->where(['deal_type' => 'vip', 'deleted' => 0, 'status' => 'payed'])->where('deal_status', 'IN', ['init'])->order('id ASC')->select();
|
||||
foreach ($list as $one) {
|
||||
if ($one['deal_status'] == 'init') {
|
||||
D('orders')->where(['id' => $one['id']])->update(['deal_status' => 'ing']);
|
||||
$deal_params = c_safe_to_json($one['deal_params']);
|
||||
$num = $deal_params['num'];
|
||||
$order_no = $one['order_no'];
|
||||
$user_id = $one['user_id'];
|
||||
$user = D('user')->where(['id' => $user_id])->find();
|
||||
if (empty($user)) {
|
||||
D('orders')->where(['id' => $one['id']])->update(['deal_status' => 'fail']);
|
||||
$this->log_error('用户不存在:' . $user_id . ';order_no:'.$order_no, 'auto_deal_vip', 'auto_deal_vip');
|
||||
continue;
|
||||
}
|
||||
$now_expire_time = $user['vip_expire_time'];
|
||||
if (!$now_expire_time) {
|
||||
$now_expire_time = time();
|
||||
} else {
|
||||
$now_expire_time = strtotime($now_expire_time);
|
||||
}
|
||||
$now_expire_time = $now_expire_time + $num * 30 * 24 * 3600;
|
||||
$now_expire_time = date('Y-m-d', $now_expire_time) . ' 23:59:59';
|
||||
D('user')->where(['id' => $user_id])->update(['vip_expire_time' => $now_expire_time]);
|
||||
D('orders')->where(['id' => $one['id']])->update(['deal_result' => $now_expire_time, 'deal_status' => 'done']);
|
||||
}
|
||||
}
|
||||
if (count($list) == 0) {
|
||||
echo 'No Task';
|
||||
}
|
||||
}
|
||||
// 一寸照异步返回
|
||||
public function auto_deal_type_SegmentBody_01_cb($order_no) {
|
||||
$root_dir = root_path();
|
||||
$out_dir = $root_dir . 'public';
|
||||
$out_path = '/output/SegmentBody_01/' . $order_no . '.jpg';
|
||||
$filepath = $out_dir . $out_path;
|
||||
if (file_exists($filepath)) {
|
||||
D('orders')->where(['order_no' => $order_no])->update(['deal_result' => $out_path, 'deal_status' => 'done']);
|
||||
} else {
|
||||
D('orders')->where(['order_no' => $order_no])->update(['deal_status' => 'fail']);
|
||||
}
|
||||
return ajaxSuccess();
|
||||
}
|
||||
// 一寸照
|
||||
public function auto_deal_type_SegmentBody_01() {
|
||||
$list = D('orders')->where(['deal_type' => 'SegmentBody', 'deleted' => 0, 'status' => 'payed'])->where('deal_status', 'IN', ['init', 'ing'])->order('id ASC')->limit(2)->select();
|
||||
foreach ($list as $one) {
|
||||
if ($one['deal_status'] == 'ing') continue;
|
||||
if ($one['deal_status'] == 'init') {
|
||||
D('orders')->where(['id' => $one['id']])->update(['deal_status' => 'ing']);
|
||||
$deal_params = c_safe_to_json($one['deal_params']);
|
||||
$root_dir = root_path();
|
||||
$path = $root_dir . 'public' . $deal_params['path'];
|
||||
$color = $deal_params['color'];
|
||||
$order_no = $one['order_no'];
|
||||
$out_dir = $root_dir . 'public';
|
||||
$out_path = '/output/SegmentBody_01/' . $order_no . '.jpg';
|
||||
// 运行python
|
||||
echo 'python3 ./idcard/idcard.py -p ' . $path .' '. $color . ' ' . $out_dir . $out_path;
|
||||
// 执行回调结果
|
||||
echo "\n";
|
||||
echo "curl 'http://127.0.0.1/index.php/sys/auto_deal_type_SegmentBody_01_cb?order_no=" . $order_no . "' -H 'Host:zhihuitb.zhonganonline.top'";
|
||||
// echo 'python3'.c_json_encode($deal_params) . '_' . $order_id;
|
||||
// $imageUrl = $this->service_tool->tuPianShangSe($deal_params['path']);
|
||||
// if($imageUrl) {
|
||||
// D('orders')->where(['id'=>$one['id']])->update(['deal_result'=>$imageUrl,'deal_status'=>'done']);
|
||||
// } else {
|
||||
// D('orders')->where(['id'=>$one['id']])->update(['deal_status'=>'fail']);
|
||||
// }
|
||||
}
|
||||
}
|
||||
if (count($list) == 0) {
|
||||
echo 'No Task';
|
||||
}
|
||||
}
|
||||
|
||||
// 照片上色
|
||||
public function auto_deal_type_ColorizeImage_01() {
|
||||
$list = D('orders')->where(['deal_type' => 'ColorizeImage', 'deleted' => 0, 'status' => 'payed'])->where('deal_status', 'IN', ['init', 'ing'])->order('id ASC')->limit(2)->select();
|
||||
print_r($list);
|
||||
foreach ($list as $one) {
|
||||
if ($one['deal_status'] == 'ing') continue;
|
||||
if ($one['deal_status'] == 'init') {
|
||||
D('orders')->where(['id' => $one['id']])->update(['deal_status' => 'ing']);
|
||||
$deal_params = c_safe_to_json($one['deal_params']);
|
||||
$root_dir = root_path();
|
||||
$filepath = $root_dir . 'public' . $deal_params['path'];
|
||||
$imageUrl = $this->service_tool->tuPianShangSe($filepath);
|
||||
if ($imageUrl) {
|
||||
D('orders')->where(['id' => $one['id']])->update(['deal_result' => $imageUrl, 'deal_status' => 'done']);
|
||||
} else {
|
||||
D('orders')->where(['id' => $one['id']])->update(['deal_status' => 'fail']);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($list) == 0) {
|
||||
echo 'No Task';
|
||||
}
|
||||
}
|
||||
|
||||
public function timer_cancel_order() {
|
||||
D('orderx')->where(['status' => 'wait_pay'])->where('create_time', '<=', c_now(time() - 30 * 60))->update(['status' => 'cancel']);
|
||||
return ajaxSuccess();
|
||||
}
|
||||
|
||||
|
||||
public function clear_access_token() {
|
||||
$cache_key = Constant::$CACHE_ACCESS_TOKEN;
|
||||
Cache::set($cache_key, '');
|
||||
return '';
|
||||
}
|
||||
/**
|
||||
* 定时获取access_token
|
||||
* test ok
|
||||
* http://testwx.yunyoumg.com/index.php/api/sys/access_token
|
||||
*/
|
||||
public function access_token() {
|
||||
$cache_key = Constant::$CACHE_ACCESS_TOKEN;
|
||||
$env = env('app.envName', 'prod');
|
||||
if ($env == 'prod') {
|
||||
$cache_a_k = Cache::get($cache_key);
|
||||
// c_debug($cache_a_k);
|
||||
if ($cache_a_k) {
|
||||
if ($cache_a_k['time'] + 3600 >= time()) {
|
||||
return ajaxSuccess($cache_a_k);
|
||||
}
|
||||
}
|
||||
c_debug('重新获取小程序ac了');
|
||||
$appid = Config::get('app.APPID');
|
||||
$secret = Config::get('app.SECERT_KEY');
|
||||
$data = curl_get_https("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret);
|
||||
$data = json_decode($data, true);
|
||||
if (!array_key_exists('errorCode', $data)) {
|
||||
Cache::set($cache_key, [
|
||||
'access_token' => $data['access_token'],
|
||||
'time' => time(),
|
||||
], $data['expires_in'] * 1);
|
||||
return ajaxSuccess($data);
|
||||
}
|
||||
return ajaxFail($data, -1);
|
||||
}
|
||||
// $data = curl_get_https('https://www.yunyoumg.com/api/Collection/getMini');
|
||||
// $data = curl_get_https('https://mini.yunyoumg.com/index.php/api/sys/get_access_token');
|
||||
// $data = json_decode($data, true);
|
||||
// if (!array_key_exists('errorCode', $data)) {
|
||||
// Cache::set($cache_key, [
|
||||
// 'access_token' => $data['data']['accessToken'],
|
||||
// 'time' => time(),
|
||||
// ]);
|
||||
// return ajaxSuccess($data['data']['accessToken']);
|
||||
// }
|
||||
Cache::set($cache_key, $data['model']);
|
||||
}
|
||||
public function get_access_token() {
|
||||
$cache_key = Constant::$CACHE_ACCESS_TOKEN;
|
||||
$ac = Cache::get($cache_key);
|
||||
// echo json_encode([
|
||||
// 'data'=>[
|
||||
// 'accessToken'=>$ac['access_token'],
|
||||
// ]
|
||||
// ]);
|
||||
// exit();
|
||||
return ajaxSuccess($ac);
|
||||
}
|
||||
public function test($t) {
|
||||
$this->log_notice($t, 'feishu', 'feishu');
|
||||
return ajaxSuccess();
|
||||
}
|
||||
}
|
||||
602
app/controller/V1.php
Normal file
602
app/controller/V1.php
Normal file
|
|
@ -0,0 +1,602 @@
|
|||
<?php
|
||||
|
||||
namespace app\controller;
|
||||
|
||||
use think\App;
|
||||
use app\BaseController;
|
||||
use think\facade\Log;
|
||||
use think\exception\ValidateException;
|
||||
use app\AppCache;
|
||||
use think\facade\Cache;
|
||||
use app\Constant;
|
||||
use Exception;
|
||||
use think\facade\Config;
|
||||
use app\service\ToolService;
|
||||
|
||||
class V1 extends BaseController
|
||||
{
|
||||
protected $service_tool = null;
|
||||
function __construct(
|
||||
App $app,
|
||||
ToolService $toolService
|
||||
) {
|
||||
$this->service_tool = $toolService;
|
||||
$this->check_actions = [
|
||||
];
|
||||
$this->className = 'V1';
|
||||
$this->not_check_action_login = [
|
||||
'test',
|
||||
'pay_notify',
|
||||
'wx_login',
|
||||
];
|
||||
parent::__construct($app);
|
||||
}
|
||||
public function goods_list() {
|
||||
$list = D('goods')->where(['deleted' => 0])->order('sort ASC')->select();
|
||||
return ajaxSuccess($list);
|
||||
}
|
||||
public function test() {
|
||||
// $root_dir = root_path();
|
||||
// $filepath = $root_dir . '/public/uploads/' . 'zpss.jpg';
|
||||
// $re = $this->service_tool->tuPianShangSe($filepath);
|
||||
$re = $this->mark_order_yiCunZhao(2, '/uploads/ycz.jpg', 'white');
|
||||
return ajaxSuccess($re);
|
||||
}
|
||||
public function mark_order_vip($goods_id = '', $num = 1) {
|
||||
$deal_params = ['num' => $num];
|
||||
$goods = D('goods')->where(['id' => $goods_id, 'deleted' => 0])->find();
|
||||
if (empty($goods)) {
|
||||
return ajaxFail('不存在的服务', -1);
|
||||
}
|
||||
$order_no = s_order_id_render('Z');
|
||||
$order = [
|
||||
'user_id' => $this->user_id,
|
||||
'goods_id' => $goods_id,
|
||||
// 'from_user_id' => $share['from_user_id'],
|
||||
'create_time' => c_now(),
|
||||
'status' => 'wait_pay',
|
||||
'order_no' => $order_no,
|
||||
'price' => $goods['price'] * $num,
|
||||
'deal_type' => $goods['deal_type'],
|
||||
'funct_name' => $goods['funct_name'],
|
||||
'deal_params' => c_json_encode($deal_params),
|
||||
];
|
||||
D('orders')->insert($order);
|
||||
return ajaxSuccess(['order_no' => $order_no]);
|
||||
}
|
||||
public function mark_order_tongYongFenGe($goods_id='',$path='') {
|
||||
$deal_params = ['path' => $path];
|
||||
return $this->mark_order_base($goods_id, $deal_params);
|
||||
}
|
||||
// color: red blue white;
|
||||
public function mark_order_yiCunZhao($goods_id = '', $path = '', $color = '') {
|
||||
$deal_params = ['path' => $path,
|
||||
'color' => $color];
|
||||
return $this->mark_order_base($goods_id, $deal_params);
|
||||
}
|
||||
public function mark_order_zhaopianshangse($goods_id = '', $path = '') {
|
||||
$deal_params = ['path' => $path];
|
||||
return $this->mark_order_base($goods_id, $deal_params);
|
||||
}
|
||||
private function mark_order_base($goods_id, $deal_params) {
|
||||
// 是否是vip
|
||||
$is_vip = strtotime($this->user_info['vip_expire_time'] ?: c_now()) > time();
|
||||
if (!$is_vip) {
|
||||
$goods_free_use_limit = D('config')->where(['k' => 'goods_free_use_limit'])->value('v');
|
||||
$find_user_use = D('user_use_cnt')->where(['goods_id' => $goods_id, 'user_id' => $this->user_id])->find();
|
||||
$use_cnt = 0;
|
||||
if($find_user_use) {
|
||||
$use_cnt = $find_user_use['use_cnt'];
|
||||
}else{
|
||||
D('user_use_cnt')->insert(['goods_id' => $goods_id, 'user_id' => $this->user_id, 'use_cnt'=>0]);
|
||||
}
|
||||
if ($use_cnt >= $goods_free_use_limit) {
|
||||
return ajaxFail('免费次数使用结束,请先充值', -1);
|
||||
}
|
||||
}
|
||||
$goods = D('goods')->where(['id' => $goods_id, 'deleted' => 0])->find();
|
||||
if (empty($goods)) {
|
||||
return ajaxFail('不存在的服务', -2);
|
||||
}
|
||||
$order_no = s_order_id_render('Z');
|
||||
$order = [
|
||||
'user_id' => $this->user_id,
|
||||
'goods_id' => $goods_id,
|
||||
// 'from_user_id' => $share['from_user_id'],
|
||||
'create_time' => c_now(),
|
||||
'status' => 'wait_pay',
|
||||
'order_no' => $order_no,
|
||||
'price' => $goods['price'],
|
||||
'deal_type' => $goods['deal_type'],
|
||||
'funct_name' => $goods['funct_name'],
|
||||
'deal_params' => c_json_encode($deal_params),
|
||||
];
|
||||
D('orders')->insert($order);
|
||||
D('user_use_cnt')->where(['goods_id' => $goods_id, 'user_id' => $this->user_id])->inc('use_cnt');
|
||||
$this->pay_notify($order_no);
|
||||
return ajaxSuccess(['order_no' => $order_no]);
|
||||
}
|
||||
public function order_list($page = 1) {
|
||||
$list = D('orders')->where(['deleted' => 0, 'user_id' => $this->user_id])->where(['status' => 'payed'])->page($page, 10)->order('id DESC')->select();
|
||||
return ajaxSuccess($list);
|
||||
}
|
||||
|
||||
public function config_one($k) {
|
||||
$v = D('config')->where(['k' => $k])->value('v');
|
||||
$v = c_safe_to_json($v, $v);
|
||||
return ajaxSuccess($v);
|
||||
}
|
||||
|
||||
public function configs($ks = '') {
|
||||
$model = D('config');
|
||||
if ($ks) {
|
||||
$model->where('k', 'in', $ks);
|
||||
}
|
||||
$all_enums = $model->select();
|
||||
$re = [];
|
||||
foreach ($all_enums as $one) {
|
||||
$re[$one['k']] = c_safe_to_json($one['v'], $one['v']);
|
||||
}
|
||||
//
|
||||
return ajaxSuccess($re);
|
||||
}
|
||||
public function my() {
|
||||
$info = $this->user_info;
|
||||
if ($info['is_share']) {
|
||||
$info['price_sum'] = D('orderx')->where(['status' => 'payed'])->where(['from_user_id' => $this->user_id])->sum('price');
|
||||
$info['share_cnt'] = D('share')->where(['from_user_id' => $this->user_id])->count();
|
||||
$info['share_view_cnt'] = D('share')->where(['from_user_id' => $this->user_id])->sum('view_cnt');
|
||||
}
|
||||
$show_vip_link = $info['is_share'] ? true : false;
|
||||
if (!$show_vip_link) {
|
||||
if (D('orderx')->where(['status' => 'payed'])->where(['user_id' => $this->user_id])->find()) {
|
||||
$show_vip_link = true;
|
||||
}
|
||||
}
|
||||
$info['show_vip_link'] = $show_vip_link;
|
||||
$info['payed_vip_link'] = D('config')->where(['k' => 'payed_vip_link'])->value('v');
|
||||
return ajaxSuccess($info);
|
||||
}
|
||||
public function set_name($name = '') {
|
||||
D('user')->where(['id' => $this->user_id])->update(['real_name' => $name]);
|
||||
return ajaxSuccess();
|
||||
}
|
||||
|
||||
public function bind_auth_phone($code = '') {
|
||||
$row_user = D('user')->where([
|
||||
'id' => $this->user_id,
|
||||
])->find();
|
||||
|
||||
$cache_a_k = Cache::get(Constant::$CACHE_ACCESS_TOKEN);
|
||||
$qdata = [
|
||||
'code' => $code,
|
||||
];
|
||||
$re_data = curl_post_https('https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=' . $cache_a_k['access_token'], json_encode($qdata));
|
||||
$this->log_notice([$re_data], '授权手机号返回', 'bind_auth_phone');
|
||||
// $session_key = $row_user['session_key'];
|
||||
// $data = decrypt_wx_data($encrypted_data, $iv, $session_key);
|
||||
// if (is_int($data) && $data < 0) {
|
||||
// return ajaxFail('数据解析失败', -1);
|
||||
// }
|
||||
// /*
|
||||
// {
|
||||
// "phoneNumber": "13580006666",
|
||||
// "purePhoneNumber": "13580006666",
|
||||
// "countryCode": "86",
|
||||
// "watermark":
|
||||
// {
|
||||
// "appid":"APPID",
|
||||
// "timestamp": TIMESTAMP
|
||||
// }
|
||||
// }
|
||||
// */
|
||||
// //更新数据
|
||||
// $pure_phone_number = $data['purePhoneNumber'];
|
||||
// $country_code = $data['countryCode'];
|
||||
$re_data_json = c_safe_to_json($re_data);
|
||||
if (isset($re_data_json['errcode']) && $re_data_json['errcode'] == 0) {
|
||||
$pure_phone_number = $re_data_json['phone_info']['purePhoneNumber'];
|
||||
$country_code = $re_data_json['phone_info']['countryCode'];
|
||||
D('user')->where([
|
||||
'id' => $this->user_id,
|
||||
])->update([
|
||||
'phone' => $pure_phone_number,
|
||||
'phone_country_code' => $country_code,
|
||||
]);
|
||||
return ajaxSuccess($pure_phone_number);
|
||||
}
|
||||
return ajaxFail('获取手机号失败', -1);
|
||||
}
|
||||
|
||||
public function static_data_get($id) {
|
||||
$row = D('static_data')->where(['id' => $id])->find();
|
||||
return ajaxSuccess($row);
|
||||
}
|
||||
|
||||
/**
|
||||
*小程序上传文件
|
||||
*/
|
||||
public function wx_upload() {
|
||||
$file = request()->file('img_file');
|
||||
if ($file) {
|
||||
try {
|
||||
validate([
|
||||
'img_file' => [
|
||||
'fileSize' => (20 * 1024 * 1024),
|
||||
'fileExt' => ['png', 'jpg', 'jpeg'],
|
||||
]
|
||||
])->check(['img_file' => $file]);
|
||||
$savename = \think\facade\Filesystem::disk('public')->putFile(date('Y-m-d'), $file, 'md5');
|
||||
return ajaxSuccess([
|
||||
'path' => '/uploads/' . str_replace('\\', '/', $savename),
|
||||
]);
|
||||
} catch (ValidateException $e) {
|
||||
// 上传失败获取错误信息
|
||||
$this->log_notice($e->getMessage(), '上传失败获取错误信息', 'wx_upload');
|
||||
return ajaxFail($e->getMessage(), -2);
|
||||
}
|
||||
}
|
||||
|
||||
$file = request()->file('audio_file');
|
||||
if ($file) {
|
||||
try {
|
||||
validate([
|
||||
'audio_file' => [
|
||||
'fileSize' => (20 * 1024 * 1024),
|
||||
'fileExt' => ['mp3'],
|
||||
]
|
||||
])->check(['audio_file' => $file]);
|
||||
$savename = \think\facade\Filesystem::disk('public')->putFile(date('Y-m-d'), $file, 'md5');
|
||||
return ajaxSuccess([
|
||||
'path' => '/uploads/' . str_replace('\\', '/', $savename),
|
||||
]);
|
||||
} catch (ValidateException $e) {
|
||||
// 上传失败获取错误信息
|
||||
return ajaxFail($e->getMessage(), -2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$file = request()->file('video_file');
|
||||
if ($file) {
|
||||
try {
|
||||
validate([
|
||||
'video_file' => [
|
||||
'fileSize' => (200 * 1024 * 1024),
|
||||
'fileExt' => ['mp4'],
|
||||
]
|
||||
])->check(['video_file' => $file]);
|
||||
$savename = \think\facade\Filesystem::disk('public')->putFile(date('Y-m-d'), $file, 'md5');
|
||||
return ajaxSuccess([
|
||||
'path' => '/uploads/' . str_replace('\\', '/', $savename),
|
||||
]);
|
||||
} catch (ValidateException $e) {
|
||||
// 上传失败获取错误信息
|
||||
return ajaxFail($e->getMessage(), -3);
|
||||
}
|
||||
}
|
||||
return ajaxFail('未选择上传文件,请重试', -3);
|
||||
}
|
||||
public function wx_login($code) {
|
||||
if ($code != 'test') {
|
||||
$data = code_2_session($code);
|
||||
if ($data == null) {
|
||||
return ajaxFail('授权失败', -1);
|
||||
}
|
||||
} else {
|
||||
$data['openid'] = 'o3CkR7ecDQlsBfAW88Cmjin4YkmI';
|
||||
$data['unionid'] = 'oV_Fvs_X63XiA1UDc2Bvx1YbD3bk';
|
||||
$data['session_key'] = 'HBwb0sNhajpzzgM4nuMt6w==';
|
||||
}
|
||||
|
||||
$openid = $data['openid'];
|
||||
$unionid = $data['unionid'] ?? '';
|
||||
$session_key = $data['session_key'];
|
||||
$row_user = D('user')->where('openid', $openid)->where(['deleted' => 0])->find();
|
||||
if (empty($row_user)) {
|
||||
D('user')->insert([
|
||||
'union_id' => $unionid,
|
||||
'openid' => $openid,
|
||||
'session_key' => $session_key,
|
||||
'create_time' => date('Y-m-d H:i:s', time()),
|
||||
]);
|
||||
$user_id = D('user')->getLastInsID();
|
||||
}
|
||||
//update
|
||||
else {
|
||||
$user_id = $row_user['id'];
|
||||
$update = [
|
||||
'session_key' => $session_key,
|
||||
// 'union_id'=>$unionid,
|
||||
];
|
||||
if ($unionid) {
|
||||
$update['union_id'] = $unionid;
|
||||
}
|
||||
D('user')->where('openid', $openid)->update($update);
|
||||
}
|
||||
// c_debug('有人登录了:' . $user_id);
|
||||
return ajaxSuccess([
|
||||
// 'union_id' => $unionid,
|
||||
'user_id' => a_encode($user_id . '|' . time()),
|
||||
'openid' => $openid,
|
||||
'phone' => empty($row_user) ? '' : $row_user['phone'],
|
||||
]);
|
||||
}
|
||||
public function login_id($id=0) {
|
||||
$row_user = D('user')->where(['id'=>$id])->find();
|
||||
setcookie('user_id', a_encode($id . '|' . time()));
|
||||
return ajaxSuccess([
|
||||
// 'union_id' => $unionid,
|
||||
'user_id' => a_encode($id . '|' . time()),
|
||||
'openid' => $row_user['openid'],
|
||||
'phone' => empty($row_user) ? '' : $row_user['phone'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function fetch_order($order_no) {
|
||||
$order = D('orders')->where([
|
||||
'order_no' => $order_no,
|
||||
'user_id' => $this->user_id,
|
||||
])->find();
|
||||
return ajaxSuccess(c_filter_property($order, ['deleted', 'pay_wx_data', 'need_auto_refund', 'deal_type', 'deal_params', 'deal_result'], true));
|
||||
}
|
||||
|
||||
public function pay_order($order_no = '') {
|
||||
$order = D('orders')->where([
|
||||
'order_no' => $order_no,
|
||||
// 'user_id' => $this->user_id,
|
||||
])->find();
|
||||
if (empty($order)) {
|
||||
return ajaxFail('不存在的订单', -2);
|
||||
}
|
||||
$price = intval($order['price']);
|
||||
// $debug = false;
|
||||
// $debug = Config::get('app.APP_DEBUG');
|
||||
// if ($debug) {
|
||||
// $price = 1;
|
||||
// }
|
||||
$appid = Config::get('app.APPID');
|
||||
$body = '商城订单' . $order_no;
|
||||
$mch_id = Config::get('app.MCH_ID');
|
||||
$pay_url = Config::get('app.PAY_NOTIFY_URL_SHOP');
|
||||
$key = Config::get('app.PAY_KEY');
|
||||
$nonce_str = '0123456789';
|
||||
$openid = $this->user_info['openid'];
|
||||
$create_ip = '127.0.0.1';
|
||||
$need_encode_str = "appid=" . $appid
|
||||
. "&body=" . $body
|
||||
. "&mch_id=" . $mch_id
|
||||
. "&nonce_str=" . $nonce_str
|
||||
. "¬ify_url=" . $pay_url
|
||||
. "&openid=" . $openid
|
||||
. "&out_trade_no=" . $order_no
|
||||
. "&sign_type=MD5"
|
||||
. "&spbill_create_ip=" . $create_ip
|
||||
. "&total_fee=" . $price
|
||||
. "&trade_type=JSAPI"
|
||||
. "&key=" . $key;
|
||||
$this->log_notice($need_encode_str, '$need_encode_str', 'pay_order');
|
||||
$sign = strtoupper(md5($need_encode_str));
|
||||
$xml = '<xml>'
|
||||
. '<appid>' . $appid . '</appid>'
|
||||
. '<body><![CDATA[' . $body . ']]></body>'
|
||||
. '<mch_id>' . $mch_id . '</mch_id>'
|
||||
. '<nonce_str>' . $nonce_str . '</nonce_str>'
|
||||
. '<notify_url>' . $pay_url . '</notify_url>'
|
||||
. '<openid>' . $openid . '</openid>'
|
||||
. '<out_trade_no>' . $order_no . '</out_trade_no>'
|
||||
. '<sign_type>MD5</sign_type>'
|
||||
. '<spbill_create_ip>' . $create_ip . '</spbill_create_ip>'
|
||||
. '<total_fee>' . $price . '</total_fee>'
|
||||
. '<trade_type>JSAPI</trade_type>'
|
||||
. '<sign>' . $sign . '</sign>'
|
||||
. '</xml>';
|
||||
$res_map = \s_make_wx_order($xml);
|
||||
// Log::write(json_encode($res_map), 'notice');
|
||||
$this->log_notice($res_map, '请求支付参数', 'pay_order');
|
||||
if ($res_map['return_code'] == 'SUCCESS') {
|
||||
$timeStamp = time();
|
||||
$paySign = md5('appId=' . $appid
|
||||
. '&nonceStr=' . $nonce_str
|
||||
. '&package=prepay_id=' . $res_map['prepay_id']
|
||||
. '&signType=MD5'
|
||||
. '&timeStamp=' . $timeStamp
|
||||
. '&key=' . $key);
|
||||
return ajaxSuccess([
|
||||
'timeStamp' => '' . $timeStamp,
|
||||
'nonceStr' => $nonce_str,
|
||||
'package' => 'prepay_id=' . $res_map['prepay_id'],
|
||||
'signType' => 'MD5',
|
||||
'paySign' => $paySign,
|
||||
]);
|
||||
}
|
||||
return ajaxFail('调用支付接口失败', -3);
|
||||
}
|
||||
|
||||
// 微信支付回调
|
||||
public function pay_notify($_test_success_order_no = '') {
|
||||
$str = file_get_contents('php://input');
|
||||
if ($_test_success_order_no) {
|
||||
$str = '';
|
||||
}
|
||||
// 模拟支付成功
|
||||
if (!$str && $_test_success_order_no) {
|
||||
$map = ['out_trade_no' => $_test_success_order_no,
|
||||
'系统默认支付成功,0元或测试单'];
|
||||
} else {
|
||||
$this->log_notice($str, '支付通知', 'pay_notify');
|
||||
$map = c_read_xml_to_map($str);
|
||||
if (empty($map) || !isset($map['out_trade_no'])) {
|
||||
$this->log_warn($map['out_trade_no'], '错误的支付消息', 'pay_notify');
|
||||
echo '<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[错误的消息]]></return_msg></xml>';
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
$order_no = $map['out_trade_no'];
|
||||
$notify_return = 0;
|
||||
$order_detail = D('orders')->where(['order_no' => $order_no])->find(); // 查询包含已删除
|
||||
if (empty($order_detail)) {
|
||||
$notify_return = -1;
|
||||
}
|
||||
if ($order_detail['status'] != 'wait_pay') {
|
||||
// 只记录,不失败
|
||||
$this->log_warn($map['out_trade_no'], '订单状态不正确', 'pay_notify');
|
||||
// $this->service_any->sendqywx_test($map['out_trade_no'] . '订单状态不正确','');
|
||||
if ($order_detail['status'] != 'payed') {
|
||||
D('orders')->where(['id' => $order_detail['id']])->update(['need_auto_refund' => 1]);
|
||||
}
|
||||
}
|
||||
//超时支付和正常支付都算能支付
|
||||
D('orders')->where(['id' => $order_detail['id'], 'deleted' => 0])->update(['status' => 'payed', 'pay_time' => c_now(), 'pay_wx_data' => $str]);
|
||||
if ($notify_return == -1) {
|
||||
if ($_test_success_order_no) {
|
||||
return ajaxFail([$order_no], '订单ID不存在', 'pay_notify');
|
||||
}
|
||||
echo '<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[订单ID不存在]]></return_msg></xml>';
|
||||
} else if ($notify_return == 0) {
|
||||
if ($_test_success_order_no) {
|
||||
return ajaxSuccess();
|
||||
}
|
||||
echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
|
||||
}
|
||||
if ($_test_success_order_no) {
|
||||
return ajaxFail([$order_no], '支付通知', 'pay_notify');
|
||||
}
|
||||
}
|
||||
//
|
||||
public function ______unuse_function_start______() {}
|
||||
public function notice_list() {
|
||||
$list = D('notice')->where(['delete' => 0])
|
||||
->where('start_time', '<=', date('Y-m-d H:i:s', time()))
|
||||
->where('end_time', '>=', date('Y-m-d H:i:s', time()))->select();
|
||||
return ajaxSuccess(c_filter_property_list($list, ['id', 'title', 'content', 'create_time']));
|
||||
}
|
||||
public function notice_deital($id) {
|
||||
$detail = D('notice')->where(['id' => $id, 'delete' => 0])->find();
|
||||
return ajaxSuccess(\c_filter_property($detail, ['delete', 'start_time', 'end_time'], true));
|
||||
}
|
||||
public function mark_order_info($order_no, $name = '', $phone = '', $position = '') {
|
||||
D('orderx')->where(['order_no' => $order_no])->update([
|
||||
'name' => $name,
|
||||
'phone' => $phone,
|
||||
'position' => $position,
|
||||
]);
|
||||
return ajaxSuccess();
|
||||
}
|
||||
|
||||
public function make_order($share_id) {
|
||||
$share = D('share')->where(['id' => $share_id, 'deleted' => 0])->find();
|
||||
if (empty($share)) {
|
||||
return ajaxFail('链接已失效,请联系客服');
|
||||
}
|
||||
if ($share['expire_time']) {
|
||||
if ($share['expire_time'] <= c_now()) {
|
||||
return ajaxFail('购买链接已过期,请重新联系客服');
|
||||
}
|
||||
}
|
||||
$order_no = s_order_id_render('P');
|
||||
$order = [
|
||||
'user_id' => $this->user_id,
|
||||
'share_id' => $share_id,
|
||||
'from_user_id' => $share['from_user_id'],
|
||||
'create_time' => c_now(),
|
||||
'status' => 'wait_pay',
|
||||
'order_no' => $order_no,
|
||||
'price' => $share['price'],
|
||||
'buy_type' => $share['buy_type'],
|
||||
];
|
||||
D('orderx')->insert($order);
|
||||
return ajaxSuccess(['order_no' => $order_no]);
|
||||
}
|
||||
public function get_share($id) {
|
||||
$data = D('share')->where(['id' => $id, 'deleted' => 0])->find();
|
||||
// if(strtotime($data['expire_time']) >= time()) {
|
||||
// return ajaxFail('支付链接已超时,请联系客服');
|
||||
// }
|
||||
// $v = D('config')->where(['k' => 'buy_types'])->value('v');
|
||||
// $data['buy_types'] = c_safe_to_json($v, $v);
|
||||
// $v = D('config')->where(['k' => 'tip_before_pay'])->value('v');
|
||||
// $data['tip_before_pay'] = c_safe_to_json($v, $v);
|
||||
// $v = D('config')->where(['k' => 'tip_after_pay'])->value('v');
|
||||
// $data['tip_after_pay'] = c_safe_to_json($v, $v);
|
||||
|
||||
return ajaxSuccess($data);
|
||||
}
|
||||
public function view_share($id) {
|
||||
D('share')->where(['id' => $id, 'deleted' => 0])->inc('view_cnt')->update();
|
||||
return ajaxSuccess();
|
||||
}
|
||||
public function del_share($id) {
|
||||
D('share')->where(['id' => $id])->update(['deleted' => 1]);
|
||||
return ajaxSuccess();
|
||||
}
|
||||
public function share_link_list($page = 1, $pageSize = 10) {
|
||||
$list = D('share')->where(['from_user_id' => $this->user_id, 'deleted' => 0])->where('expire_time', '>=', c_now())->page($page, $pageSize)->select();
|
||||
return ajaxSuccess($list);
|
||||
}
|
||||
public function create_share($price, $expireDate, $buy_type = '') {
|
||||
if (!$this->user_info['is_share']) {
|
||||
return ajaxFail('您暂无分销权限', -1);
|
||||
}
|
||||
$data = [
|
||||
'from_user_id' => $this->user_id,
|
||||
'price' => $price * 100,
|
||||
'expire_time' => $expireDate . ' 23:59:59',
|
||||
'create_time' => c_now(),
|
||||
'title' => '推荐您购买' . $buy_type,
|
||||
'img' => 'http://cdn.zhonganonline.top/liiistem/static/liii_icon.png',
|
||||
'buy_type' => $buy_type,
|
||||
];
|
||||
D('share')->insert($data);
|
||||
$id = D('share')->getLastInsID();
|
||||
$data['id'] = $id;
|
||||
// $data['path'] =
|
||||
return ajaxSuccess($data);
|
||||
}
|
||||
public function mark($id, $remark = '') {
|
||||
$one = D('orderx')->where(['id' => $id, 'from_user_id' => $this->user_id])->find();
|
||||
if (empty($one)) {
|
||||
return ajaxFail('不存在的内容', -1);
|
||||
}
|
||||
D('orderx')->where(['id' => $id])->update(['remark' => $remark]);
|
||||
return ajaxSuccess();
|
||||
}
|
||||
public function share_list($page = 1, $status = '') {
|
||||
$model = D('orderx')->where(['from_user_id' => $this->user_id]);
|
||||
if ($status) {
|
||||
$model->where(['status' => $status]);
|
||||
} else {
|
||||
$model->where('status', 'IN', ['payed', 'wait_pay']);
|
||||
}
|
||||
$list = $model->page($page, 10)->order('id DESC')->select();
|
||||
return ajaxSuccess($list);
|
||||
}
|
||||
|
||||
public function banner_list() {
|
||||
$where = ['deleted' => 0];
|
||||
$list = D('banner')->where($where)->order('id DESC')->select();
|
||||
return ajaxSuccess($list);
|
||||
}
|
||||
|
||||
public function news_list($page = 1, $pageSize = 10) {
|
||||
$where = ['deleted' => 0,
|
||||
'status' => 1];
|
||||
$model = D('news')->order('id DESC')->where($where);
|
||||
$list = $model->page($page, $pageSize)->select();
|
||||
return ajaxSuccess($list);
|
||||
}
|
||||
|
||||
public function news_detail($id = '') {
|
||||
$detail = D('news')->where(['id' => $id, 'deleted' => 0])->find();
|
||||
if (!$detail) {
|
||||
return ajaxFail('数据不存在', -1);
|
||||
}
|
||||
$detail['view_cnt'] = $detail['view_cnt'] + 1;
|
||||
D('news')->where(['id' => $id, 'deleted' => 0])->update(['view_cnt' => $detail['view_cnt']]);
|
||||
return ajaxSuccess([
|
||||
'detail' => $detail,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
15
app/event.php
Normal file
15
app/event.php
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
// 事件定义文件
|
||||
return [
|
||||
'bind' => [],
|
||||
|
||||
'listen' => [
|
||||
'AppInit' => [],
|
||||
'HttpRun' => [],
|
||||
'HttpEnd' => [],
|
||||
'LogLevel' => [],
|
||||
'LogWrite' => [],
|
||||
],
|
||||
|
||||
'subscribe' => [],
|
||||
];
|
||||
12
app/exceptions/NoAccessException.php
Normal file
12
app/exceptions/NoAccessException.php
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace app\exceptions;
|
||||
|
||||
use think\Exception;
|
||||
|
||||
/**
|
||||
* 权限失效异常类
|
||||
*/
|
||||
class NoAccessException extends Exception
|
||||
{
|
||||
}
|
||||
12
app/exceptions/NotLoginException.php
Normal file
12
app/exceptions/NotLoginException.php
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace app\exceptions;
|
||||
|
||||
use think\Exception;
|
||||
|
||||
/**
|
||||
* 登录失效异常类
|
||||
*/
|
||||
class NotLoginException extends Exception
|
||||
{
|
||||
}
|
||||
12
app/exceptions/ParamsValidateException.php
Normal file
12
app/exceptions/ParamsValidateException.php
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace app\exceptions;
|
||||
|
||||
use think\Exception;
|
||||
|
||||
/**
|
||||
* 参数校验异常类
|
||||
*/
|
||||
class ParamsValidateException extends Exception
|
||||
{
|
||||
}
|
||||
10
app/middleware.php
Normal file
10
app/middleware.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
// 全局中间件定义文件
|
||||
return [
|
||||
// 全局请求缓存
|
||||
// \think\middleware\CheckRequestCache::class,
|
||||
// 多语言加载
|
||||
// \think\middleware\LoadLangPack::class,
|
||||
// Session初始化
|
||||
// \think\middleware\SessionInit::class
|
||||
];
|
||||
9
app/provider.php
Normal file
9
app/provider.php
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
use app\ExceptionHandle;
|
||||
use app\Request;
|
||||
|
||||
// 容器Provider定义文件
|
||||
return [
|
||||
'think\Request' => Request::class,
|
||||
'think\exception\Handle' => ExceptionHandle::class,
|
||||
];
|
||||
9
app/service.php
Normal file
9
app/service.php
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
use app\AppService;
|
||||
|
||||
// 系统服务定义文件
|
||||
// 服务在完成全局初始化之后执行
|
||||
return [
|
||||
AppService::class,
|
||||
];
|
||||
51
app/service/BaseService.php
Normal file
51
app/service/BaseService.php
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace app\service;
|
||||
|
||||
use think\Service;
|
||||
use think\facade\Log;
|
||||
use think\exception\ErrorException;
|
||||
|
||||
class BaseService extends Service
|
||||
{
|
||||
private $className = '';
|
||||
public function __construct($className)
|
||||
{
|
||||
$this->className = $className;
|
||||
}
|
||||
protected function log_notice($any, $msg = '', $tag = 'log_notice')
|
||||
{
|
||||
if ($any instanceof ErrorException || $any instanceof Exception) {
|
||||
$str = c_formate_exception($any);
|
||||
} else {
|
||||
$str = json_encode($any, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
Log::write('[' . $this->className . ']' . '[' . $tag . ']' . '[' . $msg . ']' . '[' . $str . ']', 'NOTICE');
|
||||
}
|
||||
protected function log_warn($any, $msg = '', $tag = 'log_warn')
|
||||
{
|
||||
if ($any instanceof ErrorException || $any instanceof Exception) {
|
||||
$str = c_formate_exception($any);
|
||||
} else {
|
||||
$str = json_encode($any, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
Log::write('[' . $this->className . ']' . '[' . $tag . ']' . '[' . $msg . ']' . '[' . json_encode($any, JSON_UNESCAPED_UNICODE) . ']', 'WARN');
|
||||
}
|
||||
protected function log_error($any, $msg = '', $tag = 'log_error')
|
||||
{
|
||||
if ($any instanceof ErrorException || $any instanceof Exception) {
|
||||
$str = c_formate_exception($any);
|
||||
} else {
|
||||
$str = json_encode($any, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
Log::write('[' . $this->className . ']' . '[' . $tag . ']' . '[' . $msg . ']' . '[' . json_encode($any, JSON_UNESCAPED_UNICODE) . ']', 'ERROR');
|
||||
}
|
||||
protected function alarm($type = '', $content = '')
|
||||
{
|
||||
D('alarm')->insert([
|
||||
'type' => $type,
|
||||
'content' => $content,
|
||||
'create_time' => c_now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
177
app/service/ToolService.php
Normal file
177
app/service/ToolService.php
Normal file
|
|
@ -0,0 +1,177 @@
|
|||
<?php
|
||||
|
||||
namespace app\service;
|
||||
|
||||
use app\service\BaseService;
|
||||
use app\AppCache;
|
||||
use think\facade\Config;
|
||||
use AlibabaCloud\SDK\Imageenhan\V20190930\Imageenhan;
|
||||
use AlibabaCloud\SDK\Imageseg\V20191230\Imageseg;
|
||||
use \Exception;
|
||||
use AlibabaCloud\Tea\Utils\Utils;
|
||||
use Darabonba\OpenApi\Models\Config as DaraConfig;
|
||||
use AlibabaCloud\SDK\Imageenhan\V20190930\Models\ColorizeImageAdvanceRequest;
|
||||
use AlibabaCloud\SDK\Imageseg\V20191230\Models\SegmentCommonImageAdvanceRequest;
|
||||
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
|
||||
use GuzzleHttp\Psr7\Stream;
|
||||
|
||||
class ToolService extends BaseService
|
||||
{
|
||||
|
||||
private $access_key_id = 'LTAI5tE6gkXQqJBbCxFfo4hv';
|
||||
private $access_secret = 'pziJRQfXlev3vEIY4dHuB6C7E73Uv6';
|
||||
private $sign_name = '';
|
||||
private $imgClient = null;
|
||||
public function __construct() {
|
||||
parent::__construct('ToolService');
|
||||
$this->config = new DaraConfig([
|
||||
"accessKeyId" => $this->access_key_id,
|
||||
"accessKeySecret" => $this->access_secret,
|
||||
]);
|
||||
}
|
||||
|
||||
public function tongYongFenGe($imgUrl) {
|
||||
$this->config->endpoint = "imageseg.cn-shanghai.aliyuncs.com";
|
||||
$client = new Imageseg($this->config);
|
||||
$file = fopen($imgUrl, 'rb');
|
||||
$stream = new Stream($file);
|
||||
$segmentCommonImageAdvanceRequest = new SegmentCommonImageAdvanceRequest([
|
||||
"imageURLObject" => $stream,
|
||||
"returnForm" => "whiteBK"
|
||||
]);
|
||||
$runtime = new RuntimeOptions([]);
|
||||
try {
|
||||
$resp = $client->segmentCommonImageAdvance($segmentCommonImageAdvanceRequest, $runtime);
|
||||
# 获取整体结果
|
||||
$json_str = Utils::toJSONString($resp->body);
|
||||
$json = c_safe_to_json($json_str);
|
||||
// return ['code'=>0,$json];
|
||||
$this->log_notice($json, '照片上色结果', 'tuPianShangSe');
|
||||
return $json['Data']['ImageURL'] ?? '';
|
||||
} catch (Exception $exception) {
|
||||
# 获取整体报错信息
|
||||
$this->log_error(Utils::toJSONString($exception), '照片上色失败', 'tuPianShangSe');
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function tuPianShangSe($imgUrl) {
|
||||
$this->config->endpoint = "imageenhan.cn-shanghai.aliyuncs.com";
|
||||
$client = new Imageenhan($this->config);
|
||||
$file = fopen($imgUrl, 'rb');
|
||||
//$stream = new Stream($file);
|
||||
// 场景二,使用任意可访问的url
|
||||
// $file = fopen('http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageenhan/ColorizeImage/ColorizeImage1.jpg', 'rb');
|
||||
$stream = new Stream($file);
|
||||
$colorizeImageAdvanceRequest = new ColorizeImageAdvanceRequest([
|
||||
"imageURLObject" => $stream
|
||||
]);
|
||||
$runtime = new RuntimeOptions([]);
|
||||
try {
|
||||
$resp = $client->colorizeImageAdvance($colorizeImageAdvanceRequest, $runtime);
|
||||
# 获取整体结果
|
||||
$json_str = Utils::toJSONString($resp->body);
|
||||
$json = c_safe_to_json($json_str);
|
||||
// return ['code'=>0,$json];
|
||||
$this->log_notice($json, '照片上色结果', 'tuPianShangSe');
|
||||
return $json['Data']['ImageURL'] ?? '';
|
||||
} catch (Exception $exception) {
|
||||
# 获取整体报错信息
|
||||
$this->log_error(Utils::toJSONString($exception), '照片上色失败', 'tuPianShangSe');
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
// private function base($options_query): bool
|
||||
// {
|
||||
// $is_prod = false;
|
||||
// if (env('app.envName', 'prod') == 'prod') {
|
||||
// $is_prod = true;
|
||||
// }
|
||||
// if (!$is_prod) {
|
||||
// $this->log_notice($options_query, '', 'base');
|
||||
// if (!isset($options_query['Test'])) {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// $options_query['RegionId'] = 'cn-hangzhou';
|
||||
// $options_query['SignName'] = $this->sign_name;
|
||||
// try {
|
||||
// $result = AlibabaCloud::rpc()
|
||||
// ->product('Dysmsapi')
|
||||
// // ->scheme('https') // https | http
|
||||
// ->version('2017-05-25')
|
||||
// ->action('SendSms')
|
||||
// ->method('POST')
|
||||
// ->host('dysmsapi.aliyuncs.com')
|
||||
// ->options([
|
||||
// 'query' => $options_query
|
||||
// ])
|
||||
// ->request();
|
||||
// $this->log_notice(['发送结果:' => $result->toArray(), "发送内容" => $options_query], '短信发送成功', 'base');
|
||||
// return true;
|
||||
// } catch (ClientException $e) {
|
||||
// $this->log_error(['发送结果:' => $e->getErrorMessage(), "发送内容" => $options_query], '短信发送失败', 'base');
|
||||
// } catch (ServerException $e) {
|
||||
// $this->log_error(['发送结果:' => $e->getErrorMessage(), "发送内容" => $options_query], '短信发送失败', 'base');
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// public function sendTest() {
|
||||
// return $this->base([
|
||||
// 'Test' => 'test',
|
||||
// 'TemplateCode' => "SMS_173476256",
|
||||
// 'PhoneNumbers' => '13873044202',
|
||||
// 'TemplateParam' => c_json_encode([
|
||||
// 'OrderNo' => '11111111111111',
|
||||
// 'CustomerName' => '测试',
|
||||
// 'ProductName' => c_max_len_3dot('裸心堡红宝石水疗送双人下午茶/每天限量抢购'),
|
||||
// 'ProductCount' => 2,
|
||||
// ]),
|
||||
// ]);
|
||||
// }
|
||||
|
||||
// public function sendSMS($body_arr): bool
|
||||
// {
|
||||
// return $this->base($body_arr);
|
||||
// }
|
||||
|
||||
// public function sendBindPhoneVcode($user_id, $phone): string
|
||||
// {
|
||||
// $vcode = random_vcode(6);
|
||||
// $this->base([
|
||||
// 'TemplateCode' => "SMS_307600272",
|
||||
// 'PhoneNumbers' => $phone,
|
||||
// 'TemplateParam' => c_json_encode(['code' => $vcode]),
|
||||
// ]);
|
||||
// return $vcode;
|
||||
// }
|
||||
|
||||
public function sendqywx($text, $phone) {
|
||||
$this->log_notice([$text, $phone], 'sendqywx', 'sendqywx');
|
||||
return curl_post_https(Config::get('app.order_qywx_webhook'),
|
||||
json_encode([
|
||||
'msgtype' => 'text',
|
||||
'text' => [
|
||||
'content' => $text,
|
||||
'mentioned_mobile_list' => [$phone],
|
||||
],
|
||||
]),
|
||||
['header' => ['Content-Type:application/json']]);
|
||||
}
|
||||
public function sendqywx_test($text, $phone) {
|
||||
$this->log_notice([$text, $phone], 'sendqywx_test', 'sendqywx_test');
|
||||
return curl_post_https(Config::get('app.self_qxwx_alarm_webhook'),
|
||||
json_encode([
|
||||
'msgtype' => 'text',
|
||||
'text' => [
|
||||
'content' => $text,
|
||||
'mentioned_mobile_list' => [$phone],
|
||||
],
|
||||
]),
|
||||
['header' => ['Content-Type:application/json']]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue