DengTao 8 жил өмнө
parent
commit
9e5b7dde78

+ 0 - 97
www/protected/commands/GetKennelWorkCommand.php

@@ -1,97 +0,0 @@
-<?php
-/**
- * Created by PhpStorm.
- * User: PHP
- * Date: 2016/11/23
- * Time: 9:11
- */
-class GetKennelWorkCommand extends CConsoleCommand {
-    public function run($args){
-        error_reporting(E_ERROR);
-        ini_set('memory_limit', '256M');
-        //ini_set('mongo.long_as_object',1);
-        set_time_limit(0);
-        self::getKennel();
-    }
-
-    public function getKennel(){
-        $count = 0;
-        $page = intval(Yii::app()->redis->get('page'));
-        if (empty($page)) $page =1;
-        while($page) {
-            if ($count >= 1000) {
-                Yii::app()->redis->set('page', intval(--$page));
-                exit;
-            }
-            $res = CommonFn::simple_http("http://deal.wozhua.mobi/api/kennel/list?user_id=546b16f50eb9fb494f8b4664&page=".$page++."&rows=10");
-            $res = json_decode($res,true);
-            if ($res['success']) {
-                $list = $res['data']['list'];
-
-                foreach ($list as $key => $value) {
-                    $count++;
-                    $tmp = json_decode(CommonFn::simple_http("http://deal.wozhua.mobi/api/kennel/desc?user_id=546b16f50eb9fb494f8b4664&kennel_id=" . $value['id']), true);
-                    if (!empty($tmp)) {
-                        $tmp = $tmp['data'];
-                        if (!empty(Kennel::model()->get(new MongoId($value['id'])))) {
-                            $kennel = Kennel::model()->get(new MongoId($value['id']));
-                        } else {
-                            $kennel = new Kennel();
-                        }
-                        $kennel->_id = new MongoId($value['id']);
-                        $kennel->status = 1;
-                        $kennel->weight = 0;
-                        $kennel->name = $value['name'];
-                        $kennel->avatar = self::getVaildDataPost($value['avatar']);
-                        //$kennel->avatar = $value['avatar'];
-                        $kennel->join_time = time();
-                        $kennel->region = (Object)$value['region'];
-                        $kennel->video = (Object)$value['video'];
-                        //if ($value['is_certified']) {
-                            //$kennel->type = 1;
-                        //} else {
-                            $kennel->type = 2;
-                        //}
-                        foreach ( $tmp['tags'] as $k => $v)
-                            $kennel->tags[$k] = $v;
-                        $kennel->desc = $tmp['desc'];
-                        foreach ($tmp['desc_pics'] as $k => $v) {
-                            if (!empty($v['url'])){
-                                $v['url'] =  self::getVaildDataPost($v['url']);
-                            }
-                            if (!empty($v['video_url'])) {
-                                $v['video_url'] = '';
-                            }
-                            $kennel->desc_pics[$k] = $v;
-                        }
-                        $kennel->address = $tmp['address'];
-                        $kennel->phone = $tmp['phone'];
-                        $kennel->from = 'wozhua';
-                        //$kennel->favorable_rate = $tmp['favorable_rate'];
-                        //$kennel->comment_count = $tmp['comment_count'];
-                        //$kennel->favorable_count = $tmp['favorable_count'];
-                        //$kennel->average = $tmp['favorable_star'];
-                        $kennel->save();
-                        sleep(3);
-                    }
-                }
-                sleep(3);
-            }
-        }
-    }
-
-    public function getVaildDataPost($url){
-        $tmp[] =  str_replace(parse_url($url)['host'],'pics.maiyizhi.cn',$url);
-        $tmp[] = str_replace(parse_url($url)['host'],'avatars.maiyizhi.cn',$url);
-        $tmp[] = str_replace(parse_url($url)['host'],'test.maiyizhi.cn',$url);
-        $tmp[] = str_replace(parse_url($url)['host'],'icons.maiyizhi.cn',$url);
-        foreach ($tmp as $value){
-            if (empty(json_decode(CommonFn::simple_http($value),true)['error'])){
-                $url = $value;break;
-            }
-        }
-        return $url;
-    }
-
-
-}

+ 0 - 113
www/protected/commands/GetPetWorkCommand.php

@@ -1,113 +0,0 @@
-<?php
-/**
- * Created by PhpStorm.
- * User: PHP
- * Date: 2016/11/23
- * Time: 9:11
- */
-class GetPetWorkCommand extends CConsoleCommand
-{
-    public function run($args)
-    {
-        error_reporting(E_ERROR);
-        ini_set('memory_limit', '256M');
-        //ini_set('mongo.long_as_object',1);
-        set_time_limit(0);
-        self::getPet();
-    }
-
-    public function getPet()
-    {
-        $kennels = new Kennel();
-        $cursor = $kennels->findAll();
-        foreach ($cursor as $kennel) {
-            $resources = CommonFn::simple_http("http://deal.wozhua.mobi/api/pet/list?user_id=546b16f50eb9fb494f8b4664&page=1&rows=2000&kennel=" . $kennel['_id']);
-            $resources = json_decode($resources, true);
-            if (!empty($resources['data']['list'])) {
-                $petsList = $resources['data']['list'];
-                foreach ($petsList as $k => $pet) {
-                    //获取pet详情
-                    $tmp = json_decode(CommonFn::simple_http("http://deal.wozhua.mobi/api/pet/info?user_id=546b16f50eb9fb494f8b4664&pet_id=" . $pet['id']), true);
-                    $tmp = $tmp['data'];
-                    if (!empty($tmp)) {
-                        if (!empty(DealPet::model()->get(new MongoId($tmp['id'])))) {
-                            $dealPet = DealPet::model()->get(new MongoId($tmp['id']));
-                        } else {
-                            $dealPet = new DealPet();
-                        }
-                        $dealPet->_id = new MongoId($tmp['id']);
-                        $dealPet->is_one_pay = 0;
-                        $dealPet->name = $tmp['name'];
-                        $dealPet->status = $tmp['status'];
-                        $dealPet->price = $tmp['price'];
-                        foreach ($tmp['pics'] as $key => $v) {
-                            if (!empty($v['url'])){
-                                $v['url'] = self::getVaildDataPost($v['url']);
-                            }
-                            $dealPet->pics[$key] = $v;
-                        }
-
-                        $dealPet->root_parent = new MongoId($tmp['root_praent']);
-                        $dealPet->kennel = new MongoId($tmp['kennel']);
-                        $dealPet->pet_type = new MongoId($tmp['pet_type']);
-                        $dealPet->birth_date = intval($tmp['birth_date']);
-                        $dealPet->gender = $tmp['gender'];
-                        foreach ($tmp['tags'] as $key => $v)
-                            $dealPet->tags[$key] = $v;
-                        $tmp['father_info']['avatar'] = self::getVaildDataPost($tmp['father_info']['avatar']);
-                        var_dump($tmp['father_info']['avatar']);exit;
-                        $dealPet->father_info = (Object)$tmp['father_info'];
-                        $tmp['mather_info']['avatar'] = self::getVaildDataPost($tmp['father_info']['avatar']);;
-                        $dealPet->mother_info = (Object)$tmp['mother_info'];
-                        $dealPet->desc = $tmp['desc'];
-                        foreach ($tmp['vaccine_info'] as $key => $v)
-                            $dealPet->vaccine_info[$key] = $v;
-                        $dealPet->add_time = time();
-                        //$dealPet->sort_weight = $tmp['sort_weight'];
-                        $dealPet->delivery_time = $tmp['delivery_time'];
-                        $dealPet->delivery_date = $tmp['delivery_date'];
-                        //这里改成数组
-                        $dealPet->deworming_info = (Object)$tmp['deworming_info'];
-                        $dealPet->hair_color = $tmp['hair_color'];
-                        $video = array();
-                        foreach($tmp['video'] as $key => $v){
-                            if ($key == 'url'){
-                                $v = self::getVaildDataPost($v);
-                            }
-                            $video[$key] = $v;
-                        }
-                        $dealPet->video = (Object)$video;
-                        $dealPet->carriage = (Object)$tmp['carriage'];
-                        //$dealPet->last_modify = $tmp['last_modify'];
-                        //$dealPet->view_count = $tmp['view_count'];
-                        //$dealPet->contact_count = $tmp['contact_count'];
-                        $dealPet->region = (Object)$tmp['region'];
-                        //$dealPet->last_deny_reason = $tmp['last_deny_reason'];
-                        $dealPet->from = 'wozhua';
-
-                        $dealPet->save();
-
-                        sleep(3);
-                    }
-                }
-                sleep(3);
-            }
-        }
-    }
-
-
-    public function getVaildDataPost($url){
-        $tmp[] =  str_replace(parse_url($url)['host'],'pics.maiyizhi.cn',$url);
-        $tmp[] = str_replace(parse_url($url)['host'],'avatars.maiyizhi.cn',$url);
-        $tmp[] = str_replace(parse_url($url)['host'],'test.maiyizhi.cn',$url);
-        $tmp[] = str_replace(parse_url($url)['host'],'icons.maiyizhi.cn',$url);
-        foreach ($tmp as $value){
-            if (empty(json_decode(CommonFn::simple_http($value),true)['error'])){
-                $url = $value;break;
-            }
-        }
-
-        return $url;
-    }
-
-}

+ 0 - 517
www/protected/models/DealPet.php

@@ -1,517 +0,0 @@
-<?php
-/**
- * 宠物模型
- */
-class DealPet extends MongoActiveRecord {
-
-    public $_id;
-
-    public $is_one_pay = 0;             //一元购产品 是否为一元购产品  默认0 不是  1 是
-    public $one_pay_counts = 0;         //如果是一元购产品  总份数
-
-    public $name;               // String   : 名称
-    public $status = 0;         // Int      : 状态
-    public $price;              // Int      : 价格
-    public $pics = [];          // Array    : 图片,参考Topic模型pics字段
-    public $root_parent;        // ObjectId : 父分类id
-    public $kennel;             // ObjectId : 所属商家
-    public $pet_type;           // ObjectId : 宠物类型
-    public $birth_date;         // Int      : 出生日期时间戳
-    public $gender;             // Int      : 性别
-    public $tags = [];          // Array    : 标签
-    public $father_info;        // Object   : 父亲信息
-    public $mother_info;        // Object   : 母亲信息
-    public $desc;               // String   : 说明文字
-    //public $desc_pics;          // Array    : 详情中的图片列表
-    public $vaccine_info;       // Array    : 疫苗信息
-    public $add_time;           // Int      : 添加时间
-    public $sort_weight = 0;    // int      : 排序权重
-    public $delivery_time;      // Int      : 交货时间,时间范围,取值范围0-7
-    public $delivery_date;      // 发货日期
-    public $deworming_info;     // Object   : 驱虫信息
-    public $hair_color;         // Stirng   : 毛色
-    public $video;              // Object   : 视频 {url:'', length:0, 'avatar':''}
-    public $carriage;           // Object   : 运费 {nonlocal:0, local:0}
-    public $last_modify;        // Int      : 最后一次修改时间
-    public $view_count;         // Int      : 查看次数
-    public $contact_count;      // Int      : 咨询数
-    public $region;             // Object   : 冗余字段,用于地区显示及筛选,同kennel
-    public $last_deny_reason;   // String   : 最后一次审核未通过理由
-    public $recommend=0;          // Int 是否推荐  1推荐  0不推荐
-    public $recommend_time;//推荐的截至时间  时间戳
-
-    public $reply_count = 0;//回复数
-    public $all_reply_count = 0;//所有的回复数
-    public $last_post_time;//最后回复时间
-
-    public $last_change_time;//最后一次修改时间
-
-    public $count = 1;//现存数量   针对小宠
-
-    public $from;//数据来源   wozhua xinchong chongwushichang
-
-    public static $status_option = [
-        -100 => ['name' => '信息不完善'],
-        -2   => ['name' => '审核未通过'],
-        -1   => ['name' => '已删除'],
-        0    => ['name' => '待审核'],
-        1    => ['name' => '待售'],
-        2    => ['name' => '待支付'],
-        3    => ['name' => '已预订'],
-    ];
-
-    public static $gender_option = [
-        0 => ['name' => '未知'],
-        1 => ['name' => 'DD'],
-        2 => ['name' => 'MM'],
-        3 => ['name' => '未知'],
-    ];
-
-    public static $tag_option = [
-        1 => ['name' => '30天保障'],
-        2 => ['name' => '①宠①拍'],
-        3 => ['name' => '先行赔付']
-    ];
-
-    public function __construct($scenario = 'insert') {
-        $this->setMongoDBComponent(Yii::app()->getComponent('deal'));
-        parent::__construct($scenario);
-    }
-
-    public function getCollectionName() {
-        return 'pets';
-    }
-
-    public static function model($className = __CLASS__) {
-        return parent::model($className);
-    }
-
-    public static function getNewPet(){
-        $cache = new ARedisCache();
-        $key = 'data_cache_new_pet_list_'.__CLASS__;
-        $data_cache = $cache->get($key);
-        $res = array();
-        if($data_cache){
-            $res = unserialize($data_cache);
-        }else{
-            $data = array();
-
-            $criteria = new EMongoCriteria();
-            $criteria->root_parent('==',new MongoId('54671c4b0eb9fb89048b45f5'));//狗狗
-            $criteria->status('==',1);
-            $criteria->limit(4);
-            $criteria->offset(rand(0,100));
-            $cursor = self::model()->findAll($criteria);
-            foreach ($cursor as $key => $value) {
-                $data[] = $value;
-            }
-            $dogs = self::model()->parseIndexList($cursor);
-
-            $criteria = new EMongoCriteria();
-            $criteria->root_parent('==',new MongoId('546805e40eb9fb32018b45fe'));//猫猫
-            $criteria->status('==',1);
-            $criteria->limit(5);
-            $criteria->offset(rand(0,100));
-            $cursor = self::model()->findAll($criteria);
-            foreach ($cursor as $key => $value) {
-                $data[] = $value;
-            }
-
-            // $criteria = new EMongoCriteria();
-            // $criteria->root_parent('notin',[new MongoId('546805e40eb9fb32018b45fe'),new MongoId('54671c4b0eb9fb89048b45f5')]);//其他
-            // $criteria->status('==',1);
-            // $criteria->limit(3);
-            // $criteria->offset(rand(0,10));
-            // $cursor = self::model()->findAll($criteria);
-            // foreach ($cursor as $key => $value) {
-            //     $data[] = $value;
-            // }
-            foreach ($data as $key => $obj) {
-                $temp['id'] = (string)$obj->_id;
-                $temp['name'] = $obj->name;
-                $temp['price'] = $obj->price;
-                $pics = $obj->pics;
-                $temp['pic'] = (object)array();
-                if($pics){
-                    $temp['pic'] = $pics[0];
-                }
-                $temp['pet_type_info'] = '';
-                $temp['pet_type_str'] = '';
-                $temp['pet_type_parent'] = '';
-                if (CommonFn::isMongoId($obj->pet_type)) {
-                    $pet_type = PetTypes::get($obj->pet_type);
-                    if ($pet_type) {
-                        $temp['pet_type_info'] = PetTypes::model()->parseRow($pet_type);
-                        $temp['pet_type_str'] = $pet_type->name;
-                        $temp['pet_type_parent'] = (string)$pet_type->parent;
-                    }
-                }
-                $res[] = $temp;
-            }
-            $cache->set($key,serialize($res),86400);
-        }
-        return $res;
-    }
-
-    public static function get($_id) {
-        if (CommonFn::isMongoId($_id)) {
-            $criteria = new EMongoCriteria();
-            $criteria->_id('==', $_id);
-            $model = self::model()->find($criteria);
-            return $model;
-        } else {
-            return false;
-        }
-    }
-
-    /**
-     * 根据出生日期时间戳计算时间
-     * @param Int $time : 出生日期时间戳
-     */
-    public static function makeAge($time) {
-        if (!$time) return '无';
-        $days = (strtotime(date('Ymd')) - $time) / 86400;
-        if ($days <= 31) {
-            return $days.'天';
-        } else if ($days == 365) {
-            return '一年';
-        } else if ($days > 335 && $days < 365) {
-            return '12月'.($days - 335).'天';
-        } else if ($days < 365) {
-            $age = (int)($days / 30).'个月';
-            if ($days % 30) {
-                $age .= ($days % 30).'天';
-            }
-            return $age;
-        } else if ($days > 365 && $days <= 730) {
-            $age = '1年';
-            if (intval(($days-365) / 30)) {
-                $age .= intval(($days-365) / 30).'个月';
-            }
-            if (($days - 365) % 30) {
-                $age .= (($days - 365) % 30).'天';
-            }
-            return $age;
-        } else {
-            return '无';
-        }
-    }
-
-    /**
-     * 宠物信息保存后的回调
-     */
-    public function afterSave() {
-        parent::afterSave();
-
-        // 类型
-        // 更新总类型列表
-        $type__cache = VariableRedis::get('pet_type_id_list');
-        if ($type__cache) {
-            $type_cache_data = unserialize($type__cache);
-            if (!in_array($this->pet_type, $type_cache_data['data'])) {
-                VariableRedis::remove('pet_type_id_list');
-            }
-        }
-        // 该类型下宠物列表还未过缓存,不需要清除
-
-        // 商家
-        // 更新商家在售宠物类型列表
-        $kennel_type_cache = VariableRedis::get('pet_types_' . (string)$this->kennel);
-        if ($kennel_type_cache) {
-            VariableRedis::remove('pet_types_' . (string)$this->kennel);
-        }
-        // 更新商家在售宠物列表
-        $kennel_pet_cache = VariableRedis::get('pet_list_' . (string)$this->kennel);
-        if ($kennel_pet_cache) {
-            VariableRedis::remove('pet_list_' . (string)$this->kennel);
-        }
-    }
-
-    /**
-     * 宠物列表接口
-     */
-    public function parseIndexList($rows = []) {
-        $data = [];
-        foreach ($rows as $key => $item) {
-            $temp['id'] = (string)$item['_id'];
-            // 名字
-            $temp['name'] = CommonFn::get_val_if_isset($item, 'name', '');
-            // 价格
-            $temp['price'] = CommonFn::get_val_if_isset($item, 'price', 0);
-            // 商家名
-            if (isset($item['kennel']) && CommonFn::isMongoId($item['kennel'])) {
-                $kennel = Kennel::get($item['kennel']);
-                $temp['kennel_name'] = $kennel->name;
-            } else {
-                $temp['kennel_name'] = '';
-            }
-            // 图片
-            if (isset($item['pics']) && count($item['pics'])) {
-                $temp['pic'] = $item['pics'][0];
-            } else {
-                $temp['pic'] = [
-                    'url' => Yii::app()->params['defaultGoodsAvatar'],
-                    'width' => 200,
-                    'height' => 200,
-                ];
-            }
-            $data[] = $temp;
-        }
-
-        return $data;
-    }
-
-    /**
-     * 更新宠物的查看数并返回
-     */
-    public function updateViewCount() {
-        // mongo
-        $view_count = $this->getAttr('view_count', 0);
-        // redis
-        $redis_key = 'view_count_' . (string)$this->_id;
-        $cache = VariableRedis::get($redis_key);
-        if (!$cache) {
-            $data = ['count' => 0, 'expire' => (time() + 7200)];
-            VariableRedis::set($redis_key, serialize($data));
-            $this->view_count = $view_count + 1;
-            $this->save();
-            return $view_count + 1;
-        } else {
-            $cache_data = unserialize($cache);
-            if (time() < $cache_data['expire']) {
-                $data = ['count' => $cache_data['count'] + 1, 'expire' => $cache_data['expire']];
-                VariableRedis::set($redis_key, serialize($data));
-                return $view_count + $cache_data['count'] + 1;
-            } else {
-                $data = ['count' => 0, 'expire' => (time() + 7200)];
-                VariableRedis::set($redis_key, serialize($data));
-                $this->view_count = $view_count + $cache_data['count'] + 1;
-                $this->save();
-                return $view_count + $cache_data['count'] + 1;
-            }
-        }
-    }
-
-    /**
-     * 返回查看数
-     */
-    public function getViewCount() {
-        $key = 'view_count_' . (string)$this->_id;
-        $view_count = $this->getAttr('view_count', 0);
-        $cache = VariableRedis::get($key);
-
-        if ($cache) {
-            $cache_data = unserialize($cache);
-            $cache_count = isset($cache_data['count'])? $cache_data['count'] : 0;
-            return $view_count + $cache_count;
-        } else {
-            return $view_count;
-        }
-    }
-
-    public function parseRow($row, $output = []) {
-        $newRow = [];
-
-        $newRow['id']             = (string)$row['_id'];
-        $newRow['name']           = CommonFn::get_val_if_isset($row, 'name', '');
-        $newRow['status']         = CommonFn::get_val_if_isset($row, 'status', 0);
-        $newRow['is_one_pay']         = CommonFn::get_val_if_isset($row, 'is_one_pay', 0);
-        $newRow['one_pay_counts']         = CommonFn::get_val_if_isset($row, 'one_pay_counts', 0);
-
-        //如果是一元购的话   在redis存放    还能被购买的份数
-        $newRow['one_pay_left_counts'] = 0;
-        if($newRow['is_one_pay']){
-            $key = 'one_pay_left_counts_'.(string)$row['_id'];
-            $result = VariableRedis::get($key);
-            if(empty($result)){
-                $newRow['one_pay_left_counts'] = $newRow['one_pay_counts'];
-            }else{
-                $newRow['one_pay_left_counts'] = $result;
-            }
-        }
-
-        $newRow['status_str']     = self::$status_option[$newRow['status']]['name'];
-        $newRow['price']          = CommonFn::get_val_if_isset($row, 'price', 0);
-        $newRow['pics']           = CommonFn::get_val_if_isset($row, 'pics', []);
-
-        //$newRow['kennel']         = (string)CommonFn::get_val_if_isset($row, 'kennel', '');
-        $newRow['root_parent']    = (string)CommonFn::get_val_if_isset($row, 'root_parent', '');
-        //$newRow['pet_type']       = (string)CommonFn::get_val_if_isset($row, 'pet_type', '');
-        $newRow['birth_date']     = CommonFn::get_val_if_isset($row, 'birth_date', 0);
-        $newRow['birth_date_str'] = $newRow['birth_date'] ? date('Y-m-d', $newRow['birth_date']) : '';
-        $newRow['age']            = self::makeAge($newRow['birth_date']);
-        $newRow['gender']         = CommonFn::get_val_if_isset($row, 'gender', 0);
-        $newRow['gender_str']     = self::$gender_option[$newRow['gender']]['name'];
-        $newRow['tags']           = CommonFn::get_val_if_isset($row, 'tags', []);
-        $newRow['father_info']    = CommonFn::get_val_if_isset($row, 'father_info', []);
-        $newRow['mother_info']    = CommonFn::get_val_if_isset($row, 'mother_info', []);
-        $newRow['desc']           = CommonFn::get_val_if_isset($row, 'desc', '');
-        $newRow['desc']  = str_replace("<br>","\n",$newRow['desc']);
-        //$newRow['desc_pics']      = CommonFn::get_val_if_isset($row, 'desc_pics', []);
-
-        $newRow['vaccine_info']   = CommonFn::get_val_if_isset($row, 'vaccine_info', []);
-
-        $newRow['count']       = CommonFn::get_val_if_isset($row, 'count', 1);
-
-        $newRow['add_time']       = CommonFn::get_val_if_isset($row, 'add_time', 0);
-        $newRow['add_time_str']   = $newRow['add_time']? date('Y-m-d H:i', $newRow['add_time']) : '';
-        $newRow['sort_weight']    = CommonFn::get_val_if_isset($row, 'sort_weight', 0);
-
-        $newRow['delivery_time']  = CommonFn::get_val_if_isset($row, 'delivery_time', 0);
-        $newRow['delivery_date']  = CommonFn::get_val_if_isset($row, 'delivery_date','');
-        $newRow['hair_color']     = CommonFn::get_val_if_isset($row, 'hair_color', '');
-        $newRow['last_modify']    = CommonFn::get_val_if_isset($row, 'last_modify', 0);
-        $newRow['region']         = CommonFn::get_val_if_isset($row, 'region', []);
-
-        $newRow['recommend_time'] = CommonFn::get_val_if_isset($row,'recommend_time',time());
-
-        $newRow['reply_count'] = CommonFn::get_val_if_isset($row,'reply_count',0);
-        $newRow['contact_count'] = CommonFn::get_val_if_isset($row,'contact_count',0);
-        $newRow['all_reply_count'] = CommonFn::get_val_if_isset($row,'all_reply_count',0);
-        $newRow['last_post_time'] = CommonFn::get_val_if_isset($row,'last_post_time',time());
-        if($newRow['reply_count'] == 0){
-            $newRow['last_post_time_str'] = '';
-        }else{
-            $newRow['last_post_time_str'] = CommonFn::sgmdate("Y年n月d日", $newRow['last_post_time'],1);
-        }
-        // 查看数统计
-        $newRow['view_count'] = CommonFn::get_val_if_isset($row, 'view_count', 0);
-
-        // 视频信息
-        $newRow['video'] = CommonFn::get_val_if_isset($row, 'video', []);
-
-        if (APPLICATION == 'api') {
-            // 运费信息
-            $newRow['carriage'] = CommonFn::get_val_if_isset($row, 'carriage', []);
-            $newRow['carriage']['nonlocal'] = CommonFn::get_val_if_isset($newRow['carriage'], 'nonlocal', 0);
-            $newRow['carriage']['local'] = CommonFn::get_val_if_isset($newRow['carriage'], 'local', 0);
-            $newRow['carriage']['self'] = CommonFn::get_val_if_isset($newRow['carriage'], 'self', 0);
-        }
-
-        $pet_type_str = '';
-        $pet_type_parent = '';
-        $kennel_str = '';
-
-        // 品种信息
-        $newRow['pet_type_info'] = [];
-
-        // root_parent不存在时添加本字段
-        if (CommonFn::isMongoId($row['pet_type'])) {
-            $pet_type = PetTypes::get(new MongoId($row['pet_type']));
-            if ($pet_type) {
-                $newRow['pet_type_info'] = PetTypes::model()->parseRow($pet_type);
-                $pet_type_str = $pet_type->name;
-                $pet_type_parent = (string)$pet_type->parent;
-                if(empty($newRow['root_parent'])){
-                    $self_update = self::get($row['_id']);
-                    $self_update->root_parent = $pet_type->parent;
-                    $self_update->update(array('root_parent'),true);
-                }
-            }
-        }
-
-        // 商家信息
-        $newRow['kennel_info'] = [];
-        if (CommonFn::isMongoId($row['kennel'])) {
-            $kennel = Kennel::get(new MongoId($row['kennel']));
-            $kennel_str = $kennel->name;
-            if ($kennel) {
-                $newRow['kennel_info'] = Kennel::model()->parseRow($kennel->attributes,array('id','name','avatar','phone','average','type','region','comment_count','address'));
-            }
-        }
-
-        $pics = CommonFn::get_val_if_isset($row, 'pics', []);
-        if(count($pics)){
-            $newRow['avatar'] = $pics[0];
-        }
-
-        /*if(!isset($newRow['avatar']) || !$newRow['avatar']){
-            $desc_pics = CommonFn::get_val_if_isset($row, 'desc_pics', []);
-            if(count($desc_pics)){
-                $newRow['avatar'] = $desc_pics[0];
-            }
-        }*/
-
-        // 疫苗信息
-        foreach ($newRow['vaccine_info'] as $key => &$item) {
-            if (isset($item['time'])) {
-                $item['time_str'] = date('Y-m-d', $item['time']);
-            } else {
-                $item['time_str'] = '';
-            }
-        }
-
-        // 驱虫信息
-        $deworming_info = CommonFn::get_val_if_isset($row, 'deworming_info', []);
-        //$deworming_info['vitro'] = isset($deworming_info['vitro'])&&$deworming_info['vitro']? date('Y-m-d', $deworming_info['vitro']) : '';
-        $deworming_info['vivo']  = isset($deworming_info['vivo'])&&$deworming_info['vivo']? date('Y-m-d', $deworming_info['vivo']) : '';
-        $deworming_info['brand'] = isset($deworming_info['brand'])? $deworming_info['brand'] : '';
-        $newRow['deworming_info'] = $deworming_info;
-
-        // 最后一次未通过理由
-        $newRow['last_deny_reason'] = CommonFn::get_val_if_isset($row, 'last_deny_reason', '');
-
-        $newRow['recommend'] = CommonFn::get_val_if_isset($row, 'recommend', 0);
-
-        // action-info
-        if (APPLICATION == 'admin') {
-            $newRow['action_user'] = CommonFn::get_val_if_isset($row, 'action_user', '');
-            $newRow['action_time'] = CommonFn::get_val_if_isset($row, 'action_time', '');
-            $newRow['action_log']  = CommonFn::get_val_if_isset($row, 'action_log', '');
-        }
-
-        if (APPLICATION == 'api') {
-            unset($newRow['debug']);
-            unset($newRow['last_deny_reason']);
-            unset($newRow['last_post_time_str']);
-            unset($newRow['recommend_time']);
-            unset($newRow['last_modify']);
-            unset($newRow['sort_weight']);
-            unset($newRow['add_time']);
-            unset($newRow['add_time_str']);
-        }
-
-        if (APPLICATION == 'admin') {
-            $newRow['pics_json']      = json_encode($newRow['pics']);
-            $newRow['kennel']         = (string)CommonFn::get_val_if_isset($row, 'kennel', '');
-            $newRow['pet_type']       = (string)CommonFn::get_val_if_isset($row, 'pet_type', '');
-            $newRow['video_json'] = $newRow['video']? json_encode($newRow['video']) : '{}';
-            // 运费信息
-            $newRow['carriage'] = CommonFn::get_val_if_isset($row, 'carriage', []);
-            $newRow['carriage_nonlocal'] = CommonFn::get_val_if_isset($newRow['carriage'], 'nonlocal', 0);
-            $newRow['carriage_local'] = CommonFn::get_val_if_isset($newRow['carriage'], 'local', 0);
-
-            $newRow['pet_type_str'] = $pet_type_str;
-            $newRow['pet_type_parent'] = $pet_type_parent;
-            $newRow['kennel_str'] = $kennel_str;
-            $parents_info = [];
-            // 父亲信息
-            $father_info = CommonFn::get_val_if_isset($row, 'father_info', []);
-            //$parents_info['father_name']            = CommonFn::get_val_if_isset($father_info, 'name', '');
-            $parents_info['father_avatar']          = CommonFn::get_val_if_isset($father_info, 'avatar', '');
-            $parents_info['father_breeds']          = CommonFn::get_val_if_isset($father_info, 'breeds', '');
-            //$parents_info['father_shoulder_height'] = CommonFn::get_val_if_isset($father_info, 'shoulder_height', 0);
-            //$parents_info['father_weight']          = CommonFn::get_val_if_isset($father_info, 'weight', 0);
-            //$parents_info['father_hair_color']      = CommonFn::get_val_if_isset($father_info, 'hair_color', '');
-            // 母亲信息
-            $mother_info = CommonFn::get_val_if_isset($row, 'mother_info', []);
-            // $parents_info['mother_name']            = CommonFn::get_val_if_isset($mother_info, 'name', '');
-            $parents_info['mother_avatar']          = CommonFn::get_val_if_isset($mother_info, 'avatar', '');
-            $parents_info['mother_breeds']          = CommonFn::get_val_if_isset($mother_info, 'breeds', '');
-            //$parents_info['mother_shoulder_height'] = CommonFn::get_val_if_isset($mother_info, 'shoulder_height', 0);
-            //$parents_info['mother_weight']          = CommonFn::get_val_if_isset($mother_info, 'weight', 0);
-            //$parents_info['mother_hair_color']      = CommonFn::get_val_if_isset($mother_info, 'hair_color', '');
-
-            $newRow['parents_info'] = $parents_info;
-
-            $deworming_info = CommonFn::get_val_if_isset($row, 'deworming_info', []);
-            // 驱虫信息
-            $newRow['deworming_vitro'] = isset($deworming_info['vitro'])&&$deworming_info['vitro']? date('Y-m-d', $deworming_info['vitro']) : '';
-            $newRow['deworming_vivo']  = isset($deworming_info['vivo'])&&$deworming_info['vivo']? date('Y-m-d', $deworming_info['vivo']) : '';
-            $newRow['deworming_brand'] = isset($deworming_info['brand'])? $deworming_info['brand'] : '';
-        }
-
-        return $this->output($newRow, $output);
-    }
-
-}

+ 0 - 404
www/protected/models/Kennel.php

@@ -1,404 +0,0 @@
-<?php
-/**
- * 商家模型
- */
-class Kennel extends MongoAr {
-
-    public $_id;
-    public $name;               // String : 商家名
-    public $avatar;             // String : 商家头像,url
-    //public $pics;               // Array  : 商家页面轮播图
-    public $status = 1;         // Int    : 状态
-    public $join_time;          // Int    : 加入时间
-    public $tags;               // Array  : 商家标签
-    public $weight = 0;         // Int    : 排序权重
-    public $desc;               // String : 详细说明文字
-    public $desc_pics;          // Array  : 详情图片
-    //public $brief_intro;        // String : 简介,用于其他页面显示
-    public $region;             // Object : 地区,{province: '', city: '', area: ''}
-    public $address;            // String : 地址,参考ROrder模型address字段
-    public $phone;              // String : 电话
-    public $order_count = 0;        // Int    : 总订单数(包括取消、赔付的订单)
-    public $finished_order = 0;     // Int    : 完成订单数
-
-    public $average;            // Float  平均分
-    public $favorable_rate;     // Float  : 好评率
-    public $comment_count;      // Int    : 评价总数
-    public $favorable_count;    // Int    : 好评数
-
-    public $video;              // Object : 视频 {url:'',width:0,height:'',avatar:'',length:0}
-    //public $wechat;             // String : 微信号
-    //public $weixin_userid;      // String : 微信企业号userid
-
-    public $type=2;               // Int    : 商家类型,1认证商家,2普通商家
-
-    // 审核相关
-    public $business_license;   // 营业执照,{url: '', width: '', height: ''}
-    public $certificate;        // 协会证书,{url: '', width: '', height: ''}
-
-    // 账号相关
-    public $apply_time;         // 申请时间
-    public $account_type;       // 收款账号类型,参考ping++,alipay支付宝,wx微信支付,etc.
-    public $account_name;       // 收款账号姓名,参考ping++,alipay支付宝,wx微信支付,etc.
-    public $account;            // 账号
-
-    public $have_change;        // 最近信息变更状态
-
-    public $last_deny_reason;   // 最近一次审核未通过理由
-
-    public $last_change_time;//最后一次修改时间
-
-    public $from;//数据来源   wozhua xinchong chongwushichang
-
-    public static $status_option = [
-        0  => ['name' => '待审核', 'wx' => 0],
-        1  => ['name' => '正常',   'wx' => 1],
-        -1 => ['name' => '已删除', 'wx' => 0],
-        -2 => ['name' => '审核未通过', 'wx' => 0],
-    ];
-
-    /**
-     * 商家申请状态设置
-     */
-    public static $apply_status_option = [
-        0    => ['name' => '未申请'],
-        1    => ['name' => '正在申请'],
-        2    => ['name' => '申请通过'],
-        -1   => ['name' => '申请失败'],
-        // status <= -2没有权限
-        -2   => ['name' => '商家管理员资格正在审核'],
-        -3   => ['name' => '管理员被取消授权'],
-        -100 => ['name' => '商家已被删除'],
-    ];
-
-    /**
-     * 商家标签,根据需要拓展或修改
-     */
-    public static $tag_option = [
-        1 => ['name' => '30天保障'],
-        2 => ['name' => '100%环境实拍'],
-        3 => ['name' => '①宠①拍']
-    ];
-
-    public static $type_option = [
-        0 => ['name' => '未知'],
-        1 => ['name' => '认证商家'],
-        2 => ['name' => '普通卖家'],
-    ];
-
-    public function __construct($scenario = 'insert') {
-        $this->setMongoDBComponent(Yii::app()->getComponent('deal'));
-        parent::__construct($scenario);
-    }
-
-    public function getCollectionName() {
-        return 'kennels';
-    }
-
-    public static function model($className = __CLASS__) {
-        return parent::model($className);
-    }
-
-    public static function get($_id) {
-        if (CommonFn::isMongoId($_id)) {
-            $criteria = new EMongoCriteria();
-            $criteria->_id('==', $_id);
-            $model = self::model()->find($criteria);
-            return $model;
-        } else {
-            return false;
-        }
-    }
-
-    /**
-     * 根据微信Userid获取商家
-     */
-    public static function getByUserid($weixin_userid) {
-        $criteria = new EMongoCriteria();
-        $criteria->weixin_userid('==', $weixin_userid);
-        $model = self::model()->find($criteria);
-        return $model;
-    }
-
-    /**
-     * 修改微信端状态
-     */
-    /*public function updateWeixinStatus($status) {
-        $weixin_userid = $this->weixin_userid;
-        $weixin_enable = self::$status_option[$status]['wx'];
-        $user_data = [
-            'userid' => $weixin_userid,
-            'enable' => $weixin_enable,
-        ];
-        $option = WechatConfig::getIns()->getLinkOption();
-        $secret = WechatConfig::getIns()->getSecret('admin_dev');
-        $wechat = new QyWechat($option);
-        $wechat->checkAuth($option['appid'], $secret);
-        return $wechat->updateUser($user_data);
-    }*/
-
-
-    /**
-     * MongoDB-Distinct获取商家内宠物类型列表
-     * 过Redis,过期时间7200秒
-     *
-     * @return Array $list : 宠物类型列表,包含宠物类型信息
-     * $list = [
-     *     [
-     *         'id'   => '...',
-     *         'name' => '...',
-     *         etc.
-     *    ]
-     * ];
-     */
-    public function getPetTypes() {
-        $key = 'pet_types_'.(string)$this->_id;
-        $cache = VariableRedis::get($key);
-        if (!$cache) {
-            $cache_data = [];
-        } else {
-            $cache_data = unserialize($cache);
-        }
-
-        if (!$cache_data || $cache_data['expire'] < time()) {
-            $list = [];
-        } else {
-            $list = $cache_data['data'];
-        }
-
-        if (!$list) {
-            $distinct_query = ['status' => 1, 'kennel' => $this->_id];
-            $mongo = new MongoClient(DB_CONNETC);
-            $db = $mongo->deal;
-            $collection = $db->selectCollection('pets');
-            $result = $collection->distinct('pet_type', $distinct_query);
-
-            //$models = PetTypes::find()->where(['_id' => $result])->all();
-
-            $criteria = new EMongoCriteria;
-            $criteria->_id('in',$result);
-            $cursor = PetTypes::model()->findAll($criteria);
-
-            $list = [];
-            foreach ($cursor as $key => $item) {
-                $list[] = PetTypes::model()->parseRow($item->attributes);
-            }
-
-            $cache_data = ['data' => $list, 'expire' => time() + 7200];
-            VariableRedis::set('pet_types_' . (string)$this->_id, serialize($cache_data));
-        }
-
-        return $list;
-    }
-
-    /**
-     * 获取商家宠物列表
-     * 过Redis,过期时间7200秒
-     *
-     * @param  Int   $limit : 显示数目
-     *
-     * @return Array $data  : 返回结果,包含宠物列表及商家宠物总数
-     * $data = [
-     *     'list' => [
-     *         ['id' => '...', 'name' => '...', etc.],
-     *     ],
-     *     'count' => 100,
-     * ];
-     */
-    public function getPetList($limit = 3) {
-        $key = 'pet_list_' . (string)$this->_id;
-
-        $cache = VariableRedis::get($key);
-        if (!$cache) {
-            $cache_data = [];
-        } else {
-            $cache_data = unserialize($cache);
-        }
-
-        if (!$cache_data || $cache_data['expire'] < time()) {
-            $criteria = new EMongoCriteria();
-            $criteria->status('==',1);
-            $criteria->kennel('==',$this->_id);
-            $criteria->sort('sort_weight',EMongoCriteria::SORT_DESC);
-            $criteria->sort('view',EMongoCriteria::SORT_DESC);
-            $criteria->limit($limit);
-            $models = DealPet::model()->findAll($criteria);
-            $count = $models->count();
-
-            $list = [];
-            foreach ($models as $item) {
-                $list[] = DealPet::model()->parseRow($item->attributes,array('id', 'name', 'region', 'price','avatar'));
-            }
-
-            $data = ['list' => $list, 'count' => $count];
-            $cache_data = ['data' => $data, 'expire' => time() + 7200];
-            VariableRedis::set($key, serialize($cache_data), 0);
-        } else {
-            $data = $cache_data['data'];
-        }
-
-        return $data;
-    }
-
-
-
-    /**
-     * 获取该商家的一条评价(根据权重排序)
-     * 优先从缓存中获取数据
-     */
-    public function getCommentOne() {
-        $key = 'kennel_comment_one_'.(string)$this->_id;
-        $cache = VariableRedis::get($key);
-        if (ENVIRONMENT != 'product') {
-            $cache = '';
-        }
-        if (!$cache) {
-            $cache_data = [];
-        } else {
-            $cache_data = unserialize($cache);
-        }
-
-        if (!$cache_data) {
-            $criteria = new EMongoCriteria();
-            $criteria->kennel('==',$this->_id);
-            $criteria->status('==',1);
-            $criteria->sort('weight',EMongoCriteria::SORT_DESC);
-            $cursor = DealComment::model()->findAll($criteria);
-            if (!$cursor->count()) {
-                return (object)[];
-            }
-
-            foreach(CommonFn::getRowsFromCursor($cursor) as $value){
-                $comment = $value;break;
-            }
-            $data = DealComment::model()->parseRow($cursor->attributes,array('user_info', 'pet_info', 'time_str'));
-            VariableRedis::set($key, serialize($data), 7200);
-            return $data;
-        } else {
-            return $cache_data;
-        }
-    }
-
-    public function parseRow($row, $output = []) {
-        $newRow = [];
-
-        $newRow['id']                = (string)$row['_id'];
-        $newRow['name']              = CommonFn::get_val_if_isset($row, 'name', '');
-        $newRow['avatar']            = CommonFn::get_val_if_isset($row, 'avatar', '');
-        $newRow['status']            = CommonFn::get_val_if_isset($row, 'status', 0);
-        $newRow['status_str']        = self::$status_option[$newRow['status']]['name'];
-        $newRow['join_time']         = CommonFn::get_val_if_isset($row, 'join_time', 0);
-        $newRow['join_time_str']     = $newRow['join_time'] != 0 ? date('Y-m-d', $newRow['join_time']) : '';
-        $newRow['tags']              = CommonFn::get_val_if_isset($row, 'tags', []);
-        $newRow['weight']            = CommonFn::get_val_if_isset($row, 'weight', 0);
-        $newRow['desc']              = CommonFn::get_val_if_isset($row, 'desc', '');
-        $newRow['desc']  = str_replace("<br>","\n",$newRow['desc']);
-        $newRow['desc_pics']         = CommonFn::get_val_if_isset($row, 'desc_pics', []);
-
-        //$newRow['brief_intro']       = CommonFn::get_val_if_isset($row, 'brief_intro', '');
-        $newRow['region']            = CommonFn::get_val_if_isset($row, 'region', []);
-        $newRow['address']           = CommonFn::get_val_if_isset($row, 'address', '');
-        $newRow['phone']             = CommonFn::get_val_if_isset($row, 'phone', '');
-        $newRow['order_count']       = CommonFn::get_val_if_isset($row, 'order_count', 0);
-        $newRow['finished_order']    = CommonFn::get_val_if_isset($row, 'finished_order', 0);
-        $newRow['favorable_rate']    = CommonFn::get_val_if_isset($row, 'favorable_rate', 0.0);
-        $newRow['comment_count']     = CommonFn::get_val_if_isset($row, 'comment_count', 0);
-        $newRow['favorable_count']   = CommonFn::get_val_if_isset($row, 'favorable_count', 0);
-        //$newRow['description_match'] = CommonFn::get_val_if_isset($row, 'description_match', 0.0);
-        //$newRow['service_attitude']  = CommonFn::get_val_if_isset($row, 'service_attitude', 0.0);
-        //$newRow['logistics_service'] = CommonFn::get_val_if_isset($row, 'logistics_service', 0.0);
-        $newRow['video']             = CommonFn::get_val_if_isset($row, 'video', []);
-        //$newRow['wechat']            = CommonFn::get_val_if_isset($row, 'wechat', '');
-        //$newRow['weixin_userid']     = CommonFn::get_val_if_isset($row, 'weixin_userid', '');
-        $newRow['type']              = CommonFn::get_val_if_isset($row, 'type', 2);
-
-        // 审核相关
-        $newRow['business_license']  = CommonFn::get_val_if_isset($row, 'business_license', []);
-        $newRow['certificate']       = CommonFn::get_val_if_isset($row, 'certificate', []);
-
-        // 账号
-        $newRow['account_type']      = CommonFn::get_val_if_isset($row, 'account_type', '');
-        $newRow['account_name']      = CommonFn::get_val_if_isset($row, 'account_name', '');
-        $newRow['account']           = CommonFn::get_val_if_isset($row, 'account', '');
-
-        $newRow['last_deny_reason']           = CommonFn::get_val_if_isset($row, 'last_deny_reason', '');
-        $newRow['have_change']           = CommonFn::get_val_if_isset($row, 'have_change', 0);
-        $newRow['pet_types']           = $this->getPetTypes();
-
-
-        /*$cache = new ARedisCache();
-        $key = 'average_'.$newRow['id'];
-        $average_cache = $cache->get($key);
-        $_average=0;
-        if($average_cache){
-            $_average = $average_cache;
-        }else{
-            $criteria = new EMongoCriteria;
-            $criteria->status('==',1);
-            $criteria->kennel('==',$row['_id']);
-            $cursor = DealComment::model()->findAll($criteria);
-            $comment_count = $cursor->count();
-            $total_score = 0;
-            foreach ($cursor as $key => $item) {
-                $total_score += $item->score;
-            }
-            if($comment_count){
-                $_average = $total_score/$comment_count;
-            }else{
-                $_average = 5;
-            }
-
-            $cache->set($key,$_average,86400);
-        }
-        $newRow['average'] =  $_average;*/
-
-        if($newRow['favorable_rate']>0){
-            $newRow['average'] = round($newRow['favorable_rate'] * 5);
-        }else{
-            $newRow['average'] = 5;
-        }
-
-
-        $cache = new ARedisCache();
-        $key = 'pets_count_'.$newRow['id'];
-        $count_cache = $cache->get($key);
-        $_count=0;
-        if($count_cache){
-            $_count = $count_cache;
-        }else{
-            $criteria = new EMongoCriteria;
-            $criteria->status('in',array(1, 2,));
-            $criteria->kennel('==',$row['_id']);
-            $cursor = DealPet::model()->findAll($criteria);
-            $_count = $cursor->count();
-
-            $cache->set($key,$_count,86400);
-        }
-        $newRow['pets_count'] =  $_count;
-
-        $manager_user_id = '';
-        if(APPLICATION=='admin'){
-            $newRow['region_json']       = (string)json_encode($newRow['region']);
-            $newRow['video_json']        = $newRow['video']? json_encode($newRow['video']) : '{}';
-            //$newRow['wechat']            = CommonFn::get_val_if_isset($row, 'wechat', '');
-            //$newRow['weixin_userid']     = CommonFn::get_val_if_isset($row, 'weixin_userid', '');
-
-            $manager = KennelManager::getByKennel($row['_id']);
-            if ($manager) {
-                $newRow['id_card'] = $manager->id_card? $manager->id_card : ['url' => '', 'width' => 0, 'height' => 0];
-                $newRow['id_card_inhand'] = $manager->id_card_inhand? $manager->id_card_inhand : ['url' => '', 'width' => 0, 'height' => 0];
-                $newRow['user_id'] = (string)$manager->user;
-                $manager_user_id = $newRow['user_id'];
-            } else {
-                $newRow['id_card'] = ['url' => '', 'width' => 0, 'height' => 0];
-                $newRow['id_card_inhand'] = ['url' => '', 'width' => 0, 'height' => 0];
-                $newRow['user_id'] = '';
-            }
-        }
-
-        $newRow['manager_user_id'] =  $manager_user_id;
-
-        return $this->output($newRow, $output);
-    }
-
-}