123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- <?php
- namespace app\api\controller\v1;
- use app\api\model\Qy_basic;
- use app\api\model\Sym;
- use OpenApi\Annotations as OA;
- use app\BaseController;
- use thans\jwt\facade\JWTAuth;
- use think\facade\Request as re;
- use think\Request;
- use thans\jwt\JWT;
- use app\api\model\Chandi as ChandiModel;
- use app\validate\Chandi as ChandiValidate;
- use think\exception\ValidateException;
- class Chandi extends BaseController{
- use ResponseJson;
- protected $request;
- protected $middleware = [
- 'jwt' => ['except' => ['qycount'] ],
- 'check' => ['except' =>[]]
- ];
- public function __construct(Request $request)
- {
- $this->request = $request;
- }
-
- public function AddPlaceInfo()
- {
-
- $data = $this->request->post();
- $qydm=$data['qydm'];
- $qy=Qy_basic::Where('qydm','=',$qydm)->find();
- if($qy){
- $jd=ChandiModel::field('cdbh')->where('qydm','=',$qydm)->order('cdbh desc')->find();
- if(!$jd['cdbh']&&$jd['cdbh']==''){
- $data['cdbh']='000';
- }else{
- $x='1'.$jd['cdbh'];
- $y=intval($x)+1;
- $data["cdbh"]=substr($y,1);
- }
-
- $result = ChandiModel::create($data);
- if($result) {
- return $this->jsonSuccessData($result);
- }else {
- return $this->jsonData(-1,"产地上传失败");
- }
- }
- else{
- return $this->jsonData(-2,"企业未注册");
- }
- }
-
- public function DoEditPlaceInfo(){
-
-
- $data = $this->request->post();
-
- $condition = ['bh'=>$data['bh']];
- $result = ChandiModel::update($data,$condition);
- if($result) {
- return $this->jsonSuccessData($result);
- }else {
- return $this->jsonData(-1,"更新失败");
- }
- }
-
- public function DelPlaceInfo()
- {
-
- $data = $this->request->post();
- $map['bh']= $data['bh'];
-
- $result = ChandiModel::where($map)->delete();
- if($result) {
- return $this->jsonSuccessData($result);
- }else {
- return $this->jsonData(-1,"产地信息删除失败");
- }
- }
-
- public function PlaceInfo(){
-
- $data = $this->request->post();
- $page = $data['page'];
- $query = $data['query'];
- $pageSize=$data['pageSize'];
- $qydm=$data['qydm'];
- if($query) {
- $result['rows']= ChandiModel::
- where([
- ['chandi', 'like', '%' . $query . '%'],
- ['t_chandi.qydm', '=', $qydm]
- ])
- ->field("t_chandi.*,t_qy_basic.qymc")
- ->leftjoin('t_qy_basic','t_chandi.qydm=t_qy_basic.qydm')
- ->page($page,$pageSize)
- ->select();
- $result['total']=ChandiModel::
- where([
- ['chandi', 'like', '%' . $query . '%'],
- ['t_chandi.qydm', '=', $qydm]
- ])
- -> leftjoin('t_qy_basic','t_chandi.qydm=t_qy_basic.qydm')->count();
- $result['page']=$page;
- }
- else{
- $result['rows']= ChandiModel::
- where(
- 't_chandi.qydm', '=', $qydm
- )
- ->field("t_chandi.*,t_qy_basic.qymc")
- ->leftjoin('t_qy_basic','t_chandi.qydm=t_qy_basic.qydm')
- ->page($page,$pageSize)
- ->select();
- $result['total']=ChandiModel::
- where('t_chandi.qydm', '=', $qydm)
- ->leftjoin('t_qy_basic','t_chandi.qydm=t_qy_basic.qydm')->count();
- $result['page']=$page;
- }
- if($result['rows']){
- return $this->jsonSuccessData($result);
- }
- else{
- return $this->jsonData('-1',"查询错误");
- }
- }
- public function qycount()
- {
- $sum=0;
- $count1 =Qy_basic::where(
- 'qylx','=','药材'
- )->field('qydm')->select();
- for ($i = 0;$i<count($count1);$i++){
- $sym =Sym::where('qydm',$count1[$i]['qydm'])->count('bh');
- $sum=$sum+$sym;
- }
- return $this->jsonSuccessData(
- $sum
- );
- }
- }
|