| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
- namespace app\admin\controller;
- use think\exception\ValidateException;
- use app\model\RegisterField;
- class RegisterfieldController extends Base
- {
- function getPtype()
- {
- $path = input('post.path', '', 'serach_in');
- if(!empty($path)){
- $tmppath = explode('/', $path);
- return $tmppath[2];
- }
- }
- function index()
- {
- $path = input('post.path', '', 'serach_in');
- $keyword = input('post.keyword', '', 'serach_in');
- $query = RegisterField::where(['weid' => weid()]);
- $ptype = $this->getPtype();
- if ($ptype == 'users') {
- $ptype = 'member';
- }
- RegisterField::datainitial($ptype);
- $query->where('ptype', $ptype);
- if (!empty($keyword)) {
- $query->where('viewmingcheng', 'like', '%' . $keyword . '%');
- }
- $Fielddata = $query->order('sort asc,id asc')->select()->toArray();
- $data['data'] = $Fielddata;
- return $this->json($data);
- }
- function listUpdate()
- {
- $data = only('id,status,is_listView,is_input,is_front,is_frontinput,is_import,is_search,sort');
- if (!$data['id']) throw new ValidateException('参数错误');
- RegisterField::update($data);
- return $this->json(['msg' => '操作成功']);
- }
- public function update()
- {
- $data = input('post.');
-
- if(empty($data['inputtype'])){
- throw new ValidateException('请选择输入方式');
- }
- if(!empty($data['selectvalue'])){
- $data['selectvalue'] = implode(',', $data['selectvalue']);
- }else{
- $data['selectvalue'] = '';
- }
- if(!empty($data['valuerules'])){
- $data['valuerules'] = implode('|', $data['valuerules']);
- }else{
- $data['valuerules'] = '';
- }
- unset($data['create_time']);
- $id = $this->request->post('id');
- if (empty($id)) {
- $data['weid'] = weid();
- $path = input('post.path', '', 'serach_in');
- $data['ptype'] = $this->getPtype();
- if ($data['ptype'] == 'users') {
- $data['ptype'] = 'member';
- }
- try {
- $res = RegisterField::create($data);
- if ($res->id && empty($data['sort'])) {
- RegisterField::update(['sort' => $res->id, 'id' => $res->id]);
- }
- } catch (\Exception $e) {
- throw new ValidateException($e->getMessage());
- }
- return $this->json(['msg' => '添加成功', 'data' => $res->id]);
- } else {
- try {
- RegisterField::update($data);
- } catch (\Exception $e) {
- throw new ValidateException($e->getMessage());
- }
- return $this->json(['msg' => '修改成功']);
- }
- }
- function getInfo()
- {
- $id = $this->request->post('id', '', 'serach_in');
- if (!$id) throw new ValidateException('参数错误');
- $data = RegisterField::field('*')->find($id)->toArray();
- if(!empty($data['selectvalue'])) {
- $data['selectvalue'] = explode(',', $data['selectvalue']);
- }
- if(!empty($data['valuerules'])) {
- $data['valuerules'] = explode('|', $data['valuerules']);
- }else{
- $data['valuerules'] = [];
- }
- return $this->json(['data' => $data]);
- }
- function delete()
- {
- return $this->del(new RegisterField());
- }
- }
|