RegisterfieldController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace app\admin\controller;
  3. use think\exception\ValidateException;
  4. use app\model\RegisterField;
  5. class RegisterfieldController extends Base
  6. {
  7. function getPtype()
  8. {
  9. $path = input('post.path', '', 'serach_in');
  10. if(!empty($path)){
  11. $tmppath = explode('/', $path);
  12. return $tmppath[2];
  13. }
  14. }
  15. function index()
  16. {
  17. $path = input('post.path', '', 'serach_in');
  18. $keyword = input('post.keyword', '', 'serach_in');
  19. $query = RegisterField::where(['weid' => weid()]);
  20. $ptype = $this->getPtype();
  21. if ($ptype == 'users') {
  22. $ptype = 'member';
  23. }
  24. RegisterField::datainitial($ptype);
  25. $query->where('ptype', $ptype);
  26. if (!empty($keyword)) {
  27. $query->where('viewmingcheng', 'like', '%' . $keyword . '%');
  28. }
  29. $Fielddata = $query->order('sort asc,id asc')->select()->toArray();
  30. $data['data'] = $Fielddata;
  31. return $this->json($data);
  32. }
  33. function listUpdate()
  34. {
  35. $data = only('id,status,is_listView,is_input,is_front,is_frontinput,is_import,is_search,sort');
  36. if (!$data['id']) throw new ValidateException('参数错误');
  37. RegisterField::update($data);
  38. return $this->json(['msg' => '操作成功']);
  39. }
  40. public function update()
  41. {
  42. $data = input('post.');
  43. if(empty($data['inputtype'])){
  44. throw new ValidateException('请选择输入方式');
  45. }
  46. if(!empty($data['selectvalue'])){
  47. $data['selectvalue'] = implode(',', $data['selectvalue']);
  48. }else{
  49. $data['selectvalue'] = '';
  50. }
  51. if(!empty($data['valuerules'])){
  52. $data['valuerules'] = implode('|', $data['valuerules']);
  53. }else{
  54. $data['valuerules'] = '';
  55. }
  56. unset($data['create_time']);
  57. $id = $this->request->post('id');
  58. if (empty($id)) {
  59. $data['weid'] = weid();
  60. $path = input('post.path', '', 'serach_in');
  61. $data['ptype'] = $this->getPtype();
  62. if ($data['ptype'] == 'users') {
  63. $data['ptype'] = 'member';
  64. }
  65. try {
  66. $res = RegisterField::create($data);
  67. if ($res->id && empty($data['sort'])) {
  68. RegisterField::update(['sort' => $res->id, 'id' => $res->id]);
  69. }
  70. } catch (\Exception $e) {
  71. throw new ValidateException($e->getMessage());
  72. }
  73. return $this->json(['msg' => '添加成功', 'data' => $res->id]);
  74. } else {
  75. try {
  76. RegisterField::update($data);
  77. } catch (\Exception $e) {
  78. throw new ValidateException($e->getMessage());
  79. }
  80. return $this->json(['msg' => '修改成功']);
  81. }
  82. }
  83. function getInfo()
  84. {
  85. $id = $this->request->post('id', '', 'serach_in');
  86. if (!$id) throw new ValidateException('参数错误');
  87. $data = RegisterField::field('*')->find($id)->toArray();
  88. if(!empty($data['selectvalue'])) {
  89. $data['selectvalue'] = explode(',', $data['selectvalue']);
  90. }
  91. if(!empty($data['valuerules'])) {
  92. $data['valuerules'] = explode('|', $data['valuerules']);
  93. }else{
  94. $data['valuerules'] = [];
  95. }
  96. return $this->json(['data' => $data]);
  97. }
  98. function delete()
  99. {
  100. return $this->del(new RegisterField());
  101. }
  102. }