FCleanPlanRecord.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\Db;
  5. use think\Exception;
  6. class FCleanPlanRecord extends Auth
  7. {
  8. public function __construct(App $app = null) {
  9. parent::__construct($app);
  10. $this->model= new \app\common\model\FCleanPlanRecord();
  11. $this->table= $this->model->table;
  12. }
  13. public function index($id=0){
  14. if(request()->isAjax()){
  15. //分页参数
  16. $length = input('rows',10,'intval'); //每页条数
  17. $page = input('page',1,'intval'); //第几页
  18. $start = ($page - 1) * $length; //分页开始位置
  19. //排序
  20. $sortRow = input('sidx','id','trim'); //排序列
  21. $sort = input('sord','desc','trim'); //排序方式
  22. $order = $sortRow.' '.$sort;
  23. $title = input('title','','trim');
  24. if($title){
  25. $map[] = ['title','like','%'.$title.'%'];
  26. }
  27. $enable = input('enable','','trim');
  28. if($enable != ''){
  29. $map[] = ['enable','=',$enable];
  30. }
  31. $formId = input('formId','','trim');
  32. if($formId != ''){
  33. $map[] = ['form_id','=',$formId];
  34. }
  35. $addrId = input('addrId','','trim');
  36. if($addrId != ''){
  37. $map[] = ['address_id','=',$addrId];
  38. }
  39. $map[] = ['del','=',0];
  40. $map[] = ['org_id','=',$this->orgId];
  41. $map[] = ['plan_id','=',$id];
  42. $map= empty($map) ? true: $map;
  43. //数据查询
  44. $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
  45. foreach ($lists as $k=>$v){
  46. $ftitle = Db::name('f_clean_type')->where('id',$v['form_id'])->value('title');
  47. $atitle = Db::name('address')->where('id','in',explode(',',$v['address_id']))->select();
  48. $lists[$k]['form_title'] = $ftitle;
  49. $lists[$k]['addr_title'] = $atitle?implode(',',array_column($atitle,'title')):"";
  50. }
  51. //数据返回
  52. $totalCount = db($this->table)->where($map)->count();
  53. $totalPage = ceil($totalCount/$length);
  54. $result['page'] = $page;
  55. $result['total'] = $totalPage;
  56. $result['records'] = $totalCount;
  57. $result['rows'] = $lists;
  58. return json($result);
  59. }else{
  60. $pinfo = Db::name('f_clean_plan')->where('id',$id)->find();
  61. $this->assign('pinfo',$pinfo);
  62. $ptitle = Db::name('f_clean_plan')->where('id',$pinfo['pid'])->value('title');
  63. $this->assign('m_name','['.$ptitle.']'.$pinfo['month'].'日计划');
  64. $forms = $pinfo['forms']?explode(',',$pinfo['forms']):[];
  65. $addrs = $pinfo['addrs']?explode(',',$pinfo['addrs']):[];
  66. $typs = (new \app\common\model\CleanType())->getList();
  67. $address = (new \app\common\model\Address())->getListByType(8);
  68. foreach ($typs as $k=>$v){
  69. if(!in_array($v['id'],$forms)){
  70. unset($typs[$k]);
  71. }
  72. }
  73. foreach ($address as $k=>$v){
  74. if(!in_array($v['id'],$addrs)){
  75. unset($address[$k]);
  76. }
  77. }
  78. $this->assign('type',$typs?$typs:[]);
  79. $this->assign('address',$address?$address:[]);
  80. return $this->fetch();
  81. }
  82. }
  83. /**
  84. * 新增
  85. */
  86. public function add($id=0,$plan_id=0){
  87. if(request()->isPost()){
  88. $res = $this->model->addSave();
  89. if($res){
  90. $this->success('操作成功',url('index'));
  91. }else{
  92. $this->error($this->model->getError());
  93. }
  94. }else{
  95. $pinfo = Db::name('f_clean_plan')->where('id',$plan_id)->find();
  96. if($id > 0){
  97. $info = Db::name($this->table)->where('id',$id)->find();
  98. if($info){
  99. $plan_id = $info['plan_id'];
  100. }
  101. }else{
  102. $info['start'] = $pinfo['month'].'-01';
  103. $info['end'] = $pinfo['month'].'-01';
  104. }
  105. $this->assign('info',$info);
  106. $this->assign('plan_id',$plan_id);
  107. $forms = $pinfo['forms']?explode(',',$pinfo['forms']):[];
  108. $addrs = $pinfo['addrs']?explode(',',$pinfo['addrs']):[];
  109. $uids = $pinfo['user']?explode(',',$pinfo['user']):[];
  110. $typs = (new \app\common\model\FCleanType())->getList();
  111. $address = (new \app\common\model\Address())->getListByType(8);
  112. foreach ($typs as $k=>$v){
  113. if(!in_array($v['id'],$forms)){
  114. unset($typs[$k]);
  115. }
  116. }
  117. foreach ($address as $k=>$v){
  118. if(!in_array($v['id'],$addrs)){
  119. unset($address[$k]);
  120. }
  121. }
  122. $users = (new \app\common\model\User())->getCleanWorker();
  123. $nuser = [];
  124. foreach ($users as $k=>$v){
  125. if(in_array($v['id'],$uids)){
  126. $nuser[] = $v;
  127. }
  128. }
  129. $this->assign('user',$nuser);
  130. $this->assign('type',$typs?$typs:[]);
  131. $this->assign('address',$address?$address:[]);
  132. return $this->fetch();
  133. }
  134. }
  135. /**
  136. * 新增
  137. */
  138. public function edit($id=0){
  139. if(request()->isPost()){
  140. $res = $this->model->editSave();
  141. if($res){
  142. $this->success('操作成功',url('index'));
  143. }else{
  144. $this->error($this->model->getError());
  145. }
  146. }else{
  147. if($id > 0){
  148. $info = Db::name($this->table)->where('id',$id)->find();
  149. if($info){
  150. $plan_id = $info['plan_id'];
  151. $uids = Db::name('f_clean_plan_user')->where('record_id',$info['id'])->column('user_id');
  152. $info['user'] = $uids?$uids:[];
  153. $info['address_id'] = $info['address_id']?explode(',',$info['address_id']):[];
  154. }
  155. $this->assign('info',$info);
  156. }
  157. $this->assign('plan_id',$plan_id);
  158. $pinfo = Db::name('f_clean_plan')->where('id',$plan_id)->find();
  159. $forms = $pinfo['forms']?explode(',',$pinfo['forms']):[];
  160. $addrs = $pinfo['addrs']?explode(',',$pinfo['addrs']):[];
  161. $uids = $pinfo['user']?explode(',',$pinfo['user']):[];
  162. $typs = (new \app\common\model\FCleanType())->getList();
  163. $address = (new \app\common\model\Address())->getListByType(8);
  164. foreach ($typs as $k=>$v){
  165. if(!in_array($v['id'],$forms)){
  166. unset($typs[$k]);
  167. }
  168. }
  169. foreach ($address as $k=>$v){
  170. if(!in_array($v['id'],$addrs)){
  171. unset($address[$k]);
  172. }
  173. }
  174. $users = (new \app\common\model\User())->getCleanWorker();
  175. $nuser = [];
  176. foreach ($users as $k=>$v){
  177. if(in_array($v['id'],$uids)){
  178. $nuser[] = $v;
  179. }
  180. }
  181. $this->assign('user',$nuser);
  182. $this->assign('type',$typs?$typs:[]);
  183. $this->assign('address',$address?$address:[]);
  184. return $this->fetch();
  185. }
  186. }
  187. /**
  188. * 删除记录
  189. * @param int $id
  190. */
  191. public function del($id=0){
  192. if(!$id){
  193. $this->error('参数错误');
  194. }
  195. $res = db($this->table)->where('id',$id)->setField('del',1);
  196. if($res){
  197. $this->success('删除成功');
  198. }else{
  199. $this->error('删除失败');
  200. }
  201. }
  202. /**
  203. * 改变字段值
  204. * @param int $fv
  205. * @param string $fn
  206. * @param int $fv
  207. */
  208. public function changeField($id=0,$fn='',$fv=0){
  209. if(!$fn||!$id){
  210. $this->error('参数错误');
  211. }
  212. $res = db($this->table)->where('id',$id)->setField($fn,$fv);
  213. if($res){
  214. $this->success('操作成功');
  215. }else{
  216. $this->error('操作失败');
  217. }
  218. }
  219. public function calendar(){
  220. $m = input('month','');
  221. $curMonth = input('month',date('Y-m'));
  222. $this->assign('curMonth',$curMonth);
  223. $back = 0;
  224. $year = '';
  225. if($m){
  226. $back = 1;
  227. list($year,$y1) = explode('-',$m);
  228. }
  229. $this->assign('back',$back);
  230. $this->assign('year',$year);
  231. return $this->fetch();
  232. }
  233. public function calendardata(){
  234. $start = input('start');
  235. $end = input('end');
  236. $data = array();
  237. if(!$start||!$end||$start>$end){
  238. header('Content-Type:application/json; charset=utf-8');
  239. exit(json_encode($data));
  240. }
  241. $start = date('Y-m-d H:i:s',strtotime($start));
  242. $end = date('Y-m-d H:i:s',strtotime($end));
  243. $map[] = [''];
  244. $list = (new \app\common\model\FCleanPlanRecord())->get_list_by_time($this->orgId,$start,$end);
  245. foreach ($list as $k=>$v){
  246. $arr = array(
  247. 'taskid' => $v['id'],
  248. 'title' => "任务项:{$v['ftitle']}<br>地点:{$v['atitle']}<br>开始时间:{$v['start']}<br>结束时间:{$v['end']}<br>",
  249. 'status' => $v['enable'],
  250. 'start' => $v['start'].' 00:00:00',
  251. 'end' => $v['end'].' 23:59:59'
  252. );
  253. if($v['enable'] == 0){
  254. $arr['color'] = '#478fca';
  255. }else{
  256. $arr['color'] = '#69aa46';
  257. }
  258. // if($v['status'] == 0){
  259. // $arr['color'] = '#777777';
  260. // }else if($v['status'] == 1){
  261. // $arr['color'] = '#478fca';
  262. // }else if($v['status'] == 2){
  263. // $arr['color'] = '#69aa46';
  264. // }else if($v['status'] == 3){
  265. // $arr['color'] = '#dd5a43';
  266. // }else if($v['status'] == 5){
  267. // $arr['color'] = '#53a2a7';
  268. // }else{
  269. // $arr['color'] = '#5b53a7';
  270. // }
  271. $data[] = $arr;
  272. }
  273. header('Content-Type:application/json; charset=utf-8');
  274. exit(json_encode($data));
  275. }
  276. public function year(){
  277. $year = input('year',date('Y'));
  278. $month = [];
  279. for ($i=1;$i<=12;$i++){
  280. if($i>10){
  281. $a = $i;
  282. }else{
  283. $a='0'.$i;
  284. }
  285. $month[] = $year.'-'.$a;
  286. }
  287. $list = [];
  288. foreach ($month as $k=>$v){
  289. $c = $c1 = $c2 = 0;
  290. $plan =Db::name('f_clean_plan')
  291. ->where('del',0)
  292. ->where('enable',1)
  293. ->where('org_id',$this->orgId)
  294. ->where('month',$v)
  295. ->find();
  296. if($plan){
  297. $c = Db::name('f_clean_plan_record')
  298. ->where('plan_id',$plan['id'])
  299. ->where('del',0)->count();
  300. $c1 = Db::name('f_clean_plan_record')
  301. ->where('plan_id',$plan['id'])
  302. ->where('del',0)
  303. ->where('enable',0)
  304. ->count();
  305. $c2 = Db::name('f_clean_plan_record')
  306. ->where('plan_id',$plan['id'])
  307. ->where('del',0)
  308. ->where('enable',1)
  309. ->count();
  310. }
  311. $list[] = [
  312. 'title'=>$v,
  313. 'count'=>$c,
  314. 'count1'=>$c1,
  315. 'count2'=>$c2,
  316. ];
  317. }
  318. $this->assign('lists',$list);
  319. $this->assign('last',$year+1);
  320. $this->assign('prv',$year-1);
  321. return $this->fetch();
  322. }
  323. public function detail($id = 0){
  324. $info = $this->model->detail($id,$this->orgId);
  325. if($info){
  326. $info['imgs'] = $info['imgs']?explode(',',$info['imgs']):[];
  327. }
  328. $this->assign('info',$info);
  329. return $this->fetch();
  330. }
  331. public function rindex(){
  332. if(request()->isAjax()){
  333. //分页参数
  334. $length = input('rows',10,'intval'); //每页条数
  335. $page = input('page',1,'intval'); //第几页
  336. $start = ($page - 1) * $length; //分页开始位置
  337. //排序
  338. $sortRow = input('sidx','id','trim'); //排序列
  339. $sort = input('sord','desc','trim'); //排序方式
  340. $order = $sortRow.' '.$sort;
  341. $title = input('title','','trim');
  342. if($title){
  343. $map[] = ['title','like','%'.$title.'%'];
  344. }
  345. $enable = input('enable','','trim');
  346. if($enable != ''){
  347. $map[] = ['enable','=',$enable];
  348. }
  349. $formId = input('formId','','trim');
  350. if($formId != ''){
  351. $map[] = ['form_id','=',$formId];
  352. }
  353. $addrId = input('addrId','','trim');
  354. if($addrId != ''){
  355. $map[] = ['address_id','=',$addrId];
  356. }
  357. $map[] = ['del','=',0];
  358. $map[] = ['org_id','=',$this->orgId];
  359. $map= empty($map) ? true: $map;
  360. //数据查询
  361. $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
  362. foreach ($lists as $k=>$v){
  363. $ftitle = Db::name('f_clean_type')->where('id',$v['form_id'])->value('title');
  364. $atitle = Db::name('address')->where('id','in',explode(',',$v['address_id']))->select();
  365. $lists[$k]['form_title'] = $ftitle;
  366. $lists[$k]['addr_title'] = $atitle?implode(',',array_column($atitle,'title')):"";
  367. }
  368. //数据返回
  369. $totalCount = db($this->table)->where($map)->count();
  370. $totalPage = ceil($totalCount/$length);
  371. $result['page'] = $page;
  372. $result['total'] = $totalPage;
  373. $result['records'] = $totalCount;
  374. $result['rows'] = $lists;
  375. return json($result);
  376. }else{
  377. $typs = (new \app\common\model\CleanType())->getList();
  378. $address = (new \app\common\model\Address())->getListByType(8);
  379. $this->assign('type',$typs?$typs:[]);
  380. $this->assign('address',$address?$address:[]);
  381. return $this->fetch();
  382. }
  383. }
  384. }