| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- <?php
- namespace addons\BossWeight\api\modules\v1\controllers;
- use addons\BossWeight\common\logic\CommissionLogLogic;
- use addons\BossWeight\common\models\AddonsBoss;
- use addons\BossWeight\common\models\AddonsBossCommissionLog;
- use addons\BossWeight\common\models\AddonsBossLevel;
- use addons\BossWeight\common\models\AddonsBossLevelSetting;
- use common\enums\OrderStatusEnum;
- use common\enums\StatusEnum;
- use common\models\order\Order;
- use Yii;
- use api\controllers\OnAuthController;
- use addons\BossWeight\common\enums\BossEnum;
- use addons\BossWeight\common\enums\LevelEnum;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\BossWeight\api\modules\v1\controllers
- */
- class DefaultController extends OnAuthController
- {
- public $modelClass = '';
- public $enableCsrfValidation = false;
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- // protected $authOptional = ['index'];
- /**
- * 股东分红首页
- *
- * @return string
- */
- public function actionIndex()
- {
- if (Yii::$app->request->isGet) {
- $get = Yii::$app->request->get();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($get,[
- [['page','limit'], 'integer']
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $data['user_id'] = $this->user_id;
- $data['nickname'] = $this->user->nickname ?? '';
- $data['avatar_url'] = $this->user->avatar_url ?? '';
- // 获取股东信息
- $boss = AddonsBoss::getOne([['mall_id' => $this->mall_id,'user_id' => $this->user_id,'status'=>1]]);
- if(!$boss){
- return $this->error('您还不是股东,无法查看股东信息');
- }
- // 数据初始化
- $amounts = 0;
- $commission = 0;
- // 获取配置
- $config = \Yii::$app->services->setting->addons->get($this->mall_id, BossEnum::ADDONS_NAME, 'basic');
- $data['total_turnover_name'] = $config['total_turnover_name'] ?? '平台营业额';
- $data['amounts_name'] = $config['amounts_name'] ?? '上期股东收益';
- $data['user_weight_name'] = $config['user_weight_name'] ?? '持有权重数量';
- $data['total_weight_name'] = $config['total_weight_name'] ?? '平台总权重数量';
- $data['is_customize'] = $config['is_customize'] ?? 0;
- // 获取收益列表
- $where = [];
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['=', 'user_id', $this->user_id];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- $order = 'created_at desc,end_time desc';
- $select = 'amounts,commission,type,compute_period,start_time,end_time';
- $params = array('where' => $where, 'order' => $order, 'select' => $select , 'limit' => $get['limit']);
- $list = AddonsBossCommissionLog::listPage($params, false, true);
- $commonission_type = LevelEnum::getCommissionType();// 分红类型
- foreach ($list['list'] as $key => &$item) {
- // if ($get['page'] == 1) {
- // // 循环获取本期收益
- // if (in_array($key, [1])) {
- // if ($item['type'] == 1) {
- //// $amounts = $item['amounts'];
- // $commission += $item['commission'];
- // }
- // if ($item['type'] == 2) $commission += $item['commission'];
- // if ($item['type'] == 4) $commission += $item['commission'];
- // }
- // }
- if($get['page'] == 1){
- if($item['type'] == 4 && $item['start_time'] == date("Ymd",strtotime('-1 day'))){
- $commission += $item['commission'];
- }
- }
- $item['start_time'] = date_format(date_create($item['start_time']),"Y-m-d");
- $item['end_time'] = date_format(date_create($item['end_time']),"Y-m-d");
- $item['type_desc'] = $commonission_type[$item['type']] ?? '';
- if($item['type'] == 4 && $data['is_customize']){
- $item['type_desc'] = '权重鼎分红';
- }
- }
- if(isset($config['compute_show_type']) && $config['compute_show_type'] == 2){
- $computeTimeArr = [strtotime(date('Y-m-d 00:00:00')),strtotime(date('Y-m-d 00:00:00'))];
- }else{
- //获取结算时间
- $computeTimeArr = CommissionLogLogic::getComputeTime($this->mall_id);
- }
- $totalTurnover = Order::find()->where([
- 'pay_status' => [ OrderStatusEnum::PAY],
- 'mall_id' => $this->mall_id,
- 'status' => 1,
- ])->andWhere([
- 'and',
- ['>=','pay_time',$computeTimeArr[0]],
- ['<','pay_time',$computeTimeArr[1] + 86400],
- ])->sum('pay_money');
- $totalTurnover = $totalTurnover?:0;
- //昨日营业额
- $startDate = date('Y-m-d',strtotime("-1 day"));
- $yesterdayTurnover = Order::find()->where([
- 'pay_status' => [ OrderStatusEnum::PAY],
- 'mall_id' => $this->mall_id,
- 'status' => 1,
- ])->andWhere([
- 'and',
- ['>=','pay_time',strtotime($startDate)],
- ['<','pay_time',strtotime(date("Y-m-d"))],
- ])->sum('pay_money');
- $yesterdayTurnover = $yesterdayTurnover?:0;
- $data['is_boss'] = $boss ? 1 : 0;// 是否是股东,0=否,1=是
- // $data['amounts'] = sprintf("%.2f",substr(sprintf("%.3f", $amounts), 0, -2));// 分红池
- $data['commission'] = sprintf("%.2f",substr(sprintf("%.3f", $commission), 0, -2));// 本期收益
- $total_weight = CommissionLogLogic::getTotalWeight($this->mall_id);//平台权重
- if(!empty($boss)){
- $level = $boss->level;
- $levelData = AddonsBossLevelSetting::find()->where(["level" => $level,"status" => AddonsBossLevelSetting::STATUS_ENABLE,'mall_id'=>$this->mall_id])->one();
- if(!empty($levelData)){
- $totalTurnover = round($totalTurnover * $levelData->weight_turnover_ratio / 100,2);
- $yesterdayTurnover = round($yesterdayTurnover * $levelData->weight_turnover_ratio / 100,2);
- }
- }else{
- $totalTurnover = 0;
- $yesterdayTurnover = 0;
- $total_weight = 0;
- }
- //加权分红
- $data['total_turnover'] = $totalTurnover;//平台营业额
- $data['amounts'] = $yesterdayTurnover;// 分红池,昨日营业额
- $data['total_weight'] = $total_weight;//平台权重
- $bossArr = AddonsBoss::find()->where(['mall_id' => $this->mall_id,'user_id' => $this->user_id,'status'=>1])->asArray()->one();
- $data['user_weight'] = 0;
- if($bossArr){
- $data['user_weight'] = CommissionLogLogic::getBossWeight($bossArr);//用户权重
- }
- $data['able_withdrawal_commission'] = $boss->commission;// 可提现收益
- $data['list'] = $list;
- $this->success('获取成功', $data);
- }
- }
- public function actionRights()
- {
- if (Yii::$app->request->isGet) {
- // 获取股东信息
- $boss = AddonsBoss::getOne([['mall_id' => $this->mall_id,'user_id' => $this->user_id]]);
- // 获取股东等级
- $list = AddonsBossLevel::getBossLevel([['mall_id' => $this->mall_id]],[],true,'level,name,explain','level asc');
- foreach ($list as $level) {
- if ($boss->level == $level['level']) {
- $level_name = $level['name'];
- break;
- }
- }
- $data['user_id'] = $this->user_id;
- $data['nickname'] = $this->user->nickname ?? '';
- $data['avatar_url'] = $this->user->avatar_url ?? '';
- $data['level_name'] = $level_name ?? '';
- $data['list'] = $list;
- $this->success('获取成功', $data);
- }
- }
- }
|