123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- declare (strict_types = 1);
- namespace app\command;
- use think\console\Command;
- use think\console\Input;
- use think\console\input\Argument;
- use think\console\input\Option;
- use think\console\Output;
- use think\facade\Cache;
- use think\facade\Db;
- class updatecgd extends Command
- {
- protected $db="";
- protected function configure()
- {
- // 指令配置
- $this->setName('CopyData')
- ->setDescription('the CopyData command');
- }
- protected function execute(Input $input, Output $output)
- {
- $redis = Cache::store('redis');
- $iscgd = $redis->get("thstatus");
- if ($iscgd == 0) {
- $redis->set("thstatus", 1,1200);
- } else {
- return;
- }
- $data= $this->GetData();
- if(empty($data)){
- return;
- }
- foreach ($data as $key=>$value){
- if($value['th_cgdNo']!=''){
- $cgd = Db::name("cgd_info")->where([['ShortText1618315935182','=',$value['th_cgdNo']]])->find();
- if(empty($cgd)){
- echo $value['th_cgdNo'];
- continue;
- }
- $thnum = Db::name('th_source')->where([['th_cgdNo',"=",$value['th_cgdNo']],['th_status','=',1]])
- ->field('sum(th_cgd_fee) as th_fee,sum(th_num) as th_num')->find();
- $cgd['th_status'] = isset($thnum['th_num']) && $thnum['th_num']>0 ?
- ($cgd['Number1618240600907']>$thnum['th_num'] ? 2 : 3) :1;
- $cgd['Number1619625470651'] = $thnum['th_num'];
- $cgd['Number1619625483510'] = $thnum['th_fee'];
- $cgd['Number1618330472961'] =$cgd['Number1618240685904']-round($cgd['Number1618330470625'])-$thnum['th_fee'];
- $cgd['Number1618330543270'] = $cgd['Number1618240685904']-round($cgd['Number1618330541286'])-$thnum['th_fee'];
- Db::name("cgd_info")->save($cgd);
- }else{
- echo $value['th_cgdNo'];
- }
- }
- $redis->set("thstatus", 0);
- $output->writeln('CopyData');
- }
- protected function GetData(){
- $date = date("Y-m-d H:i:s",strtotime("-3 day"));
- $list = Db::name('th_source')->where([['addtime',">=",$date],['th_status','=',1]])->select();
- return $list;
- }
- }
|