After.php 31 KB

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