Orderback.php 13 KB

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