member.table.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. class MemberTable extends We7Table {
  8. public function accountMemberFields($uniacid, $is_available, $select = array()) {
  9. if ($is_available) {
  10. $this->query->where('a.available', 1);
  11. }
  12. if (empty($select)) {
  13. $select = array('a.title', 'b.field');
  14. }
  15. return $this->query->from('mc_member_fields', 'a')->leftjoin('profile_fields', 'b')->on('a.fieldid', 'b.id')->where('a.uniacid', $uniacid)->select($select)->orderby('displayorder DESC')->getall('field');
  16. }
  17. public function emailExist($uid, $email) {
  18. load()->model('mc');
  19. if (empty($email)) {
  20. return false;
  21. }
  22. $this->query->from('mc_members')->where('uniacid', mc_current_real_uniacid())->where('email', trim($email));
  23. if (!empty($uid)) {
  24. $this->query->where('uid <>', $uid);
  25. }
  26. $emailexists = $this->query->getcolumn('email');
  27. if ($emailexists) {
  28. return true;
  29. } else {
  30. return false;
  31. }
  32. }
  33. public function mobileExist($uid, $mobile) {
  34. load()->model('mc');
  35. if (empty($mobile)) {
  36. return false;
  37. }
  38. $this->query->from('mc_members')->where('uniacid', mc_current_real_uniacid())->where('mobile', trim($mobile));
  39. if (!empty($uid)) {
  40. $this->query->where('uid <>', $uid);
  41. }
  42. $mobilexists = $this->query->getcolumn('mobile');
  43. if ($mobilexists) {
  44. return true;
  45. } else {
  46. return false;
  47. }
  48. }
  49. public function updateMember($uid, $fields = array()) {
  50. load()->model('mc');
  51. $member = $this->query->from('mc_members')->where('uid', $uid)->get();
  52. if (!empty($fields['email']) && $this->emailExist($uid, $fields['email'])) {
  53. unset($fields['email']);
  54. }
  55. if (!empty($fields['mobile']) && $this->mobileExist($uid, $fields['mobile'])) {
  56. unset($fields['mobile']);
  57. }
  58. if (empty($member)) {
  59. if(empty($fields['mobile']) && empty($fields['email'])) {
  60. return false;
  61. }
  62. $fields['uniacid'] = mc_current_real_uniacid();
  63. $fields['createtime'] = TIMESTAMP;
  64. pdo_insert('mc_members', $fields);
  65. $insert_id = pdo_insertid();
  66. return $insert_id;
  67. } else {
  68. if (!empty($fields)) {
  69. $result = pdo_update('mc_members', $fields, array('uid' => $uid));
  70. } else {
  71. $result = 0;
  72. }
  73. return $result > 0;
  74. }
  75. }
  76. public function creditsRecordList()
  77. {
  78. global $_W;
  79. $this->query->from('mc_credits_record', 'r')
  80. ->select('r.*, u.username as username')
  81. ->leftjoin('users', 'u')
  82. ->on(array('r.operator' => 'u.uid'))
  83. ->where('r.uniacid', $_W['uniacid']);
  84. $this->query->orderby('r.id', 'desc');
  85. return $this->query->getall();
  86. }
  87. public function searchCreditsRecordUid($uid) {
  88. $this->query->where('r.uid', $uid);
  89. return $this;
  90. }
  91. public function searchCreditsRecordType($type) {
  92. $this->query->where('r.credittype', $type);
  93. return $this;
  94. }
  95. public function searchWithMember() {
  96. return $this->query->from('mc_members')->get();
  97. }
  98. public function searchWithMemberEmail($email) {
  99. $this->query->where('email', $email);
  100. return $this;
  101. }
  102. public function searchWithMobile($mobile) {
  103. $this->query->where('mobile', $mobile);
  104. return $this;
  105. }
  106. public function searchWithRandom($info) {
  107. $this->query->where('mobile', $info)->whereor('email', $info);
  108. return $this;
  109. }
  110. public function mcFieldsList($uniacid) {
  111. return $this->query->from('mc_member_fields', 'm')->select('m.title, m.fieldid, p.field')->leftjoin('profile_fields', 'p')
  112. ->on(array('m.fieldid' => 'p.id'))->where('m.uniacid', $uniacid)->getall('field');
  113. }
  114. }