| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- <?php
- namespace app\admin\controller\service\shop;
- use app\common\controller\Backend;
- use think\Db;
- use fast\Random;
- use app\admin\model\service\shop\Shop;
- /**
- * 申请商户管理
- *
- * @icon fa fa-circle-o
- */
- class Applyshop extends Backend
- {
- /**
- * Applyshop模型对象
- * @var \app\admin\model\service\shop\Applyshop
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\service\shop\Applyshop;
- $this->view->assign("applytypeList", $this->model->getApplytypeList());
- $this->view->assign("typeList", $this->model->getTypeList());
- $this->view->assign("stateList", $this->model->getStateList());
- $this->view->assign("toShopList", $this->model->getToShopList());
- }
- public function index()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags', 'trim']);
- if (false === $this->request->isAjax()) {
- return $this->view->fetch();
- }
- //如果发送的来源是 Selectpage,则转发到 Selectpage
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- [$where, $sort, $order, $offset, $limit] = $this->buildparams();
- $list = $this->model
- ->where($where)
- ->where('applytype',0)
- ->order($sort, $order)
- ->paginate($limit);
- foreach ($list as $row)
- {
- $row->categoryname = $row->category_ids?model('app\admin\model\service\Category')->getCategoryList($row->category_ids):'';
- $row->goodsname = $row->goods_ids?model('app\admin\model\service\Goods')->getGoodsList($row->goods_ids):'';
- $row->create_time = date("Y-m-d H:i",$row->createtime);
- $row->update_time = $row->updatetime ? date("Y-m-d H:i",$row->updatetime):'';
- }
- $result = ['total' => $list->total(), 'rows' => $list->items()];
- return json($result);
- }
- public function edit($ids = null)
- {
- $row = $this->model->get($ids);
- if (!$row) {
- $this->error(__('No Results were found'));
- }
- $adminIds = $this->getDataLimitAdminIds();
- if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
- $this->error(__('You have no permission'));
- }
- if (false === $this->request->isPost()) {
- $this->view->assign('row', $row);
- return $this->view->fetch();
- }
- $params = $this->request->post('row/a');
- if (empty($params)) {
- $this->error(__('Parameter %s can not be empty', ''));
- }
- ($row->state == 1 && $params['state'] != 1) && $this->error('请勿重复审核');
- $params = $this->preExcludeFields($params);
- if($params['state'] == 1)
- {
- $params['code'] = str_pad($row->user_id,8,Random::alnum(8-strlen($row->user_id)));
- }
- $result = false;
- Db::startTrans();
- try {
- //是否采用模型验证
- if ($this->modelValidate) {
- $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
- $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
- $row->validateFailException()->validate($validate);
- }
- $result = $row->allowField(true)->save($params);
- if($params['state'] == 1)
- {
- $this->model->where('id',$row->id)->update(['applytype'=>1]);
- model('app\admin\model\service\User')->where('user_id',$row->user_id)->update(['is_shop'=>1]);
- $data = db('service_apply_shop')->where('id',$row->id)->find();
- $count = model('app\admin\model\service\shop\Shop')->where('state',1)->count();
- $data['code'] = str_pad(date('d').$count,8,0);
- $data['accept_nums'] = \app\api\model\service\ProjectConfig::getProjectConfig('shop_accept_nums');
- $shop = new Shop($data);
- $shop->allowField(true)->save();
- }
- Db::commit();
- } catch (ValidateException|PDOException|Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if (false === $result) {
- $this->error(__('No rows were updated'));
- }
- $this->success();
- }
- public function agree($ids = null)
- {
- $row = $this->model->get($ids);
- if (false === $this->request->isPost()) {
- $this->view->assign('row', $row);
- return $this->view->fetch();
- }
- $params = $this->request->post('row/a');
- if (empty($params)) {
- $this->error(__('Parameter %s can not be empty', ''));
- }
- $params = $this->preExcludeFields($params);
- $row->applytype != 0 && $this->error('请勿重复审核');
- $params['state'] = 1;
- $result = false;
- Db::startTrans();
- try {
- //是否采用模型验证
- if ($this->modelValidate) {
- $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
- $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
- $row->validateFailException()->validate($validate);
- }
- $result = $row->allowField(true)->save($params);
- $this->model->where('id',$row->id)->update(['applytype'=>1]);
- model('app\admin\model\service\User')->where('user_id',$row->user_id)->update(['is_shop'=>1]);
- $data = db('service_apply_shop')->where('id',$row->id)->find();
- $data['percent'] = $params['percent'];
- $data['to_shop'] = $params['to_shop'];
- $data['settle_day'] = $params['settle_day'];
- $count = model('app\admin\model\service\shop\Shop')->where('state',1)->count();
- $data['day'] = 1;
- $data['accept_nums'] = \app\api\model\service\ProjectConfig::getProjectConfig('shop_accept_nums');
- $data['service_nums'] = \app\api\model\service\ProjectConfig::getProjectConfig('service_nums');
- $data['code'] = str_pad(date('d').$count,8,0);
- $data['updatetime'] = time();
- unset($data['id']);
- $shop = new Shop($data);
- $shop->allowField(true)->save();
- Db::commit();
- } catch (ValidateException|PDOException|Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if (false === $result) {
- $this->error(__('No rows were updated'));
- }
- $this->success('已审核');
- }
- public function refuse($ids = null)
- {
- $row = $this->model->get($ids);
- if (false === $this->request->isPost()) {
- $this->view->assign('row', $row);
- return $this->view->fetch();
- }
- $params = $this->request->post('row/a');
- if (empty($params)) {
- $this->error(__('Parameter %s can not be empty', ''));
- }
- $params = $this->preExcludeFields($params);
- $params['state'] = -1;
- $result = false;
- Db::startTrans();
- try {
- //是否采用模型验证
- if ($this->modelValidate) {
- $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
- $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
- $row->validateFailException()->validate($validate);
- }
- $result = $row->allowField(true)->save($params);
- Db::commit();
- } catch (ValidateException|PDOException|Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if (false === $result) {
- $this->error(__('No rows were updated'));
- }
- $this->success();
- }
- }
|