DengTao 8 anni fa
parent
commit
fb86790cb3

+ 57 - 6
www/protected/controllers/RechargeController.php

@@ -66,6 +66,7 @@ class RechargeController extends AdminController {
         $rows = CommonFn::getRowsFromCursor($recharge);
 
         $parsedRows = Recharge::model()->parse($rows);
+
         echo CommonFn::composeDatagridData($parsedRows, $total);
     }
     //添加充值卡信息
@@ -74,19 +75,61 @@ class RechargeController extends AdminController {
         $cash_back = intval(Yii::app()->request->getParam('cash_back', 0));
         $status = intval(Yii::app()->request->getParam('status', 0));
         $desc = Yii::app()->request->getParam('desc', '');
+        $coupons = array();
+        $select_fun = Yii::app()->request->getParam('add_select_fun', '');
         $flag = empty($denomination);
-        $flag = $flag || $status == -1;
+        $flag = $flag || $status == -1 ;
         if ($flag) {
             CommonFn::requestAjax(false, '请检查数据完整性', array());
             exit;
         }
+        $coupons_obj = array();
+        //判断 返现 代金券
+        if ($select_fun == 'coupon') {
+            //数组分割处理
+            $coupons = explode("<br />",nl2br(trim(Yii::app()->request->getParam('text_coupons'))));
+
+            foreach ($coupons as $key => $coupon) {
+                $coupon = rtrim(trim($coupon),',');
+                foreach ($coupons as $k => $v) {
+                    if ($key != $k) {
+                        $v = rtrim(trim($v),',');
+                        if ($v == $coupon) {
+                            CommonFn::requestAjax(false, '代金券id重复');
+                            break;
+                        }
+                    }
+                }
+
+                $coupon = new MongoId($coupon);
+                $coupon_obj = Coupon::get($coupon);
+
+                if (!$coupon_obj) {
+                    CommonFn::requestAjax(false, '代金券不存在');
+                    break;
+                } else {
+                    $coupons_obj[$key] = $coupon;
+                }
+            }
+
+        } else{
+            //返现
+            $cash_back = intval(Yii::app()->request->getParam('cash_back', ''));
+            if ($cash_back <= 0 ){
+                CommonFn::requestAjax(false, '返现金额不能为0');
+            }
+        }
+
+
+
         $recharge = new Recharge();
         $recharge->denomination = intval($denomination);//充值面额
         $recharge->cash_back = intval($cash_back);//返现金额
+        $recharge->coupons = $coupons_obj;
         $recharge->desc = $desc;//描述
         $recharge->status = intval($status);//状态
 
-        $addRecharge_arr = array('denomination','cash_back','status','desc');
+        $addRecharge_arr = array('denomination','cash_back','status','desc','coupons');
         $success = $recharge->save(true, $addRecharge_arr);
 
         CommonFn::requestAjax($success, '', array());
@@ -97,11 +140,11 @@ class RechargeController extends AdminController {
     public function actionEdit() {
         $denomination = intval(Yii::app()->request->getParam('denomination',''));//面额
         $desc = Yii::app()->request->getParam('desc', '');//描述
-        $status = Yii::app()->request->getParam('status', '');
+        $status = intval(Yii::app()->request->getParam('status', '0'));
         $id = Yii::app()->request->getParam('id', '');
         $coupons = array();//代金券
         $select_fun = Yii::app()->request->getParam('select_fun', '');
-
+        $coupons_obj = array();
         //指定状态
         if ($status == 100) {
             CommonFn::requestAjax(false, '必须指定状态!');
@@ -110,10 +153,13 @@ class RechargeController extends AdminController {
         if (!isset($denomination)) {
             CommonFn::requestAjax(false, '必须填写面额!');
         }
+
+
+
         $cash_back = 0;
         if ($select_fun == 'coupon') {
             //数组分割处理
-            $coupons = explode("<br />",nl2br(trim(Yii::app()->request->getParam('coupons'))));
+            $coupons = explode("<br />",nl2br(trim(Yii::app()->request->getParam('text_coupons'))));
 
             foreach ($coupons as $key => $coupon) {
                 $coupon = rtrim(trim($coupon),',');
@@ -133,18 +179,23 @@ class RechargeController extends AdminController {
                 if (!$coupon_obj) {
                     CommonFn::requestAjax(false, '代金券不存在');
                     break;
+                } else {
+                    $coupons_obj[$key] = $coupon;
                 }
             }
 
         } else{
             //返现
             $cash_back = intval(Yii::app()->request->getParam('cash_back', ''));
+            if ($cash_back <= 0 ){
+                CommonFn::requestAjax(false, '返现金额不能为0');
+            }
         }
         $criteria = new EMongoCriteria();
         $criteria->_id = new MongoId($id);
         $recharge = Recharge::model()->find($criteria);
 
-        $recharge->coupons = $coupons;
+        $recharge->coupons = $coupons_obj;
         $recharge->cash_back = $cash_back;
         $recharge->desc = $desc;
         $recharge->denomination = $denomination;

+ 2 - 3
www/protected/modules/o2o/models/Recharge.php

@@ -73,13 +73,12 @@ class Recharge extends MongoAr
             }
         }
 
-        $newRow['coupons'] = CommonFn::get_val_if_isset($row,'coupons');
-
+        $newRow['coupons'] = $coupons;
         $newRow['status'] = CommonFn::get_val_if_isset($row,'status',1);
         $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  (APPLICATION=='api'||APPLICATION=='common'){
             unset($newRow['action_user']);
             unset($newRow['action_time']);
             unset($newRow['action_log']);

+ 66 - 10
www/protected/views/recharge/index.php

@@ -63,7 +63,7 @@
                                         </div>
 
                                         <div class="box_flex f_content">
-                                        <input type="radio" name="select_fun" id="edit_cash_back" checked="true" value='cash_back' />返现金额
+                                        <input type="radio" name="select_fun" id="edit_cash_back"  value='cash_back' />返现金额
                                             <span id="id_str"></span>
                                         <input type="radio" name="select_fun" id="edit_coupon"  value="coupon" />使用代金券
                                         </div>
@@ -80,7 +80,7 @@
                                         </div>
                                         <div class="box_flex f_content" id="coupons" style="display: none;">
                                             <div id="coupons_items"></div>
-                                            <textarea id="text_coupons" name="coupons" style="width: 250px;min-height: 50px" placeholder="若使用代金券,填写代金券id,多个代金券时用换行分割"></textarea>
+                                            <textarea id="text_coupons" name="text_coupons" style="width: 250px;min-height: 50px" placeholder="若使用代金券,填写代金券id,多个代金券时用换行分割"></textarea>
                                         </div>
                                     </div>
                                 </li>
@@ -91,7 +91,7 @@
                                             <span>介绍: </span>
                                         </div>
                                         <div class="box_flex f_content">
-                                            <textarea name="desc" style="width: 250px;min-height: 100px"></textarea>
+                                            <textarea name="desc" id="edit_desc" style="width: 250px;min-height: 100px"></textarea>
                                         </div>
                                     </div>
                                 </li>
@@ -148,13 +148,31 @@
                 <li class="f_item">
                     <div class="box">
                         <div class="f_label">
-                            <span>返现的金额: </span>
+                            <span>选择方式: </span>
                         </div>
                         <div class="box_flex f_content">
-                            <input id="cash_back" name="cash_back" style="width: 250px;"  />
+                            <input type="radio" name="add_select_fun" id="add_cash_back" checked="true" value="cash_back" />返现金额
+                            <span id="id_str"></span>
+                            <input type="radio" name="add_select_fun" id="add_coupon"  value="coupon" />使用代金券
                         </div>
                     </div>
                 </li>
+
+                <li class="f_item">
+                    <div class="box">
+                        <div class="f_label">
+                            <span></span>
+                        </div>
+                        <div class="box_flex f_content" id="add_cash">
+                            <input type="text" name="cash_back" id="cash_back_add" value='' />
+                        </div>
+                        <div class="box_flex f_content" id="add_coupons" style="display: none;">
+                            <div id="coupons_items"></div>
+                            <textarea id="add_text_coupons" name="coupons" style="width: 250px;min-height: 50px" placeholder="若使用代金券,填写代金券id,多个代金券时用换行分割"></textarea>
+                        </div>
+                    </div>
+                </li>
+
                 <li class="f_item">
                     <div class="box">
                         <div class="f_label">
@@ -199,7 +217,6 @@
     var jq_setStatus_add = $('#setStatus_add');
     var module_router = site_root + '/index.php?r=Recharge';
     var status_data = <?php echo json_encode($status); ?>;
-    var main_coupons = <?php echo json_encode($main_coupons); ?>;
     var jq_setStatus = $('#setStatus');
     var w_width = $(window).width();
     var w_height = $(window).height();
@@ -273,7 +290,6 @@
         data: status_data
     });
 
-
     jq_add_dialog.dialog({
         title: '新建充值卡',
         width: 500,
@@ -344,6 +360,15 @@
             {field:'id', title:'id', hidden:true},
             {field:'denomination', title:'充值面额', width:25,sortable:false
             },
+            {field:'type', title:'类型', width:8, sortable: true,
+                formatter: function(value, row){
+                   if(row.cash_back == 0){
+                       return "代金券";
+                   } else {
+                       return "返现";
+                   }
+                }
+                },
             {field:'cash_back', title:'返现金额', width:25,sortable:false},
             {field:'status', title:'状态', width:50, sortable: true,
                 formatter: function(value, row){
@@ -356,6 +381,25 @@
             var data = $.extend({}, row);
             $('#id_str').html(data.id);
             $('#recharge_id').val(data.id);
+
+
+            if (data.cash_back <= 0){
+                $('#edit_cash_back').prop("checked",false);
+
+                $('#edit_coupon').prop("checked",true);
+                $('#cash').hide();
+                $('#coupons').show();
+            } else {
+                $('#edit_coupon').prop("checked",false);
+                $('#edit_cash_back').prop("checked",true);
+                $('#coupons').hide();
+                $('#cash').show();
+            }
+            coupon = '';
+            for(var i in data.coupons){
+                coupon += data['coupons'][i]['id']+'<br/>';
+            }
+            $('#coupons_items').html(coupon);
             jq_content_form.form('load', data);
             $('#admins_edit_info').html('');
             if (data['action_user'] != ''){
@@ -460,7 +504,14 @@
         $('#cash').show();
         $('#coupons').hide();
     });
-
+    $('#add_coupon').change(function(){
+        $('#add_cash').hide();
+        $('#add_coupons').show();
+    });
+    $('#add_cash_back').change(function(){
+        $('#add_cash').show();
+        $('#add_coupons').hide();
+    });
 
 });
 
@@ -502,8 +553,13 @@ function checkAddForm () {
         $.messager.alert('提示', '请输入充值面额', 'warning');
         return false;
     }
-    if ($('#cash_back').val() == '') {
-        $.messager.alert('提示', '请输入返现的金额', 'warning');
+
+    if ($('#add_cash_back').attr("checked") == 'undefined'  || $('#add_coupon').attr("checked") == 'undefined') {
+        $.messager.alert('提示', '请选择方式', 'warning');
+        return false;
+    }
+    if ($('#add_text_coupons').val() == '' && $('#cash_back_add').val() == '') {
+        $.messager.alert('提示', '请输入返现的金额或请输入代金券id', 'warning');
         return false;
     }