[ 'status'], '%like%'=>['title'], ]; } /** * @notes 地址信息列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author ljj * @date 2022/2/16 3:18 下午 */ public function lists(): array { $lists = (new AssetArea())->field('id,id value ,title , title label,level,pid,create_time') ->where($this->searchWhere) ->limit($this->limitOffset, $this->limitLength) ->Order('sort desc') ->select() ->toArray(); if($this->params['is_tree'] ==1){ $treeList = linear_to_tree($lists, 'children'); if (empty($treeList) && !empty($lists)) { foreach ($lists as &$v) { $v['children'] = []; } return $lists; } return $treeList; }else{ return $lists; } // } /** * @notes 地址信息数量 * @return int * @author ljj * @date 2022/2/16 3:18 下午 */ public function count(): int { return (new AssetArea())->where($this->searchWhere)->count(); } /** * @notes 添加地址 * @param array $params * @author heshihu * @date 2022/2/22 9:57 */ public static function add(array $params) { $pid = $params['pid']; $level = 1; $pidInfo = AssetArea::find($pid); if(!empty($pidInfo)){ $level = $pidInfo['level'] + 1; } AssetArea::create([ 'title' => $params['title'], 'level' => $level, 'pid' => $pid, 'sort' => $params['sort']??0 ]); } /** * @notes 编辑地址 * @param array $params * @return bool * @author heshihu * @date 2022/2/22 10:12 */ public static function edit(array $params) : bool { try { AssetArea::update([ 'id' => $params['id'], 'title' => $params['title'], 'sort' => $params['sort']??0 ]); return true; } catch (\Exception $e) { self::setError($e->getMessage()); return false; } } /** * @notes 删除地址 * @param array $params * @author heshihu * @date 2022/2/22 10:17 */ public static function delete(array $params) { AssetArea::destroy($params['id']); } /** * @notes 查看地址详情 * @param $params * @return array * @author heshihu * @date 2022/2/22 10:15 */ public static function detail($params) : array { return AssetArea::findOrEmpty($params['id'])->toArray(); } public static function updateStatus(array $params) { AssetArea::update([ 'id' => $params['id'], 'status' => $params['status'] ]); return true; } }