Orderback.php 16 KB

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