| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace addons\BusinessCard\common\models;
- use common\models\goods\Goods;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_business_card_goods_statistics".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $user_id 用户ID
- * @property int $parent_id 分享者ID
- * @property int|null $goods_id 商品ID
- * @property int $total_visitors 访客数
- * @property int $total_views 浏览量
- * @property int|null $browse_time 浏览时长
- * @property int $status 状态[1启用 0禁用 -1删除]
- * @property int $created_at 创建时间
- * @property int $updated_at 更新时间
- */
- class BusinessCardGoodsStatistics extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'qimall_addons_business_card_goods_statistics';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'parent_id', 'goods_id', 'total_visitors', 'total_views', 'browse_time', 'status', 'created_at', 'updated_at'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => 'User ID',
- 'parent_id' => 'Parent ID',
- 'goods_id' => 'Goods ID',
- 'total_visitors' => 'Total Visitors',
- 'total_views' => 'Total Views',
- 'browse_time' => 'Browse Time',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * 保存数据
- *
- * @author ltm
- * @return bool|\Exception
- */
- public static function setData($params) {
- try {
- $model = self::findOne(['goods_id' => $params['goods_id'],'user_id'=> $params['user_id']]);
- if (!$model) {
- $model = new self();
- }else{
- if($params['browse_time']>0) $model->browse_time = $model->browse_time + $params['browse_time'];
- //if($params['total_visitors']>0) $model->total_visitors = $model->total_visitors + $params['total_visitors'];
- if($params['total_views']>0) $model->total_views = $model->total_views + $params['total_views'];
- unset($params['browse_time'],$params['total_visitors'],$params['total_views']);
- }
- if (!$model->load($params, '') || !$model->save()) throw new \Exception($model->getErrorMessage());
- return $model->id;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * 关联商品信息
- * @Author:ltm
- * @DateTime: 2022/5/27 0022 17:13
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return \yii\db\ActiveQuery
- */
- public function getGoods()
- {
- return $this->hasOne(Goods::class, ['id' => 'goods_id'])->select('id,goods_name,cover_pic');
- }
- }
|