You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.5 KiB
69 lines
1.5 KiB
<?php
|
|
declare (strict_types=1);
|
|
|
|
namespace app\api\model;
|
|
|
|
use think\facade\Db;
|
|
use think\Model;
|
|
|
|
/**
|
|
* @mixin think\Model
|
|
*/
|
|
class CateRelation extends CmsCommon
|
|
{
|
|
|
|
public $table = 'bmz_cate_relation';
|
|
|
|
|
|
/**
|
|
* 列表数据模型
|
|
* @return array|\think\Collection
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function index()
|
|
{
|
|
|
|
$_op = $this->field('*');
|
|
$data = parent::parentLists($_op);
|
|
|
|
$cates = Db::name('cate')
|
|
->where('site_id',SITE_ID)
|
|
->where('template_id',TEMPLATE_ID)
|
|
->select()->toArray();
|
|
$cates_all = array_column($cates,null,'id');
|
|
|
|
foreach ($data['data'] as &$item){
|
|
$cate_arr = explode(',',$item['cate_ids']);
|
|
$cate_str = [];
|
|
foreach ($cate_arr as $i){
|
|
if(isset($cates_all[$i])){
|
|
$cate_str[] = $cates_all[$i]['cate_name'];
|
|
}
|
|
}
|
|
$item['cate_strs'] = implode(',',$cate_str);
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
/**
|
|
* 新增或修改前
|
|
* @param Model $model
|
|
* @return mixed|void
|
|
*/
|
|
public static function onBeforeWrite(Model $model)
|
|
{
|
|
|
|
parent::onBeforeWrite($model);
|
|
}
|
|
|
|
|
|
public static function onAfterDelete(Model $model)
|
|
{
|
|
parent::onAfterDelete($model);
|
|
}
|
|
|
|
}
|
|
|