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.
422 lines
18 KiB
422 lines
18 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;
|
|
use app\common\model\order\Delivery as DeliveryModel;
|
|
use app\common\model\Standard as StandardModel;
|
|
|
|
/**
|
|
* 订单管理
|
|
* 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 forceCancel(int $orderId){
|
|
$model = OrderModel::detail($orderId);
|
|
if ($model->cancel()) {
|
|
return $this->renderSuccess($model->getMessage());
|
|
}
|
|
return $this->renderError($model->getError() ?: '订单取消失败');
|
|
}
|
|
/**
|
|
* 非商城订单
|
|
*/
|
|
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'));
|
|
}
|
|
|
|
public function updateDelivery(int $delivery_id): Json
|
|
{
|
|
$model = new DeliveryModel;
|
|
if(!$model->where('delivery_id', $delivery_id)->find())
|
|
{
|
|
return $this->renderError('该物流记录不存在');
|
|
}
|
|
|
|
$model->where('delivery_id', $delivery_id)->save($this->postForm());
|
|
return $this->renderSuccess('修改成功');
|
|
}
|
|
|
|
|
|
/**
|
|
* 审单
|
|
* @param $orderId
|
|
* @return Json
|
|
*/
|
|
public function standard($orderId): Json
|
|
{
|
|
$model = new OrderModel;
|
|
$standardCount = new StandardModel();
|
|
$params = $this->postForm();
|
|
$type = $params['type'];
|
|
$orderDetail = $model->where('order_id', $orderId)->find();
|
|
$count = $standardCount->where('order_id', $orderId)->count();
|
|
$num = $orderDetail['standard_count'] +1;
|
|
if (!$orderDetail) {
|
|
return $this->renderError('订单不存在');
|
|
}
|
|
//第一次审核
|
|
if (($orderDetail['standard_count'] !=0 && $type == 10) || ($count <1 && $type == 20) ) {
|
|
return $this->renderError('审核状态不对');
|
|
}
|
|
if($orderDetail['standard_status'] == 30)
|
|
{
|
|
return $this->renderError('请先在审单记录当中进行审核');
|
|
}
|
|
//第二次审核
|
|
if ($orderDetail['standard_count'] !=1 && $type == 20) {
|
|
return $this->renderError('审核状态不对');
|
|
}
|
|
if($orderDetail['standard_count'] == 1 || $orderDetail['standard_count'] == 0){
|
|
if ($model->where('order_id', $orderId)->update(['is_standard' => 1,"standard_count"=>$num])) {
|
|
// Db::name('order')->where('order_id',$orderId)->Inc('standard_count',1);
|
|
return $this->renderSuccess('操作成功');
|
|
}
|
|
}
|
|
return $this->renderError($model->getError() ?: '操作失败');
|
|
}
|
|
|
|
/**
|
|
* 获取审单记录
|
|
* @param $orderId
|
|
* @return Json
|
|
*/
|
|
public function getStandard(int $orderId): Json
|
|
{
|
|
$model = new StandardModel;
|
|
$list = $model->where("order_id",$orderId)->select();
|
|
foreach ($list as $key => $value) {
|
|
$value['order_image_url'] = UploadFile::withoutGlobalScope()->where("file_id",'in',$value['order_image'])->select();
|
|
$value['transfer_image_url'] = UploadFile::withoutGlobalScope()->where("file_id",'in',$value['transfer_image'])->select();
|
|
}
|
|
return $this->renderSuccess(compact('list'));
|
|
}
|
|
|
|
/**
|
|
* 修改审单记录
|
|
* [10通过 20不通过]
|
|
* @param $standardId
|
|
* @return Json
|
|
*/
|
|
public function updateStandard(int $standardId): Json
|
|
{
|
|
$model = new StandardModel;
|
|
$standard = $model->where('id', $standardId)->find();
|
|
if (!$standard) {
|
|
return $this->renderError('该记录不存在');
|
|
}
|
|
if ($standard['standard_status'] == 10|| $standard['standard_status'] == 20) {
|
|
return $this->renderError('该订单以审核过了');
|
|
}
|
|
$orderId = $standard['order_id'];
|
|
$data = $this->postForm();
|
|
$status = $data['standard_status'];
|
|
$cause = $data['cause'] ?? '';
|
|
$order = new OrderModel;
|
|
if ($status != 10 && $status != 20 ) {
|
|
return $this->renderError('状态错误');
|
|
}
|
|
$model->where("id",$standardId)->update(['standard_status'=>$status ,'cause'=>$cause]);
|
|
$order->where("order_id",$orderId)->update(['standard_status'=>$status,'standard_time'=>time(),'cause'=>$cause]);
|
|
|
|
return $this->renderSuccess('修改成功');
|
|
}
|
|
|
|
public function disputeStatus(int $orderId)
|
|
{
|
|
$params = $this->postForm();
|
|
$result = OrderModel::where('order_id',$orderId)->update(['dispute_status'=>$params['disputeStatus']]);
|
|
if ($result) {
|
|
return $this->renderSuccess('更新成功');
|
|
} else {
|
|
return $this->renderError('更新失败');
|
|
}
|
|
}
|
|
}
|
|
|