supplier.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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\Db;
  10. class supplier extends Command
  11. {
  12. protected $db="";
  13. protected function configure()
  14. {
  15. // 指令配置
  16. $this->setName('supplier')
  17. ->setDescription('the CopyData command');
  18. }
  19. protected function execute(Input $input, Output $output)
  20. {
  21. // 指令输php出
  22. $this->db =Db::connect("mysql2");
  23. $data = $this->GetData();
  24. $list=[];
  25. foreach ($data as $key=>$value){
  26. $relas = Db::name('supplier_info')->where("code","=",$value['code'])->find();
  27. if($relas){
  28. Db::name('supplier_info')->where("code","=",$value['code'])->save($value);
  29. }else{
  30. Db::name('supplier_info')->insert($value);
  31. }
  32. }
  33. $output->writeln('CopyData');
  34. }
  35. private function GetData(){
  36. $date = date("Y-m-d H:i:s",strtotime("-1 day"));
  37. $data = $this->db->table("iw48m_Supplier_info")->alias('a')->where("a.modifiedTime",">=",$date)
  38. ->field("name,
  39. ifnull(sequenceNo,'') as code,
  40. ifnull(ShortText1614742711656,'') 'source',
  41. ifnull(text1614751047046,'') 'contector',
  42. ifnull(text1614751060372,'') 'post',
  43. ifnull(dropdown1614742750833,'') 'type',
  44. ifnull(dropdown1614750342128,'') 'nature',
  45. ifnull(text1614742995718,'') 'corporation',
  46. ifnull(dropdown1614750626613,'') 'pay_method',
  47. ifnull(ShortText1617870922867,0) 'paydays',
  48. ifnull(number1614751108814,'') 'mobile',
  49. ifnull(ShortText1617870495099,'') 'address',
  50. ifnull(dropdown1614750757071,'') 'return_ticket',
  51. ifnull(dropdown1614751201116,'') 'delivery',
  52. 1 'status',
  53. createdTime 'addtime',
  54. modifiedTime 'updatetime'")->select()->toArray();
  55. return $data;
  56. }
  57. }