123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- /**
- * 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 client = sequelize.define('CLD_client', {
- cid : {type: DataTypes.INTEGER(11), primaryKey: true, autoIncrement: true},
- clientname: DataTypes.STRING,
- companyid: DataTypes.INTEGER,
- companyname: DataTypes.STRING,
- position: DataTypes.STRING,
- telephone: DataTypes.STRING,
- gender: DataTypes.STRING,
- nicename: DataTypes.STRING,
- qq: DataTypes.INTEGER(15),
- phone: DataTypes.STRING,
- email: DataTypes.STRING,
- area: DataTypes.STRING,
- keynum: DataTypes.STRING,
- unit: DataTypes.STRING,
- nature: DataTypes.STRING,
- local: DataTypes.STRING,
- fax: DataTypes.STRING,
- webservice: DataTypes.STRING,
- department: DataTypes.STRING,
- office: DataTypes.STRING,
- address: DataTypes.STRING,
- district: DataTypes.STRING,
- tag: DataTypes.STRING,
- //tooltip: DataTypes.STRING,
- ride: DataTypes.STRING,
- stay: DataTypes.STRING,
- landmarks: DataTypes.STRING,
- mark: DataTypes.STRING,
- priority: DataTypes.STRING,
- updatetime: DataTypes.INTEGER(11),
- createTime:DataTypes.DATE,
- servicetime: DataTypes.INTEGER(11),
- }, {});
- /*
- * 根据ID合集获得客户信息
- * */
- client.findAllInCid=async function(cid,attributes){
- if(cid==undefined){
- return [];
- }
- var condition={
- raw:true,
- where: {
- cid: {
- [Op.or]: [cid]
- }
- }};
- if(attributes!=undefined){
- condition.attributes=attributes;
- }
- var clientList = await this.findAll(condition);
- clientList.forEach(function(v,i){
- clientList[i].cidKey=hash.hashEncode(clientList[i].cid.toString());
- //console.log(clientList[i].dataValues.cidKey);
- //console.log(hash.hashDecode(clientList[i].dataValues.cidKey.toString()));
- });
- return clientList;
- };
- /*
- * 根据ID获得客户信息
- * */
- client.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合集获得客户信息
- * */
- client.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合集获得客户信息
- * */
- client.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 client;
- };
|