人人商城

module.table.php 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 ModuleTable extends We7Table {
  8. protected $tableName = 'modules';
  9. protected $primaryKey = 'mid';
  10. protected $modulesRecycle = 'modules_recycle';
  11. public function bindings() {
  12. return $this->hasMany('modulebinding', 'module', 'name');
  13. }
  14. public function getModuleInfo($module, $fields = '*') {
  15. return $this->query->from($this->tableName)->select($fields)->where('name', $module)->get();
  16. }
  17. public function getInstalledModuleInfo($module) {
  18. return $this->query->from('modules', 'a')->leftjoin('modules_recycle', 'b')->on(array('a.name' => 'b.modulename'))->where('a.name', $module)->where('b.modulename', 'NULL')->get();
  19. }
  20. public function moduleBindingsInfo($module, $do = '', $entry = '') {
  21. $condition = array(
  22. 'module' => $module,
  23. 'do' => $do,
  24. );
  25. if (!empty($do)) {
  26. $condition['do'] = $do;
  27. }
  28. if (!empty($entry)) {
  29. $condition['entry'] = $entry;
  30. }
  31. return $this->query->from('modules_bindings')->where($condition)->get();
  32. }
  33. public function moduleLists($package_group_module) {
  34. return $this->query->from('modules')->where('issystem', 1)->whereor('name', $package_group_module)->orderby('mid', 'desc')->getall('name');
  35. }
  36. public function moduleRank($module_name = '') {
  37. global $_W;
  38. $this->query->from('modules_rank')->where('uid', $_W['uid']);
  39. if (!empty($module_name)) {
  40. $this->query->where('module_name', $module_name);
  41. }
  42. return $this->query->getall('module_name');
  43. }
  44. public function moduleMaxRank() {
  45. global $_W;
  46. $rank_info = $this->query->from('modules_rank')->select('max(rank)')->where('uid', $_W['uid'])->get();
  47. return $rank_info['0'];
  48. }
  49. public function moduleSetRankTop($module_name) {
  50. global $_W;
  51. if (empty($module_name)) {
  52. return false;
  53. }
  54. $max_rank = $this->moduleMaxRank();
  55. $exist = $this->moduleRank($module_name);
  56. if (!empty($exist)) {
  57. pdo_update('modules_rank', array('rank' => ($max_rank + 1)), array('module_name' => $module_name));
  58. } else {
  59. pdo_insert('modules_rank', array('uid' => $_W['uid'], 'module_name' => $module_name, 'rank' => ($max_rank + 1)));
  60. }
  61. return true;
  62. }
  63. public function modulesWxappList() {
  64. return $this->query->from('modules')->where('wxapp_support', MODULE_SUPPORT_WXAPP)->getall('mid');
  65. }
  66. public function moduleLinkUniacidInfo($module_name) {
  67. if (empty($module_name)) {
  68. return array();
  69. }
  70. $result = $this->query->from('uni_account_modules')->where('module', $module_name)->getall();
  71. if (!empty($result)) {
  72. foreach ($result as $key => $value) {
  73. $result[$key]['settings'] = iunserializer($value['settings']);
  74. if (empty($result[$key]['settings']) || empty($result[$key]['settings']['link_uniacid'])) {
  75. unset($result[$key]);
  76. }
  77. }
  78. return $result;
  79. }
  80. return array();
  81. }
  82. public function uniAccountModuleInfo($module_name) {
  83. global $_W;
  84. if (empty($module_name)) {
  85. return array();
  86. }
  87. $result = $this->query->from('uni_account_modules')->where('module', $module_name)->where('uniacid', $_W['uniacid'])->get();
  88. if (!empty($result)) {
  89. $result['settings'] = iunserializer($result['settings']);
  90. return $result;
  91. }
  92. return array();
  93. }
  94. public function getModulesList() {
  95. return $this->query->from($this->tableName)->getall('name');
  96. }
  97. public function searchWithType($type, $method = '=') {
  98. if ($method == '=') {
  99. $this->query->where('type', $type);
  100. } else {
  101. $this->query->where('type <>', $type);
  102. }
  103. return $this;
  104. }
  105. public function getInstalledModuleList() {
  106. return $this->query->from($this->tableName, 'a')->leftjoin('modules_recycle', 'b')->on(array('a.name' => 'b.modulename'))->where('b.modulename', 'NULL')->getall('name');
  107. }
  108. public function getModuleRecycle() {
  109. return $this->query->select('modulename')->from($this->modulesRecycle)->getall('modulename');
  110. }
  111. public function getSubscribesModules() {
  112. return $this->query->select('name', 'subscribes')->from($this->tableName)->where('subscribes !=', '')->getall();
  113. }
  114. public function cleanModuleInfo($modulename, $isCleanRule = false) {
  115. $this->query->from('core_queue')->where('module', $modulename)->delete();
  116. $this->query->from($this->tableName)->where('name', $modulename)->delete();
  117. $this->query->from('modules_bindings')->where('module', $modulename)->delete();
  118. if (!empty($isCleanRule)) {
  119. $this->query->from('rule')->where('module', $modulename)->delete();
  120. $this->query->from('rule_keyword')->where('module', $modulename)->delete();
  121. $cover_rule = $this->query->from('cover_reply')->where('module', $modulename)->getall('rid');
  122. if (!empty($cover_rule)) {
  123. $rids = array_keys($cover_rule);
  124. $this->query->from('rule_keyword')->where('module', 'cover')->where('rid', $rids)->delete();
  125. $this->query->from('rule')->where('module', 'cover')->where('id', $rids)->delete();
  126. $this->query->from('cover_reply')->where('module', $modulename)->delete();
  127. }
  128. }
  129. $this->query->from('site_nav')->where('module', $modulename)->delete();
  130. $this->query->from('uni_account_modules')->where('module', $modulename)->delete();
  131. return true;
  132. }
  133. }