| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?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,false);
- $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());
- }
- }
- }
|