|
|
|
@ -41,165 +41,37 @@ class Goods extends Controller |
|
|
|
|
*/ |
|
|
|
|
public function index(): Json |
|
|
|
|
{ |
|
|
|
|
$list = Db::connect("dataCenterMysql")->table('goods_sku') |
|
|
|
|
|
|
|
|
|
->order('update_time desc') |
|
|
|
|
->paginate(15); |
|
|
|
|
return $this->renderSuccess(compact('list')); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取商城登录token |
|
|
|
|
* @param int $storeId |
|
|
|
|
* @return Json |
|
|
|
|
*/ |
|
|
|
|
public function superLogin(int $storeId): Json |
|
|
|
|
{ |
|
|
|
|
// 获取指定商城的管理员用户信息 |
|
|
|
|
$userInfo = StoreUserService::getUserInfoByStoreId($storeId); |
|
|
|
|
if (empty($userInfo)) { |
|
|
|
|
return $this->renderError('未找到该商城管理员用户'); |
|
|
|
|
} |
|
|
|
|
// 登录商户后台 |
|
|
|
|
$token = StoreUserService::login($userInfo->toArray()); |
|
|
|
|
return $this->renderSuccess([ |
|
|
|
|
'userId' => $userInfo['store_user_id'], |
|
|
|
|
'token' => $token |
|
|
|
|
]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 回收站列表 |
|
|
|
|
* @return Json |
|
|
|
|
* @throws \think\db\exception\DbException |
|
|
|
|
*/ |
|
|
|
|
public function recycle(): Json |
|
|
|
|
{ |
|
|
|
|
// 商城列表 |
|
|
|
|
$model = new StoreModel; |
|
|
|
|
$list = $model->getList(true); |
|
|
|
|
return $this->renderSuccess(compact('list')); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 新增商城 |
|
|
|
|
* @return Json |
|
|
|
|
*/ |
|
|
|
|
public function add(): Json |
|
|
|
|
{ |
|
|
|
|
// 新增记录 |
|
|
|
|
$model = new StoreModel; |
|
|
|
|
if ($model->add($this->postForm())) { |
|
|
|
|
return $this->renderSuccess('添加成功'); |
|
|
|
|
$params = $this->request->param(); |
|
|
|
|
$sort = $this->request->param('sort', 'id'); |
|
|
|
|
$order = $this->request->param('order', 'desc'); |
|
|
|
|
$where = []; |
|
|
|
|
if (isset($params['channel']) && $params['channel']) { |
|
|
|
|
$where[] = ['channel', '=', $params['channel']]; |
|
|
|
|
} |
|
|
|
|
return $this->renderError($model->getError() ?: '添加失败'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 移入回收站 |
|
|
|
|
* @param int $storeId |
|
|
|
|
* @return Json |
|
|
|
|
*/ |
|
|
|
|
public function recovery(int $storeId): Json |
|
|
|
|
{ |
|
|
|
|
// 商城详情 |
|
|
|
|
$model = StoreModel::detail($storeId); |
|
|
|
|
if (!$model->recycle()) { |
|
|
|
|
return $this->renderError($model->getError() ?: '操作失败'); |
|
|
|
|
if (isset($params['min_profit_rate']) && $params['min_profit_rate']) { |
|
|
|
|
$where[] = ['profit_rate', '>=', $params['min_profit_rate']]; |
|
|
|
|
} |
|
|
|
|
return $this->renderSuccess('操作成功'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 移出回收站 |
|
|
|
|
* @param int $storeId |
|
|
|
|
* @return Json |
|
|
|
|
*/ |
|
|
|
|
public function move(int $storeId): Json |
|
|
|
|
{ |
|
|
|
|
// 商城详情 |
|
|
|
|
$model = StoreModel::detail($storeId); |
|
|
|
|
if (!$model->recycle(false)) { |
|
|
|
|
return $this->renderError($model->getError() ?: '操作失败'); |
|
|
|
|
if (isset($params['max_profit_rate']) && $params['max_profit_rate']) { |
|
|
|
|
$where[] = ['profit_rate', '<=', $params['max_profit_rate']]; |
|
|
|
|
} |
|
|
|
|
return $this->renderSuccess('操作成功'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 删除商城 |
|
|
|
|
* @param int $storeId |
|
|
|
|
* @return Json |
|
|
|
|
*/ |
|
|
|
|
public function delete(int $storeId): Json |
|
|
|
|
{ |
|
|
|
|
// 商城详情 |
|
|
|
|
$model = StoreModel::detail($storeId); |
|
|
|
|
if (!$model->setDelete()) { |
|
|
|
|
return $this->renderError($model->getError() ?: '操作失败'); |
|
|
|
|
if (isset($params['min_price']) && $params['min_price']) { |
|
|
|
|
$where[] = ['net_price', '>=', $params['min_price']]; |
|
|
|
|
} |
|
|
|
|
return $this->renderSuccess('操作成功'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 审核商城 |
|
|
|
|
* @param int $storeId |
|
|
|
|
* @return Json |
|
|
|
|
*/ |
|
|
|
|
public function audit(int $storeId): Json |
|
|
|
|
{ |
|
|
|
|
// 商城详情 |
|
|
|
|
$model = StoreModel::detail($storeId); |
|
|
|
|
if (!$model->auditStore($this->request->param())) { |
|
|
|
|
return $this->renderError($model->getError() ?: '操作失败'); |
|
|
|
|
if (isset($params['max_price']) && $params['max_price']) { |
|
|
|
|
$where[] = ['net_price', '<=', $params['max_price']]; |
|
|
|
|
} |
|
|
|
|
return $this->renderSuccess('操作成功'); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 审核商城 |
|
|
|
|
* @param int $storeId |
|
|
|
|
* @return Json |
|
|
|
|
*/ |
|
|
|
|
public function platformList(): Json |
|
|
|
|
{ |
|
|
|
|
$platformList = [ |
|
|
|
|
'sn' => "苏宁" |
|
|
|
|
]; |
|
|
|
|
return $this->renderSuccess($platformList); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 审核商城 |
|
|
|
|
* @param int $storeId |
|
|
|
|
* @return Json |
|
|
|
|
*/ |
|
|
|
|
public function getStorePlatform(int $storeId): Json |
|
|
|
|
{ |
|
|
|
|
$list = SyncTask::where("store_id", $storeId)->order('create_time desc')->select()->toArray(); |
|
|
|
|
|
|
|
|
|
return $this->renderSuccess($list); |
|
|
|
|
$list = Db::connect("dataCenterMysql")->table('goods_sku') |
|
|
|
|
->where($where) |
|
|
|
|
->order($sort." ".$order) |
|
|
|
|
->paginate($this->request->param('per_page', 15))->each(function ($item, $key){ |
|
|
|
|
|
|
|
|
|
return $item; |
|
|
|
|
}); |
|
|
|
|
return $this->renderSuccess(compact('list')); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 审核商城 |
|
|
|
|
* @param int $storeId |
|
|
|
|
* @return Json |
|
|
|
|
*/ |
|
|
|
|
public function auth(int $storeId): Json |
|
|
|
|
{ |
|
|
|
|
SyncTask::where('store_id', $storeId)->delete(); |
|
|
|
|
$platformList = $this->request->param('platformList'); |
|
|
|
|
$inData = []; |
|
|
|
|
foreach ($platformList as $value) { |
|
|
|
|
$inData[] = [ |
|
|
|
|
'store_id' => $storeId, |
|
|
|
|
'channel' => $value, |
|
|
|
|
'create_time' => time(), |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
$model = new SyncTask; |
|
|
|
|
$model->addAll($inData); |
|
|
|
|
|
|
|
|
|
return $this->renderSuccess('操作成功'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|