123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- /**
- * Created by MyPC on 2019/11/5.
- */
- 'use strict';
- const hash= require('../class/hash');
- const Sequelize = require('sequelize');
- const Op = Sequelize.Op;
- module.exports = (sequelize, DataTypes) => {
- const serviceLog = sequelize.define('CLD_service_log', {
- slid : {type: DataTypes.INTEGER(11), primaryKey: true, autoIncrement: true},
- status: DataTypes.INTEGER,
- mark: DataTypes.STRING,
- date: DataTypes.DATE,
- category: DataTypes.STRING,
- clientid: DataTypes.INTEGER,
- staffname: DataTypes.STRING,
- staffid: DataTypes.INTEGER,
- }, {});
- /*
- * 根据客户ID合集获得服务信息
- * */
- serviceLog.findAllByClientid=async function(clientid,attributes){
- if(clientid==undefined){
- return [];
- }
- var condition={
- raw:true,
- where: {
- clientid: clientid
- },
- order: [['date', 'desc']]
- };
- if(attributes!=undefined){
- condition.attributes=attributes;
- }
- var serviceLogList = await this.findAll(condition);
- serviceLogList.forEach(function(v,i){
- serviceLogList[i].slidKey=hash.hashEncode(serviceLogList[i].slid.toString());
- });
- return serviceLogList;
- };
- /*
- * 根据ID获得客户信息
- * */
- serviceLog.findById=async function(cid,attributes){
- if(!hash.isNotANumber(cid)){
- cid=hash.hashDecode(cid);
- if(!hash.isNotANumber(cid)){
- return [];
- }
- }
- //console.log(cid);
- if(hash.isExistence(attributes)){
- condition.attributes=attributes;
- }
- var condition={
- raw:true,
- where: {
- cid: cid
- }};
- var detail = await this.findOne(condition);
- if(!hash.isExistence(detail)){
- return [];
- }
- var staffDetail=[];
- var sqlQuery = 'SELECT b.* FROM CLD_client_staff as a left join CLD_staff as b on (a.sid=b.sid) where a.cid=?';
- await sequelize.query(sqlQuery,
- { replacements: [cid], type: sequelize.QueryTypes.SELECT }
- ).then(function(results) {
- staffDetail=results[0];
- })
- // await this.sequelize.query('SELECT b.* FROM CLD_client_staff as a left join CLD_staff as b on (a.sid=b.sid) where a.cid=7').spread((results, metadata) => {
- // staffDetail=results[0];
- // });
- detail['staff']=staffDetail;
- detail.cidKey=hash.hashEncode(detail.cid.toString());
- detail.cid=hash.hashEncode(detail.cid.toString());
- return detail;
- };
- /*
- * 根据ID合集获得客户信息
- * */
- serviceLog.getClentListByClientname=async function(clientname,attributes){
- if(!hash.isExistence(clientname)){
- return [];
- }
- //
- var condition={
- raw:true,
- limit:30,
- where: {
- clientname: {
- [Op.like]: '%'+clientname+'%'
- }
- }};
- if(hash.isExistence(attributes)){
- condition.attributes=attributes;
- };
- var clientList = await this.findAll(condition);
- clientList.forEach(function(v,i){
- clientList[i].cidKey=hash.hashEncode(clientList[i].cid.toString());
- });
- return clientList;
- };
- /*
- * 根据ID合集获得客户信息
- * */
- serviceLog.getClentListByPhone=async function(phone,attributes){
- if(!hash.isExistence(phone)){
- return [];
- }
- //
- var condition={
- raw:true,
- limit:30,
- where: {
- telephone: {
- [Op.like]: '%'+phone+'%'
- }
- }};
- if(hash.isExistence(attributes)){
- condition.attributes=attributes;
- };
- var clientList = await this.findAll(condition);
- clientList.forEach(function(v,i){
- clientList[i].cidKey=hash.hashEncode(clientList[i].cid.toString());
- });
- return clientList;
- };
- return serviceLog;
- };
|