nk-lihaink-cn/app/admin/model/store/paramter/ParameterTemplate.php
2023-03-16 12:18:52 +08:00

129 lines
3.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* @date 2023年03月9日
* @author刘孝全
* @emailq8197264@126.com
*
* @ 商品参数列表与模板添加
*/
namespace app\admin\model\store\paramter;
use think\Model;
use app\common\model\merchant\system\merchant\Merchant;
use app\common\model\merchant\system\Relevance;
// use app\admin\model\store\paramter\Parameter as ParameterModel;
class ParameterTemplate extends Model
{
protected $connection = 'shop';
public static function tablePk(): string
{
return 'template_id';
}
public static function tableName(): string
{
return 'eb_parameter_template';
}
public function merchant()
{
return $this->hasOne(Merchant::class,'mer_id','mer_id');
}
public function parameter()
{
return $this->hasMany(Parameter::class,'template_id','template_id');
}
public function cateId()
{
return $this->hasMany(Relevance::class,'left_id','template_id')->where('type', 'product_params_cate');
}
public function searchCateIdAttr($query, $value)
{
$id = Relevance::where('right_id',$value)->where('type', 'product_params_cate')->column('left_id');
$query->where('template_id','in',$id);
}
public function searchTemplateNameAttr($query, $value)
{
$query->whereLike('template_name',"%{$value}%");
}
public function searchTemplateIdsAttr($query, $value)
{
$query->whereIn('template_id',$value);
}
public function searchMerIdAttr($query, $value)
{
$query->where('mer_id',$value);
}
public function searchMerNameAttr($query, $value)
{
$value = Merchant::whereLike('mer_name',"%{$value}%")->coupon('mer_id');
$query->whereIn('mer_id',$value);
}
public function searchIsMerAttr($query, $value)
{
if ($value == 1) {
$query->where('mer_id','>',0);
} else {
$query->where('mer_id',0);
}
}
public function getList($where, $page, $limit)
{
$paramterModel = new Parameter();
$query = self::getSearch($where)->field('template_id,mer_id,template_name,sort,create_time')
->with([
'cateId' => function($query){
$query->with(['category' =>function($query) {
$query->field('store_category_id,cate_name');
}]);
},
'merchant' => function($query) {
$query->field('mer_id,mer_name');
}
// 'parameter' =>function($query){
// $query->field('parameter_id,template_id,name,value,sort')->order('sort DESC');
// }
])
->order('sort DESC,create_time DESC');
$count = $query->count();
$list = $query->page($page, $limit)->select();
return compact('count', 'list');
}
/**
* TODO 搜索
* @param $where
*/
public static function getSearch(array $where)
{
foreach ($where as $key => $item) {
if ($item !== '') {
$keyArray[] = $key;
$whereArr[$key] = $item;
}
}
if(empty($keyArray)){
return new self;
}else{
return self::withSearch($keyArray, $whereArr);
}
}
}