From 33f004d1196d056b99a3886de070d429315bac39 Mon Sep 17 00:00:00 2001
From: quanwei <419654421@qq.com>
Date: Thu, 11 Dec 2025 18:12:38 +0800
Subject: [PATCH] 将分类改为多选 修复活动报名 实现成为vip会员时根据活动报名信息绑定下级

---
 admin/app/common/model/release/SupplyProject.php |  186 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 186 insertions(+), 0 deletions(-)

diff --git a/admin/app/common/model/release/SupplyProject.php b/admin/app/common/model/release/SupplyProject.php
new file mode 100644
index 0000000..ba90cc3
--- /dev/null
+++ b/admin/app/common/model/release/SupplyProject.php
@@ -0,0 +1,186 @@
+<?php
+
+namespace app\api\model\plus\release;
+
+use app\common\model\plus\release\Project as ProjectModel;
+use app\common\model\plus\release\ReleaseProjectImage as ReleaseProjectImageModel;
+use app\common\model\plus\release\Tag as TagModel;
+use app\common\model\plus\release\ReleaseProjectTag as ReleaseProjectTagModel;
+
+
+/**
+ * 模型
+ */
+class SupplyProject extends ProjectModel
+{
+    /**
+     * 获取提现明细
+     */
+    public function getList($user_id, $postdata)
+    {
+        $model = $this;
+        if(!empty($postdata["keyword"])){
+            $model = $model->where('name', 'like', '%'.$postdata["keyword"].'%');
+        }
+        return $model->where('is_delete', '=', 0)
+            ->where('project_type', '=', 1)
+            ->where('user_id', '=', $user_id)
+            ->order(['create_time' => 'desc'])
+            ->paginate($postdata);
+    }
+    /**
+     * 新增记录
+     */
+    public function add($postdata,$supply)
+    {
+        $data = json_decode($postdata["formData"],true);
+        if (empty($data['name'])) {
+                $this->error = '请输入标题';
+                return false;
+         }
+        if (empty($data['category_id'])) {
+                $this->error = '请选择分类';
+                return false;
+         }
+        if (empty($data['price'])) {
+                $this->error = '请输入您的价格';
+                return false;
+        }
+       if (empty($data['content'])) {
+                $this->error = '请输入您的详细描述';
+                return false;
+        }
+        
+        $save_data =[
+            'user_id'=>$supply["user_id"],
+            'name'=>$data["name"],
+            'category_id'=>$data["category_id"],
+            'price'=>$data["price"],
+            'content'=>$data["content"],
+            'detail'=>$data["detail"],
+            'project_type'=>1,
+            'is_show'=>$data["is_show"],
+            'app_id'=>self::$app_id,
+
+        ];
+        if(!empty($data["finish_time"]) && $data["finish_time"] != '请选择日期'){
+            $save_data["finish_time"] = strtotime($data["finish_time"]);
+        }else{
+            $save_data["finish_time"] = '';
+        }
+
+          return $this->transaction(function () use ($data, $save_data) {
+            // 记录内容
+            $this->save($save_data);
+            // 记录图片
+            $this->saveAllImages($this['project_id'],$data);
+            // 记录标签
+            $this->saveTag($this['project_id'],$data);
+            
+            return $this['project_id'];
+        });
+    }
+
+    /**
+     * 更新记录
+     */
+    public function edit($postdata)
+    {
+        $data = json_decode($postdata["formData"],true);
+        if (empty($data['name'])) {
+                $this->error = '请输入标题';
+                return false;
+         }
+        if (empty($data['category_id'])) {
+                $this->error = '请选择分类';
+                return false;
+         }
+        if (empty($data['price'])) {
+                $this->error = '请输入您的价格';
+                return false;
+        }
+       if (empty($data['content'])) {
+                $this->error = '请输入您的详细描述';
+                return false;
+        }
+         $save_data =[
+            'name'=>$data["name"],
+            'category_id'=>$data["category_id"],
+            'price'=>$data["price"],
+            'content'=>$data["content"],
+            'detail'=>$data["detail"],
+            'is_show'=>$data["is_show"],
+            'status'=>0,
+        ];
+        if(!empty($data["finish_time"]) && $data["finish_time"] != '请选择日期'){
+            $save_data["finish_time"] = strtotime($data["finish_time"]);
+        }else{
+            $save_data["finish_time"] = '';
+        }
+
+        return $this->transaction(function () use ($data, $save_data) {
+            // 记录内容
+            $this->where("project_id","=",$data["project_id"])->save($save_data);
+            // 记录图片
+            $this->saveAllImages($data['project_id'],$data);
+            // 记录标签
+            $this->saveTag($data['project_id'],$data);
+            
+            return true;
+        });
+    }
+     /**
+     * 记录图片
+     */
+    private function saveAllImages($id,$formData)
+    {
+        (new ReleaseProjectImageModel())->where("project_id","=",$id)->delete();
+        // 生成图片数据
+        if(!empty($formData['image_list'])){
+            $imageData = [];
+            foreach ($formData['image_list'] as $imageId) {
+                $imageData[] = [
+                    'project_id' => $id,
+                    'image_id' => !empty($imageId['image_id']) ? $imageId['image_id'] : $imageId['file_id'],
+                    'app_id' => self::$app_id
+                ];
+            }
+            $model = new ReleaseProjectImageModel;
+            return !empty($imageData) && $model->saveAll($imageData);
+        }
+        return true;
+
+    }
+
+    /**
+     * 记录标签
+     */
+    private function saveTag($id,$formData)
+    {
+        (new ReleaseProjectTagModel())->where("project_id","=",$id)->delete();
+        // 生成数据
+        if(!empty($formData['tag_list'])){
+            $tagData = [];
+            foreach ($formData['tag_list'] as $val) {
+                $tagData[] = [
+                    'project_id' => $id,
+                    'tag_id' => $val,
+                    'app_id' => self::$app_id
+                ];
+            }
+            $model = new ReleaseProjectTagModel;
+            return !empty($tagData) && $model->saveAll($tagData);
+        }
+        return true;
+
+    }
+
+    /**
+     * 软删除
+     */
+    public function setDelete($id)
+    {
+        return $this->where("project_id","=",$id)->save(['is_delete' => 1]);
+    }
+
+}
\ No newline at end of file

--
Gitblit v1.9.2