123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\Admin;
- use app\admin\model\User;
- use app\common\controller\Backend;
- use app\common\model\Attachment;
- use app\common\model\SysConfig;
- use fast\Date;
- use think\Db;
- /**
- * 控制台
- *
- * @icon fa fa-dashboard
- * @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
- */
- class Customer extends Backend
- {
- /**
- * 查看
- */
- public function index()
- {
- try {
- \think\Db::execute("SET @@sql_mode='';");
- } catch (\Exception $e) {
- }
- $postTime = input('startTime','');
- $where = [];
- $map = [];
- if($postTime){
- $time = explode(' - ',$postTime);
- $startTime = strtotime($time[0]);
- $endTime = strtotime($time[1]);
- $where['create_time'] = array('between',[$startTime,$endTime]);
- $map['createtime'] = array('between',[$startTime,$endTime]);
- }
- //新增用户数
- $register = Db('User')->where($map)->count();
- //下单用户数
- $buy = Db('Orders')->where($where)->where('status','in','5,10,20')->group('user_id')->count();
- //下单支付转化率
- $orderNum = Db('Orders')->where($where)->count();
- $payRate = 0;
- if($orderNum > 0)$payRate = round($buy/$orderNum,2)*100;
- $payRate = $payRate.'%';
- //支付方式
- $orderList = Db("Orders")->where($where)
- ->field('pay_type, COUNT(*) AS nums')
- ->group('pay_type')
- ->select();
- $payTotalCount = Db("Orders")->where($where)->where('status','in','5,10,20,30')->count();
- $payTypeList = [];
- $payTypeList1 = [];
- foreach ($orderList as $k => $v) {
- if($v['pay_type'] == 1){
- $v['pay_type'] = '企业网银';
- }elseif ($v['pay_type'] == 2){
- $v['pay_type'] = '微信';
- }elseif ($v['pay_type'] == 3){
- $v['pay_type'] = '支付宝';
- }elseif ($v['pay_type'] == 4){
- $v['pay_type'] = '银联';
- }elseif ($v['pay_type'] == 5){
- $v['pay_type'] = '代付';
- }elseif ($v['pay_type'] == 6){
- $v['pay_type'] = '线下';
- }
- $rate = 0;
- if($payTotalCount > 0)$rate = round($v['nums']/$payTotalCount,2)*100;
- $rate = $rate.'%';
- $payTypeList[$v['pay_type']] = $v['nums'];
- $payTypeList1[$v['pay_type']] = $rate;
- }
- if ($this->request->isAjax()) {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- $limit = 2;
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $this->model = new \app\admin\model\Orders;
- $list = $this->model
- ->with(['user'])
- ->field('orders.*,user.nickname,user.username, SUM(orders.amount_pay) AS total')
- ->where('orders.status','in','5,10,20')
- ->order('total desc')
- ->group('orders.user_id')
- ->paginate($limit);
- $result = array("total" => $list->total(), "rows" => $list->items());
- return json($result);
- }
- $this->view->assign([
- 'register' => $register,
- 'buy' => $buy,
- 'post_time'=>$postTime,
- 'pay_rate' =>$payRate
- ]);
- $this->assignconfig('type_column', array_keys($payTypeList));
- $this->assignconfig('type_data', array_values($payTypeList));
- $this->assignconfig('type_column1', array_keys($payTypeList1));
- $this->assignconfig('type_data1', array_values($payTypeList1));
- return $this->view->fetch();
- }
- }
|