Purchback.php 12 KB

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