cgdmx.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 cgdmx extends Command
  12. {
  13. protected $db="";
  14. protected function configure()
  15. {
  16. // 指令配置
  17. $this->setName('cgdmx')
  18. ->setDescription('the cgdmx command');
  19. }
  20. protected function execute(Input $input, Output $output)
  21. {
  22. // 指令输出
  23. $redis = Cache::store('redis');
  24. $iscgd = $redis->get("cgdmx");
  25. if($iscgd==0){
  26. $redis->set("cgdmx",1,1200);
  27. }else{
  28. return;
  29. }
  30. $this->db =Db::connect("mysql2");
  31. $data = $this->GetData();
  32. foreach ($data as $value){
  33. $ist = Db::table("source_all")->where('cgdNo',"=",$value['cgdNo'])->find();
  34. if($ist){
  35. Db::table("source_all")->where('id',"=",$ist['id'])->save($value);
  36. }else{
  37. if($value['cgdtype']=="备库采购"){
  38. Db::table("source_all")->insert($value);
  39. }
  40. }
  41. }
  42. $redis->set("cgdmx",0);
  43. $output->writeln('cgdmx');
  44. }
  45. private function GetData(){
  46. $date =date("Y-m-d",strtotime("-12 day"));
  47. $sql="SELECT
  48. b.sequenceNo As cgdjlNo,
  49. b.ShortText1618315935182 AS cgdNo,
  50. b.ShortText1618270466672 AS company,
  51. b.Date1618315953443 AS cgdtime,
  52. b.ShortText1618270412964 AS cgdtype,
  53. b.ShortText1618465932373 as delivery_type,
  54. b.ShortText1617866144054 as is_stock,
  55. (
  56. SELECT
  57. `b_`.`name`
  58. FROM
  59. `h_org_user` `b_`
  60. WHERE
  61. ( CONVERT ( `b_`.`id` USING utf8mb4 ) = `b`.`creater` )) AS cgd_saler,
  62. b.ShortText1620399144946 AS supplier,
  63. b.ShortText1617861287265 AS supplierNo,
  64. b.ShortText1619625566608 AS paking,
  65. b.ShortText1617865688485 AS cgd_tax,
  66. round( `b`.`Number1617865810822`, 2 ) AS pakage_fee,
  67. round( `b`.`Number1617865813284`, 2 ) AS cert_fee,
  68. round( `b`.`Number1617865807879`, 2 ) AS mark_fee,
  69. round( `b`.`Number1617865816181`, 2 ) AS open_fee,
  70. round( `b`.`number1618240204358`, 2 ) AS cost_fee,
  71. round( `b`.`Number1617865804813`, 2 ) AS naked_fee,
  72. round( `b`.`number1618240287778`, 2 ) AS delivery_fee,
  73. round(`b`.`Number1619632830397`, 2 ) AS cgd_diff_weight,
  74. round( `b`.`Number1619632826654`, 2 ) AS diff_fee,
  75. round( `b`.`Number1617865818517`, 2 ) AS cgd_price,
  76. cast( `b`.`Number1618240600907` AS signed ) AS cgd_num,
  77. round( `b`.`Number1618240685904`, 2 ) AS cgd_total,
  78. round( 0, 2 ) AS cgd_cost,
  79. b.ShortText1618859161646 AS bkNo,
  80. b.Date1618859180209 AS bktime,
  81. (
  82. SELECT
  83. `b_`.`name`
  84. FROM
  85. `h_org_user` `b_`
  86. WHERE
  87. (
  88. CONVERT ( `b_`.`id` USING utf8mb4 ) = json_extract( `b`.`StaffSelector1618885082387`, '$[0].id' ))) AS saler,
  89. b.ShortText1618900704399 AS warehouse,
  90. b.ShortText1617861966146 AS cgd_good_name,
  91. b.ShortText1617861001482 AS cgd_good_no,
  92. b.ShortText1617865626160 AS cgd_cat_f,
  93. c.text1615776646788 AS cgd_cat_s,
  94. c.ShortText1618558317611 AS cgd_cat_t,
  95. ifnull(c.ShortText1618678132819,'') AS financial,
  96. b.ShortText1617865685744 AS cgd_unit,
  97. b.ShortText1618240134229 AS glod_type,
  98. round( `b`.`Number1618240458074`, 2 ) AS glod_price,
  99. round( `b`.`Number1618240480148`, 2 ) AS product_weight,
  100. round((
  101. SELECT
  102. ifnull(sum( `d_`.`number1617817090573` ),0)
  103. FROM
  104. `iw48m_CGFKHPMX_form` `d_`
  105. WHERE
  106. ((
  107. `d_`.`ShortText1617816811172` = `b`.`ShortText1618315935182`
  108. )
  109. AND ( `d_`.`ShortText1615789379545` = '付款' )
  110. AND (
  111. `d_`.`sequenceStatus` IN ( 'PROCESSING', 'COMPLETED' )))),
  112. 2
  113. ) AS `apay_fee`,
  114. round((
  115. SELECT
  116. ifnull(sum( `d_`.`number1617817077461` ),0)
  117. FROM
  118. `iw48m_CGFKHPMX_form` `d_`
  119. WHERE
  120. ((
  121. `d_`.`ShortText1617816811172` = `b`.`ShortText1618315935182`
  122. )
  123. AND ( `d_`.`ShortText1615789379545` = '回票' )
  124. AND (
  125. `d_`.`sequenceStatus` IN ( 'PROCESSING', 'COMPLETED' )))),
  126. 2
  127. ) AS `inv_fee`,
  128. round((
  129. SELECT
  130. ROUND(`b`.`Number1618240685904`,2)-ifnull(sum( `d_`.`number1617817090573` ),0)-round(ifnull(b.Number1619625483510,0),2) as total
  131. FROM
  132. `iw48m_CGFKHPMX_form` `d_`
  133. WHERE
  134. ((
  135. `d_`.`ShortText1617816811172` = `b`.`ShortText1618315935182`
  136. )
  137. AND ( `d_`.`ShortText1615789379545` = '付款' )
  138. AND (
  139. `d_`.`sequenceStatus` IN ( 'PROCESSING', 'COMPLETED' )))),
  140. 2
  141. ) AS `wpay_fee`,
  142. round((
  143. SELECT
  144. ROUND(`b`.`Number1618240685904`,2)-ifnull(sum( `d_`.`number1617817077461` ),0)-round(ifnull(b.Number1619625483510,0),2) as total
  145. FROM
  146. `iw48m_CGFKHPMX_form` `d_`
  147. WHERE
  148. ((
  149. `d_`.`ShortText1617816811172` = `b`.`ShortText1618315935182`
  150. )
  151. AND ( `d_`.`ShortText1615789379545` = '回票' )
  152. AND (
  153. `d_`.`sequenceStatus` IN ( 'PROCESSING', 'COMPLETED' )))),
  154. 2
  155. ) AS `winv_fee`,
  156. if(round((
  157. SELECT
  158. ROUND(`b`.`Number1618240685904`,2)-ifnull(sum( `d_`.`number1617817090573` ),0)-round(ifnull(b.Number1619625483510,0),2) as total
  159. FROM
  160. `iw48m_CGFKHPMX_form` `d_`
  161. WHERE
  162. ((
  163. `d_`.`ShortText1617816811172` = `b`.`ShortText1618315935182`
  164. )
  165. AND ( `d_`.`ShortText1615789379545` = '付款' )
  166. AND (
  167. `d_`.`sequenceStatus` IN ( 'PROCESSING', 'COMPLETED' )))),
  168. 2
  169. )=0,'已付','未付') AS pay_status,
  170. if(round((
  171. SELECT
  172. ROUND(`b`.`Number1618240685904`,2)-ifnull(sum( `d_`.`number1617817077461` ),0)-round(ifnull(b.Number1619625483510,0),2) as total
  173. FROM
  174. `iw48m_CGFKHPMX_form` `d_`
  175. WHERE
  176. ((
  177. `d_`.`ShortText1617816811172` = `b`.`ShortText1618315935182`
  178. )
  179. AND ( `d_`.`ShortText1615789379545` = '回票' )
  180. AND (
  181. `d_`.`sequenceStatus` IN ( 'PROCESSING', 'COMPLETED' )))),
  182. 2
  183. )=0,'已回','未回') AS inv_status,
  184. cast( `b`.`Number1618316157066` AS signed ) AS delivery_send,
  185. cast( `b`.`Number1618316171848` AS signed ) AS delivery_wsend,
  186. b.ShortText1618859321070 AS cgd_delivery_status
  187. /**b.Number1619625483510 as th_fee,
  188. b.Number1619625470651 as th_num
  189. b.modifiedTime updatetime,
  190. b.createdTime addtime**/
  191. FROM
  192. (
  193. iw48m_CGDJL AS b
  194. LEFT JOIN
  195. ibt0b_commodity AS c
  196. ON
  197. (
  198. (
  199. c.sequenceNo = b.ShortText1617861001482
  200. )
  201. )
  202. )
  203. WHERE
  204. (
  205. (
  206. 1 = 1
  207. ) AND
  208. (
  209. b.ShortText1618270412964 IN ('确认单采购','备库采购')
  210. )
  211. AND
  212. date_format( `b`.`modifiedTime`, '%Y-%m-%d' ) >= '{$date}'
  213. )
  214. ORDER BY
  215. b.ShortText1618315935182 ASC";
  216. $data=$this->db->query($sql);
  217. return $data;
  218. }
  219. }