After.php 43 KB

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