After.php 42 KB

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