Apply.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace app\admin\controller\commission;
  3. use app\common\controller\Backend;
  4. use app\common\model\commission\Apply as ApplyModel;
  5. use app\common\model\commission\Identity as IdentityModel;
  6. use app\common\Service\commission\AgentApply as AgentApplyService;
  7. use think\Db;
  8. use think\Exception;
  9. class Apply extends Backend
  10. {
  11. protected $model = null;
  12. protected $searchFields = 'id,user.nickname,real_name,company_name,status,agent_type,identity.name';
  13. protected $relationSearch = true;
  14. public function _initialize()
  15. {
  16. parent::_initialize();
  17. $this->model = new ApplyModel();
  18. }
  19. /**
  20. * 查看
  21. */
  22. public function index()
  23. {
  24. if (!$this->request->isAjax()) {
  25. return $this->view->fetch();
  26. }
  27. if ($this->request->request('keyField')) {
  28. return $this->selectpage();
  29. }
  30. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  31. $list = $this->model
  32. ->with(['user', 'identity', 'province', 'city', 'district', 'admin'])
  33. ->where($where)
  34. ->order($sort, $order)
  35. ->paginate($limit);
  36. $result = ['total' => $list->total(), 'rows' => $list->items()];
  37. return json($result);
  38. }
  39. /**
  40. * 详情
  41. */
  42. public function detail($ids = null)
  43. {
  44. $row = $this->model::with(['user', 'identity', 'province', 'city', 'district', 'admin'])
  45. ->where('id', $ids)
  46. ->find();
  47. if (!$row) {
  48. $this->error(__('No Results were found'));
  49. }
  50. $this->view->assign('row', $row);
  51. return $this->view->fetch();
  52. }
  53. /**
  54. * 审核通过
  55. */
  56. public function approve($ids = null)
  57. {
  58. if (!$this->request->isPost()) {
  59. $this->error(__('Invalid parameters'));
  60. }
  61. $row = $this->model->get($ids);
  62. if (!$row) {
  63. $this->error(__('No Results were found'));
  64. }
  65. if ($row->status != ApplyModel::STATUS_PENDING) {
  66. $this->error('该申请已经处理过了');
  67. }
  68. Db::transaction(function () use ($row) {
  69. $service = new AgentApplyService();
  70. $service->approveApply($row, $this->auth->id);
  71. });
  72. $this->success('审核通过成功');
  73. }
  74. /**
  75. * 审核拒绝
  76. */
  77. public function reject($ids = null)
  78. {
  79. if (!$this->request->isPost()) {
  80. $this->error(__('Invalid parameters'));
  81. }
  82. $row = $this->model->get($ids);
  83. if (!$row) {
  84. $this->error(__('No Results were found'));
  85. }
  86. if ($row->status != ApplyModel::STATUS_PENDING) {
  87. $this->error('该申请已经处理过了');
  88. }
  89. $reason = $this->request->post('reason', '');
  90. if (empty($reason)) {
  91. $this->error('请填写拒绝原因');
  92. }
  93. $service = new AgentApplyService();
  94. $service->rejectApply($row, $reason, $this->auth->id);
  95. $this->success('审核拒绝成功');
  96. }
  97. /**
  98. * 批量审核通过
  99. */
  100. public function multi($ids = null)
  101. {
  102. if (!$this->request->isPost()) {
  103. $this->error(__('Invalid parameters'));
  104. }
  105. $action = $this->request->post('action');
  106. if ($action != 'approve') {
  107. return parent::multi($ids);
  108. }
  109. if (!$ids) {
  110. $this->error(__('Parameter %s can not be empty', 'ids'));
  111. }
  112. $ids = explode(',', $ids);
  113. $service = new AgentApplyService();
  114. Db::transaction(function () use ($ids, $service) {
  115. foreach ($ids as $id) {
  116. $row = $this->model->get($id);
  117. if ($row && $row->status == ApplyModel::STATUS_PENDING) {
  118. $service->approveApply($row, $this->auth->id);
  119. }
  120. }
  121. });
  122. $this->success('批量审核成功');
  123. }
  124. }