| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- namespace addons\BusinessCard\common\models;
- use common\enums\StatusEnum;
- use Exception;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_business_card_material_share".
- *
- * @property int $id 用户分享素材统计
- * @property int|null $mall_id 商城ID
- * @property int|null $user_id 用户ID
- * @property int|null $material_id 素材ID
- * @property int|null $share_times 分享次数
- * @property int|null $recent_time 最近分享时间
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- * @property int|null $created_at 创建时间
- * @property int|null $updated_at 更新时间
- */
- class BusinessCardMaterialsShare extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'qimall_addons_business_card_material_share';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'material_id', 'share_times', 'recent_time', 'status', 'created_at', 'updated_at'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => 'User ID',
- 'material_id' => 'Material ID',
- 'share_times' => 'Share Times',
- 'recent_time' => 'Recent Time',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * 数据设置
- */
- public static function setData(array $params)
- {
- try{
- if (!isset($params['mall_id']) || empty($params['mall_id'])) throw new Exception('缺少商城ID');
- if (isset($params['id']) && !empty($params['id'])) {
- $model = self::findOne([
- 'id' => $params['id'],
- 'mall_id' => $params['mall_id'],
- 'status' => StatusEnum::ENABLED
- ]);
- if(empty($model)) throw new Exception('分享记录不存在或已删除');
- } else if (isset($params['user_id']) && !empty($params['user_id']) && isset($params['material_id']) && !empty($params['material_id'])) {
- $model = self::findOne([
- 'user_id' => $params['user_id'],
- 'material_id' => $params['material_id'],
- 'mall_id' => $params['mall_id'],
- 'status' => StatusEnum::ENABLED
- ]);
- }
- if (!empty($model)) {
- if (isset($params['share_times'])) {
- $model->share_times = $model->share_times + $params['share_times'];
- unset($params['share_times']);
- }
- } else {
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $params['mall_id'];
- }
- if (!$model->load($params,'') || !$model->save()) throw new Exception($model->getErrorMessage());
- return $model;
- }catch(Exception $e){
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- }
|