WasteRecord.php 9.8 KB

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