wupengfei %!s(int64=3) %!d(string=hai) anos
pai
achega
8e7426d23c

+ 13 - 0
application/api/common.php

@@ -41,6 +41,19 @@ function get_refund_cause()
     return $list;
 }
 
+// 更新直播状态
+function change_live_status()
+{
+    $date_str = date("Y-m-d H:i:s");
+    // 将活动改为进行中状态
+    Db::table('store_live')->where([['start_at','< time',$date_str],['end_at','> time',$date_str],['status','=',2]])->update(['status'=>1]);
+    // 将活动改为过期状态
+    Db::table('store_live')->where([['end_at','< time',$date_str]])->update(['status'=>3]);
+}
+
+
+
+
 
 
 

+ 0 - 1
application/api/controller/Expedite.php

@@ -133,5 +133,4 @@ class Expedite extends Base
 
 
 
-
 }

+ 56 - 0
application/api/controller/Live.php

@@ -0,0 +1,56 @@
+<?php
+
+
+namespace app\api\controller;
+use think\Controller;
+use think\Db;
+
+/**
+ * @title 直播
+ * Class Live
+ * @controller Live
+ * @group base
+ */
+class Live extends Base
+{
+
+    /**
+     * @title 获取直播详情列表
+     * @desc  获取直播详情列表
+     * @author  qc
+     * @url /api/Live/getLiveList
+     * @method GET
+     * @param  name:page type:int  : default:1 desc:页数
+     * @param  name:page_num type:int  : default:20 desc:每页数
+     * @param  name:status type:int  : default:0 desc:直播状态 (0全部,1直播中,2未开始,3 已结束)
+     * @return name:id type:int default:-- desc:id
+     * @return name:name type:string default:-- desc:直播标题
+     * @return name:desc type:string default:-- desc:直播简介
+     * @return name:cover type:string default:-- desc:直播封面
+     * @return name:create_at type:string default:-- desc:直播开始时间
+     * @return name:end_at type:string default:-- desc:直播结束
+     * @return name:status type:string default:-- desc:直播状态(1直播中,2未开始,3 已结束)
+     * @return name:detail type:string default:-- desc:直播商品详情
+     */
+    public function getLiveList()
+    {
+        $where = [];
+        $where['is_deleted'] = 0;
+        if(input('status',0)) $where['status'] = input('status');
+        $list = Db::table('store_live')
+            ->where($where)
+            ->order('sort desc , id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select();
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+
+
+
+
+
+
+
+}

+ 10 - 0
application/api/controller/Timedtask.php

@@ -86,5 +86,15 @@ class Timedtask
 
     }
 
+    /**
+     *
+     */
+    public function changeLiveStatus()
+    {
+
+    }
+
+
+
 
 }

+ 30 - 11
application/store/controller/Live.php

@@ -137,21 +137,40 @@ class Live extends Controller
      */
     protected function _form_result($result)
     {
-        $live_info = Db::table('store_live')->find($result);
+        /*$live_info = Db::table('store_live')->find($result);
         $live_goods = json_decode($live_info['detail'],true);
-        Db::table('store_live_goods')->where(['live_id'=>$result])->delete();
+        //Db::table('store_live_goods')->where(['live_id'=>$result])->delete();
+        $ch_goods = Db::table('store_live_goods')->where(['live_id'=>$result])->select();
+        $ck_ids = array_column($ch_goods,'goods_id');
+        $new_ids =  array_column($live_goods,'goods_id');
         $int_data = [];
         foreach ($live_goods  as $v) {
-            $int_data[]=[
-                'live_id' => $result ,
-                'goods_id' => $v['goods_id'] ,
-                'st_at' => $v['gl_st'] ,
-                'end_at' => $v['gl_end'] ,
-                'live_status' => $live_info['status'] ,
-                'create_at' => date('Y-m-d H:i:s') ,
-            ];
+            // 需要新加
+            if(!in_array($v['goods_id'],$ck_ids)) {
+                $int_data[]=[
+                    'live_id' => $result ,
+                    'goods_id' => $v['goods_id'] ,
+                    'st_at' => $v['gl_st'] ,
+                    'end_at' => $v['gl_end'] ,
+                    'live_status' => $live_info['status'] ,
+                    'create_at' => date('Y-m-d H:i:s') ,
+                ];
+            }else if(in_array($v['goods_id'],$ck_ids)) {// 更新
+                $up_data = [
+                    'st_at' => $v['gl_st'] ,
+                    'end_at' => $v['gl_end'] ,
+                    'live_status' => $live_info['status'] ,
+                    'create_at' => date('Y-m-d H:i:s') ,
+                ];
+                Db::table('store_live_goods')->where(['live_id'=>$result,'goods_id'=>$v['goods_id']])->update($up_data);
+            }
         }
-        Db::table('store_live_goods')->insertAll($int_data);
+        if(!empty($int_data)) Db::table('store_live_goods')->insertAll($int_data);
+        // 删掉多余的
+        foreach ($ck_ids as $cv) {
+            if(!in_array($cv,$new_ids))  Db::table('store_live_goods')->where(['live_id'=>$result,'goods_id'=>$cv])->delete();
+        }*/
+
     }
 
 

+ 1 - 0
config/apidoc.php

@@ -15,6 +15,7 @@ return [
         'api\\controller\\Area',
         'api\\controller\\Shoppingcar',
         'api\\controller\\Order',
+        'api\\controller\\Live',
         'api\\controller\\Timedtask',
     ],
     // 指定公共注释定义的文件地址