WasteRecord.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\api\controller\Base;
  4. use app\hander\HelpHander;
  5. use think\App;
  6. use think\Db;
  7. class WasteRecord extends Base
  8. {
  9. public function __construct(App $app = null) {
  10. parent::__construct($app);
  11. $this->model = new \app\common\model\WasteRecord();
  12. }
  13. public function printRecord (){
  14. $id=input('id/d');
  15. db('waste_record')->where('id',$id)
  16. ->update(['is_print' =>1]);
  17. HelpHander::success([],'操作成功');
  18. }
  19. public function queryIsPrint(){
  20. $id=input('id/d');
  21. $ret=$this->model->queryIsPrint($id);
  22. if($ret){
  23. HelpHander::success($ret);
  24. }else{
  25. HelpHander::error('暂无数据');
  26. }
  27. }
  28. public function queryWasteRecordList(){
  29. $orgId=input('orgId/d');
  30. $status=input('status');
  31. $createTime=trim(input('createTime'));
  32. $page=input('page/d',1);
  33. $size=input('size/d',10);
  34. $ret=$this->model->wasteRecordList($orgId,$status,$createTime,$page,$size);
  35. if($ret){
  36. HelpHander::success($ret);
  37. }else{
  38. HelpHander::error('暂无数据');
  39. }
  40. }
  41. public function queryUnTransportList(){
  42. $orgId=input('orgId/d');
  43. $createTime=trim(input('createTime'));
  44. $ret=$this->model->unTransportList($orgId,$createTime);
  45. if($ret){
  46. HelpHander::success($ret);
  47. }else{
  48. HelpHander::error('暂无数据');
  49. }
  50. }
  51. // 保存医废记录
  52. public function saveRecord(){
  53. $data = [
  54. 'org_id' => input('orgId/d'),
  55. 'user_id' => $this->userId,
  56. 'waste_device_id' => input('wasteDeviceId'),
  57. 'cateid' =>input('cateId'),
  58. 'weight' => input('weight'),
  59. 'status' => 0,
  60. 'is_print' => 0
  61. ];
  62. if(!$data['waste_device_id']){
  63. HelpHander::error('未选择收取科室');
  64. }
  65. if(!$data['cateid']){
  66. HelpHander::error('类型不能为空');
  67. }
  68. if($data['weight'] <= 0){
  69. HelpHander::error('称重必须大于0');
  70. }
  71. $waste_record_id = $this->model->saverecord($data);
  72. if(!$waste_record_id){
  73. HelpHander::error($this->model->getError());
  74. }
  75. $info = $this->model->getOne($waste_record_id,$data['org_id']);
  76. if(!$info){
  77. HelpHander::error('操作失败');
  78. }
  79. $info['wasteDeviceName'] = Db::name('address')
  80. ->where('id',$info['waste_device_id'])
  81. ->value('title');
  82. $info['cateId']=$info['cateid'];
  83. $a = formatArray(['id','create_time',
  84. 'serial_number','wasteDeviceName','cateId','is_print'],$info);
  85. HelpHander::success($a,'操作成功');
  86. }
  87. public function save(){
  88. $json = [
  89. 'serialNumber'=>input('serialNumber'),
  90. 'weight2'=>input('weight2'),
  91. 'status'=>input('status'),
  92. 'reason'=>input('reason'),
  93. 'userId'=>$this->userId,
  94. ];
  95. if(!in_array($json['status'],[1,2,3])){
  96. HelpHander::error('参数错误');
  97. }
  98. $ret = $this->model->saveStatus($json);
  99. if($ret){
  100. HelpHander::success([],'操作成功');
  101. }else{
  102. HelpHander::error('操作失败'.$this->model->getError());
  103. }
  104. }
  105. public function detail(){
  106. $serialNum = input('serialNum');
  107. $orgId = $this->orgId;
  108. if(strlen($serialNum) == 14){ // 包编号
  109. $ret = $this->model->packInfo($serialNum,$orgId);
  110. }else{
  111. $ret = $this->model->recordInfo($serialNum,$orgId);
  112. }
  113. if($ret){
  114. HelpHander::success($ret,'操作成功');
  115. }else{
  116. HelpHander::error('操作失败');
  117. }
  118. }
  119. public function lists(){
  120. $depId = input('depId');
  121. $date = input('date');
  122. $orgId = $this->orgId;
  123. $page=input('page/d',1);
  124. $size=input('size/d',10);
  125. $ret=$this->model->lists($orgId,$depId,$date,$page,$size,$this->userId);
  126. HelpHander::success($ret);
  127. }
  128. public function sign(){
  129. $path = input('path');
  130. $wasterecordid = input('wasteRecordId');
  131. if(!$path || !$wasterecordid){
  132. HelpHander::error('参数错误');
  133. }
  134. $ids = explode(',',$wasterecordid);
  135. $succ = 0;
  136. foreach ($ids as $k=>$v){
  137. $info = $this->model->getOne($v,$this->orgId);
  138. if(!$info){
  139. HelpHander::error($v.'记录不存在');
  140. }
  141. if($info['sign'] == 1){
  142. continue;
  143. }
  144. $res = Db::name('waste_record')
  145. ->where('id',$v)
  146. ->update([
  147. 'sign' => 1,
  148. 'sign_path' => $path,
  149. 'sign_user_id' => $this->userId,
  150. 'sign_time' => getTime()
  151. ]);
  152. if($res){
  153. $succ++;
  154. }
  155. }
  156. if($succ==count($ids)){
  157. HelpHander::success('操作成功');
  158. }else{
  159. HelpHander::error('操作失败');
  160. }
  161. }
  162. // 保存医废打包
  163. public function savePackage(){
  164. $data = [
  165. 'org_id' =>$this->orgId,
  166. 'user_id' => $this->userId,
  167. 'ids' =>input('ids'),
  168. ];
  169. $ids = explode(',',$data['ids']);
  170. $nids = [];
  171. foreach ($ids as $k=>$v){
  172. if($v && !in_array($v,$nids)){
  173. $nids[] = $v;
  174. }
  175. }
  176. $data['ids'] = $nids;
  177. if(!$data['ids']){
  178. HelpHander::error('未选择医废记录');
  179. }
  180. $ret = $this->model->savePackage($data);
  181. if(!$ret){
  182. HelpHander::error($this->model->getError());
  183. }
  184. HelpHander::success(['id' => $ret],'操作成功');
  185. }
  186. // 可使用的打包医废记录
  187. public function yflist(){
  188. $ret=$this->model->yflist($this->orgId,$this->userId);
  189. HelpHander::success($ret);
  190. }
  191. // 删除包内医废记录
  192. public function delpackage(){
  193. $id = input('id'); // 包id
  194. $recordId = input('recordId'); // 记录id
  195. $ret=$this->model->delpackage($this->orgId,$this->userId,$id,$recordId);
  196. if(!$ret){
  197. HelpHander::error($this->model->getError());
  198. }
  199. HelpHander::success([],'操作成功');
  200. }
  201. // 交接包
  202. public function jjpackage(){
  203. $id = input('id');
  204. $ret=$this->model->jjpackage($this->orgId,$this->userId,$id);
  205. if(!$ret){
  206. HelpHander::error($this->model->getError());
  207. }
  208. HelpHander::success([],'操作成功');
  209. }
  210. // 转运包
  211. public function zypackage(){
  212. $id = input('id');
  213. $ret=$this->model->zypackage($this->orgId,$this->userId,$id);
  214. if(!$ret){
  215. HelpHander::error($this->model->getError());
  216. }
  217. HelpHander::success([],'操作成功');
  218. }
  219. public function packages(){
  220. $page = input('page',1);
  221. $size = input('size',10);
  222. $ret=$this->model->packagesLists($this->orgId,$page,$size,$this->userId);
  223. HelpHander::success($ret);
  224. }
  225. }