- 按 docs/renew-code-comment.md 将 PHP 文件头改为带边框的 Author 注释\n- 注释中的 crmeb.com 替换为 uj345.cn(代码字符串中的外链未改)\n- 新增 docs/renew-code-comment.md 说明 Made-with: Cursor
210 lines
4.8 KiB
PHP
210 lines
4.8 KiB
PHP
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Author: ScottPan Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\model\activity\promotions;
|
|
|
|
|
|
use app\model\activity\coupon\StoreCouponIssue;
|
|
use app\model\product\brand\StoreBrand;use app\model\product\label\StoreProductLabel;use app\model\product\product\StoreProduct;
|
|
use app\model\product\sku\StoreProductAttrValue;
|
|
use crmeb\basic\BaseModel;
|
|
use crmeb\traits\ModelTrait;use think\Model;
|
|
|
|
/**
|
|
* 优惠活动辅助表
|
|
*/
|
|
class StorePromotionsAuxiliary extends BaseModel
|
|
{
|
|
use ModelTrait;
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $key = 'id';
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $name = 'store_promotions_auxiliary';
|
|
|
|
/**
|
|
* 商品规格
|
|
* @param $value
|
|
* @return array|mixed
|
|
*/
|
|
protected function getUniqueAttr($value, $data)
|
|
{
|
|
if ($value) {
|
|
return is_string($value) && (!isset($data['type']) || $data['type'] != 3) ? explode(',', $value) : $value;
|
|
}
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* 关联优惠券
|
|
* @return \think\model\relation\HasOne
|
|
*/
|
|
public function coupon()
|
|
{
|
|
return $this->hasOne(StoreCouponIssue::class, 'id', 'coupon_id');
|
|
}
|
|
|
|
/**
|
|
* 关联商品
|
|
* @return \think\model\relation\HasOne
|
|
*/
|
|
public function productInfo()
|
|
{
|
|
return $this->hasOne(StoreProduct::class, 'id', 'product_id');
|
|
}
|
|
|
|
/**
|
|
* 赠送sku一对一
|
|
* @return \think\model\relation\hasOne
|
|
*/
|
|
public function giveAttrValue()
|
|
{
|
|
return $this->hasOne(StoreProductAttrValue::class, 'unique', 'unique')->where('type', 0);
|
|
}
|
|
|
|
/**
|
|
* sku一对多
|
|
* @return \think\model\relation\HasMany
|
|
*/
|
|
public function attrValue()
|
|
{
|
|
return $this->hasMany(StoreProductAttrValue::class, 'product_id', 'product_id')->where('type', 0);
|
|
}
|
|
|
|
/**
|
|
* 关联商品品牌
|
|
* @return \think\model\relation\HasOne
|
|
*/
|
|
public function brandInfo()
|
|
{
|
|
return $this->hasOne(StoreBrand::class, 'id', 'brand_id');
|
|
}
|
|
|
|
/**
|
|
* 关联商品标签
|
|
* @return \think\model\relation\HasOne
|
|
*/
|
|
public function productLabelInfo()
|
|
{
|
|
return $this->hasOne(StoreProductLabel::class, 'id', 'store_label_id');
|
|
}
|
|
|
|
|
|
/**
|
|
* type搜索器
|
|
* @param Model $query
|
|
* @param $value
|
|
*/
|
|
public function searchTypeAttr($query, $value)
|
|
{
|
|
if ($value) $query->where('type', $value);
|
|
}
|
|
|
|
/**
|
|
* product_partake_type搜索器
|
|
* @param Model $query
|
|
* @param $value
|
|
*/
|
|
public function searchProductPartakeTypeAttr($query, $value)
|
|
{
|
|
if ($value !== '') {
|
|
if (is_array($value)) {
|
|
if ($value) $query->whereIn('product_partake_type', $value);
|
|
} else {
|
|
if ($value) $query->where('product_partake_type', $value);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* promotions_id搜索器
|
|
* @param $query
|
|
* @param $value
|
|
*/
|
|
public function searchPromotionsIdAttr($query, $value)
|
|
{
|
|
if (is_array($value)) {
|
|
if ($value) $query->whereIn('promotions_id', $value);
|
|
} else {
|
|
if ($value !== '') $query->where('promotions_id', $value);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* coupon_id搜索器
|
|
* @param $query
|
|
* @param $value
|
|
*/
|
|
public function searchCouponIdAttr($query, $value)
|
|
{
|
|
if (is_array($value)) {
|
|
if ($value) $query->whereIn('coupon_id', $value);
|
|
} else {
|
|
if ($value !== '') $query->where('coupon_id', $value);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* product_id搜索器
|
|
* @param $query
|
|
* @param $value
|
|
*/
|
|
public function searchProductIdAttr($query, $value)
|
|
{
|
|
if (is_array($value)) {
|
|
if ($value) $query->whereIn('product_id', $value);
|
|
} else {
|
|
if ($value !== '') $query->where('product_id', $value);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* is_all搜索器
|
|
* @param $query
|
|
* @param $value
|
|
*/
|
|
public function searchIsAllAttr($query, $value)
|
|
{
|
|
if ($value !== '') {
|
|
$query->where('is_all', $value);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* brand_id
|
|
* @param $query
|
|
* @param $value
|
|
*/
|
|
public function searchBrandIdAttr($query, $value)
|
|
{
|
|
if (is_array($value)) {
|
|
if ($value) $query->whereIn('brand_id', $value);
|
|
} else {
|
|
if ($value !== '') $query->where('brand_id', $value);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* store_label_id
|
|
* @param $query
|
|
* @param $value
|
|
*/
|
|
public function searchStoreLabelIdAttr($query, $value)
|
|
{
|
|
if (is_array($value)) {
|
|
if ($value) $query->whereIn('store_label_id', $value);
|
|
} else {
|
|
if ($value !== '') $query->where('store_label_id', $value);
|
|
}
|
|
}
|
|
|
|
}
|