'ID', 'goods_id' => '商品ID', 'goods_attr_id' => '规格ID', 'min_score' => '最低抵扣积分', 'min_limit' => '是否限制[0=不限制,1=限制]', 'max_score' => '最高抵扣积分', 'max_limit' => '是否限制[0=不限制,1=限制]', 'status' => '状态[-1:删除;0:禁用;1启用]', 'created_at' => '创建时间', 'updated_at' => '更新时间', ]; } /** * @notes:数据保存 * @param $params * @return bool|void * @author: lun * @Time: 2022/10/22 15:59 */ public static function setData($params) { try { foreach ($params as $attr) { $attr['min_limit'] = $attr['min_limit'] === 'true' ? 1 : 0; $attr['max_limit'] = $attr['max_limit'] === 'true' ? 1 : 0; $model = self::findOne(['goods_id' => $attr['goods_id'], 'goods_attr_id' => $attr['goods_attr_id'], 'status' => StatusEnum::ENABLED]); if (empty($model)) { $model = new self(); $model->loadDefaultValues(); } if (!$model->load($attr, '') || !$model->save()) throw new Exception($model->getErrorMessage()); } return true; } catch (\Exception $e) { self::setStaticError($e->getMessage()); return false; } } /** * @notes:批量添加规格 * @param $attrs * @param $setting * @param $score_deduct_ratio * @return bool * @author: lun * @Time: 2022/11/15 15:37 */ public static function percentSetData($attrs, $setting, $score_deduct_ratio) { try { foreach ($attrs as $attr) { $attr['min_limit'] = $setting['min_limit'] === 'true' ? 1 : 0; $attr['max_limit'] = $setting['max_limit'] === 'true' ? 1 : 0; $attr['min_score'] = ceil($setting['min_score'] * $score_deduct_ratio * $attr['price']) / 100; $attr['max_score'] = ceil($setting['max_score'] * $score_deduct_ratio * $attr['price']) / 100; $model = self::findOne(['goods_id' => $attr['goods_id'], 'goods_attr_id' => $attr['goods_attr_id'], 'status' => StatusEnum::ENABLED]); if (empty($model)) { $model = new self(); $model->loadDefaultValues(); } if (!$model->load($attr, '') || !$model->save()) throw new Exception($model->getErrorMessage()); } return true; } catch (\Exception $e) { self::setStaticError($e->getMessage()); return false; } } }