bztang-admin/plugins/weight-value/src/models/GoodsWeightValue.php

51 lines
1.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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');
}
}