123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- <?php
- namespace app\api\controller\v1;
- use app\api\model\Chanpin;
- use app\api\model\Chandi;
- use app\api\model\Qy_basic;
- use app\api\model\Zd_cpmc;
- use app\api\model\Sym;
- use app\api\model\Nszy;
- use app\api\model\Trpsy;
- use OpenApi\Annotations as OA;
- use app\BaseController;
- use thans\jwt\facade\JWTAuth;
- //use think\Db;
- use think\facade\Request as re;
- use think\Request;
- use thans\jwt\JWT;
- use app\validate\Chandi as ChandiValidate;
- use think\exception\ValidateException;
- use rsa\Rsa;
- //use think\Facade\Db;
- class Traceability extends BaseController
- {
- use ResponseJson;
- protected $request;
- protected $middleware = [
- 'jwt' => ['except' => []],
- // 'SelectProductionInfo','TraceabilityPrint','TraceabilityPrint2','ShowInformation'
- ];
- public function __construct(Request $request)
- {
- $this->request = $request;
- }
- //溯源码打印界面,选择产品批次号接口
- public function SelectProductionInfo(){
- $data = $this->request->post();
- $query=$data['query'];
- $qydm=$data['qydm'];
- if($query){
- $result['rows']=Chanpin::
- where([
- ['t_chanpin.qydm', '=', $qydm],
- ['t_zd_cpmc.cpmc', 'like', '%'.$query .'%']
- ])
- ->field("t_chanpin.*,t_qy_basic.qymc,t_zd_cpmc.cpgg,t_zd_cpmc.cpmc")
- ->leftJoin('t_qy_basic','t_chanpin.qydm=t_qy_basic.qydm')
- ->leftJoin('t_zd_cpmc','t_chanpin.cpbh=t_zd_cpmc.cpbh and t_chanpin.qydm=t_zd_cpmc.qydm')
- ->select();
- $result['total']=Chanpin::
- where([
- ['t_chanpin.qydm', '=', $qydm],
- ['t_zd_cpmc.cpmc', 'like', '%'.$query .'%']
- ])
- ->field("t_chanpin.*,t_qy_basic.qymc,t_zd_cpmc.cpgg,t_zd_cpmc.cpmc")
- ->leftJoin('t_qy_basic','t_chanpin.qydm=t_qy_basic.qydm')
- ->leftJoin('t_zd_cpmc','t_chanpin.cpbh=t_zd_cpmc.cpbh and t_chanpin.qydm=t_zd_cpmc.qydm')
- ->count();
- }
- else{
- $result['rows']=Db::name('chanpin')
- ->where('t_chanpin.qydm', '=', $qydm)
- ->field("t_chanpin.*,t_qy_basic.qymc,t_zd_cpmc.cpgg,t_zd_cpmc.cpmc")
- ->leftJoin('t_zd_cpmc','t_chanpin.cpbh=t_zd_cpmc.cpbh and t_chanpin.qydm=t_zd_cpmc.qydm')
- ->leftJoin('t_qy_basic','t_chanpin.qydm=t_qy_basic.qydm')
- ->select();
- $result['total']=Db::name('chanpin')->where('t_chanpin.qydm', '=', $qydm)->count();
- }
- // $publicEncrypt = $rsa->publicEncrypt(json_encode($result)); //公钥加密
- if($result){
- return $this->jsonSuccessData($result);
- }
- else{
- return $this->jsonData(-1,"无查询结果");
- }
- }
- /*溯源码打印功能,先输入信息,后打码*/
- public function TraceabilityPrint(){
- //加密
- // require_once(dirname(__FILE__)."/Rsa.php");
- // $rsa = new Rsa();
- $data = $this->request->post();
- $nums = $data['nums'];
- $cpmc = $data['cpmc'];
- $pch = $data['pch'];
- $qydm= $data['qydm'];
- $bh = Qy_basic::where('t_qy_basic.qydm','=',$qydm)->field('t_qy_basic.bh,t_qy_basic.qymc,t_qy_basic.fzrtel')->find();
- $result = Chanpin::where([
- ['t_chanpin.qydm', '=', $qydm],
- ['t_chanpin.pch', '=',$pch]
- ])
- ->field('t_chanpin.chandi,t_chanpin.rq')
- ->find();
- $chandi = $result['chandi'];
- $ret = Chandi::where([
- ['t_chandi.qydm', '=', $qydm],
- ['t_chandi.chandi', '=',$chandi]
- ])
- ->field('t_chandi.*')
- ->find();
- $rets = Zd_cpmc::where([
- ['t_zd_cpmc.qydm', '=', $qydm],
- ['t_zd_cpmc.cpmc', '=',$cpmc]
- ])
- ->find();
- for($i=0;$i<$nums;$i++){
- $numbers=rand(10000,19999);
- $symMes['qydm'] = $qydm;
- $symMes['cpbh'] = $rets['cpbh'];
- $symMes['cdbh'] = $ret['cdbh'];
- $symMes['pch'] = $pch;
- $symMes['date'] = date("Y-m-d");
- $symMes['sym']=$bh['bh'].reter(substr($data['pch'],0,2)).
- reter(substr($data['pch'],2,2)).
- reter(substr($data['pch'],4,2)).
- substr($data['pch'],6,2).substr($numbers,0,5);
- $Infomation[$i]['sym'] = $symMes['sym'];
- $symres = Sym::create($symMes);
- }
- // dump($symres);die();
- /*以上部分完成溯源码的生成*/
- /*下面开始完成根据$symres['bh']查找该条溯源码的信息*/
- $infomations = array();
- for($i=0;$i<$nums;$i++) {
- $infomations[$i]['qymc'] = $bh['qymc'];
- $infomations[$i]['fzrtel'] = $bh['fzrtel'];
- $infomations[$i]['sym'] = $Infomation[$i]['sym'];
- $infomations[$i]['date'] = $result['rq'];
- $infomations[$i]['cpmc'] = $cpmc;
- $infomations[$i]['chandi'] = $ret['chandi'];
- $infomations[$i]['cpgg'] = $rets['cpgg'];
- $infomations[$i]['url'] = 'http://www.aielab.net/ah/S?'.$Infomation[$i]['sym'];
- }
- // $infomations['qymc'] = $bh['qymc'];
- // $infomations['fzrtel'] = $bh['fzrtel'];
- // $infomations['sym'] = $symres['sym'];
- // $infomations['date'] = $result['rq'];
- // $infomations['cpmc'] = $cpmc;
- // $publicEncrypt = $rsa->publicEncrypt(json_encode($infomations)); //公钥加密
- if($infomations){
- return $this->jsonSuccessData($infomations);
- }else{
- return $this->jsonData(-1,'无查询结果');
- }
- }
- /*溯源码打印功能,先生成溯源码,后补充信息*/
- public function TraceabilityPrint2(){
- $data = $this->request->post();
- $qydm = $data['qydm'];
- $bh = Qy_basic::where('qydm','=',$qydm)->field('bh')->find();
- $randomnums = generate_word();
- $numbers=rand(10000,19999);
- $symMes['sym']=$bh['bh'].$randomnums.substr($numbers,0,5);
- $symMes['date'] = date("Y-m-d");
- $symMes['qydm'] = $qydm;
- $symres = Sym::create($symMes);
- // $publicEncrypt = $rsa->publicEncrypt(json_encode($symres)); //公钥加密
- if($symres){
- return $this->jsonSuccessData($symres);
- }else{
- return $this->jsonData(-1,'无查询结果');
- }
- }
- /*扫码显示界面的信息*/
- public function ShowInformation(){
- //加密
- // require_once(dirname(__FILE__)."/Rsa.php");
- // $rsa = new Rsa();
- $data = $this->request->post();
- $qydm = $data['qydm'];
- $symresult = Sym::where('t_sym.sym','=',$data['sym'])->field("t_sym.pch,t_sym.cdbh,t_sym.cpbh,t_sym.qydm")->find();
- // dump($symresult);die();
- $information = Qy_basic::where('t_qy_basic.qydm','=',$qydm)->field("t_qy_basic.dwjj,t_qy_basic.qymc,t_qy_basic.fzrtel")->find();
- $productresult = Zd_cpmc::where([
- ['t_zd_cpmc.cpbh','=',$symresult['cpbh']],
- ['t_zd_cpmc.qydm','=',$qydm]
- ])
- ->field("t_zd_cpmc.cpmc,t_zd_cpmc.picname,t_zd_cpmc.bzq,t_zd_cpmc.ms,t_zd_cpmc.cpgg")
- ->find();
- $chanpinresult = Chanpin::where([
- ['t_chanpin.pch','=',$symresult['pch']],
- ['t_chanpin.qydm','=',$qydm]
- ])
- ->field("t_chanpin.rq,t_chanpin.chandi")
- ->find();
- $nszyresult = Nszy::where([
- ['t_nszy.cdbh','=',$symresult['cdbh']],
- ['t_nszy.qydm','=',$qydm]
- ])
- ->field("t_nszy.nszy,t_nszy.trpmc,t_nszy.zyl,t_nszy.zyldw,t_nszy.rq,t_nszy.zyr")
- ->select();
- $trpresult = Trpsy::where([
- ['t_trpsy.cdbh','=',$symresult['cdbh']],
- ['t_trpsy.qydm','=',$qydm]
- ])
- ->field("t_trpsy.trpm,t_trpsy.trpgg,t_trpsy.cgrq,t_trpsy.cgr")
- ->select();
- $information['cpmc'] = $productresult['cpmc'];
- $information['bzq'] = $productresult['bzq'];
- $information['ms'] = $productresult['ms'];
- $information['cpgg'] = $productresult['cpgg'];
- $information['picname'] = "http://qklapi.ahaia.net/Uploads/".$qydm."/".$productresult['picname'];
- $information['rq'] = $chanpinresult['rq'];
- $information['chandi'] = $chanpinresult['chandi'];
- $information['nszy'] = $nszyresult;
- $information['trpsy'] = $trpresult;
- // $publicEncrypt = $rsa->publicEncrypt(json_encode($information)); //公钥加密
- if($symresult['pch']&&$symresult['cpbh']!=null) {
- return $this->jsonSuccessData($information);
- }else if($symresult==null) {
- return $this->jsonData(-1, "该溯源码不存在");
- }
- }
- }
|