Is_Login(); // 权限校验 $this->Is_Power(); } /** * [Index 装饰列表] */ public function Index() { // 参数 $param = array_merge($_POST, $_GET); // 模型模型 $m = D('Culture/CultureDecorate'); // 条件 $where = $this->GetIndexWhere(); // 分页 $number = MyC('admin_page_number'); $page_param = array( 'number' => $number, 'total' => $m->where($where)->count(), 'where' => $param, 'url' => U('Culture/CultureDecorate/Index'), ); $page = new \My\Page($page_param); // 获取列表 $field = array('decorate_id', 'decorate_name', 'thumb', 'description', 'decorate_type_id', 'decorate_target_type_id', 'decorate_target_id', 'decorate_target_property_id', 'sale_price', 'created_at', 'updated_at'); $list = $this->SetDataHandle($m->field($field)->where($where)->relation("DecorateType")->limit($page->GetPageStarNumber(), $number)->order('decorate_id desc')->select()); // 参数 $this->assign('param', $param); // 分页 $this->assign('page_html', $page->GetPageHtml()); // 数据列表 $this->assign('list', $list); $this->display('Index'); } /** * [SetDataHandle 数据处理] * @param [array] $data [装饰数据] * @return [array] [处理好的数据] */ private function SetDataHandle($data) { foreach ($data as $k => &$value) { //获取装饰对象类型 unset($map); $map['decorate_target_type_id'] = $value['decorate_target_type_id']; $target_type = D('Culture/CultureDecorateTargetType')->field("decorate_target_type_name, model, mark")->where($map)->find(); $value['decorate_target_type_name'] = $target_type['decorate_target_type_name']; //获取装饰对象 if($value['decorate_target_id']){ unset($map); $map["{$target_type['mark']}_id"] = $value['decorate_target_id']; $target = D($target_type['model'])->field("{$target_type['mark']}_id, {$target_type['mark']}_name")->where($map)->find(); $value['decorate_target_name'] = $target["{$target_type['mark']}_name"]; if($value['decorate_target_property_id']){ unset($map); switch ($target_type['mark']) { case 'scene': $map['scene_id'] = $value['decorate_target_property_id']; $value['decorate_target_property_name'] = D("Culture/CultureScene")->where($map)->getField("scene_name"); break; case 'pet_type': $map['pet_id'] = $value['decorate_target_property_id']; $map['pet_type_id'] = $value['decorate_target_id']; $value['decorate_target_property_name'] = D("Culture/CulturePet")->where($map)->getField("pet_name"); break; default: $value['decorate_target_property_name'] = ''; break; } } } } return $data; } /** * [GetIndexWhere 装饰列表条件] */ private function GetIndexWhere() { $where = array(); // 模糊 if(!empty($_REQUEST['keyword'])) { $like_keyword = array('like', '%'.I('keyword').'%'); $where[] = array( 'decorate_name' => $like_keyword, ); } // 是否更多条件 if(I('is_more', 0) == 1) { // 表达式 if(!empty($_REQUEST['time_start'])) { $where['created_at'][] = array('gt', I('time_start') . ' 00:00:00'); } if(!empty($_REQUEST['time_end'])) { $where['created_at'][] = array('lt', I('time_end') . ' 23:59:59'); } } $where['deleted_at'] = ["exp", "is null"]; return $where; } /** * [SaveInfo 装饰添加/编辑页面] */ public function SaveInfo() { // 装饰信息 $data = empty($_REQUEST['decorate_id']) ? array() : D('Culture/CultureDecorate')->find(I('decorate_id')); $this->assign('data', $data); // 获取装饰类型 if($data['decorate_type_id']){ $map['decorate_target_type_id'] = $data['decorate_target_type_id']; if($data['decorate_target_id']){ $map['decorate_target_id'] = $data['decorate_target_id']; } if($data['decorate_target_property_id']){ $map['decorate_target_property_id'] = $data['decorate_target_property_id']; } $decorate_type_list = D("Culture/CultureDecorateType")->field("decorate_type_id, decorate_type_name")->where($map)->select(); $this->assign('decorate_type_list', $decorate_type_list); } // 装饰对象类型信息 unset($map); $map['deleted_at'] = ["exp", "is null"]; $decorate_target_type_list = D('Culture/CultureDecorateTargetType')->field("decorate_target_type_id, decorate_target_type_name")->where($map)->select(); $this->assign('decorate_target_type_list', $decorate_target_type_list); //获取装饰对象信息 if($data['decorate_target_id']){ unset($map); $map['decorate_target_type_id'] = $data['decorate_target_type_id']; $target_type = D('Culture/CultureDecorateTargetType')->field("model, mark")->where($map)->find(); unset($map); $map['deleted_at'] = ["exp", "is null"]; $decorate_target_list = D($target_type['model'])->field("{$target_type['mark']}_id as id, {$target_type['mark']}_name as name")->where($map)->select(); if($decorate_target_list){ $this->assign('decorate_target_list', $decorate_target_list); } //获取装饰对象专属信息 if($data['decorate_target_property_id']){ switch ($target_type['mark']) { case 'scene': break; case 'pet_type': unset($map); $map['pet_type_id'] = $target["{$target_type['mark']}_id"]; $decorate_target_property_list = D("Culture/CulturePet")->field("pet_id as id, pet_name as name")->where($map)->select(); if($decorate_target_property_list){ $this->assign('decorate_target_property_list', $decorate_target_property_list); } break; default: break; } } } $this->display('SaveInfo'); } /** * [Save 装饰添加/编辑] */ public function Save() { // 是否ajax请求 if(!IS_AJAX) { $this->error(L('common_unauthorized_access')); } // 添加 if(empty($_POST['decorate_id'])) { $this->Add(); // 编辑 } else { $this->Edit(); } } /** * [Add 装饰添加] */ private function Add() { // 装饰模型 $m = D('Culture/CultureDecorate'); // 数据自动校验 if($m->create($_POST, 1)) { $m->created_at = date('Y-m-d H:i:s'); $m->updated_at = date('Y-m-d H:i:s'); // 数据添加 if($m->add()) { $this->ajaxReturn(L('common_operation_add_success')); } else { echo M()->getLastsql();exit; $this->ajaxReturn(L('common_operation_add_error'), -100); } } else { $this->ajaxReturn($m->getError(), -1); } } /** * [Edit 装饰编辑] */ private function Edit() { // 装饰模型 $m = D('Culture/CultureDecorate'); // 数据自动校验 if($m->create($_POST, 2)) { $m->updated_at = date('Y-m-d H:i:s'); // 更新数据库 if($m->where(array('decorate_id'=>I('decorate_id')))->save()) { $this->ajaxReturn(L('common_operation_edit_success')); } else { $this->ajaxReturn(L('common_operation_edit_error'), -100); } } else { $this->ajaxReturn($m->getError(), -1); } } /** * [Delete 装饰删除] */ public function Delete() { // 是否ajax请求 if(!IS_AJAX) { $this->error(L('common_unauthorized_access')); } // 参数处理 $id = I('decorate_id'); // 删除数据 if(!empty($id)) { // 装饰模型 $m = D('Culture/CultureDecorate'); // 装饰是否存在 $scene = $m->where(array('decorate_id'=>$id))->count(); if(empty($scene)) { $this->ajaxReturn(L('common_user_no_exist_error'), -2); } // 删除装饰 $update_data['delete'] = date('Y-m-d H:i:s'); $state = $m->where(array('decorate_id'=>$id))->save($update_data); if($state !== false) { $this->ajaxReturn(L('common_operation_delete_success')); } else { $this->ajaxReturn(L('common_operation_delete_error'), -100); } } else { $this->ajaxReturn(L('common_param_error'), -1); } } /** * 获取装饰对象 */ public function getDecorateTarget() { $decorate_target_type_id = (int) I('decorate_target_type_id'); //获取对象表 $map['decorate_target_type_id'] = $decorate_target_type_id; $target_type = D('Culture/CultureDecorateTargetType')->field("model, mark")->where($map)->find(); unset($map); $map['deleted_at'] = ["exp", "is null"]; $list = D($target_type['model'])->field("{$target_type['mark']}_id as id, {$target_type['mark']}_name as name")->where($map)->select(); if(!$list){ $response_data['code'] = 400; $response_data['msg'] = "暂无数据"; echo json_encode($response_data, JSON_UNESCAPED_UNICODE); exit(); } $response_data['code'] = 0; $response_data['msg'] = "获取成功"; $response_data['data'] = $list; echo json_encode($response_data, JSON_UNESCAPED_UNICODE); exit(); } /** * 获取装饰对象专属ID */ public function getDecorateTargetProperty() { $decorate_target_type_id = (int) I('decorate_target_type_id'); $decorate_target_id = (int) I('decorate_target_id'); //获取对象表 $map['decorate_target_type_id'] = $decorate_target_type_id; $target_type = D('Culture/CultureDecorateTargetType')->field("model, mark")->where($map)->find(); unset($map); $map['deleted_at'] = ["exp", "is null"]; $map["{$target_type['mark']}_id"] = $decorate_target_id; $target = D($target_type['model'])->field("{$target_type['mark']}_id, {$target_type['mark']}_name")->where($map)->find(); switch ($target_type['mark']) { case 'scene': $list = []; break; case 'pet_type': unset($map); $map['pet_type_id'] = $target["{$target_type['mark']}_id"]; $list = D("Culture/CulturePet")->field("pet_id as id, pet_name as name")->where($map)->select(); break; default: $list = []; break; } if(count($list) < 1){ $response_data['code'] = 400; $response_data['msg'] = "暂无数据"; echo json_encode($response_data, JSON_UNESCAPED_UNICODE); exit(); } $response_data['code'] = 0; $response_data['msg'] = "获取成功"; $response_data['data'] = $list; echo json_encode($response_data, JSON_UNESCAPED_UNICODE); exit(); } /** * 获取装饰类型 */ public function getDecorateType() { $decorate_target_type_id = (int) I('decorate_target_type_id'); $decorate_target_id = (int) I('decorate_target_id'); $decorate_target_property_id = (int) I('decorate_target_property_id'); if(!$decorate_target_type_id){ $response_data['code'] = 400; $response_data['msg'] = "暂无数据"; echo json_encode($response_data, JSON_UNESCAPED_UNICODE); exit(); } $map['decorate_target_type_id'] = $decorate_target_type_id; if($decorate_target_id){ $map['decorate_target_id'] = $decorate_target_id; } if($decorate_target_property_id){ $map['decorate_target_property_id'] = $decorate_target_property_id; } // 装饰类型信息 $map['deleted_at'] = ["exp", "is null"]; $list = D('Culture/CultureDecorateType')->field("decorate_type_id as id, decorate_type_name as name")->where($map)->select(); $response_data['code'] = 0; $response_data['msg'] = "获取成功"; $response_data['data'] = $list; echo json_encode($response_data, JSON_UNESCAPED_UNICODE); exit(); } }