From e01e6654884da903d92c822ec88c1dae7a7be0c9 Mon Sep 17 00:00:00 2001 From: lqmac Date: Sat, 3 Feb 2024 10:53:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=80=BB=E5=90=8E=E5=8F=B0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E5=92=8C=E5=95=86=E5=9F=8E=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + app/admin/controller/Goods.php | 210 +++++++++++++++++++++++++++++ app/admin/controller/Store.php | 57 ++++++++ app/admin/model/store/SyncTask.php | 28 ++++ config/database.php | 40 ++++++ 5 files changed, 336 insertions(+) create mode 100644 app/admin/controller/Goods.php create mode 100644 app/admin/model/store/SyncTask.php diff --git a/.gitignore b/.gitignore index 6260622e..75f63ea1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /runtime /public/uploads /public/static +sftp-config.json \ No newline at end of file diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php new file mode 100644 index 00000000..a663d57b --- /dev/null +++ b/app/admin/controller/Goods.php @@ -0,0 +1,210 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\admin\controller; + +use think\response\Json; +use think\facade\Db; + +/** + * 商城管理 + * Class Store + * @package app\admin\controller + */ +class Goods extends Controller +{ + /** + * 强制验证当前访问的控制器方法method + * @var array + */ + protected array $methodRules = [ + 'index' => 'GET', + 'recycle' => 'GET', + 'add' => 'POST', + 'move' => 'POST', + 'delete' => 'POST', + ]; + + /** + * 商城列表 + * @return Json + * @throws \think\db\exception\DbException + */ + 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('添加成功'); + } + 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() ?: '操作失败'); + } + 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() ?: '操作失败'); + } + 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() ?: '操作失败'); + } + 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() ?: '操作失败'); + } + 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); + } + + /** + * 审核商城 + * @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('操作成功'); + } + + + + + + + +} diff --git a/app/admin/controller/Store.php b/app/admin/controller/Store.php index f3a2568b..05465518 100644 --- a/app/admin/controller/Store.php +++ b/app/admin/controller/Store.php @@ -14,6 +14,7 @@ namespace app\admin\controller; use think\response\Json; use app\admin\model\Store as StoreModel; +use app\admin\model\store\SyncTask; use app\admin\service\store\User as StoreUserService; /** @@ -154,5 +155,61 @@ class Store extends Controller } 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); + } + + /** + * 审核商城 + * @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('操作成功'); + } + + + + + + + + + + } diff --git a/app/admin/model/store/SyncTask.php b/app/admin/model/store/SyncTask.php new file mode 100644 index 00000000..3bcffa29 --- /dev/null +++ b/app/admin/model/store/SyncTask.php @@ -0,0 +1,28 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\admin\model\store; +use cores\BaseModel; + +/** + * 商家功能模块模型 + * Class Module + * @package app\admin\model\store + */ +class SyncTask extends BaseModel +{ + // 定义表名 + protected $name = 'sync_task'; + + // 定义表主键 + protected $pk = 'id'; +} diff --git a/config/database.php b/config/database.php index 7adcff83..40f054b6 100644 --- a/config/database.php +++ b/config/database.php @@ -72,7 +72,47 @@ return [ // 字段缓存路径 'schema_cache_path' => app()->getRuntimePath() . 'schema' . DIRECTORY_SEPARATOR, ], + 'dataCenterMysql' => [ + // 数据库类型 + 'type' => env('database.type', 'mysql'), + // 服务器地址 + 'hostname' => env('database.hostname', $config['host']), + // 数据库名 + 'database' => "data_center", + // 用户名 + 'username' => env('database.username', $config['username']), + // 密码 + 'password' => env('database.password', $config['password']), + // 端口 + 'hostport' => env('database.hostport', $config['hostport']), + // 数据库连接参数 + 'params' => [], + // 数据库编码默认采用utf8 + 'charset' => env('database.charset', 'utf8'), + // 数据库表前缀 + 'prefix' => "", + + // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) + 'deploy' => 0, + // 数据库读写是否分离 主从式有效 + 'rw_separate' => false, + // 读写分离后 主服务器数量 + 'master_num' => 1, + // 指定从服务器序号 + 'slave_no' => '', + // 是否严格检查字段是否存在 + 'fields_strict' => true, + // 是否需要断线重连 + 'break_reconnect' => false, + // 监听SQL + 'trigger_sql' => true, + // 开启字段缓存 + 'fields_cache' => false, + // 字段缓存路径 + 'schema_cache_path' => app()->getRuntimePath() . 'schema' . DIRECTORY_SEPARATOR, + ], // 更多的数据库配置信息 ], + ];