After.php 50 KB

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