After.php 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  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\Exception;
  7. use think\facade\Db;
  8. use think\facade\Validate;
  9. //售后
  10. class After extends Base
  11. {
  12. // public $post=[];
  13. public function __construct(App $app)
  14. {
  15. parent::__construct($app);
  16. // $this->post =$this->request->post();
  17. }
  18. public function create(){
  19. $outCode = isset($this->post['outCode']) &&$this->post['outCode']!=''?trim($this->post['outCode']) :"";
  20. if($outCode==''){
  21. return error_show(1004,"参数outCode 不能为空");
  22. }
  23. $orderout= Db::name("order_out")->where(["outCode"=>$outCode])->find();
  24. if(empty($orderout)){
  25. return error_show(1005,"未找到订单数据");
  26. }
  27. $oder= Db::name("sale")->where(["orderCode"=>$orderout['orderCode'],"is_del"=>0])->find();
  28. if(empty($oder)){
  29. return error_show(1005,"未找到订单数据");
  30. }
  31. $errorCode = isset($this->post['errorCode']) &&$this->post['errorCode']!=''?trim($this->post['errorCode']) :"";
  32. if($outCode==''){
  33. return error_show(1004,"参数errorCode 不能为空");
  34. }
  35. $error =Db::name('result_info')->where(["result_code"=>$errorCode,"is_del"=>0])->find();
  36. if(empty($error)){
  37. return error_show(1005,"未找到退货原因数据");
  38. }
  39. $remark =isset($this->post['remark']) &&$this->post['remark']!=''?trim($this->post['remark']) :"";
  40. $is_receive =isset($this->post['is_receive']) &&$this->post['is_receive']!==''?intval($this->post['is_receive'])
  41. :"";
  42. if($is_receive===""){
  43. return error_show(1004,"参数 is_receive 不能为空");
  44. }
  45. if($is_receive==0){
  46. $num=$orderout['send_num'];
  47. }else{
  48. $num =isset($this->post['num']) &&$this->post['num']!=''?intval($this->post['num']) :"";
  49. if($num==""){
  50. return error_show(1004,"参数 num 不能为空或零");
  51. }
  52. }
  53. $except_code =isset($this->post['except_code']) &&$this->post['except_code']!=''?trim($this->post['except_code']) :"";
  54. $img = isset($this->post['img']) &&$this->post['img']!=''?trim($this->post['img']) :"";
  55. $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
  56. if($token==''){
  57. return error_show(105,"参数token不能为空");
  58. }
  59. $user =GetUserInfo($token);
  60. if(empty($user)||$user['code']!=0){
  61. return error_show(102,"申请人数据不存在");
  62. }
  63. $rm= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  64. $ri= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  65. $returnCode=makeNo("RS");
  66. Db::startTrans();
  67. try{
  68. $in = [
  69. "returnCode"=>$returnCode,
  70. "outCode"=>$outCode,
  71. "orderCode"=> $oder['orderCode'],
  72. "good_code"=>$oder['good_code'],
  73. "good_name"=>$oder['good_name'],
  74. "customer_code"=>$oder['customer_code'],
  75. "apply_id"=>$rm,
  76. "apply_name"=>$ri,
  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"=>1,
  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,'SHD',0,$orde);
  95. if($create>0){
  96. $process=["order_code"=>$returnCode,"order_id"=>$create,"order_status"=>$in['status'],"order_type"=>'SHD'];
  97. ProcessOrder::AddProcess($token,$process);
  98. Db::commit();
  99. return app_show(0,"售后申请单新建成功",["returnCode"=>$returnCode]);
  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. $role=$this->checkRole();
  166. if(!empty($role['write'])){
  167. $where[]=["apply_id","in",$role['write']];
  168. }
  169. $count=Db::name("order_return")->alias("a")->leftJoin("order_returninfo b","a.returnCode=b.returnCode")->where
  170. ($where)->count();
  171. $total = ceil($count/$size);
  172. $page = $total>=$page ? $page :$total;
  173. $list =Db::name("order_return")->alias("a")->leftJoin("order_returninfo b","a.returnCode=b.returnCode")->where($where)
  174. ->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)
  175. ->order("addtime desc")->select();
  176. $data=[];
  177. foreach ($list as $value){
  178. $customer = Db::name("customer_info")->where(["companyNo"=>$value['customer_code']])->find();
  179. $value['customer_name'] = isset($customer['companyName']) ?trim($customer['companyName']):'';
  180. $data[]=$value;
  181. }
  182. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  183. }
  184. /**
  185. * @return \think\response\Json|void
  186. * @throws \think\db\exception\DataNotFoundException
  187. * @throws \think\db\exception\DbException
  188. * @throws \think\db\exception\ModelNotFoundException
  189. */
  190. public function info()
  191. {
  192. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode'] != "" ? trim($this->post['returnCode']) : "";
  193. if ($bkcode == "") {
  194. return error_show(1005, "参数returnCode 不能为空");
  195. }
  196. $info = Db::name("order_return")->alias("a")->leftJoin("order_returninfo b", "a.returnCode=b.returnCode")
  197. ->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")
  198. ->where(['a.returnCode' => $bkcode])->find();
  199. if (empty($info)) {
  200. return error_show(1005, "未找到售后数据");
  201. }
  202. $orderinfo = Db::name("sale")->where(["orderCode" => $info["orderCode"]])->find();
  203. $info['origin_price'] = $orderinfo['origin_price'];
  204. $info['order_type'] = $orderinfo['order_type'];
  205. $info['sale_price'] = $orderinfo['sale_price'];
  206. $info['total_price'] = sprintf("%1\$.2f", $orderinfo['sale_price'] * $info['error_num']);
  207. if ($orderinfo['order_type'] == 3 || $orderinfo['order_type'] == 4) {
  208. $goon = Db::name("good_zixun")->where(["spuCode" => $orderinfo['good_code'], "is_del" => 0])->find();
  209. } else {
  210. $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  211. ->where(['a.skuCode' => $orderinfo['skuCode']])->find();
  212. }
  213. if (empty($goon)) {
  214. return error_show(1003, "未找到商品数据");
  215. }
  216. $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  217. $addcode = '';
  218. if ($info['addr_code'] != "") {
  219. list($a, $b, $c) = explode(",", $info['addr_code']);
  220. $addcode = json_encode(["provice_code" => $a, "city_code" => $b, "area_code" => $c]);
  221. }
  222. $info["addr_cn"]=GetAddr($addcode);
  223. // $info["addr_code"]=json_decode($addcode,true);
  224. $out =Db::name("order_out")->where(["outCode"=>$info['outCode']])->find();
  225. $info['out_num'] = isset($out['send_num'])?$out['send_num']:'';
  226. // $customer = Db::name("customer_info")->where(["companyNo"=>$info['customer_code']])->find();
  227. $wsmcode=[];
  228. if($info['return_wsm']!=''){
  229. $wsmcode = Db::name("warehouse_info")
  230. ->alias("a")
  231. ->leftJoin("supplier b","a.supplierNo=b.code")
  232. ->where(["a.wsm_code"=>$info['return_wsm']])
  233. ->field("a.name as wsm_name,b.name,b.code,a.wsm_code,a.contactor_name,a.position,a.mobile,a.addrs_code,a.addr,a.companyNo")
  234. ->find();
  235. }
  236. $info['wsm_code'] =isset($wsmcode['wsm_code']) ? $wsmcode['wsm_code']:"";
  237. $info['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  238. $info['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  239. $info['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  240. $customer=[];
  241. if(isset($orderinfo['supplierNo'])&&$orderinfo['supplierNo']!=''){
  242. $customer = Db::name("business")->field('id,company,companyNo')->where(["companyNo"=>$orderinfo['supplierNo']])->find();
  243. }
  244. $info['customer_name'] = isset($customer['company']) ?trim($customer['company']):'';
  245. $info['customer_code'] = isset($customer['companyNo']) ?trim($customer['companyNo']):'';
  246. $info['can']=$int;
  247. //仓库的联系人、职位、电话、省市区和地址
  248. isset($wsmcode['contactor_name'])? $info['contactor'] =$wsmcode['contactor_name']:'';//联系人
  249. isset($wsmcode['mobile'])? $info['mobile'] =$wsmcode['mobile']:'';//联系人
  250. isset($wsmcode['addrs_code'])? $info['addr_code'] =$wsmcode['addrs_code']:'';//联系人
  251. isset($wsmcode['addr'])? $info['addr'] =$wsmcode['addr']:'';//联系人
  252. isset($wsmcode['contactor_name'])? $info['contactor'] =$wsmcode['contactor_name']:'';//联系人
  253. // $info['position'] = $wsmcode['position'];//职位
  254. // $info['mobile'] = $wsmcode['mobile'];//电话
  255. // $info['addrs_code'] = json_decode($wsmcode['addrs_code'], true);//省市区编码
  256. // $info['addr'] = $wsmcode['addr'];//地址
  257. $info['spuCode'] = $orderinfo['good_code'];//地址
  258. $info['skuCode'] = $orderinfo['skuCode'];//地址
  259. $info['return_tag'] = $info['return_tag']==0?"":$info['return_tag'];//地址
  260. $info['is_th'] = $info['is_th']==0?"":$info['is_th'];//地址
  261. return app_show(0,"获取成功",$info);
  262. }
  263. public function status(){
  264. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  265. if($bkcode==""){
  266. return error_show(1005,"参数returnCode 不能为空");
  267. }
  268. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  269. if(empty($info)){
  270. return error_show(1005,"未找到售后数据");
  271. }
  272. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status'])
  273. :"";
  274. if($status===""){
  275. return error_show(1005,"参数status 不能为空");
  276. }
  277. $orde= Db::name("order_out")->where(["outCode"=>$info['outCode']])->find();
  278. if($orde==false){
  279. return error_show(1005,"未找到出库单数据");
  280. }
  281. $remark = isset($this->post['remark'])&&$this->post['remark']!=''?trim($this->post['remark']):"";
  282. if($remark!=''){
  283. $info['remark'] =$remark;
  284. }
  285. if($status==3 && $info['is_receive']==1){
  286. $post =isset($this->post['is_post'])&&$this->post['is_post']!==""? intval($this->post['is_post']):"";
  287. if($post===""){
  288. return error_show(1005,"参数is_post不能为空");
  289. }
  290. $info['is_post']=$post;
  291. $return_tag =isset($this->post['return_tag'])&&$this->post['return_tag']!==""? intval($this->post['return_tag']):"";
  292. if($return_tag===""){
  293. return error_show(1005,"参数return_tag不能为空");
  294. }
  295. $info['return_tag']=$return_tag;
  296. $is_th =isset($this->post['is_th'])&&$this->post['is_th']!==""? intval($this->post['is_th']):"0";
  297. $info['is_th']=$is_th;
  298. }
  299. // $status = $info['order_status']==1&&$info['order_type']==1 && $status==1?4:$status;
  300. Db::startTrans();
  301. try{
  302. $var=$info['status'];
  303. $info['status']=$status;
  304. $info['updatetime']=date("Y-m-d H:i:s");
  305. $up =Db::name("order_return")->save($info);
  306. if($up){
  307. $order = ["order_code"=>$info['returnCode'],"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
  308. ActionLog::logAdd($this->post['token'],$order,"SHD", $info['status'],$this->post);
  309. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$status,"order_type"=>"SHD"];
  310. ProcessOrder::AddProcess($this->post['token'],$process);
  311. Db::commit();
  312. return app_show(0,"更新成功");
  313. }else{
  314. Db::rollback();
  315. return error_show(1004,"更新失败");
  316. }
  317. }catch (\Exception $e){
  318. Db::rollback();
  319. return error_show(1004,$e->getMessage());
  320. }
  321. }
  322. public function setWsm(){
  323. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  324. if($bkcode==""){
  325. return error_show(1005,"参数returnCode 不能为空");
  326. }
  327. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  328. if(empty($info)){
  329. return error_show(1005,"未找到售后数据");
  330. }
  331. if($info['status']!=3){
  332. return error_show(1005,"采购主管未审核无法设置退回仓库");
  333. }
  334. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']) :"";
  335. if($info['return_tag']==2) {
  336. if($wsm_code==""){
  337. return error_show(1005,"参数 wsm_code 不能为空");
  338. }
  339. $warehouse =Db::name("warehouse_info")->where(["wsm_code"=>$wsm_code])->find();
  340. if($warehouse==false){
  341. return error_show(1005,"仓库数据未找到");
  342. }
  343. $wareaddr =Db::name("warehouse_addr")->where(["wsm_code"=>$wsm_code,"is_del"=>0,"status"=>1])->find();
  344. }
  345. $addrcode=isset($this->post['addr_code'])&&$this->post['addr_code']!=""?$this->post['addr_code']:"";
  346. if($addrcode==""){
  347. return error_show(1005,"参数 addr_code 不能为空");
  348. }
  349. $addr=isset($this->post['addr'])&&$this->post['addr']!=""?trim($this->post['addr']):"";
  350. if($addr==""){
  351. return error_show(1005,"参数 addr 不能为空");
  352. }
  353. $mobile=isset($this->post['mobile'])&&$this->post['mobile']!=""?trim($this->post['mobile']):"";
  354. if($mobile==""){
  355. return error_show(1005,"参数 mobile 不能为空");
  356. }
  357. $contactor=isset($this->post['contactor'])&&$this->post['contactor']!=""?trim($this->post['contactor']):"";
  358. if($contactor==""){
  359. return error_show(1005,"参数 contactor 不能为空");
  360. }
  361. $returninfo=[
  362. "returnCode"=>$bkcode,
  363. "return_wsm"=>$wsm_code,
  364. "contactor"=>$contactor,
  365. "mobile"=>$mobile ,
  366. "addr"=>$addr,
  367. "addr_code"=>$addrcode,
  368. "addtime"=>date("Y-m-d H:i:s")
  369. ];
  370. Db::startTrans();
  371. try {
  372. $in=Db::name("order_returninfo")->insert($returninfo);
  373. if($in){
  374. if($info['return_tag']==2 &&$wareaddr==false) {
  375. $addrs =[
  376. "wsm_code"=>$wsm_code,
  377. "wsm_type"=>1,
  378. "wsm_name"=>$contactor,
  379. "wsm_addr"=>$addr,
  380. "addr_code"=>$addrcode,
  381. "wsm_mobile"=>$mobile,
  382. "status"=>'1',
  383. "is_del"=>'0',
  384. "addtime"=>date("Y-m-d H:i:s"),
  385. "updatetime"=>date("Y-m-d H:i:s")
  386. ];
  387. $wareaddr =Db::name("warehouse_addr")->insert($addrs);
  388. if($wareaddr==false){
  389. Db::rollback();
  390. return app_show(1004,"退货仓库地址录入失败");
  391. }
  392. }
  393. $old_info_status = $info['status'];
  394. $info['status']=4;
  395. $info["updatetime"]=date("Y-m-d H:i:s");
  396. $up =Db::name("order_return")->save($info);
  397. if($up){
  398. //修改状态,添加待办
  399. ActionLog::logAdd($this->post['token'], [
  400. "order_code" => $info['returnCode'],//销售单code
  401. "status" => $old_info_status,//这里的status是之前的值
  402. "action_remark" => '',//备注
  403. "action_type" => "status"//新建create,编辑edit,更改状态status
  404. ], "SHD", $info['status'], $info);
  405. ProcessOrder::AddProcess($this->post['token'], [
  406. "order_type" => 'SHD',
  407. "order_code" => $info['returnCode'],//销售单code
  408. "order_id" => $info['id'],
  409. "order_status" => $info['status']
  410. ]);
  411. Db::commit();
  412. return app_show(0,"退货仓库设置成功");
  413. }
  414. }
  415. Db::rollback();
  416. return error_show(1004,"设置失败");
  417. }catch (\Exception $e){
  418. Db::rollback();
  419. return error_show(1004,$e->getMessage());
  420. }
  421. }
  422. /**
  423. * @return \think\response\Json|void
  424. * @throws \think\db\exception\DataNotFoundException
  425. * @throws \think\db\exception\DbException
  426. * @throws \think\db\exception\ModelNotFoundException
  427. */
  428. public function postfeed(){
  429. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  430. if($bkcode==""){
  431. return error_show(1005,"参数returnCode 不能为空");
  432. }
  433. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  434. if(empty($info)){
  435. return error_show(1005,"未找到售后数据");
  436. }
  437. $contactor = isset($this->post['contactor']) && $this->post['contactor']!="" ? trim($this->post['contactor']) :"";
  438. $mobile = isset($this->post['mobile']) && $this->post['mobile']!="" ? trim($this->post['mobile']):"";
  439. $addr = isset($this->post['addr']) && $this->post['addr']!="" ? trim($this->post['addr']):"";
  440. $addr_code = isset($this->post['addr_code']) && $this->post['addr_code']!=""&&!empty($this->post['addr_code']) ?
  441. $this->post['addr_code']:"";
  442. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  443. if($wsm_code==""){
  444. return error_show(1005,"参数 wsm_code不能为空");
  445. }
  446. if($info['is_th']==0&&$info['order_type']==1) {
  447. $wsm = Db::name("warehouse_info")->where(["wsm_code" => $wsm_code])->find();
  448. if (empty($wsm)) {
  449. return error_show(1005, "未找到仓库数据");
  450. }
  451. $sm = Db::name("warehouse_addr")->where(["wsm_code" => $wsm_code,"is_del"=>0])->find();
  452. $contactor==""?(isset($sm['wsm_name']) ? $contactor=$sm['wsm_name']:""):"";
  453. $sm['wsm_name'] =isset($sm['wsm_name']) ? $sm['wsm_name']:"";
  454. $mobile==""?(isset($sm['wsm_mobile']) ? $mobile=$sm['wsm_mobile']:""):"";
  455. $sm['wsm_mobile'] =isset($sm['wsm_mobile']) ? $sm['wsm_mobile']:"";
  456. $addr==""?(isset($sm['wsm_addr']) ? $addr=$sm['wsm_addr']:""):"";
  457. $sm['wsm_addr'] =isset($sm['wsm_addr']) ? $sm['wsm_addr']:"";
  458. $addr_code==""?(isset($sm['addr_code']) ? $addr=$sm['addr_code']:""):"";
  459. $sm['addr_code'] =isset($sm['addr_code']) ? $sm['addr_code']:"";
  460. }
  461. $remark = isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  462. if($info['is_th']==1 && $info['order_type']==1){
  463. if($contactor==''){
  464. return error_show(1005,"参数 contactor 不能为空");
  465. }
  466. if($mobile==''){
  467. return error_show(1005,"参数 mobile 不能为空");
  468. }
  469. if($addr==''){
  470. return error_show(1005,"参数 addr 不能为空");
  471. }
  472. if($addr_code==''){
  473. return error_show(1005,"参数 addr_code 不能为空");
  474. }
  475. if($addr_code!==''&&is_array($addr_code)){
  476. $addrs=[];
  477. $addrs['provice_code'] = $addr_code[0];
  478. $addrs['city_code'] = $addr_code[1];
  479. $addrs['area_code'] = $addr_code[2];
  480. $addr_code = json_encode($addrs);
  481. }
  482. }
  483. Db::startTrans();
  484. try{
  485. $var=$info['status'];
  486. $info['status']=$info['order_type']==1?3:4;
  487. $info['remark']=$remark;
  488. $info['updatetime']=date("Y-m-d H:i:s");
  489. $up =Db::name("order_return")->save($info);
  490. if($up){
  491. // var_dump($contactor);
  492. $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
  493. if(empty($returninfo)){
  494. $returninfo=[
  495. "returnCode"=>$bkcode,
  496. "return_wsm"=>$wsm_code,
  497. "contactor"=>$contactor,
  498. "mobile"=>$mobile ,
  499. "addr"=>$addr,
  500. "addr_code"=>$addr_code,
  501. "addtime"=>date("Y-m-d H:i:s")
  502. ];
  503. }else{
  504. $returninfo['return_wsm'] = $wsm_code;
  505. //if($info['is_th']==1 && $info['order_type']==1) {
  506. $contactor !==""? $returninfo['contactor'] = $contactor:"";
  507. $mobile!==""?$returninfo['mobile'] = $mobile:"";
  508. $addr!==""? $returninfo['addr'] = $addr:"";
  509. $addr_code!==""?$returninfo['addr_code'] = $addr_code:"";
  510. // }
  511. }
  512. // var_dump($contactor);
  513. // var_dump($returninfo);
  514. $in=Db::name("order_returninfo")->save($returninfo);
  515. if($in){
  516. $order = ["order_code"=>$info['returnCode'],"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
  517. ActionLog::logAdd($this->post['token'],$order,"SHD",$info['status'],$this->post);
  518. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>"SHD"];
  519. ProcessOrder::AddProcess($this->post['token'],$process);
  520. Db::commit();
  521. return app_show(0,"更新成功");
  522. }
  523. }
  524. Db::rollback();
  525. return error_show(1004,"更新失败");
  526. }catch (\Exception $e){
  527. Db::rollback();
  528. return error_show(1004,$e->getMessage());
  529. }
  530. }
  531. /**
  532. * @return \think\response\Json|void
  533. * @throws \think\db\exception\DataNotFoundException
  534. * @throws \think\db\exception\DbException
  535. * @throws \think\db\exception\ModelNotFoundException
  536. */
  537. public function addpost(){
  538. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  539. if($bkcode==""){
  540. return error_show(1005,"参数returnCode 不能为空");
  541. }
  542. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  543. if(empty($info)){
  544. return error_show(1005,"未找到售后数据");
  545. }
  546. $return_info = Db::name("order_returninfo")->where(['returnCode'=>$bkcode])->find();
  547. if(empty($return_info)){
  548. $return_info=[
  549. "returnCode"=>$bkcode,
  550. "return_wsm"=>'',
  551. "contactor"=>'',
  552. "mobile"=>'',
  553. "addr"=>'',
  554. "addr_code"=>'',
  555. "addtime"=>date("Y-m-d H:i:s"),
  556. "post_company"=>'',
  557. "post_code"=>'',
  558. "post_fee"=>'',
  559. ];
  560. }
  561. $post_own = isset($this->post['own']) &&$this->post['own']!='' ? trim($this->post['own']):"";
  562. if($post_own==''){
  563. return error_show(1005,"参数own不能为空");
  564. }
  565. $info['post_own'] = $post_own;
  566. $post_company = isset($this->post['company'])&&$this->post['company']!='' ? trim($this->post['company']):"";
  567. if($post_company==''){
  568. return error_show(1005,"参数company不能为空");
  569. }
  570. $return_info['post_company'] = $post_company;
  571. $post_code = isset($this->post['post_code'])&&$this->post['post_code']!='' ? trim($this->post['post_code']):"";
  572. if($post_code==''){
  573. return error_show(1005,"参数post_code不能为空");
  574. }
  575. $return_info['post_code'] = $post_code;
  576. $fee= isset($this->post['post_fee'])&&$this->post['post_fee']!=='' ? round($this->post['post_fee'],2):"";
  577. if($fee===''){
  578. return error_show(1005,"参数post_fee不能为空");
  579. }
  580. $return_info['post_fee'] = $fee;
  581. Db::startTrans();
  582. try{
  583. $str=$info['status'];
  584. $info['status']=$info['order_type']==1?4:5;
  585. $info['updatetime']=date("Y-m-d H:i:s");
  586. $up =Db::name("order_return")->save($info);
  587. if($up){
  588. $order = ["order_code"=>$info['orderCode'],"status"=>$str,"action_remark"=>'',"action_type"=>"edit"];
  589. ActionLog::logAdd($this->post['token'],$order,"SHD",$info['status'],$this->post);
  590. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>"SHD"];
  591. ProcessOrder::AddProcess($this->post['token'],$process);
  592. $in=Db::name("order_returninfo")->save($return_info);
  593. if($in){
  594. $data=[
  595. 'thNo'=>makeNo("ST"),
  596. "orderCode"=>$info['orderCode'],
  597. "order_type"=>$info['order_type'],
  598. "outCode"=>$info['outCode'],
  599. "returnCode"=>$info['returnCode'],
  600. "good_code"=>$info['good_code'],
  601. "good_name"=>$info['good_name'],
  602. "return_wsm"=>$return_info['return_wsm'],
  603. "return_num"=>$info['error_num'],
  604. "contactor"=>$return_info['contactor'],
  605. "mobile"=>$return_info['mobile'],
  606. "addr"=>$return_info['addr'],
  607. "addr_code"=>$return_info['addr_code'],
  608. "return_code"=>$info['error_code'],
  609. "return_msg"=>$info['error_msg'],
  610. "post_fee"=>$return_info['post_fee'],
  611. "post_code"=>$return_info['post_code'],
  612. "post_company"=>$return_info['post_company'],
  613. "customer_code"=>$info['customer_code'],
  614. "addtime"=>date("Y-m-d H:i:s"),
  615. "updatetime"=>date("Y-m-d H:i:s")
  616. ];
  617. $back =Db::name("order_back")->insert($data,true);
  618. if($back>0){
  619. $order = ["order_code"=>$data['thNo'],"status"=>0,"action_remark"=>'',"action_type"=>"create"];
  620. ActionLog::logAdd($this->post['token'],$order,"CKTHD", 0,$data);
  621. $process=["order_code"=>$data['thNo'],"order_id"=>$back,"order_status"=>0,"order_type"=>"CKTHD"];
  622. ProcessOrder::AddProcess($this->post['token'],$process);
  623. Db::commit();
  624. return app_show(0,"更新成功");
  625. }
  626. }
  627. }
  628. Db::rollback();
  629. return error_show(1004,"更新失败");
  630. }catch (\Exception $e){
  631. Db::rollback();
  632. return error_show(1004,$e->getMessage());
  633. }
  634. }
  635. /**
  636. * @return \think\response\Json|void
  637. * @throws \think\db\exception\DataNotFoundException
  638. * @throws \think\db\exception\DbException
  639. * @throws \think\db\exception\ModelNotFoundException
  640. */
  641. public function GysFeed(){
  642. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  643. if($bkcode==""){
  644. return error_show(1005,"参数returnCode 不能为空");
  645. }
  646. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  647. if(empty($info)){
  648. return error_show(1005,"未找到售后数据");
  649. }
  650. $isth = isset($this->post['is_th']) && $this->post['is_th']!="" ? intval($this->post['is_th']):"0";
  651. $contactor = isset($this->post['contactor']) && $this->post['contactor']!="" ? trim($this->post['contactor'])
  652. :"";
  653. $mobile = isset($this->post['mobile']) && $this->post['mobile']!="" ? trim($this->post['mobile']):"";
  654. $addr = isset($this->post['addr']) && $this->post['addr']!="" ? trim($this->post['addr']):"";
  655. $addr_code = isset($this->post['addr_code']) && $this->post['addr_code']!=""&&!empty($this->post['addr_code']) ? $this->post['addr_code']:"";
  656. $remark = isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  657. if($isth==1){
  658. if($contactor==''){
  659. return error_show(1005,"参数 contactor 不能为空");
  660. }
  661. if($mobile==''){
  662. return error_show(1005,"参数 mobile 不能为空");
  663. }
  664. if($addr==''){
  665. return error_show(1005,"参数 addr 不能为空");
  666. }
  667. // var_dump(isset($this->post['addr_code']) , $this->post['addr_code']!="",!empty($addr_code));
  668. if($addr_code==''){
  669. return error_show(1005,"参数 addr_code 不能为空");
  670. }
  671. if(is_array($addr_code)){
  672. $addrs=[];
  673. $addrs['provice_code'] = $addr_code[0];
  674. $addrs['city_code'] = $addr_code[1];
  675. $addrs['area_code'] = $addr_code[2];
  676. $addr_code = json_encode($addrs);
  677. }
  678. }
  679. $orde= Db::name("order_out")->where(["outCode"=>$info['outCode'],"is_del"=>0])->find();
  680. if(empty($orde)){
  681. return error_show(1005,"未找到出库单数据");
  682. }
  683. Db::startTrans();
  684. try{
  685. $stat=$info['status'];
  686. $info['status']=$info['order_status']==1?5:3;
  687. $info['is_th']=$isth;
  688. $info['updatetime']=date("Y-m-d H:i:s");
  689. $up =Db::name("order_return")->save($info);
  690. if($up){
  691. $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
  692. if(empty($returninfo)){
  693. $returninfo=[
  694. "returnCode"=>$bkcode,
  695. "return_wsm"=>'',
  696. "contactor"=>$contactor,
  697. "mobile"=>$mobile ,
  698. "addr"=>$addr,
  699. "addr_code"=>$addr_code,
  700. "gys_remark"=>$remark,
  701. "addtime"=>date("Y-m-d H:i:s")
  702. ];
  703. }else{
  704. $returninfo['return_wsm'] = '';
  705. $returninfo['contactor'] = $contactor;
  706. $returninfo['mobile'] = $mobile;
  707. $returninfo['addr'] = $addr;
  708. $returninfo['gys_remark'] = $remark;
  709. $returninfo['addr_code'] = $addr_code;
  710. }
  711. $in=Db::name("order_returninfo")->save($returninfo);
  712. if($in){
  713. $order = ["order_code"=>$info['returnCode'],"status"=>$stat,"action_remark"=>'',"action_type"=>"edit"];
  714. ActionLog::logAdd($this->post['token'],$order,"SHD", $info['status'],$this->post);
  715. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"SHD"];
  716. ProcessOrder::AddProcess($this->post['token'],$process);
  717. Db::commit();
  718. return app_show(0,"更新成功");
  719. }
  720. }
  721. Db::rollback();
  722. return error_show(1004,"更新失败");
  723. }catch (\Exception $e){
  724. Db::rollback();
  725. return error_show(1004,$e->getMessage());
  726. }
  727. }
  728. public function GetWsm(){
  729. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  730. if($bkcode==""){
  731. return error_show(1005,"参数returnCode 不能为空");
  732. }
  733. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  734. if($info==false){
  735. return error_show(1005,"未找到售后数据");
  736. }
  737. $list=[];
  738. if($info['is_th']==1){
  739. if($info["order_type"]==1){
  740. $out =Db::name("order_out")->where(["outCode"=>$info['outCode']])->find();
  741. if(empty($out)){
  742. return error_show(1005,"未找到出库单数据");
  743. }
  744. $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")
  745. ->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();
  746. if(empty($ware)){
  747. return error_show(1005,"未找到仓库数据");
  748. }
  749. $temp['wsm_code']=isset($ware['wsm_code'])?$ware['wsm_code']:"";
  750. $temp['wsm_name']=isset($ware['name'])?$ware['name']:"";
  751. $temp['contactor'] = isset($ware['wsm_name'])?$ware['wsm_name']:"";
  752. $temp['mobile'] =isset($ware['wsm_mobile'])?$ware['wsm_mobile']:"";
  753. $temp['addr'] =isset($ware['wsm_addr'])?$ware['wsm_addr']:"";
  754. $temp['addr_code'] = isset($ware['addr_code'])?$ware['addr_code']:"";
  755. $temp['addr_cn'] =GetAddr( $ware['addr_code']);
  756. $list[]=$temp;
  757. }else {
  758. $returninfo = Db::name("order_returninfo")->where(["returnCode" => $bkcode])->find();
  759. if (empty($returninfo)) {
  760. return error_show(1005, "未找到供应商仓库数据");
  761. }
  762. $data = [];
  763. $data['wsm_code'] = isset($returninfo['return_wsm']) && $returninfo['return_wsm'] != "" ? $returninfo['return_wsm'] : "-";
  764. $data['wsm_name'] = '供应商仓';
  765. $data['supplier_name'] = '供应商';
  766. $data['contactor'] = $returninfo['contactor'];
  767. $data['mobile'] = $returninfo['mobile'];
  768. $data['addr'] = $returninfo['addr'];
  769. $data['addr_cn'] =GetAddr( $returninfo['addr_code']);
  770. $data['addr_code'] = $returninfo['addr_code'];
  771. $list[] = $data;
  772. }
  773. }
  774. $supplier = Db::name("supplier")->where(["is_platform"=>1,"status"=>1,"is_del"=>0])->column("code,name");
  775. if(empty($supplier)){
  776. return error_show(1005,"未找到供应商仓库数据");
  777. }
  778. foreach ($supplier as $value){
  779. $temp=[];
  780. $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")
  781. ->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();
  782. if(empty($ware)){
  783. continue;
  784. }
  785. $temp['wsm_code']=isset($ware['wsm_code'])?$ware['wsm_code']:"";
  786. $temp['wsm_name']=isset($ware['name'])?$ware['name']:"";
  787. $temp['supplier_name']=$value['name'];
  788. $temp['contactor'] = isset($ware['wsm_name'])?$ware['wsm_name']:"";
  789. $temp['mobile'] =isset($ware['wsm_mobile'])?$ware['wsm_mobile']:"";
  790. $temp['addr'] =isset($ware['wsm_addr'])?$ware['wsm_addr']:"";
  791. $temp['addr_cn'] =GetAddr($ware['addr_code']);
  792. $temp['addr_code'] = isset($ware['addr_code'])?$ware['addr_code']:"";
  793. $list[]=$temp;
  794. }
  795. return app_show(0,"获取成功",$list);
  796. }
  797. public function setdelivery(){
  798. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  799. if($bkcode==""){
  800. return error_show(1005,"参数returnCode 不能为空");
  801. }
  802. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  803. if(empty($info)){
  804. return error_show(1005,"未找到售后数据");
  805. }
  806. if(($info['is_receive']==0&&$info['status']!=3)||($info['is_receive']==1&&$info['status']!=4) ){
  807. return error_show(1005,"售后单流程状态有误");
  808. }
  809. $out=Db::name("order_out")->where(["outCode"=>$info["outCode"]])->find();
  810. if($out==false){
  811. return error_show(1005,"未找到发货单数据");
  812. }
  813. $is_th = isset($this->post['is_th'])&&$this->post['is_th']!=="" ? intval($this->post['is_th']):"";
  814. if($is_th===""){
  815. return error_show(1005,"参数is_th不能为空");
  816. }
  817. $company=isset($this->post['company'])&&$this->post['company']!=""?trim($this->post['company']):"";
  818. $post_code=isset($this->post['post_code'])&&$this->post['post_code']!=""?trim($this->post['post_code']):"";
  819. $post_fee=isset($this->post['post_fee'])&&$this->post['post_fee']!==""?floatval($this->post['post_fee']):"";
  820. if($is_th==1){
  821. if($company==""){
  822. return error_show(1005,"参数company不能为空");
  823. }
  824. if($post_code==""){
  825. return error_show(1005,"参数post_code不能为空");
  826. }
  827. if($post_fee===""){
  828. return error_show(1005,"参数post_fee不能为空");
  829. }
  830. }
  831. Db::startTrans();
  832. try {
  833. $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
  834. if($returninfo==false){
  835. $returninfo=[
  836. "returnCode"=>$bkcode,
  837. "return_wsm"=>"",
  838. "contactor"=>"",
  839. "mobile"=>"",
  840. "addr"=>"",
  841. "addr_code"=>"",
  842. "post_code"=>$post_code,
  843. "post_company"=>$company,
  844. "post_fee"=>$post_fee,
  845. "gys_remark"=>"",
  846. "addtime"=>date("Y-m-d H:i:s")
  847. ];
  848. }else{
  849. $returninfo['post_fee']=$post_fee;
  850. $returninfo['post_company']=$company;
  851. $returninfo['post_code']=$post_code;
  852. }
  853. $up =Db::name("order_returninfo")->save($returninfo);
  854. if($up){
  855. $old_info_status = $info['status'];
  856. $info['status']=5;
  857. $info['updatetime']=date("y-m-d H:i:s");
  858. $ro =Db::name("order_return")->save($info);
  859. if($ro){
  860. //修改状态,添加待办
  861. ActionLog::logAdd($this->post['token'], [
  862. "order_code" => $info['returnCode'],//销售单code
  863. "status" => $old_info_status,//这里的status是之前的值
  864. "action_remark" => '',//备注
  865. "action_type" => "status"//新建create,编辑edit,更改状态status
  866. ], "SHD", $info['status'], $this->post);
  867. ProcessOrder::AddProcess($this->post['token'], [
  868. "order_type" => 'SHD',
  869. "order_code" => $info['returnCode'],//销售单code
  870. "order_id" => $info['id'],
  871. "order_status" => $info['status']
  872. ]);
  873. $thNo =makeNo("ST");
  874. $thdata=[
  875. "thNo"=>$thNo,
  876. "orderCode"=>$out["orderCode"],
  877. "outCode"=>$out["outCode"],
  878. "order_type"=>$info["order_type"],
  879. "returnCode"=>$info["returnCode"],
  880. "good_code"=>$info["good_code"],
  881. "good_name"=>$info["good_name"],
  882. "return_wsm"=>$returninfo["return_wsm"],
  883. // "defective_wsm"=>'',
  884. "return_msg"=>$info["error_msg"],
  885. "return_num"=>$info["error_num"],
  886. "normal_num"=>0,
  887. "received_num"=>0,
  888. "apply_id"=>$info['apply_id'],
  889. "apply_name"=>$info['apply_name'],
  890. "contactor"=>$returninfo["contactor"],
  891. "mobile"=>$returninfo["mobile"],
  892. "addr"=>$returninfo["addr"],
  893. "addr_code"=>$returninfo["addr_code"],
  894. "return_code"=>$info["error_code"],
  895. "post_fee"=>$returninfo["post_fee"],
  896. "post_code"=>$returninfo["post_code"],
  897. "post_company"=>$returninfo["post_company"],
  898. "customer_code"=>$info["customer_code"],
  899. "status"=>1,
  900. "addtime"=>date("Y-m-d H:i:s"),
  901. "updatetime"=>date("Y-m-d H:i:s")
  902. ];
  903. $sav= Db::name("order_back")->insert($thdata,true);
  904. if($sav){
  905. //修改状态,添加待办
  906. ActionLog::logAdd($this->post['token'], [
  907. "order_code" => $thdata['thNo'],//销售单code
  908. "status" => $thdata['status'],//这里的status是之前的值
  909. "action_remark" => '',//备注
  910. "action_type" => "create"//新建create,编辑edit,更改状态status
  911. ], "CKTHD", $thdata['status'], $thdata);
  912. ProcessOrder::AddProcess($this->post['token'], [
  913. "order_type" => 'CKTHD',
  914. "order_code" => $thdata['thNo'],//销售单code
  915. "order_id" => $sav,
  916. "order_status" => $thdata['status']
  917. ]);
  918. // $out['status']=$info['is_receive']==1&&$info['total_num']>$info['error_num'] ?3:4;
  919. // $out['updatetime']=date("Y-m-d H:i:s");
  920. // $outup=Db::name("order_out")->save($out);
  921. // if($outup==false){
  922. // Db::rollback();
  923. // return error_show(1005,"发货单更新失败");
  924. // }
  925. Db::commit();
  926. return app_show(0,"退货单新建成功",["thNo"=>$thNo]);
  927. }
  928. }
  929. }
  930. Db::rollback();
  931. return error_show(1004,'退货失败');
  932. }catch (\Exception $e){
  933. Db::rollback();
  934. return error_show(1004,$e->getMessage());
  935. }
  936. }
  937. //取消售后
  938. public function Cancel()
  939. {
  940. //接收参数
  941. $data = $this->request->only(['token', 'returnCode'], 'post', 'trim');
  942. $val = Validate::rule(['returnCode|售后单编号' => 'require']);
  943. if (!$val->check($data)) return error_show(1005, $val->getError());
  944. Db::startTrans();
  945. try {
  946. $rs = Db::name('order_return')->field('id,status')->where([['returnCode', '=', $data['returnCode']], ['is_del', '=', 0], ['status', '<>', 8]])->find();
  947. if (!$rs) throw new Exception('该售后单记录不存在');
  948. //修改记录
  949. $res = Db::name('order_return')->where(['id' => $rs['id']])->update(['status' => 8, 'updatetime' => date('Y-m-d H:i:s')]);
  950. if (!$res) throw new Exception('该售后单记录修改失败');
  951. //记录日志
  952. ActionLog::logAdd($data['token'], ["order_code" => $data['returnCode'], "status" => $rs['status'], "action_remark" => '', "action_type" => "cancel"], 'SHD', 8, $this->post);
  953. ProcessOrder::AddProcess($this->post['token'], ["order_code" => $data['returnCode'], "order_id" => $rs['id'], "order_status" => 8, "order_type" => 'SHD']);
  954. //提交
  955. Db::commit();
  956. return app_show(0, "取消成功");
  957. } catch (\Exception $e) {
  958. Db::rollback();
  959. return error_show(1004, $e->getMessage());
  960. }
  961. }
  962. }