|
|
@@ -0,0 +1,116 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\controller\admin;
|
|
|
+
|
|
|
+use app\extra\basic\Base;
|
|
|
+use app\extra\tools\DataExtend;
|
|
|
+use app\middleware\AuthMiddleware;
|
|
|
+use app\model\saas\SaasCategory;
|
|
|
+use app\service\saas\CategoryService;
|
|
|
+use DI\Attribute\Inject;
|
|
|
+use LinFly\Annotation\Attributes\Route\Controller;
|
|
|
+use LinFly\Annotation\Attributes\Route\GetMapping;
|
|
|
+use LinFly\Annotation\Attributes\Route\Middleware;
|
|
|
+use LinFly\Annotation\Attributes\Route\PostMapping;
|
|
|
+use support\Request;
|
|
|
+use support\Response;
|
|
|
+use Webman\RedisQueue\Redis;
|
|
|
+
|
|
|
+
|
|
|
+#[Controller("/api/category"),Middleware(AuthMiddleware::class)]
|
|
|
+class Category extends Base
|
|
|
+{
|
|
|
+
|
|
|
+ #[Inject]
|
|
|
+ protected CategoryService $service;
|
|
|
+
|
|
|
+ #[Inject]
|
|
|
+ protected SaasCategory $model;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据列表
|
|
|
+ * @param Request $request
|
|
|
+ * @return Response
|
|
|
+ */
|
|
|
+ #[GetMapping('list')]
|
|
|
+ public function getStoreCategory(Request $request): Response
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $data = $this->service->setModel()->getList($request->all(),null,true);
|
|
|
+ $tree = DataExtend::arr2tree($data,"category_id","parent_id");
|
|
|
+ return successTrans(100010,$tree,200);
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ return error($th->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 同步门店分类
|
|
|
+ * @param Request $request
|
|
|
+ * @return Response
|
|
|
+ */
|
|
|
+ #[GetMapping('sync')]
|
|
|
+ public function syncStore(Request $request): Response
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ Redis::send("sync-category",[
|
|
|
+ "appid" => sConf("wechat.appid"),
|
|
|
+ "secret" => sConf("wechat.secret"),
|
|
|
+ "account" => sConf("wechat.shop_id"),
|
|
|
+ ]);
|
|
|
+ return success("发起成功");
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
+ return error($throwable->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 编辑代理信息
|
|
|
+ * @param Request $request
|
|
|
+ * @return Response
|
|
|
+ */
|
|
|
+ #[PostMapping("edit")]
|
|
|
+ public function setListData(Request $request): Response
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $param = $request->post();
|
|
|
+ $factory = $this->model->where("id",$param['id'])->findOrEmpty();
|
|
|
+ if ($factory->isEmpty()) return errorTrans("error.data");
|
|
|
+ $state = $this->model->setAutoData($param);
|
|
|
+ if (!$state) return errorTrans("error.data");
|
|
|
+ return successTrans("success.data");
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
+ return error($throwable->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量操作
|
|
|
+ * @param Request $request
|
|
|
+ * @return Response
|
|
|
+ */
|
|
|
+ #[PostMapping("batch")]
|
|
|
+ public function setGoodsBatch(Request $request): Response
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $param = $this->_valid([
|
|
|
+ "id.require" => "参数错误",
|
|
|
+ "value.require" => "参数错误",
|
|
|
+ "field.require" => "参数错误",
|
|
|
+ "type.require" => "参数错误"
|
|
|
+ ],"post");
|
|
|
+ if (!is_array($param)) return error($param);
|
|
|
+ if ($param['type'] == "batch") {
|
|
|
+ $state = $this->model->where("id","in",$param['id'])->save([$param['field'] => $param['value']]);
|
|
|
+ } else {
|
|
|
+ $state = $this->model->where("id",$param['id'])->save([$param['field'] => $param['value']]);
|
|
|
+ }
|
|
|
+ if (!$state) return errorTrans("error.data");
|
|
|
+ return successTrans("success.data");
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
+ return error($throwable->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|