You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
307 lines
14 KiB
307 lines
14 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
|
// +----------------------------------------------------------------------
|
|
// | Author: 萤火科技 <admin@yiovo.com>
|
|
// +----------------------------------------------------------------------
|
|
declare (strict_types=1);
|
|
|
|
namespace app\store\controller;
|
|
|
|
use app\store\model\Order as OrderModel;
|
|
use app\store\model\Goods as GoodsModel;
|
|
use think\response\Json;
|
|
use app\common\model\UploadFile as UploadFileModel;
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions\F;
|
|
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;
|
|
|
|
/**
|
|
* 订单管理
|
|
* Class Order
|
|
* @package app\store\controller
|
|
*/
|
|
class Order extends Controller
|
|
{
|
|
/**
|
|
* 订单列表
|
|
* @param string $dataType
|
|
* @return Json
|
|
*/
|
|
public function list(string $dataType): Json
|
|
{
|
|
// 订单列表
|
|
$model = new OrderModel;
|
|
$params = $this->request->param();
|
|
$params['merchantId'] = $this->merchantId;
|
|
$result = $model->getList($params);
|
|
$data = $result->items();
|
|
$goodsModel = new GoodsModel;
|
|
if (!empty($data)) {
|
|
foreach ($data as $key => $value) {
|
|
$data[$key]['address_match_text'] = '--';
|
|
$copy_text = "订单号:{$value['order_no']}\n";
|
|
$goods_images = $goodsModel->storeUsePlatformGoodsImage(array_column($value['goods']->toArray(), '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";
|
|
}
|
|
$data[$key]['copy_text'] = $copy_text;
|
|
if ($value['delivery_type'] == 10) {
|
|
if ($value['address_match'] == 20) {
|
|
$data[$key]['address_match_text'] = '匹配';
|
|
} else {
|
|
$data[$key]['address_match_text'] = '不匹配';
|
|
}
|
|
}
|
|
$merchant = null;
|
|
if ($value['merchant_id']) {
|
|
$merchant = \app\common\model\Merchant::detail($value['merchant_id'], $value['store_id']);
|
|
if ($merchant) {
|
|
if ($merchant['license_img_id']) {
|
|
$img_ids = explode(",", $merchant['license_img_id']);
|
|
$files = UploadFileModel::getFileList($img_ids, $value['store_id']);
|
|
$merchant['licenseImg'] = $files ?: null;
|
|
}
|
|
if ($merchant['logo_image_id']) {
|
|
$files = UploadFileModel::getFileList([$merchant['logo_image_id']], $value['store_id']);
|
|
$merchant['logoImage'] = $files ?: null;
|
|
}
|
|
}
|
|
|
|
}
|
|
$data[$key]['merchant'] = $merchant;
|
|
|
|
}
|
|
}
|
|
$list['current_page'] = $result->currentPage();
|
|
$list['last_page'] = $result->lastPage();
|
|
$list['total'] = $result->total();
|
|
$list['data'] = $data;
|
|
return $this->renderSuccess(compact('dataType', 'list'));
|
|
}
|
|
|
|
|
|
/**
|
|
* 订单详情
|
|
* @param int $orderId
|
|
* @return Json
|
|
*/
|
|
public function detail(int $orderId): Json
|
|
{
|
|
// 订单详情
|
|
$model = new OrderModel;
|
|
$MerchantRemarks = new MerchantRemarksModel;
|
|
if (!$detail = $model->getDetail($orderId)) {
|
|
return $this->renderError('未找到该订单记录');
|
|
}
|
|
$merchant = $MerchantRemarks->orderRemarkList($orderId);
|
|
if ($merchant) {
|
|
foreach ($merchant as $key => $value) {
|
|
// 初始化 $image_id 为 null 或者一个默认值
|
|
$image_id = null;
|
|
|
|
if (isset($value['image_id']) && !empty($value['image_id'])) {
|
|
$decoded_image_id = json_decode($value['image_id'], true);
|
|
|
|
// 检查 json_decode 是否成功并且结果中存在 'image_id' 键
|
|
if (is_array($decoded_image_id) && isset($decoded_image_id['image_id'])) {
|
|
$image_id = $decoded_image_id['image_id'];
|
|
}
|
|
}
|
|
|
|
if ($image_id !== null) { // 确保 $image_id 已经被设置
|
|
$item['image_id'] = $image_id;
|
|
$value['image_url'] = $MerchantRemarks->getRemarkImage($item['image_id']);
|
|
}
|
|
}
|
|
}
|
|
$detail['merchant'] = $merchant;
|
|
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'));
|
|
}
|
|
|
|
|
|
}
|
|
|