Index.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\store\StoreProduct;
  4. use app\admin\model\system\SystemConfig;
  5. use app\admin\model\system\SystemMenus;
  6. use app\admin\model\system\SystemNotice as NoticeModel;
  7. use app\admin\model\system\SystemNotice;
  8. use app\admin\model\system\SystemRole;
  9. use app\admin\model\order\StoreOrder;
  10. use app\admin\model\user\UserExtract;
  11. use service\CacheService;
  12. use service\UpgradeService;
  13. use service\UpgradeApi;
  14. use think\DB;
  15. /**
  16. * 首页控制器
  17. * Class Index
  18. * @package app\admin\controller
  19. *
  20. */
  21. class Index extends AuthController
  22. {
  23. public function index()
  24. {
  25. //获取当前登录后台的管理员信息
  26. $adminInfo = $this->adminInfo->toArray();
  27. $roles = explode(',',$adminInfo['roles']);
  28. $site_logo = SystemConfig::getOneConfig('menu_name','site_logo')->toArray();
  29. // dump(SystemMenus::menuList());
  30. // exit();
  31. $this->assign([
  32. 'menuList'=>SystemMenus::menuList(),
  33. 'site_logo'=>json_decode($site_logo['value'],true),
  34. 'role_name'=>SystemRole::where('id',$roles[0])->field('role_name')->find()
  35. ]);
  36. return $this->fetch();
  37. }
  38. //后台首页内容
  39. public function main()
  40. {
  41. /*首页第一行统计*/
  42. $now_month = strtotime(date('Y-m'));
  43. $pre_month = strtotime(date('Y-m',strtotime('-1 month')));
  44. $now_day = strtotime(date('Y-m-d'));
  45. $pre_day = strtotime(date('Y-m-d',strtotime('-1 day')));//昨天时间戳
  46. $day = strtotime(date('Y-m-d',strtotime('0 day')));//今天时间戳
  47. //昨天待发货数量
  48. $topData['orderDeliveryNum'] = StoreOrder::isMainYesterdayCount($pre_day,$day)
  49. ->where('status',0)
  50. ->where('paid',1)
  51. ->where('refund_status',0)
  52. ->count();
  53. //昨天退换货订单数
  54. $topData['orderRefundNum'] = StoreOrder::isMainYesterdayCount($pre_day,$day)
  55. ->where('paid',1)
  56. ->where('refund_status','IN','1,2')
  57. ->count();
  58. //库存预警
  59. $replenishment_num = SystemConfig::getValue('store_stock') > 0 ? SystemConfig::getValue('store_stock') : 20;//库存预警界限
  60. $topData['stockProduct'] = StoreProduct::where('stock','<=',$replenishment_num)->where('is_del',0)->count();
  61. //待处理提现
  62. $topData['treatedExtract'] = UserExtract::where('status',0)->count();
  63. //昨日订单数
  64. $topData['orderNum'] = StoreOrder::isMainYesterdayCount($pre_day,$day)->count();
  65. //昨日交易额
  66. $orderPriceNum = StoreOrder::isMainYesterdayCount($pre_day,$day)->field('sum(pay_price) as pay_price')->find()['pay_price'];
  67. $topData['orderPriceNum'] = $orderPriceNum ? $orderPriceNum : 0;
  68. //总收入->日
  69. $now_day_order_p = StoreOrder::where('paid',1)->where('pay_time','gt',$now_day)->value('sum(pay_price)');
  70. $pre_day_order_p = StoreOrder::where('paid',1)->where('pay_time','gt',$pre_day)->where('pay_time','lt',$now_day)->value('sum(pay_price)');
  71. $first_line['d_price'] = [
  72. 'data' => $now_day_order_p ? $now_day_order_p : 0,
  73. 'percent' => abs($now_day_order_p - $pre_day_order_p),
  74. 'is_plus' => $now_day_order_p - $pre_day_order_p > 0 ? 1 : ($now_day_order_p - $pre_day_order_p == 0 ? -1 : 0)
  75. ];
  76. //总收入->月
  77. $now_month_order_p = StoreOrder::where('paid',1)->where('pay_time','gt',$now_month)->value('sum(pay_price)');
  78. $pre_month_order_p = StoreOrder::where('paid',1)->where('pay_time','gt',$pre_month)->where('pay_time','lt',$now_month)->value('sum(pay_price)');
  79. $first_line['m_price'] = [
  80. 'data' => $now_month_order_p > 0 ? $now_month_order_p : 0,
  81. 'percent' => abs($now_month_order_p - $pre_month_order_p),
  82. 'is_plus' => $now_month_order_p - $pre_month_order_p > 0 ? 1 : ($now_month_order_p - $pre_month_order_p == 0 ? -1 : 0)
  83. ];
  84. //新粉丝->日
  85. $now_day_user = DB::name('User')->where('add_time','gt',$now_day)->count();
  86. $pre_day_user = DB::name('User')->where('add_time','gt',$pre_day)->where('add_time','lt',$now_day)->count();
  87. $pre_day_user = $pre_day_user ? $pre_day_user : 0;
  88. $first_line['day'] = [
  89. 'data' => $now_day_user ? $now_day_user : 0,
  90. 'percent' => abs($now_day_user - $pre_day_user),
  91. 'is_plus' => $now_day_user - $pre_day_user > 0 ? 1 : ($now_day_user - $pre_day_user == 0 ? -1 : 0)
  92. ];
  93. //新粉丝->月
  94. $now_month_user = DB::name('User')->where('add_time','gt',$now_month)->count();
  95. $pre_month_user = DB::name('User')->where('add_time','gt',$pre_month)->where('add_time','lt',$now_month)->count();
  96. $first_line['month'] = [
  97. 'data' => $now_month_user ? $now_month_user : 0,
  98. 'percent' => abs($now_month_user - $pre_month_user),
  99. 'is_plus' => $now_month_user - $pre_month_user > 0 ? 1 : ($now_month_user - $pre_month_user == 0 ? -1 : 0)
  100. ];
  101. /*首页第二行统计*/
  102. $second_line['order_count_max'] = 50; //max最小为100
  103. for ($i=0; $i < 7; $i++) {
  104. $time = strtotime('-'.$i.' day');
  105. $now_day_info = strtotime(date('Y-m-d',strtotime('-'.($i-1).' day')));
  106. $pre_day_info = strtotime(date('Y-m-d',strtotime('-'.$i.' day')));
  107. $order_count[$i]['y'] = date('Y',$time);
  108. $order_count[$i]['m'] = date('m',$time);
  109. $order_count[$i]['d'] = date('d',$time);
  110. $order_count[$i]['count'] = StoreOrder::where('add_time','gt',$pre_day_info)->where('add_time','lt',$now_day_info)->count();
  111. $second_line['order_count_max'] = $second_line['order_count_max'] > $order_count[$i]['count'] ? $second_line['order_count_max'] : $order_count[$i]['count'];
  112. }
  113. $second_line['order_count'] = $order_count;
  114. //本月订单总数
  115. $now_order_info_c = StoreOrder::where('add_time','gt',$now_month)->count();
  116. $pre_order_info_c = StoreOrder::where('add_time','gt',$pre_month)->where('add_time','lt',$now_month)->count();
  117. $order_info['first'] = [
  118. 'data' => $now_order_info_c ? $now_order_info_c : 0,
  119. 'percent' => abs($now_order_info_c - $pre_order_info_c),
  120. 'is_plus' => $now_order_info_c - $pre_order_info_c > 0 ? 1 : ($now_order_info_c - $pre_order_info_c == 0 ? -1 : 0)
  121. ];
  122. //上月订单总数
  123. $second_now_month = strtotime(date('Y-m',strtotime('-1 month')));
  124. $second_pre_month = strtotime(date('Y-m',strtotime('-2 month')));
  125. $now_order_info_c = StoreOrder::where('add_time','gt',$pre_month)->where('add_time','lt',$now_month)->count();
  126. $pre_order_info_c = StoreOrder::where('add_time','gt',$second_pre_month)->where('add_time','lt',$second_now_month)->count();
  127. $order_info["second"] = [
  128. 'data' => $now_order_info_c ? $now_order_info_c : 0,
  129. 'percent' => abs($now_order_info_c - $pre_order_info_c),
  130. 'is_plus' => $now_order_info_c - $pre_order_info_c > 0 ? 1 : ($now_order_info_c - $pre_order_info_c == 0 ? -1 : 0)
  131. ];
  132. $second_line['order_info'] = $order_info;
  133. /*首页第三行统计*/
  134. $third_line['order_count_max'] = 100; //max最小为100
  135. for ($x=0; $x < 30; $x++) {
  136. $time = strtotime('-'.$x.' day');
  137. $now_day_info = strtotime(date('Y-m-d',strtotime('-'.($x-1).' day')));
  138. $pre_day_info = strtotime(date('Y-m-d',strtotime('-'.$x.' day')));
  139. $price_count[$x]['y'] = date('Y',$time);
  140. $price_count[$x]['m'] = date('m',$time);
  141. $price_count[$x]['d'] = date('d',$time);
  142. $price_count[$x]['count'] = StoreOrder::where('paid',1)->where('pay_time','gt',$pre_day_info)->where('pay_time','lt',$now_day_info)->value('sum(pay_price)');
  143. $third_line['order_count_max'] = $third_line['order_count_max'] > $price_count[$x]['count'] ? $third_line['order_count_max'] : $price_count[$x]['count'];
  144. }
  145. $third_line['price_count'] = $price_count;
  146. $this->assign([
  147. 'first_line' => $first_line,
  148. 'second_line' => $second_line,
  149. 'third_line' => $third_line,
  150. 'topData' => $topData,
  151. ]);
  152. return $this->fetch();
  153. }
  154. public function test(){
  155. UpgradeService::start();
  156. }
  157. }