lqmac 3 months ago
commit ebc7e6f44c
  1. 2
      app/admin/model/Course.php
  2. 160
      app/store/controller/Order.php
  3. 58
      app/store/model/Order.php
  4. 59
      app/store/model/OrderRefund.php

@ -41,7 +41,7 @@ class Course extends CourseModel
// 检索查询条件 // 检索查询条件
$filter = $this->getFilter($param); $filter = $this->getFilter($param);
$list = $this->where($filter) $list = $this->where($filter)
->order(['course_id' => 'desc']) ->order(['sort' => 'asc','create_time' => 'desc'])
->paginate($pageSize); ->paginate($pageSize);
return $list; return $list;
} }

@ -18,6 +18,10 @@ use think\response\Json;
use app\common\model\UploadFile as UploadFileModel; use app\common\model\UploadFile as UploadFileModel;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions\F; use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions\F;
use app\common\model\MerchantRemarks as MerchantRemarksModel; use app\common\model\MerchantRemarks as MerchantRemarksModel;
use app\store\model\OrderRefund as OrderRefundModel;
use app\common\model\UploadFile;
use app\common\model\TransferRecord as TransferRecordModel;
use app\api\model\Express as ExpressModel;
/** /**
* 订单管理 * 订单管理
@ -143,5 +147,161 @@ class Order extends Controller
return $this->renderSuccess(compact('detail')); return $this->renderSuccess(compact('detail'));
} }
/**
* 订单列表
* @param string $dataType
* @return Json
*/
public function orderList(string $dataType): Json
{
$params = $this->request->param();
$params['searchType'] = 'all';
$goodsModel = new GoodsModel;
$MerchantRemarks = new MerchantRemarksModel();
// 订单列表
if (!empty($params['dataType']) && $params['dataType'] == 'refund') {
$model = new OrderRefundModel;
$list = $model->getOrderNewList($params);
if (!empty($list['data'])) {
foreach ($list['data'] as $key => &$value) {
$goods_images = $goodsModel->storeUsePlatformGoodsImage(array_column($value['goods'], 'origin_goods_id'));
foreach ($value['goods'] as &$good) {
//使用总后台的商品图片
if ($good['origin_goods_id'] && $value['store_id'] > 0) {
$good['goods_image'] = $goods_images[$good['origin_goods_id']][0]['file']['preview_url'] ?? "";
}
}
}
}
return $this->renderSuccess(compact('list'));
} else {
$model = new OrderModel;
$list = $model->getOrderList($params);
if (!empty($list['data'])) {
foreach ($list['data'] as $key => &$value) {
if (!empty($value['transfer']) && !empty($value['transfer']['chat_image_id'])) {
$chat_image_ids = UploadFile::whereIn('file_id', explode(",", $value['transfer']['chat_image_id']))->field('file_id,file_path,file_type,storage,domain')->select();
foreach ($chat_image_ids as &$chat_image_id) {
$chat_image_id['file_path'] = getUrl($chat_image_id['file_path'], $chat_image_id['domain']);
}
$list['data'][$key]['transfer']['chat_image_ids'] = $chat_image_ids;
}
if (!empty($value['transfer']) && !empty($value['transfer']['transfer_image_id'])) {
$transfer_image_ids = UploadFile::whereIn('file_id', explode(",", $value['transfer']['transfer_image_id']))->field('file_id,file_path,file_type,storage,domain')->select();
foreach ($transfer_image_ids as &$transfer_image_id) {
$transfer_image_id['file_path'] = getUrl($transfer_image_id['file_path'], $transfer_image_id['domain']);
}
$list['data'][$key]['transfer']['transfer_image_ids'] = $transfer_image_ids;
}
//复制信息
$copy_text = "订单号:{$value['order_no']}\n";
$goods_images = $goodsModel->storeUsePlatformGoodsImage(array_column($value['goods'], 'origin_goods_id'));
foreach ($value['goods'] as &$good) {
//使用总后台的商品图片
if ($good['origin_goods_id'] && $value['store_id'] > 0) {
$good['goods_image'] = $goods_images[$good['origin_goods_id']][0]['file']['preview_url'] ?? "";
}
$copy_text .= "商品名称:{$good['goods_name']}\n";
if (!empty($good['goods_no'])) {
$copy_text .= "商品编码:{$good['goods_no']}\n";
}
$copy_text .= "单价:{$good['goods_price']}\n";
$copy_text .= "数量:{$good['total_num']}\n";
$copy_text .= "总价:{$good['total_price']}\n";
$copy_text .= "\n";
}
if (!empty($value['address'])) {
$copy_text .= "\n";
$copy_text .= "收件人:{$value['address']['name']}\n";
$copy_text .= "电话:{$value['address']['phone']}\n";
$address = '';
if (!empty($value['address']['region'])) {
$address = $value['address']['region']['province'] . $value['address']['region']['city'] . $value['address']['region']['region'];
}
$copy_text .= "地址:$address{$value['address']['detail']}\n";
}
$list['data'][$key]['copy_text'] = $copy_text;
}
}
return $this->renderSuccess(compact('dataType', 'list'));
}
}
/**
* 非商城订单
*/
public function transferList(): Json
{
$params = $this->request->param();
$where = [];
if (!empty($params['search'])) {
$where[] = ['goods_sn', 'like', "%{$params["search"]}%"];
}
$list = TransferRecordModel::where('status', 1)
->where($where)
->order("id desc")
->paginate(10)->each(function ($item, $key) {
$goods_sn = explode("、", $item['goods_sn']);
$goods_num = explode("、", $item['goods_num']);
$goods_price = explode("、", $item['goods_price']);
$goods = [];
$total_price = 0;
foreach ($goods_sn as $seq => $value) {
$price = (float)$goods_price[$seq] ?? 0.00;
$goods[] = [
'name' => $value,
'price' => $price,
'num' => $goods_num[$seq] ?? 0,
"image" => 'https://imgservice5.suning.cn/uimg1/b2c/image/nXmtUUkwKxasCEBIX90d7w.png'
];
$total_price += $price;
}
$item['goods'] = $goods;
$item['total_price'] = $total_price;
$transfer_image_ids = UploadFile::whereIn('file_id', explode(",", $item['transfer_image_id']))->field('file_id,file_path,file_type,storage,domain')->select();
foreach ($transfer_image_ids as &$transfer_image_id) {
$transfer_image_id['file_path'] = getUrl($transfer_image_id['file_path'], $transfer_image_id['domain']);
}
$chat_image_ids = UploadFile::whereIn('file_id', explode(",", $item['chat_image_id']))->field('file_id,file_path,file_type,storage,domain')->select();
foreach ($chat_image_ids as &$chat_image_id) {
$chat_image_id['file_path'] = getUrl($chat_image_id['file_path'], $chat_image_id['domain']);
}
$item['transfer_image_ids'] = $transfer_image_ids;
$item['chat_image_ids'] = $chat_image_ids;
return $item;
})->toArray();
return $this->renderSuccess($list);
}
public function addTransfer(): Json
{
$params = $this->request->param();
$storeid = request()->header()['storeid'];
$params['user_id'] = \app\api\service\User::getCurrentLoginUserId();
$params['store_id'] = $storeid;
TransferRecordModel::create($params);
return $this->renderSuccess('ok');
}
/**
* 物流公司列表
* @return Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function expressList(): Json
{
$model = new ExpressModel;
$list = $model->getAll();
return $this->renderSuccess(compact('list'));
}
} }

@ -172,6 +172,64 @@ class Order extends OrderModel
return $list; return $list;
} }
/**
* 订单列表 (API调用)
* @param array $param
* @return mixed
*/
public function getOrderList(array $param = [])
{
// 检索查询条件
$filter = $this->getQueryFilter($param);
//不是店长查询当前用户订单
// if (!UserService::isStore()) {
// $filter[] = ['user.user_id', '=', UserService::getCurrentLoginUserId()];
// }
//普通会员和plus会员查询条件
if (!empty($param['user_id'])) {
$filter[] = ['user.user_id', '=', $param['user_id']];
}
if (!empty($param['delivery_type'])) {
//$filter[] = ['order.delivery_type', '=', DeliveryType::EXPRESS];
$filter[] = ['order.delivery_type', '=', $param['delivery_type']];
}
$filterOr = [];
if (!empty($param['searchValue']) && $param['searchType'] == 'all') {
// $filterOr = [
// ['order.order_no', 'like', "%{$param['searchValue']}%"],
// ['user.nick_name', 'like', "%{$param['searchValue']}%"],
// ['address.name', 'like', "%{$param['searchValue']}%"],
// ['address.phone', 'like', "%{$param['searchValue']}%"],
// ];
$filterOr = [
['order.order_no|user.nick_name|address.name|address.phone', 'like', "%{$param['searchValue']}%"]
];
}
// 设置订单类型条件
$dataTypeFilter = $this->getFilterDataType($param['dataType']);
// 获取数据列表
$query = $this
->alias('order')
->field('order.*')
->leftJoin('user', 'user.user_id = order.user_id')
->leftJoin('order_address address', 'address.order_id = order.order_id')
->where($dataTypeFilter)
->where($filter)
->with(['transfer'])
->where('order.is_delete', '=', 0);
if (!empty($filterOr)) {
// $query = $query->whereOr($filterOr);
$query = $query->where($filterOr);
}
// 加载关联订单数据
$list = $query->order(['order.create_time' => 'desc'])
->paginate($param['pageSize'] ?? 15);
$list = static::preload($list, ['goods.image', 'user.avatar', 'address', 'delivery'], true);
return $list;
}
/** /**
* 订单列表(全部) * 订单列表(全部)
* @param array $param * @param array $param

@ -29,6 +29,7 @@ use app\store\model\Order as OrderModel;
use app\store\model\OrderGoods as OrderGoodsMOdel; use app\store\model\OrderGoods as OrderGoodsMOdel;
use app\common\model\Goods as GoodsModel; use app\common\model\Goods as GoodsModel;
/** /**
* 售后单模型 * 售后单模型
* Class OrderRefund * Class OrderRefund
@ -139,6 +140,64 @@ class OrderRefund extends OrderRefundModel
return $list; return $list;
} }
/**
* 获取售后单列表
* @param array $param
* @return iterable|\think\model\Collection|\think\Paginator
*/
public function getOrderNewList(array $param = [])
{
// 检索查询条件
$filter = $this->getFilter($param);
// //不是店长查询当前用户订单
// if (!UserService::isStore()) {
// $filter[] = ['user.user_id', '=', UserService::getCurrentLoginUserId()];
// }
//普通会员和plus会员查询条件
if (!empty($param['user_id'])) {
$filter[] = ['user.user_id', '=', $param['user_id']];
}
if (!empty($param['delivery_type'])) {
$filter[] = ['order.delivery_type', '=', DeliveryType::EXPRESS];
}
$filterOr = [];
if (!empty($param['searchValue']) && $param['searchType'] == 'all') {
// $filterOr = [
// ['order.order_no', 'like', "%{$param['searchValue']}%"],
// ['user.nick_name', 'like', "%{$param['searchValue']}%"],
// ['order.user_id', '=', (int)$param['searchValue']]
// ];
$filterOr = [
['order.order_no|user.nick_name|order.user_id', 'like', "%{$param['searchValue']}%"]
];
}
// 获取列表数据
$query = $this
->alias('refund')
->field('refund.*, order.order_no')
->join('order', 'order.order_id = refund.order_id')
->join('user', 'user.user_id = order.user_id')
->where($filter);
if (!empty($filterOr)) {
// $query = $query->whereOr($filterOr);
$query = $query->where($filterOr);
}
$list = $query->order(['refund.create_time' => 'desc', 'refund.' . $this->getPk()])
->paginate(10);
// 加载关联订单数据
$list = static::preload($list, ['goods.image', 'orderData', 'user.avatar', 'images.file'], 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'];//配送方式
$newRow = array_merge($row, $row['orderData']);
$list['data'][$key] = $newRow;
unset($list['data'][$key]['orderData']);
}
return $list;
}
/** /**
* 获取售后单详情 * 获取售后单详情
* @param int $orderRefundId * @param int $orderRefundId

Loading…
Cancel
Save