123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace app\controller;
- use app\model\ProductBatch;
- use app\BaseController;
- use app\service\ZdXzqService;
- use think\facade\Db;
- use think\response\Json;
- use think\exception\ValidateException;
- use think\annotation\Route;
- use think\annotation\route\Middleware;
- use hg\apidoc\annotation as Apidoc;
- /**
- * @Apidoc\Title("溯源码")
- * @Apidoc\Group("溯源码")
- * @Apidoc\Sort (18)
- */
- class Sym extends BaseController
- {
- /**
- * @Apidoc\Title("溯源码生成")
- * @Apidoc\Tag("溯源码")
- * @Apidoc\Method ("post")
- * @Apidoc\Author ("ihavoc")
- * @Route("code",method="post")
- * @Middleware({"jwt"})
- */
- public function code(): Json
- {
- $data=$this->request->post();
- $data['qydm']=getQydm();
- $chandi= ProductBatch::where([['batch_id','=',$data['batch_id']],['qydm','=',$data['qydm']]])->findOrEmpty();
- $xzq["xzqdm"] = explode(".",$data["qydm"])[0];
- $city["towns"]=ZdXzqService::getXzqDetail($data["qydm"]);
- $city["country"] = ZdXzqService::getXzqDetail(str_pad(substr($xzq["xzqdm"],0,6),9,'0'));
- $city["city"] = ZdXzqService::getXzqDetail(str_pad(substr($xzq["xzqdm"],0,4),9,'0'));
- // var_dump($city);
- $data['base_id']=$chandi['base_id'];
- $data['date']=date('Y-m-d H:i:s');
- for ($i=0;$i<$data['num'];$i++){
- $data['sym']=strtoupper(substr(md5($this->msectime()),8,16).$i);
- $res = Db::name('sym')->strict(false)->save($data);
- $re[$i] = Db::name('product')->where([['t_product.qydm','=',$data['qydm']],['t_product.id','=',$chandi['product_id']]])->field('e.enterprises_name,e.fzr_phone,t_product.product_name')->join('t_enterprises e','t_product.qydm=e.qydm')->findOrEmpty();
- $re[$i]["city"]="安徽省".$city["city"]["xzqmc"].$city["country"]["xzqmc"];
- $re[$i]['sym']=$data['sym'];
- $re[$i]['create_date']=date('Y-m-d');
- }
- return $this->JsonSucess($re);
- }
- function msectime()
- {
- list($msec, $sec) = explode(' ', microtime());
- $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
- return $msectime;
- }
- }
|