FinancialSeal.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace app\cxinv\controller;
  3. use app\cxinv\model\FinancialManager;
  4. use app\cxinv\model\ProductFz;
  5. use app\cxinv\model\ProductSeal;use think\App;
  6. class FinancialSeal extends Base{
  7. public function __construct(App $app) {
  8. parent::__construct($app);
  9. $this->model = new \app\cxinv\model\ProductFz();
  10. }
  11. // 列表
  12. public function list(){
  13. $params = $this->request->param(["page"=>1,"size"=>10,"company_code"=>"","status"=>"","fz_date"=>""],"post","trim");
  14. $where=[];
  15. if($params['company_code']!=''){
  16. $where[]=['company_code','=',$params['company_code']];
  17. }
  18. if($params['status']!=''){
  19. $where[]=['status','=',$params['status']];
  20. }
  21. if($params['fz_date']!=''){
  22. $where[]=['fz_date','=',$params['fz_date']];
  23. }
  24. $list = $this->model->where($where)->order('id desc')->paginate(['list_rows'=>$params['size'],'page'=>$params['page']]);
  25. return success('获取成功',['list'=>$list->items(),'count'=>$list->total()]);
  26. }
  27. public function getQuery(){
  28. $params = $this->request->param(['company_code'=>'','status'=>''],'post','trim');
  29. $where=[];
  30. if($params['company_code']!='') $where[]=['company_code','=',$params['company_code']];
  31. if($params['status']!='') $where[]=['status','=',$params['status']];
  32. $list=$this->model->where($where)->select();
  33. return success('获取成功',$list);
  34. }
  35. //0解封 1封账中 2 封账完成 3 封账失败
  36. public function status(){
  37. $params = $this->request->param(["id"=>"","status"=>""],"post","trim");
  38. $valid=$this->validate($params,[
  39. 'id'=>'require',
  40. 'status'=>'require|in:0,1,2,3'
  41. ]);
  42. if($valid!==true) return error($valid);
  43. $row = $this->model->findOrEmpty($params['id']);
  44. if($row->isEmpty()) return error('数据不存在');
  45. $getLastMonth= date("Y-m",strtotime("-1 month"));
  46. if($row['fz_date']!=$getLastMonth && $params['status']==0) return error('非上月数据不可解封');
  47. if($params['status']==1){
  48. $montah = date('Y-m',strtotime('-1 month',strtotime($row['fz_date'])));
  49. $lasMonth= $this->model->where('fz_date',$montah)->where('company_code',$row->company_code)->findOrEmpty();
  50. if(!$lasMonth->isEmpty()&& $lasMonth['status']!=2) return error($montah.'数据未封账');
  51. $mamger= FinancialManager::where(function($query) use($row){
  52. $query->whereOr([
  53. [['buyer_code','=',$row['company_code']],['type','in',[1,3]]],
  54. [['seller_code','=',$row['company_code']],['type','in',[2,4]]]
  55. ]);
  56. })->where(["status"=>1,"fz_date"=>$row['fz_date']])->findOrEmpty();
  57. if(!$mamger->isEmpty()) return error(FinancialManager::$ManagerType[$mamger['type']]."【{$mamger['id']}】未处理");
  58. }
  59. $row->status=$params['status'];
  60. $row->apply_id=$this->uid;
  61. $row->apply_name=$this->uname;
  62. $as = $row->save();
  63. if($as==false) return error('操作失败');
  64. return success('操作成功');
  65. }
  66. public function FzList(){
  67. $params = $this->request->param(["page"=>1,"size"=>10,"company_code"=>"","skuCode"=>"",'product_id'=>"","fz_date"=>""],"post","trim");
  68. $where=[];
  69. if($params['company_code']!=''){
  70. $where[]=['company_code','=',$params['company_code']];
  71. }
  72. if($params['product_id']!=''){
  73. $where[]=['product_id','=',$params['product_id']];
  74. }
  75. if($params['skuCode']!='') $where[]=['skuCode','like','%'.$params];
  76. if($params['fz_date']!=''){
  77. $where[]=['fz_date','=',$params['fz_date']];
  78. }
  79. $list = ProductSeal::with(["PorductFz",'Porduct'])->withJoin(["PorductFz"],"left")->where($where)->order('product_seal.id desc')->paginate(['list_rows'=>$params['size'],'page'=>$params['page']]);
  80. return success('获取成功',['list'=>$list->items(),'count'=>$list->total()]);
  81. }
  82. public function Export(){
  83. $params = $this->request->param(['company_code'=>'','status'=>'','fz_date'=>''],'post','trim');
  84. $where=[];
  85. if($params['company_code']!=''){
  86. $where[]=['company_code','=',$params['company_code']];
  87. }
  88. if($params['status']!=''){
  89. $where[]=['status','=',$params['status']];
  90. }
  91. if($params['fz_date']!=''){
  92. $where[]=['fz_date','=',$params['fz_date']];
  93. }
  94. $list = ProductSeal::with(["PorductFz",'Porduct'])->withJoin(['PorductFz'],'left')->where($where)->order('product_seal.id desc')->select();
  95. return success('获取成功',$list);
  96. }
  97. }