| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- <?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_gsmc同步
- */
- 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){
- //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('成功');
- }
- /**
- * 同步bach
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function vo5()
- {
- $num1 = 0;
- $num2 = 1;
- if($num2<=$num1){
- $this->error('同步num1到num2之间的数据, 要求num2大于num1');
- }
- // 连接到其他数据库
- $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_bach')
- ->limit($num1,$num2-$num1)
- ->order('id desc')
- ->select();
- $userInfo = Session::get('admin');
- $company_id = (int)$userInfo['company'];
- foreach($rows1 as $v){
- //1. 查询mongodb中是否存在该条记录
- $bool = $this->model->name($company_id.'_'."qcode_bach")->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中
- $qcodeBach = new \app\admin\model\QcodeBach();
- $qcodeBach->save($row);
- $pid = $qcodeBach->getLastInsID();
- $rows2 = $db->name('qcode_large')
- ->where('bach_id',$v['id'])
- ->select();
- foreach ($rows2 as $value){
- //1. 查询mongodb中是否存在该条记录
- $qcodeLarge = new QcodeLarge();
- $bool = $qcodeLarge->name($company_id.'_'."qcode_large")->where('oid_id',$value['id'])->find();
- if ($bool) continue;
- $row = $value;
- $row['old_bach_id'] = $value['bach_id'];
- $row['bach_id'] = $pid;
- $row['old_id'] = $value['id'];
- unset($row['id']);
- $qcodeLarge->save($row);
- $pid3 = $qcodeLarge->getLastInsID();
- $rows3 = $db->name('qcode_small')
- ->where('large_id',$value['id'])
- ->select();
- foreach ($rows3 as $value3){
- //1. 查询mongodb中是否存在该条记录
- $qcodeSmall = new QcodeSmall();
- $bool = $qcodeSmall->name($company_id.'_'."qcode_large")->where('oid_id',$value3['id'])->find();
- if ($bool) continue;
- $row = $value3;
- $row['old_bach_id'] = $value3['bach_id'];
- $row['old_large_id'] = $value3['large_id'];
- $row['old_id'] = $value3['id'];
- $row['bach_id'] = $pid;
- $row['large_id'] = $pid3;
- unset($row['id']);
- $qcodeSmall->save($row);
- }
- }
- }
- $this->success('成功');
- }
- }
|