Orderback.php 11 KB

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