|
@@ -0,0 +1,145 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+
|
|
|
|
|
+namespace app\controller\admin;
|
|
|
|
|
+
|
|
|
|
|
+use app\extra\basic\Base;
|
|
|
|
|
+use app\extra\service\agent\StoreAddressService;
|
|
|
|
|
+use app\extra\tools\CodeExtend;
|
|
|
|
|
+use app\middleware\AuthMiddleware;
|
|
|
|
|
+use app\model\saas\SaasAgent;
|
|
|
|
|
+use app\model\saas\SaasStore;
|
|
|
|
|
+use app\model\saas\SaasStoreFactory;
|
|
|
|
|
+use app\model\system\SystemUser;
|
|
|
|
|
+use app\validate\store\StoreAddressValidate;
|
|
|
|
|
+use app\validate\user\StoreValidate;
|
|
|
|
|
+use DI\Attribute\Inject;
|
|
|
|
|
+use Hzdad\Codecheck\Codecheck;
|
|
|
|
|
+use LinFly\Annotation\Route\Controller;
|
|
|
|
|
+use LinFly\Annotation\Route\Route;
|
|
|
|
|
+use support\Request;
|
|
|
|
|
+use support\Response;
|
|
|
|
|
+use Webman\Annotation\Middleware;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+#[Controller(prefix: "/api/store-address"),Middleware(AuthMiddleware::class)]
|
|
|
|
|
+class StoreAddress extends Base
|
|
|
|
|
+{
|
|
|
|
|
+ #[Inject]
|
|
|
|
|
+ protected StoreAddressService $service;
|
|
|
|
|
+
|
|
|
|
|
+ #[Inject]
|
|
|
|
|
+ protected StoreAddressValidate $validate;
|
|
|
|
|
+
|
|
|
|
|
+ #[Inject]
|
|
|
|
|
+ protected SaasStoreFactory $model;
|
|
|
|
|
+
|
|
|
|
|
+ protected string $scene = "edit";
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ #[Route(path: "list",methods: "get")]
|
|
|
|
|
+ public function getStoreList(Request $request): Response
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $param = $request->get();
|
|
|
|
|
+ $list = $this->service->getList($param);
|
|
|
|
|
+ return successTrans("success.data",pageFormat($list),200);
|
|
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
|
|
+ return error($throwable->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 新增/编辑代理
|
|
|
|
|
+ * @param Request $request
|
|
|
|
|
+ * @return Response
|
|
|
|
|
+ */
|
|
|
|
|
+ #[Route(path: "save",methods: "post")]
|
|
|
|
|
+ public function save(Request $request): Response
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $param = $request->post();
|
|
|
|
|
+ $agent = (new SaasAgent)->where("agent_id",$param['agent_id'])->findOrEmpty();
|
|
|
|
|
+ if ($agent->isEmpty()) return errorTrans("error.agent-no-exist");
|
|
|
|
|
+ if (!isset($param['id'])) {
|
|
|
|
|
+ $this->scene = "add";
|
|
|
|
|
+ $code = (new Codecheck)->mobile($param['mobile'])->scene($param['scene'])->code($param['yzm'])->check();
|
|
|
|
|
+ if (!$code) return errorTrans("error.sms-err");
|
|
|
|
|
+ $param['user_id'] = $param['store_id'] = CodeExtend::random(16,1,date("md"));
|
|
|
|
|
+ if (!empty($param['username'])) {
|
|
|
|
|
+ $userName = (new SystemUser)->where("username",$param['username'])->findOrEmpty();
|
|
|
|
|
+ if (!$userName->isEmpty()) return errorTrans("error.user-exist");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ $param['vip_at'] = $agent['vip_at'];
|
|
|
|
|
+ if (!$this->validate->scene($this->scene)->check($request->post())) return error($this->validate->getError());
|
|
|
|
|
+ $state = $this->model->setAutoData($param);
|
|
|
|
|
+ if (!$state) return errorTrans("error.data");
|
|
|
|
|
+ $this->sceneUser($param,3,"id");
|
|
|
|
|
+ return successTrans("success.data");
|
|
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
|
|
+ echo $throwable->getMessage()."\n";
|
|
|
|
|
+ echo $throwable->getFile()."\n";
|
|
|
|
|
+ echo $throwable->getLine()."\n";
|
|
|
|
|
+ return error($throwable->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @param Request $request
|
|
|
|
|
+ * @return Response
|
|
|
|
|
+ */
|
|
|
|
|
+ #[Route(path: "batch",methods: "post")]
|
|
|
|
|
+ public function setBatchData(Request $request): Response
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $param = $this->_valid([
|
|
|
|
|
+ "id.require" => trans("empty.require"),
|
|
|
|
|
+ "value.require" => trans("empty.require"),
|
|
|
|
|
+ "field.require" => trans("empty.require"),
|
|
|
|
|
+ "type.require" => trans("empty.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());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 删除
|
|
|
|
|
+ * @param Request $request
|
|
|
|
|
+ * @return Response
|
|
|
|
|
+ */
|
|
|
|
|
+ #[Route(path: "del",methods: "post")]
|
|
|
|
|
+ public function delUser(Request $request): Response
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $param = $this->_valid([
|
|
|
|
|
+ "id.require" => trans("empty.require"),
|
|
|
|
|
+ "type.default" => "one",
|
|
|
|
|
+ ],"post");
|
|
|
|
|
+ if (!is_array($param)) return error($param);
|
|
|
|
|
+ if ($param['type'] == "batch") {
|
|
|
|
|
+ $state = $this->model->where("id","in",$param['id'])->delete();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $data = $this->model->where("id",$param['id'])->findOrEmpty();
|
|
|
|
|
+ if ($data->isEmpty()) return errorTrans("empty.data");
|
|
|
|
|
+ // 删除其他相关数据
|
|
|
|
|
+ $state = $data->delete();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!$state) return errorTrans("error.data");
|
|
|
|
|
+ return successTrans("success.data");
|
|
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
|
|
+ return error($throwable->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|