| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- <?php
- namespace addons\Xhs\common\models;
- use common\enums\StatusEnum;
- use common\models\goods\Goods;
- use common\models\user\User;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "qimall_addons_xhs_content".
- *
- * @property int $id ID
- * @property int $mall_id 商城ID
- * @property int $user_id 用户ID
- * @property int $goods_id 商品ID
- * @property int $cate_id 内容所属的分类的id
- * @property int $views_count 浏览数
- * @property int $stars_count 点赞数
- * @property int $shares_count 被分享数
- * @property int $discuss_count 评论数
- * @property int|null $order_count 订单数
- * @property int|null $goods_views_count 商品浏览数量
- * @property int $content_type 内容类型,1:图片+文字,2:视频+文字
- * @property int $check_status 内容状态,1:在审核中,2:审核通过,3:审核未通过
- * @property int|null $check_time 审核是时间
- * @property string|null $check_remark 审核原因
- * @property string $title 标题
- * @property string $main_text 正文
- * @property int $time_length 视频时长,单位 秒,如果是图文,时长为 0
- * @property string $source 此字段保存资源相关的数据,即图片或者视频的保存路径。数据保存的结构形式如,[{url: "/path/to/11.mp4", front_cover: "/path/to/11.jpg"}].其中 url 的值是图片或者视频的保存路径, front_cover 是封面图片的保存路径
- * @property int|null $status 状态,-1是删除,0是禁用,1是启用
- * @property int $created_at 创建时间
- * @property int $updated_at 更新ID
- * @property int $video_wide 视频宽
- * @property int $video_long 视频长
- * @property int $is_top 是否置顶0.否|1.是
- */
- class AddonsXhsContent extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_xhs_content}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'cate_id', 'main_text', 'source'], 'required'],
- [['mall_id', 'user_id', 'goods_id', 'cate_id', 'views_count', 'stars_count', 'shares_count', 'discuss_count', 'order_count', 'goods_views_count', 'content_type', 'check_status', 'check_time', 'time_length', 'status', 'created_at', 'updated_at', 'video_wide', 'video_long', 'is_top'], 'integer'],
- [['main_text', 'source'], 'string'],
- [['check_remark'], 'string', 'max' => 255],
- [['title'], 'string', 'max' => 50],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'user_id' => '用户ID',
- 'goods_id' => '商品ID',
- 'cate_id' => '内容所属的分类的id',
- 'views_count' => '浏览数',
- 'stars_count' => '点赞数',
- 'shares_count' => '被分享数',
- 'discuss_count' => '评论数',
- 'order_count' => '订单数',
- 'goods_views_count' => '商品浏览数量',
- 'content_type' => '内容类型,1:图片+文字,2:视频+文字',
- 'check_status' => '内容状态,1:在审核中,2:审核通过,3:审核未通过',
- 'check_time' => '审核是时间',
- 'check_remark' => '审核原因',
- 'title' => '标题',
- 'main_text' => '正文',
- 'time_length' => '视频时长,单位 秒,如果是图文,时长为 0',
- 'source' => '此字段保存资源相关的数据,即图片或者视频的保存路径。数据保存的结构形式如,[{url: \"/path/to/11.mp4\", front_cover: \"/path/to/11.jpg\"}].其中 url 的值是图片或者视频的保存路径, front_cover 是封面图片的保存路径',
- 'status' => '状态,-1是删除,0是禁用,1是启用',
- 'created_at' => '创建时间',
- 'updated_at' => '更新ID',
- 'video_wide' => '视频宽',
- 'video_long' => '视频长',
- 'is_top' => '是否置顶0.否|1.是',
- ];
- }
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,mobile,nickname,avatar_url,parent_id,username');
- }
- public function getLike()
- {
- return $this->hasOne(AddonsXhsUserLike::class, ['content_id' => 'id'])->select('id,is_likes,content_id,user_id');
- }
- //管理商品
- public function getGoods()
- {
- return $this->hasOne(Goods::class, ['id' => 'goods_id'])->select('id,goods_name,price,cover_pic,sales_num,virtual_sales');
- }
- //管理商品
- public function getGoodsstatistics()
- {
- return $this->hasOne(AddonsXhsGoodsStatistics::class, ['goods_id' => 'goods_id'])->select('id,total_amount,order_num,goods_id,bought_count');
- }
- /**
- * 获取分类
- * @Author: ltm
- * @DateTime: 2021/12/13 0022 17:13
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $params
- * @return AddonsMaterial|bool
- */
- public function getCate(){
- return $this->hasOne(AddonsXhsCate::class, ['id' => 'cate_id'])->andWhere(['<>','status',StatusEnum::DELETE]);
- }
- /**
- * 保存数据
- * @Author: ltm
- * @DateTime: 2021/12/13 0022 17:13
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $params
- * @return string
- */
- public static function setData(array $params){
- try{
- if (!empty($params['id'])) {
- $model = self::findOne(['id'=>$params['id'],'mall_id'=>$params['mall_id']]);
- if (empty($model)) throw new Exception('记录不存在或已删除');
- }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::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- *
- */
- public static function handle($mall_id,$id,$type,$user_id){
- $find_data = AddonsXhsContent::findOne(['id' => $id]);
- $params['id'] = $id;
- $params['mall_id'] = $mall_id;
- switch ($type){
- case 'views';
- $params['views_count'] = $find_data ['views_count']+ 1;
- $statistics_data['views_count'] = 1;
- break;
- case 'stars';
- $res = self::likeLog($mall_id,$id,$user_id);
- if($res == StatusEnum::ENABLED) { //点赞
- $params['stars_count'] = $find_data ['stars_count'] + 1;
- $statistics_data['stars_count'] = 1;
- }else { //取消点赞
- $params['stars_count'] = $find_data ['stars_count'] - 1;
- $statistics_data['stars_count'] = "-1";
- }
- break;
- case 'shares';
- $params['shares_count'] = $find_data ['shares_count']+ 1;
- $statistics_data['shares_count'] = 1;
- break;
- case 'goods_views';
- $params['goods_views_count'] = $find_data ['goods_views_count']+ 1;
- if($find_data ['goods_id']){
- $statistics_data['goods_views_count'] = 1;
- self::goodsViewsLog($mall_id,$id,$user_id,$find_data['goods_id']);
- }
- break;
- case 'discuss';//评论
- $params['discuss_count'] = $find_data ['discuss_count']+ 1;
- $statistics_data['discuss_count'] = 1;
- break;
- case 'push_count'; //发布信息
- $statistics_data['push_count'] = 1;
- }
- $statistics_data['mall_id'] = $mall_id;
- if($id){
- if(!$find_data->load($params,'') || !$find_data->save()){
- throw new Exception($find_data->getErrorMessage());
- }
- }
- AddonsXhsStatistics::setData($statistics_data);
- AddonsXhsAllStatistics::setData($statistics_data);
- return true;
- }
- //添加商品访问记录
- public static function goodsViewsLog($mall_id,$id,$user_id,$goods_id){
- $like_data['mall_id'] = $mall_id;
- $like_data['content_id'] = $id;
- $like_data['user_id'] = $user_id;
- $like_data['goods_id'] = $goods_id;
- AddonsXhsGoodsVisit::setData($like_data);
- $goods_data['goods_id'] = $goods_id;
- $goods_data['goods_views_count'] = 1;
- $goods_data['mall_id'] = $mall_id;
- AddonsXhsGoodsStatistics::setData($goods_data);
- }
- //用户喜欢记录
- public static function likeLog($mall_id,$id,$user_id){
- $like_data['mall_id'] = $mall_id;
- $like_data['content_id'] = $id;
- $like_data['user_id'] = $user_id;
- return AddonsXhsUserLike::setData($like_data);
- }
- }
|