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')], ]; $userinfo = User::where('account_id',$user['account_id'])->findOrEmpty(); $temps=[ 'code'=>date('YmdHis'), 'belong'=>1, 'openId'=>$userinfo['openId']??"", 'template_id'=>$this->templateInfo['template_id'], 'template_name'=>$this->templateInfo['template_name'], 'action_name'=>'商品税目财务设置', 'template_data'=>$temp, 'uid'=>$user['account_id'], 'uname'=>$userinfo['nickname']??"", ]; Cache::store('redis')->handler()->lpush('wxpush_queue',json_encode($temps,JSON_UNESCAPED_UNICODE)); } protected function GetGoodBasicNum($companyNo){ return GoodBasic::where([['companyNo',"=",$companyNo],["is_del","=",0],["status","=",9]])->count(); } protected function GetGoodBidsNum($companyNo){ return ConsultBids::withJoin(["ConsultOrder"]) ->where([ ['ConsultOrder.companyNo',"=",$companyNo], ["ConsultOrder.is_del","=",0], ["tax_status","=",0], ["ConsultBids.is_del","=",0], ]) ->count(); } }