clientStaff.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 clientStaff = sequelize.define('CLD_client_staff', {
  10. csid : {type: DataTypes.INTEGER(11), primaryKey: true, autoIncrement: true},
  11. sid: DataTypes.INTEGER,
  12. cid: DataTypes.INTEGER,
  13. }, {});
  14. /*
  15. * 根据ID合集获得客户信息
  16. * */
  17. clientStaff.findByCid=async function(cid,attributes){
  18. /*if(!hash.isNotANumber(cid)){
  19. cid=hash.hashDecode(cid);
  20. if(!hash.isNotANumber(cid)){
  21. return [];
  22. }
  23. }
  24. if(hash.isExistence(attributes)){
  25. condition.attributes=attributes;
  26. }
  27. var condition={
  28. raw:true,
  29. where: {
  30. cid: cid
  31. }};
  32. var detail = await this.findOne(condition);
  33. if(!hash.isExistence(detail)){
  34. return [];
  35. }
  36. detail.cid=hash.hashEncode(detail.cid.toString());
  37. detail.sid=hash.hashEncode(detail.sid.toString());
  38. detail.csid=hash.hashEncode(detail.csid.toString());
  39. return detail;*/
  40. };
  41. /*
  42. * 根据ID获得客户信息
  43. * */
  44. clientStaff.findById=async function(cid,attributes){
  45. if(!hash.isNotANumber(cid)){
  46. cid=hash.hashDecode(cid);
  47. if(!hash.isNotANumber(cid)){
  48. return [];
  49. }
  50. }
  51. if(hash.isExistence(attributes)){
  52. condition.attributes=attributes;
  53. }
  54. var condition={
  55. raw:true,
  56. where: {
  57. cid: cid
  58. }};
  59. var detail = await this.findOne(condition);
  60. if(!hash.isExistence(detail)){
  61. return [];
  62. }
  63. detail.cidKey=hash.hashEncode(detail.cid.toString());
  64. detail.cid=hash.hashEncode(detail.cid.toString());
  65. return detail;
  66. };
  67. return clientStaff;
  68. };