12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\ActionLog;
- use app\admin\model\DataGroup as DataGroupModel;
- use app\admin\model\GoodLog;
- use app\admin\model\GoodStockInfo;
- use app\admin\model\ProcessOrder;
- use think\App;
- use think\Exception;
- use think\facade\Db;
- use think\facade\Validate;
- //售后
- class After extends Base
- {
- public function __construct(App $app)
- {
- parent::__construct($app);
- }
- //新建售后申请单
- public function create()
- {
- $param = $this->request->only(['outCode', 'errorCode', 'remark' => '', 'is_receive', 'num', 'except_code' => '', 'img'], 'post', 'trim');
- $val = Validate::rule([
- 'outCode' => 'require',
- 'errorCode' => 'require',
- 'is_receive' => 'require|in:0,1',
- 'num' => 'requireIf:is_receive,1',
- 'except_code' => 'require',
- 'img' => 'require',
- ]);
- if ($val->check($param) == false) return json_show(1004, $val->getError());
- // $outCode = isset($this->post['outCode']) &&$this->post['outCode']!=''?trim($this->post['outCode']) :"";
- // if($outCode==''){
- // return error_show(1004,"参数outCode 不能为空");
- // }
- $orderout = Db::name("order_out")
- ->field('id,orderCode,wsm_code,send_num,order_type')
- ->where(["outCode" => $param['outCode'], 'is_del' => 0])
- ->findOrEmpty();
- if (empty($orderout)) return error_show(1005, "未找到发货单数据");
- $after_num = Db::name("order_return")
- ->where(["orderCode" => $orderout['orderCode'], "outCode" => $param['outCode']])
- ->where("status", "not in", [5, 6, 8])
- ->sum("error_num");
- $th_num = Db::name("order_back")
- ->where(["orderCode" => $orderout['orderCode'], "outCode" => $param['outCode'], "is_del" => 0])
- ->where("status", "<", 4)
- ->sum("return_num");
- if ($th_num != 0 || $after_num != 0) return error_show(1005, "存在售后或售后退货未结束流程");
- $oder = Db::name("sale")
- ->where(["orderCode" => $orderout['orderCode'], "is_del" => 0])
- ->findOrEmpty();
- if (empty($oder)) return error_show(1005, "未找到订单数据");
- if ($oder['order_type'] != 1) {
- $wsm = Db::name("warehouse_info")
- ->where(["wsm_code" => $orderout['wsm_code']])
- ->findOrEmpty();
- if (empty($wsm)) return error_show(1005, "未找到仓库数据");
- // $cgder =$wsm['contactor_name'] ??'';
- // $cgderid =$wsm['contactor'] ??0;
- }
- // else{
- // $roleArr=\think\facade\Config::get("app");
- // $kuguan = Db::name("user_role")->where(["roleid"=>$roleArr['wsm_cgder_role'],"is_del"=>0])->column("uid");
- // if(empty($kuguan)){
- // return error_show(1005,"未找到仓库管理员数据");
- // }
- // $userinfo = Db::name("dapart_user")
- // $cgder =$wsm['contactor_name'] ??'';
- // $cgderid =$wsm['contactor'] ??0;
- // }
- if ($oder['order_type'] == 3||$oder['order_type'] == 4) {
- $goon = Db::name("good_zixun")
- ->where(["spuCode" => $oder['good_code'], "is_del" => 0])
- ->findOrEmpty();
- } else {
- $goon = Db::name('good_platform')
- ->alias('a')
- ->field("b.creater,b.createrid,b.supplierNo,b.supplierName")
- ->join('good b', 'b.spuCode=a.spuCode', 'left')
- ->where(['a.skuCode' => $oder['skuCode']])
- ->findOrEmpty();
- }
- // $errorCode = isset($this->post['errorCode']) &&$this->post['errorCode']!=''?trim($this->post['errorCode']) :"";
- // if($param['outCode']==''){
- // return error_show(1004,"参数errorCode 不能为空");
- // }
- $error = Db::name('result_info')
- ->where(["result_code" => $param['errorCode'], "is_del" => 0])
- ->findOrEmpty();
- if (empty($error)) return error_show(1005, "未找到退货原因数据");
- $userCommon = \app\admin\common\User::getIns();
- $supplier = $userCommon->handle('sInfo', ['code' => $goon['supplierNo']]);
- // if (!isset($supplier['code']) || $supplier['code'] != 0) return json_show($supplier['code'], $supplier['message'], $supplier['data']);
- $supplier = $supplier['data'];
- // $names = $userCommon->handle('getCodeAndName', ['code' => [$oder['customer_code'], $oder['supplierNo']]]);
- // $supplier =Db::name("supplier")->where(["code"=>$goon['supplierNo']])->find();
- // if($supplier==false){
- // 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 不能为空");
- // }
- $num = $param['is_receive'] == 1 ? $param['num'] : $orderout['send_num'];
- // if($param['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 不能为空或零");
- // }
- // }
- $thnum = Db::name("order_back")
- ->where(["orderCode" => $orderout['orderCode'], "outCode" => $param['outCode'], "is_del" => 0])
- ->where("status", "=", 4)
- ->sum("return_num");
- if ($num > ($orderout['send_num'] - $thnum)) return error_show(1004, "可用售后数量不足");
- $fininfo =GetFin("admin/orderischeck",["token"=>$this->post['token'],"orderCode"=>$orderout['orderCode']]);
- if(!isset($fininfo['code'])||$fininfo['code']!=0 ){
- return json_show(1005, $fininfo['message']??"结算校验失败");
- }
- // $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 = $this->uid;//isset($user["data"]['id']) ? $user["data"]['id'] : "";
- $ri = $this->uname;//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
- $returnCode = makeNo("RS");
- Db::startTrans();
- try {
- $in = [
- "returnCode" => $returnCode,
- "outCode" => $param['outCode'],
- "orderCode" => $oder['orderCode'],
- "good_code" => $oder['good_code'],
- "good_name" => $oder['good_name'],
- "customer_code" => $oder['customer_code'],
- "customer_name" =>$oder['customerName'],
- "apply_id" => $rm,
- "apply_name" => $ri,
- 'supplierNo' => $goon['supplierNo'],
- 'supplierName' => $goon['supplierName'],
- "cgder" => $wsm['contactor_name'] ?? '',
- "cgderid" => $wsm['contactor'] ?? 0,
- "person" => $supplier['person'] ?? '',
- "person_id" => $supplier['personid'] ?? 0,
- 'total_num' => $orderout['send_num'],
- "error_code" => $param['errorCode'],
- "error_num" => $num,
- "error_img" => is_array($param['img']) ? implode(',', $param['img']) : $param['img'],
- "error_msg" => $error['result'],
- "error_remark" => $param['remark'],
- "is_receive" => $param['is_receive'],
- "remark" => '',
- "except_code" => $param['except_code'],
- "order_type" => $orderout['order_type'],
- 'companyNo' => $oder['supplierNo'],
- 'companyName' => $oder['supplierName'],
- "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(['id' => $this->uid, 'nickname' => $this->uname], $orde, 'SHD', 1, $orde);
- if ($create > 0) {
- //维护台账
- // Db::name('standing_book')
- // ->whereFindInSet('outCode', $param['outCode'])
- // ->update([
- // 'returnCode' => $returnCode,
- // 'updatetime' => date("Y-m-d H:i:s")
- // ]);
- Db::execute("UPDATE `wsm_standing_book` SET `returnCode`=CONCAT(IFNULL(`returnCode`,''),',{$returnCode}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE FIND_IN_SET('{$param['outCode']}',`outCode`)");
- //当状态为1(即待业务审核)时,要将待办数据推给以下角色的用户
- // $user = Db::name('user_role')
- // ->where([
- // ['is_del', '=', 0],
- // ['roleid', 'in', [12, 13, 17, 28]],//12客服负责人,13项目负责人,17平台负责人,28网络负责人
- // ['status', '=', 1],
- // ])->column('uid');
- //筛选符合数据权限的用户
- // $temp = getUserIdsByShare('', $in['apply_id']);
- // $user = array_intersect($user, $temp);
- $process = ["order_code" => $returnCode, "order_id" => $create, "order_status" => $in['status'], "order_type" => 'SHD', "before_status" => 0, 'holder_id' => $in['apply_id']];
- ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $process);
- Db::commit();
- return json_show(0, "售后申请单新建成功", ["returnCode" => $returnCode]);
- }
- Db::rollback();
- return error_show(1005, "售后申请单新建失败");
- } catch (Exception $exception) {
- Db::rollback();
- return json_show(1005, $exception->getMessage());
- }
- }
- //售后申请单列表
- public function list()
- {
- $param = $this->request->only([
- 'page' => 1,
- 'size' => 10,
- 'relaComNo' => '',
- 'returnCode' => '',
- 'outCode' => '',
- 'status' => '',
- 'order_type' => '',
- 'orderCode' => '',
- 'good_code' => '',
- 'good_name' => '',
- 'except_code' => '',
- 'apply_name' => '',
- 'start' => '',
- 'end' => '',
- 'company_name' => '',//部门名称
- 'supplierNo' => '',
- 'customer_code' => '',
- 'companyNo' => '',
- 'order_source' => '',
- ], 'post', 'trim');
- $where = [['a.is_del', "=", 0]];
- if ($param['relaComNo'] !== '') $where[] = ['c.supplierNo', "=", $param['relaComNo']];
- if ($param['returnCode'] !== '') $where[] = ['a.returnCode', "like", "%{$param['returnCode']}%"];
- if ($param['outCode'] !== '') $where[] = ['a.outCode', "like", "%{$param['outCode']}%"];
- if ($param['status'] !== '') $where[] = ['a.status', "=", $param['status']];
- if ($param['order_type'] !== "") $where[] = ['a.order_type', "=", $param['order_type']];
- if ($param['orderCode'] != "") $where[] = ['a.orderCode', "like", "%{$param['orderCode']}%"];
- if ($param['good_code'] != "") $where[] = ['a.good_code', "like", "%{$param['good_code']}%"];
- if ($param['good_name'] != "") $where[] = ['a.good_name', "like", "%{$param['good_name']}%"];
- if ($param['customer_code'] != "") $where[] = ['a.customer_code', "like", "%{$param['customer_code']}%"];
- if ($param['except_code'] != "") $where[] = ['a.except_code', "=", $param['except_code']];
- if ($param['apply_name'] != "") $where[] = ['a.apply_name', "like", "%{$param['apply_name']}%"];
- if ($param['start'] !== "") $where[] = ['a.addtime', ">=", $param['start']];
- if ($param['end'] !== "") $where[] = ['a.addtime', "<=", $param['end']];
- if ($param['order_source'] !== "") $where[] = ['c.order_source', "=", $param['order_source']];
- if ($param['supplierNo'] !== "") $where[] = ['a.supplierNo', "like", '%' . $param['supplierNo'] . '%'];
- if ($param['companyNo'] !== "") $where[] = ['a.companyNo', "like", '%' . $param['companyNo'] . '%'];
- $condition = [];
- //只有level2的账号过滤数据权限
- if ($this->level == 2) {
- $hand = resign_hand_user($this->uid, 0);
- $role = $this->checkDataShare();
- if (!empty($role[DataGroupModel::$type_全部])) {
- $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
- $condition[] = ["a.person_id", "in", $hand];
- $condition[] = ["a.apply_id", "in", $arr];
- $condition[] = ["a.cgderid", "in", $hand];
- //查询所负责的供应商
- $supplierNos = Db::connect('mysql_sys')
- ->name('supplier')
- ->where(['is_del' => 0, 'personid' => $arr])
- ->column('code');
- $condition[] = ["a.supplierNo", "in", $supplierNos];
- }
- }
- //level3账号不允许看到库存品订单
- if ($this->level == 3) $where[] = ['c.is_stock', '<>', 1];
- // $condition .="a.cgderid in {$hand} or a.person_id in {$hand} or a.apply_id in ("
- // .implode(',',$role[DataGroupModel::$type_全部]).")";
- if ($param['company_name'] !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($param['company_name'])];
- $count = Db::name("order_return")
- ->alias("a")
- ->leftJoin("order_returninfo b", "a.returnCode=b.returnCode")
- ->leftJoin("sale c", "c.orderCode=a.orderCode AND c.is_del=0")
- ->where($where)
- ->where(function ($query) use ($condition) {
- $query->whereOr($condition);
- })
- ->count('a.id');
- // $total = ceil($count/$size);
- // $page = $total>=$page ? $page :$total;
- $list = Db::name("order_return")
- ->alias("a")
- ->leftJoin("order_returninfo b", "a.returnCode=b.returnCode")
- ->leftJoin("sale c", "c.orderCode=a.orderCode AND c.is_del=0")
- ->where($where)
- ->where(function ($query) use ($condition) {
- $query->whereOr($condition);
- })
- ->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,c.order_source")
- ->page($param['page'], $param['size'])
- ->order("a.addtime desc")
- ->select()
- ->toArray();
- //申请人及部门
- $all_createrid = array_column($list, 'apply_id');
- $item = get_company_name_by_uid($all_createrid);
- //获取客户信息
- // $all_customer_code = array_column($list, 'customer_code');
- // $userCommon = \app\admin\common\User::getIns();
- // $customer_ = $userCommon->handle('getCodeAndName', ['code' => array_unique(array_merge(array_column($list, 'customer_code'), array_column($list, 'supplierNo')))]);
- //校验是否开通了供应商账号
- $supp_account = checkHasAccountBySupplierNos(array_unique(array_column($list,'supplierNo')));
- $data = [];
- foreach ($list as $value) {
- // $value['customer_name'] = $customer_['data'][$value['customer_code']] ?? '';
- // $value['supplierName'] = $customer_['data'][$value['supplierNo']] ?? '';
- $value['company_name'] = $item[$value['apply_id']] ?? '';
- $value['has_account'] = (int)isset($supp_account[$value['supplierNo']]);
- //是否具有编辑权限
- // $value['is_allow_update'] = 0;
- // if (in_array($this->roleid, [1, 33]) || in_array($value['apply_id'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
- $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 = $this->request->post('returnCode', '', 'trim');//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])
- ->findOrEmpty();
- if (empty($info)) return error_show(1005, "未找到售后数据");
- $orderinfo = Db::name("sale")->where(["orderCode" => $info["orderCode"]])->findOrEmpty();
- $info['origin_price'] = $orderinfo['origin_price'];
- $info['order_type'] = $orderinfo['order_type'];
- $info['order_source'] = $orderinfo['order_source'];
- $info['is_stock'] = $orderinfo['is_stock'];
- // $info['customer_code'] = $orderinfo['customer_code'];
- // $info['companyNo'] = $orderinfo['supplierNo'];
- $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")
- ->field('cat_id,supplierNo')
- ->where(["spuCode" => $orderinfo['good_code'], "is_del" => 0])
- ->findOrEmpty();
- } else {
- $goon = Db::name('good_platform')
- ->alias('a')
- ->field('b.cat_id,b.supplierNo')
- ->join('good b', 'b.spuCode=a.spuCode', 'left')
- ->where(['a.skuCode' => $orderinfo['skuCode']])
- ->findOrEmpty();
- }
- if (empty($goon)) return error_show(1003, "未找到商品数据");
- // $info['supplierNo'] = $goon['supplierNo'];
- $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
- $info['can'] = $int;
- $addcode = '';
- if ($info['addr_code'] != "") {
- $temp=json_decode($info['addr_code'],true);
- if($temp) $addcode = $info['addr_code'];
- else {
- $temp = explode(',',$info['addr_code']);
- $addcode = json_encode(["provice_code" => $temp[0], "city_code" => $temp[1], "area_code" => $temp[2]]);
- }
- // 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'], "is_del" => 0])->find();
- $info['out_num'] = isset($out['send_num']) ? $out['send_num'] : '';
- // $customer = Db::name("customer_info")->where(["companyNo"=>$info['customer_code']])->find();
- $wsmcode = [];
- $info['wsm_supplier'] = '';
- 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,a.wsm_code,a.contactor_name,a.position,a.mobile,a.addrs_code,a.addr,a.companyNo,a.supplierNo")
- ->find();
- }
- // $userCommon = \app\admin\common\User::getIns();
- // $names = $userCommon->handle('getCodeAndName', ['code' => [
- // $wsmcode['supplierNo'] ?? '',
- // $wsmcode['companyNo'] ?? '',
- //// $info['customer_code'],
- //// $info['companyNo'],
- //// $info['supplierNo'],
- // ]]);
- if ($info['return_wsm'] != '') {
- $info['wsm_supplierNo'] = $wsmcode['supplierNo'] ?? "";
- $info['wsm_supplier'] = $wsmcode['supplierName'];//isset($wsmcode['name']) ? $wsmcode['name'] : "";
- $info['wsm_customer_name'] = $wsmcode['companyName'];//isset($customer['company']) ? trim($customer['company']) : '';
- $info['wsm_customer_code'] = $wsmcode['companyNo'] ?? "";//isset($customer['companyNo']) ? trim($customer['companyNo']) : '';
- $info['wsm_code'] = isset($wsmcode['wsm_code']) ? $wsmcode['wsm_code'] : "";
- $info['wsm_name'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
- }
- // $customer = [];
- // if (isset($orderinfo['supplierNo']) && $orderinfo['supplierNo'] != '') {
- // $customer = Db::name("business")->field('id,company,companyNo')->where(["companyNo" => $orderinfo['supplierNo']])->find();
- // }
- // $info['customer_name'] = $names['data'][$info['customer_code']] ?? '';
- // $info['companyName'] = $names['data'][$info['companyNo']] ?? '';
- // $info['supplierName'] = $names['data'][$info['supplierNo']] ?? '';
- //仓库的联系人、职位、电话、省市区和地址
- 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'] : '';//和地址
- // $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'];
- //校验是否开通了供应商账号
- $supp_account = checkHasAccountBySupplierNos([$info['supplierNo']]);
- $info['has_account']=(int)isset($supp_account[$info['supplierNo']]);
- return app_show(0, "获取成功", $info);
- }
- //售后申请单 审核
- //申请单状态:
- //1待业务审核,
- //2待采购审核,
- //3待设置仓库(该节点废除),
- //4待客户退货(已收到货才有),
- //5售后已完成,
- //6业务已驳回,
- //7采购已驳回(该节点废除),
- //8申请已取消,
- //9供应商审核,
- //10业务公司修改待供应商确认
- //11待设置退货工单(已收到货才有),
- //12待库管收货(已收到货才有)
- public function status()
- {
- try {
- $param = $this->request->only([
- 'returnCode',
- 'status',
- 'remark' => '',
- 'wsm_code' => '',
- 'contactor' => '',
- 'mobile' => '',
- 'addr_code' => '',
- 'addr' => '',
- ], 'post', 'trim');
- $val = Validate::rule([
- 'returnCode' => 'require',
- 'status' => 'require|number|in:1,2,4,5,6,9,10,11',
- 'remark' => 'requireIf:status,6|requireIf:status,10',
- // 'contactor|收货人' => 'requireIf:status,4',
- // 'mobile|联系电话' => 'requireIf:status,4',
- // 'addr_code|省市区编码' => 'requireIf:status,4',
- // 'addr|退货地址' => 'requireIf:status,4',
- ]);
- if ($val->check($param) == false) throw new Exception($val->getError());
- // $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(['is_del' => 0, 'returnCode' => $param['returnCode']])
- ->findOrEmpty();
- if (empty($info)) throw new Exception('未找到售后数据');
- if ($info['status'] == 6) throw new Exception('业务已驳回,无法操作');
- if ($info['status'] == 5) throw new Exception('售后已完成,无法操作');
- if ($info['status'] == 8) throw new Exception('申请已取消,无法操作');
- switch ($info['status']) {
- case 1:
- if (in_array($param['status'], [6, 2, 9]) == false) throw new Exception('选项错误');
- if ($info['order_type'] == 1 && $param['status'] != 2) throw new Exception('选项错误');//库存品不允许供应商审核,只允许走2-11-4-12-5流程
- break;
- case 9:
- if ((($info['is_receive'] == 1) && (in_array($param['status'], [2, 4]) == false) || (($info['is_receive'] == 0) && (in_array($param['status'], [2, 5]) == false)))) throw new Exception('选项错误');
- if ($param['status'] == 2 && $param['remark'] == '') throw new Exception('remark不能为空');
- // if (in_array($param['status'], [2, 4, 5]) == false) throw new Exception('选项错误');
- // if ($this->level != 3) throw new Exception('当前状态下只能由供应商账号操作');
- if ($param['status'] == 4) {
- if ($param['contactor'] == '') throw new Exception('收货人不能为空');
- if ($param['mobile'] == '') throw new Exception('联系电话不能为空');
- if ($param['addr_code'] == '') throw new Exception('省市区编码不能为空');
- if ($param['addr'] == '') throw new Exception('退货地址不能为空');
- }
- break;
- case 2:
- if ((($info['is_receive'] == 1) && (in_array($param['status'], [10, 11]) == false) || (($info['is_receive'] == 0) && (in_array($param['status'], [10, 5]) == false)))) throw new Exception('选项错误');
- if ($info['order_type'] == 1 && $param['status'] != 11) throw new Exception('选项错误');//库存品不允许供应商审核,只允许走2-11-4-12-5流程
- break;
- case 10:
- if ((($info['is_receive'] == 1) && (in_array($param['status'], [2, 4]) == false) || (($info['is_receive'] == 0) && (in_array($param['status'], [2, 5]) == false)))) throw new Exception('选项错误');
- if ($param['status'] == 2 && $param['remark'] == '') throw new Exception('remark不能为空');
- if ($param['status'] == 4) {
- if ($param['contactor'] == '') throw new Exception('收货人不能为空');
- if ($param['mobile'] == '') throw new Exception('联系电话不能为空');
- if ($param['addr_code'] == '') throw new Exception('省市区编码不能为空');
- if ($param['addr'] == '') throw new Exception('退货地址不能为空');
- }
- break;
- }
- //获取最新的供应商负责人
- $s_info = \app\admin\common\User::getIns()->handle('sInfo', ['code' => $info['supplierNo']]);
- $info['person_id'] = $s_info['data']['personid'];
- $info['person'] = $s_info['data']['person'];
- //当处于以下节点时,level2账号必须是供应商负责人操作,level3账号不做限制
- if (in_array($info['status'], [9, 10]) && ($this->level == 2) && ($this->uid != $info['person_id'])) return json_show(1004, '您不是供应商负责人,此时无权操作');
- // $param['status'] = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']) :"";
- // if($param['status']===""){
- // return error_show(1005,"参数status 不能为空");
- // }
- // $remark = isset($this->post['remark'])&&$this->post['remark']!=''?trim($this->post['remark']):"";
- if ($param['remark'] != '') $info['remark'] = $param['remark'];
- // if($param['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;
- // }
- // $param['status'] = $info['order_status']==1&&$info['order_type']==1 && $param['status']==1?4:$param['status'];
- Db::startTrans();
- try {
- $date = date('Y-m-d H:i:s');
- $action_log_user = ['id' => $this->uid, 'nickname' => $this->uname];
- //如果是小循环,增加次数
- if ($param['status'] == 10) $info['loop_total'] += 1;//只要走到节点10(业务公司修改,待供应商确认),就增加次数
- //判断 退回供应商 or 退回业务公司
- if ($info['status'] == 2 && $param['status'] == 11) {
- $info['return_tag'] = 2;
- $fininfo =GetFin("admin/orderischeck",["token"=>$this->post['token'],"orderCode"=>$info['orderCode']]);
- if(!isset($fininfo['code'])||$fininfo['code']!=0 ){
- // return json_show(1005, $fininfo['message']??"结算校验失败");
- throw new Exception($fininfo['message']??"结算校验失败");
- }
- //退入次品仓,维护
- $wsm = Db::name('warehouse_info')->where(['is_del' => 0, 'wsm_code' => $param['wsm_code']])->findOrEmpty();
- if (empty($wsm)) throw new Exception('返回仓库不存在');
- if ($wsm['wsm_type'] != 4) throw new Exception('不是次品仓');
- // if ($wsm['wsm_type'] == 4) {
- Db::name('order_returninfo')->insert([
- 'returnCode' => $param['returnCode'],
- 'return_wsm' => $param['wsm_code'],
- 'contactor' => $wsm['contactor_name'],
- 'mobile' => $wsm['mobile'],
- 'addr' => $wsm['addr'],
- 'addr_code' => $wsm['addrs_code'],
- 'post_code' => '',
- 'post_company' => '',
- 'post_fee' => 0,
- 'gys_remark' => '',
- 'addtime' => $date,
- ]);
- // }
- } else{
- $fininfo =GetFin("admin/orderischeck",["token"=>$this->post['token'],"orderCode"=>$info['orderCode'],"isCgd"=>1]);
- if(!isset($fininfo['code'])||$fininfo['code']!=0 ){
- // return json_show(1005, $fininfo['message']??"结算校验失败");
- throw new Exception($fininfo['message']??"结算校验失败");
- }
- $info['return_tag'] = 1;
- }
- $var = $info['status'];
- $info['status'] = $param['status'];
- $info['updatetime'] = $date;
- $up = Db::name("order_return")->save($info);
- if ($up) {
- //售后完成
- if ($param['status'] == 5 && $info['is_receive'] == 0) {
- $orde = Db::name("order_out")
- ->field('id,outCode,status')
- ->where(["outCode" => $info['outCode'], "is_del" => 0])
- ->findOrEmpty();
- if (empty($orde)) throw new Exception('未找到出库单数据');
- $sale = Db::name("sale")
- ->field('id,th_num,th_fee,sale_price,good_code,good_name,cat_id')
- ->where(['is_del' => 0, "orderCode" => $info['orderCode']])
- ->findOrEmpty();
- if (empty($sale)) throw new Exception('未找到销售单数据');
- $od_status = $orde['status'];
- $orde['status'] = 4;
- $orde['updatetime'] = $date;
- $out = Db::name("order_out")->save($orde);
- if ($out == false) throw new Exception("发货单更新失败");
- $order = ["order_code" => $orde['outCode'], "status" => $od_status, "action_remark" => '', "action_type" => "edit"];
- ActionLog::logAdd($action_log_user, $order, "CKD", $orde['status'], $this->post);
- $process = ["order_code" => $orde['outCode'], "order_id" => $orde['id'], "order_status" => $orde['status'], "order_type" => "CKD", "before_status" => $od_status];
- ProcessOrder::AddProcess($action_log_user, $process);
- $sale['th_num'] += $info['error_num'];
- $sale['th_fee'] += round($info['error_num'] * $sale['sale_price'], 2);
- $sale['updatetime'] = $date;
- $sup = Db::name("sale")->save($sale);
- if ($sup == false) throw new Exception("销售单更新失败");
- $data = [
- "orderCode" => $info['orderCode'],
- "th_type" => 2,
- "th_num" => $info['error_num'],
- "th_fee" => round($info['error_num'] * $sale['sale_price'], 2),
- "thCode" => $info['returnCode'],
- "spuCode" => $sale['good_code'],
- "good_name" => $sale['good_name'],
- "cat_id" => $sale['cat_id'],
- "apply_id" => $info['apply_id'],
- "apply_name" => $info['apply_name'],
- "addtime" => $date,
- "status" => 1,
- "is_del" => 0
- ];
- $inse = Db::name("th_data")->insert($data);
- if ($inse == false) throw new Exception('退回单更新失败');
- }
- //维护退货地址的收货信息
- if ($info['is_receive'] == 1 && $param['status'] == 4) {
- $tmp = Db::name('order_returninfo')
- ->field('id')
- ->where('returnCode', $param['returnCode'])
- ->findOrEmpty();
- if (empty($tmp)) {
- //新增
- Db::name('order_returninfo')
- ->insert([
- 'returnCode' => $param['returnCode'],
- 'return_wsm' => $param['wsm_code'],
- 'contactor' => $param['contactor'],
- 'mobile' => $param['mobile'],
- 'addr' => $param['addr'],
- 'addr_code' => $param['addr_code'],
- 'addtime' => $date
- ]);
- } else {
- Db::name('order_returninfo')
- ->where('id', $tmp['id'])
- ->update([
- 'return_wsm' => $param['wsm_code'],
- 'contactor' => $param['contactor'],
- 'mobile' => $param['mobile'],
- 'addr' => $param['addr'],
- 'addr_code' => $param['addr_code'],
- ]);
- }
- }
- $order = ["order_code" => $info['returnCode'], "status" => $var, "action_remark" => '', "action_type" => "edit"];
- ActionLog::logAdd($action_log_user, $order, "SHD", $info['status'], $this->post);
- // switch ($param['status']) {
- // //待采购审核
- // case 2:
- // $process = ["order_code" => $info['returnCode'], "order_id" => $info['id'], "order_status" => $param['status'], "order_type" => "SHD", "before_status" => $var, 'wait_id' => $info['person_id'], 'wait_name' => $info['person'], 'holder_id' => $info['person_id']];
- // break;
- //
- // //待设置仓库
- // case 3:
- // $process = ["order_code" => $info['returnCode'], "order_id" => $info['id'], "order_status" => $param['status'], "order_type" => "SHD", "before_status" => $var, 'wait_id' => $info['cgderid'], 'wait_name' => $info['cgder'], 'holder_id' => $info['cgderid']];
- // break;
- //
- // //待客户退货
- // case 4:
- // $process = ["order_code" => $info['returnCode'], "order_id" => $info['id'], "order_status" => $param['status'], "order_type" => "SHD", "before_status" => $var, 'wait_id' => $info['apply_id'], 'wait_name' => $info['apply_name'], 'holder_id' => $info['apply_id']];
- // break;
- //
- // default:
- // $process = ["order_code" => $info['returnCode'], "order_id" => $info['id'], "order_status" => $param['status'], "order_type" => "SHD", "before_status" => $var, 'holder_id' => $info['apply_id']];
- // }
- // if (in_array($param['status'], [2, 3])) $process = ["order_code" => $info['returnCode'], "order_id" => $info['id'], "order_status" => $param['status'], "order_type" => "SHD", "before_status" => $var, 'wait_id' => $info['cgderid'], 'wait_name' => $info['cgder'],'holder_id'=>$info['cgderid']];
- // elseif ($param['status'] == 4) $process = ["order_code" => $info['returnCode'], "order_id" => $info['id'], "order_status" => $param['status'], "order_type" => "SHD", "before_status" => $var, 'wait_id' => $info['apply_id'], 'wait_name' => $info['apply_name'],'holder_id'=>$info['apply_id']];
- // else $process = ["order_code" => $info['returnCode'], "order_id" => $info['id'], "order_status" => $param['status'], "order_type" => "SHD", "before_status" => $var,'holder_id'=>$info['apply_id']];
- $process = ["order_code" => $info['returnCode'], "order_id" => $info['id'], "order_status" => $param['status'], "order_type" => "SHD", "before_status" => $var, 'wait_id' => $info['person_id'], 'wait_name' => $info['person'], 'holder_id' => $info['person_id']];
- ProcessOrder::AddProcess($action_log_user, $process);
- Db::commit();
- return app_show(0, "更新成功");
- }
- throw new Exception('更新失败');
- } catch (Exception $e) {
- Db::rollback();
- throw new Exception($e->getMessage() . '|' . $e->getFile() . '|' . $e->getLine());
- }
- } catch (Exception $exception) {
- return json_show(1005, $exception->getMessage() . '|' . $exception->getFile() . '|' . $exception->getLine());
- }
- }
- //设置仓库
- 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']) :"";
- $warehouse=[];
- 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;
- if($info['order_type']==1){
- $info['cgder']=$warehouse['contactor_name']??"";
- $info['cgderid']=$warehouse['contactor']??0;
- }
- $info["updatetime"]=date("Y-m-d H:i:s");
- $up =Db::name("order_return")->save($info);
- if($up){
- //修改状态,添加待办
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_code" => $info['returnCode'],//销售单code
- "status" => $old_info_status,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "status"//新建create,编辑edit,更改状态status
- ], "SHD", $info['status'], $info);
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_type" => 'SHD',
- "order_code" => $info['returnCode'],//销售单code
- "order_id" => $info['id'],
- "order_status" => $info['status'],
- "before_status"=>$old_info_status,
- 'holder_id'=>$info['apply_id']
- ]);
- 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(['id'=>$this->uid,'nickname'=>$this->uname],$order,"SHD",$info['status'],$this->post);
- $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>"SHD","before_status"=>$var,'holder_id'=>$info['apply_id']];
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$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(['id'=>$this->uid,'nickname'=>$this->uname],$order,"SHD",$info['status'],$this->post);
- $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>"SHD","before_status"=>$str,'holder_id'=>$info['apply_id']];
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$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'],
- "customer_name"=>$info['customer_name'],
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s"),
- 'supplierNo' => $info['supplierNo'],
- 'supplierName' => $info['supplierName'],
- 'companyNo' => $info['companyNo'],
- 'companyName' => $info['companyName'],
- ];
- $back =Db::name("order_back")->insert($data,true);
- if($back>0){
- //维护台账
- // Db::name('standing_book')
- // ->where('returnCode', $bkcode)
- // ->update([
- // 'thNo' => $data['thNo'],
- // 'updatetime' => date("Y-m-d H:i:s")
- // ]);
- Db::execute("UPDATE `wsm_standing_book` SET `thNo`=CONCAT(IFNULL(`thNo`,''),',{$data['thNo']}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE FIND_IN_SET('{$bkcode}',`returnCode`)");//这里的returnCode可能有多个
- $order = ["order_code"=>$data['thNo'],"status"=>0,"action_remark"=>'',"action_type"=>"create"];
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$order,"CKTHD", 0,$data);
- $process=["order_code"=>$data['thNo'],"order_id"=>$back,"order_status"=>0,"order_type"=>"CKTHD","before_status"=>0];
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$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(['id'=>$this->uid,'nickname'=>$this->uname],$order,"SHD", $info['status'],$this->post);
- $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"SHD","before_status"=>$stat,'holder_id'=>$info['apply_id']];
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$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'],"is_del"=>0])->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()
- {
- $param = $this->request->only(['returnCode', 'company', 'post_code', 'post_fee'], 'post', 'trim');
- $val = Validate::rule([
- 'returnCode|售后申请单编号' => 'require',
- 'company|快递公司名' => 'require|max:255',
- 'post_code|快递单号' => 'require|max:255',
- 'post_fee|快递费用' => 'require|float',
- ]);
- if ($val->check($param) == false) return json_show(1004, $val->getError());
- $bkcode = $param['returnCode'];
- $company = $param['company'];
- $post_code = $param['post_code'];
- $post_fee = $param['post_fee'];
- $info = Db::name("order_return")
- ->where(['is_del' => 0, 'returnCode' => $bkcode])
- ->findOrEmpty();
- if (empty($info)) return error_show(1005, "未找到售后数据");
- if (($info['is_receive'] != 1 || $info['status'] != 4)) return error_show(1005, "售后单流程状态有误");
- $out = Db::name("order_out")
- ->where(["outCode" => $info["outCode"], "is_del" => 0])
- ->findOrEmpty();
- if (empty($out)) 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不能为空");
- // }
- // }
- $sale = Db::name('sale')
- ->where(['orderCode' => $info['orderCode'], "is_del" => 0])
- ->findOrEmpty();
- if (empty($sale)) return error_show(1004, "未找到销售单数据");
- Db::startTrans();
- try {
- $returninfo = Db::name("order_returninfo")->where(["returnCode" => $bkcode])->findOrEmpty();
- if (empty($returninfo)) {
- //查询次品仓的信息
- $wsm = Db::name('warehouse_info')
- ->where(['is_del' => 0, 'companyNo' => $sale['supplierNo'], 'status' => 1, 'wsm_type' => 4])
- ->findOrEmpty();
- $returninfo = [
- "returnCode" => $bkcode,
- "return_wsm" => $wsm['wsm_code'] ?? '',
- "contactor" => $wsm['contactor_name'] ?? '',
- "mobile" => $wsm['mobile'] ?? '',
- "addr" => $wsm['addr'] ?? '',
- "addr_code" => $wsm['addrs_code'] ?? '',
- "post_code" => $post_code,
- "post_company" => $company,
- "post_fee" => $post_fee,
- "gys_remark" => "",
- "addtime" => date("Y-m-d H:i:s")
- ];
- $up = Db::name("order_returninfo")->insert($returninfo);
- } else {
- $up = Db::name("order_returninfo")
- ->where(["returnCode" => $bkcode])
- ->update([
- 'post_fee' => $post_fee,
- 'post_company' => $company,
- 'post_code' => $post_code,
- ]);
- }
- if ($up) {
- //查看是否有退货工单设置信息
- $temp = Db::name('order_return_prepare')
- ->field('id')
- ->where(['is_del' => 0, 'returnCode' => $bkcode,'status'=>1])
- ->findOrEmpty();
- if (empty($temp)) $info['status'] = 5;//没有,更新到status5,售后申请已结束
- else $info['status'] = 12;//存在,要更新到status12(待库管收货)
- $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(['id' => $this->uid, 'nickname' => $this->uname], [
- "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(['id' => $this->uid, 'nickname' => $this->uname], [
- "order_type" => 'SHD',
- "order_code" => $info['returnCode'],//销售单code
- "order_id" => $info['id'],
- "order_status" => $info['status'],
- "before_status" => $old_info_status,
- 'holder_id' => $info['apply_id']
- ]);
- //如果售后已完成,维护销售单、发货单和采购单
- if ($info['status'] == 5) {
- $sale['th_num'] += $info['error_num'];
- // if ($sale['th_num'] == $sale['send_num'] && $sale['wsend_num'] == 0) $sale['status'] = 3;
- if ($sale['th_num'] == $sale['good_num']) $sale['status'] = 3;
- $sale['th_fee'] += round($info['error_num'] * $sale['sale_price'], 2);
- $sale['updatetime'] = date("Y-m-d H:i:s");
- Db::name("sale")->save($sale);
- if ($info['error_num'] >= $out['send_num']) $out['status'] = 4;
- $out['send_num'] -= $info['error_num'];
- $out['error_num'] += $info['error_num'];
- $out['updatetime'] = date("Y-m-d H:i:s");
- $upout = Db::name("order_out")->save($out);
- if ($upout == false) throw new Exception('出库单数据更新失败');
- //发货工单,有可能会有多个,要按照顺序扣减发货数
- // Db::name('order_out_child')
- // ->data(['updatetime' => date("Y-m-d H:i:s")])
- // ->where(['is_del' => 0, 'outCode' => $info["outCode"]])
- // ->dec('num', $info['error_num'])
- // ->update();
- $error_num = $info['error_num'];
- $tmp_ooc = Db::name('order_out_child')
- ->where(['is_del' => 0, 'outCode' => $info["outCode"]])
- ->field('id,num')
- ->select()
- ->toArray();
- foreach ($tmp_ooc as $tmp) {
- if ($tmp['num'] >= $error_num) {
- Db::name('order_out_child')
- ->data(['updatetime' => date("Y-m-d H:i:s")])
- ->where(['is_del' => 0, 'id' => $tmp["id"]])
- ->dec('num', $error_num)
- ->update();
- $error_num = 0;
- } else {
- Db::name('order_out_child')
- ->where(['is_del' => 0, 'id' => $tmp["id"]])
- ->update(['num' => 0, 'updatetime' => date("Y-m-d H:i:s")]);
- $error_num -= $tmp['num'];
- }
- if ($error_num == 0) break;
- }
- //如果供应商承担,维护采购单
- if ($info['return_tag'] == 1) {
- $cgd_info = Db::name('order_num')
- ->alias('a')
- ->field('a.id,b.id cgd_id,b.good_price')
- ->leftJoin('purchease_order b','b.cgdNo=a.cgdNo')
- ->where(['a.orderCode' => $info['orderCode']])
- ->findOrEmpty();
- if (!empty($cgd_info)) {
- Db::name('purchease_order')
- ->where(['is_del' => 0, 'id' => $cgd_info['cgd_id']])
- ->inc('th_num', $info['error_num'])
- ->inc('th_fee', round($cgd_info['good_price'] * $info['error_num'], 2))
- ->update();
- }
- }
- }
- Db::commit();
- return json_show(0, '退货成功');
- } else throw new Exception('修改售后申请单状态失败');
- } else throw new Exception('退货失败');
- //售后退货单数据
- // $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"],
- // "total_fee" => round($sale['sale_price'] * $info["error_num"], 2),
- // "good_price" => $sale['sale_price'],
- // "platform_id" => $sale['platform_id'],
- // "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'],
- // "cgder" => $info['cgder'],
- // "cgderid" => $info['cgderid'],
- // "person" => $info['person'],
- // "person_id" => $info['person_id'],
- // "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"],
- // "customer_name" => $info["customer_name"],
- // "status" => $info['return_tag'] == 1 ? 4 : 1, //return_tag==1退回供应商,status:4完成退货,1待验收
- // "addtime" => date("Y-m-d H:i:s"),
- // "updatetime" => date("Y-m-d H:i:s"),
- // 'supplierNo' => $info['supplierNo'],
- // 'supplierName' => $info['supplierName'],
- // 'companyNo' => $info['companyNo'],
- // 'companyName' => $info['companyName'],
- // ];
- // $sav = Db::name("order_back")->insert($thdata, true);
- // if ($sav) {
- //
- // //修改状态,添加待办
- // ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
- // "order_code" => $thdata['thNo'],//销售单code
- // "status" => $thdata['status'],//这里的status是之前的值
- // "action_remark" => '',//备注
- // "action_type" => "create"//新建create,编辑edit,更改状态status
- // ], "CKTHD", $thdata['status'], $thdata);
- //
- //
- // //售后退货单,供应商不同意退货,退回到业务公司仓的时候,要把待办数据推给供应商负责人和库管人员
- // if ($thdata['status'] == 1) {
- //
- // //31库管人员,41库管-张凯旋
- // $uids = Db::name('user_role')
- // ->where(['is_del' => 0, 'roleid' => [31, 41], 'status' => 1])
- // ->column('uid');
- //
- // ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
- // "order_type" => 'CKTHD',
- // "order_code" => $thdata['thNo'],//销售单code
- // "order_id" => $sav,
- // "order_status" => $thdata['status'],
- // "before_status" => 0,
- // 'handle_user_list' => implode(',', array_merge($uids, [$sale['cgderid']])),
- // ]);
- // } else {
- // ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
- // "order_type" => 'CKTHD',
- // "order_code" => $thdata['thNo'],//销售单code
- // "order_id" => $sav,
- // "order_status" => $thdata['status'],
- // "before_status" => 0
- // ]);
- // }
- //
- //
- // //维护台账记录
- //// Db::name('standing_book')
- //// ->where(['returnCode' => $bkcode])
- //// ->update([
- //// 'thNo' => $thNo,
- //// 'updatetime' => date("Y-m-d H:i:s")
- //// ]);
- // Db::execute("UPDATE `wsm_standing_book` SET `thNo`=CONCAT(IFNULL(`thNo`,''),',{$thNo}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE FIND_IN_SET('{$bkcode}',`returnCode`)");//这里的returnCode可能有多个
- // // 库存品退货 不退商品 需要计算成本
- //// if($info['except_code']==1){
- //// $sabebn =Db::name("sale_info")->where(["orderCode"=>$info['orderCode']])->select()->toArray();
- //// if(!empty($sabebn)){
- //// $total_num =$info["error_num"];
- //// foreach ($sabebn as $ve){
- ////
- //// $tempnum=0;
- //// if ($total_num==0) break;
- //// if($total_num>=$ve['num']){
- //// $tempnum = $ve['num'];
- //// $total_num-=$ve['num'];
- //// $ve['num']=0;
- //// }else{
- //// $tempnum = $total_num;
- //// $ve['num']-=$total_num;
- //// $total_num=0;
- //// }
- //// $bnin=GoodStockInfo::ReturnAdd($stockid,$ve['bnCode'],$tempnum,$ve['stockid']);
- //// if($bnin==false){
- //// Db::rollback();
- //// return error_show(1005, '可售商品Bn库存数入库失败');
- //// }
- //// $up=Db::name("sale_info")->save($ve);
- //// if($up==false){
- //// Db::rollback();
- //// return error_show(1005, '可售商品Bn库存数入库失败');
- //// }
- //// $bnin=GoodStockInfo::ReturnBn($info['returnCode'],$ve['id'],$tempnum);
- //// if($bnin==false){
- //// Db::rollback();
- //// return error_show(1005, '可售商品Bn库存数入库失败');
- //// }
- //// }
- //// }
- //// }else{
- ////
- //// }
- //
- // //退回供应商的时候,处理库存
- // if ($info['return_tag'] == 1) {
- // $sale['th_num'] += $info['error_num'];
- // if ($sale['th_num'] == $sale['send_num'] && $sale['wsend_num'] == 0) {
- // $sale['status'] = 3;
- // }
- // $sale['th_fee'] += round($info['error_num'] * $sale['sale_price'], 2);
- // $sale['updatetime'] = date("Y-m-d H:i:s");
- // $uap = Db::name("sale")->save($sale);
- //
- // if ($uap == false) throw new Exception('销售单订单更新失败');
- //// if($uap==false){
- //// Db::rollback();
- //// return error_show(1005,'销售单订单更新失败');
- //// }
- // if ($sale['is_stock'] == 0) {
- // $ordernum = Db::name("order_num")
- // ->where(['orderCode' => $info['orderCode']])
- // ->find();
- // if ($ordernum == false) throw new Exception('未找到关联采购单1');
- //// if($ordernum==false){
- //// Db::rollback();
- //// return error_show(1005,'未找到关联采购单');
- //// }
- // $ordernum['send_num'] -= $info['error_num'];
- // $orderup = Db::name("order_num")->save($ordernum);
- //
- // if ($orderup == false) throw new Exception('关联数据更新失败');
- //
- //// if($orderup==false){
- //// Db::rollback();
- //// return error_show(1005,'关联数据更新失败');
- //// }
- // $cgd = Db::name("purchease_order")
- // ->where(["cgdNo" => $ordernum['cgdNo'], "is_del" => 0])
- // ->findOrEmpty();
- // if (empty($cgd)) throw new Exception('未找到采购单数据');
- //// if($cgd==false){
- //// Db::rollback();
- //// return error_show(1005,'未找到采购单数据');
- //// }
- // $cgd['th_num'] += $info['error_num'];
- // if ($cgd['th_num'] == $cgd['send_num'] && $cgd['wsend_num'] == 0) {
- // $cgd['status'] = 4;
- // }
- // $cgd['th_fee'] += round($info['error_num'] * $cgd['good_price'], 2);
- // $cgd['updatetime'] = date("Y-m-d H:i:s");
- // $cgdup = Db::name("purchease_order")->save($cgd);
- //
- // if ($cgdup == false) throw new Exception('采购单数据更新失败');
- //// if($cgdup==false){
- //// Db::rollback();
- //// return error_show(1005,'采购单数据更新失败');
- //// }
- // }
- //
- // $sabebn = Db::name("sale_info")
- // ->where([["orderCode", "=", $info['orderCode']], ["num", ">", 0]])
- // ->select()
- // ->toArray();
- // if (!empty($sabebn)) {
- // $total_num = $info["error_num"];
- // foreach ($sabebn as $ve) {
- // $tempnum = 0;
- // if ($total_num == 0) break;
- // if ($total_num >= $ve['num']) {
- // $tempnum = $ve['num'];
- // $total_num -= $ve['num'];
- // $ve['th_num'] += $ve['num'];
- // $ve['num'] = 0;
- // } else {
- // $tempnum = $total_num;
- // $ve['num'] -= $total_num;
- // $ve['th_num'] += $total_num;
- // $total_num = 0;
- // }
- //
- // if ($info['except_code'] == 1) {
- //// if($sale['is_stock']==1){
- //// $bnin=GoodStockInfo::AddBn($ve['stockid'],$ve['bnCode'],$tempnum);
- //// if($bnin==false){
- //// Db::rollback();
- //// return error_show(1005, '可售商品Bn库存数入库失败');
- //// }
- //// }
- // $up = Db::name("sale_info")->save($ve);
- //
- // if ($up == false) throw new Exception('可售商品Bn库存数入库失败');
- //// if($up==false){
- //// Db::rollback();
- //// return error_show(1005, '可售商品Bn库存数入库失败');
- //// }
- // }
- //
- // $bnin = GoodStockInfo::ReturnBn($info['returnCode'], $ve['id'], $tempnum);
- // if ($bnin == false) throw new Exception('可售商品Bn库存数入库失败');
- //// if($bnin==false){
- //// Db::rollback();
- //// return error_show(1005, '可售商品Bn库存数入库失败');
- //// }
- // }
- // }
- // if ($info['error_num'] >= $out['send_num']) {
- // $out['status'] = 4;
- // $out['updatetime'] = date("Y-m-d H:i:s");
- // $upout = Db::name("order_out")->save($out);
- // if ($upout == false) throw new Exception('出库单数据更新失败');
- //// if($upout==false){
- //// Db::rollback();
- //// return error_show(1005,'出库单数据更新失败');
- //// }
- // }
- // $data = [
- // "orderCode" => $info['orderCode'],
- // "th_type" => 3,
- // "th_num" => $info['error_num'],
- // "th_fee" => round($sale['sale_price'] * $info["error_num"], 2),
- // "thCode" => $thNo,
- // "spuCode" => $sale['good_code'],
- // "good_name" => $sale['good_name'],
- // "cat_id" => $sale['cat_id'],
- // "apply_id" => $info['apply_id'],
- // "apply_name" => $info['apply_name'],
- // "addtime" => date("Y-m-d H:i:s"),
- // "status" => 1,
- // "is_del" => 0
- // ];
- // $inse = Db::name("th_data")->insert($data);
- // if ($inse == false) throw new Exception('退货单创建失败');
- //
- //
- //// if($inse==false){
- //// Db::rollback();
- //// return error_show(1004,"退货单更新失败");
- //// }
- //
- // }
- //
- // Db::commit();
- // return app_show(0, "退货单新建成功", ["thNo" => $thNo]);
- // }
- // }
- // }
- // Db::commit();
- // return json_show(0, '退货成功');
- } catch (Exception $e) {
- Db::rollback();
- return json_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,apply_id')
- ->where([
- ['returnCode', '=', $data['returnCode']],
- ['is_del', '=', 0]
- ])->findOrEmpty();
- if (empty($rs)) throw new Exception('该售后单记录不存在');
- if (in_array($rs['status'], [4, 12, 5, 8])) 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(['id' => $this->uid, 'nickname' => $this->uname], ["order_code" => $data['returnCode'], "status" => $rs['status'], "action_remark" => '', "action_type" => "delete"], 'SHD', 8, $this->post);
- ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], ["order_code" => $data['returnCode'], "order_id" => $rs['id'], "order_status" => 8, "order_type" => 'SHD', "before_status" => $rs['status'], 'holder_id' => $rs['apply_id']]);
- Db::name('order_return_prepare')
- ->where(['is_del' => 0, 'returnCode' => $data['returnCode'], 'status' => 1])
- ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s')]);
- //提交
- Db::commit();
- return app_show(0, "取消成功");
- } catch (\Exception $e) {
- Db::rollback();
- return error_show(1004, $e->getMessage());
- }
- }
- //根据审核完成的售后申请单,创建新的销售单和采购单
- public function createSaleAndCgdByAfter()
- {
- $param = $this->request->only(['token', 'returnCode'], 'post', 'trim');
- $val = Validate::rule(['token' => 'require', 'returnCode|售后申请单编号' => 'require']);
- if (!$val->check($param)) return error_show(1005, $val->getError());
- //查询售后申请单详情
- $info = Db::name('order_return')
- ->where('returnCode', $param['returnCode'])
- ->where('is_del', 0)
- ->find();
- if (empty($info)) return error_show(1005, '该售后申请单不存在');
- if ($info['status'] != 5) return error_show(1005, '该售后申请单尚未审核完成');
- if ($info['is_reissue'] == 1) return error_show(1005, '该售后申请单已完成补发,无法重复进行');
- $apply_id = GetUserInfo($param['token']);
- if (empty($apply_id) || $apply_id['code'] != 0) return error_show(1002, "申请人数据不存在");
- $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
- //原本销售单信息
- $old_sale = Db::name('sale')->where(['is_del' => 0, 'orderCode' => $info['orderCode']])->find();
- if (empty($old_sale)) return error_show(1005, '没有对应的销售单信息');
- //发货单信息
- $old_out = Db::name('order_out')->where(['is_del' => 0, 'orderCode' => $info['orderCode'], 'outCode' => $info['outCode']])->find();
- if (empty($old_out)) return error_show(1005, '没有对应的发货单信息');
- //根据是否咨询类商品,分别处理
- if ($info['order_type'] == 3) return $this->createSaleZixun($info['id'], $info['good_code'], $info, $old_sale, $rm, $ri, $old_out['addrid'], $param['token']);
- else return $this->createSaleNotZixun($info['id'], $info['good_code'], $info, $old_sale, $rm, $ri, $old_out, $param['token']);
- }
- /**
- * 咨询类商品处理
- * @param int $orid 对应售后记录的id
- * @param string $spuCode 商品的spuCode
- * @param array $info 售后申请单的详情
- * @param array $old_sale 原始销售订单
- * @param int $rm 操作人id
- * @param string $ri 操作人名称
- * @param int $addrid 原始发货单的地址id
- * @param string $token 当前用户的token
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- private function createSaleZixun(int $orid = 0, string $spuCode = '', array $info = [], array $old_sale = [], int $rm = 0, string $ri = '', int $addrid = 0, string $token = '')
- {
- $zxinfo = Db::name("consult_bids")->where(["bidNo" => $old_sale['zxNo'], "is_del" => 0])->find();
- if ($zxinfo == false) return error_show(1005, '未找到咨询单商品信息');
- $good_num = $info['error_num'];
- $sale_price = 0;
- $orderCode = makeNo("QR");
- $skuCode = "";
- //原有采购单信息
- $old_cgd = Db::name('order_num')
- ->alias('on')
- ->field('on.id onid,po.*')
- ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
- ->where('on.orderCode', $old_sale['orderCode'])
- ->find();
- $cgd = array_merge($old_cgd, [
- 'id' => null,
- // "supplierNo"=>$zxinfo['supplierNo'],
- // "companyNo"=>$zxorder['companyNo'],
- "spuCode" => $spuCode,
- "skuCode" => $skuCode,
- "orderCode" => $orderCode,
- // "good_name"=>$zxinfo['good_name'],
- "sale_price" => $old_cgd['good_price'],//采购单价格不为0,取原采购单的价格
- "total_fee" => round($old_cgd['good_price'] * $good_num, 2),
- // "pakge_fee"=>$zxinfo['pakge_fee'],
- // "cert_fee"=>$zxinfo['cert_fee'],
- // "open_fee"=>$zxinfo['open_fee'],
- 'cost_fee' => $old_cgd['teach_fee'],
- // $old_sale['cost_fee']=$old_sale['teach_fee'];
- // "mark_fee"=>$zxinfo['mark_fee'],
- // "demo_fee"=>$zxinfo['demo_fee'],
- // "nake_fee"=>$zxinfo['nake_fee'],
- // "delivery_fee"=>$zxinfo['delivery_fee'],
- "good_num" => $good_num,
- "createrid" => $rm,
- "creater" => $ri,
- "good_type" => 1,
- // "weight"=>$zxinfo['good_weight'],
- // "gold_price"=>$zxinfo['gold_price'],
- // "is_diff"=>$zxinfo['is_diff'],
- "order_type" => 3,//咨询商品
- "order_source" => 6,//6售后补换货
- // 'send_way'=>$zxinfo['send_way']
- 'token' => $token,
- 'good_createrid' => $zxinfo['createrid'],
- 'good_creater' => $zxinfo['creater'],//商品创建人
- ]);
- // $token=isset($this->post['token'])&&$this->post['token']!=""? trim($this->post['token']):"";
- // if($token==""){
- // return error_show(102, "参数token不能为空");
- // }
- // $apply_id = GetUserInfo($token);
- // if (empty($apply_id) || $apply_id['code'] != 0) {
- // return error_show(102, "申请人数据不存在");
- // }
- // $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- // $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
- // $va = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
- // $send_num=0;
- // if($sendtype==1){
- // if ($va == "") {
- // return error_show(1002, "参数order_addr不能为空");
- // }
- // $send_num = array_sum(array_column($va,"receipt_quantity"));
- // }
- // if($good_num<$send_num){
- // return error_show(1002, "发货数量不能超过购买数量");
- // }
- // $arrtime=isset($this->post['arrtime'])&&$this->post['arrtime']!="" ?$this->post['arrtime']:"";
- // if($arrtime==""){
- // return error_show(1002, "参数arrtime不能为空");
- // }
- //新加字段
- // $platform_order=isset($this->post['platform_order'])&&$this->post['platform_order']!="" ?$this->post['platform_order']:"";
- // $workNo=isset($this->post['workNo'])&&$this->post['workNo']!="" ?$this->post['workNo']:"";
- // $proof_type = isset($this->post['proof_type']) && $this->post['proof_type'] != "" ? intval($this->post['proof_type']) : 0;
- // $proof_url = isset($this->post['proof_url']) && $this->post['proof_url'] != "" ? trim($this->post['proof_url']) : '';
- Db::startTrans();
- try {
- // $zx =Db::name("consult_info")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->lock(true)->find();
- // if($zx==false){
- // Db::rollback();
- // return error_show(1003,"未找到咨询单信息");
- // }
- // $supplier_temp_info = Db::name('supplier')
- // ->field('id,person,personid')
- // ->where('code',$old_cgd['supplierNo'])
- // ->findOrEmpty();
- $user= \app\admin\common\User::getIns();
- $supplier_temp_info =$user->handle("sInfo",["code"=>$old_cgd['supplierNo']]);
- $data = array_merge($old_sale, [
- 'id' => null,
- "orderCode" => $orderCode,
- "good_code" => $spuCode,
- // "skuCode"=>$skuCode,
- // "customer_code"=>$zxorder['khNo'],
- // "good_name"=>isset($zxinfo['good_name'])&&$zxinfo['good_name']!==''?$zxinfo['good_name']:'',
- "good_num" => $good_num,
- // "cat_id"=>$zxinfo['cat_id'],
- "apply_id" => $rm,
- "apply_name" => $ri,
- // "origin_price"=>$zxinfo['total_fee'],
- // "sale_price" => $old_sale['sale_price'],//取原价格
- // "post_fee"=>0,
- "status" => 0,
- "send_status" => 0,
- "th_num" => 0,
- "th_fee" => 0,//退货金额为0
- "send_num" => 0,
- "wsend_num" => $good_num,
- // "send_status"=>1,
- "good_type" => 1,
- // "send_type"=>$sendtype,
- // "supplierNo"=>$zxorder['companyNo'],
- "is_del" => 0,
- // "zxNo"=>$bidNo,
- // "platform_order"=>$platform_order,
- // "platform_id"=> $zxorder['platform_code'],
- "remark" => $old_sale['orderCode'],
- // "arrive_time"=>$arrtime,
- // "is_stock"=>0,
- // "is_activity"=>0,
- // "proof_id"=>0,
- "order_type" => 3,
- "order_source" => 6,//6售后补换货
- // 'good_weight'=>$zxinfo['good_weight'],
- // 'gold_price'=>$zxinfo['gold_price'],
- // 'cost_price'=>$zxinfo['sale_cost_fee'],
- // 'diff_weight'=>0,
- // 'diff_fee'=>0,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s"),
- 'returnCode' => $info['returnCode'],
- // 'total_price' => round($sale_price * $good_num, 2),
- // 'workNo'=>$workNo,
- 'cgderid' => $supplier_temp_info['data']['personid']??0,
- 'cgder' => $supplier_temp_info['data']['person']??"",//采购员(供应商负责人)
- 'good_createrid' => $zxinfo['createrid'],
- 'good_creater' => $zxinfo['creater'],//商品创建人
- ]);
- $datainfo = Db::name('sale')->insertGetId($data);
- if ($datainfo > 0) {
- $standing_book_data = [
- 'sale_id' => $datainfo,
- 'infoNo' => $zxinfo['infoNo'],
- 'updatetime' => date('Y-m-d H:i:s')
- ];
- //修改状态,添加待办
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_code" => $orderCode,//销售单code
- "status" => 0,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "create"//新建create,编辑edit,更改状态status
- ], "XSQRD", $data['status'], $data);
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_type" => 'XSQRD',
- "order_code" => $orderCode,//销售单code
- "order_id" => $datainfo,
- "order_status" => $data['status'],
- "before_status" => 0,
- 'holder_id' => $data['apply_id']
- ]);
- // $old_zx_status = $zx['status'];
- // $zx['status']=5;
- // $zx['updatetime']=date("Y-m-d H:i:s");
- // $sa=Db::name("consult_info")->save($zx);
- // if($sa==false){
- // Db::rollback();
- // return error_show(1002,"咨询单修改失败");
- // }else{
- // //修改状态,添加待办
- // ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
- // "order_code" => $zx['infoNo'],//咨询单详情编号
- // "status" => $old_zx_status,//这里的status是之前的值
- // "action_remark" => '',//备注
- // "action_type" => "status"//新建create,编辑edit,更改状态status
- // ], "ZXD", 5, $zx);
- //
- // }
- $this->createCgd($cgd, $standing_book_data);
- // if($bol==false){
- // Db::rollback();
- // return error_show(1002,"咨询订单创建失败");
- // }
- // $limt=[
- // "spuCode"=>$zxinfo['spuCode'],
- // "good_name"=>$zxinfo['good_name'],
- // "brand_id"=>$zxinfo['brand_id'],
- // "good_unit"=>$zxinfo['unit_id'],
- // "cat_id"=>$zxinfo['cat_id'],
- // "good_type"=>0,
- // "moq"=>1,
- // "customized"=>$zxinfo['work_day'],
- // "tax"=>$zxinfo['tax'],
- // "supplierNo"=>$zxinfo["supplierNo"],
- // "is_auth"=>0,
- // "craft_desc"=>$zxinfo['good_name'],
- // "good_remark"=>"",
- // "platform_id"=>$zxorder['platform_id'],
- // "good_img"=>$zxinfo['good_img'],
- // "good_thumb_img"=>"",
- // "good_info_img"=>"",
- // "specinfo"=>$zxinfo['specinfo'],
- // "work_day"=>$zxinfo['work_day'],
- // "noble_metal"=>$zxinfo['metal_id'],
- // "is_gold_price"=>$zxinfo['is_gold_price'],
- // "config"=>$zxinfo['config'],
- // "other_config"=>$zxinfo['other_config'],
- // "weight"=>$zxinfo['weight'],
- // "good_weight"=>$zxinfo['good_weight'],
- // "is_diff"=>$zxinfo['is_diff'],
- // "supply_area"=>$zxinfo['supply_area'],
- // "pay_way"=>$zxinfo['pay_way'],
- // "send_way"=>$zxinfo['send_way'],
- // "companyNo"=>$zxorder['companyNo'],
- // "status"=>1,
- // "is_del"=>0,
- // "createrid"=>$zxinfo['createrid'],
- // "creater"=>$zxinfo['creater'],
- // "addtime"=>date("Y-m-d H:i:s"),
- // "updatetime"=>date("Y-m-d H:i:s"),
- // 'proof_type' => $proof_type,//凭证类型
- // 'proof_url' => $proof_url,//凭证文件
- // ];
- // $good = Db::name("good_zixun")->insert($limt);
- // if(!$good){
- // Db::rollback();
- // return error_show(1006,"咨询商品录入失败");
- // }
- // if(!empty($va)){
- $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])->find();
- if (empty($order)) throw new Exception('采购单关联数据未找到');
- // foreach ($va as $value){
- // $temp=[];
- // $addrs=[];
- // if($value['addr_code']!==''&&is_array($value['addr_code'])&&!empty($value['addr_code'])){
- // $addrs['provice_code'] = $value['addr_code'][0];
- // $addrs['city_code'] = $value['addr_code'][1];
- // $addrs['area_code'] = $value['addr_code'][2];
- // $addr = json_encode($addrs);
- // }else{
- // $addr = isset($value['addr_code'])?$value['addr_code']:'';
- // }
- // $temp['orderCode']=$orderCode;
- // $temp['contactor']=$value['contactor'];
- // $temp['mobile'] = $value['mobile'];
- // $temp['addr'] = $value['addr'];
- // $temp['addr_code']=$addr;
- // $temp['customer_code'] =$zxorder['khNo'];
- // $temp['receipt_quantity']=$value['receipt_quantity'];
- // $temp['post_fee'] =0;
- // $temp['is_del'] =0;
- // $temp['addtime'] =date("Y-m-d H:i:s");
- // $temp['updatetime'] =date("Y-m-d H:i:s");
- // $temp['arrive_time']=$arrtime;
- $old_out_addr_info = Db::name('order_out')
- ->alias('oo')
- ->field('oo.id,oa.addr,oa.addr_code,oa.contactor,oa.mobile,oa.customer_code,oa.post_fee,oa.arrive_time')
- ->leftJoin('order_addr oa', 'oa.id=oo.addrid')
- ->where(['oo.outCode' => $info['outCode'], 'oo.orderCode' => $info['orderCode']])
- ->find();
- if (empty($old_out_addr_info)) throw new Exception('发货单对应的地址信息查不到');
- $temp = [
- 'orderCode' => $orderCode,
- 'addr' => $old_out_addr_info['addr'],
- 'addr_code' => $old_out_addr_info['addr_code'],
- 'contactor' => $old_out_addr_info['contactor'],
- 'mobile' => $old_out_addr_info['mobile'],
- 'customer_code' => $old_out_addr_info['customer_code'],
- 'receipt_quantity' => $good_num,
- 'arrive_time' => $old_out_addr_info['arrive_time'],
- 'addtime' => date("Y-m-d H:i:s"),
- 'updatetime' => date("Y-m-d H:i:s"),
- // ''=>'',
- ];
- $addrid = Db::name('order_addr')->insertGetId($temp);
- // if($vmp>0){
- $outCode = makeNo("DF");
- $out = [
- "orderCode" => $orderCode,
- "outCode" => $outCode,
- "apply_id" => $rm,
- "apply_name" => $ri,
- 'addrid' => $addrid,
- "post_name" => "",
- "post_code" => "",
- "post_fee" => 0,
- "sendtime" => date("Y-m-d H:i:s"),
- "send_num" => $good_num,
- "check_num" => 0,
- "error_num" => 0,
- "wsm_code" => "",
- "order_type" => 3,
- "status" => 0,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $ou = Db::name("order_out")->insert($out);
- if ($ou == false) throw new Exception('发货地址添加创建失败');
- else {
- //修改状态,添加待办
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_code" => $outCode,//出库单号
- "status" => 0,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "create"//新建create,编辑edit,更改状态status
- ], "CKD", 0, $out);
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_type" => 'CKD',
- "order_code" => $outCode,//出库单号
- "order_id" => Db::name("order_out")->getLastInsID(),
- "order_status" => 0,
- "before_status" => 0,
- 'holder_id' => $out['apply_id']
- ]);
- //将发货编号添加到台账中
- $standing_book_data['outCode'][] = $outCode;
- }
- $order['send_num'] += $good_num;
- $order['wsend_num'] -= $good_num;
- if ($order['wsend_num'] < 0) throw new Exception('发货数量已超出总数');
- $ups = Db::name("order_num")->save($order);
- if ($ups) {
- $sen = Db::name("order_send")->save([
- "cgdNo" => $order['cgdNo'],
- "outCode" => $outCode,
- "send_num" => $good_num,
- "status" => 1,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ]);
- if ($sen == false) throw new Exception('发货地址添加创建失败');
- }
- // }else{
- // Db::rollback();
- // return error_show(1002,"发货地址添加创建失败");
- // }
- // }
- //处理台账
- if (isset($standing_book_data['outCode'])) {
- Db::execute("UPDATE `wsm_standing_book` SET `outCode`=CONCAT(IFNULL(`outCode`,''),'," . implode(',', $standing_book_data['outCode']) . "'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE `infoNo`='{$standing_book_data['infoNo']}'");
- unset($standing_book_data['outCode']);
- }
- Db::name('standing_book')->where('infoNo', $standing_book_data['infoNo'])->update($standing_book_data);
- Db::name('order_return')
- ->where(['id' => $orid, 'is_reissue' => 0])
- ->update([
- 'is_reissue' => 1,
- 'newOrderCode' => $orderCode,
- 'updatetime' => date('Y-m-d H:i:s')
- ]);
- Db::commit();
- return app_show(0, "咨询订单创建成功", ["order_code" => $orderCode]);
- }
- Db::rollback();
- return error_show(1002, "咨询订单创建失败");
- } catch (Exception $e) {
- Db::rollback();
- return error_show(1003, $e->getMessage() . '|' . $e->getFile() . ':' . $e->getLine());
- }
- }
- private function createCgd($data,array &$standing_book_da=[]){
- $cgdCode = makeNo("CG");
- // $supplier=Db::name("supplier")->where(["code"=>$data['supplierNo'],"is_del"=>0])->find();
- $user= \app\admin\common\User::getIns();
- $supplier_temp =$user->handle("sInfo",["code"=>$data['supplierNo']]);
- if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) throw new Exception('该供应商不存在');
- $supplier=$supplier_temp['data'];
- $wsm= Db::name("warehouse_info")
- ->where(["supplierNo"=>$data["supplierNo"],"companyNo"=>$data['companyNo'],"wsm_type"=>2,"is_del"=>0])
- ->find();
- if($wsm==false){
- $wsm_code = makeNo("WSM");
- $inwsm=[
- "wsm_code"=>$wsm_code,
- "name"=>$supplier['name'],
- "wsm_type"=>2,
- "supplierNo"=>$supplier['code'],
- "addr"=>"",
- "addrs_code"=>"",
- "contactor"=>$data['order_type']==1? $supplier['personid']:$data['createrid'],
- "contactor_name"=>$data['order_type']==1? $supplier['person']:$data['creater'],
- "mobile"=>"",
- "position"=>"",
- "companyNo"=>$data['companyNo'],
- "status"=>1,
- "is_del"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $in = Db::name("warehouse_info")->insert($inwsm);
- if($in==false) throw new Exception('仓库新增失败');
- }else $wsm_code =$wsm['wsm_code'];
- //判断该供应商是否开通了供应商账号
- $from_tag=checkHasAccountBySupplierNos([$data['supplierNo']]);
- $cg =[
- "cgdNo"=>$cgdCode,
- "bkcode"=>"",
- "wsm_code"=>$wsm_code,
- "cgder"=>$data['good_creater'],
- "cgder_id"=>$data['good_createrid'],
- "spuCode"=>$data['spuCode'],
- "skuCode"=>$data['skuCode'],
- "good_name"=>$data['good_name'],
- "good_num"=>$data['good_num'],
- "good_price"=>$data['sale_price'],
- "total_fee"=>round($data['sale_price']*$data['good_num'],2),
- "pakge_fee"=>$data['pakge_fee'],
- "cert_fee"=>$data['cert_fee'],
- "open_fee"=>$data['open_fee'],
- "teach_fee"=>$data['cost_fee'],
- "mark_fee"=>$data['mark_fee'],
- "demo_fee"=>$data['demo_fee'],
- "nake_fee"=>$data['nake_fee'],
- "weight"=>$data['weight'],
- "delivery_fee"=>$data['delivery_fee'],
- "gold_price"=>$data['gold_price'],
- "diff_weight"=>"0",
- "diff_fee"=>"0",
- "supplierNo"=>$data['supplierNo'],
- "supplier_name"=>$supplier['name'],
- "companyNo"=>$data['companyNo'],
- "send_status"=>1,
- "send_num"=>0,
- "wsend_num"=>$data['good_num'],
- "remark"=>"",
- "status"=>0,//0初始化
- "lasttime"=>date("Y-m-d H:i:s"),
- "is_del"=>0,
- "order_type"=>$data['order_type'],
- "order_source"=>$data['order_source'],
- "good_type"=>$data['good_type'],
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s"),
- 'good_createrid' => $data['good_createrid'],
- 'good_creater' => $data['good_createrid'],//商品创建人
- 'from_tag' => isset($from_tag[$data['supplierNo']]) ? 2 : 1,//来源标签:1采销(默认),2供应商端
- ];
- $up =Db::name("purchease_order")->insertGetId($cg);
- if($up){
- //修改状态,添加待办
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_code" => $cg['cgdNo'],//销售单code
- "status" => 0,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "create"//新建create,编辑edit,更改状态status
- ], "CGD", $cg['status'], $cg);
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_type" => 'CGD',
- "order_code" => $cg['cgdNo'],//销售单code
- "order_id" => $up,
- "order_status" => $cg['status'],
- "before_status"=> 0,
- 'holder_id' => $supplier['personid'],
- 'wait_id' => $supplier['personid'],
- 'wait_name' => $supplier['person'],
- ]);
- $standing_book_da = array_merge($standing_book_da, [
- 'orderCode' => $data['orderCode'],
- 'cgdNo' => $cgdCode,
- 'spuCode' => $data['spuCode'],
- 'skuCode' => $data['skuCode'],
- 'order_type' => $data['order_type'],
- 'order_source' => $data['order_source'],
- 'supplierNo' => $data['supplierNo'],
- "companyNo" => $data['companyNo'],
- ]);
- $rela=[
- "orderCode"=>$data['orderCode'],
- "cgdNo"=>$cgdCode,
- "spuCode"=>$data['spuCode'],
- "good_num"=>$data['good_num'],
- "wsend_num"=>$data['good_num'],
- "send_num"=>0,
- "wait_num"=>0,
- "status"=>1,
- "source"=>2
- ];
- Db::name("order_num")->save($rela);
- $stokc =Db::name("good_stock")
- ->where(['spuCode'=>$data['spuCode'],"wsm_code"=>$wsm_code, "is_del"=>0])
- ->find();
- if($stokc==false){
- $stokc=[
- "spuCode"=>$data['spuCode'],
- "wsm_code"=>$wsm_code,
- "wait_in_stock"=>$data['good_num'],
- "wait_out_stock"=>0,
- "usable_stock"=>0,
- "intra_stock"=>0,
- "total_stock"=>0,
- "status"=>1,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- }else{
- $stokc['wait_in_stock']+=$data['good_num'];
- $stokc['updatetime']=date("Y-m-d H:i:s");
- }
- $stoc= Db::name("good_stock")->save($stokc);
- if($stoc==false) throw new Exception('商品仓库库存修改失败');
- $good_data[] = ['good_log_code' =>$cgdCode, "stock_id" => isset($stoc['id'])?$stoc['id']:Db::name("good_stock")->getLastInsID(), "type" => 1,'stock'=>$data['good_num'], "stock_name" => "wait_in_stock"];
- GoodLog::LogAdd($data['token'],$good_data,"CGD");
- return true;
- }else throw new Exception('商品仓库库存修改失败');
- }
- //创建采购单
- /**
- * 非咨询类商品处理
- * @param int $orid 售后记录的id
- * @param string $spuCode 商品的spuCode
- * @param array $info 售后申请单的详情
- * @param array $old_sale 原始销售订单信息
- * @param int $rm 操作人id
- * @param string $ri 操作人名称
- * @param array $old_out 原始发货单信息
- * @param string $token 当前用户的token
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- private function createSaleNotZixun(int $orid = 0, string $spuCode = '', array $info = [], array $old_sale = [], int $rm = 0, string $ri = '', array $old_out = [], string $token = '')
- {
- $goodinfo = Db::name('good')
- ->alias('g')
- ->field('g.*,gp.skuCode')
- ->join('good_platform gp', 'gp.spuCode=g.spuCode AND gp.exam_status=3')
- ->where('g.spuCode', $spuCode)
- ->where('gp.skuCode', $old_sale['skuCode'])
- ->find();
- if (empty($goodinfo)) return error_show(1005, '查不到这个商品,或该商品已下线无法售后');
- $is_activity = $old_sale['is_activity'];
- $actcode = $old_sale['activity_code'];
- $good_num = $info['error_num'];//数量,取售后申请单中的异常数量
- $supplierNo = $old_sale['supplierNo'];
- $sale_price = 0;
- $origin_price = $old_sale['origin_price'];
- $goodtype = $old_sale['good_type'];
- $is_stock = $goodinfo['is_stock'];
- $skuCode = $goodinfo['skuCode'];
- $orderCode = makeNo("QR");
- if ($is_stock == 1) {
- $stock_num = Db::name("good_stock")->alias("a")
- ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
- ->leftJoin("good_stock_info c", "a.id=c.stockid and c.balance_num>0")
- ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1, "b.wsm_type" => 5, "b.companyNo" =>$supplierNo])
- ->sum('balance_num');
- if($stock_num < $good_num){
- return error_show(1003, "批次库存数量不足"); //库存不足
- }
- }
- $goodinfo['cgd_gold_price'] = 0;
- if ($goodtype == 1) {
- if ($is_activity == 1) {
- $act = Db::name("activity_info")
- ->alias("a")
- ->leftJoin("good_activity b", "a.activity_code=b.activity_code")
- ->where(["a.skuCode" => $skuCode, "a.activity_code" => $actcode, "a.is_del" => 0, "a.status" => 1, "b.status" => 6, "b.is_del" => 0])
- ->find();
- if ($act == false) return error_show(1003, "未找到相关活动价");
- if ($act['moq_num'] > $good_num) return error_show(1003, "商品不满足活动价起订量{$act['moq_num']}");
- if ($act['activity_stock'] < $good_num) return error_show(1003, "商品活动库存剩余{$act['activity_stock']}");
- }
- // else {
- // $good = Db::name("good_ladder")
- // ->where(["skuCode" => $skuCode, "is_del" => 0, "status" => 1])
- // ->where([["min_num", "<=", $good_num]])
- // ->order("min_num desc")
- // ->find();
- //
- // if ($good == false) return error_show(1003, "未找到相关阶梯价格");
- //
- // if ($goodinfo['is_gold_price'] == 1 && $is_stock != 1) {
- // $gold = Db::name("gold_price1")
- // ->field('id,price')
- // ->where(["type" => $goodinfo['noble_metal'], "is_del" => 0, "status" => 1])
- // ->order("addtime desc")
- // ->find();
- //
- // $goodinfo['cgd_gold_price'] = $gold["price"];
- // }
- // }
- }
- //原有采购单信息
- if ($is_stock != 1){
- $old_cgd = Db::name('order_num')
- ->alias('on')
- ->field('on.id onid,po.*')
- ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
- ->where('on.orderCode', $old_sale['orderCode'])
- ->find();
- $cgd = array_merge($old_cgd, [
- 'id' => null,
- // "supplierNo" => $ct['supplierNo'],
- // "companyNo" => $supplierNo,
- "orderCode" => $orderCode,
- "spuCode" => $spuCode,
- "skuCode" => $skuCode,
- // "good_name" => $ct['good_name'],
- "sale_price" => $old_cgd['good_price'],//采购单价格不为0,取原采购单的价格
- "total_fee" => $old_cgd['good_price'] * $good_num,
- // "pakge_fee" => isset($origin['package_fee']) ? $origin['package_fee'] : 0,
- // "cert_fee" => isset($origin['cert_fee']) ? $origin['cert_fee'] : 0,
- // "open_fee" => $ct['open_fee'],
- // "cost_fee" => isset($origin['cost_fee']) ? $origin['cost_fee'] : 0,
- 'cost_fee' => $old_cgd['teach_fee'],
- // "mark_fee" => isset($origin['mark_fee']) ? $origin['mark_fee'] : 0,
- // "nake_fee" => isset($origin['nake_fee']) ? $origin['nake_fee'] : 0,
- // "delivery_fee" => isset($origin['delivery_fee']) ? $origin['delivery_fee'] : 0,
- // "demo_fee" => $ct['demo_fee'],
- "good_num" => $good_num,
- // "good_type" => $goodtype,
- // "weight" => $ct['noble_weight'],
- // "gold_price" => isset($ct['cgd_gold_price']) ? $ct['cgd_gold_price'] : 0,
- // "order_type" => $is_stock == 1 ? 1 : 2,
- "order_source" => 6,//6售后补换货
- "createrid" => $rm,
- "creater" => $ri,
- // 'send_way' => 2,
- 'token' => $token,
- 'addtime' => date('Y-m-d H:i:s'),
- 'updatetime' => date('Y-m-d H:i:s'),
- 'good_createrid' => $goodinfo['createrid'],
- 'good_creater' => $goodinfo['creater'],//商品创建人
- ]);
- // $supplier_temp_info = Db::name('supplier')
- // ->field('id,person,personid')
- // ->where('code',$cgd['supplierNo'])
- // ->findOrEmpty();
- $user= \app\admin\common\User::getIns();
- $supplier_temp =$user->handle("sInfo",["code"=>$cgd['supplierNo']]);
- }else{
- $user= \app\admin\common\User::getIns();
- $supplier_temp =$user->handle("sInfo",["code"=>$goodinfo['supplierNo']]);
- // $supplier_temp_info = Db::name('supplier')
- // ->field('id,person,personid')
- // ->where('code',$goodinfo['supplierNo'])
- // ->findOrEmpty();
- }
- $supplier_temp_info = [
- "id"=>$supplier_temp['data']['id']??0,
- "person"=>$supplier_temp['data']['person']??'',
- "personid"=>$supplier_temp['data']['personid']??0,
- ];
- // $addrlist = isset($this->post['addrlist']) && $this->post['addrlist'] !=="" ?$this->post['addrlist']:"";
- $send_num = 0;
- // if($sendtype==1){
- // if($addrlist=="" || empty($addrlist) ||!is_array($addrlist)){
- // return error_show(1004,"参数addrlist不能为空");
- // }
- // $send_num = array_sum(array_column($addrlist,"receipt_quantity"));
- // }
- // if($send_num>$good_num){
- // return error_show(1004,"发货数量超出订单总数量");
- // }
- // $remark =isset($this->post['remark']) && $this->post['remark'] !=="" ?trim($this->post['remark']):"";
- // $proof_id =isset($this->post['proof_id']) && $this->post['proof_id'] !=="" ?intval($this->post['proof_id']):0;
- // $apply_id = GetUserInfo($param['token']);
- // if (empty($apply_id) || $apply_id['code'] != 0) return error_show(1002, "申请人数据不存在");
- // $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- // $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
- Db::startTrans();
- try {
- $data = array_merge($old_sale, [
- 'id' => null,
- "orderCode" => $orderCode,
- "good_code" => $spuCode,
- "skuCode" => $skuCode,
- // "customer_code" => $info['customer_code'],
- // "good_name" => (isset($goodinfo['good_name']) && $goodinfo['good_name'] !== '') ? $goodinfo['good_name'] : '',
- "good_num" => $good_num,
- // "cat_id" => $goodinfo['cat_id'],
- "apply_id" => $rm,
- "apply_name" => $ri,
- "origin_price" => $origin_price,
- // "sale_price" => $old_sale['sale_price'],//取原价格
- // "total_price" => $sale_price,//取原总价
- // "post_fee" => 0,
- // "status" => 0,
- "th_num" => 0,
- "th_fee" => 0,//退货金额为0
- "send_num" => 0,
- "wsend_num" => $good_num,
- // "send_status" => 0,
- // "good_type" => $goodtype,
- // "send_type" => $old_sale['send_type'],
- // "supplierNo" => $supplierNo,
- // "is_del" => 0,
- // "zxNo" => "",
- // "platform_order" => $old_sale['platform_order'],
- // "platform_id" => $old_sale['platform_id'],
- "remark" => $old_sale['orderCode'],
- // "is_stock" => $is_stock,
- "is_activity" => $is_activity,
- "activity_code" => $actcode,
- // "order_type" => $is_stock == 1 ? 1 : 2,
- "order_source" => 6,//6售后补换货
- // "poNo"=>$poNo,
- // 'good_weight' => $ct['noble_weight'],
- // 'gold_price' => isset($ct['cgd_gold_price']) ? $ct['cgd_gold_price'] : 0,
- // 'cost_price' => isset($good['cost_fee']) ? $good['cost_fee'] : 0,
- // 'diff_weight' => 0,
- // 'diff_fee' => 0,
- // "workNo" => '',
- 'status' => 0,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s"),
- // 'total_price' => round($sale_price * $good_num, 2),
- // 'proof_id' => $old_sale['proof_id'],
- // 'paytime' => $old_sale['paytime'],
- 'returnCode' => $info['returnCode'],
- 'cgderid' => $supplier_temp_info['personid'],
- 'cgder' => $supplier_temp_info['person'],//采购员(供应商负责人)
- 'good_createrid' => $goodinfo['createrid'],
- 'good_creater' => $goodinfo['creater'],//商品创建人
- ]);
- $datainfo = Db::name('sale')->insertGetId($data);
- if ($datainfo > 0) {
- //修改状态,添加待办
- ActionLog::logAdd($token, [
- "order_code" => $orderCode,//销售单code
- "status" => 0,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "create"//新建create,编辑edit,更改状态status
- ], "XSQRD", 0, $this->post);
- ProcessOrder::AddProcess($token, [
- "order_type" => 'XSQRD',
- "order_code" => $orderCode,//销售单code
- "order_id" => $datainfo,
- "order_status" => 0,
- "before_status" => 0,
- 'holder_id' => $data['apply_id']
- ]);
- if ($is_activity == 1) {
- $actup = [
- "activity_stock" => $act['activity_stock'] - $good_num,
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $actupp = Db::name("activity_info")
- ->where(["skuCode" => $skuCode, "activity_code" => $actcode, "is_del" => 0, "status" => 1])
- ->save($actup);
- if ($actupp == false) throw new Exception('活动库存修改失败');
- }
- $outstatus = 0;
- $standing_book_da = ['sale_id' => $datainfo, 'customer_code' => $old_sale['customer_code'], 'skuCode' => $skuCode, 'updatetime' => date('Y-m-d H:i:s')];
- if ($is_stock == 0) $this->createCgd($cgd, $standing_book_da);
- else {
- $outstatus = 1;
- $stockid= Db::name("good_stock")->alias("a")
- ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
- ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1, "b.wsm_type" => 5, "b.companyNo" =>$supplierNo])
- ->column('a.id');
- $stockinfo =GoodStockInfo::OrderBn($orderCode,$stockid,$good_num);
- if($stockinfo==false){
- throw new Exception('库存商品更新库存失败');
- }
- // $bol = $this->RelaCgd([
- // 'orderCode' => $orderCode,
- // "good_num" => $good_num,
- // "spuCode" => $spuCode,
- // "companyNo" => $supplierNo,
- // "cost_fee" => isset($goodinfo['cost_fee']) ? $goodinfo['cost_fee'] : 0,
- // 'order_type' => $data['order_type'],
- // 'order_source' => $data['order_source'],
- // ], $standing_book_da);
- // if (isset($stock)) {
- //
- // $stck = [
- // "usable_stock" => $stock['usable_stock'] - $good_num,
- // "wait_out_stock" => $stock['wait_out_stock'] + $good_num,
- // "updatetime" => date("Y-m-d H:i:s")
- // ];
- //
- // $upad = Db::name("good_stock")->where($stock)->update($stck);
- // if ($upad == false) throw new Exception('库存商品更新库存失败');
- // $stockinfo =GoodStockInfo::OrderBn($orderCode,$stock['id'],$good_num);
- // if($stockinfo==false){
- // throw new Exception('库存商品更新库存失败'); //库存不足
- // }
- // //商品变动日志表,good_log_code字段存储采购单号
- // $good_data[] = ['good_log_code' => $orderCode, "stock_id" => $stock['id'], "type" => 2, 'stock' => $good_num, "stock_name" => "usable_stock"];
- // $good_data[] = ['good_log_code' => $orderCode, "stock_id" => $stock['id'], "type" => 1, 'stock' => $good_num, "stock_name" => "wait_out_stock"];
- // GoodLog::LogAdd($token, $good_data, "XSQRD");
- // }
- }
- // $old_out = Db::name('order_out')
- // ->field('id,addrid,wsm_code')
- // ->where(['orderCode' => $info['orderCode'], 'outCode' => $info['outCode']])
- // ->find();
- $old_out_addr_info = Db::name('order_out')
- ->alias('oo')
- ->field('oo.id,oa.addr,oa.addr_code,oa.contactor,oa.mobile,oa.customer_code,oa.post_fee,oa.arrive_time')
- ->leftJoin('order_addr oa', 'oa.id=oo.addrid')
- ->where(['oo.outCode' => $info['outCode'], 'oo.orderCode' => $info['orderCode']])
- ->find();
- if (empty($old_out_addr_info)) throw new Exception('发货单对应的地址信息查不到');
- $temp = [
- 'orderCode' => $orderCode,
- 'addr' => $old_out_addr_info['addr'],
- 'addr_code' => $old_out_addr_info['addr_code'],
- 'contactor' => $old_out_addr_info['contactor'],
- 'mobile' => $old_out_addr_info['mobile'],
- 'customer_code' => $old_out_addr_info['customer_code'],
- 'receipt_quantity' => $good_num,
- 'arrive_time' => $old_out_addr_info['arrive_time'],
- 'addtime' => date("Y-m-d H:i:s"),
- 'updatetime' => date("Y-m-d H:i:s"),
- // ''=>'',
- ];
- $addrid = Db::name('order_addr')->insertGetId($temp);
- $outCode = makeNo("DF");
- $out = array_merge($old_out, [
- 'id' => null,
- "orderCode" => $orderCode,
- "outCode" => $outCode,
- "apply_id" => $rm,
- "apply_name" => $ri,
- "addrid" => $addrid,
- "post_name" => "",
- "post_code" => "",
- "post_fee" => 0,
- "sendtime" => date("Y-m-d H:i:s"),
- "send_num" => $good_num,
- "check_num" => 0,
- "error_num" => 0,
- "wsm_code" => isset($old_out['wsm_code']) ? $old_out['wsm_code'] : '',
- "order_type" => $is_stock == 1 ? 1 : 2,
- "status" => $outstatus,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ]);
- Db::name("order_out")->insert($out);
- $standing_book_da['outCode'] = $outCode;
- if($is_stock==0){
- $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])->find();
- if (empty($order)) throw new Exception('采购单关联数据未找到');
- $order['send_num'] += $good_num;
- $order['wsend_num'] -= $good_num;
- if ($order['wsend_num'] < 0) throw new Exception('发货数量已超出总数');
- $ups = Db::name("order_num")->save($order);
- if ($ups) {
- $sen = Db::name("order_send")->save([
- "cgdNo" => $order['cgdNo'],
- "outCode" => $outCode,
- "send_num" => $good_num,
- "status" => 1,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ]);
- if ($sen == false) throw new Exception('发货地址添加创建失败');
- }
- }
- if (!isset($standing_book_da['returnCode'])) $standing_book_da['returnCode'] = '';
- if (!isset($standing_book_da['thNo'])) $standing_book_da['thNo'] = '';
- if (!isset($standing_book_da['returnGoodCode'])) $standing_book_da['returnGoodCode'] = '';
- if (!isset($standing_book_da['wsm_in_code'])) $standing_book_da['wsm_in_code'] = '';
- if (!isset($standing_book_da['cgdReturnCode'])) $standing_book_da['cgdReturnCode'] = '';
- //处理台账
- Db::name('standing_book')->insert(array_merge($standing_book_da, ['addtime' => date('Y-m-d H:i:s'), 'updatetime' => date('Y-m-d H:i:s'), 'standBookNo' => makeNo('IO')]));
- //维护售后申请单
- Db::name('order_return')
- ->where(['id' => $orid, 'is_reissue' => 0])
- ->update([
- 'is_reissue' => 1,
- 'newOrderCode' => $orderCode,
- 'updatetime' => date('Y-m-d H:i:s')
- ]);
- Db::commit();
- return error_show(0, "操作成功");
- } else throw new Exception('咨询订单创建失败');
- } catch (\Exception $e) {
- Db::rollback();
- return error_show(1005, $e->getMessage() . '|' . $e->getFile() . '|' . $e->getLine());
- }
- }
- //创建采购单
- public function RelaCgd($outinfo,array &$standing_book_da=[]){
- $cgd = Db::name("order_bk")->where([["spuCode","=",$outinfo['spuCode']],["is_del","=",0],["balance_num",">=",$outinfo['good_num']],['companyNo',"=",$outinfo['companyNo']]])->lock(true)->find();
- if($cgd==false) throw new Exception('未查询到备库单信息');
- $good=Db::name("good")
- ->where(["spuCode"=>$outinfo['spuCode'],"is_del"=>0])
- ->find();
- if($good==false) throw new Exception('未查询到商品信息');
- $cgdinfo =Db::name("purchease_order")
- ->where(['cgdNo'=>$cgd['cgdNo'],"is_del"=>0])
- ->find();
- if($cgdinfo==false) throw new Exception('未查询到采购单信息');
- //判断该供应商是否开通了供应商账号
- $from_tag=checkHasAccountBySupplierNos([$cgdinfo['supplierNo']]);
- $QrdCgd=[
- "cgdNo"=>makeNo("CG"),
- "bkcode" => $cgdinfo['bkcode'],
- 'wsm_code'=>$cgdinfo['wsm_code'],
- "cgder_id"=>$cgdinfo['cgder_id'],
- "cgder"=>$cgdinfo['cgder'],
- "spuCode"=>$cgdinfo['spuCode'],
- "good_name"=>$cgdinfo['good_name'],
- "good_num"=>$outinfo['good_num'],
- "good_price"=>$cgdinfo['good_price'],
- "total_fee"=>round($cgdinfo['good_price']*$outinfo['good_num'],2),
- "pakge_fee"=>$cgdinfo['pakge_fee'],
- "cert_fee"=>$cgdinfo['cert_fee'],
- "open_fee"=>$cgdinfo['open_fee'],
- "delivery_fee"=>$cgdinfo['delivery_fee'],
- "mark_fee"=>$cgdinfo['mark_fee'],
- "teach_fee"=>$cgdinfo['teach_fee'],
- "nake_fee"=>$cgdinfo['nake_fee'],
- "demo_fee"=>$cgdinfo['demo_fee'],
- "weight"=>$cgdinfo['weight'],
- "diff_weight"=>$cgdinfo['diff_weight'],
- "diff_fee"=>$cgdinfo['diff_fee'],
- "gold_price"=>$cgdinfo['gold_price'],
- "supplierNo"=>$cgdinfo['supplierNo'],
- "supplier_name"=>$cgdinfo['supplier_name'],
- "companyNo"=>$cgdinfo['companyNo'],
- "send_status"=>3,
- "send_num"=>$outinfo['good_num'],
- "wsend_num"=>0,
- "remark"=>$cgdinfo['remark'],
- "status"=>3,
- "lasttime"=>$cgdinfo['lasttime'],
- "is_del"=>0,
- "order_type"=>$outinfo['order_type'],
- "order_source"=>$outinfo['order_source'],
- "good_type"=>$cgdinfo['good_type'],
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s"),
- 'good_createrid' => $good['createrid'],
- 'good_creater' => $good['creater'],//商品创建人
- 'from_tag' => isset($from_tag[$cgdinfo['supplierNo']]) ? 2 : 1,//来源标签:1采销(默认),2供应商端
- ];
- $insetrCgd=Db::name("purchease_order")->insert($QrdCgd);
- if($insetrCgd==false) throw new Exception('新增采购单失败');
- else{
- $standing_book_da = array_merge($standing_book_da, [
- 'orderCode' => $outinfo['orderCode'],
- 'cgdNo' => $cgdinfo['cgdNo'],
- 'spuCode' => $outinfo['spuCode'],
- 'order_type' => $QrdCgd['order_type'],
- 'order_source' => $QrdCgd['order_source'],
- 'supplierNo' => $cgdinfo['supplierNo'],
- 'companyNo' => $cgdinfo['companyNo'],
- 'bk_code' => $cgdinfo['bkcode'],
- 'purchease_id' => Db::name('purchease')->where('bk_code', $cgdinfo['bkcode'])->value('id',0),
- ]);
- }
- if($good['is_gold_price']==1 && $good['is_stock']==1){
- $gold = Db::name("gold_price1")
- ->field('id,price')
- ->where(["type" => $good['noble_metal'], "is_del" => 0, "status" => 1])
- ->order("addtime desc")
- ->find();
- $ct['cgd_gold_price']=$gold["price"];
- $updat=[
- "sale_price"=>0,
- "total_price"=>0,
- "origin_price"=>$cgdinfo['good_price'],
- "gold_price"=>$gold["price"],
- ];
- Db::name("sale")->where(["orderCode"=>$outinfo['orderCode']])->update($updat);
- // if($upsale==false){
- // return false;
- // }
- }
- $merge_num = Db::name("purchease_order")
- ->where(["bkcode"=>$cgdinfo['bkcode'],"order_type"=>1,"is_del"=>0])
- ->where("order_source","<>",0)
- ->field("sum(send_num)-sum(th_num) as num")
- ->find();
- $cgd['balance_num']=$cgd['total_num']-$merge_num['num'];
- $cgd['merge_num']=$merge_num['num'];
- $cgd['updatetime']=date("Y-m-d H:i:s");
- $up=Db::name("order_bk")->save($cgd);
- if($up==false) throw new Exception('修改备库单失败');
- $data=[
- "orderCode"=>$outinfo['orderCode'],
- "cgdNo"=>$QrdCgd['cgdNo'],
- "spuCode"=>$outinfo['spuCode'],
- "companyNo"=>$outinfo['companyNo'],
- "good_num"=>$outinfo['good_num'],
- "wsend_num"=>$outinfo['good_num'],
- "send_num"=>0,
- "wait_num"=>$outinfo['good_num'],
- "status"=>1,
- "source"=>1,
- ];
- $order =Db::name("order_num")->save($data);
- if($order==false) throw new Exception('修改采购单销售单关联失败');
- }
- //导出
- public function export()
- {
- $param = $this->request->only([
- 'returnCode',
- 'outCode' => '',
- 'status' => '',
- 'order_type' => '',
- 'orderCode' => '',
- 'good_code' => '',
- 'good_name' => '',
- 'except_code' => '',
- 'apply_name' => '',
- 'start' => '',
- 'end' => '',
- 'company_name' => '',//部门名称
- 'supplierNo' => '',
- 'customer_code' => '',
- 'companyNo' => '',
- 'order_source' => '',
- ], 'post', 'trim');
- $val = Validate::rule(['returnCode' => 'require|array|max:10']);
- if ($val->check($param) == false) return json_show(1004, $val->getError());
- $where = [['a.is_del', "=", 0], ['a.returnCode', 'in', $param['returnCode']]];
- // if ($param['relaComNo'] !== '') $where[] = ['a.supplierNo', "=", $param['relaComNo']];
- if ($param['returnCode'] !== '') $where[] = ['a.returnCode', "like", "%{$param['returnCode']}%"];
- if ($param['outCode'] !== '') $where[] = ['a.outCode', "like", "%{$param['outCode']}%"];
- if ($param['status'] !== '') $where[] = ['a.status', "=", $param['status']];
- if ($param['order_type'] !== "") $where[] = ['a.order_type', "=", $param['order_type']];
- if ($param['orderCode'] != "") $where[] = ['a.orderCode', "like", "%{$param['orderCode']}%"];
- if ($param['good_code'] != "") $where[] = ['a.good_code', "like", "%{$param['good_code']}%"];
- if ($param['good_name'] != "") $where[] = ['a.good_name', "like", "%{$param['good_name']}%"];
- if ($param['customer_code'] != "") $where[] = ['a.customer_code', "like", "%{$param['customer_code']}%"];
- if ($param['except_code'] != "") $where[] = ['a.except_code', "=", $param['except_code']];
- if ($param['apply_name'] != "") $where[] = ['a.apply_name', "like", "%{$param['apply_name']}%"];
- if ($param['start'] !== "") $where[] = ['a.addtime', ">=", $param['start']];
- if ($param['end'] !== "") $where[] = ['a.addtime', "<=", $param['end']];
- if ($param['order_source'] !== "") $where[] = ['c.order_source', "=", $param['order_source']];
- if ($param['supplierNo'] !== "") $where[] = ['a.supplierNo', "like", '%' . $param['supplierNo'] . '%'];
- if ($param['companyNo'] !== "") $where[] = ['a.companyNo', "like", '%' . $param['companyNo'] . '%'];
- if ($param['company_name'] !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($param['company_name'])];
- //只有level2的账号过滤数据权限
- if ($this->level == 2) {
- $hand = resign_hand_user($this->uid, 0);
- $role = $this->checkDataShare();
- if (!empty($role[DataGroupModel::$type_全部])) {
- $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
- $condition[] = ["a.person_id", "in", $hand];
- $condition[] = ["a.apply_id", "in", $arr];
- $condition[] = ["a.cgderid", "in", $hand];
- $code = Db::connect('mysql_sys')
- ->name('supplier')
- ->where(['is_del' => 0, 'personid' => $this->uid])
- ->column('code');
- if($code) $condition[] = ["a.supplierNo", "in", $code];
- }
- }
- //level3账号不允许看到库存品订单
- if ($this->level == 3) $where[] = ['c.is_stock', '<>', 1];
- // $condition .="a.cgderid in {$hand} or a.person_id in {$hand} or a.apply_id in ("
- // .implode(',',$role[DataGroupModel::$type_全部]).")";
- $list = Db::name('order_return')
- ->field('
- a.returnCode 售后申请单编码,
- a.order_type 订单类型,
- a.apply_name 申请人,
- a.cgder 采购员,
- a.person 采购负责人,
- a.outCode 发货单号,
- a.is_receive 是否收到货,
- a.total_num 总数量,
- a.error_num 异常数量,
- a.error_msg 异常原因,
- a.error_remark 异常备注,
- a.except_code 客户意愿,
- a.orderCode 订单编号,
- a.good_code 商品编号,
- a.good_name 商品名称,
- a.customer_code 客户编码,
- a.customer_name 客户名称,
- a.is_post 是否承担物流费用,
- a.is_th 供应商是否退货,
- a.return_tag 退回何处,
- a.status 状态,
- a.remark 审核备注,
- a.addtime 创建时间,
- a.updatetime 更新时间,
- a.is_reissue 是否完成补发货,
- a.newOrderCode 售后完成后新的销售订单号,
- a.loop_total 状态从业务公司修改待供应商确认到待采购审核的循环次数,
- b.return_wsm 退回仓库,
- b.contactor 仓库联系人,
- b.mobile 联系方式,
- b.addr 地址,
- b.addr_code,
- b.post_code 快递单号,
- b.post_company 快递公司,
- b.post_fee 快递费用,
- b.gys_remark 供应商备注,
- a.supplierNo 供应商编码,
- a.supplierName 供应商名称,
- a.companyNo 业务公司编码,
- a.companyName 业务公司名称')
- ->alias('a')
- ->where($where)
- ->where(function ($query) use ($condition) {
- $query->whereOr($condition);
- })
- ->leftJoin('order_returninfo b', 'b.returnCode=a.returnCode')
- ->leftJoin("sale c", "c.orderCode=a.orderCode AND c.is_del=0")
- ->select()
- ->toArray();
- $order_type = [1 => '直接下单', 2 => '咨询', 3 => '项目', 4 => '平台', 5 => '有赞', 6 => '售后补换货', 7 => '报备转单', 8 => '支付渠道'];
- $is_receive = [0 => '否', 1 => '是'];
- $except_code = [0 => [1 => '退货', 2 => '补发'], 1 => [1 => '退货', 2 => '换货'],];//期望意愿
- $return_tag = [1 => '供应商', 2 => '业务企业'];
- $status = [1 => '待业务审核', 2 => '待采购审核', 4 => '待客户退货', 5 => '售后已完成', 6 => '业务已驳回', 8 => '申请已取消', 9 => '供应商审核', 10 => '业务公司修改待供应商确认'];
- foreach ($list as &$value) {
- $value['订单类型'] = $order_type[$value['订单类型']] ?? '';
- $value['客户意愿'] = $except_code[$value['是否收到货']][$value['客户意愿']] ?? '';
- $value['是否收到货'] = $is_receive[$value['是否收到货']] ?? '';
- $value['是否承担物流费用'] = $is_receive[$value['是否承担物流费用']] ?? '';
- $value['供应商是否退货'] = $is_receive[$value['供应商是否退货']] ?? '';
- $value['退回何处'] = $return_tag[$value['退回何处']] ?? '';
- $value['状态'] = $status[$value['状态']] ?? '';
- $value['是否完成补发货'] = $is_receive[$value['是否完成补发货']] ?? '';
- $addr_code = explode(',', $value['addr_code']);
- $value['地址'] = GetAddr(json_encode(['provice_code' => $addr_code[0], 'city_code' => $addr_code[1], 'area_code' => $addr_code[2]])) . $value['地址'];
- unset($value['addr_code']);
- }
- if (empty($list)) $list[] = ['没有相关可导出的数据'];
- excelSave('售后申请单' . date('YmdHis'), array_keys($list[0]), $list);
- }
- }
|