customer.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\command;
  4. use think\console\Command;
  5. use think\console\Input;
  6. use think\console\input\Argument;
  7. use think\console\input\Option;
  8. use think\console\Output;
  9. use think\facade\Cache;
  10. use think\facade\Db;
  11. use app\Admin\model\CustomerInfo;
  12. class customer extends Command
  13. {
  14. protected $db="";
  15. protected function configure()
  16. {
  17. // 指令配置
  18. $this->setName('CopyData')
  19. ->setDescription('the CopyData command');
  20. }
  21. protected function execute(Input $input, Output $output)
  22. {
  23. // 指令输php出.
  24. $redis = Cache::store('redis');
  25. $iscgd = $redis->get("customer");
  26. if($iscgd==0){
  27. $redis->set("customer",1,1200);
  28. }else{
  29. return;
  30. }
  31. $this->db =Db::connect("mysql2");
  32. $data = $this->GetData();
  33. $list=[];
  34. $customer = new CustomerInfo();
  35. foreach ($data as $key=>$value){
  36. $relas = $customer->where("companyNo","=",$value['companyNo'])->find();
  37. $inv=Db::name("customer_invoice")->where([['is_del',"=",0],['invoice_code',"=",$value['invoice_code']]])
  38. ->find();
  39. if($relas){
  40. $customer->where("companyNo","=",$value['companyNo'])->save($value);
  41. }else{
  42. $customer->insert($value);
  43. }
  44. if($inv){
  45. continue;
  46. }else{
  47. if($value['invoice_code']==""){
  48. continue;
  49. }
  50. $invv=[
  51. "invoice_title"=>$value['invoice_title'],
  52. "invoice_people"=>$value['invoice_people'],
  53. "invoice_addr"=>$value['invoice_addr'],
  54. "invoice_mobile"=>$value['invoice_mobile'],
  55. "invoice_code"=>$value['invoice_code'],
  56. "invoice_bank"=>$value['invoice_bank'],
  57. "invoice_bankNo"=>$value['invoice_bankNo'],
  58. "is_del"=>0,
  59. "addtime"=>$value['addtime'],
  60. "updatetime"=>$value['updatetime']
  61. ];
  62. Db::name("customer_invoice")->insert($invv);
  63. }
  64. }
  65. $redis->set("customer",0);
  66. $output->writeln('CopyData');
  67. }
  68. private function GetData(){
  69. $date = date("Y-m-d H:i:s",strtotime("-1 day"));
  70. $data = $this->db->table("il150_Customer_info")->alias('a')->where("modifiedTime",">=", $date)
  71. ->field("
  72. sequenceNo as companyNo,
  73. IF(`sequenceStatus` ='COMPLETED',1,0)
  74. as status,
  75. ShortText1614738964782 as companyName,
  76. ifnull(ShortText1615282447896,'') as comdepart,
  77. ifnull(text1615282721984,'') commobile,
  78. ifnull(text1615282728065,'') comtel,
  79. ifnull(text1615282771211,'') contactor,
  80. ifnull(text1615282776035,'') depart,
  81. ifnull(text1615282780018,'') mobile,
  82. ifnull((SELECT
  83. b_.`name`
  84. FROM
  85. h_org_user b_
  86. WHERE b_.id = JSON_EXTRACT (
  87. StaffSelector1616982886492,
  88. '$[0].id'
  89. )),'') AS sales_name,
  90. ifnull((SELECT
  91. b_.`name`
  92. FROM
  93. h_org_department b_
  94. WHERE b_.id = JSON_EXTRACT (
  95. StaffSelector1616982890501,
  96. '$[0].id'
  97. )),'') AS sales_depart,
  98. ifnull(text1615283088459,'') invoice_title,
  99. ifnull(text1615283102439,'') invoice_people,
  100. ifnull(text1615283117386,'') invoice_code,
  101. ifnull(text1615283125769,'') invoice_addr,
  102. ifnull(text1615283140950,'') invoice_mobile,
  103. ifnull(text1615283155377,'') invoice_bank,
  104. ifnull(text1615283198972,'') companyCode,
  105. ifnull(ShortText1617171368467,'') invoice_bankNo,
  106. ifnull(ShortText1618901742599,'') parent,
  107. ifnull(text1619411877719,'') branch,
  108. ifnull(text1619411907247,'') middle,
  109. ifnull(text1619411907991,'') country ,
  110. ifnull(text1619521602702 ,'') area,
  111. createdTime addtime,
  112. modifiedTime updatetime,
  113. (SELECT
  114. b_.`name`
  115. FROM
  116. h_org_user b_
  117. WHERE b_.id = a.modifier
  118. ) AS modifier,
  119. (SELECT
  120. b_.`name`
  121. FROM
  122. h_org_user b_
  123. WHERE b_.id = a.creater
  124. ) AS creater
  125. ")->select()->toArray();
  126. return $data;
  127. }
  128. }