TechnicalcertificateController.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace app\admin\controller;
  3. use think\exception\ValidateException;
  4. use app\model\TechnicalCertificate;
  5. class TechnicalcertificateController extends Base
  6. {
  7. function index()
  8. {
  9. $weid = weid();
  10. $keyword = input('post.keyword', '', 'serach_in');
  11. $query = TechnicalCertificate::where(['weid' => $weid]);
  12. if (!empty($keyword)) {
  13. $query->where('title', 'like', '%' . $keyword . '%');
  14. }
  15. $datalist = $query->order('sort asc,id asc')->select()->toArray();
  16. $data['data'] = $datalist;
  17. return $this->json($data);
  18. }
  19. function listUpdate()
  20. {
  21. $data = only('id,status,sort');
  22. if (!$data['id']) throw new ValidateException('参数错误');
  23. TechnicalCertificate::update($data);
  24. return $this->json(['msg' => '操作成功']);
  25. }
  26. public function update()
  27. {
  28. $id = $this->request->post('id');
  29. $data = input('post.');
  30. if (empty($id)) {
  31. $data['weid'] = weid();
  32. try {
  33. $res = TechnicalCertificate::create($data);
  34. if ($res->id && empty($data['sort'])) {
  35. TechnicalCertificate::update(['sort' => $res->id, 'id' => $res->id]);
  36. }
  37. } catch (\Exception $e) {
  38. throw new ValidateException($e->getMessage());
  39. }
  40. return $this->json(['msg' => '添加成功', 'data' => $res->id]);
  41. } else {
  42. try {
  43. TechnicalCertificate::update($data);
  44. } catch (\Exception $e) {
  45. throw new ValidateException($e->getMessage());
  46. }
  47. return $this->json(['msg' => '修改成功']);
  48. }
  49. }
  50. function getInfo()
  51. {
  52. $id = $this->request->post('id', '', 'serach_in');
  53. if (!$id) throw new ValidateException('参数错误');
  54. $data = TechnicalCertificate::field('*')->find($id)->toArray();
  55. return $this->json(['data' => $data]);
  56. }
  57. function delete()
  58. {
  59. return $this->del(new TechnicalCertificate());
  60. }
  61. }