Browse Source

【临时脚本】将业务公司数据同步到结算平台

wufeng 2 years ago
parent
commit
fb3ce52b21
2 changed files with 103 additions and 0 deletions
  1. 1 0
      app/admin/common/User.php
  2. 102 0
      app/command/TempHandleBusinessData.php

+ 1 - 0
app/admin/common/User.php

@@ -61,6 +61,7 @@ class User
         'cTitle' => 'cTitle',
         'getCodeAndName' => 'getCodeAndName',
         'upgrade' => 'supplerUpgrade',
+        'get_business_list_tmp' => 'get_business_list_tmp',
         //组织架构
         'ulist'=>'ulist',
         'add'=>'add',

+ 102 - 0
app/command/TempHandleBusinessData.php

@@ -0,0 +1,102 @@
+<?php
+
+namespace app\command;
+
+use app\admin\common\User;
+use think\console\Command;
+use think\console\Input;
+use think\console\Output;
+use think\Exception;
+use think\facade\Cache;
+use think\facade\Db;
+
+class TempHandleBusinessData extends Command
+{
+
+    private $key = 'temp_handle_business_data_lock_key';
+
+    protected function configure()
+    {
+        // 指令配置
+        $this->setName('TempHandleBusinessData')
+            ->setDescription('将业务公司数据同步到结算平台');
+    }
+
+    protected function execute(Input $input, Output $output)
+    {
+        $tmp = Cache::store('redis')->handler()->get($this->key);
+
+        if ($tmp) return '';//不执行
+
+        Cache::store('redis')->handler()->setex($this->key, 5 * 60, 1);
+
+        try {
+
+            $userCommon = new User();
+            $rs = $userCommon->handle('get_business_list_tmp', ['where' => [
+                ['addtime', '>=', date('Y-m-d H:i:s', time() - 5 * 60)],
+            ]]);
+
+            if (isset($rs['code']) && $rs['code'] == 0 && !empty($rs['data'])) {
+
+                $all_code = array_column($rs['data'], 'companyNo');
+
+                //获取结算平台已存在的编码
+                $exists = Db::connect('mysql_cxinv')
+                    ->table('cfp_company_info')
+                    ->whereIn('companyNo', $all_code)
+                    ->column('id', 'companyNo');
+
+                $insert = [];
+                foreach ($rs['data'] as $item) {
+                    if (!isset($exists[$item['companyNo']])) {
+                        $insert[] = [
+                            'companyNo' => $item['companyNo'],
+                            'company_name' => $item['company'],
+                            'company_address' => $item['addr'],
+                            'company_license' => $item['inv_code'],
+                            'bank_name' => $item['inv_bank'],
+                            'bankNo' => $item['inv_bankNo'],
+                            'contector' => $item['inv_legaler'],
+                            'mobile' => $item['mobile'],
+                            'company_img' => $item['license_img'],
+                            'status' => $item['status'],
+                            'is_del' => $item['is_del'],
+                            'addtime' => $item['addtime'],
+                            'updatetime' => $item['updatetime'],
+                            //以下字段天空字符串,需要用户在结算平台补充值
+                            'input_ticket' => '',
+                            'out_ticket' => '',
+                            'voider' => '',
+                            'payee' => '',
+                            'drawer' => '',
+                            'reviewer' => '',
+                            'ownerPlace' => '',
+                            'denomination' => '',
+                            'invoiceType' => '',
+                        ];
+                    }
+                }
+
+                if ($insert) {
+                    $res = Db::connect('mysql_cxinv')
+                        ->table('cfp_company_info')
+                        ->insertAll($insert);
+                    $output->writeln('同步业务公司数据成功,共' . $res);
+                }
+
+            }
+
+            Cache::store('redis')->handler()->set($this->key, 0);
+
+        } catch (Exception $exception) {
+
+            Cache::store('redis')->handler()->set($this->key, 0);
+
+            $output->writeln('脚本出错,' . $exception->getMessage() . '|' . $exception->getFile() . ':' . $exception->getLine());
+
+        }
+
+    }
+
+}