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.
yanzong/app/store/controller/Order.php

412 lines
18 KiB

11 months ago
<?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;
8 months ago
use think\response\Json;
5 months ago
use app\common\model\UploadFile as UploadFileModel;
5 months ago
use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions\F;
4 months ago
use app\common\model\MerchantRemarks as MerchantRemarksModel;
3 months ago
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;
2 months ago
use app\common\model\order\Delivery as DeliveryModel;
2 months ago
use app\common\model\Standard as StandardModel;
5 months ago
11 months ago
/**
* 订单管理
* Class Order
* @package app\store\controller
*/
class Order extends Controller
{
/**
* 订单列表
* @param string $dataType
* @return Json
*/
public function list(string $dataType): Json
{
// 订单列表
$model = new OrderModel;
7 months ago
$params = $this->request->param();
7 months ago
$params['merchantId'] = $this->merchantId;
7 months ago
$result = $model->getList($params);
8 months ago
$data = $result->items();
$goodsModel = new GoodsModel;
8 months ago
if (!empty($data)) {
foreach ($data as $key => $value) {
8 months ago
$data[$key]['address_match_text'] = '--';
8 months ago
$copy_text = "订单号:{$value['order_no']}\n";
$goods_images = $goodsModel->storeUsePlatformGoodsImage(array_column($value['goods']->toArray(), 'origin_goods_id'));
8 months ago
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'] ?? "";
}
8 months ago
$copy_text .= "商品名称:{$good['goods_name']}\n";
if (!empty($good['goods_no'])) {
7 months ago
$copy_text .= "商品编码:{$good['goods_no']}\n";
8 months ago
}
7 months ago
$copy_text .= "单价:{$good['goods_price']}\n";
$copy_text .= "数量:{$good['total_num']}\n";
$copy_text .= "总价:{$good['total_price']}\n";
8 months ago
$copy_text .= "\n";
}
if (!empty($value['address'])) {
7 months ago
$copy_text .= "\n";
8 months ago
$copy_text .= "收件人:{$value['address']['name']}\n";
7 months ago
$copy_text .= "电话:{$value['address']['phone']}\n";
8 months ago
$address = '';
if (!empty($value['address']['region'])) {
$address = $value['address']['region']['province'] . $value['address']['region']['city'] . $value['address']['region']['region'];
}
7 months ago
$copy_text .= "地址:$address{$value['address']['detail']}\n";
8 months ago
}
$data[$key]['copy_text'] = $copy_text;
8 months ago
if ($value['delivery_type'] == 10) {
if ($value['address_match'] == 20) {
$data[$key]['address_match_text'] = '匹配';
} else {
$data[$key]['address_match_text'] = '不匹配';
}
}
5 months ago
$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;
8 months ago
}
}
$list['current_page'] = $result->currentPage();
$list['last_page'] = $result->lastPage();
$list['total'] = $result->total();
$list['data'] = $data;
11 months ago
return $this->renderSuccess(compact('dataType', 'list'));
}
8 months ago
8 months ago
11 months ago
/**
* 订单详情
* @param int $orderId
* @return Json
*/
public function detail(int $orderId): Json
{
// 订单详情
$model = new OrderModel;
4 months ago
$MerchantRemarks = new MerchantRemarksModel;
11 months ago
if (!$detail = $model->getDetail($orderId)) {
return $this->renderError('未找到该订单记录');
}
4 months ago
$merchant = $MerchantRemarks->orderRemarkList($orderId);
4 months ago
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']);
}
4 months ago
}
}
$detail['merchant'] = $merchant;
11 months ago
return $this->renderSuccess(compact('detail'));
}
5 months ago
3 months ago
/**
* 订单列表
* @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'));
}
}
1 month ago
//强制取消订单
public function forceCancel(int $orderId){
$model = OrderModel::detail($orderId);
if ($model->cancel()) {
return $this->renderSuccess($model->getMessage());
}
return $this->renderError($model->getError() ?: '订单取消失败');
}
3 months ago
/**
* 非商城订单
*/
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'));
}
2 months ago
public function updateDelivery(int $delivery_id): Json
{
$model = new DeliveryModel;
2 months ago
if(!$model->where('delivery_id', $delivery_id)->find())
{
return $this->renderError('该物流记录不存在');
}
2 months ago
$model->where('delivery_id', $delivery_id)->save($this->postForm());
2 months ago
return $this->renderSuccess('修改成功');
2 months ago
}
5 months ago
2 months ago
/**
* 审单
* @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('修改成功');
}
11 months ago
}