customer.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. 'use strict';
  2. /**
  3. * 客户信息数据模型
  4. *
  5. * @author CaiAoLin
  6. * @date 2017/11/14
  7. * @version
  8. */
  9. module.exports = app => {
  10. class Customer extends app.BaseService {
  11. /**
  12. * 构造函数
  13. *
  14. * @param {Object} ctx - egg全局变量
  15. * @return {void}
  16. */
  17. constructor(ctx) {
  18. super(ctx);
  19. this.tableName = 'customer';
  20. }
  21. /**
  22. * 查询过虑
  23. *
  24. * @param {Object} data - 筛选表单中的get数据
  25. * @return {void}
  26. */
  27. searchFilter(data) {
  28. this.initSqlBuilder();
  29. }
  30. /**
  31. * 新增SSO用户
  32. *
  33. * @param {Object} data - 接口返回的数据
  34. * @return {Number} - 返回新增数据的id
  35. */
  36. async addSSOUser(data) {
  37. let result = 0;
  38. if (Object.keys(data).length <= 0 || data.useremail === undefined) {
  39. return result;
  40. }
  41. // 先查找是否存在
  42. const customerData = await this.db.get(this.tableName, { email: data.useremail });
  43. if (customerData !== null) {
  44. // 存在则直接返回id
  45. return customerData.id;
  46. }
  47. const insertData = {
  48. email: data.useremail,
  49. mobile: data.mobile,
  50. name: data.username,
  51. };
  52. result = await this.db.insert(this.tableName, insertData);
  53. return result.insertId;
  54. }
  55. }
  56. return Customer;
  57. };