Ccjc.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace app\api\model;
  3. use think\Model;
  4. /**
  5. * Created by PhpStorm
  6. * Author: ihavoc
  7. * Date: 2020/11/22
  8. * Time: 16:24
  9. *
  10. */
  11. class Ccjc extends model{
  12. protected $table = 't_ccjc';
  13. protected $pk = 'id';
  14. function undertake()
  15. {
  16. return $this->hasMany('undertake', 'task_id', 'id');
  17. }
  18. function orgs()
  19. {
  20. return $this->hasOne('orgs', 'task_id', 'id');
  21. }
  22. public function selectCcjcAndOrgsData($task_uid,$task_class='例行监测',$pageNum=1,$pageSize=10)
  23. {
  24. $ccjc = new Ccjc();
  25. return $ccjc->where([['task_class', '=', $task_class],])->with([
  26. 'orgs'=>function ($query) use ($task_uid){
  27. $query->where('unit_id',$task_uid);
  28. }
  29. ])->page((int)$pageNum,(int)$pageSize)->select();
  30. }
  31. public function selectUndertakeData($task_class,$where, $pageNum, $pageSize)
  32. {
  33. $result = Ccjc::hasWhere('undertake', function ($query) use ($where){
  34. $query->where($where);
  35. })->where('task_class','=',$task_class)->select();
  36. return $result;
  37. }
  38. public function countUndertakeData($task_class,$where)
  39. {
  40. $Ccjc = new Ccjc();
  41. return $Ccjc->where('task_class','=',$task_class)
  42. ->with([
  43. 'undertake'=> function ($query) use ($where){
  44. $query->where($where);
  45. }
  46. ])->count();
  47. }
  48. //查询任务列表数据
  49. public function getInfoByTaskClass($where,$pageNum=1,$pageSize=10)
  50. {
  51. return $this->where($where)->page($pageNum,$pageSize)->select();
  52. }
  53. public function getInfoListCount($where='')
  54. {
  55. return $this->where($where)->select()->count();
  56. }
  57. //删除任务
  58. public function deleteTaskByID($id)
  59. {
  60. if (empty($id)) {
  61. return false;
  62. }
  63. return $this->select($id)->delete();
  64. }
  65. //根据id查询任务发布者releaser
  66. public function getReleaserById($id)
  67. {
  68. return $this->select($id)->column('releaser');
  69. }
  70. //添加任务 返回添加数据的主键id
  71. public function createTask($data)
  72. {
  73. return $this->insertGetId($data);
  74. }
  75. public function getTaskInfoByTaskID($task_id)
  76. {
  77. return $this->where('id','=',$task_id)->find();
  78. }
  79. public function updateInfoByTaskID($task_id, $data)
  80. {
  81. return $this->where('id', '=', $task_id)->save($data);
  82. }
  83. /**
  84. * 更新任务状态
  85. * @param $arr_condition:['id'=>1,'task_name'=>'更改的名称','isPublish'=>'2']
  86. * @return false|\think\Collection
  87. * @throws \Exception
  88. */
  89. public function updateTaskByArrCondition($arr_condition)
  90. {
  91. if (empty($arr_condition)) {
  92. return false;
  93. }
  94. $result = $this->saveAll($arr_condition);
  95. return $result;
  96. }
  97. }