|
|
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;use Illuminate\Support\Facades\DB;
class Statistics extends Command{ /** * The name and signature of the console command. * * @var string */ protected $signature = 'command:statistics';
/** * The console command description. * * @var string */ protected $description = 'Command description';
/** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); }
/** * Execute the console command. * * @return int */ public function handle() {
bcscale(4); $stores = DB::table('lanzu_store')->orderBy('id', 'desc')->get()->toArray();
foreach ($stores as $key => &$store) { // 旧订单
$orderAmountOld1 = DB::table('ims_cjdc_order as ord') ->selectRaw('SUM(ord.money) AS total') ->leftJoin('ims_cjdc_order_main as main', 'main.id', '=', 'ord.order_main_id') ->whereIn('main.state', [4,5,10]) ->where('ord.store_id', '=', $store->id) ->where('main.type', '=', 1) ->first();
$orderAmountOld2 = DB::table('ims_cjdc_order as ord') ->selectRaw('SUM(ord.money) AS total') ->leftJoin('ims_cjdc_order_main as main', 'main.id', '=', 'ord.order_main_id') ->whereIn('main.dm_state', [2]) ->where('ord.store_id', '=', $store->id) ->where('main.type', '=', 4) ->first();
$orderAmountOldTotal = bcadd($orderAmountOld1->total, $orderAmountOld2->total);
// 新订单
$orderAmountNew = DB::table('lanzu_order as ord') ->selectRaw('SUM(ord.money) AS total') ->leftJoin('lanzu_order_main as main', 'main.global_order_id', '=', 'ord.order_main_id') ->whereIn('main.state', [4,5,10]) ->where('ord.store_id', '=', $store->id) ->where('main.created_at', '>=', 1600444800) ->first();
// 旧提现
$withdrawOld = DB::table('ims_cjdc_withdrawal') ->selectRaw('SUM(tx_cost) AS total') ->where('state', '=', 2) ->where('store_id', '=', $store->id) ->first();
// 新提现
$withdrawNew = DB::table('lanzu_store_withdrawal') ->selectRaw('SUM(real_cash) AS total') ->where('state', '=', 2) ->where('store_id', '=', $store->id) ->where('created_at', '>=', 1600444800) ->first();
// 旧奖励
$awardOld = DB::table('ims_cjdc_store_account') ->selectRaw('SUM(money) AS total') ->where(function($query) { $query->where('note', '=', '新用户下单成功,平台奖励') ->orWhere('note', '=', '用户下单成功,平台奖励'); }) ->where('store_id', '=', $store->id) ->first();
// 新奖励
$mod = $store->user_id % 5; $awardNew = DB::table('lanzu_financial_record_'.$mod) ->selectRaw('SUM(money) AS total') ->where('user_id', '=', $store->user_id) ->where('user_type', '=', 5) ->whereIn('money_type', [4,5]) ->where('created_at', '>=', 1600444800) ->first();
$withdrawTotal = bcadd($withdrawOld->total, $withdrawNew->total); $result = bcadd($orderAmountOldTotal, $orderAmountNew->total); $result = bcadd($result, $awardOld->total); $result = bcadd($result, $awardNew->total); $result = bcsub($result, $withdrawTotal);
// 余额
$balance = DB::table('lanzu_user_balance') ->where('source_id', '=', $store->user_id) ->where('user_type', '=', 5) ->first();
var_dump( 'store_id : ' . $store->id . ' / user_id : ' . $store->user_id . ' / order_amount : ' . bcadd($orderAmountOldTotal,$orderAmountNew->total) . ' / order_old : ' . ($orderAmountOldTotal) . ' / order_new : ' . ($orderAmountNew->total) . ' / award_total : ' . bcadd($awardOld->total, $awardNew->total) . ' / award_old : ' . ($awardOld->total) . ' / award_new : ' . ($awardNew->total) . ' / withdraw_total : ' . bcadd($withdrawOld->total, $withdrawNew->total) . ' / withdraw_old : ' . $withdrawOld->total . ' / withdraw_new : ' . $withdrawNew->total . ' / result : '.$result . ' / balance : '.$balance->balance ); }
// // 查询店铺收入列表
// $orderAmount = DB::table('lanzu_order as ord')
// ->selectRaw('SUM(ord.money) AS total_amount, ord.store_id, s.user_id')
// ->leftJoin('lanzu_order_main as main', 'main.global_order_id', '=', 'ord.order_main_id')
// ->leftJoin('lanzu_store as s', 's.id', '=', 'ord.store_id')
// ->whereIn('main.state', [4,5,10])
// ->where('store_id', '!=', 0)
// ->groupBy('ord.store_id')
// // ->limit(2)
// ->get()->toArray();
// $withdraws = [];
// $awards = [];
// foreach ($orderAmount as $k => &$item) {
//
// $tmp = DB::table('lanzu_store_withdrawal')
// ->selectRaw('SUM(real_cash) AS total_withdraw')
// ->where('state', '=', 2)
// ->where('store_id', '=', $item->store_id)
// ->first();
//
// $withdraws[$item->store_id] = $tmp->total_withdraw ? $tmp->total_withdraw : 0;
//
// $awardOld = DB::table('ims_cjdc_store_account')
// ->selectRaw('SUM(money) AS total_award')
// ->where(function($query) {
// $query->where('note', '=', '新用户下单成功,平台奖励')
// ->orWhere('note', '=', '用户下单成功,平台奖励');
// })
// ->where('store_id', '=', $item->store_id)
// ->first();
//
// $mod = $item->user_id % 5;
// $awardNew = DB::table('lanzu_financial_record_'.$mod)
// ->selectRaw('SUM(money) AS total_award')
// ->where('user_id', '=', $item->user_id)
// ->where('user_type', '=', 5)
// ->whereIn('money_type', [4,5])
// ->where('created_at', '>=', 1600444800)
// ->first();
//
// $awards[$item->store_id] = floatval($awardOld->total_award+$awardNew->total_award);
//
// $result = $item->total_amount+$awards[$item->store_id]-$withdraws[$item->store_id];
// var_dump('store_id : ' . $item->store_id . ' / order_amount : ' . $item->total_amount . ' / award : ' . $awards[$item->store_id] . ' / withdraw : ' . $withdraws[$item->store_id] . ' / result : '.$result);
// }
// var_dump($withdraws);
// var_dump($awards);
// dd($orderAmount);
}}
|