Index.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. namespace app\api\controller;
  3. use app\admin\model\QcodeGsmc;
  4. use app\admin\model\QcodeProduct;
  5. use app\admin\model\QcodeUnit;
  6. use app\common\controller\Api;
  7. use app\admin\controller\Sample;
  8. use think\Log;
  9. use think\Db;
  10. /**
  11. * 首页接口
  12. */
  13. class Index extends Api
  14. {
  15. protected $noNeedLogin = ['*'];
  16. protected $noNeedRight = ['*'];
  17. /**
  18. * 首页
  19. *
  20. */
  21. public function index()
  22. {
  23. $this->success('请求成功');
  24. }
  25. /**
  26. * 产品表qr_code_product同步
  27. */
  28. public function vo1()
  29. {
  30. $num1 = $this->request->param('num1');
  31. $num2 = $this->request->param('num2');
  32. if($num2<=$num1){
  33. $this->error('同步num1到num2之间的数据, 要求num2大于num1');
  34. }
  35. $qcodeProduct = new QcodeProduct();
  36. // 连接到其他数据库
  37. $config = [
  38. 'type' => 'mysql',
  39. 'hostname' => '127.0.0.1',
  40. 'database' => 'dm_7in6_com',
  41. 'username' => 'root',
  42. 'password' => 'root',
  43. 'charset' => 'utf8mb4',
  44. 'prefix' => 'qr_',
  45. ];
  46. $db = Db::connect($config);
  47. //查询主表记录
  48. $rows1 = $db->name('qcode_product')
  49. ->limit($num1,$num2-$num1)
  50. ->select();
  51. foreach($rows1 as $v){
  52. //1. 查询mongodb中是否存在该条记录
  53. $bool = $qcodeProduct->where('oid_id',$v['id'])->find();
  54. if ($bool) continue;
  55. //2. 获取设置主表数据
  56. $row['oid_id'] = $v['id'];
  57. $row['product_name'] = $v['product_name'];
  58. $row['product_code'] = $v['product_code'];
  59. $row['temple'] = $v['temple'];
  60. // unset($row['id']);
  61. // $row = array_merge(['oid_id'=>$v['id']],$row);
  62. //查询unit表数据
  63. $rows2 = $db->name('qcode_unit')
  64. ->where('code',$v['product_code'])
  65. ->find();
  66. if($rows2){
  67. if($rows2['main_unit']!=null){
  68. $row['main_unit'] = $rows2['main_unit'];
  69. }else{
  70. $row['main_unit'] = '';
  71. }
  72. if($rows2['sec_unit']!=null){
  73. $row['sec_unit'] = $rows2['sec_unit'];
  74. }else{
  75. $row['sec_unit'] = '';
  76. }
  77. if($rows2['proportion']!=null){
  78. $row['proportion'] = $rows2['proportion'];
  79. }else{
  80. $row['proportion'] = '';
  81. }
  82. }else{
  83. $row['main_unit'] = '';
  84. $row['sec_unit'] = '';
  85. $row['proportion'] = '';
  86. }
  87. git add application/admin/controller/QcodeBach.php
  88. git add application/admin/lang/zh-cn/qcode_bach.php
  89. git add application/admin/view/qcode_bach/index.html
  90. git add application/api/controller/Index.php
  91. git add public/assets/js/backend/qcode_bach.js
  92. git add application/admin/model/QcodeGsmc.php
  93. git add application/admin/view/qcode_bach/reprint.html
  94. git add public/assets/js/LodopFuncs.js
  95. git add vendor/phpqrcode/
  96. //3. 插入主表记录到mongodb中
  97. $qcodeProduct = new QcodeProduct();
  98. $qcodeProduct->save($row);
  99. }
  100. $this->success('成功');
  101. }
  102. /**
  103. * 产品表qr_code_unit同步
  104. */
  105. public function vo2()
  106. {
  107. $num1 = $this->request->param('num1');
  108. $num2 = $this->request->param('num2');
  109. if($num2<=$num1){
  110. $this->error('同步num1到num2之间的数据, 要求num2大于num1');
  111. }
  112. $qcodeGsmc = new QcodeGsmc();
  113. // 连接到其他数据库
  114. $config = [
  115. 'type' => 'mysql',
  116. 'hostname' => '127.0.0.1',
  117. 'database' => 'dm_7in6_com',
  118. 'username' => 'root',
  119. 'password' => 'root',
  120. 'charset' => 'utf8mb4',
  121. 'prefix' => 'qr_',
  122. ];
  123. $db = Db::connect($config);
  124. //查询主表记录
  125. $rows1 = $db->name('qcode_gsmc')
  126. ->limit($num1,$num2-$num1)
  127. ->select();
  128. foreach($rows1 as $v){
  129. //1. 查询mongodb中是否存在该条记录
  130. $bool = $qcodeGsmc->where('oid_id',$v['id'])->find();
  131. if ($bool) continue;
  132. //2. 获取设置主表数据
  133. $row = $v;
  134. unset($row['id']);
  135. $row = array_merge(['oid_id'=>$v['id']],$row);
  136. //3. 插入主表记录到mongodb中
  137. $qcodeGsmc = new QcodeGsmc();
  138. $qcodeGsmc->save($row);
  139. }
  140. $this->success('成功');
  141. }
  142. }