After.php 51 KB

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