After.php 52 KB

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