Applyskill.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. namespace app\admin\controller\service\skill;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. use app\admin\model\service\skill\Skill;
  6. /**
  7. * 技师管理
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class Applyskill extends Backend
  12. {
  13. /**
  14. * Applyskill模型对象
  15. * @var \app\admin\model\service\skill\Applyskill
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new \app\admin\model\service\skill\Applyskill;
  22. $this->view->assign("applytypeList", $this->model->getApplytypeList());
  23. $this->view->assign("sexList", $this->model->getSexList());
  24. $this->view->assign("eduList", $this->model->getEduList());
  25. $this->view->assign("experList", $this->model->getExperList());
  26. $this->view->assign("stateList", $this->model->getStateList());
  27. }
  28. /**
  29. * 查看
  30. * @return string|\think\response\Json
  31. * @throws \think\Exception
  32. * @throws \think\exception\DbException
  33. */
  34. public function index()
  35. {
  36. //设置过滤方法
  37. $this->request->filter(['strip_tags', 'trim']);
  38. if (false === $this->request->isAjax()) {
  39. return $this->view->fetch();
  40. }
  41. //如果发送的来源是 Selectpage,则转发到 Selectpage
  42. if ($this->request->request('keyField')) {
  43. return $this->selectpage();
  44. }
  45. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  46. $list = $this->model
  47. ->where($where)
  48. ->where('applytype',0)
  49. ->with('cate,category')
  50. ->order($sort, $order)
  51. ->paginate($limit);
  52. foreach ($list as &$row)
  53. {
  54. $row->goodsname = $row->goods_ids?model('app\admin\model\service\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. ($row->state == 1 && $params['state'] != 1) && $this->error('请勿重复审核');
  88. $params = $this->preExcludeFields($params);
  89. $result = false;
  90. Db::startTrans();
  91. try {
  92. //是否采用模型验证
  93. if ($this->modelValidate) {
  94. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  95. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  96. $row->validateFailException()->validate($validate);
  97. }
  98. $result = $row->allowField(true)->save($params);
  99. if($params['state'] == 1)
  100. {
  101. $this->createTime($row->id);
  102. $this->model->where('id',$row->id)->update(['applytype'=>1]);
  103. model('app\admin\model\service\User')->where('user_id',$row->user_id)->update(['is_skill'=>1]);
  104. $data = db('service_apply_skill')->where('id',$row->id)->find();
  105. $count = model('app\admin\model\service\skill\Skill')->where('state',1)->count();
  106. $data['code'] = str_pad(date('d').$count,8,0);
  107. $data['mobile'] = model('app\admin\model\service\User')->where(['user_id'=>$row->user_id])->value('mobile');
  108. $skill = new Skill($data);
  109. $skill->allowField(true)->save();
  110. }
  111. Db::commit();
  112. } catch (ValidateException|PDOException|Exception $e) {
  113. Db::rollback();
  114. $this->error($e->getMessage());
  115. }
  116. if (false === $result) {
  117. $this->error(__('No rows were updated'));
  118. }
  119. $this->success();
  120. }
  121. public function agree($ids = null)
  122. {
  123. $row = $this->model->get($ids);
  124. if (false === $this->request->isPost()) {
  125. $this->view->assign('row', $row);
  126. return $this->view->fetch();
  127. }
  128. $params = $this->request->post('row/a');
  129. if (empty($params)) {
  130. $this->error(__('Parameter %s can not be empty', ''));
  131. }
  132. $params = $this->preExcludeFields($params);
  133. $row->applytype != 0 && $this->error('请勿重复审核');
  134. $params['state'] = 1;
  135. $result = false;
  136. Db::startTrans();
  137. try {
  138. //是否采用模型验证
  139. if ($this->modelValidate) {
  140. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  141. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  142. $row->validateFailException()->validate($validate);
  143. }
  144. $result = $row->allowField(true)->save($params);
  145. $this->model->where('id',$row->id)->update(['applytype'=>1]);
  146. model('app\admin\model\service\User')->where('user_id',$row->user_id)->update(['is_skill'=>1]);
  147. $data = db('service_apply_skill')->where('id',$row->id)->find();
  148. $data['percent'] = $params['percent'];
  149. $data['accept_nums'] = \app\api\model\service\ProjectConfig::getProjectConfig('accept_nums');
  150. unset($data['id']);
  151. $count = model('app\admin\model\service\skill\Skill')->where('state',1)->count();
  152. $data['code'] = str_pad(date('d').$count,8,0);
  153. $data['mobile'] = model('app\admin\model\service\User')->where(['user_id'=>$row->user_id])->value('mobile');
  154. $data['updatetime'] = time();
  155. $skill = new Skill($data);
  156. $skill->allowField(true)->save();
  157. \app\admin\model\service\skill\Applyskill::createTime($skill->id);
  158. Db::commit();
  159. } catch (ValidateException|PDOException|Exception $e) {
  160. Db::rollback();
  161. $this->error($e->getMessage());
  162. }
  163. if (false === $result) {
  164. $this->error(__('No rows were updated'));
  165. }
  166. $this->success();
  167. }
  168. public function refuse($ids = null)
  169. {
  170. $row = $this->model->get($ids);
  171. if (false === $this->request->isPost()) {
  172. $this->view->assign('row', $row);
  173. return $this->view->fetch();
  174. }
  175. $params = $this->request->post('row/a');
  176. if (empty($params)) {
  177. $this->error(__('Parameter %s can not be empty', ''));
  178. }
  179. $params = $this->preExcludeFields($params);
  180. $params['state'] = -1;
  181. $result = false;
  182. Db::startTrans();
  183. try {
  184. //是否采用模型验证
  185. if ($this->modelValidate) {
  186. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  187. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  188. $row->validateFailException()->validate($validate);
  189. }
  190. $result = $row->allowField(true)->save($params);
  191. Db::commit();
  192. } catch (ValidateException|PDOException|Exception $e) {
  193. Db::rollback();
  194. $this->error($e->getMessage());
  195. }
  196. if (false === $result) {
  197. $this->error(__('No rows were updated'));
  198. }
  199. $this->success();
  200. }
  201. }