DefaultController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace addons\OperationCenter\api\modules\v1\controllers;
  3. use addons\OperationCenter\common\models\CommissionLog;
  4. use addons\OperationCenter\common\models\Level;
  5. use addons\OperationCenter\common\models\UserCenter;
  6. use Yii;
  7. use api\controllers\OnAuthController;
  8. /**
  9. * 默认控制器
  10. *
  11. * Class DefaultController
  12. * @package addons\OperationCenter\api\modules\v1\controllers
  13. */
  14. class DefaultController extends OnAuthController
  15. {
  16. public $modelClass = '';
  17. /**
  18. * 不用进行登录验证的方法
  19. *
  20. * 例如: ['index', 'update', 'create', 'view', 'delete']
  21. * 默认全部需要验证
  22. *
  23. * @var array
  24. */
  25. protected $authOptional = ['index'];
  26. /**
  27. * 首页
  28. *
  29. * @return string
  30. */
  31. public function actionIndex()
  32. {
  33. return 'Hello world';
  34. }
  35. /**
  36. * 获取用户运营中心信息
  37. * @Author: lun
  38. * @DateTime: 2023/8/18 0018 14:10
  39. * @Copyright: copyright (c) 2021 广东七件事集团
  40. * @return mixed|void
  41. * @throws \Exception
  42. */
  43. public function actionInfo()
  44. {
  45. if (Yii::$app->request->isGet) {
  46. $data['user_id'] = $this->user_id;
  47. $data['nickname'] = $this->user->nickname ?? '';
  48. $data['avatar_url'] = $this->user->avatar_url ?? '';
  49. $data['is_operation_center'] = 0;// 是否有运营中心身份
  50. $data['level_name'] = '普通用户';
  51. $data['frozen_commission'] = 0;// 待结算
  52. $data['commission'] = 0;// 已结算
  53. $data['total_commission'] = 0;// 总计金额
  54. // 获取用户运营中心信息
  55. $user = UserCenter::findOne(['user_id' => $this->user_id]);
  56. if ($user) {
  57. $data['level_name'] = Level::find()->select('name')->where(['mall_id' => $this->mall_id, 'level' => $user->level])->scalar();
  58. $data['is_operation_center'] = 1;
  59. $data['frozen_commission'] = bcsub($user->settlement_amount_total, $user->settlement_amount, 2) ;// 待结算
  60. $data['commission'] = $user->settlement_amount ;// 已结算
  61. $data['total_commission'] = $user->settlement_amount_total;// 总计金额
  62. }
  63. return $this->success('获取成功', $data);
  64. }
  65. }
  66. /**
  67. * 运营中心收益记录
  68. * @Author: lun
  69. * @DateTime: 2023/8/18 0018 14:18
  70. * @Copyright: copyright (c) 2021 广东七件事集团
  71. * @return mixed|void
  72. */
  73. public function actionCommissionLog()
  74. {
  75. if (Yii::$app->request->isGet) {
  76. $get = Yii::$app->request->get();
  77. // 检查提交的参数
  78. $res = Yii::$app->services->validate->validate($get,[
  79. [['page','limit'], 'integer'],
  80. ]);
  81. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  82. // 查询推荐内容
  83. $where[] = ['=', 'mall_id', $this->mall_id];
  84. $where[] = ['=', 'user_id', $this->user_id];
  85. $order = 'id desc,created_at desc';
  86. $select = 'user_id,from_user_id,goods_name,goods_price,order_no,commission_amount,status,created_at';
  87. $with = ['fromUser'];
  88. $params = array('where' => $where, 'order' => $order, 'select' => $select, 'with' => $with, 'limit' => 10);
  89. $list = CommissionLog::listPage($params);
  90. return $this->success('获取成功', $list);
  91. }
  92. }
  93. }