51 lines
1.7 KiB
PHP
51 lines
1.7 KiB
PHP
<?php
|
||
namespace Yunshop\WeightValue\models;
|
||
|
||
|
||
use app\common\models\BaseModel;
|
||
use app\frontend\models\Goods;
|
||
|
||
class GoodsWeightValue extends BaseModel{
|
||
|
||
public $table = 'yz_goods_weight_value';
|
||
public $timestamps = false;
|
||
|
||
public static function relationSave($goodsId, $data, $operate){
|
||
if (!$goodsId) return false;
|
||
if (!$data) return false;
|
||
$info = self::getModel($goodsId, $operate);
|
||
// 判断deleted
|
||
if ($operate == 'deleted') return $info->delete();
|
||
// 其他
|
||
$info->uniacid = \YunShop::app()->uniacid;
|
||
$info->goods_id = $goodsId;
|
||
$info->is_open = $data['is_open'] ?? 0;// 是否开启购买商品赠送权重值:0=未开启,1=开启
|
||
$info->user_type = $data['user_type'] ?? 0;// 受赠用户类型:0=全部用户,1=仅经销商
|
||
$info->gift_type = $data['gift_type'] ?? 0;// 赠送方式:0=赠送固定值,1=阶梯值赠送
|
||
$info->lv_type = $data['lv_type'] ?? 0;// 赠送方式:0=二级,1=三级
|
||
$info->quantity = $data['quantity'] ?? 0;// 固定值赠送数量
|
||
$info->ladder = json_encode($data['ladder'] ?? []);// 阶梯赠送信息
|
||
|
||
return $info->save();
|
||
}
|
||
|
||
public static function getModel($goodsId, $operate){
|
||
$model = false;
|
||
if ($operate != 'created') $model = static::where(['goods_id' => $goodsId])->first();
|
||
|
||
!$model && $model = new static;
|
||
|
||
return $model;
|
||
}
|
||
|
||
public function getGoodsSet($goodsId){
|
||
return self::where('goods_id', $goodsId);
|
||
}
|
||
|
||
//关联商品信息
|
||
public function belongsToGoods(){
|
||
return $this->belongsTo(Goods::class, 'goods_id', 'id');
|
||
}
|
||
|
||
}
|