123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- <?php
- namespace app\operate\controller;
- use app\common\model\DatumIntro;
- use app\common\model\Supplier;
- use app\common\model\SupplierGoods;
- use app\common\model\User;
- use library\Controller;
- use think\Db;
- class Press extends Controller
- {
- protected $table = 'Press';
-
- public function index()
- {
- $this->title = '列表';
- $where = [];
- $where[] = ['f.is_deleted','=',0];
- if($title = input('title')) $where[] = ['f.title','like','%'.$title.'%'];
- $query = $this->_query($this->table)->alias('f')
- ->field('f.*')
- ->where($where)
- ->order('sort desc,f.id desc')->page();
- }
-
- public function add()
- {
- $this->title = '添加';
- $this->_form($this->table, 'form');
- }
-
- public function edit()
- {
- $this->title = '编辑';
- $this->_form($this->table, 'form');
- }
-
- public function del()
- {
- \app\common\model\Press::where('id',input('id'))->update(['is_deleted'=>1]);
- \app\common\model\Press::esAdd(input('id'));
- \app\common\model\TopSearch::saveData(input('id'),'press');
- $this->success('已删除!');
- }
-
- public function remove()
- {
- $ids = input('id');
- foreach (explode(',',$ids) as $id) {
- \app\common\model\Press::where('id',$id)->update(['is_deleted'=>1]);
- \app\common\model\Press::esAdd($id);
- \app\common\model\TopSearch::saveData($id,'press');
- }
- $this->success('已删除!');
- }
-
- public function enable()
- {
- \app\common\model\Press::where('id',input('id'))->update(['status'=>1]);
- \app\common\model\Press::esAdd(input('id'));
- $this->success('已上架!');
- }
-
- public function forbidden()
- {
- \app\common\model\Press::where('id',input('id'))->update(['status'=>0]);
- \app\common\model\Press::esAdd(input('id'));
- \app\common\model\TopSearch::saveData(input('id'),'press');
- $this->success('已下架!');
- }
- protected function _form_filter(&$data){
-
- $this->article_list =\app\common\model\ArticleIntro::with('itemChildren')
- ->field('id,title')
- ->where(['is_deleted'=>0])->order('id asc')
- ->select()->toArray();
-
- $this->video_list = \app\common\model\VideoIntro::with('videoArr')
- ->where(['is_deleted'=>0])->order('id desc')
- ->select()->toArray();
-
- $this->datum_list = DatumIntro::with('urlArr')
- ->where(['is_deleted'=>0])->order('id desc')
- ->select()->toArray();
- $this->supplier = Supplier::with('goodsList')
- ->where(['is_deleted'=>0])
- ->where('status',1)
- ->select()->toArray();
- $this->supplier_goods = SupplierGoods::getSupplierGoodsList($this->request->action() == 'add' ? ['s.is_deleted'=>0,'g.is_deleted'=>0]: ['s.is_deleted'=>0,'g.is_deleted'=>0]);
- if($this->request->isPost())
- {
- if(empty($data['title']))$this->error('请输入标题');
- if(empty($data['images']))$this->error('请上传封面');
- if(!$data['release_time']) $data['release_time'] = date("Y-m-d H:i:s");
- if($data['hot_num'] != $data['hot_num_old']) $data['hot_time'] = date("Y-m-d H:i:s");
- if(!empty($data['phone'])) {
- $user_id = User::where('phone|email',$data['phone'])->value('id');
- if(!$user_id) $this->error('账号未注册');
- $data['user_id'] = $user_id;
- }else{
- $data['user_id'] = '';
- }
- list($post) = [$this->request->post()];
-
- if(!$post['hot_num']){
- $post['hot_num'] = 0;
- }
- if(isset($post['id'])){
- $info = \app\common\model\Press::where('id',$data['id'])->find();
- if(($post['regular_hot_end_time'] && $post['hot_target_num'] && $info['regular_hot_end_time'] != $post['regular_hot_end_time']) || ($info['hot_num'] != $post['hot_num'] && $post['regular_hot_end_time'] && $post['hot_target_num'])){
- $data['regular_hot_start_time'] = date("Y-m-d H:i:s");
- $startdate = strtotime($data['regular_hot_start_time']);
- $enddate = strtotime($post['regular_hot_end_time']);
- $diff_seconds = ($enddate-$startdate)/60;
- $min_num = ceil($diff_seconds/10);
- $hot_num = $post['hot_target_num'] - $post['hot_num'];
- $num = ceil($hot_num/$min_num);
- $data['regular_num'] = $num;
- }
- }else{
- if($post['regular_hot_end_time'] && $post['hot_target_num']){
- $data['regular_hot_start_time'] = date("Y-m-d H:i:s");
- $startdate = strtotime($data['regular_hot_start_time']);
- $enddate = strtotime($post['regular_hot_end_time']);
- $diff_seconds = ($enddate-$startdate)/60;
- $min_num = ceil($diff_seconds/10);
- $hot_num = $post['hot_target_num'] - $post['hot_num'];
- $num = ceil($hot_num/$min_num);
- $data['regular_num'] = $num;
- }
- }
-
- }
- }
- protected function _form_result(&$data)
- {
- \app\common\model\Press::esAdd($data);
- \app\common\model\TopSearch::saveData($data,'press');
- $this->success('操作成功', 'javascript:history.back()');
- }
- }
|