caixiao.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\command;
  4. use app\admin\model\CgdCaixiao;use app\admin\model\Platform;use app\admin\model\SaleCaixiao;use think\console\Command;use think\console\Input;use think\console\Output;use think\facade\Cache;use think\facade\Db;
  5. class caixiao extends Command
  6. {
  7. protected $table = null;
  8. protected $contect = null;
  9. protected $hour = null;
  10. protected function cgd(){
  11. $cgd=new CgdCaixiao();
  12. $where=[['updatetime','>=',$this->hour]];
  13. $list = $cgd->with(["originCgd"])->where($where)->select();
  14. $cgdArr=[];
  15. foreach ($list as $item){
  16. echo $item->cgdNo."--".$item->mainCode;
  17. $unique = md5($item->cgdNo.$item->updatetime);
  18. $temp=['order_type'=>2,'uniqkey'=>$unique,'status'=>1,'addtime'=>date('Y-m:d H:i:s')];
  19. if($this->isInCfp($unique)){
  20. $item['cat_name'] = json_decode($item->cat_name);
  21. $temp['data']= json_encode($item,JSON_UNESCAPED_UNICODE);
  22. $cgdArr[]=$temp;
  23. }
  24. }
  25. if(empty($cgdArr)==false) $this->table->insertAll($cgdArr);
  26. }
  27. protected function configure()
  28. {
  29. // 指令配置
  30. $this->setName('caixiao')
  31. ->setDescription('the caixiao command');
  32. }
  33. protected function execute(Input $input, Output $output)
  34. {
  35. // 指令输出
  36. $key="caixiao_copy";
  37. $rs = Cache::store('redis')->get($key);
  38. if ($rs!=0) return true;
  39. Cache::store('redis')->set($key,1,180);
  40. $this->hour=date('Y-m-d H:i:s',strtotime('-1 hours'));
  41. $this->contect= Db::connect('mysql_cxinv');
  42. $this->table =$this->contect->name("caixiao_data");
  43. $this->sale();
  44. $this->cgd();
  45. $output->writeln('caixiao');
  46. }
  47. protected function getPay($plat_id=0){
  48. $plat =new Platform();
  49. return $plat->where("id",$plat_id)->value("platform_name","");
  50. }
  51. protected function sale(){
  52. $sale=new SaleCaixiao();
  53. $where=[["updatetime",">=",$this->hour]];
  54. $list = $sale->where($where)->cursor();
  55. $qrd=[];
  56. foreach ($list as $item){
  57. $unique = md5($item->orderCode.$item->updatetime);
  58. $temp=["order_type"=>1,"uniqkey"=>$unique,"status"=>1,"addtime"=>date('Y-m:d H:i:s')];
  59. if($this->isInCfp($unique)){
  60. $item['cat_name'] = json_decode($item->cat_name);
  61. $temp["data"]= json_encode($item,JSON_UNESCAPED_UNICODE);
  62. $qrd[]=$temp;
  63. }
  64. }
  65. if(empty($qrd)==false) $this->table->insertAll($qrd);
  66. }
  67. protected function isInCfp($unique){
  68. $ist = $this->contect->name("caixiao_data")->where("uniqkey",$unique)->findOrEmpty();
  69. return empty($ist);
  70. }
  71. }