Purchback.php 9.4 KB

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