| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- declare (strict_types = 1);
- namespace app\command;
- use app\common\model\merchant\apply\MerchantHaikeApply;
- use app\common\repositories\system\merchant\MerchantIntentionRepository;
- use app\traits\HaikeApiRequest;
- use crmeb\services\YunxinSmsService;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- use think\facade\Log;
- class HaikeSendsms extends Command
- {
- use HaikeApiRequest;
- protected function configure()
- {
- // 指令配置
- $this->setName('haikesendsms')
- ->setDescription('the haikesendsms command');
- }
- protected function execute(Input $input, Output $output)
- {
- Log::info('haikesendsms:start');
- try {
- $MerchantIntentionRepository = app()->make(MerchantIntentionRepository::class);
- $query = MerchantHaikeApply::getDB()
- ->where('applysms', 0)
- ->where('authsms', 0)
- ->where('trade_type', 'WXAUTHAPPLY')
- ->whereNotNull('wx_merch_no');
- $query->chunk(100, function ($applys) use($MerchantIntentionRepository) {
- foreach ($applys as $apply) {
- if ($apply->check_result == '已授权') {
- if (!$apply->authsms){
- $apply->check_result = '已授权';
- $apply->authsms = 1;
- $apply->save();
- $return = $MerchantIntentionRepository->createMer($apply->apply_id);
- if ($return['code'] == 200) {
- $MerchantIntentionRepository->update($apply->apply_id, ['status' => 1,'check_result' => '已授权', 'mer_id' => $return['data']]);
- } else {
- Log::info('创建商户失败:'.$return['msg']);
- }
- Log::info('id:'.$apply->id);
- YunxinSmsService::sendMessage('HAIKE_CHECK_WX_AUTH_SUCCESS_CODE', $apply->id);
- }
- } else if (!empty($apply->check_result) && $apply->check_result != '已授权') {
- if (!$apply->applysms){
- $apply->check_result = $apply->check_result;
- $apply->applysms = 1;
- $apply->save();
- YunxinSmsService::sendMessage('HAIKE_CHECK_FAIL_CODE', $apply->id);
- }
- }
- }
- });
- } catch (\Throwable $e) {
- Log::info('haikesendsms:error'.$e->getMessage());
- $output->writeln('执行失败'.$e->getMessage());
- return app('json')->fail($e->getMessage());
- }
- Log::info('haikesendsms:end');
- $output->writeln('执行成功');
- }
- }
|