<?php
namespace app \index \controller ;
use think\Hook;
use app\index\controller\Acl;
use app\index\model\Serve as Serves;
use app\index\controller\Formfield;
class Serve extends Acl {
public function main(){
return $this->fetch();
}
public function serve_list(){
$input=input('post.');
if(isset_full($input,'page') && isset_full($input,'limit')){
$sql=get_sql($input,[
'name'=>'full_name_py_link',
'number'=>'full_like',
'data'=>'full_like'
],'serve') $count = Serves::where ($sql)->count() $arr = Serves::where($sql)->page($input['page'],$input['limit'])->order('id desc')->select() $resule=[
'code'=>0,
'msg'=>'获取成功',
'count'=>$count,
'data'=>$arr
] }else{
$resule=['state'=>'error','info'=>'传入参数不完整!'];
}
return json($resule);
}
public function set_serve(){
$input=input('post.');
if(isset($input['id'])){
if(empty($input['id'])){
$vali = $this->validate($input,'serve');
if($vali===true){
$input['py']=zh2py($input['name']) $create_info=Serves::create(syn_sql($input,'serve'));
Hook::listen('create_serve',$create_info) push_log('新增服务项目信息[ '.$create_info['name'].' ]') $resule=['state'=>'success'];
}else{
$resule=['state'=>'error','info'=>$vali];
}
}else{
$vali = $this->validate($input,'serve.update');
if($vali===true){
$input['py']=zh2py($input['name']) $update_info=Serves::update(syn_sql($input,'serve'));
Hook::listen('update_serve',$update_info) push_log('更新服务项目信息[ '.$update_info['name'].' ]') $resule=['state'=>'success'];
}else{
$resule=['state'=>'error','info'=>$vali];
}
}
}else{
$resule=['state'=>'error','info'=>'传入参数不完整!'];
}
return json($resule);
}
public function get_serve(){
$input=input('post.');
if(isset_full($input,'id')){
$resule=Serves::where(['id'=>$input['id']])->find();
}else{
$resule=['state'=>'error','info'=>'传入参数不完整!'];
}
return json($resule);
}
public function del_serve(){
$input=input('post.');
if(isset_full($input,'arr') && is_array($input['arr'])){
$exist=more_table_find([
['table'=>'itemorderinfo','where'=>['serve'=>['in',$input['arr']]]]
]);
if(!$exist){
$info=db('serve')->where(['id'=>['in',$input['arr']]])->select() foreach ($info as $info_vo) {
push_log('删除服务项目信息[ '.$info_vo['name'].' ]') Hook::listen('del_serve',$info_vo['id']) }
Serves::where(['id'=>['in',$input['arr']]])->delete();
$resule=['state'=>'success'];
}else{
$resule=['state'=>'error','info'=>'存在数据关联,删除失败!'];
}
}else{
$resule=['state'=>'error','info'=>'传入参数不完整!'];
}
return json($resule);
}
public function export_serve(){
$input=input('get.');
$sql=get_sql($input,[
'name'=>'full_name_py_link',
'number'=>'full_like',
'data'=>'full_like'
],'serve') $arr = Serves::where($sql)->order('id desc')->select() $formfield=get_formfield('serve_export','array') $excel=[] array_push($excel,['type'=>'title','info'=>'服务项目列表']);
$table_cell=[] foreach ($formfield as $formfield_vo) {
$table_cell[$formfield_vo['key']]=$formfield_vo['text'];
}
$table_data=[] foreach ($arr as $arr_vo) {
$row_data=[];
foreach ($formfield as $formfield_vo) {
$val='nod_initial' foreach (explode('|',$formfield_vo['data']) as $source) {
$val=$val=='nod_initial'?$arr_vo[$source]:(isset($val[$source])?$val[$source]:'');
}
$row_data[$formfield_vo['key']]=$val }
array_push($table_data,$row_data) }
array_push($excel,['type'=>'table','info'=>['cell'=>$table_cell,'data'=>$table_data]]) push_log('导出服务项目信息') export_excel('服务项目列表',$excel);
}
}