| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace addons\WriteOff\common\models;
- use addons\WriteOff\common\enums\WriteOffEnum;
- use common\enums\StatusEnum;
- use Yii;
- /**
- * This is the model class for table "{{%addons_write_off_setting}}".
- *
- * @property int $id ID
- * @property int $mall_id 商城ID
- * @property int $is_enable 启用状态[0禁用; 1启用]
- * @property int $goods_id 商品ID
- * @property float $give_num 奖励数量
- * @property int $settlement_method 计算方式[0订单完成, 1订单支付]
- * @property int $status 状态[-1删除; 0禁用; 1正常]
- * @property int $created_at 创建时间
- * @property int $updated_at 更新时间
- * @property int $is_enable_promote_reward_type 奖励类型
- * @property int $is_enable_promote_reward_prize 奖励基数
- */
- class WriteOffSetting extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_write_off_setting}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'is_enable', 'goods_id', 'settlement_method', 'status', 'created_at', 'updated_at','is_enable_promote_reward','is_enable_promote_reward_type'], 'integer'],
- [['goods_id'], 'required'],
- [['give_num','promote_reward_prize','is_enable_promote_reward_prize'], 'number'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'is_enable' => 'Is Enable',
- 'goods_id' => 'Goods ID',
- 'give_num' => 'Give Num',
- 'settlement_method' => 'Settlement Method',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'is_enable_promote_reward_type' => 'Updated At',
- 'is_enable_promote_reward_prize' => 'Updated At',
- ];
- }
- public static function getGoodSetting($params)
- {
- // 后台页面组件展示
- if ($params['type'] == 'show_component') {
- return [
- 'component' => 'com-write-off',
- 'path' => Yii::$app->basePath . '/../addons/WriteOff/backend/views/goods',
- ];
- } else {
- try {
- if (empty($params['setting'][WriteOffEnum::ADDONS_NAME])) return true;
- $setting = $params['setting'][WriteOffEnum::ADDONS_NAME];
- $setting['mall_id'] = $params['mall_id'];
- $setting['goods_id'] = $params['goods_id'];
- // 数据保存
- $res = self::setData($setting);
- if ($res === false) throw new \Exception(self::getStaticError());
- return true;
- } catch (\Exception $e) {
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- }
- public static function setData(array $params)
- {
- try {
- $model = self::findOne(['mall_id' => $params['mall_id'], 'goods_id' => $params['goods_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if (empty($model)) {
- $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;
- }
- }
- }
|