123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- <?php
- namespace app\store\controller;
- use library\Controller;
- use think\Db;
- /**
- * 商品管理
- * Class Live
- * @package app\store\controller
- */
- class Live extends Controller
- {
- /**
- * 绑定数据表
- * @var string
- */
- protected $table = 'StoreLive';
- /**
- * 直播列表
- * @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 = '直播列表';
- $query = $this->_query($this->table)->where('is_deleted',0)->like('name');
- $query->dateBetween('create_at')->order('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)
- {
- foreach ($data as $k=>&$v){
- }
- }
- /**
- * 添加商品
- * @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 = '添加直播';
- $all_goods = Db::table('store_goods')
- ->field('id,name,cover')
- ->where(['is_integral'=>0,'is_deleted'=>0,'status'=>1])
- ->order('sort desc ,id desc')
- ->select();
- $this->all_goods = $all_goods;
- $this->_form($this->table, 'add');
- }
- /**
- * 编辑商品
- * @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
- */
- function edit()
- {
- $this->title = '编辑直播';
- $all_goods = Db::table('store_goods')
- ->field('id,name,cover')
- ->where(['is_integral'=>0,'is_deleted'=>0,'status'=>1])
- ->order('sort desc ,id desc')
- ->select();
- $this->all_goods = $all_goods;
- $this->_form($this->table, 'form');
- }
- /**
- * 表单数据处理
- * @auth true
- * @menu true
- * @param array $data
- */
- protected function _form_filter(&$data)
- {
- if($this->request->isGet()){
- if($this->request->action() == 'edit') {
- if($data['detail']) $data['detail'] = json_decode($data['detail'],true);
- }
- }
- // 添加或编辑商品
- if ($this->request->isPost()) {
- $detail_count = count($data['gl_st']);
- $live_goods = [];
- for ($i= 0;$i < $detail_count;$i++) {
- $live_goods[$i]['gl_st'] = $data['gl_st'][$i];
- $live_goods[$i]['gl_end'] = $data['gl_end'][$i];
- $live_goods[$i]['goods_id'] = $data['goods_id'][$i];
- }
- $data['detail'] = json_encode($live_goods);
- if($data['end_at'] < date('Y-m-d H:i:s')) $data['status'] = 3;
- if($data['end_at'] > date('Y-m-d H:i:s') && $data['start_at'] < date('Y-m-d H:i:s') ) $data['status'] = 1;
- if($data['start_at'] > date('Y-m-d H:i:s')) $data['status'] = 2;
- }
- }
- /**
- * 表单结果处理
- * @param boolean $result
- */
- protected function _form_result($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();
- $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) {
- // 需要新加
- 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);
- }
- }
- 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();
- }*/
- }
- /**
- * @auth true
- * @menu true
- * 商品上架
- */
- public function up()
- {
- $this->_save($this->table, ['status' => '1']);
- }
- /**
- * @auth true
- * @menu true
- * 商品下架
- */
- public function down()
- {
- $this->_save($this->table, ['status' => '0']);
- }
- /**
- * @auth true
- * @menu true
- * 商品下架
- */
- public function del()
- {
- $this->_save($this->table, ['is_deleted' => '1']);
- }
- public function upload(){
- if(!in_array($_FILES["file"]["type"],['image/png','image/jpeg','image/jpeg'])) echo '图片类型不支持';
- if($_FILES["file"]["size"] > 50000000) echo '图片大小最大50M';
- if ($_FILES["file"]["error"] > 0) echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
- // $dir = env('root_path') . 'public/static/pic';
- $dir = $_SERVER['DOCUMENT_ROOT']. '/static/pic';
- /* var_dump($dir);
- if(!is_dir($dir)) {
- var_dump(mkdir($dir));
- }*/
- move_uploaded_file($_FILES["file"]["tmp_name"], $dir."/" . $_FILES["file"]["name"]);
- echo $dir."/" . $_FILES["file"]["name"];
- }
- }
|