delete(); // 公共 $info->uniacid = \YunShop::app()->uniacid; $info->goods_id = $isTeamDividend ? 0 : $goodsId;// 经销商设置true goods_id = 0;否则为goodsId $info->team_dividend_level_id = $isTeamDividend ? $goodsId : 0;// 经销商设置true team_dividend_level_id = goodsId;否则为0 $info->is_open = $data['is_open'] ?? 0;// 是否开启购买商品赠送权重值:0=未开启,1=开启 $info->is_self_purchase = $data['is_self_purchase'] ?? 0;// 是否开启自购:0=不开启,1=开启 // 经纪人 $info->gift_type = $data['gift_type'] ?? 0;// 赠送方式:0=赠送固定值,1=阶梯值赠送 $info->lv_type = $data['lv_type'] ?? 0;// 赠送方式:0=二级,1=三级 $info->calculation_type = $data['calculation_type'] ?? 0;// 计算类型:0=固定值,1=支付比例 $info->quantity = $data['quantity'] ?? 0;// 固定值赠送数量 foreach($data['ladder'] as $ladderIndex => $ladderItem){ if((float)$ladderItem['where'] <= 0 || (float)$ladderItem['num'] <= 0) unset($data['ladder'][$ladderIndex]); } $info->ladder = json_encode($data['ladder'] ?? []);// 阶梯赠送信息 // 代理商 $info->agent_gift_type = $data['agent_gift_type'] ?? 0;// 赠送方式:0=赠送固定值,1=阶梯值赠送 $info->agent_calculation_type = $data['agent_calculation_type'] ?? 0;// 计算类型:0=固定值,1=支付比例 $info->agent_quantity = $data['agent_quantity'] ?? 0;// 固定值赠送数量 foreach($data['agent_ladder'] as $ladderIndex => $ladderItem){ if((float)$ladderItem['where'] <= 0 || (float)$ladderItem['num'] <= 0) unset($data['agent_ladder'][$ladderIndex]); } $info->agent_ladder = json_encode($data['agent_ladder'] ?? []);// 阶梯赠送信息 // 省公司 $info->province_gift_type = $data['province_gift_type'] ?? 0;// 赠送方式:0=赠送固定值,1=阶梯值赠送 $info->province_calculation_type = $data['province_calculation_type'] ?? 0;// 计算类型:0=固定值,1=支付比例 $info->province_quantity = $data['province_quantity'] ?? 0;// 固定值赠送数量 foreach($data['province_ladder'] as $ladderIndex => $ladderItem){ if((float)$ladderItem['where'] <= 0 || (float)$ladderItem['num'] <= 0) unset($data['province_ladder'][$ladderIndex]); } $info->province_ladder = json_encode($data['province_ladder'] ?? []);// 阶梯赠送信息 return $info->save(); } public static function getModel($goodsId, $operate,$isTeamDividend = false){ $model = false; // 商品设置 if ($operate != 'created') { if($isTeamDividend) $model = static::where(['team_dividend_level_id' => $goodsId])->first();// 经销商设置 else $model = static::where(['goods_id' => $goodsId])->first();// 经销商设置 } !$model && $model = new static; return $model; } public function getGoodsSet($goodsId,$isTeamDividend = false){ if($isTeamDividend) return self::where('team_dividend_level_id', $goodsId); return self::where('goods_id', $goodsId); } //关联商品信息 public function belongsToGoods(){ return $this->belongsTo(Goods::class, 'goods_id', 'id'); } }