zory 3 weeks ago
parent
commit
2be3ab4f4e
2 changed files with 126 additions and 0 deletions
  1. 83 0
      app/controller/merchant/Config.php
  2. 43 0
      app/model/saas/SaasAgentConfig.php

+ 83 - 0
app/controller/merchant/Config.php

@@ -0,0 +1,83 @@
+<?php
+
+namespace app\controller\merchant;
+
+use app\extra\basic\Base;
+use app\middleware\AuthMiddleware;
+use app\model\saas\SaasAgent;
+use app\model\saas\SaasAgentConfig;
+use DI\Attribute\Inject;
+use LinFly\Annotation\Route\Controller;
+use LinFly\Annotation\Route\Route;
+use support\Request;
+use support\Response;
+use Webman\Annotation\Middleware;
+
+
+#[Controller(prefix: "/api/merchant/config"),Middleware(AuthMiddleware::class)]
+class Config extends Base
+{
+
+    #[Inject]
+    protected SaasAgentConfig $model;
+
+    /**
+     * 通用配置
+     * @param Request $request
+     * @return Response
+     */
+    #[Route(path: "get",methods: "get")]
+    public function getConfigData(Request $request): Response
+    {
+        try {
+            $type = $request->get("type","base");
+            $data = $this->model->where("type",$type)->where("agent_id",$request->user['agent_id'])->findOrEmpty();
+            $result = [];
+            if (!$data->isEmpty()) {
+                $result = $data['content'];
+            }
+            if ($type == 'life') {
+                $result['webhook'] = "https://notify.jsshuita.com/dy/hook/".$request->user['agent_id'];
+                $result['spi'] = "https://notify.jsshuita.com/dy/spi/".$request->user['agent_id'];
+            }
+            if ($type == 'meituan') {
+                $result['webhook'] = "https://notify.jsshuita.com/mt/hook/".$request->user['agent_id'];
+            }
+            $result['auth'] = (new SaasAgent)->where("agent_id",$request->user['agent_id'])->value('mall_type');
+            return successTrans("success.data",$result,empty($result)?2:1);
+        } catch (\Throwable $exception) {
+            return error($exception->getMessage());
+        }
+    }
+
+
+    /**
+     * 保存通用配置
+     * @param Request $request
+     * @return Response
+     */
+    #[Route(path: "save",methods: "post")]
+    public function setConfigData(Request $request): Response
+    {
+        try {
+            $param = $request->post();
+            $resp = $this->model->where("agent_id",$request->user['user_id'])->where("type",$param['type'])->findOrEmpty();
+            if ($resp->isEmpty()) {
+                $state = $resp->insert([
+                    "agent_id"  => $request->user['user_id'],
+                    "type"      => $param['type'],
+                    "content"   => json_encode($param['data'])
+                ]);
+            } else {
+                $state = $resp->save([
+                    "content"   => json_encode($param['data'])
+                ]);
+            }
+            if (!$state) return errorTrans("error.data");
+            return successTrans("success.data");
+        } catch (\Throwable $exception){
+            return error($exception->getMessage());
+        }
+
+    }
+}

+ 43 - 0
app/model/saas/SaasAgentConfig.php

@@ -0,0 +1,43 @@
+<?php
+
+namespace app\model\saas;
+
+use app\extra\basic\Model;
+
+
+/**
+ * @property integer $id (主键)
+ * @property integer $agent_id
+ */
+class SaasAgentConfig extends Model
+{
+    /**
+     * The connection name for the model.
+     *
+     * @var string|null
+     */
+    protected $connection = 'mysql';
+    
+    /**
+     * The table associated with the model.
+     *
+     * @var string
+     */
+    protected string $table = "saas_agent_config";
+    
+    /**
+     * The primary key associated with the table.
+     *
+     * @var string
+     */
+    protected string $primaryKey = "id";
+    
+    /**
+     * Indicates if the model should be timestamped.
+     *
+     * @var bool
+     */
+    public bool $timestamps = false;
+
+
+}