Commit 84030e52 by 朱继来

temp

parent 14cfcd96
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
use App\Model\OrderModel;
use App\Model\PayLogModel;
use App\Model\ErpPayLogModel;
use App\Model\RemovalModel;
use App\Model\UserMainModel;
class CronController extends Controller
{
// 统计 2019-8-5 到 2019-10-31 期间的用户总额
public function userAmount()
{
// $start_time = strtotime('2019-8-5');
// $end_time = strtotime('2019-10-31 23:59:59');
$start_time = strtotime('2018-8-5');
$end_time = strtotime('2018-10-31 23:59:59');
$PayLogModel = new PayLogModel();
$ErpPayLogModel = new ErpPayLogModel();
$RemovalModel = new RemovalModel();
// 查询联营、自营线上支付记录
$pay_log_field = ['pay_log_id', 'order_id', 'order_sn', 'user_id', 'pay_type', 'is_paid', 'pay_amount', 'pay_time'];
$pay_log_list = $PayLogModel->where('is_paid', 1)
->whereBetween('pay_time', [$start_time, $end_time])
->select($pay_log_field)
// ->select('user_id', DB::raw('sum(pay_amount) as pay_amount'))
->orderBy('pay_time', 'desc')
// ->groupBy('user_id')
->get()
->toArray();
$pay_log = $this->filterFake($pay_log_list); // 过滤数据
$pay_log_amount = $this->countByCurrency($pay_log); // 统计金额
// 联营线下支付记录
$joint_offline_field = ['log_id', 'order_id', 'order_sn', 'user_id', 'receipt_sn', 'receipt_amount', 'currency', 'status', 'receipt_time', 'create_time'];
$joint_offline_list = $ErpPayLogModel->where('status', 1)
->whereBetween('create_time', [$start_time, $end_time])
->select($joint_offline_field)
->orderBy('create_time', 'desc')
->get()
->toArray();
$joint_offline = $this->filterData($joint_offline_list); // 过滤数据
$joint_offline_amount = $this->countByCurrency($joint_offline, 'receipt_amount'); // 统计金额
dd($joint_offline_amount);
// 自营账期支付记录
$self_accounts_field = ['removal_id', 'order_id', 'order_sn', 'user_id', 'checkout_paid', 'checkout_paid_time', 'checkout_paid_amount'];
$self_accounts = $RemovalModel->where('checkout_paid', 1)
->whereBetween('checkout_paid_time', [$start_time, $end_time])
->select($self_accounts_field)
->orderBy('checkout_paid_time', 'desc')
->get();
}
// 过滤尽调数据、添加币种
public function filterFake($data)
{
$OrderModel = new OrderModel();
foreach ($data as $k=>&$v) {
$order = $OrderModel->where(['order_id'=>$v['order_id']])->select('order_id', 'user_id', 'currency', 'is_type')->first();
if ($order['is_type']) {
unset($data[$k]);
continue;
}
$v['currency'] = $order['currency'];
}
return $data;
}
// 过滤联营线下支付数据
public function filterData($data)
{
$PayLogModel = new PayLogModel();
foreach ($data as $k=>$v) {
$pay_log = $PayLogModel->where(['order_id'=>$v['order_id']])->select('pay_log_id')->first();
// 若pay_log表里已存在订单支付记录,则说明该订单已收款完成,需要清除
if ($pay_log) {
unset($data[$k]);
continue;
}
}
return $data;
}
// 根据币种统计用户金额
public function countByCurrency($data, $field='pay_amount')
{
if (!$data) return false;
$amount = [];
// 获取用户对应的金额
foreach ($data as $k=>$v) {
if ($v['currency'] == 1) { // RMB
$amount[$v['user_id']]['rmb'][$k] = $v[$field];
} else { // USD
$amount[$v['user_id']]['usd'][$k] = $v[$field];
}
}
if (!empty($amount)) {
// 统计用户金额
foreach ($amount as &$val)
{
if (isset($val['rmb'])) {
$val['rmb'] = array_sum($val['rmb']);
}
if (isset($v['usd'])) {
$val['usd'] = array_sum($val['usd']);
}
}
}
return $amount;
}
}
\ No newline at end of file
......@@ -142,5 +142,6 @@ Route::group(['middleware' => 'api'], function () {
Route::get ('/api/check/changeprice', 'SpecialController@changeOrderPrice');
Route::get ('/api/check/exportdimission', 'SpecialController@exportDimission');
Route::match (['get', 'post'], '/api/check/importdimission', 'SpecialController@importDimission');
Route::get('/act/useramoumt', 'CronController@userAmount'); // 活动统计用户实付金额
});
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Request;
use Excel;
use DB;
class ErpPayLogModel extends Model
{
protected $connection = 'order';
protected $table = 'lie_erp_pay_log';
protected $primaryKey = 'log_id';
public $timestamps = false;
}
\ No newline at end of file
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Request;
use Excel;
use DB;
class PayLogModel extends Model
{
protected $connection = 'order';
protected $table = 'lie_pay_log';
protected $primaryKey = 'pay_log_id';
public $timestamps = false;
}
\ No newline at end of file
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Request;
use Excel;
use DB;
class RemovalModel extends Model
{
protected $connection = 'order';
protected $table = 'lie_removal';
protected $primaryKey = 'removal_id';
public $timestamps = false;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment