After.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  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. $order= Db::name("order_out")->where(["outCode"=>$outCode])->find();
  21. if(empty($order)){
  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'=>$order['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,'zxd',0,$orde);
  86. if($create>0){
  87. $process=["order_code"=>$returnCode,"order_id"=>$create,"order_status"=>0,"order_type"=>'SHD'];
  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,"zxd", $info['status'],$this->post);
  238. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$status,"order_type"=>'SHD'];
  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. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  261. if($wsm_code==""){
  262. return error_show(1005,"参数 wsm_code不能为空");
  263. }
  264. if($info['is_th']==0&&$info['order_type']==1) {
  265. $wsm = Db::name("warehouse_info")->where(["wsm_code" => $wsm_code])->find();
  266. if (empty($wsm)) {
  267. return error_show(1005, "未找到仓库数据");
  268. }
  269. }
  270. $contactor = isset($this->post['contactor']) && $this->post['contactor']!="" ? trim($this->post['contactor'])
  271. :"";
  272. $mobile = isset($this->post['mobile']) && $this->post['mobile']!="" ? trim($this->post['mobile']):"";
  273. $addr = isset($this->post['addr']) && $this->post['addr']!="" ? trim($this->post['addr']):"";
  274. $addr_code = isset($this->post['addr_code']) && $this->post['addr_code']!=""&&!empty($this->post['addr_code']) ?
  275. $this->post['addr_code']:"";
  276. $remark = isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  277. if($info['is_th']==1 && $info['order_type']==1){
  278. if($contactor==''){
  279. return error_show(1005,"参数 contactor 不能为空");
  280. }
  281. if($mobile==''){
  282. return error_show(1005,"参数 mobile 不能为空");
  283. }
  284. if($addr==''){
  285. return error_show(1005,"参数 addr 不能为空");
  286. }
  287. if($addr_code==''){
  288. return error_show(1005,"参数 addr_code 不能为空");
  289. }
  290. if($addr_code!==''&&is_array($addr_code)){
  291. $addrs=[];
  292. $addrs['provice_code'] = $addr_code[0];
  293. $addrs['city_code'] = $addr_code[1];
  294. $addrs['area_code'] = $addr_code[2];
  295. $addr_code = json_encode($addrs);
  296. }
  297. }
  298. Db::startTrans();
  299. try{
  300. $var=$info['status'];
  301. $info['status']=$info['order_type']==1?3:4;
  302. $info['remark']=$remark;
  303. $info['updatetime']=date("Y-m-d H:i:s");
  304. $up =Db::name("order_return")->save($info);
  305. if($up){
  306. $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
  307. if(empty($returninfo)){
  308. $returninfo=[
  309. "returnCode"=>$bkcode,
  310. "return_wsm"=>$wsm_code,
  311. "contactor"=>$contactor,
  312. "mobile"=>$mobile ,
  313. "addr"=>$addr,
  314. "addr_code"=>$addr_code,
  315. "addtime"=>date("Y-m-d H:i:s")
  316. ];
  317. }else{
  318. $returninfo['return_wsm'] = $wsm_code;
  319. if($info['is_th']==1 && $info['order_type']==1) {
  320. $returninfo['contactor'] = $contactor;
  321. $returninfo['mobile'] = $mobile;
  322. $returninfo['addr'] = $addr;
  323. $returninfo['addr_code'] = $addr_code;
  324. }
  325. }
  326. $in=Db::name("order_returninfo")->save($returninfo);
  327. if($in){
  328. $order = ["order_code"=>$info['returnCode'],"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
  329. ActionLog::logAdd($this->post['token'],$order,"AFTER",$info['status'],$order);
  330. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'SHD'];
  331. ProcessOrder::AddProcess($this->post['token'],$process);
  332. Db::commit();
  333. return app_show(0,"更新成功");
  334. }
  335. }
  336. Db::rollback();
  337. return error_show(1004,"更新失败");
  338. }catch (\Exception $e){
  339. Db::rollback();
  340. return error_show(1004,$e->getMessage());
  341. }
  342. }
  343. /**
  344. * @return \think\response\Json|void
  345. * @throws \think\db\exception\DataNotFoundException
  346. * @throws \think\db\exception\DbException
  347. * @throws \think\db\exception\ModelNotFoundException
  348. */
  349. public function addpost(){
  350. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  351. if($bkcode==""){
  352. return error_show(1005,"参数returnCode 不能为空");
  353. }
  354. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  355. if(empty($info)){
  356. return error_show(1005,"未找到售后数据");
  357. }
  358. $return_info = Db::name("order_returninfo")->where(['returnCode'=>$bkcode])->find();
  359. if(empty($return_info)){
  360. $return_info=[
  361. "returnCode"=>$bkcode,
  362. "return_wsm"=>'',
  363. "contactor"=>'',
  364. "mobile"=>'',
  365. "addr"=>'',
  366. "addr_code"=>'',
  367. "addtime"=>date("Y-m-d H:i:s"),
  368. "post_company"=>'',
  369. "post_code"=>'',
  370. "post_fee"=>'',
  371. ];
  372. }
  373. $post_own = isset($this->post['own']) &&$this->post['own']!='' ? trim($this->post['own']):"";
  374. if($post_own==''){
  375. return error_show(1005,"参数own不能为空");
  376. }
  377. $info['post_own'] = $post_own;
  378. $post_company = isset($this->post['company'])&&$this->post['company']!='' ? trim($this->post['company']):"";
  379. if($post_company==''){
  380. return error_show(1005,"参数company不能为空");
  381. }
  382. $return_info['post_company'] = $post_company;
  383. $post_code = isset($this->post['post_code'])&&$this->post['post_code']!='' ? trim($this->post['post_code']):"";
  384. if($post_code==''){
  385. return error_show(1005,"参数post_code不能为空");
  386. }
  387. $return_info['post_code'] = $post_code;
  388. $fee= isset($this->post['post_fee'])&&$this->post['post_fee']!=='' ? round($this->post['post_fee'],2):"";
  389. if($fee===''){
  390. return error_show(1005,"参数post_fee不能为空");
  391. }
  392. $return_info['post_fee'] = $fee;
  393. Db::startTrans();
  394. try{
  395. $str=$info['status'];
  396. $info['status']=$info['order_type']==1?4:5;
  397. $info['updatetime']=date("Y-m-d H:i:s");
  398. $up =Db::name("order_return")->save($info);
  399. if($up){
  400. $order = ["order_code"=>$info['orderCode'],"status"=>$str,"action_remark"=>'',"action_type"=>"edit"];
  401. ActionLog::logAdd($this->post['token'],$order,"zxd",$info['status'],$order);
  402. $in=Db::name("order_returninfo")->save($return_info);
  403. if($in){
  404. $data=[
  405. 'thNo'=>makeNo("TH"),
  406. "orderCode"=>$info['orderCode'],
  407. "order_type"=>$info['order_type'],
  408. "outCode"=>$info['outCode'],
  409. "returnCode"=>$info['returnCode'],
  410. "good_code"=>$info['good_code'],
  411. "good_name"=>$info['good_name'],
  412. "return_wsm"=>$return_info['return_wsm'],
  413. "return_num"=>$info['error_num'],
  414. "contactor"=>$return_info['contactor'],
  415. "mobile"=>$return_info['mobile'],
  416. "addr"=>$return_info['addr'],
  417. "addr_code"=>$return_info['addr_code'],
  418. "return_code"=>$info['error_code'],
  419. "return_msg"=>$info['error_msg'],
  420. "post_fee"=>$return_info['post_fee'],
  421. "post_code"=>$return_info['post_code'],
  422. "post_company"=>$return_info['post_company'],
  423. "customer_code"=>$info['customer_code'],
  424. "addtime"=>date("Y-m-d H:i:s"),
  425. "updatetime"=>date("Y-m-d H:i:s")
  426. ];
  427. $back =Db::name("order_back")->insert($data,true);
  428. if($back>0){
  429. $order = ["order_code"=>$info['orderCode'],"status"=>$str,"action_remark"=>'',"action_type"=>"edit"];
  430. ActionLog::logAdd($this->post['token'],$order,"zxd", $info['status'],$order);
  431. $process=["order_code"=>$info['returnCode'],"order_id"=>$back,"order_status"=>$info['status'],"order_type"=>'SHD'];
  432. ProcessOrder::AddProcess($this->post['token'],$process);
  433. Db::commit();
  434. return app_show(0,"更新成功");
  435. }
  436. }
  437. }
  438. Db::rollback();
  439. return error_show(1004,"更新失败");
  440. }catch (\Exception $e){
  441. Db::rollback();
  442. return error_show(1004,$e->getMessage());
  443. }
  444. }
  445. /**
  446. * @return \think\response\Json|void
  447. * @throws \think\db\exception\DataNotFoundException
  448. * @throws \think\db\exception\DbException
  449. * @throws \think\db\exception\ModelNotFoundException
  450. */
  451. public function GysFeed(){
  452. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  453. if($bkcode==""){
  454. return error_show(1005,"参数returnCode 不能为空");
  455. }
  456. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  457. if(empty($info)){
  458. return error_show(1005,"未找到售后数据");
  459. }
  460. $isth = isset($this->post['is_th']) && $this->post['is_th']!="" ? intval($this->post['is_th']):"0";
  461. $contactor = isset($this->post['contactor']) && $this->post['contactor']!="" ? trim($this->post['contactor'])
  462. :"";
  463. $mobile = isset($this->post['mobile']) && $this->post['mobile']!="" ? trim($this->post['mobile']):"";
  464. $addr = isset($this->post['addr']) && $this->post['addr']!="" ? trim($this->post['addr']):"";
  465. $addr_code = isset($this->post['addr_code']) && $this->post['addr_code']!=""&&!empty($this->post['addr_code']) ? $this->post['addr_code']:"";
  466. $remark = isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  467. if($isth==1){
  468. if($contactor==''){
  469. return error_show(1005,"参数 contactor 不能为空");
  470. }
  471. if($mobile==''){
  472. return error_show(1005,"参数 mobile 不能为空");
  473. }
  474. if($addr==''){
  475. return error_show(1005,"参数 addr 不能为空");
  476. }
  477. // var_dump(isset($this->post['addr_code']) , $this->post['addr_code']!="",!empty($addr_code));
  478. if($addr_code==''){
  479. return error_show(1005,"参数 addr_code 不能为空");
  480. }
  481. if(is_array($addr_code)){
  482. $addrs=[];
  483. $addrs['provice_code'] = $addr_code[0];
  484. $addrs['city_code'] = $addr_code[1];
  485. $addrs['area_code'] = $addr_code[2];
  486. $addr_code = json_encode($addrs);
  487. }
  488. }
  489. Db::startTrans();
  490. try{
  491. $stat=$info['status'];
  492. $info['status']=3;
  493. $info['is_th']=$isth;
  494. $info['updatetime']=date("Y-m-d H:i:s");
  495. $up =Db::name("order_return")->save($info);
  496. if($up){
  497. $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
  498. if(empty($returninfo)){
  499. $returninfo=[
  500. "returnCode"=>$bkcode,
  501. "return_wsm"=>'',
  502. "contactor"=>$contactor,
  503. "mobile"=>$mobile ,
  504. "addr"=>$addr,
  505. "addr_code"=>$addr_code,
  506. "gys_remark"=>$remark,
  507. "addtime"=>date("Y-m-d H:i:s")
  508. ];
  509. }else{
  510. $returninfo['return_wsm'] = '';
  511. $returninfo['contactor'] = $contactor;
  512. $returninfo['mobile'] = $mobile;
  513. $returninfo['addr'] = $addr;
  514. $returninfo['gys_remark'] = $remark;
  515. $returninfo['addr_code'] = $addr_code;
  516. }
  517. $in=Db::name("order_returninfo")->save($returninfo);
  518. if($in){
  519. $order = ["order_code"=>$info['orderCode'],"status"=>$stat,"action_remark"=>'',"action_type"=>"edit"];
  520. ActionLog::logAdd($this->post['token'],$order,"zxd",3,$order);
  521. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'SHD'];
  522. ProcessOrder::AddProcess($this->post['token'],$process);
  523. Db::commit();
  524. return app_show(0,"更新成功");
  525. }
  526. }
  527. Db::rollback();
  528. return error_show(1004,"更新失败");
  529. }catch (\Exception $e){
  530. Db::rollback();
  531. return error_show(1004,$e->getMessage());
  532. }
  533. }
  534. public function GetWsm(){
  535. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  536. if($bkcode==""){
  537. return error_show(1005,"参数returnCode 不能为空");
  538. }
  539. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  540. if(empty($info)){
  541. return error_show(1005,"未找到售后数据");
  542. }
  543. $list=[];
  544. if($info['is_th']==1){
  545. if($info["order_type"]==1){
  546. $out =Db::name("order_out")->where(["outCode"=>$info['outCode']])->find();
  547. if(empty($out)){
  548. return error_show(1005,"未找到出库单数据");
  549. }
  550. $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")
  551. ->where(["a.status"=>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();
  552. if(empty($ware)){
  553. return error_show(1005,"未找到仓库数据");
  554. }
  555. $temp['wsm_code']=isset($ware['wsm_code'])?$ware['wsm_code']:"";
  556. $temp['wsm_name']=isset($ware['name'])?$ware['name']:"";
  557. $temp['contactor'] = isset($ware['wsm_name'])?$ware['wsm_name']:"";
  558. $temp['mobile'] =isset($ware['wsm_mobile'])?$ware['wsm_mobile']:"";
  559. $temp['addr'] =isset($ware['wsm_addr'])?$ware['wsm_addr']:"";
  560. $temp['addr_cn'] =GetAddr( $ware['addr_code']);
  561. $temp['addr_code'] = isset($ware['addr_code'])?$ware['addr_code']:"";
  562. $list[]=$temp;
  563. }else {
  564. $returninfo = Db::name("order_returninfo")->where(["returnCode" => $bkcode])->find();
  565. if (empty($returninfo)) {
  566. return error_show(1005, "未找到供应商仓库数据");
  567. }
  568. $data = [];
  569. $data['wsm_code'] = isset($returninfo['return_wsm']) && $returninfo['return_wsm'] != "" ? $returninfo['return_wsm'] : "-";
  570. $data['wsm_name'] = '供应商仓';
  571. $data['supplier_name'] = '供应商';
  572. $data['contactor'] = $returninfo['contactor'];
  573. $data['mobile'] = $returninfo['mobile'];
  574. $data['addr'] = $returninfo['addr'];
  575. $data['addr_cn'] =GetAddr( $returninfo['addr_code']);
  576. $data['addr_code'] = $returninfo['addr_code'];
  577. $list[] = $data;
  578. }
  579. }
  580. $supplier = Db::name("supplier")->where(["is_platform"=>1,"status"=>1,"is_del"=>0])->column("code,name");
  581. if(empty($supplier)){
  582. return error_show(1005,"未找到供应商仓库数据");
  583. }
  584. foreach ($supplier as $value){
  585. $temp=[];
  586. $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")
  587. ->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();
  588. if(empty($ware)){
  589. continue;
  590. }
  591. $temp['wsm_code']=isset($ware['wsm_code'])?$ware['wsm_code']:"";
  592. $temp['wsm_name']=isset($ware['name'])?$ware['name']:"";
  593. $temp['supplier_name']=$value['name'];
  594. $temp['contactor'] = isset($ware['wsm_name'])?$ware['wsm_name']:"";
  595. $temp['mobile'] =isset($ware['wsm_mobile'])?$ware['wsm_mobile']:"";
  596. $temp['addr'] =isset($ware['wsm_addr'])?$ware['wsm_addr']:"";
  597. $temp['addr_cn'] =GetAddr($ware['addr_code']);
  598. $temp['addr_code'] = isset($ware['addr_code'])?$ware['addr_code']:"";
  599. $list[]=$temp;
  600. }
  601. return app_show(0,"获取成功",$list);
  602. }
  603. }