123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- declare (strict_types = 1);
- namespace app\command;
- use app\admin\model\ConsultBids;
- use app\admin\model\GoodBasic;
- use app\bug\model\WechatSetPush;
- use app\user\model\User;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;
- class GoodCatCheck extends Command
- {
- protected $templateInfo;
- protected function configure()
- {
- // 指令配置
- $this->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();
- }
- }
|