Chandi.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\api\model\Qy_basic;
  4. use app\api\model\Sym;
  5. use OpenApi\Annotations as OA;
  6. use app\BaseController;
  7. use thans\jwt\facade\JWTAuth;
  8. use think\facade\Request as re;
  9. use think\Request;
  10. use thans\jwt\JWT;
  11. use app\api\model\Chandi as ChandiModel;
  12. use app\validate\Chandi as ChandiValidate;
  13. use think\exception\ValidateException;
  14. //use rsa\Rsa;
  15. class Chandi extends BaseController{
  16. use ResponseJson;
  17. protected $request;
  18. protected $middleware = [
  19. 'jwt' => ['except' => ['qycount'] ],
  20. 'check' => ['except' =>[]]
  21. // 'AddPlaceInfo','AddPlaceInfo','DoEditPlaceInfo','DelPlaceInfo','PlaceInfo'
  22. ];
  23. public function __construct(Request $request)
  24. {
  25. $this->request = $request;
  26. }
  27. /*产地增加*/
  28. public function AddPlaceInfo()
  29. {
  30. //加密
  31. // require_once(dirname(__FILE__)."/Rsa.php");
  32. // $rsa = new Rsa();
  33. $data = $this->request->post();
  34. $qydm=$data['qydm'];
  35. // $chandi=$data['chandi'];
  36. // $lng=$data['lng'];
  37. // $lat=$data['lat'];
  38. // $yt=$data['yt'];
  39. // if(isset($data['jldw'])){
  40. // try{
  41. // validate(ChandiValidate::class)->check(
  42. // [
  43. // 'qydm'=>$qydm,
  44. // 'chandi'=>$chandi,
  45. // 'lng' =>$lng,
  46. // 'lat'=>$lat,
  47. // 'yt'=>$yt ,
  48. // 'tiliang'=>$data['tiliang'],
  49. // 'jldw'=>$data['jldw'],
  50. // ]
  51. // );
  52. // }catch (ValidateException $e){
  53. // return ($e->getError());
  54. // }
  55. // }
  56. $qy=Qy_basic::Where('qydm','=',$qydm)->find();
  57. if($qy){
  58. $jd=ChandiModel::field('cdbh')->where('qydm','=',$qydm)->order('cdbh desc')->find();//按照产地查找产地表中的所有信息,
  59. if(!$jd['cdbh']&&$jd['cdbh']==''){
  60. $data['cdbh']='000';
  61. }else{
  62. $x='1'.$jd['cdbh'];
  63. $y=intval($x)+1;//十进制取整
  64. $data["cdbh"]=substr($y,1);//给产地编号赋值
  65. }
  66. //新增记录
  67. $result = ChandiModel::create($data);
  68. // $publicEncrypt = $rsa->publicEncrypt(json_encode($result)); //公钥加密
  69. if($result) {
  70. return $this->jsonSuccessData($result);
  71. }else {
  72. return $this->jsonData(-1,"产地上传失败");
  73. }
  74. }
  75. else{
  76. return $this->jsonData(-2,"企业未注册");
  77. }
  78. }
  79. /*执行产地信息修改*/
  80. public function DoEditPlaceInfo(){
  81. //加密
  82. // require_once(dirname(__FILE__)."/Rsa.php");
  83. // $rsa = new Rsa();
  84. //从提交表单中排除关联字段cpmc字段
  85. $data = $this->request->post();
  86. //设置更新条件
  87. $condition = ['bh'=>$data['bh']];
  88. $result = ChandiModel::update($data,$condition);
  89. // $publicEncrypt = $rsa->publicEncrypt(json_encode($result)); //公钥加密
  90. if($result) {
  91. return $this->jsonSuccessData($result);
  92. }else {
  93. return $this->jsonData(-1,"更新失败");
  94. }
  95. }
  96. /*产地删除*/
  97. public function DelPlaceInfo()
  98. {
  99. //加密
  100. // require_once(dirname(__FILE__)."/Rsa.php");
  101. // $rsa = new Rsa();
  102. $data = $this->request->post();
  103. $map['bh']= $data['bh'];
  104. //删除产地信息
  105. $result = ChandiModel::where($map)->delete();
  106. // $publicEncrypt = $rsa->publicEncrypt(json_encode($result)); //公钥加密
  107. if($result) {
  108. return $this->jsonSuccessData($result);
  109. }else {
  110. return $this->jsonData(-1,"产地信息删除失败");
  111. }
  112. }
  113. /*产地信息查询*/
  114. public function PlaceInfo(){
  115. //加密
  116. // require_once(dirname(__FILE__)."/Rsa.php");
  117. // $rsa = new Rsa();
  118. $data = $this->request->post();
  119. $page = $data['page']; //分页的页码
  120. $query = $data['query']; //前台传过来的查询
  121. $pageSize=$data['pageSize'];
  122. $qydm=$data['qydm'];
  123. if($query) {
  124. $result['rows']= ChandiModel::
  125. where([
  126. ['chandi', 'like', '%' . $query . '%'],
  127. ['t_chandi.qydm', '=', $qydm]
  128. ])
  129. ->field("t_chandi.*,t_qy_basic.qymc")
  130. ->leftjoin('t_qy_basic','t_chandi.qydm=t_qy_basic.qydm')
  131. ->page($page,$pageSize)
  132. ->select();
  133. $result['total']=ChandiModel::
  134. where([
  135. ['chandi', 'like', '%' . $query . '%'],
  136. ['t_chandi.qydm', '=', $qydm]
  137. ])
  138. -> leftjoin('t_qy_basic','t_chandi.qydm=t_qy_basic.qydm')->count();
  139. $result['page']=$page;
  140. }
  141. else{
  142. $result['rows']= ChandiModel::
  143. where(
  144. 't_chandi.qydm', '=', $qydm
  145. )
  146. ->field("t_chandi.*,t_qy_basic.qymc")
  147. ->leftjoin('t_qy_basic','t_chandi.qydm=t_qy_basic.qydm')
  148. ->page($page,$pageSize)
  149. ->select();
  150. $result['total']=ChandiModel::
  151. where('t_chandi.qydm', '=', $qydm)
  152. ->leftjoin('t_qy_basic','t_chandi.qydm=t_qy_basic.qydm')->count();
  153. $result['page']=$page;
  154. }
  155. // $publicEncrypt = $rsa->publicEncrypt(json_encode($result)); //公钥加密
  156. if($result['rows']){
  157. return $this->jsonSuccessData($result);
  158. }
  159. else{
  160. return $this->jsonData('-1',"查询错误");
  161. }
  162. }
  163. public function qycount()
  164. {
  165. $sum=0;
  166. $count1 =Qy_basic::where(
  167. 'qylx','=','药材'
  168. )->field('qydm')->select();
  169. // dump(count($count1));die();
  170. // $sym =Sym::where('date','>','2021-06-01')->count('bh');
  171. //
  172. // return $this->jsonSuccessData(
  173. // $count1
  174. // );
  175. for ($i = 0;$i<count($count1);$i++){
  176. $sym =Sym::where('qydm',$count1[$i]['qydm'])->count('bh');
  177. $sum=$sum+$sym;
  178. }
  179. return $this->jsonSuccessData(
  180. $sum
  181. );
  182. //
  183. }
  184. }