Perfect.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. namespace app\admin\controller\service\shop;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. use app\admin\model\service\shop\Shop;
  6. /**
  7. * 申请商户管理
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class Perfect extends Backend
  12. {
  13. /**
  14. * Perfect模型对象
  15. * @var \app\admin\model\service\shop\Perfect
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new \app\admin\model\service\shop\Perfect;
  22. $this->view->assign("applytypeList", $this->model->getApplytypeList());
  23. $this->view->assign("typeList", $this->model->getTypeList());
  24. $this->view->assign("stateList", $this->model->getStateList());
  25. }
  26. public function index()
  27. {
  28. //设置过滤方法
  29. $this->request->filter(['strip_tags', 'trim']);
  30. if (false === $this->request->isAjax()) {
  31. return $this->view->fetch();
  32. }
  33. //如果发送的来源是 Selectpage,则转发到 Selectpage
  34. if ($this->request->request('keyField')) {
  35. return $this->selectpage();
  36. }
  37. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  38. $list = $this->model
  39. ->where($where)
  40. ->where('applytype',1)
  41. ->order($sort, $order)
  42. ->paginate($limit);
  43. foreach ($list as $row)
  44. {
  45. $row->categoryname = $row->category_ids?model('app\admin\model\service\Category')->getCategoryList($row->category_ids):'';
  46. $row->goodsname = $row->goods_ids?model('app\admin\model\service\Goods')->getGoodsList($row->goods_ids):'';
  47. $row->create_time = date("Y-m-d H:i",$row->createtime);
  48. $row->update_time = $row->updatetime ? date("Y-m-d H:i",$row->updatetime):'';
  49. }
  50. $result = ['total' => $list->total(), 'rows' => $list->items()];
  51. return json($result);
  52. }
  53. public function edit($ids = null)
  54. {
  55. $row = $this->model->get($ids);
  56. if (!$row) {
  57. $this->error(__('No Results were found'));
  58. }
  59. $adminIds = $this->getDataLimitAdminIds();
  60. if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
  61. $this->error(__('You have no permission'));
  62. }
  63. if (false === $this->request->isPost()) {
  64. $this->view->assign('row', $row);
  65. return $this->view->fetch();
  66. }
  67. $params = $this->request->post('row/a');
  68. if (empty($params)) {
  69. $this->error(__('Parameter %s can not be empty', ''));
  70. }
  71. $params = $this->preExcludeFields($params);
  72. $result = false;
  73. Db::startTrans();
  74. try {
  75. //是否采用模型验证
  76. if ($this->modelValidate) {
  77. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  78. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  79. $row->validateFailException()->validate($validate);
  80. }
  81. $result = $row->allowField(true)->save($params);
  82. if($params['state'] == 1)
  83. {
  84. $data = db('service_apply_shop')->where('id',$row->id)->find();
  85. $shop = new Shop();
  86. $shop->allowField(true)->save($data,['user_id'=>$row->user_id]);
  87. }
  88. Db::commit();
  89. } catch (ValidateException|PDOException|Exception $e) {
  90. Db::rollback();
  91. $this->error($e->getMessage());
  92. }
  93. if (false === $result) {
  94. $this->error(__('No rows were updated'));
  95. }
  96. $this->success();
  97. }
  98. public function agree($ids = null)
  99. {
  100. $row = $this->model->get($ids);
  101. $params['state'] = 1;
  102. $result = false;
  103. Db::startTrans();
  104. try {
  105. //是否采用模型验证
  106. if ($this->modelValidate) {
  107. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  108. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  109. $row->validateFailException()->validate($validate);
  110. }
  111. $result = $row->allowField(true)->save($params);
  112. $data = db('service_apply_shop')->where('id',$row->id)->find();
  113. unset($data['id']);
  114. $data['goods_ids'] = \app\api\model\service\Shop::updateShopGoodsIds($row->user_id,$row->goods_ids);
  115. $shop = new Shop();
  116. $shop->allowField(true)->save($data,['user_id'=>$row->user_id]);
  117. Db::commit();
  118. } catch (ValidateException|PDOException|Exception $e) {
  119. Db::rollback();
  120. $this->error($e->getMessage());
  121. }
  122. if (false === $result) {
  123. $this->error(__('No rows were updated'));
  124. }
  125. $this->success();
  126. }
  127. public function refuse($ids = null)
  128. {
  129. $row = $this->model->get($ids);
  130. if (false === $this->request->isPost()) {
  131. $this->view->assign('row', $row);
  132. return $this->view->fetch();
  133. }
  134. $params = $this->request->post('row/a');
  135. if (empty($params)) {
  136. $this->error(__('Parameter %s can not be empty', ''));
  137. }
  138. $params = $this->preExcludeFields($params);
  139. $params['state'] = -1;
  140. $result = false;
  141. Db::startTrans();
  142. try {
  143. //是否采用模型验证
  144. if ($this->modelValidate) {
  145. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  146. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  147. $row->validateFailException()->validate($validate);
  148. }
  149. $result = $row->allowField(true)->save($params);
  150. Db::commit();
  151. } catch (ValidateException|PDOException|Exception $e) {
  152. Db::rollback();
  153. $this->error($e->getMessage());
  154. }
  155. if (false === $result) {
  156. $this->error(__('No rows were updated'));
  157. }
  158. $this->success();
  159. }
  160. }