Ccjc.php 3.1 KB

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