Orderback.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <?php
  2. namespace app\Admin\controller;
  3. use think\App;
  4. use think\facade\Db;
  5. class Orderback extends \app\BaseController
  6. {
  7. public $post=[];
  8. public function __construct(App $app)
  9. {
  10. parent::__construct($app);
  11. $this->post =$this->request->post();
  12. }
  13. public function list(){
  14. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  15. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  16. $where =[['is_del',"=",0]];
  17. $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
  18. if($thNo!=""){
  19. $where[]=['thNo',"like", "%{$thNo}%"];
  20. }
  21. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  22. if($status!==""){
  23. // $where['status'] = $status;
  24. $where[]=['status',"=", $status];
  25. }
  26. $post_code= isset($this->post['post_code']) && $this->post['post_code']!="" ? trim($this->post['post_code']):"";
  27. if($post_code!=""){
  28. $where[]=['post_code',"like", "%{$post_code}%"];
  29. }
  30. $post_compay = isset($this->post['post_compay']) && $this->post['post_compay']!="" ? trim($this->post['post_compay']):"";
  31. if($post_compay!=""){
  32. $where[]=['post_company',"=", $post_compay];
  33. }
  34. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code']!="" ? trim($this->post['customer_code']):"";
  35. if($customer_code!=""){
  36. $where[]=['customer_code',"like", "%{$customer_code}%"];
  37. }
  38. $order_code = isset($this->post['order_code']) && $this->post['order_code']!="" ? trim($this->post['order_code']):"";
  39. if($order_code!=""){
  40. $where[]=['orderCode',"like", "%{$order_code}%"];
  41. }
  42. $out_code = isset($this->post['out_code']) && $this->post['out_code']!="" ? trim($this->post['out_code']):"";
  43. if($out_code!=""){
  44. $where[]=['outCode',"like", "%{$out_code}%"];
  45. }
  46. $return_code = isset($this->post['return_code']) && $this->post['return_code']!="" ? trim($this->post['return_code']):"";
  47. if($return_code!=""){
  48. $where[]=['returnCode',"like", "%{$return_code}%"];
  49. }
  50. $start =isset($this->post['start'])&&$this->post['start']!='' ? $this->post['start']:"";
  51. if($start!==""){
  52. $where[]=['addtime',">=", $start];
  53. }
  54. $end =isset($this->post['end'])&&$this->post['end']!='' ? $this->post['end']:"";
  55. if($end!==""){
  56. $where[]=['addtime',"<=", $end];
  57. }
  58. $count=Db::name("order_back")->where($where)->count();
  59. $total = ceil($count/$size);
  60. $page = $page >= $total ? $total : $page;
  61. $list = Db::name("order_back")->where($where)->page($page,$size)->order("addtime desc")->select();
  62. $data=[];
  63. foreach ($list as $value){
  64. $value['wsm_name']="";
  65. $value['wsm_supplier']='';
  66. $value['wsm_supplierNo']='';
  67. if($value['return_wsm']!=""){
  68. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  69. ->where(["a.wsm_code"=>$value['return_wsm']])->field("a.name as wsm_name,b.name,b.code")->find();
  70. $value['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  71. $value['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  72. $value['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  73. }
  74. $inorder= Db::name("order_backinfo")->where(['thNo'=>$value['thNo'],"is_del"=>0])->select();
  75. $value['child']=empty($inorder)? [] : $inorder;
  76. $data[]=$value;
  77. }
  78. return app_show(0,"获取成功",["list"=>$data ,"count"=>$count]);
  79. }
  80. /**
  81. * @return \think\response\Json|void
  82. * @throws \think\db\exception\DataNotFoundException
  83. * @throws \think\db\exception\DbException
  84. * @throws \think\db\exception\ModelNotFoundException
  85. */
  86. public function info(){
  87. $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
  88. if($thNo==""){
  89. return error_show(1004,"参数thNo不能为空");
  90. }
  91. $info =Db::name("order_back")->where(['thNo'=>$thNo])->find();
  92. if(empty($info)){
  93. return error_show(1004,"未找到数据");
  94. }
  95. $info['wsm_name']="";
  96. $info['wsm_supplier']='';
  97. $info['wsm_supplierNo']='';
  98. if($info['return_wsm']!=""){
  99. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  100. ->where(["a.wsm_code"=>$info['return_wsm']])->field("a.name as wsm_name,b.name,b.code")->find();
  101. $info['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  102. $info['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  103. $info['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  104. }
  105. $inorder= Db::name("order_backinfo")->where(['thNo'=>$info['thNo'],"is_del"=>0])->select();
  106. $info['child']=empty($inorder)? [] : $inorder;
  107. return app_show(0,"获取成功",$info);
  108. }
  109. /**
  110. * @return \think\response\Json|void
  111. * @throws \think\db\exception\DataNotFoundException
  112. * @throws \think\db\exception\DbException
  113. * @throws \think\db\exception\ModelNotFoundException
  114. */
  115. public function check(){
  116. $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
  117. if($thNo==""){
  118. return error_show(1004,"参数thNo不能为空");
  119. }
  120. $info =Db::name("order_back")->where(['thNo'=>$thNo])->find();
  121. if(empty($info)){
  122. return error_show(1004,"未找到数据");
  123. }
  124. $receive = isset($this->post['receive']) && $this->post['receive']!="" ? intval($this->post['receive']):"";
  125. if($receive==""){
  126. return error_show(1004,"参数receive不能为空");
  127. }
  128. $normal = isset($this->post['normal']) && $this->post['normal']!=="" ? intval($this->post['normal']):"";
  129. if($receive===""){
  130. return error_show(1004,"参数receive不能为空");
  131. }
  132. $errorlist = isset($this->post['errorlist']) && $this->post['errorlist']!=="" ? $this->post['errorlist']:[];
  133. if($info['status']== 2){
  134. return error_show(1002,"退货单已验货");
  135. }
  136. $remark = isset($this->post['remark']) && $this->post['remark']!=="" ? trim($this->post['remark']):"";
  137. $info['received_num'] = $receive;
  138. $info['normal_num'] = $normal;
  139. $info['remark'] = $remark;
  140. $info['status'] = 2;
  141. $info['updatetime'] = date("Y-m-d H:i:s");
  142. Db::startTrans();
  143. try{
  144. $up=Db::name("order_back")->save($info);
  145. if($up){
  146. if(empty($errorlist)){
  147. Db::commit();
  148. return app_show(0,'更新成功');
  149. }
  150. $temp =[];
  151. foreach($errorlist as $value){
  152. $data=[];
  153. $data['thNo']=$thNo;
  154. $data['error_num']=$value['error_num'];
  155. $data['error_code']=$value['error_code'];
  156. $data['error_remark']=$value['error_remark'];
  157. $data['addtime']=date("Y-m-d H:i:s");
  158. $data['updatetime']=date("Y-m-d H:i:s");
  159. $temp[]=$data;
  160. }
  161. $in = Db::name("order_backinfo")->insertAll($temp);
  162. if($in){
  163. Db::commit();
  164. return app_show(0,'更新成功');
  165. }
  166. }
  167. Db::rollback();
  168. return error_show(1005,'更新失败');
  169. }catch (\Exception $e){
  170. Db::rollback();
  171. return error_show(1004,$e->getMessage());
  172. }
  173. }
  174. public function CheckExam(){
  175. $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
  176. if($thNo==""){
  177. return error_show(1004,"参数thNo不能为空");
  178. }
  179. $info =Db::name("order_back")->where(['thNo'=>$thNo])->find();
  180. if(empty($info)){
  181. return error_show(1004,"未找到数据");
  182. }
  183. $errorlist = isset($this->post['errorlist']) && $this->post['errorlist']!=="" ? $this->post['errorlist']:[];
  184. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  185. if($status===""){
  186. return error_show(1004,"参数status不能为空");
  187. }
  188. Db::startTrans();
  189. try{
  190. $info['status'] =$status;
  191. $info['updatetime'] = date("Y-m-d H:i:s");
  192. $up=Db::name("order_back")->save($info);
  193. if($up){
  194. if(empty($errorlist)){
  195. Db::commit();
  196. return app_show(0,'更新成功');
  197. }
  198. // $temp =[];
  199. foreach($errorlist as $value){
  200. $temp=Db::name("order_backinfo")->where(['id'=>$value["id"],"is_del"=>0,"thNo"=>$thNo])->find();
  201. if(empty($temp)){
  202. Db::rollback();
  203. return error_show(1005,'异常记录数据未找到');
  204. }
  205. $temp['status']=$value['status'];
  206. $temp['exam_remark']=$value['remark'];
  207. $temp['updatetime']=date("Y-m-d H:i:s");
  208. $com = Db::name("order_backinfo")->save($temp);
  209. if($com==false){
  210. Db::rollback();
  211. return error_show(1005,'异常记录数据更新失败');
  212. }
  213. }
  214. Db::commit();
  215. return app_show(0,'更新成功');
  216. }
  217. Db::rollback();
  218. return error_show(1005,'更新失败');
  219. }catch (\Exception $e){
  220. Db::rollback();
  221. return error_show(1004,$e->getMessage());
  222. }
  223. }
  224. public function Exam(){
  225. $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
  226. if($thNo==""){
  227. return error_show(1004,"参数thNo不能为空");
  228. }
  229. $info =Db::name("order_back")->where(['thNo'=>$thNo])->find();
  230. if(empty($info)){
  231. return error_show(1004,"未找到数据");
  232. }
  233. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  234. if($status===""){
  235. return error_show(1004,"参数status不能为空");
  236. }
  237. $remark= isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  238. Db::startTrans();
  239. try{
  240. $info['status'] =$status;
  241. $info['remark'] =$remark;
  242. $info['updatetime'] = date("Y-m-d H:i:s");
  243. $up=Db::name("order_back")->save($info);
  244. if($up){
  245. Db::commit();
  246. return app_show(0,'更新成功');
  247. }
  248. Db::rollback();
  249. return error_show(1005,'更新失败');
  250. }catch (\Exception $e){
  251. Db::rollback();
  252. return error_show(1004,$e->getMessage());
  253. }
  254. }
  255. }