Orderback.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  217. if($status===""){
  218. return error_show(1004,"参数status不能为空");
  219. }
  220. Db::startTrans();
  221. try{
  222. $temp=$info['status'];
  223. $info['status'] =$status;
  224. $info['updatetime'] = date("Y-m-d H:i:s");
  225. $up=Db::name("order_back")->save($info);
  226. if($up){
  227. $stn = ["order_code"=>$thNo,"status"=>$temp,"action_remark"=>'',"action_type"=>"edit"];
  228. ActionLog::logAdd($this->post['token'],$stn,$info['order_type'] == 2?"ZXCKTHD":"CKTHD",$info['status'],$stn);
  229. $process=["order_code"=>$info['thNo'],"order_id"=>$info['id'],"order_status"=>$status,"order_type"=>$info['order_type'] == 2?"ZXCKTHD":"CKTHD"];
  230. ProcessOrder::AddProcess($this->post['token'],$process);
  231. if(empty($errorlist)){
  232. Db::commit();
  233. return app_show(0,'更新成功');
  234. }
  235. // $temp =[];
  236. foreach($errorlist as $value){
  237. $temp=Db::name("order_backinfo")->where(['id'=>$value["id"],"is_del"=>0,"thNo"=>$thNo])->find();
  238. if(empty($temp)){
  239. Db::rollback();
  240. return error_show(1005,'异常记录数据未找到');
  241. }
  242. $temp['status']=$value['status'];
  243. $temp['exam_remark']=$value['remark'];
  244. $temp['updatetime']=date("Y-m-d H:i:s");
  245. $com = Db::name("order_backinfo")->save($temp);
  246. if($com==false){
  247. Db::rollback();
  248. return error_show(1005,'异常记录数据更新失败');
  249. }
  250. }
  251. Db::commit();
  252. return app_show(0,'更新成功');
  253. }
  254. Db::rollback();
  255. return error_show(1005,'更新失败');
  256. }catch (\Exception $e){
  257. Db::rollback();
  258. return error_show(1004,$e->getMessage());
  259. }
  260. }
  261. public function Exam(){
  262. $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
  263. if($thNo==""){
  264. return error_show(1004,"参数thNo不能为空");
  265. }
  266. $info =Db::name("order_back")->where(['thNo'=>$thNo])->find();
  267. if(empty($info)){
  268. return error_show(1004,"未找到数据");
  269. }
  270. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  271. if($status===""){
  272. return error_show(1004,"参数status不能为空");
  273. }
  274. $remark= isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  275. Db::startTrans();
  276. try{
  277. $var = $info['status'];
  278. $info['status'] =$status;
  279. $info['remark'] =$remark;
  280. $info['updatetime'] = date("Y-m-d H:i:s");
  281. $up=Db::name("order_back")->save($info);
  282. if($up){
  283. $stn = ["order_code"=>$thNo,"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
  284. ActionLog::logAdd($this->post['token'],$stn,$info['order_type'] == 2?"ZXCKTHD":"CKTHD",$info['status'],$stn);
  285. $process=["order_code"=>$info['thNo'],"order_id"=>$info['id'],"order_status"=>$status,"order_type"=>$info['order_type'] == 2?"ZXCKTHD":"CKTHD"];
  286. ProcessOrder::AddProcess($this->post['token'],$process);
  287. Db::commit();
  288. return app_show(0,'更新成功');
  289. }
  290. Db::rollback();
  291. return error_show(1005,'更新失败');
  292. }catch (\Exception $e){
  293. Db::rollback();
  294. return error_show(1004,$e->getMessage());
  295. }
  296. }
  297. }