<?php
|
|
namespace app\api\controller\user;
|
|
use app\api\controller\Controller;
|
use app\api\model\plus\region\Referee;
|
use app\api\model\plus\region\Setting;
|
use app\api\model\plus\region\User as RegionUserModel;
|
use app\api\model\plus\region\Apply as RegionApplyModel;
|
use app\api\model\plus\team\Order as TeamOrder;
|
use app\api\model\settings\Message as MessageModel;
|
use app\api\model\plus\agent\User as AgentUserModel;
|
use app\common\model\product\Product as ProductModel;
|
use app\api\model\order\OrderProduct as OrderProductModel;
|
use app\common\model\settings\Region as RegionModel;
|
|
/**
|
* 分销中心
|
*/
|
class Region extends Controller
|
{
|
// 用户
|
private $user;
|
// 股东
|
private $region;
|
// 代理设置
|
private $setting;
|
|
/**
|
* 构造方法
|
*/
|
public function initialize()
|
{
|
// 用户信息
|
$this->user = $this->getUser();
|
// 代理信息
|
$this->region = RegionUserModel::detail($this->user['user_id'],['user','grade']);
|
// 代理设置
|
$this->setting = Setting::getAll();
|
// 分销商用户信息
|
$this->agent = AgentUserModel::detail($this->user['user_id']);
|
}
|
|
/**
|
* 股东中心
|
*/
|
public function center()
|
{
|
//如果不是股东,列出条件 by lyzflash
|
$is_region = $this->isRegionUser();
|
$setting = $this->setting['basic']['values'];
|
$agent_total = $agent_money = $team_money = 0;
|
$can_register = false;
|
if ($setting['become'] == 10) {
|
$can_register = true;
|
}
|
//统计下级分销商总数
|
if ($setting['become'] == '40' && $this->agent) {
|
$agent_total = $this->agent['first_num'] + $this->agent['second_num']+ $this->agent['third_num'];
|
$can_register = $agent_total >= $setting['totalfxs_down'];
|
}
|
// 累计佣金
|
if ($setting['become'] == '50' && $this->agent) {
|
$agent_money = $this->agent['total_money'];
|
$can_register = $agent_money >= $setting['total_money'];
|
}
|
// 累计团队业绩
|
if ($setting['become'] == '70') {
|
$team_money = TeamOrder::getOrderAllPrice($this->user['user_id']);
|
$can_register = $team_money >= $setting['total_team_money'];
|
}
|
// 购买商品
|
$productList = [];
|
if ($setting['become'] == '100') {
|
if ($setting['become__buy_product_ids']) {
|
$productList = (new ProductModel)->getListByIds($setting['become__buy_product_ids']);
|
$userBuyCount = (new OrderProductModel)->where('product_id', 'IN', $setting['become__buy_product_ids'])
|
->where('user_id', '=', $this->user['user_id'])
|
->count();
|
$can_register = $userBuyCount > 0;
|
}
|
}
|
return $this->renderSuccess('', [
|
// 当前是否为分销商
|
'is_agent' => $this->isAgentUser(),
|
// 当前是否为股东
|
'is_region' => $is_region,
|
// 当前是否在申请中
|
'is_applying' => RegionApplyModel::isApplying($this->user['user_id']),
|
// 当前用户信息
|
'user' => $this->user,
|
// 股东用户信息
|
'region' => $this->region,
|
// 背景图
|
'background' => $this->setting['background']['values']['index'],
|
//权益说明
|
'description_pic' => $this->setting['background']['values']['description'],
|
// 页面文字
|
'words' => $this->setting['words']['values'],
|
//'regionnum'=>count($user_ids),
|
// 下级分销商总数
|
'agent_total' => $agent_total,
|
// 累计佣金
|
'agent_money' => $agent_money,
|
// 累计团队业绩
|
'team_money' => $team_money,
|
'setting' => $setting,
|
'can_register' => $can_register,
|
'productList' => $productList
|
]);
|
}
|
|
/**
|
* 股东申请状态
|
*/
|
public function apply($platform= '')
|
{
|
$regionData = RegionModel::getRegionForApi();
|
return $this->renderSuccess('', [
|
// 当前是否为股东
|
'is_region' => $this->isRegionUser(),
|
// 当前是否在申请中
|
'is_applying' => RegionApplyModel::isApplying($this->user['user_id']),
|
// 背景图
|
'background' => $this->setting['background']['values']['apply'],
|
//权益说明
|
'description' => $this->setting['background']['values']['description'],
|
// 页面文字
|
'words' => $this->setting['words']['values'],
|
// 申请协议
|
'license' => $this->setting['license']['values']['license'],
|
// 如果来源是小程序, 则获取小程序订阅消息id.获取售后通知.
|
'template_arr' => MessageModel::getMessageByNameArr($platform, ['region_apply_user']),
|
'regionData' => $regionData,
|
]);
|
}
|
|
/**
|
* 股东提现信息
|
*/
|
public function cash($platform = '')
|
{
|
// 如果来源是小程序, 则获取小程序订阅消息id.获取售后通知.
|
$template_arr = MessageModel::getMessageByNameArr($platform, ['region_cash_user']);
|
return $this->renderSuccess('', [
|
// 股东用户信息
|
'region' => $this->region,
|
// 结算设置
|
'settlement' => $this->setting['settlement']['values'],
|
// 背景图
|
'background' => $this->setting['background']['values']['cash_apply'],
|
// 页面文字
|
'words' => $this->setting['words']['values'],
|
// 小程序消息
|
'template_arr' => $template_arr
|
]);
|
}
|
|
/**
|
* 当前用户是否为股东
|
*/
|
private function isRegionUser()
|
{
|
return !!$this->region && !$this->region['is_delete'];
|
}
|
|
/**
|
* 当前用户是否为分销商
|
*/
|
private function isAgentUser()
|
{
|
return !!$this->agent && !$this->agent['is_delete'];
|
}
|
}
|