Browse Source

Merge branch 'goods_editor'

master
Lemon 5 years ago
parent
commit
0868fc7e46
  1. 3
      app/Controller/v3/GoodsController.php
  2. 1
      app/Controller/v3/OrderOnlineController.php
  3. 36
      app/Request/v3/GoodsEditorRequest.php
  4. 9
      app/Service/v3/Implementations/GoodsService.php

3
app/Controller/v3/GoodsController.php

@ -3,6 +3,7 @@
namespace App\Controller\v3;
use App\Controller\BaseController;
use App\Request\v3\GoodsEditorRequest;
use App\Service\v3\Interfaces\ShopCartServiceInterface;
use App\Service\v3\Implementations\GoodsActivityService;
use App\Service\v3\Interfaces\CollectStoreServiceInterface;
@ -78,7 +79,7 @@ class GoodsController extends BaseController
return $this->success($res);
}
public function update()
public function update(GoodsEditorRequest $request)
{
$res = $this->goodsService->update($this->request->all());
return $this->success($res);

1
app/Controller/v3/OrderOnlineController.php

@ -103,6 +103,7 @@ class OrderOnlineController extends BaseController
->orderByDesc('updated_at')
->first();
$market = Market::find($marketId);
$distance = 0;
if(!empty($address->lng) && !empty($address->lat)){
$distance = $this->locationService->getDistanceByTencent($market->lng,$market->lat,$address->lng,$address->lat);
}

36
app/Request/v3/GoodsEditorRequest.php

@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace App\Request\v3;
use App\Request\BaseFormRequest;
class GoodsEditorRequest extends BaseFormRequest
{
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
return [
'id' => 'required|nonempty|integer',
];
}
/**
* @return array
*/
public function messages(): array
{
return [
'*.*' => ':attribute无效',
];
}
public function attributes(): array
{
return parent::attributes();
}
}

9
app/Service/v3/Implementations/GoodsService.php

@ -78,15 +78,12 @@ class GoodsService implements GoodsServiceInterface
public function update($params)
{
$goods = Goods::query()->withoutGlobalScope('normal')->find($params['id']);
$goods = Goods::query()->withoutGlobalScope('normal')->where('id',$params['id'])->first();
if (empty($goods)) {
throw new ErrorCodeException( ErrorCode::GOODS_NOT_EXISTS);
}
foreach ($params as $k => $v){
if(isset($goods->$k)){
$goods->$k = $v;
}
}
$goods->price = $params['price'];
$goods->on_sale = $params['on_sale'];
return $goods->save();
}

Loading…
Cancel
Save