FinancialSeal.php 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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"=>"","remark"=>""],"post","trim");
  38. $valid=$this->validate($params,[
  39. 'id'=>'require',
  40. 'status'=>'require|in:0,1,2,3,4',
  41. 'remark'=>'max:255'
  42. ]);
  43. if($valid!==true) return error($valid);
  44. $row = $this->model->findOrEmpty($params['id']);
  45. if($row->isEmpty()) return error('数据不存在');
  46. $getLastMonth= date("Y-m",strtotime("-1 month"));
  47. if($row['fz_date']!=$getLastMonth && $params['status']==0) return error('非上月数据不可解封');
  48. //当月账期不可封账
  49. if($params['status']==1){
  50. if($row['fz_date']==date('Y-m')) return error('当月数据不可封账');
  51. $montah = date('Y-m',strtotime('-1 month',strtotime($row['fz_date'])));
  52. $lasMonth= $this->model->where('fz_date',$montah)->where('company_code',$row->company_code)->findOrEmpty();
  53. if(!$lasMonth->isEmpty()&& $lasMonth['status']!=2) return error($montah.'数据未封账');
  54. $mamger= FinancialManager::where(function($query) use($row){
  55. $query->whereOr([
  56. [['buyer_code','=',$row['company_code']],['type','in',[1,3]]],
  57. [['seller_code','=',$row['company_code']],['type','in',[2,4]]]
  58. ]);
  59. })->where(["status"=>[1,4],"fz_date"=>$row['fz_date']])->findOrEmpty();
  60. if(!$mamger->isEmpty()) return error(FinancialManager::$ManagerType[$mamger['type']]."【{$mamger['id']}】未处理");
  61. }
  62. $row->status=$params['status'];
  63. $row->remark=$params['remark'];
  64. $row->apply_id=$this->uid;
  65. $row->apply_name=$this->uname;
  66. $as = $row->save();
  67. if($as==false) return error('操作失败');
  68. return success('操作成功');
  69. }
  70. public function FzList(){
  71. $params = $this->request->param(["page"=>1,"size"=>10,"company_code"=>"","skuCode"=>"",'product_id'=>"","fz_date"=>""],"post","trim");
  72. $where=[];
  73. if($params['company_code']!=''){
  74. $where[]=['company_code','=',$params['company_code']];
  75. }
  76. if($params['product_id']!=''){
  77. $where[]=['product_id','=',$params['product_id']];
  78. }
  79. if($params['skuCode']!='') $where[]=['skuCode','like','%'.$params];
  80. if($params['fz_date']!=''){
  81. $where[]=['fz_date','=',$params['fz_date']];
  82. }
  83. $list = ProductSeal::with(["PorductFz",'Porduct'])->withJoin(["PorductFz"],"left")->where($where)->order('product_seal.id desc')->paginate(['list_rows'=>$params['size'],'page'=>$params['page']]);
  84. return success('获取成功',['list'=>$list->items(),'count'=>$list->total()]);
  85. }
  86. }