Orderback.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. $goon = Db::name('good')->alias('b')->join("good_type a", "a.good_code=b.good_code", "left")
  107. ->where(['a.type_code' => $info['good_code']])->find();
  108. if (empty($goon)) {
  109. return error_show(1003, "未找到商品数据");
  110. }
  111. $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  112. $info['wsm_name']="";
  113. $info['wsm_supplier']='';
  114. $info['wsm_supplierNo']='';
  115. if($info['return_wsm']!=""){
  116. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  117. ->where(["a.wsm_code"=>$info['return_wsm']])->field("a.name as wsm_name,b.name,b.code")->find();
  118. $info['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  119. $info['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  120. $info['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  121. }
  122. $inorder= Db::name("order_backinfo")->alias("a")->leftJoin("result_info b","a.error_code=b.result_code")
  123. ->where(['a.thNo'=>$info['thNo'],"a.is_del"=>0])->field("a.*,b.result as error_msg")->select();
  124. $info['child']=empty($inorder)? [] : $inorder;
  125. $info['can']=$int;
  126. return app_show(0,"获取成功",$info);
  127. }
  128. /**
  129. * @return \think\response\Json|void
  130. * @throws \think\db\exception\DataNotFoundException
  131. * @throws \think\db\exception\DbException
  132. * @throws \think\db\exception\ModelNotFoundException
  133. */
  134. public function check(){
  135. $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
  136. if($thNo==""){
  137. return error_show(1004,"参数thNo不能为空");
  138. }
  139. $info =Db::name("order_back")->where(['thNo'=>$thNo])->find();
  140. if(empty($info)){
  141. return error_show(1004,"未找到数据");
  142. }
  143. // $receive = isset($this->post['receive']) && $this->post['receive']!="" ? intval($this->post['receive']):"";
  144. // if($receive==""){
  145. // return error_show(1004,"参数receive不能为空");
  146. // }
  147. $normal = isset($this->post['normal']) && $this->post['normal']!=="" ? intval($this->post['normal']):"";
  148. if($normal===""){
  149. return error_show(1004,"参数normal不能为空");
  150. }
  151. $errorlist = isset($this->post['errorlist']) && $this->post['errorlist']!=="" ? $this->post['errorlist']:[];
  152. if($info['status']== 2){
  153. return error_show(1002,"退货单已验货");
  154. }
  155. $receive=$normal+array_sum(array_column($errorlist,'error_num'));
  156. $remark = isset($this->post['remark']) && $this->post['remark']!=="" ? trim($this->post['remark']):"";
  157. $info['received_num'] = $receive;
  158. $info['normal_num'] = $normal;
  159. $info['remark'] = $remark;
  160. $str = $info['status'];
  161. $info['status'] = 2;
  162. $info['updatetime'] = date("Y-m-d H:i:s");
  163. Db::startTrans();
  164. try{
  165. $up=Db::name("order_back")->save($info);
  166. if($up){
  167. $stn = ["order_code"=>$info['thNo'],"status"=>$str,"action_remark"=>'',"action_type"=>"edit"];
  168. ActionLog::logAdd($this->post['token'],$stn,$info['order_type'] == 2?"ZXCKTHD":"CKTHD",2,$info);
  169. $process=["order_code"=>$info['thNo'],"order_id"=>$info['id'],"order_status"=>2,"order_type"=>$info['order_type'] == 2?"ZXCKTHD":"CKTHD"];
  170. ProcessOrder::AddProcess($this->post['token'],$process);
  171. if(empty($errorlist)){
  172. Db::commit();
  173. return app_show(0,'更新成功');
  174. }
  175. //$temp =[];
  176. foreach($errorlist as $value){
  177. $data=[];
  178. isset($value['id'])&&$value['id']!=''?$data['id']=$value['id']:"";
  179. $data['thNo']=$thNo;
  180. $data['error_num']=$value['error_num'];
  181. $data['error_code']=$value['error_code'];
  182. $data['error_remark']=$value['error_remark'];
  183. $data['is_del']=isset($value['is_del'])?$value['is_del']:0;
  184. isset($value['id'])&&$value['id']!=''? "" : $data['addtime']=date("Y-m-d H:i:s");
  185. $data['updatetime']=date("Y-m-d H:i:s");
  186. $in = Db::name("order_backinfo")->save($data);
  187. if(!$in){
  188. Db::rollback();
  189. return error_show(1005,'更新失败');
  190. }
  191. }
  192. Db::commit();
  193. return app_show(0,'更新成功');
  194. }
  195. Db::rollback();
  196. return error_show(1005,'更新失败');
  197. }catch (\Exception $e){
  198. Db::rollback();
  199. return error_show(1004,$e->getMessage());
  200. }
  201. }
  202. public function CheckExam(){
  203. $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
  204. if($thNo==""){
  205. return error_show(1004,"参数thNo不能为空");
  206. }
  207. $info =Db::name("order_back")->where(['thNo'=>$thNo])->find();
  208. if(empty($info)){
  209. return error_show(1004,"未找到数据");
  210. }
  211. $errorlist = isset($this->post['errorlist']) && $this->post['errorlist']!=="" ? $this->post['errorlist']:[];
  212. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  213. if($status===""){
  214. return error_show(1004,"参数status不能为空");
  215. }
  216. Db::startTrans();
  217. try{
  218. $temp=$info['status'];
  219. $info['status'] =$status;
  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"=>$status,"order_type"=>$info['order_type'] == 2?"ZXCKTHD":"CKTHD"];
  226. ProcessOrder::AddProcess($this->post['token'],$process);
  227. if(empty($errorlist)){
  228. Db::commit();
  229. return app_show(0,'更新成功');
  230. }
  231. // $temp =[];
  232. foreach($errorlist as $value){
  233. $temp=Db::name("order_backinfo")->where(['id'=>$value["id"],"is_del"=>0,"thNo"=>$thNo])->find();
  234. if(empty($temp)){
  235. Db::rollback();
  236. return error_show(1005,'异常记录数据未找到');
  237. }
  238. $temp['status']=$value['status'];
  239. $temp['exam_remark']=$value['remark'];
  240. $temp['updatetime']=date("Y-m-d H:i:s");
  241. $com = Db::name("order_backinfo")->save($temp);
  242. if($com==false){
  243. Db::rollback();
  244. return error_show(1005,'异常记录数据更新失败');
  245. }
  246. }
  247. Db::commit();
  248. return app_show(0,'更新成功');
  249. }
  250. Db::rollback();
  251. return error_show(1005,'更新失败');
  252. }catch (\Exception $e){
  253. Db::rollback();
  254. return error_show(1004,$e->getMessage());
  255. }
  256. }
  257. public function Exam(){
  258. $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
  259. if($thNo==""){
  260. return error_show(1004,"参数thNo不能为空");
  261. }
  262. $info =Db::name("order_back")->where(['thNo'=>$thNo])->find();
  263. if(empty($info)){
  264. return error_show(1004,"未找到数据");
  265. }
  266. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  267. if($status===""){
  268. return error_show(1004,"参数status不能为空");
  269. }
  270. $remark= isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  271. Db::startTrans();
  272. try{
  273. $var = $info['status'];
  274. $info['status'] =$status;
  275. $info['remark'] =$remark;
  276. $info['updatetime'] = date("Y-m-d H:i:s");
  277. $up=Db::name("order_back")->save($info);
  278. if($up){
  279. $stn = ["order_code"=>$thNo,"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
  280. ActionLog::logAdd($this->post['token'],$stn,$info['order_type'] == 2?"ZXCKTHD":"CKTHD",$info['status'],$stn);
  281. $process=["order_code"=>$info['thNo'],"order_id"=>$info['id'],"order_status"=>$status,"order_type"=>$info['order_type'] == 2?"ZXCKTHD":"CKTHD"];
  282. ProcessOrder::AddProcess($this->post['token'],$process);
  283. Db::commit();
  284. return app_show(0,'更新成功');
  285. }
  286. Db::rollback();
  287. return error_show(1005,'更新失败');
  288. }catch (\Exception $e){
  289. Db::rollback();
  290. return error_show(1004,$e->getMessage());
  291. }
  292. }
  293. }