diff --git a/app/common/enum/OrderEnum.php b/app/common/enum/OrderEnum.php index 6f6d337f3..1234e32e3 100644 --- a/app/common/enum/OrderEnum.php +++ b/app/common/enum/OrderEnum.php @@ -95,6 +95,10 @@ class OrderEnum const SUPPLIER = 3; const SYSTEM = 4; + const REFUND_STATUS_NO = 0; + const REFUND_STATUS_YES = 1; + const REFUND_STATUS_FINISH = 2; + /** * @notes 获取支付类型 * @param bool $value @@ -140,4 +144,39 @@ class OrderEnum } return $data[$value] ?? ''; } + + /** + * @notes 获取订单状态类型 + */ + public static function refundStatus($value = true) + { + $data = [ + self::REFUND_STATUS_NO => '未退款', + self::REFUND_STATUS_YES => '退款中', + self::REFUND_STATUS_FINISH => '已退款', + ]; + if ($value === true) { + return $data; + } + return $data[$value] ?? ''; + } + + /** + * @notes 获取订单状态类型 + */ + public static function refundType($value = true) + { + $data = [ + 1 => '仅退款', + 2 => '退款退货', + 3 => '拒绝退款', + 4 => '商品待退货', + 5 => '退货待收货', + 6 => '已退款', + ]; + if ($value === true) { + return $data; + } + return $data[$value] ?? ''; + } } diff --git a/app/common/lists/order/StoreRefundOrderLists.php b/app/common/lists/order/StoreRefundOrderLists.php new file mode 100644 index 000000000..ca54da8ed --- /dev/null +++ b/app/common/lists/order/StoreRefundOrderLists.php @@ -0,0 +1,88 @@ + ['order_id', 'refund_type'], + ]; + } + + + /** + * @notes 获取订单列表列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/05/31 16:02 + */ + public function lists(): array + { + return StoreOrder::with(['user', 'staff', 'product' => function ($query) { + $query->field(['id', 'oid', 'product_id', 'cart_info']); + }]) + ->where($this->searchWhere) + ->where('refund_status', '>', 0) + ->when(!empty($this->request->adminInfo['store_id']), function ($query) { + $query->where('store_id', '=', $this->request->adminInfo['store_id']); + }) + ->when(!empty($this->params['start_time']), function ($query) { + $query->whereTime('refund_reason_time', '>=', $this->params['start_time']); + }) + ->when(!empty($this->params['end_time']), function ($query) { + $query->whereTime('refund_reason_time', '<=', $this->params['end_time']); + }) + ->field(['id', 'store_id', 'staff_id', 'order_id', 'pay_price', 'pay_time', 'pay_type', 'status', 'uid', 'refund_status', 'refund_type', 'refund_reason_wap', 'refund_reason_time', 'refund_reason_wap_explain', 'refund_reason_wap_img']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function ($item) { + $item['pay_time'] = $item['pay_time'] > 0 ? date('Y-m-d H:i:s', $item['pay_time']) : ''; + $item['refund_status_name'] = OrderEnum::refundStatus($item['refund_status']) ?? ''; + $item['refund_type_name'] = OrderEnum::refundType($item['refund_type']) ?? ''; + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取订单列表数量 + * @return int + * @author admin + * @date 2024/05/31 16:02 + */ + public function count(): int + { + return StoreOrder::where($this->searchWhere) + ->where('refund_status', '>', 0) + ->when(!empty($this->request->adminInfo['store_id']), function ($query) { + $query->where('store_id', '=', $this->request->adminInfo['store_id']); + }) + ->when(!empty($this->params['start_time']), function ($query) { + $query->whereTime('refund_reason_time', '>=', $this->params['start_time']); + }) + ->when(!empty($this->params['end_time']), function ($query) { + $query->whereTime('refund_reason_time', '<=', $this->params['end_time']); + }) + ->count(); + } + +} diff --git a/app/common/logic/store_order/StoreOrderLogic.php b/app/common/logic/store_order/StoreOrderLogic.php index ac6db621c..acaa8e71a 100644 --- a/app/common/logic/store_order/StoreOrderLogic.php +++ b/app/common/logic/store_order/StoreOrderLogic.php @@ -126,6 +126,8 @@ class StoreOrderLogic extends BaseLogic } $order['pay_time'] = $order['pay_time'] > 0 ? date('Y-m-d H:i:s', $order['pay_time']) : ''; $order['status_name'] = OrderEnum::getOrderType($order['status']) ?? ''; + $order['refund_status_name'] = OrderEnum::refundStatus($order['refund_status']) ?? ''; + $order['refund_type_name'] = OrderEnum::refundType($order['refund_type']) ?? ''; return $order->toArray(); } diff --git a/app/store/controller/store_order/StoreRefundOrderController.php b/app/store/controller/store_order/StoreRefundOrderController.php new file mode 100644 index 000000000..14ffbb3ec --- /dev/null +++ b/app/store/controller/store_order/StoreRefundOrderController.php @@ -0,0 +1,98 @@ + 'id', 'desc' => 'ID', 'type' => 'int'], + ['name' => 'order_id', 'desc' => '订单编号', 'type' => 'string'], + ['name' => 'pay_price', 'desc' => '支付金额', 'type' => 'string'], + ['name' => 'pay_time', 'desc' => '支付时间', 'type' => 'float'], + ['name' => 'pay_type', 'desc' => '支付方式', 'type' => 'float'], + ['name' => 'status_name', 'desc' => '状态', 'type' => 'int'], + ['name' => 'refund_status_name', 'desc' => '退款状态', 'type' => 'string'], + ['name' => 'refund_type_name', 'desc' => '退款类型', 'type' => 'string'], + ['name' => 'refund_reason_time', 'desc' => '退款时间', 'type' => 'int'], + ['name' => 'staff_name', 'desc' => '店员', 'type' => 'int'], + ['name' => 'nickname', 'desc' => '用户昵称', 'type' => 'string'], + ['name' => 'avatar', 'desc' => '用户头像', 'type' => 'string'], + ['name' => 'product', 'desc' => '商品信息', 'type' => 'array', 'children' => [ + ['name' => 'cart_info', 'desc' => '商品信息', 'type' => 'array', 'children' => [ + ['name' => 'name', 'desc' => '商品名称', 'type' => 'int'], + ['name' => 'image', 'desc' => '图片', 'type' => 'string'], + ['name' => 'cart_num', 'desc' => '购买数量', 'type' => 'string'], + ['name' => 'price', 'desc' => '单价', 'type' => 'string'], + ]], + ]], + ]), + ] + public function lists() + { + return $this->dataLists(new StoreRefundOrderLists()); + } + + #[ + ApiDoc\Title('编辑订单'), + ApiDoc\url('/store/store_order/storeRefundOrder/edit'), + ApiDoc\Method('POST'), + ApiDoc\NotHeaders(), + ApiDoc\Author('中国队长'), + ApiDoc\Header(ref: [Definitions::class, "token"]), + ApiDoc\ResponseSuccess("data", type: "array"), + ] + public function edit() + { + $params = (new StoreOrderValidate())->post()->goCheck('edit'); + $result = StoreOrderLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(StoreOrderLogic::getError()); + } + + #[ + ApiDoc\Title('订单详情'), + ApiDoc\url('/store/store_order/storeRefundOrder/detail'), + ApiDoc\Method('GET'), + ApiDoc\NotHeaders(), + ApiDoc\Author('中国队长'), + ApiDoc\Header(ref: [Definitions::class, "token"]), + ApiDoc\Query(name: 'id', type: 'int', require: true, desc: '订单id'), + ApiDoc\ResponseSuccess("data", type: "array"), + ] + public function detail(StoreOrderLogic $orderLogic) + { + $params = (new StoreOrderValidate())->goCheck('detail'); + $result = $orderLogic->detail($params); + return $this->data($result); + } + + +}