模型对应的观察者OrderAllocationObserver public function created(TmOrderManagement $tmOrderManagement) { $userid= $tmOrderManagement->userid; $townname= TmToilet::where('id',$userid)->value('town'); $townid=TmTown::where('townname',$townname)->value('id'); if(DB::table('tm_zone_management')->where('townid',$townid) ->where('allocation_status',0)->first()==null) { DB::table('tm_zone_management')->where('townid',$townid) ->update(['allocation_status'=>0]); } //如果区域内的所以可分配员工都被分配,重置分配状态 $tmOrderManagement->workid=DB::table('tm_zone_management')->where('townid',$townid) ->where('allocation_status',0)->first()->workerid; DB::table('tm_zone_management')->where('workerid',$tmOrderManagement->workid)->update(['allocation_status'=>1]); //获取工作人员id赋值给工单,然后把区域表里对应工作人员的分配状态置为1 $tmOrderManagement->save(); // }
分类