Label.php 4.4 KB

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