model = new OrderTag(); } //标签创建 public function create(){ $param = $this->request->param(["tag_id"=>"","code"=>"","total_fee"=>"","tag_img"=>"","tag_remark"=>""],"post","trim"); $valid = Validate::rule([ "tag_id|标签id"=>"require|number|gt:0", "code|订单编号"=>"require|max:255", "total_fee|标签金额"=>"require|float|gt:0", "tag_img|标签图片"=>"max:255", "tag_remark|标签备注"=>"max:255" ]); if(!$valid->check($param)) return error($valid->getError()); $tag_info= $this->model->where("id",$param["tag_id"])->findOrEmpty(); if($tag_info->isEmpty()) return error("标签不存在"); $tagdata=[ 'code'=>$param['code'], 'tag_id'=>$param['tag_id'], 'creater'=>$this->uname, 'createrid'=>$this->uid, 'tag_fee'=>$param['total_fee'], 'tag_img'=>$param['tag_img'], 'tag_remark'=>$param['tag_remark'], 'status'=>1, ]; $this->model->startTrans(); try{ TagLog::CheckOrderInfo($param['code'],$param['total_fee'],$tag_info['type']); TagLog::create($tagdata); $this->model->commit(); }catch (\Exception $e){ $this->model->rollback(); return error($e->getMessage()); } return success('创建成功'); } // 标签解除 public function returnTag(){ $param= $this->request->post(['orderCode'=>'','type'=>''],'post','trim'); $valid =Validate::rule(['orderCode|订单编号'=>'require','type|标签类型'=>'require|number|in:1,2,3,4,5,6']); if($valid->check($param)==false)return error($valid->getError()); $loginfo = TagLog::withJoin(['tagInfo'])->where(['code'=>$param['orderCode'],'tag_log.status'=>[1,2], 'tagInfo.type'=>$param['type']])->order('tag_log.id','desc')->findOrEmpty(); if($loginfo->isEmpty())return error('未找到标签关联数据'); $this->model->startTrans(); try{ $fee= TagLog::ReturnTag($param['type'],$param['orderCode']); if($fee==0) throw new \Exception('标签已解除'); $loginfo['status']=0; $loginfo['tag_fee']=$fee; unset($loginfo['addtime'],$loginfo['updatetime']); $loginfo->id=null; $loginfo->apply_id=$this->uid; $loginfo->apply_name=$this->uname; TagLog::create($loginfo->toArray()); $this->model->commit(); }catch (\Exception $exception){ $this->model->rollback(); return error($exception->getMessage()); } return success("数据标签解除"); } // 标签列表 public function List(){ $param = $this->request->param(['betweenTime'=>[],'customerNo'=>'','supplierNo'=>'','companyNo'=>'', 'type'=>'','status'=>'','orderCode'=>'','creater'=>'','order_type'=>1,'size'=>10,'page'=>1],'post','trim'); $modela=['','payInfo','orderInfo','cgdInfo']; $sbtable = $modela[$param['order_type']]; $type = [[],[1,2],[3,4],[5,6]]; $where=[['tagInfo.type','in',$type[$param['order_type']]],["{$sbtable}.is_del",'=',0],['tagInfo.is_del','=',0]]; empty($param['betweenTime'])?:$where[]=['tag_log.addtime','between',$param['betweenTime']]; if($param['order_type']==2)$param['customerNo']==''?:$where[]=["{$sbtable}.customerNo",'like',"%{$param['customerNo']}%"]; if($param['order_type']!=2)$param['supplierNo']==''?:$where[]=["{$sbtable}.supplierNo",'like',"%{$param['supplierNo']}%"]; $param['companyNo']==''?:$where[]=["{$sbtable}.companyNo",'like',"%{$param['companyNo']}%"]; $param['type']==''?:$where[]=['tagInfo.type','=',$param['type']]; $param['status']===''?:$where[]=['tag_log.status','=',$param['status']]; $param['orderCode']==''?:$where[]=['code','like',"%{$param['orderCode']}%"]; $param['creater']==''?:$where[]=['creater','like',"%{$param['creater']}%"]; $model =new TagLog(); $list = $model->withJoin(['tagInfo',$sbtable],'left')->where($where) ->order('id','desc') ->paginate(['list_rows'=>$param['size'],'page'=>$param['page']]); return success('获取成功',['list'=>$list->items(),'count'=>$list->total()]); } }