| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- <?php
- namespace common\models\user;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use PHPUnit\Util\Exception;
- use Yii;
- /**
- * This is the model class for table "qimall_user_level_upgrade_condition".
- *
- *
- * @property int $id
- * @property int $mall_id
- * @property int $user_level_id 会员等级ID
- * @property int $is_auto_upgrade 是否开启自动升级
- * @property string $checked_condition_values 升级条件
- * @property string $upgrade_type_condition 条件升级
- * @property string $checked_condition_keys 升级条件选中的key集合
- * @property int $condition_type 0 未选择、1满足其一 2、满足所有
- * @property int $upgrade_type_goods 购买升级商品,0关闭,1开启
- * @property int $goods_type 商品升级类型,1- 任意商品 2- 指定商品
- * @property string $goods_ids 商品id集合
- * @property string $cate_ids 商品分类id集合
- * @property int $buy_cate_type 订单完成0;支付完成:1
- * @property string $goods_list 商品列表json
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- * @property int $store_upgrade_type_goods 购买门店升级商品,0关闭,1开启
- * @property int $store_buy_goods_type 门店订单完成0;支付完成:1
- * @property int $store_goods_type 门店商品升级类型,1- 任意商品 2- 指定商品
- * @property string $store_goods_ids 门店商品id集合
- * @property string|null $store_goods_list 门店商品列表json
- * @property int $enable_goods_protocol 商品协议开关[0关闭;1开启]
- * @property int $is_custom_condition_num 是否自定义升级商品条件数量
- */
- class UserLevelUpgradeCondition extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%user_level_upgrade_condition}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_level_id', 'checked_condition_values', 'condition_type', 'upgrade_type_goods'], 'required'],
- [['mall_id', 'user_level_id', 'is_auto_upgrade', 'upgrade_type_condition', 'condition_type', 'upgrade_type_goods', 'goods_type', 'buy_goods_type', 'buy_cate_type', 'status', 'created_at', 'updated_at',
- 'store_upgrade_type_goods', 'store_buy_goods_type', 'store_goods_type', 'enable_goods_protocol', 'is_custom_condition_num'], 'integer'],
- [['checked_condition_values', 'checked_condition_keys','store_goods_list'], 'string'],
- [['goods_ids', 'cate_ids','store_goods_ids'], 'string', 'max' => 3000],
- [['goods_list'], 'string', 'max' => 50000],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_level_id' => '会员等级ID',
- 'is_auto_upgrade' => '是否开启自动升级',
- 'upgrade_type_condition' => '条件升级',
- 'checked_condition_keys' => '升级条件选中的key集合',
- 'checked_condition_values' => '升级条件',
- 'condition_type' => '0 未选择、1满足其一 2、满足所有',
- 'upgrade_type_goods' => '购买升级商品,0关闭,1开启',
- 'goods_type' => '商品升级类型,1- 任意商品 2- 指定商品',
- 'buy_goods_type' => '商品升级类型,1- 任意商品 2- 指定商品',
- 'goods_ids' => '商品id集合',
- 'goods_list' => '商品列表json',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'store_upgrade_type_goods' => '购买门店升级商品,0关闭,1开启',
- 'store_buy_goods_type' => '门店订单完成0;支付完成:1',
- 'store_goods_type' => '门店商品升级类型,1- 任意商品 2- 指定商品',
- 'store_goods_ids' => '门店商品id集合',
- 'store_goods_list' => '门店商品列表json',
- 'enable_goods_protocol' => '商品协议开关[0关闭;1开启]',
- 'is_custom_condition_num' => '是否自定义升级商品条件数量',
- ];
- }
- /**
- * 保存数据
- * @param array $params
- * @return bool|UserLevelUpgradeCondition
- */
- public static function setData(array $params)
- {
- try {
- $model = self::findOne(['mall_id' => $params['mall_id'], 'user_level_id' => $params['user_level_id'], 'status' => [StatusEnum::ENABLED,StatusEnum::DISABLED]]);
- if (empty($model)) {
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '')) throw new Exception($model->getErrorMessage());
- if (empty($params['checked_condition_keys'])) $params['checked_condition_keys'] = [];
- if (empty($params['checked_condition_values'])) $params['checked_condition_values'] = [];
- if (empty($params['goods_ids'])) $params['goods_ids'] = [];
- if (empty($params['store_goods_ids'])) $params['store_goods_ids'] = [];
- if (empty($params['cate_ids'])) $params['cate_ids'] = [];
- if (empty($params['goods_list'])) $params['goods_list'] = [];
- if (empty($params['store_goods_list'])) $params['store_goods_list'] = [];
- $model->checked_condition_keys = json_encode($params['checked_condition_keys'], JSON_NUMERIC_CHECK);
- $model->checked_condition_values = json_encode($params['checked_condition_values'], JSON_NUMERIC_CHECK);
- $model->goods_ids = json_encode($params['goods_ids'], JSON_NUMERIC_CHECK);
- $model->store_goods_ids = json_encode($params['store_goods_ids'], JSON_NUMERIC_CHECK);
- $model->cate_ids = json_encode($params['cate_ids'], JSON_NUMERIC_CHECK);
- $model->goods_list = json_encode($params['goods_list'], JSON_NUMERIC_CHECK);
- $model->store_goods_list = json_encode($params['store_goods_list'], JSON_NUMERIC_CHECK);
- if (!$model->save()) throw new Exception($model->getErrorMessage());
- return $model;
- } catch (Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * 获取升级条件模板数据
- * @param $obj
- * @param $mall_id
- * @param $rules
- * @return array
- */
- public static function getUpgradeConditionData($obj, $mall_id, $rules)
- {
- // $tpl = $obj->renderPartial('../upgrade-condition/tpl/tpl.php', ['rules' => $rules, 'mall_id' => $mall_id]);
- $tpl = $obj->renderPartial('@backend/modules/mall/views/upgrade-condition/tpl/tpl.php', ['rules' => $rules, 'mall_id' => $mall_id]);
- $source_list = [];
- $key_arr = [];
- foreach ($rules as $k => $item) {
- $row = [];
- $row['key'] = $item['id'];
- foreach ($item['setting'] as $value) {
- $row['value'][$value['name']] = '';
- if (!empty($value['source']['class']) && !empty($value['source']['method'])) {
- $class = $value['source']['class'];
- $method = $value['source']['method'];
- $rows = $class::$method(['mall_id' => $mall_id]);
- $source_list[$value['source']['key']] = $rows;
- }
- }
- $key_arr[] = $row;
- }
- $source_list = json_encode($source_list, JSON_NUMERIC_CHECK);
- $key_arr = json_encode($key_arr, JSON_NUMERIC_CHECK);
- return ['tpl' => $tpl, 'source_list' => $source_list, 'key_arr' => $key_arr];
- }
- /**
- * @param $where
- * @param $status
- * @return bool
- */
- public static function del($where, $status)
- {
- try {
- $query = self::find();
- self::paramPack(['where' => $where], $query);
- $model = $query->one();
- $model->status = $status;
- $res = $model->save();
- if ($res === false) throw new Exception(UserLevelUpgradeCondition::getStaticError());
- return true;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|