| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 | 
							- <?php
 
- namespace app\admin\controller;
 
- use think\exception\ValidateException;
 
- use app\model\PartnerLevel;
 
- class PartnerlevelController extends Base
 
- {
 
- 	function index()
 
- 	{
 
- 		$weid = weid();
 
- 		$keyword = input('post.keyword', '', 'serach_in');
 
- 		$query = PartnerLevel::where(['weid' => $weid]);
 
- 		if (!empty($keyword)) {
 
- 			$query->where('title', 'like', '%' . $keyword . '%');
 
- 		}
 
- 		$datalist = $query->order('sort asc,id asc')->select()->toArray();
 
- 		if (empty($datalist)) {
 
- 			PartnerLevel::datainitial();
 
- 			$datalist = $query->order('sort asc,id asc')->select()->toArray();
 
- 		}
 
- 		$data['data'] = $datalist;
 
- 		return $this->json($data);
 
- 	}
 
- 	function listUpdate()
 
- 	{
 
- 		$data = only('id,is_default,status,sort');
 
- 		if (!$data['id']) throw new ValidateException('参数错误');
 
- 		PartnerLevel::update($data);
 
- 		return $this->json(['msg' => '操作成功']);
 
- 	}
 
- 	public function update()
 
- 	{
 
- 		$id = $this->request->post('id');
 
- 		$data = input('post.');
 
- 		unset($data['create_time']);
 
- 		if (empty($id)) {
 
- 			$data['weid'] = weid();
 
- 			try {
 
- 				$res = PartnerLevel::create($data);
 
- 				if ($res->id && empty($data['sort'])) {
 
- 					PartnerLevel::update(['sort' => $res->id, 'id' => $res->id]);
 
- 				}
 
- 			} catch (\Exception $e) {
 
- 				throw new ValidateException($e->getMessage());
 
- 			}
 
- 			return $this->json(['msg' => '添加成功', 'data' => $res->id]);
 
- 		} else {
 
- 			try {
 
- 				PartnerLevel::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 = PartnerLevel::field('*')->find($id)->toArray();
 
- 		return $this->json(['data' => $data]);
 
- 	}
 
- 	function delete()
 
- 	{
 
- 		return $this->del(new PartnerLevel());
 
- 	}
 
- }
 
 
  |