BusinessCardGoodsStatistics.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace addons\BusinessCard\common\models;
  3. use common\models\goods\Goods;
  4. use Yii;
  5. /**
  6. * This is the model class for table "qimall_addons_business_card_goods_statistics".
  7. *
  8. * @property int $id
  9. * @property int $mall_id
  10. * @property int $user_id 用户ID
  11. * @property int $parent_id 分享者ID
  12. * @property int|null $goods_id 商品ID
  13. * @property int $total_visitors 访客数
  14. * @property int $total_views 浏览量
  15. * @property int|null $browse_time 浏览时长
  16. * @property int $status 状态[1启用 0禁用 -1删除]
  17. * @property int $created_at 创建时间
  18. * @property int $updated_at 更新时间
  19. */
  20. class BusinessCardGoodsStatistics extends \common\models\base\BaseActiveRecord
  21. {
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public static function tableName()
  26. {
  27. return 'qimall_addons_business_card_goods_statistics';
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function rules()
  33. {
  34. return [
  35. [['mall_id', 'user_id', 'parent_id', 'goods_id', 'total_visitors', 'total_views', 'browse_time', 'status', 'created_at', 'updated_at'], 'integer'],
  36. ];
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function attributeLabels()
  42. {
  43. return [
  44. 'id' => 'ID',
  45. 'mall_id' => 'Mall ID',
  46. 'user_id' => 'User ID',
  47. 'parent_id' => 'Parent ID',
  48. 'goods_id' => 'Goods ID',
  49. 'total_visitors' => 'Total Visitors',
  50. 'total_views' => 'Total Views',
  51. 'browse_time' => 'Browse Time',
  52. 'status' => 'Status',
  53. 'created_at' => 'Created At',
  54. 'updated_at' => 'Updated At',
  55. ];
  56. }
  57. /**
  58. * 保存数据
  59. *
  60. * @author ltm
  61. * @return bool|\Exception
  62. */
  63. public static function setData($params) {
  64. try {
  65. $model = self::findOne(['goods_id' => $params['goods_id'],'user_id'=> $params['user_id']]);
  66. if (!$model) {
  67. $model = new self();
  68. }else{
  69. if($params['browse_time']>0) $model->browse_time = $model->browse_time + $params['browse_time'];
  70. //if($params['total_visitors']>0) $model->total_visitors = $model->total_visitors + $params['total_visitors'];
  71. if($params['total_views']>0) $model->total_views = $model->total_views + $params['total_views'];
  72. unset($params['browse_time'],$params['total_visitors'],$params['total_views']);
  73. }
  74. if (!$model->load($params, '') || !$model->save()) throw new \Exception($model->getErrorMessage());
  75. return $model->id;
  76. } catch (\Exception $e) {
  77. self::$static_error = $e->getMessage();
  78. return false;
  79. }
  80. }
  81. /**
  82. * 关联商品信息
  83. * @Author:ltm
  84. * @DateTime: 2022/5/27 0022 17:13
  85. * @Copyright: copyright (c) 2021 广东七件事集团
  86. * @return \yii\db\ActiveQuery
  87. */
  88. public function getGoods()
  89. {
  90. return $this->hasOne(Goods::class, ['id' => 'goods_id'])->select('id,goods_name,cover_pic');
  91. }
  92. }