403 lines
11 KiB
PHP
Executable File
403 lines
11 KiB
PHP
Executable File
<?php
|
||
namespace wstmart\app\controller;
|
||
use wstmart\common\model\Orders as M;
|
||
use wstmart\common\model\Payments;
|
||
|
||
/**
|
||
* ============================================================================
|
||
* 订单控制器
|
||
*/
|
||
class Orders extends Base{
|
||
// 前置方法执行列表
|
||
protected $beforeActionList = [
|
||
'checkAuth'
|
||
];
|
||
/*********************************************** 用户操作订单 ************************************************************/
|
||
/**
|
||
* 提醒发货
|
||
*/
|
||
public function noticeDeliver(){
|
||
$m = new M();
|
||
return $m->noticeDeliver();
|
||
}
|
||
/**
|
||
* 提交订单
|
||
*/
|
||
public function submit(){
|
||
$m = new M();
|
||
$rs = $m->submit(3);
|
||
exit(json_encode($rs));
|
||
}
|
||
/**
|
||
* 提交虚拟订单
|
||
*/
|
||
public function quickSubmit(){
|
||
$m = new M();
|
||
$rs = $m->quickSubmit();
|
||
return $rs;
|
||
}
|
||
/**
|
||
* 在线支付方式
|
||
*/
|
||
public function succeed(){
|
||
//获取支付方式
|
||
$pa = new Payments();
|
||
$payments = $pa->getByGroup('4',-1,true);//具体支付场景1pc,2wap,3微信,4app
|
||
exit(jsonReturn('',1,$payments));
|
||
// $this->assign('payments',$payments);
|
||
// $this->assign('orderNo',input("get.orderNo"));
|
||
// $this->assign('isBatch',(int)input("get.isBatch/d",0));
|
||
// return $this->fetch("users/orders/orders_pay_list");
|
||
}
|
||
/**
|
||
* 订单管理
|
||
*/
|
||
public function index(){
|
||
$type = input('param.type','');
|
||
$this->assign('type',$type);
|
||
return $this->fetch("users/orders/orders_list");
|
||
}
|
||
public function findExpress(){
|
||
$orderId = (int)input("orderId");
|
||
$userId = $this->getUserId();
|
||
$where['userId'] = $userId;
|
||
if(!$orderId){
|
||
$where['orderStatus'] = 1;//待收货状态
|
||
$orderId = model('orders')->where($where)->max('orderId');
|
||
}else{
|
||
$where['orderId'] = $orderId;
|
||
$find = model('orders')->where($where)->value('orderId');//杜绝别人查看物流情况
|
||
if(!$find){
|
||
exit(jsonReturn('获取失败',-1));
|
||
}
|
||
}
|
||
if($orderId){
|
||
$m = new \addons\kuaidi\model\Kuaidi();
|
||
$rs = $m->getOrderExpress($orderId);
|
||
$express = json_decode($rs, true);
|
||
$state = isset($express["state"])?$express["state"]:'-1';
|
||
$data = $m->getOrderInfo($orderId);
|
||
$data["express"]["stateTxt"] = $this->getExpressState($state);
|
||
$express["express"] = $data["express"];
|
||
$express["goodsImg"] = $data["goodsImg"];
|
||
exit(jsonReturn('',1,$express));
|
||
}else{
|
||
exit(jsonReturn('获取失败',-1));
|
||
}
|
||
|
||
}
|
||
public function getExpressState($state){
|
||
$stateTxt = "";
|
||
switch ($state) {
|
||
case '0':$stateTxt="运输中";break;
|
||
case '1':$stateTxt="揽件";break;
|
||
case '2':$stateTxt="疑难";break;
|
||
case '3':$stateTxt="收件人已签收";break;
|
||
case '4':$stateTxt="已退签";break;
|
||
case '5':$stateTxt="派件中";break;
|
||
case '6':$stateTxt="退回";break;
|
||
default:$stateTxt="暂未获取到状态";break;
|
||
}
|
||
return $stateTxt;
|
||
}
|
||
/**
|
||
* 订单列表
|
||
*/
|
||
public function getOrderList(){
|
||
/*
|
||
-3:拒收、退款列表
|
||
-2:待付款列表
|
||
-1:已取消订单
|
||
0,1: 待收货
|
||
2:待评价/已完成
|
||
*/
|
||
$flag = -1;
|
||
$type = input('param.type');
|
||
$status = [];
|
||
$m = new M();
|
||
if(strpos($type, "zg")===0){
|
||
switch ($type) {
|
||
case 'zgwaitPay':
|
||
$status=[-2];
|
||
break;
|
||
case 'zgwaitDeliver':
|
||
$status=[0];
|
||
break;
|
||
case 'zgwaitReceive':
|
||
$status=[1];
|
||
break;
|
||
case 'zgwaitAppraise':
|
||
$status=[2];
|
||
$flag=0;
|
||
break;
|
||
case 'zgfinish':
|
||
$status=[2];
|
||
break;
|
||
case 'zgabnormal': // 退款/拒收 与取消合并
|
||
$status=[-1,-3];
|
||
break;
|
||
case 'zgall':
|
||
default:
|
||
$status=[-5,-4,-3,-2,-1,0,1,2];
|
||
break;
|
||
}
|
||
$rs = $m->userZgOrdersByPage($status,$flag);
|
||
}else{
|
||
switch ($type) {
|
||
case 'waitPay':
|
||
$status=[-2];
|
||
break;
|
||
case 'waitDeliver':
|
||
$status=[0];
|
||
break;
|
||
case 'waitReceive':
|
||
$status=[1];
|
||
break;
|
||
case 'waitAppraise':
|
||
$status=[2];
|
||
$flag=0;
|
||
break;
|
||
case 'finish':
|
||
$status=[2];
|
||
break;
|
||
case 'abnormal': // 退款/拒收 与取消合并
|
||
$status=[-1,-3];
|
||
break;
|
||
default:
|
||
$status=[-5,-4,-3,-2,-1,0,1,2];
|
||
break;
|
||
}
|
||
$rs = $m->userOrdersByPage($status,$flag);
|
||
}
|
||
foreach($rs['Rows'] as $k=>$v){
|
||
if(!empty($v['list'])){
|
||
foreach($v['list'] as $k1=>$v1){
|
||
$rs['Rows'][$k]['list'][$k1]['goodsImg'] = $v1['goodsImg'];
|
||
}
|
||
}
|
||
}
|
||
// param.pagesize = 10;
|
||
//param.page = Number( $('#currPage').val() ) + 1;
|
||
exit(jsonReturn('',1,$rs));
|
||
}
|
||
|
||
public function confirmHelpSale(){
|
||
$m = new M();
|
||
$id = (int)input('orderId');
|
||
exit(jsonReturn('',1,$m->confirmHelpSale($id)));
|
||
|
||
}
|
||
public function cancelHelpSale(){
|
||
$m = new M();
|
||
$id = (int)input('orderId');
|
||
exit(jsonReturn('',1,$m->cancelHelpSale($id)));
|
||
}
|
||
/**
|
||
* 订单详情
|
||
*/
|
||
public function getDetail(){
|
||
$m = new M();
|
||
$rs = $m->getByView((int)input('id'));
|
||
$rs['status'] = WSTLangOrderStatus($rs['orderStatus']);
|
||
$rs['payInfo'] = WSTLangPayType($rs['payType']);
|
||
$rs['deliverInfo'] = WSTLangDeliverType($rs['deliverType']);
|
||
foreach($rs['goods'] as $k=>$v){
|
||
$v['goodsImg'] = WSTImg($v['goodsImg'],3);
|
||
}
|
||
// 优惠券钩子
|
||
hook('mobileDocumentOrderSummaryView',['rs'=>&$rs]);
|
||
// 满就送钩子
|
||
hook('mobileDocumentOrderViewGoodsPromotion',['rs'=>&$rs]);
|
||
exit(jsonReturn('',1,$rs));
|
||
}
|
||
|
||
/**
|
||
* 用户确认收货
|
||
*/
|
||
public function receive(){
|
||
$m = new M();
|
||
$rs = $m->receive();
|
||
exit(json_encode($rs));
|
||
}
|
||
|
||
/**
|
||
* 获取上传凭证
|
||
*/
|
||
public function getCertificate(){
|
||
$m = new M();
|
||
$rs = $m->viewCertificate();
|
||
exit(json_encode($rs));
|
||
}
|
||
/**
|
||
* 用户上传凭证
|
||
*/
|
||
public function uploadCertificate(){
|
||
$m = new M();
|
||
$rs = $m->uploadCertificate();
|
||
exit(json_encode($rs));
|
||
}
|
||
/**
|
||
* 用户-评价页
|
||
*/
|
||
public function getOrderAppraise(){
|
||
$m = model('Orders');
|
||
$oId = (int)input('oId');
|
||
//根据订单id获取 商品信息
|
||
$data = $m->getOrderInfoAndAppr();
|
||
$data['shopName']=model('shops')->getShopName($oId);
|
||
$data['oId']=$oId;
|
||
exit(jsonReturn('',1,$data));
|
||
}
|
||
/**
|
||
* 用户取消订单
|
||
*/
|
||
public function cancellation(){
|
||
$m = new M();
|
||
$rs = $m->cancel();
|
||
return $rs;
|
||
}
|
||
/**
|
||
* 获取取消订单原因
|
||
* @return [type] [description]
|
||
*/
|
||
public function getCancelCause(){
|
||
exit(jsonReturn("",1,WSTDatas('ORDER_CANCEL')));
|
||
}
|
||
/**
|
||
* 获取拒收订单原因
|
||
* @return [type] [description]
|
||
*/
|
||
public function getRejectCause(){
|
||
exit(jsonReturn("",1,WSTDatas('ORDER_REJECT')));
|
||
}
|
||
/**
|
||
* 获取申请退款原因
|
||
* @return [type] [description]
|
||
*/
|
||
public function getRefundCause(){
|
||
exit(jsonReturn("",1,WSTDatas('REFUND_TYPE')));
|
||
}
|
||
/**
|
||
* 用户拒收订单
|
||
*/
|
||
public function reject(){
|
||
$m = new M();
|
||
$rs = $m->reject();
|
||
exit(json_encode($rs));
|
||
}
|
||
|
||
/**
|
||
* 用户退款
|
||
*/
|
||
public function getRefund(){
|
||
$orderId = (int)input('id');
|
||
$userId = $this->getUserId();
|
||
$orders = model('orders')->where(['orderId'=>$orderId,'userId'=>$userId,'dataFlag'=>1])->field('orderStatus')->find();
|
||
if(empty($orders))return jsonReturn("无效的订单");
|
||
$m = new M();
|
||
$data = $m->getMoneyByOrder($orderId);
|
||
exit(jsonReturn("",1,$data));
|
||
}
|
||
/**
|
||
* 获取快递公司列表
|
||
* @return [type] [description]
|
||
*/
|
||
public function getExpress(){
|
||
$express = model('Express')->listQuery();
|
||
exit(jsonReturn("",1,$express));
|
||
}
|
||
/**
|
||
* 用户-延时收货
|
||
*/
|
||
public function delay(){
|
||
$m = new M();
|
||
$rs = $m->delay();
|
||
return $rs;
|
||
}
|
||
|
||
public function shundaiList()
|
||
{
|
||
$page = input('page/d', 1);
|
||
$size = input('size/d', 10);
|
||
$lat = (float)input("lat",0);
|
||
$lng = (float)input("lng",0);
|
||
$m = new M();
|
||
$status=[0];
|
||
$rs = $m->alias('o')->join('__SHOPS__ s','o.shopId=s.shopId','left')
|
||
->field('o.userAddress, o.userName, o.userPhone, o.deliverMoney,
|
||
o.goodsMoney as feeMoney,o.payTime as deliverBefore,
|
||
s.lng as shopLng, s.lat as shopLat, s.shopAddress, s.phone as shopPhone,
|
||
ROUND(12756.276*ASIN(SQRT(POW(SIN(('.$lat.'*0.0174532925-s.lat*0.0174532925)/2),2)+
|
||
COS('.$lat.'*0.0174532925)*COS(s.lat*0.0174532925)*POW(SIN(('.$lng.'*0.0174532925-s.lng*0.0174532925)/2),2)))*1000) AS distance
|
||
')
|
||
->whereIn('o.orderStatus', $status)
|
||
->where('o.deliverType', '=', 2)
|
||
->order('distance', 'asc')
|
||
->limit(($page-1)*$size, $size)
|
||
->select();
|
||
exit(jsonReturn('',1,$rs));
|
||
}
|
||
|
||
/*********************************************** 商家操作订单 ************************************************************/
|
||
|
||
// /**
|
||
// * 商家-查看订单列表
|
||
// */
|
||
// public function sellerOrder(){
|
||
// $type = input('param.type','');
|
||
// $this->assign('type',$type);
|
||
// $express = model('Express')->listQuery();
|
||
// $this->assign('express',$express);
|
||
// return $this->fetch('users/sellerorders/orders_list');
|
||
// }
|
||
|
||
// /**
|
||
// * 商家-订单列表
|
||
// */
|
||
// public function getSellerOrderList(){
|
||
// /*
|
||
// -3:拒收、退款列表
|
||
// -2:待付款列表
|
||
// -1:已取消订单
|
||
// 0: 待发货
|
||
// 1,2:待评价/已完成
|
||
// */
|
||
// $type = input('param.type');
|
||
// $status = [];
|
||
// switch ($type) {
|
||
// case 'waitPay':
|
||
// $status=-2;
|
||
// break;
|
||
// case 'waitDeliver':
|
||
// $status=0;
|
||
// break;
|
||
// case 'waitReceive':
|
||
// $status=1;
|
||
// break;
|
||
// case 'waitDelivery':
|
||
// $status=0;
|
||
// break;
|
||
// case 'finish':
|
||
// $status=2;
|
||
// break;
|
||
// case 'abnormal': // 退款/拒收 与取消合并
|
||
// $status=[-1,-3];
|
||
// break;
|
||
// default:
|
||
// $status=[-5,-4,-3,-2,-1,0,1,2];
|
||
// break;
|
||
// }
|
||
// $m = new M();
|
||
// $rs = $m->shopOrdersByPage($status);
|
||
// //dump($rs);die;
|
||
// foreach($rs['Rows'] as $k=>$v){
|
||
// if(!empty($v['list'])){
|
||
// foreach($v['list'] as $k1=>$v1){
|
||
// $rs['Rows'][$k]['list'][$k1]['goodsImg'] = $v1['goodsImg'];
|
||
// }
|
||
// }
|
||
// }
|
||
// return $rs;
|
||
// }
|
||
}
|