client.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /**
  2. * Created by MyPC on 2019/11/5.
  3. */
  4. 'use strict';
  5. const hash= require('../class/hash');
  6. const Sequelize = require('sequelize');
  7. const Op = Sequelize.Op;
  8. module.exports = (sequelize, DataTypes) => {
  9. const client = sequelize.define('CLD_client', {
  10. cid : {type: DataTypes.INTEGER(11), primaryKey: true, autoIncrement: true},
  11. clientname: DataTypes.STRING,
  12. companyid: DataTypes.INTEGER,
  13. companyname: DataTypes.STRING,
  14. position: DataTypes.STRING,
  15. telephone: DataTypes.STRING,
  16. gender: DataTypes.STRING,
  17. nicename: DataTypes.STRING,
  18. qq: DataTypes.INTEGER(15),
  19. phone: DataTypes.STRING,
  20. email: DataTypes.STRING,
  21. area: DataTypes.STRING,
  22. keynum: DataTypes.STRING,
  23. unit: DataTypes.STRING,
  24. nature: DataTypes.STRING,
  25. local: DataTypes.STRING,
  26. fax: DataTypes.STRING,
  27. webservice: DataTypes.STRING,
  28. department: DataTypes.STRING,
  29. office: DataTypes.STRING,
  30. address: DataTypes.STRING,
  31. district: DataTypes.STRING,
  32. tag: DataTypes.STRING,
  33. //tooltip: DataTypes.STRING,
  34. ride: DataTypes.STRING,
  35. stay: DataTypes.STRING,
  36. landmarks: DataTypes.STRING,
  37. mark: DataTypes.STRING,
  38. priority: DataTypes.STRING,
  39. updatetime: DataTypes.INTEGER(11),
  40. createTime:DataTypes.DATE,
  41. servicetime: DataTypes.INTEGER(11),
  42. }, {});
  43. /*
  44. * 根据ID合集获得客户信息
  45. * */
  46. client.findAllInCid=async function(cid,attributes){
  47. if(cid==undefined){
  48. return [];
  49. }
  50. var condition={
  51. raw:true,
  52. where: {
  53. cid: {
  54. [Op.or]: [cid]
  55. }
  56. }};
  57. if(attributes!=undefined){
  58. condition.attributes=attributes;
  59. }
  60. var clientList = await this.findAll(condition);
  61. clientList.forEach(function(v,i){
  62. clientList[i].cidKey=hash.hashEncode(clientList[i].cid.toString());
  63. //console.log(clientList[i].dataValues.cidKey);
  64. //console.log(hash.hashDecode(clientList[i].dataValues.cidKey.toString()));
  65. });
  66. return clientList;
  67. };
  68. /*
  69. * 根据ID获得客户信息
  70. * */
  71. client.findById=async function(cid,attributes){
  72. if(!hash.isNotANumber(cid)){
  73. cid=hash.hashDecode(cid);
  74. if(!hash.isNotANumber(cid)){
  75. return [];
  76. }
  77. }
  78. //console.log(cid);
  79. if(hash.isExistence(attributes)){
  80. condition.attributes=attributes;
  81. }
  82. var condition={
  83. raw:true,
  84. where: {
  85. cid: cid
  86. }};
  87. var detail = await this.findOne(condition);
  88. if(!hash.isExistence(detail)){
  89. return [];
  90. }
  91. var staffDetail=[];
  92. 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) => {
  93. staffDetail=results[0];
  94. });
  95. detail['staff']=staffDetail;
  96. detail.cidKey=hash.hashEncode(detail.cid.toString());
  97. detail.cid=hash.hashEncode(detail.cid.toString());
  98. return detail;
  99. };
  100. /*
  101. * 根据ID合集获得客户信息
  102. * */
  103. client.getClentListByClientname=async function(clientname,attributes){
  104. if(!hash.isExistence(clientname)){
  105. return [];
  106. }
  107. //
  108. var condition={
  109. raw:true,
  110. limit:30,
  111. where: {
  112. clientname: {
  113. [Op.like]: '%'+clientname+'%'
  114. }
  115. }};
  116. if(hash.isExistence(attributes)){
  117. condition.attributes=attributes;
  118. };
  119. var clientList = await this.findAll(condition);
  120. clientList.forEach(function(v,i){
  121. clientList[i].cidKey=hash.hashEncode(clientList[i].cid.toString());
  122. });
  123. return clientList;
  124. };
  125. return client;
  126. };