qa-ifish7/web/Application/Admin/Controller/OrderController.class.php

407 lines
16 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Admin\Controller;
use Think\Controller;
class OrderController extends AdminController{
public function __construct() {
parent::__construct();
$this->table = D("ShopOrder");
$this->status_name = array("未支付",'已支付');
$this->delivery_status_name = array("未发货",'已发货');
$this->distribution_mode=str2arr( C("shop.distribution_mode"),"\r\n",":");
//系统查询哪些超时付款,超时未收货自动做相关操作
$this->table->autoReceipt();
$this->table->autoCancelOrder();
//
}
public function index(){
//下单时间
$start_time = I("get.start_time");
$end_time = I("get.end_time");
if($start_time || $end_time){
$start_time = strtotime($start_time ? $start_time : 0);
$end_time = strtotime(($end_time ? $end_time : date("Y-m-d"))."23:59:59");
$where["addtime"] = array(array("EGT",$start_time),array("ELT",$end_time));
}
//指定字段搜索
$keywords=I("get.keywords");
if($keywords){
$keytype=I("get.keytype");
if($keytype=="order_num"){
$where["order_num"] =$keywords;
}
elseif($keytype=="mobile"){
$where["member_id"] =M("member")->where(array("mobile"=>$keywords))->getField("member_id");
}
elseif($keytype=="member_id"){
$where["member_id"] =M("member")->where(array("member_id"=>$keywords))->getField("member_id");
}
}
//订单状态
$this->status_code=I("get.status_code");
if($this->status_code){
if($this->status_code==101){
$where["status_code"]=array("in","101,111");
}else{
$where["status_code"]=$this->status_code;
}
}
//不同状态下的订单统计
$this->readyPayCount=$this->table->where(array(
"status_code"=>array("in","101,111"),
))->count();
$this->readyDeliveryCount=$this->table->where(array(
"status_code"=>102,
))->count();
$this->readyReceiptCount=$this->table->where(array(
"status_code"=>103,
))->count();
$this->ReceiptCount=$this->table->where(array(
"status_code"=>104,
))->count();
$listRows=C("display.admin_shownum");//每页显示多少条
$total=$this->table->where($where)->count();
$page = new \Think\Page($total,$listRows);
$data=$this->table->relation(true)->where($where)->group("order_id")->order("order_id desc")->limit($page->firstRow,$page->listRows)->select();
$this->assign("listpage", $page->show());
$this->data = $data;
$this->display();
}
public function detail($order_id){
$this->r = $this->table->relation(true)->find($order_id);
$this->pagetitle="订单详情";
$this->display();
}
//商品发货列表
public function goods_delivery(){
$is_delivery=I("is_delivery");
//已发货
if($is_delivery){
$where["is_delivery"]=1;
}else{
$where["status_code"]=102;
}
//订单号
$order_num=I("get.order_num");
if($order_num){
$where["order_num"]=$order_num;
}
//不同状态下的数量
//待发货
$this->readyDeliveryCount=$this->table->where(array(
"status_code"=>102,
))->count();
//已发货
$this->hasDeliveryCount=$this->table->where(array(
"is_delivery"=>1,
))->count();
$listRows=C("display.admin_shownum");//每页显示多少条
$total=$this->table->where($where)->count();
$page = new \Think\Page($total, $listRows);
$data = $this->table->relation("shop_order_address")->where($where)->order("order_id desc")->limit($page->firstRow, $page->listRows)->select();
$listpage = $page->show();
$this->assign("listpage", $listpage);
$this->data = $data;
$this->display();
}
//商品发货
public function goods_delivery_add(){
if(IS_POST){
$order_id = I("post.order_id");
$order=$this->table->find($order_id);
$express_company_code = I("post.express_company_code");
$express_company_num = I("post.express_company_num");
if(!$order){$this->error("订单不存在");}
if(!$express_company_code){$this->error("请选择物流公司");}
if(!$express_company_num){$this->error("请输入物流单号");}
if(I("post.invoice_as")){
$shop_order_invoice_address=array(
"express_company_code"=>$express_company_code,
"express_company_num"=>$express_company_num,
);
}
$delivery_time=$order["delivery_time"]?$order["delivery_time"]:time();
$data=array(
"order_id"=>$order_id,
"delivery_time"=>$delivery_time,
"is_delivery"=>1,
"shop_order_address"=>array(
"express_company_code"=>$express_company_code,
"express_company_num"=>$express_company_num,
),
"shop_order_invoice_address"=>$shop_order_invoice_address,
);
$this->table->relation(true)->save($data);
$this->table->setOrderState($order_id);//改状态
//写日志
$this->table->log($order_id,"商品发货");
$this->success();
}else{
$order_id = I("order_id");
$this->data = $this->table->relation(true)->find($order_id);
$this->display();
}
}
//发票发货列表
public function invoice_delivery(){
$is_delivery=I("is_delivery");
//已发货查询条件
$is_where="db_shop_order_invoice_address.express_company_num is not null and is_delivery=1";
//未发货查询条件
$not_where="db_shop_order_invoice_address.express_company_num is null and status_code=102";
//已发货
if($is_delivery){
$where=$is_where;
}else{
$where=$not_where;
}
//订单号
$order_num=I("get.order_num");
if($order_num){
$where.=" and order_num=".$order_num;
}
//不同状态下的数量
//待发货
$this->readyDeliveryCount=$this->table->join("db_shop_order_invoice_address on db_shop_order_invoice_address.order_id=db_shop_order.order_id")->where($not_where)->count();
//已发货
$this->hasDeliveryCount=$this->table->join("db_shop_order_invoice_address on db_shop_order_invoice_address.order_id=db_shop_order.order_id")->where($is_where)->count();
$listRows=C("display.admin_shownum");//每页显示多少条
$total=$this->table->join("db_shop_order_invoice_address on db_shop_order_invoice_address.order_id=db_shop_order.order_id")->where($where)->count();
$page = new \Think\Page($total, $listRows);
$data = $this->table->relation("shop_order_invoice_address")->join("db_shop_order_invoice_address on db_shop_order_invoice_address.order_id=db_shop_order.order_id")->where($where)->order("db_shop_order.order_id desc")->limit($page->firstRow, $page->listRows)->select();
$listpage = $page->show();
$this->assign("listpage", $listpage);
$this->data = $data;
$this->display();
}
//发票发货
public function invoice_delivery_add(){
if(IS_POST){
$order_id = I("post.order_id");
$express_company_code = I("post.express_company_code");
$express_company_num = I("post.express_company_num");
if(!$order_id){$this->error("缺少订单号");}
if(!$express_company_code){$this->error("请选择物流公司");}
if(!$express_company_num){$this->error("请输入物流单号");}
$data=array(
"order_id"=>$order_id,
"is_delivery"=>1,
"shop_order_invoice_address"=>array(
"express_company_code"=>$express_company_code,
"express_company_num"=>$express_company_num,
),
);
$this->table->relation(true)->save($data);
$this->table->setOrderState($order_id);//改状态
//写日志
$this->table->log($order_id,"发票邮寄");
$this->success();
}else{
$order_id = I("order_id");
$this->data = $this->table->relation("shop_order_invoice_address")->find($order_id);
$this->display();
}
}
//修改订单价格
public function editor_price(){
if(IS_POST){
$order_id = I("post.order_id");
$new_money = I("post.new_money","intval",0);
if(!$new_money){
$this->error("请输入正确的价格");
}
$new_money= number_format($new_money,2, '.', '');
$where["order_id"]=$order_id;
$order=$this->table->where($where)->find();
if(!$order){
$this->error("订单不存在");
}
//只有待付款状态下才可以改价
if($order[status_code]!=101&&$order[status_code]!=111){
$this->error("当前的订单状态不允许改价");
}
$this->table->save(array(
"order_id"=>$order_id,
"pay_money"=>$new_money,
));
//写日志
$this->table->log($order_id,"后台用户[".session("user_name")."]修改价格,原价:{$order[pay_money]},修改后:{$new_money}");
$this->success();
}else{
$order_id = I("get.order_id");
$this->r=$this->table->find($order_id);
$this->pagetitle="修改价格";
$this->display();
}
}
//线下付款-确认
public function isBankPay(){
$order_id = I("get.order_id");
$where["order_id"]=$order_id;
$order=$this->table->where($where)->find();
if(!$order){
$this->error("订单不存在");
}
if($order[status_code]!=111){
$this->error("当前操作不充许");
}
$this->table->save(array(
"order_id"=>$order_id,
"is_pay"=>1,
));
//改状态
$this->table->setOrderState($order_id);//改状态
//写日志
$this->table->log($order_id,"后台用户[".session("user_name")."]确认客户已付款");
$this->success();
}
//订单日志
public function log($order_id){
$this->data=M("shop_order_log")->where(array(
"order_id"=>$order_id
))->order("addtime asc")->select();
$this->pagetitle="订单日志";
$this->display();
}
//删除订单2针对对公转账的订单删除
public function delete2(){
$order_id = I("get.order_id");
$where["order_id"]=$order_id;
$order=$this->table->where($where)->find();
if(!$order){
$this->error("订单不存在");
}
if($order[status_code]!=111){
$this->error("订单状态不允许删除");
}
//调用模型里的删除订单
$this->table->deleteOrder($order_id);
$this->success("删除成功");
}
//删除订单
public function delete(){
$order_id = I("get.order_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 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();
}
}
//退款订单列表
public function refundOrder(){
//订单状态
$this->status_code=I("get.status_code");
if($this->status_code){
$where["status_code"]=$this->status_code;
}
//订单号
$order_num=I("get.order_num");
if($order_num){
$where["order_num"]=$order_num;
}
//不同状态下的数量
//待处理的
$this->readCount=$this->table->where(array(
"status_code"=>301,
))->count();
//同意的
$this->agreeCount=$this->table->where(array(
"status_code"=>302,
))->count();
//不同意的
$this->disagreeCount=$this->table->where(array(
"status_code"=>311,
))->count();
//已发货
$listRows=C("display.admin_shownum");//每页显示多少条
$total=$this->table->join("db_shop_order_refund on db_shop_order_refund.order_id=db_shop_order.order_id")->where($where)->count();
$page = new \Think\Page($total, $listRows);
$data = $this->table->relation("member")->join("db_shop_order_refund on db_shop_order_refund.order_id=db_shop_order.order_id")->where($where)->order("db_shop_order.order_id desc")->limit($page->firstRow, $page->listRows)->select();
$listpage = $page->show();
$this->assign("listpage", $listpage);
$this->data = $data;
$this->display();
}
//同意退款
public function agree_refund($order_id){
$where["order_id"]=$order_id;
$order=$this->table->where($where)->find();
if(!$order){
$this->error("订单不存在");
}
if($order[status_code]!=301){
$this->error("订单状态不允许删除");
}
//查询shop_order_payment表是否有付款数据
$payment=M("shop_order_payment")->find($order_id);
//线上支付
if($payment){
//支付宝原路返款
if($payment["paytype"]=="alipay"){
$result=$this->table->alipayRefund($payment);
if(!$result){
$this->error("退款失败,支付宝返回错误提示:".$this->table->getError());
}
$log_content="后台用户[".session("user_name")."]同意客户退款,并且已通过支付宝原路退款!";
}
//修改退款表
M("shop_order_refund")->save(array(
"order_id"=>$order_id,
"is_rerund_agree"=>1,
"is_back_money"=>1,
));
//线下支付
}else{
//修改退款表
M("shop_order_refund")->save(array(
"order_id"=>$order_id,
"is_rerund_agree"=>1,
));
$log_content="后台用户[".session("user_name")."]同意客户退款,用户通过线下付款的,需要人工退还款项!";
}
//改状态
$this->table->setOrderState($order_id);//改状态
//写日志
$this->table->log($order_id,$log_content);
$this->success("操作成功");
}
//不同意退款
public function disagree_refund($order_id){
$where["order_id"]=$order_id;
$order=$this->table->where($where)->find();
if(!$order){
$this->error("订单不存在");
}
if($order[status_code]!=301){
$this->error("订单状态不允许删除");
}
M("shop_order_refund")->save(array(
"order_id"=>$order_id,
"is_rerund_disagree"=>1,
));
//改状态
$this->table->setOrderState($order_id);//改状态
//写日志
$this->table->log($order_id,"后台用户[".session("user_name")."]不同意客户退款");
$this->success("操作成功");
}
}