Пример #1
0
 public function liu_yan()
 {
     AAA($_REQUEST);
 }
Пример #2
0
 public function do_edit_list()
 {
     //判断表下的某个字段是否已经存在
     $list_id = $_REQUEST['list_id'];
     $list = $this->CM('cm_list')->find($_REQUEST['list_id']);
     $list_name = $list['list_name'];
     $list_expand_column = array();
     $sql = 'select  column_name, column_comment  from Information_schema.columns  where table_Name ="cm_list_item"  AND table_schema = "' . C('DB_NAME') . '"';
     $exist_column = M()->query($sql);
     //AAA($exist_column);
     //获取category的所有扩展字段
     foreach ($exist_column as $key => $one_column) {
         //如果存爱字段
         $expand_column = explode('_', $one_column['column_name']);
         $expand_column_name = $expand_column[0];
         //print_r($expand_column); echo '<br>';
         //如果是category开头
         if ($list_name == $expand_column_name) {
             $one = array();
             $one['column_name'] = $one_column['column_name'];
             $one['sign'] = 'delete';
             $list_expand_column[$one_column['column_name']] = $one;
         }
     }
     //AAA($list_expand_column);
     $expands = $_REQUEST['list_add_column_name'];
     $expands_type = $_REQUEST['list_column_type'];
     $expands_desc = $_REQUEST['list_add_column_desc'];
     //判断操作符
     foreach ($expands as $key => $font_column_name) {
         if (empty($font_column_name)) {
             continue;
         }
         $column_op = $list_name . '_' . $font_column_name;
         if (isset($list_expand_column[$column_op])) {
             $list_expand_column[$column_op]['sign'] = 'update';
         } else {
             $list_expand_column[$column_op] = array('column_show_name' => $font_column_name, 'column_name' => $column_op, 'sign' => 'insert');
         }
     }
     foreach ($list_expand_column as $val) {
         if ($val['sign'] == 'insert') {
             $sql = "ALTER TABLE cm_list_item ADD " . $val['column_name'] . " VARCHAR( 255 )  NOT NULL DEFAULT ''  ";
             M()->query($sql);
         }
         if ($val['sign'] == 'delete') {
             $sql = "ALTER TABLE cm_list_item DROP " . $val['column_name'];
             //删除数据库字段
             M()->query($sql);
         }
     }
     $now_column = array();
     $my_key = 0;
     foreach ($list_expand_column as $key => $val) {
         if ($val['sign'] != 'delete') {
             $now_column[] = array('column_show_name' => $val['column_show_name'], 'column_name' => $val['column_name'], 'column_type' => $expands_type[$my_key], 'column_desc' => $expands_desc[$my_key]);
             $my_key += 1;
         }
     }
     $data['expand_column'] = serialize($now_column);
     $data['list_id'] = $list_id;
     M('cm_list')->save($data);
     AAA($now_column);
     //AAA($now_column);
     //AAA($list_expand_column);
     // foreach($_REQUEST['list_add_column_name'] as $key => $list_column_name){
     // $flag = true;
     // echo $flag.'<br>';
     // if( $flag  ){
     // $sql="ALTER TABLE cm_list_item ADD ".$list_column_name." VARCHAR( 255 )  NOT NULL DEFAULT ''  ";
     // M()->query($sql);
     // }
     // }
 }