| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <?php
- namespace addons\ShortVideo\common\models;
- use addons\ShortVideo\common\enums\AddonsShortVideoEnum;
- use common\enums\StatusEnum;
- use common\models\goods\Goods;
- use Yii;
- /**
- * This is the model class for table "{{%addons_short_video_config}}".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $is_enabled 是否开启 0--关闭|1--开启
- * @property int $is_check 是否需要审核0:否 1:是
- * @property int $release_rule 发布权限:0:无条件 1:有条件
- * @property int|null $award_status 是否开启全局带货奖励0:否 1:是
- * @property int $award_type 奖励类型 0:金额 1:百分比
- * @property float $award_percentage 奖励百分比
- * @property float $award_money 奖励金额
- * @property int|null $purchase_times_status 消费达到多少次 是否开启 0:未开启 1:开启
- * @property int|null $purchase_times 消费达到多少次
- * @property int|null $purchase_cost_status 消费达标是否开启0:未开启 1:已开启
- * @property float|null $purchase_cost 消费达到多少钱
- * @property int|null $purchase_goods_status 消费商品是否开启0:未开启 1:已开启
- * @property int|null $purchase_goods_id 消费某个商品
- * @property int $video_lenght 视频发布时长
- * @property string|null $agreement 视频协议
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int|null $client_status 是否开启文本审核 0:否 1:是
- * @property string|null $start_up_diagram 启动图
- * @property string|null $share_img 分享图片
- * @property string|null $share_title 分享标题
- * @property string|null $share_content 分享内容
- * @property int $created_at
- * @property int $updated_at
- */
- class ShortVideoConfig extends \common\models\base\BaseActiveRecord
- {
- private static $cache_key = 'qimall:short-video:config:mall_id:';
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_short_video_config}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id'], 'required'],
- [['mall_id', 'is_enabled', 'is_check', 'release_rule', 'award_status', 'award_type', 'purchase_times_status', 'purchase_times', 'purchase_cost_status', 'purchase_goods_status', 'purchase_goods_id', 'video_lenght', 'status', 'client_status', 'created_at', 'updated_at'], 'integer'],
- [['award_percentage', 'award_money', 'purchase_cost'], 'number'],
- [['agreement'], 'string'],
- [['start_up_diagram', 'share_img'], 'string', 'max' => 255],
- [['share_title', 'share_content'], 'string', 'max' => 65],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'is_enabled' => 'Is Enabled',
- 'is_check' => 'Is Check',
- 'release_rule' => 'Release Rule',
- 'award_status' => 'Award Status',
- 'award_type' => 'Award Type',
- 'award_percentage' => 'Award Percentage',
- 'award_money' => 'Award Money',
- 'purchase_times_status' => 'Purchase Times Status',
- 'purchase_times' => 'Purchase Times',
- 'purchase_cost_status' => 'Purchase Cost Status',
- 'purchase_cost' => 'Purchase Cost',
- 'purchase_goods_status' => 'Purchase Goods Status',
- 'purchase_goods_id' => 'Purchase Goods ID',
- 'video_lenght' => 'Video Lenght',
- 'agreement' => 'Agreement',
- 'status' => 'Status',
- 'client_status' => 'Client Status',
- 'start_up_diagram' => 'Start Up Diagram',
- 'share_img' => 'Share Img',
- 'share_title' => 'Share Title',
- 'share_content' => 'Share Content',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- public static function getConfig(int $mall_id)
- {
- $cache = \Yii::$app->cache;
- $configs = $cache->get(self::$cache_key . $mall_id);
- // dd($configs);
- if (!empty($configs)) return $configs;
- $configs = self::find()
- ->where(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'is_enabled' => AddonsShortVideoEnum::IS_ENABLE_YES])
- ->asArray()
- ->orderBy('updated_at desc')
- ->limit(1)
- ->one();
- if (!empty($configs)) {
- if (1 == $configs['purchase_goods_status'] && !empty($configs['purchase_goods_id'])) {
- $good = Goods::findOne(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'id' => $configs['purchase_goods_id']]);
- $configs['purchase_goods_name'] = $good->goods_name;
- }
- $cache->set(self::$cache_key . $mall_id, $configs, 3600);
- } else {
- $configs = [];
- }
- return $configs;
- }
- public static function setData(int $mall_id, array $data)
- {
- if (!empty($data['id'])) {
- $model = self::findOne(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'id' => $data['id']]);
- if (empty($model)) {
- self::$static_error = '配置数据不存在';
- return false;
- }
- } else {
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $mall_id;
- }
- foreach ($data as $key => $val) {
- $model->$key = $val;
- }
- if (!$model->save()) {
- self::$static_error = '保存奖励数据失败:' . $model->getErrorMessage();
- return false;
- }
- \Yii::$app->cache->delete(self::$cache_key . $mall_id);
- return $model;
- }
- }
|