Orderback.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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($normal===""){
  130. return error_show(1004,"参数normal不能为空");
  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. $receive=$normal+array_sum(array_column($errorlist,'error_num'));
  137. $remark = isset($this->post['remark']) && $this->post['remark']!=="" ? trim($this->post['remark']):"";
  138. $info['received_num'] = $receive;
  139. $info['normal_num'] = $normal;
  140. $info['remark'] = $remark;
  141. $info['status'] = 2;
  142. $info['updatetime'] = date("Y-m-d H:i:s");
  143. Db::startTrans();
  144. try{
  145. $up=Db::name("order_back")->save($info);
  146. if($up){
  147. if(empty($errorlist)){
  148. Db::commit();
  149. return app_show(0,'更新成功');
  150. }
  151. //$temp =[];
  152. foreach($errorlist as $value){
  153. $data=[];
  154. isset($value['id'])&&$value['id']!=''?$data['id']=$value['id']:"";
  155. $data['thNo']=$thNo;
  156. $data['error_num']=$value['error_num'];
  157. $data['error_code']=$value['error_code'];
  158. $data['error_remark']=$value['error_remark'];
  159. $data['is_del']=isset($value['is_del'])?$value['is_del']:0;
  160. isset($value['id'])&&$value['id']!=''? "" : $data['addtime']=date("Y-m-d H:i:s");
  161. $data['updatetime']=date("Y-m-d H:i:s");
  162. $in = Db::name("order_backinfo")->save($data);
  163. if(!$in){
  164. Db::rollback();
  165. return error_show(1005,'更新失败');
  166. }
  167. }
  168. Db::commit();
  169. return app_show(0,'更新成功');
  170. }
  171. Db::rollback();
  172. return error_show(1005,'更新失败');
  173. }catch (\Exception $e){
  174. Db::rollback();
  175. return error_show(1004,$e->getMessage());
  176. }
  177. }
  178. public function CheckExam(){
  179. $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
  180. if($thNo==""){
  181. return error_show(1004,"参数thNo不能为空");
  182. }
  183. $info =Db::name("order_back")->where(['thNo'=>$thNo])->find();
  184. if(empty($info)){
  185. return error_show(1004,"未找到数据");
  186. }
  187. $errorlist = isset($this->post['errorlist']) && $this->post['errorlist']!=="" ? $this->post['errorlist']:[];
  188. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  189. if($status===""){
  190. return error_show(1004,"参数status不能为空");
  191. }
  192. Db::startTrans();
  193. try{
  194. $info['status'] =$status;
  195. $info['updatetime'] = date("Y-m-d H:i:s");
  196. $up=Db::name("order_back")->save($info);
  197. if($up){
  198. if(empty($errorlist)){
  199. Db::commit();
  200. return app_show(0,'更新成功');
  201. }
  202. // $temp =[];
  203. foreach($errorlist as $value){
  204. $temp=Db::name("order_backinfo")->where(['id'=>$value["id"],"is_del"=>0,"thNo"=>$thNo])->find();
  205. if(empty($temp)){
  206. Db::rollback();
  207. return error_show(1005,'异常记录数据未找到');
  208. }
  209. $temp['status']=$value['status'];
  210. $temp['exam_remark']=$value['remark'];
  211. $temp['updatetime']=date("Y-m-d H:i:s");
  212. $com = Db::name("order_backinfo")->save($temp);
  213. if($com==false){
  214. Db::rollback();
  215. return error_show(1005,'异常记录数据更新失败');
  216. }
  217. }
  218. Db::commit();
  219. return app_show(0,'更新成功');
  220. }
  221. Db::rollback();
  222. return error_show(1005,'更新失败');
  223. }catch (\Exception $e){
  224. Db::rollback();
  225. return error_show(1004,$e->getMessage());
  226. }
  227. }
  228. public function Exam(){
  229. $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
  230. if($thNo==""){
  231. return error_show(1004,"参数thNo不能为空");
  232. }
  233. $info =Db::name("order_back")->where(['thNo'=>$thNo])->find();
  234. if(empty($info)){
  235. return error_show(1004,"未找到数据");
  236. }
  237. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  238. if($status===""){
  239. return error_show(1004,"参数status不能为空");
  240. }
  241. $remark= isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  242. Db::startTrans();
  243. try{
  244. $info['status'] =$status;
  245. $info['remark'] =$remark;
  246. $info['updatetime'] = date("Y-m-d H:i:s");
  247. $up=Db::name("order_back")->save($info);
  248. if($up){
  249. Db::commit();
  250. return app_show(0,'更新成功');
  251. }
  252. Db::rollback();
  253. return error_show(1005,'更新失败');
  254. }catch (\Exception $e){
  255. Db::rollback();
  256. return error_show(1004,$e->getMessage());
  257. }
  258. }
  259. }