setName('CopyData') ->setDescription('the CopyData command'); } protected function execute(Input $input, Output $output) { // 指令输php出. $redis = Cache::store('redis'); $iscgd = $redis->get("customer"); if($iscgd==0){ $redis->set("customer",1,1200); }else{ return; } $this->db =Db::connect("mysql2"); $data = $this->GetData(); $list=[]; $customer = new CustomerInfo(); foreach ($data as $key=>$value){ $relas = $customer->where("companyNo","=",$value['companyNo'])->find(); $inv=Db::name("customer_invoice")->where([['is_del',"=",0],['invoice_code',"=",$value['invoice_code']]]) ->find(); if($relas){ $customer->where("companyNo","=",$value['companyNo'])->save($value); }else{ $customer->insert($value); } if($inv){ continue; }else{ if($value['invoice_code']==""){ continue; } $invv=[ "invoice_title"=>$value['invoice_title'], "invoice_people"=>$value['invoice_people'], "invoice_addr"=>$value['invoice_addr'], "invoice_mobile"=>$value['invoice_mobile'], "invoice_code"=>$value['invoice_code'], "invoice_bank"=>$value['invoice_bank'], "invoice_bankNo"=>$value['invoice_bankNo'], "is_del"=>0, "addtime"=>$value['addtime'], "updatetime"=>$value['updatetime'] ]; Db::name("customer_invoice")->insert($invv); } } $redis->set("customer",0); $output->writeln('CopyData'); } private function GetData(){ $date = date("Y-m-d H:i:s",strtotime("-1 day")); $data = $this->db->table("il150_Customer_info")->alias('a')->where("modifiedTime",">=", $date) ->field(" sequenceNo as companyNo, IF(`sequenceStatus` ='COMPLETED',1,0) as status, ShortText1614738964782 as companyName, ifnull(ShortText1615282447896,'') as comdepart, ifnull(text1615282721984,'') commobile, ifnull(text1615282728065,'') comtel, ifnull(text1615282771211,'') contactor, ifnull(text1615282776035,'') depart, ifnull(text1615282780018,'') mobile, ifnull((SELECT b_.`name` FROM h_org_user b_ WHERE b_.id = JSON_EXTRACT ( StaffSelector1616982886492, '$[0].id' )),'') AS sales_name, ifnull((SELECT b_.`name` FROM h_org_department b_ WHERE b_.id = JSON_EXTRACT ( StaffSelector1616982890501, '$[0].id' )),'') AS sales_depart, ifnull(text1615283088459,'') invoice_title, ifnull(text1615283102439,'') invoice_people, ifnull(text1615283117386,'') invoice_code, ifnull(text1615283125769,'') invoice_addr, ifnull(text1615283140950,'') invoice_mobile, ifnull(text1615283155377,'') invoice_bank, ifnull(text1615283198972,'') companyCode, ifnull(ShortText1617171368467,'') invoice_bankNo, ifnull(ShortText1618901742599,'') parent, ifnull(text1619411877719,'') branch, ifnull(text1619411907247,'') middle, ifnull(text1619411907991,'') country , ifnull(text1619521602702 ,'') area, createdTime addtime, modifiedTime updatetime, (SELECT b_.`name` FROM h_org_user b_ WHERE b_.id = a.modifier ) AS modifier, (SELECT b_.`name` FROM h_org_user b_ WHERE b_.id = a.creater ) AS creater ")->select()->toArray(); return $data; } }