copyCxData.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\command;
  3. use think\console\Command;
  4. use think\console\Input;
  5. use think\console\Output;
  6. use think\console\Table;use think\facade\Db;
  7. use think\helper\Str;
  8. //将wsm_sale_caixiao和wsm_cgd_caixiao的数据复制到cfp_caixiao_data
  9. class copyCxData extends command
  10. {
  11. private $interval = 3600;//执行间隔,单位:分(每次同步前5分钟的数据)
  12. protected function configure()
  13. {
  14. parent::configure(); // TODO: Change the autogenerated stub
  15. $this->setName('copyCxData')->setDescription('复制采销数据到中间表');
  16. }
  17. protected function execute(Input $input, Output $output)
  18. {
  19. foreach ($this->Qrd() as $v){
  20. $uniqkey = md5($v["orderCode"].$v["updatetime"]);
  21. $ist =Db::name("caixiao_data")->where(["uniqkey"=>$uniqkey])->value("id",0);
  22. if($ist==0){
  23. Db::name("caixiao_data")->insert(["order_type"=>1,"data"=>json_encode($v,JSON_UNESCAPED_UNICODE),"uniqkey"=>$uniqkey,"status"=>1]);
  24. }
  25. }
  26. foreach ($this->Cgd() as $v){
  27. $uniqkey = md5($v["cgdNo"].$v["updatetime"]);
  28. $ist =Db::name("caixiao_data")->where(["uniqkey"=>$uniqkey])->value("id",0);
  29. if($ist==0){
  30. Db::name("caixiao_data")->insert(["order_type"=>2,"data"=>json_encode($v,JSON_UNESCAPED_UNICODE),"uniqkey"=>$uniqkey,"status"=>1]);
  31. }
  32. }
  33. }
  34. protected function Qrd(){
  35. $sale = Db::connect('mysql_wsm')
  36. ->name('sale_caixiao')
  37. ->where('updatetime',"<=",date("Y-m-d H:i:s",time()-$this->interval))->limit(100)->order("id desc")
  38. ->cursor();
  39. foreach ($sale as $value){
  40. yield $value;
  41. }
  42. }
  43. protected function Cgd(){
  44. $sale = Db::connect('mysql_wsm')
  45. ->name('cgd_caixiao')
  46. ->where('updatetime',">=",date("Y-m-d H:i:s",time()-$this->interval))
  47. ->cursor();
  48. foreach ($sale as $value){
  49. yield $value;
  50. }
  51. }
  52. }