商品库
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\model\PostCategory;
|
||||
use app\common\service\OssService;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\SkuService;
|
||||
use support\Request;
|
||||
|
||||
class SkuController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new SkuService();
|
||||
}
|
||||
public function store(Request $request)
|
||||
{
|
||||
try {
|
||||
$data = $this->validate($this->service->getValidator(), $request->post(), 'store');
|
||||
$res = $this->service->serviceStore($request, $data);
|
||||
return $this->success($res, '创建成功');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage().$e->getLine().$e->getFile());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
protected function indexFormat($data)
|
||||
{
|
||||
if (isset($data['created_at']))
|
||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
if (isset($data['updated_at']))
|
||||
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
if (isset($data['spec_json'])){
|
||||
$data['spec'] = json_decode($data['spec_json'], true);
|
||||
}
|
||||
if (isset($data['category_id']))
|
||||
$data['category_name'] = PostCategory::where('id', $data['category_id'])->value('name');
|
||||
$ossservice = new OssService();
|
||||
if (!empty($data['image'])){
|
||||
$data['image'] = explode(',',$data['image']);
|
||||
foreach ($data['image'] as $key => $image){
|
||||
$data['image_pull'][$key] = $ossservice->generatePrivateUrl($image);
|
||||
}
|
||||
}
|
||||
if (!empty($data['main_image'])){
|
||||
$data['main_image_pull'] = $ossservice->generatePrivateUrl($data['main_image']);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user