123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- <?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;
- class copydata 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("cgdjl");
- if($iscgd==0){
- $redis->set("cgdjl",1,1200);
- }else{
- return;
- }
- $this->db =Db::connect("mysql2");
- $data = $this->GetData();
- $list=[];
- foreach ($data as $key=>$value){
- $temp=[];
- $staff1 = $value['StaffSelector1618885082387']!=""? json_decode($value['StaffSelector1618885082387'],true):"";
- $staff2 = $value['StaffSelector1620899427104']!="" ? json_decode($value['StaffSelector1620899427104'],true):"";
- if($staff1 !=""&&isset($staff1[0])&& $staff1[0]['id']!=""){
- $user = $this->GetUserInfo($staff1[0]['id']);
- $value['StaffSelector1618885082387'] = array_merge($user,$staff1[0]);
- }
- if( $staff2 !=""&&isset($staff2[0]) &&$staff2[0]['id']!=""){
- $user = $this->GetUserInfo($staff2[0]['id']);
- $value['StaffSelector1620899427104'] = array_merge($user,$staff2[0]);
- }
- if($value['creater']!=""){
- $user = $this->GetUserInfo($value['creater']);
- $value['creater'] =isset($user['name']) ? $user['name'] : "";
- }
- if($value['createdDeptId']!=""){
- $user = $this->GetDepart($value['createdDeptId']);
- $value['createdDeptId'] =isset($user['name']) ? $user['name'] : "";
- }
- if($value['ShortText1618315935182']!=""){
- $hkhp = $this->GetHkHp($value['ShortText1618315935182'],1);
- if(!empty($hkhp)){
- $value['Number1618330470625'] = $hkhp['pay_fee'];
- $value['Number1618330472961'] =$value['Number1618240685904']- $hkhp['pay_fee'];
- $value['ShortText1619463188366'] = $value['Number1618240685904']==$hkhp['pay_fee'] ? "3":"1";
- }
- $hkhp = $this->GetHkHp($value['ShortText1618315935182'],2);
- if(!empty($hkhp)){
- $value['Number1618330541286'] = $hkhp['inv_fee'];
- $value['Number1618330543270'] =$value['Number1618240685904']- $hkhp['inv_fee'];
- $value['ShortText1619463208482'] = $value['Number1618240685904']==$hkhp['inv_fee'] ? "3":"1";
- }
- }
- $temp['data']=json_encode($value,JSON_UNESCAPED_UNICODE);
- $temp['uniqkey']=$value['id'];
- $temp['addtime']=date("Y-m-d H:i:s");
- $temp['createtime']=date("Y-m-d H:i:s");
- $temp['status']=1;
- $isT= Db::table("source_data")->where("uniqkey","=",$value['id'])->count("id");
- if($isT==0){
- Db::table("source_data")->insert($temp);
- }
- }
- $redis->set("cgdjl",0);
- $output->writeln('CopyData');
- }
- protected function GetData(){
- $date = date("Y-m-d H:i:s",strtotime("-3 day"));
- $table = $this->db->table("biz_workflow_instance")->alias("w")->join('iw48m_CGDJL c','w.id = c.workflowInstanceId',"left")
- ->where("appCode = 'purchase' AND schemaCode = 'CGDJL' and c.sequenceStatus='COMPLETED' and w.startTime>'{$date}'")->field(" w.id,
- w.instanceName,
- w.departmentName,
- w.originatorName,
- w.finishTime,
- w.startTime,
- w.sequenceNo,
- w.appCode,
- w.id,
- c.`name`,
- c.`creater`,
- c.`createdDeptId`,
- c.sequenceStatus,
- c.createdTime,
- c.ShortText1618270412964,
- c.ShortText1618270466672,
- c.number1618272663951,
- c.ShortText1618308753677,
- c.ShortText1618315935182,
- c.Date1618315953443,
- c.Number1618316157066,
- c.Number1618316171848,
- c.ShortText1617866362204,
- c.ShortText1617866360004,
- c.ShortText1618239976714,
- c.ShortText1617866364821,
- c.ShortText1618239993162,
- c.RelevanceForm1617860945268,
- c.ShortText1617861001482,
- c.ShortText1617861966146,
- c.ShortText1617865626160,
- c.ShortText1617865633070,
- c.ShortText1617865678025,
- c.ShortText1617865675342,
- c.ShortText1617865680605,
- c.ShortText1617865683042,
- c.text1618268357055,
- c.ShortText1617865685744,
- c.Number1618240480148,
- c.ShortText1618240134229,
- c.Number1618240458074,
- c.ShortText1617866158120,
- c.Number1618240350696,
- c.number1618240356104,
- c.ShortText1617865688485,
- c.Number1617865804813,
- c.Number1617865807879,
- c.Number1617865810822,
- c.Number1617865813284,
- c.Number1617865816181,
- c.number1618240204358,
- c.number1618240287778,
- c.Number1617865818517,
- c.Number1617865824797,
- c.ShortText1617866144054,
- c.Number1618240600907,
- c.Number1618240685904,
- c.RelevanceForm1617861284547,
- c.ShortText1617861287265,
- c.ShortText1617861449444,
- c.Date1617866234869,
- c.ShortText1617861455145,
- c.Date1618324547052,
- c.Number1618330470625,
- c.Number1618330541286,
- c.Number1618330472961,
- c.Number1618330543270,
- c.ShortText1618465932373,
- c.number1618467257146,
- c.ShortText1618859161646,
- c.Date1618859180209,
- c.StaffSelector1618859194105,
- c.ShortText1618859321070,
- c.StaffSelector1618885082387,
- c.ShortText1618900704399,
- c.Date1619009560712,
- c.ShortText1619147112929,
- c.ShortText1619164207953,
- c.ShortText1619463188366,
- c.ShortText1619463208482,
- c.Date1619624209148,
- c.ShortText1619624490635,
- c.Number1619625470651,
- c.Number1619625483510,
- c.ShortText1619625566608,
- c.Number1619632830397,
- c.Number1619632826654,
- c.RelevanceForm1620373842422,
- c.ShortText1620399144946,
- c.ShortText1620753234895,
- c.ShortText1620753237335,
- c.StaffSelector1620899427104")->select();
- echo $this->db->getLastSql();
- return $table;
- }
- protected function GetUserInfo($ksy){
- $userinfo = $this->db->table("h_org_user")->where("id","=",$ksy)->field("name,mobile,username")->find();
- return $userinfo;
- }
- protected function GetDepart($ksy){
- $userinfo = $this->db->table("h_org_department")->where("id","=",$ksy)->field("name")->find();
- return $userinfo;
- }
- protected function GetHkHp($cgdCode,$type=1){
- $condition=[];
- $condition[]=["ShortText1617816811172","=",$cgdCode];
- $condition[]=["ShortText1615789379545","=",$type==1?"付款":"回票"];
- $condition[]=["sequenceStatus","=","COMPLETED"];
- $userinfo = $this->db->table("iw48m_CGFKHPMX_form")->where($condition)->field("sum(number1617817090573) as pay_fee,sum(number1617817077461) as inv_fee")->find();
- return $userinfo;
- }
- }
|