人人商城

account.table.php 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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. protected $uni_verifycode = 'uni_verifycode';
  11. protected $uniSettings = 'uni_settings';
  12. protected $uniAccountUsers = 'uni_account_users';
  13. public function baseaccount() {
  14. return $this->hasOne('baseaccount', 'acid', 'default_acid');
  15. }
  16. public function menus() {
  17. return $this->hasMany('menu', 'uniacid', 'uniacid');
  18. }
  19. public function unigroup() {
  20. return $this->belongsMany('unigroup', 'id', 'uniacid', 'uni_account_group', 'groupid' ,'uniacid');
  21. }
  22. public function searchAccount($expire, $fields, $founder_id) {
  23. global $_W;
  24. $this->query->from('uni_account', 'a')
  25. ->select($fields)
  26. ->leftjoin('account', 'b')
  27. ->on(array('a.uniacid' => 'b.uniacid', 'a.default_acid' => 'b.acid'))
  28. ->where('b.isdeleted !=', '1')
  29. ->where('a.default_acid !=', '0');
  30. if (!user_is_founder($_W['uid']) || user_is_vice_founder() || !empty($founder_id)) {
  31. $this->query->leftjoin('uni_account_users', 'c')
  32. ->on(array('a.uniacid' => 'c.uniacid'))
  33. ->where('c.uid', empty($founder_id) ? $_W['uid'] : $founder_id);
  34. }
  35. if (!empty($expire)) {
  36. $this->searchWithExprie();
  37. }
  38. return $this;
  39. }
  40. public function searchAccountList($expire = false, $fields = 'a.uniacid', $founder_id = 0) {
  41. $this->searchAccount($expire, $fields, $founder_id);
  42. $list = $this->query->getall('uniacid');
  43. return $list;
  44. }
  45. public function searchAccountListFields($fields = 'a.uniacid',$expire = false) {
  46. $this->searchAccount($expire, $fields, 0);
  47. $this->accountUniacidOrder();
  48. $list = $this->query->getall('uniacid');
  49. return $list;
  50. }
  51. public function searchAccounTotal($expire = false, $founder_id = 0) {
  52. $this->searchAccount($expire, 'count(*) as total, b.type', $founder_id);
  53. $this->query->groupby('b.type');
  54. $list = $this->query->getall();
  55. return $list;
  56. }
  57. public function userOwnedAccount($uid = 0) {
  58. global $_W;
  59. $uid = intval($uid) > 0 ? intval($uid) : $_W['uid'];
  60. $is_founder = user_is_founder($uid, true);
  61. if (empty($is_founder)) {
  62. $users_table = table('users');
  63. $uniacid_list = $users_table->userOwnedAccount($uid);
  64. if (empty($uniacid_list)) {
  65. return array();
  66. }
  67. $this->query->where('u.uniacid', $uniacid_list);
  68. }
  69. return $this->query->from('uni_account', 'u')->leftjoin('account', 'a')->on(array('u.default_acid' => 'a.acid'))->where('a.isdeleted', 0)->getall('uniacid');
  70. }
  71. public function accountWechatsInfo($uniacids, $uid) {
  72. return $this->query->from('uni_account', 'a')
  73. ->leftjoin('account_wechats', 'w')
  74. ->on(array('w.uniacid' => 'a.uniacid'))
  75. ->leftjoin('uni_account_users', 'au')
  76. ->on(array('a.uniacid' => 'au.uniacid'))
  77. ->where(array('a.uniacid' => $uniacids))
  78. ->where(array('au.uid' => $uid))
  79. ->orderby('a.uniacid', 'asc')
  80. ->getall('acid');
  81. }
  82. public function accountWxappInfo($uniacids, $uid) {
  83. return $this->query->from('uni_account', 'a')
  84. ->leftjoin('account_wxapp', 'w')
  85. ->on(array('w.uniacid' => 'a.uniacid'))
  86. ->leftjoin('uni_account_users', 'au')
  87. ->on(array('a.uniacid' => 'au.uniacid'))
  88. ->where(array('a.uniacid' => $uniacids))
  89. ->where(array('au.uid' => $uid))
  90. ->orderby('a.uniacid', 'asc')
  91. ->getall('acid');
  92. }
  93. public function accountWebappInfo($uniacids, $uid) {
  94. return $this->query->from('uni_account', 'a')
  95. ->leftjoin('account_webapp', 'w')
  96. ->on(array('w.uniacid' => 'a.uniacid'))
  97. ->leftjoin('uni_account_users', 'au')
  98. ->on(array('a.uniacid' => 'au.uniacid'))
  99. ->where(array('a.uniacid' => $uniacids))
  100. ->where(array('au.uid' => $uid))
  101. ->orderby('a.uniacid', 'asc')
  102. ->getall('acid');
  103. }
  104. public function accountPhoneappInfo($uniacids, $uid) {
  105. return $this->query->from('uni_account', 'a')
  106. ->leftjoin('account_phoneapp', 'w')
  107. ->on(array('w.uniacid' => 'a.uniacid'))
  108. ->leftjoin('uni_account_users', 'au')
  109. ->on(array('a.uniacid' => 'au.uniacid'))
  110. ->where(array('a.uniacid' => $uniacids))
  111. ->where(array('au.uid' => $uid))
  112. ->orderby('a.uniacid', 'asc')
  113. ->getall('acid');
  114. }
  115. public function accountXzappInfo($uniacids, $uid) {
  116. return $this->query->from('uni_account', 'a')
  117. ->leftjoin('account_xzapp', 'w')
  118. ->on(array('w.uniacid' => 'a.uniacid'))
  119. ->leftjoin('uni_account_users', 'au')
  120. ->on(array('a.uniacid' => 'au.uniacid'))
  121. ->where(array('a.uniacid' => $uniacids))
  122. ->where(array('au.uid' => $uid))
  123. ->orderby('a.uniacid', 'asc')
  124. ->getall('acid');
  125. }
  126. public function searchWithKeyword($title) {
  127. if (empty($title)) {
  128. return $this;
  129. }
  130. $this->query->where('a.name LIKE', "%{$title}%");
  131. return $this;
  132. }
  133. public function searchWithTitle($title) {
  134. $this->query->where('a.name', $title);
  135. return $this;
  136. }
  137. public function searchWithType($types = array()) {
  138. $this->query->where(array('b.type' => $types));
  139. return $this;
  140. }
  141. public function searchWithLetter($letter) {
  142. if (!empty($letter) && strlen($letter) == 1) {
  143. $this->query->where('a.title_initial', $letter);
  144. }
  145. return $this;
  146. }
  147. public function accountRankOrder() {
  148. $this->query->orderby('a.rank', 'desc');
  149. return $this;
  150. }
  151. public function accountUniacidOrder($order = 'desc') {
  152. $order = !empty($order) ? $order : 'desc';
  153. $this->query->orderby('a.uniacid', $order);
  154. return $this;
  155. }
  156. public function searchWithNoconnect() {
  157. $this->query->where('b.isconnect =', '0');
  158. return $this;
  159. }
  160. public function searchWithExprie() {
  161. global $_W;
  162. if (user_is_founder($_W['uid']) && !user_is_vice_founder()) {
  163. $this->query->leftjoin('uni_account_users', 'c')->on(array('a.uniacid' => 'c.uniacid'));
  164. $this->query->leftjoin('users', 'u')->on(array('c.uid' => 'u.uid'))
  165. ->where('c.role', 'owner')->where('u.endtime !=', 0)->where('u.endtime <', TIMESTAMP);
  166. }
  167. return $this;
  168. }
  169. public function getWechatappAccount($acid) {
  170. return $this->query->from('account_wechats')->where('acid', $acid)->get();
  171. }
  172. public function getWxappAccount($acid) {
  173. return $this->query->from('account_wxapp')->where('acid', $acid)->get();
  174. }
  175. public function getWebappAccount($acid) {
  176. return $this->query->from('account_webapp')->where('acid', $acid)->get();
  177. }
  178. public function getPhoneappAccount($acid) {
  179. return $this->query->from('account_phoneapp')->where('acid', $acid)->get();
  180. }
  181. public function getUniAccountByAcid($acid) {
  182. $account = $this->query->from('account')->where('acid', $acid)->get();
  183. $uniaccount = array();
  184. if (!empty($account)) {
  185. $uniaccount = $this->query->from('uni_account')->where('uniacid', $account['uniacid'])->get();
  186. }
  187. if (empty($account)) {
  188. return array();
  189. } else {
  190. return array_merge($account, $uniaccount);
  191. }
  192. }
  193. public function getUniAccountByUniacid($uniacid) {
  194. $account = $this->getAccountByUniacid($uniacid);
  195. $uniaccount = array();
  196. if (!empty($account)) {
  197. $uniaccount = $this->query->from('uni_account')->where('uniacid', $account['uniacid'])->get();
  198. }
  199. if (empty($account)) {
  200. return array();
  201. } else {
  202. return !empty($uniaccount) && is_array($uniaccount) ? array_merge($account, $uniaccount) : $account;
  203. }
  204. }
  205. public function accountGroupModules($uniacid, $type = '') {
  206. $packageids = $this->query->from('uni_account_group')->where('uniacid', $uniacid)->select('groupid')->getall('groupid');
  207. $packageids = empty($packageids) ? array() : array_keys($packageids);
  208. if (in_array('-1', $packageids)) {
  209. $modules = $this->query->from('modules')->select('name')->getall('name');
  210. return array_keys($modules);
  211. }
  212. $uni_modules = array();
  213. $site_store_buy_package = table('store')->searchUserBuyPackage($uniacid);
  214. $packageids = array_merge($packageids, array_keys($site_store_buy_package));
  215. $uni_groups = $this->query->from('uni_group')->where('uniacid', $uniacid)->whereor('id', $packageids)->getall('modules');
  216. if (!empty($uni_groups)) {
  217. if (empty($type)) {
  218. $account = $this->getAccountByUniacid($uniacid);
  219. $type = $account['type'];
  220. }
  221. foreach ($uni_groups as $group) {
  222. $group_module = (array)iunserializer($group['modules']);
  223. if (empty($group_module)) {
  224. continue;
  225. }
  226. switch ($type) {
  227. case ACCOUNT_TYPE_OFFCIAL_NORMAL:
  228. case ACCOUNT_TYPE_OFFCIAL_AUTH:
  229. $uni_modules = is_array($group_module['modules']) ? array_merge($group_module['modules'], $uni_modules) : $uni_modules;
  230. break;
  231. case ACCOUNT_TYPE_APP_NORMAL:
  232. case ACCOUNT_TYPE_APP_AUTH:
  233. case ACCOUNT_TYPE_WXAPP_WORK:
  234. $uni_modules = is_array($group_module['wxapp']) ? array_merge($group_module['wxapp'], $uni_modules) : $uni_modules;
  235. break;
  236. case ACCOUNT_TYPE_WEBAPP_NORMAL:
  237. $uni_modules = is_array($group_module['webapp']) ? array_merge($group_module['webapp'], $uni_modules) : $uni_modules;
  238. break;
  239. case ACCOUNT_TYPE_XZAPP_NORMAL:
  240. case ACCOUNT_TYPE_XZAPP_AUTH:
  241. $uni_modules = is_array($group_module['xzapp']) ? array_merge($group_module['xzapp'], $uni_modules) : $uni_modules;
  242. break;
  243. case ACCOUNT_TYPE_PHONEAPP_NORMAL:
  244. $uni_modules = is_array($group_module['phoneapp']) ? array_merge($group_module['phoneapp'], $uni_modules) : $uni_modules;
  245. break;
  246. case ACCOUNT_TYPE_ALIAPP_NORMAL:
  247. $uni_modules = is_array($group_module['aliapp']) ? array_merge($group_module['aliapp'], $uni_modules) : $uni_modules;
  248. break;
  249. }
  250. }
  251. $uni_modules = array_unique($uni_modules);
  252. }
  253. return $uni_modules;
  254. }
  255. public function getAccountOwner($uniacid) {
  256. if (empty($uniacid)) {
  257. return array();
  258. }
  259. $owneruid = $this->query->from('uni_account_users')->where(array('uniacid' => $uniacid, 'role' => ACCOUNT_MANAGE_NAME_OPERATOR))->getcolumn('uid');
  260. if (empty($owneruid)) {
  261. return array();
  262. }
  263. return table('users')->usersInfo($owneruid);
  264. }
  265. public function getAccountByUniacid($uniacid) {
  266. return $this->query->from('account')->where('uniacid', $uniacid)->get();
  267. }
  268. public function getAccountExtraPermission($uniacid) {
  269. if (empty($uniacid)) {
  270. return array();
  271. }
  272. $result = $this->query->from('uni_group')->where('uniacid', $uniacid)->get();
  273. if (!empty($result)) {
  274. $result['templates'] = iunserializer($result['templates']);
  275. $group_module = (array)iunserializer($result['modules']);
  276. if (empty($group_module)) {
  277. $result['modules'] = array();
  278. } else {
  279. $account = $this->getAccountByUniacid($uniacid);
  280. switch ($account['type']) {
  281. case ACCOUNT_TYPE_OFFCIAL_NORMAL:
  282. case ACCOUNT_TYPE_OFFCIAL_AUTH:
  283. $result['modules'] = $group_module['modules'];
  284. break;
  285. case ACCOUNT_TYPE_APP_NORMAL:
  286. case ACCOUNT_TYPE_APP_AUTH:
  287. case ACCOUNT_TYPE_WXAPP_WORK:
  288. $result['modules'] = $group_module['wxapp'];
  289. break;
  290. case ACCOUNT_TYPE_WEBAPP_NORMAL:
  291. $result['modules'] = $group_module['webapp'];
  292. break;
  293. case ACCOUNT_TYPE_XZAPP_NORMAL:
  294. case ACCOUNT_TYPE_XZAPP_AUTH:
  295. $result['modules'] = $group_module['xzapp'];
  296. break;
  297. case ACCOUNT_TYPE_PHONEAPP_NORMAL:
  298. $result['modules'] = $group_module['phoneapp'];
  299. break;
  300. default:
  301. $result['modules'] = array();
  302. }
  303. }
  304. } else {
  305. $result = array();
  306. }
  307. return $result;
  308. }
  309. public function getUniVerifycode($params) {
  310. global $_W;
  311. $this->query->from($this->uni_verifycode);
  312. if (!empty($params['uniacid'])) {
  313. $this->query->where('uniacid', $params['uniacid']);
  314. }
  315. if (!empty($params['receiver'])) {
  316. $this->query->where('receiver', $params['receiver']);
  317. }
  318. if (!empty($params['createtime >'])) {
  319. $this->query->where('createtime >', $params['createtime >']);
  320. }
  321. if (!empty($params['verifycode'])) {
  322. $this->query->where('verifycode', $params['verifycode']);
  323. }
  324. return $this->query->get();
  325. }
  326. public function getUniSetting() {
  327. return $this->query->from($this->uniSettings)->get();
  328. }
  329. public function getUniAccountList() {
  330. return $this->query->select('uniacid')->from($this->tableName)->getall();
  331. }
  332. public function getOwnerUid() {
  333. return $this->query->from($this->uniAccountUsers)->getcolumn('uid');
  334. }
  335. public function getOwnedAccountCount($uid) {
  336. return $this->query->from($this->uniAccountUsers, 'u')->select('d.type, count(*) as count')->leftjoin($this->tableName, 'a')
  337. ->on(array('u.uniacid' => 'a.uniacid'))->leftjoin('account', 'd')->on(array('a.default_acid' => 'd.acid'))
  338. ->where('u.uid', $uid)->where('u.role', 'owner')->where('d.isdeleted', 0)->groupby('d.type')->getall();
  339. }
  340. }