Orderback.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. $inorder= Db::name("order_backinfo")->where(['thNo'=>$value['thNo'],"is_del"=>0])->select();
  76. $value['child']=empty($inorder)? [] : $inorder;
  77. $data[]=$value;
  78. }
  79. return app_show(0,"获取成功",["list"=>$data ,"count"=>$count]);
  80. }
  81. /**
  82. * @return \think\response\Json|void
  83. * @throws \think\db\exception\DataNotFoundException
  84. * @throws \think\db\exception\DbException
  85. * @throws \think\db\exception\ModelNotFoundException
  86. */
  87. public function info(){
  88. $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
  89. if($thNo==""){
  90. return error_show(1004,"参数thNo不能为空");
  91. }
  92. $info =Db::name("order_back")->where(['thNo'=>$thNo])->find();
  93. if(empty($info)){
  94. return error_show(1004,"未找到数据");
  95. }
  96. $info['wsm_name']="";
  97. $info['wsm_supplier']='';
  98. $info['wsm_supplierNo']='';
  99. if($info['return_wsm']!=""){
  100. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  101. ->where(["a.wsm_code"=>$info['return_wsm']])->field("a.name as wsm_name,b.name,b.code")->find();
  102. $info['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  103. $info['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  104. $info['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  105. }
  106. $inorder= Db::name("order_backinfo")->where(['thNo'=>$info['thNo'],"is_del"=>0])->select();
  107. $info['child']=empty($inorder)? [] : $inorder;
  108. return app_show(0,"获取成功",$info);
  109. }
  110. /**
  111. * @return \think\response\Json|void
  112. * @throws \think\db\exception\DataNotFoundException
  113. * @throws \think\db\exception\DbException
  114. * @throws \think\db\exception\ModelNotFoundException
  115. */
  116. public function check(){
  117. $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
  118. if($thNo==""){
  119. return error_show(1004,"参数thNo不能为空");
  120. }
  121. $info =Db::name("order_back")->where(['thNo'=>$thNo])->find();
  122. if(empty($info)){
  123. return error_show(1004,"未找到数据");
  124. }
  125. // $receive = isset($this->post['receive']) && $this->post['receive']!="" ? intval($this->post['receive']):"";
  126. // if($receive==""){
  127. // return error_show(1004,"参数receive不能为空");
  128. // }
  129. $normal = isset($this->post['normal']) && $this->post['normal']!=="" ? intval($this->post['normal']):"";
  130. if($normal===""){
  131. return error_show(1004,"参数normal不能为空");
  132. }
  133. $errorlist = isset($this->post['errorlist']) && $this->post['errorlist']!=="" ? $this->post['errorlist']:[];
  134. if($info['status']== 2){
  135. return error_show(1002,"退货单已验货");
  136. }
  137. $receive=$normal+array_sum(array_column($errorlist,'error_num'));
  138. $remark = isset($this->post['remark']) && $this->post['remark']!=="" ? trim($this->post['remark']):"";
  139. $info['received_num'] = $receive;
  140. $info['normal_num'] = $normal;
  141. $info['remark'] = $remark;
  142. $str = $info['status'];
  143. $info['status'] = 2;
  144. $info['updatetime'] = date("Y-m-d H:i:s");
  145. Db::startTrans();
  146. try{
  147. $up=Db::name("order_back")->save($info);
  148. if($up){
  149. $stn = ["order_code"=>$info['thNo'],"status"=>$str,"action_remark"=>'',"action_type"=>"edit"];
  150. ActionLog::logAdd($this->post['token'],$stn,"BKD",2,$stn);
  151. if(empty($errorlist)){
  152. Db::commit();
  153. return app_show(0,'更新成功');
  154. }
  155. //$temp =[];
  156. foreach($errorlist as $value){
  157. $data=[];
  158. isset($value['id'])&&$value['id']!=''?$data['id']=$value['id']:"";
  159. $data['thNo']=$thNo;
  160. $data['error_num']=$value['error_num'];
  161. $data['error_code']=$value['error_code'];
  162. $data['error_remark']=$value['error_remark'];
  163. $data['is_del']=isset($value['is_del'])?$value['is_del']:0;
  164. isset($value['id'])&&$value['id']!=''? "" : $data['addtime']=date("Y-m-d H:i:s");
  165. $data['updatetime']=date("Y-m-d H:i:s");
  166. $in = Db::name("order_backinfo")->save($data);
  167. if(!$in){
  168. $stm = ["order_code"=>$info['thNo'],"status"=>$str,"action_remark"=>'',"action_type"=>"edit"];
  169. ActionLog::logAdd($this->post['token'],$stm,"BKD",2,$stm);
  170. Db::rollback();
  171. return error_show(1005,'更新失败');
  172. }
  173. }
  174. Db::commit();
  175. return app_show(0,'更新成功');
  176. }
  177. Db::rollback();
  178. return error_show(1005,'更新失败');
  179. }catch (\Exception $e){
  180. Db::rollback();
  181. return error_show(1004,$e->getMessage());
  182. }
  183. }
  184. public function CheckExam(){
  185. $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
  186. if($thNo==""){
  187. return error_show(1004,"参数thNo不能为空");
  188. }
  189. $info =Db::name("order_back")->where(['thNo'=>$thNo])->find();
  190. if(empty($info)){
  191. return error_show(1004,"未找到数据");
  192. }
  193. $errorlist = isset($this->post['errorlist']) && $this->post['errorlist']!=="" ? $this->post['errorlist']:[];
  194. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  195. if($status===""){
  196. return error_show(1004,"参数status不能为空");
  197. }
  198. Db::startTrans();
  199. try{
  200. $temp=$info['status'];
  201. $info['status'] =$status;
  202. $info['updatetime'] = date("Y-m-d H:i:s");
  203. $up=Db::name("order_back")->save($info);
  204. if($up){
  205. $stn = ["order_code"=>$thNo,"status"=>$temp,"action_remark"=>'',"action_type"=>"edit"];
  206. ActionLog::logAdd($this->post['token'],$stn,"BKD",$info['status'],$stn);
  207. if(empty($errorlist)){
  208. Db::commit();
  209. return app_show(0,'更新成功');
  210. }
  211. // $temp =[];
  212. foreach($errorlist as $value){
  213. $temp=Db::name("order_backinfo")->where(['id'=>$value["id"],"is_del"=>0,"thNo"=>$thNo])->find();
  214. if(empty($temp)){
  215. Db::rollback();
  216. return error_show(1005,'异常记录数据未找到');
  217. }
  218. $temp['status']=$value['status'];
  219. $temp['exam_remark']=$value['remark'];
  220. $temp['updatetime']=date("Y-m-d H:i:s");
  221. $com = Db::name("order_backinfo")->save($temp);
  222. if($com==false){
  223. Db::rollback();
  224. return error_show(1005,'异常记录数据更新失败');
  225. }
  226. }
  227. Db::commit();
  228. return app_show(0,'更新成功');
  229. }
  230. Db::rollback();
  231. return error_show(1005,'更新失败');
  232. }catch (\Exception $e){
  233. Db::rollback();
  234. return error_show(1004,$e->getMessage());
  235. }
  236. }
  237. public function Exam(){
  238. $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
  239. if($thNo==""){
  240. return error_show(1004,"参数thNo不能为空");
  241. }
  242. $info =Db::name("order_back")->where(['thNo'=>$thNo])->find();
  243. if(empty($info)){
  244. return error_show(1004,"未找到数据");
  245. }
  246. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  247. if($status===""){
  248. return error_show(1004,"参数status不能为空");
  249. }
  250. $remark= isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  251. Db::startTrans();
  252. try{
  253. $var = $info['status'];
  254. $info['status'] =$status;
  255. $info['remark'] =$remark;
  256. $info['updatetime'] = date("Y-m-d H:i:s");
  257. $up=Db::name("order_back")->save($info);
  258. if($up){
  259. $stn = ["order_code"=>$thNo,"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
  260. ActionLog::logAdd($this->post['token'],$stn,"BKD",$info['status'],$stn);
  261. Db::commit();
  262. return app_show(0,'更新成功');
  263. }
  264. Db::rollback();
  265. return error_show(1005,'更新失败');
  266. }catch (\Exception $e){
  267. Db::rollback();
  268. return error_show(1004,$e->getMessage());
  269. }
  270. }
  271. }