var appPath = getAppPath();
$(function(){
  $("#opreateHtml").window("close");
  $("#coupon").show();
  $("#integral").hide();
  $("#addcompensatingContentCoupon").combobox({
        url:appPath+"/page/compensationtypeAct/ecCouponTypeSelect",
        valueField:"id",
        textField:"text",
        panelHeight:"auto",
        editable:false
    });
  $("#compensatingContent").combobox({
        url:appPath+"/page/compensationtypeAct/ecCouponTypeSelect",
        valueField:"id",
        textField:"text",
        panelHeight:"auto",
        editable:false
    });
  $("#deliveryGrid").datagrid({
    url:appPath+"/page/compensationtypeAct/getPage",
    height:"full",
    striped:true,
    remoteSort:false,
    pagination:true,
    rownumbers:false,
    singleSelect:false,
    queryParams:getQueryParam(),
    columns:[[
              {field:"opt",title:"操作",width:60,align:"center",
                  formatter:function(value,rowData,rowIndex){
                    var html="<img class='op-enable' style='heigh:50px' src='"+appPath+"/js/lib/jquery-easyui/themes/icons/cancel.png' onClick='deletes("+rowData.id+")' title='删除'/>";
                    return html;
                  }
               },
              {field:'giveExcuse',title:'补偿理由',width:100,align:'center',sortable:true},
              {field:'compensatingForm',title:'补偿形式',width:100,align:'center',sortable:true,
                  formatter:function(value){
                      if(value=="coupon"){
                          return "优惠券";
                      }else if(value=="integral"){
                          return "积分";
                      }else{
                          return value;
                      }
                  }
              },
              {field:'compensatingContent',title:'补偿内容',width:100,align:'center',sortable:true},
              {field:'opts',title:'补偿操作',width:250,align:'center',sortable:true,
                  formatter:function(value,rowData,rowIndex){
                      return "<label id='bcSa"+rowData.id+"'>&nbsp;<input type='inputText'  id='memberIdOrOrderId"+rowData.id+"' value='请输入会员账号/订单号' />&nbsp;" +
                               "<input type='button'  onClick='bcSave("+rowData.id+")' value='补偿'/></label>" +
                               "<label id='bcSh"+rowData.id+"'><a href='javascript:void(0);' onclick='bcShow("+rowData.id+")'>补偿</a>&nbsp;</label>";
                  }
              }
   ]],
   onLoadSuccess: function(data) {
       for (var int = 0; int < data.total; int++) {
          $("#bcSa"+data.rows[int].id).hide();
       }
   },
   toolbar:[
      {
          id:'btnadd',
          text:'创建补偿类型',
          iconCls:'icon-add',
          handler:function(){
             showWin(null);
          }
      }
   ]
 });
});

function getQueryParam(){
  var compensationtype =new Object();
      compensationtype.compensatingContent=$("#compensatingContent").combobox("getValue");
      compensationtype.giveExcuse=$.trim($("#giveExcuse").val());
      compensationtype.compensatingForm=$("#compensatingForm").combobox("getValue");
  return compensationtype;
}

function doQuery(){
  $("#deliveryGrid").datagrid('load',getQueryParam());
}

function deletes(id){
    var ids = id+',';
    $.messager.confirm('提示',"确定要删除此数据吗?",function(r){
       if(r){
            $.post(
                   appPath+"/page/compensationtypeAct/deleteIdsLogic",
                   {"ids":ids},
                   function(data){
                     $.messager.alert('提示','删除成功','');
                      doQuery();
                   });
       }
    });
}

function showWin(){
  if(!checkUserButtonRight('compensationtype')){
        return ;
  }
  $("#idHidden").val("");
  $("#addcompensatingContentIntegral").val("");
  $("#addcompensatingContentCoupon").combobox("setValue","");
  $("#addgiveExcuse").val("");
  $("#addcompensatingForm").val("");
  var iconStr="icon-add";
  var title="添加补偿类型";
  $('#opreateHtml').window({
    title:title,
    iconCls:iconStr,
    width:350,
    height:220,
    left:200,
    modal: true,
    shadow: true,
    collapsible:false,
    minimizable:false,
    maximizable:false
  });
  $('#opreateHtml').window('move',{top:100});
  $('#opreateHtml').window('open');
}

function closeWin(id){
  $('#opreateHtml').window('close');
}

function save(){
  var compensationtype=new Object();
  compensationtype.id=$("#idHidden").val();
  if($("#addgiveExcuse").val()==null||$("#addgiveExcuse").val()==""){
      $.messager.alert('提示','请填写补偿理由','info');
      return;
  }
  compensationtype.giveExcuse=$("#addgiveExcuse").val();
  compensationtype.compensatingForm=$('input:radio[name="addcompensatingForm"]:checked').val();
  if($('input:radio[name="addcompensatingForm"]:checked').val()=="coupon"){
      if($("#addcompensatingContentCoupon").combobox("getValue")==null||$("#addcompensatingContentCoupon").combobox("getValue")==""){
          $.messager.alert('提示','请选择优惠券','info');
          return;
      }
      compensationtype.compensatingContent=$("#addcompensatingContentCoupon").combobox("getValue");
  }else if($('input:radio[name="addcompensatingForm"]:checked').val()=="integral"){
      if($("#addcompensatingContentIntegral").val()==null||$("#addcompensatingContentIntegral").val()==""){
          $.messager.alert('提示','请填写积分','info');
          return;
      }
      compensationtype.compensatingContent=$("#addcompensatingContentIntegral").val();
  }
  doAjax({
    url:appPath+'/page/compensationtypeAct/saveOrUpdate',
    type:'post',
    data:compensationtype,
    success:function(data){
      $.messager.alert('提示','保存成功','info');
      $('#opreateHtml').window('close');
      doQuery();
    }
  });
}

function addcompensatingFormShow(type){
    switch(type){
    case "coupon":
        $("#coupon").show();
        $("#integral").hide();
        break;
    case "integral":
        $("#integral").show();
        $("#coupon").hide();
        break;
    default:
         $("#coupon").show();
         $("#integral").hide();
        break;
    }
}

//补偿
function bcSave(id){
    //添加补偿
    var compensatingLog = new Object();
    compensatingLog.compensationtypeId =id;
    compensatingLog.memberId = $("#memberIdOrOrderId"+id).val();
    doAjax({
        url : appPath + '/page/compensatingLogAct/save',
        type : 'post',
        data : compensatingLog,
        success : function(data) {
            if(data=='ok'){
                $.messager.alert('提示信息', '添加成功', 'info');
                $("#bcSh"+id).show();
                $("#bcSa"+id).hide();
                $("#memberIdOrOrderId"+id).val("请输入会员账号/订单号");
            }else{
                $.messager.alert('提示信息', data, 'info');
            }
        }
    });
}

function bcShow(id){
    $("#memberIdOrOrderId"+id).val("请输入会员账号/订单号");
    $("#memberIdOrOrderId"+id).focus(function(){
          $("#memberIdOrOrderId"+id).val("");
    });
    $("#bcSh"+id).hide();
    $("#bcSa"+id).show();
}

//jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<jsp:include page="/jsp/common/header.jsp"></jsp:include>
<script src="${ctx }/js/promote/compensationtype.js"></script>
<table class="queryTable">
  <tr>
    <td class="queryTitle" width="80px">补偿理由</td>
    <td class="queryContent" ><input class="inputText" type="text" id="giveExcuse" /></td>
    <td class="queryTitle" width="80px">补偿形式</td>
    <td class="queryContent" >
       <select id="compensatingForm" class="easyui-combobox" style="width: 100px" panelHeight="auto">
            <option value>请选择</option>
            <option value="coupon">优惠券</option>
            <option value="integral">积分</option>
        </select>
     </td>
   </tr>
   <tr>
    <td class="queryTitle" width="80px">补偿类型</td>
    <td class="queryContent" ><input class="inputText" type="text" id="compensatingContent" /></td>
    <td class="queryBtnTd" colspan="2"><a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search"  onclick="doQuery()">查&nbsp;&nbsp;询</a></td>
  </tr>
</table>

<table id="deliveryGrid"></table>

<div id="opreateHtml" class="easyui-window" title="" iconCls="icon-edit" style="width:300px; height:220px;text-align:center; background: #fafafa;">
  <div class="easyui-layout" fit="true">
    <div region="center" border="false" style="background:#fff;border:0px solid #ccc;">
       <form>
           <input type="hidden" id="idHidden" name="idHidden" value="" />
           <table class="queryTable" style="width: 300px;margin: auto;margin-top: 10px">
             <tr>
               <td class="queryTitle" width="80px">补偿理由</td>
               <td class="queryContent" ><input class="inputText" type="text" id="addgiveExcuse" /></td>
            </tr>
            <tr>
               <td class="queryTitle" width="80px">补偿形式</td>
               <td class="queryContent" >
                   <input type="radio" id="form1" name="addcompensatingForm"  value="coupon" checked="checked" onclick="addcompensatingFormShow('coupon')">优惠券&nbsp;&nbsp;
                   <input type="radio" id="form2" name="addcompensatingForm"  value="integral" onclick="addcompensatingFormShow('integral')">积分
               </td>
            </tr>
            <tr id="coupon">
               <td class="queryTitle" width="80px">选择优惠券</td>
               <td class="queryContent" ><input class="inputText" type="text" id="addcompensatingContentCoupon" /></td>
            </tr>
            <tr id="integral">
               <td class="queryTitle" width="100px">请输入补偿积分</td>
               <td class="queryContent" ><input class="easyui-numberbox" precision="0" type="text"  id="addcompensatingContentIntegral" /></td>
            </tr>
           </table>
       </form>
    </div>
  <div region="south" border="false" style="text-align:center;height:30px;line-height:30px;">
     <a class="easyui-linkbutton" iconCls="icon-ok" href="javascript:void(0);" onclick="save();">保存</a>&nbsp;&nbsp;
     <a class="easyui-linkbutton" iconCls="icon-cancel" href="javascript:void(0);" onclick="closeWin();">关闭</a>
  </div>
</div>
</div>
//java

/**
   *@description 保存或者更新
   */
   @RequestMapping(value="/save")
   @ResponseBody
   public String updateOrSave(HttpServletRequest request,HttpServletResponse response,CompensatingLog compensatingLog)
   {
        Long memberId=0l;
        //会员是否存在(由于输入的可能是会员账号(登录名)或是订单ID)
        String loginName=compensatingLog.getMemberId();
        Member mm=memberCommonService.getMemberByLoginname(loginName);
        OrderInfo o=new OrderInfo();
        try {
            if(mm==null){
                o.setOrderId(new Long(loginName));
                OrderInfo order=compensatingLogService.getOrderObj(o);
                if(order==null){
                    return "不存在此会员或是此订单";
                }else{
                    memberId=order.getMemberId();
                }
            }else{
                memberId=mm.getMemberId();
            }
        } catch (NumberFormatException e) {
            return "不存在此会员或是此订单";
        }
        Compensationtype type=new Compensationtype();
        type.setId(new Long(compensatingLog.getCompensationtypeId()));
        Compensationtype compensationtype=compensationtypeService.getCompensationtype(type);
        //根据补偿ID查询(积分,优惠券)优惠券类型的所有发放批次取都大于三十天中的有限期最短的可用优惠券进行发放
        if(compensationtype.getCompensatingForm().equals("coupon")){
            //发放优惠券调用发放优惠券的接口
            EcCouponPublish ecCouponPublish=new EcCouponPublish();
            ecCouponPublish.setCouponTypeId(new Integer(compensationtype.getCompensatingContent()));
            List<EcCouponPublish> couponList=ecCouponPublishService.getUnUsedEcCouponPublishTime(ecCouponPublish);
            int publishId=0;
            if(couponList.size()>0){
                 publishId=couponList.get(0).getPublishId();
            }else{
                 return "此类型优惠券没有批次大于30天的可用优惠券";
            }

            CouponsAssignParam  param = new CouponsAssignParam();
            /*会员id*/
            param.setMemberId(memberId);
            /*批次号*/
            param.setPublishId(publishId);
            /*领取数量*/
            param.setAssignCouponsCount(1);
            /*调用服务  saveCouponsByMemberToPublishId*/
            ServiceMessage<List<EcCoupons>> msg = ecCouponsService.saveCouponsByMemberToPublishId(param);
            if(!msg.getStatus().equals(MsgStatus.NORMAL)){
                logger.error("优惠券SOA服务异常");
                return msg.getMessage();
           }
        }else if(compensationtype.getCompensatingForm().equals("integral")){
            //积分调用积分的接口
            MemberPointsHis mem=new MemberPointsHis();
            mem.setMemberId(memberId);
            mem.setPoints(new Integer(compensationtype.getCompensatingContent()));
            MemberPointsSetting set=new MemberPointsSetting();
            set.setPointsType("manual_points"); //member_points_setting表中的人工添加
            ServiceMessage<MemberPointsHis> msgRes=memberPointHisService.changePointsNoRankId(mem, set); //添加积分
            if(!msgRes.getStatus().equals(MsgStatus.NORMAL)){
                logger.error("积分SOA服务异常");
                return "补偿积分添加失败";
           }
        }
        String userId=request.getSession().getAttribute("userId").toString();
        super.bindingProperty(compensatingLog, userId);
        compensatingLog.setMemberId(memberId.toString());
        compensatingLogService.save(compensatingLog);
        return "ok";
   }
}

jquery之营销系统(补偿记录)的更多相关文章

  1. jquery之营销系统(会员促销)

    var appPath = getAppPath(); var cnt = 0; var loadCnt = 0; $(function() { $("#opreateHtml") ...

  2. jquery之营销系统

    // //////////////////////////优惠券开始//////////////////////////// // 给附加条件选择框添加事件 function inputFuJia() ...

  3. 升讯威微信营销系统开发实践:订阅号和服务号深入分析( 完整开源于 Github)

    GitHub:https://github.com/iccb1013/Sheng.WeixinConstruction因为个人精力时间有限,不会再对现有代码进行更新维护,不过微信接口比较稳定,经测试至 ...

  4. .net core 和 WPF 开发升讯威在线客服与营销系统:背景和产品介绍

    本系列文章详细介绍使用 .net core 和 WPF 开发 升讯威在线客服与营销系统 的过程.本产品已经成熟稳定并投入商用. 在线演示环境:https://kf-m.shengxunwei.com ...

  5. .net core 和 WPF 开发升讯威在线客服与营销系统:系统总体架构

    本系列文章详细介绍使用 .net core 和 WPF 开发 升讯威在线客服与营销系统 的过程.本产品已经成熟稳定并投入商用. 在线演示环境:https://kf.shengxunwei.com 注意 ...

  6. MiniCRT 64位 linux 系统移植记录:64位gcc的几点注意

    32位未修改源码与修改版的代码下载: git clone git@github.com:youzhonghui/MiniCRT.git MiniCRT 64位 linux 系统移植记录 MiniCRT ...

  7. 9月19号-9月21号丰宁坝上草原行 - 营销系统 - 京东内部论坛 - Powered by Discuz!

    9月19号-9月21号丰宁坝上草原行 - 营销系统 - 京东内部论坛 - Powered by Discuz! 9月19号-9月21号丰宁坝上草原行   [复制链接]

  8. GitHub开源:升讯威微信营销系统(第三方微信平台)完整源代码

    GitHub:https://github.com/iccb1013/Sheng.WeixinConstruction 升讯威微信营销系统开发实践系列升讯威微信营销系统开发实践:(1)功能设计与架构设 ...

  9. 升讯威微信营销系统开发实践:(4)源代码结构说明 与 安装部署说明( 完整开源于 Github)

    GitHub:https://github.com/iccb1013/Sheng.WeixinConstruction因为个人精力时间有限,不会再对现有代码进行更新维护,不过微信接口比较稳定,经测试至 ...

随机推荐

  1. C++中基类对象的引用

    代码: #include <iostream> #include <cstdio> using namespace std; class A{ public: void pri ...

  2. [HDU1017]Exact cover[DLX][Dancing Links详解][注释例程学习法]

    Dancing Links解决Exact Cover问题. 用到了循环双向十字链表. dfs. 论文一知半解地看了一遍,搜出一篇AC的源码,用注释的方法帮助理解. HIT ACM 感谢源码po主.链接 ...

  3. 函数递归时,递归次数到900多时,就是抛出异常exception RuntimeError('maximum recursion depth exceeded',)

    import subprocess import multiprocessing import urllib import sys import os import pymongo import si ...

  4. ThinkPHP实现RBAC

    RBAC: role base access control   基于角色的用户访问权限控制 不同人员登录系统要显示不同的菜单项目 1.传统方式权限设置: 具体操作权限与用户直接联系:

  5. PHP 过滤二维数组和三维数组

    <?php $arr = [ [1,3,5,7,9], [2,4,6,8,0] ]; $arr2 = [ 'list' => [ [1,3,5,7], [2,4,6,8], [3,2,9, ...

  6. 2015年6月股灾永远载入A股史册

    之前很奇怪这次牛市行情的暴涨与暴跌,后来发现成交量是以往不可想象的,而这一切的源头就是融资融券,也就是杠杆. 杠杆的作用是无穷的,就像阿基米德说的那样“给我一个支点,我就能撬起地球”. 杠杆是个放大器 ...

  7. Linux学习——卸载Ubuntu,安装CentOS,第一次使用命令

    最近,看了相关的资料,发现Ubuntu不是很利于学习Linux操作系统,而CentOS比较有利于学习Linux操作系统,就卸载了. 当然,对于菜鸟,自然是很没有主见. 卸载Ubuntu感觉很奇怪,下来 ...

  8. RAILS ON

    我是按照下面这个URL来轻快安装的. http://lxiaodao.iteye.com/blog/1579992 (1)RVM官方网站应该是改版过一次, 使用 curl -L https://get ...

  9. curl http认证

    有些站点需要http认证.(apache认证:http://blog.csdn.net/zf213/article/details/4252592) 如果访问http://test:123789@xx ...

  10. 【HDOJ】1341 Simple Computers

    注意PC要与31. #include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 40 ...