CommissionController.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace addons\Community\api\modules\v1\controllers;
  3. use addons\Community\common\service\CommissionService;
  4. use api\controllers\OnAuthController;
  5. use Yii;
  6. class CommissionController extends OnAuthController
  7. {
  8. public $modelClass = '';
  9. /**
  10. * 不用进行登录验证的方法
  11. *
  12. * 例如: ['index', 'update', 'create', 'view', 'delete']
  13. * 默认全部需要验证
  14. *
  15. * @var array
  16. */
  17. protected $authOptional = [];
  18. public function actionIndex()
  19. {
  20. // 是否需要校验验证码
  21. $data = Yii::$app->request->get();
  22. $valid = Yii::$app->services->validate->validate($data, [
  23. [['page', 'limit'], 'integer'],
  24. [['date'], 'string']
  25. ]);
  26. if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  27. $data['user_id'] = $this->user_id; // 自提点管理人
  28. $ret = (new CommissionService())->page($this->mall_id, $data, true);
  29. if (!empty($ret['list'])) {
  30. foreach ($ret['list'] as &$item) {
  31. $item['commission'] = bcdiv($item['commission'], 100, 2);
  32. $item['intro'] = "订单:{$item['order']['order_no']},成功自提获得佣金奖励。";
  33. unset($item['order']);
  34. }
  35. }
  36. if (!empty($ret['commission'])) {
  37. $ret['commission'] = bcdiv($ret['commission'], 100, 2);
  38. }
  39. if (!empty($ret['today_commission'])) {
  40. $ret['today_commission'] = bcdiv($ret['today_commission'], 100, 2);
  41. }
  42. return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret);
  43. }
  44. }