0])->count(); $lists = UserRight::where(['del'=>0])->order('sort', 'desc')->page($get['page'], $get['limit'])->select()->toArray(); foreach ($lists as &$item){ $item['image'] = UrlServer::getFileUrl($item['image']); } return ['count' => $count, 'lists' => $lists]; } public static function add($post) { try{ $userLevel = UserRight::where(['title'=>trim($post['title']), 'del'=>0])->findOrEmpty(); if(!$userLevel->isEmpty()) { throw new \think\Exception('权益名称已被使用,请更换后重试'); } $time = time(); $data = [ 'title' => trim($post['title']), 'show_title' => trim($post['show_title']), 'image' => clearDomain($post['image']), 'explain' => trim($post['explain']), // 'number' => trim($post['number']), 'sort' => $post['sort'], 'create_time' => $time, 'update_time' => $time, 'del' => 0 ]; UserRight::create($data); return true; }catch(\Exception $e) { self::$error = $e->getMessage(); return false; } } public static function detail($id) { $detail = UserRight::where(['id'=>$id])->findOrEmpty(); if($detail->isEmpty()) { return []; } $detail = $detail->toArray(); $detail['image'] = UrlServer::getFileUrl($detail['image']); return $detail; } public static function edit($post) { try{ $userLevel = UserRight::where([ ['title', '=', trim($post['title'])], ['del', '=', 0], ['id', '<>', $post['id']] ])->findOrEmpty(); if(!$userLevel->isEmpty()) { throw new \think\Exception('权益名称已被使用,请更换后重试'); } $time = time(); $data = [ 'id' => $post['id'], 'title' => trim($post['title']), 'show_title' => trim($post['show_title']), 'image' => clearDomain($post['image']), 'explain' => trim($post['explain']), // 'number' => trim($post['number']), 'sort' => $post['sort'], 'create_time' => $time, 'update_time' => $time, 'del' => 0 ]; UserRight::update($data); return true; }catch(\Exception $e) { self::$error = $e->getMessage(); return false; } } public static function del($id) { try{ $data = [ 'id' => $id, 'del' => 1, 'update_time' => time() ]; UserRight::update($data); return true; }catch(\Exception $e) { self::$error = $e->getMessage(); return false; } } }