copydata.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. class copydata extends Command
  12. {
  13. protected $db="";
  14. protected function configure()
  15. {
  16. // 指令配置
  17. $this->setName('CopyData')
  18. ->setDescription('the CopyData command');
  19. }
  20. protected function execute(Input $input, Output $output)
  21. {
  22. // 指令输php出
  23. $redis = Cache::store('redis');
  24. $iscgd = $redis->get("cgdjl");
  25. if($iscgd==0){
  26. $redis->set("cgdjl",1,1200);
  27. }else{
  28. return;
  29. }
  30. $this->db =Db::connect("mysql2");
  31. $data = $this->GetData();
  32. $list=[];
  33. foreach ($data as $key=>$value){
  34. $temp=[];
  35. $staff1 = $value['StaffSelector1618885082387']!=""? json_decode($value['StaffSelector1618885082387'],true):"";
  36. $staff2 = $value['StaffSelector1620899427104']!="" ? json_decode($value['StaffSelector1620899427104'],true):"";
  37. if($staff1 !=""&&isset($staff1[0])&& $staff1[0]['id']!=""){
  38. $user = $this->GetUserInfo($staff1[0]['id']);
  39. $value['StaffSelector1618885082387'] = array_merge($user,$staff1[0]);
  40. }
  41. if( $staff2 !=""&&isset($staff2[0]) &&$staff2[0]['id']!=""){
  42. $user = $this->GetUserInfo($staff2[0]['id']);
  43. $value['StaffSelector1620899427104'] = array_merge($user,$staff2[0]);
  44. }
  45. if($value['creater']!=""){
  46. $user = $this->GetUserInfo($value['creater']);
  47. $value['creater'] =isset($user['name']) ? $user['name'] : "";
  48. }
  49. if($value['createdDeptId']!=""){
  50. $user = $this->GetDepart($value['createdDeptId']);
  51. $value['createdDeptId'] =isset($user['name']) ? $user['name'] : "";
  52. }
  53. if($value['ShortText1618315935182']!=""){
  54. $hkhp = $this->GetHkHp($value['ShortText1618315935182'],1);
  55. if(!empty($hkhp)){
  56. $value['Number1618330470625'] = $hkhp['pay_fee'];
  57. $value['Number1618330472961'] =$value['Number1618240685904']- $hkhp['pay_fee'];
  58. $value['ShortText1619463188366'] = $value['Number1618240685904']==$hkhp['pay_fee'] ? "3":"1";
  59. }
  60. $hkhp = $this->GetHkHp($value['ShortText1618315935182'],2);
  61. if(!empty($hkhp)){
  62. $value['Number1618330541286'] = $hkhp['inv_fee'];
  63. $value['Number1618330543270'] =$value['Number1618240685904']- $hkhp['inv_fee'];
  64. $value['ShortText1619463208482'] = $value['Number1618240685904']==$hkhp['inv_fee'] ? "3":"1";
  65. }
  66. }
  67. $temp['data']=json_encode($value,JSON_UNESCAPED_UNICODE);
  68. $temp['uniqkey']=$value['id'];
  69. $temp['addtime']=date("Y-m-d H:i:s");
  70. $temp['createtime']=date("Y-m-d H:i:s");
  71. $temp['status']=1;
  72. $isT= Db::table("source_data")->where("uniqkey","=",$value['id'])->count("id");
  73. if($isT==0){
  74. Db::table("source_data")->insert($temp);
  75. }
  76. }
  77. $redis->set("cgdjl",0);
  78. $output->writeln('CopyData');
  79. }
  80. protected function GetData(){
  81. $date = date("Y-m-d H:i:s",strtotime("-3 day"));
  82. $table = $this->db->table("biz_workflow_instance")->alias("w")->join('iw48m_CGDJL c','w.id = c.workflowInstanceId',"left")
  83. ->where("appCode = 'purchase' AND schemaCode = 'CGDJL' and c.sequenceStatus='COMPLETED' and w.startTime>'{$date}'")->field(" w.id,
  84. w.instanceName,
  85. w.departmentName,
  86. w.originatorName,
  87. w.finishTime,
  88. w.startTime,
  89. w.sequenceNo,
  90. w.appCode,
  91. w.id,
  92. c.`name`,
  93. c.`creater`,
  94. c.`createdDeptId`,
  95. c.sequenceStatus,
  96. c.createdTime,
  97. c.ShortText1618270412964,
  98. c.ShortText1618270466672,
  99. c.number1618272663951,
  100. c.ShortText1618308753677,
  101. c.ShortText1618315935182,
  102. c.Date1618315953443,
  103. c.Number1618316157066,
  104. c.Number1618316171848,
  105. c.ShortText1617866362204,
  106. c.ShortText1617866360004,
  107. c.ShortText1618239976714,
  108. c.ShortText1617866364821,
  109. c.ShortText1618239993162,
  110. c.RelevanceForm1617860945268,
  111. c.ShortText1617861001482,
  112. c.ShortText1617861966146,
  113. c.ShortText1617865626160,
  114. c.ShortText1617865633070,
  115. c.ShortText1617865678025,
  116. c.ShortText1617865675342,
  117. c.ShortText1617865680605,
  118. c.ShortText1617865683042,
  119. c.text1618268357055,
  120. c.ShortText1617865685744,
  121. c.Number1618240480148,
  122. c.ShortText1618240134229,
  123. c.Number1618240458074,
  124. c.ShortText1617866158120,
  125. c.Number1618240350696,
  126. c.number1618240356104,
  127. c.ShortText1617865688485,
  128. c.Number1617865804813,
  129. c.Number1617865807879,
  130. c.Number1617865810822,
  131. c.Number1617865813284,
  132. c.Number1617865816181,
  133. c.number1618240204358,
  134. c.number1618240287778,
  135. c.Number1617865818517,
  136. c.Number1617865824797,
  137. c.ShortText1617866144054,
  138. c.Number1618240600907,
  139. c.Number1618240685904,
  140. c.RelevanceForm1617861284547,
  141. c.ShortText1617861287265,
  142. c.ShortText1617861449444,
  143. c.Date1617866234869,
  144. c.ShortText1617861455145,
  145. c.Date1618324547052,
  146. c.Number1618330470625,
  147. c.Number1618330541286,
  148. c.Number1618330472961,
  149. c.Number1618330543270,
  150. c.ShortText1618465932373,
  151. c.number1618467257146,
  152. c.ShortText1618859161646,
  153. c.Date1618859180209,
  154. c.StaffSelector1618859194105,
  155. c.ShortText1618859321070,
  156. c.StaffSelector1618885082387,
  157. c.ShortText1618900704399,
  158. c.Date1619009560712,
  159. c.ShortText1619147112929,
  160. c.ShortText1619164207953,
  161. c.ShortText1619463188366,
  162. c.ShortText1619463208482,
  163. c.Date1619624209148,
  164. c.ShortText1619624490635,
  165. c.Number1619625470651,
  166. c.Number1619625483510,
  167. c.ShortText1619625566608,
  168. c.Number1619632830397,
  169. c.Number1619632826654,
  170. c.RelevanceForm1620373842422,
  171. c.ShortText1620399144946,
  172. c.ShortText1620753234895,
  173. c.ShortText1620753237335,
  174. c.StaffSelector1620899427104")->select();
  175. echo $this->db->getLastSql();
  176. return $table;
  177. }
  178. protected function GetUserInfo($ksy){
  179. $userinfo = $this->db->table("h_org_user")->where("id","=",$ksy)->field("name,mobile,username")->find();
  180. return $userinfo;
  181. }
  182. protected function GetDepart($ksy){
  183. $userinfo = $this->db->table("h_org_department")->where("id","=",$ksy)->field("name")->find();
  184. return $userinfo;
  185. }
  186. protected function GetHkHp($cgdCode,$type=1){
  187. $condition=[];
  188. $condition[]=["ShortText1617816811172","=",$cgdCode];
  189. $condition[]=["ShortText1615789379545","=",$type==1?"付款":"回票"];
  190. $condition[]=["sequenceStatus","=","COMPLETED"];
  191. $userinfo = $this->db->table("iw48m_CGFKHPMX_form")->where($condition)->field("sum(number1617817090573) as pay_fee,sum(number1617817077461) as inv_fee")->find();
  192. return $userinfo;
  193. }
  194. }