Ai
1 Star 0 Fork 1

heli/简易订单处理系统

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
OrderController.php 3.88 KB
一键复制 编辑 原始数据 按行查看 历史
heli 提交于 2024-05-13 17:06 +08:00 . '修改'
<?php
//引入基础类文件
include 'BaseController.php';
//引入订单处理文件
include 'Service/OrderService.php';
class Order extends Base{
const orderStatusArr=['pending','completed','cancelled'];//订单状态值
//创建订单
public function createOrder(){
$product_id = $this->getParameter('product_id')?:1;
$quantity = $this->getParameter('quantity')?:2;
try {
// 检查是否接收到商品ID和数量
if ($product_id && $quantity) {
// 获取用户输入的商品ID和数量
$OrderService=new OrderService();
$res=$OrderService->create($product_id,$quantity);
if(!$res){
$this->error('订单创建失败');
}
// 输出成功消息
$this->success('订单生成成功',$res);
} else {
// 输出错误消息
$this->error('商品id或数量不存在');
}
} catch (PDOException $e) {
// 输出错误消息
$this->error($e->getMessage());
}
}
//更改订单状态
public function updateOrderStatus(){
$orderStatusArr=self::orderStatusArr;
$order_id = $this->getParameter('order_id')?:1;
$status = $this->getParameter('status')?:'completed';
if(!in_array($status,$orderStatusArr)){
$this->error('参数错误');
}
try {
// 检查是否接收到订单ID和状态值
if ($order_id && $status) {
$OrderService=new OrderService();
//查询当前订单状态
$order=$OrderService->getById($order_id);
if(!$order){
$this->error('订单不存在');
}
if($order['status']!='pending'){
$this->error('该状态不允许修改');
}
$res=$OrderService->updateStatus($order_id,$status);
if(!$res){
$this->error('订单修改失败');
}
// 输出成功消息
$this->success('订单修改成功');
} else {
// 输出错误消息
$this->error('订单id或状态值不存在');
}
} catch (PDOException $e) {
// 输出错误消息
$this->error($e->getMessage());
}
}
//查看订单详情
public function getOrder(){
$order_id = $this->getParameter('order_id')?:14;
try {
// 检查是否接收到订单ID
if ($order_id) {
$OrderService=new OrderService();
//查询当前订单状态
$order=$OrderService->getById($order_id);
if(!$order){
$this->error('订单不存在');
}
$this->success('success',$order);
} else {
// 输出错误消息
$this->error('订单id不存在');
}
} catch (PDOException $e) {
// 输出错误消息
$this->error($e->getMessage());
}
}
//支付回调
public function payNotice(){
//解析回调信息合法性
//////////
//验证成功获取到订单号
$order_no='';
$OrderService=new OrderService();
//查询当前订单状态
$order=$OrderService->getByNo($order_no);
if(!$order){
echo '订单不存在';
}
if($order['pay_status']==2){
echo '订单已经支付';
}
//更新订单支付状态
$res=$OrderService->updatePayOk($order['id']);
if($res){
echo 'success';
}
echo 'fail';
}
}
$methodName=$_GET['a'];
$exampleObj = new Order();
$exampleObj->$methodName();
?>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/heli97/simple-order-processing-system.git
git@gitee.com:heli97/simple-order-processing-system.git
heli97
simple-order-processing-system
简易订单处理系统
master

搜索帮助