caixiao.php 3.3 KB

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