Review.php 3.0 KB
Newer Older
_
__FresHmaN 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
<?php
/**
 * FecShop file.
 *
 * @link http://www.fecshop.com/
 * @copyright Copyright (c) 2016 FecShop Software LLC
 * @license http://www.fecshop.com/license/
 */

namespace fecshop\models\mongodb\product;

use yii\mongodb\ActiveRecord;

/**
 * @author Terry Zhao <2358269014@qq.com>
 * @since 1.0
 */
class Review extends ActiveRecord
{
    public static $_customAttrs;
    // 评论默认状态,也就是用户添加了评论后的状态(前面是客户的评论信息需要审核的前提下,如果客户信息不需要审核的话,则就是ACTIVE_STATUS)
    const NOACTIVE_STATUS = 10;
    // 审核通过的状态
    const ACTIVE_STATUS = 1;
    // 审核拒绝的状态
    const REFUSE_STATUS = 2;
27 28 29 30 31 32 33 34 35 36 37 38 39
    
    
    public function getActiveStatus(){
        return self::ACTIVE_STATUS;
    }
    
    public function getNoActiveStatus(){
        return self::NOACTIVE_STATUS;
    }
    
    public function getRefuseStatus(){
        return self::REFUSE_STATUS;
    }
T
Terry 已提交
40 41 42
    /**
     * mongodb collection 的名字,相当于mysql的table name
     */
_
__FresHmaN 已提交
43 44 45 46 47 48 49 50 51 52
    public static function collectionName()
    {
        return 'review';
    }

    // 动态增加字段。
    public static function addCustomAttrs($attrs)
    {
        self::$_customAttrs = $attrs;
    }
T
Terry 已提交
53 54 55 56
    /**
     * mongodb是没有表结构的,因此不能像mysql那样取出来表结构的字段作为model的属性
     * 因此,需要自己定义model的属性,下面的方法就是这个作用
     */
_
__FresHmaN 已提交
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
    public function attributes($origin = false)
    {
        $origin = [
            '_id',
            'product_spu',
            'product_sku',
            'product_id',
            'rate_star',
            'name',
            'user_id',
            'ip',
            'summary',
            'review_content',        // 评论的内容
            'review_date',            // 评论的最后更新时间
            'store',            // store
            'lang_code',        // 语言
            'status',            // 审核状态 10代表未审核,1代表已审核。
            'audit_user',        // 审核账号
            'audit_date',        // 审核时间
        ];
        if ($origin) { // 取原始的数据
            return $origin;
        }
        if (is_array(self::$_customAttrs) && !empty(self::$_customAttrs)) {
            $origin = array_merge($origin, self::$_customAttrs);
        }

        return $origin;
    }
T
Terry 已提交
86 87 88 89 90 91
    /**
     * 给model对应的表创建索引的方法
     * 在indexs数组中填写索引,如果有多个索引,可以填写多行
     * 在migrate的时候会运行创建索引,譬如:
     * @fecshop/migrations/mongodb/m170228_072455_fecshop_tables
     */
_
__FresHmaN 已提交
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    public static function create_index()
    {
        $indexs = [
            ['product_spu'        => -1],
            ['product_sku'        => -1],
            ['product_id' => -1],
            ['user_id' => -1],

        ];

        $options = ['background' => true];
        foreach ($indexs as $columns) {
            self::getCollection()->createIndex($columns, $options);
        }
    }
}