Forráskód Böngészése

活动报名按钮

lizhen 6 napja
szülő
commit
85cea64a94

+ 25 - 5
addons/unishop/controller/Product.php

@@ -64,6 +64,12 @@ class Product extends Base
                 $this->error(__('Goods are off the shelves'));
             }
 
+            //没到过期时间,就能报名
+            $data->canbuy = 0;
+            if(time() < $data->activetime){
+                $data->canbuy = 1;
+            }
+
             // 真实浏览量加一
             $data->real_look++;
             $data->look++;
@@ -94,7 +100,7 @@ class Product extends Base
 
             $data->coupon = [];
             if($this->auth->isLogin()){
-                $data->coupon = Db::name('unishop_coupon_user')->alias('cu')
+               /* $data->coupon = Db::name('unishop_coupon_user')->alias('cu')
                     ->field(['cu.id as cu_id','c.id','c.title','c.least','c.value','c.starttime','c.endtime'])
                     ->join('unishop_coupon c','cu.coupon_id = c.id','LEFT')
                     ->where('cu.user_id',$this->auth->id)
@@ -103,7 +109,7 @@ class Product extends Base
                     ->where('c.switch',Coupon::SWITCH_ON)
                     ->where('c.starttime','<',time())
                     ->where('c.endtime','>',time())
-                    ->select();
+                    ->select();*/
             }
 
 
@@ -155,9 +161,10 @@ class Product extends Base
         $pagesize = input('listrow', 20);
         $by = input('by', 'activetime');
         $desc = input('desc', 'desc');
+        $canbuy = input('canbuy', 1);//能报名的
 
 //        $sid = input('sid'); // 二级分类Id
-        $fid = input('fid'); // 一级分类Id
+//        $fid = input('fid'); // 一级分类Id
 
         $productModel = new productModel();
 
@@ -171,10 +178,16 @@ class Product extends Base
             $sid && $productModel->where(['category_id' => $sid]);
         }*/
 
-        $fid && $productModel->where(['category_id' => $fid]);
+//        $fid && $productModel->where(['category_id' => $fid]);
 
+        $where = ['switch' => productModel::SWITCH_ON];
+        if($canbuy == 1){
+            $where['activetime'] = ['gt', time()];
+        }else{
+            $where['activetime'] = ['lt', time()];
+        }
         $result = $productModel
-            ->where(['switch' => productModel::SWITCH_ON])
+            ->where($where)
             ->page($page, $pagesize)
             ->order($by, $desc)
             ->field('id,title,info,image,sales_price,use_spec,activetime')
@@ -182,6 +195,13 @@ class Product extends Base
 
         if ($result) {
             $result = collection($result)->toArray();
+            foreach ($result as &$v) {
+                //没到过期时间,就能报名
+                $v['canbuy'] = 0;
+                if(time() < $v['activetime']){
+                    $v['canbuy'] = 1;
+                }
+            }
         } else {
             $result = [];
         }

+ 177 - 0
application/api/controller/Deepseek.php

@@ -0,0 +1,177 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use Symfony\Component\HttpFoundation\StreamedResponse;
+use think\Db;
+use app\common\library\Deepseek as DeepseekAI;
+/**
+ * AI
+ */
+class Deepseek extends Api
+{
+    protected $noNeedLogin = ['*'];
+    protected $noNeedRight = ['*'];
+
+
+    public function index()
+    {
+        $params = input();
+
+        $chat = new DeepseekAI();
+        $response = $chat->completions($params['messages'],$params['model'],$params['type']);
+       // dump($response);
+
+        return new StreamedResponse(function() use ($response) {
+            $body = $response->getBody();
+            while (!$body->eof()) {
+                echo $body->read(1024); // 每次读取 1024 字节
+                ob_flush();
+                flush();
+            }
+        }, 200, [
+            'Content-Type' => 'application/json', // 根据实际情况设置响应头
+        ]);
+    }
+
+
+    public function mockDeepSeekStream()
+    {
+
+        // 这是模拟的文本片段 - 实际应替换为真实的API调用
+        $textChunks = [
+            "你好!这是 DeepSeek 的流式文本响应。\n\n",
+            "我正在逐块返回文本内容。\n",
+            "这种方式可以实现实时输出效果。\n",
+            "这种方式可以实现实时输出效果。\n",
+            "最后一块内容。\n"
+        ];
+
+        // 逐块输出文本
+        foreach ($textChunks as $chunk) {
+            echo $chunk;
+            ob_flush(); // 刷新PHP输出缓冲区
+            flush();    // 刷新系统缓冲区
+            sleep(1); // 暂停0.3秒模拟网络延迟
+        }
+    }
+
+    public function deepseek(){
+        $config = config('deepseek');
+        $apiKey = $config['key']; //
+        $url = 'https://api.deepseek.com/chat/completions';
+
+        $params = input();
+        $data = [
+            'model' => $params['model'],
+            'messages' => $params['messages'],
+//            "frequency_penalty" => 0,
+            "max_tokens"        => 2048,
+            /*"presence_penalty"  => 0,
+            "response_format"   => [
+                "type" => $params['type']
+            ],
+            "stop"              => null,*/
+            "stream"            => true,
+            /*"stream_options"    => null,
+            "temperature"       => 1,
+            "top_p"             => 1,
+            "tools"             => null,
+            "tool_choice"       => "none",
+            "logprobs"          => false,
+            "top_logprobs"      => null*/
+        ];
+
+        // 初始化cURL会话
+        $ch = curl_init($url);
+
+// 设置cURL选项
+        curl_setopt_array($ch, [
+            CURLOPT_RETURNTRANSFER => true,
+            CURLOPT_SSL_VERIFYPEER => false,
+            CURLOPT_POST => true,
+            CURLOPT_POSTFIELDS => json_encode($data),
+            CURLOPT_HTTPHEADER => [
+                'Content-Type: application/json',
+                'Authorization: Bearer ' . $apiKey,
+                'Accept: text/event-stream' // 重要:声明接受事件流
+            ],
+            CURLOPT_WRITEFUNCTION => function($ch, $data) {
+                // 实时处理流数据
+                $lines = explode("\n", $data);
+
+                foreach ($lines as $line) {
+                    if (strpos($line, 'data: ') === 0) {
+                        $jsonStr = substr($line, 6); // 移除"data: "前缀
+
+                        // 跳过结束标记
+                        if (trim($jsonStr) === '[DONE]') {
+                            continue;
+                        }
+
+                        // 解析JSON数据
+                        $eventData = json_decode($jsonStr, true);
+
+                        if (isset($eventData['choices'][0]['delta']['content'])) {
+                            $content = $eventData['choices'][0]['delta']['content'];
+
+                            // 输出内容并立即刷新缓冲区
+                            echo $content;
+                            ob_flush();
+                            flush();
+                        }
+                    }
+                }
+
+                return strlen($data); // 返回已处理数据长度
+            }
+        ]);
+
+// 执行请求
+        $response = curl_exec($ch);
+
+// 错误处理
+        if (curl_errno($ch)) {
+            echo 'Error: ' . curl_error($ch);
+        }
+
+// 关闭连接
+        curl_close($ch);
+
+        // 创建cURL句柄
+       /* $ch = curl_init();
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+        curl_setopt($ch, CURLOPT_URL, $url);
+        curl_setopt($ch, CURLOPT_POST, true);
+        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
+        curl_setopt($ch, CURLOPT_HTTPHEADER, [
+            'Content-Type: application/json',
+            'Authorization: Bearer ' . $apiKey,
+            'Accept: text/event-stream' // 重要:声明接受事件流
+        ]);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 直接输出
+        curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($ch, $chunk) {
+            // 直接输出接收到的数据块
+            echo $chunk;
+//            ob_flush();
+//            flush();
+            return strlen($chunk); // 必须返回写入的字节数
+        });
+
+        // 执行请求
+        curl_exec($ch);
+
+        // 检查错误
+        if (curl_errno($ch)) {
+            // 错误处理
+            echo "\n\n[ERROR] API请求失败: " . curl_error($ch);
+        }
+
+        curl_close($ch);*/
+
+
+    }
+
+}

+ 2 - 1
public/assets/js/backend/general/attachment.js

@@ -7,7 +7,7 @@ define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefin
                 extend: {
                     index_url: 'general/attachment/index',
                     add_url: 'general/attachment/add',
-                    edit_url: 'general/attachment/edit',
+                    // edit_url: 'general/attachment/edit',
                     del_url: 'general/attachment/del',
                     multi_url: 'general/attachment/multi',
                     table: 'attachment'
@@ -20,6 +20,7 @@ define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefin
             table.bootstrapTable({
                 url: $.fn.bootstrapTable.defaults.extend.index_url,
                 sortName: 'id',
+                search: false,
                 columns: [
                     [
                         {field: 'state', checkbox: true},