| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- namespace addons\SalesCompany\api\modules\v1\controllers;
- use Yii;
- use api\controllers\OnAuthController;
- use addons\SalesCompany\common\models\CommissionLog;
- use addons\SalesCompany\common\models\SalesCompany;
- use common\models\user\User;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\SalesCompany\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';
- }
- /**
- *我的收益列表
- * @return array|mixed
- */
- public function actionList(){
- try{
- if (\Yii::$app->request->isGet) {
- $res = SalesCompany::findOne(['user_id'=>$this->user->id]);
- if(!$res){
- throw new \Exception('您还未绑定销售公司');
- }
- $param = \Yii::$app->request->get();
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['=', 'user_id', $this->user->id];
- $params['where'] = $where;
- $params['order'] = ' created_at desc';
- $params['select'] = 'id,user_id,created_at,desc,money';
- $data = CommissionLog::listPage($params, false);
- if(!empty($data['list'])){
- foreach($data['list'] as &$list){
- $list['created_at'] = date('Y-m-d H:i:s',$list['created_at']);
- $list['type'] = 1;
- }
- }
- $data['total_money'] = 0;
- $data['today_money'] = 0;
- $data['rate_money'] = 0;
- $commissionLog = CommissionLog::find()->select('sum(money) as money,sum(total_money) as total_money')->where(['user_id'=>$this->user->id,'mall_id'=>$this->mall_id])->asArray()->one();
- if($commissionLog){
- $data['total_money'] = $commissionLog['money'] ?? 0;
- $data['rate_money'] = $commissionLog['total_money'] - $commissionLog['money'] ?? 0;
- }
- $start_time = strtotime(date('Y-m-d 00:00:00',time()));
- $end_time = $start_time + 24 * 60 * 60;
- $commissionLog = CommissionLog::find()
- ->select('sum(money) as money')
- ->where(['user_id'=>$this->user->id,'mall_id'=>$this->mall_id])
- ->andWhere(['>=','created_at',$start_time])
- ->andWhere(['<','created_at',$end_time])
- ->asArray()
- ->one();
- if($commissionLog){
- $data['today_money'] = $commissionLog['money'] ?? 0;
- }
- $user = User::findOne(['id'=>$this->user->id]);
- $data['user'] = [
- 'nickname' => $user->nickname,
- 'id' => $user->id,
- 'avatar_url' => $user->avatar_url,
- ];
- return $this->success('操作成功', $data);
- }else{
- throw new \Exception("请求方法错误!");
- }
- }catch(\Exception $e){
- return $this->error($e->getMessage());
- }
- }
- }
|