123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- declare (strict_types = 1);
- namespace app\command;
- use think\console\Command;
- use think\console\Input;
- use think\console\input\Argument;
- use think\console\input\Option;
- use think\console\Output;
- use think\facade\Cache;
- use think\facade\Db;
- use app\Admin\model\CustomerInfo;
- class customer extends Command
- {
- protected $db="";
- protected function configure()
- {
- // 指令配置
- $this->setName('CopyData')
- ->setDescription('the CopyData command');
- }
- protected function execute(Input $input, Output $output)
- {
- // 指令输php出.
- $redis = Cache::store('redis');
- $iscgd = $redis->get("customer");
- if($iscgd==0){
- $redis->set("customer",1,1200);
- }else{
- return;
- }
- $this->db =Db::connect("mysql2");
- $data = $this->GetData();
- $list=[];
- $customer = new CustomerInfo();
- foreach ($data as $key=>$value){
- $relas = $customer->where("companyNo","=",$value['companyNo'])->find();
- $inv=Db::name("customer_invoice")->where([['is_del',"=",0],['invoice_code',"=",$value['invoice_code']]])
- ->find();
- if($relas){
- $customer->where("companyNo","=",$value['companyNo'])->save($value);
- }else{
- $customer->insert($value);
- }
- if($inv){
- continue;
- }else{
- if($value['invoice_code']==""){
- continue;
- }
- $invv=[
- "invoice_title"=>$value['invoice_title'],
- "invoice_people"=>$value['invoice_people'],
- "invoice_addr"=>$value['invoice_addr'],
- "invoice_mobile"=>$value['invoice_mobile'],
- "invoice_code"=>$value['invoice_code'],
- "invoice_bank"=>$value['invoice_bank'],
- "invoice_bankNo"=>$value['invoice_bankNo'],
- "is_del"=>0,
- "addtime"=>$value['addtime'],
- "updatetime"=>$value['updatetime']
- ];
- Db::name("customer_invoice")->insert($invv);
- }
- }
- $redis->set("customer",0);
- $output->writeln('CopyData');
- }
- private function GetData(){
- $date = date("Y-m-d H:i:s",strtotime("-1 day"));
- $data = $this->db->table("il150_Customer_info")->alias('a')->where("modifiedTime",">=", $date)
- ->field("
- sequenceNo as companyNo,
- IF(`sequenceStatus` ='COMPLETED',1,0)
- as status,
- ShortText1614738964782 as companyName,
- ifnull(ShortText1615282447896,'') as comdepart,
- ifnull(text1615282721984,'') commobile,
- ifnull(text1615282728065,'') comtel,
- ifnull(text1615282771211,'') contactor,
- ifnull(text1615282776035,'') depart,
- ifnull(text1615282780018,'') mobile,
- ifnull((SELECT
- b_.`name`
- FROM
- h_org_user b_
- WHERE b_.id = JSON_EXTRACT (
- StaffSelector1616982886492,
- '$[0].id'
- )),'') AS sales_name,
- ifnull((SELECT
- b_.`name`
- FROM
- h_org_department b_
- WHERE b_.id = JSON_EXTRACT (
- StaffSelector1616982890501,
- '$[0].id'
- )),'') AS sales_depart,
- ifnull(text1615283088459,'') invoice_title,
- ifnull(text1615283102439,'') invoice_people,
- ifnull(text1615283117386,'') invoice_code,
- ifnull(text1615283125769,'') invoice_addr,
- ifnull(text1615283140950,'') invoice_mobile,
- ifnull(text1615283155377,'') invoice_bank,
- ifnull(text1615283198972,'') companyCode,
- ifnull(ShortText1617171368467,'') invoice_bankNo,
- ifnull(ShortText1618901742599,'') parent,
- ifnull(text1619411877719,'') branch,
- ifnull(text1619411907247,'') middle,
- ifnull(text1619411907991,'') country ,
- ifnull(text1619521602702 ,'') area,
- createdTime addtime,
- modifiedTime updatetime,
- (SELECT
- b_.`name`
- FROM
- h_org_user b_
- WHERE b_.id = a.modifier
- ) AS modifier,
- (SELECT
- b_.`name`
- FROM
- h_org_user b_
- WHERE b_.id = a.creater
- ) AS creater
- ")->select()->toArray();
- return $data;
- }
- }
|