用户中心
This commit is contained in:
@@ -1,135 +0,0 @@
|
||||
<?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();
|
||||
if ($list) {
|
||||
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;
|
||||
}
|
||||
|
||||
if (!isset($map['id'])) {
|
||||
return $this->error('非法操作!');
|
||||
}
|
||||
|
||||
$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("取消失败!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
<?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("支付失败!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user