|
@@ -7,14 +7,14 @@ use app\common\model\Order as OrderModel;
|
|
use app\common\model\User as UserModel;
|
|
use app\common\model\User as UserModel;
|
|
use think\Hook;
|
|
use think\Hook;
|
|
use think\Db;
|
|
use think\Db;
|
|
-
|
|
|
|
|
|
+use app\common\Service\Commission\Agent as AgentService;
|
|
/**
|
|
/**
|
|
* 测试控制器
|
|
* 测试控制器
|
|
* 仅用于开发和测试环境
|
|
* 仅用于开发和测试环境
|
|
*/
|
|
*/
|
|
class Test extends Api
|
|
class Test extends Api
|
|
{
|
|
{
|
|
- protected $noNeedLogin = [];
|
|
|
|
|
|
+ protected $noNeedLogin = ['getCommissionStats'];
|
|
protected $noNeedRight = ['*'];
|
|
protected $noNeedRight = ['*'];
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -68,61 +68,20 @@ class Test extends Api
|
|
/**
|
|
/**
|
|
* 获取分销统计数据
|
|
* 获取分销统计数据
|
|
*/
|
|
*/
|
|
- private function getCommissionStats($order, $user)
|
|
|
|
|
|
+ public function getCommissionStats()
|
|
{
|
|
{
|
|
- // 查询分销订单
|
|
|
|
- $commissionOrders = Db::name('commission_order')
|
|
|
|
- ->where('order_id', $order->id)
|
|
|
|
- ->select();
|
|
|
|
-
|
|
|
|
- // 查询佣金记录
|
|
|
|
- $rewards = Db::name('commission_reward')
|
|
|
|
- ->alias('r')
|
|
|
|
- ->leftJoin('commission_order o', 'r.commission_order_id = o.id')
|
|
|
|
- ->where('o.order_id', $order->id)
|
|
|
|
- ->field('r.*')
|
|
|
|
- ->select();
|
|
|
|
-
|
|
|
|
- // 查询用户分销商信息
|
|
|
|
- $agent = Db::name('shop_commission_agent')
|
|
|
|
- ->where('user_id', $user->id)
|
|
|
|
- ->find();
|
|
|
|
-
|
|
|
|
- // 查询用户的上级关系
|
|
|
|
- $parentInfo = null;
|
|
|
|
- if ($user->parent_user_id > 0) {
|
|
|
|
- $parentUser = UserModel::where('id', $user->parent_user_id)->find();
|
|
|
|
- if ($parentUser) {
|
|
|
|
- $parentAgent = Db::name('shop_commission_agent')
|
|
|
|
- ->where('user_id', $parentUser->id)
|
|
|
|
- ->find();
|
|
|
|
-
|
|
|
|
- $parentInfo = [
|
|
|
|
- 'parent_user_id' => $parentUser->id,
|
|
|
|
- 'parent_nickname' => $parentUser->nickname,
|
|
|
|
- 'parent_is_agent' => !empty($parentAgent),
|
|
|
|
- 'bind_time' => $user->bind_time ? date('Y-m-d H:i:s', $user->bind_time) : null
|
|
|
|
- ];
|
|
|
|
- }
|
|
|
|
|
|
+ //$userId = $payload['user_id'];
|
|
|
|
+ $userId = $this->request->param('user_id');
|
|
|
|
+ if (empty($userId)) {
|
|
|
|
+ $this->error('请提供用户ID');
|
|
}
|
|
}
|
|
|
|
+ $agent = new AgentService($userId);
|
|
|
|
|
|
- return [
|
|
|
|
- 'user_commission' => $user->commission,
|
|
|
|
- 'agent_info' => $agent ? [
|
|
|
|
- 'agent_id' => $agent['id'],
|
|
|
|
- 'agent_type' => $agent['agent_type'],
|
|
|
|
- 'total_income' => $agent['total_income'],
|
|
|
|
- 'withdrawn_amount' => $agent['withdrawn_amount'],
|
|
|
|
- 'child_user_count_all' => $agent['child_user_count_all'],
|
|
|
|
- 'child_order_money_all' => $agent['child_order_money_all'],
|
|
|
|
- ] : null,
|
|
|
|
- 'parent_info' => $parentInfo,
|
|
|
|
- 'commission_orders_count' => count($commissionOrders),
|
|
|
|
- 'commission_orders' => $commissionOrders,
|
|
|
|
- 'rewards_count' => count($rewards),
|
|
|
|
- 'rewards' => $rewards,
|
|
|
|
- 'total_reward_amount' => array_sum(array_column($rewards, 'commission'))
|
|
|
|
- ];
|
|
|
|
|
|
+ if ($agent->user) {
|
|
|
|
+ Db::transaction(function () use ($agent) {
|
|
|
|
+ $agent->runAgentUpgradePlan();
|
|
|
|
+ });
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|