diff --git a/app/admin/controller/OrderController.php b/app/admin/controller/OrderController.php new file mode 100644 index 0000000..2ae5a26 --- /dev/null +++ b/app/admin/controller/OrderController.php @@ -0,0 +1,95 @@ +dataLists(new OrderLists()); + } + + + /** + * @notes 添加 + * @return \think\response\Json + * @author likeadmin + * @date 2025/07/17 17:16 + */ + public function add() + { + $params = (new OrderValidate())->post()->goCheck('add'); + $result = OrderLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(OrderLogic::getError()); + } + + + /** + * @notes 编辑 + * @return \think\response\Json + * @author likeadmin + * @date 2025/07/17 17:16 + */ + public function edit() + { + $params = (new OrderValidate())->post()->goCheck('edit'); + $result = OrderLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(OrderLogic::getError()); + } + + + /** + * @notes 删除 + * @return \think\response\Json + * @author likeadmin + * @date 2025/07/17 17:16 + */ + public function delete() + { + $params = (new OrderValidate())->post()->goCheck('delete'); + OrderLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取详情 + * @return \think\response\Json + * @author likeadmin + * @date 2025/07/17 17:16 + */ + public function detail() + { + $params = (new OrderValidate())->goCheck('detail'); + $result = OrderLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/lists/OrderLists.php b/app/admin/lists/OrderLists.php new file mode 100644 index 0000000..7fd2663 --- /dev/null +++ b/app/admin/lists/OrderLists.php @@ -0,0 +1,72 @@ + ['order_sn', 'uid', 'project_id', 'order_type', 'status', 'paid', 'pay_time', 'customer_name', 'phone'], + + ]; + } + + + /** + * @notes 获取列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2025/07/17 17:16 + */ + public function lists(): array + { + return Order::where($this->searchWhere) + ->with(['project']) + ->field(['id', 'order_sn', 'uid', 'project_id', 'order_type', 'total_amount', 'pay_amount', 'status', 'paid', 'pay_time', 'customer_name', 'phone', 'address', 'delivery_time', 'create_time']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->each(function ($item) { + $item['status_text'] = $item->statusText; + $item['pay_status_text'] = $item->payStatusText; + $item['order_type_text'] = $item->orderTypeText; + }) + ->toArray(); + } + + + /** + * @notes 获取数量 + * @return int + * @author likeadmin + * @date 2025/07/17 17:16 + */ + public function count(): int + { + return Order::where($this->searchWhere)->count(); + } + +} diff --git a/app/admin/logic/OrderLogic.php b/app/admin/logic/OrderLogic.php new file mode 100644 index 0000000..018f7f9 --- /dev/null +++ b/app/admin/logic/OrderLogic.php @@ -0,0 +1,130 @@ + $params['order_sn'], + 'uid' => $params['uid'], + 'project_id' => $params['project_id'], + 'order_type' => $params['order_type'], + 'total_amount' => $params['total_amount'], + 'pay_amount' => $params['pay_amount'], + 'status' => $params['status'], + 'paid' => $params['paid'], + 'pay_time' => $params['pay_time'], + 'customer_name' => $params['customer_name'], + 'phone' => $params['phone'], + 'address' => $params['address'], + 'delivery_time' => $params['delivery_time'], + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑 + * @param array $params + * @return bool + * @author likeadmin + * @date 2025/07/17 17:16 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + Order::where('id', $params['id'])->update([ + 'order_sn' => $params['order_sn'], + 'uid' => $params['uid'], + 'project_id' => $params['project_id'], + 'order_type' => $params['order_type'], + 'total_amount' => $params['total_amount'], + 'pay_amount' => $params['pay_amount'], + 'status' => $params['status'], + 'paid' => $params['paid'], + 'pay_time' => $params['pay_time'], + 'customer_name' => $params['customer_name'], + 'phone' => $params['phone'], + 'address' => $params['address'], + 'delivery_time' => $params['delivery_time'], + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除 + * @param array $params + * @return bool + * @author likeadmin + * @date 2025/07/17 17:16 + */ + public static function delete(array $params): bool + { + return Order::destroy($params['id']); + } + + + /** + * @notes 获取详情 + * @param $params + * @return array + * @author likeadmin + * @date 2025/07/17 17:16 + */ + public static function detail($params): array + { + $data = Order::with(['orderDishes' => function ($query) { + $query->with('dishes'); + }, 'orderProduct' => function ($query) { + $query->with('product'); + }])->findOrEmpty($params['id']); + if (empty($data)) { + self::setError('订单不存在'); + return []; + } + $data['status_text'] = $data->statusText; + $data['pay_status_text'] = $data->payStatusText; + $data['order_type_text'] = $data->orderTypeText; + return $data->toArray(); + } +} diff --git a/app/admin/validate/OrderValidate.php b/app/admin/validate/OrderValidate.php new file mode 100644 index 0000000..90113df --- /dev/null +++ b/app/admin/validate/OrderValidate.php @@ -0,0 +1,82 @@ + 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return OrderValidate + * @author likeadmin + * @date 2025/07/17 17:16 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return OrderValidate + * @author likeadmin + * @date 2025/07/17 17:16 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return OrderValidate + * @author likeadmin + * @date 2025/07/17 17:16 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return OrderValidate + * @author likeadmin + * @date 2025/07/17 17:16 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/model/Order.php b/app/common/model/Order.php new file mode 100644 index 0000000..a25e845 --- /dev/null +++ b/app/common/model/Order.php @@ -0,0 +1,71 @@ + '待发货', + 1 => '待收货', + 2 => '待评价', + 3 => '已完成', + 9 => '拼团中', + 10 => '待付尾款', + 11 => '尾款超时未付', + -1 => '已退款', + ]; + const OrderTypeMap = [ + 1 => '普通订单', + 2 => '自提订单', + ]; + const PayStatusMap = [ + 0 => '待支付', + 1 => '已支付', + ]; + + protected $name = 'order'; + protected $deleteTime = 'delete_time'; + + public function project() + { + return $this->hasOne(Project::class, 'id', 'project_id')->field('id,name'); + } + + public function orderDishes() + { + return $this->hasMany(OrderDishes::class, 'order_id', 'id'); + } + + public function orderProduct() + { + return $this->hasMany(OrderProduct::class, 'order_id', 'id'); + } + + public function getStatusTextAttr($value) + { + return self::StatusMap[$this->status]; + } + + public function getOrderTypeTextAttr($value) + { + return self::OrderTypeMap[$this->order_type]; + } + + public function getPayStatusTextAttr($value) + { + return self::PayStatusMap[$this->paid]; + } + +} diff --git a/app/common/model/OrderDishes.php b/app/common/model/OrderDishes.php new file mode 100644 index 0000000..3ac7366 --- /dev/null +++ b/app/common/model/OrderDishes.php @@ -0,0 +1,24 @@ +hasOne(Dishes::class, 'id', 'dishes_id'); + } + +} diff --git a/app/common/model/OrderProduct.php b/app/common/model/OrderProduct.php new file mode 100644 index 0000000..882d7ea --- /dev/null +++ b/app/common/model/OrderProduct.php @@ -0,0 +1,25 @@ +hasOne(Product::class, 'id', 'product_id'); + } + +}