After.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  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 After 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 create(){
  16. $outCode = isset($this->post['outCode']) &&$this->post['outCode']!=''?trim($this->post['outCode']) :"";
  17. if($outCode==''){
  18. return error_show(1004,"参数outCode 不能为空");
  19. }
  20. $orderout= Db::name("order_out")->where(["outCode"=>$outCode])->find();
  21. if(empty($orderout)){
  22. return error_show(1005,"未找到订单数据");
  23. }
  24. $oder= Db::name("sale")->where(["orderCode"=>$orderout['orderCode'],"is_del"=>0])->find();
  25. if(empty($oder)){
  26. return error_show(1005,"未找到订单数据");
  27. }
  28. $errorCode = isset($this->post['errorCode']) &&$this->post['errorCode']!=''?trim($this->post['errorCode']) :"";
  29. if($outCode==''){
  30. return error_show(1004,"参数errorCode 不能为空");
  31. }
  32. $error =Db::name('result_info')->where(["result_code"=>$errorCode,"is_del"=>0])->find();
  33. if(empty($error)){
  34. return error_show(1005,"未找到退货原因数据");
  35. }
  36. if($orderout['status']==1){
  37. $num=$orderout['send_num'];
  38. $orde_status = 1;
  39. }else{
  40. $orde_status = 2;
  41. $num =isset($this->post['num']) &&$this->post['num']!=''?intval($this->post['num']) :"";
  42. if($num==""){
  43. return error_show(1004,"参数 num 不能为空或零");
  44. }
  45. }
  46. $remark =isset($this->post['remark']) &&$this->post['remark']!=''?trim($this->post['remark']) :"";
  47. $is_receive =isset($this->post['is_receive']) &&$this->post['is_receive']!==''?intval($this->post['is_receive'])
  48. :"";
  49. if($is_receive===""){
  50. return error_show(1004,"参数 is_receive 不能为空");
  51. }
  52. $except_code =isset($this->post['except_code']) &&$this->post['except_code']!=''?trim($this->post['except_code']) :"";
  53. $img = isset($this->post['img']) &&$this->post['img']!=''?trim($this->post['img']) :"";
  54. $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
  55. if($token==''){
  56. return error_show(105,"参数token不能为空");
  57. }
  58. $user =GetUserInfo($token);
  59. if(empty($user)||$user['code']!=0){
  60. return error_show(102,"申请人数据不存在");
  61. }
  62. $rm= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  63. $ri= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  64. $returnCode=makeNo("RXS");
  65. Db::startTrans();
  66. try{
  67. $in = [
  68. "returnCode"=>$returnCode,
  69. "outCode"=>$outCode,
  70. "orderCode"=> $oder['orderCode'],
  71. "good_code"=>$oder['good_code'],
  72. "good_name"=>$oder['good_name'],
  73. "customer_code"=>$oder['customer_code'],
  74. "apply_id"=>$rm,
  75. "apply_name"=>$ri,
  76. "order_status"=>$orde_status,
  77. 'total_num'=>$orderout['send_num'],
  78. "error_code"=>$errorCode,
  79. "error_num"=>$num,
  80. "error_img"=>$img,
  81. "error_msg"=>$error['result'],
  82. "error_remark"=>$remark,
  83. "is_receive"=>$is_receive,
  84. "remark"=>'',
  85. "except_code"=>$except_code,
  86. "order_type"=>$orderout['order_type'],
  87. "status"=>0,
  88. "is_del"=>0,
  89. "addtime"=>date("Y-m-d H:i:s"),
  90. "updatetime"=>date("Y-m-d H:i:s")
  91. ];
  92. $create = Db::name("order_return")->insert($in,true);
  93. $orde = ["order_code"=>$returnCode,"status"=>$in['status'],"action_remark"=>'',"action_type"=>"create"];
  94. ActionLog::logAdd($this->post['token'],$orde,$orderout['order_type']==1?'SHD':"ZXSHD",0,$orde);
  95. if($create>0){
  96. $process=["order_code"=>$returnCode,"order_id"=>$create,"order_status"=>0,"order_type"=>$orderout['order_type']==1?'SHD':"ZXSHD"];
  97. ProcessOrder::AddProcess($token,$process);
  98. Db::commit();
  99. return app_show(0,"售后申请单新建成功");
  100. }
  101. Db::rollback();
  102. return error_show(1005,"售后申请单新建失败");
  103. }catch (\Exception $e){
  104. Db::rollback();
  105. return error_show(1005,$e->getMessage());
  106. }
  107. }
  108. public function list(){
  109. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  110. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  111. $where =[['a.is_del',"=",0]];
  112. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  113. if($bkcode!=""){
  114. $where[]=['a.returnCode',"like", "%{$bkcode}%"];
  115. }
  116. $out = isset($this->post['outCode']) && $this->post['outCode']!="" ? trim($this->post['outCode']):"";
  117. if($out!=""){
  118. $where[]=['a.outCode',"like", "%{$out}%"];
  119. }
  120. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  121. if($status!==""){
  122. $where[]=['a.status',"=", $status];
  123. }
  124. $order_type = isset($this->post['order_type']) && $this->post['order_type']!=="" ? intval($this->post['order_type']):"";
  125. if($order_type!==""){
  126. $where[]=['a.order_type',"=", $order_type];
  127. }
  128. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode']!="" ? trim($this->post['orderCode'])
  129. :"";
  130. if($orderCode!=""){
  131. $where[]=['a.orderCode',"like", "%{$orderCode}%"];
  132. }
  133. $good_code = isset($this->post['good_code']) && $this->post['good_code']!="" ? trim($this->post['good_code'])
  134. :"";
  135. if($good_code!=""){
  136. $where[]=['a.good_code',"like", "%{$good_code}%"];
  137. }
  138. $good_name = isset($this->post['good_name']) && $this->post['good_name']!="" ? trim($this->post['good_name'])
  139. :"";
  140. if($good_name!=""){
  141. $where[]=['a.good_name',"like", "%{$good_name}%"];
  142. }
  143. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code']!="" ? trim($this->post['customer_code'])
  144. :"";
  145. if($customer_code!=""){
  146. $where[]=['a.customer_code',"like", "%{$customer_code}%"];
  147. }
  148. $except_code = isset($this->post['except_code']) && $this->post['except_code']!="" ? trim($this->post['except_code']):"";
  149. if($except_code!=""){
  150. $where[]=['a.except_code',"=", $except_code];
  151. }
  152. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name']!="" ? trim($this->post['apply_name'])
  153. :"";
  154. if($apply_name!=""){
  155. $where[]=['a.apply_name',"like", "%{$apply_name}%"];
  156. }
  157. $start =isset($this->post['start'])&&$this->post['start']!='' ? $this->post['start']:"";
  158. if($start!==""){
  159. $where[]=['a.addtime',">=", $start];
  160. }
  161. $end =isset($this->post['end'])&&$this->post['end']!='' ? $this->post['end']:"";
  162. if($end!==""){
  163. $where[]=['a.addtime',"<=", $end];
  164. }
  165. $count=Db::name("order_return")->alias("a")->leftJoin("order_returninfo b","a.returnCode=b.returnCode")->where
  166. ($where)->count();
  167. $total = ceil($count/$size);
  168. $page = $total>=$page ? $page :$total;
  169. $list =Db::name("order_return")->alias("a")->leftJoin("order_returninfo b","a.returnCode=b.returnCode")->where($where)
  170. ->field("a.*,b.return_wsm,b.contactor,b.mobile,b.addr,b.addr_code,b.post_code,b.post_company,b.post_fee,b.gys_remark")->page($page,$size)
  171. ->order("addtime desc")->select();
  172. $data=[];
  173. foreach ($list as $value){
  174. $customer = Db::name("customer_info")->where(["companyNo"=>$value['customer_code']])->find();
  175. $value['customer_name'] = isset($customer['companyName']) ?trim($customer['companyName']):'';
  176. $data[]=$value;
  177. }
  178. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  179. }
  180. /**
  181. * @return \think\response\Json|void
  182. * @throws \think\db\exception\DataNotFoundException
  183. * @throws \think\db\exception\DbException
  184. * @throws \think\db\exception\ModelNotFoundException
  185. */
  186. public function info(){
  187. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  188. if($bkcode==""){
  189. return error_show(1005,"参数returnCode 不能为空");
  190. }
  191. $info = Db::name("order_return")->alias("a")->leftJoin("order_returninfo b","a.returnCode=b.returnCode")
  192. ->field("a.*,b.return_wsm,b.contactor,b.mobile,b.addr,b.addr_code,b.post_code,b.post_company,b.post_fee,b.gys_remark")
  193. ->where(['a.returnCode'=>$bkcode])->find();
  194. if(empty($info)){
  195. return error_show(1005,"未找到售后数据");
  196. }
  197. $orderinfo = Db::name("sale")->where(["orderCode"=>$info["orderCode"]])->find();
  198. $info['origin_price']=$orderinfo['origin_price'];
  199. $info['sale_price']=$orderinfo['sale_price'];
  200. $info['total_price']=sprintf("%1\$.2f",$orderinfo['sale_price']*$info['error_num']);
  201. $goon = Db::name('good')->alias('b')->join("good_type a", "a.good_code=b.good_code", "left")
  202. ->where(['a.type_code' => $info['good_code']])->find();
  203. if (empty($goon)) {
  204. return error_show(1003, "未找到商品数据");
  205. }
  206. $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  207. $info["addr_cn"]=GetAddr($info['addr_code']);
  208. $info["addr_code"]=json_decode($info['addr_code'],true);
  209. $out =Db::name("order_out")->where(["outCode"=>$info['outCode']])->find();
  210. $info['out_num'] = isset($out['send_num'])?$out['send_num']:'';
  211. $customer = Db::name("customer_info")->where(["companyNo"=>$info['customer_code']])->find();
  212. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  213. ->where(["a.wsm_code"=>$info['return_wsm']])->field("a.name as wsm_name,b.name,b.code,a.wsm_code")->find();
  214. $info['wsm_code'] =isset($wsmcode['wsm_code']) ? $wsmcode['wsm_code']:"";
  215. $info['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  216. $info['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  217. $info['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  218. $info['customer_name'] = isset($customer['companyName']) ?trim($customer['companyName']):'';
  219. $info['can']=$int;
  220. return app_show(0,"获取成功",$info);
  221. }
  222. public function status(){
  223. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  224. if($bkcode==""){
  225. return error_show(1005,"参数returnCode 不能为空");
  226. }
  227. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  228. if(empty($info)){
  229. return error_show(1005,"未找到售后数据");
  230. }
  231. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status'])
  232. :"";
  233. if($status===""){
  234. return error_show(1005,"参数status 不能为空");
  235. }
  236. $orde= Db::name("order_out")->where(["outCode"=>$info['outCode'],"is_del"=>0])->find();
  237. if(empty($orde)){
  238. return error_show(1005,"未找到出库单数据");
  239. }
  240. $remark = isset($this->post['remark'])&&$this->post['remark']!=''?trim($this->post['remark']):"";
  241. if($remark!=''){
  242. $info['remark'] =$remark;
  243. }
  244. if($status==3){
  245. $post =isset($this->post['is_post'])&&$this->post['is_post']!==""? intval($this->post['is_post']):"";
  246. if($post===""){
  247. return error_show(1005,"参数is_post不能为空");
  248. }
  249. $info['is_post']=$post;
  250. }
  251. // $status = $info['order_status']==1&&$info['order_type']==1 && $status==1?4:$status;
  252. Db::startTrans();
  253. try{
  254. $var=$info['status'];
  255. $info['status']=$status;
  256. $info['updatetime']=date("Y-m-d H:i:s");
  257. $up =Db::name("order_return")->save($info);
  258. if($up){
  259. // if($info['order_status']==1&&$info['order_type']==1 && $status==4){
  260. // $orderout= Db::name("order_out")->where($orde)->save(['status'=>3,"updatetime"=>date("Y-m-d H:i:s")]);
  261. // $order = ["order_code"=>$orde['outCode'],"status"=>$orde['status'],"action_remark"=>'',"action_type"=>"edit"];
  262. // ActionLog::logAdd($this->post['token'],$order,$orde['order_type']==1?'CKD':"ZXCKD", 3,['status'=>3,"updatetime"=>date("Y-m-d H:i:s")]);
  263. // $process=["order_code"=>$orde['outCode'],"order_id"=>$orde['id'],"order_status"=>3,"order_type"=>$orde['order_type']==1?'CKD':"ZXCKD"];
  264. // ProcessOrder::AddProcess($this->post['token'],$process);
  265. // if($orderout){
  266. // Db::commit();
  267. // return app_show(0,"更新成功");
  268. // }else{
  269. // Db::rollback();
  270. // return error_show(1004,"更新失败");
  271. // }
  272. // }
  273. $order = ["order_code"=>$info['returnCode'],"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
  274. ActionLog::logAdd($this->post['token'],$order,$info['order_type']==1?'SHD':"ZXSHD", $info['status'],$this->post);
  275. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$status,"order_type"=>$info['order_type']==1?'SHD':"ZXSHD"];
  276. ProcessOrder::AddProcess($this->post['token'],$process);
  277. Db::commit();
  278. return app_show(0,"更新成功");
  279. }else{
  280. Db::rollback();
  281. return error_show(1004,"更新失败");
  282. }
  283. }catch (\Exception $e){
  284. Db::rollback();
  285. return error_show(1004,$e->getMessage());
  286. }
  287. }
  288. public function setWsm(){
  289. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  290. if($bkcode==""){
  291. return error_show(1005,"参数returnCode 不能为空");
  292. }
  293. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  294. if(empty($info)){
  295. return error_show(1005,"未找到售后数据");
  296. }
  297. if($info['status']!=3){
  298. return error_show(1005,"采购主管未审核无法设置退回仓库");
  299. }
  300. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code'])
  301. :"";
  302. if($wsm_code==""){
  303. return error_show(1005,"参数wsm_code 不能为空");
  304. }
  305. $addrcode=isset($this->post['addr_code'])&&$this->post['addr_code']!=""?$this->post['addr_code']:"";
  306. if($addrcode==""){
  307. return error_show(1005,"参数 addr_code 不能为空");
  308. }
  309. $addr=isset($this->post['addr'])&&$this->post['addr']!=""?trim($this->post['addr']):"";
  310. if($addr==""){
  311. return error_show(1005,"参数 addr 不能为空");
  312. }
  313. $mobile=isset($this->post['mobile'])&&$this->post['mobile']!=""?trim($this->post['mobile']):"";
  314. if($mobile==""){
  315. return error_show(1005,"参数 mobile 不能为空");
  316. }
  317. $contactor=isset($this->post['contactor'])&&$this->post['contactor']!=""?trim($this->post['contactor']):"";
  318. if($contactor==""){
  319. return error_show(1005,"参数 contactor 不能为空");
  320. }
  321. $returninfo=[
  322. "returnCode"=>$bkcode,
  323. "return_wsm"=>$wsm_code,
  324. "contactor"=>$contactor,
  325. "mobile"=>$mobile ,
  326. "addr"=>$addr,
  327. "addr_code"=>$addrcode,
  328. "addtime"=>date("Y-m-d H:i:s")
  329. ];
  330. Db::startTrans();
  331. try {
  332. $in=Db::name("order_returninfo")->insert($returninfo);
  333. if($in){
  334. $info['status']=4;
  335. $info["updatetime"]=date("Y-m-d H:i:s");
  336. $up =Db::name("order_return")->save($info);
  337. if($up){
  338. Db::commit();
  339. return app_show(0,"退货仓库设置成功");
  340. }
  341. }
  342. Db::rollback();
  343. return error_show(1004,"设置失败");
  344. }catch (\Exception $e){
  345. Db::rollback();
  346. return error_show(1004,$e->getMessage());
  347. }
  348. }
  349. /**
  350. * @return \think\response\Json|void
  351. * @throws \think\db\exception\DataNotFoundException
  352. * @throws \think\db\exception\DbException
  353. * @throws \think\db\exception\ModelNotFoundException
  354. */
  355. public function postfeed(){
  356. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  357. if($bkcode==""){
  358. return error_show(1005,"参数returnCode 不能为空");
  359. }
  360. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  361. if(empty($info)){
  362. return error_show(1005,"未找到售后数据");
  363. }
  364. $contactor = isset($this->post['contactor']) && $this->post['contactor']!="" ? trim($this->post['contactor']) :"";
  365. $mobile = isset($this->post['mobile']) && $this->post['mobile']!="" ? trim($this->post['mobile']):"";
  366. $addr = isset($this->post['addr']) && $this->post['addr']!="" ? trim($this->post['addr']):"";
  367. $addr_code = isset($this->post['addr_code']) && $this->post['addr_code']!=""&&!empty($this->post['addr_code']) ?
  368. $this->post['addr_code']:"";
  369. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  370. if($wsm_code==""){
  371. return error_show(1005,"参数 wsm_code不能为空");
  372. }
  373. // var_dump($contactor);
  374. if($info['is_th']==0&&$info['order_type']==1) {
  375. $wsm = Db::name("warehouse_info")->where(["wsm_code" => $wsm_code])->find();
  376. if (empty($wsm)) {
  377. return error_show(1005, "未找到仓库数据");
  378. }
  379. $sm = Db::name("warehouse_addr")->where(["wsm_code" => $wsm_code,"is_del"=>0])->find();
  380. // var_dump(Db::name("warehouse_addr")->getLastSql());
  381. $contactor==""?(isset($sm['wsm_name']) ? $contactor=$sm['wsm_name']:""):"";
  382. $sm['wsm_name'] =isset($sm['wsm_name']) ? $sm['wsm_name']:"";
  383. $mobile==""?(isset($sm['wsm_mobile']) ? $mobile=$sm['wsm_mobile']:""):"";
  384. $sm['wsm_mobile'] =isset($sm['wsm_mobile']) ? $sm['wsm_mobile']:"";
  385. $addr==""?(isset($sm['wsm_addr']) ? $addr=$sm['wsm_addr']:""):"";
  386. $sm['wsm_addr'] =isset($sm['wsm_addr']) ? $sm['wsm_addr']:"";
  387. $addr_code==""?(isset($sm['addr_code']) ? $addr=$sm['addr_code']:""):"";
  388. $sm['addr_code'] =isset($sm['addr_code']) ? $sm['addr_code']:"";
  389. }
  390. //var_dump($contactor);
  391. $remark = isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  392. if($info['is_th']==1 && $info['order_type']==1){
  393. if($contactor==''){
  394. return error_show(1005,"参数 contactor 不能为空");
  395. }
  396. if($mobile==''){
  397. return error_show(1005,"参数 mobile 不能为空");
  398. }
  399. if($addr==''){
  400. return error_show(1005,"参数 addr 不能为空");
  401. }
  402. if($addr_code==''){
  403. return error_show(1005,"参数 addr_code 不能为空");
  404. }
  405. if($addr_code!==''&&is_array($addr_code)){
  406. $addrs=[];
  407. $addrs['provice_code'] = $addr_code[0];
  408. $addrs['city_code'] = $addr_code[1];
  409. $addrs['area_code'] = $addr_code[2];
  410. $addr_code = json_encode($addrs);
  411. }
  412. }
  413. Db::startTrans();
  414. try{
  415. $var=$info['status'];
  416. $info['status']=$info['order_type']==1?3:4;
  417. $info['remark']=$remark;
  418. $info['updatetime']=date("Y-m-d H:i:s");
  419. $up =Db::name("order_return")->save($info);
  420. if($up){
  421. // var_dump($contactor);
  422. $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
  423. if(empty($returninfo)){
  424. $returninfo=[
  425. "returnCode"=>$bkcode,
  426. "return_wsm"=>$wsm_code,
  427. "contactor"=>$contactor,
  428. "mobile"=>$mobile ,
  429. "addr"=>$addr,
  430. "addr_code"=>$addr_code,
  431. "addtime"=>date("Y-m-d H:i:s")
  432. ];
  433. }else{
  434. $returninfo['return_wsm'] = $wsm_code;
  435. //if($info['is_th']==1 && $info['order_type']==1) {
  436. $contactor !==""? $returninfo['contactor'] = $contactor:"";
  437. $mobile!==""?$returninfo['mobile'] = $mobile:"";
  438. $addr!==""? $returninfo['addr'] = $addr:"";
  439. $addr_code!==""?$returninfo['addr_code'] = $addr_code:"";
  440. // }
  441. }
  442. // var_dump($contactor);
  443. // var_dump($returninfo);
  444. $in=Db::name("order_returninfo")->save($returninfo);
  445. if($in){
  446. $order = ["order_code"=>$info['returnCode'],"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
  447. ActionLog::logAdd($this->post['token'],$order,$info['order_type']==1?'SHD':"ZXSHD",$info['status'],$order);
  448. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>$info['order_type']==1?'SHD':"ZXSHD"];
  449. ProcessOrder::AddProcess($this->post['token'],$process);
  450. Db::commit();
  451. return app_show(0,"更新成功");
  452. }
  453. }
  454. Db::rollback();
  455. return error_show(1004,"更新失败");
  456. }catch (\Exception $e){
  457. Db::rollback();
  458. return error_show(1004,$e->getMessage());
  459. }
  460. }
  461. /**
  462. * @return \think\response\Json|void
  463. * @throws \think\db\exception\DataNotFoundException
  464. * @throws \think\db\exception\DbException
  465. * @throws \think\db\exception\ModelNotFoundException
  466. */
  467. public function addpost(){
  468. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  469. if($bkcode==""){
  470. return error_show(1005,"参数returnCode 不能为空");
  471. }
  472. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  473. if(empty($info)){
  474. return error_show(1005,"未找到售后数据");
  475. }
  476. $return_info = Db::name("order_returninfo")->where(['returnCode'=>$bkcode])->find();
  477. if(empty($return_info)){
  478. $return_info=[
  479. "returnCode"=>$bkcode,
  480. "return_wsm"=>'',
  481. "contactor"=>'',
  482. "mobile"=>'',
  483. "addr"=>'',
  484. "addr_code"=>'',
  485. "addtime"=>date("Y-m-d H:i:s"),
  486. "post_company"=>'',
  487. "post_code"=>'',
  488. "post_fee"=>'',
  489. ];
  490. }
  491. $post_own = isset($this->post['own']) &&$this->post['own']!='' ? trim($this->post['own']):"";
  492. if($post_own==''){
  493. return error_show(1005,"参数own不能为空");
  494. }
  495. $info['post_own'] = $post_own;
  496. $post_company = isset($this->post['company'])&&$this->post['company']!='' ? trim($this->post['company']):"";
  497. if($post_company==''){
  498. return error_show(1005,"参数company不能为空");
  499. }
  500. $return_info['post_company'] = $post_company;
  501. $post_code = isset($this->post['post_code'])&&$this->post['post_code']!='' ? trim($this->post['post_code']):"";
  502. if($post_code==''){
  503. return error_show(1005,"参数post_code不能为空");
  504. }
  505. $return_info['post_code'] = $post_code;
  506. $fee= isset($this->post['post_fee'])&&$this->post['post_fee']!=='' ? round($this->post['post_fee'],2):"";
  507. if($fee===''){
  508. return error_show(1005,"参数post_fee不能为空");
  509. }
  510. $return_info['post_fee'] = $fee;
  511. Db::startTrans();
  512. try{
  513. $str=$info['status'];
  514. $info['status']=$info['order_type']==1?4:5;
  515. $info['updatetime']=date("Y-m-d H:i:s");
  516. $up =Db::name("order_return")->save($info);
  517. if($up){
  518. $order = ["order_code"=>$info['orderCode'],"status"=>$str,"action_remark"=>'',"action_type"=>"edit"];
  519. ActionLog::logAdd($this->post['token'],$order,$info['order_type']==1?'SHD':"ZXSHD",$info['status'],$order);
  520. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>$info['order_type']==1?'SHD':"ZXSHD"];
  521. ProcessOrder::AddProcess($this->post['token'],$process);
  522. $in=Db::name("order_returninfo")->save($return_info);
  523. if($in){
  524. $data=[
  525. 'thNo'=>makeNo("TH"),
  526. "orderCode"=>$info['orderCode'],
  527. "order_type"=>$info['order_type'],
  528. "outCode"=>$info['outCode'],
  529. "returnCode"=>$info['returnCode'],
  530. "good_code"=>$info['good_code'],
  531. "good_name"=>$info['good_name'],
  532. "return_wsm"=>$return_info['return_wsm'],
  533. "return_num"=>$info['error_num'],
  534. "contactor"=>$return_info['contactor'],
  535. "mobile"=>$return_info['mobile'],
  536. "addr"=>$return_info['addr'],
  537. "addr_code"=>$return_info['addr_code'],
  538. "return_code"=>$info['error_code'],
  539. "return_msg"=>$info['error_msg'],
  540. "post_fee"=>$return_info['post_fee'],
  541. "post_code"=>$return_info['post_code'],
  542. "post_company"=>$return_info['post_company'],
  543. "customer_code"=>$info['customer_code'],
  544. "addtime"=>date("Y-m-d H:i:s"),
  545. "updatetime"=>date("Y-m-d H:i:s")
  546. ];
  547. $back =Db::name("order_back")->insert($data,true);
  548. if($back>0){
  549. $order = ["order_code"=>$data['thNo'],"status"=>0,"action_remark"=>'',"action_type"=>"create"];
  550. ActionLog::logAdd($this->post['token'],$order,$info['order_type']==1?'SHD':"ZXSHD", 0,$data);
  551. $process=["order_code"=>$data['thNo'],"order_id"=>$back,"order_status"=>0,"order_type"=>$info['order_type']==1?'CKTHD':"ZXCKTHD"];
  552. ProcessOrder::AddProcess($this->post['token'],$process);
  553. Db::commit();
  554. return app_show(0,"更新成功");
  555. }
  556. }
  557. }
  558. Db::rollback();
  559. return error_show(1004,"更新失败");
  560. }catch (\Exception $e){
  561. Db::rollback();
  562. return error_show(1004,$e->getMessage());
  563. }
  564. }
  565. /**
  566. * @return \think\response\Json|void
  567. * @throws \think\db\exception\DataNotFoundException
  568. * @throws \think\db\exception\DbException
  569. * @throws \think\db\exception\ModelNotFoundException
  570. */
  571. public function GysFeed(){
  572. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  573. if($bkcode==""){
  574. return error_show(1005,"参数returnCode 不能为空");
  575. }
  576. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  577. if(empty($info)){
  578. return error_show(1005,"未找到售后数据");
  579. }
  580. $isth = isset($this->post['is_th']) && $this->post['is_th']!="" ? intval($this->post['is_th']):"0";
  581. $contactor = isset($this->post['contactor']) && $this->post['contactor']!="" ? trim($this->post['contactor'])
  582. :"";
  583. $mobile = isset($this->post['mobile']) && $this->post['mobile']!="" ? trim($this->post['mobile']):"";
  584. $addr = isset($this->post['addr']) && $this->post['addr']!="" ? trim($this->post['addr']):"";
  585. $addr_code = isset($this->post['addr_code']) && $this->post['addr_code']!=""&&!empty($this->post['addr_code']) ? $this->post['addr_code']:"";
  586. $remark = isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  587. if($isth==1){
  588. if($contactor==''){
  589. return error_show(1005,"参数 contactor 不能为空");
  590. }
  591. if($mobile==''){
  592. return error_show(1005,"参数 mobile 不能为空");
  593. }
  594. if($addr==''){
  595. return error_show(1005,"参数 addr 不能为空");
  596. }
  597. // var_dump(isset($this->post['addr_code']) , $this->post['addr_code']!="",!empty($addr_code));
  598. if($addr_code==''){
  599. return error_show(1005,"参数 addr_code 不能为空");
  600. }
  601. if(is_array($addr_code)){
  602. $addrs=[];
  603. $addrs['provice_code'] = $addr_code[0];
  604. $addrs['city_code'] = $addr_code[1];
  605. $addrs['area_code'] = $addr_code[2];
  606. $addr_code = json_encode($addrs);
  607. }
  608. }
  609. $orde= Db::name("order_out")->where(["outCode"=>$info['outCode'],"is_del"=>0])->find();
  610. if(empty($orde)){
  611. return error_show(1005,"未找到出库单数据");
  612. }
  613. Db::startTrans();
  614. try{
  615. $stat=$info['status'];
  616. $info['status']=$info['order_status']==1?5:3;
  617. $info['is_th']=$isth;
  618. $info['updatetime']=date("Y-m-d H:i:s");
  619. $up =Db::name("order_return")->save($info);
  620. if($up){
  621. $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
  622. if(empty($returninfo)){
  623. $returninfo=[
  624. "returnCode"=>$bkcode,
  625. "return_wsm"=>'',
  626. "contactor"=>$contactor,
  627. "mobile"=>$mobile ,
  628. "addr"=>$addr,
  629. "addr_code"=>$addr_code,
  630. "gys_remark"=>$remark,
  631. "addtime"=>date("Y-m-d H:i:s")
  632. ];
  633. }else{
  634. $returninfo['return_wsm'] = '';
  635. $returninfo['contactor'] = $contactor;
  636. $returninfo['mobile'] = $mobile;
  637. $returninfo['addr'] = $addr;
  638. $returninfo['gys_remark'] = $remark;
  639. $returninfo['addr_code'] = $addr_code;
  640. }
  641. $in=Db::name("order_returninfo")->save($returninfo);
  642. if($in){
  643. if( $info['order_status']==1&&$info['order_type']==2){
  644. $orderout= Db::name("order_out")->where($orde)->save(['status'=>3,"updatetime"=>date("Y-m-d H:i:s")]);
  645. $order = ["order_code"=>$orde['outCode'],"status"=>$orde['status'],"action_remark"=>'',"action_type"=>"edit"];
  646. ActionLog::logAdd($this->post['token'],$order,$orde['order_type']==1?'CKD':"ZXCKD", 3,
  647. ['status'=>3,"updatetime"=>date("Y-m-d H:i:s")]);
  648. $process=["order_code"=>$orde['outCode'],"order_id"=>$orde['id'],"order_status"=>3,
  649. "order_type"=>$orde['order_type']==1?'CKD':"ZXCKD"];
  650. ProcessOrder::AddProcess($this->post['token'],$process);
  651. if($orderout){
  652. Db::commit();
  653. return app_show(0,"更新成功");
  654. }else{
  655. Db::rollback();
  656. return error_show(1004,"更新失败");
  657. }
  658. }
  659. $order = ["order_code"=>$info['returnCode'],"status"=>$stat,"action_remark"=>'',"action_type"=>"edit"];
  660. ActionLog::logAdd($this->post['token'],$order,$info['order_type']==1?'CKTHD':"ZXCKTHD",3,$order);
  661. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>$info['order_type']==1?'CKTHD':"ZXCKTHD"];
  662. ProcessOrder::AddProcess($this->post['token'],$process);
  663. Db::commit();
  664. return app_show(0,"更新成功");
  665. }
  666. }
  667. Db::rollback();
  668. return error_show(1004,"更新失败");
  669. }catch (\Exception $e){
  670. Db::rollback();
  671. return error_show(1004,$e->getMessage());
  672. }
  673. }
  674. public function GetWsm(){
  675. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  676. if($bkcode==""){
  677. return error_show(1005,"参数returnCode 不能为空");
  678. }
  679. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  680. if(empty($info)){
  681. return error_show(1005,"未找到售后数据");
  682. }
  683. $list=[];
  684. if($info['is_th']==1){
  685. if($info["order_type"]==1){
  686. $out =Db::name("order_out")->where(["outCode"=>$info['outCode']])->find();
  687. if(empty($out)){
  688. return error_show(1005,"未找到出库单数据");
  689. }
  690. $ware = Db::name("warehouse_info")->alias("a")->leftJoin("warehouse_addr b","a.wsm_code=b.wsm_code and b.status=1 and b.is_del=0")
  691. ->where(["a.status"=>1,"wsm_type"=>1,"a.is_del"=>0,"a.supplierNo"=>$out['wsm_code']])->field("a.wsm_code,a.name,b.wsm_name,b.wsm_mobile,b.wsm_addr,b.addr_code")->find();
  692. if(empty($ware)){
  693. return error_show(1005,"未找到仓库数据");
  694. }
  695. $temp['wsm_code']=isset($ware['wsm_code'])?$ware['wsm_code']:"";
  696. $temp['wsm_name']=isset($ware['name'])?$ware['name']:"";
  697. $temp['contactor'] = isset($ware['wsm_name'])?$ware['wsm_name']:"";
  698. $temp['mobile'] =isset($ware['wsm_mobile'])?$ware['wsm_mobile']:"";
  699. $temp['addr'] =isset($ware['wsm_addr'])?$ware['wsm_addr']:"";
  700. $temp['addr_code'] = isset($ware['addr_code'])?$ware['addr_code']:"";
  701. $temp['addr_cn'] =GetAddr( $ware['addr_code']);
  702. $list[]=$temp;
  703. }else {
  704. $returninfo = Db::name("order_returninfo")->where(["returnCode" => $bkcode])->find();
  705. if (empty($returninfo)) {
  706. return error_show(1005, "未找到供应商仓库数据");
  707. }
  708. $data = [];
  709. $data['wsm_code'] = isset($returninfo['return_wsm']) && $returninfo['return_wsm'] != "" ? $returninfo['return_wsm'] : "-";
  710. $data['wsm_name'] = '供应商仓';
  711. $data['supplier_name'] = '供应商';
  712. $data['contactor'] = $returninfo['contactor'];
  713. $data['mobile'] = $returninfo['mobile'];
  714. $data['addr'] = $returninfo['addr'];
  715. $data['addr_cn'] =GetAddr( $returninfo['addr_code']);
  716. $data['addr_code'] = $returninfo['addr_code'];
  717. $list[] = $data;
  718. }
  719. }
  720. $supplier = Db::name("supplier")->where(["is_platform"=>1,"status"=>1,"is_del"=>0])->column("code,name");
  721. if(empty($supplier)){
  722. return error_show(1005,"未找到供应商仓库数据");
  723. }
  724. foreach ($supplier as $value){
  725. $temp=[];
  726. $ware = Db::name("warehouse_info")->alias("a")->leftJoin("warehouse_addr b","a.wsm_code=b.wsm_code and b.status=1 and b.is_del=0")
  727. ->where(["a.wsm_type"=>1,"a.status"=>1,"a.is_del"=>0,"a.supplierNo"=>$value['code']])->field("a.wsm_code,a.name,b.wsm_name,b.wsm_mobile,b.wsm_addr,b.addr_code")->find();
  728. if(empty($ware)){
  729. continue;
  730. }
  731. $temp['wsm_code']=isset($ware['wsm_code'])?$ware['wsm_code']:"";
  732. $temp['wsm_name']=isset($ware['name'])?$ware['name']:"";
  733. $temp['supplier_name']=$value['name'];
  734. $temp['contactor'] = isset($ware['wsm_name'])?$ware['wsm_name']:"";
  735. $temp['mobile'] =isset($ware['wsm_mobile'])?$ware['wsm_mobile']:"";
  736. $temp['addr'] =isset($ware['wsm_addr'])?$ware['wsm_addr']:"";
  737. $temp['addr_cn'] =GetAddr($ware['addr_code']);
  738. $temp['addr_code'] = isset($ware['addr_code'])?$ware['addr_code']:"";
  739. $list[]=$temp;
  740. }
  741. return app_show(0,"获取成功",$list);
  742. }
  743. }