count(); $data['wf'] = self::statusByWhere(1, new self(), '')->count(); $data['tk'] = self::statusByWhere(-1, new self(), '')->count(); $data['yt'] = self::statusByWhere(-2, new self(), '')->count(); return $data; } public static function getBadge($where) { $price = self::getOrderPrice($where); return [ [ 'name' => '订单数量', 'field' => '件', 'count' => $price['order_sum'], 'background_color' => 'layui-bg-blue', 'col' => 3 ], [ 'name' => '订单金额', 'field' => '元', 'count' => $price['price'], 'background_color' => 'layui-bg-blue', 'col' => 3 ], [ 'name' => '退款金额', 'field' => '元', 'count' => $price['refund_price'], 'background_color' => 'layui-bg-blue', 'col' => 3 ], [ 'name' => '微信支付金额', 'field' => '元', 'count' => $price['pay_price_wx'], 'background_color' => 'layui-bg-blue', 'col' => 3 ], [ 'name' => '余额支付金额', 'field' => '元', 'count' => $price['pay_price_yue'], 'background_color' => 'layui-bg-blue', 'col' => 3 ], [ 'name' => '支付宝支付金额', 'field' => '元', 'count' => $price['pay_price_zhifubao'], 'background_color' => 'layui-bg-blue', 'col' => 3 ], [ 'name' => '抖音支付金额', 'field' => '元', 'count' => $price['pay_price_toutiao'], 'background_color' => 'layui-bg-blue', 'col' => 3 ], [ 'name' => '快手支付金额', 'field' => '元', 'count' => $price['pay_price_kuaishou'], 'background_color' => 'layui-bg-blue', 'col' => 3 ] ]; } /** * 处理订单金额 * @param $where * @return array */ public static function getOrderPrice($where) { $price = array(); $price['pay_price'] = 0; //支付金额 $price['refund_price'] = 0; //退款金额 $price['pay_price_wx'] = 0; //微信支付金额 $price['pay_price_yue'] = 0; //余额支付金额 $price['pay_price_zhifubao'] = 0; //支付宝支付金额 $price['pay_price_toutiao'] = 0; //抖音支付金额 $price['pay_price_kuaishou'] = 0; //快手支付金额 $list = self::getOrderWhere($where, self::alias('a')->join('user r', 'r.uid=a.uid', 'LEFT'), 'a.', 'r')->field([ 'sum(a.price) as price', 'sum(a.refund_price) as refund_price' ])->find()->toArray(); $price['price'] = $list['price']; //支付金额 $price['refund_price'] = $list['refund_price']; //退款金额 $list = self::getOrderWhere($where, self::alias('a')->join('user r', 'r.uid=a.uid', 'LEFT'), 'a.', 'r')->field('sum(a.price) as price,a.recharge_type')->group('a.recharge_type')->select()->toArray(); foreach ($list as $v) { if ($v['recharge_type'] == 'weixin') { $price['pay_price_wx'] = $v['price']; } elseif ($v['recharge_type'] == 'yue') { $price['pay_price_yue'] = $v['price']; } elseif ($v['recharge_type'] == 'zhifubao') { $price['pay_price_zhifubao'] = $v['price']; } } $price['order_sum'] = self::getOrderWhere($where, self::alias('a')->join('user r', 'r.uid=a.uid', 'LEFT'), 'a.', 'r')->count(); return $price; } /** * 处理where条件 * @param $where * @param $model * @return mixed */ public static function getOrderWhere($where, $model, $aler = '', $join = '') { if ($where['status'] != '') { $model = self::statusByWhere($where['status'], $model, $aler); } else { $model = $model->where($aler . 'is_del', 0); } if (isset($where['uid']) && $where['uid']) { $model = $model->where($aler . 'uid', $where['uid']); } if ($where['real_name'] != '') { $model = $model->where($aler . 'order_id|' . $aler . 'uid' . ($join ? '|' . $join . '.nickname|' . $join . '.uid|' . $join . '.phone' : ''), 'LIKE', "%$where[real_name]%"); } if ($where['data'] !== '') { $model = self::getModelTime($where, $model, $aler . 'add_time'); } return $model; } public static function statusByWhere($status, $model = null, $alert = '') { if ($model == null) $model = new self; $model = $model->where($alert . 'is_del', 0); if ('' === $status) return $model; else if ($status == 0) //未支付 return $model->where($alert . 'paid', 0)->where($alert . 'status', 0)->where($alert . 'refund_status', 0); else if ($status == 1) //已支付 return $model->where($alert . 'paid', 1)->where($alert . 'status', 0)->where($alert . 'refund_status', 0); else if ($status == -1) //退款中 return $model->where($alert . 'paid', 1)->where($alert . 'refund_status', 1); else if ($status == -2) //已退款 return $model->where($alert . 'paid', 1)->where($alert . 'refund_status', 2); else return $model; } public static function systemPage($where) { $model = self::getOrderWhere($where, self::alias('a')->join('user r', 'r.uid=a.uid', 'LEFT'), 'a.', 'r')->field('a.*,r.nickname,r.phone'); if ($where['order'] != '') { $model = $model->order(self::setOrder($where['order'])); } else { $model = $model->order('a.id desc'); } if (isset($where['excel']) && $where['excel'] == 1) { $data = ($data = $model->select()) && count($data) ? $data->toArray() : []; } else { $data = ($data = $model->page((int)$where['page'], (int)$where['limit'])->select()) && count($data) ? $data->toArray() : []; } foreach ($data as &$item) { $item['order_name'] = '[充值订单]'; $item['color'] = '#895612'; if ($item['paid'] == 1) { switch ($item['recharge_type']) { case 'weixin': $item['pay_type_name'] = '微信支付'; break; case 'yue': $item['pay_type_name'] = '余额支付'; break; case 'zhifubao': $item['pay_type_name'] = '支付宝支付'; break; case 'toutiao': $item['pay_type_name'] = '抖音支付'; break; case 'kuaishou': $item['pay_type_name'] = '快手支付'; break; } } else { $item['pay_type_name'] = '未支付'; } if ($item['paid'] == 0 && $item['status'] == 0) { $item['status_name'] = '未支付'; } else if ($item['paid'] == 1 && $item['status'] == 0 && $item['refund_status'] == 0) { $item['status_name'] = '已支付'; } else if ($item['paid'] == 1 && $item['refund_status'] == 2) { $item['status_name'] = '已退款'; } if ($item['paid'] == 0 && $item['status'] == 0 && $item['refund_status'] == 0) { $item['_status'] = 1; } else if ($item['paid'] == 1 && $item['status'] == 0 && $item['refund_status'] == 0) { $item['_status'] = 2; } else if ($item['paid'] == 1 && $item['refund_status'] == 2) { $item['_status'] = 7; } $item['pay_time'] = $item['pay_time'] > 0 ? date('Y-m-d H:i:s', $item['pay_time']) : '无'; $item['refund_reason_time'] = date('Y-m-d H:i:s', $item['refund_reason_time']); } if (isset($where['excel']) && $where['excel'] == 1) { self::SaveExcel($data); } $count = self::getOrderWhere($where, self::alias('a')->join('user r', 'r.uid=a.uid', 'LEFT'), 'a.', 'r')->count(); return compact('count', 'data'); } /** * 保存并下载excel * $list array * return */ public static function SaveExcel($list) { $export = []; foreach ($list as $index => $item) { if ($item['paid'] == 0 && $item['status'] == 0) { $item['status_name'] = '未支付'; } else if ($item['paid'] == 1 && $item['status'] == 0 && $item['refund_status'] == 0) { $item['status_name'] = '已支付'; } else if ($item['paid'] == 1 && $item['refund_status'] == 1) { $item['status_name'] = '退款中'; } else if ($item['paid'] == 1 && $item['refund_status'] == 2) { $item['status_name'] = '已退款'; } $export[] = [ $item['order_id'], $item['nickname'] . '/' . $item['uid'], $item['status_name'], $item['pay_type_name'], $item['paid'] == 1 ? '已支付' : '未支付' . '/支付时间: ' . $item['pay_time'], $item['gold_num'], $item['price'], $item['refund_price'] ]; } $filename = '充值订单导出' . time() . '.xlsx'; $head = ['订单号', '用户信息', '订单状态', '支付方式', '支付状态', '虚拟币数量', '支付金额', '退款金额']; PhpSpreadsheetService::outdata($filename, $export, $head); } }