|
@@ -1,159 +0,0 @@
|
|
|
-<?php
|
|
|
-/**
|
|
|
- * User: charlie
|
|
|
- * 闪购、抽奖、积分兑换的商品
|
|
|
- */
|
|
|
-class Goods extends MongoAr
|
|
|
-{
|
|
|
- public $_id;
|
|
|
- public $name;//商品名字
|
|
|
- public $avatar;//商品封面
|
|
|
- public $city_info=array();//商品城市属性,设置此属性的商品,只有此地区用户可见
|
|
|
- public $desc='';//商品介绍
|
|
|
- public $type;//'exchange'=>兑换 'lottery'=>抽奖 'buy'=>抢购
|
|
|
-
|
|
|
- public $order=1;//排序权重
|
|
|
- public $status=1;//0 删除 1正常 -1已过期
|
|
|
- public $is_real=1;//是否是实物 1实物 0不是实物
|
|
|
-
|
|
|
- public $market_price=0;//市场价
|
|
|
- public $count=0;//库存数量
|
|
|
- public $min_level=0;//无论是兑换、抽奖、抢购 最低可以参与的人的等级 0就是不限制
|
|
|
- public $score;//如果是兑换 就是兑换该商品所需的爪币数;如果是抽奖 就是抽一次所需的爪币;如果是抢购 就是最多可以用多少爪币抵现金
|
|
|
- public $max_exchange = 1;//一件商品允许兑换的最多次数
|
|
|
- public $pics=array();//商品图片
|
|
|
- public $start_time;//商品上线时间戳
|
|
|
- public $end_time;//商品结束时间戳
|
|
|
- public $probability=0.001;//如果是抽奖 抽中的概率
|
|
|
- public $max_times_per_day=100;//如果是抽奖 每个用户每天最多抽的次数
|
|
|
- public $lottertimes=0;//如果是抽奖 一共被抽的次数
|
|
|
-
|
|
|
-
|
|
|
- //public $give_score=0;//如果是抢购的商品 如果购买成功 赠送的爪币
|
|
|
- //public $shop_price;//如果是抢购的商品 本店售价
|
|
|
-
|
|
|
- public static $status_option = array(
|
|
|
- 1 => array('name' => '正常'),
|
|
|
- 0 => array('name' => '删除'),
|
|
|
- -1 => array('name' => '已过期'),
|
|
|
- -2 => array('name' => '已下架')
|
|
|
- );
|
|
|
-
|
|
|
- public static $type_option = array(
|
|
|
- 'exchange' => array('name' => '兑换'),
|
|
|
- 'lottery' => array('name' => '抽奖'),
|
|
|
- 'buy' => array('name' => '抢购')
|
|
|
- );
|
|
|
-
|
|
|
-
|
|
|
- //无论是抽奖抽中 还是兑换 每个商品每人只能一次
|
|
|
- public function __construct($scenario='insert'){
|
|
|
- $this->setMongoDBComponent(Yii::app()->getComponent('mongodb_data'));
|
|
|
- parent::__construct($scenario);
|
|
|
- }
|
|
|
-
|
|
|
- public static function model($className=__CLASS__)
|
|
|
- {
|
|
|
- return parent::model($className);
|
|
|
- }
|
|
|
-
|
|
|
- public function getCollectionName()
|
|
|
- {
|
|
|
- return 'goods';
|
|
|
- }
|
|
|
-
|
|
|
- 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;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public function parseRow($row,$output=array()){
|
|
|
- $newRow = array();
|
|
|
- $newRow['id'] = (string)$row['_id'];
|
|
|
-
|
|
|
- $newRow['name'] = CommonFn::get_val_if_isset($row,'name','');
|
|
|
- $newRow['desc'] = CommonFn::get_val_if_isset($row,'desc','');
|
|
|
- $newRow['type'] = CommonFn::get_val_if_isset($row,'type','');
|
|
|
-
|
|
|
- $newRow['avatar'] = CommonFn::get_val_if_isset($row,'avatar',Yii::app()->params['defaultGoodsAvatar']);//默认图标
|
|
|
- if($newRow['avatar']==''){
|
|
|
- $newRow['avatar'] = Yii::app()->params['defaultGoodsAvatar'];
|
|
|
- }
|
|
|
-
|
|
|
- $newRow['city_info'] = CommonFn::get_val_if_isset($row,'city_info',array("province"=>"","city"=>"","area"=>""));
|
|
|
- if(!isset($newRow['city_info']['province'])){
|
|
|
- $newRow['city_info']['province'] = '';
|
|
|
- }
|
|
|
- if(!isset($newRow['city_info']['city'])){
|
|
|
- $newRow['city_info']['city'] = '';
|
|
|
- }
|
|
|
- if(!isset($newRow['city_info']['area'])){
|
|
|
- $newRow['city_info']['area'] = '';
|
|
|
- }
|
|
|
-
|
|
|
- $newRow['max_exchange'] = CommonFn::get_val_if_isset($row,'max_exchange',1);
|
|
|
- $newRow['order'] = CommonFn::get_val_if_isset($row,'order',1);
|
|
|
- $newRow['status'] = CommonFn::get_val_if_isset($row,'status',1);
|
|
|
- $newRow['is_real'] = CommonFn::get_val_if_isset($row,'is_real',1);
|
|
|
-
|
|
|
- $newRow['market_price'] = CommonFn::get_val_if_isset($row,'market_price',1);
|
|
|
- $newRow['count'] = CommonFn::get_val_if_isset($row,'count',1);
|
|
|
- if($newRow['count']<=0 && $newRow['status']==1 ){
|
|
|
- $newRow['status'] = -2;
|
|
|
- $model = self::get($row['_id']);
|
|
|
- $model->status = -2;
|
|
|
- $model->update(array('status'),true);
|
|
|
- }
|
|
|
- $newRow['min_level'] = CommonFn::get_val_if_isset($row,'min_level',1);
|
|
|
- $newRow['score'] = CommonFn::get_val_if_isset($row,'score',1);
|
|
|
-
|
|
|
- $newRow['pics'] = CommonFn::get_val_if_isset($row,'pics',array());
|
|
|
- if(empty($newRow['pics'])){
|
|
|
- $newRow['pics'] = CommonFn::$empty;
|
|
|
- }
|
|
|
-
|
|
|
- $newRow['start_time'] = CommonFn::get_val_if_isset($row,'start_time',0);
|
|
|
- $newRow['end_time'] = CommonFn::get_val_if_isset($row,'end_time',0);
|
|
|
-
|
|
|
- if($newRow['end_time']<time() && $newRow['status']==1 ){
|
|
|
- $newRow['status'] = -1;
|
|
|
- $model = self::get($row['_id']);
|
|
|
- $model->status = -1;
|
|
|
- $model->update(array('status'),true);
|
|
|
- }
|
|
|
-
|
|
|
- $newRow['start_time_str'] = CommonFn::bgmdate("Y年n月d日", $newRow['start_time'],1);
|
|
|
- $newRow['end_time_str'] = CommonFn::bgmdate("Y年n月d日", $newRow['end_time'],1);
|
|
|
-
|
|
|
- $newRow['probability'] = floatval(CommonFn::get_val_if_isset($row,'probability',0.001));
|
|
|
- $newRow['max_times_per_day'] = CommonFn::get_val_if_isset($row,'max_times_per_day',100);
|
|
|
- $newRow['lottertimes'] = CommonFn::get_val_if_isset($row,'lottertimes',0);
|
|
|
-
|
|
|
- $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'||APPLICATION=='common'){
|
|
|
- if($newRow['end_time']>time()){
|
|
|
- $newRow['countdown'] = $newRow['end_time'] - time();
|
|
|
- }else {
|
|
|
- $newRow['countdown'] = 0;
|
|
|
- }
|
|
|
- unset($newRow['probability']);
|
|
|
- unset($newRow['max_times_per_day']);
|
|
|
- unset($newRow['lottertimes']);
|
|
|
- unset($newRow['action_user']);
|
|
|
- unset($newRow['action_time']);
|
|
|
- unset($newRow['action_log']);
|
|
|
- }
|
|
|
-
|
|
|
- return $this->output($newRow,$output);
|
|
|
- }
|
|
|
-
|
|
|
-}
|