修改订单详情

This commit is contained in:
luofei 2024-06-05 15:49:43 +08:00
parent 337873c199
commit d1c52d222a
4 changed files with 49 additions and 35 deletions

View File

@ -28,7 +28,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
public function setSearch(): array public function setSearch(): array
{ {
return [ return [
'=' => ['order_id', 'pay_type', 'status'], '=' => ['order_id', 'pay_type', 'status', 'staff_id'],
]; ];
} }
@ -59,10 +59,9 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
->field(['id', 'store_id', 'staff_id', 'order_id', 'pay_price', 'pay_time', 'pay_type', 'status', 'uid']) ->field(['id', 'store_id', 'staff_id', 'order_id', 'pay_price', 'pay_time', 'pay_type', 'status', 'uid'])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->order(['id' => 'desc'])
->select()->each(function($item){ ->select()->each(function ($item) {
$item['pay_type_name']=PayEnum::getPaySceneDesc($item['pay_type']); $item['pay_time'] = $item['pay_time'] > 0 ? date('Y-m-d H:i:s', $item['pay_time']) : '';
$item['pay_time']=$item['pay_time']>0?date('Y-m-d H:i:s',$item['pay_time']):''; $item['status_name'] = OrderEnum::getOrderType($item['status']) ?? '';
$item['status_name']= OrderEnum::getOrderType($item['status'])??'';
return $item; return $item;
}) })

View File

@ -1,6 +1,8 @@
<?php <?php
namespace app\common\logic\store_order; namespace app\common\logic\store_order;
use app\common\enum\OrderEnum;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use app\common\enum\PayEnum; use app\common\enum\PayEnum;
use app\common\model\order\Cart; use app\common\model\order\Cart;
@ -14,6 +16,7 @@ use think\facade\Db;
class StoreOrderLogic extends BaseLogic class StoreOrderLogic extends BaseLogic
{ {
public static $total; public static $total;
/** /**
* @notes 获取购物车商品信息 * @notes 获取购物车商品信息
* @param $params * @param $params
@ -33,7 +36,7 @@ class StoreOrderLogic extends BaseLogic
/** 计算价格 */ /** 计算价格 */
foreach ($cart_select as $k => $v) { foreach ($cart_select as $k => $v) {
$find = StoreProduct::where(['id' => $v['product_id']])->field('store_name,image,unit,price')->find(); $find = StoreProduct::where(['id' => $v['product_id']])->field('store_name,image,unit,price')->find();
if(!$find){ if (!$find) {
continue; continue;
} }
$cart_select[$k]['total'] = bcmul($v['cart_num'], $find['price'], 2); $cart_select[$k]['total'] = bcmul($v['cart_num'], $find['price'], 2);
@ -44,7 +47,7 @@ class StoreOrderLogic extends BaseLogic
$cart_select[$k]['product_id'] = $v['product_id']; $cart_select[$k]['product_id'] = $v['product_id'];
$cart_select[$k]['cart_num'] = $v['cart_num']; $cart_select[$k]['cart_num'] = $v['cart_num'];
$cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name'); $cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name');
self::$total=bcadd(self::$total, $cart_select[$k]['total'], 2); self::$total = bcadd(self::$total, $cart_select[$k]['total'], 2);
} }
$order = [ $order = [
'time' => time(), 'time' => time(),
@ -52,7 +55,7 @@ class StoreOrderLogic extends BaseLogic
'total' => self::$total, 'total' => self::$total,
'pay_type' => $params['pay_type'] ?? 0, 'pay_type' => $params['pay_type'] ?? 0,
'cart_id' => implode(',', $cartId), 'cart_id' => implode(',', $cartId),
'delivery_msg'=>' 预计48小时发货 ' 'delivery_msg' => ' 预计48小时发货 '
]; ];
} catch (\Exception $e) { } catch (\Exception $e) {
self::setError($e->getMessage()); self::setError($e->getMessage());
@ -68,16 +71,16 @@ class StoreOrderLogic extends BaseLogic
static public function createOrder($cartId, $addressId, $user = null, $params = []) static public function createOrder($cartId, $addressId, $user = null, $params = [])
{ {
$orderInfo = self::cartIdByOrderInfo($cartId, $addressId, $user, $params); $orderInfo = self::cartIdByOrderInfo($cartId, $addressId, $user, $params);
if(!$orderInfo){ if (!$orderInfo) {
return false; return false;
} }
$_order = $orderInfo['order']; $_order = $orderInfo['order'];
$_order['deduction_price'] = 0; $_order['deduction_price'] = 0;
$_order['store_id'] = $params['store_id']; $_order['store_id'] = $params['store_id'];
$_order['uid'] = request()->userId; $_order['uid'] = request()->userId;
if($addressId>0){ if ($addressId > 0) {
$address=UserAddress::where(['id'=>$addressId,'uid'=>Request()->userId])->find(); $address = UserAddress::where(['id' => $addressId, 'uid' => Request()->userId])->find();
if($address){ if ($address) {
$_order['real_name'] = $address['real_name']; $_order['real_name'] = $address['real_name'];
$_order['user_phone'] = $address['phone']; $_order['user_phone'] = $address['phone'];
$_order['user_address'] = $address['detail']; $_order['user_address'] = $address['detail'];
@ -85,8 +88,8 @@ class StoreOrderLogic extends BaseLogic
} }
} }
if($params['pay_type']==PayEnum::CASH_PAY){ if ($params['pay_type'] == PayEnum::CASH_PAY) {
$_order['money']=$_order['total']; $_order['money'] = $_order['total'];
} }
Db::startTrans(); Db::startTrans();
try { try {
@ -98,7 +101,7 @@ class StoreOrderLogic extends BaseLogic
} }
(new StoreOrderCartInfo())->saveAll($goods_list); (new StoreOrderCartInfo())->saveAll($goods_list);
$where = ['is_pay' => 0, 'is_fail' => 0]; $where = ['is_pay' => 0, 'is_fail' => 0];
Cart::whereIn('id', $cartId)->where($where)->update(['is_pay'=>1]); Cart::whereIn('id', $cartId)->where($where)->update(['is_pay' => 1]);
Db::commit(); Db::commit();
return $order; return $order;
} catch (\Exception $e) { } catch (\Exception $e) {
@ -108,6 +111,31 @@ class StoreOrderLogic extends BaseLogic
} }
} }
/**
* 订单详情
* @param $params
* @return array
*/
public function detail($params)
{
$order = StoreOrder::with(['user', 'staff', 'product' => function ($query) {
$query->field(['id', 'oid', 'product_id', 'cart_info']);
}])->where($params)->find();
if (empty($order)) {
throw new \Exception('订单不存在');
}
$order['pay_time'] = $order['pay_time'] > 0 ? date('Y-m-d H:i:s', $order['pay_time']) : '';
$order['status_name'] = OrderEnum::getOrderType($order['status']) ?? '';
return $order->toArray();
}
/**
* 订单统计
* @param $storeId
* @param $status
* @return int|\think\db\Query
* @throws \think\db\exception\DbException
*/
public function storeOrderCount($storeId, $status) public function storeOrderCount($storeId, $status)
{ {
return StoreOrder::where(['store_id' => $storeId, 'status' => $status, 'paid' => 1])->count(); return StoreOrder::where(['store_id' => $storeId, 'status' => $status, 'paid' => 1])->count();

View File

@ -43,7 +43,7 @@ class StoreOrder extends BaseModel
public function user() public function user()
{ {
return $this->hasOne(User::class, 'id', 'uid')->bind(['nickname', 'avatar']); return $this->hasOne(User::class, 'id', 'uid')->bind(['nickname', 'avatar', 'mobile']);
} }
public function product() public function product()

View File

@ -7,6 +7,7 @@ use app\admin\lists\store_order\StoreOrderLists;
use app\common\controller\Definitions; use app\common\controller\Definitions;
use app\common\enum\PayEnum; use app\common\enum\PayEnum;
use app\common\logic\SystemStoreStaffLogic; use app\common\logic\SystemStoreStaffLogic;
use app\common\model\store_order\StoreOrder;
use app\store\controller\BaseAdminController; use app\store\controller\BaseAdminController;
use app\common\logic\store_order\StoreOrderLogic; use app\common\logic\store_order\StoreOrderLogic;
use app\store\validate\store_order\StoreOrderValidate; use app\store\validate\store_order\StoreOrderValidate;
@ -29,6 +30,7 @@ class StoreOrderController extends BaseAdminController
ApiDoc\NotHeaders(), ApiDoc\NotHeaders(),
ApiDoc\Author('中国队长'), ApiDoc\Author('中国队长'),
ApiDoc\Query(name: 'order_id', type: 'string', require: false, desc: '订单编号'), ApiDoc\Query(name: 'order_id', type: 'string', require: false, desc: '订单编号'),
ApiDoc\Query(name: 'staff_id', type: 'int', require: false, desc: '店员id'),
ApiDoc\Query(name: 'pay_type', type: 'int', require: false, desc: '支付方式'), ApiDoc\Query(name: 'pay_type', type: 'int', require: false, desc: '支付方式'),
ApiDoc\Query(name: 'start_time', type: 'string', require: false, desc: '开始时间'), ApiDoc\Query(name: 'start_time', type: 'string', require: false, desc: '开始时间'),
ApiDoc\Query(name: 'end_time', type: 'string', require: false, desc: '结束时间'), ApiDoc\Query(name: 'end_time', type: 'string', require: false, desc: '结束时间'),
@ -40,7 +42,7 @@ class StoreOrderController extends BaseAdminController
['name' => 'order_id', 'desc' => '订单编号', 'type' => 'string'], ['name' => 'order_id', 'desc' => '订单编号', 'type' => 'string'],
['name' => 'pay_price', 'desc' => '支付金额', 'type' => 'string'], ['name' => 'pay_price', 'desc' => '支付金额', 'type' => 'string'],
['name' => 'pay_time', 'desc' => '支付时间', 'type' => 'float'], ['name' => 'pay_time', 'desc' => '支付时间', 'type' => 'float'],
['name' => 'pay_type_name', 'desc' => '支付方式', 'type' => 'float'], ['name' => 'pay_type', 'desc' => '支付方式', 'type' => 'float'],
['name' => 'status_name', 'desc' => '状态', 'type' => 'int'], ['name' => 'status_name', 'desc' => '状态', 'type' => 'int'],
['name' => 'staff_name', 'desc' => '店员', 'type' => 'int'], ['name' => 'staff_name', 'desc' => '店员', 'type' => 'int'],
['name' => 'nickname', 'desc' => '用户昵称', 'type' => 'string'], ['name' => 'nickname', 'desc' => '用户昵称', 'type' => 'string'],
@ -120,22 +122,6 @@ class StoreOrderController extends BaseAdminController
return $this->fail(StoreOrderLogic::getError()); return $this->fail(StoreOrderLogic::getError());
} }
#[
ApiDoc\Title('删除订单'),
ApiDoc\url('/store/store_order/storeOrder/delete'),
ApiDoc\Method('POST'),
ApiDoc\NotHeaders(),
ApiDoc\Author('中国队长'),
ApiDoc\Header(ref: [Definitions::class, "token"]),
ApiDoc\ResponseSuccess("data", type: "array"),
]
public function delete()
{
$params = (new StoreOrderValidate())->post()->goCheck('delete');
StoreOrderLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
#[ #[
ApiDoc\Title('订单详情'), ApiDoc\Title('订单详情'),
ApiDoc\url('/store/store_order/storeOrder/detail'), ApiDoc\url('/store/store_order/storeOrder/detail'),
@ -143,12 +129,13 @@ class StoreOrderController extends BaseAdminController
ApiDoc\NotHeaders(), ApiDoc\NotHeaders(),
ApiDoc\Author('中国队长'), ApiDoc\Author('中国队长'),
ApiDoc\Header(ref: [Definitions::class, "token"]), ApiDoc\Header(ref: [Definitions::class, "token"]),
ApiDoc\Query(name: 'id', type: 'int', require: true, desc: '订单id'),
ApiDoc\ResponseSuccess("data", type: "array"), ApiDoc\ResponseSuccess("data", type: "array"),
] ]
public function detail() public function detail(StoreOrderLogic $orderLogic)
{ {
$params = (new StoreOrderValidate())->goCheck('detail'); $params = (new StoreOrderValidate())->goCheck('detail');
$result = StoreOrderLogic::detail($params); $result = $orderLogic->detail($params);
return $this->data($result); return $this->data($result);
} }