tname = $_M['form']['tname']; $this->sqlk = $_YW['k'][$this->tname]; } public function __destruct() { global $_M,$_YW; if($this->destruct){ switch ($this->tname) { case 'para': $this->para = [ 'p_type' => $_M['form']['p_type'] ]; break; default: break; } if(count($this->para)) $para = '&'.http_build_query($this->para); turnover($this->returl?:$_M['url']['own_name'] . 'c=table_on&a=do'.$this->tname.$para, $this->tips); } } //主方法 public function doindex(){ global $_M,$_YW; $this->allid = array_filter(explode(',', $_M['form']['all_id'])); switch ($_M['form']['submit_type']) { case 'delet': self::delet(); break; case 'save': self::save(); break; case 'enableon': case 'enableoff': self::enable(); break; case 'enable_on': case 'enable_off': self::enable(false); break; case 'typeonoff': self::typeonoff(); break; default: break; } if($_M['form']['method'] == 'ajax') { $this->destruct = false; echo jsoncallback(['code' => $this->tsql->error()?1:0 ]); } } //保存 private function save() { global $_M,$_YW; foreach ($this->allid as $id) { if($id){ $field = self::info($id); if(is_number($id)){ $this->tsql->table($this->tname) ->field($field) ->where(" id = '{$id}' ") ->upd(); } else { $this->tsql->table($this->tname) ->field($field) ->add(); } } } } //删除 private function delet() { global $_M,$_YW; foreach ($this->allid as $id) { if($id){ //删除关联表 $ret = self::todel($id); if($ret == false) continue; //删除本表 $where = " id = '{$id}' "; $this->tsql->table($this->tname) ->where($where) ->del(); } } } //调整广告位状态 private function enable($type = true) { global $_M,$_YW; $enable = $_M['form']['submit_type'] == 'enableon' || $_M['form']['submit_type'] == 'enable_on'?1:0; $fid = $type?'e_vid':'id'; foreach ($this->allid as $id) { if($id){ $this->tsql->table('elevator') ->field(['e_enable' => $enable]) ->where([$fid => $id]) ->upd(); } } } //ajax单独调整 private function typeonoff() { global $_M,$_YW; $field = $_M['form']['field']; $special = "ABS({$field}-1)"; $array = [$field => $special]; $field_id = 'id'; foreach ($this->allid as $id) { if($id){ $this->tsql->table($this->tname) ->special($special) ->field($array) ->where([$field_id => $id]) ->upd(); } } } //保存信息 private function info($id) { global $_M,$_YW; $lang = ''; switch ($this->tname) { case 'para': $info = [ 'p_type' => $_M['form']['p_type-'.$id], 'p_order' => $_M['form']['p_order-'.$id], 'p_name' => $_M['form']['p_name-'.$id], 'p_value' => $_M['form']['p_value-'.$id], 'p_text' => $_M['form']['p_text-'.$id] ]; break; default: break; } return $info; } //删除其他的关联表 private function todel($id) { global $_M,$_YW; $ret = true; switch ($this->tname) { case 'contract': //获取合同编号 $contract = $this->tsql->table('contract') ->where(['id' => $id]) ->one(); //删除相关计划 $this->tsql->table('launch') ->where(['l_hnumber' => $contract['h_number'] ]) ->del(); //删除相关排期 $this->tsql->table('schedule') ->where(['s_hnumber' => $contract['h_number'] ]) ->del(); break; case 'launch': //删除相关排期 $this->tsql->table('schedule') ->where(['s_lid' => $id ]) ->del(); break; case 'para': //删除相关的光广告位 if($_M['form']['p_num-'.$id] > 0) $ret = false; break; case 'village': //查询需要删除的广告位编号 $elevator = $this->tsql->table('elevator') ->where(['e_vid' => $id]) ->all(); $e_number = array_column($elevator, 'e_number'); self::del_elevator($e_number); break; case 'elevator': $elevator = $this->tsql->table('elevator') ->where(['id' => $id]) ->one(); //删除相关排期广告位编号 self::del_elevator($elevator['e_number']); break; default: break; } return $ret; } // 删除排期广告位编号 private function del_elevator($num) { $dellist = []; if(!is_array($num)) $num = [$num]; $num = array_unique($num); if(count($num) == 0) return false; // 广告位数组 foreach ($num as $e_number){ // 删除广告位 $this->tsql->table('elevator') ->where(['e_number' => $e_number ]) ->del(); //删除相关排期缓存 $this->tsql->table('schedule') ->where(['s_enumber' => $e_number ]) ->del(); // 整理数据 $launch = false; // 选择的广告位 $launch = $this->tsql->table('launch') ->where(" find_in_set( '{$e_number}', l_selectenum ) ") ->all(); // 处理的核心函数 $col = function($launch,$field) use(&$dellist,$e_number){ foreach ($launch as $val){ $dellist[$val['id']]['info'] = $val; $dellist[$val['id']][$field][] = $e_number; } }; if($launch != false) $col($launch,'l_selectenum'); // 排期成功的广告位 $launch = $this->tsql->table('launch') ->where(" find_in_set( '{$e_number}', l_enumber ) ") ->all(); if($launch != false) $col($launch,'l_enumber'); } if(count($dellist) == 0) return false; // 对值进行统计并修改 foreach ($dellist as $id => $la){ // 处理的核心函数 $enum = function($field) use($la){ // 拿到la内需要去掉的值 数组 // 再通过对比获得差异值,并去重,再转成字符串 return is_array($la[$field])?arrayto_string(array_unique(array_diff(stringto_array($la['info'][$field],','),$la[$field])),','):$la['info'][$field]; }; //mysql $this->tsql->table('launch') ->field(['l_selectenum' => $enum('l_selectenum'), 'l_enumber' => $enum('l_enumber')]) ->where(['id' => $id]) ->upd(); } } } ?>