|
|
|
@ -35,8 +35,13 @@ class Store extends Controller |
|
|
|
|
public function index(): Json |
|
|
|
|
{ |
|
|
|
|
// 商城列表 |
|
|
|
|
$model = new AdminStoreModel; |
|
|
|
|
$list = $model->getList(); |
|
|
|
|
$list = AdminStoreModel::withoutGlobalScope()->where('is_recycle', '=', 0) |
|
|
|
|
->where('p_store_id', '=', $this->storeId) |
|
|
|
|
|
|
|
|
|
->where('is_delete', '=', 0) |
|
|
|
|
->order(['sort' => 'asc', 'create_time' => 'desc']) |
|
|
|
|
->paginate(15); |
|
|
|
|
|
|
|
|
|
if (!$list->isEmpty()) { |
|
|
|
|
$list = $list->toArray(); |
|
|
|
|
foreach ($list['data'] as &$value) { |
|
|
|
@ -53,7 +58,15 @@ class Store extends Controller |
|
|
|
|
{ |
|
|
|
|
// 新增记录 |
|
|
|
|
$model = new AdminStoreModel; |
|
|
|
|
if ($model->add($this->postForm())) { |
|
|
|
|
$params = $this->postForm(); |
|
|
|
|
$params['is_store'] = 1; |
|
|
|
|
$params['p_store_id'] = $this->storeId; |
|
|
|
|
$store = AdminStoreModel::detail($this->storeId); |
|
|
|
|
$count = AdminStoreModel::withoutGlobalScope()->where('p_store_id', $this->storeId)->where('is_recycle', '=', 0)->where('is_delete', '=', 0)->count(); |
|
|
|
|
if ($store['limit_open_store_num'] <= $count) { |
|
|
|
|
return $this->renderError("您授权的商城数量已达到上限:".$count); |
|
|
|
|
} |
|
|
|
|
if ($model->add($params)) { |
|
|
|
|
return $this->renderSuccess('添加成功'); |
|
|
|
|
} |
|
|
|
|
return $this->renderError($model->getError() ?: '添加失败'); |
|
|
|
@ -65,11 +78,10 @@ class Store extends Controller |
|
|
|
|
public function edit(int $storeId): Json |
|
|
|
|
{ |
|
|
|
|
$params = $this->postForm(); |
|
|
|
|
// 商城详情 |
|
|
|
|
$model = AdminStoreModel::detail($storeId); |
|
|
|
|
|
|
|
|
|
// 更新记录 |
|
|
|
|
if (!$model->edit($params)) { |
|
|
|
|
return $this->renderError($model->getError() ?: '更新失败'); |
|
|
|
|
if (!AdminStoreModel::withoutGlobalScope()->where('store_id', $storeId)->update($params)) { |
|
|
|
|
return $this->renderError('更新失败'); |
|
|
|
|
} |
|
|
|
|
return $this->renderSuccess('更新成功'); |
|
|
|
|
} |
|
|
|
|