| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace addons\OperationCenter\api\modules\v1\controllers;
- use addons\OperationCenter\common\models\CommissionLog;
- use addons\OperationCenter\common\models\Level;
- use addons\OperationCenter\common\models\UserCenter;
- use Yii;
- use api\controllers\OnAuthController;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\OperationCenter\api\modules\v1\controllers
- */
- class DefaultController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = ['index'];
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- return 'Hello world';
- }
- /**
- * 获取用户运营中心信息
- * @Author: lun
- * @DateTime: 2023/8/18 0018 14:10
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- * @throws \Exception
- */
- public function actionInfo()
- {
- if (Yii::$app->request->isGet) {
- $data['user_id'] = $this->user_id;
- $data['nickname'] = $this->user->nickname ?? '';
- $data['avatar_url'] = $this->user->avatar_url ?? '';
- $data['is_operation_center'] = 0;// 是否有运营中心身份
- $data['level_name'] = '普通用户';
- $data['frozen_commission'] = 0;// 待结算
- $data['commission'] = 0;// 已结算
- $data['total_commission'] = 0;// 总计金额
- // 获取用户运营中心信息
- $user = UserCenter::findOne(['user_id' => $this->user_id]);
- if ($user) {
- $data['level_name'] = Level::find()->select('name')->where(['mall_id' => $this->mall_id, 'level' => $user->level])->scalar();
- $data['is_operation_center'] = 1;
- $data['frozen_commission'] = bcsub($user->settlement_amount_total, $user->settlement_amount, 2) ;// 待结算
- $data['commission'] = $user->settlement_amount ;// 已结算
- $data['total_commission'] = $user->settlement_amount_total;// 总计金额
- }
- return $this->success('获取成功', $data);
- }
- }
- /**
- * 运营中心收益记录
- * @Author: lun
- * @DateTime: 2023/8/18 0018 14:18
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionCommissionLog()
- {
- 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());
- // 查询推荐内容
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['=', 'user_id', $this->user_id];
- $order = 'id desc,created_at desc';
- $select = 'user_id,from_user_id,goods_name,goods_price,order_no,commission_amount,status,created_at';
- $with = ['fromUser'];
- $params = array('where' => $where, 'order' => $order, 'select' => $select, 'with' => $with, 'limit' => 10);
- $list = CommissionLog::listPage($params);
- return $this->success('获取成功', $list);
- }
- }
- }
|