admin/app/model/newModel/common/Area.php

68 lines
2.1 KiB
PHP

<?php
/** ZJMall商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2022-2032 四川正今科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.zjphp.com
* 这不是自由软件!未经允许不得用于商业目或程序代码摘取及修改。
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布传播。
* 唯一发布渠道官方颁发授权证书,无纸质授权凭证书视为侵权行为。
* =========================================================
*/
namespace app\model\newModel\common;
use app\model\NewBaseModel;
class Area extends NewBaseModel{
protected $pk = 'id'; // 默认主键id
protected $name = 'area';
protected $autoWriteTimestamp = false; // 开启自动时间戳
protected $deleteTime = false; // 软删除字段
/**
* Common: 获取地区列表
* Author: wu-hui
* Time: 2022/10/22 18:01
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(){
// 参数获取
$pid = (int)input('pid',0);
$isGetChildren = (boolean)input('is_get_children',false);
// 列表信息获取
$list = $this
->field('id,pid,name')
->when($isGetChildren,function($query){
$query->with(['children'=>function($children){
$children->field('id,pid,name');
}]);
})
->where('pid',$pid)
->where('status',1)
->select();
if($list) $list = $list->toArray();
return $this->success($list);
}
/**
* Common: 关联查询 当前类
* Author: wu-hui
* Time: 2022/10/24 9:04
* @return \think\model\relation\HasMany
*/
public function children(){
return $this->hasMany(self::class,'pid','id');
}
}