| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- <?php
- namespace app\api\controller;
- use app\admin\model\QcodeClassification;
- use app\admin\model\QcodeGsmc;
- use app\admin\model\QcodeProduct;
- use app\admin\model\QcodeUnit;
- use app\common\controller\Api;
- use app\admin\controller\Sample;
- use think\Log;
- use think\Db;
- use think\Model;
- /**
- * 首页接口
- */
- class Index extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * 首页
- *
- */
- public function index()
- {
- $this->success('请求成功');
- }
- /**
- * 产品表qr_qcode_product同步
- */
- public function vo1()
- {
- $num1 = $this->request->param('num1');
- $num2 = $this->request->param('num2');
- if($num2<=$num1){
- $this->error('同步num1到num2之间的数据, 要求num2大于num1');
- }
- $qcodeProduct = new QcodeProduct();
- // 连接到其他数据库
- $config = [
- 'type' => 'mysql',
- 'hostname' => '127.0.0.1',
- 'database' => 'dm_7in6_com',
- 'username' => 'root',
- 'password' => 'root',
- 'charset' => 'utf8mb4',
- 'prefix' => 'qr_',
- ];
- $db = Db::connect($config);
- //查询主表记录
- $rows1 = $db->name('qcode_product')
- ->limit($num1,$num2-$num1)
- ->select();
- foreach($rows1 as $v){
- //1. 查询mongodb中是否存在该条记录
- $bool = $qcodeProduct->where('oid_id',$v['id'])->find();
- if ($bool) continue;
- //2. 获取设置主表数据
- $row['oid_id'] = $v['id'];
- $row['product_name'] = $v['product_name'];
- $row['product_code'] = $v['product_code'];
- $row['temple'] = $v['temple'];
- // unset($row['id']);
- // $row = array_merge(['oid_id'=>$v['id']],$row);
- //查询unit表数据
- $rows2 = $db->name('qcode_unit')
- ->where('code',$v['product_code'])
- ->find();
- if($rows2){
- if($rows2['main_unit']!=null){
- $row['main_unit'] = $rows2['main_unit'];
- }else{
- $row['main_unit'] = '';
- }
- if($rows2['sec_unit']!=null){
- $row['sec_unit'] = $rows2['sec_unit'];
- }else{
- $row['sec_unit'] = '';
- }
- if($rows2['proportion']!=null){
- $row['proportion'] = $rows2['proportion'];
- }else{
- $row['proportion'] = '';
- }
- }else{
- $row['main_unit'] = '';
- $row['sec_unit'] = '';
- $row['proportion'] = '';
- }
- //3. 插入主表记录到mongodb中
- $qcodeProduct = new QcodeProduct();
- $qcodeProduct->save($row);
- }
- $this->success('成功');
- }
- /**
- * 产品表qr_qcode_unit同步
- */
- public function vo2()
- {
- $num1 = $this->request->param('num1');
- $num2 = $this->request->param('num2');
- if($num2<=$num1){
- $this->error('同步num1到num2之间的数据, 要求num2大于num1');
- }
- $qcodeGsmc = new QcodeGsmc();
- // 连接到其他数据库
- $config = [
- 'type' => 'mysql',
- 'hostname' => '127.0.0.1',
- 'database' => 'dm_7in6_com',
- 'username' => 'root',
- 'password' => 'root',
- 'charset' => 'utf8mb4',
- 'prefix' => 'qr_',
- ];
- $db = Db::connect($config);
- //查询主表记录
- $rows1 = $db->name('qcode_gsmc')
- ->limit($num1,$num2-$num1)
- ->select();
- foreach($rows1 as $v){
- //1. 查询mongodb中是否存在该条记录
- $bool = $qcodeGsmc->where('oid_id',$v['id'])->find();
- if ($bool) continue;
- //2. 获取设置主表数据
- $row = $v;
- unset($row['id']);
- $row = array_merge(['oid_id'=>$v['id']],$row);
- //3. 插入主表记录到mongodb中
- $qcodeGsmc = new QcodeGsmc();
- $qcodeGsmc->save($row);
- }
- $this->success('成功');
- }
- /**
- * 产品表qr_qcode_classification同步
- */
- public function vo3()
- {
- $num1 = $this->request->param('num1');
- $num2 = $this->request->param('num2');
- if($num2<=$num1){
- $this->error('同步num1到num2之间的数据, 要求num2大于num1');
- }
- $qcodeClassification = new QcodeClassification();
- // 连接到其他数据库
- $config = [
- 'type' => 'mysql',
- 'hostname' => '127.0.0.1',
- 'database' => 'dm_7in6_com',
- 'username' => 'root',
- 'password' => 'root',
- 'charset' => 'utf8mb4',
- 'prefix' => 'qr_',
- ];
- $db = Db::connect($config);
- //查询主表记录
- $rows1 = $db->name('qcode_classification')
- ->limit($num1,$num2-$num1)
- ->select();
- foreach($rows1 as $v){
- //1. 查询mongodb中是否存在该条记录
- $bool = $qcodeClassification->where('oid_id',$v['id'])->find();
- if ($bool) continue;
- //2. 获取设置主表数据
- $row['oid_id'] = $v['id'];
- $row['code'] = $v['code'];
- $row['name'] = $v['name'];
- $row['status'] = $v['status'];
- //3. 插入主表记录到mongodb中
- $qcodeClassification = new QcodeClassification();
- $qcodeClassification->save($row);
- }
- $this->success('成功');
- }
- /**
- * 设置产品表qr_qcode_classification
- */
- public function vo4()
- {
- $qcodeClassification = new QcodeProduct();
- //查询主表记录
- $rows1 = $qcodeClassification->select();
- foreach($rows1 as $v){
- dump($v['product_code']);
- //2. 获取设置主表数据
- $row = [];
- $row['code'] = substr($v['product_code'],0,4);
- //3. 插入主表记录到mongodb中
- $qcodeClassification = new QcodeProduct();
- $row = $qcodeClassification->where('oid_id',$v['oid_id'])->update($row);
- }
- $this->success('成功');
- }
- }
|