@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\service\partner;
|
||||
|
||||
use app\admin\model\shopro\order\Order as OrderModel;
|
||||
|
||||
/**
|
||||
* 30 日活跃:含今天共 N 个自然日有本人合格订单
|
||||
*/
|
||||
class ActiveService
|
||||
{
|
||||
public function windowStart($endTime = null)
|
||||
{
|
||||
$days = PartnerConfig::activeDays();
|
||||
$end = $endTime ?: time();
|
||||
$endDay = strtotime(date('Y-m-d 00:00:00', $end));
|
||||
return $endDay - ($days - 1) * 86400;
|
||||
}
|
||||
|
||||
public function isActive($agent, $atTime = null)
|
||||
{
|
||||
if (!$agent) {
|
||||
return false;
|
||||
}
|
||||
$last = is_array($agent) ? ($agent['last_self_order_time'] ?? null) : ($agent->last_self_order_time ?? null);
|
||||
$userId = is_array($agent) ? ($agent['user_id'] ?? 0) : ($agent->user_id ?? 0);
|
||||
$at = $atTime ?: time();
|
||||
$start = $this->windowStart($at);
|
||||
|
||||
if ($last) {
|
||||
return intval($last) >= $start;
|
||||
}
|
||||
if (!$userId) {
|
||||
return false;
|
||||
}
|
||||
return $this->hasQualifiedOrder($userId, $start, $at);
|
||||
}
|
||||
|
||||
public function hasQualifiedOrder($userId, $start, $end)
|
||||
{
|
||||
$order = OrderModel::where('user_id', $userId)
|
||||
->where('type', '<>', 'score')
|
||||
->where('pay_fee', '>', 0)
|
||||
->paid()
|
||||
->where('paid_time', '>=', $start)
|
||||
->where('paid_time', '<=', $end)
|
||||
->find();
|
||||
return (bool) $order;
|
||||
}
|
||||
|
||||
public function activeUserIds($start, $end, $extraWhere = [])
|
||||
{
|
||||
$query = \think\Db::name('shopro_commission_agent')
|
||||
->where('status', 'in', ['normal', 'freeze'])
|
||||
->where('level', '>=', 1)
|
||||
->where(function ($q) use ($start, $end) {
|
||||
$q->where('last_self_order_time', '>=', $start)
|
||||
->where('last_self_order_time', '<=', $end);
|
||||
});
|
||||
foreach ($extraWhere as $field => $value) {
|
||||
$query->where($field, $value);
|
||||
}
|
||||
return $query->column('user_id');
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户