Commission.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace app\api\controller\commission;
  3. use app\common\Service\Commission\Agent as AgentService;
  4. use app\common\model\commission\Agent as AgentModel;
  5. use app\common\Service\ShopConfigService;
  6. use app\api\controller\Base;
  7. class Commission extends Base
  8. {
  9. protected AgentService $service;
  10. public function _initialize()
  11. {
  12. parent::_initialize();
  13. $on = ShopConfigService::getConfigField('shop.commission.level');
  14. if (!$on) {
  15. $this->error('分销中心已关闭,该功能暂不可用', null, 101);
  16. }
  17. $user = auth_user();
  18. // 检查分销商状态
  19. $this->service = new AgentService($user);
  20. // 检查用户是否是代理商
  21. if (!$this->service->agent) {
  22. $this->error('您还不是代理商,无法访问该功能', null);
  23. }
  24. // 检查代理商状态是否被禁用
  25. if ($this->service->agent->status === AgentModel::AGENT_STATUS_FORBIDDEN) {
  26. $this->error('您的账户已被禁用,该功能暂不可用', null);
  27. }
  28. }
  29. }