Workorder_model.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * 工单模型
  4. */
  5. class Workorder_model extends CI_Model {
  6. private $collection_name = 'workorder';
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. }
  11. public function get_workorder_with_id($id){
  12. return $this->mongo_db->where(array("workorder_id"=> $id))->find_one($this->collection_name);
  13. }
  14. public function aggregate($begin_datetime,$end_datetime,$group,$project=NULL,$where=NULL,$limit=NULL,$offset=NULL,$order = NULL){
  15. return $this->mongo_db->where_between("create_time",$begin_datetime,$end_datetime)->where($where)->order_by($order)->limit($limit)->offset($offset)->aggregate($this->collection_name,$group,$project);
  16. }
  17. public function filter_finished_workorder($now){
  18. return $this->mongo_db->set_wheres(array('status' => "50", 'end_time' => array('$lt'=>$now)))->set("status","60")->update_all($this->collection_name);
  19. }
  20. public function list_workorder($limit,$offset,$like = NULL,$where = NULL,$order = NULL){
  21. if(!$order){
  22. $order = array("create_time"=>"DESC");
  23. }
  24. if($like && $where){
  25. if(is_array($where) && array_key_exists("type",$where)) {
  26. $where['type']=$this->mongo_db->create_like($where['type']);
  27. $where_or = array(
  28. 'workorder_name'=>$this->mongo_db->create_like($like),
  29. 'workorder_id'=>$this->mongo_db->create_like($like),
  30. 'remark_list.remark_content'=>$this->mongo_db->create_like($like)
  31. );
  32. }else{
  33. $where_or = array(
  34. 'workorder_name'=>$this->mongo_db->create_like($like),
  35. 'workorder_id'=>$this->mongo_db->create_like($like),
  36. 'remark_list.remark_content'=>$this->mongo_db->create_like($like)
  37. );
  38. }
  39. return $this->mongo_db->where_or($where_or)->where($where)->order_by($order)->limit($limit)->offset($offset)->get($this->collection_name);
  40. }else if($like && !$where){
  41. $where_or = array('workorder_name'=>$this->mongo_db->create_like($like),'workorder_id'=>$this->mongo_db->create_like($like),'remark_list.remark_content'=>$this->mongo_db->create_like($like));
  42. return $this->mongo_db->where_or($where_or)->order_by($order)->limit($limit)->offset($offset)->get($this->collection_name);
  43. }else if(!$like && $where){
  44. if(is_array($where) && array_key_exists("type",$where)){
  45. $where['type'] = $this->mongo_db->create_like($where['type']);
  46. return $this->mongo_db->where($where)->order_by($order)->limit($limit)->offset($offset)->get($this->collection_name);
  47. }else{
  48. return $this->mongo_db->where($where)->order_by($order)->limit($limit)->offset($offset)->get($this->collection_name);
  49. }
  50. }else{
  51. return $this->mongo_db->order_by($order)->limit($limit)->offset($offset)->get($this->collection_name);
  52. }
  53. }
  54. /**
  55. * 获取数据条数
  56. */
  57. public function count_workorder($like = NULL,$where = NULL){
  58. if($like && $where){
  59. if(is_array($where) && array_key_exists("type",$where)) {
  60. $type = $where['type'];
  61. unset($where['type']);
  62. $where_or = array('workorder_name'=>$this->mongo_db->create_like($like),'workorder_id'=>$this->mongo_db->create_like($like),'remark_content'=>$this->mongo_db->create_like($like),'remark_list.remark_content'=>$this->mongo_db->create_like($like),'type'=>$this->mongo_db->create_like($type));
  63. }else{
  64. $where_or = array('workorder_name'=>$this->mongo_db->create_like($like),'workorder_id'=>$this->mongo_db->create_like($like),'remark_content'=>$this->mongo_db->create_like($like),'remark_list.remark_content'=>$this->mongo_db->create_like($like));
  65. }
  66. return $this->mongo_db->where_or($where_or)->where($where)->count($this->collection_name);
  67. }else if($like && !$where){
  68. $where_or = array('workorder_name'=>$this->mongo_db->create_like($like),'workorder_id'=>$this->mongo_db->create_like($like),'remark_content'=>$this->mongo_db->create_like($like),'remark_list.remark_content'=>$this->mongo_db->create_like($like));
  69. return $this->mongo_db->where_or($where_or)->count($this->collection_name);
  70. }else if(!$like && $where){
  71. if(is_array($where) && array_key_exists("type",$where)) {
  72. $where['type'] = $this->mongo_db->create_like($where['type']);
  73. return $this->mongo_db->where($where)->count($this->collection_name);
  74. }else{
  75. return $this->mongo_db->where($where)->count($this->collection_name);
  76. }
  77. }else{
  78. return $this->mongo_db->count($this->collection_name);
  79. }
  80. }
  81. /**
  82. *新增工单
  83. */
  84. public function insert_workorder($workorder_data){
  85. return $this->mongo_db->insert($this->collection_name, $workorder_data);
  86. }
  87. /**
  88. *更新工单
  89. */
  90. public function update_workorder($workorder_data){
  91. $data['filter'] = array("workorder_id"=>$workorder_data['workorder_id']);
  92. $data['update'] = $workorder_data;
  93. return $this->mongo_db->update($this->collection_name,$data);
  94. }
  95. /**
  96. * 删除工单
  97. */
  98. public function delete_workorder($id){
  99. return $this->mongo_db->where(array("workorder_id"=>$id))->delete($this->collection_name);
  100. }
  101. /**
  102. * 删除多个工单
  103. */
  104. public function delete_all_workorder($ids){
  105. return $this->mongo_db->where_in("workorder_id",$ids)->delete_all($this->collection_name);
  106. }
  107. }