123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- <?php
- namespace app\api\controller\v1;
- use app\api\controller\Base;
- use app\common\model\User;
- use app\hander\HelpHander;
- use think\App;
- use think\Db;
- class WasteRecord extends Base
- {
- public function __construct(App $app = null) {
- parent::__construct($app);
- $this->model = new \app\common\model\WasteRecord();
- }
- public function printRecord (){
- $id=input('id/d');
- db('waste_record')->where('id',$id)
- ->update(['is_print' =>1]);
- HelpHander::success([],'操作成功');
- }
- public function queryIsPrint(){
- $id=input('id/d');
- $ret=$this->model->queryIsPrint($id);
- if($ret){
- HelpHander::success($ret);
- }else{
- HelpHander::error('暂无数据');
- }
- }
- public function queryWasteRecordList(){
- $orgId=input('orgId/d');
- $status=input('status');
- $createTime=trim(input('createTime'));
- $page=input('page/d',1);
- $size=input('size/d',10);
- $ret=$this->model->wasteRecordList($orgId,$status,$createTime,$page,$size);
- if($ret){
- HelpHander::success($ret);
- }else{
- HelpHander::error('暂无数据');
- }
- }
- public function queryUnTransportList(){
- $orgId=input('orgId/d');
- $createTime=trim(input('createTime'));
- $ret=$this->model->unTransportList($orgId,$createTime);
- if($ret){
- HelpHander::success($ret);
- }else{
- HelpHander::error('暂无数据');
- }
- }
- // 保存医废记录
- public function saveRecord(){
- $data = [
- 'org_id' => input('orgId/d'),
- 'user_id' => $this->userId,
- 'waste_device_id' => input('wasteDeviceId'),
- 'cateid' =>input('cateId'),
- 'weight' => input('weight'),
- 'status' => 0,
- 'is_print' => 0,
- 'num'=>input('num')
- ];
- if(!$data['waste_device_id']){
- HelpHander::error('未选择收取科室');
- }
- if(!$data['cateid']){
- HelpHander::error('类型不能为空');
- }
- if($data['weight'] <= 0){
- HelpHander::error('称重必须大于0');
- }
- $waste_record_id = $this->model->saverecord($data);
- if(!$waste_record_id){
- HelpHander::error($this->model->getError());
- }
- $info = $this->model->getOne($waste_record_id,$data['org_id']);
- if(!$info){
- HelpHander::error('操作失败');
- }
- $info['unit'] = Db::name('waste_type')->where('id',$info['cateid'])->value('unit');
- $info['wasteDeviceName'] = Db::name('address')
- ->where('id',$info['waste_device_id'])
- ->value('title');
- $info['cateId']=$info['cateid'];
- $a = formatArray(['id','create_time',
- 'serial_number','wasteDeviceName','cateId','is_print','num','unit'],$info);
- HelpHander::success($a,'操作成功');
- }
- public function save(){
- $json = [
- 'serialNumber'=>input('serialNumber'),
- 'weight2'=>input('weight2'),
- 'status'=>input('status'),
- 'reason'=>input('reason'),
- 'userId'=>$this->userId,
- ];
- if(!in_array($json['status'],[1,2,3])){
- HelpHander::error('参数错误');
- }
- $ret = $this->model->saveStatus($json);
- if($ret){
- HelpHander::success([],'操作成功');
- }else{
- HelpHander::error('操作失败'.$this->model->getError());
- }
- }
- public function detail(){
- $serialNum = input('serialNum');
- $platform = input('platform');
- $orgId = $this->orgId;
- if(strlen($serialNum) == 14){ // 包编号
- $ret = $this->model->packInfo($serialNum,$orgId,$platform);
- }else{
- $ret = $this->model->recordInfo($serialNum,$orgId);
- }
- if($ret){
- HelpHander::success($ret,'操作成功');
- }else{
- HelpHander::error('操作失败');
- }
- }
- public function lists(){
- $depId = input('depId');
- $date = input('date');
- $orgId = $this->orgId;
- $page=input('page/d',1);
- $size=input('size/d',10);
- $ret=$this->model->lists($orgId,$depId,$date,$page,$size,$this->userId);
- HelpHander::success($ret);
- }
- public function sign(){
- $path = input('path');
- $wasterecordid = input('wasteRecordId');
- if(!$path || !$wasterecordid){
- HelpHander::error('参数错误');
- }
- $ids = explode(',',$wasterecordid);
- $succ = 0;
- foreach ($ids as $k=>$v){
- $info = $this->model->getOne($v,$this->orgId);
- if(!$info){
- HelpHander::error($v.'记录不存在');
- }
- if($info['sign'] == 1){
- continue;
- }
- $res = Db::name('waste_record')
- ->where('id',$v)
- ->update([
- 'sign' => 1,
- 'sign_path' => $path,
- 'sign_user_id' => $this->userId,
- 'sign_time' => getTime()
- ]);
- if($res){
- $succ++;
- }
- }
- if($succ==count($ids)){
- HelpHander::success('操作成功');
- }else{
- HelpHander::error('操作失败');
- }
- }
- // 保存医废打包
- public function savePackage(){
- $data = [
- 'org_id' =>$this->orgId,
- 'user_id' => $this->userId,
- 'ids' =>input('ids'),
- ];
- $ids = explode(',',$data['ids']);
- $nids = [];
- foreach ($ids as $k=>$v){
- if($v && !in_array($v,$nids)){
- $nids[] = $v;
- }
- }
- $data['ids'] = $nids;
- if(!$data['ids']){
- HelpHander::error('未选择医废记录');
- }
- $ret = $this->model->savePackage($data);
- if(!$ret){
- HelpHander::error($this->model->getError());
- }
- HelpHander::success(['id' => $ret],'操作成功');
- }
- // 可使用的打包医废记录
- public function yflist(){
- $ret=$this->model->yflist($this->orgId,$this->userId);
- HelpHander::success($ret);
- }
- // 删除包内医废记录
- public function delpackage(){
- $id = input('id'); // 包id
- $recordId = input('recordId'); // 记录id
- $ret=$this->model->delpackage($this->orgId,$this->userId,$id,$recordId);
- if(!$ret){
- HelpHander::error($this->model->getError());
- }
- HelpHander::success([],'操作成功');
- }
- // 交接包
- public function jjpackage(){
- $id = input('id');
- $ret=$this->model->jjpackage($this->orgId,$this->userId,$id);
- if(!$ret){
- HelpHander::error($this->model->getError());
- }
- HelpHander::success([],'操作成功');
- }
- // 转运包
- public function zypackage(){
- $id = input('id');
- $ret=$this->model->zypackage($this->orgId,$this->userId,$id);
- if(!$ret){
- HelpHander::error($this->model->getError());
- }
- HelpHander::success([],'操作成功');
- }
- public function packages(){
- $page = input('page',1);
- $size = input('size',10);
- $ret=$this->model->packagesLists($this->orgId,$page,$size,$this->userId);
- HelpHander::success($ret);
- }
- public function recordLists(){
- $wasteDeviceId = input('wasteDeviceId/d',0);
- $start = input('start','');
- $end = input('end','');
- $orgId = $this->orgId;
- $page = input('page',1);
- $size = input('size',10);
- $ret=$this->model->recordLists($orgId,$wasteDeviceId,$start,$end,$page,$size,$this->userId);
- HelpHander::success($ret);
- }
- public function getByDepDayList(){
- $wasteDeviceId = input('wasteDeviceId/d',0);
- $str=$this->model->getByDepDayList($wasteDeviceId,$this->orgId);
- HelpHander::success(['str'=>$str]);
- }
- public function printList(){
- $ret=$this->model->printList($this->orgId,$this->userId);
- HelpHander::success($ret);
- }
- public function print(){
- $ids = input('ids','');
- if(empty($ids)){
- HelpHander::error('参数错误');
- }
- $ret = $this->model->print($ids,$this->orgId,$this->userId);
- $ret?HelpHander::success($ret):HelpHander::error($this->model->getError());
- }
- //补录
- public function addRecord(){
- $data = [
- 'org_id' => $this->orgId,
- 'user_id' => input('uid/d',0),
- 'waste_device_id' => input('wasteDeviceId/d',0),
- 'cateid' =>input('cateid/d',0),
- 'weight' => input('weight'),
- 'create_time' => input('createTime'),
- 'status' => 0,
- 'is_print' => 0,
- 'num'=>input('num',0),
- ];
- if(!$data['waste_device_id']){
- HelpHander::error('未选择收取科室');
- }
- if(!$data['cateid']){
- HelpHander::error('类型不能为空');
- }
- if($data['weight'] <= 0){
- HelpHander::error('重量不能为空');
- }
- $type = Db::name('waste_type')->where('id',$data['cateid'])->find();
- if(!$type){
- HelpHander::error('类型不存在');
- }
- if($type['type'] == 0){
- $data['num'] = 0;
- }
- if(!$data['create_time']){
- HelpHander::error('未选择收取时间');
- }
- $waste_record_id = model('WasteRecord')->saverecord($data);
- if(!$waste_record_id){
- HelpHander::error(model('WasteRecord')->getError());
- }
- HelpHander::success([],'操作成功');
- }
- public function getWasteUserList(){
- $lists = (new User())->getWasteWorker();
- HelpHander::success($lists);
- }
- }
|