Production.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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\Production as ProductValidate;
  16. use app\api\model\Chanpin;
  17. use rsa\Rsa;
  18. class Production extends BaseController{
  19. use ResponseJson;
  20. protected $request;
  21. protected $middleware = [
  22. 'jwt' => ['except' => []],
  23. // 'login','AddProductionInfo','DelProductionInfo','DoEditProductionInfo','QueryProductionInfo'
  24. ];
  25. public function __construct(Request $request)
  26. {
  27. $this->request = $request;
  28. }
  29. /*产品生产增加*/
  30. public function AddProductionInfo(){
  31. $data = $this->request->post();
  32. $qydm=$data['qydm'];
  33. $rq=$data['rq'];
  34. $jd=Chanpin::where([['qydm','=',$qydm], ['rq','=',$rq]])->field('pch')->order('pch','desc')->select();
  35. $pcqz = substr($rq,2,2).substr($rq,5,2).substr($rq,8,2);
  36. if(count($jd)){
  37. $data["pch"]=$jd[0]['pch']+1;
  38. }else{
  39. $data["pch"]=$pcqz.'01';
  40. }
  41. $result=Chanpin::create($data);
  42. if($result){
  43. return $this->jsonData(0,"信息添加成功");
  44. }else{
  45. return $this->jsonData(-1,"信息添加失败");
  46. }
  47. }
  48. /*产品生产删除*/
  49. public function DelProductionInfo(){
  50. $data = $this->request->post();
  51. $result = Chanpin::where('bh',$data['bh'])->delete();
  52. if($result){
  53. return $this->jsonData(0,"信息删除成功");
  54. }else{
  55. return $this->jsonData(-1,"信息删除失败");
  56. }
  57. }
  58. /*产品生产修改*/
  59. public function DoEditProductionInfo(){
  60. $data = $this->request->post();
  61. //设置更新条件
  62. $condition = ['bh'=>$data['bh']];
  63. //更新当前记录
  64. $result = Chanpin::update($data,$condition);
  65. if ($result) {
  66. return $this->jsonData(0, "信息修改成功");
  67. } else {
  68. return $this->jsonData(-1, "信息修改失败");
  69. }
  70. }
  71. /*生产产品查询*/
  72. public function QueryProductionInfo(){
  73. $data = $this->request->post();
  74. $pageNum=$data['pageNum'];
  75. $pageSize=$data['pageSize'];
  76. $query=$data['query'];
  77. $qydm=$data['qydm'];
  78. if($query){
  79. $result['rows']=Chanpin::where([
  80. ['cpmc', 'like', '%'.$query .'%'],
  81. ['t_chanpin.qydm', '=', $qydm]
  82. ])
  83. ->field("t_chanpin.*,t_qy_basic.qymc,t_zd_cpmc.cpgg,t_zd_cpmc.cpmc")
  84. ->join('t_zd_cpmc','t_chanpin.cpbh=t_zd_cpmc.cpbh and t_chanpin.qydm=t_zd_cpmc.qydm')
  85. ->join('t_qy_basic','t_chanpin.qydm=t_qy_basic.qydm')
  86. ->page($pageNum,$pageSize)
  87. ->select();
  88. $result['pages']=$pageNum;
  89. $result['total']=Chanpin::where([
  90. ['cpmc', 'like', '%'.$query .'%'],
  91. ['t_chanpin.qydm', '=', $qydm]
  92. ])
  93. ->join('t_zd_cpmc','t_chanpin.cpbh=t_zd_cpmc.cpbh and t_chanpin.qydm=t_zd_cpmc.qydm')
  94. ->join('t_qy_basic','t_chanpin.qydm=t_qy_basic.qydm')
  95. ->select()
  96. ->count('bh');
  97. }
  98. else{
  99. $result['rows']=$result['rows']=Chanpin::where([
  100. ['t_chanpin.qydm', '=', $qydm]
  101. ])
  102. ->field("t_chanpin.*,t_qy_basic.qymc,t_zd_cpmc.cpgg,t_zd_cpmc.cpmc")
  103. ->join('t_zd_cpmc','t_chanpin.cpbh=t_zd_cpmc.cpbh and t_chanpin.qydm=t_zd_cpmc.qydm')
  104. ->join('t_qy_basic','t_chanpin.qydm=t_qy_basic.qydm')
  105. ->page($pageNum,$pageSize)
  106. ->select();
  107. $result['pages']=$pageNum;
  108. $result['total']=Chanpin::where([
  109. ['t_chanpin.qydm', '=', $qydm]
  110. ])
  111. ->join('t_zd_cpmc','t_chanpin.cpbh=t_zd_cpmc.cpbh and t_chanpin.qydm=t_zd_cpmc.qydm')
  112. ->join('t_qy_basic','t_chanpin.qydm=t_qy_basic.qydm')
  113. ->select()
  114. ->count('bh');
  115. }
  116. if($result){
  117. return $this->jsonSuccessData($result);
  118. }
  119. else{
  120. return $this->jsonData('-1',"查询错误");
  121. }
  122. }
  123. }