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.*,u.name,u.phone,u.headimg') ->leftJoin('store_member u','u.id = f.user_id') ->where($where) ->order('sort desc,f.id desc')->page(); } /** * 删除 * @auth true * @throws \think\Exception * @throws \think\exception\PDOException */ public function del() { \app\common\model\PlatformDemand::where('id',input('id'))->update(['is_deleted'=>1]); \app\common\model\PlatformDemand::esAdd(input('id')); \app\common\model\TopSearch::saveData(input('id'),'demand'); $this->success('已删除!'); } /** * 批量删除 * @auth true * @throws \think\Exception * @throws \think\exception\PDOException */ public function remove() { $ids = input('id'); foreach (explode(',',$ids) as $id) { \app\common\model\PlatformDemand::where('id',$id)->update(['is_deleted'=>1]); \app\common\model\PlatformDemand::esAdd($id); \app\common\model\TopSearch::saveData($id,'demand'); } $this->success('已删除!'); } /** * 编辑 * @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->_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->_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 up() { \app\common\model\PlatformDemand::where('id',input('id'))->update(['status'=>1]); \app\common\model\PlatformDemand::esAdd(input('id')); \app\common\model\TopSearch::saveData(input('id'),'demand'); $this->success('已上架!'); } /** * 商品下架 * @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 down() { \app\common\model\PlatformDemand::where('id',input('id'))->update(['status'=>0]); \app\common\model\PlatformDemand::esAdd(input('id')); \app\common\model\TopSearch::saveData(input('id'),'demand'); $this->success('已下架!'); } protected function _form_filter(&$data) { // 资料 $this->datum_list = DatumIntro::with('urlArr') ->where(['is_deleted'=>0])->order('id desc') ->select()->toArray(); if($this->request->isGet() && $this->request->action() == 'edit') $this->user_info = Db::name('store_member')->find($data['user_id']); if($this->request->isPost()) { 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'] = 0; } list($post) = [$this->request->post()]; //定时热搜 if(!$post['hot_num']){ $post['hot_num'] = 0; } if(isset($post['id'])){ $info = \app\common\model\PlatformDemand::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); if($num < 0){ $num = 0; } $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); if($num < 0){ $num = 0; } $data['regular_num'] = $num; } } //定时热搜end } } protected function _form_result($result){ \app\common\model\PlatformDemand::esAdd($result); \app\common\model\TopSearch::saveData($result,'demand'); $this->success('操作成功', 'javascript:history.back()'); } }