12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace app\cxinv\controller;
- use app\cxinv\model\FinancialCheck;
- use app\cxinv\model\FinancialTz;
- use app\cxinv\model\FinancialManager;
- use app\cxinv\model\ProductFz;
- use think\App;
- class FinancialCancel extends Base
- {
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->model = new \app\cxinv\model\FinancialCancel();
- }
- public function create(){
- $params=$this->request->param(['type'=>"","item_ids"=>[],"remark"=>""],"post",'trim');
- $valid = $this->validate($params,[
- 'type|类型'=>'require|in:1,2',
- 'item_ids|订单id'=>'require|array',
- 'remark|备注'=>'max:255',
- ]);
- if($valid!== true) return error($valid);
- $create=[];
- foreach ($params['item_ids'] as $k=>$v){
- if($params['type']==1){
- $ManagerInfo=FinancialManager::where('id',$v)->findOrEmpty();
- if($ManagerInfo->isEmpty()) return error("[$v]订单数据不存在");
- if($ManagerInfo->status!=2 && $ManagerInfo->status!=3) return error("[$v]订单数据状态不正确");
- if($ManagerInfo->type==1||$ManagerInfo->type==3){
- //校验账期是否封账
- $company_code=$ManagerInfo->buyer_code;
- }else{
- $company_code=$ManagerInfo->seller_code;
- }
- $fz = ProductFz::where('company_code',$company_code)->where('fz_date',$ManagerInfo->fz_date)->findOrEmpty();
- if($fz->isEmpty()) return error("[$v]账期数据不存在");
- if($fz->status!=0) return error("[$v]账期数据状态已封账/未解封");
- if($ManagerInfo->status==3){
- $TzInfo=FinancialTz::where('manager_id',$v)->findOrEmpty();
- if(!$TzInfo->isEmpty()){
- if($TzInfo->status!=4) return error("[$v]计提数据单子未处理");
- }
- }
- }else{
- $TzInfo=FinancialTz::with(['Manager'])->where('id',$v)->findOrEmpty();
- if($TzInfo->isEmpty()) return error("[$v]计提数据不存在");
- if($TzInfo->status!=1 && $TzInfo->status!=2) return error("[$v]计提数据状态不正确");
- if($TzInfo->status==2){
- $fz = ProductFz::where('company_code',$TzInfo->Manager->seller_code)->where('fz_date',$TzInfo->fz_date)->findOrEmpty();
- if($fz->isEmpty()) return error("[$v]账期数据不存在");
- if($fz->status!=0) return error("[$v]账期数据状态已封账/未解封");
- }
- if($TzInfo->is_checkOrder==1){
- $check=FinancialCheck::where('code',$TzInfo->ktCode)->findOrEmpty();
- if(!$check->isEmpty()) return error("[$v]调整单未删除,请先处理关联调整单");
- }
- }
- $create[]=[
- 'type'=>$params['type'],
- 'item_id'=>$v,
- 'remark'=>$params['remark'],
- 'apply_id'=>$this->uid,
- 'apply_name'=>$this->uname,
- ];
- }
- $this->model->startTrans();
- try{
- $res=$this->model->saveAll($create);
- if($res->isEmpty()) throw new \Exception("删除数据失败");
- $this->model->commit();
- }catch (\Exception $e){
- $this->model->rollback();
- return error($e->getMessage());
- }
- return success("删除数据成功");
- }
- //列表
- public function list(){
- $params=$this->request->param(['type'=>1,"item_id"=>"","page"=>1,"size"=>20],"post",'trim');
- $where=[];
- if($params['type']!='') {
- $where[]=['type','=',$params['type']];
- $model=($params['type']==1)?'FinancialManager':'FinancialTz';
- }
- if($params['item_id']!='') $where[]=['item_id','=',$params['item_id']];
- $list=$this->model->with([$model])->where($where)->order('id desc')->paginate(['page'=>$params['page'],'list_rows'=>$params['size']]);
- return success("获取成功",['list'=>$list->items(),'count'=>$list->total()]);
- }
- }
|