setName('copyCxData')->setDescription('复制采销数据到中间表'); } protected function execute(Input $input, Output $output) { foreach ($this->Qrd() as $v){ $uniqkey = md5($v["orderCode"].$v["updatetime"]); $ist =Db::name("caixiao_data")->where(["uniqkey"=>$uniqkey])->value("id",0); if($ist==0){ Db::name("caixiao_data")->insert(["order_type"=>1,"data"=>json_encode($v,JSON_UNESCAPED_UNICODE),"uniqkey"=>$uniqkey,"status"=>1]); } } foreach ($this->Cgd() as $v){ $uniqkey = md5($v["cgdNo"].$v["updatetime"]); $ist =Db::name("caixiao_data")->where(["uniqkey"=>$uniqkey])->value("id",0); if($ist==0){ Db::name("caixiao_data")->insert(["order_type"=>2,"data"=>json_encode($v,JSON_UNESCAPED_UNICODE),"uniqkey"=>$uniqkey,"status"=>1]); } } } protected function Qrd(){ $sale = Db::connect('mysql_wsm') ->name('sale_caixiao') ->where('updatetime',"<=",date("Y-m-d H:i:s",time()-$this->interval))->limit(100)->order("id desc") ->cursor(); foreach ($sale as $value){ yield $value; } } protected function Cgd(){ $sale = Db::connect('mysql_wsm') ->name('cgd_caixiao') ->where('updatetime',">=",date("Y-m-d H:i:s",time()-$this->interval)) ->cursor(); foreach ($sale as $value){ yield $value; } } }