ConveyCate.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class ConveyCate extends Base
  5. {
  6. public $cate = [
  7. 1=>"病人",
  8. 2=>"普通",
  9. 3=>"限时",
  10. 4=>"预约",
  11. 5=>"药品"
  12. ];
  13. public $priority = [
  14. 1=>"可延缓的",
  15. 2=>"常规",
  16. 3=>"紧急",
  17. 4=>"预约"
  18. ];
  19. protected $createTime = 'create_time';
  20. protected $updateTime = 'update_time';
  21. public $table = 'convey_cate';
  22. protected $validateName = 'ConveyCate';
  23. public function updates(){
  24. $data = request()->post();
  25. $data['org_id'] =cur_org_id();
  26. $result = validate($this->validateName)->check($data,[],'');
  27. if(true !== $result){
  28. $this->error = validate($this->validateName)->getError();
  29. return false;
  30. }
  31. $id = $data['id'];
  32. unset($data['id']);
  33. if($id > 0){
  34. $data['update_time'] = date('Y-m-d H:i:s');
  35. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  36. }else{
  37. $data['create_time'] = date('Y-m-d H:i:s');
  38. $ret = $this->allowField(true)->save($data);
  39. }
  40. if(!$ret){
  41. $this->error = '操作失败';
  42. return false;
  43. }
  44. return true;
  45. }
  46. public function getList($orgId=0){
  47. if($orgId==0){
  48. $orgId = cur_org_id();
  49. }
  50. $list = $this
  51. ->where('org_id',$orgId)
  52. ->where('enable',1)
  53. ->where('del',0)
  54. ->select();
  55. foreach ($list as $k=>$v){
  56. if($v['time_id'] > 0){
  57. $time = Db::name('time')
  58. ->where('id',$v['time_id'])
  59. ->find();
  60. $list[$k]['xq_time'] = date('Y-m-d H:i');
  61. $list[$k]['ywc_time'] = date('Y-m-d H:i',time() + 60*$time['bz_time']);
  62. }else{
  63. $list[$k]['xq_time'] = date('Y-m-d H:i');
  64. $list[$k]['ywc_time'] = '';
  65. }
  66. $ends = $v['ends']?explode(',',$v['ends']):[];
  67. $starts = $v['starts']?explode(',',$v['starts']):[];
  68. $list[$k]['endList'] = $ends;
  69. $list[$k]['startList'] = $starts;
  70. $list[$k]['ends'] = 0;
  71. $list[$k]['starts'] = 0;
  72. if(count($ends) == 1){
  73. $list[$k]['ends'] = $ends[0];
  74. }
  75. if(count($starts) == 1){
  76. $list[$k]['starts'] = $starts[0];
  77. }
  78. }
  79. $list = model("UserConveyCate")->sortUserCates($list,is_login());
  80. return $list;
  81. }
  82. public function getList1($orgId=0){
  83. if($orgId==0){
  84. $orgId = cur_org_id();
  85. }
  86. $list = $this
  87. ->where('org_id',$orgId)
  88. ->where('enable',1)
  89. ->where('del',0)
  90. ->select();
  91. foreach ($list as $k=>$v){
  92. if($v['time_id'] > 0){
  93. $time = Db::name('time')
  94. ->where('id',$v['time_id'])
  95. ->find();
  96. $list[$k]['xq_time'] = date('Y-m-d H:i');
  97. $list[$k]['ywc_time'] = date('Y-m-d H:i',time() + 60*$time['bz_time']);
  98. }else{
  99. $list[$k]['xq_time'] = date('Y-m-d H:i');
  100. $list[$k]['ywc_time'] = '';
  101. }
  102. $ends = $v['ends']?explode(',',$v['ends']):[];
  103. if($ends && count($ends)==1){
  104. $list[$k]['ends'] = Db::name('address')
  105. ->where('id','in',$ends)
  106. ->field('id,title')
  107. ->select();
  108. }else{
  109. $list[$k]['ends'] = [];
  110. }
  111. $list[$k]['priorityName'] = $this->priority[$v['priority']];
  112. }
  113. return $list;
  114. }
  115. public function getInfo($id){
  116. $v = $this
  117. ->where('id',$id)
  118. ->where('enable',1)
  119. ->where('del',0)
  120. ->find();
  121. $v = $v->toArray()?$v:[];
  122. if($v['time_id'] > 0){
  123. $time = Db::name('time')
  124. ->where('id',$v['time_id'])
  125. ->find();
  126. $v['xq_time'] = date('Y-m-d H:i');
  127. $v['ywc_time'] = date('Y-m-d H:i',time() + 60*$time['bz_time']);
  128. }else{
  129. $v['xq_time'] = date('Y-m-d H:i');
  130. $v['ywc_time'] = '';
  131. }
  132. $ends = $v['ends']?explode(',',$v['ends']):[];
  133. if($ends && count($ends)==1){
  134. $v['ends'] = Db::name('address')
  135. ->where('id','in',$ends)
  136. ->field('id,title')
  137. ->select();
  138. }else{
  139. $v['ends'] = null;
  140. }
  141. $v['priorityName'] = $this->priority[$v['priority']];
  142. return $v;
  143. }
  144. }