Laojiaqian.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: qisse
  5. * Date: 2017/6/27
  6. * Time: 20:02
  7. */
  8. namespace app\master\logic;
  9. use app\laojiaqian\model\User;
  10. use app\laojiaqian\model\UserDueDetail;
  11. use think\Cache;
  12. use think\Db;
  13. use tool\Common;
  14. class Laojiaqian extends Base
  15. {
  16. public function getCangList() {
  17. $map = [
  18. 'user_id'=>['gt', 0]
  19. ];
  20. if( isset($this->app['addTimeTo']) &&
  21. isset($this->app['addTimeFrom'])) {
  22. $map['add_time'] = ['between time', [$this->app['addTimeFrom'],Common::timetodate(Common::datetotime($this->app['addTimeTo']) + 86400, 0)]];
  23. }
  24. if(isset($this->app['status']) && $this->app['status']) {
  25. $map['status'] = $this->app['status'];
  26. }
  27. if(!isset($this->app['pageIndex']) || !$this->app['pageIndex']) {
  28. $this->app['pageIndex'] = 1;
  29. }
  30. if(!isset($this->app['pageItemCount']) || !$this->app['pageItemCount']) {
  31. $this->app['pageItemCount'] = 10;
  32. }
  33. $app = $this->app;
  34. $list = UserDueDetail::with([
  35. 'user'=>function($query) use ($app) {
  36. $map = [];
  37. if(isset($app['keyword']) && $app['keyword']) {
  38. $map['mobile|real_name'] = ['like', '%'.$app['keyword'].'%'];
  39. }
  40. if(isset($app['clientType']) && $app['clientType']) {
  41. if($app['clientType'] == 1) {
  42. $map['device_type'] = 1;
  43. }
  44. else if($app['clientType'] == 2) {
  45. $map['device_type'] = 2;
  46. }
  47. else if($app['clientType'] == 3){
  48. $map['device_type'] = 3;
  49. }
  50. else if($app['clientType'] == 4){
  51. $map['device_type'] = 4;
  52. }
  53. }
  54. if(!empty($map)) {
  55. $query->where($map);
  56. }
  57. },
  58. 'project'=>function($query) use ($app) {
  59. $map = [];
  60. if(isset($app['typeID']) && $app['typeID']) {
  61. $map['type'] = $app['type'];
  62. }
  63. if(!empty($map)) {
  64. $query->where($map);
  65. }
  66. }
  67. //])->where($map)->limit(($this->app['pageIndex'] - 1) * $this->app['pageItemCount'], $this->app['pageItemCount'])->order('id desc')->select();
  68. ])->where($map)->order('id desc')->select();
  69. /*if($list->isEmpty()) {
  70. return Common::rm(-2, '数据为空');
  71. }*/
  72. $_list = [];
  73. $stat_currentTotal = 0;
  74. $stat_total = UserDueDetail::where([
  75. 'user_id'=>['gt', 0],
  76. 'status'=>1
  77. ])->sum('due_capital');
  78. $stat_totalAll = UserDueDetail::where([
  79. 'user_id'=>['gt', 0]
  80. ])->sum('due_capital');
  81. $stat_futouList = UserDueDetail::where([
  82. 'user_id'=>['gt', 0]
  83. ])->field('due_capital, user_id, status')
  84. ->group('user_id')
  85. ->having('count(user_id)>1 and status = 2')
  86. ->select();
  87. $stat_futouUserIDS = array_column(collection($stat_futouList)->toArray(), 'user_id');
  88. $stat_futouUserYouxiaoIDS = [];
  89. foreach ($stat_futouUserIDS as $item) {
  90. $stat_futouList = UserDueDetail::where([
  91. 'user_id'=>$item
  92. ])->field('due_capital, user_id, status, add_time')->select();
  93. $has = false;
  94. foreach ($stat_futouList as $_k=>$_item) {
  95. foreach ($stat_futouList as $__k=>$__item) {
  96. if(abs(Common::datetotime($_item['add_time']) - Common::datetotime($__item['add_time'])) > 14 * 86400) {
  97. $stat_futouUserYouxiaoIDS[] = $item;
  98. $has = true;
  99. break;
  100. }
  101. }
  102. if($has) {
  103. break;
  104. }
  105. }
  106. }
  107. //复投用户量
  108. $stat_futouUserTotal = count($stat_futouUserYouxiaoIDS);
  109. //总用户量
  110. $stat_userTotal = UserDueDetail::where([
  111. 'user_id'=>['gt', 0]
  112. ])->group('user_id')
  113. ->count();
  114. foreach ($list as $k=>$item) {
  115. if($item['user'] && $item['project']) {
  116. $_list[] = $item;
  117. $stat_currentTotal += $item['due_capital'];
  118. }
  119. }
  120. Cache::set('stat_laojiaqian', [
  121. 'stat_total'=>number_format($stat_total),
  122. 'stat_totalAll'=>number_format($stat_totalAll),
  123. 'stat_userTotal'=>$stat_userTotal
  124. ]);
  125. return Common::rm(1, '操作成功', [
  126. 'cangList'=>$_list,
  127. 'stat_currentTotal'=>number_format($stat_currentTotal),
  128. 'stat_total'=>number_format($stat_total),
  129. 'stat_totalAll'=>number_format($stat_totalAll),
  130. 'stat_futouUserTotal'=>$stat_futouUserTotal,
  131. 'stat_userTotal'=>$stat_userTotal,
  132. 'count'=>count($_list),
  133. 'pageItemCount'=>$this->app['pageItemCount']
  134. ]);
  135. }
  136. }