Product.old.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. namespace app\api\controller\v1;
  3. use OpenApi\Annotations as OA;
  4. use app\BaseController;
  5. use thans\jwt\facade\JWTAuth;
  6. use think\exception\ValidateException;
  7. use think\facade\Request as re;
  8. use think\Request;
  9. use thans\jwt\JWT;
  10. use app\api\model\Chandi as ChandiModel;
  11. use app\api\model\Qy_basic;
  12. use app\api\model\Zd_cpmc;
  13. use app\api\model\Nszy as NszyModel;
  14. use think\File;
  15. use app\validate\Product as ProductValidate;
  16. use rsa\Rsa;
  17. class Product extends BaseController{
  18. use ResponseJson;
  19. protected $request;
  20. protected $middleware = [
  21. 'jwt' => ['except' => [] ],
  22. // 'login','AddProductInfo','DelProductInfo','DoEditProductInfo','QueryProductInfo'
  23. ];
  24. public function __construct(Request $request)
  25. {
  26. $this->request = $request;
  27. }
  28. /*产品增加*/
  29. public function AddProductInfo() {
  30. // 加密
  31. // require_once(dirname(__FILE__)."/Rsa.php");
  32. // $rsa = new Rsa();
  33. $data = $this->request->post();
  34. $qydm=$data['qydm'];
  35. // $cpmc=$data['cpmc'];
  36. // try{
  37. // validate(ProductValidate::class)->check(
  38. // [
  39. // 'qydm'=>$qydm,
  40. // 'cpmc'=>$cpmc,
  41. // 'ms' =>$data['ms'],
  42. // 'cpgg'=>$data['cpgg'],
  43. // 'bzq'=>$data['bzq'] ,
  44. // ]
  45. // );
  46. // }catch (ValidateException $e){
  47. // return ($e->getError());
  48. // }
  49. $qy=Qy_basic::Where('qydm','=',$qydm)->find();
  50. if($qy){
  51. $jd=Zd_cpmc::field('cpbh')->where('qydm','=',$qydm)->select();
  52. //dump($jd);die;
  53. $wz=count($jd) - 1;//产品数量-1
  54. // dump($wz);die;
  55. if(count($jd)){
  56. $x="1".$jd[$wz]['cpbh'];//对应最后一条cpbh
  57. $y=intval($x)+1;
  58. $data["cpbh"]=substr($y,1);
  59. }else{
  60. $data["cpbh"]='001';
  61. }
  62. //dump($data);die;
  63. //新增记录
  64. $result = Zd_cpmc::create($data);
  65. // $publicEncrypt = $rsa->publicEncrypt(json_encode($result)); //公钥加密
  66. if($result) {
  67. return $this->jsonData(0,"添加成功");
  68. }else {
  69. return $this->jsonData(-1,"添加错误");
  70. }
  71. }
  72. else{
  73. return $this->jsonData(-2,"企业未注册");
  74. }
  75. }
  76. /*产品删除*/
  77. public function DelProductInfo(){
  78. //加密
  79. // require_once(dirname(__FILE__)."/Rsa.php");
  80. // $rsa = new Rsa();
  81. $data = $this->request->post();
  82. $Zd_cpmc = new Zd_cpmc();
  83. $bh = $data['bh'];
  84. $del=$Zd_cpmc->delproduct($bh);
  85. // $publicEncrypt = $rsa->publicEncrypt(json_encode($data)); //公钥加密
  86. if ($del == '1') {
  87. return $this->jsonData(
  88. 0,
  89. "删除成功"
  90. );
  91. } else {
  92. return $this->jsonData(-1, "删除失败");
  93. }
  94. }
  95. /*执行产品修改*/
  96. public function DoEditProductInfo() {
  97. $data = $this->request->post();
  98. //设置更新条件
  99. $condition = ['bh'=>$data['bh']];
  100. //更新当前记录
  101. $result = Zd_cpmc::update($data,$condition);
  102. if ($result) {
  103. return $this->jsonData(0,"修改成功");
  104. } else {
  105. return $this->jsonData(-1, "修改失败");
  106. }
  107. }
  108. /*产品查询*/
  109. public function QueryProductInfo(){
  110. $data = $this->request->post();
  111. $pageNum=$data['pageNum'];
  112. $pageSize=$data['pageSize'];
  113. $query=$data['query'];
  114. $qydm=$data['qydm'];
  115. if($query){
  116. $result['rows']=Zd_cpmc::where([
  117. ['cpmc', 'like', '%'.$query .'%'],
  118. ['t_zd_cpmc.qydm', '=', $qydm]
  119. ])
  120. ->field("t_zd_cpmc.*,t_qy_basic.qymc")
  121. ->leftjoin('t_qy_basic',' t_zd_cpmc.qydm=t_qy_basic.qydm')
  122. ->page($pageNum,$pageSize)
  123. ->select();
  124. $result['pages']=$pageNum;
  125. $result['total']=Zd_cpmc::where(
  126. [
  127. ['cpmc', 'like', '%'.$query .'%'],
  128. ['t_zd_cpmc.qydm', '=', $qydm]
  129. ]
  130. )
  131. ->select()
  132. ->count('bh');
  133. }
  134. else{
  135. $result['rows']=Zd_cpmc::where([
  136. ['t_zd_cpmc.qydm', '=', $qydm]
  137. ])
  138. ->field("t_zd_cpmc.*,t_qy_basic.qymc")
  139. ->leftjoin('t_qy_basic',' t_zd_cpmc.qydm=t_qy_basic.qydm')
  140. ->page($pageNum,$pageSize)
  141. ->select();
  142. $result['pages']=$pageNum;
  143. $result['total']=Zd_cpmc::where(
  144. [
  145. ['cpmc', 'like', '%'.$query .'%'],
  146. ['t_zd_cpmc.qydm', '=', $qydm]
  147. ]
  148. )
  149. ->select()
  150. ->count('bh');
  151. }
  152. if($result){
  153. return $this->jsonSuccessData($result);
  154. }
  155. else{
  156. return $this->jsonData('-1',"查询错误");
  157. }
  158. }
  159. }