getMap(); $data_list = DB::table('dp_task_list')->where($map) ->order('time desc') ->paginate(); // 广告主 $name_ad = Db::table('dp_user_list')->where('role_id',1)->column('name'); // 核代 $name_hedai = Db::table('dp_user_list')->where('role_id',0)->column('name'); $sum_data = DB::table('dp_task_list')->where($map)->select(); $params = [ "sum_0_data"=>0,"sum_1_data"=>0,"sum_2_data"=>0, ]; foreach ($sum_data as $value) { if ($value["status"]==0) { $params["sum_0_data"] += $value["money"]; // code... } if ($value["status"]==1) { $params["sum_1_data"] += $value["money"]; // code... } if ($value["status"]==2) { $params["sum_2_data"] += $value["money"]; // code... } # code... } cookie('dp_task_list', $map); return ZBuilder::make('table') ->setTableName('task_list') // 设置数据表名 ->addColumns([ // 批量添加列 ['id', '任务订单ID'], ['name','任务订单名称'], ['time', '创建时间'], ['begin_time', '投放时间'], ['name_ad', '广告主'], ['name_hedai', '核代'], ['money', '金额'], ['status', '状态','status','',[0=>'待付款',1=>'已验收付款',2=>'已完成']], ['right_button', '操作','btn'], ]) ->hideCheckbox() ->setRowList($data_list) // 设置表格数据 ->setSearchArea([ ['select', 'name_ad', '广告主','','',$name_ad ], ['select', 'name_hedai', '核代','','',$name_hedai], ['daterange', 'time', '创建时间','',''], ['daterange', 'begin_time', '预计投放时间','',''], ['select', 'status', '任务状态','','', [0=>'待付款',1=>'已验收付款',2=>'已完成']], ['text', 'id', '任务订单ID'], ]) //筛选条件 ->setHeight('auto') ->addTopButton('add',['title'=>'新增任务']) ->addTopButton('export', [ 'title' => '导出订单', 'class' => 'btn btn-success', 'icon' => 'fa fa-fw fa-file-excel-o', 'href' => '/admin.php/back/task_list/export.html?' . $this->request->query() ]) ->addRightButtons(['edit'=>['title'=>'操作','icon'=>'fa fa-fw fa-gears'], 'delete','info'=>[ 'title' => '操作', 'icon' => 'fa fa-fw fa-gears', 'href' => url('info', ['id' => '__id__']) ],'check'=>[ 'title' => '查看', 'icon' => 'fa fa-fw fa-check', 'href' => url('check', ['id' => '__id__']) ],'supplement'=>[ 'title' => '补充', 'icon' => 'fa fa-fw fa-plus-circle', 'href' => url('supplement', ['id' => '__id__']) ]]) //操作按钮 ->replaceRightButton(['status' => ['in', '1,2']], '', 'delete') ->replaceRightButton(['status' => ['in', '1,2']], '', 'edit') ->replaceRightButton(['status' => ['in', '0,2']], '', 'info') ->replaceRightButton(['status' => ['in', '0,1']], '', 'check') ->replaceRightButton(['status' => ['in', '0,2']], '', 'supplement') ->setExtraHtmlFile('dp_task_list', 'toolbar_top', $params) ->fetch(); // 渲染页面 } // -----------------新增任务 public function add() { if ($this->request->isPost()) { // 表单数据 $data = $this->request->post(); $ad_index = $data['name_ad']; $hedai_index = $data['name_hedai']; $data['ad_id']= Db::table('dp_user_list')->where('role_id',1)->where('status',1)->select()[$ad_index]['id']; $data['name_ad']= Db::table('dp_user_list')->where('role_id',1)->where('status',1)->select()[$ad_index]['name']; $data['hedai_id']= Db::table('dp_user_list')->where('role_id',0)->where('status',1)->select()[$hedai_index]['id']; $data['name_hedai']= Db::table('dp_user_list')->where('role_id',0)->where('status',1)->select()[$hedai_index]['name']; if ($data["name"] =='') { return $this->error('任务名称不能为空'); } if ($data["money"] =='') { return $this->error('金额不能为空'); } if ($data["begin_time"] =='') { return $this->error('投放时间不能为空'); } if ($data["end_time"] =='') { return $this->error('投放时间不能为空'); } if ($data["name_ad"] =='') { return $this->error('广告主不能为空'); } if ($data["name_hedai"] =='') { return $this->error('核代不能为空'); } $r = DB::table('dp_task_list')->insert($data); if ($r) { $this->success('新增成功', 'index'); } else { $this->error('新增失败'); } } // 广告主 $name_ad_list = Db::table('dp_user_list')->where('role_id',1)->where('status',1)->column('name'); // 核代 $name_hedai_list = Db::table('dp_user_list')->where('role_id',0)->where('status',1)->column('name'); return ZBuilder::make('form') ->addFormItems([ // 批量添加列 ['text', 'name', '任务名称', '必填'], ['textarea', 'describe', '任务描述'], ['text', 'money', '金额', '必填'], ['select', 'name_ad', '广告主', '必选', $name_ad_list], ['select', 'name_hedai', '核代', '必选',$name_hedai_list], ['date', 'begin_time', '预计投放时间','必选'], ['date', 'end_time', '预计投放结束时间','必选'], ['date', 'payback_time', '预计回款时间'], ['text', 'money_back', '预计回款金额'], ['files', 'accessory_add', '上传附件'], ['flowdiagram','',"",'0'], ]) ->fetch(); // 渲染页面 } // --------------待付款页面 public function edit($id = '') { $dataInfo = Db::table('dp_task_list')->where('id',$id)->find(); // 用户id $uid = session('user_auth')['uid']; // 用户昵称 $username = get_nickname($uid); if($dataInfo['payback_time']==0){ $dataInfo['payback_time']=''; } // 提交待付款保存数据 if ($this->request->isPost()) { // 表单数据 $data = $this->request->post(); $r =Db::table('dp_task_list') ->where('id', $id) ->update([ 'user_id_pay' => $uid, 'user_name_pay' => $username, 'status' => 1, 'accessory_pay'=>$data['accessory_pay'] ]); if ($r) { $this->success('提交成功', 'index'); } else { $this->error('提交失败'); } } return ZBuilder::make('form') ->addFormItems([ // 批量添加列 ['static', 'name', '任务名称'], ['static', 'describe', '任务描述'], ['static', 'money', '金额'], ['static', 'name_ad', '广告主'], ['static', 'name_hedai', '核代'], ['static', 'begin_time', '预计投放时间'], ['static', 'end_time', '预计投放结束时间'], ['static', 'payback_time', '预计回款时间'], ['static', 'money_back', '预计回款金额'], ['archives', 'accessory_add', '附件'], ['flowdiagram','',"",'1',"0"], ['hr'], ['files', 'accessory_pay', '付款附件'], ]) ->setFormData($dataInfo) ->submitConfirm() ->setBtnTitle('submit', '确定付款') ->fetch(); // 渲染页面 } //------------------- 付款验收页面 public function info($id = '') { $dataInfo = Db::table('dp_task_list')->where('id',$id)->find(); // 用户id $uid = session('user_auth')['uid']; // 用户昵称 $username = get_nickname($uid); if($dataInfo['payback_time']==0){ $dataInfo['payback_time']=''; } // 提交验收保存数据 if ($this->request->isPost()) { // 表单数据 $data = $this->request->post(); $r =Db::table('dp_task_list') ->where('id', $id) ->update([ 'user_id_check' => $uid, //验收人id 'user_name_check' => $username, //验收人username 'status' => 2, 'accessory_check'=>$data['accessory_check'] ]); if ($r) { $this->success('提交成功', 'index'); } else { $this->error('提交失败'); } } return ZBuilder::make('form') ->addFormItems([ // 批量添加列 ['static', 'name', '任务名称'], ['static', 'describe', '任务描述'], ['static', 'money', '金额'], ['static', 'name_ad', '广告主'], ['static', 'name_hedai', '核代'], ['static', 'begin_time', '预计投放时间'], ['static', 'end_time', '预计投放结束时间'], ['static', 'payback_time', '预计回款时间'], ['static', 'money_back', '预计回款金额'], ['archives', 'accessory_add', '附件'], ['flowdiagram','',"",'1',"1","0"], ['hr'], ['archives', 'accessory_pay', '付款附件'], ['static', 'user_name_pay', '审核人'], ['static', 'content_check', '补充'], ['files', 'accessory_check', '验收付款附件'], ]) ->setFormData($dataInfo) ->layout(['accessory_pay' => 4, 'user_name_pay' => 4,'content_check'=>4]) ->submitConfirm() ->setBtnTitle('submit', '确定验收') ->fetch(); // 渲染页面 } // -----------------------已完成页面 public function check($id = '') { $dataInfo = Db::table('dp_task_list')->where('id',$id)->find(); if($dataInfo['payback_time']==0){ $dataInfo['payback_time']=''; } return ZBuilder::make('form') ->addFormItems([ // 批量添加列 ['static', 'name', '任务名称'], ['static', 'describe', '任务描述'], ['static', 'money', '金额'], ['static', 'name_ad', '广告主'], ['static', 'name_hedai', '核代'], ['static', 'begin_time', '预计投放时间'], ['static', 'end_time', '预计投放结束时间'], ['static', 'payback_time', '预计回款时间'], ['static', 'money_back', '预计回款金额'], ['archives', 'accessory_add', '附件'], ['flowdiagram','',"",'1',"1","1"], ['hr'], ['archives', 'accessory_pay', '付款附件'], ['static', 'user_name_pay', '审核人'], ['static', 'content_check', '补充'], ['archives', 'accessory_check', '已验收付款附件'], ['static', 'user_name_check', '审核人'], ]) ->setFormData($dataInfo) ->layout(['accessory_pay' => 6, 'user_name_pay' => 3,'content_check'=>3]) ->layout(['accessory_check' => 7, 'user_name_check' => 4]) ->submitConfirm() ->hideBtn('submit') ->fetch(); // 渲染页面 } //------------------- 补充 public function supplement($id = '') { // $data_list = Db::table('dp_task_list')->where('id',$id)->value('content_check'); $data_list = Db::table('dp_task_list')->where('id',$id)->find(); // 提交验收保存数据 if ($this->request->isPost()) { // 表单数据 $data = $this->request->post(); if($data['content_check']==''){ return $this->error('补充信息不能为空'); } $r =Db::table('dp_task_list') ->where('id', $id) ->update([ 'content_check' => $data['content_check'], //验收补充内容 ]); if ($r) { $this->success('提交成功', 'index'); } else { $this->error('提交失败'); } } return ZBuilder::make('form') ->addFormItems([ // 批量添加列 ['textarea', 'content_check', '补充'], ]) ->setFormData($data_list) ->fetch(); // 渲染页面 } //导出 public function export() { $map = $this->getMap(); $data_list = DB::table('dp_task_list')->field(['id', 'name', 'time','name_ad','name_hedai','money','status'])->where($map)->select(); // 转换状态值并保存在新字段中 foreach ($data_list as &$data) { if ($data['status'] == 0) { $data['status_text'] = '待付款'; } elseif ($data['status'] == 1) { $data['status_text'] = '已验收付款'; }else{ $data['status_text'] = '已完成'; } } // 设置表头信息(对应字段名,宽度,显示表头名称) $cellName = [ ['id', 10, '任务ID'], ['name', 10, '任务名称'], ['time', 10, '时间'], ['name_ad', 20, '广告主'], ['name_hedai', 20, '核代'], ['money', 20, '金额'], ['status_text', 20, '状态'], ]; // 调用插件(传入插件名,[导出文件名、表头信息、具体数据]) plugin_action('Excel/Excel/export', ['任务订单管理列表'.date('Y-m-d H:i:s'), $cellName, $data_list]); } }