wupengfei 3 năm trước cách đây
mục cha
commit
84da4c890e

+ 1 - 3
application/api/common.php

@@ -46,9 +46,7 @@ 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]);
+    Db::table('store_live')->where([['start_at','< time',$date_str],['status','=',2]])->update(['status'=>1]);
 }
 
 

+ 3 - 4
application/api/controller/Live.php

@@ -15,6 +15,7 @@ class Live extends Base
 {
 
     public function initialize(){
+        change_live_status();
        //parent::check_login();
     }
 
@@ -39,18 +40,16 @@ class Live extends Base
      * @return name:goods.id type:string default:-- desc:商品id
      * @return name:goods.name type:string default:-- desc:商品名
      * @return name:goods.cover type:string default:-- desc:封面
-     * @return name:goods.floor_price type:string default:-- desc:价格
      */
     public function getIndexLive()
     {
-        change_live_status();
-        $info = Db::table('store_live')->where(['status'=>2])->order('sort desc,id desc')->find();
+        $info = Db::table('store_live')->where('status','=',2)->where('start_at','> time',date('Y-m-d H:i:s'))->order('sort desc,id desc')->find();
         if(empty($info)) $this->success('ok',['info'=>[],'goods'=>[]]);
         $is_app =  Db::table('live_goods_app')->where(['user_id'=>$this->uid,'live_id'=>$info['id']])->count();
         $info['is_app'] = $is_app ?1:0;
         $goods_set = json_decode($info['detail'],true);
         $goods_arr = Db::table('store_goods')
-            ->field('id,name,cover,floor_price')
+            ->field('id,name,cover')
             ->where(['id'=>array_column($goods_set,'goods_id')])->select();
         $this->success('ok',['info'=>$info,'goods'=>$goods_arr]);
     }

+ 36 - 0
application/store/controller/Live.php

@@ -1,6 +1,7 @@
 <?php
 namespace app\store\controller;
 use library\Controller;
+use library\helper\PageHelper;
 use think\Db;
 
 /**
@@ -17,6 +18,12 @@ class Live extends Controller
      */
     protected $table = 'StoreLive';
 
+    public function initialize(){
+        $date_str = date("Y-m-d H:i:s");
+        // 将活动改为进行中状态
+        Db::table('store_live')->where([['start_at','< time',$date_str],['status','=',2]])->update(['status'=>1]);
+    }
+
     /**
      * 直播列表
      * @auth true
@@ -178,6 +185,35 @@ class Live extends Controller
 
 
 
+    /**
+     * @auth true
+     * @menu true
+     * 直播商品
+     */
+
+    public function liveGoods()
+    {
+        $lid = input('id');
+        $this->title = 'WWWW';
+        $query = $this->_query('StoreLiveGoods')->order('sort desc ,id desc')->page();
+    }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 
 
 }

+ 160 - 0
application/store/controller/LiveGoodsManage.php

@@ -0,0 +1,160 @@
+<?php
+namespace app\store\controller;
+use library\Controller;
+use think\Db;
+
+/**
+ * 直播商品添加
+ * Class Goods
+ * @package app\store\controller
+ */
+class LiveGoods extends Controller
+{
+
+    /**
+     * 绑定数据表
+     * @var string
+     */
+    protected $table = 'StoreLiveGoods';
+
+    /**
+     * 直播商品列表
+     * @auth true
+     * @menu true
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function index()
+    {
+        $this->title = '直播商品列表';
+        $this->cate_id = input('cate_id');
+        $goods_cate = Db::table('store_live_cate')
+            ->field('id,title')
+            ->where('status',1)
+            ->where('is_deleted',0)
+            ->order('sort desc , id desc')
+            ->select();
+        $this->goods_cate = array_column($goods_cate,null,'id');
+        $query = $this->_query($this->table)->where('is_deleted',0);
+        if($this->cate_id) $query->where('cate_id',$this->cate_id );
+        $query->like('name');
+        $query->order('status desc , sort desc , id desc')->page();
+    }
+
+    /**
+     * 数据列表处理
+     * @auth true
+     * @menu true
+     * @param array $data
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    protected function _index_page_filter(&$data)
+    {
+
+    }
+
+
+
+
+
+
+
+    /**
+     * 添加商品
+     * @auth true
+     * @menu true
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function add()
+    {
+        $this->title = '添加商品';
+        $this->goods_cate = Db::table('store_live_cate')
+            ->field('id,title')
+            ->where('status',1)
+            ->where('is_deleted',0)
+            ->order('sort desc , id desc')
+            ->select();
+        $this->_form($this->table, 'form');
+    }
+
+
+    /**
+     * 编辑商品
+     * @auth true
+     * @menu true
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function edit()
+    {
+        $this->title = '编辑商品';
+        $this->goods_cate = Db::table('store_live_cate')
+            ->field('id,title')
+            ->where('status',1)
+            ->where('is_deleted',0)
+            ->order('sort desc , id desc')
+            ->select();
+        $this->_form($this->table, 'form');
+    }
+
+    /**
+     * 禁用
+     * @auth true
+     * @menu true
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     */
+    public function forbidden()
+    {
+        $this->_save($this->table, ['status' => '0']);
+    }
+
+    /**
+     * 启用
+     * @auth true
+     * @menu true
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     */
+    public function enable()
+    {
+        $this->_save($this->table, ['status' => 1]);
+    }
+
+    /**
+     * 删除
+     * @auth true
+     * @menu true
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     */
+    public function del()
+    {
+        $this->_save($this->table, ['is_deleted' => 1]);
+    }
+
+
+    /**
+     * 表单数据处理
+     * @auth true
+     * @menu true
+     * @param array $data
+     */
+    protected function _form_filter(&$data)
+    {
+        $data['create_at'] = date('Y-m-d H:i:s');
+    }
+
+}

+ 1 - 1
application/store/view/live/index.html

@@ -34,7 +34,7 @@
                 {if $vo.status !=3}
                 <span class="layui-btn layui-btn-sm layui-btn-warm" onclick="btn_confirm('关闭','close','{$vo.id}');">关 闭</span>
                 {/if}
-                <a data-title="商品管理" class="layui-btn layui-btn-sm" data-open='{:url("edit")}?id={$vo.id}'>商品管理</a>
+                <a data-title="商品管理" class="layui-btn layui-btn-sm" data-open='{:url("live_goods")}?id={$vo.id}'>商品管理</a>
             </td>
         </tr>
         {/foreach}

+ 69 - 0
application/store/view/live/live_goods.html

@@ -0,0 +1,69 @@
+{extend name='admin@main'}
+
+{block name="button"}
+    <a data-open='{:url("add")}'   data-title="添加商品" class='layui-btn layui-btn-sm layui-btn-primary'>添加直播</a>
+{/block}
+
+{block name="content"}
+<div class="think-box-shadow">
+    {include file='live/index_search'}
+    <table class="layui-table margin-top-10" lay-skin="line">
+        {notempty name='list'}
+        <thead>
+        <tr>
+            <th class='list-table-check-td think-checkbox'><input data-auto-none data-check-target='.list-check-box' type='checkbox'></th>
+            <th class='list-table-sort-td'><button type="button" data-reload class="layui-btn layui-btn-xs">刷 新</button></th>
+            <th class='text-left nowrap'>标题</th>
+            <th class='text-left nowrap'>封面</th>
+            <th class='text-left nowrap'>开始时间</th>
+            <th class="text-left nowrap">操作</th>
+        </tr>
+        </thead>
+        {/notempty}
+        <tbody>
+        {foreach $list as $key=>$vo}
+        <tr>
+            <td class='list-table-check-td think-checkbox'><input class="list-check-box" value='{$vo.id}' type='checkbox'></td>
+            <td class='list-table-sort-td'><input data-action-blur="{:request()->url()}" data-value="id#{$vo.id};action#sort;sort#{value}" data-loading="false" value="{$vo.sort}" class="list-sort-input"></td>
+            <td class='text-left nowrap'>{$vo.name|default=''}</td>
+            <td class='text-left nowrap'><img data-tips-image="{$vo.cover|default=''}"  src="{$vo.cover|default=''}" width="50px"></td>
+            <td class='text-left nowrap'>{$vo.start_at|format_datetime}</td>
+            <td class='text-left nowrap'>
+                <a data-title="编辑" class="layui-btn layui-btn-sm" data-open='{:url("edit")}?id={$vo.id}'>编 辑</a>
+                <span class="layui-btn layui-btn-sm layui-btn-danger" onclick="btn_confirm('关闭','del','{$vo.id}');">删 除</span>
+                {if $vo.status !=3}
+                <span class="layui-btn layui-btn-sm layui-btn-warm" onclick="btn_confirm('关闭','close','{$vo.id}');">关 闭</span>
+                {/if}
+                <a data-title="商品管理" class="layui-btn layui-btn-sm" data-open='{:url("edit")}?id={$vo.id}'>商品管理</a>
+            </td>
+        </tr>
+        {/foreach}
+        </tbody>
+    </table>
+    {empty name='list'}<span class="notdata">没有记录哦</span>{else}{$pagehtml|raw|default=''}{/empty}
+</div>
+<script>
+    function btn_confirm(msg,fun,id) {
+        layer.confirm('请确定是否'+msg, {btn: ['确定', '取消'], title: "提示"}, function () {
+            var url = "/store/live/"+fun;
+            layer.closeAll();
+            $.ajax({
+                type: "post",
+                url: url,
+                data: {id:id},
+                dataType: "json",
+                async: false,
+                success: function (data) {
+                    layer.msg(data.info);
+                    setTimeout(function () {
+                        window.location.reload();
+                    },1000)
+                }
+            });
+        });
+    }
+</script>
+{/block}
+
+
+