117 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			PHP
		
	
	
		
		
			
		
	
	
			117 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			PHP
		
	
	
| 
								 | 
							
								<?php
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								namespace app\model;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								use Exception;
							 | 
						||
| 
								 | 
							
								use think\db\exception\DataNotFoundException;
							 | 
						||
| 
								 | 
							
								use think\db\exception\DbException;
							 | 
						||
| 
								 | 
							
								use think\db\exception\ModelNotFoundException;
							 | 
						||
| 
								 | 
							
								use think\facade\Db;
							 | 
						||
| 
								 | 
							
								use think\model\relation\HasOne;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								class AccountRecord extends Base
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    public const TYPE_CONTENT = 'content';//内容
							 | 
						||
| 
								 | 
							
								    public const TYPE_SPU     = 'spu';//商品
							 | 
						||
| 
								 | 
							
								    public const TYPE_OTHER   = 'other';//其他
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public const ACTION_COLLECT    = 'collect';//收藏
							 | 
						||
| 
								 | 
							
								    public const ACTION_LIKE       = 'like';//点赞
							 | 
						||
| 
								 | 
							
								    public const ACTION_SHARE      = 'share';//分享
							 | 
						||
| 
								 | 
							
								    public const ACTION_SEARCH     = 'search';//搜索
							 | 
						||
| 
								 | 
							
								    public const ACTION_VIEW       = 'view';//查看
							 | 
						||
| 
								 | 
							
								    public const ACTION_REGISTER   = 'register';//注册
							 | 
						||
| 
								 | 
							
								    public const ACTION_SHARE_VIEW = 'share_view';//分享内容被查看 记录的account_id为分享人ID
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public const COLLECTED = 1;
							 | 
						||
| 
								 | 
							
								    public const LIKED     = 1;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * 允许的类型
							 | 
						||
| 
								 | 
							
								     *
							 | 
						||
| 
								 | 
							
								     * @return string[]
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public static function allowTypes(): array
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        return [
							 | 
						||
| 
								 | 
							
								            self::TYPE_CONTENT, self::TYPE_OTHER, self::TYPE_SPU
							 | 
						||
| 
								 | 
							
								        ];
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * 允许的操作
							 | 
						||
| 
								 | 
							
								     *
							 | 
						||
| 
								 | 
							
								     * @return string[]
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public static function allowActions(): array
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        return [
							 | 
						||
| 
								 | 
							
								            self::ACTION_COLLECT, self::ACTION_LIKE, self::ACTION_SHARE,
							 | 
						||
| 
								 | 
							
								            self::ACTION_REGISTER, self::ACTION_VIEW, self::ACTION_SHARE_VIEW
							 | 
						||
| 
								 | 
							
								        ];
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * 内容表允许的操作
							 | 
						||
| 
								 | 
							
								     *
							 | 
						||
| 
								 | 
							
								     * @return string[]
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public static function archivesActions(): array
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        return [
							 | 
						||
| 
								 | 
							
								            self::ACTION_COLLECT, self::ACTION_LIKE, self::ACTION_SHARE,
							 | 
						||
| 
								 | 
							
								            self::ACTION_VIEW
							 | 
						||
| 
								 | 
							
								        ];
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * 不可撤销的操作 即每次都新增记录 如 分享、咨询、注册
							 | 
						||
| 
								 | 
							
								     * 注意:可撤销操作需要防止撤销后重新操作导致的无限制增加统计 即刷数据 如收藏、点赞等
							 | 
						||
| 
								 | 
							
								     *
							 | 
						||
| 
								 | 
							
								     * @return string[]
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public static function notUndoActions(): array
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        return [self::ACTION_SHARE, self::ACTION_REGISTER, self::ACTION_VIEW];
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * 操作对应字段
							 | 
						||
| 
								 | 
							
								     *
							 | 
						||
| 
								 | 
							
								     * @return string[]
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public static function actionField(): array
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        return [
							 | 
						||
| 
								 | 
							
								            self::ACTION_REGISTER   => 'customer',
							 | 
						||
| 
								 | 
							
								            self::ACTION_COLLECT    => 'collects',
							 | 
						||
| 
								 | 
							
								            self::ACTION_LIKE       => 'likes',
							 | 
						||
| 
								 | 
							
								            self::ACTION_VIEW       => 'views',
							 | 
						||
| 
								 | 
							
								            self::ACTION_SHARE      => 'shares',
							 | 
						||
| 
								 | 
							
								            self::ACTION_SHARE_VIEW => 'views',//分享内容被查看 也增加views
							 | 
						||
| 
								 | 
							
								        ];
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * 概览操作对应字段
							 | 
						||
| 
								 | 
							
								     *
							 | 
						||
| 
								 | 
							
								     * @return string[]
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public static function overviewField(): array
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        return [
							 | 
						||
| 
								 | 
							
								            self::ACTION_REGISTER   => 'customer',
							 | 
						||
| 
								 | 
							
								            self::ACTION_VIEW       => 'views',
							 | 
						||
| 
								 | 
							
								            self::ACTION_SHARE      => 'shares',
							 | 
						||
| 
								 | 
							
								            self::ACTION_SHARE_VIEW => 'views',//分享内容被查看 也增加views
							 | 
						||
| 
								 | 
							
								        ];
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * 模型关联:内容文档
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public function archive(): HasOne
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        return $this->hasOne(Archives::class, 'id', 'relation_id');
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 |