250 lines
10 KiB
PHP
Executable File
250 lines
10 KiB
PHP
Executable File
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | likeshop开源商城系统
|
||
// +----------------------------------------------------------------------
|
||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||
// | github下载:https://github.com/likeshop-github
|
||
// | 访问官网:https://www.likeshop.cn
|
||
// | 访问社区:https://home.likeshop.cn
|
||
// | 访问手册:http://doc.likeshop.cn
|
||
// | 微信公众号:likeshop技术社区
|
||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||
// | likeshop团队版权所有并拥有最终解释权
|
||
// +----------------------------------------------------------------------
|
||
// | author: likeshop.cn.team
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace app\adminapi\lists\order;
|
||
|
||
|
||
use app\adminapi\lists\BaseAdminDataLists;
|
||
use app\common\enum\OrderEnum;
|
||
use app\common\enum\PayEnum;
|
||
use app\common\lists\ListsExtendInterface;
|
||
use app\common\model\coach\Coach;
|
||
use app\common\model\order\Order;
|
||
use app\common\model\order\OrderGoods;
|
||
use app\common\model\pay\PayConfig;
|
||
use app\common\model\pay\PayWay;
|
||
use app\common\model\shop\Shop;
|
||
use app\common\model\user\User;
|
||
use app\common\service\FileService;
|
||
|
||
class OrderLists extends BaseAdminDataLists implements ListsExtendInterface
|
||
{
|
||
public $where = [];
|
||
/**
|
||
* @notes 搜索条件
|
||
* @return array
|
||
* @author ljj
|
||
* @date 2022/2/10 6:14 下午
|
||
*/
|
||
public function setWhere()
|
||
{
|
||
$this->where = [];
|
||
$params = $this->params;
|
||
if(isset($params['order_status']) && '' != $params['order_status']){
|
||
$this->where[] = ['O.order_status','=',$params['order_status']];
|
||
}
|
||
if (isset($params['order_info']) && $params['order_info'] != '') {
|
||
$this->where[] = ['O.sn','like','%'.$params['order_info'].'%'];
|
||
}
|
||
if (isset($params['user_info']) && $params['user_info'] != '') {
|
||
$this->where[] = ['U.sn|U.nickname|U.account','like','%'.$params['user_info'].'%'];
|
||
}
|
||
if (isset($params['goods_info']) && $params['goods_info'] != '') {
|
||
$orderIds = OrderGoods::where('goods_name','like','%'.$params['goods_info'].'%')->field('order_id')->select()->toArray();
|
||
empty($orderIds) && $orderIds = [];
|
||
$orderIds = array_column($orderIds,'order_id');
|
||
$this->where[] = ['O.id','in',implode(',',$orderIds)];
|
||
}
|
||
if (isset($params['pay_status']) && $params['pay_status'] != '') {
|
||
$this->where[] = ['O.pay_status','=',$params['pay_status']];
|
||
}
|
||
if (isset($params['start_time']) && $params['start_time'] != '') {
|
||
$timeType = $params['time_type'] ?? 1;
|
||
switch ($timeType){
|
||
case 1:
|
||
$this->where[] = ['O.create_time','>=',strtotime($params['start_time'])];
|
||
break;
|
||
case 2:
|
||
$this->where[] = ['O.pay_time','>=',strtotime($params['start_time'])];
|
||
break;
|
||
case 3:
|
||
$this->where[] = ['O.true_server_finish_time','>=',strtotime($params['start_time'])];
|
||
break;
|
||
}
|
||
}
|
||
if (isset($params['end_time']) && $params['end_time'] != '') {
|
||
$timeType = $params['time_type'] ?? 1;
|
||
switch ($timeType){
|
||
case 1:
|
||
$this->where[] = ['O.create_time','<=',strtotime($params['end_time'])];
|
||
break;
|
||
case 2:
|
||
$this->where[] = ['O.pay_time','<=',strtotime($params['end_time'])];
|
||
break;
|
||
case 3:
|
||
$this->where[] = ['O.true_server_finish_time','<=',strtotime($params['end_time'])];
|
||
break;
|
||
}
|
||
}
|
||
if (isset($params['coach_info']) && $params['coach_info'] != '') {
|
||
$this->where[] = ['C.name|C.sn','like','%'.$params['coach_info'].'%'];
|
||
}
|
||
if(isset($params['pay_way']) && $params['pay_way']){
|
||
$this->where[] = ['O.pay_way','=',$params['pay_way']];
|
||
}
|
||
if(isset($params['sn']) && $params['sn']){
|
||
$this->where[] = ['O.sn','like','%'.$params['sn'].'%'];
|
||
}
|
||
return $this->where;
|
||
}
|
||
|
||
/**
|
||
* @notes 订单列表
|
||
* @return array
|
||
* @author ljj
|
||
* @date 2022/2/10 6:19 下午
|
||
*/
|
||
public function lists(): array
|
||
{
|
||
self::setWhere();
|
||
$lists = Order::alias('O')
|
||
->join('user U','O.user_id = U.id')
|
||
->join('coach C','O.coach_id = C.id')
|
||
->where($this->where)
|
||
->order('O.id desc')
|
||
->field('O.id,O.shop_id,O.total_order_amount,O.total_refund_amount,O.order_distance,O.pay_status,O.user_id,O.total_amount,O.coach_id,O.sn,O.order_status,O.appoint_time,O.order_amount,O.create_time')
|
||
->append(['order_distance_desc','appoint_time','appoint_date','order_status_desc','take_order_btn','depart_btn','dispatch_btn','arrive_btn','server_start_btn','server_finish_btn','refund_btn','cancel_btn','order_cancel_time'])
|
||
->limit($this->limitOffset, $this->limitLength)
|
||
->select()->toArray();
|
||
if(empty($lists)){
|
||
return [];
|
||
}
|
||
$orderIds = array_column($lists,'id');
|
||
$lists = array_column($lists,null,'id');
|
||
$orderGoodsLists = OrderGoods::where(['order_id'=>$orderIds])->select()->toArray();
|
||
$coachIds = array_column($lists,'coach_id');
|
||
$coachLists = Coach::where(['id'=>$coachIds])->column('sn,name,work_photo,shop_id','id');
|
||
$shopIds = array_column($lists,'shop_id');
|
||
$shopLists = Shop::where(['id'=>$shopIds])->column('sn,name','id');
|
||
$userIds = array_column($lists,'user_id');
|
||
$userLists = User::where(['id'=>$userIds])->column('id,sn,nickname,mobile,avatar','id');
|
||
foreach ($orderGoodsLists as $orderGoodsList){
|
||
$orderGoods = $lists[$orderGoodsList['order_id']]['order_goods'] ?? [];
|
||
$orderGoods[] = $orderGoodsList;
|
||
$lists[$orderGoodsList['order_id']]['order_goods'] = $orderGoods;
|
||
}
|
||
foreach ($lists as $key => $order){
|
||
$lists[$key]['coach_info'] = $coachLists[$order['coach_id']] ?? [];
|
||
$lists[$key]['coach_info']['work_photo'] = FileService::getFileUrl($lists[$key]['coach_info']['work_photo'] ?? '');
|
||
$lists[$key]['shop_info'] = $shopLists[$order['shop_id']] ?? [];
|
||
$lists[$key]['user_info'] = $userLists[$order['user_id']] ?? [];
|
||
$lists[$key]['user_info']['avatar'] = FileService::getFileUrl($lists[$key]['user_info']['avatar'] ?? '');
|
||
if(!isset($order['address_snap']['house_number'])){
|
||
$lists[$key]['address_snap']['house_number'] = '';
|
||
}
|
||
}
|
||
|
||
return array_values($lists);
|
||
}
|
||
|
||
/**
|
||
* @notes 订单总数
|
||
* @return int
|
||
* @author ljj
|
||
* @date 2022/2/10 6:19 下午
|
||
*/
|
||
public function count(): int
|
||
{
|
||
return Order::alias('O')
|
||
->join('user U','O.user_id = U.id')
|
||
->join('coach C','O.coach_id = C.id')
|
||
->where($this->where)
|
||
->count();
|
||
}
|
||
|
||
/**
|
||
* @notes 订单数据统计
|
||
* @return array
|
||
* @author ljj
|
||
* @date 2022/2/15 11:07 上午
|
||
*/
|
||
public function extend(): array
|
||
{
|
||
if(isset($this->where[0]) && 'O.order_status' == $this->where[0][0]){
|
||
unset($this->where[0]);
|
||
$this->where = array_values($this->where);
|
||
}
|
||
$lists = Order::alias('O')
|
||
->join('user U','O.user_id = U.id')
|
||
->join('coach C','O.coach_id = C.id')
|
||
->where($this->where)
|
||
->field('O.order_status')
|
||
->select();
|
||
//全部
|
||
$data['all_count'] = 0;
|
||
//待支付
|
||
$data['wait_pay_count'] = 0;
|
||
//待接单
|
||
$data['wait_take_count'] = 0;
|
||
//待出发
|
||
$data['wait_depart_count'] = 0;
|
||
//已出发
|
||
$data['depart_count'] = 0;
|
||
//已到达
|
||
$data['arrive_count'] = 0;
|
||
//服务中
|
||
$data['start_server_count'] = 0;
|
||
//完成服务
|
||
$data['finish_server_count'] = 0;
|
||
//关闭
|
||
$data['close_count'] = 0;
|
||
$data['pay_way'] = PayConfig::field('id,name,pay_way')->select();
|
||
$data['order_status'] = OrderEnum::getOrderStatusDesc();
|
||
foreach ($lists as $val) {
|
||
//全部
|
||
$data['all_count'] += 1;
|
||
switch ($val['order_status']){
|
||
//待支付
|
||
case OrderEnum::ORDER_STATUS_WAIT_PAY:
|
||
$data['wait_pay_count']++;
|
||
break;
|
||
//待接单
|
||
case OrderEnum::ORDER_STATUS_WAIT_RECEIVING:
|
||
$data['wait_take_count']++;
|
||
break;
|
||
//待出发
|
||
case OrderEnum::ORDER_STATUS_WAIT_DEPART:
|
||
$data['wait_depart_count']++;
|
||
break;
|
||
//已出发
|
||
case OrderEnum::ORDER_STATUS_DEPART:
|
||
$data['depart_count']++;
|
||
break;
|
||
//已达到
|
||
case OrderEnum::ORDER_STATUS_ARRIVE:
|
||
$data['arrive_count']++;
|
||
break;
|
||
//服务中
|
||
case OrderEnum::ORDER_STATUS_START_SERVER:
|
||
$data['start_server_count']++;
|
||
break;
|
||
//完成服务
|
||
case OrderEnum::ORDER_STATUS_SERVER_FINISH:
|
||
$data['finish_server_count']++;
|
||
break;
|
||
//服务关闭
|
||
case OrderEnum::ORDER_STATUS_CLOSE:
|
||
$data['close_count']++;
|
||
break;
|
||
}
|
||
|
||
}
|
||
return $data;
|
||
}
|
||
} |