107 lines
4.3 KiB
PHP
107 lines
4.3 KiB
PHP
<?php
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use App\Model\Seller\Shop;
|
|
use App\Model\ShopAgent;
|
|
use App\Model\ShopAgentBill;
|
|
use App\Model\Order;
|
|
use App\Model\Seller\ShopBill;
|
|
use Log;
|
|
//执行代理每日的提点计算
|
|
class ShopAgentBillCommand extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'ShopAgentBillCommand {sdate?} {edate?}';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = '执行代理每日的提点计算';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
*执行代理每日的提点计算
|
|
**/
|
|
public function handle()
|
|
{
|
|
|
|
$sdate = empty($this->argument('sdate')) ? date("Ymd",strtotime("-1 day")) : $this->argument('sdate');
|
|
$edate = empty($this->argument('edate')) ? date("Ymd",strtotime("-1 day")) : $this->argument('edate');
|
|
//查询服务费日志
|
|
$data = ShopBill::selectRaw('created_date,order_id,money as use_amount,shop_id')
|
|
->where('type',2)
|
|
->whereBetween('created_date',[$sdate,$edate])
|
|
->get()->map(function($item){
|
|
//查询对应的流水
|
|
$item->amount = Order::where('id',$item->order_id)->value('money');
|
|
$item->use_rate = 0.004; //平台服务费 费率
|
|
$item->shop_agent_id = Shop::where('id',$item->shop_id)->value('shop_agent_id');
|
|
$item->shop_agent_pid = $item->shop_agent_id>0?ShopAgent::where('agent_id',$item->shop_agent_id)->value('agent_pid'):0;
|
|
return $item;
|
|
})->toArray();
|
|
|
|
$newdata = [];
|
|
foreach ($data as $k => $v) {
|
|
$newdata[$v['created_date']][$v['shop_id']] = $v;
|
|
$newdata[$v['created_date']][$v['shop_id']]['amount'] = isset($newdata[$v['created_date']][$v['shop_id']]['amount'])?$newdata[$v['created_date']][$v['shop_id']]['amount']:0+$v['amount'];
|
|
$newdata[$v['created_date']][$v['shop_id']]['use_amount'] = isset($newdata[$v['created_date']][$v['shop_id']]['use_amount'])?$newdata[$v['created_date']][$v['shop_id']]['use_amount']:0+$v['use_amount'];
|
|
}
|
|
|
|
foreach ($newdata as $k => $v) {
|
|
foreach ($v as $kk => $vv) {
|
|
// if($vv['shop_agent_id']==0) continue; //没有代理的不需要跑数据
|
|
$cdate = date("Y-m-d",strtotime($k));
|
|
if($vv['shop_agent_pid']==0){
|
|
//一级代理
|
|
$agent_rate = ShopAgentBill::SHOP_AGENT_RATE_ONE;
|
|
}else{
|
|
//二级代理
|
|
$agent_rate = ShopAgentBill::SHOP_AGENT_RATE_TWO;
|
|
//写入自己下面的二代店铺的提成
|
|
$checkdata = ['shop_id'=>$kk,'cdate'=>$cdate,'shop_agent_id'=>$vv['shop_agent_pid'],'shop_agent_pid'=>0];
|
|
$indata = ['amount'=>$vv['amount'],
|
|
'use_rate'=>$vv['use_rate'],
|
|
'use_amount'=>$vv['use_amount'],
|
|
'ctype'=>1,
|
|
'agent_rate'=>ShopAgentBill::SHOP_AGENT_RATE_SUPPER,
|
|
'agent_amount'=>$vv['use_amount']*ShopAgentBill::SHOP_AGENT_RATE_SUPPER
|
|
];
|
|
$ret = ShopAgentBill::updateOrCreate(
|
|
$checkdata,
|
|
$indata
|
|
);
|
|
}
|
|
//写入自己代理的店铺提成
|
|
$checkdata = ['shop_id'=>$kk,'cdate'=>$cdate,'shop_agent_id'=>$vv['shop_agent_id'],'shop_agent_pid'=>$vv['shop_agent_pid']];
|
|
$indata = ['amount'=>$vv['amount'],
|
|
'use_rate'=>$vv['use_rate'],
|
|
'use_amount'=>$vv['use_amount'],
|
|
'ctype'=>1,
|
|
'agent_rate'=>$agent_rate,
|
|
'agent_amount'=>$vv['use_amount']*$agent_rate
|
|
];
|
|
$ret = ShopAgentBill::updateOrCreate(
|
|
$checkdata,
|
|
$indata
|
|
);
|
|
}
|
|
}
|
|
dd('over');
|
|
}
|
|
} |