| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- namespace addons\ReservationService\api\modules\v1\controllers;
- use addons\ReservationService\common\enums\ReservationServiceEnum;
- use addons\ReservationService\common\models\ReservationServiceUser;
- use addons\ReservationService\common\services\CommissionService;
- use addons\ReservationService\common\services\UserService;
- use api\controllers\OnAuthController;
- use common\enums\StatusEnum;
- use common\models\common\CapitalLog;
- use common\models\user\User;
- use common\models\user\UserPartitionRelationship;
- class CommissionController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = [];
- public function actionIndex()
- {
- $params = \Yii::$app->request->get();
- $res = \Yii::$app->services->validate->validate($params, [
- [['page', 'limit', 'status'],'integer'],
- ]);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- // $ret = (new CommissionService())->page($this->mall_id, $params, $this->user_id);
- $ret = (new CommissionService())->list($this->mall_id, $this->user_id, $params);
- return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret);
- }
- public function actionHead()
- {
- // 用户信息
- $data['user_id'] = empty($this->user_id) ? 0 : $this->user_id;
- $data['nickname'] = empty($this->user->nickname) ? '' : $this->user->nickname;
- $data['avatar_url'] = empty($this->user->avatar_url) ? '' : $this->user->avatar_url;
- $data['mobile'] = empty($this->user->mobile) ? '' : $this->user->mobile;
- $data['level_name'] = empty($user_level_arr[$this->user->level]) ? '普通会员' : $user_level_arr[$this->user->level];
- $data['level'] = empty($this->user->level) ? '' : $this->user->level;
- $data['tag'] = [];
- $service = new UserService();
- try {
- $user = $service->customByUserId($this->mall_id, $this->user_id);
- $data['staff_level_name'] = empty($user['level']) ? '默认等级' : $user['level']['name'];
- // 佣金
- $wallet_type = 'commission';
- CapitalLog::$capitalType = "{$wallet_type}_frozen";
- $where = ['user_id' => $this->user_id, 'from_type' => ReservationServiceEnum::ADDONS_NAME, 'status' => CapitalLog::STATUS_WAIT_SEND];
- $query = CapitalLog::find();
- $frozen_price = $query->where($where)->sum('change_num');
- CapitalLog::$capitalType = "{$wallet_type}";
- $where = ['user_id' => $this->user_id, 'from_type' => ReservationServiceEnum::ADDONS_NAME];
- $query = CapitalLog::find();
- $total_price = $query->where($where)->sum('change_num');
- $data['statistics'] = [
- 'unsettlement' => bcmul(empty($frozen_price) ? 0 : $frozen_price, 1, 2),
- 'settled' => bcmul(empty($total_price) ? 0 : $total_price, 1, 2),
- 'total' => bcmul((empty($total_price) ? 0 : $total_price) + (empty($frozen_price) ? 0 : $frozen_price), 1, 2),
- ];
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- return $this->success('获取成功', $data);
- }
- /**
- * 我的团队
- * @return mixed|null
- */
- public function actionTeam()
- {
- $child = User::find()->select('id')->where(['mall_id' => $this->mall_id])
- ->andWhere(['parent_id' => $this->user_id])->select('id')->column();
- $list = [
- 'first' => [],
- 'second'=> []
- ];
- if (!empty($child)) {
- $s_child = User::find()->select('id')->where(['mall_id' => $this->mall_id])
- ->andWhere(['parent_id' => $child])->select('id')->column();
- if (!empty($s_child)) {
- $list['second'] = ReservationServiceUser::lists([
- 'where' => [
- ['mall_id' => $this->mall_id],
- ['status' => StatusEnum::ENABLED],
- ['check_status' => ReservationServiceEnum::CHECK_ADOPT],
- ['user_id' => $s_child]
- ],
- 'select'=> 'user_id',
- 'order' => 'id desc',
- 'with' => ['user' => function($query) {
- $query->select('id, nickname, avatar_url, mobile');
- }]
- ]);
- if (!empty($list['second'])) {
- foreach ($list['second'] as &$item) {
- $item = $item['user'];
- }
- }
- }
- $list['first'] = ReservationServiceUser::lists([
- 'where' => [
- ['mall_id' => $this->mall_id],
- ['status' => StatusEnum::ENABLED],
- ['check_status' => ReservationServiceEnum::CHECK_ADOPT],
- ['user_id' => $child]
- ],
- 'select'=> 'user_id',
- 'order' => 'id desc',
- 'with' => ['user' => function($query) {
- $query->select('id, nickname, avatar_url, mobile');
- }]
- ]);
- if (!empty($list['first'])) {
- foreach ($list['first'] as &$item) {
- $item = $item['user'];
- }
- }
- }
- return $this->success('获取成功', $list);
- }
- }
|