售后服务

This commit is contained in:
TL 2022-08-31 17:16:24 +08:00
parent d9523418a1
commit 88f00f21c4
6 changed files with 65 additions and 7 deletions

View File

@ -11,6 +11,7 @@
namespace Beike\Admin\Http\Controllers;
use Beike\Admin\Http\Resources\RmaReasonDetail;
use Beike\Repositories\RmaReasonRepo;
use Beike\Repositories\LanguageRepo;
use Exception;
@ -21,9 +22,10 @@ class RmaReasonController extends Controller
public function index(Request $request)
{
$rmaReasons = RmaReasonRepo::list($request->only('name'));
$data = [
'languages' => LanguageRepo::all(),
'rmaReasons' => $rmaReasons,
'rmaReasons' => RmaReasonDetail::collection($rmaReasons)->jsonSerialize(),
];
return view('admin::pages.rma_reasons.index', $data);

View File

@ -0,0 +1,26 @@
<?php
/**
* RmaReasonDetail.php
*
* @copyright 2022 opencart.cn - All Rights Reserved
* @link http://www.guangdawangluo.com
* @author TL <mengwb@opencart.cn>
* @created 2022-08-31 11:56:28
* @modified 2022-08-31 11:56:28
*/
namespace Beike\Admin\Http\Resources;
use Beike\Repositories\RmaRepo;
use Illuminate\Http\Resources\Json\JsonResource;
class RmaReasonDetail extends JsonResource
{
public function toArray($request): array
{
return [
'id' => $this->id,
'name' => json_decode($this->name, true)[locale()] ?? '',
];
}
}

View File

@ -29,6 +29,7 @@ class RmaReasonRepo
*/
public static function create($data)
{
$data['name'] = json_encode($data['name']);
$item = RmaReason::query()->create($data);
return $item;
}
@ -47,6 +48,7 @@ class RmaReasonRepo
if (!$reason) {
throw new Exception("退换货原因id $reason 不存在");
}
$data['name'] = json_encode($data['name']);
$reason->update($data);
return $reason;
}
@ -78,10 +80,11 @@ class RmaReasonRepo
*/
public static function list(array $data = [])
{
$builder = RmaReason::query()->where('locale', locale());
$builder = RmaReason::query();
if (isset($data['name'])) {
$builder->where('name', 'like', "%{$data['name']}%");
$locale = locale();
$builder->whereJsonContains("name->$locale", 'like', "%{$data['name']}%");
}
return $builder->get();

View File

@ -12,6 +12,7 @@
namespace Beike\Shop\Http\Controllers\Account;
use App\Http\Controllers\Controller;
use Beike\Admin\Http\Resources\RmaReasonDetail;
use Beike\Repositories\RmaReasonRepo;
use Beike\Repositories\RmaRepo;
use Beike\Shop\Http\Requests\RmaRequest;
@ -54,7 +55,7 @@ class RmaController extends Controller
$data = [
'orderProduct' => OrderProductRepo::find($orderProductId),
'statuses' => RmaRepo::getStatuses(),
'reasons' => RmaReasonRepo::list()->toArray(),
'reasons' => RmaReasonDetail::collection(RmaReasonRepo::list())->jsonSerialize(),
'types' => RmaRepo::getTypes(),
];

View File

@ -0,0 +1,26 @@
<?php
/**
* RmaReasonDetail.php
*
* @copyright 2022 opencart.cn - All Rights Reserved
* @link http://www.guangdawangluo.com
* @author TL <mengwb@opencart.cn>
* @created 2022-08-31 11:56:28
* @modified 2022-08-31 11:56:28
*/
namespace Beike\Admin\Http\Resources;
use Beike\Repositories\RmaRepo;
use Illuminate\Http\Resources\Json\JsonResource;
class RmaReasonDetail extends JsonResource
{
public function toArray($request): array
{
return [
'id' => $this->id,
'name' => json_decode($this->name, true)[locale()] ?? '',
];
}
}

View File

@ -40,9 +40,9 @@ class ReturnTable extends Migration
$table->timestamps();
});
Schema::create('rma_reasons', function (Blueprint $table) {
$table->bigInteger('id');
$table->string('locale');
$table->string('name');
$table->id();
$table->json('name'); // 值示例: {"en":"cannot to use","zh_cn":"无法使用"}
$table->timestamps();
});
}