初始化代码
This commit is contained in:
135
app/shop/model/ShopGoodsSpe.php
Normal file
135
app/shop/model/ShopGoodsSpe.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class ShopGoodsSpe extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_v2_shop_spe';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-06-12 15:28
|
||||
*/
|
||||
public function getImageAttr($value,$data){
|
||||
|
||||
if(!empty($value)){
|
||||
|
||||
return $value;
|
||||
}else{
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @param $dis
|
||||
* @param int $page
|
||||
* @return mixed
|
||||
* 获取多规格
|
||||
*/
|
||||
public function goodsSpe($dis){
|
||||
$data = $this->where($dis)->select()->toArray();
|
||||
return $this->getTree($data,0);
|
||||
}
|
||||
/**
|
||||
* @param $data
|
||||
* @param $pId
|
||||
* @return array
|
||||
* 递归无限极
|
||||
*/
|
||||
public function getTree($data, $pId){
|
||||
$tree = array();
|
||||
if(!empty($data)){
|
||||
foreach($data as $k => $v) {
|
||||
if($v['pid'] == $pId) {
|
||||
$v['cate'] = $this->getTree($data, $v['id']);
|
||||
$tree[] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return int|string
|
||||
* 添加商品规格
|
||||
*/
|
||||
|
||||
public function goodsSpeAdd($data){
|
||||
$data['create_time'] = time();
|
||||
$data['status'] = 1;
|
||||
$res = $this->insert($data);
|
||||
$res = $this->getLastInsID();
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return int|string
|
||||
* 添加商品规格
|
||||
*/
|
||||
|
||||
public function goodsSpeUpdate($dis,$data){
|
||||
$data['update_time'] = time();
|
||||
$res = $this->where($dis)->update($data);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $dis
|
||||
* 根据条件获取id
|
||||
*/
|
||||
|
||||
public function goodsSpeId($dis){
|
||||
$data = $this->where($dis)->column('id');
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $dis
|
||||
* @return array|\think\Model|null
|
||||
* @throws \think\exception\DbException
|
||||
* 获取一个
|
||||
*/
|
||||
public function getSinge($dis){
|
||||
$data = $this->where($dis)->find();
|
||||
return !empty($data)?$data->toArray():$data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $dis
|
||||
* @param int $page
|
||||
* @return mixed
|
||||
* 获取多规格
|
||||
*/
|
||||
public function goodsSpeNot($dis,$data){
|
||||
$data = $this->where($dis)->where('pid','not in',$data)->select()->toArray();
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $dis
|
||||
* 获取多规格的pid
|
||||
*/
|
||||
public function goodSpePid($dis){
|
||||
$data = $this->where($dis)->value('pid');
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user