Purchback.php 11 KB

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