DengTao 8 jaren geleden
bovenliggende
commit
b4fe52943e

+ 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(){
-        $count = 0;
-        $kennelPage = intval(Yii::app()->redis->get('kennelPage'));
-        var_dump('开始时间'.date('y-m-d h:i:s'));
-        if (empty($kennelPage)){
-            $kennelPage = 1;
-        }
-        while($kennelPage) {
-            if ($count >= 1000) {
-                var_dump('开始时间'.date('y-m-d h:i:s'));
-                Yii::app()->redis->set('kennelPage', intval(--$kennelPage));
-                exit;
-            }
-
-            //获取商家id
-            var_dump('kennelPage='.$kennelPage);
-            $res = CommonFn::simple_http("http://deal.wozhua.mobi/api/kennel/list?user_id=546b16f50eb9fb494f8b4664&page=".$kennelPage++."&rows=10");
-            $res = json_decode($res,true);
-            //var_dump($res);
-            if ($res['success']) {
-                $list = $res['data']['list'];
-
-                foreach ($list as $key => $value) {
-                    $kennel = $value['id'];
-                    //获取对应商家的petid
-                    $page = 1;
-                    $flag = 1;
-                    var_dump($value['id']);
-                    while ($flag) {
-                        $resources = CommonFn::simple_http("http://deal.wozhua.mobi/api/pet/list?user_id=546b16f50eb9fb494f8b4664&kennel=" . $kennel . "&page=" . $page++ . "&rows=20");
-                        $resources = json_decode($resources, true);
-                        if (empty($resources['data']['list'])){
-                            $flag = 0;
-                        } else {
-                            $petsList = $resources['data']['list'];
-                            foreach ($petsList as $k => $pet) {
-                                $count++;
-                                var_dump('count='.$count);
-                                //获取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 $v) {
-                                        $dealPet->pics[] = $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'];
-                                    $dealPet->tags = $tmp['tags'];
-                                    $dealPet->father_info = $tmp['father_info'];
-                                    $dealPet->mother_info = $tmp['mother_info'];
-                                    $dealPet->desc = $tmp['desc'];
-                                    $dealPet->vaccine_info = $tmp['vaccine_info'];
-                                    $dealPet->add_time = $tmp['add_time'];
-                                    $dealPet->sort_weight = $tmp['sort_weight'];
-                                    $dealPet->delivery_time = $tmp['delivery_time'];
-                                    $dealPet->delivery_date = $tmp['delivery_date'];
-                                    $dealPet->deworming_info = $tmp['deworming_info'];
-                                    $dealPet->hair_color = $tmp['hair_color'];
-                                    $dealPet->video = $tmp['video'];
-                                    $dealPet->carriage = $tmp['carriage'];
-                                    $dealPet->last_modify = $tmp['last_modify'];
-                                    $dealPet->view_count = $tmp['view_count'];
-                                    $dealPet->contact_count = $tmp['contact_count'];
-                                    $dealPet->region = $tmp['region'];
-                                    $dealPet->last_deny_reason = $tmp['last_deny_reason'];
-
-
-                                    var_dump($dealPet->save());
-
-                                    sleep(3);
-                                }
-                            }
-                            sleep(3);
-
-
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-
-}

+ 0 - 138
www/protected/commands/getPetUserWorkCommand.php

@@ -1,138 +0,0 @@
-<?php
-/**
- * Created by PhpStorm.
- * User: PHP
- * Date: 2016/11/9
- * Time: 15:31
- */
-class GetPetUserWorkCommand 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);
-       // $this->getPetUser();
-
-
-    }
-    public function getKennel(){
-        $count = 0;
-        $page = intval(Yii::app()->redis->get('page'));
-        if (empty($page)) $page =1;
-        var_dump($page);
-        while($page) {
-            if ($count >= 10) {
-                Yii::app()->redis->set('page', intval(--$page));
-                exit;
-            }
-            var_dump($page);
-            $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 = 0;
-                        $kennel->weight = 0;
-                        $kennel->name = $value['name'];
-                        $kennel->avatar = $value['avatar'];
-                        $kennel->region = $value['region'];
-                        $kennel->video = $value['video'];
-                        if ($value['is_certified']) {
-                            $kennel->type = 1;
-                        } else {
-                            $kennel->type = 2;
-                        }
-                        $kennel->tags = $tmp['tags'];
-                        $kennel->desc = $tmp['desc'];
-                        foreach ($tmp['desc_pics'] as $v) {
-                            $kennel->desc_pics[] = $v;
-                        }
-                        $kennel->address = $tmp['address'];
-                        $kennel->phone = $tmp['phone'];
-                        $kennel->favorable_rate = $tmp['favorable_rate'];
-                        $kennel->comment_count = $tmp['comment_count'];
-                        $kennel->favorable_count = $tmp['favorable_count'];
-                        $kennel->average = $tmp['favorable_star'];
-                        $success = $kennel->save();
-                        if ($success) {
-                            echo "success";
-                        }
-                        sleep(3);
-                    }
-                }
-                sleep(3);
-            }
-        }
-    }
-    public function getPetUser(){
-        $m = new MongoClient(DB_CONNETC);
-        $collection = $m->selectCollection('fuwu','material');
-        var_dump($collection->drop());
-        $c = $m->selectCollection('fuwu','stock');
-        var_dump($c->drop());
-      /*  $m = new MongoClient(DB_CONNETC);
-        $count = 0;
-        $collection = $m->selectCollection('cute','pet_user');
-        $cursor = $collection->find();
-        $cursor->sort(array('id' => -1));
-        $index = $cursor->getNext()['id'];
-        if (empty($index)){
-            $index = 1;
-        }
-
-        while($index) {
-            if($count>= 50){
-                exit;
-            }
-            $count++;
-            $res = CommonFn::simple_http('http://pet.appcute.im/api/user/get?id=' . $index++);
-            $d = json_decode($res, true);
-            if ($d['error'] == 10000) {
-                $data = $d['data'];
-                if (!$collection->findOne(array('id' => $data['id']))) {
-                    foreach($data['photos'] as $key => $value) {
-                        $data['photos'][$key] = $value;
-                    }
-                    foreach ($data['contact'] as $key => $value) {
-                        $data['contact'][$key] = $value;
-                    }
-                    foreach ($data['services'] as $key => $value) {
-                        $data['services'][$key] = $value;
-                    }
-                    foreach ($data['area'] as $key => $value) {
-                        if (is_array($data['area'][$key])){
-                            foreach($data['area'][$key] as $k => $v) {
-                                $data['area'][$key][$k] = $v;
-                            }
-                        } else {
-                            $data['area'][$key] = $value;
-                        }
-
-                    }
-                    $collection->insert($data);
-                }
-            }
-            sleep(3);
-        }*/
-    }
-
-
-    public function writeLastIndex($index){
-        echo $index;
-        $file = fopen(dirname(__FILE__).'/../data/petUser.json', "w") or die("Unable to open file!");
-        $data['last_index'] = $index;
-        fwrite($file, json_encode($data));
-        fclose($file);
-    }
-}

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

@@ -1,515 +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 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('data'));
-        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);
-    }
-
-}

+ 16 - 13
www/protected/modules/o2o/controllers/AdvisoryController.php

@@ -8,7 +8,7 @@
 class AdvisoryController extends O2oBaseController {
 
     public function actionIndex(){
-        $status_option = CommonFn::getComboboxData(TechInfo::$status_option, 1, true, 100);
+        $status_option = CommonFn::getComboboxData(Advisory::$status_option, 1, true, 100);
         $this->render('index', [
             'status_option' => $status_option
            ]);
@@ -29,27 +29,30 @@ class AdvisoryController extends O2oBaseController {
         if ($status != 100) {
             $criteria->status('==', $status);
         }
-       /* // 搜索
-        if ($search) {
-            // 搜索ID
-            if (!preg_match('/\D/', $search)) {
-                $criteria->_id('==', intval($search));
-                // 搜索姓名或微信ID
-            } else {
-                $criteria->name('or', new MongoRegex('/'.$search.'/'));
-                $criteria->wechat_id('or', new MongoRegex('/'.$search.'/'));
-            }
-        }*/
 
         $cursor = Advisory::model()->findAll($criteria);
         $rows = CommonFn::getRowsFromCursor($cursor);
         $parsedRows = Advisory::model()->parse($rows);
         $total = $cursor->count();
-        var_dump($parsedRows);
+
         echo CommonFn::composeDatagridData($parsedRows, $total);
 
     }
     public function actionEdit(){
+        $status = intval(Yii::app()->request->getParam('status', 100));
+        $id     = Yii::app()->request->getParam('id');
+        if (!$id) {
+            CommonFn::requestAjax(false, '');
+        }
+        if ($status == 100) {
+            CommonFn::requestAjax(false, '请选择状态');
+        }
+        $advisory = Advisory::model()->get(new MongoId($id));
+        $advisory->status = $status;
+        $success = $advisory->save();
+        if ($success) {
+            CommonFn::requestAjax(true, '修改成功');
+        }
 
     }
 

+ 3 - 3
www/protected/modules/o2o/models/Advisory.php

@@ -19,8 +19,8 @@ class Advisory extends MongoAr{
     public $time;//创建时间
 
     public static $status_option = array(
-        0 => '待处理',
-        1 => '已处理'
+        1 => '待处理',
+        2 => '已处理'
     );
     public function __construct($scenario='insert'){
         $this->setMongoDBComponent(Yii::app()->getComponent('mongodb_o2o'));
@@ -55,7 +55,7 @@ class Advisory extends MongoAr{
 
         $newRow['user_name'] = CommonFn::get_val_if_isset($row,'user_name','');
         $newRow['mobile'] = CommonFn::get_val_if_isset($row,'mobile','');
-        $newRow['area'] = intval(CommonFn::get_val_if_isset($row,'area',''));
+        $newRow['area'] = CommonFn::get_val_if_isset($row,'area','');
         $newRow['homeType'] = CommonFn::get_val_if_isset($row,'homeType','');
         $newRow['num'] = CommonFn::get_val_if_isset($row,'num','');
         $newRow['sex'] = CommonFn::get_val_if_isset($row,'sex','');

+ 405 - 0
www/protected/modules/o2o/views/advisory/index.php

@@ -0,0 +1,405 @@
+<style>
+    .f_label {width: 90px;}
+    .accordion-body {padding: 0;}
+    #view_select_position {
+        display:inline-block;
+        padding:1px 4px 1px 4px;
+        border:1px solid #999999;
+        text-decoration:none;
+        color:#333333;
+    }
+</style>
+
+<div id="main">
+    <div region="west" border="false" id="west_panel">
+        <table id="dg_content"></table>
+        <div id="tb_content">
+
+            <div class="tb_line">
+                <span class="tb_label">状态: </span>
+                <input id="filter_status" />
+
+            </div>
+
+
+        </div>
+    </div>
+    <div id="acc_container" class="accordion" region="center">
+        <div region="center" title="充值卡" data-options="iconCls:'icon-save',selected:true">
+            <div class="easyui-layout detail_layout">
+                <div data-options="region:'center'" class="detail_center">
+                    <div class="detail_main">
+                        <form id="content_form" method="post">
+                            <ul>
+                                <li class="f_item">
+                                    <div class="box">
+                                        <div class="f_label">
+                                            <span>ID: </span>
+                                        </div>
+                                        <div class="box_flex f_content">
+                                            <input type="hidden" name="id" id="id"/>
+                                            <span id="id_str"></span>
+                                        </div>
+                                    </div>
+                                </li>
+                                <li class="f_item">
+                                    <div class="box">
+                                        <div class="f_label">
+                                            <span>联系方式: </span>
+                                        </div>
+                                        <div class="box_flex f_content">
+<!--                                            <input type="text" name="mobile" id="edit_denomination" value='' />-->
+                                            <span id="mobile"></span>
+                                        </div>
+                                    </div>
+                                </li>
+
+                                <li class="f_item">
+                                    <div class="box">
+                                        <div class="f_label">
+                                            <span>区域: </span>
+                                        </div>
+                                        <div class="box_flex f_content">
+                                            <span id="area"></span>
+<!--                                            <textarea name="area" id="area" style="width: 250px;min-height: 100px"></textarea>-->
+                                        </div>
+                                    </div>
+                                </li>
+
+
+                                <li class="f_item">
+                                    <div class="box">
+                                        <div class="f_label">
+                                            <span>房型: </span>
+                                        </div>
+                                        <div class="box_flex f_content">
+                                            <span id="homeType"></span>
+<!--                                            <input id="edit_order" name="homeType" />-->
+                                        </div>
+                                    </div>
+                                </li>
+                                <li class="f_item">
+                                    <div class="box">
+                                        <div class="f_label">
+                                            <span>房源数: </span>
+                                        </div>
+                                        <div class="box_flex f_content">
+                                            <span id="num"> </span>
+                                            <!--<input id="edit_order" name="num" />-->
+                                        </div>
+                                    </div>
+                                </li>
+                                <li class="f_item">
+                                    <div class="box">
+                                        <div class="f_label">
+                                            <span>服务: </span>
+                                        </div>
+                                        <div class="box_flex f_content">
+                                            <span id="tech_content"> </span><!--<id="edit_order" name="tech_content" />-->
+                                        </div>
+                                    </div>
+                                </li>
+
+                                <li class="f_item">
+                                    <div class="box">
+                                        <div class="f_label">
+                                            <span>状态:</span>
+                                        </div>
+                                        <div class="box_flex f_content">
+                                            <input id="setStatus" name="status" />
+                                        </div>
+                                    </div>
+                                </li>
+                                <li class="f_item">
+                                    <div class="box">
+                                        <div class="f_label">
+                                        </div>
+                                        <div class="box_flex f_content">
+                                            <span id="action_info" style="color:green;"></span>
+                                        </div>
+                                    </div>
+                                </li>
+
+                            </ul>
+                        </form>
+                    </div>
+                    <div data-options="region:'south'" class="detail_south">
+                        <div class="detail_toolbar">
+                            <a href="#" class="easyui-linkbutton set_button" iconCls="icon-save" onclick="save_content();return false;">保存</a>
+                        </div>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+<div style="display:none;">
+    <div id="refund_tip_dialog" style="padding: 30px 0;">
+        <div style="text-align:center;"><span id="refund_tip"></span></div>
+    </div>
+</div>
+<script language="javascript" type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/coolautosuggest/jquery.coolautosuggest.js"></script>
+<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/js/coolautosuggest/jquery.coolautosuggest.css" />
+<script type="text/javascript">
+    var jq_dg_content = $('#dg_content');
+    var jq_content_form = $('#content_form');
+    var jq_filter_status = $('#filter_status');
+    var jq_setStatus_add = $('#setStatus_add');
+    var module_router = site_root + '/index.php?r=o2o/Advisory';
+    var status_data = <?php echo json_encode($status_option); ?>;
+    var jq_setStatus = $('#setStatus');
+    var w_width = $(window).width();
+    var w_height = $(window).height();
+    var jq_ss = $('#ss');
+    var jq_action_info = $('#action_info');
+
+    var jq_add_dialog = $('#add_dialog');
+    var jq_add_form = $('#add_form');
+
+
+    var jq_set_precedence = $('#set_precedence');
+
+
+    var jq_acc = $('#acc_container');
+
+    $(function(){
+
+        jq_acc.accordion({
+            height: w_height - 18,
+            onSelect: function(title) {
+
+            }
+        });
+
+
+
+        var buttons = $.extend([], $.fn.datebox.defaults.buttons);
+        buttons[0].text = '确定';
+
+        jq_setStatus.combobox({
+            editable: false,
+            data: status_data
+        });
+
+
+        jq_setStatus_add.combobox({
+            editable: false,
+            data: (function () {
+                var status_data_temp = new Array();
+                $.extend(status_data_temp, status_data);
+                status_data_temp.shift();
+
+                return status_data_temp;
+            })()
+        });
+
+
+
+
+
+
+
+        var p_width = parseInt(w_width / 2);
+        if (p_width < 520){
+            p_width = 520;
+        }
+        var d_width = p_width - 10;
+        $('#west_panel').css({width : p_width});
+        $('#main').css({width: w_width - 25, height: w_height - 18}).layout();
+
+        jq_ss.searchbox({
+            width: 130,
+            searcher:function(value){
+                search_content();
+            },
+            prompt: '请输入关键字'
+        });
+
+        jq_setStatus.combobox({
+            editable: false,
+            data: status_data
+        });
+
+
+        jq_dg_content.datagrid({
+            url: module_router + '/list',
+            title: '咨询列表',
+            width: d_width,
+            height: w_height - 18,
+            fitColumns: true,
+            autoRowHeight: true,
+            striped: true,
+            toolbar: '#tb_content',
+            singleSelect: true,
+            selectOnCheck: false,
+            checkOnSelect: false,
+            rowStyler: function(index,row){
+                if (row.status==1){
+                    //return 'color:red;';
+                }else if(row.status==-3){
+                    return 'color:green;';
+                }
+            },
+            pagination: true,
+            pageList: [20, 30, 50],
+            pageSize: 20,
+            nowrap: false,
+            idField: 'id',
+            sortName: 'order_time',
+            sortOrder: 'desc',
+            queryParams: get_param_obj(),
+            frozenColumns:[[
+                {field:'ck',checkbox:true}
+            ]],
+            columns:[[
+                {field:'user_name', title:'姓名', width:25,sortable:false},
+                {field:'mobile', title:'联系方式', width:50, sortable: true},
+                {field:'status', title:'状态', width:50, sortable: true,
+                    formatter: function(value, row){
+                        return get_filed_text(value, status_data);
+                    }
+                },
+                {field:'time', title:'咨询时间', width:70,sortable:true,formatter: function(value, row){
+                    var now=new Date(value*1000);
+
+                    var   month=now.getMonth()+1;
+                    var   date=now.getDate();
+                    var   hour = now.getHours();
+                    return   month+"月"+date+"日"+hour+":00";
+                }
+                },
+            ]],
+
+            onSelect: function(index, row){
+                var data = $.extend({}, row);
+                $('#id_str').html(data.id);
+                $('#id').html(data.id);
+                $('#user_name').html(data.user_name);
+                $('#mobile').html(data.mobile);
+                $('#area').html(data.area);
+                $('#homeType').html(data.homeType);
+                $('#num').html(data.num);
+                $('#user_name').html(data.user_name);
+                $('#tech_content').html(data.tech_content);
+                jq_content_form.form('load', data);
+                $('#admins_edit_info').html('');
+                if (data['action_user'] != ''){
+                    jq_action_info.html('信息已被编辑: ' + data['action_user'] + ' ' + data['action_time']);
+                } else {
+                    jq_action_info.html('');
+                }
+
+            }
+
+        });
+
+        jq_filter_status.combobox({
+            width: 100,
+            data: status_data,
+            editable: false,
+            onSelect: function(){
+                search_content();
+            }
+        });
+
+
+
+
+        jq_content_form.form({
+            url: module_router + '/edit',
+            onSubmit: function(param){
+                if ($('#order_id').val() == ""){
+                    return false;
+                }
+                var isValid = $(this).form('validate');
+                if (!isValid){
+                    $.messager.progress('close');
+                }
+                return isValid;
+            },
+            success: function(res){
+                $.messager.progress('close');
+                var res = JSON.parse(res);
+
+                if (res.success){
+                    jq_dg_content.datagrid('reload');
+                }
+                if(res.success){
+                    $.messager.show({
+                        title: '提示',
+                        msg: '保存成功',
+                        timeout: 3500,
+                        showType: 'slide'
+                    });
+
+                    $('#technician_id').val(0);
+                }else{
+                    $.messager.show({
+                        title: '提示',
+                        msg: res.message,
+                        timeout: 3500,
+                        showType: 'slide'
+                    });
+                }
+            }
+        });
+
+        jq_add_form.form({
+            url : module_router + '/add',
+            onSubmit : function (param) {
+                var isValid = $(this).form('validate');
+                if (!isValid){
+                    $.messager.progress('close');
+                }
+                return isValid;
+            },
+            success : function (res) {
+                $.messager.progress('close');
+                var res = JSON.parse(res);
+
+                if (res.success) {
+                    $.messager.show({
+                        title : '提示',
+                        msg : '保存成功',
+                        timeout : 3500,
+                        showType : 'slide'
+                    });
+                    jq_add_dialog.dialog('close');
+                    jq_dg_content.datagrid('reload');
+                } else {
+                    $.messager.show({
+                        title : '提示',
+                        msg : res.message,
+                        timeout : 3500,
+                        showType : 'slide'
+                    });
+                }
+            }
+        });
+
+
+    });
+
+    function save_content(){
+        if ($('#recharge_id').val() == ""){
+            return false;
+        }
+        $.messager.progress();
+        jq_content_form.submit();
+    }
+    function search_content(){
+
+        var filter_status = jq_filter_status.combobox('getValue');
+
+        jq_dg_content.datagrid({
+            pageNum: 1,
+            queryParams: {
+                status : filter_status
+            }
+        });
+
+    };
+
+
+
+</script>