Stat.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * 服务提供者
  5. * User: qissen
  6. * Date: 2017/6/7
  7. * Time: 7:36
  8. * 注意调用顺序,checkClientType,checkData必须先调用,才可以验证其他
  9. */
  10. namespace app\core\service;
  11. use app\core\model\Cang;
  12. use app\core\model\User as ModelUser;
  13. use app\core\model\UserRecharge;
  14. use think\Cache;
  15. use think\Db;
  16. use tool\Common;
  17. class Stat
  18. {
  19. public static function getStat() {
  20. //Cache::rm('stat');
  21. $stat = Cache::get('stat');
  22. if(!$stat) {
  23. $stat = [];
  24. $stat += self::getStatToday();
  25. $stat += self::getStatYesterday();
  26. $stat += self::getStatAll();
  27. $stat += self::getStatWeek();
  28. $stat += self::getStatCang30DayList();
  29. Cache::set('stat', $stat, 60);
  30. }
  31. return $stat;
  32. }
  33. public static function getStatToday()
  34. {
  35. $stat = [];
  36. $stat['moneySubjectTotal_today_ios'] = Db::view('cang', 'moneySubject,userID,status,addTime')
  37. ->view('user', 'userID,osType', 'cang.userID=user.userID and user.isForged=0')
  38. ->where('user.osType=1')
  39. ->where('status', 'EGT', Cang::STATUS_PAY)
  40. ->whereTime('addTime', 'today')
  41. ->sum('moneySubject');
  42. $stat['moneySubjectTotal_today_ios'] = number_format($stat['moneySubjectTotal_today_ios'] / 100);
  43. $stat['moneySubjectTotal_today_android'] = Db::view('cang', 'moneySubject,userID,status,addTime')
  44. ->view('user', 'userID,osType', 'cang.userID=user.userID and user.isForged=0')
  45. ->where('user.osType=2')
  46. ->where('status', 'EGT', Cang::STATUS_PAY)
  47. ->whereTime('addTime', 'today')
  48. ->sum('moneySubject');
  49. $stat['moneySubjectTotal_today_android'] = number_format($stat['moneySubjectTotal_today_android'] / 100);
  50. $stat['moneySubjectTotal_today_pc'] = Db::view('cang', 'moneySubject,userID,status,addTime')
  51. ->view('user', 'userID,osType', 'cang.userID=user.userID and user.isForged=0')
  52. ->where('user.osType=3')
  53. ->where('status', 'EGT', Cang::STATUS_PAY)
  54. ->whereTime('addTime', 'today')
  55. ->sum('moneySubject');
  56. $stat['moneySubjectTotal_today_pc'] = number_format($stat['moneySubjectTotal_today_pc'] / 100);
  57. $stat['moneySubjectTotal_today_wap'] = Db::view('cang', 'moneySubject,userID,status,addTime')
  58. ->view('user', 'userID,osType', 'cang.userID=user.userID and user.isForged=0')
  59. ->where('user.osType=4')
  60. ->where('status', 'EGT', Cang::STATUS_PAY)
  61. ->whereTime('addTime', 'today')
  62. ->sum('moneySubject');
  63. $stat['moneySubjectTotal_today_wap'] = number_format($stat['moneySubjectTotal_today_wap'] / 100);
  64. $stat['moneySubjectTotal_today'] = Db::view('cang', 'moneySubject,userID,status,addTime')
  65. ->view('user', 'userID,osType', 'cang.userID=user.userID and user.isForged=0')
  66. ->where('status', 'EGT', Cang::STATUS_PAY)
  67. ->whereTime('addTime', 'today')
  68. ->sum('moneySubject');
  69. $stat['moneySubjectTotal_today'] = number_format($stat['moneySubjectTotal_today'] / 100);
  70. $stat['cangCount_today'] = Db::name('cang')
  71. ->where('status', 'EGT', Cang::STATUS_PAY)
  72. ->where('isForged', 0)
  73. ->whereTime('addTime', 'today')
  74. ->count();
  75. $stat['userTotal_today'] = Db::name('user')
  76. ->whereTime('addTime', 'today')
  77. ->count();
  78. $stat['userTotal_today_auth'] = Db::name('user')
  79. ->whereTime('addTime', 'today')
  80. ->where('isAuthBank', 1)
  81. ->count();
  82. return $stat;
  83. }
  84. public static function getStatYesterday() {
  85. $stat = [];
  86. $stat['moneySubjectTotal_yesterday_ios'] = Db::view('cang', 'moneySubject,userID,status,addTime')
  87. ->view('user', 'userID,osType', 'cang.userID=user.userID and user.isForged=0')
  88. ->where('user.osType=1')
  89. ->where('status','EGT', Cang::STATUS_PAY)
  90. ->whereTime('addTime', 'yesterday')
  91. ->sum('moneySubject');
  92. $stat['moneySubjectTotal_yesterday_ios'] = number_format($stat['moneySubjectTotal_yesterday_ios'] / 100);
  93. $stat['moneySubjectTotal_yesterday_android'] = Db::view('cang', 'moneySubject,userID,status,addTime')
  94. ->view('user', 'userID,osType', 'cang.userID=user.userID and user.isForged=0')
  95. ->where('user.osType=2')
  96. ->where('status','EGT', Cang::STATUS_PAY)
  97. ->whereTime('addTime', 'yesterday')
  98. ->sum('moneySubject');
  99. $stat['moneySubjectTotal_yesterday_android'] = number_format($stat['moneySubjectTotal_yesterday_android'] / 100);
  100. $stat['moneySubjectTotal_yesterday_pc'] = Db::view('cang', 'moneySubject,userID,status,addTime')
  101. ->view('user', 'userID,osType', 'cang.userID=user.userID and user.isForged=0')
  102. ->where('user.osType=3')
  103. ->where('status','EGT', Cang::STATUS_PAY)
  104. ->whereTime('addTime', 'yesterday')
  105. ->sum('moneySubject');
  106. $stat['moneySubjectTotal_yesterday_pc'] = number_format($stat['moneySubjectTotal_yesterday_pc'] / 100);
  107. $stat['moneySubjectTotal_yesterday_wap'] = Db::view('cang', 'moneySubject,userID,status,addTime')
  108. ->view('user', 'userID,osType', 'cang.userID=user.userID and user.isForged=0')
  109. ->where('user.osType=4')
  110. ->where('status','EGT', Cang::STATUS_PAY)
  111. ->whereTime('addTime', 'yesterday')
  112. ->sum('moneySubject');
  113. $stat['moneySubjectTotal_yesterday_wap'] = number_format($stat['moneySubjectTotal_yesterday_wap'] / 100);
  114. $stat['moneySubjectTotal_yesterday'] = Db::view('cang', 'moneySubject,userID,status,addTime')
  115. ->view('user', 'userID,osType', 'cang.userID=user.userID and user.isForged=0')
  116. ->where('status','EGT', Cang::STATUS_PAY)
  117. ->whereTime('addTime', 'yesterday')
  118. ->sum('moneySubject');
  119. $stat['moneySubjectTotal_yesterday'] = number_format($stat['moneySubjectTotal_yesterday'] / 100);
  120. $stat['cangCount_yesterday'] = Db::name('cang')
  121. ->where('status','EGT', Cang::STATUS_PAY)
  122. ->where('isForged',0)
  123. ->whereTime('addTime', 'yesterday')
  124. ->count();
  125. $stat['userTotal_yesterday'] = Db::name('user')
  126. ->whereTime('addTime', 'yesterday')
  127. ->count();
  128. $stat['userTotal_yesterday_auth'] = Db::name('user')
  129. ->whereTime('addTime', 'yesterday')
  130. ->where('isAuthBank', 1)
  131. ->count();
  132. return $stat;
  133. }
  134. public static function getStatWeek() {
  135. $stat = [];
  136. $stat['moneySubjectTotal_week_ios'] = Db::view('cang', 'moneySubject,userID,status,addTime')
  137. ->view('user', 'userID,osType', 'cang.userID=user.userID and user.isForged=0')
  138. ->where('user.osType=1')
  139. ->where('status','EGT', Cang::STATUS_PAY)
  140. ->whereTime('addTime', 'week')
  141. ->sum('moneySubject');
  142. $stat['moneySubjectTotal_week_ios'] = number_format($stat['moneySubjectTotal_week_ios'] / 100);
  143. $stat['moneySubjectTotal_week_android'] = Db::view('cang', 'moneySubject,userID,status,addTime')
  144. ->view('user', 'userID,osType', 'cang.userID=user.userID and user.isForged=0')
  145. ->where('user.osType=2')
  146. ->where('status','EGT', Cang::STATUS_PAY)
  147. ->whereTime('addTime', 'week')
  148. ->sum('moneySubject');
  149. $stat['moneySubjectTotal_week_android'] = number_format($stat['moneySubjectTotal_week_android'] / 100);
  150. $stat['moneySubjectTotal_week_pc'] = Db::view('cang', 'moneySubject,userID,status,addTime')
  151. ->view('user', 'userID,osType', 'cang.userID=user.userID and user.isForged=0')
  152. ->where('user.osType=3')
  153. ->where('status','EGT', Cang::STATUS_PAY)
  154. ->whereTime('addTime', 'week')
  155. ->sum('moneySubject');
  156. $stat['moneySubjectTotal_week_pc'] = number_format($stat['moneySubjectTotal_week_pc'] / 100);
  157. $stat['moneySubjectTotal_week_wap'] = Db::view('cang', 'moneySubject,userID,status,addTime')
  158. ->view('user', 'userID,osType', 'cang.userID=user.userID and user.isForged=0')
  159. ->where('user.osType=4')
  160. ->where('status','EGT', Cang::STATUS_PAY)
  161. ->whereTime('addTime', 'week')
  162. ->sum('moneySubject');
  163. $stat['moneySubjectTotal_week_wap'] = number_format($stat['moneySubjectTotal_week_wap'] / 100);
  164. $stat['moneySubjectTotal_week'] = Db::view('cang', 'moneySubject,userID,status,addTime')
  165. ->view('user', 'userID,osType', 'cang.userID=user.userID and user.isForged=0')
  166. ->where('status','EGT', Cang::STATUS_PAY)
  167. ->whereTime('addTime', 'week')
  168. ->sum('moneySubject');
  169. $stat['moneySubjectTotal_week'] = number_format($stat['moneySubjectTotal_week'] / 100);
  170. $stat['cangCount_week'] = Db::name('cang')
  171. ->where('status','EGT', Cang::STATUS_PAY)
  172. ->where('isForged',0)
  173. ->whereTime('addTime', 'week')
  174. ->count();
  175. $stat['userTotal_week'] = Db::name('user')
  176. ->whereTime('addTime', 'week')
  177. ->count();
  178. $stat['userTotal_week_auth'] = Db::name('user')
  179. ->whereTime('addTime', 'week')
  180. ->where('isAuthBank', 1)
  181. ->count();
  182. return $stat;
  183. }
  184. public static function getStatAll() {
  185. $stat = [];
  186. $stat['moneySubjectTotal_all_ios'] = Db::view('cang', 'moneySubject,userID,status,addTime')
  187. ->view('user', 'userID,osType', 'cang.userID=user.userID and user.isForged=0')
  188. ->where('user.osType=1')
  189. ->where('status','EGT', Cang::STATUS_PAY)
  190. ->sum('moneySubject');
  191. $stat['moneySubjectTotal_all_ios'] = number_format($stat['moneySubjectTotal_all_ios'] / 100);
  192. $stat['moneySubjectTotal_all_android'] = Db::view('cang', 'moneySubject,userID,status,addTime')
  193. ->view('user', 'userID,osType', 'cang.userID=user.userID and user.isForged=0')
  194. ->where('user.osType=2')
  195. ->where('status','EGT', Cang::STATUS_PAY)
  196. ->sum('moneySubject');
  197. $stat['moneySubjectTotal_all_android'] = number_format($stat['moneySubjectTotal_all_android'] / 100);
  198. $stat['moneySubjectTotal_all_pc'] = Db::view('cang', 'moneySubject,userID,status,addTime')
  199. ->view('user', 'userID,osType', 'cang.userID=user.userID and user.isForged=0')
  200. ->where('user.osType=3')
  201. ->where('status','EGT', Cang::STATUS_PAY)
  202. ->sum('moneySubject');
  203. $stat['moneySubjectTotal_all_pc'] = number_format($stat['moneySubjectTotal_all_pc'] / 100);
  204. $stat['moneySubjectTotal_all_wap'] = Db::view('cang', 'moneySubject,userID,status,addTime')
  205. ->view('user', 'userID,osType', 'cang.userID=user.userID and user.isForged=0')
  206. ->where('user.osType=4')
  207. ->where('status','EGT', Cang::STATUS_PAY)
  208. ->sum('moneySubject');
  209. $stat['moneySubjectTotal_all_wap'] = number_format($stat['moneySubjectTotal_all_wap'] / 100);
  210. $stat['moneySubjectTotal_all'] = Db::view('cang', 'moneySubject,userID,status,addTime')
  211. ->view('user', 'userID,osType', 'cang.userID=user.userID and user.isForged=0')
  212. ->where('status','EGT', Cang::STATUS_PAY)
  213. ->sum('moneySubject');
  214. $stat['moneySubjectTotal_all'] = number_format($stat['moneySubjectTotal_all'] / 100);
  215. $stat['cunTotal_all'] = Db::view('cang', 'moneySubject,userID,status,addTime')
  216. ->view('user', 'userID,osType', 'cang.userID=user.userID and user.isForged=0')
  217. ->view('subject', 'BACKUPID', 'subject.subjectID=cang.subjectID')
  218. ->where('status','in', [Cang::STATUS_PAY,Cang::STATUS_INTEREST, Cang::STATUS_REPAY])
  219. ->where('subject.BACKUPID', 0)
  220. ->sum('moneySubject');
  221. $stat['cunTotal_all'] = number_format($stat['cunTotal_all'] / 100);
  222. $stat['cangCount_all'] = Db::name('cang')
  223. ->where('status','EGT', Cang::STATUS_PAY)
  224. ->where('isForged',0)
  225. ->count();
  226. $stat['userTotal_all'] = Db::name('user')
  227. ->count();
  228. $stat['userTotal_all_auth'] = Db::name('user')
  229. ->where('isAuthBank', 1)
  230. ->count();
  231. return $stat;
  232. }
  233. public static function getStatCang30DayList() {
  234. $list = Db::query("select FROM_UNIXTIME(addTime, '%Y-%m-%d') date, sum(moneySubject) as moneyTotal,count(*) as count from a_cang where isForged=0 and addTime between ".(THINK_START_TIME - 30 * 86400)." and ".THINK_START_TIME." group by date");
  235. foreach ($list as $k=>$item) {
  236. $list[$k]['moneyTotal'] = (int)($item['moneyTotal'] / 100);
  237. }
  238. $stat['cang30DayList'] = [
  239. 'dateList'=>array_column($list, 'date'),
  240. 'moneyTotalList'=>array_column($list, 'moneyTotal'),
  241. 'countList'=>array_column($list, 'count')
  242. ];
  243. return $stat;
  244. }
  245. public static function getStatUserAction() {
  246. $listAll = Cache::get('statUserAction');
  247. if(!$listAll) {
  248. $listAll = [];
  249. $list = ModelUser::where([
  250. 'isForged' => 0
  251. ])->field('mobile,trueName')->order('addTime desc')->limit(0, 10)->select();
  252. foreach ($list as $k => $item) {
  253. array_push($listAll, Common::mobileAsterisk($item['mobile']) . ' 刚刚开通新账号');
  254. }
  255. $list = UserRecharge::with(['user'])->where([
  256. 'status' => UserRecharge::STATUS_PAY
  257. ])->order('addTime desc')->limit(0, 20)->select();
  258. foreach ($list as $k => $item) {
  259. array_push($listAll, Common::mobileAsterisk($item->user['mobile']) . '完成了一笔' . $item['money'] . '元' . '的充值');
  260. }
  261. $list = Cang::with(['subject', 'user'])->where([
  262. 'isForged' => 0
  263. ])->group('userID')->order('addTime desc')->limit(0, 20)->select();
  264. foreach ($list as $k => $item) {
  265. array_push($listAll, Common::mobileAsterisk($item->user['mobile']) . '投资了' . $item->subject['title'] . ' ' . $item['moneySubject'] . '元');
  266. }
  267. $listAll = array_values(Common::shuffle_assoc($listAll));
  268. Cache::set('statUserAction', $listAll, 60);
  269. }
  270. return $listAll;
  271. }
  272. }