From 2ccae36c198ad9239a785822f76c8ca6f45f61e1 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Fri, 22 Mar 2024 16:38:16 +0800 Subject: [PATCH] 1 --- app/common/model/server/Order.php | 14 ++++++++++++- app/store/controller/Server.php | 35 ++++++++++++++++++++++++------- app/store/model/server/Server.php | 6 +++--- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/app/common/model/server/Order.php b/app/common/model/server/Order.php index e5e52b10..2646097b 100644 --- a/app/common/model/server/Order.php +++ b/app/common/model/server/Order.php @@ -3,6 +3,7 @@ declare (strict_types=1); namespace app\common\model\server; +use app\common\enum\payment\Method; use app\common\enum\ServerEnum; use app\common\model\UploadFile; use cores\BaseModel; @@ -24,12 +25,23 @@ class Order extends BaseModel */ protected $append = [ 'order_status_text', // 订单状态文字描述 + 'pay_method_text', //支付方式 ]; public function serve(): BelongsTo { - return $this->belongsTo(Server::class, 'id', 'server_id'); + return $this->belongsTo(Server::class, 'server_id', 'server_id'); + } + + public function getPayMethodTextAttr($value, $data): string + { + // 订单状态 + $result = Method::data(); + if (!empty($result[$data['pay_method']]['name'])) { + return $result[$data['pay_method']]['name']; + } + return '未知'; } /** diff --git a/app/store/controller/Server.php b/app/store/controller/Server.php index 93bcd74e..eda8636c 100644 --- a/app/store/controller/Server.php +++ b/app/store/controller/Server.php @@ -165,8 +165,7 @@ class Server extends Controller */ public function deleteServer(array $serverId): Json { - $model = new ServerModel; - if ($model->remove($serverId)) { + if (ServerModel::destroy($serverId)) { return $this->renderSuccess('删除成功'); } return $this->renderError('删除失败'); @@ -235,6 +234,22 @@ class Server extends Controller return $this->renderSuccess($data); } + /** + * @notes:订单详情 + * @return Json + * @author: wanghousheng + */ + public function orderDetail(): Json + { + $orderId = intval($this->request->post('orderId')); + $data = \app\common\model\server\Order::detail(['order_id' => $orderId], ['user', 'dealer', 'image']); + $data['server_info'] = null; + if (!empty($data['server_id'])) { + $data['server_info'] = ServerModel::detail($data['server_id'], ['category']); + } + return $this->renderSuccess(['detail' => $data]); + } + /** * @notes:订单状态 * @return Json @@ -297,16 +312,18 @@ class Server extends Controller /** * 服务配置 */ - public function configList() { + public function configList() + { $model = new StoreServerConfig(); - $list = $model->with(['iconImage'])->hidden(['iconImage'])->order(['sort'=>'desc','create_time'=>'desc'])->paginate(10); + $list = $model->with(['iconImage'])->hidden(['iconImage'])->order(['sort' => 'desc', 'create_time' => 'desc'])->paginate(10); return $this->renderSuccess(compact('list')); } /** * 服务配置添加 */ - public function configAdd() { + public function configAdd() + { $model = new StoreServerConfig(); if ($model->save(array_merge(['store_id' => $this->storeId], $this->postForm()))) { return $this->renderSuccess('新增成功'); @@ -317,7 +334,8 @@ class Server extends Controller /** * 服务配置编辑 */ - public function configEdit(int $id) { + public function configEdit(int $id) + { $detail = StoreServerConfig::get($id); if ($detail) { if ($detail->save($this->postForm())) { @@ -330,9 +348,10 @@ class Server extends Controller /** * 删除服务配置 */ - public function configDel(int $id) { + public function configDel(int $id) + { $detail = StoreServerConfig::get($id); - if($detail->delete()) { + if ($detail->delete()) { return $this->renderSuccess('删除成功'); } return $this->renderError('删除失败'); diff --git a/app/store/model/server/Server.php b/app/store/model/server/Server.php index ef844260..6dc7b553 100644 --- a/app/store/model/server/Server.php +++ b/app/store/model/server/Server.php @@ -36,12 +36,12 @@ class Server extends ServerModel /** * @notes:删除 * @param array $serverId - * @return bool * @author: wanghousheng */ - public function remove(array $serverId): bool + public function remove(array $serverId) { - return static::whereIn('server_id', $serverId)->delete(); + + return $this->whereIn('server_id', $serverId)->delete(); } /**