1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace app\cxinv\controller;
- use app\cxinv\model\FinancialManager;
- use app\cxinv\model\ProductFz;
- use app\cxinv\model\ProductSeal;use think\App;
- class FinancialSeal extends Base{
- public function __construct(App $app) {
- parent::__construct($app);
- $this->model = new \app\cxinv\model\ProductFz();
- }
- // 列表
- public function list(){
- $params = $this->request->param(["page"=>1,"size"=>10,"company_code"=>"","status"=>"","fz_date"=>""],"post","trim");
- $where=[];
- if($params['company_code']!=''){
- $where[]=['company_code','=',$params['company_code']];
- }
- if($params['status']!=''){
- $where[]=['status','=',$params['status']];
- }
- if($params['fz_date']!=''){
- $where[]=['fz_date','=',$params['fz_date']];
- }
- $list = $this->model->where($where)->order('id desc')->paginate(['list_rows'=>$params['size'],'page'=>$params['page']]);
- return success('获取成功',['list'=>$list->items(),'count'=>$list->total()]);
- }
- public function getQuery(){
- $params = $this->request->param(['company_code'=>'','status'=>''],'post','trim');
- $where=[];
- if($params['company_code']!='') $where[]=['company_code','=',$params['company_code']];
- if($params['status']!='') $where[]=['status','=',$params['status']];
- $list=$this->model->where($where)->select();
- return success('获取成功',$list);
- }
- //0解封 1封账中 2 封账完成 3 封账失败
- public function status(){
- $params = $this->request->param(["id"=>"","status"=>"","remark"=>""],"post","trim");
- $valid=$this->validate($params,[
- 'id'=>'require',
- 'status'=>'require|in:0,1,2,3,4',
- 'remark'=>'max:255'
- ]);
- if($valid!==true) return error($valid);
- $row = $this->model->findOrEmpty($params['id']);
- if($row->isEmpty()) return error('数据不存在');
- $getLastMonth= date("Y-m",strtotime("-1 month"));
- if($row['fz_date']!=$getLastMonth && $params['status']==0) return error('非上月数据不可解封');
- //当月账期不可封账
- if($params['status']==1){
- if($row['fz_date']==date('Y-m')) return error('当月数据不可封账');
- $montah = date('Y-m',strtotime('-1 month',strtotime($row['fz_date'])));
- $lasMonth= $this->model->where('fz_date',$montah)->where('company_code',$row->company_code)->findOrEmpty();
- if(!$lasMonth->isEmpty()&& $lasMonth['status']!=2) return error($montah.'数据未封账');
- $mamger= FinancialManager::where(function($query) use($row){
- $query->whereOr([
- [['buyer_code','=',$row['company_code']],['type','in',[1,3]]],
- [['seller_code','=',$row['company_code']],['type','in',[2,4]]]
- ]);
- })->where(["status"=>[1,4],"fz_date"=>$row['fz_date']])->findOrEmpty();
- if(!$mamger->isEmpty()) return error(FinancialManager::$ManagerType[$mamger['type']]."【{$mamger['id']}】未处理");
- }
- $row->status=$params['status'];
- $row->remark=$params['remark'];
- $row->apply_id=$this->uid;
- $row->apply_name=$this->uname;
- $as = $row->save();
- if($as==false) return error('操作失败');
- return success('操作成功');
- }
- public function FzList(){
- $params = $this->request->param(["page"=>1,"size"=>10,"company_code"=>"","skuCode"=>"",'product_id'=>"","fz_date"=>""],"post","trim");
- $where=[];
- if($params['company_code']!=''){
- $where[]=['company_code','=',$params['company_code']];
- }
- if($params['product_id']!=''){
- $where[]=['product_id','=',$params['product_id']];
- }
- if($params['skuCode']!='') $where[]=['skuCode','like','%'.$params];
- if($params['fz_date']!=''){
- $where[]=['fz_date','=',$params['fz_date']];
- }
- $list = ProductSeal::with(["PorductFz",'Porduct'])->withJoin(["PorductFz"],"left")->where($where)->order('product_seal.id desc')->paginate(['list_rows'=>$params['size'],'page'=>$params['page']]);
- return success('获取成功',['list'=>$list->items(),'count'=>$list->total()]);
- }
- }
|