After.php 49 KB

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