Zory 2 maanden geleden
bovenliggende
commit
6107fb8c42

+ 4 - 2
app/controller/api/Account.php

@@ -18,13 +18,14 @@ use support\Response;
 class Account extends Base
 {
 
-    protected array $noNeedLogin = ['getAccountDetail'];
+    protected array $noNeedLogin = ['getAccountDetail','getAccountList'];
 
     #[Inject]
     protected BlueExpertPlatform $model;
 
     /**
      * 绑定账号列表
+     * @param Request $request
      * @return Response
      */
     #[Route(path: "list",methods: "get")]
@@ -53,6 +54,7 @@ class Account extends Base
 
     /**
      * 查看绑定详情
+     * @param Request $request
      * @return Response
      */
     #[Route(path: "detail",methods: "get")]
@@ -63,7 +65,7 @@ class Account extends Base
                 "source.require"    => trans("empty.require")
             ],$request->method());
             if (!is_array($param)) return error($param);
-            $platform = $this->model->where(['openid' => $request->user['openid'],'source' => $param['source']])->field("id,nickname,home_page,status,url,source")->findOrEmpty();
+            $platform = $this->model->where(['openid' => $request->user['openid'],'source' => $param['source']])->field("id,nickname,home_page,status,url,source,remark")->findOrEmpty();
             if ($platform->isEmpty()) return successTrans("success.data");
             return successTrans("success.data",$platform->toArray());
         } catch (\Throwable $th) {

+ 97 - 0
app/controller/api/Address.php

@@ -0,0 +1,97 @@
+<?php
+
+namespace app\controller\api;
+
+use app\extra\basic\Base;
+use app\extra\service\blue\AddressService;
+use app\middleware\WxMiddleware;
+use app\model\blue\BlueAddress;
+use DI\Attribute\Inject;
+use LinFly\Annotation\Route\Controller;
+use LinFly\Annotation\Route\Middleware;
+use LinFly\Annotation\Route\Route;
+use support\Request;
+use support\Response;
+
+
+#[Controller(prefix: "/wx_api/address"),Middleware(WxMiddleware::class)]
+class Address extends Base
+{
+
+
+    protected array $noNeedLogin = ['getAddressList'];
+
+    #[Inject]
+    protected BlueAddress $model;
+
+    #[Inject]
+    protected AddressService $service;
+
+
+    /**
+     * 地址列表
+     * @param Request $request
+     * @return Response
+     */
+    #[Route(path: "list",methods: "get")]
+    public function getAddressList(Request $request): Response
+    {
+        try {
+            $param = $this->_valid([
+                "size.default"      => 10,
+                "page.default"      => 1,
+            ],$request->method());
+            $list = $this->service->getList(['openid' => $request->user['openid'],'pageSize' => $param['size'],'page' => $param['page']]);
+            return success("ok",pageFormat($list));
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+    /**
+     * 编辑信息
+     * @param Request $request
+     * @return Response
+     */
+    #[Route(path: "save",methods: "post")]
+    public function setListData(Request $request): Response
+    {
+        try {
+            $param = $request->post();
+            if (isset($param['id'])) {
+                $factory = $this->model->where("id",$param['id'])->findOrEmpty();
+                if ($factory->isEmpty()) return errorTrans("error.data");
+            }
+            $param['city_path'] = empty($param['city_path']) ? [] : json_encode($param['city_path']);
+            $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
+     */
+    #[Route(path: "del",methods: "post")]
+    public function delData(Request $request): Response
+    {
+        try {
+            $param = $this->_valid([
+                "id.require"        => "参数错误",
+            ],"post");
+            if (!is_array($param)) return error($param);
+            $data = $this->model->where(['id' => $param['id'], 'openid' => $request->user['openid'] ])->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());
+        }
+    }
+
+}

+ 34 - 2
app/controller/api/Task.php

@@ -69,6 +69,35 @@ class Task extends Base
     }
 
 
+    /**
+     * 检查是否绑定星图ID
+     * @param Request $request
+     * @return Response
+     */
+    #[Route(path: "starId",methods: "post")]
+    public function getStarId(Request $request): Response
+    {
+        try {
+            $param = $this->_valid([
+                "task_sn.require"   => trans("empty.require"),
+                "task_id.require"   => trans("empty.require"),
+            ],$request->method());
+            if (!is_array($param)) return error($param);
+            $task = $this->model->where(['task_sn' => $param['task_sn'],'id' => $param['task_id']])->findOrEmpty();
+            if ($task->isEmpty()) return errorTrans("empty.data");
+            $platformUser = (new BlueExpertPlatform)->where(['openid' => $request->user['openid'],"source" => $task['category'],"status" => 1])->findOrEmpty();
+            if ($platformUser->isEmpty()) return error("请先完成平台绑定");
+            return success("ok",['star_id' => $platformUser['star_id']]);
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+    /**
+     * 任务报名
+     * @param Request $request
+     * @return Response
+     */
     #[Route(path: "sign",methods: "post")]
     public function taskUserReg(Request $request): Response
     {
@@ -76,14 +105,17 @@ class Task extends Base
             $param = $this->_valid([
                 "task_sn.require"   => trans("empty.require"),
                 "task_id.require"   => trans("empty.require"),
-                "url.require"       => trans("empty.require"),
-                "image.require"     => trans("empty.require"),
+                "start_id.require"  => trans("empty.require"),
             ],$request->method());
             if (!is_array($param)) return error($param);
             $task = $this->model->where(['task_sn' => $param['task_sn'],'id' => $param['task_id']])->findOrEmpty();
             if ($task->isEmpty()) return errorTrans("empty.data");
             $platformUser = (new BlueExpertPlatform)->where(['openid' => $request->user['openid'],"source" => $task['category'],"status" => 1])->findOrEmpty();
             if ($platformUser->isEmpty()) return error("请先完成平台绑定");
+            if (empty($platformUser['star_id'])) {
+                $platformUser->star_id = $param['start_id'];
+                $platformUser->save();
+            }
             $taskUser = (new BlueTaskUser)->where(['openid' => $request->user['openid'],'task_sn' => $param['task_sn'],'id' => $param['task_id']])->findOrEmpty();
             if (!$taskUser->isEmpty()) return error("请勿重复提交");
             $state = $taskUser->insertGetId([

+ 100 - 0
app/controller/api/TaskUser.php

@@ -0,0 +1,100 @@
+<?php
+
+namespace app\controller\api;
+
+use app\extra\basic\Base;
+use app\extra\service\blue\BlueTaskUserService;
+use app\middleware\WxMiddleware;
+use app\model\blue\BlueTaskUser;
+use DI\Attribute\Inject;
+use LinFly\Annotation\Route\Controller;
+use LinFly\Annotation\Route\Middleware;
+use LinFly\Annotation\Route\Route;
+use support\Request;
+use support\Response;
+
+
+#[Controller(prefix: "/wx_api/task/user"),Middleware(WxMiddleware::class)]
+class TaskUser extends Base
+{
+    protected array $noNeedLogin = ["getTaskUserDetail"];
+
+    #[Inject]
+    protected BlueTaskUser $model;
+
+    #[Inject]
+    protected BlueTaskUserService $service;
+
+
+    /**
+     * 已接任务列表
+     * @param Request $request
+     * @return Response
+     */
+    #[Route(path: "list",methods: "get")]
+    public function getTaskUserList(Request $request): Response
+    {
+        try {
+            $param = $this->_valid([
+                "size.default"      => 10,
+                "page.default"      => 1,
+            ],$request->method());
+            $list = $this->service->getHomeList(['openid' => $request->user['openid'],'pageSize' => $param['size'],'page' => $param['page']]);
+            return success("ok",pageFormat($list));
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+
+    /**
+     * 已接任务详情
+     * @param Request $request
+     * @return Response
+     */
+    #[Route(path: "detail",methods: "get")]
+    public function getTaskUserDetail(Request $request): Response
+    {
+        try {
+            $param = $this->_valid([
+                "id.require"        => trans("empty.require"),
+                "task_sn.require"   => trans("empty.require"),
+            ],$request->method());
+            if (!is_array($param)) return error($param);
+            $task = $this->model->where(['id' => $param['id'],'task_sn' => $param['task_sn'],'openid' => '123' ])->with(['task' => function ($query) {
+                $query->field("id,title,task_sn,product_cover_url,total_budget,sign_number,need_number,category,level,sys_level,product_price")->append(['progress','total_budget_format'])->withAttr(['progress' => function ($data,$resp) {
+                    if ($resp['sign_number'] == 0) return $resp['sign_number'];
+                    return ceil($resp['sign_number']/$resp['need_number'] * 100);
+                },'total_budget_format' => function($data,$resp) {
+                    return formatMoneyKw($resp['total_budget']/100);
+                }]);
+            }])->findOrEmpty();
+            if ($task->isEmpty()) return errorTrans("empty.data");
+            return success("ok",$task->toArray());
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+    /**
+     * 任务收益记录
+     * @param Request $request
+     * @return Response
+     */
+    public function getTaskRevenue(Request $request): Response
+    {
+        try {
+            $param = $this->_valid([
+                "id.require"        => trans("empty.require"),
+                "task_sn.require"   => trans("empty.require"),
+                "date.default"      => date("Y-m-d",strtotime("-1 day")),
+            ],$request->method());
+            if (!is_array($param)) return error($param);
+
+            return success("ok");
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+}

+ 41 - 0
app/extra/service/blue/AddressService.php

@@ -0,0 +1,41 @@
+<?php
+
+namespace app\extra\service\blue;
+
+use app\extra\basic\Service;
+use app\model\blue\BlueAddress;
+
+class AddressService extends Service
+{
+
+
+    /**
+     * 列表
+     * @param array $param
+     */
+    public function getList(array $param = [])
+    {
+        $this->mode = new BlueAddress();
+        return $this->searchVal($param,$this->searchFilter($param))->paginate([
+            "list_rows" => $param['pageSize'],
+            "page"      => $param['page']
+        ]);
+    }
+
+
+    /**
+     *
+     * @param array $param
+     * @return array
+     */
+    public function searchFilter(array $param = []): array
+    {
+        $filter = [];
+        !empty($param['openid']) && $filter[] = ["openid", '=', $param['openid']];
+        !empty($param['type']) && $filter[] = ["type", '=', $param['type']];
+        !empty($param['status']) && $filter[] = ["status", '=', $param['status']];
+        !empty($param['name']) && $filter[] = ["name", 'like', "%{$param['name']}%"];
+        return $filter;
+    }
+
+}

+ 45 - 0
app/extra/service/blue/BlueTaskUserService.php

@@ -0,0 +1,45 @@
+<?php
+
+namespace app\extra\service\blue;
+
+use app\extra\basic\Service;
+use app\model\blue\BlueTaskUser;
+
+class BlueTaskUserService extends Service
+{
+
+    public function getHomeList(array $param = [])
+    {
+        $this->mode = new BlueTaskUser();
+        return $this->searchVal($param,$this->searchFilter($param))->with(['task' => function ($query) {
+            $query->field("id,title,task_sn,product_cover_url,total_budget,sign_number,need_number,category,level,sys_level,product_price")->append(['progress','total_budget_format'])->withAttr(['progress' => function ($data,$resp) {
+                if ($resp['sign_number'] == 0) return $resp['sign_number'];
+                return ceil($resp['sign_number']/$resp['need_number'] * 100);
+            },'total_budget_format' => function($data,$resp) {
+                return formatMoneyKw($resp['total_budget']/100);
+            }]);
+        }])->paginate([
+            "list_rows" => $param['pageSize'],
+            "page"      => $param['page']
+        ]);
+    }
+
+    /**
+     *
+     * @param array $param
+     * @return array
+     */
+    public function searchFilter(array $param = []): array
+    {
+        $filter = [];
+        !empty($param['id']) && $filter[] = ["id", '=', $param['id']];
+        !empty($param['openid']) && $filter[] = ["openid", '=', $param['openid']];
+        !empty($param['task_sn']) && $filter[] = ["task_sn", '=', $param['task_sn']];
+        !empty($param['type']) && $filter[] = ["type", '=', $param['type']];
+        !empty($param['category']) && $filter[] = ["category", '=', $param['category']];
+        !empty($param['status']) && $filter[] = ["status", '=', $param['status']];
+        !empty($param['name']) && $filter[] = ["name", 'like', "%{$param['name']}%"];
+        return $filter;
+    }
+
+}

+ 49 - 0
app/model/blue/BlueAddress.php

@@ -0,0 +1,49 @@
+<?php
+
+namespace app\model\blue;
+
+use app\extra\basic\Model;
+
+
+/**
+ * @property integer $id (主键)
+ * @property mixed $openid 
+ * @property string $username 
+ * @property mixed $mobile 
+ * @property string $city 
+ * @property mixed $city_path 
+ * @property string $address 
+ * @property mixed $create_at 创建时间
+ */
+class BlueAddress 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 = "blue_address";
+    
+    /**
+     * 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;
+
+
+}

+ 42 - 0
app/model/blue/BlueTaskMaterial.php

@@ -0,0 +1,42 @@
+<?php
+
+namespace app\model\blue;
+
+use app\extra\basic\Model;
+
+
+/**
+ * @property integer $id (主键)
+ */
+class BlueTaskMaterial 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 = "blue_task_material";
+    
+    /**
+     * 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;
+
+
+}

+ 12 - 8
app/model/blue/BlueTaskUser.php

@@ -6,14 +6,14 @@ use app\extra\basic\Model;
 
 
 /**
- * @property integer $id (主键)
- * @property mixed $openid 
- * @property integer $task_id 
- * @property mixed $task_sn 
- * @property mixed $platform 
- * @property string $image 
- * @property string $url 
- * @property integer $status 
+ * @property integer $id (主键)
+ * @property mixed $openid 
+ * @property integer $task_id 
+ * @property mixed $task_sn 
+ * @property mixed $platform 
+ * @property string $image 
+ * @property string $url 
+ * @property integer $status 
  * @property mixed $create_at 创建时间
  */
 class BlueTaskUser extends Model
@@ -46,5 +46,9 @@ class BlueTaskUser extends Model
      */
     public bool $timestamps = false;
 
+    public function task()
+    {
+        return $this->hasOne(BlueTask::class, 'id', 'task_id');
+    }
 
 }

+ 2 - 2
config/plugin/webman/push/app.php

@@ -1,8 +1,8 @@
 <?php
 return [
     'enable'       => true,
-    'websocket'    => 'websocket://0.0.0.0:3131',
-    'api'          => 'http://0.0.0.0:3232',
+    'websocket'    => 'websocket://0.0.0.0:3434',
+    'api'          => 'http://0.0.0.0:3535',
     'app_key'      => '9b497db73e0145ff4aea6af871c8b381',
     'app_secret'   => 'ccdc58876eaad13a1a793d12211c5016',
     'channel_hook' => 'http://127.0.0.1:8787/plugin/webman/push/hook',