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.
77 lines
2.0 KiB
77 lines
2.0 KiB
<?php
|
|
|
|
namespace app\integral\model;
|
|
|
|
use think\model\concern\SoftDelete;
|
|
|
|
class IntegralProduct extends Base
|
|
{
|
|
use SoftDelete;
|
|
|
|
/**
|
|
* 类型转换
|
|
*/
|
|
protected $type = [
|
|
'img_path' => 'serialize'
|
|
];
|
|
|
|
/**
|
|
* 获取商品列表
|
|
* @param array $where 当前模型查询条件
|
|
* @param array $where_product_category 根据关联条件查询当前模型
|
|
* @param int $page 第X页
|
|
* @param string $field 指定字段查询
|
|
* @param string $order 排序
|
|
* @date 2022-11-09
|
|
*/
|
|
public function listProductWithPage($where, $where_product_category, $page = 1, $field = '*', $order = '')
|
|
{
|
|
// 未定义排序时 按创建时间倒序排序
|
|
if (empty($order)) {
|
|
$order = 'id desc';
|
|
}
|
|
|
|
// 获取产品列表
|
|
$data_list = $this
|
|
->hasWhere('integralProductCategory', $where_product_category, $field)
|
|
->where($where)->order($order)
|
|
->paginate(['list_rows' => 10, 'page' => $page], false);
|
|
|
|
return $data_list;
|
|
}
|
|
|
|
/**
|
|
* 获取商品详情
|
|
* @date 2022-11-09
|
|
*/
|
|
public function getProduct($where = [], $field = '*')
|
|
{
|
|
// 按创建时间倒序排序
|
|
$order = 'id desc';
|
|
|
|
$data = $this->with(['integralProductSku'])->field($field)->where($where)->order($order)->find();
|
|
return $data;
|
|
}
|
|
|
|
|
|
/**
|
|
* 一对多关联 商品分类
|
|
* @date 2021-08-25
|
|
*/
|
|
public function integralProductCategory()
|
|
{
|
|
return $this->hasMany('IntegralProductCategory', 'product_id', 'id');
|
|
// return $this->belongsToMany('IntegralCategory', 'IntegralProductCategory', 'category_id', 'product_id');
|
|
}
|
|
|
|
/**
|
|
* API-一对多关联SKU
|
|
* @date 2022-11-09
|
|
*/
|
|
public function integralProductSku()
|
|
{
|
|
return $this->hasMany('IntegralProductSku', 'product_id', 'id')->field('product_id,sku,price,integral,stock,cover_img');
|
|
}
|
|
|
|
|
|
} |