caixiao.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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->where($where)->cursor();
  14. $cgdArr=[];
  15. foreach ($list as $item){
  16. $unique = md5($item->cgdNo.$item->updatetime);
  17. $temp=['order_type'=>2,'uniqkey'=>$unique,'status'=>1,'addtime'=>date('Y-m:d H:i:s')];
  18. if($this->isInCfp($unique)){
  19. $item['cat_name'] = json_decode($item->cat_name);
  20. $temp['data']= json_encode($item,JSON_UNESCAPED_UNICODE);
  21. $cgdArr[]=$temp;
  22. }
  23. }
  24. if(empty($cgdArr)==false) $this->table->insertAll($cgdArr);
  25. }
  26. protected function configure()
  27. {
  28. // 指令配置
  29. $this->setName('caixiao')
  30. ->setDescription('the caixiao command');
  31. }
  32. protected function execute(Input $input, Output $output)
  33. {
  34. // 指令输出
  35. $key="caixiao_copy";
  36. $rs = Cache::store('redis')->inc($key);
  37. if ($rs!=1){
  38. Cache::store('redis')->dec($key);
  39. return true;
  40. }
  41. $this->hour=date('Y-m-d H:i:s',strtotime('-1 hours'));
  42. $this->contect= Db::connect('mysql_cxinv');
  43. $this->table =$this->contect->name("caixiao_data");
  44. $this->sale();
  45. $this->cgd();
  46. Cache::store('redis')->dec($key);
  47. $output->writeln('caixiao');
  48. }
  49. protected function getPay($plat_id=0){
  50. $plat =new Platform();
  51. return $plat->where("id",$plat_id)->value("platform_name","");
  52. }
  53. protected function sale(){
  54. $sale=new SaleCaixiao();
  55. $where=[["updatetime",">=",$this->hour]];
  56. $list = $sale->where($where)->cursor();
  57. $qrd=[];
  58. foreach ($list as $item){
  59. $unique = md5($item->orderCode.$item->updatetime);
  60. $temp=["order_type"=>1,"uniqkey"=>$unique,"status"=>1,"addtime"=>date('Y-m:d H:i:s')];
  61. if($this->isInCfp($unique)){
  62. $item['cat_name'] = json_decode($item->cat_name);
  63. $temp["data"]= json_encode($item,JSON_UNESCAPED_UNICODE);
  64. $qrd[]=$temp;
  65. }
  66. }
  67. if(empty($qrd)==false) $this->table->insertAll($qrd);
  68. }
  69. protected function isInCfp($unique){
  70. $ist = $this->contect->name("caixiao_data")->where("uniqkey",$unique)->findOrEmpty();
  71. return empty($ist);
  72. }
  73. }