Label.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace app\cxinv\controller;
  3. use app\cxinv\model\OrderTag;
  4. use app\cxinv\model\TagLog;
  5. use think\App;
  6. use think\facade\Validate;
  7. class Label extends Base{
  8. public function __construct(App $app) {
  9. parent::__construct($app);
  10. $this->model = new OrderTag();
  11. }
  12. //标签创建
  13. public function create(){
  14. $param = $this->request->param(["tag_id"=>"","code"=>"","total_fee"=>"","tag_img"=>"","tag_remark"=>""],"post","trim");
  15. $valid = Validate::rule([
  16. "tag_id|标签id"=>"require|number|gt:0",
  17. "code|订单编号"=>"require|max:255",
  18. "total_fee|标签金额"=>"require|float|gt:0",
  19. "tag_img|标签图片"=>"max:255",
  20. "tag_remark|标签备注"=>"max:255"
  21. ]);
  22. if(!$valid->check($param)) return error($valid->getError());
  23. $tag_info= $this->model->where("id",$param["tag_id"])->findOrEmpty();
  24. if($tag_info->isEmpty()) return error("标签不存在");
  25. $tagdata=[
  26. 'code'=>$param['code'],
  27. 'tag_id'=>$param['tag_id'],
  28. 'creater'=>$this->uname,
  29. 'createrid'=>$this->uid,
  30. 'tag_fee'=>$param['total_fee'],
  31. 'tag_img'=>$param['tag_img'],
  32. 'tag_remark'=>$param['tag_remark'],
  33. 'status'=>1,
  34. ];
  35. $this->model->startTrans();
  36. try{
  37. TagLog::CheckOrderInfo($param['code'],$param['total_fee'],$tag_info['type']);
  38. TagLog::create($tagdata);
  39. $this->model->commit();
  40. }catch (\Exception $e){
  41. $this->model->rollback();
  42. return error($e->getMessage());
  43. }
  44. return success('创建成功');
  45. }
  46. // 标签解除
  47. public function returnTag(){
  48. $param= $this->request->post(['orderCode'=>'','type'=>''],'post','trim');
  49. $valid =Validate::rule(['orderCode|订单编号'=>'require','type|标签类型'=>'require|number|in:1,2,3,4,5,6']);
  50. if($valid->check($param)==false)return error($valid->getError());
  51. $loginfo = TagLog::withJoin(['tagInfo'])->where(['code'=>$param['orderCode'],'tag_log.status'=>[1,2],
  52. 'tagInfo.type'=>$param['type']])->order('tag_log.id','desc')->findOrEmpty();
  53. if($loginfo->isEmpty())return error('未找到标签关联数据');
  54. $this->model->startTrans();
  55. try{
  56. $fee= TagLog::ReturnTag($param['type'],$param['orderCode']);
  57. if($fee==0) throw new \Exception('标签已解除');
  58. $loginfo['status']=0;
  59. $loginfo['tag_fee']=$fee;
  60. unset($loginfo['addtime'],$loginfo['updatetime']);
  61. $loginfo->id=null;
  62. $loginfo->apply_id=$this->uid;
  63. $loginfo->apply_name=$this->uname;
  64. TagLog::create($loginfo->toArray());
  65. $this->model->commit();
  66. }catch (\Exception $exception){
  67. $this->model->rollback();
  68. return error($exception->getMessage());
  69. }
  70. return success("数据标签解除");
  71. }
  72. // 标签列表
  73. public function List(){
  74. $param = $this->request->param(['betweenTime'=>[],'customerNo'=>'','supplierNo'=>'','companyNo'=>'',
  75. 'type'=>'','status'=>'','orderCode'=>'','creater'=>'','order_type'=>1,'size'=>10,'page'=>1],'post','trim');
  76. $modela=['','payInfo','orderInfo','cgdInfo'];
  77. $sbtable = $modela[$param['order_type']];
  78. $type = [[],[1,2],[3,4],[5,6]];
  79. $where=[['tagInfo.type','in',$type[$param['order_type']]],["{$sbtable}.is_del",'=',0],['tagInfo.is_del','=',0]];
  80. empty($param['betweenTime'])?:$where[]=['tag_log.addtime','between',$param['betweenTime']];
  81. if($param['order_type']==2)$param['customerNo']==''?:$where[]=["{$sbtable}.customerNo",'like',"%{$param['customerNo']}%"];
  82. if($param['order_type']!=2)$param['supplierNo']==''?:$where[]=["{$sbtable}.supplierNo",'like',"%{$param['supplierNo']}%"];
  83. $param['companyNo']==''?:$where[]=["{$sbtable}.companyNo",'like',"%{$param['companyNo']}%"];
  84. $param['type']==''?:$where[]=['tagInfo.type','=',$param['type']];
  85. $param['status']===''?:$where[]=['tag_log.status','=',$param['status']];
  86. $param['orderCode']==''?:$where[]=['code','like',"%{$param['orderCode']}%"];
  87. $param['creater']==''?:$where[]=['creater','like',"%{$param['creater']}%"];
  88. $model =new TagLog();
  89. $list = $model->withJoin(['tagInfo',$sbtable],'left')->where($where)
  90. ->order('id','desc')
  91. ->paginate(['list_rows'=>$param['size'],'page'=>$param['page']]);
  92. return success('获取成功',['list'=>$list->items(),'count'=>$list->total()]);
  93. }
  94. }