/* uglified */
"use strict";var exports=process.mainModule.exports;const utils=require("../../utils/functions"),_=require("../../utils/Underscore"),isUseMockData=!1,updFav=(e,o)=>{let a=[];try{if(!_.isObject(e))throw new Error("参数：params必须是对象");if(!e.favObject)throw new Error("缺少活动信息");if(e.favObject.shopId!==nw.process.mainModule.exports.vue.business.shop.id)throw new Error("该活动的店铺ID与当前门店不一致");if(a.push(`DELETE  FROM O_FAV_ACTIVITY WHERE ID = '${e.favObject.id}'`),e.favObject.beginTime&&(e.favObject.beginTime=new Date(e.favObject.beginTime).format("yyyy-MM-dd hh:mm:ss")),e.favObject.endTime&&(e.favObject.endTime=new Date(e.favObject.endTime).format("yyyy-MM-dd hh:mm:ss")),e.favObject.createTime&&(e.favObject.createTime=new Date(e.favObject.createTime).format("yyyy-MM-dd hh:mm:ss")),e.favObject.modifyTime&&(e.favObject.modifyTime=new Date(e.favObject.modifyTime).format("yyyy-MM-dd hh:mm:ss")),a.push(utils.getInsertSql("O_FAV_ACTIVITY",e.favObject)),e.favGoodsList){a.push(`DELETE  FROM O_FAV_ACTIVITY_GOODS WHERE ACTIVITY_ID = '${e.favObject.id}'`);for(var s=0;s<e.favGoodsList.length;s++)e.favGoodsList[s].createTime&&(e.favGoodsList[s].createTime=new Date(e.favGoodsList[s].createTime).format("yyyy-MM-dd hh:mm:ss")),a.push(utils.getInsertSql("O_FAV_ACTIVITY_GOODS",e.favGoodsList[s]))}nw.process.mainModule.exports.api.db.exec(a,function(a){a?_.isFunction(o)&&o({code:500,message:a.message,data:e}):_.isFunction(o)&&o({code:200,message:"",data:e})})}catch(e){console.error(e),_.isFunction(o)&&o({code:500,message:e.message,data:null})}},delFav=(e,o)=>{let a=[];try{if(!_.isObject(e))throw new Error("参数：params必须是对象");if(!e.favId)throw new Error("缺少活动ID");a.push(`DELETE  FROM O_FAV_ACTIVITY WHERE ID = '${e.favId}'`),a.push(`DELETE  FROM O_FAV_ACTIVITY_GOODS WHERE ACTIVITY_ID = '${e.favId}'`),console.log(a),nw.process.mainModule.exports.api.db.exec(a,function(a){a?_.isFunction(o)&&o({code:500,message:a.message,data:e}):_.isFunction(o)&&o({code:200,message:"",data:e})})}catch(e){console.error(e),_.isFunction(o)&&o({code:500,message:e.message,data:null})}},getFavGoods=(e,o)=>{try{if(!e.goodId)throw new Error("缺少商品ID");let a=`SELECT \n                o1.ID AS activityId,\n                o1.FAV_NAME AS favName,\n                o1.FAV_QUANTUM AS favQuantum,\n                o1.FAV_CYCLE_TYPE AS favCycleType,\n                o1.FAV_CYCLE AS favCycle,\n                o1.NO_FAV_DATE AS noFavTime,\n                o1.VIP AS vip,\n                o1.VIP_RANK AS vipRank,\n                o1.VIP_FOLDUPFOLD AS vipFoldupfold,\n                o2.DISCOUNT_PER AS discountPer\n              FROM O_FAV_ACTIVITY as o1\n              inner join O_FAV_ACTIVITY_GOODS o2 on o1.ID = o2.ACTIVITY_ID \n              where o1.FAV_RANGE = 0 \n                and o1.FAV_STATUS < 2\n                and o2.GOODS_ID = '${e.goodId}'\n                and o1.BEGIN_TIME <= '${e.nowDate}' \n                and o1.END_TIME >= '${e.nowDate}'\n              order by o1.CREATE_TIME DESC`;nw.process.mainModule.exports.api.db.select(`${a}`,function(a){_.isFunction(o)&&o({code:200,message:"",data:{params:e,activityGoods:a}})})}catch(e){console.error(e),_.isFunction(o)&&o({code:500,message:e.message,data:null})}};module.exports={updFav:updFav,delFav:delFav,getFavGoods:getFavGoods};