12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\ActionLog;
- use app\admin\model\ProcessOrder;
- use think\App;
- use think\Exception;
- use think\facade\Db;
- use think\facade\Validate;
- //售后
- class After extends Base
- {
- // public $post=[];
- public function __construct(App $app)
- {
- parent::__construct($app);
- // $this->post =$this->request->post();
- }
- public function create(){
- $outCode = isset($this->post['outCode']) &&$this->post['outCode']!=''?trim($this->post['outCode']) :"";
- if($outCode==''){
- return error_show(1004,"参数outCode 不能为空");
- }
- $orderout= Db::name("order_out")->where(["outCode"=>$outCode])->find();
- if(empty($orderout)){
- return error_show(1005,"未找到订单数据");
- }
- $oder= Db::name("sale")->where(["orderCode"=>$orderout['orderCode'],"is_del"=>0])->find();
- if(empty($oder)){
- return error_show(1005,"未找到订单数据");
- }
- $errorCode = isset($this->post['errorCode']) &&$this->post['errorCode']!=''?trim($this->post['errorCode']) :"";
- if($outCode==''){
- return error_show(1004,"参数errorCode 不能为空");
- }
- $error =Db::name('result_info')->where(["result_code"=>$errorCode,"is_del"=>0])->find();
- if(empty($error)){
- return error_show(1005,"未找到退货原因数据");
- }
- $remark =isset($this->post['remark']) &&$this->post['remark']!=''?trim($this->post['remark']) :"";
- $is_receive =isset($this->post['is_receive']) &&$this->post['is_receive']!==''?intval($this->post['is_receive'])
- :"";
- if($is_receive===""){
- return error_show(1004,"参数 is_receive 不能为空");
- }
- if($is_receive==0){
- $num=$orderout['send_num'];
- }else{
- $num =isset($this->post['num']) &&$this->post['num']!=''?intval($this->post['num']) :"";
- if($num==""){
- return error_show(1004,"参数 num 不能为空或零");
- }
- }
- $except_code =isset($this->post['except_code']) &&$this->post['except_code']!=''?trim($this->post['except_code']) :"";
- $img = isset($this->post['img']) &&$this->post['img']!=''?trim($this->post['img']) :"";
- $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
- if($token==''){
- return error_show(105,"参数token不能为空");
- }
- $user =GetUserInfo($token);
- if(empty($user)||$user['code']!=0){
- return error_show(102,"申请人数据不存在");
- }
- $rm= isset($user["data"]['id']) ? $user["data"]['id'] : "";
- $ri= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
- $returnCode=makeNo("RS");
- Db::startTrans();
- try{
- $in = [
- "returnCode"=>$returnCode,
- "outCode"=>$outCode,
- "orderCode"=> $oder['orderCode'],
- "good_code"=>$oder['good_code'],
- "good_name"=>$oder['good_name'],
- "customer_code"=>$oder['customer_code'],
- "apply_id"=>$rm,
- "apply_name"=>$ri,
- 'total_num'=>$orderout['send_num'],
- "error_code"=>$errorCode,
- "error_num"=>$num,
- "error_img"=>$img,
- "error_msg"=>$error['result'],
- "error_remark"=>$remark,
- "is_receive"=>$is_receive,
- "remark"=>'',
- "except_code"=>$except_code,
- "order_type"=>$orderout['order_type'],
- "status"=>1,
- "is_del"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $create = Db::name("order_return")->insert($in,true);
- $orde = ["order_code"=>$returnCode,"status"=>$in['status'],"action_remark"=>'',"action_type"=>"create"];
- ActionLog::logAdd($this->post['token'],$orde,'SHD',0,$orde);
- if($create>0){
- $process=["order_code"=>$returnCode,"order_id"=>$create,"order_status"=>$in['status'],"order_type"=>'SHD'];
- ProcessOrder::AddProcess($token,$process);
- Db::commit();
- return app_show(0,"售后申请单新建成功",["returnCode"=>$returnCode]);
- }
- Db::rollback();
- return error_show(1005,"售后申请单新建失败");
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1005,$e->getMessage());
- }
- }
- public function list(){
- $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
- $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
- $where =[['a.is_del',"=",0]];
- $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
- if($bkcode!=""){
- $where[]=['a.returnCode',"like", "%{$bkcode}%"];
- }
- $out = isset($this->post['outCode']) && $this->post['outCode']!="" ? trim($this->post['outCode']):"";
- if($out!=""){
- $where[]=['a.outCode',"like", "%{$out}%"];
- }
- $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
- if($status!==""){
- $where[]=['a.status',"=", $status];
- }
- $order_type = isset($this->post['order_type']) && $this->post['order_type']!=="" ? intval($this->post['order_type']):"";
- if($order_type!==""){
- $where[]=['a.order_type',"=", $order_type];
- }
- $orderCode = isset($this->post['orderCode']) && $this->post['orderCode']!="" ? trim($this->post['orderCode'])
- :"";
- if($orderCode!=""){
- $where[]=['a.orderCode',"like", "%{$orderCode}%"];
- }
- $good_code = isset($this->post['good_code']) && $this->post['good_code']!="" ? trim($this->post['good_code'])
- :"";
- if($good_code!=""){
- $where[]=['a.good_code',"like", "%{$good_code}%"];
- }
- $good_name = isset($this->post['good_name']) && $this->post['good_name']!="" ? trim($this->post['good_name'])
- :"";
- if($good_name!=""){
- $where[]=['a.good_name',"like", "%{$good_name}%"];
- }
- $customer_code = isset($this->post['customer_code']) && $this->post['customer_code']!="" ? trim($this->post['customer_code'])
- :"";
- if($customer_code!=""){
- $where[]=['a.customer_code',"like", "%{$customer_code}%"];
- }
- $except_code = isset($this->post['except_code']) && $this->post['except_code']!="" ? trim($this->post['except_code']):"";
- if($except_code!=""){
- $where[]=['a.except_code',"=", $except_code];
- }
- $apply_name = isset($this->post['apply_name']) && $this->post['apply_name']!="" ? trim($this->post['apply_name'])
- :"";
- if($apply_name!=""){
- $where[]=['a.apply_name',"like", "%{$apply_name}%"];
- }
- $start =isset($this->post['start'])&&$this->post['start']!='' ? $this->post['start']:"";
- if($start!==""){
- $where[]=['a.addtime',">=", $start];
- }
- $end =isset($this->post['end'])&&$this->post['end']!='' ? $this->post['end']:"";
- if($end!==""){
- $where[]=['a.addtime',"<=", $end];
- }
- $role=$this->checkRole();
- if(!empty($role['write'])){
- $where[]=["apply_id","in",$role['write']];
- }
- $count=Db::name("order_return")->alias("a")->leftJoin("order_returninfo b","a.returnCode=b.returnCode")->where
- ($where)->count();
- $total = ceil($count/$size);
- $page = $total>=$page ? $page :$total;
- $list =Db::name("order_return")->alias("a")->leftJoin("order_returninfo b","a.returnCode=b.returnCode")->where($where)
- ->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)
- ->order("addtime desc")->select();
- $data=[];
- foreach ($list as $value){
- $customer = Db::name("customer_info")->where(["companyNo"=>$value['customer_code']])->find();
- $value['customer_name'] = isset($customer['companyName']) ?trim($customer['companyName']):'';
- $data[]=$value;
- }
- return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function info()
- {
- $bkcode = isset($this->post['returnCode']) && $this->post['returnCode'] != "" ? trim($this->post['returnCode']) : "";
- if ($bkcode == "") {
- return error_show(1005, "参数returnCode 不能为空");
- }
- $info = Db::name("order_return")->alias("a")->leftJoin("order_returninfo b", "a.returnCode=b.returnCode")
- ->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")
- ->where(['a.returnCode' => $bkcode])->find();
- if (empty($info)) {
- return error_show(1005, "未找到售后数据");
- }
- $orderinfo = Db::name("sale")->where(["orderCode" => $info["orderCode"]])->find();
- $info['origin_price'] = $orderinfo['origin_price'];
- $info['order_type'] = $orderinfo['order_type'];
- $info['sale_price'] = $orderinfo['sale_price'];
- $info['total_price'] = sprintf("%1\$.2f", $orderinfo['sale_price'] * $info['error_num']);
- if ($orderinfo['order_type'] == 3 || $orderinfo['order_type'] == 4) {
- $goon = Db::name("good_zixun")->where(["spuCode" => $orderinfo['good_code'], "is_del" => 0])->find();
- } else {
- $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
- ->where(['a.skuCode' => $orderinfo['skuCode']])->find();
- }
- if (empty($goon)) {
- return error_show(1003, "未找到商品数据");
- }
- $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
- $addcode = '';
- if ($info['addr_code'] != "") {
- list($a, $b, $c) = explode(",", $info['addr_code']);
- $addcode = json_encode(["provice_code" => $a, "city_code" => $b, "area_code" => $c]);
- }
- $info["addr_cn"]=GetAddr($addcode);
- // $info["addr_code"]=json_decode($addcode,true);
- $out =Db::name("order_out")->where(["outCode"=>$info['outCode']])->find();
- $info['out_num'] = isset($out['send_num'])?$out['send_num']:'';
- // $customer = Db::name("customer_info")->where(["companyNo"=>$info['customer_code']])->find();
- $wsmcode=[];
- if($info['return_wsm']!=''){
- $wsmcode = Db::name("warehouse_info")
- ->alias("a")
- ->leftJoin("supplier b","a.supplierNo=b.code")
- ->where(["a.wsm_code"=>$info['return_wsm']])
- ->field("a.name as wsm_name,b.name,b.code,a.wsm_code,a.contactor_name,a.position,a.mobile,a.addrs_code,a.addr,a.companyNo")
- ->find();
- }
- $info['wsm_code'] =isset($wsmcode['wsm_code']) ? $wsmcode['wsm_code']:"";
- $info['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
- $info['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
- $info['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
- $customer=[];
- if(isset($orderinfo['supplierNo'])&&$orderinfo['supplierNo']!=''){
- $customer = Db::name("business")->field('id,company,companyNo')->where(["companyNo"=>$orderinfo['supplierNo']])->find();
- }
- $info['customer_name'] = isset($customer['company']) ?trim($customer['company']):'';
- $info['customer_code'] = isset($customer['companyNo']) ?trim($customer['companyNo']):'';
- $info['can']=$int;
- //仓库的联系人、职位、电话、省市区和地址
- isset($wsmcode['contactor_name'])? $info['contactor'] =$wsmcode['contactor_name']:'';//联系人
- isset($wsmcode['mobile'])? $info['mobile'] =$wsmcode['mobile']:'';//联系人
- isset($wsmcode['addrs_code'])? $info['addr_code'] =$wsmcode['addrs_code']:'';//联系人
- isset($wsmcode['addr'])? $info['addr'] =$wsmcode['addr']:'';//联系人
- isset($wsmcode['contactor_name'])? $info['contactor'] =$wsmcode['contactor_name']:'';//联系人
- // $info['position'] = $wsmcode['position'];//职位
- // $info['mobile'] = $wsmcode['mobile'];//电话
- // $info['addrs_code'] = json_decode($wsmcode['addrs_code'], true);//省市区编码
- // $info['addr'] = $wsmcode['addr'];//地址
- $info['spuCode'] = $orderinfo['good_code'];//地址
- $info['skuCode'] = $orderinfo['skuCode'];//地址
- $info['return_tag'] = $info['return_tag']==0?"":$info['return_tag'];//地址
- $info['is_th'] = $info['is_th']==0?"":$info['is_th'];//地址
- return app_show(0,"获取成功",$info);
- }
- public function status(){
- $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
- if($bkcode==""){
- return error_show(1005,"参数returnCode 不能为空");
- }
- $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
- if(empty($info)){
- return error_show(1005,"未找到售后数据");
- }
- $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status'])
- :"";
- if($status===""){
- return error_show(1005,"参数status 不能为空");
- }
- $orde= Db::name("order_out")->where(["outCode"=>$info['outCode']])->find();
- if($orde==false){
- return error_show(1005,"未找到出库单数据");
- }
- $remark = isset($this->post['remark'])&&$this->post['remark']!=''?trim($this->post['remark']):"";
- if($remark!=''){
- $info['remark'] =$remark;
- }
- if($status==3 && $info['is_receive']==1){
- $post =isset($this->post['is_post'])&&$this->post['is_post']!==""? intval($this->post['is_post']):"";
- if($post===""){
- return error_show(1005,"参数is_post不能为空");
- }
- $info['is_post']=$post;
- $return_tag =isset($this->post['return_tag'])&&$this->post['return_tag']!==""? intval($this->post['return_tag']):"";
- if($return_tag===""){
- return error_show(1005,"参数return_tag不能为空");
- }
- $info['return_tag']=$return_tag;
- $is_th =isset($this->post['is_th'])&&$this->post['is_th']!==""? intval($this->post['is_th']):"0";
- $info['is_th']=$is_th;
- }
- // $status = $info['order_status']==1&&$info['order_type']==1 && $status==1?4:$status;
- Db::startTrans();
- try{
- $var=$info['status'];
- $info['status']=$status;
- $info['updatetime']=date("Y-m-d H:i:s");
- $up =Db::name("order_return")->save($info);
- if($up){
- $order = ["order_code"=>$info['returnCode'],"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
- ActionLog::logAdd($this->post['token'],$order,"SHD", $info['status'],$this->post);
- $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$status,"order_type"=>"SHD"];
- ProcessOrder::AddProcess($this->post['token'],$process);
- Db::commit();
- return app_show(0,"更新成功");
- }else{
- Db::rollback();
- return error_show(1004,"更新失败");
- }
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- }
- public function setWsm(){
- $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
- if($bkcode==""){
- return error_show(1005,"参数returnCode 不能为空");
- }
- $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
- if(empty($info)){
- return error_show(1005,"未找到售后数据");
- }
- if($info['status']!=3){
- return error_show(1005,"采购主管未审核无法设置退回仓库");
- }
- $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']) :"";
- if($info['return_tag']==2) {
- if($wsm_code==""){
- return error_show(1005,"参数 wsm_code 不能为空");
- }
- $warehouse =Db::name("warehouse_info")->where(["wsm_code"=>$wsm_code])->find();
- if($warehouse==false){
- return error_show(1005,"仓库数据未找到");
- }
- $wareaddr =Db::name("warehouse_addr")->where(["wsm_code"=>$wsm_code,"is_del"=>0,"status"=>1])->find();
- }
- $addrcode=isset($this->post['addr_code'])&&$this->post['addr_code']!=""?$this->post['addr_code']:"";
- if($addrcode==""){
- return error_show(1005,"参数 addr_code 不能为空");
- }
- $addr=isset($this->post['addr'])&&$this->post['addr']!=""?trim($this->post['addr']):"";
- if($addr==""){
- return error_show(1005,"参数 addr 不能为空");
- }
- $mobile=isset($this->post['mobile'])&&$this->post['mobile']!=""?trim($this->post['mobile']):"";
- if($mobile==""){
- return error_show(1005,"参数 mobile 不能为空");
- }
- $contactor=isset($this->post['contactor'])&&$this->post['contactor']!=""?trim($this->post['contactor']):"";
- if($contactor==""){
- return error_show(1005,"参数 contactor 不能为空");
- }
- $returninfo=[
- "returnCode"=>$bkcode,
- "return_wsm"=>$wsm_code,
- "contactor"=>$contactor,
- "mobile"=>$mobile ,
- "addr"=>$addr,
- "addr_code"=>$addrcode,
- "addtime"=>date("Y-m-d H:i:s")
- ];
- Db::startTrans();
- try {
- $in=Db::name("order_returninfo")->insert($returninfo);
- if($in){
- if($info['return_tag']==2 &&$wareaddr==false) {
- $addrs =[
- "wsm_code"=>$wsm_code,
- "wsm_type"=>1,
- "wsm_name"=>$contactor,
- "wsm_addr"=>$addr,
- "addr_code"=>$addrcode,
- "wsm_mobile"=>$mobile,
- "status"=>'1',
- "is_del"=>'0',
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $wareaddr =Db::name("warehouse_addr")->insert($addrs);
- if($wareaddr==false){
- Db::rollback();
- return app_show(1004,"退货仓库地址录入失败");
- }
- }
- $old_info_status = $info['status'];
- $info['status']=4;
- $info["updatetime"]=date("Y-m-d H:i:s");
- $up =Db::name("order_return")->save($info);
- if($up){
- //修改状态,添加待办
- ActionLog::logAdd($this->post['token'], [
- "order_code" => $info['returnCode'],//销售单code
- "status" => $old_info_status,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "status"//新建create,编辑edit,更改状态status
- ], "SHD", $info['status'], $info);
- ProcessOrder::AddProcess($this->post['token'], [
- "order_type" => 'SHD',
- "order_code" => $info['returnCode'],//销售单code
- "order_id" => $info['id'],
- "order_status" => $info['status']
- ]);
- Db::commit();
- return app_show(0,"退货仓库设置成功");
- }
- }
- Db::rollback();
- return error_show(1004,"设置失败");
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function postfeed(){
- $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
- if($bkcode==""){
- return error_show(1005,"参数returnCode 不能为空");
- }
- $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
- if(empty($info)){
- return error_show(1005,"未找到售后数据");
- }
- $contactor = isset($this->post['contactor']) && $this->post['contactor']!="" ? trim($this->post['contactor']) :"";
- $mobile = isset($this->post['mobile']) && $this->post['mobile']!="" ? trim($this->post['mobile']):"";
- $addr = isset($this->post['addr']) && $this->post['addr']!="" ? trim($this->post['addr']):"";
- $addr_code = isset($this->post['addr_code']) && $this->post['addr_code']!=""&&!empty($this->post['addr_code']) ?
- $this->post['addr_code']:"";
- $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
- if($wsm_code==""){
- return error_show(1005,"参数 wsm_code不能为空");
- }
- if($info['is_th']==0&&$info['order_type']==1) {
- $wsm = Db::name("warehouse_info")->where(["wsm_code" => $wsm_code])->find();
- if (empty($wsm)) {
- return error_show(1005, "未找到仓库数据");
- }
- $sm = Db::name("warehouse_addr")->where(["wsm_code" => $wsm_code,"is_del"=>0])->find();
- $contactor==""?(isset($sm['wsm_name']) ? $contactor=$sm['wsm_name']:""):"";
- $sm['wsm_name'] =isset($sm['wsm_name']) ? $sm['wsm_name']:"";
- $mobile==""?(isset($sm['wsm_mobile']) ? $mobile=$sm['wsm_mobile']:""):"";
- $sm['wsm_mobile'] =isset($sm['wsm_mobile']) ? $sm['wsm_mobile']:"";
- $addr==""?(isset($sm['wsm_addr']) ? $addr=$sm['wsm_addr']:""):"";
- $sm['wsm_addr'] =isset($sm['wsm_addr']) ? $sm['wsm_addr']:"";
- $addr_code==""?(isset($sm['addr_code']) ? $addr=$sm['addr_code']:""):"";
- $sm['addr_code'] =isset($sm['addr_code']) ? $sm['addr_code']:"";
- }
- $remark = isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
- if($info['is_th']==1 && $info['order_type']==1){
- if($contactor==''){
- return error_show(1005,"参数 contactor 不能为空");
- }
- if($mobile==''){
- return error_show(1005,"参数 mobile 不能为空");
- }
- if($addr==''){
- return error_show(1005,"参数 addr 不能为空");
- }
- if($addr_code==''){
- return error_show(1005,"参数 addr_code 不能为空");
- }
- if($addr_code!==''&&is_array($addr_code)){
- $addrs=[];
- $addrs['provice_code'] = $addr_code[0];
- $addrs['city_code'] = $addr_code[1];
- $addrs['area_code'] = $addr_code[2];
- $addr_code = json_encode($addrs);
- }
- }
- Db::startTrans();
- try{
- $var=$info['status'];
- $info['status']=$info['order_type']==1?3:4;
- $info['remark']=$remark;
- $info['updatetime']=date("Y-m-d H:i:s");
- $up =Db::name("order_return")->save($info);
- if($up){
- // var_dump($contactor);
- $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
- if(empty($returninfo)){
- $returninfo=[
- "returnCode"=>$bkcode,
- "return_wsm"=>$wsm_code,
- "contactor"=>$contactor,
- "mobile"=>$mobile ,
- "addr"=>$addr,
- "addr_code"=>$addr_code,
- "addtime"=>date("Y-m-d H:i:s")
- ];
- }else{
- $returninfo['return_wsm'] = $wsm_code;
- //if($info['is_th']==1 && $info['order_type']==1) {
- $contactor !==""? $returninfo['contactor'] = $contactor:"";
- $mobile!==""?$returninfo['mobile'] = $mobile:"";
- $addr!==""? $returninfo['addr'] = $addr:"";
- $addr_code!==""?$returninfo['addr_code'] = $addr_code:"";
- // }
- }
- // var_dump($contactor);
- // var_dump($returninfo);
- $in=Db::name("order_returninfo")->save($returninfo);
- if($in){
- $order = ["order_code"=>$info['returnCode'],"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
- ActionLog::logAdd($this->post['token'],$order,"SHD",$info['status'],$this->post);
- $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>"SHD"];
- ProcessOrder::AddProcess($this->post['token'],$process);
- Db::commit();
- return app_show(0,"更新成功");
- }
- }
- Db::rollback();
- return error_show(1004,"更新失败");
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function addpost(){
- $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
- if($bkcode==""){
- return error_show(1005,"参数returnCode 不能为空");
- }
- $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
- if(empty($info)){
- return error_show(1005,"未找到售后数据");
- }
- $return_info = Db::name("order_returninfo")->where(['returnCode'=>$bkcode])->find();
- if(empty($return_info)){
- $return_info=[
- "returnCode"=>$bkcode,
- "return_wsm"=>'',
- "contactor"=>'',
- "mobile"=>'',
- "addr"=>'',
- "addr_code"=>'',
- "addtime"=>date("Y-m-d H:i:s"),
- "post_company"=>'',
- "post_code"=>'',
- "post_fee"=>'',
- ];
- }
- $post_own = isset($this->post['own']) &&$this->post['own']!='' ? trim($this->post['own']):"";
- if($post_own==''){
- return error_show(1005,"参数own不能为空");
- }
- $info['post_own'] = $post_own;
- $post_company = isset($this->post['company'])&&$this->post['company']!='' ? trim($this->post['company']):"";
- if($post_company==''){
- return error_show(1005,"参数company不能为空");
- }
- $return_info['post_company'] = $post_company;
- $post_code = isset($this->post['post_code'])&&$this->post['post_code']!='' ? trim($this->post['post_code']):"";
- if($post_code==''){
- return error_show(1005,"参数post_code不能为空");
- }
- $return_info['post_code'] = $post_code;
- $fee= isset($this->post['post_fee'])&&$this->post['post_fee']!=='' ? round($this->post['post_fee'],2):"";
- if($fee===''){
- return error_show(1005,"参数post_fee不能为空");
- }
- $return_info['post_fee'] = $fee;
- Db::startTrans();
- try{
- $str=$info['status'];
- $info['status']=$info['order_type']==1?4:5;
- $info['updatetime']=date("Y-m-d H:i:s");
- $up =Db::name("order_return")->save($info);
- if($up){
- $order = ["order_code"=>$info['orderCode'],"status"=>$str,"action_remark"=>'',"action_type"=>"edit"];
- ActionLog::logAdd($this->post['token'],$order,"SHD",$info['status'],$this->post);
- $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>"SHD"];
- ProcessOrder::AddProcess($this->post['token'],$process);
- $in=Db::name("order_returninfo")->save($return_info);
- if($in){
- $data=[
- 'thNo'=>makeNo("ST"),
- "orderCode"=>$info['orderCode'],
- "order_type"=>$info['order_type'],
- "outCode"=>$info['outCode'],
- "returnCode"=>$info['returnCode'],
- "good_code"=>$info['good_code'],
- "good_name"=>$info['good_name'],
- "return_wsm"=>$return_info['return_wsm'],
- "return_num"=>$info['error_num'],
- "contactor"=>$return_info['contactor'],
- "mobile"=>$return_info['mobile'],
- "addr"=>$return_info['addr'],
- "addr_code"=>$return_info['addr_code'],
- "return_code"=>$info['error_code'],
- "return_msg"=>$info['error_msg'],
- "post_fee"=>$return_info['post_fee'],
- "post_code"=>$return_info['post_code'],
- "post_company"=>$return_info['post_company'],
- "customer_code"=>$info['customer_code'],
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $back =Db::name("order_back")->insert($data,true);
- if($back>0){
- $order = ["order_code"=>$data['thNo'],"status"=>0,"action_remark"=>'',"action_type"=>"create"];
- ActionLog::logAdd($this->post['token'],$order,"CKTHD", 0,$data);
- $process=["order_code"=>$data['thNo'],"order_id"=>$back,"order_status"=>0,"order_type"=>"CKTHD"];
- ProcessOrder::AddProcess($this->post['token'],$process);
- Db::commit();
- return app_show(0,"更新成功");
- }
- }
- }
- Db::rollback();
- return error_show(1004,"更新失败");
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function GysFeed(){
- $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
- if($bkcode==""){
- return error_show(1005,"参数returnCode 不能为空");
- }
- $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
- if(empty($info)){
- return error_show(1005,"未找到售后数据");
- }
- $isth = isset($this->post['is_th']) && $this->post['is_th']!="" ? intval($this->post['is_th']):"0";
- $contactor = isset($this->post['contactor']) && $this->post['contactor']!="" ? trim($this->post['contactor'])
- :"";
- $mobile = isset($this->post['mobile']) && $this->post['mobile']!="" ? trim($this->post['mobile']):"";
- $addr = isset($this->post['addr']) && $this->post['addr']!="" ? trim($this->post['addr']):"";
- $addr_code = isset($this->post['addr_code']) && $this->post['addr_code']!=""&&!empty($this->post['addr_code']) ? $this->post['addr_code']:"";
- $remark = isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
- if($isth==1){
- if($contactor==''){
- return error_show(1005,"参数 contactor 不能为空");
- }
- if($mobile==''){
- return error_show(1005,"参数 mobile 不能为空");
- }
- if($addr==''){
- return error_show(1005,"参数 addr 不能为空");
- }
- // var_dump(isset($this->post['addr_code']) , $this->post['addr_code']!="",!empty($addr_code));
- if($addr_code==''){
- return error_show(1005,"参数 addr_code 不能为空");
- }
- if(is_array($addr_code)){
- $addrs=[];
- $addrs['provice_code'] = $addr_code[0];
- $addrs['city_code'] = $addr_code[1];
- $addrs['area_code'] = $addr_code[2];
- $addr_code = json_encode($addrs);
- }
- }
- $orde= Db::name("order_out")->where(["outCode"=>$info['outCode'],"is_del"=>0])->find();
- if(empty($orde)){
- return error_show(1005,"未找到出库单数据");
- }
- Db::startTrans();
- try{
- $stat=$info['status'];
- $info['status']=$info['order_status']==1?5:3;
- $info['is_th']=$isth;
- $info['updatetime']=date("Y-m-d H:i:s");
- $up =Db::name("order_return")->save($info);
- if($up){
- $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
- if(empty($returninfo)){
- $returninfo=[
- "returnCode"=>$bkcode,
- "return_wsm"=>'',
- "contactor"=>$contactor,
- "mobile"=>$mobile ,
- "addr"=>$addr,
- "addr_code"=>$addr_code,
- "gys_remark"=>$remark,
- "addtime"=>date("Y-m-d H:i:s")
- ];
- }else{
- $returninfo['return_wsm'] = '';
- $returninfo['contactor'] = $contactor;
- $returninfo['mobile'] = $mobile;
- $returninfo['addr'] = $addr;
- $returninfo['gys_remark'] = $remark;
- $returninfo['addr_code'] = $addr_code;
- }
- $in=Db::name("order_returninfo")->save($returninfo);
- if($in){
- $order = ["order_code"=>$info['returnCode'],"status"=>$stat,"action_remark"=>'',"action_type"=>"edit"];
- ActionLog::logAdd($this->post['token'],$order,"SHD", $info['status'],$this->post);
- $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"SHD"];
- ProcessOrder::AddProcess($this->post['token'],$process);
- Db::commit();
- return app_show(0,"更新成功");
- }
- }
- Db::rollback();
- return error_show(1004,"更新失败");
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- }
- public function GetWsm(){
- $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
- if($bkcode==""){
- return error_show(1005,"参数returnCode 不能为空");
- }
- $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
- if($info==false){
- return error_show(1005,"未找到售后数据");
- }
- $list=[];
- if($info['is_th']==1){
- if($info["order_type"]==1){
- $out =Db::name("order_out")->where(["outCode"=>$info['outCode']])->find();
- if(empty($out)){
- return error_show(1005,"未找到出库单数据");
- }
- $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")
- ->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();
- if(empty($ware)){
- return error_show(1005,"未找到仓库数据");
- }
- $temp['wsm_code']=isset($ware['wsm_code'])?$ware['wsm_code']:"";
- $temp['wsm_name']=isset($ware['name'])?$ware['name']:"";
- $temp['contactor'] = isset($ware['wsm_name'])?$ware['wsm_name']:"";
- $temp['mobile'] =isset($ware['wsm_mobile'])?$ware['wsm_mobile']:"";
- $temp['addr'] =isset($ware['wsm_addr'])?$ware['wsm_addr']:"";
- $temp['addr_code'] = isset($ware['addr_code'])?$ware['addr_code']:"";
- $temp['addr_cn'] =GetAddr( $ware['addr_code']);
- $list[]=$temp;
- }else {
- $returninfo = Db::name("order_returninfo")->where(["returnCode" => $bkcode])->find();
- if (empty($returninfo)) {
- return error_show(1005, "未找到供应商仓库数据");
- }
- $data = [];
- $data['wsm_code'] = isset($returninfo['return_wsm']) && $returninfo['return_wsm'] != "" ? $returninfo['return_wsm'] : "-";
- $data['wsm_name'] = '供应商仓';
- $data['supplier_name'] = '供应商';
- $data['contactor'] = $returninfo['contactor'];
- $data['mobile'] = $returninfo['mobile'];
- $data['addr'] = $returninfo['addr'];
- $data['addr_cn'] =GetAddr( $returninfo['addr_code']);
- $data['addr_code'] = $returninfo['addr_code'];
- $list[] = $data;
- }
- }
- $supplier = Db::name("supplier")->where(["is_platform"=>1,"status"=>1,"is_del"=>0])->column("code,name");
- if(empty($supplier)){
- return error_show(1005,"未找到供应商仓库数据");
- }
- foreach ($supplier as $value){
- $temp=[];
- $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")
- ->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();
- if(empty($ware)){
- continue;
- }
- $temp['wsm_code']=isset($ware['wsm_code'])?$ware['wsm_code']:"";
- $temp['wsm_name']=isset($ware['name'])?$ware['name']:"";
- $temp['supplier_name']=$value['name'];
- $temp['contactor'] = isset($ware['wsm_name'])?$ware['wsm_name']:"";
- $temp['mobile'] =isset($ware['wsm_mobile'])?$ware['wsm_mobile']:"";
- $temp['addr'] =isset($ware['wsm_addr'])?$ware['wsm_addr']:"";
- $temp['addr_cn'] =GetAddr($ware['addr_code']);
- $temp['addr_code'] = isset($ware['addr_code'])?$ware['addr_code']:"";
- $list[]=$temp;
- }
- return app_show(0,"获取成功",$list);
- }
- public function setdelivery(){
- $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
- if($bkcode==""){
- return error_show(1005,"参数returnCode 不能为空");
- }
- $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
- if(empty($info)){
- return error_show(1005,"未找到售后数据");
- }
- if(($info['is_receive']==0&&$info['status']!=3)||($info['is_receive']==1&&$info['status']!=4) ){
- return error_show(1005,"售后单流程状态有误");
- }
- $out=Db::name("order_out")->where(["outCode"=>$info["outCode"]])->find();
- if($out==false){
- return error_show(1005,"未找到发货单数据");
- }
- $is_th = isset($this->post['is_th'])&&$this->post['is_th']!=="" ? intval($this->post['is_th']):"";
- if($is_th===""){
- return error_show(1005,"参数is_th不能为空");
- }
- $company=isset($this->post['company'])&&$this->post['company']!=""?trim($this->post['company']):"";
- $post_code=isset($this->post['post_code'])&&$this->post['post_code']!=""?trim($this->post['post_code']):"";
- $post_fee=isset($this->post['post_fee'])&&$this->post['post_fee']!==""?floatval($this->post['post_fee']):"";
- if($is_th==1){
- if($company==""){
- return error_show(1005,"参数company不能为空");
- }
- if($post_code==""){
- return error_show(1005,"参数post_code不能为空");
- }
- if($post_fee===""){
- return error_show(1005,"参数post_fee不能为空");
- }
- }
- Db::startTrans();
- try {
- $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
- if($returninfo==false){
- $returninfo=[
- "returnCode"=>$bkcode,
- "return_wsm"=>"",
- "contactor"=>"",
- "mobile"=>"",
- "addr"=>"",
- "addr_code"=>"",
- "post_code"=>$post_code,
- "post_company"=>$company,
- "post_fee"=>$post_fee,
- "gys_remark"=>"",
- "addtime"=>date("Y-m-d H:i:s")
- ];
- }else{
- $returninfo['post_fee']=$post_fee;
- $returninfo['post_company']=$company;
- $returninfo['post_code']=$post_code;
- }
- $up =Db::name("order_returninfo")->save($returninfo);
- if($up){
- $old_info_status = $info['status'];
- $info['status']=5;
- $info['updatetime']=date("y-m-d H:i:s");
- $ro =Db::name("order_return")->save($info);
- if($ro){
- //修改状态,添加待办
- ActionLog::logAdd($this->post['token'], [
- "order_code" => $info['returnCode'],//销售单code
- "status" => $old_info_status,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "status"//新建create,编辑edit,更改状态status
- ], "SHD", $info['status'], $this->post);
- ProcessOrder::AddProcess($this->post['token'], [
- "order_type" => 'SHD',
- "order_code" => $info['returnCode'],//销售单code
- "order_id" => $info['id'],
- "order_status" => $info['status']
- ]);
- $thNo =makeNo("ST");
- $thdata=[
- "thNo"=>$thNo,
- "orderCode"=>$out["orderCode"],
- "outCode"=>$out["outCode"],
- "order_type"=>$info["order_type"],
- "returnCode"=>$info["returnCode"],
- "good_code"=>$info["good_code"],
- "good_name"=>$info["good_name"],
- "return_wsm"=>$returninfo["return_wsm"],
- // "defective_wsm"=>'',
- "return_msg"=>$info["error_msg"],
- "return_num"=>$info["error_num"],
- "normal_num"=>0,
- "received_num"=>0,
- "apply_id"=>$info['apply_id'],
- "apply_name"=>$info['apply_name'],
- "contactor"=>$returninfo["contactor"],
- "mobile"=>$returninfo["mobile"],
- "addr"=>$returninfo["addr"],
- "addr_code"=>$returninfo["addr_code"],
- "return_code"=>$info["error_code"],
- "post_fee"=>$returninfo["post_fee"],
- "post_code"=>$returninfo["post_code"],
- "post_company"=>$returninfo["post_company"],
- "customer_code"=>$info["customer_code"],
- "status"=>1,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $sav= Db::name("order_back")->insert($thdata,true);
- if($sav){
- //修改状态,添加待办
- ActionLog::logAdd($this->post['token'], [
- "order_code" => $thdata['thNo'],//销售单code
- "status" => $thdata['status'],//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "create"//新建create,编辑edit,更改状态status
- ], "CKTHD", $thdata['status'], $thdata);
- ProcessOrder::AddProcess($this->post['token'], [
- "order_type" => 'CKTHD',
- "order_code" => $thdata['thNo'],//销售单code
- "order_id" => $sav,
- "order_status" => $thdata['status']
- ]);
- // $out['status']=$info['is_receive']==1&&$info['total_num']>$info['error_num'] ?3:4;
- // $out['updatetime']=date("Y-m-d H:i:s");
- // $outup=Db::name("order_out")->save($out);
- // if($outup==false){
- // Db::rollback();
- // return error_show(1005,"发货单更新失败");
- // }
- Db::commit();
- return app_show(0,"退货单新建成功",["thNo"=>$thNo]);
- }
- }
- }
- Db::rollback();
- return error_show(1004,'退货失败');
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- }
- //取消售后
- public function Cancel()
- {
- //接收参数
- $data = $this->request->only(['token', 'returnCode'], 'post', 'trim');
- $val = Validate::rule(['returnCode|售后单编号' => 'require']);
- if (!$val->check($data)) return error_show(1005, $val->getError());
- Db::startTrans();
- try {
- $rs = Db::name('order_return')->field('id,status')->where([['returnCode', '=', $data['returnCode']], ['is_del', '=', 0], ['status', '<>', 8]])->find();
- if (!$rs) throw new Exception('该售后单记录不存在');
- //修改记录
- $res = Db::name('order_return')->where(['id' => $rs['id']])->update(['status' => 8, 'updatetime' => date('Y-m-d H:i:s')]);
- if (!$res) throw new Exception('该售后单记录修改失败');
- //记录日志
- ActionLog::logAdd($data['token'], ["order_code" => $data['returnCode'], "status" => $rs['status'], "action_remark" => '', "action_type" => "cancel"], 'SHD', 8, $this->post);
- ProcessOrder::AddProcess($this->post['token'], ["order_code" => $data['returnCode'], "order_id" => $rs['id'], "order_status" => 8, "order_type" => 'SHD']);
- //提交
- Db::commit();
- return app_show(0, "取消成功");
- } catch (\Exception $e) {
- Db::rollback();
- return error_show(1004, $e->getMessage());
- }
- }
- }
|