From c9e0822075996fc2d59c74a552c5c202aa34fe11 Mon Sep 17 00:00:00 2001 From: TL Date: Wed, 3 Aug 2022 14:55:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E9=80=80=E6=8D=A2=E8=B4=A7?= =?UTF-8?q?=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/Http/Controllers/RmaController.php | 5 +++++ beike/Models/Rma.php | 6 +++++ beike/Models/RmaHistory.php | 22 +++++++++++++++++++ beike/Repositories/RmaRepo.php | 14 ++++++++++++ 4 files changed, 47 insertions(+) create mode 100644 beike/Models/RmaHistory.php diff --git a/beike/Admin/Http/Controllers/RmaController.php b/beike/Admin/Http/Controllers/RmaController.php index 6572d285..4b18c054 100644 --- a/beike/Admin/Http/Controllers/RmaController.php +++ b/beike/Admin/Http/Controllers/RmaController.php @@ -43,6 +43,11 @@ class RmaController extends Controller return view('admin::pages.rmas.info', $data); } + public function addHistory(Request $request, int $id) + { + RmaRepo::addHistory($id, $request->only('status', 'notify', 'comment')); + } + public function destroy(int $id): array { RmaRepo::delete($id); diff --git a/beike/Models/Rma.php b/beike/Models/Rma.php index 7cc322f8..49a199b4 100644 --- a/beike/Models/Rma.php +++ b/beike/Models/Rma.php @@ -13,6 +13,7 @@ namespace Beike\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\HasMany; class Rma extends Base { @@ -39,4 +40,9 @@ class Rma extends Base { return $this->belongsTo(RmaReason::class); } + + public function histories() :HasMany + { + return $this->hasMany(RmaHistory::class); + } } diff --git a/beike/Models/RmaHistory.php b/beike/Models/RmaHistory.php new file mode 100644 index 00000000..d1e78496 --- /dev/null +++ b/beike/Models/RmaHistory.php @@ -0,0 +1,22 @@ + + * @created 2022-08-03 15:22:18 + * @modified 2022-08-03 15:22:18 + */ + +namespace Beike\Models; + +use Illuminate\Database\Eloquent\Factories\HasFactory; + +class RmaHistory extends Base +{ + use HasFactory; + + protected $fillable = ['rma_id', 'status', 'notify', 'comment']; +} + diff --git a/beike/Repositories/RmaRepo.php b/beike/Repositories/RmaRepo.php index 6ce13a1d..9d091997 100644 --- a/beike/Repositories/RmaRepo.php +++ b/beike/Repositories/RmaRepo.php @@ -60,6 +60,20 @@ class RmaRepo return Rma::query()->find($id); } + /** + * @param $rma + * @param array $data + * @return Rma + */ + public static function addHistory($rma, Array $data) + { + if (!$rma instanceof Rma) { + $rma = self::find($rma); + } + $rma->histories()->create($data); + return $rma; + } + /** * @param $id * @return void