Orderback.php 16 KB

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