Manage.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. namespace Passport\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. public function updateAddress($id, $name, $param)
  7. {
  8. $area = Dever::param('area', $param);
  9. if ($area && is_array($area)) {
  10. $update['where_id'] = $id;
  11. $update['province'] = $area[0];
  12. $update['city'] = $area[1];
  13. $update['county'] = isset($area[2]) ? $area[2] : '';
  14. $update['town'] = isset($area[3]) ? $area[3] : '';
  15. $update['address'] = Dever::load("area/api.string", implode(',', $area), '');
  16. Dever::db('passport/address')->update($update);
  17. }
  18. }
  19. # 同步将其他地方的分类更新为system
  20. public function updateSystem($id, $name, $param)
  21. {
  22. $name = Dever::param('name', $param);
  23. $appid = Dever::param('appid', $param);
  24. $appsecret = Dever::param('appsecret', $param);
  25. $data['name'] = $name;
  26. if ($appid && $appsecret) {
  27. $data['appid'] = $appid;
  28. $data['secret'] = $appsecret;
  29. }
  30. $info = Dever::db('passport/system')->one($id);
  31. if (!$info) {
  32. Dever::db('passport/system')->insert($data);
  33. } else {
  34. $data['where_id'] = $info['id'];
  35. $data['state'] = Dever::param('state', $param);
  36. if (!$name) {
  37. unset($data['name']);
  38. };
  39. Dever::db('passport/system')->update($data);
  40. }
  41. return $info;
  42. }
  43. public function show($id)
  44. {
  45. $db = Dever::db('passport/user');
  46. $user = $db->one($id);
  47. $config = $db->config;
  48. if ($user['avatar']) {
  49. $table['头像'] = '<img src="'.$user['avatar'].'" width="150" />';
  50. } elseif ($user['avatar_id'] > 0) {
  51. $avatar = Dever::db('passport/avatar')->one($user['avatar_id']);
  52. if ($avatar) {
  53. $table['头像'] = '<img src="'.$avatar['avatar'].'" width="150" />';
  54. }
  55. }
  56. if ($user['area']) {
  57. $table['地区'] = $user['area'];
  58. }
  59. if (isset($user['address']) && $user['address']) {
  60. $table['详细地址'] = $user['address'];
  61. }
  62. if ($user['system_source']) {
  63. $table['来源'] = $config['system_source'][$user['system_source']];
  64. } elseif ($user['source_type']) {
  65. $table['来源'] = $config['source_type'][$user['source_type']];
  66. }
  67. if ($user['profession']) {
  68. $profession = Dever::db('passport/profession')->one($user['profession']);
  69. if ($profession) {
  70. $table['职业'] = $profession['name'];
  71. }
  72. }
  73. if ($user['sex']) {
  74. $table['性别'] = $config['sex'][$user['sex']];
  75. }
  76. if ($user['wechat']) {
  77. $table['微信号'] = $user['wechat'];
  78. }
  79. if ($user['email']) {
  80. $table['邮箱'] = $user['email'];
  81. }
  82. if (Dever::project('invite')) {
  83. $invite = Dever::db('invite/code')->one(array('uid' => $user['id']));
  84. if ($invite) {
  85. $table['邀请码'] = $invite['value'];
  86. }
  87. }
  88. return Dever::table($table);
  89. }
  90. public function showAvatar($id)
  91. {
  92. $db = Dever::db('passport/avatar');
  93. $user = $db->one($id);
  94. if ($user['avatar']) {
  95. $table['头像'] = '<img src="'.$user['avatar'].'" width="150" />';
  96. }
  97. return Dever::table($table);
  98. }
  99. public function search_api()
  100. {
  101. $table = 'passport/user';
  102. $keyword = Dever::input('keyword');
  103. $yes = Dever::input('yes');
  104. $where = array();
  105. $cate = Dever::input('cate');
  106. if ($cate) {
  107. $where['cate_id'] = $cate;
  108. }
  109. if ($yes) {
  110. $yes = Dever::db($table)->search(array('ids' => $yes));
  111. }
  112. if (!$keyword) {
  113. $where['limit'] = '0,10';
  114. $data = Dever::db($table)->search($where);
  115. } else {
  116. $where['username'] = $keyword;
  117. $data = Dever::db($table)->search($where);
  118. }
  119. $result = array();
  120. if ($yes) {
  121. foreach ($yes as $k => $v) {
  122. if (isset($data[$k])) {
  123. unset($data[$k]);
  124. }
  125. $yes[$k]['selected'] = 'selected';
  126. }
  127. $data = $yes + $data;
  128. $data = array_merge($data, array());
  129. } else {
  130. $data = array_merge($data, array());
  131. }
  132. if (!$data) {
  133. Dever::alert('暂无数据');
  134. }
  135. return $data;
  136. }
  137. # 获取环比增长
  138. public function getHb($user, $day)
  139. {
  140. $where = array('day' => Dever::maketime($day));
  141. $search = Dever::search_button();
  142. if ($search) {
  143. $where['config']['group'] = $search[0];
  144. $where['config']['col'] = str_replace('|id', '', $search[1]);
  145. }
  146. $prev = Dever::db('passport/stat')->prev($where);
  147. if ($prev) {
  148. $hb = round(($user-$prev['user'])/$prev['user'], 2)*100;
  149. } else {
  150. $hb = 0;
  151. }
  152. return $hb . '%';
  153. }
  154. }