After.php 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875
  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"=>0,
  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'],"is_del"=>0])->find();
  249. if(empty($orde)){
  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. // if($info['order_status']==1&&$info['order_type']==1 && $status==4){
  272. // $orderout= Db::name("order_out")->where($orde)->save(['status'=>3,"updatetime"=>date("Y-m-d H:i:s")]);
  273. // $order = ["order_code"=>$orde['outCode'],"status"=>$orde['status'],"action_remark"=>'',"action_type"=>"edit"];
  274. // ActionLog::logAdd($this->post['token'],$order,$orde['order_type']==1?'CKD':"ZXCKD", 3,['status'=>3,"updatetime"=>date("Y-m-d H:i:s")]);
  275. // $process=["order_code"=>$orde['outCode'],"order_id"=>$orde['id'],"order_status"=>3,"order_type"=>$orde['order_type']==1?'CKD':"ZXCKD"];
  276. // ProcessOrder::AddProcess($this->post['token'],$process);
  277. // if($orderout){
  278. // Db::commit();
  279. // return app_show(0,"更新成功");
  280. // }else{
  281. // Db::rollback();
  282. // return error_show(1004,"更新失败");
  283. // }
  284. // }
  285. $order = ["order_code"=>$info['returnCode'],"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
  286. ActionLog::logAdd($this->post['token'],$order,$info['order_type']==1?'SHD':"ZXSHD", $info['status'],$this->post);
  287. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$status,"order_type"=>$info['order_type']==1?'SHD':"ZXSHD"];
  288. ProcessOrder::AddProcess($this->post['token'],$process);
  289. Db::commit();
  290. return app_show(0,"更新成功");
  291. }else{
  292. Db::rollback();
  293. return error_show(1004,"更新失败");
  294. }
  295. }catch (\Exception $e){
  296. Db::rollback();
  297. return error_show(1004,$e->getMessage());
  298. }
  299. }
  300. public function setWsm(){
  301. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  302. if($bkcode==""){
  303. return error_show(1005,"参数returnCode 不能为空");
  304. }
  305. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  306. if(empty($info)){
  307. return error_show(1005,"未找到售后数据");
  308. }
  309. if($info['status']!=3){
  310. return error_show(1005,"采购主管未审核无法设置退回仓库");
  311. }
  312. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code'])
  313. :"";
  314. if($wsm_code==""){
  315. return error_show(1005,"参数wsm_code 不能为空");
  316. }
  317. $addrcode=isset($this->post['addr_code'])&&$this->post['addr_code']!=""?$this->post['addr_code']:"";
  318. if($addrcode==""){
  319. return error_show(1005,"参数 addr_code 不能为空");
  320. }
  321. $addr=isset($this->post['addr'])&&$this->post['addr']!=""?trim($this->post['addr']):"";
  322. if($addr==""){
  323. return error_show(1005,"参数 addr 不能为空");
  324. }
  325. $mobile=isset($this->post['mobile'])&&$this->post['mobile']!=""?trim($this->post['mobile']):"";
  326. if($mobile==""){
  327. return error_show(1005,"参数 mobile 不能为空");
  328. }
  329. $contactor=isset($this->post['contactor'])&&$this->post['contactor']!=""?trim($this->post['contactor']):"";
  330. if($contactor==""){
  331. return error_show(1005,"参数 contactor 不能为空");
  332. }
  333. $returninfo=[
  334. "returnCode"=>$bkcode,
  335. "return_wsm"=>$wsm_code,
  336. "contactor"=>$contactor,
  337. "mobile"=>$mobile ,
  338. "addr"=>$addr,
  339. "addr_code"=>$addrcode,
  340. "addtime"=>date("Y-m-d H:i:s")
  341. ];
  342. Db::startTrans();
  343. try {
  344. $in=Db::name("order_returninfo")->insert($returninfo);
  345. if($in){
  346. $info['status']=4;
  347. $info["updatetime"]=date("Y-m-d H:i:s");
  348. $up =Db::name("order_return")->save($info);
  349. if($up){
  350. Db::commit();
  351. return app_show(0,"退货仓库设置成功");
  352. }
  353. }
  354. Db::rollback();
  355. return error_show(1004,"设置失败");
  356. }catch (\Exception $e){
  357. Db::rollback();
  358. return error_show(1004,$e->getMessage());
  359. }
  360. }
  361. /**
  362. * @return \think\response\Json|void
  363. * @throws \think\db\exception\DataNotFoundException
  364. * @throws \think\db\exception\DbException
  365. * @throws \think\db\exception\ModelNotFoundException
  366. */
  367. public function postfeed(){
  368. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  369. if($bkcode==""){
  370. return error_show(1005,"参数returnCode 不能为空");
  371. }
  372. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  373. if(empty($info)){
  374. return error_show(1005,"未找到售后数据");
  375. }
  376. $contactor = isset($this->post['contactor']) && $this->post['contactor']!="" ? trim($this->post['contactor']) :"";
  377. $mobile = isset($this->post['mobile']) && $this->post['mobile']!="" ? trim($this->post['mobile']):"";
  378. $addr = isset($this->post['addr']) && $this->post['addr']!="" ? trim($this->post['addr']):"";
  379. $addr_code = isset($this->post['addr_code']) && $this->post['addr_code']!=""&&!empty($this->post['addr_code']) ?
  380. $this->post['addr_code']:"";
  381. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  382. if($wsm_code==""){
  383. return error_show(1005,"参数 wsm_code不能为空");
  384. }
  385. if($info['is_th']==0&&$info['order_type']==1) {
  386. $wsm = Db::name("warehouse_info")->where(["wsm_code" => $wsm_code])->find();
  387. if (empty($wsm)) {
  388. return error_show(1005, "未找到仓库数据");
  389. }
  390. $sm = Db::name("warehouse_addr")->where(["wsm_code" => $wsm_code,"is_del"=>0])->find();
  391. $contactor==""?(isset($sm['wsm_name']) ? $contactor=$sm['wsm_name']:""):"";
  392. $sm['wsm_name'] =isset($sm['wsm_name']) ? $sm['wsm_name']:"";
  393. $mobile==""?(isset($sm['wsm_mobile']) ? $mobile=$sm['wsm_mobile']:""):"";
  394. $sm['wsm_mobile'] =isset($sm['wsm_mobile']) ? $sm['wsm_mobile']:"";
  395. $addr==""?(isset($sm['wsm_addr']) ? $addr=$sm['wsm_addr']:""):"";
  396. $sm['wsm_addr'] =isset($sm['wsm_addr']) ? $sm['wsm_addr']:"";
  397. $addr_code==""?(isset($sm['addr_code']) ? $addr=$sm['addr_code']:""):"";
  398. $sm['addr_code'] =isset($sm['addr_code']) ? $sm['addr_code']:"";
  399. }
  400. $remark = isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  401. if($info['is_th']==1 && $info['order_type']==1){
  402. if($contactor==''){
  403. return error_show(1005,"参数 contactor 不能为空");
  404. }
  405. if($mobile==''){
  406. return error_show(1005,"参数 mobile 不能为空");
  407. }
  408. if($addr==''){
  409. return error_show(1005,"参数 addr 不能为空");
  410. }
  411. if($addr_code==''){
  412. return error_show(1005,"参数 addr_code 不能为空");
  413. }
  414. if($addr_code!==''&&is_array($addr_code)){
  415. $addrs=[];
  416. $addrs['provice_code'] = $addr_code[0];
  417. $addrs['city_code'] = $addr_code[1];
  418. $addrs['area_code'] = $addr_code[2];
  419. $addr_code = json_encode($addrs);
  420. }
  421. }
  422. Db::startTrans();
  423. try{
  424. $var=$info['status'];
  425. $info['status']=$info['order_type']==1?3:4;
  426. $info['remark']=$remark;
  427. $info['updatetime']=date("Y-m-d H:i:s");
  428. $up =Db::name("order_return")->save($info);
  429. if($up){
  430. // var_dump($contactor);
  431. $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
  432. if(empty($returninfo)){
  433. $returninfo=[
  434. "returnCode"=>$bkcode,
  435. "return_wsm"=>$wsm_code,
  436. "contactor"=>$contactor,
  437. "mobile"=>$mobile ,
  438. "addr"=>$addr,
  439. "addr_code"=>$addr_code,
  440. "addtime"=>date("Y-m-d H:i:s")
  441. ];
  442. }else{
  443. $returninfo['return_wsm'] = $wsm_code;
  444. //if($info['is_th']==1 && $info['order_type']==1) {
  445. $contactor !==""? $returninfo['contactor'] = $contactor:"";
  446. $mobile!==""?$returninfo['mobile'] = $mobile:"";
  447. $addr!==""? $returninfo['addr'] = $addr:"";
  448. $addr_code!==""?$returninfo['addr_code'] = $addr_code:"";
  449. // }
  450. }
  451. // var_dump($contactor);
  452. // var_dump($returninfo);
  453. $in=Db::name("order_returninfo")->save($returninfo);
  454. if($in){
  455. $order = ["order_code"=>$info['returnCode'],"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
  456. ActionLog::logAdd($this->post['token'],$order,$info['order_type']==1?'SHD':"ZXSHD",$info['status'],$order);
  457. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>$info['order_type']==1?'SHD':"ZXSHD"];
  458. ProcessOrder::AddProcess($this->post['token'],$process);
  459. Db::commit();
  460. return app_show(0,"更新成功");
  461. }
  462. }
  463. Db::rollback();
  464. return error_show(1004,"更新失败");
  465. }catch (\Exception $e){
  466. Db::rollback();
  467. return error_show(1004,$e->getMessage());
  468. }
  469. }
  470. /**
  471. * @return \think\response\Json|void
  472. * @throws \think\db\exception\DataNotFoundException
  473. * @throws \think\db\exception\DbException
  474. * @throws \think\db\exception\ModelNotFoundException
  475. */
  476. public function addpost(){
  477. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  478. if($bkcode==""){
  479. return error_show(1005,"参数returnCode 不能为空");
  480. }
  481. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  482. if(empty($info)){
  483. return error_show(1005,"未找到售后数据");
  484. }
  485. $return_info = Db::name("order_returninfo")->where(['returnCode'=>$bkcode])->find();
  486. if(empty($return_info)){
  487. $return_info=[
  488. "returnCode"=>$bkcode,
  489. "return_wsm"=>'',
  490. "contactor"=>'',
  491. "mobile"=>'',
  492. "addr"=>'',
  493. "addr_code"=>'',
  494. "addtime"=>date("Y-m-d H:i:s"),
  495. "post_company"=>'',
  496. "post_code"=>'',
  497. "post_fee"=>'',
  498. ];
  499. }
  500. $post_own = isset($this->post['own']) &&$this->post['own']!='' ? trim($this->post['own']):"";
  501. if($post_own==''){
  502. return error_show(1005,"参数own不能为空");
  503. }
  504. $info['post_own'] = $post_own;
  505. $post_company = isset($this->post['company'])&&$this->post['company']!='' ? trim($this->post['company']):"";
  506. if($post_company==''){
  507. return error_show(1005,"参数company不能为空");
  508. }
  509. $return_info['post_company'] = $post_company;
  510. $post_code = isset($this->post['post_code'])&&$this->post['post_code']!='' ? trim($this->post['post_code']):"";
  511. if($post_code==''){
  512. return error_show(1005,"参数post_code不能为空");
  513. }
  514. $return_info['post_code'] = $post_code;
  515. $fee= isset($this->post['post_fee'])&&$this->post['post_fee']!=='' ? round($this->post['post_fee'],2):"";
  516. if($fee===''){
  517. return error_show(1005,"参数post_fee不能为空");
  518. }
  519. $return_info['post_fee'] = $fee;
  520. Db::startTrans();
  521. try{
  522. $str=$info['status'];
  523. $info['status']=$info['order_type']==1?4:5;
  524. $info['updatetime']=date("Y-m-d H:i:s");
  525. $up =Db::name("order_return")->save($info);
  526. if($up){
  527. $order = ["order_code"=>$info['orderCode'],"status"=>$str,"action_remark"=>'',"action_type"=>"edit"];
  528. ActionLog::logAdd($this->post['token'],$order,$info['order_type']==1?'SHD':"ZXSHD",$info['status'],$order);
  529. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>$info['order_type']==1?'SHD':"ZXSHD"];
  530. ProcessOrder::AddProcess($this->post['token'],$process);
  531. $in=Db::name("order_returninfo")->save($return_info);
  532. if($in){
  533. $data=[
  534. 'thNo'=>makeNo("TH"),
  535. "orderCode"=>$info['orderCode'],
  536. "order_type"=>$info['order_type'],
  537. "outCode"=>$info['outCode'],
  538. "returnCode"=>$info['returnCode'],
  539. "good_code"=>$info['good_code'],
  540. "good_name"=>$info['good_name'],
  541. "return_wsm"=>$return_info['return_wsm'],
  542. "return_num"=>$info['error_num'],
  543. "contactor"=>$return_info['contactor'],
  544. "mobile"=>$return_info['mobile'],
  545. "addr"=>$return_info['addr'],
  546. "addr_code"=>$return_info['addr_code'],
  547. "return_code"=>$info['error_code'],
  548. "return_msg"=>$info['error_msg'],
  549. "post_fee"=>$return_info['post_fee'],
  550. "post_code"=>$return_info['post_code'],
  551. "post_company"=>$return_info['post_company'],
  552. "customer_code"=>$info['customer_code'],
  553. "addtime"=>date("Y-m-d H:i:s"),
  554. "updatetime"=>date("Y-m-d H:i:s")
  555. ];
  556. $back =Db::name("order_back")->insert($data,true);
  557. if($back>0){
  558. $order = ["order_code"=>$data['thNo'],"status"=>0,"action_remark"=>'',"action_type"=>"create"];
  559. ActionLog::logAdd($this->post['token'],$order,$info['order_type']==1?'SHD':"ZXSHD", 0,$data);
  560. $process=["order_code"=>$data['thNo'],"order_id"=>$back,"order_status"=>0,"order_type"=>$info['order_type']==1?'CKTHD':"ZXCKTHD"];
  561. ProcessOrder::AddProcess($this->post['token'],$process);
  562. Db::commit();
  563. return app_show(0,"更新成功");
  564. }
  565. }
  566. }
  567. Db::rollback();
  568. return error_show(1004,"更新失败");
  569. }catch (\Exception $e){
  570. Db::rollback();
  571. return error_show(1004,$e->getMessage());
  572. }
  573. }
  574. /**
  575. * @return \think\response\Json|void
  576. * @throws \think\db\exception\DataNotFoundException
  577. * @throws \think\db\exception\DbException
  578. * @throws \think\db\exception\ModelNotFoundException
  579. */
  580. public function GysFeed(){
  581. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  582. if($bkcode==""){
  583. return error_show(1005,"参数returnCode 不能为空");
  584. }
  585. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  586. if(empty($info)){
  587. return error_show(1005,"未找到售后数据");
  588. }
  589. $isth = isset($this->post['is_th']) && $this->post['is_th']!="" ? intval($this->post['is_th']):"0";
  590. $contactor = isset($this->post['contactor']) && $this->post['contactor']!="" ? trim($this->post['contactor'])
  591. :"";
  592. $mobile = isset($this->post['mobile']) && $this->post['mobile']!="" ? trim($this->post['mobile']):"";
  593. $addr = isset($this->post['addr']) && $this->post['addr']!="" ? trim($this->post['addr']):"";
  594. $addr_code = isset($this->post['addr_code']) && $this->post['addr_code']!=""&&!empty($this->post['addr_code']) ? $this->post['addr_code']:"";
  595. $remark = isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  596. if($isth==1){
  597. if($contactor==''){
  598. return error_show(1005,"参数 contactor 不能为空");
  599. }
  600. if($mobile==''){
  601. return error_show(1005,"参数 mobile 不能为空");
  602. }
  603. if($addr==''){
  604. return error_show(1005,"参数 addr 不能为空");
  605. }
  606. // var_dump(isset($this->post['addr_code']) , $this->post['addr_code']!="",!empty($addr_code));
  607. if($addr_code==''){
  608. return error_show(1005,"参数 addr_code 不能为空");
  609. }
  610. if(is_array($addr_code)){
  611. $addrs=[];
  612. $addrs['provice_code'] = $addr_code[0];
  613. $addrs['city_code'] = $addr_code[1];
  614. $addrs['area_code'] = $addr_code[2];
  615. $addr_code = json_encode($addrs);
  616. }
  617. }
  618. $orde= Db::name("order_out")->where(["outCode"=>$info['outCode'],"is_del"=>0])->find();
  619. if(empty($orde)){
  620. return error_show(1005,"未找到出库单数据");
  621. }
  622. Db::startTrans();
  623. try{
  624. $stat=$info['status'];
  625. $info['status']=$info['order_status']==1?5:3;
  626. $info['is_th']=$isth;
  627. $info['updatetime']=date("Y-m-d H:i:s");
  628. $up =Db::name("order_return")->save($info);
  629. if($up){
  630. $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
  631. if(empty($returninfo)){
  632. $returninfo=[
  633. "returnCode"=>$bkcode,
  634. "return_wsm"=>'',
  635. "contactor"=>$contactor,
  636. "mobile"=>$mobile ,
  637. "addr"=>$addr,
  638. "addr_code"=>$addr_code,
  639. "gys_remark"=>$remark,
  640. "addtime"=>date("Y-m-d H:i:s")
  641. ];
  642. }else{
  643. $returninfo['return_wsm'] = '';
  644. $returninfo['contactor'] = $contactor;
  645. $returninfo['mobile'] = $mobile;
  646. $returninfo['addr'] = $addr;
  647. $returninfo['gys_remark'] = $remark;
  648. $returninfo['addr_code'] = $addr_code;
  649. }
  650. $in=Db::name("order_returninfo")->save($returninfo);
  651. if($in){
  652. if( $info['order_status']==1&&$info['order_type']==2){
  653. $orderout= Db::name("order_out")->where($orde)->save(['status'=>3,"updatetime"=>date("Y-m-d H:i:s")]);
  654. $order = ["order_code"=>$orde['outCode'],"status"=>$orde['status'],"action_remark"=>'',"action_type"=>"edit"];
  655. ActionLog::logAdd($this->post['token'],$order,$orde['order_type']==1?'CKD':"ZXCKD", 3,
  656. ['status'=>3,"updatetime"=>date("Y-m-d H:i:s")]);
  657. $process=["order_code"=>$orde['outCode'],"order_id"=>$orde['id'],"order_status"=>3,
  658. "order_type"=>$orde['order_type']==1?'CKD':"ZXCKD"];
  659. ProcessOrder::AddProcess($this->post['token'],$process);
  660. if($orderout){
  661. Db::commit();
  662. return app_show(0,"更新成功");
  663. }else{
  664. Db::rollback();
  665. return error_show(1004,"更新失败");
  666. }
  667. }
  668. $order = ["order_code"=>$info['returnCode'],"status"=>$stat,"action_remark"=>'',"action_type"=>"edit"];
  669. ActionLog::logAdd($this->post['token'],$order,$info['order_type']==1?'CKTHD':"ZXCKTHD",3,$order);
  670. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>$info['order_type']==1?'CKTHD':"ZXCKTHD"];
  671. ProcessOrder::AddProcess($this->post['token'],$process);
  672. Db::commit();
  673. return app_show(0,"更新成功");
  674. }
  675. }
  676. Db::rollback();
  677. return error_show(1004,"更新失败");
  678. }catch (\Exception $e){
  679. Db::rollback();
  680. return error_show(1004,$e->getMessage());
  681. }
  682. }
  683. public function GetWsm(){
  684. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  685. if($bkcode==""){
  686. return error_show(1005,"参数returnCode 不能为空");
  687. }
  688. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  689. if(empty($info)){
  690. return error_show(1005,"未找到售后数据");
  691. }
  692. $list=[];
  693. if($info['is_th']==1){
  694. if($info["order_type"]==1){
  695. $out =Db::name("order_out")->where(["outCode"=>$info['outCode']])->find();
  696. if(empty($out)){
  697. return error_show(1005,"未找到出库单数据");
  698. }
  699. $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")
  700. ->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();
  701. if(empty($ware)){
  702. return error_show(1005,"未找到仓库数据");
  703. }
  704. $temp['wsm_code']=isset($ware['wsm_code'])?$ware['wsm_code']:"";
  705. $temp['wsm_name']=isset($ware['name'])?$ware['name']:"";
  706. $temp['contactor'] = isset($ware['wsm_name'])?$ware['wsm_name']:"";
  707. $temp['mobile'] =isset($ware['wsm_mobile'])?$ware['wsm_mobile']:"";
  708. $temp['addr'] =isset($ware['wsm_addr'])?$ware['wsm_addr']:"";
  709. $temp['addr_code'] = isset($ware['addr_code'])?$ware['addr_code']:"";
  710. $temp['addr_cn'] =GetAddr( $ware['addr_code']);
  711. $list[]=$temp;
  712. }else {
  713. $returninfo = Db::name("order_returninfo")->where(["returnCode" => $bkcode])->find();
  714. if (empty($returninfo)) {
  715. return error_show(1005, "未找到供应商仓库数据");
  716. }
  717. $data = [];
  718. $data['wsm_code'] = isset($returninfo['return_wsm']) && $returninfo['return_wsm'] != "" ? $returninfo['return_wsm'] : "-";
  719. $data['wsm_name'] = '供应商仓';
  720. $data['supplier_name'] = '供应商';
  721. $data['contactor'] = $returninfo['contactor'];
  722. $data['mobile'] = $returninfo['mobile'];
  723. $data['addr'] = $returninfo['addr'];
  724. $data['addr_cn'] =GetAddr( $returninfo['addr_code']);
  725. $data['addr_code'] = $returninfo['addr_code'];
  726. $list[] = $data;
  727. }
  728. }
  729. $supplier = Db::name("supplier")->where(["is_platform"=>1,"status"=>1,"is_del"=>0])->column("code,name");
  730. if(empty($supplier)){
  731. return error_show(1005,"未找到供应商仓库数据");
  732. }
  733. foreach ($supplier as $value){
  734. $temp=[];
  735. $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")
  736. ->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();
  737. if(empty($ware)){
  738. continue;
  739. }
  740. $temp['wsm_code']=isset($ware['wsm_code'])?$ware['wsm_code']:"";
  741. $temp['wsm_name']=isset($ware['name'])?$ware['name']:"";
  742. $temp['supplier_name']=$value['name'];
  743. $temp['contactor'] = isset($ware['wsm_name'])?$ware['wsm_name']:"";
  744. $temp['mobile'] =isset($ware['wsm_mobile'])?$ware['wsm_mobile']:"";
  745. $temp['addr'] =isset($ware['wsm_addr'])?$ware['wsm_addr']:"";
  746. $temp['addr_cn'] =GetAddr($ware['addr_code']);
  747. $temp['addr_code'] = isset($ware['addr_code'])?$ware['addr_code']:"";
  748. $list[]=$temp;
  749. }
  750. return app_show(0,"获取成功",$list);
  751. }
  752. public function setdelivery(){
  753. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  754. if($bkcode==""){
  755. return error_show(1005,"参数returnCode 不能为空");
  756. }
  757. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  758. if(empty($info)){
  759. return error_show(1005,"未找到售后数据");
  760. }
  761. if(($info['is_receive']==0&&$info['status']!=3)||($info['is_receive']==1&&$info['status']!=4) ){
  762. return error_show(1005,"售后单流程状态有误");
  763. }
  764. $out=Db::name("order_out")->where(["outCode"=>$info["outCode"]])->find();
  765. $is_th = isset($this->post['is_th'])&&$this->post['is_th']!=="" ? intval($this->post['is_th']):"";
  766. if($is_th===""){
  767. return error_show(1005,"参数is_th不能为空");
  768. }
  769. $company=isset($this->post['company'])&&$this->post['company']!=""?trim($this->post['company']):"";
  770. $post_code=isset($this->post['post_code'])&&$this->post['post_code']!=""?trim($this->post['post_code']):"";
  771. $post_fee=isset($this->post['post_fee'])&&$this->post['post_fee']!==""?floatval($this->post['post_fee']):"";
  772. if($is_th==1){
  773. if($company==""){
  774. return error_show(1005,"参数company不能为空");
  775. }
  776. if($post_code==""){
  777. return error_show(1005,"参数post_code不能为空");
  778. }
  779. if($post_fee==""){
  780. return error_show(1005,"参数post_fee不能为空");
  781. }
  782. }
  783. try {
  784. $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
  785. if($returninfo==false){
  786. $returninfo=[
  787. "returnCode"=>$bkcode,
  788. "return_wsm"=>"",
  789. "contactor"=>"",
  790. "mobile"=>"",
  791. "addr"=>"",
  792. "addr_code"=>"",
  793. "post_code"=>$post_code,
  794. "post_company"=>$company,
  795. "post_fee"=>$post_fee,
  796. "gys_remark"=>"",
  797. "addtime"=>date("Y-m-d H:i:s")
  798. ];
  799. }else{
  800. $returninfo['post_fee']=$post_fee;
  801. $returninfo['post_company']=$company;
  802. $returninfo['post_code']=$post_code;
  803. }
  804. $up =Db::name("order_returninfo")->save($returninfo);
  805. if($up){
  806. $info['status']=5;
  807. $info['updatetime']=date("y-m-d H:i:s");
  808. $ro =Db::name("order_return")->save($info);
  809. if($ro){
  810. $thNo =makeNo("TH");
  811. $thdata=[
  812. "thNo"=>$thNo,
  813. "orderCode"=>$out["orderCode"],
  814. "outCode"=>$out["outCode"],
  815. "order_type"=>$info["order_type"],
  816. "returnCode"=>$info["returnCode"],
  817. "good_code"=>$info["good_code"],
  818. "good_name"=>$info["good_name"],
  819. "return_wsm"=>$returninfo["return_wsm"],
  820. "defective_wsm"=>'',
  821. "return_msg"=>$out["error_msg"],
  822. "return_num"=>$info["total_num"],
  823. "normal_num"=>0,
  824. "received_num"=>0,
  825. "defective_num"=>0,
  826. "loss_num"=>0,
  827. "contactor"=>$returninfo["contactor"],
  828. "mobile"=>$returninfo["mobile"],
  829. "addr"=>$returninfo["addr"],
  830. "addr_code"=>$returninfo["addr_code"],
  831. "return_code"=>$info["error_code"],
  832. "post_fee"=>$returninfo["post_fee"],
  833. "post_code"=>$returninfo["post_code"],
  834. "post_company"=>$returninfo["post_company"],
  835. "customer_code"=>$returninfo["customer_code"],
  836. "status"=>1,
  837. "addtime"=>date("Y-m-d H:i:s"),
  838. "updatetime"=>date("Y-m-d H:i:s")
  839. ];
  840. $sav= Db::name("order_back")->insert($thdata);
  841. if($sav){
  842. Db::commit();
  843. return app_show(0,"退货单新建成功",["thNo"=>$thNo]);
  844. }
  845. }
  846. }
  847. Db::rollback();
  848. return error_show(1004,'退货失败');
  849. }catch (\Exception $e){
  850. Db::rollback();
  851. return error_show(1004,$e->getMessage());
  852. }
  853. }
  854. }