mirror of
				https://gitee.com/zoujingli/ThinkAdmin.git
				synced 2025-10-31 04:02:07 +08:00 
			
		
		
		
	[更新]代码标准化
This commit is contained in:
		
							parent
							
								
									c958252c02
								
							
						
					
					
						commit
						1ccbf8322d
					
				| @ -27,7 +27,8 @@ use think\Db; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/02/15 18:13 |  * @date 2017/02/15 18:13 | ||||||
|  */ |  */ | ||||||
| class Auth extends BasicAdmin { | class Auth extends BasicAdmin | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 默认数据模型 |      * 默认数据模型 | ||||||
| @ -38,7 +39,8 @@ class Auth extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 权限列表 |      * 权限列表 | ||||||
|      */ |      */ | ||||||
|     public function index() { |     public function index() | ||||||
|  |     { | ||||||
|         $this->title = '系统权限管理'; |         $this->title = '系统权限管理'; | ||||||
|         return parent::_list($this->table); |         return parent::_list($this->table); | ||||||
|     } |     } | ||||||
| @ -47,7 +49,8 @@ class Auth extends BasicAdmin { | |||||||
|      * 权限授权 |      * 权限授权 | ||||||
|      * @return string |      * @return string | ||||||
|      */ |      */ | ||||||
|     public function apply() { |     public function apply() | ||||||
|  |     { | ||||||
|         $auth_id = $this->request->get('id', '0'); |         $auth_id = $this->request->get('id', '0'); | ||||||
|         $method = '_apply_' . strtolower($this->request->get('action', '0')); |         $method = '_apply_' . strtolower($this->request->get('action', '0')); | ||||||
|         if (method_exists($this, $method)) { |         if (method_exists($this, $method)) { | ||||||
| @ -61,7 +64,8 @@ class Auth extends BasicAdmin { | |||||||
|      * 读取授权节点 |      * 读取授权节点 | ||||||
|      * @param $auth_id |      * @param $auth_id | ||||||
|      */ |      */ | ||||||
|     protected function _apply_getnode($auth_id) { |     protected function _apply_getnode($auth_id) | ||||||
|  |     { | ||||||
|         $nodes = NodeService::get(); |         $nodes = NodeService::get(); | ||||||
|         $checked = Db::name('SystemAuthNode')->where('auth', $auth_id)->column('node'); |         $checked = Db::name('SystemAuthNode')->where('auth', $auth_id)->column('node'); | ||||||
|         foreach ($nodes as $key => &$node) { |         foreach ($nodes as $key => &$node) { | ||||||
| @ -78,7 +82,8 @@ class Auth extends BasicAdmin { | |||||||
|      * 保存授权节点 |      * 保存授权节点 | ||||||
|      * @param $auth_id |      * @param $auth_id | ||||||
|      */ |      */ | ||||||
|     protected function _apply_save($auth_id) { |     protected function _apply_save($auth_id) | ||||||
|  |     { | ||||||
|         $data = []; |         $data = []; | ||||||
|         $post = $this->request->post(); |         $post = $this->request->post(); | ||||||
|         foreach (isset($post['nodes']) ? $post['nodes'] : [] as $node) { |         foreach (isset($post['nodes']) ? $post['nodes'] : [] as $node) { | ||||||
| @ -95,7 +100,8 @@ class Auth extends BasicAdmin { | |||||||
|      * @param int $level |      * @param int $level | ||||||
|      * @return array |      * @return array | ||||||
|      */ |      */ | ||||||
|     protected function _apply_filter($nodes, $level = 1) { |     protected function _apply_filter($nodes, $level = 1) | ||||||
|  |     { | ||||||
|         foreach ($nodes as $key => &$node) { |         foreach ($nodes as $key => &$node) { | ||||||
|             if (!empty($node['_sub_']) && is_array($node['_sub_'])) { |             if (!empty($node['_sub_']) && is_array($node['_sub_'])) { | ||||||
|                 $node['_sub_'] = $this->_apply_filter($node['_sub_'], $level + 1); |                 $node['_sub_'] = $this->_apply_filter($node['_sub_'], $level + 1); | ||||||
| @ -109,21 +115,24 @@ class Auth extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 权限添加 |      * 权限添加 | ||||||
|      */ |      */ | ||||||
|     public function add() { |     public function add() | ||||||
|  |     { | ||||||
|         return $this->_form($this->table, 'form'); |         return $this->_form($this->table, 'form'); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 权限编辑 |      * 权限编辑 | ||||||
|      */ |      */ | ||||||
|     public function edit() { |     public function edit() | ||||||
|  |     { | ||||||
|         return $this->_form($this->table, 'form'); |         return $this->_form($this->table, 'form'); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 权限禁用 |      * 权限禁用 | ||||||
|      */ |      */ | ||||||
|     public function forbid() { |     public function forbid() | ||||||
|  |     { | ||||||
|         if (DataService::update($this->table)) { |         if (DataService::update($this->table)) { | ||||||
|             $this->success("权限禁用成功!", ''); |             $this->success("权限禁用成功!", ''); | ||||||
|         } |         } | ||||||
| @ -133,7 +142,8 @@ class Auth extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 权限恢复 |      * 权限恢复 | ||||||
|      */ |      */ | ||||||
|     public function resume() { |     public function resume() | ||||||
|  |     { | ||||||
|         if (DataService::update($this->table)) { |         if (DataService::update($this->table)) { | ||||||
|             $this->success("权限启用成功!", ''); |             $this->success("权限启用成功!", ''); | ||||||
|         } |         } | ||||||
| @ -143,7 +153,8 @@ class Auth extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 权限删除 |      * 权限删除 | ||||||
|      */ |      */ | ||||||
|     public function del() { |     public function del() | ||||||
|  |     { | ||||||
|         if (DataService::update($this->table)) { |         if (DataService::update($this->table)) { | ||||||
|             $id = $this->request->post('id'); |             $id = $this->request->post('id'); | ||||||
|             Db::name('SystemAuthNode')->where('auth', $id)->delete(); |             Db::name('SystemAuthNode')->where('auth', $id)->delete(); | ||||||
|  | |||||||
| @ -24,7 +24,8 @@ use service\LogService; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/02/15 18:05 |  * @date 2017/02/15 18:05 | ||||||
|  */ |  */ | ||||||
| class Config extends BasicAdmin { | class Config extends BasicAdmin | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 当前默认数据模型 |      * 当前默认数据模型 | ||||||
| @ -41,7 +42,8 @@ class Config extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 显示系统常规配置 |      * 显示系统常规配置 | ||||||
|      */ |      */ | ||||||
|     public function index() { |     public function index() | ||||||
|  |     { | ||||||
|         if (!$this->request->isPost()) { |         if (!$this->request->isPost()) { | ||||||
|             $this->assign('title', $this->title); |             $this->assign('title', $this->title); | ||||||
|             return view(); |             return view(); | ||||||
| @ -56,7 +58,8 @@ class Config extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 文件存储配置 |      * 文件存储配置 | ||||||
|      */ |      */ | ||||||
|     public function file() { |     public function file() | ||||||
|  |     { | ||||||
|         $this->title = '文件存储配置'; |         $this->title = '文件存储配置'; | ||||||
|         $alert = ['type' => 'success', 'title' => '操作提示', 'content' => '文件引擎参数影响全局文件上传功能,请勿随意修改!']; |         $alert = ['type' => 'success', 'title' => '操作提示', 'content' => '文件引擎参数影响全局文件上传功能,请勿随意修改!']; | ||||||
|         $this->assign('alert', $alert); |         $this->assign('alert', $alert); | ||||||
|  | |||||||
| @ -28,13 +28,15 @@ use think\View; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/02/15 10:41 |  * @date 2017/02/15 10:41 | ||||||
|  */ |  */ | ||||||
| class Index extends BasicAdmin { | class Index extends BasicAdmin | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 后台框架布局 |      * 后台框架布局 | ||||||
|      * @return View |      * @return View | ||||||
|      */ |      */ | ||||||
|     public function index() { |     public function index() | ||||||
|  |     { | ||||||
|         NodeService::applyAuthNode(); |         NodeService::applyAuthNode(); | ||||||
|         $list = Db::name('SystemMenu')->where('status', '1')->order('sort asc,id asc')->select(); |         $list = Db::name('SystemMenu')->where('status', '1')->order('sort asc,id asc')->select(); | ||||||
|         $menus = $this->_filterMenu(ToolsService::arr2tree($list)); |         $menus = $this->_filterMenu(ToolsService::arr2tree($list)); | ||||||
| @ -46,7 +48,8 @@ class Index extends BasicAdmin { | |||||||
|      * @param array $menus |      * @param array $menus | ||||||
|      * @return array |      * @return array | ||||||
|      */ |      */ | ||||||
|     private function _filterMenu($menus) { |     private function _filterMenu($menus) | ||||||
|  |     { | ||||||
|         foreach ($menus as $key => &$menu) { |         foreach ($menus as $key => &$menu) { | ||||||
|             if (!empty($menu['sub'])) { |             if (!empty($menu['sub'])) { | ||||||
|                 $menu['sub'] = $this->_filterMenu($menu['sub']); |                 $menu['sub'] = $this->_filterMenu($menu['sub']); | ||||||
| @ -68,12 +71,13 @@ class Index extends BasicAdmin { | |||||||
|      * 主机信息显示 |      * 主机信息显示 | ||||||
|      * @return View |      * @return View | ||||||
|      */ |      */ | ||||||
|     public function main() { |     public function main() | ||||||
|  |     { | ||||||
|         if (session('user.username') === 'admin' && session('user.password') === '21232f297a57a5a743894a0e4a801fc3') { |         if (session('user.username') === 'admin' && session('user.password') === '21232f297a57a5a743894a0e4a801fc3') { | ||||||
|             $url = url('admin/index/pass') . '?id=' . session('user.id'); |             $url = url('admin/index/pass') . '?id=' . session('user.id'); | ||||||
|             $alert = [ |             $alert = [ | ||||||
|                 'type'    => 'danger', |                 'type' => 'danger', | ||||||
|                 'title'   => '安全提示', |                 'title' => '安全提示', | ||||||
|                 'content' => "超级管理员默认密码未修改,建议马上<a href='javascript:void(0)' data-modal='{$url}'>修改</a>!" |                 'content' => "超级管理员默认密码未修改,建议马上<a href='javascript:void(0)' data-modal='{$url}'>修改</a>!" | ||||||
|             ]; |             ]; | ||||||
|             $this->assign('alert', $alert); |             $this->assign('alert', $alert); | ||||||
| @ -87,7 +91,8 @@ class Index extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 修改密码 |      * 修改密码 | ||||||
|      */ |      */ | ||||||
|     public function pass() { |     public function pass() | ||||||
|  |     { | ||||||
|         if (in_array('10000', explode(',', $this->request->post('id')))) { |         if (in_array('10000', explode(',', $this->request->post('id')))) { | ||||||
|             $this->error('系统超级账号禁止操作!'); |             $this->error('系统超级账号禁止操作!'); | ||||||
|         } |         } | ||||||
| @ -117,7 +122,8 @@ class Index extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 修改资料 |      * 修改资料 | ||||||
|      */ |      */ | ||||||
|     public function info() { |     public function info() | ||||||
|  |     { | ||||||
|         if (in_array('10000', explode(',', $this->request->post('id')))) { |         if (in_array('10000', explode(',', $this->request->post('id')))) { | ||||||
|             $this->error('系统超级账号禁止操作!'); |             $this->error('系统超级账号禁止操作!'); | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -25,7 +25,8 @@ use think\Db; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/02/15 18:12 |  * @date 2017/02/15 18:12 | ||||||
|  */ |  */ | ||||||
| class Log extends BasicAdmin { | class Log extends BasicAdmin | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 指定当前数据表 |      * 指定当前数据表 | ||||||
| @ -36,7 +37,8 @@ class Log extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 日志列表 |      * 日志列表 | ||||||
|      */ |      */ | ||||||
|     public function index() { |     public function index() | ||||||
|  |     { | ||||||
|         $this->title = '系统操作日志'; |         $this->title = '系统操作日志'; | ||||||
|         $get = $this->request->get(); |         $get = $this->request->get(); | ||||||
|         $actions = Db::name($this->table)->group('action')->column('action'); |         $actions = Db::name($this->table)->group('action')->column('action'); | ||||||
| @ -54,7 +56,8 @@ class Log extends BasicAdmin { | |||||||
|      * 列表数据处理 |      * 列表数据处理 | ||||||
|      * @param $data |      * @param $data | ||||||
|      */ |      */ | ||||||
|     protected function _index_data_filter(&$data) { |     protected function _index_data_filter(&$data) | ||||||
|  |     { | ||||||
|         $ip = new \Ip2Region(); |         $ip = new \Ip2Region(); | ||||||
|         foreach ($data as &$vo) { |         foreach ($data as &$vo) { | ||||||
|             $result = $ip->btreeSearch($vo['ip']); |             $result = $ip->btreeSearch($vo['ip']); | ||||||
| @ -66,7 +69,8 @@ class Log extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 日志删除操作 |      * 日志删除操作 | ||||||
|      */ |      */ | ||||||
|     public function del() { |     public function del() | ||||||
|  |     { | ||||||
|         if (DataService::update($this->table)) { |         if (DataService::update($this->table)) { | ||||||
|             $this->success("日志删除成功!", ''); |             $this->success("日志删除成功!", ''); | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -26,7 +26,8 @@ use think\Db; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/02/10 13:59 |  * @date 2017/02/10 13:59 | ||||||
|  */ |  */ | ||||||
| class Login extends BasicAdmin { | class Login extends BasicAdmin | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 默认检查用户登录状态 |      * 默认检查用户登录状态 | ||||||
| @ -43,7 +44,8 @@ class Login extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 控制器基础方法 |      * 控制器基础方法 | ||||||
|      */ |      */ | ||||||
|     public function _initialize() { |     public function _initialize() | ||||||
|  |     { | ||||||
|         if (session('user') && $this->request->action() !== 'out') { |         if (session('user') && $this->request->action() !== 'out') { | ||||||
|             $this->redirect('@admin'); |             $this->redirect('@admin'); | ||||||
|         } |         } | ||||||
| @ -53,7 +55,8 @@ class Login extends BasicAdmin { | |||||||
|      * 用户登录 |      * 用户登录 | ||||||
|      * @return string |      * @return string | ||||||
|      */ |      */ | ||||||
|     public function index() { |     public function index() | ||||||
|  |     { | ||||||
|         if ($this->request->isGet()) { |         if ($this->request->isGet()) { | ||||||
|             return $this->fetch('', ['title' => '用户登录']); |             return $this->fetch('', ['title' => '用户登录']); | ||||||
|         } else { |         } else { | ||||||
| @ -80,7 +83,8 @@ class Login extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 退出登录 |      * 退出登录 | ||||||
|      */ |      */ | ||||||
|     public function out() { |     public function out() | ||||||
|  |     { | ||||||
|         LogService::write('系统管理', '用户退出系统成功'); |         LogService::write('系统管理', '用户退出系统成功'); | ||||||
|         session('user', null); |         session('user', null); | ||||||
|         session_destroy(); |         session_destroy(); | ||||||
|  | |||||||
| @ -27,7 +27,8 @@ use think\Db; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/02/15 |  * @date 2017/02/15 | ||||||
|  */ |  */ | ||||||
| class Menu extends BasicAdmin { | class Menu extends BasicAdmin | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 绑定操作模型 |      * 绑定操作模型 | ||||||
| @ -38,7 +39,8 @@ class Menu extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 菜单列表 |      * 菜单列表 | ||||||
|      */ |      */ | ||||||
|     public function index() { |     public function index() | ||||||
|  |     { | ||||||
|         $this->title = '系统菜单管理'; |         $this->title = '系统菜单管理'; | ||||||
|         $db = Db::name($this->table)->order('sort asc,id asc'); |         $db = Db::name($this->table)->order('sort asc,id asc'); | ||||||
|         return parent::_list($db, false); |         return parent::_list($db, false); | ||||||
| @ -48,7 +50,8 @@ class Menu extends BasicAdmin { | |||||||
|      * 列表数据处理 |      * 列表数据处理 | ||||||
|      * @param array $data |      * @param array $data | ||||||
|      */ |      */ | ||||||
|     protected function _index_data_filter(&$data) { |     protected function _index_data_filter(&$data) | ||||||
|  |     { | ||||||
|         foreach ($data as &$vo) { |         foreach ($data as &$vo) { | ||||||
|             ($vo['url'] !== '#') && ($vo['url'] = url($vo['url'])); |             ($vo['url'] !== '#') && ($vo['url'] = url($vo['url'])); | ||||||
|             $vo['ids'] = join(',', ToolsService::getArrSubIds($data, $vo['id'])); |             $vo['ids'] = join(',', ToolsService::getArrSubIds($data, $vo['id'])); | ||||||
| @ -59,14 +62,16 @@ class Menu extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 添加菜单 |      * 添加菜单 | ||||||
|      */ |      */ | ||||||
|     public function add() { |     public function add() | ||||||
|  |     { | ||||||
|         return $this->_form($this->table, 'form'); |         return $this->_form($this->table, 'form'); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 编辑菜单 |      * 编辑菜单 | ||||||
|      */ |      */ | ||||||
|     public function edit() { |     public function edit() | ||||||
|  |     { | ||||||
|         return $this->_form($this->table, 'form'); |         return $this->_form($this->table, 'form'); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -74,7 +79,8 @@ class Menu extends BasicAdmin { | |||||||
|      * 表单数据前缀方法 |      * 表单数据前缀方法 | ||||||
|      * @param array $vo |      * @param array $vo | ||||||
|      */ |      */ | ||||||
|     protected function _form_filter(&$vo) { |     protected function _form_filter(&$vo) | ||||||
|  |     { | ||||||
|         if ($this->request->isGet()) { |         if ($this->request->isGet()) { | ||||||
|             // 上级菜单处理
 |             // 上级菜单处理
 | ||||||
|             $_menus = Db::name($this->table)->where('status', '1')->order('sort desc,id desc')->select(); |             $_menus = Db::name($this->table)->where('status', '1')->order('sort desc,id desc')->select(); | ||||||
| @ -107,7 +113,8 @@ class Menu extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 删除菜单 |      * 删除菜单 | ||||||
|      */ |      */ | ||||||
|     public function del() { |     public function del() | ||||||
|  |     { | ||||||
|         if (DataService::update($this->table)) { |         if (DataService::update($this->table)) { | ||||||
|             $this->success("菜单删除成功!", ''); |             $this->success("菜单删除成功!", ''); | ||||||
|         } |         } | ||||||
| @ -117,7 +124,8 @@ class Menu extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 菜单禁用 |      * 菜单禁用 | ||||||
|      */ |      */ | ||||||
|     public function forbid() { |     public function forbid() | ||||||
|  |     { | ||||||
|         if (DataService::update($this->table)) { |         if (DataService::update($this->table)) { | ||||||
|             $this->success("菜单禁用成功!", ''); |             $this->success("菜单禁用成功!", ''); | ||||||
|         } |         } | ||||||
| @ -127,7 +135,8 @@ class Menu extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 菜单禁用 |      * 菜单禁用 | ||||||
|      */ |      */ | ||||||
|     public function resume() { |     public function resume() | ||||||
|  |     { | ||||||
|         if (DataService::update($this->table)) { |         if (DataService::update($this->table)) { | ||||||
|             $this->success("菜单启用成功!", ''); |             $this->success("菜单启用成功!", ''); | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -26,7 +26,8 @@ use service\ToolsService; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/02/15 18:13 |  * @date 2017/02/15 18:13 | ||||||
|  */ |  */ | ||||||
| class Node extends BasicAdmin { | class Node extends BasicAdmin | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 指定当前默认模型 |      * 指定当前默认模型 | ||||||
| @ -37,7 +38,8 @@ class Node extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 显示节点列表 |      * 显示节点列表 | ||||||
|      */ |      */ | ||||||
|     public function index() { |     public function index() | ||||||
|  |     { | ||||||
|         $alert = ['type' => 'danger', 'title' => '安全警告', 'content' => '结构为系统自动生成, 状态数据请勿随意修改!']; |         $alert = ['type' => 'danger', 'title' => '安全警告', 'content' => '结构为系统自动生成, 状态数据请勿随意修改!']; | ||||||
|         $nodes = ToolsService::arr2table(NodeService::get(), 'node', 'pnode'); |         $nodes = ToolsService::arr2table(NodeService::get(), 'node', 'pnode'); | ||||||
|         return view('', ['title' => '系统节点管理', 'nodes' => $nodes, 'alert' => $alert]); |         return view('', ['title' => '系统节点管理', 'nodes' => $nodes, 'alert' => $alert]); | ||||||
| @ -46,7 +48,8 @@ class Node extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 保存节点变更 |      * 保存节点变更 | ||||||
|      */ |      */ | ||||||
|     public function save() { |     public function save() | ||||||
|  |     { | ||||||
|         if ($this->request->isPost()) { |         if ($this->request->isPost()) { | ||||||
|             $post = $this->request->post(); |             $post = $this->request->post(); | ||||||
|             if (isset($post['name']) && isset($post['value'])) { |             if (isset($post['name']) && isset($post['value'])) { | ||||||
|  | |||||||
| @ -25,7 +25,8 @@ use think\View; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/02/21 |  * @date 2017/02/21 | ||||||
|  */ |  */ | ||||||
| class Plugs extends BasicAdmin { | class Plugs extends BasicAdmin | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 默认检查用户登录状态 |      * 默认检查用户登录状态 | ||||||
| @ -43,7 +44,8 @@ class Plugs extends BasicAdmin { | |||||||
|      * 文件上传 |      * 文件上传 | ||||||
|      * @return View |      * @return View | ||||||
|      */ |      */ | ||||||
|     public function upfile() { |     public function upfile() | ||||||
|  |     { | ||||||
|         if (!in_array(($uptype = $this->request->get('uptype')), ['local', 'qiniu'])) { |         if (!in_array(($uptype = $this->request->get('uptype')), ['local', 'qiniu'])) { | ||||||
|             $uptype = sysconf('storage_type'); |             $uptype = sysconf('storage_type'); | ||||||
|         } |         } | ||||||
| @ -58,7 +60,8 @@ class Plugs extends BasicAdmin { | |||||||
|      * 通用文件上传 |      * 通用文件上传 | ||||||
|      * @return string |      * @return string | ||||||
|      */ |      */ | ||||||
|     public function upload() { |     public function upload() | ||||||
|  |     { | ||||||
|         if ($this->request->isPost()) { |         if ($this->request->isPost()) { | ||||||
|             $md5s = str_split($this->request->post('md5'), 16); |             $md5s = str_split($this->request->post('md5'), 16); | ||||||
|             if (($info = $this->request->file('file')->move('static' . DS . 'upload' . DS . $md5s[0], $md5s[1], true))) { |             if (($info = $this->request->file('file')->move('static' . DS . 'upload' . DS . $md5s[0], $md5s[1], true))) { | ||||||
| @ -74,7 +77,8 @@ class Plugs extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 文件状态检查 |      * 文件状态检查 | ||||||
|      */ |      */ | ||||||
|     public function upstate() { |     public function upstate() | ||||||
|  |     { | ||||||
|         $post = $this->request->post(); |         $post = $this->request->post(); | ||||||
|         $filename = join('/', str_split($post['md5'], 16)) . '.' . pathinfo($post['filename'], PATHINFO_EXTENSION); |         $filename = join('/', str_split($post['md5'], 16)) . '.' . pathinfo($post['filename'], PATHINFO_EXTENSION); | ||||||
|         // 检查文件是否已上传
 |         // 检查文件是否已上传
 | ||||||
| @ -111,15 +115,16 @@ class Plugs extends BasicAdmin { | |||||||
|      * @param string $key |      * @param string $key | ||||||
|      * @return string |      * @return string | ||||||
|      */ |      */ | ||||||
|     protected function _getQiniuToken($key) { |     protected function _getQiniuToken($key) | ||||||
|  |     { | ||||||
|         $accessKey = sysconf('storage_qiniu_access_key'); |         $accessKey = sysconf('storage_qiniu_access_key'); | ||||||
|         $secretKey = sysconf('storage_qiniu_secret_key'); |         $secretKey = sysconf('storage_qiniu_secret_key'); | ||||||
|         $bucket = sysconf('storage_qiniu_bucket'); |         $bucket = sysconf('storage_qiniu_bucket'); | ||||||
|         $host = sysconf('storage_qiniu_domain'); |         $host = sysconf('storage_qiniu_domain'); | ||||||
|         $protocol = sysconf('storage_qiniu_is_https') ? 'https' : 'http'; |         $protocol = sysconf('storage_qiniu_is_https') ? 'https' : 'http'; | ||||||
|         $params = [ |         $params = [ | ||||||
|             "scope"      => "{$bucket}:{$key}", |             "scope" => "{$bucket}:{$key}", | ||||||
|             "deadline"   => 3600 + time(), |             "deadline" => 3600 + time(), | ||||||
|             "returnBody" => "{\"data\":{\"site_url\":\"{$protocol}://{$host}/$(key)\",\"file_url\":\"$(key)\"}, \"code\": \"SUCCESS\"}", |             "returnBody" => "{\"data\":{\"site_url\":\"{$protocol}://{$host}/$(key)\",\"file_url\":\"$(key)\"}, \"code\": \"SUCCESS\"}", | ||||||
|         ]; |         ]; | ||||||
|         $data = str_replace(['+', '/'], ['-', '_'], base64_encode(json_encode($params))); |         $data = str_replace(['+', '/'], ['-', '_'], base64_encode(json_encode($params))); | ||||||
| @ -129,7 +134,8 @@ class Plugs extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 字体图标 |      * 字体图标 | ||||||
|      */ |      */ | ||||||
|     public function icon() { |     public function icon() | ||||||
|  |     { | ||||||
|         $this->assign('field', $this->request->get('field', 'icon')); |         $this->assign('field', $this->request->get('field', 'icon')); | ||||||
|         return view(); |         return view(); | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -25,7 +25,8 @@ use think\Db; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/02/15 18:12 |  * @date 2017/02/15 18:12 | ||||||
|  */ |  */ | ||||||
| class User extends BasicAdmin { | class User extends BasicAdmin | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 指定当前数据表 |      * 指定当前数据表 | ||||||
| @ -36,7 +37,8 @@ class User extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 用户列表 |      * 用户列表 | ||||||
|      */ |      */ | ||||||
|     public function index() { |     public function index() | ||||||
|  |     { | ||||||
|         // 设置页面标题
 |         // 设置页面标题
 | ||||||
|         $this->title = '系统用户管理'; |         $this->title = '系统用户管理'; | ||||||
|         // 获取到所有GET参数
 |         // 获取到所有GET参数
 | ||||||
| @ -57,28 +59,32 @@ class User extends BasicAdmin { | |||||||
|      * 授权管理 |      * 授权管理 | ||||||
|      * @return array|string |      * @return array|string | ||||||
|      */ |      */ | ||||||
|     public function auth() { |     public function auth() | ||||||
|  |     { | ||||||
|         return $this->_form($this->table, 'auth'); |         return $this->_form($this->table, 'auth'); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 用户添加 |      * 用户添加 | ||||||
|      */ |      */ | ||||||
|     public function add() { |     public function add() | ||||||
|  |     { | ||||||
|         return $this->_form($this->table, 'form'); |         return $this->_form($this->table, 'form'); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 用户编辑 |      * 用户编辑 | ||||||
|      */ |      */ | ||||||
|     public function edit() { |     public function edit() | ||||||
|  |     { | ||||||
|         return $this->_form($this->table, 'form'); |         return $this->_form($this->table, 'form'); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 用户密码修改 |      * 用户密码修改 | ||||||
|      */ |      */ | ||||||
|     public function pass() { |     public function pass() | ||||||
|  |     { | ||||||
|         if (in_array('10000', explode(',', $this->request->post('id')))) { |         if (in_array('10000', explode(',', $this->request->post('id')))) { | ||||||
|             $this->error('系统超级账号禁止操作!'); |             $this->error('系统超级账号禁止操作!'); | ||||||
|         } |         } | ||||||
| @ -100,7 +106,8 @@ class User extends BasicAdmin { | |||||||
|      * 表单数据默认处理 |      * 表单数据默认处理 | ||||||
|      * @param array $data |      * @param array $data | ||||||
|      */ |      */ | ||||||
|     public function _form_filter(&$data) { |     public function _form_filter(&$data) | ||||||
|  |     { | ||||||
|         if ($this->request->isPost()) { |         if ($this->request->isPost()) { | ||||||
|             if (isset($data['authorize']) && is_array($data['authorize'])) { |             if (isset($data['authorize']) && is_array($data['authorize'])) { | ||||||
|                 $data['authorize'] = join(',', $data['authorize']); |                 $data['authorize'] = join(',', $data['authorize']); | ||||||
| @ -119,7 +126,8 @@ class User extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 删除用户 |      * 删除用户 | ||||||
|      */ |      */ | ||||||
|     public function del() { |     public function del() | ||||||
|  |     { | ||||||
|         if (in_array('10000', explode(',', $this->request->post('id')))) { |         if (in_array('10000', explode(',', $this->request->post('id')))) { | ||||||
|             $this->error('系统超级账号禁止删除!'); |             $this->error('系统超级账号禁止删除!'); | ||||||
|         } |         } | ||||||
| @ -132,7 +140,8 @@ class User extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 用户禁用 |      * 用户禁用 | ||||||
|      */ |      */ | ||||||
|     public function forbid() { |     public function forbid() | ||||||
|  |     { | ||||||
|         if (in_array('10000', explode(',', $this->request->post('id')))) { |         if (in_array('10000', explode(',', $this->request->post('id')))) { | ||||||
|             $this->error('系统超级账号禁止操作!'); |             $this->error('系统超级账号禁止操作!'); | ||||||
|         } |         } | ||||||
| @ -145,7 +154,8 @@ class User extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 用户禁用 |      * 用户禁用 | ||||||
|      */ |      */ | ||||||
|     public function resume() { |     public function resume() | ||||||
|  |     { | ||||||
|         if (DataService::update($this->table)) { |         if (DataService::update($this->table)) { | ||||||
|             $this->success("用户启用成功!", ''); |             $this->success("用户启用成功!", ''); | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -24,7 +24,8 @@ use think\Db; | |||||||
|  * @param bool $replace |  * @param bool $replace | ||||||
|  * @param string|null $pathname |  * @param string|null $pathname | ||||||
|  */ |  */ | ||||||
| function p($data, $replace = false, $pathname = NULL) { | function p($data, $replace = false, $pathname = NULL) | ||||||
|  | { | ||||||
|     is_null($pathname) && $pathname = RUNTIME_PATH . date('Ymd') . '.txt'; |     is_null($pathname) && $pathname = RUNTIME_PATH . date('Ymd') . '.txt'; | ||||||
|     $str = (is_string($data) ? $data : (is_array($data) || is_object($data)) ? print_r($data, true) : var_export($data, true)) . "\n"; |     $str = (is_string($data) ? $data : (is_array($data) || is_object($data)) ? print_r($data, true) : var_export($data, true)) . "\n"; | ||||||
|     $replace ? file_put_contents($pathname, $str) : file_put_contents($pathname, $str, FILE_APPEND); |     $replace ? file_put_contents($pathname, $str) : file_put_contents($pathname, $str, FILE_APPEND); | ||||||
| @ -35,20 +36,21 @@ function p($data, $replace = false, $pathname = NULL) { | |||||||
|  * @param string $type |  * @param string $type | ||||||
|  * @return \Wechat\WechatReceive|\Wechat\WechatUser|\Wechat\WechatPay|\Wechat\WechatScript|\Wechat\WechatOauth|\Wechat\WechatMenu |  * @return \Wechat\WechatReceive|\Wechat\WechatUser|\Wechat\WechatPay|\Wechat\WechatScript|\Wechat\WechatOauth|\Wechat\WechatMenu | ||||||
|  */ |  */ | ||||||
| function & load_wechat($type = '') { | function & load_wechat($type = '') | ||||||
|  | { | ||||||
|     static $wechat = array(); |     static $wechat = array(); | ||||||
|     $index = md5(strtolower($type)); |     $index = md5(strtolower($type)); | ||||||
|     if (!isset($wechat[$index])) { |     if (!isset($wechat[$index])) { | ||||||
|         $config = [ |         $config = [ | ||||||
|             'token'          => sysconf('wechat_token'), |             'token' => sysconf('wechat_token'), | ||||||
|             'appid'          => sysconf('wechat_appid'), |             'appid' => sysconf('wechat_appid'), | ||||||
|             'appsecret'      => sysconf('wechat_appsecret'), |             'appsecret' => sysconf('wechat_appsecret'), | ||||||
|             'encodingaeskey' => sysconf('wechat_encodingaeskey'), |             'encodingaeskey' => sysconf('wechat_encodingaeskey'), | ||||||
|             'mch_id'         => sysconf('wechat_mch_id'), |             'mch_id' => sysconf('wechat_mch_id'), | ||||||
|             'partnerkey'     => sysconf('wechat_partnerkey'), |             'partnerkey' => sysconf('wechat_partnerkey'), | ||||||
|             'ssl_cer'        => sysconf('wechat_cert_cert'), |             'ssl_cer' => sysconf('wechat_cert_cert'), | ||||||
|             'ssl_key'        => sysconf('wechat_cert_key'), |             'ssl_key' => sysconf('wechat_cert_key'), | ||||||
|             'cachepath'      => CACHE_PATH . 'wxpay' . DS, |             'cachepath' => CACHE_PATH . 'wxpay' . DS, | ||||||
|         ]; |         ]; | ||||||
|         $wechat[$index] = Loader::get($type, $config); |         $wechat[$index] = Loader::get($type, $config); | ||||||
|     } |     } | ||||||
| @ -60,7 +62,8 @@ function & load_wechat($type = '') { | |||||||
|  * @param string $string |  * @param string $string | ||||||
|  * @return string |  * @return string | ||||||
|  */ |  */ | ||||||
| function encode($string) { | function encode($string) | ||||||
|  | { | ||||||
|     $chars = ''; |     $chars = ''; | ||||||
|     $len = strlen($string = iconv('utf-8', 'gbk', $string)); |     $len = strlen($string = iconv('utf-8', 'gbk', $string)); | ||||||
|     for ($i = 0; $i < $len; $i++) { |     for ($i = 0; $i < $len; $i++) { | ||||||
| @ -74,7 +77,8 @@ function encode($string) { | |||||||
|  * @param string $string |  * @param string $string | ||||||
|  * @return string |  * @return string | ||||||
|  */ |  */ | ||||||
| function decode($string) { | function decode($string) | ||||||
|  | { | ||||||
|     $chars = ''; |     $chars = ''; | ||||||
|     foreach (str_split($string, 2) as $char) { |     foreach (str_split($string, 2) as $char) { | ||||||
|         $chars .= chr(intval(base_convert($char, 36, 10))); |         $chars .= chr(intval(base_convert($char, 36, 10))); | ||||||
| @ -87,7 +91,8 @@ function decode($string) { | |||||||
|  * @param string $node |  * @param string $node | ||||||
|  * @return bool |  * @return bool | ||||||
|  */ |  */ | ||||||
| function auth($node) { | function auth($node) | ||||||
|  | { | ||||||
|     return NodeService::checkAuthNode($node); |     return NodeService::checkAuthNode($node); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -97,7 +102,8 @@ function auth($node) { | |||||||
|  * @param bool $value 默认是false为获取值,否则为更新 |  * @param bool $value 默认是false为获取值,否则为更新 | ||||||
|  * @return string|bool |  * @return string|bool | ||||||
|  */ |  */ | ||||||
| function sysconf($name, $value = false) { | function sysconf($name, $value = false) | ||||||
|  | { | ||||||
|     static $config = []; |     static $config = []; | ||||||
|     if ($value !== false) { |     if ($value !== false) { | ||||||
|         $config = []; |         $config = []; | ||||||
| @ -117,7 +123,8 @@ function sysconf($name, $value = false) { | |||||||
|  */ |  */ | ||||||
| if (!function_exists("array_column")) { | if (!function_exists("array_column")) { | ||||||
| 
 | 
 | ||||||
|     function array_column(array &$rows, $column_key, $index_key = null) { |     function array_column(array &$rows, $column_key, $index_key = null) | ||||||
|  |     { | ||||||
|         $data = []; |         $data = []; | ||||||
|         foreach ($rows as $row) { |         foreach ($rows as $row) { | ||||||
|             if (empty($index_key)) { |             if (empty($index_key)) { | ||||||
|  | |||||||
| @ -23,12 +23,14 @@ use think\Controller; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/04/05 10:38 |  * @date 2017/04/05 10:38 | ||||||
|  */ |  */ | ||||||
| class Index extends Controller { | class Index extends Controller | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 网站入口 |      * 网站入口 | ||||||
|      */ |      */ | ||||||
|     public function index() { |     public function index() | ||||||
|  |     { | ||||||
|         $this->redirect('@admin'); |         $this->redirect('@admin'); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,26 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| // +----------------------------------------------------------------------
 |  | ||||||
| // | Think.Admin
 |  | ||||||
| // +----------------------------------------------------------------------
 |  | ||||||
| // | 版权所有 2016~2017 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
 |  | ||||||
| // +----------------------------------------------------------------------
 |  | ||||||
| // | 官方网站: http://think.ctolog.com
 |  | ||||||
| // +----------------------------------------------------------------------
 |  | ||||||
| // | 开源协议 ( http://www.apache.org/licenses/LICENSE-2.0 )
 |  | ||||||
| // +----------------------------------------------------------------------
 |  | ||||||
| // | github开源项目:https://github.com/zoujingli/Think.Admin
 |  | ||||||
| // +----------------------------------------------------------------------
 |  | ||||||
| 
 |  | ||||||
| namespace app\index\controller; |  | ||||||
| 
 |  | ||||||
| use controller\BasicApi; |  | ||||||
| use service\FileService; |  | ||||||
| 
 |  | ||||||
| class Test extends BasicApi { |  | ||||||
| 
 |  | ||||||
|     public function index() { |  | ||||||
|         dump(FileService::oss('fassdfsa', 'fsadfasdf')); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
| @ -18,7 +18,8 @@ use controller\BasicWechat; | |||||||
| use service\DataService; | use service\DataService; | ||||||
| use service\PayService; | use service\PayService; | ||||||
| 
 | 
 | ||||||
| class Wap extends BasicWechat { | class Wap extends BasicWechat | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 禁用自动网页授权 |      * 禁用自动网页授权 | ||||||
| @ -29,7 +30,8 @@ class Wap extends BasicWechat { | |||||||
|     /** |     /** | ||||||
|      * 网页授权DEMO |      * 网页授权DEMO | ||||||
|      */ |      */ | ||||||
|     public function index() { |     public function index() | ||||||
|  |     { | ||||||
| //        dump($this->oAuth(false)); // 仅获取用户openid
 | //        dump($this->oAuth(false)); // 仅获取用户openid
 | ||||||
|         dump($this->oAuth());  // 获取用户详情信息
 |         dump($this->oAuth());  // 获取用户详情信息
 | ||||||
|         dump($this->fansinfo); // 打
 |         dump($this->fansinfo); // 打
 | ||||||
| @ -39,7 +41,8 @@ class Wap extends BasicWechat { | |||||||
|      * 微信二维码支付DEMO |      * 微信二维码支付DEMO | ||||||
|      * @return \think\response\Json|\think\response\View |      * @return \think\response\Json|\think\response\View | ||||||
|      */ |      */ | ||||||
|     public function payqrc() { |     public function payqrc() | ||||||
|  |     { | ||||||
|         switch ($this->request->get('action')) { |         switch ($this->request->get('action')) { | ||||||
|             case 'payqrc': |             case 'payqrc': | ||||||
|                 $pay = &load_wechat('pay'); |                 $pay = &load_wechat('pay'); | ||||||
| @ -69,7 +72,8 @@ class Wap extends BasicWechat { | |||||||
|      * 微信JSAPI支付DEMO |      * 微信JSAPI支付DEMO | ||||||
|      * @return \think\response\Json|\think\response\View |      * @return \think\response\Json|\think\response\View | ||||||
|      */ |      */ | ||||||
|     public function payjs() { |     public function payjs() | ||||||
|  |     { | ||||||
|         $this->openid = $this->oAuth(false); |         $this->openid = $this->oAuth(false); | ||||||
|         switch ($this->request->get('action')) { |         switch ($this->request->get('action')) { | ||||||
|             case 'options': |             case 'options': | ||||||
|  | |||||||
| @ -27,7 +27,8 @@ use Wechat\WechatReceive; | |||||||
|  * @package app\wechat\controller |  * @package app\wechat\controller | ||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  */ |  */ | ||||||
| class Api extends Controller { | class Api extends Controller | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 微信openid |      * 微信openid | ||||||
| @ -45,7 +46,8 @@ class Api extends Controller { | |||||||
|      * 微信消息接口 |      * 微信消息接口 | ||||||
|      * @return string |      * @return string | ||||||
|      */ |      */ | ||||||
|     public function index() { |     public function index() | ||||||
|  |     { | ||||||
|         // 实例接口对象
 |         // 实例接口对象
 | ||||||
|         $this->wechat = &load_wechat('Receive'); |         $this->wechat = &load_wechat('Receive'); | ||||||
|         // 验证接口请求
 |         // 验证接口请求
 | ||||||
| @ -79,7 +81,8 @@ class Api extends Controller { | |||||||
|      * @param bool $isForce |      * @param bool $isForce | ||||||
|      * @return string |      * @return string | ||||||
|      */ |      */ | ||||||
|     private function _keys($keys, $isForce = false) { |     private function _keys($keys, $isForce = false) | ||||||
|  |     { | ||||||
|         list($table, $field, $value) = explode('#', $keys . '##'); |         list($table, $field, $value) = explode('#', $keys . '##'); | ||||||
|         if (is_array($info = Db::name($table)->where($field, $value)->find()) && isset($info['type'])) { |         if (is_array($info = Db::name($table)->where($field, $value)->find()) && isset($info['type'])) { | ||||||
|             // 数据状态检查
 |             // 数据状态检查
 | ||||||
| @ -152,15 +155,16 @@ class Api extends Controller { | |||||||
|      * @param int $news_id |      * @param int $news_id | ||||||
|      * @return bool|string |      * @return bool|string | ||||||
|      */ |      */ | ||||||
|     protected function _news($news_id = 0) { |     protected function _news($news_id = 0) | ||||||
|  |     { | ||||||
|         if (is_array($newsinfo = WechatService::getNewsById($news_id)) && !empty($newsinfo['articles'])) { |         if (is_array($newsinfo = WechatService::getNewsById($news_id)) && !empty($newsinfo['articles'])) { | ||||||
|             $newsdata = array(); |             $newsdata = array(); | ||||||
|             foreach ($newsinfo['articles'] as $vo) { |             foreach ($newsinfo['articles'] as $vo) { | ||||||
|                 $newsdata[] = [ |                 $newsdata[] = [ | ||||||
|                     'Title'       => $vo['title'], |                     'Title' => $vo['title'], | ||||||
|                     'Description' => $vo['digest'], |                     'Description' => $vo['digest'], | ||||||
|                     'PicUrl'      => $vo['local_url'], |                     'PicUrl' => $vo['local_url'], | ||||||
|                     'Url'         => url("@wechat/review", '', true, true) . "?content={$vo['id']}&type=article", |                     'Url' => url("@wechat/review", '', true, true) . "?content={$vo['id']}&type=article", | ||||||
|                 ]; |                 ]; | ||||||
|             } |             } | ||||||
|             return $this->wechat->news($newsdata)->reply(false, true); |             return $this->wechat->news($newsdata)->reply(false, true); | ||||||
| @ -171,7 +175,8 @@ class Api extends Controller { | |||||||
|     /** |     /** | ||||||
|      * 事件处理 |      * 事件处理 | ||||||
|      */ |      */ | ||||||
|     protected function _event() { |     protected function _event() | ||||||
|  |     { | ||||||
|         $event = $this->wechat->getRevEvent(); |         $event = $this->wechat->getRevEvent(); | ||||||
|         switch (strtolower($event['event'])) { |         switch (strtolower($event['event'])) { | ||||||
|             case 'subscribe': // 粉丝关注事件
 |             case 'subscribe': // 粉丝关注事件
 | ||||||
| @ -204,7 +209,8 @@ class Api extends Controller { | |||||||
|      * @param string $event |      * @param string $event | ||||||
|      * @return mixed |      * @return mixed | ||||||
|      */ |      */ | ||||||
|     private function _spread($event) { |     private function _spread($event) | ||||||
|  |     { | ||||||
|         $key = preg_replace('|^.*?(\d+).*?$|', '$1', "{$event}"); |         $key = preg_replace('|^.*?(\d+).*?$|', '$1', "{$event}"); | ||||||
|         // 检测推荐是否有效
 |         // 检测推荐是否有效
 | ||||||
|         $fans = Db::name('WechatFans')->where('id', $key)->find(); |         $fans = Db::name('WechatFans')->where('id', $key)->find(); | ||||||
| @ -221,14 +227,16 @@ class Api extends Controller { | |||||||
|      * 位置事情回复 |      * 位置事情回复 | ||||||
|      * @return string |      * @return string | ||||||
|      */ |      */ | ||||||
|     private function _location() { |     private function _location() | ||||||
|  |     { | ||||||
|         return 'success'; |         return 'success'; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 图片事件处理 |      * 图片事件处理 | ||||||
|      */ |      */ | ||||||
|     private function _image() { |     private function _image() | ||||||
|  |     { | ||||||
|         return 'success'; |         return 'success'; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -236,7 +244,8 @@ class Api extends Controller { | |||||||
|      * 同步粉丝状态 |      * 同步粉丝状态 | ||||||
|      * @param bool $subscribe 关注状态 |      * @param bool $subscribe 关注状态 | ||||||
|      */ |      */ | ||||||
|     protected function _updateFansInfo($subscribe = true) { |     protected function _updateFansInfo($subscribe = true) | ||||||
|  |     { | ||||||
|         if ($subscribe) { |         if ($subscribe) { | ||||||
|             $fans = WechatService::getFansInfo($this->openid); |             $fans = WechatService::getFansInfo($this->openid); | ||||||
|             if (empty($fans) || empty($fans['subscribe'])) { |             if (empty($fans) || empty($fans['subscribe'])) { | ||||||
|  | |||||||
| @ -27,7 +27,8 @@ use think\response\View; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/03/27 14:43 |  * @date 2017/03/27 14:43 | ||||||
|  */ |  */ | ||||||
| class Config extends BasicAdmin { | class Config extends BasicAdmin | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 定义当前操作表名 |      * 定义当前操作表名 | ||||||
| @ -39,7 +40,8 @@ class Config extends BasicAdmin { | |||||||
|      * 微信基础参数配置 |      * 微信基础参数配置 | ||||||
|      * @return View |      * @return View | ||||||
|      */ |      */ | ||||||
|     public function index() { |     public function index() | ||||||
|  |     { | ||||||
|         if ($this->request->isGet()) { |         if ($this->request->isGet()) { | ||||||
|             return view('', ['title' => '微信接口配置']); |             return view('', ['title' => '微信接口配置']); | ||||||
|         } |         } | ||||||
| @ -54,7 +56,8 @@ class Config extends BasicAdmin { | |||||||
|      * 微信商户参数配置 |      * 微信商户参数配置 | ||||||
|      * @return View |      * @return View | ||||||
|      */ |      */ | ||||||
|     public function pay() { |     public function pay() | ||||||
|  |     { | ||||||
|         if ($this->request->isGet()) { |         if ($this->request->isGet()) { | ||||||
|             switch ($this->request->get('action')) { |             switch ($this->request->get('action')) { | ||||||
|                 // 生成测试支付二维码
 |                 // 生成测试支付二维码
 | ||||||
|  | |||||||
| @ -27,7 +27,8 @@ use think\Db; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/03/27 14:43 |  * @date 2017/03/27 14:43 | ||||||
|  */ |  */ | ||||||
| class Fans extends BasicAdmin { | class Fans extends BasicAdmin | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 定义当前默认数据表 |      * 定义当前默认数据表 | ||||||
| @ -39,7 +40,8 @@ class Fans extends BasicAdmin { | |||||||
|      * 显示粉丝列表 |      * 显示粉丝列表 | ||||||
|      * @return array|string |      * @return array|string | ||||||
|      */ |      */ | ||||||
|     public function index() { |     public function index() | ||||||
|  |     { | ||||||
|         $this->title = '微信粉丝管理'; |         $this->title = '微信粉丝管理'; | ||||||
|         $db = Db::name($this->table)->where('is_back', '0')->order('subscribe_time desc'); |         $db = Db::name($this->table)->where('is_back', '0')->order('subscribe_time desc'); | ||||||
|         $get = $this->request->get(); |         $get = $this->request->get(); | ||||||
| @ -59,7 +61,8 @@ class Fans extends BasicAdmin { | |||||||
|      * 列表数据处理 |      * 列表数据处理 | ||||||
|      * @param type $list |      * @param type $list | ||||||
|      */ |      */ | ||||||
|     protected function _data_filter(&$list) { |     protected function _data_filter(&$list) | ||||||
|  |     { | ||||||
|         $tags = Db::name('WechatFansTags')->column('id,name'); |         $tags = Db::name('WechatFansTags')->column('id,name'); | ||||||
|         foreach ($list as &$vo) { |         foreach ($list as &$vo) { | ||||||
|             $vo['nickname'] = ToolsService::emojiDecode($vo['nickname']); |             $vo['nickname'] = ToolsService::emojiDecode($vo['nickname']); | ||||||
| @ -78,7 +81,8 @@ class Fans extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 黑名单列表 |      * 黑名单列表 | ||||||
|      */ |      */ | ||||||
|     public function back() { |     public function back() | ||||||
|  |     { | ||||||
|         $this->title = '微信粉丝黑名单管理'; |         $this->title = '微信粉丝黑名单管理'; | ||||||
|         $db = Db::name($this->table)->where('is_back', '1')->order('subscribe_time desc'); |         $db = Db::name($this->table)->where('is_back', '1')->order('subscribe_time desc'); | ||||||
|         $get = $this->request->get(); |         $get = $this->request->get(); | ||||||
| @ -97,8 +101,9 @@ class Fans extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 设置黑名单 |      * 设置黑名单 | ||||||
|      */ |      */ | ||||||
|     public function backadd() { |     public function backadd() | ||||||
|         $wechat = & load_wechat('User'); |     { | ||||||
|  |         $wechat = &load_wechat('User'); | ||||||
|         $openids = $this->_getActionOpenids(); |         $openids = $this->_getActionOpenids(); | ||||||
|         if (false !== $wechat->addBacklist($openids)) { |         if (false !== $wechat->addBacklist($openids)) { | ||||||
|             Db::name($this->table)->where('openid', 'in', $openids)->setField('is_back', '1'); |             Db::name($this->table)->where('openid', 'in', $openids)->setField('is_back', '1'); | ||||||
| @ -110,12 +115,13 @@ class Fans extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 标签选择 |      * 标签选择 | ||||||
|      */ |      */ | ||||||
|     public function tagset() { |     public function tagset() | ||||||
|  |     { | ||||||
|         $tags = $this->request->post('tags', ''); |         $tags = $this->request->post('tags', ''); | ||||||
|         $fans_id = $this->request->post('fans_id', ''); |         $fans_id = $this->request->post('fans_id', ''); | ||||||
|         $fans = Db::name('WechatFans')->where('id', $fans_id)->find(); |         $fans = Db::name('WechatFans')->where('id', $fans_id)->find(); | ||||||
|         empty($fans) && $this->error('需要操作的数据不存在!'); |         empty($fans) && $this->error('需要操作的数据不存在!'); | ||||||
|         $wechat = & load_wechat('User'); |         $wechat = &load_wechat('User'); | ||||||
|         foreach (explode(',', $fans['tagid_list']) as $tagid) { |         foreach (explode(',', $fans['tagid_list']) as $tagid) { | ||||||
|             is_numeric($tagid) && $wechat->batchDeleteUserTag($tagid, [$fans['openid']]); |             is_numeric($tagid) && $wechat->batchDeleteUserTag($tagid, [$fans['openid']]); | ||||||
|         } |         } | ||||||
| @ -131,8 +137,9 @@ class Fans extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 取消黑名 |      * 取消黑名 | ||||||
|      */ |      */ | ||||||
|     public function backdel() { |     public function backdel() | ||||||
|         $wechat = & load_wechat('User'); |     { | ||||||
|  |         $wechat = &load_wechat('User'); | ||||||
|         $openids = $this->_getActionOpenids(); |         $openids = $this->_getActionOpenids(); | ||||||
|         if (false !== $wechat->delBacklist($openids)) { |         if (false !== $wechat->delBacklist($openids)) { | ||||||
|             Db::name($this->table)->where('openid', 'in', $openids)->setField('is_back', '0'); |             Db::name($this->table)->where('openid', 'in', $openids)->setField('is_back', '0'); | ||||||
| @ -144,11 +151,12 @@ class Fans extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 给粉丝增加标签 |      * 给粉丝增加标签 | ||||||
|      */ |      */ | ||||||
|     public function tagadd() { |     public function tagadd() | ||||||
|  |     { | ||||||
|         $tagid = $this->request->post('tag_id', 0); |         $tagid = $this->request->post('tag_id', 0); | ||||||
|         empty($tagid) && $this->error('没有可能操作的标签ID'); |         empty($tagid) && $this->error('没有可能操作的标签ID'); | ||||||
|         $openids = $this->_getActionOpenids(); |         $openids = $this->_getActionOpenids(); | ||||||
|         $wechat = & load_wechat('User'); |         $wechat = &load_wechat('User'); | ||||||
|         if (false !== $wechat->batchAddUserTag($tagid, $openids)) { |         if (false !== $wechat->batchAddUserTag($tagid, $openids)) { | ||||||
|             $this->success('设置粉丝标签成功!', ''); |             $this->success('设置粉丝标签成功!', ''); | ||||||
|         } |         } | ||||||
| @ -158,11 +166,12 @@ class Fans extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 移除粉丝标签 |      * 移除粉丝标签 | ||||||
|      */ |      */ | ||||||
|     public function tagdel() { |     public function tagdel() | ||||||
|  |     { | ||||||
|         $tagid = $this->request->post('tag_id', 0); |         $tagid = $this->request->post('tag_id', 0); | ||||||
|         empty($tagid) && $this->error('没有可能操作的标签ID'); |         empty($tagid) && $this->error('没有可能操作的标签ID'); | ||||||
|         $openids = $this->_getActionOpenids(); |         $openids = $this->_getActionOpenids(); | ||||||
|         $wechat = & load_wechat('User'); |         $wechat = &load_wechat('User'); | ||||||
|         if (false !== $wechat->batchDeleteUserTag($tagid, $openids)) { |         if (false !== $wechat->batchDeleteUserTag($tagid, $openids)) { | ||||||
|             $this->success('删除粉丝标签成功!', ''); |             $this->success('删除粉丝标签成功!', ''); | ||||||
|         } |         } | ||||||
| @ -173,7 +182,8 @@ class Fans extends BasicAdmin { | |||||||
|      * 获取当前操作用户openid数组 |      * 获取当前操作用户openid数组 | ||||||
|      * @return array |      * @return array | ||||||
|      */ |      */ | ||||||
|     private function _getActionOpenids() { |     private function _getActionOpenids() | ||||||
|  |     { | ||||||
|         $ids = $this->request->post('id', ''); |         $ids = $this->request->post('id', ''); | ||||||
|         empty($ids) && $this->error('没有需要操作的数据!'); |         empty($ids) && $this->error('没有需要操作的数据!'); | ||||||
|         $openids = Db::name($this->table)->where('id', 'in', explode(',', $ids))->column('openid'); |         $openids = Db::name($this->table)->where('id', 'in', explode(',', $ids))->column('openid'); | ||||||
| @ -184,7 +194,8 @@ class Fans extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 同步粉丝列表 |      * 同步粉丝列表 | ||||||
|      */ |      */ | ||||||
|     public function sync() { |     public function sync() | ||||||
|  |     { | ||||||
|         Db::name($this->table)->where('1=1')->delete(); |         Db::name($this->table)->where('1=1')->delete(); | ||||||
|         if (WechatService::syncAllFans('')) { |         if (WechatService::syncAllFans('')) { | ||||||
|             WechatService::syncBlackFans(''); |             WechatService::syncBlackFans(''); | ||||||
|  | |||||||
| @ -24,7 +24,8 @@ use think\Db; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/03/27 14:43 |  * @date 2017/03/27 14:43 | ||||||
|  */ |  */ | ||||||
| class Keys extends BasicAdmin { | class Keys extends BasicAdmin | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 指定当前数据表 |      * 指定当前数据表 | ||||||
| @ -35,7 +36,8 @@ class Keys extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 显示关键字列表 |      * 显示关键字列表 | ||||||
|      */ |      */ | ||||||
|     public function index() { |     public function index() | ||||||
|  |     { | ||||||
|         $this->assign('title', '微信关键字'); |         $this->assign('title', '微信关键字'); | ||||||
|         $db = Db::name($this->table)->where('keys', 'not in', ['subscribe', 'default']); |         $db = Db::name($this->table)->where('keys', 'not in', ['subscribe', 'default']); | ||||||
|         return $this->_list($db); |         return $this->_list($db); | ||||||
| @ -45,7 +47,8 @@ class Keys extends BasicAdmin { | |||||||
|      * 列表数据处理 |      * 列表数据处理 | ||||||
|      * @param array $data |      * @param array $data | ||||||
|      */ |      */ | ||||||
|     protected function _index_data_filter(&$data) { |     protected function _index_data_filter(&$data) | ||||||
|  |     { | ||||||
|         $types = ['keys' => '关键字', 'image' => '图片', 'news' => '图文', 'music' => '音乐', 'text' => '文字', 'video' => '视频', 'voice' => '语音']; |         $types = ['keys' => '关键字', 'image' => '图片', 'news' => '图文', 'music' => '音乐', 'text' => '文字', 'video' => '视频', 'voice' => '语音']; | ||||||
|         foreach ($data as &$vo) { |         foreach ($data as &$vo) { | ||||||
|             $vo['type'] = isset($types[$vo['type']]) ? $types[$vo['type']] : $vo['type']; |             $vo['type'] = isset($types[$vo['type']]) ? $types[$vo['type']] : $vo['type']; | ||||||
| @ -56,7 +59,8 @@ class Keys extends BasicAdmin { | |||||||
|      * 添加关键字 |      * 添加关键字 | ||||||
|      * @return string |      * @return string | ||||||
|      */ |      */ | ||||||
|     public function add() { |     public function add() | ||||||
|  |     { | ||||||
|         $this->title = '添加关键字规则'; |         $this->title = '添加关键字规则'; | ||||||
|         return $this->_form($this->table, 'form'); |         return $this->_form($this->table, 'form'); | ||||||
|     } |     } | ||||||
| @ -65,7 +69,8 @@ class Keys extends BasicAdmin { | |||||||
|      * 编辑关键字 |      * 编辑关键字 | ||||||
|      * @return string |      * @return string | ||||||
|      */ |      */ | ||||||
|     public function edit() { |     public function edit() | ||||||
|  |     { | ||||||
|         $this->title = '编辑关键字规则'; |         $this->title = '编辑关键字规则'; | ||||||
|         return $this->_form($this->table, 'form'); |         return $this->_form($this->table, 'form'); | ||||||
|     } |     } | ||||||
| @ -75,7 +80,8 @@ class Keys extends BasicAdmin { | |||||||
|      * 表单处理 |      * 表单处理 | ||||||
|      * @param $data |      * @param $data | ||||||
|      */ |      */ | ||||||
|     protected function _form_filter($data) { |     protected function _form_filter($data) | ||||||
|  |     { | ||||||
|         if ($this->request->isPost() && isset($data['keys'])) { |         if ($this->request->isPost() && isset($data['keys'])) { | ||||||
|             $db = Db::name($this->table)->where('keys', $data['keys']); |             $db = Db::name($this->table)->where('keys', $data['keys']); | ||||||
|             !empty($data['id']) && $db->where('id', 'neq', $data['id']); |             !empty($data['id']) && $db->where('id', 'neq', $data['id']); | ||||||
| @ -86,7 +92,8 @@ class Keys extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 删除关键字 |      * 删除关键字 | ||||||
|      */ |      */ | ||||||
|     public function del() { |     public function del() | ||||||
|  |     { | ||||||
|         if (DataService::update($this->table)) { |         if (DataService::update($this->table)) { | ||||||
|             $this->success("关键字删除成功!", ''); |             $this->success("关键字删除成功!", ''); | ||||||
|         } |         } | ||||||
| @ -97,7 +104,8 @@ class Keys extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 关键字禁用 |      * 关键字禁用 | ||||||
|      */ |      */ | ||||||
|     public function forbid() { |     public function forbid() | ||||||
|  |     { | ||||||
|         if (DataService::update($this->table)) { |         if (DataService::update($this->table)) { | ||||||
|             $this->success("关键字禁用成功!", ''); |             $this->success("关键字禁用成功!", ''); | ||||||
|         } |         } | ||||||
| @ -107,7 +115,8 @@ class Keys extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 关键字禁用 |      * 关键字禁用 | ||||||
|      */ |      */ | ||||||
|     public function resume() { |     public function resume() | ||||||
|  |     { | ||||||
|         if (DataService::update($this->table)) { |         if (DataService::update($this->table)) { | ||||||
|             $this->success("关键字启用成功!", ''); |             $this->success("关键字启用成功!", ''); | ||||||
|         } |         } | ||||||
| @ -117,7 +126,8 @@ class Keys extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 关注默认回复 |      * 关注默认回复 | ||||||
|      */ |      */ | ||||||
|     public function subscribe() { |     public function subscribe() | ||||||
|  |     { | ||||||
|         $this->assign('title', '编辑默认回复'); |         $this->assign('title', '编辑默认回复'); | ||||||
|         return $this->_form($this->table, 'form'); |         return $this->_form($this->table, 'form'); | ||||||
|     } |     } | ||||||
| @ -126,7 +136,8 @@ class Keys extends BasicAdmin { | |||||||
|      * 关注默认回复表单处理 |      * 关注默认回复表单处理 | ||||||
|      * @param $data |      * @param $data | ||||||
|      */ |      */ | ||||||
|     protected function _subscribe_form_filter(&$data) { |     protected function _subscribe_form_filter(&$data) | ||||||
|  |     { | ||||||
|         if ($this->request->isGet()) { |         if ($this->request->isGet()) { | ||||||
|             $data = Db::name($this->table)->where('keys', 'subscribe')->find(); |             $data = Db::name($this->table)->where('keys', 'subscribe')->find(); | ||||||
|         } |         } | ||||||
| @ -137,7 +148,8 @@ class Keys extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 无配置默认回复 |      * 无配置默认回复 | ||||||
|      */ |      */ | ||||||
|     public function defaults() { |     public function defaults() | ||||||
|  |     { | ||||||
|         $this->assign('title', '编辑无配置默认回复'); |         $this->assign('title', '编辑无配置默认回复'); | ||||||
|         return $this->_form($this->table, 'form'); |         return $this->_form($this->table, 'form'); | ||||||
|     } |     } | ||||||
| @ -147,7 +159,8 @@ class Keys extends BasicAdmin { | |||||||
|      * 无配置默认回复表单处理 |      * 无配置默认回复表单处理 | ||||||
|      * @param $data |      * @param $data | ||||||
|      */ |      */ | ||||||
|     protected function _defaults_form_filter(&$data) { |     protected function _defaults_form_filter(&$data) | ||||||
|  |     { | ||||||
|         if ($this->request->isGet()) { |         if ($this->request->isGet()) { | ||||||
|             $data = Db::name($this->table)->where('keys', 'default')->find(); |             $data = Db::name($this->table)->where('keys', 'default')->find(); | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -26,7 +26,8 @@ use think\Db; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/03/27 14:43 |  * @date 2017/03/27 14:43 | ||||||
|  */ |  */ | ||||||
| class Menu extends BasicAdmin { | class Menu extends BasicAdmin | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 指定当前页面标题 |      * 指定当前页面标题 | ||||||
| @ -45,20 +46,21 @@ class Menu extends BasicAdmin { | |||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     protected $menu_type = array( |     protected $menu_type = array( | ||||||
|         'view'               => '跳转URL', |         'view' => '跳转URL', | ||||||
|         'click'              => '点击推事件', |         'click' => '点击推事件', | ||||||
|         'scancode_push'      => '扫码推事件', |         'scancode_push' => '扫码推事件', | ||||||
|         'scancode_waitmsg'   => '扫码推事件且弹出“消息接收中”提示框', |         'scancode_waitmsg' => '扫码推事件且弹出“消息接收中”提示框', | ||||||
|         'pic_sysphoto'       => '弹出系统拍照发图', |         'pic_sysphoto' => '弹出系统拍照发图', | ||||||
|         'pic_photo_or_album' => '弹出拍照或者相册发图', |         'pic_photo_or_album' => '弹出拍照或者相册发图', | ||||||
|         'pic_weixin'         => '弹出微信相册发图器', |         'pic_weixin' => '弹出微信相册发图器', | ||||||
|         'location_select'    => '弹出地理位置选择器', |         'location_select' => '弹出地理位置选择器', | ||||||
|     ); |     ); | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 显示列表操作 |      * 显示列表操作 | ||||||
|      */ |      */ | ||||||
|     public function index() { |     public function index() | ||||||
|  |     { | ||||||
|         return parent::_list(Db::name($this->table), false, true); |         return parent::_list(Db::name($this->table), false, true); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -66,14 +68,16 @@ class Menu extends BasicAdmin { | |||||||
|      * 列表数据处理 |      * 列表数据处理 | ||||||
|      * @param array $data |      * @param array $data | ||||||
|      */ |      */ | ||||||
|     protected function _index_data_filter(&$data) { |     protected function _index_data_filter(&$data) | ||||||
|  |     { | ||||||
|         $data = ToolsService::arr2tree($data, 'index', 'pindex'); |         $data = ToolsService::arr2tree($data, 'index', 'pindex'); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 微信菜单编辑 |      * 微信菜单编辑 | ||||||
|      */ |      */ | ||||||
|     public function edit() { |     public function edit() | ||||||
|  |     { | ||||||
|         if ($this->request->isPost()) { |         if ($this->request->isPost()) { | ||||||
|             $post = $this->request->post(); |             $post = $this->request->post(); | ||||||
|             !isset($post['data']) && $this->error('访问出错,请稍候再试!'); |             !isset($post['data']) && $this->error('访问出错,请稍候再试!'); | ||||||
| @ -103,7 +107,8 @@ class Menu extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 取消菜单 |      * 取消菜单 | ||||||
|      */ |      */ | ||||||
|     public function cancel() { |     public function cancel() | ||||||
|  |     { | ||||||
|         $wehcat = &load_wechat('Menu'); |         $wehcat = &load_wechat('Menu'); | ||||||
|         if (false !== $wehcat->deleteMenu()) { |         if (false !== $wehcat->deleteMenu()) { | ||||||
|             $this->success('菜单取消成功,重新关注可立即生效!', ''); |             $this->success('菜单取消成功,重新关注可立即生效!', ''); | ||||||
| @ -114,12 +119,13 @@ class Menu extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 菜单推送 |      * 菜单推送 | ||||||
|      */ |      */ | ||||||
|     protected function _push() { |     protected function _push() | ||||||
|  |     { | ||||||
|         $result = Db::name($this->table) |         $result = Db::name($this->table) | ||||||
|                 ->field('id,index,pindex,name,type,content') |             ->field('id,index,pindex,name,type,content') | ||||||
|                 ->where('status', '1') |             ->where('status', '1') | ||||||
|                 ->order('sort ASC,id ASC') |             ->order('sort ASC,id ASC') | ||||||
|                 ->select(); |             ->select(); | ||||||
|         foreach ($result as &$row) { |         foreach ($result as &$row) { | ||||||
|             empty($row['content']) && $row['content'] = uniqid(); |             empty($row['content']) && $row['content'] = uniqid(); | ||||||
|             switch ($row['type']) { |             switch ($row['type']) { | ||||||
|  | |||||||
| @ -29,7 +29,8 @@ use think\response\View; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/03/27 14:43 |  * @date 2017/03/27 14:43 | ||||||
|  */ |  */ | ||||||
| class News extends BasicAdmin { | class News extends BasicAdmin | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 设置默认操作表 |      * 设置默认操作表 | ||||||
| @ -40,7 +41,8 @@ class News extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 图文列表 |      * 图文列表 | ||||||
|      */ |      */ | ||||||
|     public function index() { |     public function index() | ||||||
|  |     { | ||||||
|         $this->assign('title', '图文列表'); |         $this->assign('title', '图文列表'); | ||||||
|         $db = Db::name($this->table)->where('is_deleted', '0')->order('id desc'); |         $db = Db::name($this->table)->where('is_deleted', '0')->order('id desc'); | ||||||
|         return parent::_list($db); |         return parent::_list($db); | ||||||
| @ -50,7 +52,8 @@ class News extends BasicAdmin { | |||||||
|      * 图文选择器 |      * 图文选择器 | ||||||
|      * @return string |      * @return string | ||||||
|      */ |      */ | ||||||
|     public function select() { |     public function select() | ||||||
|  |     { | ||||||
|         return $this->index(); |         return $this->index(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -58,7 +61,8 @@ class News extends BasicAdmin { | |||||||
|      * 媒体资源显示 |      * 媒体资源显示 | ||||||
|      * @return array |      * @return array | ||||||
|      */ |      */ | ||||||
|     public function image() { |     public function image() | ||||||
|  |     { | ||||||
|         $_GET['rows'] = 18; |         $_GET['rows'] = 18; | ||||||
|         $this->assign('field', $this->request->get('field', 'local_url')); |         $this->assign('field', $this->request->get('field', 'local_url')); | ||||||
|         return $this->_list(Db::name('WechatNewsMedia')->where('type', 'image')); |         return $this->_list(Db::name('WechatNewsMedia')->where('type', 'image')); | ||||||
| @ -68,7 +72,8 @@ class News extends BasicAdmin { | |||||||
|      * 图文列表数据处理 |      * 图文列表数据处理 | ||||||
|      * @param $data |      * @param $data | ||||||
|      */ |      */ | ||||||
|     protected function _index_data_filter(&$data) { |     protected function _index_data_filter(&$data) | ||||||
|  |     { | ||||||
|         foreach ($data as &$vo) { |         foreach ($data as &$vo) { | ||||||
|             $vo = WechatService::getNewsById($vo['id']); |             $vo = WechatService::getNewsById($vo['id']); | ||||||
|         } |         } | ||||||
| @ -78,7 +83,8 @@ class News extends BasicAdmin { | |||||||
|      * 图文列表数据处理 |      * 图文列表数据处理 | ||||||
|      * @param $data |      * @param $data | ||||||
|      */ |      */ | ||||||
|     protected function _select_data_filter(&$data) { |     protected function _select_data_filter(&$data) | ||||||
|  |     { | ||||||
|         foreach ($data as &$vo) { |         foreach ($data as &$vo) { | ||||||
|             $vo = WechatService::getNewsById($vo['id']); |             $vo = WechatService::getNewsById($vo['id']); | ||||||
|         } |         } | ||||||
| @ -88,7 +94,8 @@ class News extends BasicAdmin { | |||||||
|      * 添加图文 |      * 添加图文 | ||||||
|      * @return View |      * @return View | ||||||
|      */ |      */ | ||||||
|     public function add() { |     public function add() | ||||||
|  |     { | ||||||
|         if ($this->request->isGet()) { |         if ($this->request->isGet()) { | ||||||
|             return view('form', ['title' => '新建图文']); |             return view('form', ['title' => '新建图文']); | ||||||
|         } |         } | ||||||
| @ -108,7 +115,8 @@ class News extends BasicAdmin { | |||||||
|      * 编辑图文 |      * 编辑图文 | ||||||
|      * @return View |      * @return View | ||||||
|      */ |      */ | ||||||
|     public function edit() { |     public function edit() | ||||||
|  |     { | ||||||
|         $id = $this->request->get('id', ''); |         $id = $this->request->get('id', ''); | ||||||
|         if ($this->request->isGet()) { |         if ($this->request->isGet()) { | ||||||
|             empty($id) && $this->error('参数错误,请稍候再试!'); |             empty($id) && $this->error('参数错误,请稍候再试!'); | ||||||
| @ -131,7 +139,8 @@ class News extends BasicAdmin { | |||||||
|      * @param array $ids |      * @param array $ids | ||||||
|      * @return string |      * @return string | ||||||
|      */ |      */ | ||||||
|     protected function _apply_news_article($data, $ids = []) { |     protected function _apply_news_article($data, $ids = []) | ||||||
|  |     { | ||||||
|         foreach ($data as &$vo) { |         foreach ($data as &$vo) { | ||||||
|             $vo['create_by'] = session('user.id'); |             $vo['create_by'] = session('user.id'); | ||||||
|             $vo['create_at'] = date('Y-m-d H:i:s'); |             $vo['create_at'] = date('Y-m-d H:i:s'); | ||||||
| @ -152,7 +161,8 @@ class News extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 删除用户 |      * 删除用户 | ||||||
|      */ |      */ | ||||||
|     public function del() { |     public function del() | ||||||
|  |     { | ||||||
|         if (DataService::update($this->table)) { |         if (DataService::update($this->table)) { | ||||||
|             $this->success("图文删除成功!", ''); |             $this->success("图文删除成功!", ''); | ||||||
|         } |         } | ||||||
| @ -163,7 +173,8 @@ class News extends BasicAdmin { | |||||||
|      * 推荐图文 |      * 推荐图文 | ||||||
|      * @return array|void |      * @return array|void | ||||||
|      */ |      */ | ||||||
|     public function push() { |     public function push() | ||||||
|  |     { | ||||||
|         # 获取将要推送的粉丝列表
 |         # 获取将要推送的粉丝列表
 | ||||||
|         switch (strtolower($this->request->get('action', ''))) { |         switch (strtolower($this->request->get('action', ''))) { | ||||||
|             case 'getuser': |             case 'getuser': | ||||||
| @ -182,8 +193,8 @@ class News extends BasicAdmin { | |||||||
|                 if ($this->request->isGet()) { |                 if ($this->request->isGet()) { | ||||||
|                     $fans_tags = Db::name('WechatFansTags')->select(); |                     $fans_tags = Db::name('WechatFansTags')->select(); | ||||||
|                     array_unshift($fans_tags, [ |                     array_unshift($fans_tags, [ | ||||||
|                         'id'    => 0, |                         'id' => 0, | ||||||
|                         'name'  => '全部', |                         'name' => '全部', | ||||||
|                         'count' => Db::name('WechatFans')->where('subscribe', '1')->count(), |                         'count' => Db::name('WechatFans')->where('subscribe', '1')->count(), | ||||||
|                     ]); |                     ]); | ||||||
|                     return view('push', ['vo' => $newsinfo, 'fans_tags' => $fans_tags]); |                     return view('push', ['vo' => $newsinfo, 'fans_tags' => $fans_tags]); | ||||||
| @ -218,7 +229,8 @@ class News extends BasicAdmin { | |||||||
|      * @param type $newsinfo |      * @param type $newsinfo | ||||||
|      * @return boolean |      * @return boolean | ||||||
|      */ |      */ | ||||||
|     private function _uploadWechatNews(&$newsinfo) { |     private function _uploadWechatNews(&$newsinfo) | ||||||
|  |     { | ||||||
|         foreach ($newsinfo['articles'] as &$article) { |         foreach ($newsinfo['articles'] as &$article) { | ||||||
|             $article['thumb_media_id'] = WechatService::uploadForeverMedia($article['local_url']); |             $article['thumb_media_id'] = WechatService::uploadForeverMedia($article['local_url']); | ||||||
|             $article['content'] = preg_replace_callback("/<img(.*?)src=['\"](.*?)['\"](.*?)\/?>/i", function ($matches) { |             $article['content'] = preg_replace_callback("/<img(.*?)src=['\"](.*?)['\"](.*?)\/?>/i", function ($matches) { | ||||||
| @ -226,7 +238,7 @@ class News extends BasicAdmin { | |||||||
|                 return "<img{$matches[1]}src=\"{$src}\"{$matches[3]}/>"; |                 return "<img{$matches[1]}src=\"{$src}\"{$matches[3]}/>"; | ||||||
|             }, htmlspecialchars_decode($article['content'])); |             }, htmlspecialchars_decode($article['content'])); | ||||||
|         } |         } | ||||||
|         $wechat = & load_wechat('media'); |         $wechat = &load_wechat('media'); | ||||||
|         // 如果已经上传过,先删除之前的历史记录
 |         // 如果已经上传过,先删除之前的历史记录
 | ||||||
|         !empty($newsinfo['media_id']) && $wechat->delForeverMedia($newsinfo['media_id']); |         !empty($newsinfo['media_id']) && $wechat->delForeverMedia($newsinfo['media_id']); | ||||||
|         // 上传图文到微信服务器
 |         // 上传图文到微信服务器
 | ||||||
|  | |||||||
| @ -25,9 +25,11 @@ use think\Log; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/04/05 14:02 |  * @date 2017/04/05 14:02 | ||||||
|  */ |  */ | ||||||
| class Notify extends Controller { | class Notify extends Controller | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     public function index() { |     public function index() | ||||||
|  |     { | ||||||
|         // 实例支付接口
 |         // 实例支付接口
 | ||||||
|         $pay = &load_wechat('Pay'); |         $pay = &load_wechat('Pay'); | ||||||
| 
 | 
 | ||||||
| @ -43,7 +45,7 @@ class Notify extends Controller { | |||||||
|             //支付通知数据获取成功
 |             //支付通知数据获取成功
 | ||||||
|             if ($notifyInfo['result_code'] == 'SUCCESS' && $notifyInfo['return_code'] == 'SUCCESS') { |             if ($notifyInfo['result_code'] == 'SUCCESS' && $notifyInfo['return_code'] == 'SUCCESS') { | ||||||
|                 // 记录支付通知数据
 |                 // 记录支付通知数据
 | ||||||
|                 if(!Db::name('WechatPayNotify')->insert($notifyInfo)){ |                 if (!Db::name('WechatPayNotify')->insert($notifyInfo)) { | ||||||
|                     $pay->replyXml(['return_code' => 'ERROR', 'return_msg' => '系统记录微信通知时发生异常!']); |                     $pay->replyXml(['return_code' => 'ERROR', 'return_msg' => '系统记录微信通知时发生异常!']); | ||||||
|                 } |                 } | ||||||
|                 $prepayMap = ['out_trade_no' => $notifyInfo['out_trade_no']]; |                 $prepayMap = ['out_trade_no' => $notifyInfo['out_trade_no']]; | ||||||
|  | |||||||
| @ -19,13 +19,15 @@ use service\WechatService; | |||||||
| use think\Controller; | use think\Controller; | ||||||
| use think\Db; | use think\Db; | ||||||
| 
 | 
 | ||||||
| class Review extends Controller { | class Review extends Controller | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 显示手机预览 |      * 显示手机预览 | ||||||
|      * @return string |      * @return string | ||||||
|      */ |      */ | ||||||
|     public function index() { |     public function index() | ||||||
|  |     { | ||||||
|         $get = $this->request->get(); |         $get = $this->request->get(); | ||||||
|         $content = str_replace("\n", "<br>", $this->request->get('content', '')); // 内容
 |         $content = str_replace("\n", "<br>", $this->request->get('content', '')); // 内容
 | ||||||
|         $type = $this->request->get('type', 'text'); // 类型
 |         $type = $this->request->get('type', 'text'); // 类型
 | ||||||
| @ -49,7 +51,8 @@ class Review extends Controller { | |||||||
|     /** |     /** | ||||||
|      * 微信图片显示 |      * 微信图片显示 | ||||||
|      */ |      */ | ||||||
|     public function img() { |     public function img() | ||||||
|  |     { | ||||||
|         $url = $this->request->get('url', ''); |         $url = $this->request->get('url', ''); | ||||||
|         $filename = FileService::getFileName($url, 'jpg', 'tmp/'); |         $filename = FileService::getFileName($url, 'jpg', 'tmp/'); | ||||||
|         if (false === ($img = FileService::getFileUrl($filename))) { |         if (false === ($img = FileService::getFileUrl($filename))) { | ||||||
|  | |||||||
| @ -27,7 +27,8 @@ use think\Db; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/03/27 14:43 |  * @date 2017/03/27 14:43 | ||||||
|  */ |  */ | ||||||
| class Tags extends BasicAdmin { | class Tags extends BasicAdmin | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 定义当前默认数据表 |      * 定义当前默认数据表 | ||||||
| @ -39,7 +40,8 @@ class Tags extends BasicAdmin { | |||||||
|      * 显示粉丝标签列表 |      * 显示粉丝标签列表 | ||||||
|      * @return array|string |      * @return array|string | ||||||
|      */ |      */ | ||||||
|     public function index() { |     public function index() | ||||||
|  |     { | ||||||
|         $this->title = '微信粉丝标签管理'; |         $this->title = '微信粉丝标签管理'; | ||||||
|         $get = $this->request->get(); |         $get = $this->request->get(); | ||||||
|         $db = Db::name($this->table)->order('id asc'); |         $db = Db::name($this->table)->order('id asc'); | ||||||
| @ -54,14 +56,15 @@ class Tags extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 添加粉丝标签 |      * 添加粉丝标签 | ||||||
|      */ |      */ | ||||||
|     public function add() { |     public function add() | ||||||
|  |     { | ||||||
|         if ($this->request->isGet()) { |         if ($this->request->isGet()) { | ||||||
|             return parent::_form($this->table, 'form', 'id'); |             return parent::_form($this->table, 'form', 'id'); | ||||||
|         } |         } | ||||||
|         $name = $this->request->post('name', ''); |         $name = $this->request->post('name', ''); | ||||||
|         empty($name) && $this->error('粉丝标签名不能为空!'); |         empty($name) && $this->error('粉丝标签名不能为空!'); | ||||||
|         (Db::name($this->table)->where('name', $name)->count() > 0) && $this->error('粉丝标签标签名已经存在, 请使用其它标签名!'); |         (Db::name($this->table)->where('name', $name)->count() > 0) && $this->error('粉丝标签标签名已经存在, 请使用其它标签名!'); | ||||||
|         $wechat = & load_wechat('User'); |         $wechat = &load_wechat('User'); | ||||||
|         if (false === ($result = $wechat->createTags($name)) && isset($result['tag'])) { |         if (false === ($result = $wechat->createTags($name)) && isset($result['tag'])) { | ||||||
|             $this->error("添加粉丝标签失败. {$wechat->errMsg}[{$wechat->errCode}]"); |             $this->error("添加粉丝标签失败. {$wechat->errMsg}[{$wechat->errCode}]"); | ||||||
|         } |         } | ||||||
| @ -73,7 +76,8 @@ class Tags extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 编辑粉丝标签 |      * 编辑粉丝标签 | ||||||
|      */ |      */ | ||||||
|     public function edit() { |     public function edit() | ||||||
|  |     { | ||||||
|         // 显示编辑界面
 |         // 显示编辑界面
 | ||||||
|         if ($this->request->isGet()) { |         if ($this->request->isGet()) { | ||||||
|             return parent::_form($this->table, 'form', 'id'); |             return parent::_form($this->table, 'form', 'id'); | ||||||
| @ -98,7 +102,8 @@ class Tags extends BasicAdmin { | |||||||
|     /** |     /** | ||||||
|      * 同步粉丝标签列表 |      * 同步粉丝标签列表 | ||||||
|      */ |      */ | ||||||
|     public function sync() { |     public function sync() | ||||||
|  |     { | ||||||
|         Db::name($this->table)->where('1=1')->delete(); |         Db::name($this->table)->where('1=1')->delete(); | ||||||
|         if (WechatService::syncFansTags()) { |         if (WechatService::syncFansTags()) { | ||||||
|             LogService::write('微信管理', '同步全部微信粉丝标签成功'); |             LogService::write('微信管理', '同步全部微信粉丝标签成功'); | ||||||
|  | |||||||
| @ -24,7 +24,8 @@ use think\Db; | |||||||
|  * Class BasicAdmin |  * Class BasicAdmin | ||||||
|  * @package controller |  * @package controller | ||||||
|  */ |  */ | ||||||
| class BasicAdmin extends Controller { | class BasicAdmin extends Controller | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 页面标题 |      * 页面标题 | ||||||
| @ -59,13 +60,14 @@ class BasicAdmin extends Controller { | |||||||
|      * @param array $extendData 扩展数据 |      * @param array $extendData 扩展数据 | ||||||
|      * @return array|string |      * @return array|string | ||||||
|      */ |      */ | ||||||
|     protected function _form($dbQuery = null, $tplFile = '', $pkField = '', $where = [], $extendData = []) { |     protected function _form($dbQuery = null, $tplFile = '', $pkField = '', $where = [], $extendData = []) | ||||||
|  |     { | ||||||
|         $db = is_null($dbQuery) ? Db::name($this->table) : (is_string($dbQuery) ? Db::name($dbQuery) : $dbQuery); |         $db = is_null($dbQuery) ? Db::name($this->table) : (is_string($dbQuery) ? Db::name($dbQuery) : $dbQuery); | ||||||
|         $pk = empty($pkField) ? ($db->getPk() ? $db->getPk() : 'id') : $pkField; |         $pk = empty($pkField) ? ($db->getPk() ? $db->getPk() : 'id') : $pkField; | ||||||
|         $pkValue = $this->request->request($pk, isset($where[$pk]) ? $where[$pk] : (isset($extendData[$pk]) ? $extendData[$pk] : null)); |         $pkValue = $this->request->request($pk, isset($where[$pk]) ? $where[$pk] : (isset($extendData[$pk]) ? $extendData[$pk] : null)); | ||||||
|         // 非POST请求, 获取数据并显示表单页面
 |         // 非POST请求, 获取数据并显示表单页面
 | ||||||
|         if (!$this->request->isPost()) { |         if (!$this->request->isPost()) { | ||||||
|             $vo = ($pkValue !== null) ? array_merge((array) $db->where($pk, $pkValue)->where($where)->find(), $extendData) : $extendData; |             $vo = ($pkValue !== null) ? array_merge((array)$db->where($pk, $pkValue)->where($where)->find(), $extendData) : $extendData; | ||||||
|             if (false !== $this->_callback('_form_filter', $vo)) { |             if (false !== $this->_callback('_form_filter', $vo)) { | ||||||
|                 empty($this->title) || $this->assign('title', $this->title); |                 empty($this->title) || $this->assign('title', $this->title); | ||||||
|                 return $this->fetch($tplFile, ['vo' => $vo]); |                 return $this->fetch($tplFile, ['vo' => $vo]); | ||||||
| @ -90,7 +92,8 @@ class BasicAdmin extends Controller { | |||||||
|      * @param bool $total 总记录数 |      * @param bool $total 总记录数 | ||||||
|      * @return array|string |      * @return array|string | ||||||
|      */ |      */ | ||||||
|     protected function _list($dbQuery = null, $isPage = true, $isDisplay = true, $total = false) { |     protected function _list($dbQuery = null, $isPage = true, $isDisplay = true, $total = false) | ||||||
|  |     { | ||||||
|         $db = is_null($dbQuery) ? Db::name($this->table) : (is_string($dbQuery) ? Db::name($dbQuery) : $dbQuery); |         $db = is_null($dbQuery) ? Db::name($this->table) : (is_string($dbQuery) ? Db::name($dbQuery) : $dbQuery); | ||||||
|         // 列表排序默认处理
 |         // 列表排序默认处理
 | ||||||
|         if ($this->request->isPost() && $this->request->post('action') === 'resort') { |         if ($this->request->isPost() && $this->request->post('action') === 'resort') { | ||||||
| @ -131,7 +134,8 @@ class BasicAdmin extends Controller { | |||||||
|      * @param array|bool $data |      * @param array|bool $data | ||||||
|      * @return bool |      * @return bool | ||||||
|      */ |      */ | ||||||
|     protected function _callback($method, &$data) { |     protected function _callback($method, &$data) | ||||||
|  |     { | ||||||
|         foreach ([$method, "_" . $this->request->action() . "{$method}"] as $_method) { |         foreach ([$method, "_" . $this->request->action() . "{$method}"] as $_method) { | ||||||
|             if (method_exists($this, $_method) && false === $this->$_method($data)) { |             if (method_exists($this, $_method) && false === $this->$_method($data)) { | ||||||
|                 return false; |                 return false; | ||||||
|  | |||||||
| @ -24,7 +24,8 @@ use think\Response; | |||||||
|  * Class BasicApi |  * Class BasicApi | ||||||
|  * @package controller |  * @package controller | ||||||
|  */ |  */ | ||||||
| class BasicApi { | class BasicApi | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 访问请求对象 |      * 访问请求对象 | ||||||
| @ -42,7 +43,8 @@ class BasicApi { | |||||||
|      * 基础接口SDK |      * 基础接口SDK | ||||||
|      * @param Request|null $request |      * @param Request|null $request | ||||||
|      */ |      */ | ||||||
|     public function __construct(Request $request = null) { |     public function __construct(Request $request = null) | ||||||
|  |     { | ||||||
|         // CORS 跨域 Options 检测响应
 |         // CORS 跨域 Options 检测响应
 | ||||||
|         ToolsService::corsOptionsHandler(); |         ToolsService::corsOptionsHandler(); | ||||||
|         // 获取当前 Request 对象
 |         // 获取当前 Request 对象
 | ||||||
| @ -66,7 +68,8 @@ class BasicApi { | |||||||
|      * @param string $type 返回类型 JSON XML |      * @param string $type 返回类型 JSON XML | ||||||
|      * @return Response |      * @return Response | ||||||
|      */ |      */ | ||||||
|     public function response($msg, $code = 'SUCCESS', $data = [], $type = 'json') { |     public function response($msg, $code = 'SUCCESS', $data = [], $type = 'json') | ||||||
|  |     { | ||||||
|         $result = ['msg' => $msg, 'code' => $code, 'data' => $data, 'token' => $this->token, 'dataType' => strtolower($type)]; |         $result = ['msg' => $msg, 'code' => $code, 'data' => $data, 'token' => $this->token, 'dataType' => strtolower($type)]; | ||||||
|         return Response::create($result, $type)->header(ToolsService::corsRequestHander())->code(200); |         return Response::create($result, $type)->header(ToolsService::corsRequestHander())->code(200); | ||||||
|     } |     } | ||||||
| @ -78,7 +81,8 @@ class BasicApi { | |||||||
|      * @param int|null $expire 有效时间 0为永久 |      * @param int|null $expire 有效时间 0为永久 | ||||||
|      * @return bool |      * @return bool | ||||||
|      */ |      */ | ||||||
|     public function setCache($name, $value, $expire = null) { |     public function setCache($name, $value, $expire = null) | ||||||
|  |     { | ||||||
|         return Cache::set("{$this->token}_{$name}", $value, $expire); |         return Cache::set("{$this->token}_{$name}", $value, $expire); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -88,7 +92,8 @@ class BasicApi { | |||||||
|      * @param mixed $default 默认值 |      * @param mixed $default 默认值 | ||||||
|      * @return mixed |      * @return mixed | ||||||
|      */ |      */ | ||||||
|     public function getCache($name, $default = false) { |     public function getCache($name, $default = false) | ||||||
|  |     { | ||||||
|         return Cache::get("{$this->token}_{$name}", $default); |         return Cache::get("{$this->token}_{$name}", $default); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -97,7 +102,8 @@ class BasicApi { | |||||||
|      * @param string $name 缓存标识 |      * @param string $name 缓存标识 | ||||||
|      * @return bool |      * @return bool | ||||||
|      */ |      */ | ||||||
|     public function delCache($name) { |     public function delCache($name) | ||||||
|  |     { | ||||||
|         return Cache::rm("{$this->token}_{$name}"); |         return Cache::rm("{$this->token}_{$name}"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -105,7 +111,8 @@ class BasicApi { | |||||||
|      * API接口调度 |      * API接口调度 | ||||||
|      * @return Response |      * @return Response | ||||||
|      */ |      */ | ||||||
|     public function _empty() { |     public function _empty() | ||||||
|  |     { | ||||||
|         list($module, $controller, $action, $method) = explode('/', $this->request->path() . '///'); |         list($module, $controller, $action, $method) = explode('/', $this->request->path() . '///'); | ||||||
|         if (!empty($module) && !empty($controller) && !empty($action) && !empty($method)) { |         if (!empty($module) && !empty($controller) && !empty($action) && !empty($method)) { | ||||||
|             $action = ucfirst($action); |             $action = ucfirst($action); | ||||||
|  | |||||||
| @ -23,7 +23,8 @@ use think\Log; | |||||||
|  * Class BasicWechat |  * Class BasicWechat | ||||||
|  * @package controller |  * @package controller | ||||||
|  */ |  */ | ||||||
| class BasicWechat extends Controller { | class BasicWechat extends Controller | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 当前粉丝用户OPENID |      * 当前粉丝用户OPENID | ||||||
| @ -52,7 +53,8 @@ class BasicWechat extends Controller { | |||||||
|     /** |     /** | ||||||
|      * 初始化方法 |      * 初始化方法 | ||||||
|      */ |      */ | ||||||
|     public function _initialize() { |     public function _initialize() | ||||||
|  |     { | ||||||
|         // 当前完整URL地址
 |         // 当前完整URL地址
 | ||||||
|         $this->url = $this->request->url(true); |         $this->url = $this->request->url(true); | ||||||
|         // 网页授权,并获粉丝信息
 |         // 网页授权,并获粉丝信息
 | ||||||
| @ -66,7 +68,8 @@ class BasicWechat extends Controller { | |||||||
|      * @param bool $fullMode 获取完整 |      * @param bool $fullMode 获取完整 | ||||||
|      * @return string |      * @return string | ||||||
|      */ |      */ | ||||||
|     protected function oAuth($fullMode = true) { |     protected function oAuth($fullMode = true) | ||||||
|  |     { | ||||||
|         // 本地开发调试用户 openid
 |         // 本地开发调试用户 openid
 | ||||||
|         if (in_array($this->request->host(), ['127.0.0.1', 'localhost'])) { |         if (in_array($this->request->host(), ['127.0.0.1', 'localhost'])) { | ||||||
|             session('openid', 'oBWB3wWVNujb-PJlmPmxC5CBTNF0'); |             session('openid', 'oBWB3wWVNujb-PJlmPmxC5CBTNF0'); | ||||||
|  | |||||||
| @ -26,7 +26,8 @@ use think\View; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/05/12 11:59 |  * @date 2017/05/12 11:59 | ||||||
|  */ |  */ | ||||||
| class AccessAuth { | class AccessAuth | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 当前请求对象 |      * 当前请求对象 | ||||||
| @ -38,7 +39,8 @@ class AccessAuth { | |||||||
|      * 行为入口 |      * 行为入口 | ||||||
|      * @param $params |      * @param $params | ||||||
|      */ |      */ | ||||||
|     public function run(&$params) { |     public function run(&$params) | ||||||
|  |     { | ||||||
|         $this->request = Request::instance(); |         $this->request = Request::instance(); | ||||||
|         list($module, $controller, $action) = [$this->request->module(), $this->request->controller(), $this->request->action()]; |         list($module, $controller, $action) = [$this->request->module(), $this->request->controller(), $this->request->action()]; | ||||||
|         $vars = get_class_vars(config('app_namespace') . "\\{$module}\\controller\\{$controller}"); |         $vars = get_class_vars(config('app_namespace') . "\\{$module}\\controller\\{$controller}"); | ||||||
|  | |||||||
| @ -23,7 +23,8 @@ use think\Request; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/04/25 11:59 |  * @date 2017/04/25 11:59 | ||||||
|  */ |  */ | ||||||
| class FilterView { | class FilterView | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 当前请求对象 |      * 当前请求对象 | ||||||
| @ -35,12 +36,13 @@ class FilterView { | |||||||
|      * 行为入口 |      * 行为入口 | ||||||
|      * @param $params |      * @param $params | ||||||
|      */ |      */ | ||||||
|     public function run(&$params) { |     public function run(&$params) | ||||||
|  |     { | ||||||
|         $this->request = Request::instance(); |         $this->request = Request::instance(); | ||||||
|         $appRoot = $this->request->root(true); |         $appRoot = $this->request->root(true); | ||||||
|         $replace = [ |         $replace = [ | ||||||
|             '__APP__'    => $appRoot, |             '__APP__' => $appRoot, | ||||||
|             '__SELF__'   => $this->request->url(true), |             '__SELF__' => $this->request->url(true), | ||||||
|             '__PUBLIC__' => strpos($appRoot, EXT) ? ltrim(dirname($appRoot), DS) : $appRoot, |             '__PUBLIC__' => strpos($appRoot, EXT) ? ltrim(dirname($appRoot), DS) : $appRoot, | ||||||
|         ]; |         ]; | ||||||
|         $params = str_replace(array_keys($replace), array_values($replace), $params); |         $params = str_replace(array_keys($replace), array_values($replace), $params); | ||||||
| @ -51,7 +53,8 @@ class FilterView { | |||||||
|      * 百度统计实现代码 |      * 百度统计实现代码 | ||||||
|      * @param $params |      * @param $params | ||||||
|      */ |      */ | ||||||
|     public function baidu(&$params) { |     public function baidu(&$params) | ||||||
|  |     { | ||||||
|         if (($key = sysconf('tongji_baidu_key'))) { |         if (($key = sysconf('tongji_baidu_key'))) { | ||||||
|             $script = <<<SCRIPT |             $script = <<<SCRIPT | ||||||
|         <script> |         <script> | ||||||
|  | |||||||
| @ -24,7 +24,8 @@ use think\Request; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/03/22 15:32 |  * @date 2017/03/22 15:32 | ||||||
|  */ |  */ | ||||||
| class DataService { | class DataService | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 删除指定序号 |      * 删除指定序号 | ||||||
| @ -32,7 +33,8 @@ class DataService { | |||||||
|      * @param string $type |      * @param string $type | ||||||
|      * @return bool |      * @return bool | ||||||
|      */ |      */ | ||||||
|     public static function deleteSequence($sequence, $type = 'SYSTEM') { |     public static function deleteSequence($sequence, $type = 'SYSTEM') | ||||||
|  |     { | ||||||
|         $data = ['sequence' => $sequence, 'type' => strtoupper($type)]; |         $data = ['sequence' => $sequence, 'type' => strtoupper($type)]; | ||||||
|         return Db::name('SystemSequence')->where($data)->delete(); |         return Db::name('SystemSequence')->where($data)->delete(); | ||||||
|     } |     } | ||||||
| @ -43,7 +45,8 @@ class DataService { | |||||||
|      * @param string $type 序号顾类型 |      * @param string $type 序号顾类型 | ||||||
|      * @return string |      * @return string | ||||||
|      */ |      */ | ||||||
|     public static function createSequence($length = 10, $type = 'SYSTEM') { |     public static function createSequence($length = 10, $type = 'SYSTEM') | ||||||
|  |     { | ||||||
|         $times = 0; |         $times = 0; | ||||||
|         while ($times++ < 10) { |         while ($times++ < 10) { | ||||||
|             $i = 0; |             $i = 0; | ||||||
| @ -69,7 +72,8 @@ class DataService { | |||||||
|      * @param array $where 其它的where条件 |      * @param array $where 其它的where条件 | ||||||
|      * @return bool |      * @return bool | ||||||
|      */ |      */ | ||||||
|     public static function save($dbQuery, $data, $key = 'id', $where = []) { |     public static function save($dbQuery, $data, $key = 'id', $where = []) | ||||||
|  |     { | ||||||
|         $db = is_string($dbQuery) ? Db::name($dbQuery) : $dbQuery; |         $db = is_string($dbQuery) ? Db::name($dbQuery) : $dbQuery; | ||||||
|         $where[$key] = isset($data[$key]) ? $data[$key] : ''; |         $where[$key] = isset($data[$key]) ? $data[$key] : ''; | ||||||
|         if ($db->where($where)->count() > 0) { |         if ($db->where($where)->count() > 0) { | ||||||
| @ -84,7 +88,8 @@ class DataService { | |||||||
|      * @param array $where 额外查询条件 |      * @param array $where 额外查询条件 | ||||||
|      * @return bool|null |      * @return bool|null | ||||||
|      */ |      */ | ||||||
|     public static function update(&$dbQuery, $where = []) { |     public static function update(&$dbQuery, $where = []) | ||||||
|  |     { | ||||||
|         $request = Request::instance(); |         $request = Request::instance(); | ||||||
|         $db = is_string($dbQuery) ? Db::name($dbQuery) : $dbQuery; |         $db = is_string($dbQuery) ? Db::name($dbQuery) : $dbQuery; | ||||||
|         $ids = explode(',', $request->post('id', '')); |         $ids = explode(',', $request->post('id', '')); | ||||||
|  | |||||||
| @ -21,7 +21,8 @@ namespace service; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/03/15 15:17 |  * @date 2017/03/15 15:17 | ||||||
|  */ |  */ | ||||||
| class ExpressService { | class ExpressService | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     const APPID = '1232779'; |     const APPID = '1232779'; | ||||||
|     const APPKEY = 'ac45f461-8c1a-4518-87b1-bb8e835a2f9d'; |     const APPKEY = 'ac45f461-8c1a-4518-87b1-bb8e835a2f9d'; | ||||||
| @ -33,14 +34,15 @@ class ExpressService { | |||||||
|      * @param $LogisticCode string 物流单号 |      * @param $LogisticCode string 物流单号 | ||||||
|      * @return string array 轨迹数据 |      * @return string array 轨迹数据 | ||||||
|      */ |      */ | ||||||
|     public static function line($ShipperCode, $LogisticCode) { |     public static function line($ShipperCode, $LogisticCode) | ||||||
|  |     { | ||||||
|         $sendData = json_encode(array('ShipperCode' => $ShipperCode, 'LogisticCode' => $LogisticCode), JSON_UNESCAPED_UNICODE); |         $sendData = json_encode(array('ShipperCode' => $ShipperCode, 'LogisticCode' => $LogisticCode), JSON_UNESCAPED_UNICODE); | ||||||
|         $data = array( |         $data = array( | ||||||
|             'RequestData' => $sendData, |             'RequestData' => $sendData, | ||||||
|             'EBusinessID' => self::APPID, |             'EBusinessID' => self::APPID, | ||||||
|             'RequestType' => '1002', |             'RequestType' => '1002', | ||||||
|             'DataType'    => 2, |             'DataType' => 2, | ||||||
|             'DataSign'    => base64_encode(md5($sendData . self::APPKEY)), |             'DataSign' => base64_encode(md5($sendData . self::APPKEY)), | ||||||
|         ); |         ); | ||||||
|         $result = HttpService::post(self::APIURI, $data); |         $result = HttpService::post(self::APIURI, $data); | ||||||
|         !($resultJson = json_decode($result, true)) && die(var_export($result)); |         !($resultJson = json_decode($result, true)) && die(var_export($result)); | ||||||
| @ -52,7 +54,8 @@ class ExpressService { | |||||||
|      * @param $result 结果处理 |      * @param $result 结果处理 | ||||||
|      * @return array 通用的结果集 array('result' => 'success或者fail','data' => array( array('time' => '时间','info' => '地点'),......),'reason' => '失败原因') |      * @return array 通用的结果集 array('result' => 'success或者fail','data' => array( array('time' => '时间','info' => '地点'),......),'reason' => '失败原因') | ||||||
|      */ |      */ | ||||||
|     public static function response($result) { |     public static function response($result) | ||||||
|  |     { | ||||||
|         $status = "fail"; |         $status = "fail"; | ||||||
|         $data = array(); |         $data = array(); | ||||||
|         $message = "此单号无跟踪记录"; |         $message = "此单号无跟踪记录"; | ||||||
|  | |||||||
| @ -30,7 +30,8 @@ use think\Log; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/03/15 15:17 |  * @date 2017/03/15 15:17 | ||||||
|  */ |  */ | ||||||
| class FileService { | class FileService | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 根据文件后缀获取文件MINE |      * 根据文件后缀获取文件MINE | ||||||
| @ -38,7 +39,8 @@ class FileService { | |||||||
|      * @param array $mine 文件后缀MINE信息 |      * @param array $mine 文件后缀MINE信息 | ||||||
|      * @return string |      * @return string | ||||||
|      */ |      */ | ||||||
|     public static function getFileMine($exts, $mine = []) { |     public static function getFileMine($exts, $mine = []) | ||||||
|  |     { | ||||||
|         $mines = Config::get('mines'); |         $mines = Config::get('mines'); | ||||||
|         foreach (is_string($exts) ? explode(',', $exts) : $exts as $_e) { |         foreach (is_string($exts) ? explode(',', $exts) : $exts as $_e) { | ||||||
|             if (isset($mines[strtolower($_e)])) { |             if (isset($mines[strtolower($_e)])) { | ||||||
| @ -55,7 +57,8 @@ class FileService { | |||||||
|      * @param string|null $storage |      * @param string|null $storage | ||||||
|      * @return bool|string |      * @return bool|string | ||||||
|      */ |      */ | ||||||
|     public static function getFileUrl($filename, $storage = null) { |     public static function getFileUrl($filename, $storage = null) | ||||||
|  |     { | ||||||
|         if (self::hasFile($filename, $storage) === false) { |         if (self::hasFile($filename, $storage) === false) { | ||||||
|             return false; |             return false; | ||||||
|         } |         } | ||||||
| @ -74,7 +77,8 @@ class FileService { | |||||||
|      * 根据配置获取到七牛云文件上传目标地址 |      * 根据配置获取到七牛云文件上传目标地址 | ||||||
|      * @return string |      * @return string | ||||||
|      */ |      */ | ||||||
|     public static function getUploadLocalUrl() { |     public static function getUploadLocalUrl() | ||||||
|  |     { | ||||||
|         return url('@admin/plugs/upload'); |         return url('@admin/plugs/upload'); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -83,7 +87,8 @@ class FileService { | |||||||
|      * @param bool $isClient |      * @param bool $isClient | ||||||
|      * @return string |      * @return string | ||||||
|      */ |      */ | ||||||
|     public static function getUploadQiniuUrl($isClient = true) { |     public static function getUploadQiniuUrl($isClient = true) | ||||||
|  |     { | ||||||
|         $region = sysconf('storage_qiniu_region'); |         $region = sysconf('storage_qiniu_region'); | ||||||
|         $isHttps = !!sysconf('storage_qiniu_is_https'); |         $isHttps = !!sysconf('storage_qiniu_is_https'); | ||||||
|         switch ($region) { |         switch ($region) { | ||||||
| @ -115,7 +120,8 @@ class FileService { | |||||||
|      * 获取AliOSS上传地址 |      * 获取AliOSS上传地址 | ||||||
|      * @return string |      * @return string | ||||||
|      */ |      */ | ||||||
|     public static function getUploadOssUrl() { |     public static function getUploadOssUrl() | ||||||
|  |     { | ||||||
|         return (request()->isSsl() ? 'https' : 'http') . '://' . sysconf('storage_oss_domain'); |         return (request()->isSsl() ? 'https' : 'http') . '://' . sysconf('storage_oss_domain'); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -123,7 +129,8 @@ class FileService { | |||||||
|      * 获取服务器URL前缀 |      * 获取服务器URL前缀 | ||||||
|      * @return string |      * @return string | ||||||
|      */ |      */ | ||||||
|     public static function getBaseUriLocal() { |     public static function getBaseUriLocal() | ||||||
|  |     { | ||||||
|         $request = request(); |         $request = request(); | ||||||
|         $base = $request->root(); |         $base = $request->root(); | ||||||
|         $root = strpos($base, '.') ? ltrim(dirname($base), DS) : $base; |         $root = strpos($base, '.') ? ltrim(dirname($base), DS) : $base; | ||||||
| @ -137,7 +144,8 @@ class FileService { | |||||||
|      * 获取七牛云URL前缀 |      * 获取七牛云URL前缀 | ||||||
|      * @return string |      * @return string | ||||||
|      */ |      */ | ||||||
|     public static function getBaseUriQiniu() { |     public static function getBaseUriQiniu() | ||||||
|  |     { | ||||||
|         return (sysconf('storage_qiniu_is_https') ? 'https' : 'http') . '://' . sysconf('storage_qiniu_domain') . '/'; |         return (sysconf('storage_qiniu_is_https') ? 'https' : 'http') . '://' . sysconf('storage_qiniu_domain') . '/'; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -145,7 +153,8 @@ class FileService { | |||||||
|      * 获取AliOss URL前缀 |      * 获取AliOss URL前缀 | ||||||
|      * @return string |      * @return string | ||||||
|      */ |      */ | ||||||
|     public static function getBaseUriOss() { |     public static function getBaseUriOss() | ||||||
|  |     { | ||||||
|         return (sysconf('storage_oss_is_https') ? 'https' : 'http') . '://' . sysconf('storage_oss_domain') . '/'; |         return (sysconf('storage_oss_is_https') ? 'https' : 'http') . '://' . sysconf('storage_oss_domain') . '/'; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -156,7 +165,8 @@ class FileService { | |||||||
|      * @param string $pre 文件前缀 |      * @param string $pre 文件前缀 | ||||||
|      * @return string |      * @return string | ||||||
|      */ |      */ | ||||||
|     public static function getFileName($source, $ext = '', $pre = '') { |     public static function getFileName($source, $ext = '', $pre = '') | ||||||
|  |     { | ||||||
|         return $pre . join('/', str_split(md5($source), 16)) . '.' . $ext; |         return $pre . join('/', str_split(md5($source), 16)) . '.' . $ext; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -166,7 +176,8 @@ class FileService { | |||||||
|      * @param string|null $storage |      * @param string|null $storage | ||||||
|      * @return bool |      * @return bool | ||||||
|      */ |      */ | ||||||
|     public static function hasFile($filename, $storage = null) { |     public static function hasFile($filename, $storage = null) | ||||||
|  |     { | ||||||
|         switch (empty($storage) ? sysconf('storage_type') : $storage) { |         switch (empty($storage) ? sysconf('storage_type') : $storage) { | ||||||
|             case 'local': |             case 'local': | ||||||
|                 return file_exists(ROOT_PATH . 'static/upload/' . $filename); |                 return file_exists(ROOT_PATH . 'static/upload/' . $filename); | ||||||
| @ -188,7 +199,8 @@ class FileService { | |||||||
|      * @param string|null $storage |      * @param string|null $storage | ||||||
|      * @return string|null |      * @return string|null | ||||||
|      */ |      */ | ||||||
|     public static function readFile($filename, $storage = null) { |     public static function readFile($filename, $storage = null) | ||||||
|  |     { | ||||||
|         switch (empty($storage) ? sysconf('storage_type') : $storage) { |         switch (empty($storage) ? sysconf('storage_type') : $storage) { | ||||||
|             case 'local': |             case 'local': | ||||||
|                 $filepath = ROOT_PATH . 'static/upload/' . $filename; |                 $filepath = ROOT_PATH . 'static/upload/' . $filename; | ||||||
| @ -213,7 +225,8 @@ class FileService { | |||||||
|      * @param string|null $file_storage |      * @param string|null $file_storage | ||||||
|      * @return array|false |      * @return array|false | ||||||
|      */ |      */ | ||||||
|     public static function save($filename, $content, $file_storage = null) { |     public static function save($filename, $content, $file_storage = null) | ||||||
|  |     { | ||||||
|         $type = empty($file_storage) ? sysconf('storage_type') : $file_storage; |         $type = empty($file_storage) ? sysconf('storage_type') : $file_storage; | ||||||
|         if (!method_exists(__CLASS__, $type)) { |         if (!method_exists(__CLASS__, $type)) { | ||||||
|             Log::error("保存存储失败,调用{$type}存储引擎不存在!"); |             Log::error("保存存储失败,调用{$type}存储引擎不存在!"); | ||||||
| @ -228,7 +241,8 @@ class FileService { | |||||||
|      * @param string $content |      * @param string $content | ||||||
|      * @return array|null |      * @return array|null | ||||||
|      */ |      */ | ||||||
|     public static function local($filename, $content) { |     public static function local($filename, $content) | ||||||
|  |     { | ||||||
|         try { |         try { | ||||||
|             $filepath = ROOT_PATH . 'static/upload/' . $filename; |             $filepath = ROOT_PATH . 'static/upload/' . $filename; | ||||||
|             !file_exists(dirname($filepath)) && mkdir(dirname($filepath), '0755', true); |             !file_exists(dirname($filepath)) && mkdir(dirname($filepath), '0755', true); | ||||||
| @ -248,7 +262,8 @@ class FileService { | |||||||
|      * @param string $content |      * @param string $content | ||||||
|      * @return array|null |      * @return array|null | ||||||
|      */ |      */ | ||||||
|     public static function qiniu($filename, $content) { |     public static function qiniu($filename, $content) | ||||||
|  |     { | ||||||
|         $auth = new Auth(sysconf('storage_qiniu_access_key'), sysconf('storage_qiniu_secret_key')); |         $auth = new Auth(sysconf('storage_qiniu_access_key'), sysconf('storage_qiniu_secret_key')); | ||||||
|         $token = $auth->uploadToken(sysconf('storage_qiniu_bucket')); |         $token = $auth->uploadToken(sysconf('storage_qiniu_bucket')); | ||||||
|         $uploadMgr = new UploadManager(); |         $uploadMgr = new UploadManager(); | ||||||
| @ -268,7 +283,8 @@ class FileService { | |||||||
|      * @param string $content |      * @param string $content | ||||||
|      * @return array|null |      * @return array|null | ||||||
|      */ |      */ | ||||||
|     public static function oss($filename, $content) { |     public static function oss($filename, $content) | ||||||
|  |     { | ||||||
|         try { |         try { | ||||||
|             $ossClient = new OssClient(sysconf('storage_oss_keyid'), sysconf('storage_oss_secret'), self::getBaseUriOss(), true); |             $ossClient = new OssClient(sysconf('storage_oss_keyid'), sysconf('storage_oss_secret'), self::getBaseUriOss(), true); | ||||||
|             $result = $ossClient->putObject(sysconf('storage_oss_bucket'), $filename, $content); |             $result = $ossClient->putObject(sysconf('storage_oss_bucket'), $filename, $content); | ||||||
| @ -285,7 +301,8 @@ class FileService { | |||||||
|      * @param bool $isForce 是否强制重新下载文件 |      * @param bool $isForce 是否强制重新下载文件 | ||||||
|      * @return array|null; |      * @return array|null; | ||||||
|      */ |      */ | ||||||
|     public static function download($url, $isForce = false) { |     public static function download($url, $isForce = false) | ||||||
|  |     { | ||||||
|         try { |         try { | ||||||
|             $filename = self::getFileName($url, strtolower(pathinfo($url, 4)), 'download/'); |             $filename = self::getFileName($url, strtolower(pathinfo($url, 4)), 'download/'); | ||||||
|             if (false === $isForce && ($siteUrl = self::getFileUrl($filename, 'local'))) { |             if (false === $isForce && ($siteUrl = self::getFileUrl($filename, 'local'))) { | ||||||
|  | |||||||
| @ -23,7 +23,8 @@ use CURLFile; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/03/22 15:32 |  * @date 2017/03/22 15:32 | ||||||
|  */ |  */ | ||||||
| class HttpService { | class HttpService | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * HTTP GET 请求 |      * HTTP GET 请求 | ||||||
| @ -33,7 +34,8 @@ class HttpService { | |||||||
|      * @param array $header 请求Header信息 |      * @param array $header 请求Header信息 | ||||||
|      * @return bool|string |      * @return bool|string | ||||||
|      */ |      */ | ||||||
|     public static function get($url, $data = array(), $second = 30, $header = []) { |     public static function get($url, $data = array(), $second = 30, $header = []) | ||||||
|  |     { | ||||||
|         if (!empty($data)) { |         if (!empty($data)) { | ||||||
|             $url .= (stripos($url, '?') === false ? '?' : '&'); |             $url .= (stripos($url, '?') === false ? '?' : '&'); | ||||||
|             $url .= (is_array($data) ? http_build_query($data) : $data); |             $url .= (is_array($data) ? http_build_query($data) : $data); | ||||||
| @ -58,7 +60,8 @@ class HttpService { | |||||||
|      * @param array $header 请求Header信息 |      * @param array $header 请求Header信息 | ||||||
|      * @return bool|string |      * @return bool|string | ||||||
|      */ |      */ | ||||||
|     static public function post($url, $data = [], $second = 30, $header = []) { |     static public function post($url, $data = [], $second = 30, $header = []) | ||||||
|  |     { | ||||||
|         self::_setUploadFile($data); |         self::_setUploadFile($data); | ||||||
|         $curl = curl_init(); |         $curl = curl_init(); | ||||||
|         curl_setopt($curl, CURLOPT_TIMEOUT, $second); |         curl_setopt($curl, CURLOPT_TIMEOUT, $second); | ||||||
| @ -80,7 +83,8 @@ class HttpService { | |||||||
|      * @param $curl |      * @param $curl | ||||||
|      * @param string $url |      * @param string $url | ||||||
|      */ |      */ | ||||||
|     private static function _setSsl(&$curl, $url) { |     private static function _setSsl(&$curl, $url) | ||||||
|  |     { | ||||||
|         if (stripos($url, "https") === 0) { |         if (stripos($url, "https") === 0) { | ||||||
|             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); | ||||||
| @ -93,7 +97,8 @@ class HttpService { | |||||||
|      * @param array $data |      * @param array $data | ||||||
|      * @return string |      * @return string | ||||||
|      */ |      */ | ||||||
|     private static function _setUploadFile(&$data) { |     private static function _setUploadFile(&$data) | ||||||
|  |     { | ||||||
|         if (!is_array($data)) { |         if (!is_array($data)) { | ||||||
|             return null; |             return null; | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -24,13 +24,15 @@ use think\Request; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/03/24 13:25 |  * @date 2017/03/24 13:25 | ||||||
|  */ |  */ | ||||||
| class LogService { | class LogService | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 获取数据操作对象 |      * 获取数据操作对象 | ||||||
|      * @return \think\db\Query |      * @return \think\db\Query | ||||||
|      */ |      */ | ||||||
|     protected static function db() { |     protected static function db() | ||||||
|  |     { | ||||||
|         return Db::name('SystemLog'); |         return Db::name('SystemLog'); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -40,7 +42,8 @@ class LogService { | |||||||
|      * @param string $content |      * @param string $content | ||||||
|      * @return bool |      * @return bool | ||||||
|      */ |      */ | ||||||
|     public static function write($action = '行为', $content = "内容描述") { |     public static function write($action = '行为', $content = "内容描述") | ||||||
|  |     { | ||||||
|         $request = Request::instance(); |         $request = Request::instance(); | ||||||
|         $node = strtolower(join('/', [$request->module(), $request->controller(), $request->action()])); |         $node = strtolower(join('/', [$request->module(), $request->controller(), $request->action()])); | ||||||
|         $data = ['ip' => $request->ip(), 'node' => $node, 'username' => session('user.username') . '', 'action' => $action, 'content' => $content]; |         $data = ['ip' => $request->ip(), 'node' => $node, 'username' => session('user.username') . '', 'action' => $action, 'content' => $content]; | ||||||
|  | |||||||
| @ -23,13 +23,15 @@ use think\Db; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/05/08 11:28 |  * @date 2017/05/08 11:28 | ||||||
|  */ |  */ | ||||||
| class NodeService { | class NodeService | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 应用用户权限节点 |      * 应用用户权限节点 | ||||||
|      * @return bool |      * @return bool | ||||||
|      */ |      */ | ||||||
|     public static function applyAuthNode() { |     public static function applyAuthNode() | ||||||
|  |     { | ||||||
|         cache('need_access_node', null); |         cache('need_access_node', null); | ||||||
|         if (($userid = session('user.id'))) { |         if (($userid = session('user.id'))) { | ||||||
|             session('user', Db::name('SystemUser')->where('id', $userid)->find()); |             session('user', Db::name('SystemUser')->where('id', $userid)->find()); | ||||||
| @ -50,7 +52,8 @@ class NodeService { | |||||||
|      * 获取授权节点 |      * 获取授权节点 | ||||||
|      * @return array |      * @return array | ||||||
|      */ |      */ | ||||||
|     public static function getAuthNode() { |     public static function getAuthNode() | ||||||
|  |     { | ||||||
|         $nodes = cache('need_access_node'); |         $nodes = cache('need_access_node'); | ||||||
|         if (empty($nodes)) { |         if (empty($nodes)) { | ||||||
|             $nodes = Db::name('SystemNode')->where('is_auth', '1')->column('node'); |             $nodes = Db::name('SystemNode')->where('is_auth', '1')->column('node'); | ||||||
| @ -64,7 +67,8 @@ class NodeService { | |||||||
|      * @param string $node 节点 |      * @param string $node 节点 | ||||||
|      * @return bool |      * @return bool | ||||||
|      */ |      */ | ||||||
|     public static function checkAuthNode($node) { |     public static function checkAuthNode($node) | ||||||
|  |     { | ||||||
|         list($module, $controller, $action) = explode('/', str_replace(['?', '=', '&'], '/', $node . '///')); |         list($module, $controller, $action) = explode('/', str_replace(['?', '=', '&'], '/', $node . '///')); | ||||||
|         $auth_node = strtolower(trim("{$module}/{$controller}/{$action}", '/')); |         $auth_node = strtolower(trim("{$module}/{$controller}/{$action}", '/')); | ||||||
|         if (session('user.username') === 'admin' || stripos($node, 'admin/index') === 0) { |         if (session('user.username') === 'admin' || stripos($node, 'admin/index') === 0) { | ||||||
| @ -80,7 +84,8 @@ class NodeService { | |||||||
|      * 获取系统代码节点 |      * 获取系统代码节点 | ||||||
|      * @return array |      * @return array | ||||||
|      */ |      */ | ||||||
|     public static function get() { |     public static function get() | ||||||
|  |     { | ||||||
|         $alias = []; |         $alias = []; | ||||||
|         foreach (Db::name('SystemNode')->select() as $vo) { |         foreach (Db::name('SystemNode')->select() as $vo) { | ||||||
|             $alias["{$vo['node']}"] = $vo; |             $alias["{$vo['node']}"] = $vo; | ||||||
| @ -113,7 +118,8 @@ class NodeService { | |||||||
|      * @param array $nodes 额外数据 |      * @param array $nodes 额外数据 | ||||||
|      * @return array |      * @return array | ||||||
|      */ |      */ | ||||||
|     public static function getNodeTree($path, $nodes = []) { |     public static function getNodeTree($path, $nodes = []) | ||||||
|  |     { | ||||||
|         foreach (self::_getFilePaths($path) as $vo) { |         foreach (self::_getFilePaths($path) as $vo) { | ||||||
|             if (!preg_match('|/(\w+)/controller/(\w+)|', str_replace(DS, '/', $vo), $matches) || count($matches) !== 3) { |             if (!preg_match('|/(\w+)/controller/(\w+)|', str_replace(DS, '/', $vo), $matches) || count($matches) !== 3) { | ||||||
|                 continue; |                 continue; | ||||||
| @ -138,7 +144,8 @@ class NodeService { | |||||||
|      * @param string $ext 文件后缀 |      * @param string $ext 文件后缀 | ||||||
|      * @return array |      * @return array | ||||||
|      */ |      */ | ||||||
|     private static function _getFilePaths($path, $data = [], $ext = 'php') { |     private static function _getFilePaths($path, $data = [], $ext = 'php') | ||||||
|  |     { | ||||||
|         foreach (scandir($path) as $dir) { |         foreach (scandir($path) as $dir) { | ||||||
|             if ($dir[0] === '.') { |             if ($dir[0] === '.') { | ||||||
|                 continue; |                 continue; | ||||||
|  | |||||||
| @ -26,14 +26,16 @@ use think\Db; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2016/10/25 14:49 |  * @date 2016/10/25 14:49 | ||||||
|  */ |  */ | ||||||
| class PayService { | class PayService | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 查询订单是否已经支付 |      * 查询订单是否已经支付 | ||||||
|      * @param string $order_no |      * @param string $order_no | ||||||
|      * @return bool |      * @return bool | ||||||
|      */ |      */ | ||||||
|     public static function isPay($order_no) { |     public static function isPay($order_no) | ||||||
|  |     { | ||||||
|         $map = ['order_no' => $order_no, 'is_pay' => '1']; |         $map = ['order_no' => $order_no, 'is_pay' => '1']; | ||||||
|         return Db::name('WechatPayPrepayid')->where($map)->count() > 0; |         return Db::name('WechatPayPrepayid')->where($map)->count() > 0; | ||||||
|     } |     } | ||||||
| @ -47,7 +49,8 @@ class PayService { | |||||||
|      * @param string $from 订单来源 |      * @param string $from 订单来源 | ||||||
|      * @return false|string |      * @return false|string | ||||||
|      */ |      */ | ||||||
|     public static function createWechatPayQrc(WechatPay $pay, $order_no, $fee, $title, $from = 'wechat') { |     public static function createWechatPayQrc(WechatPay $pay, $order_no, $fee, $title, $from = 'wechat') | ||||||
|  |     { | ||||||
|         $prepayid = self::createWechatPrepayid($pay, null, $order_no, $fee, $title, 'NATIVE', $from); |         $prepayid = self::createWechatPrepayid($pay, null, $order_no, $fee, $title, 'NATIVE', $from); | ||||||
|         if ($prepayid === false) { |         if ($prepayid === false) { | ||||||
|             return false; |             return false; | ||||||
| @ -71,7 +74,8 @@ class PayService { | |||||||
|      * @param string $title 订单标题 |      * @param string $title 订单标题 | ||||||
|      * @return bool|array |      * @return bool|array | ||||||
|      */ |      */ | ||||||
|     public static function createWechatPayJsPicker(WechatPay $pay, $openid, $order_no, $fee, $title) { |     public static function createWechatPayJsPicker(WechatPay $pay, $openid, $order_no, $fee, $title) | ||||||
|  |     { | ||||||
|         if (($prepayid = self::createWechatPrepayid($pay, $openid, $order_no, $fee, $title, 'JSAPI')) === false) { |         if (($prepayid = self::createWechatPrepayid($pay, $openid, $order_no, $fee, $title, 'JSAPI')) === false) { | ||||||
|             return false; |             return false; | ||||||
|         } |         } | ||||||
| @ -86,7 +90,8 @@ class PayService { | |||||||
|      * @param string|null $refund_no 退款订单号 |      * @param string|null $refund_no 退款订单号 | ||||||
|      * @return bool |      * @return bool | ||||||
|      */ |      */ | ||||||
|     public static function putWechatRefund(WechatPay $pay, $order_no, $fee = 0, $refund_no = NULL, $refund_account = '') { |     public static function putWechatRefund(WechatPay $pay, $order_no, $fee = 0, $refund_no = NULL, $refund_account = '') | ||||||
|  |     { | ||||||
|         $map = array('order_no' => $order_no, 'is_pay' => '1', 'appid' => $pay->appid); |         $map = array('order_no' => $order_no, 'is_pay' => '1', 'appid' => $pay->appid); | ||||||
|         $notify = Db::name('WechatPayPrepayid')->where($map)->find(); |         $notify = Db::name('WechatPayPrepayid')->where($map)->find(); | ||||||
|         if (empty($notify)) { |         if (empty($notify)) { | ||||||
| @ -116,7 +121,8 @@ class PayService { | |||||||
|      * @param string $from 订单来源 |      * @param string $from 订单来源 | ||||||
|      * @return bool|string |      * @return bool|string | ||||||
|      */ |      */ | ||||||
|     public static function createWechatPrepayid(WechatPay $pay, $openid, $order_no, $fee, $title, $trade_type = 'JSAPI', $from = 'wechat') { |     public static function createWechatPrepayid(WechatPay $pay, $openid, $order_no, $fee, $title, $trade_type = 'JSAPI', $from = 'wechat') | ||||||
|  |     { | ||||||
|         $map = ['order_no' => $order_no, 'is_pay' => '1', 'expires_in' => time(), 'appid' => $pay->appid, 'trade_type' => $trade_type]; |         $map = ['order_no' => $order_no, 'is_pay' => '1', 'expires_in' => time(), 'appid' => $pay->appid, 'trade_type' => $trade_type]; | ||||||
|         $where = 'appid=:appid and order_no=:order_no and (is_pay=:is_pay or expires_in>:expires_in) and trade_type=:trade_type'; |         $where = 'appid=:appid and order_no=:order_no and (is_pay=:is_pay or expires_in>:expires_in) and trade_type=:trade_type'; | ||||||
|         $prepayinfo = Db::name('WechatPayPrepayid')->where($where, $map)->find(); |         $prepayinfo = Db::name('WechatPayPrepayid')->where($where, $map)->find(); | ||||||
|  | |||||||
| @ -21,12 +21,14 @@ namespace service; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2016/10/25 14:49 |  * @date 2016/10/25 14:49 | ||||||
|  */ |  */ | ||||||
| class ToolsService { | class ToolsService | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Cors Options 授权处理 |      * Cors Options 授权处理 | ||||||
|      */ |      */ | ||||||
|     public static function corsOptionsHandler() { |     public static function corsOptionsHandler() | ||||||
|  |     { | ||||||
|         if (request()->isOptions()) { |         if (request()->isOptions()) { | ||||||
|             header('Access-Control-Allow-Origin:*'); |             header('Access-Control-Allow-Origin:*'); | ||||||
|             header('Access-Control-Allow-Headers:Accept,Referer,Host,Keep-Alive,User-Agent,X-Requested-With,Cache-Control,Content-Type,Cookie,token'); |             header('Access-Control-Allow-Headers:Accept,Referer,Host,Keep-Alive,User-Agent,X-Requested-With,Cache-Control,Content-Type,Cookie,token'); | ||||||
| @ -44,13 +46,14 @@ class ToolsService { | |||||||
|      * Cors Request Header信息 |      * Cors Request Header信息 | ||||||
|      * @return array |      * @return array | ||||||
|      */ |      */ | ||||||
|     public static function corsRequestHander() { |     public static function corsRequestHander() | ||||||
|  |     { | ||||||
|         return [ |         return [ | ||||||
|             'Access-Control-Allow-Origin'      => '*', |             'Access-Control-Allow-Origin' => '*', | ||||||
|             'Access-Control-Allow-Credentials' => true, |             'Access-Control-Allow-Credentials' => true, | ||||||
|             'Access-Control-Allow-Methods'     => 'GET,POST,OPTIONS', |             'Access-Control-Allow-Methods' => 'GET,POST,OPTIONS', | ||||||
|             'X-Support'                        => 'service@cuci.cc', |             'X-Support' => 'service@cuci.cc', | ||||||
|             'X-Servers'                        => 'Guangzhou Cuci Technology Co. Ltd', |             'X-Servers' => 'Guangzhou Cuci Technology Co. Ltd', | ||||||
|         ]; |         ]; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -59,10 +62,11 @@ class ToolsService { | |||||||
|      * @param string $content |      * @param string $content | ||||||
|      * @return string |      * @return string | ||||||
|      */ |      */ | ||||||
|     public static function emojiEncode($content) { |     public static function emojiEncode($content) | ||||||
|         return json_decode(preg_replace_callback("/(\\\u[ed][0-9a-f]{3})/i", function($str) { |     { | ||||||
|                     return addslashes($str[0]); |         return json_decode(preg_replace_callback("/(\\\u[ed][0-9a-f]{3})/i", function ($str) { | ||||||
|                 }, json_encode($content))); |             return addslashes($str[0]); | ||||||
|  |         }, json_encode($content))); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
| @ -70,10 +74,11 @@ class ToolsService { | |||||||
|      * @param string $content |      * @param string $content | ||||||
|      * @return string |      * @return string | ||||||
|      */ |      */ | ||||||
|     public static function emojiDecode($content) { |     public static function emojiDecode($content) | ||||||
|         return json_decode(preg_replace_callback('/\\\\\\\\/i', function() { |     { | ||||||
|                     return '\\'; |         return json_decode(preg_replace_callback('/\\\\\\\\/i', function () { | ||||||
|                 }, json_encode($content))); |             return '\\'; | ||||||
|  |         }, json_encode($content))); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
| @ -84,7 +89,8 @@ class ToolsService { | |||||||
|      * @param string $son 定义子数据Key |      * @param string $son 定义子数据Key | ||||||
|      * @return array |      * @return array | ||||||
|      */ |      */ | ||||||
|     public static function arr2tree($list, $id = 'id', $pid = 'pid', $son = 'sub') { |     public static function arr2tree($list, $id = 'id', $pid = 'pid', $son = 'sub') | ||||||
|  |     { | ||||||
|         $tree = $map = array(); |         $tree = $map = array(); | ||||||
|         foreach ($list as $item) { |         foreach ($list as $item) { | ||||||
|             $map[$item[$id]] = $item; |             $map[$item[$id]] = $item; | ||||||
| @ -108,7 +114,8 @@ class ToolsService { | |||||||
|      * @param string $path |      * @param string $path | ||||||
|      * @return array |      * @return array | ||||||
|      */ |      */ | ||||||
|     public static function arr2table($list, $id = 'id', $pid = 'pid', $path = 'path', $ppath = '') { |     public static function arr2table($list, $id = 'id', $pid = 'pid', $path = 'path', $ppath = '') | ||||||
|  |     { | ||||||
|         $_array_tree = self::arr2tree($list, $id, $pid); |         $_array_tree = self::arr2tree($list, $id, $pid); | ||||||
|         $tree = array(); |         $tree = array(); | ||||||
|         foreach ($_array_tree as $_tree) { |         foreach ($_array_tree as $_tree) { | ||||||
| @ -122,7 +129,7 @@ class ToolsService { | |||||||
|             $tree[] = $_tree; |             $tree[] = $_tree; | ||||||
|             if (!empty($sub)) { |             if (!empty($sub)) { | ||||||
|                 $sub_array = self::arr2table($sub, $id, $pid, $path, $_tree[$path]); |                 $sub_array = self::arr2table($sub, $id, $pid, $path, $_tree[$path]); | ||||||
|                 $tree = array_merge($tree, (Array) $sub_array); |                 $tree = array_merge($tree, (Array)$sub_array); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         return $tree; |         return $tree; | ||||||
| @ -136,7 +143,8 @@ class ToolsService { | |||||||
|      * @param string $pkey 父Key |      * @param string $pkey 父Key | ||||||
|      * @return array |      * @return array | ||||||
|      */ |      */ | ||||||
|     public static function getArrSubIds($list, $id = 0, $key = 'id', $pkey = 'pid') { |     public static function getArrSubIds($list, $id = 0, $key = 'id', $pkey = 'pid') | ||||||
|  |     { | ||||||
|         $ids = array(intval($id)); |         $ids = array(intval($id)); | ||||||
|         foreach ($list as $vo) { |         foreach ($list as $vo) { | ||||||
|             if (intval($vo[$pkey]) > 0 && intval($vo[$pkey]) == intval($id)) { |             if (intval($vo[$pkey]) > 0 && intval($vo[$pkey]) == intval($id)) { | ||||||
|  | |||||||
| @ -24,7 +24,8 @@ use think\Log; | |||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/03/22 15:32 |  * @date 2017/03/22 15:32 | ||||||
|  */ |  */ | ||||||
| class WechatService { | class WechatService | ||||||
|  | { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 通过图文ID读取图文信息 |      * 通过图文ID读取图文信息 | ||||||
| @ -32,7 +33,8 @@ class WechatService { | |||||||
|      * @param array $where 额外的查询条件 |      * @param array $where 额外的查询条件 | ||||||
|      * @return array |      * @return array | ||||||
|      */ |      */ | ||||||
|     public static function getNewsById($id, $where = []) { |     public static function getNewsById($id, $where = []) | ||||||
|  |     { | ||||||
|         $data = Db::name('WechatNews')->where('id', $id)->where($where)->find(); |         $data = Db::name('WechatNews')->where('id', $id)->where($where)->find(); | ||||||
|         $article_ids = explode(',', $data['article_id']); |         $article_ids = explode(',', $data['article_id']); | ||||||
|         $articles = Db::name('WechatNewsArticle')->where('id', 'in', $article_ids)->select(); |         $articles = Db::name('WechatNewsArticle')->where('id', 'in', $article_ids)->select(); | ||||||
| @ -54,7 +56,8 @@ class WechatService { | |||||||
|      * @param string $local_url |      * @param string $local_url | ||||||
|      * @return string|null |      * @return string|null | ||||||
|      */ |      */ | ||||||
|     public static function uploadImage($local_url) { |     public static function uploadImage($local_url) | ||||||
|  |     { | ||||||
|         # 检测文件上否已经上传过了
 |         # 检测文件上否已经上传过了
 | ||||||
|         if (($img = Db::name('WechatNewsImage')->where('md5', md5($local_url))->find()) && isset($img['media_url'])) { |         if (($img = Db::name('WechatNewsImage')->where('md5', md5($local_url))->find()) && isset($img['media_url'])) { | ||||||
|             return $img['media_url']; |             return $img['media_url']; | ||||||
| @ -84,7 +87,8 @@ class WechatService { | |||||||
|      * @param array $video_info 视频信息 |      * @param array $video_info 视频信息 | ||||||
|      * @return string|null |      * @return string|null | ||||||
|      */ |      */ | ||||||
|     public static function uploadForeverMedia($local_url = '', $type = 'image', $is_video = false, $video_info = array()) { |     public static function uploadForeverMedia($local_url = '', $type = 'image', $is_video = false, $video_info = array()) | ||||||
|  |     { | ||||||
|         # 检测文件上否已经上传过了
 |         # 检测文件上否已经上传过了
 | ||||||
|         $wechat = &load_wechat('media'); |         $wechat = &load_wechat('media'); | ||||||
|         # 检查文件URL是否已经上传为永久素材
 |         # 检查文件URL是否已经上传为永久素材
 | ||||||
| @ -112,7 +116,8 @@ class WechatService { | |||||||
|      * 从微信服务器获取所有标签 |      * 从微信服务器获取所有标签 | ||||||
|      * @return bool |      * @return bool | ||||||
|      */ |      */ | ||||||
|     public static function syncFansTags() { |     public static function syncFansTags() | ||||||
|  |     { | ||||||
|         $wechat = &load_wechat("User"); |         $wechat = &load_wechat("User"); | ||||||
|         if (($result = $wechat->getTags()) !== false) { |         if (($result = $wechat->getTags()) !== false) { | ||||||
|             $tags = $result['tags']; |             $tags = $result['tags']; | ||||||
| @ -132,7 +137,8 @@ class WechatService { | |||||||
|      * @param string $openid |      * @param string $openid | ||||||
|      * @return bool |      * @return bool | ||||||
|      */ |      */ | ||||||
|     public static function syncFansTagsByOpenid($openid) { |     public static function syncFansTagsByOpenid($openid) | ||||||
|  |     { | ||||||
|         $wechat = &load_wechat('User'); |         $wechat = &load_wechat('User'); | ||||||
|         $tagsid = $wechat->getUserTags($openid); |         $tagsid = $wechat->getUserTags($openid); | ||||||
|         if ($tagsid === false || !is_array($tagsid)) { |         if ($tagsid === false || !is_array($tagsid)) { | ||||||
| @ -148,7 +154,8 @@ class WechatService { | |||||||
|      * @param string $appid |      * @param string $appid | ||||||
|      * @return bool |      * @return bool | ||||||
|      */ |      */ | ||||||
|     public static function setFansInfo($userInfo, $appid = '') { |     public static function setFansInfo($userInfo, $appid = '') | ||||||
|  |     { | ||||||
|         if (!empty($userInfo['subscribe_time'])) { |         if (!empty($userInfo['subscribe_time'])) { | ||||||
|             $userInfo['subscribe_at'] = date('Y-m-d H:i:s', $userInfo['subscribe_time']); |             $userInfo['subscribe_at'] = date('Y-m-d H:i:s', $userInfo['subscribe_time']); | ||||||
|         } |         } | ||||||
| @ -166,7 +173,8 @@ class WechatService { | |||||||
|      * @param string $appid 公众号appid |      * @param string $appid 公众号appid | ||||||
|      * @return array|false |      * @return array|false | ||||||
|      */ |      */ | ||||||
|     public static function getFansInfo($openid, $appid = null) { |     public static function getFansInfo($openid, $appid = null) | ||||||
|  |     { | ||||||
|         $map = ['openid' => $openid]; |         $map = ['openid' => $openid]; | ||||||
|         is_string($appid) && $map['appid'] = $appid; |         is_string($appid) && $map['appid'] = $appid; | ||||||
|         if (($fans = Db::name('WechatFans')->where($map)->find()) && isset($fans['nickname'])) { |         if (($fans = Db::name('WechatFans')->where($map)->find()) && isset($fans['nickname'])) { | ||||||
| @ -180,7 +188,8 @@ class WechatService { | |||||||
|      * @param string $next_openid |      * @param string $next_openid | ||||||
|      * @return bool |      * @return bool | ||||||
|      */ |      */ | ||||||
|     public static function syncAllFans($next_openid = '') { |     public static function syncAllFans($next_openid = '') | ||||||
|  |     { | ||||||
|         $wechat = &load_wechat('User'); |         $wechat = &load_wechat('User'); | ||||||
|         if (false === ($result = $wechat->getUserList($next_openid)) || empty($result['data']['openid'])) { |         if (false === ($result = $wechat->getUserList($next_openid)) || empty($result['data']['openid'])) { | ||||||
|             Log::error("获取粉丝列表失败, {$wechat->errMsg} [{$wechat->errCode}]"); |             Log::error("获取粉丝列表失败, {$wechat->errMsg} [{$wechat->errCode}]"); | ||||||
| @ -209,7 +218,8 @@ class WechatService { | |||||||
|      * @param string $next_openid |      * @param string $next_openid | ||||||
|      * @return bool |      * @return bool | ||||||
|      */ |      */ | ||||||
|     public static function syncBlackFans($next_openid = '') { |     public static function syncBlackFans($next_openid = '') | ||||||
|  |     { | ||||||
|         $wechat = &load_wechat('User'); |         $wechat = &load_wechat('User'); | ||||||
|         $result = $wechat->getBacklist($next_openid); |         $result = $wechat->getBacklist($next_openid); | ||||||
|         if ($result === false || (empty($result['data']['openid']))) { |         if ($result === false || (empty($result['data']['openid']))) { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user