HaikeSendsms.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\command;
  4. use app\common\model\merchant\apply\MerchantHaikeApply;
  5. use app\common\repositories\system\merchant\MerchantIntentionRepository;
  6. use app\traits\HaikeApiRequest;
  7. use crmeb\services\YunxinSmsService;
  8. use think\console\Command;
  9. use think\console\Input;
  10. use think\console\Output;
  11. use think\facade\Log;
  12. class HaikeSendsms extends Command
  13. {
  14. use HaikeApiRequest;
  15. protected function configure()
  16. {
  17. // 指令配置
  18. $this->setName('haikesendsms')
  19. ->setDescription('the haikesendsms command');
  20. }
  21. protected function execute(Input $input, Output $output)
  22. {
  23. Log::info('haikesendsms:start');
  24. try {
  25. $MerchantIntentionRepository = app()->make(MerchantIntentionRepository::class);
  26. $query = MerchantHaikeApply::getDB()
  27. ->where('applysms', 0)
  28. ->where('authsms', 0)
  29. ->where('trade_type', 'WXAUTHAPPLY')
  30. ->whereNotNull('wx_merch_no');
  31. $query->chunk(100, function ($applys) use($MerchantIntentionRepository) {
  32. foreach ($applys as $apply) {
  33. if ($apply->check_result == '已授权') {
  34. if (!$apply->authsms){
  35. $apply->check_result = '已授权';
  36. $apply->authsms = 1;
  37. $apply->save();
  38. $return = $MerchantIntentionRepository->createMer($apply->apply_id);
  39. if ($return['code'] == 200) {
  40. $MerchantIntentionRepository->update($apply->apply_id, ['status' => 1,'check_result' => '已授权', 'mer_id' => $return['data']]);
  41. } else {
  42. Log::info('创建商户失败:'.$return['msg']);
  43. }
  44. Log::info('id:'.$apply->id);
  45. YunxinSmsService::sendMessage('HAIKE_CHECK_WX_AUTH_SUCCESS_CODE', $apply->id);
  46. }
  47. } else if (!empty($apply->check_result) && $apply->check_result != '已授权') {
  48. if (!$apply->applysms){
  49. $apply->check_result = $apply->check_result;
  50. $apply->applysms = 1;
  51. $apply->save();
  52. YunxinSmsService::sendMessage('HAIKE_CHECK_FAIL_CODE', $apply->id);
  53. }
  54. }
  55. }
  56. });
  57. } catch (\Throwable $e) {
  58. Log::info('haikesendsms:error'.$e->getMessage());
  59. $output->writeln('执行失败'.$e->getMessage());
  60. return app('json')->fail($e->getMessage());
  61. }
  62. Log::info('haikesendsms:end');
  63. $output->writeln('执行成功');
  64. }
  65. }