member.table.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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) {
  9. if ($is_available) {
  10. $this->query->where('a.available', 1);
  11. }
  12. return $this->query->from('mc_member_fields', 'a')->leftjoin('profile_fields', 'b')->on('a.fieldid', 'b.id')->where('a.uniacid', $uniacid)->select(array('a.title', 'b.field'))->getall('field');
  13. }
  14. public function emailExist($uid, $email) {
  15. load()->model('mc');
  16. if (empty($email)) {
  17. return false;
  18. }
  19. $this->query->from('mc_members')->where('uniacid', mc_current_real_uniacid())->where('email', trim($email));
  20. if (!empty($uid)) {
  21. $this->query->where('uid <>', $uid);
  22. }
  23. $emailexists = $this->query->getcolumn('email');
  24. if ($emailexists) {
  25. return true;
  26. } else {
  27. return false;
  28. }
  29. }
  30. public function mobileExist($uid, $mobile) {
  31. load()->model('mc');
  32. if (empty($mobile)) {
  33. return false;
  34. }
  35. $this->query->from('mc_members')->where('uniacid', mc_current_real_uniacid())->where('mobile', trim($mobile));
  36. if (!empty($uid)) {
  37. $this->query->where('uid <>', $uid);
  38. }
  39. $mobilexists = $this->query->getcolumn('mobile');
  40. if ($mobilexists) {
  41. return true;
  42. } else {
  43. return false;
  44. }
  45. }
  46. public function updateMember($uid, $fields = array()) {
  47. load()->model('mc');
  48. $member = $this->query->from('mc_members')->where('uid', $uid)->get();
  49. if (!empty($fields['email']) && $this->emailExist($uid, $fields['email'])) {
  50. unset($fields['email']);
  51. }
  52. if (!empty($fields['mobile']) && $this->mobileExist($uid, $fields['mobile'])) {
  53. unset($fields['mobile']);
  54. }
  55. if (empty($member)) {
  56. if(empty($fields['mobile']) && empty($fields['email'])) {
  57. return false;
  58. }
  59. $fields['uniacid'] = mc_current_real_uniacid();
  60. $fields['createtime'] = TIMESTAMP;
  61. pdo_insert('mc_members', $fields);
  62. $insert_id = pdo_insertid();
  63. return $insert_id;
  64. } else {
  65. if (!empty($fields)) {
  66. $result = pdo_update('mc_members', $fields, array('uid' => $uid));
  67. } else {
  68. $result = 0;
  69. }
  70. return $result > 0;
  71. }
  72. }
  73. public function creditsRecordList()
  74. {
  75. global $_W;
  76. $this->query->from('mc_credits_record', 'r')
  77. ->select('r.*, u.username as username')
  78. ->leftjoin('users', 'u')
  79. ->on(array('r.operator' => 'u.uid'))
  80. ->where('r.uniacid', $_W['uniacid']);
  81. $this->query->orderby('r.id', 'desc');
  82. return $this->query->getall();
  83. }
  84. public function searchCreditsRecordUid($uid) {
  85. $this->query->where('r.uid', $uid);
  86. return $this;
  87. }
  88. public function searchCreditsRecordType($type) {
  89. $this->query->where('r.credittype', $type);
  90. return $this;
  91. }
  92. public function searchWithMember() {
  93. return $this->query->from('mc_members')->get();
  94. }
  95. public function searchWithMemberEmail($email) {
  96. $this->query->where('email', $email);
  97. return $this;
  98. }
  99. public function searchWithMobile($mobile) {
  100. $this->query->where('mobile', $mobile);
  101. return $this;
  102. }
  103. public function searchWithRandom($info) {
  104. $this->query->where('mobile', $info)->whereor('email', $info);
  105. return $this;
  106. }
  107. public function mcFieldsList($uniacid) {
  108. return $this->query->from('mc_member_fields', 'm')->select('m.title, m.fieldid, p.field')->leftjoin('profile_fields', 'p')
  109. ->on(array('m.fieldid' => 'p.id'))->where('m.uniacid', $uniacid)->getall('field');
  110. }
  111. }