mirror of
				https://gitee.com/zoujingli/ThinkAdmin.git
				synced 2025-10-27 02:12:08 +08:00 
			
		
		
		
	[增加]系统增加日志模块
This commit is contained in:
		
							parent
							
								
									342d19366a
								
							
						
					
					
						commit
						7571356173
					
				
							
								
								
									
										69
									
								
								application/admin/controller/Log.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								application/admin/controller/Log.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,69 @@ | |||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | // +----------------------------------------------------------------------
 | ||||||
|  | // | Think.Admin
 | ||||||
|  | // +----------------------------------------------------------------------
 | ||||||
|  | // | 版权所有 2016~2017 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
 | ||||||
|  | // +----------------------------------------------------------------------
 | ||||||
|  | // | 官方网站: http://think.ctolog.com
 | ||||||
|  | // +----------------------------------------------------------------------
 | ||||||
|  | // | 开源协议 ( https://mit-license.org )
 | ||||||
|  | // +----------------------------------------------------------------------
 | ||||||
|  | // | github开源项目:https://github.com/zoujingli/Think.Admin
 | ||||||
|  | // +----------------------------------------------------------------------
 | ||||||
|  | 
 | ||||||
|  | namespace app\admin\controller; | ||||||
|  | 
 | ||||||
|  | use controller\BasicAdmin; | ||||||
|  | use service\DataService; | ||||||
|  | use think\Db; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * 系统日志管理 | ||||||
|  |  * Class User | ||||||
|  |  * @package app\admin\controller | ||||||
|  |  * @author Anyon <zoujingli@qq.com> | ||||||
|  |  * @date 2017/02/15 18:12 | ||||||
|  |  */ | ||||||
|  | class Log extends BasicAdmin { | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 指定当前数据表 | ||||||
|  |      * @var string | ||||||
|  |      */ | ||||||
|  |     protected $table = 'SystemLog'; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 日志列表 | ||||||
|  |      */ | ||||||
|  |     public function index() { | ||||||
|  |         $this->title = '系统操作日志'; | ||||||
|  |         $db = Db::name($this->table)->order('id desc'); | ||||||
|  |         parent::_list($db); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 列表数据处理 | ||||||
|  |      * @param $data | ||||||
|  |      */ | ||||||
|  |     protected function _index_data_filter(&$data) { | ||||||
|  |         $ip = new \Ip2Region(); | ||||||
|  |         foreach ($data as &$vo) { | ||||||
|  |             $result = $ip->btreeSearch($vo['ip']); | ||||||
|  |             $vo['isp'] = isset($result['region']) ? $result['region'] : ''; | ||||||
|  |             $vo['isp'] = str_replace(['|0|0|0|0', '|'], ['', ' '], $vo['isp']); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 日志删除操作 | ||||||
|  |      */ | ||||||
|  |     public function del() { | ||||||
|  |         if (DataService::update($this->table)) { | ||||||
|  |             $this->success("日志删除成功!", ''); | ||||||
|  |         } else { | ||||||
|  |             $this->error("日志删除失败,请稍候再试!"); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -16,6 +16,7 @@ namespace app\admin\controller; | |||||||
| 
 | 
 | ||||||
| use app\admin\model\Node; | use app\admin\model\Node; | ||||||
| use controller\BasicAdmin; | use controller\BasicAdmin; | ||||||
|  | use service\LogService; | ||||||
| use think\Db; | use think\Db; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
| @ -55,6 +56,7 @@ class Login extends BasicAdmin { | |||||||
|             Db::name('SystemUser')->where('id', $user['id'])->update(['login_at' => ['exp', 'now()'], 'login_num' => ['exp', 'login_num+1']]); |             Db::name('SystemUser')->where('id', $user['id'])->update(['login_at' => ['exp', 'now()'], 'login_num' => ['exp', 'login_num+1']]); | ||||||
|             session('user', $user); |             session('user', $user); | ||||||
|             !empty($user['authorize']) && Node::applyAuthNode(); |             !empty($user['authorize']) && Node::applyAuthNode(); | ||||||
|  |             LogService::write('登录系统', '用户登录系统成功!'); | ||||||
|             $this->success('登录成功,正在进入系统...', '@admin'); |             $this->success('登录成功,正在进入系统...', '@admin'); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @ -63,6 +65,7 @@ class Login extends BasicAdmin { | |||||||
|      * 退出登录 |      * 退出登录 | ||||||
|      */ |      */ | ||||||
|     public function out() { |     public function out() { | ||||||
|  |         LogService::write('退出系统', '用户退出系统成功!'); | ||||||
|         session('user', null); |         session('user', null); | ||||||
|         $this->success('退出登录成功!', '@admin/login'); |         $this->success('退出登录成功!', '@admin/login'); | ||||||
|     } |     } | ||||||
|  | |||||||
							
								
								
									
										48
									
								
								application/admin/view/log.index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								application/admin/view/log.index.html
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,48 @@ | |||||||
|  | {extend name='extra@admin/content' /} | ||||||
|  | 
 | ||||||
|  | {block name="button"} | ||||||
|  | <div class="nowrap pull-right" style="margin-top:10px"> | ||||||
|  |     {if auth("$classuri/del")} | ||||||
|  |     <button data-update data-field='delete' data-action='{:url("$classuri/del")}' | ||||||
|  |             class='layui-btn layui-btn-small layui-btn-danger'><i class='fa fa-remove'></i> 删除日志 | ||||||
|  |     </button> | ||||||
|  |     {/if} | ||||||
|  | </div> | ||||||
|  | {/block} | ||||||
|  | 
 | ||||||
|  | {block name="content"} | ||||||
|  | <form onsubmit="return false;" data-auto="" method="POST"> | ||||||
|  |     <input type="hidden" value="resort" name="action"/> | ||||||
|  |     <table class="table table-hover"> | ||||||
|  |         <thead> | ||||||
|  |         <tr> | ||||||
|  |             <th class='list-table-check-td'> | ||||||
|  |                 <input data-none-auto="" data-check-target='.list-check-box' type='checkbox'/> | ||||||
|  |             </th> | ||||||
|  |             <th class='text-center'>操作者</th> | ||||||
|  |             <th class='text-center'>节点</th> | ||||||
|  |             <th class='text-center'>行为</th> | ||||||
|  |             <th class='text-center'>操作内容</th> | ||||||
|  |             <th class='text-center'>操作位置</th> | ||||||
|  |             <th class='text-center'>操作时间</th> | ||||||
|  |         </tr> | ||||||
|  |         </thead> | ||||||
|  |         <tbody> | ||||||
|  |         {foreach $list as $key=>$vo} | ||||||
|  |         <tr> | ||||||
|  |             <td class='list-table-check-td'> | ||||||
|  |                 <input class="list-check-box" value='{$vo.id}' type='checkbox'/> | ||||||
|  |             </td> | ||||||
|  |             <td class='text-center'>{$vo.username}</td> | ||||||
|  |             <td class='text-center'>{$vo.node}</td> | ||||||
|  |             <td class='text-center'>{$vo.action}</td> | ||||||
|  |             <td class='text-center'>{$vo.content}</td> | ||||||
|  |             <td class='text-center'>{$vo.isp|default=$vo.ip}</td> | ||||||
|  |             <td class='text-center'>{$vo.create_at}</td> | ||||||
|  |         </tr> | ||||||
|  |         {/foreach} | ||||||
|  |         </tbody> | ||||||
|  |     </table> | ||||||
|  |     {if isset($page)}<p>{$page}</p>{/if} | ||||||
|  | </form> | ||||||
|  | {/block} | ||||||
| @ -6,6 +6,7 @@ use service\ToolsService; | |||||||
| use think\Cache; | use think\Cache; | ||||||
| use think\Request; | use think\Request; | ||||||
| use think\Response; | use think\Response; | ||||||
|  | use Wechat\Lib\Tools; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * 数据接口通用控制器 |  * 数据接口通用控制器 | ||||||
| @ -38,10 +39,10 @@ class BasicApi { | |||||||
|         if (in_array(strtolower($this->request->action()), ['response', 'setcache', 'getcache', 'delcache', '_empty'])) { |         if (in_array(strtolower($this->request->action()), ['response', 'setcache', 'getcache', 'delcache', '_empty'])) { | ||||||
|             exit($this->response('禁止访问接口安全方法!', 'ACCESS_NOT_ALLOWED')->send()); |             exit($this->response('禁止访问接口安全方法!', 'ACCESS_NOT_ALLOWED')->send()); | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|         // 访问 Token 检测处理
 |         // 访问 Token 检测处理
 | ||||||
|         $this->token = $this->request->param('token', $this->request->header('token', false)); |         $this->token = $this->request->param('token', $this->request->header('token', false)); | ||||||
| //        if ((empty($this->token) || !$this->getCache($this->token)) && ($this->request->action() !== 'auth')) {
 |         if (empty($this->token) && !method_exists($this, $this->request->action())) { | ||||||
|         if (empty($this->token) && $this->request->action() !== 'auth') { |  | ||||||
|             exit($this->response('访问TOKEN失效,请重新授权!', 'ACCESS_TOKEN_FAILD')->send()); |             exit($this->response('访问TOKEN失效,请重新授权!', 'ACCESS_TOKEN_FAILD')->send()); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @ -55,8 +56,8 @@ class BasicApi { | |||||||
|      * @return Response |      * @return Response | ||||||
|      */ |      */ | ||||||
|     public function response($msg, $code = 'SUCCESS', $data = [], $type = 'json') { |     public function response($msg, $code = 'SUCCESS', $data = [], $type = 'json') { | ||||||
|         $result = ['code' => $code, 'msg' => $msg, '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)->code(200); |         return Response::create($result, $type)->header(ToolsService::corsRequestHander())->code(200); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
| @ -16,7 +16,6 @@ namespace service; | |||||||
| 
 | 
 | ||||||
| use think\Db; | use think\Db; | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| /** | /** | ||||||
|  * 基础数据服务 |  * 基础数据服务 | ||||||
|  * Class DataService |  * Class DataService | ||||||
|  | |||||||
| @ -22,8 +22,9 @@ use think\Config; | |||||||
| use think\Log; | use think\Log; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * 文件服务处理 |  * 系统文件服务 | ||||||
|  * @class FileService |  * Class FileService | ||||||
|  |  * @package service | ||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2017/03/15 15:17 |  * @date 2017/03/15 15:17 | ||||||
|  */ |  */ | ||||||
|  | |||||||
| @ -16,7 +16,6 @@ namespace service; | |||||||
| 
 | 
 | ||||||
| use think\Config; | use think\Config; | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| /** | /** | ||||||
|  * HTTP请求服务 |  * HTTP请求服务 | ||||||
|  * Class HttpService |  * Class HttpService | ||||||
|  | |||||||
							
								
								
									
										50
									
								
								extend/service/LogService.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								extend/service/LogService.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,50 @@ | |||||||
|  | <?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 service; | ||||||
|  | 
 | ||||||
|  | use think\Db; | ||||||
|  | use think\Request; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * 操作日志服务 | ||||||
|  |  * Class LogService | ||||||
|  |  * @package service | ||||||
|  |  * @author Anyon <zoujingli@qq.com> | ||||||
|  |  * @date 2017/03/24 13:25 | ||||||
|  |  */ | ||||||
|  | class LogService { | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 获取数据操作对象 | ||||||
|  |      * @return \think\db\Query | ||||||
|  |      */ | ||||||
|  |     protected static function db() { | ||||||
|  |         return Db::name('SystemLog'); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 写入操作日志 | ||||||
|  |      * @param string $action | ||||||
|  |      * @param string $content | ||||||
|  |      * @return bool | ||||||
|  |      */ | ||||||
|  |     public static function write($action = '行为', $content = "内容描述") { | ||||||
|  |         $request = Request::instance(); | ||||||
|  |         $node = strtolower(join('/', [$request->module(), $request->controller(), $request->action()])); | ||||||
|  |         $data = ['ip' => $request->ip(), 'node' => $node, 'username' => session('user.username') . '', 'action' => $action, 'content' => $content]; | ||||||
|  |         return self::db()->insert($data) !== false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -19,9 +19,11 @@ use think\Db; | |||||||
| use think\Log; | use think\Log; | ||||||
| use Wechat\WechatPay; | use Wechat\WechatPay; | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| /** | /** | ||||||
|  * 支付数据处理 |  * 支付数据服务 | ||||||
|  * |  * Class PayService | ||||||
|  |  * @package service | ||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2016/10/25 14:49 |  * @date 2016/10/25 14:49 | ||||||
|  */ |  */ | ||||||
| @ -32,8 +34,9 @@ class PayService { | |||||||
|      * @param string $order_no |      * @param string $order_no | ||||||
|      * @return bool |      * @return bool | ||||||
|      */ |      */ | ||||||
|     static public function isPay($order_no) { |     public static function isPay($order_no) { | ||||||
|         return Db::name('WechatPayPrepayid')->where('order_no', $order_no)->where('is_pay', '1')->count() > 0; |         $map = ['order_no' => $order_no, 'is_pay' => '1']; | ||||||
|  |         return Db::name('WechatPayPrepayid')->where($map)->count() > 0; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
| @ -45,7 +48,7 @@ class PayService { | |||||||
|      * @param string $from 订单来源 |      * @param string $from 订单来源 | ||||||
|      * @return bool |      * @return bool | ||||||
|      */ |      */ | ||||||
|     public static function createWechatPayQrc($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; | ||||||
| @ -58,7 +61,7 @@ class PayService { | |||||||
|         } |         } | ||||||
|         ob_clean(); |         ob_clean(); | ||||||
|         header("Content-type: image/png"); |         header("Content-type: image/png"); | ||||||
|         FileService::readFile($filename); |         return FileService::readFile($filename); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -71,7 +74,7 @@ class PayService { | |||||||
|      * @param string $title 订单标题 |      * @param string $title 订单标题 | ||||||
|      * @return bool|array |      * @return bool|array | ||||||
|      */ |      */ | ||||||
|     public static function createWechatPayJsPicker($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 +89,7 @@ class PayService { | |||||||
|      * @param string|null $refund_no 退款订单号 |      * @param string|null $refund_no 退款订单号 | ||||||
|      * @return bool |      * @return bool | ||||||
|      */ |      */ | ||||||
|     public static function putWechatRefund($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 +119,7 @@ class PayService { | |||||||
|      * @param string $from 订单来源 |      * @param string $from 订单来源 | ||||||
|      * @return bool|string |      * @return bool|string | ||||||
|      */ |      */ | ||||||
|     protected static function _createWechatPrepayid($pay, $openid, $order_no, $fee, $title, $trade_type = 'JSAPI', $from = 'shop') { |     protected static function _createWechatPrepayid(WechatPay $pay, $openid, $order_no, $fee, $title, $trade_type = 'JSAPI', $from = 'shop') { | ||||||
|         $map = ['order_no' => $order_no, 'is_pay' => '1', 'expires_in' => time(), 'appid' => $pay->appid]; |         $map = ['order_no' => $order_no, 'is_pay' => '1', 'expires_in' => time(), 'appid' => $pay->appid]; | ||||||
|         $where = 'appid=:appid and order_no=:order_no and (is_pay=:is_pay or expires_in>:expires_in)'; |         $where = 'appid=:appid and order_no=:order_no and (is_pay=:is_pay or expires_in>:expires_in)'; | ||||||
|         $prepayinfo = Db::name('WechatPayPrepayid')->where($where, $map)->find(); |         $prepayinfo = Db::name('WechatPayPrepayid')->where($where, $map)->find(); | ||||||
|  | |||||||
| @ -16,7 +16,8 @@ namespace service; | |||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * 系统工具服务 |  * 系统工具服务 | ||||||
|  * |  * Class ToolsService | ||||||
|  |  * @package service | ||||||
|  * @author Anyon <zoujingli@qq.com> |  * @author Anyon <zoujingli@qq.com> | ||||||
|  * @date 2016/10/25 14:49 |  * @date 2016/10/25 14:49 | ||||||
|  */ |  */ | ||||||
| @ -39,6 +40,20 @@ class ToolsService { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Cors Request Header信息 | ||||||
|  |      * @return array | ||||||
|  |      */ | ||||||
|  |     public static function corsRequestHander() { | ||||||
|  |         return [ | ||||||
|  |             'Access-Control-Allow-Origin'      => '*', | ||||||
|  |             'Access-Control-Allow-Credentials' => true, | ||||||
|  |             'Access-Control-Allow-Methods'     => 'GET,POST,OPTIONS', | ||||||
|  |             'X-Support'                        => 'service@cuci.cc', | ||||||
|  |             'X-Servers'                        => 'Guangzhou Cuci Technology Co. Ltd', | ||||||
|  |         ]; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     /** |     /** | ||||||
|      * 一维数据数组生成数据树 |      * 一维数据数组生成数据树 | ||||||
|      * @param array $list 数据列表 |      * @param array $list 数据列表 | ||||||
|  | |||||||
| @ -17,7 +17,6 @@ namespace service; | |||||||
| use think\Db; | use think\Db; | ||||||
| use think\Log; | use think\Log; | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| /** | /** | ||||||
|  * 微信数据服务 |  * 微信数据服务 | ||||||
|  * Class WechatService |  * Class WechatService | ||||||
|  | |||||||
							
								
								
									
										4008
									
								
								think.admin.sql
									
									
									
									
									
								
							
							
						
						
									
										4008
									
								
								think.admin.sql
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user