162 lines
5.8 KiB
PHP
162 lines
5.8 KiB
PHP
<?php
|
|
namespace Shop\Controller;
|
|
use Member\Controller\BaseController;
|
|
class ShopOrderController extends BaseController {
|
|
public function __construct() {
|
|
parent::__construct();
|
|
$this->table = D("ShopOrder");
|
|
//系统查询哪些超时付款,超时未收货自动做相关操作
|
|
$this->table->autoReceipt();
|
|
$this->table->autoCancelOrder();
|
|
}
|
|
public function index(){
|
|
$this->status_code=I("get.status_code");//订单状态
|
|
$where=array();
|
|
$where["member_id"]=session("member.member_id");
|
|
//订单号
|
|
$order_num=I("get.order_num");
|
|
if($order_num){
|
|
$where["db_shop_order.order_num"]=$order_num;
|
|
}
|
|
//订货号
|
|
$type_no=I("get.type_no");
|
|
if($type_no){
|
|
$where["type_no"]=$type_no;
|
|
}
|
|
//产品名称
|
|
$title=I("get.title");
|
|
if($title){
|
|
$where["title"]=array("like","%".$title."%");
|
|
}
|
|
//订单状态
|
|
if($this->status_code){
|
|
$where["status_code"]=$this->status_code;
|
|
}
|
|
//不同状态下的订单统计
|
|
$this->readyPayCount=$this->table->where(array(
|
|
"member_id"=>session("member.member_id"),
|
|
"status_code"=>101,
|
|
))->count();
|
|
$this->readyDeliveryCount=$this->table->where(array(
|
|
"member_id"=>session("member.member_id"),
|
|
"status_code"=>102,
|
|
))->count();
|
|
$this->readyReceiptCount=$this->table->where(array(
|
|
"member_id"=>session("member.member_id"),
|
|
"status_code"=>103,
|
|
))->count();
|
|
$this->ReceiptCount=$this->table->where(array(
|
|
"member_id"=>session("member.member_id"),
|
|
"status_code"=>104,
|
|
))->count();
|
|
//
|
|
$total=$this->table
|
|
->join("db_shop_order_detail on db_shop_order.order_id=db_shop_order_detail.order_id")
|
|
->where($where)->group("db_shop_order.order_id")->count();
|
|
$page = new \Think\Page($total,10);
|
|
$data=$this->table
|
|
->join("db_shop_order_detail on db_shop_order.order_id=db_shop_order_detail.order_id")
|
|
->relation(true)->where($where)->group("db_shop_order.order_id")->order("db_shop_order.order_id desc")->limit($page->firstRow,$page->listRows)->select();
|
|
$this->assign("listpage", $page->show());
|
|
$this->assign("data",$data);
|
|
$this->pagetitle="我的订单";
|
|
$this->navLight="wddj";//菜单高亮
|
|
$this->display();
|
|
}
|
|
//订单详情
|
|
public function show($order_id){
|
|
$where["member_id"]=session("member.member_id");
|
|
$where["order_id"]=$order_id;
|
|
$this->r=$this->table->relation(true)->where($where)->find();
|
|
$this->pagetitle="订单详情";
|
|
$this->navLight="wddj";//菜单高亮
|
|
$this->display();
|
|
}
|
|
//取消订单
|
|
public function cancelOrder($order_id){
|
|
$where["member_id"]=session("member.member_id");
|
|
$where["order_id"]=$order_id;
|
|
$order=$this->table->where($where)->find();
|
|
if(!$order){
|
|
$this->error("订单不存在");
|
|
}
|
|
//
|
|
if($order[status_code]!=101){
|
|
$this->error("订单状态不允许取消");
|
|
}
|
|
//调用模型里的取消订单
|
|
$this->table->cancelOrder($order_id,"用户取消订单");
|
|
$this->success("取消成功");
|
|
}
|
|
//用户申请退款
|
|
public function refundOrder($order_id){
|
|
$where["member_id"]=session("member.member_id");
|
|
$where["order_id"]=$order_id;
|
|
$order=$this->table->where($where)->find();
|
|
if(!$order){
|
|
$this->error("订单不存在");
|
|
}
|
|
//查看是否支付
|
|
if($order[is_pay]!=1){
|
|
$this->error("未付款订单不需要申请退款");
|
|
}
|
|
if(M("shop_order_refund")->find($order_id)){
|
|
$this->error("您已经申请过了");
|
|
}
|
|
//增加退款表
|
|
M("shop_order_refund")->add(array(
|
|
"order_id"=>$order_id,
|
|
"is_refund"=>1,
|
|
"is_refund_time"=>time(),
|
|
));
|
|
//改状态
|
|
$this->table->setOrderState($order_id);//改状态
|
|
//写日志
|
|
$this->table->log($order_id,"用户申请退款");
|
|
$this->success("操作成功");
|
|
}
|
|
//删除订单
|
|
public function deleteOrder($order_id){
|
|
$where["member_id"]=session("member.member_id");
|
|
$where["order_id"]=$order_id;
|
|
$order=$this->table->where($where)->find();
|
|
if(!$order){
|
|
$this->error("订单不存在");
|
|
}
|
|
//
|
|
if($order[status_code]!=201){
|
|
$this->error("订单状态不允许删除");
|
|
}
|
|
//调用模型里的取消订单
|
|
$this->table->deleteOrder($order_id);
|
|
$this->success("删除成功");
|
|
}
|
|
//用户确认收货
|
|
public function confirmReceipt($order_id){
|
|
$where["member_id"]=session("member.member_id");
|
|
$where["order_id"]=$order_id;
|
|
$order=$this->table->where($where)->find();
|
|
if(!$order){
|
|
$this->error("订单不存在");
|
|
}
|
|
//
|
|
if($order[status_code]!=103){
|
|
$this->error("订单状态不允许操作");
|
|
}
|
|
//调用模型里的确认收货
|
|
$this->table->confirmReceipt($order_id,"用户确认收货");
|
|
$this->success("取消成功");
|
|
}
|
|
//快递
|
|
public function kuaidi($com,$num){
|
|
$kuaidi=new \Model\KuaidiModel($com, $num);
|
|
$kuaidi_result=$kuaidi->getKuaidi();
|
|
if(!$kuaidi_result){
|
|
$this->error($kuaidi->getError());
|
|
}else{
|
|
$this->data=$kuaidi_result;
|
|
$this->pagetitle="物流查询";
|
|
$this->display();
|
|
}
|
|
}
|
|
} |