订单列表添加筛选条件

wxl
ztt 9 months ago
parent a1771b455c
commit c45d3c1d80
  1. 61
      app/api/common.php
  2. 28
      app/common.php
  3. 15
      app/common/model/Order.php
  4. 15
      app/store/model/Order.php
  5. 15
      app/store/model/OrderRefund.php

@ -27,3 +27,64 @@ function getPlatform(): ?string
} }
return $value; return $value;
} }
/**
* 计算用户和门店距离
* @param float $lat1 用户纬度
* @param float $lon1 用户经度
* @param float $lat2
* @param float $lon2
* @return float
*/
function calculateDistance($lat1, $lon1, $lat2, $lon2): float
{
// 将角度转换为弧度
$degToRad = M_PI / 180;
// 经纬度转换成弧度
$lat1 *= $degToRad;
$lon1 *= $degToRad;
$lat2 *= $degToRad;
$lon2 *= $degToRad;
// 应用Haversine Formula计算球体上两点之间的距离
$dLat = ($lat2 - $lat1);
$dLon = ($lon2 - $lon1);
$a = pow(sin($dLat/2), 2) + cos($lat1) * cos($lat2) * pow(sin($dLon/2), 2);
$c = 2 * atan2(sqrt($a), sqrt(1-$a));
$distance = 6371 * $c; // 地球平均半径为6371km
return round($distance, 2); // 返回结果保留小数点后两位
}
/**
* 格式化起止时间(为了兼容前端RangePicker组件)
* 2020-04-01T08:15:08.891Z => 1585670400
* @param array $times
* @param bool $isWithTime 是否包含时间
* @return array
*/
function between_time(array $times, bool $isWithTime = false): array
{
foreach ($times as &$time) {
$time = trim($time, '"');
$time = str2date($time, $isWithTime);
}
return ['start_time' => current($times), 'end_time' => next($times)];
}
/**
* 日期转换时间戳
* 例如: 2020-04-01 08:15:08 => 1585670400
* @param string $date
* @param bool $isWithTime 是否包含时间
* @return false|int
*/
function str2date(string $date, bool $isWithTime = false)
{
if (!$isWithTime) {
$date = date('Y-m-d', strtotime($date));
}
return strtotime($date);
}

@ -458,31 +458,3 @@ function getUrl($value, $host = ''){
return $value ? $host."/".$value : ""; return $value ? $host."/".$value : "";
} }
/**
* 计算用户和门店距离
* @param float $lat1 用户纬度
* @param float $lon1 用户经度
* @param float $lat2
* @param float $lon2
* @return float
*/
function calculateDistance($lat1, $lon1, $lat2, $lon2): float
{
// 将角度转换为弧度
$degToRad = M_PI / 180;
// 经纬度转换成弧度
$lat1 *= $degToRad;
$lon1 *= $degToRad;
$lat2 *= $degToRad;
$lon2 *= $degToRad;
// 应用Haversine Formula计算球体上两点之间的距离
$dLat = ($lat2 - $lat1);
$dLon = ($lon2 - $lon1);
$a = pow(sin($dLat/2), 2) + cos($lat1) * cos($lat2) * pow(sin($dLon/2), 2);
$c = 2 * atan2(sqrt($a), sqrt(1-$a));
$distance = 6371 * $c; // 地球平均半径为6371km
return round($distance, 2); // 返回结果保留小数点后两位
}

@ -12,6 +12,8 @@ declare (strict_types=1);
namespace app\common\model; namespace app\common\model;
use app\common\enum\order\DeliveryType;
use app\common\enum\payment\Method;
use cores\BaseModel; use cores\BaseModel;
use app\common\model\store\shop\Order as ShopOrder; use app\common\model\store\shop\Order as ShopOrder;
use app\common\service\Order as OrderService; use app\common\service\Order as OrderService;
@ -53,6 +55,8 @@ class Order extends BaseModel
*/ */
protected $append = [ protected $append = [
'state_text', // 售后单状态文字描述 'state_text', // 售后单状态文字描述
'pay_method_text', //订单支付方式文字描述
'delivery_type_text', //配送方式文字描述
]; ];
/** /**
@ -391,4 +395,15 @@ class Order extends BaseModel
} }
return true; return true;
} }
public function getPayMethodTextAttr($value,$data): string
{
return !empty(Method::data()[$data['pay_method']])?Method::data()[$data['pay_method']]['name']:'';//支付方式
}
public function getDeliveryTypeTextAttr($value,$data): string
{
return !empty(DeliveryType::data()[$data['delivery_type']])? DeliveryType::data()[$data['delivery_type']]['name']: '';//配送方式
}
} }

@ -13,17 +13,17 @@ declare (strict_types=1);
namespace app\store\model; namespace app\store\model;
use app\api\service\User as UserService; use app\api\service\User as UserService;
use app\common\enum\payment\Method;
use app\common\model\Order as OrderModel; use app\common\model\Order as OrderModel;
use app\common\service\Order as OrderService; use app\common\service\Order as OrderService;
use app\common\service\order\Refund as RefundService; use app\common\service\order\Refund as RefundService;
use app\common\service\order\Printer as PrinterService; use app\common\service\order\Printer as PrinterService;
use app\common\enum\order\{ use app\common\enum\order\{DataType as DataTypeEnum,
DataType as DataTypeEnum, DeliveryType,
PayStatus as PayStatusEnum, PayStatus as PayStatusEnum,
OrderStatus as OrderStatusEnum, OrderStatus as OrderStatusEnum,
ReceiptStatus as ReceiptStatusEnum, ReceiptStatus as ReceiptStatusEnum,
DeliveryStatus as DeliveryStatusEnum DeliveryStatus as DeliveryStatusEnum};
};
use app\common\library\helper; use app\common\library\helper;
use cores\exception\BaseException; use cores\exception\BaseException;
@ -121,7 +121,7 @@ class Order extends OrderModel
// 设置订单类型条件 // 设置订单类型条件
$dataTypeFilter = $this->getFilterDataType($param['dataType']); $dataTypeFilter = $this->getFilterDataType($param['dataType']);
// 获取数据列表 // 获取数据列表
$query = $this->with(['goods.image', 'user.avatar', 'address', 'delivery']) $query = $this
->alias('order') ->alias('order')
->field('order.*') ->field('order.*')
->leftJoin('user', 'user.user_id = order.user_id') ->leftJoin('user', 'user.user_id = order.user_id')
@ -133,8 +133,10 @@ class Order extends OrderModel
// $query = $query->whereOr($filterOr); // $query = $query->whereOr($filterOr);
$query = $query->where($filterOr); $query = $query->where($filterOr);
} }
// 加载关联订单数据
$list = $query->order(['order.create_time' => 'desc']) $list = $query->order(['order.create_time' => 'desc'])
->paginate(10); ->paginate(10);
$list = static::preload($list, ['goods.image', 'user.avatar', 'address', 'delivery'], true);
return $list; return $list;
} }
@ -197,7 +199,8 @@ class Order extends OrderModel
} }
// 起止时间 // 起止时间
if (!empty($params['betweenTime'])) { if (!empty($params['betweenTime'])) {
$times = between_time($params['betweenTime']); $betweenTime = explode(',', $params['betweenTime']);
$times = between_time($betweenTime);
$filter[] = ['order.create_time', '>=', $times['start_time']]; $filter[] = ['order.create_time', '>=', $times['start_time']];
$filter[] = ['order.create_time', '<', $times['end_time'] + 86400]; $filter[] = ['order.create_time', '<', $times['end_time'] + 86400];
} }

@ -13,6 +13,9 @@ declare (strict_types=1);
namespace app\store\model; namespace app\store\model;
use app\api\service\User as UserService; use app\api\service\User as UserService;
use app\common\enum\dealer\withdraw\PayType;
use app\common\enum\order\DeliveryType;
use app\common\enum\payment\Method;
use app\store\model\User as UserModel; use app\store\model\User as UserModel;
use app\common\model\OrderRefund as OrderRefundModel; use app\common\model\OrderRefund as OrderRefundModel;
use app\common\enum\order\refund\RefundType as RefundTypeEnum; use app\common\enum\order\refund\RefundType as RefundTypeEnum;
@ -101,7 +104,17 @@ class OrderRefund extends OrderRefundModel
$list = $query->order(['refund.create_time' => 'desc', 'refund.' . $this->getPk()]) $list = $query->order(['refund.create_time' => 'desc', 'refund.' . $this->getPk()])
->paginate(10); ->paginate(10);
// 加载关联订单数据 // 加载关联订单数据
return static::preload($list, ['goods.image', 'orderData', 'user.avatar']); $list = static::preload($list, ['goods.image', 'orderData', 'user.avatar'], true);
foreach ($list['data'] as $key => $row) {
$row['orderData']['pay_method_text'] = Method::data()[$row['orderData']['pay_method']]['name'];//支付方式
$row['orderData']['delivery_type_text'] = DeliveryType::data()[$row['orderData']['delivery_type']]['name'];//配送方式
// $row['orderData']['order_status'] = $row['orderData']['status'];
// unset($row['orderData']['status']);
$newRow = array_merge($row, $row['orderData']);
$list['data'][$key] = $newRow;
unset($list['data'][$key]['orderData']);
}
return $list;
} }
/** /**

Loading…
Cancel
Save