Sym.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\controller;
  3. use app\model\ProductBatch;
  4. use app\BaseController;
  5. use app\service\ZdXzqService;
  6. use think\facade\Db;
  7. use think\response\Json;
  8. use think\exception\ValidateException;
  9. use think\annotation\Route;
  10. use think\annotation\route\Middleware;
  11. use hg\apidoc\annotation as Apidoc;
  12. /**
  13. * @Apidoc\Title("溯源码")
  14. * @Apidoc\Group("溯源码")
  15. * @Apidoc\Sort (18)
  16. */
  17. class Sym extends BaseController
  18. {
  19. /**
  20. * @Apidoc\Title("溯源码生成")
  21. * @Apidoc\Tag("溯源码")
  22. * @Apidoc\Method ("post")
  23. * @Apidoc\Author ("ihavoc")
  24. * @Route("code",method="post")
  25. * @Middleware({"jwt"})
  26. */
  27. public function code(): Json
  28. {
  29. $data=$this->request->post();
  30. $data['qydm']=getQydm();
  31. $chandi= ProductBatch::where([['batch_id','=',$data['batch_id']],['qydm','=',$data['qydm']]])->findOrEmpty();
  32. $xzq["xzqdm"] = explode(".",$data["qydm"])[0];
  33. $city["towns"]=ZdXzqService::getXzqDetail($data["qydm"]);
  34. $city["country"] = ZdXzqService::getXzqDetail(str_pad(substr($xzq["xzqdm"],0,6),9,'0'));
  35. $city["city"] = ZdXzqService::getXzqDetail(str_pad(substr($xzq["xzqdm"],0,4),9,'0'));
  36. // var_dump($city);
  37. $data['base_id']=$chandi['base_id'];
  38. $data['date']=date('Y-m-d H:i:s');
  39. for ($i=0;$i<$data['num'];$i++){
  40. $data['sym']=strtoupper(substr(md5($this->msectime()),8,16).$i);
  41. $res = Db::name('sym')->strict(false)->save($data);
  42. $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();
  43. $re[$i]["city"]="安徽省".$city["city"]["xzqmc"].$city["country"]["xzqmc"];
  44. $re[$i]['sym']=$data['sym'];
  45. $re[$i]['create_date']=date('Y-m-d');
  46. }
  47. return $this->JsonSucess($re);
  48. }
  49. function msectime()
  50. {
  51. list($msec, $sec) = explode(' ', microtime());
  52. $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
  53. return $msectime;
  54. }
  55. }