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()); } } /** * 新增店铺品类授权 * @param Request $request * @return Response */ #[PostMapping("cate")] public function addCategory(Request $request): Response { try { $param = $this->_valid([ "poi_id.require" => trans("empty.require"), "category.require" => trans("empty.require"), "product_type.require" => trans("empty.require"), ],$request->method()); if (!is_array($param)) return error($param); $storeMode = (new SaasStoreCategory); $inData = []; foreach ($param['category'] as $key => $value) { if (!isset($value[2])) return error("请选择正确的品类"); $lastId = $value[2]; $storeCategory = $storeMode->where("category_id",$lastId)->where("poi_id",$param['poi_id'])->with(['cate'])->findOrEmpty(); if (!$storeCategory->isEmpty()) return error("【{$storeCategory['cate']['name']}】已存在,请勿重复添加"); $inData[$key] = [ "category_id" => $value[2], "poi_id" => $param['poi_id'], "product_type" => json_encode($param["product_type"]), ]; } $state = $storeMode->insertAll($inData); if (!$state) return errorTrans("error.data"); return successTrans("success.data"); } catch (\Throwable $throwable) { return error($throwable->getMessage()); } } /** * 删除店铺品类授权 * @param Request $request * @return Response */ #[PostMapping("cate/del")] public function delCategory(Request $request): Response { try { $param = $this->_valid([ "poi_id.require" => trans("empty.require"), "id.require" => trans("empty.require") ],$request->method()); if (!is_array($param)) return error($param); $data = (new SaasStoreCategory)->where(['poi_id' => $param['poi_id'],'category_id' => $param['id']])->findOrEmpty(); if ($data->isEmpty()) return errorTrans("error.data"); $state = $data->delete(); if (!$state) return errorTrans("error.data"); return successTrans("success.data"); } catch (\Throwable $throwable) { return error($throwable->getMessage()); } } }