| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- <?php
- namespace app\controller\admin;
- use app\extra\basic\Base;
- use app\middleware\AuthMiddleware;
- use app\model\saas\SaasStore;
- use app\service\saas\GoodsService;
- use app\service\saas\StoreService;
- 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\Container;
- use support\Request;
- use support\Response;
- use Webman\RedisQueue\Redis;
- /**
- * POI门店
- */
- #[Controller("/api/store"),Middleware(AuthMiddleware::class)]
- class Store extends Base
- {
- #[Inject]
- protected StoreService $service;
- #[Inject]
- protected GoodsService $goodsService;
- #[Inject]
- protected SaasStore $model;
- /**
- * 数据列表
- * @param Request $request
- * @return Response
- */
- #[GetMapping('list')]
- public function getStoreData(Request $request): Response
- {
- try {
- $param = $request->all();
- $data = $this->service->setModel()->getList($param,null,true,['type'],['type' => function($query,$resp){
- if (empty($resp['product_type'])) return [];
- $productType = json_decode($resp['product_type'],true);
- $typeData = [];
- foreach ($this->goodsService->productType() as $key => $value) {
- if (in_array($value['key'],$productType)) {
- $typeData[] = $value['name'];
- }
- }
- return $typeData;
- }]);
- return successTrans(100010,pageFormat($data),200);
- } catch (\Throwable $th) {
- return error($th->getMessage());
- }
- }
- /**
- * 同步POI门店
- * @param Request $request
- * @return Response
- */
- #[GetMapping('sync')]
- public function syncStore(Request $request): Response
- {
- try {
- Redis::send("sync-store",[
- "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());
- }
- }
- #[GetMapping("cate")]
- public function getCategory(): Response
- {
- try {
- $data = $this->goodsService->productType();
- return successTrans("success",compact('data'));
- } catch (\Throwable $throwable) {
- return error($throwable->getMessage());
- }
- }
- }
|