TempHandleBusinessData.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\command;
  3. use app\admin\common\User;
  4. use think\console\Command;
  5. use think\console\Input;
  6. use think\console\Output;
  7. use think\Exception;
  8. use think\facade\Cache;
  9. use think\facade\Db;
  10. class TempHandleBusinessData extends Command
  11. {
  12. private $key = 'temp_handle_business_data_lock_key';
  13. protected function configure()
  14. {
  15. // 指令配置
  16. $this->setName('TempHandleBusinessData')
  17. ->setDescription('将业务公司数据同步到结算平台');
  18. }
  19. protected function execute(Input $input, Output $output)
  20. {
  21. $tmp = Cache::store('redis')->handler()->get($this->key);
  22. if ($tmp) return '';//不执行
  23. Cache::store('redis')->handler()->set($this->key,1,5*60);
  24. try {
  25. $userCommon = new User();
  26. $rs = $userCommon->handle('get_business_list_tmp', ['where' => [
  27. ['addtime', '>=', date('Y-m-d H:i:s', time() - 5 * 60)],
  28. ]]);
  29. if (isset($rs['code']) && $rs['code'] == 0 && !empty($rs['data'])) {
  30. $all_code = array_column($rs['data'], 'companyNo');
  31. //获取结算平台已存在的编码
  32. $exists = Db::connect('mysql_cxinv')
  33. ->table('cfp_company_info')
  34. ->whereIn('companyNo', $all_code)
  35. ->column('id', 'companyNo');
  36. $insert = [];
  37. foreach ($rs['data'] as $item) {
  38. if (!isset($exists[$item['companyNo']])) {
  39. $insert[] = [
  40. 'companyNo' => $item['companyNo'],
  41. 'company_name' => $item['company'],
  42. 'company_address' => $item['addr'],
  43. 'company_license' => $item['inv_code'],
  44. 'bank_name' => $item['inv_bank'],
  45. 'bankNo' => $item['inv_bankNo'],
  46. 'contector' => $item['inv_legaler'],
  47. 'mobile' => $item['mobile'],
  48. 'company_img' => $item['license_img'],
  49. 'status' => 0,//默认禁用,需要在结算平台启用
  50. 'is_del' => $item['is_del'],
  51. 'addtime' => $item['addtime'],
  52. 'updatetime' => $item['updatetime'],
  53. 'invoice_title' => $item['invoice_title'],
  54. //以下字段填空字符串,需要用户在结算平台补充值
  55. 'input_ticket' => '',
  56. 'out_ticket' => '',
  57. 'voider' => '',
  58. 'payee' => '',
  59. 'drawer' => '',
  60. 'reviewer' => '',
  61. 'ownerPlace' => '',
  62. 'denomination' => '',
  63. 'invoiceType' => '',
  64. ];
  65. }
  66. }
  67. if ($insert) {
  68. $res = Db::connect('mysql_cxinv')
  69. ->table('cfp_company_info')
  70. ->insertAll($insert);
  71. $output->writeln('同步业务公司数据成功,共' . $res);
  72. }
  73. }
  74. Cache::store('redis')->handler()->set($this->key, 0);
  75. } catch (Exception $exception) {
  76. Cache::store('redis')->handler()->set($this->key, 0);
  77. $output->writeln('脚本出错,' . $exception->getMessage() . '|' . $exception->getFile() . ':' . $exception->getLine());
  78. }
  79. }
  80. }