123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <?php
- namespace app\admin\controller\commission;
- use app\common\controller\Backend;
- use app\common\model\commission\Apply as ApplyModel;
- use app\common\model\commission\Identity as IdentityModel;
- use app\common\Service\commission\AgentApply as AgentApplyService;
- use think\Db;
- use think\Exception;
- class Apply extends Backend
- {
- protected $model = null;
- protected $searchFields = 'id,user.nickname,real_name,company_name,status,agent_type,identity.name';
- protected $relationSearch = true;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new ApplyModel();
- }
- /**
- * 查看
- */
- public function index()
- {
- if (!$this->request->isAjax()) {
- return $this->view->fetch();
- }
-
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
-
- [$where, $sort, $order, $offset, $limit] = $this->buildparams();
-
- $list = $this->model
- ->with(['user', 'identity', 'province', 'city', 'district', 'admin'])
- ->where($where)
- ->order($sort, $order)
- ->paginate($limit);
-
- $result = ['total' => $list->total(), 'rows' => $list->items()];
- return json($result);
- }
- /**
- * 详情
- */
- public function detail($ids = null)
- {
- $row = $this->model::with(['user', 'identity', 'province', 'city', 'district', 'admin'])
- ->where('id', $ids)
- ->find();
- if (!$row) {
- $this->error(__('No Results were found'));
- }
- $this->view->assign('row', $row);
- return $this->view->fetch();
- }
- /**
- * 审核通过
- */
- public function approve($ids = null)
- {
- if (!$this->request->isPost()) {
- $this->error(__('Invalid parameters'));
- }
-
- $row = $this->model->get($ids);
- if (!$row) {
- $this->error(__('No Results were found'));
- }
-
- if ($row->status != ApplyModel::STATUS_PENDING) {
- $this->error('该申请已经处理过了');
- }
-
- Db::transaction(function () use ($row) {
- $service = new AgentApplyService();
- $service->approveApply($row, $this->auth->id);
- });
-
- $this->success('审核通过成功');
- }
- /**
- * 审核拒绝
- */
- public function reject($ids = null)
- {
- if (!$this->request->isPost()) {
- $this->error(__('Invalid parameters'));
- }
-
- $row = $this->model->get($ids);
- if (!$row) {
- $this->error(__('No Results were found'));
- }
-
- if ($row->status != ApplyModel::STATUS_PENDING) {
- $this->error('该申请已经处理过了');
- }
-
- $reason = $this->request->post('reason', '');
- if (empty($reason)) {
- $this->error('请填写拒绝原因');
- }
-
- $service = new AgentApplyService();
- $service->rejectApply($row, $reason, $this->auth->id);
-
- $this->success('审核拒绝成功');
- }
- /**
- * 批量审核通过
- */
- public function multi($ids = null)
- {
- if (!$this->request->isPost()) {
- $this->error(__('Invalid parameters'));
- }
-
- $action = $this->request->post('action');
- if ($action != 'approve') {
- return parent::multi($ids);
- }
-
- if (!$ids) {
- $this->error(__('Parameter %s can not be empty', 'ids'));
- }
-
- $ids = explode(',', $ids);
- $service = new AgentApplyService();
-
- Db::transaction(function () use ($ids, $service) {
- foreach ($ids as $id) {
- $row = $this->model->get($id);
- if ($row && $row->status == ApplyModel::STATUS_PENDING) {
- $service->approveApply($row, $this->auth->id);
- }
- }
- });
-
- $this->success('批量审核成功');
- }
- }
|