售后服务申请(退换货)功能
This commit is contained in:
parent
78f3a181d7
commit
01f1822c27
|
|
@ -21,7 +21,7 @@ class RmaController extends Controller
|
|||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$rmas = RmaRepo::list($request->only('name', 'email', 'telephone', 'product_name', 'model', 'type', 'status'));
|
||||
$rmas = RmaRepo::list($request->only('name', 'email', 'telephone', 'product_name', 'sku', 'type', 'status'));
|
||||
$data = [
|
||||
'rmas' => $rmas,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -11,9 +11,17 @@
|
|||
|
||||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class OrderProduct extends Base
|
||||
{
|
||||
protected $fillable = [
|
||||
'product_id', 'order_number', 'product_sku', 'name', 'image', 'quantity', 'price',
|
||||
];
|
||||
|
||||
public function order(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Order::class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class Rma extends Base
|
|||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['order_id','order_product_id','customer_id','name','email','telephone','product_name','model','quantity','opened','rma_reason_id','type','status','comment'];
|
||||
protected $fillable = ['order_id','order_product_id','customer_id','name','email','telephone','product_name','sku','quantity','opened','rma_reason_id','type','status','comment'];
|
||||
|
||||
public function order() :BelongsTo
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,6 +12,11 @@
|
|||
namespace Beike\Repositories;
|
||||
|
||||
use Beike\Models\Order;
|
||||
use Beike\Models\OrderProduct;
|
||||
use Beike\Models\Rma;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class OrderProductRepo
|
||||
{
|
||||
|
|
@ -31,4 +36,13 @@ class OrderProductRepo
|
|||
}
|
||||
$order->orderProducts()->createMany($orderProducts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return Builder|Builder[]|Collection|Model|null
|
||||
*/
|
||||
public static function find($id)
|
||||
{
|
||||
return OrderProduct::query()->findOrFail($id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,8 +106,8 @@ class RmaRepo
|
|||
if (isset($data['product_name'])) {
|
||||
$builder->where('product_name', 'like', "%{$data['product_name']}%");
|
||||
}
|
||||
if (isset($data['model'])) {
|
||||
$builder->where('model', 'like', "%{$data['model']}%");
|
||||
if (isset($data['sku'])) {
|
||||
$builder->where('sku', 'like', "%{$data['sku']}%");
|
||||
}
|
||||
if (isset($data['type'])) {
|
||||
$builder->where('type', $data['type']);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
/**
|
||||
* RmaController.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
* @author TL <mengwb@opencart.cn>
|
||||
* @created 2022-08-03 21:17:04
|
||||
* @modified 2022-08-03 21:17:04
|
||||
*/
|
||||
|
||||
namespace Beike\Shop\Http\Controllers;
|
||||
|
||||
use Beike\Repositories\RmaRepo;
|
||||
use Beike\Shop\Http\Requests\RmaRequest;
|
||||
use Beike\Shop\Services\RmaService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class RmaController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$rmas = RmaRepo::listByCustomer(current_customer());
|
||||
$data = [
|
||||
'rmas' => $rmas,
|
||||
];
|
||||
|
||||
return view('rmas.index', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function show(int $id)
|
||||
{
|
||||
$data = [
|
||||
'rma' => RmaRepo::find($id),
|
||||
'statuses' => RmaRepo::getStatuses(),
|
||||
'types' => RmaRepo::getTypes(),
|
||||
];
|
||||
return view('rms/info', $data);
|
||||
}
|
||||
|
||||
public function create(int $orderProductId)
|
||||
{
|
||||
$data = [
|
||||
'orderProductId' => $orderProductId,
|
||||
'statuses' => RmaRepo::getStatuses(),
|
||||
'types' => RmaRepo::getTypes(),
|
||||
];
|
||||
return view('rms/form', $data);
|
||||
}
|
||||
|
||||
public function store(RmaRequest $request)
|
||||
{
|
||||
$rma = RmaService::createFromShop($request->only('order_product_id', 'quantity', 'opened', 'rma_reason_id', 'type', 'comment'));
|
||||
|
||||
return json_success('售后服务申请提交成功', $rma);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
/**
|
||||
* RmaRequest.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
* @author TL <mengwb@opencart.cn>
|
||||
* @created 2022-08-03 11:17:04
|
||||
* @modified 2022-08-03 11:17:04
|
||||
*/
|
||||
|
||||
namespace Beike\Shop\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class RmaRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$rules = [
|
||||
'order_id' => 'required|exists:orders,id',
|
||||
'order_product_id' => 'required|exists:order_products,id',
|
||||
'customer_id' => 'required|exists:customers,id',
|
||||
'quantity' => 'required',
|
||||
'opened' => 'required',
|
||||
'rma_reason_id' => 'required|exists:rma_reasons,id',
|
||||
'type' => 'required',
|
||||
];
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function attributes()
|
||||
{
|
||||
return [
|
||||
'order_id' => '订单',
|
||||
'order_product_id' => '订单商品',
|
||||
'customer_id' => '顾客',
|
||||
'quantity' => '数量',
|
||||
'opened' => '已拆包装',
|
||||
'rma_reason_id' => '退换货原因',
|
||||
'type' => '售后服务类型',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
/**
|
||||
* RmaService.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
* @author Sam Chen <sam.chen@opencart.cn>
|
||||
* @created 2022-08-03 16:52:57
|
||||
* @modified 2022-08-03 16:52:57
|
||||
*/
|
||||
|
||||
namespace Beike\Shop\Services;
|
||||
|
||||
|
||||
|
||||
use Beike\Repositories\OrderProductRepo;
|
||||
use Beike\Repositories\RmaRepo;
|
||||
|
||||
class RmaService
|
||||
{
|
||||
public static function createFromShop($data)
|
||||
{
|
||||
$orderProduct = OrderProductRepo::find($data['order_product_id']);
|
||||
$customer = current_customer();
|
||||
$params = [
|
||||
'order_id' => $orderProduct->order->id,
|
||||
'order_product_id' => $data['order_product_id'],
|
||||
'customer_id' => $customer->id,
|
||||
'name' => $customer->name,
|
||||
'email' => $customer->email,
|
||||
'telephone' => $customer->telephone,
|
||||
'product_name' => $orderProduct->name,
|
||||
'sku' => $orderProduct->product_sku,
|
||||
'product_name' => $orderProduct->name,
|
||||
'quantity' => $data['quantity'],
|
||||
'opened' => $data['opened'],
|
||||
'rma_reason_id' => $data['rma_reason_id'],
|
||||
'type' => $data['type'],
|
||||
'comment' => $data['comment'],
|
||||
];
|
||||
|
||||
$rma = RmaRepo::create($params);
|
||||
|
||||
return $rma;
|
||||
}
|
||||
}
|
||||
|
|
@ -22,7 +22,7 @@ class ReturnTable extends Migration
|
|||
$table->string('email');
|
||||
$table->string('telephone');
|
||||
$table->string('product_name');
|
||||
$table->string('model');
|
||||
$table->string('sku');
|
||||
$table->integer('quantity');
|
||||
$table->tinyInteger('opened');
|
||||
$table->unsignedInteger('rma_reason_id');
|
||||
|
|
|
|||
Loading…
Reference in New Issue