account.table.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 AccountTable extends We7Table {
  8. protected $tableName = 'uni_account';
  9. protected $primaryKey = 'acid';
  10. public function baseaccount() {
  11. return $this->hasOne('baseaccount', 'acid', 'default_acid');
  12. }
  13. public function menus() {
  14. return $this->hasMany('menu', 'uniacid', 'uniacid');
  15. }
  16. public function unigroup() {
  17. return $this->belongsMany('unigroup', 'id', 'uniacid', 'uni_account_group', 'groupid' ,'uniacid');
  18. }
  19. public function searchAccountList($expire = false) {
  20. global $_W;
  21. $this->query->from('uni_account', 'a')->select('a.uniacid')->leftjoin('account', 'b')
  22. ->on(array('a.uniacid' => 'b.uniacid', 'a.default_acid' => 'b.acid'))
  23. ->where('b.isdeleted !=', '1');
  24. if (!user_is_founder($_W['uid']) || user_is_vice_founder()) {
  25. $this->query->leftjoin('uni_account_users', 'c')->on(array('a.uniacid' => 'c.uniacid'))
  26. ->where('a.default_acid !=', '0')->where('c.uid', $_W['uid']);
  27. } else {
  28. $this->query->where('a.default_acid !=', '0');
  29. }
  30. if (!empty($expire)) {
  31. $this->searchWithExprie();
  32. }
  33. $this->accountUniacidOrder();
  34. $list = $this->query->getall('uniacid');
  35. return $list;
  36. }
  37. public function userOwnedAccount($uid = 0) {
  38. global $_W;
  39. $uid = intval($uid) > 0 ? intval($uid) : $_W['uid'];
  40. $is_founder = user_is_founder($uid);
  41. if (empty($is_founder) || user_is_vice_founder($uid)) {
  42. $users_table = table('users');
  43. $uniacid_list = $users_table->userOwnedAccount($uid);
  44. if (empty($uniacid_list)) {
  45. return array();
  46. }
  47. $this->query->where('u.uniacid', $uniacid_list);
  48. }
  49. return $this->query->from('uni_account', 'u')->leftjoin('account', 'a')->on(array('u.default_acid' => 'a.acid'))->where('a.isdeleted', 0)->getall('uniacid');
  50. }
  51. public function accountWechatsInfo($uniacids, $uid) {
  52. return $this->query->from('uni_account', 'a')
  53. ->leftjoin('account_wechats', 'w')
  54. ->on(array('w.uniacid' => 'a.uniacid'))
  55. ->leftjoin('uni_account_users', 'au')
  56. ->on(array('a.uniacid' => 'au.uniacid'))
  57. ->where(array('a.uniacid' => $uniacids))
  58. ->where(array('au.uid' => $uid))
  59. ->orderby('a.uniacid', 'asc')
  60. ->getall('acid');
  61. }
  62. public function accountWxappInfo($uniacids, $uid) {
  63. return $this->query->from('uni_account', 'a')
  64. ->leftjoin('account_wxapp', 'w')
  65. ->on(array('w.uniacid' => 'a.uniacid'))
  66. ->leftjoin('uni_account_users', 'au')
  67. ->on(array('a.uniacid' => 'au.uniacid'))
  68. ->where(array('a.uniacid' => $uniacids))
  69. ->where(array('au.uid' => $uid))
  70. ->orderby('a.uniacid', 'asc')
  71. ->getall('acid');
  72. }
  73. public function accountWebappInfo($uniacids, $uid) {
  74. return $this->query->from('uni_account', 'a')
  75. ->leftjoin('account_webapp', 'w')
  76. ->on(array('w.uniacid' => 'a.uniacid'))
  77. ->leftjoin('uni_account_users', 'au')
  78. ->on(array('a.uniacid' => 'au.uniacid'))
  79. ->where(array('a.uniacid' => $uniacids))
  80. ->where(array('au.uid' => $uid))
  81. ->orderby('a.uniacid', 'asc')
  82. ->getall('acid');
  83. }
  84. public function accountPhoneappInfo($uniacids, $uid) {
  85. return $this->query->from('uni_account', 'a')
  86. ->leftjoin('account_phoneapp', 'w')
  87. ->on(array('w.uniacid' => 'a.uniacid'))
  88. ->leftjoin('uni_account_users', 'au')
  89. ->on(array('a.uniacid' => 'au.uniacid'))
  90. ->where(array('a.uniacid' => $uniacids))
  91. ->where(array('au.uid' => $uid))
  92. ->orderby('a.uniacid', 'asc')
  93. ->getall('acid');
  94. }
  95. public function searchWithKeyword($title) {
  96. $this->query->where('a.name LIKE', "%{$title}%");
  97. return $this;
  98. }
  99. public function searchWithTitle($title) {
  100. $this->query->where('a.name', $title);
  101. return $this;
  102. }
  103. public function searchWithType($types = array()) {
  104. $this->query->where(array('b.type' => $types));
  105. return $this;
  106. }
  107. public function searchWithLetter($letter) {
  108. if (!empty($letter)) {
  109. $this->query->where('a.title_initial', $letter);
  110. } else {
  111. $this->query->where('a.title_initial', '');
  112. }
  113. return $this;
  114. }
  115. public function accountRankOrder() {
  116. $this->query->orderby('a.rank', 'desc');
  117. return $this;
  118. }
  119. public function accountUniacidOrder($order = 'desc') {
  120. $order = !empty($order) ? $order : 'desc';
  121. $this->query->orderby('a.uniacid', $order);
  122. return $this;
  123. }
  124. public function searchWithNoconnect() {
  125. $this->query->where('b.isconnect =', '0');
  126. return $this;
  127. }
  128. public function searchWithExprie() {
  129. global $_W;
  130. if (user_is_founder($_W['uid']) && !user_is_vice_founder()) {
  131. $this->query->leftjoin('uni_account_users', 'c')->on(array('a.uniacid' => 'c.uniacid'));
  132. $this->query->leftjoin('users', 'u')->on(array('c.uid' => 'u.uid'))
  133. ->where('c.role', 'owner')->where('u.endtime !=', 0)->where('u.endtime <', TIMESTAMP);
  134. }
  135. return $this;
  136. }
  137. public function getWechatappAccount($acid) {
  138. return $this->query->from('account_wechats')->where('acid', $acid)->get();
  139. }
  140. public function getWxappAccount($acid) {
  141. return $this->query->from('account_wxapp')->where('acid', $acid)->get();
  142. }
  143. public function getWebappAccount($acid) {
  144. return $this->query->from('account_webapp')->where('acid', $acid)->get();
  145. }
  146. public function getPhoneappAccount($acid) {
  147. return $this->query->from('account_phoneapp')->where('acid', $acid)->get();
  148. }
  149. public function getUniAccountByAcid($acid) {
  150. $account = $this->query->from('account')->where('acid', $acid)->get();
  151. $uniaccount = array();
  152. if (!empty($account)) {
  153. $uniaccount = $this->query->from('uni_account')->where('uniacid', $account['uniacid'])->get();
  154. }
  155. if (empty($account)) {
  156. return array();
  157. } else {
  158. return array_merge($account, $uniaccount);
  159. }
  160. }
  161. public function getUniAccountByUniacid($uniacid) {
  162. $account = $this->getAccountByUniacid($uniacid);
  163. $uniaccount = array();
  164. if (!empty($account)) {
  165. $uniaccount = $this->query->from('uni_account')->where('uniacid', $account['uniacid'])->get();
  166. }
  167. if (empty($account)) {
  168. return array();
  169. } else {
  170. return !empty($uniaccount) && is_array($uniaccount) ? array_merge($account, $uniaccount) : $account;
  171. }
  172. }
  173. public function getAccountOwner($uniacid) {
  174. if (empty($uniacid)) {
  175. return array();
  176. }
  177. $owneruid = $this->query->from('uni_account_users')->where(array('uniacid' => $uniacid, 'role' => ACCOUNT_MANAGE_NAME_OPERATOR))->getcolumn('uid');
  178. if (empty($owneruid)) {
  179. return array();
  180. }
  181. return table('users')->usersInfo($owneruid);
  182. }
  183. public function getAccountByUniacid($uniacid) {
  184. return $this->query->from('account')->where('uniacid', $uniacid)->get();
  185. }
  186. public function getAccountExtraPermission($uniacid) {
  187. if (empty($uniacid)) {
  188. return array();
  189. }
  190. $result = $this->query->from('uni_group')->where('uniacid', $uniacid)->get();
  191. if (!empty($result)) {
  192. $result['modules'] = iunserializer($result['modules']);
  193. $result['templates'] = iunserializer($result['templates']);
  194. } else {
  195. $result = array();
  196. }
  197. return $result;
  198. }
  199. }