瀏覽代碼

couoncode

Charlie 8 年之前
父節點
當前提交
e109f424a8

+ 4 - 4
www/protected/commands/CouponFactoryCommand.php

@@ -14,13 +14,13 @@ class CouponFactoryCommand extends CConsoleCommand{
         set_time_limit(0);
         
         $count = 3;//生成数量
-        $channel = '20160114-zhoujunchao';
-        $desc = '礼物版块兑换使用158碳酸浴';
+        $channel = '20161011-test';
+        $desc = '测试用';
         $date = date('Ymd');
         $i = 0;
         $coupons = array();
-        $coupon_ids[] = '56974c73a84ea07e6d8bcdc5';
-        // $coupon_ids[] = '561cbd190eb9fb80628b4aaf';
+        $coupon_ids[] = '57fb18dda84ea03a0a8b458d';
+        $coupon_ids[] = '57df714b9f5160c1048b456a';
         // $coupon_ids[] = '561cbd7b0eb9fbaa628b4a80';
         // $coupon_ids[] = '561cbdc70eb9fb60638b4a93';
         foreach ($coupon_ids as $value) {

+ 67 - 0
www/protected/controllers/CouponCodeController.php

@@ -0,0 +1,67 @@
+<?php
+class CouponCodeController extends AdminController{
+
+    public function actionIndex()
+    {
+        $status_option = CouponCode::$status_option;
+        $status = CommonFn::getComboboxData($status_option, 100, true, 100);
+
+        $this->render('index', array(
+            'status' => $status,
+        ));
+    }
+
+    public function actionList(){
+        $search = Yii::app()->request->getParam('search', '');
+        $filter_status = intval(Yii::app()->request->getParam('status', 100));
+
+        $params = CommonFn::getPageParams();
+        $criteria = new EMongoCriteria($params);
+
+
+        if ($filter_status != 100){
+            $criteria->status('==', $filter_status);
+        }
+
+        if ($search != '') {
+            $criteria->code('or', new MongoRegex('/'.$search.'/'));
+            $criteria->channel('or', new MongoRegex('/'.$search.'/'));
+        }
+
+        $cursor = CouponCode::model()->findAll($criteria);
+        $total = $cursor->count();
+        $rows = CommonFn::getRowsFromCursor($cursor);
+        $parsedRows = CouponCode::model()->parse($rows);
+        echo CommonFn::composeDatagridData($parsedRows, $total);
+    }
+
+    public function actionEdit(){
+        $id = Yii::app()->request->getParam('id', '');
+        $status = intval(Yii::app()->request->getParam('status', 1));
+
+        if(!$id){
+            CommonFn::requestAjax(false, '请选择兑换码');
+        }
+
+        if($status == 100 ){
+            CommonFn::requestAjax(false, '必须指定状态');
+        }
+
+        $status=$status>1?1:$status;
+
+        $criteria = new EMongoCriteria();
+        $criteria->_id = new MongoId($id);
+        $coupon_code = CouponCode::model()->find($criteria);
+        if (empty($coupon_code)){
+            CommonFn::requestAjax(false, '兑换码 不存在');
+        }
+
+        $arr_coupon = array('status');
+
+        $coupon_code->status = $status;
+
+        $success = $coupon_code->save(true,$arr_coupon);
+        CommonFn::requestAjax($success, '', array());
+    }
+
+}

+ 61 - 5
www/protected/modules/o2o/models/CouponCode.php

@@ -3,7 +3,7 @@ class CouponCode extends MongoAr
 {
     public $_id;    //object id
 
-    public $code;   //兑换码
+    public $code;   //兑换码 string
 
     public $channel; //使用渠道  唯一批次标记
 
@@ -11,13 +11,13 @@ class CouponCode extends MongoAr
 
     public $coupons = array();
 
-    public $stop_time;
+    public $stop_time;//过期时间
 
-    public $use_time;
+    public $use_time;//使用时间
 
-    public $user;
+    public $user;//使用者
 
-    public $user_device_id;//领用用户的device_id
+    public $user_device_id;//领用用户的device_id or unionid
 
     public $alway = 0; //是否可以重复使用
 
@@ -30,6 +30,10 @@ class CouponCode extends MongoAr
         $this->code = substr($time,2);
     }
 
+    public static $status_option = array(
+        0 => array('name' => '未使用'),
+        1 => array('name' => '已使用'),
+    );
 
     public static function model($className=__CLASS__)
     {
@@ -41,6 +45,58 @@ class CouponCode extends MongoAr
         return 'coupon_code';
     }
 
+    public function parseRow($row,$output=array()){
+        $newRow = array();
+        $newRow['id'] = (string)$row['_id'];
+
+        $newRow['code'] = CommonFn::get_val_if_isset($row,'code','');
+        $newRow['channel'] = CommonFn::get_val_if_isset($row,'channel','');
+        $newRow['desc'] = CommonFn::get_val_if_isset($row,'desc','');
+
+        $newRow['user_device_id'] = CommonFn::get_val_if_isset($row,'user_device_id','');
+
+        $user = array();
+        if(isset($row['user'])){
+            $_user = RUser::get($row['user']);
+            $user = $_user->parseRow($_user->attributes,array('user_name','id','avatar'));
+        }
+        $newRow['user'] = $user;
+
+        $newRow['stop_time'] = CommonFn::get_val_if_isset($row,'stop_time',time());
+        $newRow['stop_time_str'] = CommonFn::sgmdate("Y年n月d日", $newRow['stop_time'],1);
+
+        $newRow['use_time'] = CommonFn::get_val_if_isset($row,'use_time',time());
+        $newRow['use_time_str'] = CommonFn::sgmdate("Y年n月d日", $newRow['use_time'],1);
+
+        $newRow['status'] = CommonFn::get_val_if_isset($row,'status',0);
+        $newRow['always'] = CommonFn::get_val_if_isset($row,'always',0);
+
+        $coupons = array();
+        if(isset($row['coupons']) && !empty($row['coupons'])){
+            foreach($row['coupons'] as $coupon_id){
+                $_coupon = Coupon::get($coupon_id);
+                if($_coupon){
+                    $coupons[] = Coupon::model()->parse($_coupon->attributes,false,array('id','name'));
+                }else{
+                    continue;
+                }
+            }
+        }
+        $newRow['coupons'] = $coupons;
+
+        $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['action_user']);
+            unset($newRow['action_time']);
+            unset($newRow['action_log']);
+        }
+
+        return $this->output($newRow,$output);
+    }
+
     public static function get($_id) {
         if(CommonFn::isMongoId($_id)){
             $criteria = new EMongoCriteria();