目录结构调整
@@ -244,14 +244,9 @@ class Addons extends Admin {
|
|||||||
public function addhook(){
|
public function addhook(){
|
||||||
$hooks = model('Hooks');
|
$hooks = model('Hooks');
|
||||||
if (IS_POST) {
|
if (IS_POST) {
|
||||||
$data = input();
|
$result = $hooks->change();
|
||||||
if ($data) {
|
if ($result !== false) {
|
||||||
$result = $hooks->change($data);
|
return $this->success("修改成功");
|
||||||
if ($result !== false) {
|
|
||||||
return $this->success("修改成功");
|
|
||||||
}else{
|
|
||||||
return $this->error($hooks->getError());
|
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
return $this->error($hooks->getError());
|
return $this->error($hooks->getError());
|
||||||
}
|
}
|
||||||
@@ -270,14 +265,9 @@ class Addons extends Admin {
|
|||||||
public function edithook($id){
|
public function edithook($id){
|
||||||
$hooks = model('Hooks');
|
$hooks = model('Hooks');
|
||||||
if (IS_POST) {
|
if (IS_POST) {
|
||||||
$data = input('post.');
|
$result = $hooks->change();
|
||||||
if ($data) {
|
if ($result !== false) {
|
||||||
$result = $hooks->change($data);
|
return $this->success("修改成功");
|
||||||
if ($result !== false) {
|
|
||||||
return $this->success("修改成功");
|
|
||||||
}else{
|
|
||||||
return $this->error($hooks->getError());
|
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
return $this->error($hooks->getError());
|
return $this->error($hooks->getError());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,8 +50,9 @@ class Content extends Admin{
|
|||||||
$map = $this->buildMap();
|
$map = $this->buildMap();
|
||||||
$field = array_filter($grid_list['fields']);
|
$field = array_filter($grid_list['fields']);
|
||||||
if ($this->modelInfo['extend'] == 1) {
|
if ($this->modelInfo['extend'] == 1) {
|
||||||
$map['model_id'] = $this->modelInfo['id'];
|
|
||||||
array_push($field, 'is_top');
|
array_push($field, 'is_top');
|
||||||
|
}else{
|
||||||
|
unset($map['model_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$list = $this->model->where($map)->field($field)->order($order)->paginate(15);
|
$list = $this->model->where($map)->field($field)->order($order)->paginate(15);
|
||||||
@@ -249,21 +250,27 @@ class Content extends Admin{
|
|||||||
*/
|
*/
|
||||||
protected function buildMap(){
|
protected function buildMap(){
|
||||||
$map = array();
|
$map = array();
|
||||||
$keyword = input('get.keyword', '', 'trim');
|
$data = $this->request->get();
|
||||||
$category = input('get.category', '', 'trim');
|
foreach ($data as $key => $value) {
|
||||||
|
if ($value) {
|
||||||
if ($keyword) {
|
if ($key == 'keyword') {
|
||||||
$map['title'] = array("LIKE", "%$keyword%");
|
$map['title'] = array("LIKE", "%$value%");
|
||||||
}
|
}elseif($key == 'category'){
|
||||||
if ($category){
|
$map['category_id'] = $value;
|
||||||
$map['category_id'] = $category;
|
}elseif($key == 'create_time'){
|
||||||
|
$map['create_time'] = array('BETWEEN',array(strtotime($value[0]),strtotime($value[1])));
|
||||||
|
}else{
|
||||||
|
$map[$key] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->modelInfo['extend'] == 1) {
|
if ($this->modelInfo['extend'] == 1) {
|
||||||
|
$category = isset($data['category']) ? $data['category'] : '';
|
||||||
$cate_list = parse_field_bind('category', $category, $this->modelInfo['id']);
|
$cate_list = parse_field_bind('category', $category, $this->modelInfo['id']);
|
||||||
$this->assign('cate_list', $cate_list);
|
$this->assign('cate_list', $cate_list);
|
||||||
}
|
}
|
||||||
$this->assign($this->request->get());
|
$this->assign($data);
|
||||||
return $map;
|
return $map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,9 +23,7 @@ class Group extends Admin {
|
|||||||
|
|
||||||
|
|
||||||
//会员分组首页控制器
|
//会员分组首页控制器
|
||||||
public function index(){
|
public function index($type = 'admin'){
|
||||||
$type = input('get.type','admin','trim');
|
|
||||||
|
|
||||||
$map['module'] = $type;
|
$map['module'] = $type;
|
||||||
|
|
||||||
$list = db('AuthGroup')->where($map)->order('id desc')->paginate(10);
|
$list = db('AuthGroup')->where($map)->order('id desc')->paginate(10);
|
||||||
@@ -112,9 +110,7 @@ class Group extends Admin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//权限节点控制器
|
//权限节点控制器
|
||||||
public function access(){
|
public function access($type = 'admin'){
|
||||||
$type = input('get.type','admin','trim');
|
|
||||||
|
|
||||||
$map['module'] = $type;
|
$map['module'] = $type;
|
||||||
|
|
||||||
$list = db('AuthRule')->where($map)->order('id desc')->paginate(10);
|
$list = db('AuthRule')->where($map)->order('id desc')->paginate(10);
|
||||||
@@ -253,8 +249,7 @@ class Group extends Admin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delnode(){
|
public function delnode($id){
|
||||||
$id = input('id','','trim,intval');
|
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
return $this->error("非法操作!");
|
return $this->error("非法操作!");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,11 +118,8 @@ class User extends Admin{
|
|||||||
* del
|
* del
|
||||||
* @author colin <colin@tensent.cn>
|
* @author colin <colin@tensent.cn>
|
||||||
*/
|
*/
|
||||||
public function del(){
|
public function del($id){
|
||||||
$ids = input('post.ids');
|
$uid = array('IN',is_array($id) ? implode(',',$id) : $id);
|
||||||
//多条删除和单条删除
|
|
||||||
empty($ids) ? $ids = input('get.id') : $ids = $ids;
|
|
||||||
$uid = array('IN',is_array($ids) ? implode(',',$ids) : $ids);
|
|
||||||
//获取用户信息
|
//获取用户信息
|
||||||
$find = $this->getUserinfo($uid);
|
$find = $this->getUserinfo($uid);
|
||||||
model('User')->where(array('uid'=>$uid))->delete();
|
model('User')->where(array('uid'=>$uid))->delete();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ html,body {
|
|||||||
-webkit-font-smoothing:antialiased;
|
-webkit-font-smoothing:antialiased;
|
||||||
}
|
}
|
||||||
a.badge{color: #ffffff;}
|
a.badge{color: #ffffff;}
|
||||||
|
.pt-5{padding-top: 5px;}
|
||||||
textarea{resize:none; min-height: 80px;}
|
textarea{resize:none; min-height: 80px;}
|
||||||
@media (max-width:419px) {
|
@media (max-width:419px) {
|
||||||
html,body {
|
html,body {
|
||||||
|
|||||||
124
application/admin/view/content/book.html
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
{extend name="public/base"/}
|
||||||
|
{block name="style"}
|
||||||
|
<!-- datepicker statr -->
|
||||||
|
<link href="__PUBLIC__/plugs/datepicker/css/foundation-datepicker.min.css" rel="stylesheet" type="text/css">
|
||||||
|
<script src="__PUBLIC__/plugs/datepicker/js/foundation-datepicker.js"></script>
|
||||||
|
<script src="__PUBLIC__/plugs/datepicker/js/foundation-datepicker.zh-CN.js"></script>
|
||||||
|
<!-- datepicker end -->
|
||||||
|
{/block}
|
||||||
|
{block name="body"}
|
||||||
|
<div class="main-box clearfix">
|
||||||
|
<header class="main-box-header clearfix">
|
||||||
|
<div class="pull-left">
|
||||||
|
<h2>{$meta_title}</h2>
|
||||||
|
</div>
|
||||||
|
<div class="pull-right">
|
||||||
|
<a class="btn btn-primary" href="{:url('admin/content/add?model_id='.$model_id)}">新 增</a>
|
||||||
|
<button class="btn btn-danger ajax-post confirm" url="{:url('admin/content/del?model_id='.$model_id)}" target-form="ids">删 除</button>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
<div class="main-box-body clearfix">
|
||||||
|
<div class="row">
|
||||||
|
<form method="get">
|
||||||
|
<div class="col-sm-12 col-md-4 pt-5">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-addon">书名:</div>
|
||||||
|
<input type="text" class="form-control" name="book_name" value="{$book_name|default=''}" placeholder="书名">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-12 col-md-4 pt-5">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-addon">发布时间:</div>
|
||||||
|
<div class="col-sm-5">
|
||||||
|
<input type="text" class="form-control create_time" name="create_time[]" id="create_time" placeholder="开始时间" value="{$create_time[0]|default=''}" readonly>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-5">
|
||||||
|
<input type="text" class="form-control create_time" name="create_time[]" id="create_time" placeholder="结束时间" value="{$create_time[1]|default=''}" readonly>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-12 col-md-4 pt-5">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-addon">标准类型:</div>
|
||||||
|
<select class="form-control" name="stand_class"></select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-12 col-md-4 pt-5">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-addon">编号:</div>
|
||||||
|
<input type="text" class="form-control" name="book_no" value="{$book_no|default=''}" placeholder="编号">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-12 col-md-4 pt-5">
|
||||||
|
<button class="btn btn-primary" type="submit">搜索</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="table-responsive clearfix">
|
||||||
|
|
||||||
|
<div class="table-responsive clearfix">
|
||||||
|
<table class="table table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th width="30"><input class="checkbox check-all" type="checkbox"></th>
|
||||||
|
{volist name="grid['grids']" id="item"}
|
||||||
|
<th>{$item['title']}</th>
|
||||||
|
{/volist}
|
||||||
|
<th>操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{if condition="empty($list)"}
|
||||||
|
{php}
|
||||||
|
$cow = count($grid['grids'])+2;
|
||||||
|
{/php}
|
||||||
|
<tr>
|
||||||
|
<td colspan="{$cow}" align="center">暂无数据!</td>
|
||||||
|
</tr>
|
||||||
|
{else/}
|
||||||
|
{volist name="list" id="item"}
|
||||||
|
<tr>
|
||||||
|
<td><input class="ids row-selected" type="checkbox" name="id[]" value="{$item['id']}"></td>
|
||||||
|
{volist name="grid['grids']" id="vo"}
|
||||||
|
{if isset($vo['format'])}
|
||||||
|
<td>{$item[$vo['field'][0]]|$vo['format']}</td>
|
||||||
|
{else/}
|
||||||
|
<td>{$item[$vo['field'][0]]}</td>
|
||||||
|
{/if}
|
||||||
|
{/volist}
|
||||||
|
<td>
|
||||||
|
{if isset($item['status'])}
|
||||||
|
{if $item['status']}
|
||||||
|
<a href="{:url('admin/content/status',array('id'=>$item['id'],'model_id'=>$model_id,'status'=>'0'))}" class="ajax-get">取消审核</a>
|
||||||
|
{else/}
|
||||||
|
<a href="{:url('admin/content/status',array('id'=>$item['id'],'model_id'=>$model_id,'status'=>'1'))}" class="ajax-get">审核</a>
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
|
<a href="{:url('admin/content/edit',array('id'=>$item['id'],'model_id'=>$model_id))}" >编辑</a>
|
||||||
|
<a href="{:url('admin/content/del',array('id'=>$item['id'],'model_id'=>$model_id))}" class="ajax-get confirm">删除</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{/volist}
|
||||||
|
{/if}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{$page}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/block}
|
||||||
|
{block name="script"}
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(function(){
|
||||||
|
$('.create_time').fdatepicker({
|
||||||
|
format: 'yyyy-mm-dd',
|
||||||
|
pickTime: true
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.height_btn').click(function(){
|
||||||
|
$('.height').show();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
{/block}
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
<?php
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
// | OneThink [ WE CAN DO IT JUST THINK IT ]
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
|
|
||||||
namespace app\common\model;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分类模型
|
|
||||||
*/
|
|
||||||
class Book extends Content{
|
|
||||||
|
|
||||||
protected $auto = array('date_last_modify', 'user_last_modify');
|
|
||||||
protected $type = array(
|
|
||||||
'id' => 'integer',
|
|
||||||
'cover_id' => 'integer',
|
|
||||||
'sort' => 'integer'
|
|
||||||
);
|
|
||||||
|
|
||||||
protected function setStatusAttr($value){
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function setCreateTimeAttr($value){
|
|
||||||
return $value ? strtotime($value) : time();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function setDateLastModifyAttr($value){
|
|
||||||
return $value ? strtotime($value) : time();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function setUserLastModifyAttr($value){
|
|
||||||
return session('user_auth.uid');
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getCreateTimeAttr($value){
|
|
||||||
return date('Y-m-d H:i:s', $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getDateLastModifyAttr($value){
|
|
||||||
return date('Y-m-d H:i:s', $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getStandClassTextAttr($value, $data){
|
|
||||||
$text = array(
|
|
||||||
'1' => 'BK ', '2' => 'CN', '3' => 'QT', '4' => 'DB',
|
|
||||||
);
|
|
||||||
return $text[$data['stand_class']];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -64,19 +64,6 @@ class Hooks extends Base {
|
|||||||
return $keylist;
|
return $keylist;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function change($data){
|
|
||||||
if (!empty($data)) {
|
|
||||||
if ($data['id']) {
|
|
||||||
$this->save($data,array('id'=>$data['id']));
|
|
||||||
}else{
|
|
||||||
$this->save($data);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
$this->error = "非法操作!";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addHooks($addons_name){
|
public function addHooks($addons_name){
|
||||||
$addons_class = get_addon_class($addons_name);//获取插件名
|
$addons_class = get_addon_class($addons_name);//获取插件名
|
||||||
if(!class_exists($addons_class)){
|
if(!class_exists($addons_class)){
|
||||||
@@ -94,5 +81,5 @@ class Hooks extends Base {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$methods = get_class_methods($addons_class);
|
$methods = get_class_methods($addons_class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
<?php
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
// | OneThink [ WE CAN DO IT JUST THINK IT ]
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
|
|
||||||
namespace app\common\model;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分类模型
|
|
||||||
*/
|
|
||||||
class Order extends Base{
|
|
||||||
|
|
||||||
protected $auto = array('update_time');
|
|
||||||
protected $insert = array('create_time', 'uid', 'status'=>1, 'order_no');
|
|
||||||
|
|
||||||
protected function setOrderNoAttr($value){
|
|
||||||
return 'SN'.date('YmdHis',time()).rand('1000','9999');
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function setUidAttr($value){
|
|
||||||
return session('user_auth.uid');
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getPayTypeTextAttr($value, $data){
|
|
||||||
$type = array('wechat'=>'微信支付', 'alipay'=>'支付宝支付');
|
|
||||||
return $type[$data['pay_type']];
|
|
||||||
}
|
|
||||||
protected function getPayStatusTextAttr($value, $data){
|
|
||||||
$type = array(
|
|
||||||
0 => '未付款',
|
|
||||||
1 => '已付款',
|
|
||||||
);
|
|
||||||
return $type[$data['pay_status']];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function product(){
|
|
||||||
return $this->hasMany('OrderProduct', 'order_no', 'order_no');
|
|
||||||
}
|
|
||||||
|
|
||||||
//生成订单
|
|
||||||
public function createOrder($data){
|
|
||||||
$order_id = $this->save($data);
|
|
||||||
foreach ($data['list'] as $key => $value) {
|
|
||||||
$value['order_no'] = $this->data['order_no'];
|
|
||||||
$value['product_id'] = $value['id'];
|
|
||||||
unset($value['id']);
|
|
||||||
$value['create_time'] = time();
|
|
||||||
$value['update_time'] = time();
|
|
||||||
$goods[] = $value;
|
|
||||||
}
|
|
||||||
db('OrderProduct')->insertAll($goods);
|
|
||||||
return $order_id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
70
application/index/controller/Book.php
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace app\index\controller;
|
||||||
|
use app\common\controller\Fornt;
|
||||||
|
|
||||||
|
class Book extends Fornt{
|
||||||
|
|
||||||
|
public function _initialize(){
|
||||||
|
parent::_initialize();
|
||||||
|
$this->book = model('Book');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index(){
|
||||||
|
$map = $this->search();
|
||||||
|
$order = 'id desc';
|
||||||
|
$list = $this->book->where($map)->order($order)->paginate(10);
|
||||||
|
|
||||||
|
$data = array(
|
||||||
|
'list' => $list,
|
||||||
|
'page' => $list->render()
|
||||||
|
);
|
||||||
|
$this->assign($data);
|
||||||
|
return $this->fetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
//图书详情
|
||||||
|
public function detail($id = 0){
|
||||||
|
$map['id'] = $id;
|
||||||
|
|
||||||
|
$info = $this->book->where($map)->find();
|
||||||
|
|
||||||
|
$data = array(
|
||||||
|
'info' => $info,
|
||||||
|
);
|
||||||
|
$this->assign($data);
|
||||||
|
return $this->fetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
//图书搜索条件组织
|
||||||
|
protected function search(){
|
||||||
|
$map = array();
|
||||||
|
$data = $this->request->post();
|
||||||
|
$data['is_show_height'] = 0;
|
||||||
|
if (isset($data['book_name']) && $data['book_name']) {
|
||||||
|
$map['book_name'] = array("LIKE", "%" . $data['book_name'] . "%");
|
||||||
|
}
|
||||||
|
if (isset($data['book_no']) && $data['book_no']) {
|
||||||
|
$map['book_no'] = array("LIKE", "%" . $data['book_no'] . "%");
|
||||||
|
$data['is_show_height'] = 1;
|
||||||
|
}
|
||||||
|
if (isset($data['stand_class']) && $data['stand_class']) {
|
||||||
|
$map['stand_class'] = $data['stand_class'];
|
||||||
|
$data['is_show_height'] = 1;
|
||||||
|
}
|
||||||
|
if (isset($data['create_time'][0]) && isset($data['create_time'][1]) && $data['create_time'][0] && $data['create_time'][1]) {
|
||||||
|
$map['create_time'] = array('BETWEEN',$data['create_time']);
|
||||||
|
$data['is_show_height'] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assign($data);
|
||||||
|
return $map;
|
||||||
|
}
|
||||||
|
}
|
||||||
53
application/index/controller/Cart.php
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace app\index\controller;
|
||||||
|
use app\common\controller\Fornt;
|
||||||
|
|
||||||
|
class Cart extends Fornt{
|
||||||
|
|
||||||
|
public function _initialize(){
|
||||||
|
$this->cart = new \com\Cart();
|
||||||
|
}
|
||||||
|
|
||||||
|
//购物车
|
||||||
|
public function index(){
|
||||||
|
$list = $this->cart->all();
|
||||||
|
|
||||||
|
$data = array(
|
||||||
|
'list' => $list,
|
||||||
|
);
|
||||||
|
$this->assign($data);
|
||||||
|
return $this->fetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
//加入购物车
|
||||||
|
public function add($id, $num){
|
||||||
|
if ($num > 0) {
|
||||||
|
$this->cart->addItem($id, $num);
|
||||||
|
}
|
||||||
|
$info['code'] = 1;
|
||||||
|
$info['num'] = $this->cart->getCount();
|
||||||
|
return $info;
|
||||||
|
}
|
||||||
|
|
||||||
|
//加入购物车
|
||||||
|
public function del($id){
|
||||||
|
$this->cart->delItem($id);
|
||||||
|
$info['code'] = 1;
|
||||||
|
$info['data'] = array('num'=>$this->cart->getCount());
|
||||||
|
return $info;
|
||||||
|
}
|
||||||
|
|
||||||
|
//购物车统计
|
||||||
|
public function count(){
|
||||||
|
$data = array('info'=>$this->cart->getCount());
|
||||||
|
echo json_encode($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
128
application/user/controller/Order.php
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace app\user\controller;
|
||||||
|
use app\common\controller\User;
|
||||||
|
|
||||||
|
class Order extends User{
|
||||||
|
|
||||||
|
public function _initialize(){
|
||||||
|
parent::_initialize();
|
||||||
|
$this->order = model('Order');
|
||||||
|
$this->cart = new \com\Cart();
|
||||||
|
}
|
||||||
|
|
||||||
|
//会员中心订单首页
|
||||||
|
public function index(){
|
||||||
|
$map['uid'] = session('user_auth.uid');
|
||||||
|
$map['status'] = array('gt',0);
|
||||||
|
|
||||||
|
$rows = array();
|
||||||
|
$list = $this->order->where($map)->order('id desc')->paginate(10);
|
||||||
|
foreach ($list as $key => $value) {
|
||||||
|
$value['product'] = $value->product;
|
||||||
|
$rows[] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = array(
|
||||||
|
'list' => $rows,
|
||||||
|
'page' => $list->render()
|
||||||
|
);
|
||||||
|
$this->assign($data);
|
||||||
|
return $this->fetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
//订单结算列表
|
||||||
|
public function lists(){
|
||||||
|
$id = input('id', '', 'trim');
|
||||||
|
$order_id = input('order_id', '', 'trim');
|
||||||
|
|
||||||
|
//立即购买,把物品放入购物车
|
||||||
|
if ($id) {
|
||||||
|
$this->cart->addItem($id, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$order_id) {
|
||||||
|
$price_count = '0.00';
|
||||||
|
$list = $this->cart->all();
|
||||||
|
foreach ($list as $key => $value) {
|
||||||
|
$price_count += $value['price_count'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = array(
|
||||||
|
'list' => $list,
|
||||||
|
'price_count' => $price_count
|
||||||
|
);
|
||||||
|
|
||||||
|
//生成订单
|
||||||
|
$map['id'] = $this->order->createOrder($data);
|
||||||
|
}else{
|
||||||
|
$map['id'] = $order_id;
|
||||||
|
}
|
||||||
|
$order = $this->order->where($map)->find();
|
||||||
|
|
||||||
|
$data = array(
|
||||||
|
'list' => $order->product,
|
||||||
|
'order_id' => $map['id'],
|
||||||
|
'price_count' => $order['price_count']
|
||||||
|
);
|
||||||
|
//订单生成后情况购物车
|
||||||
|
$this->cart->clear();
|
||||||
|
$this->assign($data);
|
||||||
|
return $this->fetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function confirm(){
|
||||||
|
$order_id = input('order_id', '', 'trim');
|
||||||
|
$payment = input('payment', '', 'trim');
|
||||||
|
$map['id'] = $order_id;
|
||||||
|
$this->order->where($map)->update(array('pay_type'=>$payment));
|
||||||
|
$info = $this->order->where($map)->find();
|
||||||
|
|
||||||
|
$data = array(
|
||||||
|
'info' => $info
|
||||||
|
);
|
||||||
|
$this->assign($data);
|
||||||
|
return $this->fetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单支付
|
||||||
|
* @param int $order_id
|
||||||
|
* @return html
|
||||||
|
*/
|
||||||
|
public function pay($order_id){
|
||||||
|
$info = $this->order->where(array('id'=>$order_id))->find();
|
||||||
|
if ($info['pay_status']) {
|
||||||
|
return $this->success("您已支付!", url('user/order/index'));
|
||||||
|
}
|
||||||
|
$pay = array(
|
||||||
|
'body' => '测试支付',
|
||||||
|
'fee' => $info['price_count'],
|
||||||
|
//'fee' => 0.01,
|
||||||
|
'order_no' => $info['order_no'],
|
||||||
|
'title' => config('web_site_title') . ' - 订单付款',
|
||||||
|
'param' => array('order_id'=>$info['id'])
|
||||||
|
);
|
||||||
|
$data = array('type' => $info['pay_type'], 'pay_data'=>$pay);
|
||||||
|
$data = action('user/pay/index',$data);
|
||||||
|
$data['order_no'] = $info['order_no'];
|
||||||
|
$this->assign($data);
|
||||||
|
return $this->fetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function cancel($order_id){
|
||||||
|
$result = $this->order->where(array('id'=>$order_id))->setField('status',0);
|
||||||
|
if ($result) {
|
||||||
|
return $this->success("已取消!");
|
||||||
|
}else{
|
||||||
|
return $this->error("取消失败!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
70
application/user/controller/Pay.php
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace app\user\controller;
|
||||||
|
use app\common\controller\User;
|
||||||
|
|
||||||
|
class Pay extends User{
|
||||||
|
|
||||||
|
public function index($type = 'alipay', $pay_data){
|
||||||
|
$pay = new \com\Pay($type);
|
||||||
|
$pay_data['bank'] = isset($pay_data['bank']) ? $pay_data['bank'] : '';
|
||||||
|
$pay_data['callback'] = url('user/pay/returnback',array('apitype'=>input('apitype', 'alipay', 'trim')));
|
||||||
|
$pay_data['url'] = url('user/pay/returnback',array('apitype'=>input('apitype', 'alipay', 'trim')));
|
||||||
|
$pay_data['param'] = isset($pay_data['param']) ? $pay_data['param'] : '';
|
||||||
|
|
||||||
|
$input = new \com\pay\Input();
|
||||||
|
$input->setBody($pay_data['body'])
|
||||||
|
->setUid(session('user_auth.uid'))
|
||||||
|
->setFee($pay_data['fee']) //支付金额
|
||||||
|
->setOrderNo($pay_data['order_no'])//订单号
|
||||||
|
->setTitle($pay_data['title'])//设置商品名称
|
||||||
|
->setBank($pay_data['bank'])//设置银行
|
||||||
|
->setCallback($pay_data['callback'])/*** 设置支付完成后的后续操作接口 */
|
||||||
|
->setUrl($pay_data['url']) /* 设置支付完成后的跳转地址*/
|
||||||
|
->setParam($pay_data['param']);
|
||||||
|
$data = $pay->pay($input);
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
//返回
|
||||||
|
public function returnback(){
|
||||||
|
$apitype = input('get.apitype');
|
||||||
|
$method = input('get.method');
|
||||||
|
if (!empty($_POST)) {
|
||||||
|
$result = input('post.');
|
||||||
|
}elseif (!empty($_GET)) {
|
||||||
|
$result = input('get.');;
|
||||||
|
unset($result['method']);
|
||||||
|
unset($result['apitype']);
|
||||||
|
} else {
|
||||||
|
exit('Access Denied');
|
||||||
|
}
|
||||||
|
$pay = new \com\Pay($apitype);
|
||||||
|
$res = $pay->verifyNotify($result);
|
||||||
|
$status = ($result['trade_status'] == 'TRADE_FINISHED' || $result['trade_status'] == 'TRADE_SUCCESS') ? true : false;
|
||||||
|
if ($res && $status) {
|
||||||
|
db('Order')->where(array('order_no'=>$result['out_trade_no']))->update(array('pay_status'=>1));
|
||||||
|
return $this->success("支付成功!", url('user/order/index'));
|
||||||
|
}else{
|
||||||
|
return $this->error("支付失败!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//异步获取
|
||||||
|
public function notify(){
|
||||||
|
$order_no = input('post.order_no');
|
||||||
|
$pay_status = db('Order')->where(array('order_no'=>$order_no))->value('pay_status');
|
||||||
|
if ($pay_status) {
|
||||||
|
return $this->success("支付成功!", url('user/order/index'));
|
||||||
|
}else{
|
||||||
|
return $this->error("支付失败!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
application/user/lang/zh-cn.php
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'find_password' => '您的找回密码确认地址为:{:url}',
|
||||||
|
);
|
||||||
140
application/user/view/login/find.html
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>找回密码</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/libs/font-awesome.css"/>
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/common.css"/>
|
||||||
|
<!-- <link href='//fonts.googleapis.com/css?family=Open+Sans:400,600,700,300|Titillium+Web:200,300,400' rel='stylesheet' type='text/css'> -->
|
||||||
|
<link rel="stylesheet" type="text/css" href="__CSS__/member_login.css"/>
|
||||||
|
<script src="__PUBLIC__/js/jquery.js"></script>
|
||||||
|
<!--[if lt IE 9]>
|
||||||
|
<script src="__PUBLIC__/js/html5shiv.js"></script>
|
||||||
|
<script src="__PUBLIC__/js/respond.min.js"></script>
|
||||||
|
<![endif]-->
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="header-wrap">
|
||||||
|
<header class="public-head-layout wrapper">
|
||||||
|
<h1 class="site-logo">
|
||||||
|
<a href="{:url('index/index/index')}"><img src="__PUBLIC__/images/logo.png" class="pngFix"></a>
|
||||||
|
</h1>
|
||||||
|
<div class="nc-login-now">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
</div>
|
||||||
|
<div class="nc-login-layout">
|
||||||
|
<div class="left-pic"><img src="http://s.dxpd.cn/data/upload/shop/login/1.jpg" border="0"></div>
|
||||||
|
<div class="nc-login">
|
||||||
|
<div class="nc-login-mode">
|
||||||
|
<ul class="tabs-nav">
|
||||||
|
<li><a href="#default" class="tabulous_active">找回密码<i></i></a></li>
|
||||||
|
</ul>
|
||||||
|
<div id="tabs_container" class="tabs-container">
|
||||||
|
<div id="default" class="tabs-content">
|
||||||
|
<form id="login_form" class="nc-login-form" method="post">
|
||||||
|
<dl>
|
||||||
|
<dt>注册邮箱:</dt>
|
||||||
|
<dd>
|
||||||
|
<input type="text" class="text" autocomplete="off" name="email" placeholder="注册邮箱" value="{$email}" id="email" readonly >
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
<dl>
|
||||||
|
<dt>设置密码:</dt>
|
||||||
|
<dd>
|
||||||
|
<input type="password" id="password" name="password" class="text" placeholder="6-20个大小写英文字母、符号或数字"/>
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
<dl>
|
||||||
|
<dt>确认密码:</dt>
|
||||||
|
<dd>
|
||||||
|
<input type="password" id="repassword" name="repassword" class="text" placeholder="请再次输入密码"/>
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
<div class="code-div mt15">
|
||||||
|
<dl>
|
||||||
|
<dt>验证码:</dt>
|
||||||
|
<dd>
|
||||||
|
<input type="text" name="verify" autocomplete="off" class="text w80" placeholder="输入验证码" id="verify" size="10" />
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
<span><img src="{:url('user/index/verify')}" id="codeimage"/> <a class="makecode" href="javascript:void(0)">看不清,换一张</a></span>
|
||||||
|
</div>
|
||||||
|
<div class="submit-div">
|
||||||
|
<input type="hidden" name="token" value="{$token}">
|
||||||
|
<input type="hidden" name="uid" value="{$uid}">
|
||||||
|
<input type="submit" class="submit" value="登 录">
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="clear"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="footer" class="wrapper">
|
||||||
|
<p><a href="{:url('index/index/index')}">首页</a>
|
||||||
|
| <a href="{:url('user/index/index')}">会员中心</a>
|
||||||
|
</p>
|
||||||
|
Copyright 2015 <a href="http://www.tensent.cn" target="_blank">腾速科技</a> All rights reserved.<br/>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
<script src="__PUBLIC__/js/messager.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(function(){
|
||||||
|
|
||||||
|
$("form").submit(function(e){
|
||||||
|
e.preventDefault();
|
||||||
|
var self = $(this);
|
||||||
|
$.post(self.attr("action"), self.serialize(), success, "json");
|
||||||
|
|
||||||
|
function success(data){
|
||||||
|
if(data.code){
|
||||||
|
$.messager.show(data.msg, {placement: 'center',type:'success'});
|
||||||
|
setTimeout(function(){
|
||||||
|
window.location.href = data.url;
|
||||||
|
},3000);
|
||||||
|
} else {
|
||||||
|
$.messager.show(data.msg, {placement: 'center',type:'success'});
|
||||||
|
//刷新验证码
|
||||||
|
$(".makecode").click();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//初始化选中用户名输入框
|
||||||
|
$("#itemBox").find("input[name=username]").focus();
|
||||||
|
//刷新验证码
|
||||||
|
var verifyimg = $("#codeimage").attr("src");
|
||||||
|
$(".makecode").click(function(){
|
||||||
|
if( verifyimg.indexOf('?')>0){
|
||||||
|
$("#codeimage").attr("src", verifyimg+'&random='+Math.random());
|
||||||
|
}else{
|
||||||
|
$("#codeimage").attr("src", verifyimg.replace(/\?.*$/,'')+'?'+Math.random());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//placeholder兼容性
|
||||||
|
//如果支持
|
||||||
|
function isPlaceholer(){
|
||||||
|
var input = document.createElement('input');
|
||||||
|
return "placeholder" in input;
|
||||||
|
}
|
||||||
|
//如果不支持
|
||||||
|
if(!isPlaceholer()){
|
||||||
|
$(".placeholder_copy").css({display:'block'})
|
||||||
|
$("#itemBox input").keydown(function(){
|
||||||
|
$(this).parents(".item").next(".placeholder_copy").css({display:'none'})
|
||||||
|
})
|
||||||
|
$("#itemBox input").blur(function(){
|
||||||
|
if($(this).val()==""){
|
||||||
|
$(this).parents(".item").next(".placeholder_copy").css({display:'block'});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
126
application/user/view/login/forget.html
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>找回密码</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/libs/font-awesome.css"/>
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/common.css"/>
|
||||||
|
<!-- <link href='//fonts.googleapis.com/css?family=Open+Sans:400,600,700,300|Titillium+Web:200,300,400' rel='stylesheet' type='text/css'> -->
|
||||||
|
<link rel="stylesheet" type="text/css" href="__CSS__/member_login.css"/>
|
||||||
|
<script src="__PUBLIC__/js/jquery.js"></script>
|
||||||
|
<!--[if lt IE 9]>
|
||||||
|
<script src="__PUBLIC__/js/html5shiv.js"></script>
|
||||||
|
<script src="__PUBLIC__/js/respond.min.js"></script>
|
||||||
|
<![endif]-->
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="header-wrap">
|
||||||
|
<header class="public-head-layout wrapper">
|
||||||
|
<h1 class="site-logo">
|
||||||
|
<a href="{:url('index/index/index')}"><img src="__PUBLIC__/images/logo.png" class="pngFix"></a>
|
||||||
|
</h1>
|
||||||
|
<div class="nc-login-now">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
</div>
|
||||||
|
<div class="nc-login-layout">
|
||||||
|
<div class="left-pic"><img src="http://s.dxpd.cn/data/upload/shop/login/1.jpg" border="0"></div>
|
||||||
|
<div class="nc-login">
|
||||||
|
<div class="nc-login-mode">
|
||||||
|
<ul class="tabs-nav">
|
||||||
|
<li><a href="#default" class="tabulous_active">找回密码<i></i></a></li>
|
||||||
|
</ul>
|
||||||
|
<div id="tabs_container" class="tabs-container">
|
||||||
|
<div id="default" class="tabs-content">
|
||||||
|
<form id="login_form" class="nc-login-form" method="post">
|
||||||
|
<dl>
|
||||||
|
<dt>注册邮箱:</dt>
|
||||||
|
<dd>
|
||||||
|
<input type="text" class="text" autocomplete="off" name="email" placeholder="注册邮箱" id="email" >
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
<div class="code-div mt15">
|
||||||
|
<dl>
|
||||||
|
<dt>验证码:</dt>
|
||||||
|
<dd>
|
||||||
|
<input type="text" name="verify" autocomplete="off" class="text w80" placeholder="输入验证码" id="verify" size="10" />
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
<span><img src="{:url('user/index/verify')}" id="codeimage"/> <a class="makecode" href="javascript:void(0)">看不清,换一张</a></span>
|
||||||
|
</div>
|
||||||
|
<div class="submit-div">
|
||||||
|
<input type="submit" class="submit" value="登 录">
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="clear"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="footer" class="wrapper">
|
||||||
|
<p><a href="{:url('index/index/index')}">首页</a>
|
||||||
|
| <a href="{:url('user/index/index')}">会员中心</a>
|
||||||
|
</p>
|
||||||
|
Copyright 2015 <a href="http://www.tensent.cn" target="_blank">腾速科技</a> All rights reserved.<br/>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
<script src="__PUBLIC__/js/messager.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(function(){
|
||||||
|
|
||||||
|
$("form").submit(function(e){
|
||||||
|
e.preventDefault();
|
||||||
|
var self = $(this);
|
||||||
|
$.post(self.attr("action"), self.serialize(), success, "json");
|
||||||
|
|
||||||
|
function success(data){
|
||||||
|
if(data.code){
|
||||||
|
$.messager.show(data.msg, {placement: 'center',type:'success'});
|
||||||
|
setTimeout(function(){
|
||||||
|
window.location.href = data.url;
|
||||||
|
},3000);
|
||||||
|
} else {
|
||||||
|
$.messager.show(data.msg, {placement: 'center',type:'success'});
|
||||||
|
//刷新验证码
|
||||||
|
$(".makecode").click();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//初始化选中用户名输入框
|
||||||
|
$("#itemBox").find("input[name=username]").focus();
|
||||||
|
//刷新验证码
|
||||||
|
var verifyimg = $("#codeimage").attr("src");
|
||||||
|
$(".makecode").click(function(){
|
||||||
|
if( verifyimg.indexOf('?')>0){
|
||||||
|
$("#codeimage").attr("src", verifyimg+'&random='+Math.random());
|
||||||
|
}else{
|
||||||
|
$("#codeimage").attr("src", verifyimg.replace(/\?.*$/,'')+'?'+Math.random());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//placeholder兼容性
|
||||||
|
//如果支持
|
||||||
|
function isPlaceholer(){
|
||||||
|
var input = document.createElement('input');
|
||||||
|
return "placeholder" in input;
|
||||||
|
}
|
||||||
|
//如果不支持
|
||||||
|
if(!isPlaceholer()){
|
||||||
|
$(".placeholder_copy").css({display:'block'})
|
||||||
|
$("#itemBox input").keydown(function(){
|
||||||
|
$(this).parents(".item").next(".placeholder_copy").css({display:'none'})
|
||||||
|
})
|
||||||
|
$("#itemBox input").blur(function(){
|
||||||
|
if($(this).val()==""){
|
||||||
|
$(this).parents(".item").next(".placeholder_copy").css({display:'block'});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
94
application/user/view/order/confirm.html
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
|
||||||
|
<title>确认订单信息-会员中心 - Powered by TenSent,Inc.</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/bootstrap/bootstrap.min.css"/>
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/libs/font-awesome.css"/>
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/libs/nanoscroller.css"/>
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/common.css"/>
|
||||||
|
<!-- <link href='//fonts.googleapis.com/css?family=Open+Sans:400,600,700,300|Titillium+Web:200,300,400' rel='stylesheet' type='text/css'> -->
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/style.css"/>
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/order.css"/>
|
||||||
|
<script src="__PUBLIC__/js/jquery.js"></script>
|
||||||
|
<!--[if lt IE 9]>
|
||||||
|
<script src="__PUBLIC__/js/html5shiv.js"></script>
|
||||||
|
<script src="__PUBLIC__/js/respond.min.js"></script>
|
||||||
|
<![endif]-->
|
||||||
|
{block name="style"}{/block}
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="header">
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12">
|
||||||
|
<div class="logo">
|
||||||
|
<a href="{:url('index/book/index')}"><img src="__PUBLIC__/images/logo.png" alt="确认订单信息-会员中心"></a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12">
|
||||||
|
<div class="progress">
|
||||||
|
<div class="progress-bar progress-bar-danger progress-bar-striped" style="width: 25%">
|
||||||
|
<span>1、购物车</span>
|
||||||
|
</div>
|
||||||
|
<div class="progress-bar progress-bar-danger progress-bar-striped" style="width: 25%">
|
||||||
|
<span>2、确认订单信息</span>
|
||||||
|
</div>
|
||||||
|
<div class="progress-bar progress-bar-success progress-bar-striped" style="width: 25%">
|
||||||
|
<span>3、选择支付</span>
|
||||||
|
</div>
|
||||||
|
<div class="progress-bar progress-bar-primary progress-bar-striped" style="width: 25%">
|
||||||
|
<span>4、订购完成</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12">
|
||||||
|
<p class="no-data"><span class="red"><i class="fa fa-edit"></i></span> 订单已成功提交!</p>
|
||||||
|
<form action="{:url('user/order/pay')}" method="post" class="form">
|
||||||
|
<table class="table table-bordered">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td width="200" class="text-right">订单编号:</td>
|
||||||
|
<td>{$info['order_no']}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td width="200" class="text-right">订单金额:</td>
|
||||||
|
<td>¥{$info['price_count']}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td width="200" class="text-right">支付方式:</td>
|
||||||
|
<td>{$info['pay_type_text']}</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="pull-right">
|
||||||
|
<input type="hidden" name="order_id" value="{$info['id']}">
|
||||||
|
<input type="hidden" name="pay_type" value="{$info['pay_type']}">
|
||||||
|
<button class="btn btn-danger">立即支付</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="footer">
|
||||||
|
<div class="warp">
|
||||||
|
<p>Copyright © 2013-2016 <a href="http://www.tensent.cn" target="_blank">腾速科技</a> 版权所有</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
50
application/user/view/order/index.html
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
{extend name="public/base" /}
|
||||||
|
{block name="body"}
|
||||||
|
<div class="tabs-wrapper">
|
||||||
|
<ul class="nav nav-tabs">
|
||||||
|
<li class="active"><a href="#editpw" data-toggle="tab">我的订单</a></li>
|
||||||
|
</ul>
|
||||||
|
<div class="tab-content">
|
||||||
|
<div class="tab-pane fade in active" id="editpw">
|
||||||
|
{volist name="list" id="item"}
|
||||||
|
<div class="panel panel-info">
|
||||||
|
<div class="panel-heading">
|
||||||
|
订单号:{$item['order_no']}({$item['create_time']|date='Y-m-d',###})
|
||||||
|
<span class="pull-right">
|
||||||
|
{if $item['pay_status']}
|
||||||
|
已付款
|
||||||
|
{else/}
|
||||||
|
<a href="{:url('user/order/cancel',array('order_id'=>$item['id']))}" class="ajax-get"><i class="fa fa-close"></i> 取消订单</a>
|
||||||
|
<a href="{:url('user/order/lists',array('order_id'=>$item['id']))}" target="_blank" class="text-danger">付款</a>
|
||||||
|
{/if}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<table class="table">
|
||||||
|
<tr>
|
||||||
|
<th>图书</th>
|
||||||
|
<th>图书名称</th>
|
||||||
|
<th>操作</th>
|
||||||
|
</tr>
|
||||||
|
{volist name="item['product']" id="product"}
|
||||||
|
<tr>
|
||||||
|
<td width="80">
|
||||||
|
<a href="{:url('index/book/detail', array('id'=>$product['product_id']))}" target="_blank"><img src="{:get_cover($product->book['cover_id'],'path')}" alt="{$product->book['book_name']}" width="60"></a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="{:url('index/book/detail', array('id'=>$product['product_id']))}" target="_blank">{$product->book['book_name']}</a>
|
||||||
|
</td>
|
||||||
|
<td width="120">
|
||||||
|
{if $item['pay_status']}
|
||||||
|
<a href="{:url('user/upload/download',array('order_id'=>$item['id'],'product_id'=>$product['product_id']))}" target="_blank">下载图书</a>
|
||||||
|
{/if}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{/volist}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{/volist}
|
||||||
|
{$page}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/block}
|
||||||
124
application/user/view/order/lists.html
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
|
||||||
|
<title>确认订单信息-会员中心 - Powered by TenSent,Inc.</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/bootstrap/bootstrap.min.css"/>
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/libs/font-awesome.css"/>
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/libs/nanoscroller.css"/>
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/common.css"/>
|
||||||
|
<!-- <link href='//fonts.googleapis.com/css?family=Open+Sans:400,600,700,300|Titillium+Web:200,300,400' rel='stylesheet' type='text/css'> -->
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/style.css"/>
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/order.css"/>
|
||||||
|
<script src="__PUBLIC__/js/jquery.js"></script>
|
||||||
|
<!--[if lt IE 9]>
|
||||||
|
<script src="__PUBLIC__/js/html5shiv.js"></script>
|
||||||
|
<script src="__PUBLIC__/js/respond.min.js"></script>
|
||||||
|
<![endif]-->
|
||||||
|
{block name="style"}{/block}
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="header">
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12">
|
||||||
|
<div class="logo">
|
||||||
|
<a href="{:url('index/book/index')}"><img src="__PUBLIC__/images/logo.png" alt="确认订单信息-会员中心"></a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12">
|
||||||
|
<div class="progress">
|
||||||
|
<div class="progress-bar progress-bar-danger progress-bar-striped" style="width: 25%">
|
||||||
|
<span>1、购物车</span>
|
||||||
|
</div>
|
||||||
|
<div class="progress-bar progress-bar-success progress-bar-striped" style="width: 25%">
|
||||||
|
<span>2、确认订单信息</span>
|
||||||
|
</div>
|
||||||
|
<div class="progress-bar progress-bar-primary progress-bar-striped" style="width: 25%">
|
||||||
|
<span>3、选择支付</span>
|
||||||
|
</div>
|
||||||
|
<div class="progress-bar progress-bar-primary progress-bar-striped" style="width: 25%">
|
||||||
|
<span>4、订购完成</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12">
|
||||||
|
<form action="{:url('user/order/confirm')}" method="post" class="form">
|
||||||
|
<div class="order_title">商品清单</div>
|
||||||
|
{if !empty($list)}
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>商品</th>
|
||||||
|
<th>名称</th>
|
||||||
|
<th>单价</th>
|
||||||
|
<th>数量</th>
|
||||||
|
<th>小计</th>
|
||||||
|
<th>操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{volist name="list" id="item"}
|
||||||
|
<tr>
|
||||||
|
<td width="90">
|
||||||
|
<a href="{:url('index/book/detail',array('id'=>$item->book['id']))}"><img src="{:get_cover($item->book['cover_id'],'path')}" width="80"></a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="{:url('index/book/detail',array('id'=>$item->book['id']))}">{$item->book['book_name']}</a>
|
||||||
|
</td>
|
||||||
|
<td>¥{$item['price']}</td>
|
||||||
|
<td>{$item['num']}</td>
|
||||||
|
<td>¥{$item['price_count']}</td>
|
||||||
|
<td width="60">
|
||||||
|
<a href="{:url('index/cart/del',array('id'=>$item['id']))}" class="ajax-get confirm"><i class="fa fa-close"></i></a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{/volist}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<div class="text-right price_count">
|
||||||
|
<p>应付总额:<span>¥{$price_count}</span></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="order_title">支付方式</div>
|
||||||
|
<div class="clearfix">
|
||||||
|
<ul class="payment-list">
|
||||||
|
<li class="selected">
|
||||||
|
<input type="radio" name="payment" value="alipay" checked="true">
|
||||||
|
<label><b>支付宝支付</b> </label>
|
||||||
|
<div><img src="__PUBLIC__/images/pay/alipay.png" width="180"></div>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="pull-right">
|
||||||
|
<input type="hidden" name="order_id" value="{$order_id}">
|
||||||
|
<button type="submit" class="btn btn-danger">提交订单</button>
|
||||||
|
</div>
|
||||||
|
{else/}
|
||||||
|
<p class="no-data">购物车为空!<a href="{:url('index/book/index')}">去继续选择……</a></p>
|
||||||
|
{/if}
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="footer">
|
||||||
|
<div class="warp">
|
||||||
|
<p>Copyright © 2013-2016 <a href="http://www.tensent.cn" target="_blank">腾速科技</a> 版权所有</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
93
application/user/view/order/pay.html
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
|
||||||
|
<title>确认订单信息-会员中心 - Powered by TenSent,Inc.</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/bootstrap/bootstrap.min.css"/>
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/libs/font-awesome.css"/>
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/libs/nanoscroller.css"/>
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/common.css"/>
|
||||||
|
<!-- <link href='//fonts.googleapis.com/css?family=Open+Sans:400,600,700,300|Titillium+Web:200,300,400' rel='stylesheet' type='text/css'> -->
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/style.css"/>
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/order.css"/>
|
||||||
|
<script src="__PUBLIC__/js/jquery.js"></script>
|
||||||
|
<!--[if lt IE 9]>
|
||||||
|
<script src="__PUBLIC__/js/html5shiv.js"></script>
|
||||||
|
<script src="__PUBLIC__/js/respond.min.js"></script>
|
||||||
|
<![endif]-->
|
||||||
|
{block name="style"}{/block}
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="header">
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12">
|
||||||
|
<div class="logo">
|
||||||
|
<a href="{:url('index/book/index')}"><img src="__PUBLIC__/images/logo.png" alt="确认订单信息-会员中心"></a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12">
|
||||||
|
<div class="progress">
|
||||||
|
<div class="progress-bar progress-bar-danger progress-bar-striped" style="width: 25%">
|
||||||
|
<span>1、购物车</span>
|
||||||
|
</div>
|
||||||
|
<div class="progress-bar progress-bar-danger progress-bar-striped" style="width: 25%">
|
||||||
|
<span>2、确认订单信息</span>
|
||||||
|
</div>
|
||||||
|
<div class="progress-bar progress-bar-danger progress-bar-striped" style="width: 25%">
|
||||||
|
<span>3、选择支付</span>
|
||||||
|
</div>
|
||||||
|
<div class="progress-bar progress-bar-success progress-bar-striped" style="width: 25%">
|
||||||
|
<span>4、订购完成</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12">
|
||||||
|
<p class="no-data"><span class="red"><i class="fa fa-spinner fa-spin fa-fw"></i></span> 等待支付!</p>
|
||||||
|
{$sHtml}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{if $is_submit}
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(function(){
|
||||||
|
setTimeout(function(){
|
||||||
|
document.forms['paysubmit'].submit();
|
||||||
|
},300);
|
||||||
|
|
||||||
|
setInterval(function(){
|
||||||
|
$.ajax({
|
||||||
|
url : " {:config('base_url')} " + "/user/pay/notify.html",
|
||||||
|
type : 'post',
|
||||||
|
data : {'order_id':"{$order_no}"},
|
||||||
|
success : function(data){
|
||||||
|
if(data.code === 1){
|
||||||
|
window.location
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dataType : 'json'
|
||||||
|
})
|
||||||
|
},10000);
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
{/if}
|
||||||
|
<div class="footer">
|
||||||
|
<div class="warp">
|
||||||
|
<p>Copyright © 2013-2016 <a href="http://www.tensent.cn" target="_blank">腾速科技</a> 版权所有</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -10,13 +10,12 @@
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
define('THINK_VERSION', '5.0.0 RC3');
|
define('THINK_VERSION', '5.0.0 RC3');
|
||||||
define('START_TIME', microtime(true));
|
define('START_TIME', number_format(microtime(true), 8, '.', ''));
|
||||||
define('START_MEM', memory_get_usage());
|
define('START_MEM', memory_get_usage());
|
||||||
define('EXT', '.php');
|
define('EXT', '.php');
|
||||||
define('DS', DIRECTORY_SEPARATOR);
|
define('DS', DIRECTORY_SEPARATOR);
|
||||||
defined('THINK_PATH') or define('THINK_PATH', __DIR__ . DS);
|
defined('THINK_PATH') or define('THINK_PATH', __DIR__ . DS);
|
||||||
define('LIB_PATH', THINK_PATH . 'library' . DS);
|
define('LIB_PATH', THINK_PATH . 'library' . DS);
|
||||||
define('MODE_PATH', THINK_PATH . 'mode' . DS); // 系统应用模式目录
|
|
||||||
define('CORE_PATH', LIB_PATH . 'think' . DS);
|
define('CORE_PATH', LIB_PATH . 'think' . DS);
|
||||||
define('TRAIT_PATH', LIB_PATH . 'traits' . DS);
|
define('TRAIT_PATH', LIB_PATH . 'traits' . DS);
|
||||||
defined('APP_PATH') or define('APP_PATH', dirname($_SERVER['SCRIPT_FILENAME']) . DS);
|
defined('APP_PATH') or define('APP_PATH', dirname($_SERVER['SCRIPT_FILENAME']) . DS);
|
||||||
@@ -30,8 +29,6 @@ defined('TEMP_PATH') or define('TEMP_PATH', RUNTIME_PATH . 'temp' . DS);
|
|||||||
defined('CONF_PATH') or define('CONF_PATH', APP_PATH); // 配置文件目录
|
defined('CONF_PATH') or define('CONF_PATH', APP_PATH); // 配置文件目录
|
||||||
defined('CONF_EXT') or define('CONF_EXT', EXT); // 配置文件后缀
|
defined('CONF_EXT') or define('CONF_EXT', EXT); // 配置文件后缀
|
||||||
defined('ENV_PREFIX') or define('ENV_PREFIX', 'PHP_'); // 环境变量的配置前缀
|
defined('ENV_PREFIX') or define('ENV_PREFIX', 'PHP_'); // 环境变量的配置前缀
|
||||||
defined('IS_API') or define('IS_API', false); // 是否API接口
|
|
||||||
defined('AUTO_SCAN_PACKAGE') or define('AUTO_SCAN_PACKAGE', false); // 是否自动扫描非Composer安装类库
|
|
||||||
|
|
||||||
// 环境常量
|
// 环境常量
|
||||||
define('IS_CLI', PHP_SAPI == 'cli' ? true : false);
|
define('IS_CLI', PHP_SAPI == 'cli' ? true : false);
|
||||||
@@ -44,9 +41,11 @@ require CORE_PATH . 'Loader.php';
|
|||||||
if (is_file(ROOT_PATH . 'env' . EXT)) {
|
if (is_file(ROOT_PATH . 'env' . EXT)) {
|
||||||
$env = include ROOT_PATH . 'env' . EXT;
|
$env = include ROOT_PATH . 'env' . EXT;
|
||||||
foreach ($env as $key => $val) {
|
foreach ($env as $key => $val) {
|
||||||
$name = ENV_PREFIX . $key;
|
$name = ENV_PREFIX . strtoupper($key);
|
||||||
if (is_bool($val)) {
|
if (is_bool($val)) {
|
||||||
$val = $val ? 1 : 0;
|
$val = $val ? 1 : 0;
|
||||||
|
} elseif (!is_scalar($val)) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
putenv("$name=$val");
|
putenv("$name=$val");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,111 +0,0 @@
|
|||||||
<?php
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
// | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
// | Author: liu21st <liu21st@gmail.com>
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ThinkPHP 类库映射定义
|
|
||||||
*/
|
|
||||||
return [
|
|
||||||
'think\App' => CORE_PATH . 'App' . EXT,
|
|
||||||
'think\Build' => CORE_PATH . 'Build' . EXT,
|
|
||||||
'think\Cache' => CORE_PATH . 'Cache' . EXT,
|
|
||||||
'think\cache\driver\Apc' => CORE_PATH . 'cache' . DS . 'driver' . DS . 'Apc' . EXT,
|
|
||||||
'think\cache\driver\File' => CORE_PATH . 'cache' . DS . 'driver' . DS . 'File' . EXT,
|
|
||||||
'think\cache\driver\Lite' => CORE_PATH . 'cache' . DS . 'driver' . DS . 'Lite' . EXT,
|
|
||||||
'think\cache\driver\Memcache' => CORE_PATH . 'cache' . DS . 'driver' . DS . 'Memcache' . EXT,
|
|
||||||
'think\cache\driver\Memcached' => CORE_PATH . 'cache' . DS . 'driver' . DS . 'Memcached' . EXT,
|
|
||||||
'think\cache\driver\Redis' => CORE_PATH . 'cache' . DS . 'driver' . DS . 'Redis' . EXT,
|
|
||||||
'think\cache\driver\Redisd' => CORE_PATH . 'cache' . DS . 'driver' . DS . 'Redisd' . EXT,
|
|
||||||
'think\cache\driver\Sae' => CORE_PATH . 'cache' . DS . 'driver' . DS . 'Sae' . EXT,
|
|
||||||
'think\cache\driver\Secache' => CORE_PATH . 'cache' . DS . 'driver' . DS . 'Secache' . EXT,
|
|
||||||
'think\cache\driver\Sqlite' => CORE_PATH . 'cache' . DS . 'driver' . DS . 'Sqlite' . EXT,
|
|
||||||
'think\cache\driver\Wincache' => CORE_PATH . 'cache' . DS . 'driver' . DS . 'Wincache' . EXT,
|
|
||||||
'think\cache\driver\Xcache' => CORE_PATH . 'cache' . DS . 'driver' . DS . 'Xcache' . EXT,
|
|
||||||
'think\Collection' => CORE_PATH . 'Collection' . EXT,
|
|
||||||
'think\Config' => CORE_PATH . 'Config' . EXT,
|
|
||||||
'think\config\Ini' => CORE_PATH . 'config' . DS . 'driver' . DS . 'Ini' . EXT,
|
|
||||||
'think\config\Json' => CORE_PATH . 'config' . DS . 'driver' . DS . 'Json' . EXT,
|
|
||||||
'think\config\Xml' => CORE_PATH . 'config' . DS . 'driver' . DS . 'Xml' . EXT,
|
|
||||||
'think\Console' => CORE_PATH . 'Console' . EXT,
|
|
||||||
'think\Controller' => CORE_PATH . 'Controller' . EXT,
|
|
||||||
'think\controller\Hprose' => CORE_PATH . 'controller' . DS . 'Hprose' . EXT,
|
|
||||||
'think\controller\Jsonrpc' => CORE_PATH . 'controller' . DS . 'Jsonrpc' . EXT,
|
|
||||||
'think\controller\Rest' => CORE_PATH . 'controller' . DS . 'Rest' . EXT,
|
|
||||||
'think\controller\Rpc' => CORE_PATH . 'controller' . DS . 'Rpc' . EXT,
|
|
||||||
'think\controller\Yar' => CORE_PATH . 'controller' . DS . 'Yar' . EXT,
|
|
||||||
'think\Cookie' => CORE_PATH . 'Cookie' . EXT,
|
|
||||||
'think\Db' => CORE_PATH . 'Db' . EXT,
|
|
||||||
'think\db\Connection' => CORE_PATH . 'db' . DS . 'Connection' . EXT,
|
|
||||||
'think\db\connector\Mysql' => CORE_PATH . 'db' . DS . 'connector' . DS . 'Mysql' . EXT,
|
|
||||||
'think\db\connector\Oracle' => CORE_PATH . 'db' . DS . 'connector' . DS . 'Oracle' . EXT,
|
|
||||||
'think\db\connector\Pgsql' => CORE_PATH . 'db' . DS . 'connector' . DS . 'Pgsql' . EXT,
|
|
||||||
'think\db\connector\Sqlite' => CORE_PATH . 'db' . DS . 'connector' . DS . 'Sqlite' . EXT,
|
|
||||||
'think\db\connector\Sqlsrv' => CORE_PATH . 'db' . DS . 'connector' . DS . 'Sqlsrv' . EXT,
|
|
||||||
'think\db\Builder' => CORE_PATH . 'db' . DS . 'Builder' . EXT,
|
|
||||||
'think\db\builder\Mysql' => CORE_PATH . 'db' . DS . 'builder' . DS . 'Mysql' . EXT,
|
|
||||||
'think\db\builder\Oracle' => CORE_PATH . 'db' . DS . 'builder' . DS . 'Oracle' . EXT,
|
|
||||||
'think\db\builder\Pgsql' => CORE_PATH . 'db' . DS . 'builder' . DS . 'Pgsql' . EXT,
|
|
||||||
'think\db\builder\Sqlite' => CORE_PATH . 'db' . DS . 'builder' . DS . 'Sqlite' . EXT,
|
|
||||||
'think\db\builder\Sqlsrv' => CORE_PATH . 'db' . DS . 'builder' . DS . 'Sqlsrv' . EXT,
|
|
||||||
'think\db\Query' => CORE_PATH . 'db' . DS . 'Query' . EXT,
|
|
||||||
'think\Debug' => CORE_PATH . 'Debug' . EXT,
|
|
||||||
'think\Error' => CORE_PATH . 'Error' . EXT,
|
|
||||||
'think\Exception' => CORE_PATH . 'Exception' . EXT,
|
|
||||||
'think\exception\ClassNotFoundException' => CORE_PATH . 'exception' . DS . 'ClassNotFoundException' . EXT,
|
|
||||||
'think\exception\DbException' => CORE_PATH . 'exception' . DS . 'DbException' . EXT,
|
|
||||||
'think\exception\ErrorException' => CORE_PATH . 'exception' . DS . 'ErrorException' . EXT,
|
|
||||||
'think\exception\Handle' => CORE_PATH . 'exception' . DS . 'Handle' . EXT,
|
|
||||||
'think\exception\HttpException' => CORE_PATH . 'exception' . DS . 'HttpException' . EXT,
|
|
||||||
'think\exception\HttpResponseException' => CORE_PATH . 'exception' . DS . 'HttpResponseException' . EXT,
|
|
||||||
'think\exception\PDOException' => CORE_PATH . 'exception' . DS . 'PDOException' . EXT,
|
|
||||||
'think\exception\TemplateNotFoundException' => CORE_PATH . 'exception' . DS . 'TemplateNotFoundException' . EXT,
|
|
||||||
'think\exception\ThrowableError' => CORE_PATH . 'exception' . DS . 'ThrowableError' . EXT,
|
|
||||||
'think\exception\ValidateException' => CORE_PATH . 'exception' . DS . 'ValidateException' . EXT,
|
|
||||||
'think\File' => CORE_PATH . 'File' . EXT,
|
|
||||||
'think\Hook' => CORE_PATH . 'Hook' . EXT,
|
|
||||||
'think\Lang' => CORE_PATH . 'Lang' . EXT,
|
|
||||||
'think\Log' => CORE_PATH . 'Log' . EXT,
|
|
||||||
'think\log\driver\Browser' => CORE_PATH . 'log' . DS . 'driver' . DS . 'Browser' . EXT,
|
|
||||||
'think\log\driver\File' => CORE_PATH . 'log' . DS . 'driver' . DS . 'File' . EXT,
|
|
||||||
'think\log\driver\Sae' => CORE_PATH . 'log' . DS . 'driver' . DS . 'Sae' . EXT,
|
|
||||||
'think\log\driver\Socket' => CORE_PATH . 'log' . DS . 'driver' . DS . 'Socket' . EXT,
|
|
||||||
'think\log\driver\Trace' => CORE_PATH . 'log' . DS . 'driver' . DS . 'Trace' . EXT,
|
|
||||||
'think\Model' => CORE_PATH . 'Model' . EXT,
|
|
||||||
'think\model\Merge' => CORE_PATH . 'model' . DS . 'Merge' . EXT,
|
|
||||||
'think\model\Pivot' => CORE_PATH . 'model' . DS . 'Pivot' . EXT,
|
|
||||||
'think\model\Relation' => CORE_PATH . 'model' . DS . 'Relation' . EXT,
|
|
||||||
'think\Process' => CORE_PATH . 'Process' . EXT,
|
|
||||||
'think\Paginator' => CORE_PATH . 'Paginator' . EXT,
|
|
||||||
'think\paginator\Collection' => CORE_PATH . 'paginator' . DS . 'Collection' . EXT,
|
|
||||||
'think\paginator\driver\Bootstrap' => CORE_PATH . 'paginator' . DS . 'driver' . DS . 'Bootstrap' . EXT,
|
|
||||||
'think\Request' => CORE_PATH . 'Request' . EXT,
|
|
||||||
'think\Response' => CORE_PATH . 'Response' . EXT,
|
|
||||||
'think\response\Json' => CORE_PATH . 'response' . DS . 'Json' . EXT,
|
|
||||||
'think\response\Jsonp' => CORE_PATH . 'response' . DS . 'Jsonp' . EXT,
|
|
||||||
'think\response\Redirect' => CORE_PATH . 'response' . DS . 'Redirect' . EXT,
|
|
||||||
'think\response\View' => CORE_PATH . 'response' . DS . 'View' . EXT,
|
|
||||||
'think\response\Xml' => CORE_PATH . 'response' . DS . 'Xml' . EXT,
|
|
||||||
'think\Route' => CORE_PATH . 'Route' . EXT,
|
|
||||||
'think\Session' => CORE_PATH . 'Session' . EXT,
|
|
||||||
'think\session\driver\Memcache' => CORE_PATH . 'session' . DS . 'driver' . DS . 'Memcache' . EXT,
|
|
||||||
'think\session\driver\Memcached' => CORE_PATH . 'session' . DS . 'driver' . DS . 'Memcached' . EXT,
|
|
||||||
'think\session\driver\Redis' => CORE_PATH . 'session' . DS . 'driver' . DS . 'Redis' . EXT,
|
|
||||||
'think\Template' => CORE_PATH . 'Template' . EXT,
|
|
||||||
'think\template\Taglib' => CORE_PATH . 'template' . DS . 'Taglib' . EXT,
|
|
||||||
'think\template\taglib\Cx' => CORE_PATH . 'template' . DS . 'taglib' . DS . 'Cx' . EXT,
|
|
||||||
'think\template\driver\File' => CORE_PATH . 'template' . DS . 'driver' . DS . 'File' . EXT,
|
|
||||||
'think\template\driver\Sae' => CORE_PATH . 'template' . DS . 'driver' . DS . 'Sae' . EXT,
|
|
||||||
'think\Url' => CORE_PATH . 'Url' . EXT,
|
|
||||||
'think\Validate' => CORE_PATH . 'Validate' . EXT,
|
|
||||||
'think\View' => CORE_PATH . 'View' . EXT,
|
|
||||||
'think\view\driver\Think' => CORE_PATH . 'view' . DS . 'driver' . DS . 'Think' . EXT,
|
|
||||||
'think\view\driver\Php' => CORE_PATH . 'view' . DS . 'driver' . DS . 'Php' . EXT,
|
|
||||||
'traits\controller\Jump' => TRAIT_PATH . 'controller' . DS . 'Jump' . EXT,
|
|
||||||
];
|
|
||||||
@@ -140,12 +140,20 @@ return [
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
'log' => [
|
'log' => [
|
||||||
// 日志记录方式,支持 file socket trace sae
|
// 日志记录方式,支持 file socket sae
|
||||||
'type' => 'File',
|
'type' => 'File',
|
||||||
// 日志保存目录
|
// 日志保存目录
|
||||||
'path' => LOG_PATH,
|
'path' => LOG_PATH,
|
||||||
],
|
],
|
||||||
|
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Trace设置
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
'trace' => [
|
||||||
|
//支持Html,Console 设为false则不显示
|
||||||
|
'type' => false,
|
||||||
|
],
|
||||||
|
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | 缓存设置
|
// | 缓存设置
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|||||||
114
core/extend/com/Cart.php
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace com;
|
||||||
|
|
||||||
|
class Cart{
|
||||||
|
|
||||||
|
private $goods = 'book';
|
||||||
|
private $items = array();
|
||||||
|
|
||||||
|
public function __construct(){
|
||||||
|
$this->items = session('sent_cart') ? session('sent_cart') : array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加购物车
|
||||||
|
* @param integer $id 商品ID标识
|
||||||
|
* @param integer $num 添加的数量
|
||||||
|
*/
|
||||||
|
public function addItem($id,$num=1) {
|
||||||
|
if ($this->hasItem($id)) {
|
||||||
|
$this->incNum($id,$num);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->items[$id] = $num;
|
||||||
|
session('sent_cart', $this->items);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否有某个商品
|
||||||
|
* @param integer $id 商品ID标识
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
protected function hasItem($id) {
|
||||||
|
return isset($this->items[$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除商品
|
||||||
|
* @param integer $id 商品ID标识
|
||||||
|
*/
|
||||||
|
public function delItem($id) {
|
||||||
|
unset($this->items[$id]);
|
||||||
|
session('sent_cart', $this->items);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function modNum($id,$num=1) {
|
||||||
|
if (!$this->hasItem($id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$this->items[$id] = $num;
|
||||||
|
session('sent_cart', $this->items);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function incNum($id,$num=1) {
|
||||||
|
if ($this->hasItem($id)) {
|
||||||
|
$this->items[$id] += $num;
|
||||||
|
}
|
||||||
|
session('sent_cart', $this->items);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function decNum($id,$num=1) {
|
||||||
|
if ($this->hasItem($id)) {
|
||||||
|
$this->items[$id] -= $num;
|
||||||
|
}
|
||||||
|
if ($this->items[$id] <1) {
|
||||||
|
$this->delItem($id);
|
||||||
|
}
|
||||||
|
session('sent_cart', $this->items);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCount() {
|
||||||
|
return count($this->items);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getNum(){
|
||||||
|
if ($this->getCount() == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sum = 0;
|
||||||
|
foreach ($this->items as $item) {
|
||||||
|
$sum += $item;
|
||||||
|
}
|
||||||
|
return $sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function all(){
|
||||||
|
$list = array();
|
||||||
|
foreach ($this->items as $key => $value) {
|
||||||
|
$goods = \think\Db::name($this->goods)->where(array('id'=>$key))->find();
|
||||||
|
$list[] = array(
|
||||||
|
'id' => $goods['id'],
|
||||||
|
'name' => $goods['book_name'],
|
||||||
|
'price' => $goods['price'],
|
||||||
|
'cover_id' => $goods['cover_id'],
|
||||||
|
'price_count' => $value*$goods['price'],
|
||||||
|
'num' => $value
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clear() {
|
||||||
|
$this->items = array();
|
||||||
|
session('sent_cart', $this->items);
|
||||||
|
}
|
||||||
|
}
|
||||||
2343
core/extend/com/Email.php
Normal file
80
core/extend/com/Pay.php
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace com;
|
||||||
|
|
||||||
|
class Pay{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付驱动实例
|
||||||
|
* @var Object
|
||||||
|
*/
|
||||||
|
private $payer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置参数
|
||||||
|
* @var type
|
||||||
|
*/
|
||||||
|
private $config;
|
||||||
|
|
||||||
|
public function __construct($driver) {
|
||||||
|
|
||||||
|
//获取配置
|
||||||
|
$this->getConfig($driver);
|
||||||
|
/* 配置 */
|
||||||
|
$pos = strrpos($driver, '\\');
|
||||||
|
$pos = $pos === false ? 0 : $pos + 1;
|
||||||
|
$apitype = strtolower(substr($driver, $pos));
|
||||||
|
$this->config['notify_url'] = url('user/pay/notify',array('apitype'=>$apitype), false, true);
|
||||||
|
$this->config['return_url'] = url("user/pay/returnback", array('apitype' => $apitype, 'method' => 'return'), false, true);
|
||||||
|
|
||||||
|
$this->config['pey_type'] = $driver;
|
||||||
|
|
||||||
|
/* 设置支付驱动 */
|
||||||
|
$class = strpos($driver, '\\') ? $driver : 'com\\pay\\driver\\' . ucfirst(strtolower($driver));
|
||||||
|
$this->setDriver($class, $this->config);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function pay(pay\Input $input){
|
||||||
|
return $this->payer->pay($input);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取配置
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getConfig($driver){
|
||||||
|
$config = \think\Config::load(APP_PATH . 'pay.php');
|
||||||
|
$this->config = $config[$driver];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置支付驱动
|
||||||
|
* @param string $class 驱动类名称
|
||||||
|
*/
|
||||||
|
private function setDriver($class, $config) {
|
||||||
|
$this->payer = new $class($config);
|
||||||
|
if (!$this->payer) {
|
||||||
|
throw new \think\Exception("不存在支付驱动:{$class}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __call($method, $arguments) {
|
||||||
|
if (method_exists($this, $method)) {
|
||||||
|
return call_user_func_array(array(&$this, $method), $arguments);
|
||||||
|
} elseif (!empty($this->payer) && $this->payer instanceof Pay\Pay && method_exists($this->payer, $method)) {
|
||||||
|
return call_user_func_array(array(&$this->payer, $method), $arguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
176
core/extend/com/pay/Input.php
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace com\pay;
|
||||||
|
|
||||||
|
class Input{
|
||||||
|
|
||||||
|
protected $_orderNo;
|
||||||
|
protected $_fee;
|
||||||
|
protected $_title;
|
||||||
|
protected $_body;
|
||||||
|
protected $_callback;
|
||||||
|
protected $_url;
|
||||||
|
protected $_uid;
|
||||||
|
protected $_bank;
|
||||||
|
protected $_param;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置订单号
|
||||||
|
* @param type $order_no
|
||||||
|
* @return \Think\Pay\PayVo
|
||||||
|
*/
|
||||||
|
public function setOrderNo($order_no) {
|
||||||
|
$this->_orderNo = $order_no;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置商品价格
|
||||||
|
* @param type $fee
|
||||||
|
* @return \Think\Pay\PayVo
|
||||||
|
*/
|
||||||
|
public function setFee($fee) {
|
||||||
|
$this->_fee = $fee;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置商品名称
|
||||||
|
* @param type $title
|
||||||
|
* @return \Think\Pay\PayVo
|
||||||
|
*/
|
||||||
|
public function setTitle($title) {
|
||||||
|
$this->_title = $title;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置商品描述
|
||||||
|
* @param type $body
|
||||||
|
* @return \Think\Pay\PayVo
|
||||||
|
*/
|
||||||
|
public function setBody($body) {
|
||||||
|
$this->_body = $body;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置支付完成后的后续操作接口
|
||||||
|
* @param type $callback
|
||||||
|
* @return \Think\Pay\PayVo
|
||||||
|
*/
|
||||||
|
public function setCallback($callback) {
|
||||||
|
$this->_callback = $callback;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置支付完成后的跳转地址
|
||||||
|
* @param type $url
|
||||||
|
* @return \Think\Pay\PayVo
|
||||||
|
*/
|
||||||
|
public function setUrl($url) {
|
||||||
|
$this->_url = $url;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置订单的额外参数
|
||||||
|
* @param type $param
|
||||||
|
* @return \Think\Pay\PayVo
|
||||||
|
*/
|
||||||
|
public function setParam($param) {
|
||||||
|
$this->_param = $param;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置订单的用户ID
|
||||||
|
* @param type $param
|
||||||
|
* @return \Think\Pay\PayVo
|
||||||
|
*/
|
||||||
|
public function setUid($uid) {
|
||||||
|
$this->_uid = $uid;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBank($bank){
|
||||||
|
$this->_bank = $bank;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取订单号
|
||||||
|
* @return type
|
||||||
|
*/
|
||||||
|
public function getOrderNo() {
|
||||||
|
return $this->_orderNo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取商品价格
|
||||||
|
* @return type
|
||||||
|
*/
|
||||||
|
public function getFee() {
|
||||||
|
return $this->_fee;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取商品名称
|
||||||
|
* @return type
|
||||||
|
*/
|
||||||
|
public function getTitle() {
|
||||||
|
return $this->_title;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取支付完成后的后续操作接口
|
||||||
|
* @return type
|
||||||
|
*/
|
||||||
|
public function getCallback() {
|
||||||
|
return $this->_callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取支付完成后的跳转地址
|
||||||
|
* @return type
|
||||||
|
*/
|
||||||
|
public function getUrl() {
|
||||||
|
return $this->_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取商品描述
|
||||||
|
* @return type
|
||||||
|
*/
|
||||||
|
public function getBody() {
|
||||||
|
return $this->_body;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取订单的额外参数
|
||||||
|
* @return type
|
||||||
|
*/
|
||||||
|
public function getParam() {
|
||||||
|
return $this->_param;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户UID
|
||||||
|
* @return type
|
||||||
|
*/
|
||||||
|
public function getUid() {
|
||||||
|
return $this->_uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBank(){
|
||||||
|
return $this->_bank;
|
||||||
|
}
|
||||||
|
}
|
||||||
260
core/extend/com/pay/Pay.php
Normal file
@@ -0,0 +1,260 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace com\pay;
|
||||||
|
|
||||||
|
abstract class Pay extends \think\Controller{
|
||||||
|
|
||||||
|
protected $config;
|
||||||
|
protected $info;
|
||||||
|
|
||||||
|
public function __construct($config) {
|
||||||
|
parent::__construct();
|
||||||
|
$this->config = array_merge($this->config, $config);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置检查
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function check() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证通过后获取订单信息
|
||||||
|
* @return type
|
||||||
|
*/
|
||||||
|
public function getInfo() {
|
||||||
|
return $this->info;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成订单号
|
||||||
|
* 可根据自身的业务需求更改
|
||||||
|
*/
|
||||||
|
public function createOrderNo() {
|
||||||
|
$year_code = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
|
||||||
|
return $year_code[intval(date('Y')) - 2010] .
|
||||||
|
strtoupper(dechex(date('m'))) . date('d') .
|
||||||
|
substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('d', rand(0, 99));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 建立提交表单
|
||||||
|
*/
|
||||||
|
abstract public function pay(\com\pay\Input $input);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造表单
|
||||||
|
*/
|
||||||
|
protected function _buildForm($params, $gateway,$is_submit=true, $method = 'post') {
|
||||||
|
$sHtml = "<meta http-equiv='content-type' content='text/html; charset=utf-8'><form id='paysubmit' name='paysubmit' action='{$gateway}' method='{$method}' target='_blank'>";
|
||||||
|
foreach ($params as $k => $v) {
|
||||||
|
$sHtml.= "<input type=\"hidden\" name=\"{$k}\" value=\"{$v}\" />\n";
|
||||||
|
}
|
||||||
|
$sHtml = $sHtml . "</form>";
|
||||||
|
|
||||||
|
$data = array(
|
||||||
|
'sHtml' => $sHtml,
|
||||||
|
'is_submit' => $is_submit,
|
||||||
|
'params' => $params,
|
||||||
|
);
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付通知验证
|
||||||
|
*/
|
||||||
|
abstract public function verifyNotify($notify);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 异步通知验证成功返回信息
|
||||||
|
*/
|
||||||
|
public function notifySuccess() {
|
||||||
|
echo "success";
|
||||||
|
}
|
||||||
|
|
||||||
|
final protected function fsockOpen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE', $allowcurl = TRUE, $position = 0, $files = array()) {
|
||||||
|
$return = '';
|
||||||
|
$matches = parse_url($url);
|
||||||
|
$scheme = $matches['scheme'];
|
||||||
|
$host = $matches['host'];
|
||||||
|
$path = $matches['path'] ? $matches['path'] . ($matches['query'] ? '?' . $matches['query'] : '') : '/';
|
||||||
|
$port = !empty($matches['port']) ? $matches['port'] : ($scheme == 'http' ? '80' : '');
|
||||||
|
$boundary = $encodetype == 'URLENCODE' ? '' : random(40);
|
||||||
|
|
||||||
|
if ($post) {
|
||||||
|
if (!is_array($post)) {
|
||||||
|
parse_str($post, $post);
|
||||||
|
}
|
||||||
|
$this->formatPostkey($post, $postnew);
|
||||||
|
$post = $postnew;
|
||||||
|
}
|
||||||
|
if (function_exists('curl_init') && function_exists('curl_exec') && $allowcurl) {
|
||||||
|
$ch = curl_init();
|
||||||
|
$httpheader = array();
|
||||||
|
if ($ip) {
|
||||||
|
$httpheader[] = "Host: " . $host;
|
||||||
|
}
|
||||||
|
if ($httpheader) {
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
|
||||||
|
}
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $scheme . '://' . ($ip ? $ip : $host) . ($port ? ':' . $port : '') . $path);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||||
|
curl_setopt($ch, CURLOPT_HEADER, 1);
|
||||||
|
if ($post) {
|
||||||
|
curl_setopt($ch, CURLOPT_POST, 1);
|
||||||
|
if ($encodetype == 'URLENCODE') {
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
|
||||||
|
} else {
|
||||||
|
foreach ($post as $k => $v) {
|
||||||
|
if (isset($files[$k])) {
|
||||||
|
$post[$k] = '@' . $files[$k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($files as $k => $file) {
|
||||||
|
if (!isset($post[$k]) && file_exists($file)) {
|
||||||
|
$post[$k] = '@' . $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($cookie) {
|
||||||
|
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
|
||||||
|
}
|
||||||
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
|
||||||
|
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||||
|
$data = curl_exec($ch);
|
||||||
|
$status = curl_getinfo($ch);
|
||||||
|
$errno = curl_errno($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
if ($errno || $status['http_code'] != 200) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
$GLOBALS['filesockheader'] = substr($data, 0, $status['header_size']);
|
||||||
|
$data = substr($data, $status['header_size']);
|
||||||
|
return !$limit ? $data : substr($data, 0, $limit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($post) {
|
||||||
|
if ($encodetype == 'URLENCODE') {
|
||||||
|
$data = http_build_query($post);
|
||||||
|
} else {
|
||||||
|
$data = '';
|
||||||
|
foreach ($post as $k => $v) {
|
||||||
|
$data .= "--$boundary\r\n";
|
||||||
|
$data .= 'Content-Disposition: form-data; name="' . $k . '"' . (isset($files[$k]) ? '; filename="' . basename($files[$k]) . '"; Content-Type: application/octet-stream' : '') . "\r\n\r\n";
|
||||||
|
$data .= $v . "\r\n";
|
||||||
|
}
|
||||||
|
foreach ($files as $k => $file) {
|
||||||
|
if (!isset($post[$k]) && file_exists($file)) {
|
||||||
|
if ($fp = @fopen($file, 'r')) {
|
||||||
|
$v = fread($fp, filesize($file));
|
||||||
|
fclose($fp);
|
||||||
|
$data .= "--$boundary\r\n";
|
||||||
|
$data .= 'Content-Disposition: form-data; name="' . $k . '"; filename="' . basename($file) . '"; Content-Type: application/octet-stream' . "\r\n\r\n";
|
||||||
|
$data .= $v . "\r\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$data .= "--$boundary\r\n";
|
||||||
|
}
|
||||||
|
$out = "POST $path HTTP/1.0\r\n";
|
||||||
|
$header = "Accept: */*\r\n";
|
||||||
|
$header .= "Accept-Language: zh-cn\r\n";
|
||||||
|
$header .= $encodetype == 'URLENCODE' ? "Content-Type: application/x-www-form-urlencoded\r\n" : "Content-Type: multipart/form-data; boundary=$boundary\r\n";
|
||||||
|
$header .= 'Content-Length: ' . strlen($data) . "\r\n";
|
||||||
|
$header .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
|
||||||
|
$header .= "Host: $host:$port\r\n";
|
||||||
|
$header .= "Connection: Close\r\n";
|
||||||
|
$header .= "Cache-Control: no-cache\r\n";
|
||||||
|
$header .= "Cookie: $cookie\r\n\r\n";
|
||||||
|
$out .= $header;
|
||||||
|
$out .= $data;
|
||||||
|
} else {
|
||||||
|
$out = "GET $path HTTP/1.0\r\n";
|
||||||
|
$header = "Accept: */*\r\n";
|
||||||
|
$header .= "Accept-Language: zh-cn\r\n";
|
||||||
|
$header .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
|
||||||
|
$header .= "Host: $host:$port\r\n";
|
||||||
|
$header .= "Connection: Close\r\n";
|
||||||
|
$header .= "Cookie: $cookie\r\n\r\n";
|
||||||
|
$out .= $header;
|
||||||
|
}
|
||||||
|
|
||||||
|
$fpflag = 0;
|
||||||
|
if (!$fp = @fsocketopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout)) {
|
||||||
|
$context = array(
|
||||||
|
'http' => array(
|
||||||
|
'method' => $post ? 'POST' : 'GET',
|
||||||
|
'header' => $header,
|
||||||
|
'content' => $post,
|
||||||
|
'timeout' => $timeout,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$context = stream_context_create($context);
|
||||||
|
$fp = @fopen($scheme . '://' . ($ip ? $ip : $host) . ':' . $port . $path, 'b', false, $context);
|
||||||
|
$fpflag = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$fp) {
|
||||||
|
return '';
|
||||||
|
} else {
|
||||||
|
stream_set_blocking($fp, $block);
|
||||||
|
stream_set_timeout($fp, $timeout);
|
||||||
|
@fwrite($fp, $out);
|
||||||
|
$status = stream_get_meta_data($fp);
|
||||||
|
if (!$status['timed_out']) {
|
||||||
|
while (!feof($fp) && !$fpflag) {
|
||||||
|
$header = @fgets($fp);
|
||||||
|
$headers .= $header;
|
||||||
|
if ($header && ($header == "\r\n" || $header == "\n")) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$GLOBALS['filesockheader'] = $headers;
|
||||||
|
|
||||||
|
if ($position) {
|
||||||
|
for ($i = 0; $i < $position; $i++) {
|
||||||
|
$char = fgetc($fp);
|
||||||
|
if ($char == "\n" && $oldchar != "\r") {
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
$oldchar = $char;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($limit) {
|
||||||
|
$return = stream_get_contents($fp, $limit);
|
||||||
|
} else {
|
||||||
|
$return = stream_get_contents($fp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@fclose($fp);
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final protected function formatPostkey($post, &$result, $key = '') {
|
||||||
|
foreach ($post as $k => $v) {
|
||||||
|
$_k = $key ? $key . '[' . $k . ']' : $k;
|
||||||
|
if (is_array($v)) {
|
||||||
|
$this->formatPostkey($v, $result, $_k);
|
||||||
|
} else {
|
||||||
|
$result[$_k] = $v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
140
core/extend/com/pay/driver/Alipay.php
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace com\pay\driver;
|
||||||
|
|
||||||
|
class Alipay extends \com\pay\Pay {
|
||||||
|
|
||||||
|
protected $gateway = 'https://mapi.alipay.com/gateway.do';
|
||||||
|
protected $verify_url = 'http://notify.alipay.com/trade/notify_query.do';
|
||||||
|
protected $config = array(
|
||||||
|
'email' => '',
|
||||||
|
'key' => '',
|
||||||
|
'partner' => '',
|
||||||
|
);
|
||||||
|
|
||||||
|
public function check() {
|
||||||
|
if (!$this->config['email'] || !$this->config['key'] || !$this->config['partner']) {
|
||||||
|
E("支付宝账号未开通!");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function pay(\com\pay\Input $input) {
|
||||||
|
$param = array(
|
||||||
|
'service' => 'create_direct_pay_by_user',
|
||||||
|
'payment_type' => '1',
|
||||||
|
'_input_charset' => 'utf-8',
|
||||||
|
'seller_email' => $this->config['email'],
|
||||||
|
'partner' => $this->config['partner'],
|
||||||
|
'notify_url' => $this->config['notify_url'],
|
||||||
|
'return_url' => $this->config['return_url'],
|
||||||
|
'out_trade_no' => $input->getOrderNo(),
|
||||||
|
'subject' => $input->getTitle(),
|
||||||
|
'body' => $input->getBody(),
|
||||||
|
'total_fee' => $input->getFee()
|
||||||
|
);
|
||||||
|
|
||||||
|
ksort($param);
|
||||||
|
reset($param);
|
||||||
|
|
||||||
|
$arg = '';
|
||||||
|
foreach ($param as $key => $value) {
|
||||||
|
if ($value) {
|
||||||
|
$arg .= "$key=$value&";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//echo substr($arg, 0, -1) . $this->config['key'];exit();
|
||||||
|
$param['sign'] = md5(substr($arg, 0, -1) . $this->config['key']);
|
||||||
|
$param['sign_type'] = 'MD5';
|
||||||
|
|
||||||
|
$sHtml = $this->_buildForm($param, $this->gateway,true, 'get');
|
||||||
|
|
||||||
|
return $sHtml;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取返回时的签名验证结果
|
||||||
|
* @param $para_temp 通知返回来的参数数组
|
||||||
|
* @param $sign 返回的签名结果
|
||||||
|
* @return 签名验证结果
|
||||||
|
*/
|
||||||
|
protected function getSignVeryfy($param, $sign) {
|
||||||
|
//除去待签名参数数组中的空值和签名参数
|
||||||
|
$param_filter = array();
|
||||||
|
while (list ($key, $val) = each($param)) {
|
||||||
|
if ($key == "sign" || $key == "sign_type" || $val == "") {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
$param_filter[$key] = $param[$key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ksort($param_filter);
|
||||||
|
reset($param_filter);
|
||||||
|
|
||||||
|
//把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
|
||||||
|
$prestr = "";
|
||||||
|
while (list ($key, $val) = each($param_filter)) {
|
||||||
|
$prestr.=$key . "=" . $val . "&";
|
||||||
|
}
|
||||||
|
//去掉最后一个&字符
|
||||||
|
$prestr = substr($prestr, 0, -1);
|
||||||
|
|
||||||
|
$prestr = $prestr . $this->config['key'];
|
||||||
|
$mysgin = md5($prestr);
|
||||||
|
|
||||||
|
if ($mysgin == $sign) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 针对notify_url验证消息是否是支付宝发出的合法消息
|
||||||
|
* @return 验证结果
|
||||||
|
*/
|
||||||
|
public function verifyNotify($notify) {
|
||||||
|
|
||||||
|
//生成签名结果
|
||||||
|
$isSign = $this->getSignVeryfy($notify, $notify["sign"]);
|
||||||
|
//获取支付宝远程服务器ATN结果(验证是否是支付宝发来的消息)
|
||||||
|
$responseTxt = 'true';
|
||||||
|
if (!empty($notify["notify_id"])) {
|
||||||
|
$responseTxt = $this->getResponse($notify["notify_id"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preg_match("/true$/i", $responseTxt) && $isSign) {
|
||||||
|
$this->setInfo($notify);
|
||||||
|
return $this->info;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setInfo($notify) {
|
||||||
|
$info = array();
|
||||||
|
//支付状态
|
||||||
|
$info['status'] = ($notify['trade_status'] == 'TRADE_FINISHED' || $notify['trade_status'] == 'TRADE_SUCCESS') ? true : false;
|
||||||
|
$info['total_fee'] = $notify['total_fee'];
|
||||||
|
$info['out_trade_no'] = $notify['out_trade_no'];
|
||||||
|
$this->info = $info;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取远程服务器ATN结果,验证返回URL
|
||||||
|
* @param $notify_id 通知校验ID
|
||||||
|
* @return 服务器ATN结果
|
||||||
|
* 验证结果集:
|
||||||
|
* invalid命令参数不对 出现这个错误,请检测返回处理中partner和key是否为空
|
||||||
|
* true 返回正确信息
|
||||||
|
* false 请检查防火墙或者是服务器阻止端口问题以及验证时间是否超过一分钟
|
||||||
|
*/
|
||||||
|
protected function getResponse($notify_id) {
|
||||||
|
$partner = $this->config['partner'];
|
||||||
|
$veryfy_url = $this->verify_url . "?partner=" . $partner . "¬ify_id=" . $notify_id;
|
||||||
|
$responseTxt = $this->fsockOpen($veryfy_url);
|
||||||
|
return $responseTxt;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
@@ -12,6 +12,7 @@
|
|||||||
namespace think;
|
namespace think;
|
||||||
|
|
||||||
use think\Config;
|
use think\Config;
|
||||||
|
use think\debug\Trace;
|
||||||
use think\Exception;
|
use think\Exception;
|
||||||
use think\exception\HttpException;
|
use think\exception\HttpException;
|
||||||
use think\exception\HttpResponseException;
|
use think\exception\HttpResponseException;
|
||||||
@@ -70,7 +71,7 @@ class App
|
|||||||
* 执行应用程序
|
* 执行应用程序
|
||||||
* @access public
|
* @access public
|
||||||
* @param Request $request Request对象
|
* @param Request $request Request对象
|
||||||
* @return mixed
|
* @return Response
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static function run(Request $request = null)
|
public static function run(Request $request = null)
|
||||||
@@ -136,22 +137,29 @@ class App
|
|||||||
$data = $exception->getResponse();
|
$data = $exception->getResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 监听app_end
|
|
||||||
Hook::listen('app_end', $data);
|
|
||||||
// 清空类的实例化
|
// 清空类的实例化
|
||||||
Loader::clearInstance();
|
Loader::clearInstance();
|
||||||
|
|
||||||
// 输出数据到客户端
|
// 输出数据到客户端
|
||||||
if ($data instanceof Response) {
|
if ($data instanceof Response) {
|
||||||
return $data;
|
$response = $data;
|
||||||
} elseif (!is_null($data)) {
|
} elseif (!is_null($data)) {
|
||||||
// 默认自动识别响应输出类型
|
// 默认自动识别响应输出类型
|
||||||
$isAjax = $request->isAjax();
|
$isAjax = $request->isAjax();
|
||||||
$type = $isAjax ? Config::get('default_ajax_return') : Config::get('default_return_type');
|
$type = $isAjax ? Config::get('default_ajax_return') : Config::get('default_return_type');
|
||||||
return Response::create($data, $type);
|
$response = Response::create($data, $type);
|
||||||
} else {
|
} else {
|
||||||
return Response::create();
|
$response = Response::create();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 监听app_end
|
||||||
|
Hook::listen('app_end', $response);
|
||||||
|
|
||||||
|
//注入Trace
|
||||||
|
self::$debug && Trace::inject($response);
|
||||||
|
|
||||||
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -349,6 +357,15 @@ class App
|
|||||||
self::$debug = Config::get('app_debug');
|
self::$debug = Config::get('app_debug');
|
||||||
if (!self::$debug) {
|
if (!self::$debug) {
|
||||||
ini_set('display_errors', 'Off');
|
ini_set('display_errors', 'Off');
|
||||||
|
} else {
|
||||||
|
//重新申请一块比较大的buffer
|
||||||
|
if (ob_get_level() > 0) {
|
||||||
|
$output = ob_get_clean();
|
||||||
|
}
|
||||||
|
ob_start();
|
||||||
|
if (!empty($output)) {
|
||||||
|
echo $output;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 应用命名空间
|
// 应用命名空间
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ class Config
|
|||||||
|
|
||||||
if (!strpos($name, '.')) {
|
if (!strpos($name, '.')) {
|
||||||
// 判断环境变量
|
// 判断环境变量
|
||||||
$result = getenv(ENV_PREFIX . $name);
|
$result = getenv(ENV_PREFIX . strtoupper($name));
|
||||||
if (false !== $result) {
|
if (false !== $result) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,7 @@ class Config
|
|||||||
} else {
|
} else {
|
||||||
// 二维数组设置和获取支持
|
// 二维数组设置和获取支持
|
||||||
$name = explode('.', $name);
|
$name = explode('.', $name);
|
||||||
$result = getenv(ENV_PREFIX . $name[0] . '_' . $name[1]);
|
$result = getenv(ENV_PREFIX . strtoupper($name[0] . '_' . $name[1]));
|
||||||
// 判断环境变量
|
// 判断环境变量
|
||||||
if (false !== $result) {
|
if (false !== $result) {
|
||||||
return $result;
|
return $result;
|
||||||
@@ -113,7 +113,7 @@ class Config
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!strpos($name, '.')) {
|
if (!strpos($name, '.')) {
|
||||||
$result = getenv(ENV_PREFIX . $name);
|
$result = getenv(ENV_PREFIX . strtoupper($name));
|
||||||
if (false !== $result) {
|
if (false !== $result) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
@@ -122,7 +122,7 @@ class Config
|
|||||||
} else {
|
} else {
|
||||||
// 二维数组设置和获取支持
|
// 二维数组设置和获取支持
|
||||||
$name = explode('.', $name);
|
$name = explode('.', $name);
|
||||||
$result = getenv(ENV_PREFIX . $name[0] . '_' . $name[1]);
|
$result = getenv(ENV_PREFIX . strtoupper($name[0] . '_' . $name[1]));
|
||||||
// 判断环境变量
|
// 判断环境变量
|
||||||
if (false !== $result) {
|
if (false !== $result) {
|
||||||
return $result;
|
return $result;
|
||||||
|
|||||||
@@ -43,9 +43,8 @@ class Hook
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量导入插件
|
* 批量导入插件
|
||||||
* @param array $data 插件信息
|
* @param array $tags 插件信息
|
||||||
* @param boolean $recursive 是否递归合并
|
* @param boolean $recursive 是否递归合并
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public static function import($tags, $recursive = true)
|
public static function import($tags, $recursive = true)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ class Loader
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
includeFile($file);
|
__include_file($file);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -142,35 +142,88 @@ class Loader
|
|||||||
{
|
{
|
||||||
if (is_array($namespace)) {
|
if (is_array($namespace)) {
|
||||||
foreach ($namespace as $prefix => $paths) {
|
foreach ($namespace as $prefix => $paths) {
|
||||||
self::setPsr4($prefix . '\\', rtrim($paths, DS));
|
self::addPsr4($prefix . '\\', rtrim($paths, DS), true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self::setPsr4($namespace . '\\', rtrim($path, DS));
|
self::addPsr4($namespace . '\\', rtrim($path, DS), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注册Psr0空间
|
// 添加Ps0空间
|
||||||
private static function setPsr0($prefix, $paths)
|
private static function addPsr0($prefix, $paths, $prepend = false)
|
||||||
{
|
{
|
||||||
if (!$prefix) {
|
if (!$prefix) {
|
||||||
self::$fallbackDirsPsr0 = (array)$paths;
|
if ($prepend) {
|
||||||
|
self::$fallbackDirsPsr0 = array_merge(
|
||||||
|
(array)$paths,
|
||||||
|
self::$fallbackDirsPsr0
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
self::$fallbackDirsPsr0 = array_merge(
|
||||||
|
self::$fallbackDirsPsr0,
|
||||||
|
(array)$paths
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$first = $prefix[0];
|
||||||
|
if (!isset(self::$prefixesPsr0[$first][$prefix])) {
|
||||||
|
self::$prefixesPsr0[$first][$prefix] = (array)$paths;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($prepend) {
|
||||||
|
self::$prefixesPsr0[$first][$prefix] = array_merge(
|
||||||
|
(array)$paths,
|
||||||
|
self::$prefixesPsr0[$first][$prefix]
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
self::$prefixesPsr0[$prefix[0]][$prefix] = (array)$paths;
|
self::$prefixesPsr0[$first][$prefix] = array_merge(
|
||||||
|
self::$prefixesPsr0[$first][$prefix],
|
||||||
|
(array)$paths
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注册Psr4空间
|
|
||||||
private static function setPsr4($prefix, $paths)
|
// 添加Psr4空间
|
||||||
|
private static function addPsr4($prefix, $paths, $prepend = false)
|
||||||
{
|
{
|
||||||
if (!$prefix) {
|
if (!$prefix) {
|
||||||
self::$fallbackDirsPsr4 = (array)$paths;
|
// Register directories for the root namespace.
|
||||||
} else {
|
if ($prepend) {
|
||||||
|
self::$fallbackDirsPsr4 = array_merge(
|
||||||
|
(array)$paths,
|
||||||
|
self::$fallbackDirsPsr4
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
self::$fallbackDirsPsr4 = array_merge(
|
||||||
|
self::$fallbackDirsPsr4,
|
||||||
|
(array)$paths
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} elseif (!isset(self::$prefixDirsPsr4[$prefix])) {
|
||||||
|
// Register directories for a new namespace.
|
||||||
$length = strlen($prefix);
|
$length = strlen($prefix);
|
||||||
if ('\\' !== $prefix[$length - 1]) {
|
if ('\\' !== $prefix[$length - 1]) {
|
||||||
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
|
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
|
||||||
}
|
}
|
||||||
self::$prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
|
self::$prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
|
||||||
self::$prefixDirsPsr4[$prefix] = (array)$paths;
|
self::$prefixDirsPsr4[$prefix] = (array)$paths;
|
||||||
|
} elseif ($prepend) {
|
||||||
|
// Prepend directories for an already registered namespace.
|
||||||
|
self::$prefixDirsPsr4[$prefix] = array_merge(
|
||||||
|
(array)$paths,
|
||||||
|
self::$prefixDirsPsr4[$prefix]
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Append directories for an already registered namespace.
|
||||||
|
self::$prefixDirsPsr4[$prefix] = array_merge(
|
||||||
|
self::$prefixDirsPsr4[$prefix],
|
||||||
|
(array)$paths
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,7 +250,9 @@ class Loader
|
|||||||
'traits' => LIB_PATH . 'traits' . DS,
|
'traits' => LIB_PATH . 'traits' . DS,
|
||||||
]);
|
]);
|
||||||
// 加载类库映射文件
|
// 加载类库映射文件
|
||||||
self::addClassMap(includeFile(THINK_PATH . 'classmap' . EXT));
|
if (is_file(RUNTIME_PATH . 'classmap' . EXT)) {
|
||||||
|
self::addClassMap(__include_file(RUNTIME_PATH . 'classmap' . EXT));
|
||||||
|
}
|
||||||
|
|
||||||
// Composer自动加载支持
|
// Composer自动加载支持
|
||||||
if (is_dir(VENDOR_PATH . 'composer')) {
|
if (is_dir(VENDOR_PATH . 'composer')) {
|
||||||
@@ -214,14 +269,14 @@ class Loader
|
|||||||
if (is_file(VENDOR_PATH . 'composer/autoload_namespaces.php')) {
|
if (is_file(VENDOR_PATH . 'composer/autoload_namespaces.php')) {
|
||||||
$map = require VENDOR_PATH . 'composer/autoload_namespaces.php';
|
$map = require VENDOR_PATH . 'composer/autoload_namespaces.php';
|
||||||
foreach ($map as $namespace => $path) {
|
foreach ($map as $namespace => $path) {
|
||||||
self::setPsr0($namespace, $path);
|
self::addPsr0($namespace, $path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_file(VENDOR_PATH . 'composer/autoload_psr4.php')) {
|
if (is_file(VENDOR_PATH . 'composer/autoload_psr4.php')) {
|
||||||
$map = require VENDOR_PATH . 'composer/autoload_psr4.php';
|
$map = require VENDOR_PATH . 'composer/autoload_psr4.php';
|
||||||
foreach ($map as $namespace => $path) {
|
foreach ($map as $namespace => $path) {
|
||||||
self::setPsr4($namespace, $path);
|
self::addPsr4($namespace, $path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,7 +291,7 @@ class Loader
|
|||||||
$includeFiles = require VENDOR_PATH . 'composer/autoload_files.php';
|
$includeFiles = require VENDOR_PATH . 'composer/autoload_files.php';
|
||||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||||
if (empty(self::$autoloadFiles[$fileIdentifier])) {
|
if (empty(self::$autoloadFiles[$fileIdentifier])) {
|
||||||
requireFile($file);
|
__require_file($file);
|
||||||
self::$autoloadFiles[$fileIdentifier] = true;
|
self::$autoloadFiles[$fileIdentifier] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -253,16 +308,18 @@ class Loader
|
|||||||
public static function import($class, $baseUrl = '', $ext = EXT)
|
public static function import($class, $baseUrl = '', $ext = EXT)
|
||||||
{
|
{
|
||||||
static $_file = [];
|
static $_file = [];
|
||||||
|
$key = $class . $baseUrl;
|
||||||
$class = str_replace(['.', '#'], [DS, '.'], $class);
|
$class = str_replace(['.', '#'], [DS, '.'], $class);
|
||||||
if (isset($_file[$class . $baseUrl])) {
|
if (isset($_file[$key])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($baseUrl)) {
|
if (empty($baseUrl)) {
|
||||||
list($name, $class) = explode(DS, $class, 2);
|
list($name, $class) = explode(DS, $class, 2);
|
||||||
if (isset(self::$prefixDirsPsr4[$name])) {
|
|
||||||
|
if (isset(self::$prefixDirsPsr4[$name . '\\'])) {
|
||||||
// 注册的命名空间
|
// 注册的命名空间
|
||||||
$baseUrl = self::$prefixDirsPsr4[$name];
|
$baseUrl = self::$prefixDirsPsr4[$name . '\\'];
|
||||||
} elseif ('@' == $name) {
|
} elseif ('@' == $name) {
|
||||||
//加载当前模块应用类库
|
//加载当前模块应用类库
|
||||||
$baseUrl = App::$modulePath;
|
$baseUrl = App::$modulePath;
|
||||||
@@ -292,8 +349,8 @@ class Loader
|
|||||||
if (IS_WIN && pathinfo($filename, PATHINFO_FILENAME) != pathinfo(realpath($filename), PATHINFO_FILENAME)) {
|
if (IS_WIN && pathinfo($filename, PATHINFO_FILENAME) != pathinfo(realpath($filename), PATHINFO_FILENAME)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
includeFile($filename);
|
__include_file($filename);
|
||||||
$_file[$class . $baseUrl] = true;
|
$_file[$key] = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -483,12 +540,12 @@ class Loader
|
|||||||
* @param $file
|
* @param $file
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function includeFile($file)
|
function __include_file($file)
|
||||||
{
|
{
|
||||||
return include $file;
|
return include $file;
|
||||||
}
|
}
|
||||||
|
|
||||||
function requireFile($file)
|
function __require_file($file)
|
||||||
{
|
{
|
||||||
return require $file;
|
return require $file;
|
||||||
}
|
}
|
||||||
@@ -10,9 +10,19 @@
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
namespace think;
|
namespace think;
|
||||||
|
use think\exception\ClassNotFoundException;
|
||||||
|
|
||||||
use think\App;
|
/**
|
||||||
|
* Class Log
|
||||||
|
* @package think
|
||||||
|
*
|
||||||
|
* @method void log($msg) static
|
||||||
|
* @method void error($msg) static
|
||||||
|
* @method void info($msg) static
|
||||||
|
* @method void sql($msg) static
|
||||||
|
* @method void notice($msg) static
|
||||||
|
* @method void alert($msg) static
|
||||||
|
*/
|
||||||
class Log
|
class Log
|
||||||
{
|
{
|
||||||
const LOG = 'log';
|
const LOG = 'log';
|
||||||
@@ -30,40 +40,29 @@ class Log
|
|||||||
protected static $type = ['log', 'error', 'info', 'sql', 'notice', 'alert'];
|
protected static $type = ['log', 'error', 'info', 'sql', 'notice', 'alert'];
|
||||||
// 日志写入驱动
|
// 日志写入驱动
|
||||||
protected static $driver;
|
protected static $driver;
|
||||||
// 通知发送驱动
|
|
||||||
protected static $alarm;
|
|
||||||
// 当前日志授权key
|
// 当前日志授权key
|
||||||
protected static $key;
|
protected static $key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 日志初始化
|
* 日志初始化
|
||||||
* @return void
|
* @param array $config
|
||||||
*/
|
*/
|
||||||
public static function init($config = [])
|
public static function init($config = [])
|
||||||
{
|
{
|
||||||
$type = isset($config['type']) ? $config['type'] : 'File';
|
$type = isset($config['type']) ? $config['type'] : 'File';
|
||||||
$class = false !== strpos($type, '\\') ? $type : '\\think\\log\\driver\\' . ucwords($type);
|
$class = false !== strpos($type, '\\') ? $type : '\\think\\log\\driver\\' . ucwords($type);
|
||||||
self::$config = $config;
|
self::$config = $config;
|
||||||
unset($config['type']);
|
unset($config['type']);
|
||||||
self::$driver = new $class($config);
|
if(class_exists($class)) {
|
||||||
|
self::$driver = new $class($config);
|
||||||
|
} else {
|
||||||
|
throw new ClassNotFoundException('class not exists:' . $class, $class);
|
||||||
|
}
|
||||||
// 记录初始化信息
|
// 记录初始化信息
|
||||||
App::$debug && Log::record('[ LOG ] INIT ' . $type . ': ' . var_export($config, true), 'info');
|
App::$debug && Log::record('[ LOG ] INIT ' . $type . ': ' . var_export($config, true), 'info');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 通知初始化
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function alarm($config = [])
|
|
||||||
{
|
|
||||||
$type = isset($config['type']) ? $config['type'] : 'Email';
|
|
||||||
$class = false !== strpos($type, '\\') ? $type : '\\think\\log\\alarm\\' . ucwords($type);
|
|
||||||
unset($config['type']);
|
|
||||||
self::$alarm = new $class($config['alarm']);
|
|
||||||
// 记录初始化信息
|
|
||||||
App::$debug && Log::record('[ CACHE ] ALARM ' . $type . ': ' . var_export($config, true), 'info');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取日志信息
|
* 获取日志信息
|
||||||
* @param string $type 信息类型
|
* @param string $type 信息类型
|
||||||
@@ -164,19 +163,11 @@ class Log
|
|||||||
return self::$driver->save($log);
|
return self::$driver->save($log);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送预警通知
|
|
||||||
* @param mixed $msg 调试信息
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function send($msg)
|
|
||||||
{
|
|
||||||
self::$alarm && self::$alarm->send($msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 静态调用
|
* 静态调用
|
||||||
* @return void
|
* @param $method
|
||||||
|
* @param $args
|
||||||
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function __callStatic($method, $args)
|
public static function __callStatic($method, $args)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ class Request
|
|||||||
{
|
{
|
||||||
if (array_key_exists($method, self::$hook)) {
|
if (array_key_exists($method, self::$hook)) {
|
||||||
array_unshift($args, $this);
|
array_unshift($args, $this);
|
||||||
call_user_func_array(self::$hook[$method], $args);
|
return call_user_func_array(self::$hook[$method], $args);
|
||||||
} else {
|
} else {
|
||||||
throw new Exception('method not exists:' . __CLASS__ . '->' . $method);
|
throw new Exception('method not exists:' . __CLASS__ . '->' . $method);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,9 +93,6 @@ class Response
|
|||||||
// 处理输出数据
|
// 处理输出数据
|
||||||
$data = $this->getContent();
|
$data = $this->getContent();
|
||||||
|
|
||||||
// 监听response_data
|
|
||||||
Hook::listen('response_data', $data, $this);
|
|
||||||
|
|
||||||
if (!headers_sent() && !empty($this->header)) {
|
if (!headers_sent() && !empty($this->header)) {
|
||||||
// 发送状态码
|
// 发送状态码
|
||||||
http_response_code($this->code);
|
http_response_code($this->code);
|
||||||
@@ -165,6 +162,26 @@ class Response
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置页面输出内容
|
||||||
|
* @param $content
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function content($content)
|
||||||
|
{
|
||||||
|
if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable([
|
||||||
|
$content,
|
||||||
|
'__toString',
|
||||||
|
])
|
||||||
|
) {
|
||||||
|
throw new \InvalidArgumentException(sprintf('variable type error: %s', gettype($content)));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->content = (string)$content;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送HTTP状态
|
* 发送HTTP状态
|
||||||
* @param integer $code 状态码
|
* @param integer $code 状态码
|
||||||
@@ -231,7 +248,7 @@ class Response
|
|||||||
$this->header['Content-Type'] = $contentType . '; charset=' . $charset;
|
$this->header['Content-Type'] = $contentType . '; charset=' . $charset;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取头部信息
|
* 获取头部信息
|
||||||
* @param string $name 头部名称
|
* @param string $name 头部名称
|
||||||
@@ -257,17 +274,20 @@ class Response
|
|||||||
*/
|
*/
|
||||||
public function getContent()
|
public function getContent()
|
||||||
{
|
{
|
||||||
$content = $this->output($this->data);
|
if ($this->content == null) {
|
||||||
|
$content = $this->output($this->data);
|
||||||
|
|
||||||
if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable([
|
if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable([
|
||||||
$content,
|
$content,
|
||||||
'__toString',
|
'__toString',
|
||||||
])
|
])
|
||||||
) {
|
) {
|
||||||
throw new \InvalidArgumentException(sprintf('variable type error: %s', gettype($content)));
|
throw new \InvalidArgumentException(sprintf('variable type error: %s', gettype($content)));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->content = (string)$content;
|
||||||
}
|
}
|
||||||
|
return $this->content;
|
||||||
return (string) $content;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -776,8 +776,13 @@ class Query
|
|||||||
$fields[] = $alias . '.' . $val;
|
$fields[] = $alias . '.' . $val;
|
||||||
$this->options['map'][$val] = $alias . '.' . $val;
|
$this->options['map'][$val] = $alias . '.' . $val;
|
||||||
} else {
|
} else {
|
||||||
$fields[] = $alias . '.' . $key . ' AS ' . $val;
|
if (preg_match('/[,=\.\'\"\(\s]/', $key)) {
|
||||||
$this->options['map'][$val] = $alias . '.' . $key;
|
$name = $key;
|
||||||
|
} else {
|
||||||
|
$name = $alias . '.' . $key;
|
||||||
|
}
|
||||||
|
$fields[] = $name . ' AS ' . $val;
|
||||||
|
$this->options['map'][$val] = $name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1661,6 +1666,7 @@ class Query
|
|||||||
// 如果存在主键数据 则自动作为更新条件
|
// 如果存在主键数据 则自动作为更新条件
|
||||||
if (is_string($pk) && isset($data[$pk])) {
|
if (is_string($pk) && isset($data[$pk])) {
|
||||||
$where[$pk] = $data[$pk];
|
$where[$pk] = $data[$pk];
|
||||||
|
$key = 'think:' . $options['table'] . '|' . $data[$pk];
|
||||||
unset($data[$pk]);
|
unset($data[$pk]);
|
||||||
} elseif (is_array($pk)) {
|
} elseif (is_array($pk)) {
|
||||||
// 增加复合主键支持
|
// 增加复合主键支持
|
||||||
@@ -1687,6 +1693,11 @@ class Query
|
|||||||
// 获取实际执行的SQL语句
|
// 获取实际执行的SQL语句
|
||||||
return $this->connection->getRealSql($sql, $this->bind);
|
return $this->connection->getRealSql($sql, $this->bind);
|
||||||
} else {
|
} else {
|
||||||
|
// 检测缓存
|
||||||
|
if (isset($key) && Cache::get($key)) {
|
||||||
|
// 删除缓存
|
||||||
|
Cache::rm($key);
|
||||||
|
}
|
||||||
// 执行操作
|
// 执行操作
|
||||||
return '' == $sql ? 0 : $this->execute($sql, $this->getBind());
|
return '' == $sql ? 0 : $this->execute($sql, $this->getBind());
|
||||||
}
|
}
|
||||||
@@ -1808,8 +1819,12 @@ class Query
|
|||||||
$result = false;
|
$result = false;
|
||||||
if (empty($options['fetch_sql']) && !empty($options['cache'])) {
|
if (empty($options['fetch_sql']) && !empty($options['cache'])) {
|
||||||
// 判断查询缓存
|
// 判断查询缓存
|
||||||
$cache = $options['cache'];
|
$cache = $options['cache'];
|
||||||
$key = is_string($cache['key']) ? $cache['key'] : md5(serialize($options));
|
if (true === $cache['key'] && !is_array($data)) {
|
||||||
|
$key = 'think:' . $options['table'] . '|' . $data;
|
||||||
|
} else {
|
||||||
|
$key = is_string($cache['key']) ? $cache['key'] : md5(serialize($options));
|
||||||
|
}
|
||||||
$result = Cache::get($key);
|
$result = Cache::get($key);
|
||||||
}
|
}
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
@@ -1959,6 +1974,10 @@ class Query
|
|||||||
$options = $this->parseExpress();
|
$options = $this->parseExpress();
|
||||||
|
|
||||||
if (!is_null($data) && true !== $data) {
|
if (!is_null($data) && true !== $data) {
|
||||||
|
if (!is_array($data)) {
|
||||||
|
// 缓存标识
|
||||||
|
$key = 'think:' . $options['table'] . '|' . $data;
|
||||||
|
}
|
||||||
// AR模式分析主键条件
|
// AR模式分析主键条件
|
||||||
$this->parsePkWhere($data, $options);
|
$this->parsePkWhere($data, $options);
|
||||||
}
|
}
|
||||||
@@ -1969,10 +1988,17 @@ class Query
|
|||||||
}
|
}
|
||||||
// 生成删除SQL语句
|
// 生成删除SQL语句
|
||||||
$sql = $this->builder()->delete($options);
|
$sql = $this->builder()->delete($options);
|
||||||
|
|
||||||
if ($options['fetch_sql']) {
|
if ($options['fetch_sql']) {
|
||||||
// 获取实际执行的SQL语句
|
// 获取实际执行的SQL语句
|
||||||
return $this->connection->getRealSql($sql, $this->bind);
|
return $this->connection->getRealSql($sql, $this->bind);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检测缓存
|
||||||
|
if (isset($key) && Cache::get($key)) {
|
||||||
|
// 删除缓存
|
||||||
|
Cache::rm($key);
|
||||||
|
}
|
||||||
// 执行操作
|
// 执行操作
|
||||||
return $this->execute($sql, $this->getBind());
|
return $this->execute($sql, $this->getBind());
|
||||||
}
|
}
|
||||||
|
|||||||
63
core/library/think/debug/Trace.php
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: yunwuxin <448901948@qq.com>
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
namespace think\debug;
|
||||||
|
|
||||||
|
use think\Config;
|
||||||
|
use think\exception\ClassNotFoundException;
|
||||||
|
use think\Log;
|
||||||
|
use think\Request;
|
||||||
|
use think\Response;
|
||||||
|
use think\response\Redirect;
|
||||||
|
|
||||||
|
class Trace
|
||||||
|
{
|
||||||
|
public static function inject(Response $response)
|
||||||
|
{
|
||||||
|
$config = Config::get('trace');
|
||||||
|
|
||||||
|
$type = isset($config['type']) ? $config['type'] : 'Html';
|
||||||
|
|
||||||
|
if ($type !== false) {
|
||||||
|
$request = Request::instance();
|
||||||
|
$accept = $request->header('accept');
|
||||||
|
$contentType = $response->getHeader('Content-Type');
|
||||||
|
|
||||||
|
$class = false !== strpos($type, '\\') ? $type : '\\think\\debug\\trace\\' . ucwords($type);
|
||||||
|
unset($config['type']);
|
||||||
|
if(class_exists($class)) {
|
||||||
|
$trace = new $class($config);
|
||||||
|
} else {
|
||||||
|
throw new ClassNotFoundException('class not exists:' . $class, $class);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($response instanceof Redirect) {
|
||||||
|
//TODO 记录
|
||||||
|
} elseif (strpos($accept, 'application/json') === 0 || $request->isAjax()) {
|
||||||
|
//TODO 记录
|
||||||
|
} elseif (!empty($contentType) && strpos($contentType, 'html') === false) {
|
||||||
|
//TODO 记录
|
||||||
|
} else {
|
||||||
|
$output = $trace->output(Log::getLog());
|
||||||
|
|
||||||
|
$content = $response->getContent();
|
||||||
|
|
||||||
|
$pos = strripos($content, '</body>');
|
||||||
|
if (false !== $pos) {
|
||||||
|
$content = substr($content, 0, $pos) . $output . substr($content, $pos);
|
||||||
|
} else {
|
||||||
|
$content = $content . $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
$response->content($content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,18 +9,17 @@
|
|||||||
// | Author: yangweijie <yangweijiester@gmail.com>
|
// | Author: yangweijie <yangweijiester@gmail.com>
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
namespace think\log\driver;
|
namespace think\debug\trace;
|
||||||
|
|
||||||
use think\Cache;
|
use think\Cache;
|
||||||
use think\Config;
|
use think\Config;
|
||||||
use think\Db;
|
use think\Db;
|
||||||
use think\Debug;
|
use think\Debug;
|
||||||
use think\Request;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 浏览器调试输出
|
* 浏览器调试输出
|
||||||
*/
|
*/
|
||||||
class Browser
|
class Console
|
||||||
{
|
{
|
||||||
protected $config = [
|
protected $config = [
|
||||||
'trace_tabs' => ['base' => '基本', 'file' => '文件', 'info' => '流程', 'notice|error' => '错误', 'sql' => 'SQL', 'debug|log' => '调试'],
|
'trace_tabs' => ['base' => '基本', 'file' => '文件', 'info' => '流程', 'notice|error' => '错误', 'sql' => 'SQL', 'debug|log' => '调试'],
|
||||||
@@ -40,21 +39,22 @@ class Browser
|
|||||||
* @param array $log 日志信息
|
* @param array $log 日志信息
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function save(array $log = [])
|
public function output(array $log = [])
|
||||||
{
|
{
|
||||||
if (IS_CLI || IS_API || Request::instance()->isAjax() || (defined('RESPONSE_TYPE') && !in_array(RESPONSE_TYPE, ['html', 'view']))) {
|
|
||||||
// ajax cli api方式下不输出
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// 获取基本信息
|
// 获取基本信息
|
||||||
$runtime = microtime(true) - START_TIME;
|
$runtime = number_format(microtime(true), 8, '.', '') - START_TIME;
|
||||||
$reqs = number_format(1 / number_format($runtime, 8), 2);
|
$reqs = number_format(1 / $runtime, 2);
|
||||||
$runtime = number_format($runtime, 6);
|
|
||||||
$mem = number_format((memory_get_usage() - START_MEM) / 1024, 2);
|
$mem = number_format((memory_get_usage() - START_MEM) / 1024, 2);
|
||||||
|
|
||||||
|
if (isset($_SERVER['HTTP_HOST'])) {
|
||||||
|
$uri = $_SERVER['SERVER_PROTOCOL'] . ' ' . $_SERVER['REQUEST_METHOD'] . ' : ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
||||||
|
} else {
|
||||||
|
$uri = "cmd:" . implode(' ', $_SERVER['argv']);
|
||||||
|
}
|
||||||
|
|
||||||
// 页面Trace信息
|
// 页面Trace信息
|
||||||
$base = [
|
$base = [
|
||||||
'请求信息' => date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']) . ' ' . $_SERVER['SERVER_PROTOCOL'] . ' ' . $_SERVER['REQUEST_METHOD'] . ' : ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
|
'请求信息' => date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']) . ' ' . $uri,
|
||||||
'运行时间' => "{$runtime}s [ 吞吐率:{$reqs}req/s ] 内存消耗:{$mem}kb 文件加载:" . count(get_included_files()),
|
'运行时间' => "{$runtime}s [ 吞吐率:{$reqs}req/s ] 内存消耗:{$mem}kb 文件加载:" . count(get_included_files()),
|
||||||
'查询信息' => Db::$queryTimes . ' queries ' . Db::$executeTimes . ' writes ',
|
'查询信息' => Db::$queryTimes . ' queries ' . Db::$executeTimes . ' writes ',
|
||||||
'缓存信息' => Cache::$readTimes . ' reads,' . Cache::$writeTimes . ' writes',
|
'缓存信息' => Cache::$readTimes . ' reads,' . Cache::$writeTimes . ' writes',
|
||||||
@@ -96,54 +96,53 @@ class Browser
|
|||||||
//输出到控制台
|
//输出到控制台
|
||||||
$lines = '';
|
$lines = '';
|
||||||
foreach ($trace as $type => $msg) {
|
foreach ($trace as $type => $msg) {
|
||||||
$lines .= $this->output($type, $msg);
|
$lines .= $this->console($type, $msg);
|
||||||
}
|
}
|
||||||
$js = <<<JS
|
$js = <<<JS
|
||||||
|
|
||||||
<script>
|
<script type='text/javascript'>
|
||||||
{$lines}
|
{$lines}
|
||||||
</script>
|
</script>
|
||||||
JS;
|
JS;
|
||||||
echo $js;
|
return $js;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function output($type, $msg)
|
protected function console($type, $msg)
|
||||||
{
|
{
|
||||||
$type = strtolower($type);
|
$type = strtolower($type);
|
||||||
$trace_tabs = array_values($this->config['trace_tabs']);
|
$trace_tabs = array_values($this->config['trace_tabs']);
|
||||||
$line[] = ($type == $trace_tabs[0] || '调试' == $type || '错误'== $type)
|
$line[] = ($type == $trace_tabs[0] || '调试' == $type || '错误' == $type)
|
||||||
? "console.group('{$type}');"
|
? "console.group('{$type}');"
|
||||||
: "console.groupCollapsed('{$type}');";
|
: "console.groupCollapsed('{$type}');";
|
||||||
|
|
||||||
foreach ((array)$msg as $key => $m) {
|
foreach ((array) $msg as $key => $m) {
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case '调试':
|
case '调试':
|
||||||
$var_type = gettype($m);
|
$var_type = gettype($m);
|
||||||
if(in_array($var_type, ['array', 'string'])){
|
if (in_array($var_type, ['array', 'string'])) {
|
||||||
$line[] = "console.log(".json_encode($m).");";
|
$line[] = "console.log(" . json_encode($m) . ");";
|
||||||
}else{
|
} else {
|
||||||
$line[] = "console.log(".json_encode(var_export($m, 1)).");";
|
$line[] = "console.log(" . json_encode(var_export($m, 1)) . ");";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '错误':
|
case '错误':
|
||||||
$msg = str_replace(PHP_EOL, '\n', $m);
|
$msg = str_replace(PHP_EOL, '\n', $m);
|
||||||
$style = 'color:#F4006B;font-size:14px;';
|
$style = 'color:#F4006B;font-size:14px;';
|
||||||
$line[] = "console.error(\"%c{$msg}\", \"{$style}\");";
|
$line[] = "console.error(\"%c{$msg}\", \"{$style}\");";
|
||||||
break;
|
break;
|
||||||
case 'sql':
|
case 'sql':
|
||||||
$msg = str_replace(PHP_EOL, '\n', $m);
|
$msg = str_replace(PHP_EOL, '\n', $m);
|
||||||
$style = "color:#009bb4;";
|
$style = "color:#009bb4;";
|
||||||
$line[] = "console.log(\"%c{$msg}\", \"{$style}\");";
|
$line[] = "console.log(\"%c{$msg}\", \"{$style}\");";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$m = is_string($key)? $key . ' ' . $m : $key+1 . ' ' . $m;
|
$m = is_string($key) ? $key . ' ' . $m : $key + 1 . ' ' . $m;
|
||||||
$msg = json_encode($m);
|
$msg = json_encode($m);
|
||||||
$line[] = "console.log({$msg});";
|
$line[] = "console.log({$msg});";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$line[]= "console.groupEnd();";
|
$line[] = "console.groupEnd();";
|
||||||
return implode(PHP_EOL, $line);
|
return implode(PHP_EOL, $line);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -9,18 +9,17 @@
|
|||||||
// | Author: liu21st <liu21st@gmail.com>
|
// | Author: liu21st <liu21st@gmail.com>
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
namespace think\log\driver;
|
namespace think\debug\trace;
|
||||||
|
|
||||||
use think\Cache;
|
use think\Cache;
|
||||||
use think\Config;
|
use think\Config;
|
||||||
use think\Db;
|
use think\Db;
|
||||||
use think\Debug;
|
use think\Debug;
|
||||||
use think\Request;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 页面Trace调试
|
* 页面Trace调试
|
||||||
*/
|
*/
|
||||||
class Trace
|
class Html
|
||||||
{
|
{
|
||||||
protected $config = [
|
protected $config = [
|
||||||
'trace_file' => '',
|
'trace_file' => '',
|
||||||
@@ -40,22 +39,22 @@ class Trace
|
|||||||
* @param array $log 日志信息
|
* @param array $log 日志信息
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function save(array $log = [])
|
public function output(array $log = [])
|
||||||
{
|
{
|
||||||
if (IS_CLI || IS_API || Request::instance()->isAjax() || (defined('RESPONSE_TYPE') && !in_array(RESPONSE_TYPE, ['html', 'view']))) {
|
|
||||||
// ajax cli api方式下不输出
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取基本信息
|
// 获取基本信息
|
||||||
$runtime = microtime(true) - START_TIME;
|
$runtime = number_format(microtime(true), 8, '.', '') - START_TIME;
|
||||||
$reqs = number_format(1 / number_format($runtime, 8), 2);
|
$reqs = number_format(1 / $runtime, 2);
|
||||||
$runtime = number_format($runtime, 6);
|
|
||||||
$mem = number_format((memory_get_usage() - START_MEM) / 1024, 2);
|
$mem = number_format((memory_get_usage() - START_MEM) / 1024, 2);
|
||||||
|
|
||||||
// 页面Trace信息
|
// 页面Trace信息
|
||||||
|
if (isset($_SERVER['HTTP_HOST'])) {
|
||||||
|
$uri = $_SERVER['SERVER_PROTOCOL'] . ' ' . $_SERVER['REQUEST_METHOD'] . ' : ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
||||||
|
} else {
|
||||||
|
$uri = "cmd:" . implode(' ', $_SERVER['argv']);
|
||||||
|
}
|
||||||
$base = [
|
$base = [
|
||||||
'请求信息' => date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']) . ' ' . $_SERVER['SERVER_PROTOCOL'] . ' ' . $_SERVER['REQUEST_METHOD'] . ' : ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
|
'请求信息' => date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']) . ' ' . $uri,
|
||||||
'运行时间' => "{$runtime}s [ 吞吐率:{$reqs}req/s ] 内存消耗:{$mem}kb 文件加载:" . count(get_included_files()),
|
'运行时间' => "{$runtime}s [ 吞吐率:{$reqs}req/s ] 内存消耗:{$mem}kb 文件加载:" . count(get_included_files()),
|
||||||
'查询信息' => Db::$queryTimes . ' queries ' . Db::$executeTimes . ' writes ',
|
'查询信息' => Db::$queryTimes . ' queries ' . Db::$executeTimes . ' writes ',
|
||||||
'缓存信息' => Cache::$readTimes . ' reads,' . Cache::$writeTimes . ' writes',
|
'缓存信息' => Cache::$readTimes . ' reads,' . Cache::$writeTimes . ' writes',
|
||||||
@@ -96,8 +95,7 @@ class Trace
|
|||||||
// 调用Trace页面模板
|
// 调用Trace页面模板
|
||||||
ob_start();
|
ob_start();
|
||||||
include $this->config['trace_file'];
|
include $this->config['trace_file'];
|
||||||
echo ob_get_clean();
|
return ob_get_clean();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -155,8 +155,10 @@ class Handle
|
|||||||
while (ob_get_level() > 1) {
|
while (ob_get_level() > 1) {
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$data['echo'] = ob_get_clean();
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
ob_implicit_flush(0);
|
|
||||||
extract($data);
|
extract($data);
|
||||||
include Config::get('exception_tmpl');
|
include Config::get('exception_tmpl');
|
||||||
// 获取并清空缓存
|
// 获取并清空缓存
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
<?php
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
// | Author: liu21st <liu21st@gmail.com>
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
|
|
||||||
namespace think\log\alarm;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 邮件通知驱动
|
|
||||||
*/
|
|
||||||
class Email
|
|
||||||
{
|
|
||||||
|
|
||||||
protected $config = [
|
|
||||||
'address' => '',
|
|
||||||
];
|
|
||||||
|
|
||||||
// 实例化并传入参数
|
|
||||||
public function __construct($config = [])
|
|
||||||
{
|
|
||||||
$this->config = array_merge($this->config, $config);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通知发送接口
|
|
||||||
* @access public
|
|
||||||
* @param string $msg 日志信息
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function send($msg = '')
|
|
||||||
{
|
|
||||||
return error_log($msg, 1, $this->config['address']);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -54,9 +54,8 @@ class File
|
|||||||
} else {
|
} else {
|
||||||
$current_uri = "cmd:" . implode(' ', $_SERVER['argv']);
|
$current_uri = "cmd:" . implode(' ', $_SERVER['argv']);
|
||||||
}
|
}
|
||||||
$runtime = microtime(true) - START_TIME;
|
$runtime = number_format(microtime(true), 8, '.', '') - START_TIME;
|
||||||
$reqs = number_format(1 / number_format($runtime, 8), 2);
|
$reqs = number_format(1 / $runtime, 2);
|
||||||
$runtime = number_format($runtime, 6);
|
|
||||||
$time_str = " [运行时间:{$runtime}s] [吞吐率:{$reqs}req/s]";
|
$time_str = " [运行时间:{$runtime}s] [吞吐率:{$reqs}req/s]";
|
||||||
$memory_use = number_format((memory_get_usage() - START_MEM) / 1024, 2);
|
$memory_use = number_format((memory_get_usage() - START_MEM) / 1024, 2);
|
||||||
$memory_str = " [内存消耗:{$memory_use}kb]";
|
$memory_str = " [内存消耗:{$memory_use}kb]";
|
||||||
@@ -67,7 +66,7 @@ class File
|
|||||||
foreach ($val as $msg) {
|
foreach ($val as $msg) {
|
||||||
if (!is_string($msg)) {
|
if (!is_string($msg)) {
|
||||||
$msg = var_export($msg, true);
|
$msg = var_export($msg, true);
|
||||||
}
|
}
|
||||||
$info .= '[ ' . $type . ' ] ' . $msg . "\r\n";
|
$info .= '[ ' . $type . ' ] ' . $msg . "\r\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||