問題描述:
平臺后臺->設(shè)置->配送設(shè)置->城市數(shù)據(jù)
添加城市數(shù)據(jù),如下圖,前端頁面只展示一級地址,不展示二三級
解決方法:
路徑:app/common/repositories/store/CityAreaRepository.php
重寫 create和delete方法,在創(chuàng)建和刪除的同時修改一下父級的snum字段 注釋:snum 子級的數(shù)量
新增代碼:
/**
* 創(chuàng)建
* @param $data
* @return \app\common\dao\BaseDao|\think\Model
*/
public function create($data)
{
if($data['parent_id'] > 0){
// 修改父級snum
$this->dao->incField($data['parent_id'],'snum');
}
return $this->dao->create($data);
}
/**
* 刪除
* @param $id
* @return int
*/
public function delete($id)
{
$res = $this->dao->get($id);
if (empty($res)) {
throw new ValidateException('數(shù)據(jù)不存在');
}
if ($res['parent_id'] > 0) {
// 修改父級snum
$this->dao->decField($res['parent_id'], 'snum');
}
return $this->dao->delete($id);
}