0
0

WashingRecord.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. use think\Exception;
  5. class WashingRecord extends Base
  6. {
  7. public function addSave($post){
  8. $data = [
  9. 'create_time'=>date('Y-m-d H:i:s'),
  10. 'create_yyyy'=>date('Y'),
  11. 'create_yyyymm'=>date('Ym'),
  12. 'create_yyyymmdd'=>date('Ymd'),
  13. ];
  14. $items =$post['items'];
  15. unset($post['items']);
  16. $data = array_merge($data,$post);
  17. $this->startTrans();
  18. try{
  19. $recordId = $this->insertGetId($data);
  20. if(intval($recordId) <=0){
  21. exception('添加记录失败');
  22. }
  23. foreach ($items as $k=>$v){
  24. $items[$k]['create_time'] =date('Y-m-d H:i:s');
  25. $items[$k]['washing_record_id'] =$recordId;
  26. }
  27. $res = Db::name('washing_record_item')->insertAll($items);
  28. if (!$res) {
  29. \exception('保存物品失败');
  30. }
  31. $data['id'] = $recordId;
  32. $this->commit();
  33. return true;
  34. }catch (Exception $e){
  35. $this->rollback();
  36. $this->error = $e->getMessage();
  37. return false;
  38. }
  39. }
  40. public function returnWash($id,$orgId){
  41. $ret = $this->where('id',$id)
  42. ->where('mode',1)
  43. ->where('org_id',$orgId)
  44. ->find();
  45. if(!$ret){
  46. $this->error='记录不存在,或当前状态已归还';
  47. return false;
  48. }
  49. $res = $this->where('id',$id)->update(
  50. ['mode'=>2,'return_time'=>date('Y-m-d H:i:s')]);
  51. return $res;
  52. }
  53. public function confirmWash($id,$orgId,$sign='',$img=''){
  54. $ret = $this->where('id',$id)
  55. ->where('mode',2)
  56. ->where('org_id',$orgId)
  57. ->find();
  58. if(!$ret){
  59. $this->error='记录不存在,或当前状态不可确认';
  60. return false;
  61. }
  62. $res = $this->where('id',$id)->update(
  63. ['mode'=>3,'confirm_time'=>date('Y-m-d H:i:s'),'sign'=>$sign,'img'=>$img]);
  64. return $res;
  65. }
  66. public function getApiList($page,$size,$type,$userId,$orgId){
  67. $offset =($page-1)*$size;
  68. $data = $this
  69. ->alias('a')
  70. ->join('address b','a.dep_id=b.id')
  71. ->field('a.id,a.create_time,a.return_time,a.confirm_time,b.title,a.mode as mode')
  72. ->where('a.mode',$type)
  73. ->where('a.user_id',$userId)
  74. ->where('a.org_id',$orgId)
  75. ->where('a.del',0)
  76. ->limit($offset,$size)
  77. ->select();
  78. $data = $data?$data->toArray():[];
  79. foreach ($data as $k=>$v){
  80. $data[$k]['return_time'] = $v['return_time']?$v['return_time']:'';
  81. $data[$k]['confirm_time'] = $v['confirm_time']?$v['confirm_time']:'';
  82. }
  83. return $data;
  84. }
  85. }