From 52f669abecd073a6ba685b7b4c74c02c20b82235 Mon Sep 17 00:00:00 2001 From: molong Date: Thu, 30 Jun 2016 16:53:58 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=AE=E5=BD=95=E7=BB=93=E6=9E=84=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Addons.php | 22 +- application/admin/controller/Content.php | 27 +- application/admin/controller/Group.php | 11 +- application/admin/controller/User.php | 7 +- application/admin/static/css/style.css | 1 + application/admin/view/content/book.html | 124 + application/common/model/Book.php | 54 - application/common/model/Hooks.php | 15 +- application/common/model/Order.php | 58 - application/index/controller/Book.php | 70 + application/index/controller/Cart.php | 53 + application/user/controller/Order.php | 128 + application/user/controller/Pay.php | 70 + application/user/lang/zh-cn.php | 12 + application/user/view/login/find.html | 140 + application/user/view/login/forget.html | 126 + application/user/view/order/confirm.html | 94 + application/user/view/order/index.html | 50 + application/user/view/order/lists.html | 124 + application/user/view/order/pay.html | 93 + core/base.php | 9 +- core/classmap.php | 111 - core/convention.php | 10 +- {extend => core/extend}/com/Auth.php | 0 core/extend/com/Cart.php | 114 + {extend => core/extend}/com/Database.php | 0 {extend => core/extend}/com/Datatable.php | 0 core/extend/com/Email.php | 2343 +++++++++++++++++ core/extend/com/Pay.php | 80 + {extend => core/extend}/com/Sent.php | 0 {extend => core/extend}/com/Tree.php | 0 {extend => core/extend}/com/Ueditor.php | 0 core/extend/com/pay/Input.php | 176 ++ core/extend/com/pay/Pay.php | 260 ++ core/extend/com/pay/driver/Alipay.php | 140 + {extend => core/extend}/org/Crypt.php | 0 {extend => core/extend}/org/Image.php | 0 {extend => core/extend}/org/Oauth.php | 0 {extend => core/extend}/org/Parser.php | 0 {extend => core/extend}/org/Transform.php | 0 {extend => core/extend}/org/Upload.php | 0 {extend => core/extend}/org/Verify.php | 0 .../extend}/org/image/driver/Gd.php | 0 .../extend}/org/image/driver/Gif.php | 0 .../extend}/org/image/driver/Imagick.php | 0 {extend => core/extend}/org/oauth/Driver.php | 0 .../extend}/org/oauth/driver/Diandian.php | 0 .../extend}/org/oauth/driver/Douban.php | 0 .../extend}/org/oauth/driver/Github.php | 0 .../extend}/org/oauth/driver/Google.php | 0 .../extend}/org/oauth/driver/Kaixin.php | 0 .../extend}/org/oauth/driver/Msn.php | 0 .../extend}/org/oauth/driver/Qq.php | 0 .../extend}/org/oauth/driver/Renren.php | 0 .../extend}/org/oauth/driver/Sina.php | 0 .../extend}/org/oauth/driver/Sohu.php | 0 .../extend}/org/oauth/driver/T163.php | 0 .../extend}/org/oauth/driver/Taobao.php | 0 .../extend}/org/oauth/driver/Tencent.php | 0 .../extend}/org/oauth/driver/X360.php | 0 .../extend}/org/parser/driver/Markdown.php | 0 .../extend}/org/parser/driver/Ubb.php | 0 .../extend}/org/transform/driver/Base64.php | 0 .../extend}/org/transform/driver/Json.php | 0 .../extend}/org/transform/driver/Xml.php | 0 .../extend}/org/upload/driver/Ftp.php | 0 .../extend}/org/upload/driver/Local.php | 0 .../extend}/org/upload/driver/Qiniu.php | 0 .../extend}/org/upload/driver/Sae.php | 0 .../extend}/org/upload/driver/Upyun.php | 0 .../org/upload/driver/qiniu/QiniuStorage.php | 0 {extend => core/extend}/org/verify/bgs/1.jpg | Bin {extend => core/extend}/org/verify/bgs/2.jpg | Bin {extend => core/extend}/org/verify/bgs/3.jpg | Bin {extend => core/extend}/org/verify/bgs/4.jpg | Bin {extend => core/extend}/org/verify/bgs/5.jpg | Bin {extend => core/extend}/org/verify/bgs/6.jpg | Bin {extend => core/extend}/org/verify/bgs/7.jpg | Bin {extend => core/extend}/org/verify/bgs/8.jpg | Bin {extend => core/extend}/org/verify/ttfs/1.ttf | Bin {extend => core/extend}/org/verify/ttfs/2.ttf | Bin {extend => core/extend}/org/verify/ttfs/3.ttf | Bin {extend => core/extend}/org/verify/ttfs/4.ttf | Bin {extend => core/extend}/org/verify/ttfs/5.ttf | Bin {extend => core/extend}/org/verify/ttfs/6.ttf | Bin .../extend}/org/verify/zhttfs/1.ttf | Bin core/library/think/App.php | 29 +- core/library/think/Config.php | 8 +- core/library/think/Hook.php | 5 +- core/library/think/Loader.php | 101 +- core/library/think/Log.php | 57 +- core/library/think/Request.php | 2 +- core/library/think/Response.php | 46 +- core/library/think/db/Query.php | 34 +- core/library/think/debug/Trace.php | 63 + .../Browser.php => debug/trace/Console.php} | 69 +- .../driver/Trace.php => debug/trace/Html.php} | 26 +- core/library/think/exception/Handle.php | 4 +- core/library/think/log/alarm/Email.php | 41 - core/library/think/log/driver/File.php | 7 +- core/library/think/log/driver/Sae.php | 7 +- core/library/think/log/driver/Socket.php | 3 +- core/library/think/response/Jsonp.php | 6 +- core/library/think/template/taglib/Cx.php | 4 +- core/tpl/think_exception.tpl | 32 +- core/vendor/.gitignore | 0 index.php | 10 + 107 files changed, 4600 insertions(+), 476 deletions(-) create mode 100644 application/admin/view/content/book.html delete mode 100644 application/common/model/Book.php delete mode 100644 application/common/model/Order.php create mode 100644 application/index/controller/Book.php create mode 100644 application/index/controller/Cart.php create mode 100644 application/user/controller/Order.php create mode 100644 application/user/controller/Pay.php create mode 100644 application/user/lang/zh-cn.php create mode 100644 application/user/view/login/find.html create mode 100644 application/user/view/login/forget.html create mode 100644 application/user/view/order/confirm.html create mode 100644 application/user/view/order/index.html create mode 100644 application/user/view/order/lists.html create mode 100644 application/user/view/order/pay.html delete mode 100644 core/classmap.php rename {extend => core/extend}/com/Auth.php (100%) create mode 100644 core/extend/com/Cart.php rename {extend => core/extend}/com/Database.php (100%) rename {extend => core/extend}/com/Datatable.php (100%) create mode 100644 core/extend/com/Email.php create mode 100644 core/extend/com/Pay.php rename {extend => core/extend}/com/Sent.php (100%) rename {extend => core/extend}/com/Tree.php (100%) rename {extend => core/extend}/com/Ueditor.php (100%) create mode 100644 core/extend/com/pay/Input.php create mode 100644 core/extend/com/pay/Pay.php create mode 100644 core/extend/com/pay/driver/Alipay.php rename {extend => core/extend}/org/Crypt.php (100%) rename {extend => core/extend}/org/Image.php (100%) rename {extend => core/extend}/org/Oauth.php (100%) rename {extend => core/extend}/org/Parser.php (100%) rename {extend => core/extend}/org/Transform.php (100%) rename {extend => core/extend}/org/Upload.php (100%) rename {extend => core/extend}/org/Verify.php (100%) rename {extend => core/extend}/org/image/driver/Gd.php (100%) rename {extend => core/extend}/org/image/driver/Gif.php (100%) rename {extend => core/extend}/org/image/driver/Imagick.php (100%) rename {extend => core/extend}/org/oauth/Driver.php (100%) rename {extend => core/extend}/org/oauth/driver/Diandian.php (100%) rename {extend => core/extend}/org/oauth/driver/Douban.php (100%) rename {extend => core/extend}/org/oauth/driver/Github.php (100%) rename {extend => core/extend}/org/oauth/driver/Google.php (100%) rename {extend => core/extend}/org/oauth/driver/Kaixin.php (100%) rename {extend => core/extend}/org/oauth/driver/Msn.php (100%) rename {extend => core/extend}/org/oauth/driver/Qq.php (100%) rename {extend => core/extend}/org/oauth/driver/Renren.php (100%) rename {extend => core/extend}/org/oauth/driver/Sina.php (100%) rename {extend => core/extend}/org/oauth/driver/Sohu.php (100%) rename {extend => core/extend}/org/oauth/driver/T163.php (100%) rename {extend => core/extend}/org/oauth/driver/Taobao.php (100%) rename {extend => core/extend}/org/oauth/driver/Tencent.php (100%) rename {extend => core/extend}/org/oauth/driver/X360.php (100%) rename {extend => core/extend}/org/parser/driver/Markdown.php (100%) rename {extend => core/extend}/org/parser/driver/Ubb.php (100%) rename {extend => core/extend}/org/transform/driver/Base64.php (100%) rename {extend => core/extend}/org/transform/driver/Json.php (100%) rename {extend => core/extend}/org/transform/driver/Xml.php (100%) rename {extend => core/extend}/org/upload/driver/Ftp.php (100%) rename {extend => core/extend}/org/upload/driver/Local.php (100%) rename {extend => core/extend}/org/upload/driver/Qiniu.php (100%) rename {extend => core/extend}/org/upload/driver/Sae.php (100%) rename {extend => core/extend}/org/upload/driver/Upyun.php (100%) rename {extend => core/extend}/org/upload/driver/qiniu/QiniuStorage.php (100%) rename {extend => core/extend}/org/verify/bgs/1.jpg (100%) rename {extend => core/extend}/org/verify/bgs/2.jpg (100%) rename {extend => core/extend}/org/verify/bgs/3.jpg (100%) rename {extend => core/extend}/org/verify/bgs/4.jpg (100%) rename {extend => core/extend}/org/verify/bgs/5.jpg (100%) rename {extend => core/extend}/org/verify/bgs/6.jpg (100%) rename {extend => core/extend}/org/verify/bgs/7.jpg (100%) rename {extend => core/extend}/org/verify/bgs/8.jpg (100%) rename {extend => core/extend}/org/verify/ttfs/1.ttf (100%) rename {extend => core/extend}/org/verify/ttfs/2.ttf (100%) rename {extend => core/extend}/org/verify/ttfs/3.ttf (100%) rename {extend => core/extend}/org/verify/ttfs/4.ttf (100%) rename {extend => core/extend}/org/verify/ttfs/5.ttf (100%) rename {extend => core/extend}/org/verify/ttfs/6.ttf (100%) rename {extend => core/extend}/org/verify/zhttfs/1.ttf (100%) create mode 100644 core/library/think/debug/Trace.php rename core/library/think/{log/driver/Browser.php => debug/trace/Console.php} (67%) rename core/library/think/{log/driver/Trace.php => debug/trace/Html.php} (82%) delete mode 100644 core/library/think/log/alarm/Email.php create mode 100644 core/vendor/.gitignore diff --git a/application/admin/controller/Addons.php b/application/admin/controller/Addons.php index d8ce7b37..611bc8eb 100644 --- a/application/admin/controller/Addons.php +++ b/application/admin/controller/Addons.php @@ -244,14 +244,9 @@ class Addons extends Admin { public function addhook(){ $hooks = model('Hooks'); if (IS_POST) { - $data = input(); - if ($data) { - $result = $hooks->change($data); - if ($result !== false) { - return $this->success("修改成功"); - }else{ - return $this->error($hooks->getError()); - } + $result = $hooks->change(); + if ($result !== false) { + return $this->success("修改成功"); }else{ return $this->error($hooks->getError()); } @@ -270,14 +265,9 @@ class Addons extends Admin { public function edithook($id){ $hooks = model('Hooks'); if (IS_POST) { - $data = input('post.'); - if ($data) { - $result = $hooks->change($data); - if ($result !== false) { - return $this->success("修改成功"); - }else{ - return $this->error($hooks->getError()); - } + $result = $hooks->change(); + if ($result !== false) { + return $this->success("修改成功"); }else{ return $this->error($hooks->getError()); } diff --git a/application/admin/controller/Content.php b/application/admin/controller/Content.php index adbe4ddd..ea76fb11 100644 --- a/application/admin/controller/Content.php +++ b/application/admin/controller/Content.php @@ -50,8 +50,9 @@ class Content extends Admin{ $map = $this->buildMap(); $field = array_filter($grid_list['fields']); if ($this->modelInfo['extend'] == 1) { - $map['model_id'] = $this->modelInfo['id']; array_push($field, 'is_top'); + }else{ + unset($map['model_id']); } $list = $this->model->where($map)->field($field)->order($order)->paginate(15); @@ -249,21 +250,27 @@ class Content extends Admin{ */ protected function buildMap(){ $map = array(); - $keyword = input('get.keyword', '', 'trim'); - $category = input('get.category', '', 'trim'); - - if ($keyword) { - $map['title'] = array("LIKE", "%$keyword%"); - } - if ($category){ - $map['category_id'] = $category; + $data = $this->request->get(); + foreach ($data as $key => $value) { + if ($value) { + if ($key == 'keyword') { + $map['title'] = array("LIKE", "%$value%"); + }elseif($key == 'category'){ + $map['category_id'] = $value; + }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) { + $category = isset($data['category']) ? $data['category'] : ''; $cate_list = parse_field_bind('category', $category, $this->modelInfo['id']); $this->assign('cate_list', $cate_list); } - $this->assign($this->request->get()); + $this->assign($data); return $map; } diff --git a/application/admin/controller/Group.php b/application/admin/controller/Group.php index 0773f0f8..0471f992 100644 --- a/application/admin/controller/Group.php +++ b/application/admin/controller/Group.php @@ -23,9 +23,7 @@ class Group extends Admin { //会员分组首页控制器 - public function index(){ - $type = input('get.type','admin','trim'); - + public function index($type = 'admin'){ $map['module'] = $type; $list = db('AuthGroup')->where($map)->order('id desc')->paginate(10); @@ -112,9 +110,7 @@ class Group extends Admin { } //权限节点控制器 - public function access(){ - $type = input('get.type','admin','trim'); - + public function access($type = 'admin'){ $map['module'] = $type; $list = db('AuthRule')->where($map)->order('id desc')->paginate(10); @@ -253,8 +249,7 @@ class Group extends Admin { } } - public function delnode(){ - $id = input('id','','trim,intval'); + public function delnode($id){ if (!$id) { return $this->error("非法操作!"); } diff --git a/application/admin/controller/User.php b/application/admin/controller/User.php index d88496a8..9a41c0f1 100644 --- a/application/admin/controller/User.php +++ b/application/admin/controller/User.php @@ -118,11 +118,8 @@ class User extends Admin{ * del * @author colin */ - public function del(){ - $ids = input('post.ids'); - //多条删除和单条删除 - empty($ids) ? $ids = input('get.id') : $ids = $ids; - $uid = array('IN',is_array($ids) ? implode(',',$ids) : $ids); + public function del($id){ + $uid = array('IN',is_array($id) ? implode(',',$id) : $id); //获取用户信息 $find = $this->getUserinfo($uid); model('User')->where(array('uid'=>$uid))->delete(); diff --git a/application/admin/static/css/style.css b/application/admin/static/css/style.css index 0c039303..20474e3e 100644 --- a/application/admin/static/css/style.css +++ b/application/admin/static/css/style.css @@ -3,6 +3,7 @@ html,body { -webkit-font-smoothing:antialiased; } a.badge{color: #ffffff;} +.pt-5{padding-top: 5px;} textarea{resize:none; min-height: 80px;} @media (max-width:419px) { html,body { diff --git a/application/admin/view/content/book.html b/application/admin/view/content/book.html new file mode 100644 index 00000000..c604855b --- /dev/null +++ b/application/admin/view/content/book.html @@ -0,0 +1,124 @@ +{extend name="public/base"/} +{block name="style"} + + + + + +{/block} +{block name="body"} +
+
+
+

{$meta_title}

+
+
+ 新 增 + +
+
+
+
+
+
+
+
书名:
+ +
+
+
+
+
发布时间:
+
+ +
+
+ +
+
+
+
+
+
标准类型:
+ +
+
+
+
+
编号:
+ +
+
+
+ +
+
+
+
+ +
+ + + + + {volist name="grid['grids']" id="item"} + + {/volist} + + + + + {if condition="empty($list)"} + {php} + $cow = count($grid['grids'])+2; + {/php} + + + + {else/} + {volist name="list" id="item"} + + + {volist name="grid['grids']" id="vo"} + {if isset($vo['format'])} + + {else/} + + {/if} + {/volist} + + + {/volist} + {/if} + +
{$item['title']}操作
暂无数据!
{$item[$vo['field'][0]]|$vo['format']}{$item[$vo['field'][0]]} + {if isset($item['status'])} + {if $item['status']} + 取消审核 + {else/} + 审核 + {/if} + {/if} + 编辑 + 删除 +
+
+ {$page} +
+
+
+{/block} +{block name="script"} + +{/block} \ No newline at end of file diff --git a/application/common/model/Book.php b/application/common/model/Book.php deleted file mode 100644 index d3e8f31f..00000000 --- a/application/common/model/Book.php +++ /dev/null @@ -1,54 +0,0 @@ - -// +---------------------------------------------------------------------- - -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']]; - } -} \ No newline at end of file diff --git a/application/common/model/Hooks.php b/application/common/model/Hooks.php index ffe20730..e20d895f 100644 --- a/application/common/model/Hooks.php +++ b/application/common/model/Hooks.php @@ -64,19 +64,6 @@ class Hooks extends Base { 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){ $addons_class = get_addon_class($addons_name);//获取插件名 if(!class_exists($addons_class)){ @@ -94,5 +81,5 @@ class Hooks extends Base { return false; } $methods = get_class_methods($addons_class); - } + } } \ No newline at end of file diff --git a/application/common/model/Order.php b/application/common/model/Order.php deleted file mode 100644 index 4282ee2b..00000000 --- a/application/common/model/Order.php +++ /dev/null @@ -1,58 +0,0 @@ - -// +---------------------------------------------------------------------- - -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; - } -} \ No newline at end of file diff --git a/application/index/controller/Book.php b/application/index/controller/Book.php new file mode 100644 index 00000000..e0af7d2b --- /dev/null +++ b/application/index/controller/Book.php @@ -0,0 +1,70 @@ + +// +---------------------------------------------------------------------- + +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; + } +} \ No newline at end of file diff --git a/application/index/controller/Cart.php b/application/index/controller/Cart.php new file mode 100644 index 00000000..a4e78b5d --- /dev/null +++ b/application/index/controller/Cart.php @@ -0,0 +1,53 @@ + +// +---------------------------------------------------------------------- + +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); + } +} \ No newline at end of file diff --git a/application/user/controller/Order.php b/application/user/controller/Order.php new file mode 100644 index 00000000..8dfa3a2a --- /dev/null +++ b/application/user/controller/Order.php @@ -0,0 +1,128 @@ + +// +---------------------------------------------------------------------- + +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("取消失败!"); + } + } +} \ No newline at end of file diff --git a/application/user/controller/Pay.php b/application/user/controller/Pay.php new file mode 100644 index 00000000..ff42d720 --- /dev/null +++ b/application/user/controller/Pay.php @@ -0,0 +1,70 @@ + +// +---------------------------------------------------------------------- + +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("支付失败!"); + } + } +} \ No newline at end of file diff --git a/application/user/lang/zh-cn.php b/application/user/lang/zh-cn.php new file mode 100644 index 00000000..37fcf19b --- /dev/null +++ b/application/user/lang/zh-cn.php @@ -0,0 +1,12 @@ + +// +---------------------------------------------------------------------- + +return array( + 'find_password' => '您的找回密码确认地址为:{:url}', +); \ No newline at end of file diff --git a/application/user/view/login/find.html b/application/user/view/login/find.html new file mode 100644 index 00000000..41401003 --- /dev/null +++ b/application/user/view/login/find.html @@ -0,0 +1,140 @@ + + + + + + +找回密码 + + + + + + + + +
+
+

+ +

+ +
+
+ + + + + + + \ No newline at end of file diff --git a/application/user/view/login/forget.html b/application/user/view/login/forget.html new file mode 100644 index 00000000..d3910e15 --- /dev/null +++ b/application/user/view/login/forget.html @@ -0,0 +1,126 @@ + + + + + + +找回密码 + + + + + + + + +
+
+

+ +

+ +
+
+ + + + + + + \ No newline at end of file diff --git a/application/user/view/order/confirm.html b/application/user/view/order/confirm.html new file mode 100644 index 00000000..1731f8a5 --- /dev/null +++ b/application/user/view/order/confirm.html @@ -0,0 +1,94 @@ + + + + + + +确认订单信息-会员中心 - Powered by TenSent,Inc. + + + + + + + + + +{block name="style"}{/block} + + + +
+
+
+
+ +
+
+
+
+ +
+ +
+
+
+
+ 1、购物车 +
+
+ 2、确认订单信息 +
+
+ 3、选择支付 +
+
+ 4、订购完成 +
+
+
+
+
+
+

订单已成功提交!

+
+ + + + + + + + + + + + + + + +
订单编号:{$info['order_no']}
订单金额:¥{$info['price_count']}
支付方式:{$info['pay_type_text']}
+ + +
+ + + +
+
+
+
+
+ + + + \ No newline at end of file diff --git a/application/user/view/order/index.html b/application/user/view/order/index.html new file mode 100644 index 00000000..d188dac5 --- /dev/null +++ b/application/user/view/order/index.html @@ -0,0 +1,50 @@ +{extend name="public/base" /} +{block name="body"} +
+ +
+
+ {volist name="list" id="item"} +
+
+ 订单号:{$item['order_no']}({$item['create_time']|date='Y-m-d',###}) + + {if $item['pay_status']} + 已付款 + {else/} + 取消订单 + 付款 + {/if} + +
+ + + + + + + {volist name="item['product']" id="product"} + + + + + + {/volist} +
图书图书名称操作
+ {$product->book['book_name']} + + {$product->book['book_name']} + + {if $item['pay_status']} + 下载图书 + {/if} +
+
+ {/volist} + {$page} +
+
+
+{/block} \ No newline at end of file diff --git a/application/user/view/order/lists.html b/application/user/view/order/lists.html new file mode 100644 index 00000000..077131e8 --- /dev/null +++ b/application/user/view/order/lists.html @@ -0,0 +1,124 @@ + + + + + + +确认订单信息-会员中心 - Powered by TenSent,Inc. + + + + + + + + + +{block name="style"}{/block} + + + +
+
+
+
+ +
+
+
+
+ +
+ +
+
+
+
+ 1、购物车 +
+
+ 2、确认订单信息 +
+
+ 3、选择支付 +
+
+ 4、订购完成 +
+
+
+
+
+
+
+
商品清单
+ {if !empty($list)} + + + + + + + + + + + + + {volist name="list" id="item"} + + + + + + + + + {/volist} + +
商品名称单价数量小计操作
+ + + {$item->book['book_name']} + ¥{$item['price']}{$item['num']}¥{$item['price_count']} + +
+ +
+

应付总额:¥{$price_count}

+
+ +
支付方式
+
+
    +
  • + + +
    +
  • +
+
+
+ + +
+ {else/} +

购物车为空!去继续选择……

+ {/if} +
+
+
+
+ + + + \ No newline at end of file diff --git a/application/user/view/order/pay.html b/application/user/view/order/pay.html new file mode 100644 index 00000000..5282e009 --- /dev/null +++ b/application/user/view/order/pay.html @@ -0,0 +1,93 @@ + + + + + + +确认订单信息-会员中心 - Powered by TenSent,Inc. + + + + + + + + + +{block name="style"}{/block} + + + +
+
+
+
+ +
+
+
+
+ +
+ +
+
+
+
+ 1、购物车 +
+
+ 2、确认订单信息 +
+
+ 3、选择支付 +
+
+ 4、订购完成 +
+
+
+
+
+
+

等待支付!

+ {$sHtml} +
+
+
+ +{if $is_submit} + +{/if} + + + \ No newline at end of file diff --git a/core/base.php b/core/base.php index 052febe7..78b3f920 100644 --- a/core/base.php +++ b/core/base.php @@ -10,13 +10,12 @@ // +---------------------------------------------------------------------- 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('EXT', '.php'); define('DS', DIRECTORY_SEPARATOR); defined('THINK_PATH') or define('THINK_PATH', __DIR__ . DS); define('LIB_PATH', THINK_PATH . 'library' . DS); -define('MODE_PATH', THINK_PATH . 'mode' . DS); // 系统应用模式目录 define('CORE_PATH', LIB_PATH . 'think' . DS); define('TRAIT_PATH', LIB_PATH . 'traits' . 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_EXT') or define('CONF_EXT', EXT); // 配置文件后缀 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); @@ -44,9 +41,11 @@ require CORE_PATH . 'Loader.php'; if (is_file(ROOT_PATH . 'env' . EXT)) { $env = include ROOT_PATH . 'env' . EXT; foreach ($env as $key => $val) { - $name = ENV_PREFIX . $key; + $name = ENV_PREFIX . strtoupper($key); if (is_bool($val)) { $val = $val ? 1 : 0; + } elseif (!is_scalar($val)) { + continue; } putenv("$name=$val"); } diff --git a/core/classmap.php b/core/classmap.php deleted file mode 100644 index 9fe54787..00000000 --- a/core/classmap.php +++ /dev/null @@ -1,111 +0,0 @@ - -// +---------------------------------------------------------------------- - -/** - * 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, -]; diff --git a/core/convention.php b/core/convention.php index eca9e883..3ad29bb5 100644 --- a/core/convention.php +++ b/core/convention.php @@ -140,12 +140,20 @@ return [ // +---------------------------------------------------------------------- 'log' => [ - // 日志记录方式,支持 file socket trace sae + // 日志记录方式,支持 file socket sae 'type' => 'File', // 日志保存目录 'path' => LOG_PATH, ], + // +---------------------------------------------------------------------- + // | Trace设置 + // +---------------------------------------------------------------------- + 'trace' => [ + //支持Html,Console 设为false则不显示 + 'type' => false, + ], + // +---------------------------------------------------------------------- // | 缓存设置 // +---------------------------------------------------------------------- diff --git a/extend/com/Auth.php b/core/extend/com/Auth.php similarity index 100% rename from extend/com/Auth.php rename to core/extend/com/Auth.php diff --git a/core/extend/com/Cart.php b/core/extend/com/Cart.php new file mode 100644 index 00000000..8c24c9b8 --- /dev/null +++ b/core/extend/com/Cart.php @@ -0,0 +1,114 @@ + +// +---------------------------------------------------------------------- + +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); + } +} \ No newline at end of file diff --git a/extend/com/Database.php b/core/extend/com/Database.php similarity index 100% rename from extend/com/Database.php rename to core/extend/com/Database.php diff --git a/extend/com/Datatable.php b/core/extend/com/Datatable.php similarity index 100% rename from extend/com/Datatable.php rename to core/extend/com/Datatable.php diff --git a/core/extend/com/Email.php b/core/extend/com/Email.php new file mode 100644 index 00000000..07737810 --- /dev/null +++ b/core/extend/com/Email.php @@ -0,0 +1,2343 @@ + '1 (Highest)', + 2 => '2 (High)', + 3 => '3 (Normal)', + 4 => '4 (Low)', + 5 => '5 (Lowest)' + ); + + // -------------------------------------------------------------------- + + /** + * Constructor - Sets Email Preferences + * + * The constructor can be passed an array of config values + * + * @param array $config = array() + * @return void + */ + public function __construct(array $config = array()) + { + $this->charset = \think\Config::get('charset'); + + if (count($config) > 0) + { + $this->initialize($config); + } + else + { + $this->_smtp_auth = ! ($this->smtp_user === '' && $this->smtp_pass === ''); + } + + $this->_safe_mode = ( ! version_compare("5.4", PHP_VERSION, ">") && ini_get('safe_mode')); + $this->charset = strtoupper($this->charset); + + \think\Log::write('Email Class Initialized', 'info'); + } + + // -------------------------------------------------------------------- + + /** + * Destructor - Releases Resources + * + * @return void + */ + public function __destruct() + { + if (is_resource($this->_smtp_connect)) + { + $this->_send_command('quit'); + } + } + + // -------------------------------------------------------------------- + + /** + * Initialize preferences + * + * @param array + * @return CI_Email + */ + public function initialize($config = array()) + { + foreach ($config as $key => $val) + { + if (isset($this->$key)) + { + $method = 'set_'.$key; + + if (method_exists($this, $method)) + { + $this->$method($val); + } + else + { + $this->$key = $val; + } + } + } + $this->clear(); + + $this->_smtp_auth = ! ($this->smtp_user === '' && $this->smtp_pass === ''); + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Initialize the Email Data + * + * @param bool + * @return CI_Email + */ + public function clear($clear_attachments = FALSE) + { + $this->_subject = ''; + $this->_body = ''; + $this->_finalbody = ''; + $this->_header_str = ''; + $this->_replyto_flag = FALSE; + $this->_recipients = array(); + $this->_cc_array = array(); + $this->_bcc_array = array(); + $this->_headers = array(); + $this->_debug_msg = array(); + + $this->set_header('User-Agent', $this->useragent); + $this->set_header('Date', $this->_set_date()); + + if ($clear_attachments !== FALSE) + { + $this->_attachments = array(); + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set FROM + * + * @param string $from + * @param string $name + * @param string $return_path = NULL Return-Path + * @return CI_Email + */ + public function from($from, $name = '', $return_path = NULL) + { + if (preg_match('/\<(.*)\>/', $from, $match)) + { + $from = $match[1]; + } + + if ($this->validate) + { + $this->validate_email($this->_str_to_array($from)); + if ($return_path) + { + $this->validate_email($this->_str_to_array($return_path)); + } + } + + // prepare the display name + if ($name !== '') + { + // only use Q encoding if there are characters that would require it + if ( ! preg_match('/[\200-\377]/', $name)) + { + // add slashes for non-printing characters, slashes, and double quotes, and surround it in double quotes + $name = '"'.addcslashes($name, "\0..\37\177'\"\\").'"'; + } + else + { + $name = $this->_prep_q_encoding($name); + } + } + + $this->set_header('From', $name.' <'.$from.'>'); + + isset($return_path) OR $return_path = $from; + $this->set_header('Return-Path', '<'.$return_path.'>'); + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Reply-to + * + * @param string + * @param string + * @return CI_Email + */ + public function reply_to($replyto, $name = '') + { + if (preg_match('/\<(.*)\>/', $replyto, $match)) + { + $replyto = $match[1]; + } + + if ($this->validate) + { + $this->validate_email($this->_str_to_array($replyto)); + } + + if ($name !== '') + { + // only use Q encoding if there are characters that would require it + if ( ! preg_match('/[\200-\377]/', $name)) + { + // add slashes for non-printing characters, slashes, and double quotes, and surround it in double quotes + $name = '"'.addcslashes($name, "\0..\37\177'\"\\").'"'; + } + else + { + $name = $this->_prep_q_encoding($name); + } + } + + $this->set_header('Reply-To', $name.' <'.$replyto.'>'); + $this->_replyto_flag = TRUE; + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Recipients + * + * @param string + * @return CI_Email + */ + public function to($to) + { + $to = $this->_str_to_array($to); + $to = $this->clean_email($to); + + if ($this->validate) + { + $this->validate_email($to); + } + + if ($this->_get_protocol() !== 'mail') + { + $this->set_header('To', implode(', ', $to)); + } + + $this->_recipients = $to; + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set CC + * + * @param string + * @return CI_Email + */ + public function cc($cc) + { + $cc = $this->clean_email($this->_str_to_array($cc)); + + if ($this->validate) + { + $this->validate_email($cc); + } + + $this->set_header('Cc', implode(', ', $cc)); + + if ($this->_get_protocol() === 'smtp') + { + $this->_cc_array = $cc; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set BCC + * + * @param string + * @param string + * @return CI_Email + */ + public function bcc($bcc, $limit = '') + { + if ($limit !== '' && is_numeric($limit)) + { + $this->bcc_batch_mode = TRUE; + $this->bcc_batch_size = $limit; + } + + $bcc = $this->clean_email($this->_str_to_array($bcc)); + + if ($this->validate) + { + $this->validate_email($bcc); + } + + if ($this->_get_protocol() === 'smtp' OR ($this->bcc_batch_mode && count($bcc) > $this->bcc_batch_size)) + { + $this->_bcc_array = $bcc; + } + else + { + $this->set_header('Bcc', implode(', ', $bcc)); + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Email Subject + * + * @param string + * @return CI_Email + */ + public function subject($subject) + { + $subject = $this->_prep_q_encoding($subject); + $this->set_header('Subject', $subject); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Body + * + * @param string + * @return CI_Email + */ + public function message($body) + { + $this->_body = rtrim(str_replace("\r", '', $body)); + + /* strip slashes only if magic quotes is ON + if we do it with magic quotes OFF, it strips real, user-inputted chars. + + NOTE: In PHP 5.4 get_magic_quotes_gpc() will always return 0 and + it will probably not exist in future versions at all. + */ + if ( ! version_compare("5.4", PHP_VERSION, ">") && get_magic_quotes_gpc()) + { + $this->_body = stripslashes($this->_body); + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Assign file attachments + * + * @param string $file Can be local path, URL or buffered content + * @param string $disposition = 'attachment' + * @param string $newname = NULL + * @param string $mime = '' + * @return CI_Email + */ + public function attach($file, $disposition = '', $newname = NULL, $mime = '') + { + if ($mime === '') + { + if (strpos($file, '://') === FALSE && ! file_exists($file)) + { + $this->_set_error_message('lang:email_attachment_missing', $file); + return FALSE; + } + + if ( ! $fp = @fopen($file, 'rb')) + { + $this->_set_error_message('lang:email_attachment_unreadable', $file); + return FALSE; + } + + $file_content = stream_get_contents($fp); + $mime = $this->_mime_types(pathinfo($file, PATHINFO_EXTENSION)); + fclose($fp); + } + else + { + $file_content =& $file; // buffered file + } + + $this->_attachments[] = array( + 'name' => array($file, $newname), + 'disposition' => empty($disposition) ? 'attachment' : $disposition, // Can also be 'inline' Not sure if it matters + 'type' => $mime, + 'content' => chunk_split(base64_encode($file_content)) + ); + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set and return attachment Content-ID + * + * Useful for attached inline pictures + * + * @param string $filename + * @return string + */ + public function attachment_cid($filename) + { + if ($this->multipart !== 'related') + { + $this->multipart = 'related'; // Thunderbird need this for inline images + } + + for ($i = 0, $c = count($this->_attachments); $i < $c; $i++) + { + if ($this->_attachments[$i]['name'][0] === $filename) + { + $this->_attachments[$i]['cid'] = uniqid(basename($this->_attachments[$i]['name'][0]).'@'); + return $this->_attachments[$i]['cid']; + } + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Add a Header Item + * + * @param string + * @param string + * @return CI_Email + */ + public function set_header($header, $value) + { + $this->_headers[$header] = str_replace(array("\n", "\r"), '', $value); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Convert a String to an Array + * + * @param string + * @return array + */ + protected function _str_to_array($email) + { + if ( ! is_array($email)) + { + return (strpos($email, ',') !== FALSE) + ? preg_split('/[\s,]/', $email, -1, PREG_SPLIT_NO_EMPTY) + : (array) trim($email); + } + + return $email; + } + + // -------------------------------------------------------------------- + + /** + * Set Multipart Value + * + * @param string + * @return CI_Email + */ + public function set_alt_message($str) + { + $this->alt_message = (string) $str; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Mailtype + * + * @param string + * @return CI_Email + */ + public function set_mailtype($type = 'text') + { + $this->mailtype = ($type === 'html') ? 'html' : 'text'; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Wordwrap + * + * @param bool + * @return CI_Email + */ + public function set_wordwrap($wordwrap = TRUE) + { + $this->wordwrap = (bool) $wordwrap; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Protocol + * + * @param string + * @return CI_Email + */ + public function set_protocol($protocol = 'mail') + { + $this->protocol = in_array($protocol, $this->_protocols, TRUE) ? strtolower($protocol) : 'mail'; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Priority + * + * @param int + * @return CI_Email + */ + public function set_priority($n = 3) + { + $this->priority = preg_match('/^[1-5]$/', $n) ? (int) $n : 3; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Newline Character + * + * @param string + * @return CI_Email + */ + public function set_newline($newline = "\n") + { + $this->newline = in_array($newline, array("\n", "\r\n", "\r")) ? $newline : "\n"; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set CRLF + * + * @param string + * @return CI_Email + */ + public function set_crlf($crlf = "\n") + { + $this->crlf = ($crlf !== "\n" && $crlf !== "\r\n" && $crlf !== "\r") ? "\n" : $crlf; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Message Boundary + * + * @return void + */ + protected function _set_boundaries() + { + $this->_alt_boundary = 'B_ALT_'.uniqid(''); // multipart/alternative + $this->_atc_boundary = 'B_ATC_'.uniqid(''); // attachment boundary + } + + // -------------------------------------------------------------------- + + /** + * Get the Message ID + * + * @return string + */ + protected function _get_message_id() + { + $from = str_replace(array('>', '<'), '', $this->_headers['Return-Path']); + return '<'.uniqid('').strstr($from, '@').'>'; + } + + // -------------------------------------------------------------------- + + /** + * Get Mail Protocol + * + * @param bool + * @return mixed + */ + protected function _get_protocol($return = TRUE) + { + $this->protocol = strtolower($this->protocol); + in_array($this->protocol, $this->_protocols, TRUE) OR $this->protocol = 'mail'; + + if ($return === TRUE) + { + return $this->protocol; + } + } + + // -------------------------------------------------------------------- + + /** + * Get Mail Encoding + * + * @param bool + * @return string + */ + protected function _get_encoding($return = TRUE) + { + in_array($this->_encoding, $this->_bit_depths) OR $this->_encoding = '8bit'; + + foreach ($this->_base_charsets as $charset) + { + if (strpos($charset, $this->charset) === 0) + { + $this->_encoding = '7bit'; + } + } + + if ($return === TRUE) + { + return $this->_encoding; + } + } + + // -------------------------------------------------------------------- + + /** + * Get content type (text/html/attachment) + * + * @return string + */ + protected function _get_content_type() + { + if ($this->mailtype === 'html') + { + return (count($this->_attachments) === 0) ? 'html' : 'html-attach'; + } + elseif ($this->mailtype === 'text' && count($this->_attachments) > 0) + { + return 'plain-attach'; + } + else + { + return 'plain'; + } + } + + // -------------------------------------------------------------------- + + /** + * Set RFC 822 Date + * + * @return string + */ + protected function _set_date() + { + $timezone = date('Z'); + $operator = ($timezone[0] === '-') ? '-' : '+'; + $timezone = abs($timezone); + $timezone = floor($timezone/3600) * 100 + ($timezone % 3600) / 60; + + return sprintf('%s %s%04d', date('D, j M Y H:i:s'), $operator, $timezone); + } + + // -------------------------------------------------------------------- + + /** + * Mime message + * + * @return string + */ + protected function _get_mime_message() + { + return 'This is a multi-part message in MIME format.'.$this->newline.'Your email application may not support this format.'; + } + + // -------------------------------------------------------------------- + + /** + * Validate Email Address + * + * @param string + * @return bool + */ + public function validate_email($email) + { + if ( ! is_array($email)) + { + $this->_set_error_message('lang:email_must_be_array'); + return FALSE; + } + + foreach ($email as $val) + { + if ( ! $this->valid_email($val)) + { + $this->_set_error_message('lang:email_invalid_address', $val); + return FALSE; + } + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Email Validation + * + * @param string + * @return bool + */ + public function valid_email($email) + { + if (function_exists('idn_to_ascii') && $atpos = strpos($email, '@')) + { + $email = substr($email, 0, ++$atpos).idn_to_ascii(substr($email, $atpos)); + } + + return (bool) filter_var($email, FILTER_VALIDATE_EMAIL); + } + + // -------------------------------------------------------------------- + + /** + * Clean Extended Email Address: Joe Smith + * + * @param string + * @return string + */ + public function clean_email($email) + { + if ( ! is_array($email)) + { + return preg_match('/\<(.*)\>/', $email, $match) ? $match[1] : $email; + } + + $clean_email = array(); + + foreach ($email as $addy) + { + $clean_email[] = preg_match('/\<(.*)\>/', $addy, $match) ? $match[1] : $addy; + } + + return $clean_email; + } + + // -------------------------------------------------------------------- + + /** + * Build alternative plain text message + * + * Provides the raw message for use in plain-text headers of + * HTML-formatted emails. + * If the user hasn't specified his own alternative message + * it creates one by stripping the HTML + * + * @return string + */ + protected function _get_alt_message() + { + if ( ! empty($this->alt_message)) + { + return ($this->wordwrap) + ? $this->word_wrap($this->alt_message, 76) + : $this->alt_message; + } + + $body = preg_match('/\(.*)\<\/body\>/si', $this->_body, $match) ? $match[1] : $this->_body; + $body = str_replace("\t", '', preg_replace('#