Purchback.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  6. class Purchback extends BaseController
  7. {
  8. public $post="";
  9. public function __construct(App $app)
  10. {
  11. parent::__construct($app);
  12. $this->post=$this->request->post();
  13. }
  14. public function create(){
  15. $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
  16. $returnCode=makeNo("TH");
  17. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo'] !==""? trim($this->post['cgdNo']) :"";
  18. if($cgdNo==""){
  19. return error_show(1002,"参数cgdNo不能为空");
  20. }
  21. $cg = Db::name('purchease_order')->where(['cgdNo'=>$cgdNo,'is_del'=>0])->find();
  22. if($cg==""){
  23. return error_show(1002,"未找到采购单数据");
  24. }
  25. $gd= Db::name('good')->where(['good_code'=>$cg['good_code']])->find();
  26. if($gd==""){
  27. return error_show(1002,"未找到商品数据");
  28. }
  29. // $int= isset($gd['cat_id']) && $gd['cat_id'] !=0 ? made($gd['cat_id']):[];
  30. $return_num = isset($this->post['return_num']) && $this->post['return_num'] !=="" ? trim($this->post['return_num']):"";
  31. if($return_num==""){
  32. return error_show(1002,"参数return_num不能为空");
  33. }
  34. $apply_id =GetUserInfo($token);
  35. if(empty($apply_id)||$apply_id['code']!=0){
  36. return error_show(1002,"申请人数据不存在");
  37. }
  38. $rid= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  39. $rname= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  40. $good_total = $return_num*$cg['good_price'];
  41. // $post_company = isset($this->post['post_company']) && $this->post['post_company'] !==""? trim($this->post['post_company']) :"";
  42. // $post_code =isset($this->post['post_code']) && $this->post['post_code'] !==""? trim($this->post['post_code']) :"";
  43. // $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !==""? intval($this->post['post_fee']):"";
  44. // $status= isset($this->post['status']) && $this->post['status'] !==""? trim($this->post['status']) :"";
  45. $remark =isset($this->post['remark']) && $this->post['remark'] !==""? trim($this->post['remark']) :"";
  46. $data = [
  47. "returnCode"=>$returnCode,
  48. "cgdNo"=>$cgdNo,
  49. "good_code"=>$cg['good_code'],
  50. "return_num"=>$return_num,
  51. "good_name"=>$cg['good_name'],
  52. "good_price"=>$cg['good_price'],
  53. "good_catid"=>$gd['cat_id'],
  54. "apply_name"=>$rname,
  55. "apply_id"=>$rid,
  56. "good_total"=>$good_total,
  57. "post_company"=>"",
  58. "post_code"=>"",
  59. "post_fee"=>"",
  60. "status"=>1,
  61. "remark"=>$remark,
  62. "is_del"=>0,
  63. "addtime"=>date("Y-m-d H:i:s"),
  64. "updatetime"=>date("Y-m-d H:i:s")
  65. ];
  66. //$data['can'] = $int;
  67. $pd = Db::name('purchease_back')->insert($data);
  68. if($pd){
  69. return error_show(0,"新建成功");
  70. }else{
  71. return error_show(1002,"新建失败");
  72. }
  73. }
  74. public function list(){
  75. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  76. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  77. $where = [['a.is_del',"=",0],['b.is_del',"=",0]];
  78. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ? trim($this->post['cgdNo']):"";
  79. if($cgdNo!=""){
  80. $where[]=['a.cgdNo',"like", "%$cgdNo%"];
  81. }
  82. $returnCode= isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  83. if($returnCode!=""){
  84. $where[]=['a.returnCode',"like", "%$returnCode%"];
  85. }
  86. $good_type_code=isset($this->post['good_type_code']) && $this->post['good_type_code']!==""? trim($this->post['good_type_code']):"";
  87. if($good_type_code !=""){
  88. $where[]= ["b.good_type_code",'like',"%$good_type_code%"];
  89. }
  90. $good_name=isset($this->post['good_name']) && $this->post['good_name']!==""? trim($this->post['good_name']):"";
  91. if($good_name !=""){
  92. $where[]= ["b.good_name",'like',"%$good_name%"];
  93. }
  94. $status=isset($this->post['status']) && $this->post['status']!==""? trim($this->post['status']):"";
  95. if($status!=""){
  96. $where[]= ["a.status",'=',$status];
  97. }
  98. $count = Db::name('purchease_back')->alias('a')->join("purchease_order b","b.cgdNo=a.cgdNo","left")
  99. ->where($where)->count();
  100. $total = ceil($count / $size);
  101. $page = $page >= $total ? $total : $page;
  102. $list = Db::name('purchease_back')->alias('a')->join("purchease_order b","b.cgdNo=a.cgdNo","left")
  103. ->where($where)->page($page,$size)
  104. ->field("a.returnCode,b.good_type_code,a.good_catid,a.return_num,a.good_price,a.good_total,
  105. a.post_company,a.post_fee,a.status,a.cgdNo,b.good_name,b.order_type")->order("a.addtime desc")->select();
  106. $data=[];
  107. foreach ($list as $value){
  108. $value['can']= isset($value['good_catid']) && $value['good_catid'] !=0 ? made($value['good_catid']):[];
  109. $data[]=$value;
  110. }
  111. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  112. }
  113. public function status(){
  114. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  115. if($id==""){
  116. return error_show(1002,"参数id不能为空");
  117. }
  118. $dio = Db::name('purchease_back')->where(['id'=>$id,'is_del'=>0])->find();
  119. if(empty($dio)){
  120. return error_show(1002,"退货订单未找到");
  121. }
  122. $returnCode = isset($this->post['returnCode']) && $this->post['returnCode'] !==""? trim($this->post['returnCode']) :"";
  123. if($returnCode==""){
  124. return error_show(1002,"参数returnCode不能为空");
  125. }
  126. $status = isset($this->post['status'])&&$this->post['status']!=='' ? intval($this->post['status']) : "";
  127. if($status===""){
  128. return error_show(1001,'status不能为空');
  129. }
  130. $dio['status']=$status;
  131. $dio['updatetime']=date("Y-m-d H:i:s");
  132. $str = Db::name("purchease_back")->update($dio);
  133. if($str){
  134. return error_show(0,"更新成功");
  135. }else{
  136. return error_show(1002,"更新失败");
  137. }
  138. }
  139. public function backfe(){
  140. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  141. if($id==""){
  142. return error_show(1002,"参数id不能为空");
  143. }
  144. $dio = Db::name('purchease_back')->where(['id'=>$id,'is_del'=>0])->find();
  145. if(empty($dio)){
  146. return error_show(1002,"退货订单未找到");
  147. }
  148. $returnCode = isset($this->post['returnCode']) && $this->post['returnCode'] !==""? trim($this->post['returnCode']) :"";
  149. if($returnCode==""){
  150. return error_show(1002,"参数returnCode不能为空");
  151. }
  152. $post_company = isset($this->post['post_company']) && $this->post['post_company'] !==""? trim($this->post['post_company']) :"";
  153. if($post_company==""){
  154. return error_show(1002,"参数post_company 不能为空");
  155. }
  156. $post_code = isset($this->post['post_code']) && $this->post['post_code'] !==""? trim($this->post['post_code']) :"";
  157. if($post_code==""){
  158. return error_show(1002,"参数post_code不能为空");
  159. }
  160. $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !==""? trim($this->post['post_fee']) :"";
  161. if($post_fee==""){
  162. return error_show(1002,"参数post_fee不能为空");
  163. }
  164. $data=[
  165. "id"=>$id,
  166. "returnCode"=>$returnCode,
  167. "post_company"=>$post_company,
  168. "post_code"=>$post_code,
  169. "post_fee"=>$post_fee,
  170. "updatetime"=>date("Y-m-d H:i:s")
  171. ];
  172. $datainfo=Db::name('purchease_back')->save($data);
  173. return $datainfo ? error_show(0,"更新成功") : error_show(1002,"更新失败");
  174. }
  175. public function info(){
  176. $returnCode = isset($this->post['returnCode']) && $this->post['returnCode'] !==""? trim($this->post['returnCode']) :"";
  177. if($returnCode==""){
  178. return error_show(1002,"参数returnCode不能为空");
  179. }
  180. $info= Db::name("purchease_back")->where(['returnCode'=>$returnCode])->find();
  181. if(empty($info)){
  182. return error_show(1002,"未找到数据");
  183. }
  184. $goon = Db::name('good')->where(['good_code'=>$info['good_code']])->field("cat_id")->find();
  185. if(empty($goon)){
  186. return error_show(1002,"未找到商品数据");
  187. }
  188. $int= isset($goon['cat_id']) && $goon['cat_id'] !=0 ? made($goon['cat_id']):[];
  189. $wsmcode = Db::name("purchease_order")->alias("k")->leftJoin("supplier c", "k.supplierNo=c.code")
  190. ->where(["k.cgdNo" => $info['cgdNo']])->field("k.good_name,k.good_code,k.good_num,c.name,c.code")->find();
  191. //$info['good'] = isset($wsmcode['good_name']) ? $wsmcode['good_name'] : "";
  192. $info['goo_num'] = isset($wsmcode['good_num']) ? $wsmcode['good_num'] : "";
  193. //$info['god'] = isset($wsmcode['good_code']) ? $wsmcode['good_code'] : "";
  194. $info['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
  195. $info['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
  196. $info['can']=$int;
  197. return app_show(0,"获取成功",$info);
  198. }
  199. }