Commit a327885e by 朱继来

fix

parent 69bcdc34
......@@ -12,6 +12,9 @@ use App\Model\RemovalModel;
use App\Model\UserMainModel;
use App\Model\UserAmountModel;
use App\Model\RedisModel;
use App\Model\OrderRefundModel;
use App\Model\OrderReturnModel;
use MonitorDing;
class CronController extends Controller
{
......@@ -23,37 +26,34 @@ class CronController extends Controller
$start_time = strtotime($time['start_time']);
$end_time = strtotime($time['end_time']);
$PayLogModel = new PayLogModel();
$ErpPayLogModel = new ErpPayLogModel();
$RemovalModel = new RemovalModel();
$UserMainModel = new UserMainModel();
$UserAmountModel = new UserAmountModel();
$RedisModel = new RedisModel();
$PayLogModel = new PayLogModel();
$ErpPayLogModel = new ErpPayLogModel();
$RemovalModel = new RemovalModel();
$UserMainModel = new UserMainModel();
$UserAmountModel = new UserAmountModel();
$RedisModel = new RedisModel();
$OrderRefundModel = new OrderRefundModel();
$OrderReturnModel = new OrderReturnModel();
// 查询联营、自营线上支付记录
$pay_log_list = $PayLogModel->getPayLog($start_time, $end_time);
// $pay_log = $this->filterFake($pay_log_list); // 过滤数据
$pay_log_list = $PayLogModel->getPayLog($start_time, $end_time);
$pay_log_amount = $this->countByCurrency($pay_log_list); // 统计金额
// 联营线下支付记录
$joint_offline_list = $ErpPayLogModel->getErpPayLog($start_time, $end_time);
$joint_offline_list = $ErpPayLogModel->getErpPayLog($start_time, $end_time);
$joint_offline = $this->filterData($joint_offline_list); // 过滤数据
$joint_offline_amount = $this->countByCurrency($joint_offline, 'receipt_amount'); // 统计金额
// 自营账期支付记录
$self_accounts_list = $RemovalModel->getSelfAccounts($start_time, $end_time);
$self_accounts = $this->filterFake($self_accounts_list); // 过滤数据
$self_accounts_amount = $this->countByCurrency($self_accounts, 'checkout_paid_amount'); // 统计金额
$self_accounts_list = $RemovalModel->getSelfAccounts($start_time, $end_time);
$self_accounts_amount = $this->countByCurrency($self_accounts_list, 'checkout_paid_amount'); // 统计金额
$resp = [];
// 合并用户
$resp = $this->mergeUser($pay_log_amount, $joint_offline_amount);
$resp = $this->mergeUser($resp, $self_accounts_amount);
// 保存用户金额数据
if (!empty($resp)) {
$cur_rate = $this->getRate();
......@@ -69,12 +69,38 @@ class CronController extends Controller
$data['rmb_amount'] = isset($v['rmb']) ? $v['rmb'] : 0;
$data['usd_amount'] = isset($v['usd']) ? $v['usd'] : 0;
$data['cur_rate'] = $cur_rate;
$data['amount'] = $data['rmb_amount'] + $data['usd_amount'] * $data['cur_rate'];
$joint_return_amount = $OrderRefundModel->getJointReturnAmount($k, $start_time, $end_time); // 联营用户退款金额
if ($joint_return_amount) {
foreach ($joint_return_amount as $joint) {
if ($joint['currency'] == 1) {
$data['rmb_amount'] = $data['rmb_amount'] - ($joint['pay_amount'] - $joint['price_fall']);
} else {
$data['usd_amount'] = $data['usd_amount'] - ($joint['pay_amount'] - $joint['price_fall']);
}
}
}
$self_return_amount = $OrderReturnModel->getSelfReturnAmount($k, $start_time, $end_time); // 自营用户退款金额
if ($self_return_amount) {
foreach ($self_return_amount as $self) {
if ($self['currency'] == 1) {
$data['rmb_amount'] = $data['rmb_amount'] - $joint['return_amount'];
} else {
$data['usd_amount'] = $data['usd_amount'] - $joint['return_amount'];
}
}
}
$data['cur_rate'] = $cur_rate;
$data['amount'] = $data['rmb_amount'] + $data['usd_amount'] * $data['cur_rate'];
$res = $UserAmountModel->updateOrCreate(['user_id' => $k], $data);
if ($res === false) {
MonitorDing::sendText('活动用户汇总表---新增或更新失败,用户ID:'.$k);
echo '新增或更新失败,用户ID:'.$k; die;
}
}
......@@ -84,28 +110,8 @@ class CronController extends Controller
$rank = $UserAmountModel->getUserAmount();
$RedisModel->set('api_lx_activity_user_rank', json_encode($rank));
return $resp;
}
// 过滤尽调数据、添加币种
public function filterFake($data)
{
if (!$data) return false;
$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;
MonitorDing::sendText(date('Y-m-d').'活动用户排行榜:'.json_encode($rank));
return $RedisModel->get('api_lx_activity_user_rank');
}
// 过滤联营线下支付数据
......
......@@ -314,4 +314,16 @@ class OrderRefundModel extends Model
return $tmp;
}
// 获取活动期间已完成退款的用户金额
public function getJointReturnAmount($user_id, $start_time, $end_time)
{
return $this->where('user_id', $user_id)
->where('status', 10)
->whereBetween('refund_time', [$start_time, $end_time])
->select('user_id', 'currency', 'pay_amount', 'price_fall')
->get()
->toArray();
}
}
\ No newline at end of file
......@@ -229,4 +229,15 @@ class OrderReturnModel extends Model
}
}
// 获取活动期间已完成退款的用户金额
public function getSelfReturnAmount($user_id, $start_time, $end_time)
{
return $this->where('user_id', $user_id)
->where('status', 10)
->whereBetween('putaway_time', [$start_time, $end_time])
->select('user_id', 'currency', 'return_amount')
->get()
->toArray();
}
}
\ No newline at end of file
......@@ -13,16 +13,18 @@ class PayLogModel extends Model
protected $primaryKey = 'pay_log_id';
public $timestamps = false;
// 获取联营、自营线上支付记录
// 获取联营、自营线上支付记录 (过滤尽调订单、测试账号)
public function getPayLog($start_time, $end_time)
{
$field = ['p.pay_log_id', 'p.order_id', 'p.order_sn', 'p.user_id', 'p.pay_type', 'p.is_paid', 'p.pay_amount', 'p.pay_time', 'o.currency'];
$data = $this->from('lie_pay_log as p')
->leftJoin('lie_order as o', 'p.order_id', '=', 'o.order_id')
->leftJoin('lie_user_main as u', 'p.user_id', '=', 'u.user_id')
->where('p.is_paid', 1)
->whereBetween('p.pay_time', [$start_time, $end_time])
->where('o.status', '>', 2)
->where('o.is_type', 0)
->where('u.is_test', 0)
->select($field)
// ->select('user_id', DB::raw('sum(pay_amount) as pay_amount'))
->orderBy('p.pay_time', 'desc')
......
......@@ -13,14 +13,17 @@ class RemovalModel extends Model
protected $primaryKey = 'removal_id';
public $timestamps = false;
// 自营账期支付记录
// 自营账期支付记录 (过滤尽调订单、测试账号)
public function getSelfAccounts($start_time, $end_time)
{
$field = ['removal_id', 'order_id', 'order_sn', 'user_id', 'checkout_paid', 'checkout_paid_time', 'checkout_paid_amount'];
$data = $this->where('checkout_paid', 1)
->whereBetween('checkout_paid_time', [$start_time, $end_time])
$field = ['r.removal_id', 'r.order_id', 'r.order_sn', 'r.user_id', 'r.checkout_paid', 'r.checkout_paid_time', 'r.checkout_paid_amount', 'o.currency'];
$data = $this->from('lie_removal as r')
->leftJoin('lie_order as o', 'r.order_id', '=', 'o.order_id')
->leftJoin('lie_user_main as u', 'r.user_id', '=', 'u.user_id')
->where('r.checkout_paid', 1)
->whereBetween('r.checkout_paid_time', [$start_time, $end_time])
->select($field)
->orderBy('checkout_paid_time', 'desc')
->orderBy('r.checkout_paid_time', 'desc')
->get()
->toArray();
......
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