GoodCatCheck.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\command;
  4. use app\admin\model\ConsultBids;
  5. use app\admin\model\GoodBasic;
  6. use app\bug\model\WechatSetPush;
  7. use app\user\model\User;use think\console\Command;
  8. use think\console\Input;
  9. use think\console\input\Argument;
  10. use think\console\input\Option;
  11. use think\console\Output;use think\facade\Cache;
  12. class GoodCatCheck extends Command
  13. {
  14. protected $templateInfo;
  15. protected function configure()
  16. {
  17. // 指令配置
  18. $this->setName('goodcatcheck')
  19. ->setDescription('the goodcatcheck command');
  20. }
  21. protected function execute(Input $input, Output $output)
  22. {
  23. $output->writeln('【'.date('Y-m-d H:i:s').'】开始执行商品开票税目检查');
  24. try{
  25. $this->check();
  26. }catch (\Exception $e){
  27. $output->writeln('【'.date('Y-m-d H:i:s').'】执行商品开票税目检查失败');
  28. $output->writeln($e->getMessage());
  29. }
  30. }
  31. protected function check(){
  32. $info = WechatSetPush::where('id',1)->findOrEmpty();
  33. if($info->isEmpty()||empty($info->push_user_info)){
  34. throw new \Exception('推送信息未配置');
  35. }
  36. if($info->status==0)throw new \Exception('推送状态未开启');
  37. $this->templateInfo = $info;
  38. foreach($info->push_user_info as $k=>$v){
  39. $this->processCount($v,"GoodBasic");
  40. $this->processCount($v,"ConsultBids");
  41. }
  42. }
  43. protected function processCount($user,$method){
  44. $companyNo = $user['companyNo'];
  45. $goodBasicNum = call_user_func([$this,"Get".$method."Num"],$companyNo);
  46. if($goodBasicNum>0){
  47. $this->sendMessage($user,$method,$goodBasicNum);
  48. }
  49. }
  50. protected function sendMessage($user,$method,$goodBasicNum){
  51. $methodArr = [
  52. "GoodBasic"=>"商品成本待财务审核",
  53. "ConsultBids"=>"咨询商品待财务审核"
  54. ];
  55. $company = $user['companyName']??"";
  56. $temp = [
  57. 'thing18'=>['value'=>$methodArr[$method]],
  58. 'thing24'=>['value'=>$company],
  59. 'thing10'=>['value'=>"待财务审核"],
  60. 'character_string26'=>['value'=>$goodBasicNum],
  61. 'time25'=>['value'=>date('Y-m-d H:i:s')],
  62. ];
  63. if(!empty($user['pushinfo'])){
  64. foreach($user['pushinfo'] as $k=>$v){
  65. $temps=[
  66. 'code'=>date('YmdHis'),
  67. 'belong'=>1,
  68. 'openId'=>$v['openId']??'',
  69. 'template_id'=>$this->templateInfo['template_id'],
  70. 'template_name'=>$this->templateInfo['template_name'],
  71. 'action_name'=>'商品税目财务设置',
  72. 'template_data'=>$temp,
  73. 'uid'=>$v['account_id'],
  74. 'uname'=>$v['nickname']??'',
  75. ];
  76. Cache::store('redis')->handler()->lpush('wxpush_queue',json_encode($temps,JSON_UNESCAPED_UNICODE));
  77. }
  78. }
  79. }
  80. protected function GetGoodBasicNum($companyNo){
  81. $where = [
  82. ['is_del','=',0],['status','=',9]
  83. ];
  84. if($companyNo!=''){
  85. $where[] = ['companyNo','=',$companyNo];
  86. }
  87. return GoodBasic::where( $where)->count();
  88. }
  89. protected function GetConsultBidsNum($companyNo){
  90. $where = [
  91. ["ConsultOrder.is_del","=",0],
  92. ["tax_status","=",0],
  93. ["consult_bids.is_del","=",0],
  94. ['ConsultInfo.bargain_status','=',0],
  95. ['ConsultInfo.status','in',[2,7]],
  96. ["ConsultInfo.is_del","=",0],
  97. ];
  98. if($companyNo!=''){
  99. $where[] = ['ConsultOrder.companyNo','=',$companyNo];
  100. }
  101. return ConsultBids::withJoin(["ConsultOrder","ConsultInfo"],"LEFT")
  102. ->where( $where ) ->count();
  103. }
  104. }