updatecgd.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\command;
  4. use think\console\Command;
  5. use think\console\Input;
  6. use think\console\input\Argument;
  7. use think\console\input\Option;
  8. use think\console\Output;
  9. use think\facade\Cache;
  10. use think\facade\Db;
  11. class updatecgd extends Command
  12. {
  13. protected $db="";
  14. protected function configure()
  15. {
  16. // 指令配置
  17. $this->setName('CopyData')
  18. ->setDescription('the CopyData command');
  19. }
  20. protected function execute(Input $input, Output $output)
  21. {
  22. $redis = Cache::store('redis');
  23. $iscgd = $redis->get("thstatus");
  24. if ($iscgd == 0) {
  25. $redis->set("thstatus", 1,1200);
  26. } else {
  27. return;
  28. }
  29. $data= $this->GetData();
  30. if(empty($data)){
  31. return;
  32. }
  33. foreach ($data as $key=>$value){
  34. if($value['th_cgdNo']!=''){
  35. $cgd = Db::name("cgd_info")->where([['ShortText1618315935182','=',$value['th_cgdNo']]])->find();
  36. if(empty($cgd)){
  37. echo $value['th_cgdNo'];
  38. continue;
  39. }
  40. $thnum = Db::name('th_source')->where([['th_cgdNo',"=",$value['th_cgdNo']],['th_status','=',1]])
  41. ->field('sum(th_cgd_fee) as th_fee,sum(th_num) as th_num')->find();
  42. $cgd['th_status'] = isset($thnum['th_num']) && $thnum['th_num']>0 ?
  43. ($cgd['Number1618240600907']>$thnum['th_num'] ? 2 : 3) :1;
  44. $cgd['Number1619625470651'] = $thnum['th_num'];
  45. $cgd['Number1619625483510'] = $thnum['th_fee'];
  46. $cgd['Number1618330472961'] =$cgd['Number1618240685904']-round($cgd['Number1618330470625'])-$thnum['th_fee'];
  47. $cgd['Number1618330543270'] = $cgd['Number1618240685904']-round($cgd['Number1618330541286'])-$thnum['th_fee'];
  48. Db::name("cgd_info")->save($cgd);
  49. }else{
  50. echo $value['th_cgdNo'];
  51. }
  52. }
  53. $redis->set("thstatus", 0);
  54. $output->writeln('CopyData');
  55. }
  56. protected function GetData(){
  57. $date = date("Y-m-d H:i:s",strtotime("-3 day"));
  58. $list = Db::name('th_source')->where([['addtime',">=",$date],['th_status','=',1]])->select();
  59. return $list;
  60. }
  61. }