| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- namespace addons\CloudStock\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_cloud_stock_price_difference_gift_package".
- *
- * @property int $id
- * @property int $mall_id 商城id
- * @property string $name 礼包名称
- * @property int $pic_type 0:默认;1:自定义
- * @property string $pic 礼包主图
- * @property int $level 升级等级权重
- * @property float $price 礼包金额
- * @property string|null $goods_id
- * @property string|null $recommend_reward 推荐奖励设置
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- * @property int $is_range 是否走极差:1:是;0:否
- * @property int $is_achievement_user 是否走极差:1:是;0:否
- * @property int $not_get_price_difference 开启后若代理商获得推荐奖励,则不会同时得到差价奖 1:开启;0:关闭
- * @property int $not_distribute_payment_for_goods 开启后若推荐奖发放到货款者后不再发出 1:开启;0:关闭
- */
- class CloudStockPriceDifferenceGiftPackage extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_cloud_stock_price_difference_gift_package}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'name', 'level', 'price'], 'required'],
- [['mall_id', 'pic_type', 'level', 'status', 'created_at', 'updated_at', 'is_range', 'is_achievement_user',
- 'not_get_price_difference', 'not_distribute_payment_for_goods'], 'integer'],
- [['price'], 'number'],
- [['goods_id', 'recommend_reward'], 'string'],
- [['name', 'pic'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'name' => 'Name',
- 'pic_type' => 'Pic Type',
- 'pic' => 'Pic',
- 'level' => 'Level',
- 'price' => 'Price',
- 'goods_id' => 'Goods ID',
- 'recommend_reward' => 'Recommend Reward',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'is_range' => 'is_range',
- 'is_achievement_user' => 'is_achievement_user',
- 'not_get_price_difference' => 'not_get_price_difference',
- 'not_distribute_payment_for_goods' => 'not_distribute_payment_for_goods',
- ];
- }
- public static function setData(array $params)
- {
- try {
- if (!empty($params['id'])) {
- $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if (empty($model)) throw new \Exception('服务不存在或已删除');
- $obj = self::findOne(['mall_id' => $params['mall_id'], 'level' => $params['level'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if (!empty($obj) && $obj->id != $params['id']) {
- throw new \Exception('该等级已有礼包');
- }
- } else {
- $model = self::findOne(['mall_id' => $params['mall_id'], 'level' => $params['level'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if (!empty($model)) {
- throw new \Exception('该等级已有礼包');
- }
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|