Perfect.php 6.5 KB

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