sms_tpls.js 6.06 KB
// pages/book/b_sms.js
import App from './api';
import util from './util';
import bcm from './bookCommon';
const {regeneratorRuntime} = global
const tpls = {
  SMS_154587043: '${guest},您好!${seller_name}已为您预订${date}的桌位:${region_room_name};地址:${seller_addr},电话:${seller_phone}\n客户经理${cusman},期待您的光临!',
  SMS_162733710: '尊敬的贵宾,您好!${reserve_date}的用餐,为您安排在${seller_name_addr_room}房间,${cusman}期待您的光临,预祝就餐愉快!',
  SMS_163050401: '尊敬的贵宾,您好!\n ${seller_name}已为您安排${date}的用餐,房间:${region_room_name}; \n地址:${seller_addr}; \n电话:${seller_phone} \n预祝用餐愉快,${cusman}期待您的光临!',
  SMS_164277855:'贵宾您好!${seller_name}为您预留${date}的${region_room_name};\n电话:${seller_phone},预祝用餐愉快!',
  SMS_164268239:'贵宾您好!${seller_name}为您预留${date}的${region_room_name};\n地址:${seller_addr},电话:${seller_phone},预祝用餐愉快!',
  SMS_173950289:'已为您预订${seller_name}的${rooms}包房,用餐时间为${daotime},祝您用餐愉快!订包间享优惠,微信搜索“周到安排”。'
};

module.exports ={
  tpls:tpls,
  getTableName(tables){
    let bao = [], san = [];
    tables.forEach(t => {
      if (t.tid == 2) {
        bao.push(t.name);
      } else {
        san.push(t.name);
      }
    })
    let str = '';
    if (bao.length > 0) {
      str = '包厢(' + bao.join('、') + ')';
    }
    if (san.length > 0) {
      str += san.join('、');
    }
    str = str.substr(0, 20);
    if (str.indexOf('(') > -1 && str.indexOf(')') < 0) {
      str = str.substr(0, 19) + ')';
    }
    return str;
  },
  getTableNameBSK(tables){
    let bsk={
      1:'散座',
      2:'包间',
      3:'卡台',
    }
    let ts={};
    tables.forEach(t => {
      ts[t.tid]=typeof ts[t.tid]=='undefined'?[]:ts[t.tid];
      ts[t.tid].push(t.name);
    })
    let str = '';
    Object.keys(ts).forEach(tid => {
      str += bsk[tid]+'('+ts[tid].join('、')+')、';
    });
    let mxl=str.length-1;
    str=str.substr(0,mxl>20?20:mxl);
    return str;
  },
  getTableNameOne(tables){
    let bao = [];
    tables.forEach(t => {
      bao.push(t.name);
    })
    return bao.join('、');
  },
  getTableNameShort(tables){//短桌位
    let str=tables[0].name;
    if(tables.length>1){
      str+='等'+tables.length+'个';
    }
    return str;
  },
  async getTplMsg(bookInfo,tplcode='SMS_163050401',sc=null){
    let smsData = {}
    let txa=['早上','中午','晚上']
    let tx=await bcm.getTimeSpaceIndexData(bookInfo.rdate,sc);
    if(!bookInfo.rdateStr){
      bookInfo.rdateStr=util.unixtoTime(bookInfo.ddate, "MM月DD日 HH:II")
    }
    switch (tplcode) {
      //尊敬的贵宾,您好!(4月6日)(中午)的用餐,为您安排在(好又多复兴路店)(202)房间,(王丽娜)期待您的光临,预祝就餐愉快!
      case 'SMS_162733710':
        smsData = {
          reserve_date: util.unixtoTime(bookInfo.rdate,'MM月DD日')
            .replace(/0(\d)/g,function($0,$1){
              return $1;
            })+' '+txa[tx.timeIndex],
          seller_name_addr_room: sc.seller.selleralias+this.getTableNameShort(bookInfo.tables).substr(0, 20),
          cusman: (bookInfo.cusman || bookInfo.seller.sellername).substr(0, 20),
        }
        break;
      case 'SMS_163050401':
        smsData = {
          seller_name: bookInfo.seller.sellername.substr(0, 20),
          date: bookInfo.rdateStr.replace('日','日'+txa[tx.timeIndex]),
          region_room_name: this.getTableNameOne(bookInfo.tables).substr(0, 20),
          seller_addr: (bookInfo.seller.real_address || bookInfo.seller.map_address).substr(0, 20),
          seller_phone: bookInfo.seller.phone.substr(0, 20),
          cusman: (bookInfo.cusman||'').substr(0, 20),
        }
        break;
      case 'SMS_164277855'://短店名+无地址
        smsData = {
          seller_name: sc.seller.selleralias.substr(0, 20),
          date: bookInfo.rdateStr.replace('日','日'+txa[tx.timeIndex]),
          region_room_name: this.getTableNameBSK(bookInfo.tables),
          seller_phone: bookInfo.seller.phone.substr(0, 20),
        }
        break;
      case 'SMS_164268239'://店名+地址
        smsData = {
          seller_name: bookInfo.seller.sellername.substr(0, 20),
          date: bookInfo.rdateStr.replace('日','日'+txa[tx.timeIndex]),
          region_room_name: this.getTableNameBSK(bookInfo.tables),
          seller_addr: (bookInfo.seller.real_address || bookInfo.seller.map_address).substr(0, 20),
          seller_phone: bookInfo.seller.phone.substr(0, 20),
        }
        break;
      case 'SMS_173950289'://运营安排包间
        smsData = {
          seller_name: bookInfo.seller.sellername.substr(0, 20),
          daotime: bookInfo.rdateStr.replace('日','日'+txa[tx.timeIndex]),
          rooms: this.getTableNameOne(bookInfo.tables).substr(0, 20),
        }
        break;
      default:
        let guest = '';
        if (bookInfo.sex == 3) {
          guest = '贵宾'
        } else {
          guest = bookInfo.rname.substr(0, 1) + (bookInfo.sex == 1 ? '先生' : '女士')
        }
        smsData = {
          guest: guest,
          seller_name: bookInfo.seller.sellername.substr(0, 20),
          date: bookInfo.rdateStr,
          region_room_name: this.getTableName(bookInfo.tables),
          reserve_pnum: (bookInfo.pnum || bookInfo.pnum_str) + '人',
          seller_addr: (bookInfo.seller.real_address || bookInfo.seller.map_address).substr(0, 20),
          seller_phone: bookInfo.seller.phone.substr(0, 20),
          cusman: (bookInfo.cusman || bookInfo.seller.sellername).substr(0, 20),
          cusman_phone: (bookInfo.cusman_phone || bookInfo.seller.phone).substr(0, 20),
          code: bookInfo.code,
        }
        break;
    }
    let tpl = this.tpls[tplcode];
    this.smsData = smsData;
    tpl = tpl.replace(/\${([^}]+)}/ig, function ($0, $1) {
      //console.log($0, $1);
      return smsData[$1];
    })
    return tpl
  },
}