Customer.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\Admin;
  4. use app\admin\model\User;
  5. use app\common\controller\Backend;
  6. use app\common\model\Attachment;
  7. use app\common\model\SysConfig;
  8. use fast\Date;
  9. use think\Db;
  10. /**
  11. * 控制台
  12. *
  13. * @icon fa fa-dashboard
  14. * @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
  15. */
  16. class Customer extends Backend
  17. {
  18. /**
  19. * 查看
  20. */
  21. public function index()
  22. {
  23. try {
  24. \think\Db::execute("SET @@sql_mode='';");
  25. } catch (\Exception $e) {
  26. }
  27. $postTime = input('startTime','');
  28. $where = [];
  29. $map = [];
  30. if($postTime){
  31. $time = explode(' - ',$postTime);
  32. $startTime = strtotime($time[0]);
  33. $endTime = strtotime($time[1]);
  34. $where['create_time'] = array('between',[$startTime,$endTime]);
  35. $map['createtime'] = array('between',[$startTime,$endTime]);
  36. }
  37. //新增用户数
  38. $register = Db('User')->where($map)->count();
  39. //下单用户数
  40. $buy = Db('Orders')->where($where)->where('status','in','5,10,20')->group('user_id')->count();
  41. //下单支付转化率
  42. $orderNum = Db('Orders')->where($where)->count();
  43. $payRate = 0;
  44. if($orderNum > 0)$payRate = round($buy/$orderNum,2)*100;
  45. $payRate = $payRate.'%';
  46. //支付方式
  47. $orderList = Db("Orders")->where($where)
  48. ->field('pay_type, COUNT(*) AS nums')
  49. ->group('pay_type')
  50. ->select();
  51. $payTotalCount = Db("Orders")->where($where)->where('status','in','5,10,20,30')->count();
  52. $payTypeList = [];
  53. $payTypeList1 = [];
  54. foreach ($orderList as $k => $v) {
  55. if($v['pay_type'] == 1){
  56. $v['pay_type'] = '企业网银';
  57. }elseif ($v['pay_type'] == 2){
  58. $v['pay_type'] = '微信';
  59. }elseif ($v['pay_type'] == 3){
  60. $v['pay_type'] = '支付宝';
  61. }elseif ($v['pay_type'] == 4){
  62. $v['pay_type'] = '银联';
  63. }elseif ($v['pay_type'] == 5){
  64. $v['pay_type'] = '代付';
  65. }elseif ($v['pay_type'] == 6){
  66. $v['pay_type'] = '线下';
  67. }
  68. $rate = 0;
  69. if($payTotalCount > 0)$rate = round($v['nums']/$payTotalCount,2)*100;
  70. $rate = $rate.'%';
  71. $payTypeList[$v['pay_type']] = $v['nums'];
  72. $payTypeList1[$v['pay_type']] = $rate;
  73. }
  74. if ($this->request->isAjax()) {
  75. //如果发送的来源是Selectpage,则转发到Selectpage
  76. if ($this->request->request('keyField')) {
  77. return $this->selectpage();
  78. }
  79. $limit = 2;
  80. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  81. $this->model = new \app\admin\model\Orders;
  82. $list = $this->model
  83. ->with(['user'])
  84. ->field('orders.*,user.nickname,user.username, SUM(orders.amount_pay) AS total')
  85. ->where('orders.status','in','5,10,20')
  86. ->order('total desc')
  87. ->group('orders.user_id')
  88. ->paginate($limit);
  89. $result = array("total" => $list->total(), "rows" => $list->items());
  90. return json($result);
  91. }
  92. $this->view->assign([
  93. 'register' => $register,
  94. 'buy' => $buy,
  95. 'post_time'=>$postTime,
  96. 'pay_rate' =>$payRate
  97. ]);
  98. $this->assignconfig('type_column', array_keys($payTypeList));
  99. $this->assignconfig('type_data', array_values($payTypeList));
  100. $this->assignconfig('type_column1', array_keys($payTypeList1));
  101. $this->assignconfig('type_data1', array_values($payTypeList1));
  102. return $this->view->fetch();
  103. }
  104. }