TaskList.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <?php
  2. //任务订单列表
  3. namespace app\back\admin;
  4. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  5. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  6. use app\back\lib\xls\Client;
  7. use app\admin\controller\Admin;
  8. use app\common\builder\ZBuilder;
  9. use think\Db;
  10. use app\common\controller\Common;
  11. class TaskList extends Admin {
  12. /**
  13. *
  14. * @edit 待付款页面
  15. * @info 待验收页面
  16. * @check 已完成页面
  17. */
  18. public function index()
  19. {
  20. $map = $this->getMap();
  21. $data_list = DB::table('dp_task_list')->where($map)
  22. ->order('time desc')
  23. ->paginate();
  24. // 广告主
  25. $name_ad = Db::table('dp_user_list')->where('role_id',1)->column('name');
  26. // 核代
  27. $name_hedai = Db::table('dp_user_list')->where('role_id',0)->column('name');
  28. $sum_data = DB::table('dp_task_list')->where($map)->select();
  29. $params = [
  30. "sum_0_data"=>0,"sum_1_data"=>0,"sum_2_data"=>0,
  31. ];
  32. foreach ($sum_data as $value) {
  33. if ($value["status"]==0) {
  34. $params["sum_0_data"] += $value["money"];
  35. // code...
  36. }
  37. if ($value["status"]==1) {
  38. $params["sum_1_data"] += $value["money"];
  39. // code...
  40. }
  41. if ($value["status"]==2) {
  42. $params["sum_2_data"] += $value["money"];
  43. // code...
  44. }
  45. # code...
  46. }
  47. cookie('dp_task_list', $map);
  48. return ZBuilder::make('table')
  49. ->setTableName('task_list') // 设置数据表名
  50. ->addColumns([ // 批量添加列
  51. ['id', '任务订单ID'],
  52. ['name','任务订单名称'],
  53. ['time', '创建时间'],
  54. ['begin_time', '投放时间'],
  55. ['name_ad', '广告主'],
  56. ['name_hedai', '核代'],
  57. ['money', '金额'],
  58. ['status', '状态','status','',[0=>'待付款',1=>'已验收付款',2=>'已完成']],
  59. ['right_button', '操作','btn'],
  60. ])
  61. ->hideCheckbox()
  62. ->setRowList($data_list) // 设置表格数据
  63. ->setSearchArea([
  64. ['select', 'name_ad', '广告主','','',$name_ad ],
  65. ['select', 'name_hedai', '核代','','',$name_hedai],
  66. ['daterange', 'time', '创建时间','',''],
  67. ['daterange', 'begin_time', '预计投放时间','',''],
  68. ['select', 'status', '任务状态','','', [0=>'待付款',1=>'已验收付款',2=>'已完成']],
  69. ['text', 'id', '任务订单ID'],
  70. ]) //筛选条件
  71. ->setHeight('auto')
  72. ->addTopButton('add',['title'=>'新增任务'])
  73. ->addTopButton('export', [
  74. 'title' => '导出订单',
  75. 'class' => 'btn btn-success',
  76. 'icon' => 'fa fa-fw fa-file-excel-o',
  77. 'href' => '/admin.php/back/task_list/export.html?' . $this->request->query()
  78. ])
  79. ->addRightButtons(['edit'=>['title'=>'操作','icon'=>'fa fa-fw fa-gears'], 'delete','info'=>[
  80. 'title' => '操作',
  81. 'icon' => 'fa fa-fw fa-gears',
  82. 'href' => url('info', ['id' => '__id__'])
  83. ],'check'=>[
  84. 'title' => '查看',
  85. 'icon' => 'fa fa-fw fa-check',
  86. 'href' => url('check', ['id' => '__id__'])
  87. ],'supplement'=>[
  88. 'title' => '补充',
  89. 'icon' => 'fa fa-fw fa-plus-circle',
  90. 'href' => url('supplement', ['id' => '__id__'])
  91. ]]) //操作按钮
  92. ->replaceRightButton(['status' => ['in', '1,2']], '', 'delete')
  93. ->replaceRightButton(['status' => ['in', '1,2']], '', 'edit')
  94. ->replaceRightButton(['status' => ['in', '0,2']], '', 'info')
  95. ->replaceRightButton(['status' => ['in', '0,1']], '', 'check')
  96. ->replaceRightButton(['status' => ['in', '0,2']], '', 'supplement')
  97. ->setExtraHtmlFile('dp_task_list', 'toolbar_top', $params)
  98. ->fetch(); // 渲染页面
  99. }
  100. // -----------------新增任务
  101. public function add()
  102. {
  103. if ($this->request->isPost()) {
  104. // 表单数据
  105. $data = $this->request->post();
  106. $ad_index = $data['name_ad'];
  107. $hedai_index = $data['name_hedai'];
  108. $data['ad_id']= Db::table('dp_user_list')->where('role_id',1)->where('status',1)->select()[$ad_index]['id'];
  109. $data['name_ad']= Db::table('dp_user_list')->where('role_id',1)->where('status',1)->select()[$ad_index]['name'];
  110. $data['hedai_id']= Db::table('dp_user_list')->where('role_id',0)->where('status',1)->select()[$hedai_index]['id'];
  111. $data['name_hedai']= Db::table('dp_user_list')->where('role_id',0)->where('status',1)->select()[$hedai_index]['name'];
  112. if ($data["name"] =='') {
  113. return $this->error('任务名称不能为空');
  114. }
  115. if ($data["money"] =='') {
  116. return $this->error('金额不能为空');
  117. }
  118. if ($data["begin_time"] =='') {
  119. return $this->error('投放时间不能为空');
  120. }
  121. if ($data["end_time"] =='') {
  122. return $this->error('投放时间不能为空');
  123. }
  124. if ($data["name_ad"] =='') {
  125. return $this->error('广告主不能为空');
  126. }
  127. if ($data["name_hedai"] =='') {
  128. return $this->error('核代不能为空');
  129. }
  130. $r = DB::table('dp_task_list')->insert($data);
  131. if ($r) {
  132. $this->success('新增成功', 'index');
  133. } else {
  134. $this->error('新增失败');
  135. }
  136. }
  137. // 广告主
  138. $name_ad_list = Db::table('dp_user_list')->where('role_id',1)->where('status',1)->column('name');
  139. // 核代
  140. $name_hedai_list = Db::table('dp_user_list')->where('role_id',0)->where('status',1)->column('name');
  141. return ZBuilder::make('form')
  142. ->addFormItems([ // 批量添加列
  143. ['text', 'name', '任务名称', '<span class="text-danger">必填</span>'],
  144. ['textarea', 'describe', '任务描述'],
  145. ['text', 'money', '金额', '<span class="text-danger">必填</span>'],
  146. ['select', 'name_ad', '广告主', '<span class="text-danger">必选</span>', $name_ad_list],
  147. ['select', 'name_hedai', '核代', '<span class="text-danger">必选</span>',$name_hedai_list],
  148. ['date', 'begin_time', '预计投放时间','<span class="text-danger">必选</span>'],
  149. ['date', 'end_time', '预计投放结束时间','<span class="text-danger">必选</span>'],
  150. ['date', 'payback_time', '预计回款时间'],
  151. ['text', 'money_back', '预计回款金额'],
  152. ['files', 'accessory_add', '上传附件'],
  153. ['flowdiagram','',"",'0'],
  154. ])
  155. ->fetch(); // 渲染页面
  156. }
  157. // --------------待付款页面
  158. public function edit($id = '')
  159. {
  160. $dataInfo = Db::table('dp_task_list')->where('id',$id)->find();
  161. // 用户id
  162. $uid = session('user_auth')['uid'];
  163. // 用户昵称
  164. $username = get_nickname($uid);
  165. if($dataInfo['payback_time']==0){
  166. $dataInfo['payback_time']='';
  167. }
  168. // 提交待付款保存数据
  169. if ($this->request->isPost()) {
  170. // 表单数据
  171. $data = $this->request->post();
  172. $r =Db::table('dp_task_list')
  173. ->where('id', $id)
  174. ->update([
  175. 'user_id_pay' => $uid,
  176. 'user_name_pay' => $username,
  177. 'status' => 1,
  178. 'accessory_pay'=>$data['accessory_pay']
  179. ]);
  180. if ($r) {
  181. $this->success('提交成功', 'index');
  182. } else {
  183. $this->error('提交失败');
  184. }
  185. }
  186. return ZBuilder::make('form')
  187. ->addFormItems([ // 批量添加列
  188. ['static', 'name', '任务名称'],
  189. ['static', 'describe', '任务描述'],
  190. ['static', 'money', '金额'],
  191. ['static', 'name_ad', '广告主'],
  192. ['static', 'name_hedai', '核代'],
  193. ['static', 'begin_time', '预计投放时间'],
  194. ['static', 'end_time', '预计投放结束时间'],
  195. ['static', 'payback_time', '预计回款时间'],
  196. ['static', 'money_back', '预计回款金额'],
  197. ['archives', 'accessory_add', '附件'],
  198. ['flowdiagram','',"",'1',"0"],
  199. ['hr'],
  200. ['files', 'accessory_pay', '付款附件'],
  201. ])
  202. ->setFormData($dataInfo)
  203. ->submitConfirm()
  204. ->setBtnTitle('submit', '确定付款')
  205. ->fetch(); // 渲染页面
  206. }
  207. //------------------- 付款验收页面
  208. public function info($id = '')
  209. {
  210. $dataInfo = Db::table('dp_task_list')->where('id',$id)->find();
  211. // 用户id
  212. $uid = session('user_auth')['uid'];
  213. // 用户昵称
  214. $username = get_nickname($uid);
  215. if($dataInfo['payback_time']==0){
  216. $dataInfo['payback_time']='';
  217. }
  218. // 提交验收保存数据
  219. if ($this->request->isPost()) {
  220. // 表单数据
  221. $data = $this->request->post();
  222. $r =Db::table('dp_task_list')
  223. ->where('id', $id)
  224. ->update([
  225. 'user_id_check' => $uid, //验收人id
  226. 'user_name_check' => $username, //验收人username
  227. 'status' => 2,
  228. 'accessory_check'=>$data['accessory_check']
  229. ]);
  230. if ($r) {
  231. $this->success('提交成功', 'index');
  232. } else {
  233. $this->error('提交失败');
  234. }
  235. }
  236. return ZBuilder::make('form')
  237. ->addFormItems([ // 批量添加列
  238. ['static', 'name', '任务名称'],
  239. ['static', 'describe', '任务描述'],
  240. ['static', 'money', '金额'],
  241. ['static', 'name_ad', '广告主'],
  242. ['static', 'name_hedai', '核代'],
  243. ['static', 'begin_time', '预计投放时间'],
  244. ['static', 'end_time', '预计投放结束时间'],
  245. ['static', 'payback_time', '预计回款时间'],
  246. ['static', 'money_back', '预计回款金额'],
  247. ['archives', 'accessory_add', '附件'],
  248. ['flowdiagram','',"",'1',"1","0"],
  249. ['hr'],
  250. ['archives', 'accessory_pay', '付款附件'],
  251. ['static', 'user_name_pay', '审核人'],
  252. ['static', 'content_check', '补充'],
  253. ['files', 'accessory_check', '验收付款附件'],
  254. ])
  255. ->setFormData($dataInfo)
  256. ->layout(['accessory_pay' => 4, 'user_name_pay' => 4,'content_check'=>4])
  257. ->submitConfirm()
  258. ->setBtnTitle('submit', '确定验收')
  259. ->fetch(); // 渲染页面
  260. }
  261. // -----------------------已完成页面
  262. public function check($id = '')
  263. {
  264. $dataInfo = Db::table('dp_task_list')->where('id',$id)->find();
  265. if($dataInfo['payback_time']==0){
  266. $dataInfo['payback_time']='';
  267. }
  268. return ZBuilder::make('form')
  269. ->addFormItems([ // 批量添加列
  270. ['static', 'name', '任务名称'],
  271. ['static', 'describe', '任务描述'],
  272. ['static', 'money', '金额'],
  273. ['static', 'name_ad', '广告主'],
  274. ['static', 'name_hedai', '核代'],
  275. ['static', 'begin_time', '预计投放时间'],
  276. ['static', 'end_time', '预计投放结束时间'],
  277. ['static', 'payback_time', '预计回款时间'],
  278. ['static', 'money_back', '预计回款金额'],
  279. ['archives', 'accessory_add', '附件'],
  280. ['flowdiagram','',"",'1',"1","1"],
  281. ['hr'],
  282. ['archives', 'accessory_pay', '付款附件'],
  283. ['static', 'user_name_pay', '审核人'],
  284. ['static', 'content_check', '补充'],
  285. ['archives', 'accessory_check', '已验收付款附件'],
  286. ['static', 'user_name_check', '审核人'],
  287. ])
  288. ->setFormData($dataInfo)
  289. ->layout(['accessory_pay' => 6, 'user_name_pay' => 3,'content_check'=>3])
  290. ->layout(['accessory_check' => 7, 'user_name_check' => 4])
  291. ->submitConfirm()
  292. ->hideBtn('submit')
  293. ->fetch(); // 渲染页面
  294. }
  295. //------------------- 补充
  296. public function supplement($id = '')
  297. {
  298. // $data_list = Db::table('dp_task_list')->where('id',$id)->value('content_check');
  299. $data_list = Db::table('dp_task_list')->where('id',$id)->find();
  300. // 提交验收保存数据
  301. if ($this->request->isPost()) {
  302. // 表单数据
  303. $data = $this->request->post();
  304. if($data['content_check']==''){
  305. return $this->error('补充信息不能为空');
  306. }
  307. $r =Db::table('dp_task_list')
  308. ->where('id', $id)
  309. ->update([
  310. 'content_check' => $data['content_check'], //验收补充内容
  311. ]);
  312. if ($r) {
  313. $this->success('提交成功', 'index');
  314. } else {
  315. $this->error('提交失败');
  316. }
  317. }
  318. return ZBuilder::make('form')
  319. ->addFormItems([ // 批量添加列
  320. ['textarea', 'content_check', '补充'],
  321. ])
  322. ->setFormData($data_list)
  323. ->fetch(); // 渲染页面
  324. }
  325. //导出
  326. public function export()
  327. {
  328. $map = $this->getMap();
  329. $data_list = DB::table('dp_task_list')->field(['id', 'name', 'time','name_ad','name_hedai','money','status'])->where($map)->select();
  330. // 转换状态值并保存在新字段中
  331. foreach ($data_list as &$data) {
  332. if ($data['status'] == 0) {
  333. $data['status_text'] = '待付款';
  334. } elseif ($data['status'] == 1) {
  335. $data['status_text'] = '已验收付款';
  336. }else{
  337. $data['status_text'] = '已完成';
  338. }
  339. }
  340. // 设置表头信息(对应字段名,宽度,显示表头名称)
  341. $cellName = [
  342. ['id', 10, '任务ID'],
  343. ['name', 10, '任务名称'],
  344. ['time', 10, '时间'],
  345. ['name_ad', 20, '广告主'],
  346. ['name_hedai', 20, '核代'],
  347. ['money', 20, '金额'],
  348. ['status_text', 20, '状态'],
  349. ];
  350. // 调用插件(传入插件名,[导出文件名、表头信息、具体数据])
  351. plugin_action('Excel/Excel/export', ['任务订单管理列表'.date('Y-m-d H:i:s'), $cellName, $data_list]);
  352. }
  353. }