Applyshop.php 8.0 KB

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