setName('goodcatcheck') ->setDescription('the goodcatcheck command'); } protected function execute(Input $input, Output $output) { $output->writeln('【'.date('Y-m-d H:i:s').'】开始执行商品开票税目检查'); try{ $this->check(); }catch (\Exception $e){ $output->writeln('【'.date('Y-m-d H:i:s').'】执行商品开票税目检查失败'); $output->writeln($e->getMessage()); } } protected function check(){ $info = WechatSetPush::where('id',1)->findOrEmpty(); if($info->isEmpty()||empty($info->push_user_info)){ throw new \Exception('推送信息未配置'); } if($info->status==0)throw new \Exception('推送状态未开启'); $this->templateInfo = $info; foreach($info->push_user_info as $k=>$v){ $this->processCount($v,"GoodBasic"); $this->processCount($v,"ConsultBids"); } } protected function processCount($user,$method){ $companyNo = $user['companyNo']; $goodBasicNum = call_user_func([$this,"Get".$method."Num"],$companyNo); if($goodBasicNum>0){ $this->sendMessage($user,$method,$goodBasicNum); } } protected function sendMessage($user,$method,$goodBasicNum){ $methodArr = [ "GoodBasic"=>"商品成本待财务审核", "ConsultBids"=>"咨询商品待财务审核" ]; $company = $user['companyName']??""; $temp = [ 'thing18'=>['value'=>$methodArr[$method]], 'thing24'=>['value'=>$company], 'thing10'=>['value'=>"待财务审核"], 'character_string26'=>['value'=>$goodBasicNum], 'time25'=>['value'=>date('Y-m-d H:i:s')], ]; if(!empty($user['pushinfo'])){ foreach($user['pushinfo'] as $k=>$v){ $temps=[ 'code'=>date('YmdHis'), 'belong'=>1, 'openId'=>$v['openId']??'', 'template_id'=>$this->templateInfo['template_id'], 'template_name'=>$this->templateInfo['template_name'], 'action_name'=>'商品税目财务设置', 'template_data'=>$temp, 'uid'=>$v['account_id'], 'uname'=>$v['nickname']??'', ]; Cache::store('redis')->handler()->lpush('wxpush_queue',json_encode($temps,JSON_UNESCAPED_UNICODE)); } } } protected function GetGoodBasicNum($companyNo){ $where = [ ['is_del','=',0],['status','=',9] ]; if($companyNo!=''){ $where[] = ['companyNo','=',$companyNo]; } return GoodBasic::where( $where)->count(); } protected function GetConsultBidsNum($companyNo){ $where = [ ["ConsultOrder.is_del","=",0], ["tax_status","=",0], ["consult_bids.is_del","=",0], ['ConsultInfo.bargain_status','=',0], ['ConsultInfo.status','in',[2,7]], ["ConsultInfo.is_del","=",0], ]; if($companyNo!=''){ $where[] = ['ConsultOrder.companyNo','=',$companyNo]; } return ConsultBids::withJoin(["ConsultOrder","ConsultInfo"],"LEFT") ->where( $where ) ->count(); } }