308 lines
14 KiB
PHP
308 lines
14 KiB
PHP
<?php
|
||
namespace app\controllers\merchant;
|
||
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;
|
||
class StoreBillController extends CommonController{
|
||
public $enableCsrfValidation = false;
|
||
|
||
//查看商家余额
|
||
public function actionStoreBill(){
|
||
$result=axios_request();
|
||
$storeId=$this->wqData['storeId'];
|
||
$res=StoreBill::getMerchantMoney($this->wqData['uniacid'],$storeId);
|
||
return $this->result(1,'成功',$res);
|
||
|
||
}
|
||
//待结算
|
||
public function actionWaitMoney(){
|
||
$result=axios_request();
|
||
$storeId=$this->wqData['storeId'];
|
||
$uniacid=$this->wqData['uniacid'];
|
||
$res=StoreBill::waitMoney($uniacid,$storeId);
|
||
return $this->result(1,'成功',$res);
|
||
}
|
||
//所有账单
|
||
public function actionBillList(){
|
||
$result=axios_request();
|
||
$storeId=$this->wqData['storeId'];
|
||
$timeType=$storeId['timeType'];
|
||
$uniacid=$this->wqData['uniacid'];
|
||
$startTime=0;
|
||
$endTime=0;
|
||
if($timeType==1){
|
||
$startTime=strtotime($result['startTime']);
|
||
$endTime=strtotime($result['endTime']);
|
||
}elseif($timeType==2){
|
||
$mouthArr=explode('-',$result['mouth']);
|
||
$timeArr=mFristAndLast($mouthArr[0],$mouthArr[1]);
|
||
$startTime=$timeArr[0]['startTime'];
|
||
$endTime=$timeArr[0]['endTime'];
|
||
}
|
||
$res=StoreBill::billList($uniacid,$storeId,$result['page'],$result['size'],$startTime,$endTime);
|
||
return $this->result(1,'成功',$res);
|
||
}
|
||
//账单详情
|
||
public function actionBillInfo(){
|
||
$result=axios_request();
|
||
$storeId=$this->wqData['storeId'];
|
||
$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);
|
||
return $this->result(1,'成功',$res);
|
||
}
|
||
//订单概况
|
||
public function actionBillOrderInfo(){
|
||
$result=axios_request();
|
||
$storeId=$result['storeId']?:$this->shop_id;
|
||
$uniacid=$this->wqData['storeId'];
|
||
$page=$result['page']?:1;
|
||
$num=($page-1)*10;
|
||
$limit=10;
|
||
$startTime=strtotime($result['time']." 00:00:00");
|
||
$endTime=strtotime($result['time']." 23:59:59");
|
||
$table = (new \yii\db\Query())
|
||
->select(['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,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',
|
||
['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++) {
|
||
if ($res[$i]['payMode'] == 1) {
|
||
$res[$i]['payModeName'] = '微信支付';
|
||
} elseif ($res[$i]['payMode'] == 5) {
|
||
$res[$i]['payModeName'] = '余额支付';
|
||
}
|
||
}
|
||
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', ['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=$this->wqData['storeId'];
|
||
$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($storeWithdrawal['rate']>0){
|
||
$charge = bcmul($money, $storeWithdrawal['rate'] / 100, 2);
|
||
if ($charge < $storeWithdrawal['rateDownMoney']) {
|
||
$charge = $storeWithdrawal['rateDownMoney'];
|
||
}
|
||
if ($charge > $storeWithdrawal['rateUpMoney']) {
|
||
$charge = $storeWithdrawal['rateUpMoney'];
|
||
}
|
||
}
|
||
$data['account']=json_encode($account);
|
||
$data['charge']=$charge;//手续费
|
||
$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){
|
||
return $this->result(1,'成功');
|
||
}else{
|
||
return $this->result(2,'失败');
|
||
}
|
||
}
|
||
|
||
//提现列表
|
||
public function actionWithdrawalList(){
|
||
$result=axios_request();
|
||
$storeId=$this->wqData['storeId'];
|
||
$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]['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',$this->wqData['storeId']);
|
||
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',$this->wqData['storeId'],'提现设置');
|
||
if($re){
|
||
return $this->result(1,'成功');
|
||
}else{
|
||
return $this->result(2,'网络异常,请稍后再试');
|
||
}
|
||
}
|
||
|
||
//账户信息
|
||
public function actionAccountInfo(){
|
||
$result=axios_request();
|
||
$uniacid=$this->wqData['uniacid'];
|
||
$storeId=$this->wqData['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',$storeId);
|
||
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;
|
||
$serviceCharge=Config::getSystemSet('serviceCharge',$uniacid);
|
||
$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;
|
||
return $this->result(1,'成功',$data);
|
||
}
|
||
|
||
} |