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';
  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->get($ids);
  45. if (!$row) {
  46. $this->error(__('No Results were found'));
  47. }
  48. $row->load(['user', 'identity', 'province', 'city', 'district', 'admin']);
  49. $this->view->assign('row', $row);
  50. return $this->view->fetch();
  51. }
  52. /**
  53. * 审核通过
  54. */
  55. public function approve($ids = null)
  56. {
  57. if (!$this->request->isPost()) {
  58. $this->error(__('Invalid parameters'));
  59. }
  60. $row = $this->model->get($ids);
  61. if (!$row) {
  62. $this->error(__('No Results were found'));
  63. }
  64. if ($row->status != ApplyModel::STATUS_PENDING) {
  65. $this->error('该申请已经处理过了');
  66. }
  67. Db::transaction(function () use ($row) {
  68. $service = new AgentApplyService();
  69. $service->approveApply($row, $this->auth->id);
  70. });
  71. $this->success('审核通过成功');
  72. }
  73. /**
  74. * 审核拒绝
  75. */
  76. public function reject($ids = null)
  77. {
  78. if (!$this->request->isPost()) {
  79. $this->error(__('Invalid parameters'));
  80. }
  81. $row = $this->model->get($ids);
  82. if (!$row) {
  83. $this->error(__('No Results were found'));
  84. }
  85. if ($row->status != ApplyModel::STATUS_PENDING) {
  86. $this->error('该申请已经处理过了');
  87. }
  88. $reason = $this->request->post('reason', '');
  89. if (empty($reason)) {
  90. $this->error('请填写拒绝原因');
  91. }
  92. $service = new AgentApplyService();
  93. $service->rejectApply($row, $reason, $this->auth->id);
  94. $this->success('审核拒绝成功');
  95. }
  96. /**
  97. * 批量审核通过
  98. */
  99. public function multi($ids = null)
  100. {
  101. if (!$this->request->isPost()) {
  102. $this->error(__('Invalid parameters'));
  103. }
  104. $action = $this->request->post('action');
  105. if ($action != 'approve') {
  106. return parent::multi($ids);
  107. }
  108. if (!$ids) {
  109. $this->error(__('Parameter %s can not be empty', 'ids'));
  110. }
  111. $ids = explode(',', $ids);
  112. $service = new AgentApplyService();
  113. Db::transaction(function () use ($ids, $service) {
  114. foreach ($ids as $id) {
  115. $row = $this->model->get($id);
  116. if ($row && $row->status == ApplyModel::STATUS_PENDING) {
  117. $service->approveApply($row, $this->auth->id);
  118. }
  119. }
  120. });
  121. $this->success('批量审核成功');
  122. }
  123. }