123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace app\command;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- use think\console\Table;use think\facade\Db;
- use think\helper\Str;
- //将wsm_sale_caixiao和wsm_cgd_caixiao的数据复制到cfp_caixiao_data
- class copyCxData extends command
- {
- private $interval = 3600;//执行间隔,单位:分(每次同步前5分钟的数据)
- protected function configure()
- {
- parent::configure(); // TODO: Change the autogenerated stub
- $this->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;
- }
- }
- }
|