After.php 31 KB

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