OrderType.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class OrderType extends Base
  5. {
  6. protected $createTime = 'create_time';
  7. protected $updateTime = 'update_time';
  8. protected $table = 'order_type';
  9. protected $validateName = 'OrderType';
  10. public function updates(){
  11. $data = request()->post();
  12. $data['org_id'] = cur_org_id();
  13. $result = validate($this->validateName)->check($data,[],'');
  14. if(true !== $result){
  15. $this->error = validate($this->validateName)->getError();
  16. return false;
  17. }
  18. if($data['type']==1){
  19. if(empty($data['parent_id'])){
  20. $this->error = '请选择报修类型';
  21. return false;
  22. }
  23. }
  24. $id = $data['id'];
  25. unset($data['id']);
  26. unset($data['type']);
  27. if($id > 0){
  28. $data['update_time'] = date('Y-m-d H:i:s');
  29. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  30. }else{
  31. $data['create_time'] = date('Y-m-d H:i:s');
  32. $ret = $this->allowField(true)->save($data);
  33. }
  34. if(!$ret){
  35. $this->error = '操作失败';
  36. return false;
  37. }
  38. return true;
  39. }
  40. //获取报修类型
  41. public function list($orgId=0){
  42. if($orgId==0){
  43. $orgId = cur_org_id();
  44. }
  45. $list =$this
  46. ->where('parent_id',0)
  47. ->where('enable',1)
  48. ->where('del',0)
  49. ->where('org_id',$orgId)
  50. ->select()
  51. ->toArray();
  52. return $list;
  53. }
  54. //获取报修事项
  55. public function getList($orgId=0){
  56. if($orgId==0){
  57. $orgId = cur_org_id();
  58. }
  59. $list =$this
  60. ->where('parent_id','>',0)
  61. ->where('enable',1)
  62. ->where('del',0)
  63. ->where('org_id',$orgId)
  64. ->select()
  65. ->toArray();
  66. foreach ($list as $k=>$v){
  67. $parent_title = $this->getTableField('order_type',['id'=>$v['parent_id']],'title');
  68. $list[$k]['title'] ='['.$parent_title.']'.$v['title'];
  69. $list[$k]['count'] = Db::name('order_repair')->where('type_id',$v['id'])->count();
  70. }
  71. $list = list_sort_by($list,'count','desc');
  72. return $list;
  73. }
  74. //根据订单id获报修类型和地点
  75. public function getTypeByOrderId($orderId){
  76. $order_repair = Db::name('order_repair')
  77. ->where('order_id',$orderId)
  78. ->find();
  79. if($order_repair){
  80. $info = $this->where('id',$order_repair['type_id'])->find();
  81. $pInfo = $this->where('id',$info['parent_id'])->find();
  82. $addressTitle = Db::name('address')
  83. ->where('id',$order_repair['address_id'])
  84. ->find();
  85. $pInfo['address_title'] = $addressTitle['title'];
  86. $pInfo['child_title'] = $info['title'];
  87. $pInfo['type_id'] = $order_repair['type_id'];
  88. $pInfo['address_id'] = $order_repair['address_id'];
  89. $pInfo['repair_priority_index'] = $order_repair['repair_priority'];
  90. $pInfo['repair_priority'] = $order_repair['repair_priority']==1?'可延缓':($order_repair['repair_priority']==2?"普通":"紧急");
  91. return $pInfo;
  92. }
  93. return false;
  94. }
  95. }