feat: 开放API产品相关
This commit is contained in:
19
app/openapi/model/LanguageModel.php
Normal file
19
app/openapi/model/LanguageModel.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\openapi\model;
|
||||
|
||||
use app\common\model\LanguageBaseModel;
|
||||
|
||||
/**
|
||||
* 语言模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class LanguageModel extends LanguageBaseModel
|
||||
{
|
||||
// 所属code范围查询
|
||||
public function scopeCode($query, $code)
|
||||
{
|
||||
$query->where('code', '=', $code);
|
||||
}
|
||||
}
|
||||
33
app/openapi/model/ProductCategoryModel.php
Normal file
33
app/openapi/model/ProductCategoryModel.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\openapi\model;
|
||||
|
||||
use app\common\model\ProductCategoryBaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 产品分类模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class ProductCategoryModel extends ProductCategoryBaseModel
|
||||
{
|
||||
// 所属语言
|
||||
public function scopeLanguage($query, $language)
|
||||
{
|
||||
$query->whereExists(function($subquery) use($language) {
|
||||
$lang_model = new LanguageModel;
|
||||
$subquery->model($lang_model)
|
||||
->name($lang_model->getName())
|
||||
->where('id', '=', Db::Raw($this->getTable() . '.language_id'))
|
||||
->where('code', '=', $language);
|
||||
});
|
||||
}
|
||||
|
||||
// 所属上级范围查询
|
||||
public function scopeParent($query, $parent_id)
|
||||
{
|
||||
if (is_null($parent_id)) return;
|
||||
$query->where('pid', '=', $parent_id);
|
||||
}
|
||||
}
|
||||
62
app/openapi/model/ProductModel.php
Normal file
62
app/openapi/model/ProductModel.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\openapi\model;
|
||||
|
||||
use app\common\model\ProductBaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 产品模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class ProductModel extends ProductBaseModel
|
||||
{
|
||||
// 关联分类
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo(ProductCategoryModel::class, 'category_id', 'id');
|
||||
}
|
||||
|
||||
// 关联产品参数
|
||||
public function params()
|
||||
{
|
||||
return $this->hasMany(ProductParamsModel::class, 'product_id', 'id');
|
||||
}
|
||||
|
||||
// 关联sku
|
||||
public function skus()
|
||||
{
|
||||
return $this->hasMany(ProductSkuModel::class, 'product_id', 'id');
|
||||
}
|
||||
|
||||
// 关联购买链接
|
||||
public function links()
|
||||
{
|
||||
return $this->hasMany(ProductPurchaseLinkModel::class, 'product_id', 'id');
|
||||
}
|
||||
|
||||
// 关联相关产品
|
||||
public function related()
|
||||
{
|
||||
return $this->hasMany(ProductRelatedModel::class, 'product_id', 'id');
|
||||
}
|
||||
|
||||
// 根据所属语言范围查询
|
||||
public function scopeLanguage($query, $language)
|
||||
{
|
||||
$query->whereExists(function($subquery) use($language) {
|
||||
$lang_model = new LanguageModel;
|
||||
$subquery->model($lang_model)
|
||||
->name($lang_model->getName())
|
||||
->where('id', '=', Db::Raw($this->getTable() . '.language_id'))
|
||||
->where('code', '=', $language);
|
||||
});
|
||||
}
|
||||
|
||||
// 根据category_id范围查询
|
||||
public function scopeCategoryId($query, $category_id)
|
||||
{
|
||||
$query->where('category_id', '=', $category_id);
|
||||
}
|
||||
}
|
||||
15
app/openapi/model/ProductParamsModel.php
Normal file
15
app/openapi/model/ProductParamsModel.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\openapi\model;
|
||||
|
||||
use app\common\model\ProductParamsBaseModel;
|
||||
|
||||
/**
|
||||
* 产品参数模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class ProductParamsModel extends ProductParamsBaseModel
|
||||
{
|
||||
//
|
||||
}
|
||||
19
app/openapi/model/ProductPurchaseLinkModel.php
Normal file
19
app/openapi/model/ProductPurchaseLinkModel.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\openapi\model;
|
||||
|
||||
use app\common\model\ProductPurchaseLinkBaseModel;
|
||||
|
||||
/**
|
||||
* 产品购买链接模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class ProductPurchaseLinkModel extends ProductPurchaseLinkBaseModel
|
||||
{
|
||||
// 关联购买平台
|
||||
public function platform()
|
||||
{
|
||||
return $this->belongsTo(ProductPurchasePlatformModel::class, 'platform_id', 'id')->bind(['platform']);
|
||||
}
|
||||
}
|
||||
15
app/openapi/model/ProductPurchasePlatformModel.php
Normal file
15
app/openapi/model/ProductPurchasePlatformModel.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\openapi\model;
|
||||
|
||||
use app\common\model\ProductPurchasePlatformBaseModel;
|
||||
|
||||
/**
|
||||
* 产品购买链接平台模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class ProductPurchasePlatformModel extends ProductPurchasePlatformBaseModel
|
||||
{
|
||||
//
|
||||
}
|
||||
19
app/openapi/model/ProductRelatedModel.php
Normal file
19
app/openapi/model/ProductRelatedModel.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\openapi\model;
|
||||
|
||||
use app\common\model\ProductRelatedBaseModel;
|
||||
|
||||
/**
|
||||
* 产品 - 相关产品模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class ProductRelatedModel extends ProductRelatedBaseModel
|
||||
{
|
||||
// 关联产品
|
||||
public function product()
|
||||
{
|
||||
return $this->belongsTo(ProductModel::class, 'related_product_id', 'id');
|
||||
}
|
||||
}
|
||||
19
app/openapi/model/ProductSkuAttrModel.php
Normal file
19
app/openapi/model/ProductSkuAttrModel.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\openapi\model;
|
||||
|
||||
use app\common\model\ProductSkuAttrBaseModel;
|
||||
|
||||
/**
|
||||
* 产品sku属性模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class ProductSkuAttrModel extends ProductSkuAttrBaseModel
|
||||
{
|
||||
// 关联属性
|
||||
public function attr()
|
||||
{
|
||||
return $this->belongsTo(\app\common\model\ProductAttrBaseModel::class, 'attr_id', 'id')->bind(['attr_name']);
|
||||
}
|
||||
}
|
||||
19
app/openapi/model/ProductSkuModel.php
Normal file
19
app/openapi/model/ProductSkuModel.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\openapi\model;
|
||||
|
||||
use app\common\model\ProductSkuBaseModel;
|
||||
|
||||
/**
|
||||
* 产品sku模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class ProductSkuModel extends ProductSkuBaseModel
|
||||
{
|
||||
// 关联属性
|
||||
public function skuAttr()
|
||||
{
|
||||
return $this->hasMany(ProductSkuAttrModel::class, 'sku_id', 'id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user