962 lines
47 KiB
PHP
962 lines
47 KiB
PHP
<?php
|
||
namespace app\controllers\channel;
|
||
use Yii;
|
||
use Illuminate\Support\Facades\DB;
|
||
use app\models\common\Statistics;
|
||
use app\models\common\Store;
|
||
use app\models\common\Config;
|
||
use app\models\common\StoreBill;
|
||
use app\models\common\Export;
|
||
use app\models\common\Printing;
|
||
use app\models\common\WeChat;
|
||
use app\models\common\Bill;
|
||
|
||
class StoreBillController extends CommonController{
|
||
public $enableCsrfValidation = false;
|
||
private $shop_id;
|
||
function init(){
|
||
parent::init();
|
||
$result=axios_request();
|
||
$this->shop_id=$result['storeId']?:Store::getMainStore($this->wqData['uniacid'])['id'];
|
||
}
|
||
public function actionAssets(){
|
||
$startTime=mktime(0,0,0,date('m'),date('d'),date('Y'));
|
||
$endTime=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
|
||
$beforeStartTime=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
|
||
$beforeEndTime=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
|
||
$uniacid=$this->wqData['uniacid'];
|
||
$result=axios_request();
|
||
$dataArr=Statistics::getTimeArr(date("Y-m-d"));
|
||
if($result['time']){
|
||
if($result['type']==1){
|
||
//自然日
|
||
$startTime=strtotime($result['time']." 00:00:00");
|
||
$endTime=strtotime($result['time']." 23:59:59");
|
||
$beforeStartTime=strtotime($result['time']." 00:00:00 -1day");
|
||
$beforeEndTime=strtotime($result['time']." 23:59:59 -1day");
|
||
$dataArr=Statistics::getTimeArr($result['time']);
|
||
}
|
||
if($result['type']==2){
|
||
//自然月
|
||
$numArr=explode('-',$result['time']);
|
||
$timeArr=mFristAndLast($numArr[0],$numArr[1]);
|
||
$startTime=$timeArr[0]['startTime'];
|
||
$endTime=$timeArr[0]['endTime'];
|
||
$before=strtotime($result['time']." -1month");
|
||
$beforeTimeArr=mFristAndLast(date("Y",$before),date("m",$before));
|
||
$beforeStartTime=$beforeTimeArr['startTime'];
|
||
$beforeEndTime=$beforeTimeArr['endTime'];
|
||
$dataArr=Statistics::getDayArr($result['time']);
|
||
}
|
||
}
|
||
|
||
for($i=0;$i<count($dataArr);$i++){
|
||
$dataArr[$i]['payMoney']=Statistics::getPayMoney($uniacid,$result['storeId'],$dataArr[$i]['startTime'],$dataArr[$i]['endTime']);
|
||
$dataArr[$i]['payNum']=Statistics::getPayNum($uniacid,$result['storeId'],$dataArr[$i]['startTime'],$dataArr[$i]['endTime']);
|
||
}
|
||
$data['data']=$dataArr;
|
||
// return $this->result(1,'成功',$data);
|
||
$data['payMoney']=Statistics::getPayMoney($uniacid,$result['storeId'],$startTime,$endTime);
|
||
$data['payNum']=Statistics::getPayNum($uniacid,$result['storeId'],$startTime,$endTime);
|
||
$data['payPeople']=Statistics::getPayPeople($uniacid,$result['storeId'],$startTime,$endTime);
|
||
$data['unitPrice']=Statistics::getUnitPrice($uniacid,$result['storeId'],$startTime,$endTime);
|
||
$data['visitCount']=Statistics::getVisitCount($uniacid,$result['storeId'],$startTime,$endTime);
|
||
$data['views']=Statistics::getViews($uniacid,$result['storeId'],$startTime,$endTime);
|
||
$data['beforePayMoney']=Statistics::getPayMoney($uniacid,$result['storeId'],$beforeStartTime,$beforeEndTime);
|
||
$data['beforePayNum']=Statistics::getPayNum($uniacid,$result['storeId'],$beforeStartTime,$beforeEndTime);
|
||
$data['beforePayPeople']=Statistics::getPayPeople($uniacid,$result['storeId'],$beforeStartTime,$beforeEndTime);
|
||
$data['beforeUnitPrice']=Statistics::getUnitPrice($uniacid,$result['storeId'],$beforeStartTime,$beforeEndTime);
|
||
$data['beforeVisitCount']=Statistics::getVisitCount($uniacid,$result['storeId'],$beforeStartTime,$beforeEndTime);
|
||
$data['beforeViews']=Statistics::getViews($uniacid,$result['storeId'],$beforeStartTime,$beforeEndTime);
|
||
return $this->result(1,'成功',$data);
|
||
}
|
||
|
||
|
||
//查看商家余额
|
||
public function actionStoreBill(){
|
||
$result=axios_request();
|
||
$storeId=$result['storeId']?:$this->shop_id;
|
||
$res=StoreBill::getMerchantMoney($this->wqData['uniacid'],$storeId);
|
||
return $this->result(1,'成功',$res);
|
||
|
||
}
|
||
//待结算
|
||
public function actionWaitMoney(){
|
||
$result=axios_request();
|
||
$storeId=$result['storeId']?:$this->shop_id;
|
||
$uniacid=$this->wqData['uniacid'];
|
||
$res=StoreBill::waitMoney($uniacid,$storeId);
|
||
return $this->result(1,'成功',$res);
|
||
}
|
||
//所有账单
|
||
public function actionBillList(){
|
||
$result=axios_request();
|
||
$storeId=$result['storeId']?:$this->shop_id;
|
||
$timeType=$result['timeType'];
|
||
$uniacid=$this->wqData['uniacid'];
|
||
$res=StoreBill::billList($uniacid,$storeId,$result['page'],$result['size']?:20,$this->timeArr[$timeType]['startTime'],$this->timeArr[$timeType]['endTime']);
|
||
return $this->result(1,'成功',$res['list'],$res['count']);
|
||
}
|
||
//堂食账单详情
|
||
public function actionInStoreBillInfo(){
|
||
$result=axios_request();
|
||
$storeId=$result['storeId']?:$this->shop_id;
|
||
$uniacid=$this->wqData['uniacid'];
|
||
$startTime=strtotime($result['time']." 00:00:00");
|
||
$endTime=strtotime($result['time']." 23:59:59");
|
||
$data['inStoreCashierData']=Statistics::inStoreData($uniacid,5,$storeId,$startTime,$endTime);
|
||
$data['inStoreFastData']=Statistics::inStoreData($uniacid,6,$storeId,$startTime,$endTime);
|
||
$data['inStoreData']=Statistics::inStoreData($uniacid,7,$storeId,$startTime,$endTime);
|
||
$rate=Bill::getStoreRate($storeId);
|
||
if($rate['type']==1){
|
||
$fastPlatformProportion=$rate['fastPlatformProportion']?:0;
|
||
$inStorePlatformProportion=$rate['inStorePlatformProportion']?:0;
|
||
$cashierPlatformProportion=$rate['cashierPlatformProportion']?:0;
|
||
$data['rate']='当面付:'.$cashierPlatformProportion."% 快餐:".$fastPlatformProportion."% 店内:".$inStorePlatformProportion."%";
|
||
}else{
|
||
$cashierFixedMoney=$rate['cashierFixedMoney']?:0;
|
||
$fastFixedMoney=$rate['fastFixedMoney']?:0;
|
||
$inStoreFixedMoney=$rate['inStoreFixedMoney']?:0;
|
||
$data['rate']='当面付:'.$cashierFixedMoney."元 快餐:".$fastFixedMoney."元 店内:".$inStoreFixedMoney."元";
|
||
}
|
||
$moneyData=(new \yii\db\Query())
|
||
->select(['sum(IF(origin=5,(money-storeActualMoney+subsidy),0))cashierServiceMoney','sum(IF(origin=6,(money-storeActualMoney+subsidy),0))fastServiceMoney','sum(IF(origin=7,(money-storeActualMoney+subsidy),0))inStoreServiceMoney','sum(money-storeActualMoney+subsidy)serviceMoney'])
|
||
->from('{{%ybwm_bill}}')
|
||
->where('(payType=1 || payPort=2) AND (refundMoney=0 or refundMoney is null) AND uniacid=:uniacid AND storeId=:storeId AND statisticsAt>=:startTime AND statisticsAt<=:endTime',
|
||
['startTime'=>$startTime,'endTime'=>$endTime,':uniacid'=>$uniacid,'storeId'=>$storeId])
|
||
->one();
|
||
$data['cashierServiceMoney']=$moneyData['cashierServiceMoney']?:0;//收银服务费
|
||
$data['fastServiceMoney']=$moneyData['fastServiceMoney']?:0;//快餐服务费
|
||
$data['inStoreServiceMoney']=$moneyData['inStoreServiceMoney']?:0;//店内服务费
|
||
$data['serviceMoney']=$moneyData['serviceMoney']?:0;//总服务费
|
||
return $this->result(1,'成功',$data);
|
||
}
|
||
//账单详情
|
||
public function actionBillInfo(){
|
||
$result=axios_request();
|
||
$storeId=$result['storeId']?:$this->shop_id;
|
||
$type=$result['type']?:1;
|
||
$uniacid=$this->wqData['uniacid'];
|
||
$startTime=strtotime($result['time']." 00:00:00");
|
||
$endTime=strtotime($result['time']." 23:59:59");
|
||
$res=StoreBill::newBillInfo($uniacid,$storeId,$type,$startTime,$endTime);
|
||
return $this->result(1,'成功',$res);
|
||
}
|
||
//店内订单概况
|
||
public function actionBillInStoreOrderInfo(){
|
||
$result=axios_request();
|
||
$storeId=$result['storeId']?:$this->shop_id;
|
||
$uniacid=$this->wqData['uniacid'];
|
||
$page=$result['page']?:1;
|
||
$type=$result['type']?:1;
|
||
$num=($page-1)*10;
|
||
$limit=10;
|
||
$startTime=strtotime($result['time']." 00:00:00");
|
||
$endTime=strtotime($result['time']." 23:59:59");
|
||
if($type==1){
|
||
//当面付
|
||
$table = (new \yii\db\Query())
|
||
->select(['(a.money-a.storeActualMoney+a.subsidy) as serviceMoney','a.subsidy','m.portrait','b.profitSharing','b.profitSharingState','a.orderId','a.payMode','a.outTradeNo', 'b.origin', 'a.storeActualMoney', 'a.money', 'from_unixtime(b.payAt) payAt','a.userId','m.userName','b.userNote'])
|
||
->from('{{%ybwm_bill}} as a')
|
||
->join('LEFT JOIN', '{{%ybwm_cashier_order}} as b', 'b.outTradeNo = a.outTradeNo')
|
||
->join('LEFT JOIN', '{{%ybwm_member}} as m', 'm.id = a.userId')
|
||
->where('a.uniacid=:uniacid AND a.storeId=:storeId AND a.statisticsAt>=:startTime AND a.statisticsAt<=:endTime AND a.origin=5',
|
||
['startTime' => $startTime, 'endTime' => $endTime, ':uniacid' => $uniacid, 'storeId' => $storeId]);
|
||
$count=$table->count();
|
||
$res=$table->offset($num)
|
||
->limit($limit)->orderBy('a.id desc')->all();
|
||
$exportName='当面付订单概况';
|
||
}
|
||
if($type==2){
|
||
//快餐
|
||
$table = (new \yii\db\Query())
|
||
->select(['ifnull(b.originMoney+b.tablewareMoney,0) as originMoney','ifnull((b.originMoney+b.tablewareMoney)-b.money,0) as discountMoney'
|
||
,'b.state','(a.money-a.storeActualMoney+a.subsidy) as serviceMoney','a.subsidy','m.portrait','b.profitSharing','b.profitSharingState',
|
||
'a.orderId','a.userId','m.userName','b.userNote','b.people','b.isOut','a.outTradeNo','b.takeNo',
|
||
'b.origin','a.money','a.payMode','from_unixtime(b.payAt) payAt','a.storeActualMoney'])
|
||
->from('{{%ybwm_bill}} as a')
|
||
->join('LEFT JOIN', '{{%ybwm_instore_order}} as b', 'b.outTradeNo = a.outTradeNo')
|
||
->join('LEFT JOIN', '{{%ybwm_member}} as m', 'm.id = a.userId')
|
||
->where('a.uniacid=:uniacid AND a.storeId=:storeId AND a.statisticsAt>=:startTime AND a.statisticsAt<=:endTime AND a.origin=6',
|
||
['startTime' => $startTime, 'endTime' => $endTime, ':uniacid' => $uniacid, 'storeId' => $storeId]);
|
||
$count=$table->count();
|
||
$res=$table->offset($num)
|
||
->limit($limit)->orderBy('a.id desc')->all();
|
||
$exportName='快餐订单概况';
|
||
}
|
||
if($type==3){
|
||
//店内
|
||
$table = (new \yii\db\Query())
|
||
->select(['ifnull(b.originMoney+b.tablewareMoney,0) as originMoney','ifnull((b.originMoney+b.tablewareMoney)-b.money,0) as discountMoney','b.eatType','b.state','(a.money-a.storeActualMoney+a.subsidy) as serviceMoney','a.subsidy','m.portrait','b.profitSharing',
|
||
'b.profitSharingState','a.orderId','a.userId','m.userName','b.userNote','b.people','a.outTradeNo','b.takeNo','b.origin',
|
||
'a.money','a.payMode','from_unixtime(b.payAt) payAt','a.storeActualMoney'])
|
||
->from('{{%ybwm_bill}} as a')
|
||
->join('LEFT JOIN', '{{%ybwm_instore_order}} as b', 'b.outTradeNo = a.outTradeNo')
|
||
->join('LEFT JOIN', '{{%ybwm_member}} as m', 'm.id = a.userId')
|
||
->where('a.uniacid=:uniacid AND a.storeId=:storeId AND a.statisticsAt>=:startTime AND a.statisticsAt<=:endTime AND a.origin=7',
|
||
['startTime' => $startTime, 'endTime' => $endTime, ':uniacid' => $uniacid, 'storeId' => $storeId]);
|
||
$count=$table->count();
|
||
$res=$table->offset($num)
|
||
->limit($limit)->orderBy('a.id desc')->all();
|
||
$exportName='店内订单概况';
|
||
}
|
||
if($result['action']=='export'){
|
||
$storeInfo=(new \yii\db\Query())->select('name')->from('{{%ybwm_store}}')
|
||
->where(['id'=>$storeId])->one();
|
||
$storeName=$storeInfo['name'];
|
||
$fileName=date('Y.m.d',$startTime).'-'.date('Y.m.d',$endTime).'('.$storeName.')'.$exportName;
|
||
$data=(clone $table)->all();
|
||
$newData=[];
|
||
foreach ($data as $v){
|
||
if($v['state']==3){
|
||
$stateName='已完成';
|
||
}
|
||
if($v['state']==4){
|
||
$stateName='已取消';
|
||
}
|
||
if($v['state']==5){
|
||
$stateName='已退款';
|
||
}
|
||
switch ($v['origin']){
|
||
case 1;
|
||
$originName='微信小程序';
|
||
break;
|
||
case 2; $originName='支付宝';
|
||
break;
|
||
case 3;
|
||
break;
|
||
case 4;
|
||
break;
|
||
case 5;$originName='收银台下单';
|
||
break;
|
||
}
|
||
$newData[]=array(
|
||
'takeNo'=>'#'.$v['takeNo'],
|
||
'origin'=>$originName,
|
||
'originMoney'=>$v['originMoney'],
|
||
'discountMoney'=>$v['discountMoney'],
|
||
'money'=>$v['money'],
|
||
'serviceMoney'=>$v['serviceMoney'],
|
||
'storeActualMoney'=>$v['storeActualMoney'],
|
||
'stateName'=>$stateName,
|
||
);
|
||
}
|
||
$title=['订单序号','订单来源','应收金额','优惠金额','实付金额','平台服务费','预计收入','订单状态'];
|
||
exportExcel($title, $newData, $fileName, $savePath='./', $isDown=true);
|
||
}
|
||
for($i=0;$i<count($res);$i++) {//待完成 已完成 已退款
|
||
$res[$i]['profitSharingMsgState'] = 0;//无
|
||
if ($res[$i]['profitSharing'] == 1 AND $res[$i]['profitSharingState'] == 1) {
|
||
$res[$i]['profitSharingMsgState'] = 1;//已分账
|
||
} elseif ($res[$i]['profitSharing'] == 1 AND $res[$i]['profitSharingState'] == 3 AND ($res[$i]['state'] == 5 || $res[$i]['state'] == 6) ) {
|
||
$res[$i]['profitSharingMsgState'] = 2;//已完结分账
|
||
}elseif ($res[$i]['profitSharing'] == 1) {
|
||
$res[$i]['profitSharingMsgState'] = 3;//完结分账按钮
|
||
}
|
||
if ($res[$i]['payMode'] == 1) {
|
||
$res[$i]['payModeName'] = '微信支付';
|
||
}elseif ($res[$i]['payMode'] == 2) {
|
||
$res[$i]['payModeName'] = '支付宝支付';
|
||
} elseif ($res[$i]['payMode'] == 5) {
|
||
$res[$i]['payModeName'] = '余额支付';
|
||
}elseif ($res[$i]['payMode'] == 6) {
|
||
$res[$i]['payModeName'] = '线下支付';
|
||
}elseif ($res[$i]['payMode'] == 7) {
|
||
$res[$i]['payModeName'] = '自有pos机';
|
||
}elseif ($res[$i]['payMode'] == 8) {
|
||
$res[$i]['payModeName'] = '自由微信';
|
||
}elseif ($res[$i]['payMode'] == 9) {
|
||
$res[$i]['payModeName'] = '自由支付宝';
|
||
}
|
||
}
|
||
return $this->result(1,'成功',$res,$count);
|
||
}
|
||
//订单概况
|
||
public function actionBillOrderInfo(){
|
||
$result=axios_request();
|
||
$storeId=$result['storeId']?:$this->shop_id;
|
||
$uniacid=$this->wqData['uniacid'];
|
||
$page=$result['page']?:1;
|
||
$type=$result['type']?:1;
|
||
$num=($page-1)*10;
|
||
$limit=10;
|
||
$startTime=strtotime($result['time']." 00:00:00");
|
||
$endTime=strtotime($result['time']." 23:59:59");
|
||
if($type==1){
|
||
$table = (new \yii\db\Query())
|
||
->select(['ifnull(b.originMoney+b.boxMoney+b.deliveryMoney+b.deliveryPreferential,0) as originMoney','ifnull((b.originMoney+b.boxMoney+b.deliveryMoney+b.deliveryPreferential)-b.money,0) as discountMoney','a.subsidy','a.orderId','b.profitSharing','b.profitSharingState','b.preferentialMoney','b.newMoney','b.deliveryPreferential','IFNULL(b.platformCouponPreferential,0) platformCouponPreferential','IFNULL(b.couponPreferential,0) couponPreferential','(b.preferentialMoney+b.newMoney+b.deliveryPreferential+IFNULL(b.platformCouponPreferential,0)+IFNULL(b.couponPreferential,0)) allPreferential','a.payMode','b.deliveryMode','b.takeNo','b.state','a.outTradeNo', 'a.origin', 'a.storeActualMoney', 'a.storeDeliveryMoney', 'a.storeBoxMoney', 'a.storeGoodsMoney', 'a.money', 'TRUNCATE(a.money-a.storeActualMoney+a.subsidy,2) serviceMoney', 'from_unixtime(a.createdAt) createdAt'])
|
||
->from('{{%ybwm_bill}} as a')
|
||
->join('LEFT JOIN', '{{%ybwm_takeout_order}} as b', 'b.outTradeNo = a.outTradeNo')
|
||
->where('a.uniacid=:uniacid AND a.storeId=:storeId AND a.statisticsAt>=:startTime AND a.statisticsAt<=:endTime AND a.origin=1',
|
||
['startTime' => $startTime, 'endTime' => $endTime, ':uniacid' => $uniacid, 'storeId' => $storeId]);
|
||
$count=$table->count();
|
||
$res=$table->offset($num)
|
||
->limit($limit)->orderBy('a.id desc')->all();
|
||
|
||
for($i=0;$i<count($res);$i++) {
|
||
$res[$i]['profitSharingMsgState'] = 0;//无
|
||
if ($res[$i]['profitSharing'] == 1 AND $res[$i]['profitSharingState'] == 1) {
|
||
$res[$i]['profitSharingMsgState'] = 1;//已分账
|
||
} elseif ($res[$i]['profitSharing'] == 1 AND $res[$i]['profitSharingState'] == 3 AND ($res[$i]['state'] == 5 || $res[$i]['state'] == 6) ) {
|
||
$res[$i]['profitSharingMsgState'] = 2;//已完结分账
|
||
}elseif ($res[$i]['profitSharing'] == 1) {
|
||
$res[$i]['profitSharingMsgState'] = 3;//完结分账按钮
|
||
}
|
||
$res[$i]['payModeName']=$this->payMode[$res[$i]['payMode']];
|
||
}
|
||
}else{
|
||
$table = (new \yii\db\Query())
|
||
->select('a.outTradeNo,a.origin,a.money,a.payMode,b.userName,a.userId,from_unixtime(a.createdAt) createdAt,a.storeActualMoney')
|
||
->from('{{%ybwm_bill}} as a')
|
||
->join('LEFT JOIN', '{{%ybwm_member}} as b', 'b.id = a.userId')
|
||
->where('a.uniacid=:uniacid AND a.storeId=:storeId AND a.statisticsAt>=:startTime AND a.statisticsAt<=:endTime AND a.origin not in (1,5,6,7)',
|
||
['startTime' => $startTime, 'endTime' => $endTime, ':uniacid' => $uniacid, 'storeId' => $storeId]);
|
||
$count=$table->count();
|
||
$res=$table->offset($num)
|
||
->limit($limit)->orderBy('a.id desc')->all();
|
||
|
||
for($i=0;$i<count($res);$i++) {
|
||
$res[$i]['payModeName']=$this->payMode[$res[$i]['payMode']];
|
||
if ($res[$i]['origin'] == 4) {
|
||
$res[$i]['originName'] = '券包';
|
||
}
|
||
}
|
||
}
|
||
|
||
return $this->result(1,'成功',$res,$count);
|
||
}
|
||
//订单概况详情
|
||
public function actionBillOrderDetails(){
|
||
$result=axios_request();
|
||
$order = (new \yii\db\Query())
|
||
->select(['a.outTradeNo','from_unixtime(b.createdAt) createdAt','from_unixtime(b.completeAt) completeAt',
|
||
'from_unixtime(a.entryAt) entryAt','b.receivedName','b.receivedAddress','b.receivedTel','b.origin','a.orderId','a.storeActualMoney',
|
||
'b.appointment','b.takeNo','b.deliveryMode','b.preferentialMoney','b.couponPreferential',
|
||
'b.platformCouponPreferential','b.newMoney','b.originMoney','a.storeGoodsMoney',
|
||
'TRUNCATE(b.originMoney-a.storeGoodsMoney,2) serviceGoodsMoney','b.boxMoney',
|
||
'a.storeBoxMoney','TRUNCATE(b.boxMoney-a.storeBoxMoney,2) serviceBoxMoney',
|
||
'b.deliveryMoney','a.storeDeliveryMoney','TRUNCATE(b.deliveryMoney-a.storeDeliveryMoney,2) serviceDeliveryMoney'])
|
||
->from('{{%ybwm_bill}} as a')
|
||
->join('LEFT JOIN', '{{%ybwm_takeout_order}} as b', 'b.outTradeNo = a.outTradeNo')
|
||
->where('a.outTradeNo=:outTradeNo', ['outTradeNo' => $result['outTradeNo']])
|
||
->one();
|
||
$goods=(new \yii\db\Query())
|
||
->from('{{%ybwm_order_goods}}')
|
||
->where('orderId=:orderId and item=1', ['orderId' => $order['orderId']])
|
||
->all();
|
||
for($i=0;$i<count($goods);$i++){
|
||
$goods[$i]['material']=json_decode($goods[$i]['material'],true);
|
||
$goods[$i]['attribute']=json_decode($goods[$i]['attribute'],true);
|
||
}
|
||
$order['goodsArr']=$goods;
|
||
// print_R($order);die;
|
||
return $this->result(1,'成功',$order);
|
||
|
||
}
|
||
|
||
//提现
|
||
public function actionWithdrawal(){
|
||
|
||
$result=axios_request();
|
||
$storeId=$result['storeId']?:$this->shop_id;
|
||
$uniacid=$this->wqData['uniacid'];
|
||
$money=$result['money'];//提现金额
|
||
$withdrawal=Config::getSystemSet('withdrawal',$uniacid);//获取提现设置
|
||
$downMoney=$withdrawal['downMoney']?:0;
|
||
if($money<$downMoney){
|
||
return $this->result(2,'最低提现'.$downMoney.'元');
|
||
}
|
||
$record=(new \yii\db\Query())
|
||
->from('{{%ybwm_store_finance}}')
|
||
->where('storeId=:storeId',[':storeId'=>$storeId])
|
||
->orderBy('id desc')
|
||
->one();
|
||
if (time() < $record['createdAt'] + $withdrawal['day'] * 24 * 3600) {
|
||
return $this->result(2, '提现周期未到,不可提现');
|
||
}
|
||
$storeWithdrawal=Config::getStoreSet('withdrawal',$storeId);//获取商家提现设置
|
||
if(!$storeWithdrawal){
|
||
return $this->result(2, '商家提现方式未设置');
|
||
}
|
||
$balance=StoreBill::getMerchantMoney($uniacid,$storeId);//获取商家余额
|
||
if($balance['money']<$money){
|
||
return $this->result(2, '商家余额不足');
|
||
}
|
||
|
||
if($storeWithdrawal['type']==1){
|
||
//微信
|
||
$account['userId']=$storeWithdrawal['userId'];
|
||
$account['wxTel']=$storeWithdrawal['wxTel'];
|
||
$account['wxImg']=$storeWithdrawal['wxImg'];
|
||
}
|
||
if($storeWithdrawal['type']==2){
|
||
//支付宝
|
||
$account['aliTel']=$storeWithdrawal['aliTel'];
|
||
$account['aliAccount']=$storeWithdrawal['aliAccount'];
|
||
$account['aliUserName']=$storeWithdrawal['aliUserName'];
|
||
$account['aliImg']=$storeWithdrawal['aliImg'];
|
||
}
|
||
if($storeWithdrawal['type']==3){
|
||
//银行卡
|
||
$account['bankTel']=$storeWithdrawal['bankTel'];
|
||
$account['bankName']=$storeWithdrawal['bankName'];
|
||
$account['subBank']=$storeWithdrawal['subBank'];
|
||
$account['bankUserName']=$storeWithdrawal['bankUserName'];
|
||
$account['bankAccount']=$storeWithdrawal['bankAccount'];
|
||
}
|
||
$data['money']=$money;
|
||
$charge=0;
|
||
if($withdrawal['rate']>0){
|
||
$charge = bcmul($money, $withdrawal['rate'] / 100, 2);
|
||
if ($charge < $withdrawal['rateDownMoney']) {
|
||
$charge = $withdrawal['rateDownMoney'];
|
||
}
|
||
if ($charge > $withdrawal['rateUpMoney']) {
|
||
$charge = $withdrawal['rateUpMoney'];
|
||
}
|
||
}
|
||
$data['account']=json_encode($account);
|
||
$data['charge']=$charge?:0.00;//手续费
|
||
$data['type']=$storeWithdrawal['type'];
|
||
$data['actualMoney'] = bcsub($money, $charge, 2);
|
||
$data['state'] = 1;
|
||
$data['storeId'] = $storeId;
|
||
$data['uniacid'] = $uniacid;
|
||
$data['createdAt'] = time();
|
||
$data['outTradeNo'] = date("YmdHis") . rand(111111, 999999);
|
||
$res=Yii::$app->db->createCommand()->insert('{{%ybwm_store_finance}}', $data)->execute();
|
||
if($res){
|
||
Bill::saveStoreBill($uniacid,$storeId,$money,2,6,'提现申请',time(),$data['outTradeNo']);
|
||
return $this->result(1,'成功');
|
||
}else{
|
||
return $this->result(2,'失败');
|
||
}
|
||
}
|
||
|
||
//提现列表
|
||
public function actionWithdrawalList(){
|
||
$result=axios_request();
|
||
$storeId=$result['storeId']?:$this->shop_id;
|
||
$page=$result['page']?:1;
|
||
$num=($page-1)*10;
|
||
$limit=10;
|
||
$table=(new \yii\db\Query())
|
||
->from('{{%ybwm_store_finance}}')
|
||
->where(['storeId'=>$storeId]);
|
||
$list=$table->offset($num)
|
||
->limit($limit)->orderBy('id desc')->all();
|
||
$count=$table->count();
|
||
for($i=0;$i<count($list);$i++){
|
||
$list[$i]['serviceMoney']=bcsub($list[$i]['money'],$list[$i]['actualMoney'],2);
|
||
$list[$i]['account']=json_decode($list[$i]['account'],true)?:[];
|
||
$list[$i]['account']['userName']='';
|
||
$user=(new \yii\db\Query())
|
||
->select('userName')
|
||
->from('{{%ybwm_member}}')
|
||
->where(['id'=>$list[$i]['account']['userId']])->one();
|
||
$list[$i]['account']['userName']=$user['userName'];
|
||
$list[$i]['createdAt']=date("Y-m-d H:i:s",$list[$i]['createdAt']);
|
||
}
|
||
return $this->result(1, '成功',$list,$count);
|
||
}
|
||
//提现设置
|
||
public function actionWithdrawalSet(){
|
||
$request = Yii::$app->request;
|
||
$result=axios_request();
|
||
$uniacid=$this->wqData['uniacid'];
|
||
$res=Config::getStoreSet('withdrawal',$result['storeId']);
|
||
|
||
$res['system']=Config::getSystemSet('withdrawal',$uniacid);
|
||
|
||
if ($request->isGet){
|
||
$withdrawal=Config::getSystemSet('withdrawal',$uniacid);
|
||
$res['channel']=$withdrawal['channel'];
|
||
$user=(new \yii\db\Query())
|
||
->select('userName')
|
||
->from('{{%ybwm_member}}')
|
||
->where('id=:id AND uniacid=:uniacid',[':id'=>$res['userId'],':uniacid'=>$uniacid])
|
||
->one();
|
||
$res['userName']=$user['userName']?:'';
|
||
return $this->result(1,'成功',$res);
|
||
}
|
||
// if($res){
|
||
// return $this->result(2,'提现方式已设置,请联系管理员修改');
|
||
// }
|
||
$re=Config::saveStoreSet($result,'withdrawal',$result['storeId'],'提现设置');
|
||
if($re){
|
||
return $this->result(1,'成功');
|
||
}else{
|
||
return $this->result(2,'网络异常,请稍后再试');
|
||
}
|
||
}
|
||
|
||
//账户信息
|
||
public function actionAccountInfo(){
|
||
$result=axios_request();
|
||
$uniacid=$this->wqData['uniacid'];
|
||
$storeId=$result['storeId'];
|
||
$storeInfo=(new \yii\db\Query())
|
||
->select('name,areaId,typeId')
|
||
->from('{{%ybwm_store}}')
|
||
->where('id=:id',[':id'=>$storeId])
|
||
->one();
|
||
$data['storeName']=$storeInfo['name'];
|
||
$res=Config::getStoreSet('withdrawal',$result['storeId']);
|
||
$withdrawal=Config::getSystemSet('withdrawal',$uniacid);
|
||
if($res['type']==1){
|
||
$type='微信';
|
||
$account='用户ID:'.$res['userId'];
|
||
}elseif($res['type']==2){
|
||
$type='支付宝';
|
||
$account=$res['aliAccount'];
|
||
}elseif($res['type']==3){
|
||
$type='银行卡';
|
||
$account=$res['bankAccount'];
|
||
}
|
||
$data['type']=$type;
|
||
$data['account']=$account;
|
||
|
||
$storeSet=Config::getStoreSet('serviceCharge',$storeId);
|
||
$res=Config::getSystemSet('serviceCharge',$uniacid);
|
||
if($storeSet['rule']==2){
|
||
$res=$storeSet;
|
||
}else{
|
||
if($res['rule']==2){
|
||
//按商家分组
|
||
$storeType=(new \yii\db\Query())
|
||
->from('{{%ybwm_core_category}}')
|
||
->where('id=:id',[':id'=>$storeInfo['typeId']])->one();
|
||
$res=json_decode($storeType['data'],true);
|
||
}elseif($res['rule']==3){
|
||
//按商家区域
|
||
$storeType=(new \yii\db\Query())
|
||
->from('{{%ybwm_core_category}}')
|
||
->where('id=:id',[':id'=>$storeInfo['areaId']])->one();
|
||
$res=json_decode($storeType['data'],true);
|
||
}elseif($res['rule']==4){
|
||
//按商家单独
|
||
$res=$storeSet;
|
||
}
|
||
}
|
||
$entryDay=$res['entryDay']?:1;
|
||
if($res['type']==1){
|
||
$rate='商品:'.$res['goodsPlatformProportion']."% 包装费:".$res['boxPlatformProportion']."% 配送费:".$res['deliverPlatformProportion']."%";
|
||
}else{
|
||
$rate='商品:'.$res['goodsFixedMoney']."元 包装费:".$res['boxFixedMoney']."元 配送费:".$res['deliverFixedMoney']."元";
|
||
}
|
||
|
||
|
||
// $entryDay=1;
|
||
// $rate='无';
|
||
// if($serviceCharge['rule']==1){
|
||
// $entryDay=$serviceCharge['entryDay']?:1;
|
||
// if($serviceCharge['type']==1){
|
||
// $rate='商品:'.$serviceCharge['goodsPlatformProportion']."% 包装费:".$serviceCharge['boxPlatformProportion']."% 配送费:".$serviceCharge['deliverPlatformProportion']."%";
|
||
// }else{
|
||
// $rate='商品:'.$serviceCharge['goodsFixedMoney']."元 包装费:".$serviceCharge['boxFixedMoney']."元 配送费:".$serviceCharge['deliverFixedMoney']."元";
|
||
// }
|
||
// }elseif($serviceCharge['rule']==2){
|
||
// $storeType=(new \yii\db\Query())
|
||
// ->from('{{%ybwm_core_category}}')
|
||
// ->where('id=:id',[':id'=>$storeInfo['typeId']])->one();
|
||
// $entryDayData=json_decode($storeType['data'],true);
|
||
// $entryDay=$entryDayData['entryDay']?:1;
|
||
// if($entryDayData['type']==1) {
|
||
// $rate = '商品:' . $entryDayData['goodsPlatformProportion'] . "% 包装费:" . $entryDayData['boxPlatformProportion'] . "% 配送费:" . $entryDayData['deliverPlatformProportion'] . "%";
|
||
// }else{
|
||
// $rate = '商品:' . $entryDayData['goodsFixedMoney'] . "元 包装费:" . $entryDayData['boxFixedMoney'] . "元 配送费:" . $entryDayData['deliverFixedMoney'] . "元";
|
||
// }
|
||
// }elseif($serviceCharge['rule']==3){
|
||
// $storeType=(new \yii\db\Query())
|
||
// ->from('{{%ybwm_core_category}}')
|
||
// ->where('id=:id',[':id'=>$storeInfo['areaId']])->one();
|
||
// $entryDayData=json_decode($storeType['data'],true);
|
||
// $entryDay=$entryDayData['entryDay']?:1;
|
||
// if($entryDayData['type']==1) {
|
||
// $rate = '商品:' . $entryDayData['goodsPlatformProportion'] . "% 包装费:" . $entryDayData['boxPlatformProportion'] . "% 配送费:" . $entryDayData['deliverPlatformProportion'] . "%";
|
||
// }else{
|
||
// $rate = '商品:' . $entryDayData['goodsFixedMoney'] . "元 包装费:" . $entryDayData['boxFixedMoney'] . "元 配送费:" . $entryDayData['deliverFixedMoney'] . "元";
|
||
// }
|
||
// }
|
||
$data['rate']=$rate;
|
||
$data['entryDay']=$entryDay?:1;
|
||
$data['withdrawalDay']=$withdrawal['day'];
|
||
return $this->result(1,'成功',$data);
|
||
}
|
||
|
||
|
||
//订单概况导出
|
||
public function actionOrderExport(){
|
||
$result=axios_request();
|
||
$storeId=$result['storeId']?:$this->shop_id;
|
||
$uniacid=$this->wqData['uniacid'];
|
||
Export::BillOrderExport($uniacid,$storeId,$result['time']);
|
||
|
||
}
|
||
//其他订单概况导出
|
||
public function actionOtherOrderExport(){
|
||
$result=axios_request();
|
||
$storeId=$result['storeId']?:$this->shop_id;
|
||
$uniacid=$this->wqData['uniacid'];
|
||
Export::BillOtherOrderExport($uniacid,$storeId,$result['time']);
|
||
}
|
||
//订单概况导出
|
||
public function actionOrderExport1(){
|
||
$result=axios_request();
|
||
$storeId=$result['storeId']?:$this->shop_id;
|
||
$uniacid=$this->wqData['uniacid'];
|
||
Export::BillOrderExport1($uniacid,$storeId,$result);
|
||
|
||
}
|
||
//其他订单概况导出
|
||
public function actionOtherOrderExport1(){
|
||
$result=axios_request();
|
||
$storeId=$result['storeId']?:$this->shop_id;
|
||
$uniacid=$this->wqData['uniacid'];
|
||
Export::BillOtherOrderExport1($uniacid,$storeId,$result);
|
||
}
|
||
|
||
//账单打印
|
||
public function actionBillPrint(){
|
||
$result=axios_request();
|
||
$storeId=$result['storeId']?:$this->shop_id;
|
||
$uniacid=$this->wqData['uniacid'];
|
||
$startTime=strtotime($result['time']." 00:00:00");
|
||
$endTime=strtotime($result['time']." 23:59:59");
|
||
$res=StoreBill::billInfo($uniacid,$storeId,$startTime,$endTime);
|
||
$res['day']=$result['time'];
|
||
$res['storeId']=$storeId;
|
||
$res['uniacid']=$uniacid;
|
||
$result=Printing::billPrint($res);
|
||
if($result){
|
||
return $this->result(1,'成功');
|
||
}else{
|
||
return $this->result(2,'网络异常,请稍后再试');
|
||
}
|
||
return $this->result(1,'成功',$res);
|
||
}
|
||
|
||
//完结分账
|
||
public function actionProfitSharingFinish(){
|
||
$result=axios_request();
|
||
if(!$result['orderId']){
|
||
return $this->result(2,'参数有误');
|
||
}
|
||
$type=$result['type'];
|
||
$res=WeChat::profitSharingFinish($result['orderId'],'手动点击完结分账',$type);
|
||
if($res){
|
||
return $this->result(1,'成功');
|
||
}else{
|
||
return $this->result(2,'网络异常,请稍后再试');
|
||
}
|
||
}
|
||
//账户明细
|
||
public function actionStoreBillList(){
|
||
$result=axios_request();
|
||
$type=$result['type'];
|
||
$storeId=$result['storeId']?:$this->shop_id;
|
||
$page=$result['page']?:1;
|
||
$num=($page-1)*10;
|
||
$limit=10;
|
||
$table=(new \yii\db\Query())
|
||
->select('outTradeNo,origin,item,money,currentMoney,note,from_unixtime(createdAt) createdAt')
|
||
->from('{{%ybwm_store_bill}}')
|
||
->where(['storeId'=>$storeId]);
|
||
if($type==1){
|
||
$table->andWhere(['in','origin',[1,2,3]]);
|
||
}
|
||
if($type==2){
|
||
$table->andWhere(['in','origin',[4]]);
|
||
}
|
||
if($type==3){
|
||
$table->andWhere(['in','origin',[8]]);
|
||
}
|
||
if($type==4){
|
||
$table->andWhere(['in','origin',[6]]);
|
||
}
|
||
if($type==5){
|
||
$table->andWhere(['in','origin',[5,7]]);
|
||
}
|
||
if($result['startTime']){
|
||
$table->andWhere('createdAt>=:startTime AND createdAt<=:endTime',[':startTime'=>strtotime($result['startTime']),':endTime'=>strtotime($result['endTime']."23:59:59")]);
|
||
}
|
||
$list=$table->offset($num)
|
||
->limit($limit)->orderBy('id desc')->all();
|
||
|
||
$count=$table->count();
|
||
return $this->result(1, '成功',$list,$count);
|
||
}
|
||
//交易明细
|
||
public function actionTransaction(){
|
||
$result=axios_request();
|
||
$type=$result['type'];
|
||
$platform=$result['platform'];//平台来源
|
||
$payMode=$result['payMode'];//支付方式
|
||
$timeType=$result['timeType'];//时间搜索
|
||
$orderType=$result['orderType'];//订单类型
|
||
$storeId=$result['storeId']?:$this->shop_id;
|
||
$page=$result['page']?:1;
|
||
$num=($page-1)*10;
|
||
$limit=10;
|
||
$storeName=(new \yii\db\Query())
|
||
->select('name')
|
||
->from('{{%ybwm_store}}')
|
||
->where(['id'=>$storeId])->one()['name']?:'';
|
||
$table=(new \yii\db\Query())
|
||
->select(['refundAt','type','payMode','outTradeNo','createdAt','origin','(money-storeActualMoney+subsidy) as serviceMoney','money','storeActualMoney','subsidy','from_unixtime(createdAt) createdAt'])
|
||
->from('{{%ybwm_bill}}')
|
||
->where(['storeId'=>$storeId]);
|
||
if($type==1){
|
||
//已完成
|
||
$table->andWhere('type=2');
|
||
}
|
||
if($type==2){
|
||
//已取消
|
||
$table->andWhere('refundAt>0 || refundAt is not null');
|
||
}
|
||
if($type==3){
|
||
//进行中
|
||
$table->andWhere('type=1 AND (refundAt=0 || refundAt is null)');
|
||
}
|
||
if($platform==1){
|
||
//微信
|
||
$table->andWhere('platform=1');
|
||
}
|
||
if($platform==2){
|
||
//支付宝
|
||
$table->andWhere('platform=3');
|
||
}
|
||
if($platform==3){
|
||
//收银台
|
||
$table->andWhere('platform=5');
|
||
}
|
||
if($payMode==1){
|
||
//微信支付
|
||
$table->andWhere('payMode=1');
|
||
}
|
||
if($payMode==2){
|
||
//支付宝
|
||
$table->andWhere('payMode=2');
|
||
}
|
||
if($payMode==3){
|
||
//余额
|
||
$table->andWhere('payMode=5');
|
||
}
|
||
if($payMode==4){
|
||
//现金
|
||
$table->andWhere('payMode=6');
|
||
}
|
||
if($payMode==5){
|
||
//线下
|
||
$table->andWhere('payMode in (7,8,9,10)');
|
||
}
|
||
if($orderType==1){
|
||
//堂食
|
||
$table->andWhere('origin=7');
|
||
}
|
||
if($orderType==2){
|
||
//外卖
|
||
$table->andWhere('origin=1');
|
||
}
|
||
if($orderType==3){
|
||
//收银
|
||
$table->andWhere('origin=5');
|
||
}
|
||
if($orderType==4){
|
||
//快餐
|
||
$table->andWhere('origin=6');
|
||
}
|
||
if($orderType==5){
|
||
//其他
|
||
$table->andWhere('origin=4');
|
||
}
|
||
switch ($timeType){
|
||
case 1://今天
|
||
$startTime=strtotime(date("Y-m-d",time()));
|
||
$endTime=strtotime(date("Y-m-d",time()))+86399;
|
||
break;
|
||
case 2://近七天
|
||
$startTime=strtotime(date("Y-m-d",strtotime("-7 day")));
|
||
$endTime=time();
|
||
break;
|
||
case 3://近十五天
|
||
$startTime=strtotime(date("Y-m-d",strtotime("-15 day")));
|
||
$endTime=time();
|
||
break;
|
||
case 4://具体日期
|
||
$startTime=strtotime($result['startTime']);
|
||
$endTime=strtotime($result['endTime']);
|
||
break;
|
||
// default:
|
||
// $startTime=strtotime(date("Y-m-d",time()));
|
||
// $endTime=strtotime(date("Y-m-d",time()))+86399;
|
||
// break;
|
||
}
|
||
if($startTime){
|
||
$table->andWhere(['>=','createdAt',$startTime])->andWhere(['<=','createdAt',$endTime]);
|
||
}
|
||
|
||
|
||
|
||
$export=$result['export'];
|
||
if($export==1){
|
||
$list=$table->all();
|
||
|
||
$titleArr=['订单序号','订单编号','下单时间','订单类型','订单总金额','用户实付','支付方式','补贴(平台)','平台服务费','实际到账','订单状态'];
|
||
$newList=[];
|
||
for($j=0;$j<count($list);$j++){
|
||
$list[$j]['takeNo']=0;
|
||
if($list[$j]['refundAt']>0){
|
||
$list[$j]['stateNote']='已取消';
|
||
}elseif($list[$j]['type']==2){
|
||
$list[$j]['stateNote']='已完成';
|
||
}else{
|
||
$list[$j]['stateNote']='进行中';
|
||
}
|
||
$list[$j]['payModeName']=$this->payMode[$list[$j]['payMode']];
|
||
$list[$j]['originName']=$this->origin[$list[$j]['origin']];
|
||
if($list[$j]['origin']==1){
|
||
//外卖
|
||
$order=(new \yii\db\Query())
|
||
->select('takeNo')
|
||
->from('{{%ybwm_takeout_order}}')
|
||
->where(['outTradeNo'=>$list[$j]['outTradeNo']])->one();
|
||
$list[$j]['takeNo']=$order['takeNo']?:0;
|
||
}
|
||
if($list[$j]['origin']==7 || $list[$j]['origin']==6){
|
||
//堂食快餐
|
||
$order=(new \yii\db\Query())
|
||
->select('takeNo')
|
||
->from('{{%ybwm_instore_order}}')
|
||
->where(['outTradeNo'=>$list[$j]['outTradeNo']])->one();
|
||
$list[$j]['takeNo']=$order['takeNo']?:0;
|
||
}
|
||
$newList[]=[
|
||
$list[$j]['takeNo'],$list[$j]['outTradeNo'],$list[$j]['createdAt'],$list[$j]['originName'],
|
||
$list[$j]['money'],$list[$j]['money'],$list[$j]['payModeName'],$list[$j]['subsidy'],$list[$j]['serviceMoney'],$list[$j]['storeActualMoney'],$list[$j]['stateNote']
|
||
];
|
||
}
|
||
exportExcel($titleArr,$newList,date("Y-m-d",$startTime).'~'.date("Y-m-d",$endTime).'('.$storeName.')交易记录');
|
||
}
|
||
$list=$table->offset($num)
|
||
->limit($limit)->orderBy('id desc')->all();
|
||
for($i=0;$i<count($list);$i++){
|
||
$list[$i]['deliveryMoney']=0;
|
||
$list[$i]['takeNo']=0;
|
||
if($list[$i]['refundAt']>0){
|
||
$list[$i]['state']=2;
|
||
$list[$i]['stateNote']='已取消';
|
||
}elseif($list[$i]['type']==2){
|
||
$list[$i]['state']=1;
|
||
$list[$i]['stateNote']='已完成';
|
||
}else{
|
||
$list[$i]['state']=3;
|
||
$list[$i]['stateNote']='进行中';
|
||
}
|
||
$list[$i]['payModeName']=$this->payMode[$list[$i]['payMode']];
|
||
$list[$i]['originName']=$this->origin[$list[$i]['origin']];
|
||
if($list[$i]['origin']==1){
|
||
//外卖
|
||
$order=(new \yii\db\Query())
|
||
->select('deliveryMoney,takeNo')
|
||
->from('{{%ybwm_takeout_order}}')
|
||
->where(['outTradeNo'=>$list[$i]['outTradeNo']])->one();
|
||
$list[$i]['deliveryMoney']=$order['deliveryMoney'];
|
||
$list[$i]['takeNo']=$order['takeNo']?:0;
|
||
}
|
||
if($list[$i]['origin']==7 || $list[$i]['origin']==6){
|
||
//堂食快餐
|
||
$order=(new \yii\db\Query())
|
||
->select('takeNo')
|
||
->from('{{%ybwm_instore_order}}')
|
||
->where(['outTradeNo'=>$list[$i]['outTradeNo']])->one();
|
||
$list[$i]['takeNo']=$order['takeNo']?:0;
|
||
}
|
||
}
|
||
$count=$table->count();
|
||
|
||
return $this->result(1, '成功',$list,$count);
|
||
}
|
||
//
|
||
public function actionCurrencyOrderInfo(){
|
||
// echo date("Y-m-d");die;
|
||
$result=axios_request();
|
||
$type=$result['type'];
|
||
$outTradeNo=$result['outTradeNo'];
|
||
if($type==1){
|
||
//外卖
|
||
$order=(new \yii\db\Query())
|
||
->select(['b.refundType','b.refundAt','a.outTradeNo','b.storeActualMoney','a.otherInfo','a.id','a.origin','from_unixtime(a.createdAt) as createdAt','a.takeNo','a.money','a.payAt','a.payMode',
|
||
'a.state','a.deliveryMode','a.serviceAt','a.appointment','a.serviceTime','a.receivedName','a.receivedAddress',
|
||
'a.receivedTel','a.userNote','a.originMoney','a.deliveryMoney','a.boxMoney','a.subsidy','a.userId',
|
||
'(b.money-b.storeActualMoney+b.subsidy) as serviceMoney','a.preferentialMoney','a.newMoney','a.vipDiscount','a.deliveryPreferential',
|
||
'a.platformCouponPreferential','(a.couponPreferential+a.platformCouponPreferential) as couponPreferential','(a.deliveryMoney-b.storeDeliveryMoney) as serviceDeliveryMoney',
|
||
'(a.boxMoney-b.storeBoxMoney) as serviceBoxMoney','(a.money-a.boxMoney-a.deliveryMoney-b.storeGoodsMoney) as serviceGoodMoney',
|
||
'ifnull((a.originMoney+a.boxMoney+a.deliveryMoney+a.deliveryPreferential)-a.money,0) as discountMoney','m.userName'])
|
||
->from('{{%ybwm_takeout_order}} as a')
|
||
->join('LEFT JOIN', '{{%ybwm_bill}} as b', 'b.orderId = a.id AND b.origin=1')
|
||
->join('LEFT JOIN', '{{%ybwm_member}} as m', 'm.id = a.userId')
|
||
->where(['a.outTradeNo'=>$outTradeNo])->one();
|
||
$originName=$order['deliveryMode']==10?'外卖自提订单':'外卖订单';
|
||
$otherInfo=json_decode($order['otherInfo'],true);
|
||
$order['deliveryInfo']['riderName']=$otherInfo['result']['riderName']?:'';
|
||
$order['deliveryInfo']['riderTel']=$otherInfo['result']['riderTel']?:'';
|
||
$order['deliveryInfo']['stateMsg']=$otherInfo['result']['stateMsg']?:'';
|
||
}
|
||
if($type==2 || $type==3){
|
||
if($type==2){
|
||
$origin=7;
|
||
$originName='堂食订单';
|
||
}
|
||
if($type==3){
|
||
$origin=6;
|
||
$originName='快餐订单';
|
||
}
|
||
//堂食
|
||
$order=(new \yii\db\Query())
|
||
->select(['a.vipDiscount','b.refundType','b.refundAt','a.completeAt','a.receiptAt','a.isOut','a.eatType','a.outTradeNo','b.storeActualMoney','a.id','a.origin','from_unixtime(a.createdAt) as createdAt','a.takeNo','a.money','a.payAt','a.payMode',
|
||
'a.state','a.userNote','a.originMoney','b.subsidy','a.userId','(b.money-b.storeActualMoney+b.subsidy) as serviceMoney',
|
||
'a.preferentialMoney','a.newMoney','a.platformCouponPreferential','a.couponPreferential',
|
||
'ifnull((a.money-a.tablewareMoney-b.storeGoodsMoney),0) as serviceGoodMoney',
|
||
'ifnull((a.originMoney+a.tablewareMoney)-a.money,0) as discountMoney','m.userName'])
|
||
->from('{{%ybwm_instore_order}} as a')
|
||
->join('LEFT JOIN', '{{%ybwm_bill}} as b', 'b.orderId = a.id AND b.origin='.$origin)
|
||
->join('LEFT JOIN', '{{%ybwm_member}} as m', 'm.id = a.userId')
|
||
->where(['a.outTradeNo'=>$outTradeNo])->one();
|
||
|
||
}
|
||
if($type==4){
|
||
//收银
|
||
$order=(new \yii\db\Query())
|
||
->select(['b.refundType','b.refundAt','a.outTradeNo','b.storeActualMoney','a.id','a.origin','from_unixtime(a.createdAt) as createdAt','a.money','a.payAt','a.payMode',
|
||
'a.state','a.userNote','a.userId','(b.money-b.storeActualMoney+b.subsidy) as serviceMoney', 'm.userName'])
|
||
->from('{{%ybwm_cashier_order}} as a')
|
||
->join('LEFT JOIN', '{{%ybwm_bill}} as b', 'b.orderId = a.id AND b.origin=5')
|
||
->join('LEFT JOIN', '{{%ybwm_member}} as m', 'm.id = a.userId')
|
||
->where(['a.outTradeNo'=>$outTradeNo])->one();
|
||
$originName='当面付订单';
|
||
}
|
||
if($type==5){
|
||
//券包
|
||
$order=(new \yii\db\Query())
|
||
->select(['b.refundType','b.refundAt','a.outTradeNo','b.storeActualMoney','a.id','from_unixtime(a.createdAt) as createdAt','a.money','a.payAt','a.payMode',
|
||
'a.state','a.userId','(b.money-b.storeActualMoney+b.subsidy) as serviceMoney', 'm.userName'])
|
||
->from('{{%ybwm_roll_bag_order}} as a')
|
||
->join('LEFT JOIN', '{{%ybwm_bill}} as b', 'b.orderId = a.id AND b.origin=4')
|
||
->join('LEFT JOIN', '{{%ybwm_member}} as m', 'm.id = a.userId')
|
||
->where(['a.outTradeNo'=>$outTradeNo])->one();
|
||
$originName='券包订单';
|
||
}
|
||
$order['originName']=$originName;
|
||
$goods=(new \yii\db\Query())
|
||
->from('{{%ybwm_order_goods}}')
|
||
->where(['orderId'=>$order['id'],'item'=>$type])->all();
|
||
$order['goodsArr']=$goods;
|
||
$order['payModeName']=$this->payMode[$order['payMode']];
|
||
$order['platformName']=$this->platform[$order['origin']]?:'微信小程序';
|
||
|
||
return $this->result(1, '成功',$order);
|
||
}
|
||
|
||
}
|