12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483 |
- <?php
- declare (strict_types=1);
- namespace app\Admin\controller;
- use app\BaseController;
- use think\facade\Db;
- use think\Request;
- class Assoc extends BaseController
- {
- /**
- * 显示资源列表
- * @return \think\Response
- */
- public function index()
- {
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function create()
- {
- $post = $this->request->post();
- $token = isset($post['token']) ? trim($post['token']) : "";
- if ($token == "") {
- return error_show(101, 'token不能为空');
- }
- $effetc = VerifyTokens($token);
- if (!empty($effetc) && $effetc['code'] != 0) {
- return error_show($effetc['code'], $effetc['message']);
- }
- $guserinfo =GetUserInfo($token);
- if(isset($guserinfo['code']) && $guserinfo['code']!=0){
- return error_show($guserinfo['code'],$guserinfo['message']);
- }
- // $companyNo = isset($post['tradeNo'])&&$post['tradeNo']!=""?trim($post['tradeNo']):"";
- $companyNo = isset($post['companyNo']) && $post['companyNo'] != "" ? trim($post['companyNo']) : "";
- $type = isset($post['type']) && $post['type'] != "" ? intval($post['type']) : 2;
- // $invid = isset($post['invid'])&&$post['invid']!="" ? $post['invid'] : "";
- $tradid = isset($post['tradid']) && $post['tradid'] != "" ? $post['tradid'] : "";
- if (!in_array($type, [2, 3])) {
- return error_show(1004, "参数type 有误");
- }
- $tralog = "";
- $tradeno=[];
- // $invlog="";
- if ($type == 2) {
- $tralog = Db::name("trade_pool")->where([["is_del", "=", 0], ["id", "in", $tradid]])->select()->toArray();
- if (!$tralog) {
- return error_show(1004, "未找到对应的资金数据");
- }
- $tradeno = array_column($tralog,'traNo');
- }
- if ($type == 3) {
- $tralog = Db::name("trade_pool")->where([["is_del", "=", 0], ["id", "=", $tradid]])->find();
- if (!$tralog) {
- return error_show(1004, "未找到对应的资金数据");
- }
- $tradeno[] = $tralog['traNo'];
- }
- $isinv = Db::name("assoc_list")->where([["codeNo|viceNo","in",$tradeno],["is_del","=",0],['bstatus',"=",1],['rela_form','in',[4,5]]])->select()->toArray();
- $userinfo = GetUserInfo($token);
- $username = "";
- if ($companyNo == "") {
- return error_show(1004, "参数companyNo 不能为空");
- }
- if (isset($userinfo['code']) && $userinfo['code'] == 0) {
- $username = isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname'] : "";
- }
- $customer = Db::name("customer_info")->where("companyNo", "=", $companyNo)->find();
- if (empty($customer)) {
- return error_show(1004, "未找到客户企业信息");
- }
- $good = isset($post['good']) && $post['good'] ? explode(",", $post['good']) : "";
- if ($good == "" && empty($good)) {
- return error_show(1004, "商品信息不能为空");
- }
- $orderall = Db::name("order_list")->where([['is_del',"=",0],['type',"<>",4],['goodNo',"in",$good]])->column('orderNo');
- $isorderinv = Db::name("assoc_list")->where([["codeNo","in",$orderall],["is_del","=",0],['bstatus', "=",1],['rela_form','=',1]])->select()->toArray();
- if(!empty($isinv)&&!empty($isorderinv)){
- return error_show(1004, "订单和资金不能同时都有开票信息");
- }
- Db::startTrans();
- try {
- $orderinfo = [];
- $orderNo = makeNo('ORD');
- $total = 0;
- $fund_fee = 0;
- $wfund_fee = 0;
- $inv_fee = 0;
- $winv_fee = 0;
- foreach ($good as $value) {
- $temp = [];
- $temp['orderNo'] = $orderNo;
- $temp['goodNo'] = $value;
- $goocp = Db::name("qrd_list")->where("sequenceNo", "=", $value)->find();
- if (!$goocp) {
- continue;
- }
- $temp['good_name'] = $goocp['goodname'];
- $temp['qrdNo'] = $goocp['qrdNo'];
- $temp['brand'] = $goocp['brand'];
- $temp['unit'] = $goocp['unit'];
- $temp['good_num'] = $goocp['num'];
- $temp['price'] = $goocp['price'];
- $temp['total_fee'] = $goocp['total_fee'];
- $temp['wfund_fee'] = $goocp['wpay_fee'];
- $temp['winv_fee'] = $goocp['winv_fee'];
- $temp['other_fee'] = 0;
- $temp['status'] = 1;
- $temp['remark'] = "";
- $temp['addtime'] = date("Y-m-d H:i:s");
- $temp['updatetime'] = date("Y-m-d H:i:s");
- $total += $goocp['total_fee'];
- $fund_fee += $goocp['apay_fee'];
- $winv_fee += $goocp['winv_fee'];
- $inv_fee += $goocp['ainv_fee'];
- $wfund_fee += $goocp['wpay_fee'];
- $orderinfo[] = $temp;
- }
- $orderins = Db::name("order_info")->insertAll($orderinfo);
- if ($orderins) {
- $order = [
- "orderNo" => $orderNo,
- "companyNo" => $companyNo,
- "sales_id" => $effetc['data']['user']['id'],
- "sales_name" => $username,
- "total_amount" => $total,
- "inv_status" => 1,
- "fund_status" => 1,
- "fund_fee" => 0,
- "wfund_fee" => $wfund_fee,
- "inv_fee" => 0,
- "winv_fee" => $winv_fee,
- "status" => 0,
- "type" => $type,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $orderpool = Db::name("order_pool")->insert($order, true);
- if ($orderpool > 0) {
- if ($tralog != "" && is_array($tralog)) {
- $rela = [];
- $assNo = makeNo("ASC");
- $cancel = 0;
- if ($type == 2) {
- foreach ($tralog as $value) {
- $balance = $value["worder_fee"] > $wfund_fee ? $wfund_fee : $value["worder_fee"];
- if ($wfund_fee <= 0) {
- Db::rollback();
- return error_show(1004, "资金额度大于订单的未开票额度");
- }
- $wfund_fee -= $balance;
- $cancel += $balance;
- $rela[] = [
- "assocNo" => $assNo,
- "viceNo" => $value['traNo'],
- "vice_fee" => $value['worder_fee'] - $balance,
- "vice_total" => $value['total_fee'],
- "cancel_fee" => $balance,
- "status" => 1,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $value['worder_fee'] -= $balance;
- $value['order_used'] += $balance;
- // $value['order_status']=$balance;
- $value['is_order'] = 1;
- $value['updatetime'] = date("Y-m-d H:i:s");
- Db::name("trade_pool")->save($value);
- }
- $assoc = Db::name("assoc_rela")->insertAll($rela);
- if ($assoc) {
- $data = [
- "assocNo" => $assNo,
- "companyNo" => $companyNo,
- "type" => 1,
- "apply_id"=> $guserinfo["data"]["id"],
- "apply_name"=> $guserinfo["data"]["nickname"],
- "rela_form" => $type,
- "codeNo" => $orderNo,
- "total_fee" => $order['total_amount'],
- "balance" => $wfund_fee,
- "cancel_total" => $cancel,
- "status" => 1,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $realkey = Db::name("assoc_key")->insert($data);
- if ($realkey) {
- Db::name("order_pool")->where("orderNo", "=", $orderNo)->save
- (["wfund_fee" => $wfund_fee,'fund_used'=>$cancel, "updatetime" => date("Y-m-d H:i:s")]);
- $qrdup=$this->updateQrd($orderNo,$cancel);
- if(!$qrdup){
- Db::rollback();
- return error_show(1004, "新建关联申请失败");
- }
- Db::commit();
- return app_show(0, "新建关联成功");
- }
- }
- }
- if ($type == 3) {
- $balance = $tralog["worder_fee"] > $wfund_fee ? $wfund_fee : $tralog["worder_fee"];
- $wfund_fee -= $balance;
- $tralog['worder_fee'] -= $balance;
- $tralog['order_used'] += $balance;
- $tralog['is_order'] = 1;
- $tralog['updatetime'] = date("Y-m-d H:i:s");
- Db::name("trade_pool")->save($tralog);
- $rela = [
- "assocNo" => $assNo,
- "viceNo" => $orderNo,
- "vice_total" => $order['total_amount'],
- "vice_fee" => $wfund_fee,
- "cancel_fee" => $balance,
- "status" => 1,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $assoc = Db::name("assoc_rela")->insert($rela);
- if ($assoc) {
- $data = [
- "assocNo" => $assNo,
- "companyNo" => $companyNo,
- "type" => 3,
- "rela_form" => $type,
- "codeNo" => $tralog["traNo"],
- "total_fee" => $tralog['total_fee'],
- "balance" => $tralog['worder_fee'],
- "cancel_total" => $balance,
- "status" => 1,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $realkey = Db::name("assoc_key")->insert($data);
- if ($realkey) {
- Db::name("order_pool")->where("orderNo", "=", $orderNo)->save
- (["wfund_fee" => $wfund_fee,'fund_used'=>$balance, "updatetime" => date("Y-m-d H:i:s")]);
- $qrdup=$this->updateQrd($orderNo,$balance);
- if(!$qrdup){
- Db::rollback();
- return error_show(1004, "新建关联申请失败");
- }
- Db::commit();
- return app_show(0, "新建关联成功");
- }
- }
- }
- Db::rollback();
- return error_show(1004, "新建关联申请失败");
- }
- }
- }
- Db::rollback();
- return error_show(1004, "新建关联申请失败");
- } catch (\Exception $e) {
- Db::rollback();
- return error_show(1004, $e->getMessage());
- }
- }
- /**
- * 保存新建的资源
- *
- * @param \think\Request $request
- * @return \think\Response
- */
- public function add()
- {
- $post = $this->request->post();
- $token = isset($post['token']) ? trim($post['token']) : "";
- if ($token == "") {
- return error_show(101, 'token不能为空');
- }
- $effetc = VerifyTokens($token);
- if (!empty($effetc) && $effetc['code'] != 0) {
- return error_show($effetc['code'], $effetc['message']);
- }
- $guserinfo =GetUserInfo($token);
- if(isset($guserinfo['code']) && $guserinfo['code']!=0){
- return error_show($guserinfo['code'],$guserinfo['message']);
- }
- // $companyNo = isset($post['tradeNo'])&&$post['tradeNo']!=""?trim($post['tradeNo']):"";
- $companyNo = isset($post['companyNo']) && $post['companyNo'] != "" ? trim($post['companyNo']) : "";
- $type = isset($post['type']) && $post['type'] != "" ? intval($post['type']) : 4;
- $invid = isset($post['invid']) && $post['invid'] != "" ? $post['invid'] : "";
- $tradid = isset($post['tradid']) && $post['tradid'] != "" ? $post['tradid'] : "";
- if (!in_array($type, [4, 5])) {
- return error_show(1004, "参数type 有误");
- }
- if ($invid == "") {
- return error_show(1004, "缺少必要参数invid");
- }
- if ($tradid == "") {
- return error_show(1004, "缺少必要参数tradid");
- }
- if ($type == 5) {
- $tralog = Db::name("trade_pool")->where([["is_del", "=", 0], ["id", "=", $tradid]])->find();
- if (!$tralog) {
- return error_show(1004, "未找到对应的资金数据");
- }
- $invlog = Db::name("invoice_pool")->where([["is_del", "=", 0], ["id", "in", $invid]])->select()->toArray();
- if (!$invlog) {
- return error_show(1004, "未找到对应的发票数据");
- }
- }
- if ($type == 4) {
- $invlog = Db::name("invoice_pool")->where([["is_del", "=", 0], ["id", "=", $invid]])->find();
- if (!$invlog) {
- return error_show(1004, "未找到对应的发票数据");
- }
- $tralog = Db::name("trade_pool")->where([["is_del", "=", 0], ["id", "in", $tradid]])->select()->toArray();
- if (!$tralog) {
- return error_show(1004, "未找到对应的资金数据");
- }
- }
- Db::startTrans();
- try {
- if ($type == 5) {
- $rela = [];
- $trade = 0;
- $assNo = makeNo("ASC");
- foreach ($invlog as $value) {
- $balance = $tralog['winv_fee'] > $value['wtrade_fee'] ? $value['wtrade_fee'] : $tralog['winv_fee'];
- if ($tralog['winv_fee'] <= 0) {
- Db::rollback();
- return error_show(1005, "发票总额大于资金额度");
- }
- if ($value['wtrade_fee'] <= 0) {
- Db::rollback();
- return error_show(1005, "发票核销金额为0");
- }
- $tralog['winv_fee'] -= $balance;
- $tralog['inv_used'] += $balance;
- $trade += $balance;
- $rela[] = [
- "assocNo" => $assNo,
- "viceNo" => $value['invNo'],
- "vice_total" => $value['inv_value'],
- "vice_fee" => $value['wtrade_fee'] - $balance,
- "cancel_fee" => $balance,
- "status" => 1,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $value['wtrade_fee'] -= $balance;
- $value['fund_used'] += $balance;
- // $value['order_status']=$balance;
- // $value['is_order']=1;
- $value['updatetime'] = date("Y-m-d H:i:s");
- Db::name("invoice_pool")->save($value);
- }
- $assoc = Db::name("assoc_rela")->insertAll($rela);
- if ($assoc) {
- $data = [
- "assocNo" => $assNo,
- "companyNo" => $companyNo,
- "type" => 3,
- "apply_id"=> $guserinfo["data"]["id"],
- "apply_name"=> $guserinfo["data"]["nickname"],
- "rela_form" => $type,
- "codeNo" => $tralog["traNo"],
- "total_fee" => $tralog['total_fee'],
- "balance" => $tralog['winv_fee'],
- "cancel_total" => $trade,
- "status" => 1,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $realkey = Db::name("assoc_key")->insert($data);
- if ($realkey) {
- $tralog['updatetime'] = date("Y-m-d H:i:s");
- Db::name("trade_pool")->save($tralog);
- Db::commit();
- return app_show(0, "新建关联成功");
- }
- }
- Db::rollback();
- return error_show(1004, "新建关联申请失败");
- } else {
- $rela = [];
- $trade = 0;
- $assNo = makeNo("ASC");
- foreach ($tralog as $value) {
- $balance = $invlog['wtrade_fee'] > $value['winv_fee'] ? $value['winv_fee'] : $invlog['wtrade_fee'];
- if ($invlog['wtrade_fee'] <= 0) {
- Db::rollback();
- return error_show(1005, "资金总额大于发票额度");
- }
- if ($value['winv_fee'] <= 0) {
- Db::rollback();
- return error_show(1005, "发票核销金额为0");
- }
- $invlog['wtrade_fee'] -= $balance;
- $invlog['fund_used'] += $balance;
- $trade += $balance;
- $rela[] = [
- "assocNo" => $assNo,
- "viceNo" => $value['traNo'],
- "vice_total" => $value['total_fee'],
- "vice_fee" => $value['winv_fee'] - $balance,
- "cancel_fee" => $balance,
- "status" => 1,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $value['winv_fee'] -= $balance;
- $value['inv_used'] += $balance;
- $value['updatetime'] = date("Y-m-d H:i:s");
- Db::name("trade_pool")->save($value);
- }
- $assoc = Db::name("assoc_rela")->insertAll($rela);
- if ($assoc) {
- $data = [
- "assocNo" => $assNo,
- "companyNo" => $companyNo,
- "type" => 2,
- "rela_form" => $type,
- "codeNo" => $invlog["invNo"],
- "total_fee" => $invlog['inv_value'],
- "balance" => $invlog['wtrade_fee'],
- "cancel_total" => $trade,
- "status" => 1,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $realkey = Db::name("assoc_key")->insert($data);
- if ($realkey) {
- $invlog['updatetime'] = date("Y-m-d H:i:s");
- $order_up = Db::name("invoice_pool")->save($invlog);
- Db::commit();
- return app_show(0, "新建关联成功");
- }
- }
- Db::rollback();
- return error_show(1004, "新建关联申请失败");
- }
- } catch (\Exception $e) {
- Db::rollback();
- return error_show(1006, $e->getMessage());
- }
- }
- /**
- * 显示指定的资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function read()
- {
- $post = $this->request->post();
- $token = isset($post['token']) ? trim($post['token']) : "";
- if ($token == "") {
- return error_show(101, 'token不能为空');
- }
- $effetc = VerifyTokens($token);
- if (!empty($effetc) && $effetc['code'] != 0) {
- return error_show($effetc['code'], $effetc['message']);
- }
- $id = isset($post['id']) && $post['id'] != "" ? $post['id'] : "";
- if ($id == "") {
- return error_show(1004, "参数id 不能为空");
- }
- $condition = [['is_del', "=", 0], ["id", "=", $id]];
- $relainfo = Db::name("assoc_key")->where($condition)->find();
- if (!$relainfo) {
- return error_show(1004, "未找到关联数据");
- }
- $relainfo["order_info"] = [];
- $relainfo["inv_info"] = [];
- $relainfo["tra_info"] = [];
- $customer1 = Db::name("customer_info")->where("companyNo", "=", $relainfo['companyNo'])->find();
- $relainfo["companyName"] =$customer1?$customer1['companyName']:"";
- if ($relainfo['type'] == 1) {
- $order = Db::name("order_pool")->where("orderNo", "=", $relainfo['codeNo'])->find();
- $customer = Db::name("customer_info")->where("companyNo", "=", $order['companyNo'])->find();
- $order["companyName"] = $customer['companyName'];
- $order["cancel_fee"] = $relainfo['cancel_total'];
- $good = Db::name("order_info")->where([["orderNo", "=", $relainfo['codeNo']], ["status", "=", 1]])->select();
- $order['good'] = [];
- $qrdinfo =[];
- foreach ($good as $key => $value) {
- $tep = Db::name("qrd_list")->where("sequenceNo", "=", $value["goodNo"])->field("id,sequenceNo,goodname,qrdNo,goodNo,brand,unit,taxPoint,num,goldprice,weight,price,total_fee,touser,gys,kehu,apay_fee,wpay_fee,ainv_fee,winv_fee,pay_status,inv_status,inv_num")
- ->find();
- if(isset($tep["qrdNo"])&& !isset($qrdinfo[$tep["qrdNo"]])){
- $qrdinfo[$tep["qrdNo"]]= Db::name("qrd")->where("sequenceNo", "=", $tep["qrdNo"])->field("id,createdTime,sequenceNo,sales_name,sales_depart,customer,total_fee,contactor,mobile,type,addr,apay_fee,wpay_fee,ainv_fee,winv_fee,pay_status,inv_status")->find();
- }
- $tep['goldprice'] = isset($tep['goldprice']) ? sprintf("%.2f", $tep['goldprice']) : "";
- $tep['price'] = isset($tep['price']) ? sprintf("%.2f", $tep['price']) : "";
- $tep['total_fee'] = isset($tep['total_fee']) ? sprintf("%.2f", $tep['total_fee']) : "";
- $tep['apay_fee'] = sprintf("%.2f", $tep['apay_fee']);
- $tep['wpay_fee'] = sprintf("%.2f", $tep['wpay_fee']);
- $tep['ainv_fee'] = sprintf("%.2f", $tep['ainv_fee']);
- $tep['winv_fee'] = sprintf("%.2f", $tep['winv_fee']);
- $tep['num'] = intval($tep['num']);
- $tep['inv_num'] = isset($tep['inv_num']) ? sprintf("%d", $tep['inv_num']) : "0";
- //$order['good'][] = $tep;
- $qrdinfo[$tep["qrdNo"]]['good'][]= $tep;
- }
- $list = Db::name("assoc_rela")->where([["assocNo", "=", $relainfo['assocNo']]])->select()->toArray();
- $relainfo["order_info"] = array_values($qrdinfo);;
- if ($list) {
- foreach ($list as $key => $value) {
- if ($relainfo['rela_form'] == 1) {
- $temp = Db::name("invoice_pool")->where("invNo", "=", $value['viceNo'])->find();
- $customer = Db::name("customer_info")->where("companyNo", "=", $temp['inv_in'])->find();
- $temp["companyName"] = $customer['companyName'];
- $temp["cancel_fee"] = $value['cancel_fee'];
- $relainfo["inv_info"][] = $temp;
- }
- if ($relainfo['rela_form'] == 2) {
- $temp = Db::name("trade_list")->where("traNo", "=", $value['viceNo'])->find();
- $customer = Db::name("customer_info")->where("companyNo", "=", $temp['companyNo'])->find();
- $temp["companyName"] = $customer['companyName'];
- $temp["cancel_fee"] = $value['cancel_fee'];
- $relainfo["tra_info"][] = $temp;
- }
- }
- }
- }
- if ($relainfo['type'] == 2) {
- $inv = Db::name("invoice_pool")->where("invNo", "=", $relainfo['codeNo'])->find();
- //$relainfo["tra_info"] = Db::name("trade_pool")->where("traNo","=",$relainfo['viceNo'])->find();
- $customer = Db::name("customer_info")->where("companyNo", "=", $inv['inv_in'])->find();
- $inv["companyName"] = $customer['companyName'];
- $inv["cancel_fee"] = $relainfo['cancel_total'];
- $list = Db::name("assoc_rela")->where([["assocNo", "=", $relainfo['assocNo']]])->select()->toArray();
- $relainfo["inv_info"][] = $inv;
- if ($list) {
- foreach ($list as $key => $value) {
- if ($relainfo['rela_form'] == 4) {
- $temp = Db::name("trade_list")->where("traNo", "=", $value['viceNo'])->find();
- $customer = Db::name("customer_info")->where("companyNo", "=", $temp['companyNo'])->find();
- $temp["companyName"] = $customer['companyName'];
- $temp["cancel_fee"] = $value['cancel_fee'];
- $relainfo["tra_info"][] = $temp;
- }
- }
- }
- // $customer = Db::name("customer_info")->where("companyNo","=",$relainfo["tra_info"]['companyNo'])->find();
- // $relainfo["tra_info"]["companyName"] = $customer['companyName'];
- }
- if ($relainfo['type'] == 3) {
- // $relainfo["inv_info"] = Db::name("invoice_pool")->where("invNo","=",$relainfo['mainNo'])->find();
- $tra = Db::name("trade_list")->where("traNo", "=", $relainfo['codeNo'])->find();
- $customer = Db::name("customer_info")->where("companyNo", "=", $tra['companyNo'])->find();
- $tra["companyName"] = $customer['companyName'];
- $tra["cancel_fee"] = $relainfo['cancel_total'];
- $relainfo["tra_info"][] = $tra;
- $list = Db::name("assoc_rela")->where([["assocNo", "=", $relainfo['assocNo']]])->select()->toArray();
- if ($list) {
- foreach ($list as $key => $value) {
- if ($relainfo['rela_form'] == 5) {
- $temp = Db::name("invoice_pool")->where("invNo", "=", $value['viceNo'])->find();
- $customer = Db::name("customer_info")->where("companyNo", "=", $temp['inv_in'])->find();
- $temp["companyName"] = $customer['companyName'];
- $temp["cancel_fee"] = $value['cancel_fee'];
- $relainfo["inv_info"][] = $temp;
- }
- if ($relainfo['rela_form'] == 3) {
- $temp = Db::name("order_pool")->where("orderNo", "=", $value['viceNo'])->find();
- $customer = Db::name("customer_info")->where("companyNo", "=", $temp['companyNo'])->find();
- // $temp['good']=Db::name("order_info")->where([["orderNo","=", $value['viceNo']],["status","=",1]])
- // ->select();
- $good = Db::name("order_info")->where([["orderNo", "=", $value['viceNo']], ["status", "=", 1]])->select();
- $temp['good'] = [];
- $qrdinfo = [];
- foreach ($good as $key => $val) {
- $tep = Db::name("qrd_list")->where("sequenceNo", "=", $val["goodNo"])->field("id,sequenceNo,goodname,qrdNo,goodNo,brand,unit,taxPoint,num,goldprice,weight,price,total_fee,touser,gys,kehu,apay_fee,wpay_fee,ainv_fee,winv_fee,pay_status,inv_status,inv_num")
- ->find();
- if(isset($tep["qrdNo"])&& !isset($qrdinfo[$tep["qrdNo"]])){
- $qrdinfo[$tep["qrdNo"]]= Db::name("qrd")->where("sequenceNo", "=", $tep["qrdNo"])
- ->field("id,createdTime,sequenceNo,sales_name,sales_depart,customer,total_fee,contactor,mobile,type,addr,apay_fee,wpay_fee,ainv_fee,winv_fee,pay_status,inv_status")->find();
- }
- // $tep = Db::name("qrd_list")->where("sequenceNo", "=", $value["goodNo"])->field("id,sequenceNo,goodname,goodNo,brand,unit,taxPoint,num,goldprice,weight,price,total_fee,touser,gys,kehu,apay_fee,wpay_fee,ainv_fee,winv_fee,pay_status,inv_status,inv_num")
- // ->find();
- $tep['goldprice'] = isset($tep['goldprice']) ? sprintf("%.2f", $tep['goldprice']) : "";
- $tep['price'] = isset($tep['price']) ? sprintf("%.2f", $tep['price']) : "";
- $tep['total_fee'] = isset($tep['total_fee']) ? sprintf("%.2f", $tep['total_fee']) : "";
- $tep['apay_fee'] = sprintf("%.2f", $tep['apay_fee']);
- $tep['wpay_fee'] = sprintf("%.2f", $tep['wpay_fee']);
- $tep['ainv_fee'] = sprintf("%.2f", $tep['ainv_fee']);
- $tep['winv_fee'] = sprintf("%.2f", $tep['winv_fee']);
- $tep['num'] = intval($tep['num']);
- $tep['inv_num'] = isset($tep['inv_num']) ? sprintf("%d", $tep['inv_num']) : "0";
- $qrdinfo[$tep["qrdNo"]]['good'][] = $tep;
- }
- $temp["companyName"] = $customer['companyName'];
- $temp["cancel_fee"] = $value['cancel_fee'];
- $relainfo["order_info"] = array_values($qrdinfo);
- }
- }
- }
- }
- return app_show(0, "获取成功", $relainfo);
- }
- /**
- * 显示指定的资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function list()
- {
- $post = $this->request->post();
- $token = isset($post['token']) ? trim($post['token']) : "";
- if ($token == "") {
- return error_show(101, 'token不能为空');
- }
- $effetc = VerifyTokens($token);
- if (!empty($effetc) && $effetc['code'] != 0) {
- return error_show($effetc['code'], $effetc['message']);
- }
- $condition = [['is_del', "=", 0]];
- $guserinfo =GetUserInfo($token);
- if(isset($guserinfo['code']) && $guserinfo['code']!=0){
- return error_show($guserinfo['code'],$guserinfo['message']);
- }
- $check = checkRole($guserinfo['data']['roleid'],56);
- if($check){
- $condition[]=["apply_id","=", $guserinfo['data']['id']];
- }
- // $companyNo = isset($post['tradeNo'])&&$post['tradeNo']!=""?trim($post['tradeNo']):"";
- $companyNo = isset($post['companyNo']) && $post['companyNo'] != "" ? trim($post['companyNo']) : "";
- if ($companyNo != "") {
- $condition[] = ["companyNo", "=", $companyNo];
- }
- $type = isset($post['type']) && $post['type'] != "" ? intval($post['type']) : "";
- if ($type != "") {
- $condition[] = ["rela_form", "=", $type];
- }
- $status = isset($post['status']) && $post['status'] != "" ? $post['status'] : "";
- if ($status != "") {
- $condition[] = ["status", "=", $status];
- }
- $startTime = isset($post['start']) && $post['start'] != "" ? $post['start'] : "";
- if ($startTime != "") {
- $condition[] = ["addtime", ">=", $startTime];
- }
- $endTime = isset($post['end']) && $post['end'] != "" ? $post['end'] : "";
- if ($endTime != "") {
- $condition[] = ["addtime", "<=", $endTime];
- }
- $assocNo = isset($post['assocNo']) && $post['assocNo'] != "" ? trim($post['assocNo']) : "";
- if ($assocNo != "") {
- $condition[] = ["assocNo", "like", "%{$assocNo}%"];
- }
- $codeNo = isset($post['codeNo']) && $post['codeNo'] != "" ? trim($post['codeNo']) : "";
- $codeType = isset($post['codeType']) && $post['codeType'] != "" ? intval($post['codeType']) : "";
- if($codeType==1){
- if ($codeNo != "") {
- $condition[]=['rela_form',"in",[1,2,3]];
- $order = Db::name("order_info")->where("qrdNo", "like", "%{$codeNo}%")->column("orderNo");
- $accoslist = Db::name("assoc_list")->where('codeNo|viceNo',"in",$order)->column('assocNo');
- $condition[]=['assocNo',"in",$accoslist];
- }
- }else if($codeType==2){
- if ($codeNo != "") {
- $condition[]=['rela_form',"in",[1,4,5]];
- $accoslist = Db::name("assoc_list")->where("(codeNo='{$codeNo}' and rela_form=4) or (viceNo='{$codeNo}' and rela_form in (1,5))")->column('assocNo');
- $condition[]=['assocNo',"in",$accoslist];
- }
- }else if($codeType==3){
- if ($codeNo != "") {
- $condition[]=['rela_form',"in",[2,3,4,5]];
- $accoslist = Db::name("assoc_list")->where("(viceNo='{$codeNo}' and rela_form in (2,4)) or (codeNo='{$codeNo}' and rela_form in (3,5))")->column('assocNo');
- $condition[]=['assocNo',"in",$accoslist];
- }
- }
- $page = isset($post['page']) && $post['page'] != "" ? intval($post['page']) : 1;
- $size = isset($post['size']) && $post['size'] != "" ? intval($post['size']) : 10;
- $count = Db::name("assoc_key")->where("source=1 or (source=2 and status=3)")->where($condition)->count();
- $total = ceil($count / $size) > 1 ? ceil($count / $size) : 1;
- $page = $page >= $total ? intval($total) : $page;
- $list = Db::name("assoc_key")->where("source=1 or (source=2 and status=3)")->where($condition)->order("addtime desc")->page(intval($page), $size)->select();
- $data = [];
- foreach ($list as $key => $value) {
- $temp = [];
- $customer = Db::name("customer_info")->where("companyNo", "=", $value['companyNo'])->find();
- $temp["id"] = $value['id'];
- $temp["assocNo"] = $value['assocNo'];
- $temp["status"] = $value['status'];
- $temp["cancel_total"] = $value['cancel_total'];
- $temp["is_source"] = $value['source'];
- $temp["rela_form"] = $value['rela_form'];
- $temp["exam_remark"] = $value['exam_remark'];
- $temp["companyNo"] = $value['companyNo'];
- $temp["companyName"] = isset($customer['companyName']) ? $customer['companyName'] : "";
- $temp["addtime"] = $value['addtime'];
- if ($value['type'] == 1) {
- $ordercp = Db::name("order_info")->where([["orderNo","=",$value['codeNo']],["status","=",1]])
- ->column("qrdNo");
- $temp["orderNo"] = implode(",", array_unique($ordercp));
- // $temp["orderNo"] = $value['codeNo'];
- $temp["order_fee"] = $value['balance'];
- $temp["total_fee"] = $value['total_fee'];
- if ($value["rela_form"] == 1) {
- $inv = Db::name("assoc_rela")->where("assocNo", "=", $value["assocNo"])->column("viceNo");
- $temp["invNo"] = implode(",", $inv);
- $temp["traNo"] = "";
- $temp["inv_fee"] = "";
- $temp["tra_fee"] = "";
- }
- if ($value["rela_form"] == 2) {
- $trade = Db::name("assoc_rela")->where("assocNo", "=", $value["assocNo"])->column("viceNo");
- $temp["traNo"] = implode(",", $trade);
- $temp["invNo"] = "";
- $temp["tra_fee"] = "";
- $temp["inv_fee"] = "";
- }
- }
- if ($value['type'] == 2) {
- $temp["invNo"] = $value['codeNo'];
- $temp["inv_fee"] = $value['balance'];
- $temp["total_fee"] = $value['total_fee'];
- if ($value["rela_form"] == 4) {
- $trade = Db::name("assoc_rela")->where("assocNo", "=", $value["assocNo"])->column("viceNo");
- $temp["traNo"] = implode(",", $trade);
- $temp["tra_fee"] = "";
- $temp["order_fee"] = "";
- $temp["orderNo"] = "";
- }
- }
- if ($value['type'] == 3) {
- $temp["tra_fee"] = $value['balance'];
- $temp["total_fee"] = $value['total_fee'];
- $temp["traNo"] = $value['codeNo'];
- if ($value["rela_form"] == 3) {
- $order = Db::name("assoc_rela")->where("assocNo", "=", $value["assocNo"])->column("viceNo");
- $ordercp =[];
- if($order){
- $ordercp = Db::name("order_info")->where([["orderNo","in",$order],["status","=",1]])->column("qrdNo");
- }
- $temp["orderNo"] = implode(",", array_unique($ordercp) );
- $temp["invNo"] = "";
- $temp["inv_fee"] = "";
- $temp["order_fee"] = "";
- }
- if ($value["rela_form"] == 5) {
- $inv = Db::name("assoc_rela")->where("assocNo", "=", $value["assocNo"])->column("viceNo");
- $temp["invNo"] = implode(",", $inv);
- $temp["inv_fee"] = "";
- $temp["order_fee"] = "";
- $temp["orderNo"] = "";
- }
- }
- $data[] = $temp;
- }
- return app_show(0, "获取成功", ["list" => $data, "count" => $count]);
- }
- /**
- * 显示编辑资源表单页.
- *
- * @param int $id
- * @return \think\Response
- */
- public function edit()
- {
- $post = $this->request->post();
- $token = isset($post['token']) ? trim($post['token']) : "";
- if ($token == "") {
- return error_show(101, 'token不能为空');
- }
- $effetc = VerifyTokens($token);
- if (!empty($effetc) && $effetc['code'] != 0) {
- return error_show($effetc['code'], $effetc['message']);
- }
- $status = isset($post['status']) && $post['status'] != "" ? $post['status'] : "";
- if ($status == "") {
- return error_show(1003, "参数status 不能为空");
- }
- $id = isset($post['id']) && $post['id'] != "" ? $post['id'] : "";
- if ($id == "") {
- return error_show(1004, "参数id 不能为空");
- }
- $remark = isset($post['remark']) && $post['remark'] ? $post['remark'] : "";
- Db::startTrans();
- $assinfo = Db::name("assoc_key")->where([['id', "=", $id], ["is_del", "=", 0]])->lock(true)->find();
- if (!$assinfo) {
- Db::rollback();
- return error_show(1004, "未找到关联数据");
- }
- if ($assinfo["status"] == 3) {
- Db::rollback();
- return error_show(1004, "关联关系已通过审核");
- }
- try {
- $temp=[];
- $temp['status'] = $status;
- $temp['exam_remark'] = $remark;
- $temp['updatetime'] = date("Y-m-d H:i:s");
- $upadte = Db::name("assoc_key")->where($assinfo)->save($temp);
- if ($status == 3) {
- $list = Db::name("assoc_rela")->where("assocNo", "=", $assinfo["assocNo"])->select();
- if ($upadte) {
- $orderinfo = "";
- $invinfo = "";
- $trainfo = "";
- if ($assinfo['type'] == 1) {
- $orderinfo = Db::name("order_pool")->where("orderNo", "=", $assinfo['codeNo'])->find();
- if ($assinfo['rela_form'] == 1) {
- $invinfo = [];
- foreach ($list as $value) {
- $temp = Db::name("invoice_pool")->where([["is_del", "=", 0], ["invNo", "=",$value["viceNo"]]])->find();
- $temp['aorder_fee'] += $value['cancel_fee'];
- $temp['order_used'] -= $value['cancel_fee'];
- $temp['order_status'] = $temp['worder_fee'] == 0 ? 3 : 2;
- $temp['updatetime'] = date("Y-m-d H:i:s");
- $invinfo[] = $temp;
- }
- }
- if ($assinfo['rela_form'] == 2) {
- $trainfo = [];
- foreach ($list as $value) {
- $temp = Db::name("trade_pool")->where([["is_del", "=", 0], ["traNo", "=",
- $value["viceNo"]]])->find();
- $temp['order_fee'] += $value['cancel_fee'];
- $temp['order_used'] -= $value['cancel_fee'];
- $temp['order_status'] = $temp['worder_fee'] == 0 ? 3 : 2;
- $temp['updatetime'] = date("Y-m-d H:i:s");
- $trainfo[] = $temp;
- }
- }
- }
- if ($assinfo['type'] == 2) {
- $invinfo = Db::name("invoice_pool")->where("invNo", "=", $assinfo['codeNo'])->find();
- if ($assinfo['rela_form'] == 4) {
- $trainfo = [];
- foreach ($list as $value) {
- $temp = Db::name("trade_pool")->where([["is_del", "=", 0], ["traNo", "=",
- $value["viceNo"]]])->find();
- $temp['inv_fee'] += $value['cancel_fee'];
- $temp['inv_used'] -= $value['cancel_fee'];
- $temp['inv_status'] = $temp['winv_fee'] == 0 ? 3 : 2;
- $temp['updatetime'] = date("Y-m-d H:i:s");
- $trainfo[] = $temp;
- }
- }
- }
- if ($assinfo['type'] == 3) {
- // $invinfo = Db::name("invoice_pool")->where("invNo","=",$assinfo['mainNo'])->find();
- $trainfo = Db::name("trade_pool")->where("traNo", "=", $assinfo['codeNo'])->find();
- $ty = Db::name("trade_log")->where("logNo","=",$trainfo['logNo'])->find();
- if ($assinfo['rela_form'] == 3) {
- $orderinfo = [];
- foreach ($list as $value) {
- $temp = Db::name("order_pool")->where([["is_del", "=", 0], ["orderNo", "=",
- $value["viceNo"]]])->find();
- $temp['fund_fee'] += $value['cancel_fee'];
- $temp['fund_used'] -= $value['cancel_fee'];
- $temp['fund_status'] = $temp['wfund_fee'] == 0 ? 3 : 2;
- $temp['updatetime'] = date("Y-m-d H:i:s");
- $ipdate=$this->qrd_sure($temp["orderNo"],$value['cancel_fee']);
- if(!$ipdate){
- Db::rollback();
- return error_show(1004,"审核失败");
- }
- $orderinfo[] = $temp;
- }
- }
- if ($assinfo['rela_form'] == 5) {
- $invinfo = [];
- foreach ($list as $value) {
- $temp = Db::name("invoice_pool")->where([["is_del", "=", 0], ["invNo", "=",
- $value["viceNo"]]])->find();
- if($ty['trade_type']==1){
- $temp['wtrade_fee'] += $value['cancel_fee'];
- $temp['fund_used'] -= $value['cancel_fee'];
- $temp['trade_status'] = $temp['wtrade_fee'] == 0 ? 3 : 2;
- $temp['updatetime'] = date("Y-m-d H:i:s");
- }else{
- $temp['atrade_fee'] += $value['cancel_fee'];
- $temp['fund_used'] -= $value['cancel_fee'];
- $temp['trade_status'] = $temp['wtrade_fee'] == 0 ? 3 : 2;
- $temp['updatetime'] = date("Y-m-d H:i:s");
- }
- $invinfo[] = $temp;
- }
- }
- }
- if ($orderinfo) {
- if ($assinfo['rela_form'] == 1) {
- $orderinfo['inv_fee'] += $assinfo['cancel_total'];
- $orderinfo['inv_used'] -= $assinfo['cancel_total'];
- $orderinfo['inv_status'] = $orderinfo['winv_fee'] == 0 ? 3 : 2;
- $orderinfo['updatetime'] = date("Y-m-d H:i:s");
- Db::name("order_pool")->save($orderinfo);
- $ipdate=$this->qrd_sure_inv($orderinfo ["orderNo"],$assinfo['cancel_total']);
- if(!$ipdate){
- Db::rollback();
- return error_show(1004,"审核失败");
- }
- }
- if ($assinfo['rela_form'] == 2) {
- $orderinfo['fund_fee'] += $assinfo['cancel_total'];
- $orderinfo['fund_used'] -= $assinfo['cancel_total'];
- $orderinfo['fund_status'] = $orderinfo['wfund_fee'] == 0 ? 3 : 2;
- $orderinfo['updatetime'] = date("Y-m-d H:i:s");
- Db::name("order_pool")->save($orderinfo);
- $ipdate=$this->qrd_sure($orderinfo ["orderNo"],$assinfo['cancel_total']);
- if(!$ipdate){
- Db::rollback();
- return error_show(1004,"审核失败");
- }
- }
- if ($assinfo['type'] == 3) {
- foreach ($orderinfo as $value) {
- Db::name("order_pool")->save($value);
- }
- }
- }
- if ($invinfo) {
- if ($assinfo["type"] == 2) {
- $invinfo["atrade_fee"] += $assinfo['cancel_total'];
- $invinfo["fund_used"] -= $assinfo['cancel_total'];
- $invinfo["trade_status"] = $invinfo["wtrade_fee"] == 0 ? 3 : 2;
- $invinfo['updatetime'] = date("Y-m-d H:i:s");
- Db::name("invoice_pool")->save($invinfo);
- } else {
- foreach ($invinfo as $value) {
- Db::name("invoice_pool")->save($value);
- }
- }
- }
- if ($trainfo) {
- if ($assinfo['rela_form'] == 3) {
- $trainfo['order_fee'] += $assinfo['cancel_total'];
- $trainfo['order_used'] -= $assinfo['cancel_total'];
- $trainfo['order_status'] = $trainfo['worder_fee'] == 0 ? 3 : 2;
- $trainfo['updatetime'] = date("Y-m-d H:i:s");
- Db::name("trade_pool")->save($trainfo);
- }
- if ($assinfo['rela_form'] == 5) {
- $trainfo['inv_fee'] += $assinfo['cancel_total'];
- $trainfo['inv_used'] -= $assinfo['cancel_total'];
- $trainfo['inv_status'] = $trainfo['winv_fee'] == 0 ? 3 : 2;
- $trainfo['updatetime'] = date("Y-m-d H:i:s");
- Db::name("trade_pool")->save($trainfo);
- }
- if ($assinfo["rela_form"] == 2 || $assinfo["rela_form"] == 4) {
- foreach ($trainfo as $value) {
- Db::name("trade_pool")->save($value);
- }
- }
- }
- Db::commit();
- return app_show(0, "审核通过");
- }
- Db::rollback();
- return app_show(1005, "审核失败");
- }
- if ($status == 2) {
- Db::commit();
- return app_show(0, "审核未通过");
- }
- } catch (\Exception $e) {
- Db::rollback();
- return error_show(1005, $e->getMessage());
- }
- }
- /**
- * 保存更新的资源
- *
- * @param \think\Request $request
- * @param int $id
- * @return \think\Response
- */
- public function update(Request $request, $id)
- {
- //
- }
- /**
- * 删除指定资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function delete()
- {
- $post = $this->request->post();
- $token = isset($post['token']) ? trim($post['token']) : "";
- if ($token == "") {
- return error_show(101, 'token不能为空');
- }
- $effetc = VerifyTokens($token);
- if (!empty($effetc) && $effetc['code'] != 0) {
- return error_show($effetc['code'], $effetc['message']);
- }
- $id = isset($post['id']) && $post['id'] != "" ? $post['id'] : "";
- if ($id == "") {
- return error_show(1004, "参数id 不能为空");
- }
- $assinfo = Db::name("assoc_key")->where([['id', "=", $id], ["is_del", "=", 0]])->find();
- if (!$assinfo) {
- return error_show(1004, "未找到关联数据");
- }
- if ($assinfo['status'] == 3) {
- return error_show(1004, "数据已通过审核无法取消");
- }
- Db::startTrans();
- try {
- $assinfo['is_del'] = 1;
- $assinfo['updatetime'] = date("Y-m-d H:i:s");
- $upadte = Db::name("assoc_key")->save($assinfo);
- $list = Db::name("assoc_rela")->where("assocNo", "=", $assinfo["assocNo"])->select()->toArray();
- if ($upadte) {
- $orderinfo = "";
- $invinfo = "";
- $trainfo = "";
- if ($assinfo['type'] == 1) {
- $orderinfo = Db::name("order_pool")->where("orderNo", "=", $assinfo['codeNo'])->find();
- if ($assinfo['rela_form'] == 1) {
- $invinfo = [];
- foreach ($list as $value) {
- $temp = Db::name("invoice_pool")->where([["is_del", "=", 0], ["invNo", "=",
- $value["viceNo"]]])->find();
- $temp['worder_fee'] += $value['cancel_fee'];
- $temp['order_used'] -= $value['cancel_fee'];
- $temp['order_status'] = $temp['worder_fee'] ==$temp['inv_value'] ? 1: 2;
- $temp['updatetime'] = date("Y-m-d H:i:s");
- $invinfo[] = $temp;
- }
- }
- if ($assinfo['rela_form'] == 2) {
- $trainfo = [];
- foreach ($list as $value) {
- $temp = Db::name("trade_pool")->where([["is_del", "=", 0], ["traNo", "=",
- $value["viceNo"]]])->find();
- $temp['worder_fee'] += $value['cancel_fee'];
- $temp['order_used'] -= $value['cancel_fee'];
- $temp['order_status'] = $temp['worder_fee'] == $temp['total_fee'] ? 1 : 2;
- $temp['updatetime'] = date("Y-m-d H:i:s");
- $trainfo[] = $temp;
- }
- }
- }
- if ($assinfo['type'] == 2) {
- $invinfo = Db::name("invoice_pool")->where("invNo", "=", $assinfo['codeNo'])->find();
- if ($assinfo['rela_form'] == 4) {
- $trainfo = [];
- foreach ($list as $value) {
- $temp = Db::name("trade_pool")->where([["is_del", "=", 0], ["traNo", "=",
- $value["viceNo"]]])->find();
- $temp['winv_fee'] += $value['cancel_fee'];
- $temp['inv_used'] -= $value['cancel_fee'];
- $temp['inv_status'] = $temp['winv_fee'] ==$temp['total_fee'] ? 1 : 2;
- $temp['updatetime'] = date("Y-m-d H:i:s");
- $trainfo[] = $temp;
- }
- }
- }
- if ($assinfo['type'] == 3) {
- // $invinfo = Db::name("invoice_pool")->where("invNo","=",$assinfo['mainNo'])->find();
- $trainfo = Db::name("trade_pool")->where("traNo", "=", $assinfo['codeNo'])->find();
- if ($assinfo['rela_form'] == 3) {
- $orderinfo = [];
- foreach ($list as $value) {
- $temp = Db::name("order_pool")->where([["is_del", "=", 0], ["orderNo", "=",
- $value["viceNo"]]])->find();
- $temp['wfund_fee'] += $value['cancel_fee'];
- $temp['fund_used'] -= $value['cancel_fee'];
- $temp['fund_status'] = $temp['wfund_fee'] == $temp['total_amount'] ? 1 : 2;
- $temp['updatetime'] = date("Y-m-d H:i:s");
- $del= $this->qrd_delet($temp['orderNo'],$value['cancel_fee']);
- if(!$del){
- Db::rollback();
- return app_show(1005, "核销申请取消失败");
- }
- $orderinfo[] = $temp;
- }
- }
- if ($assinfo['rela_form'] == 5) {
- $invinfo = [];
- foreach ($list as $value) {
- $temp = Db::name("invoice_pool")->where([["is_del", "=", 0], ["invNo", "=",
- $value["viceNo"]]])->find();
- $temp['wtrade_fee'] += $value['cancel_fee'];
- $temp['fund_used'] -= $value['cancel_fee'];
- $temp['trade_status'] = $temp['wtrade_fee'] ==$temp['inv_value'] ? 1: 2;
- $temp['updatetime'] = date("Y-m-d H:i:s");
- $invinfo[] = $temp;
- }
- }
- }
- if ($orderinfo) {
- if ($assinfo['rela_form'] == 1) {
- $orderinfo['winv_fee'] += $assinfo['cancel_total'];
- $orderinfo['inv_used'] -= $assinfo['cancel_total'];
- $orderinfo['inv_status'] = $orderinfo['winv_fee'] ==$orderinfo['total_amount'] ? 1 : 2;
- $orderinfo['updatetime'] = date("Y-m-d H:i:s");
- Db::name("order_pool")->save($orderinfo);
- $del= $this->qrd_delet_inv($orderinfo['orderNo'],$assinfo['cancel_total']);
- if(!$del){
- Db::rollback();
- return app_show(1005, "核销申请取消失败");
- }
- }
- if ($assinfo['rela_form'] == 2) {
- $orderinfo['wfund_fee'] += $assinfo['cancel_total'];
- $orderinfo['fund_used'] -= $assinfo['cancel_total'];
- $orderinfo['fund_status'] = $orderinfo['wfund_fee']==$orderinfo['total_amount'] ? 1 : 2;
- $orderinfo['updatetime'] = date("Y-m-d H:i:s");
- Db::name("order_pool")->save($orderinfo);
- $del= $this->qrd_delet($orderinfo['orderNo'],$assinfo['cancel_total']);
- if(!$del){
- Db::rollback();
- return app_show(1005, "核销申请取消失败");
- }
- }
- if ($assinfo['type'] == 3) {
- foreach ($orderinfo as $value) {
- Db::name("order_pool")->save($value);
- }
- }
- }
- if ($invinfo) {
- if ($assinfo["type"] == 2) {
- $invinfo["wtrade_fee"] += $assinfo['cancel_total'];
- $invinfo["fund_used"] -= $assinfo['cancel_total'];
- $invinfo["trade_status"] = $invinfo["wtrade_fee"] ==$invinfo['inv_value'] ? 1 : 2;
- $invinfo['updatetime'] = date("Y-m-d H:i:s");
- Db::name("invoice_pool")->save($invinfo);
- } else {
- foreach ($invinfo as $value) {
- Db::name("invoice_pool")->save($value);
- }
- }
- }
- if ($trainfo) {
- if ($assinfo['rela_form'] == 3) {
- $trainfo['worder_fee'] += $assinfo['cancel_total'];
- $trainfo['order_used'] -= $assinfo['cancel_total'];
- $trainfo['order_status'] = $trainfo['worder_fee'] ==$trainfo['total_fee'] ? 1 : 2;
- $trainfo['updatetime'] = date("Y-m-d H:i:s");
- Db::name("trade_pool")->save($trainfo);
- }
- if ($assinfo['rela_form'] == 5) {
- $trainfo['winv_fee'] += $assinfo['cancel_total'];
- $trainfo['inv_used'] -= $assinfo['cancel_total'];
- $trainfo['inv_status'] = $trainfo['winv_fee']==$trainfo['total_fee'] ? 1 : 2;
- $trainfo['updatetime'] = date("Y-m-d H:i:s");
- Db::name("trade_pool")->save($trainfo);
- }
- if ($assinfo["rela_form"] == 2 || $assinfo["rela_form"] == 4) {
- foreach ($trainfo as $value) {
- Db::name("trade_pool")->save($value);
- }
- }
- }
- Db::commit();
- return app_show(0, "核销申请取消成功");
- }
- Db::rollback();
- return app_show(1005, "核销申请取消失败");
- } catch (\Exception $e) {
- Db::rollback();
- return error_show(1005, $e->getMessage());
- }
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function GetList()
- {
- $post = $this->request->post();
- $token = isset($post['token']) ? trim($post['token']) : "";
- if ($token == "") {
- return error_show(101, 'token不能为空');
- }
- $effetc = VerifyTokens($token);
- if (!empty($effetc) && $effetc['code'] != 0) {
- return error_show($effetc['code'], $effetc['message']);
- }
- $condition = [['is_del', "=", 0],['status',"=",3]];
- $guserinfo =GetUserInfo($token);
- if(isset($guserinfo['code']) && $guserinfo['code']!=0){
- return error_show($guserinfo['code'],$guserinfo['message']);
- }
- $check = checkRole($guserinfo['data']['roleid'],57);
- if($check){
- $condition[]=["apply_id","=", $guserinfo['data']['id']];
- }
- // $companyNo = isset($post['tradeNo'])&&$post['tradeNo']!=""?trim($post['tradeNo']):"";
- $companyNo = isset($post['companyNo']) && $post['companyNo'] != "" ? trim($post['companyNo']) : "";
- $codeNo = isset($post['codeNo']) && $post['codeNo'] != "" ? trim($post['codeNo']) : "";
- $assocNo = isset($post['assocNo']) && $post['assocNo'] != "" ? trim($post['assocNo']) : "";
- $type = isset($post['type']) && $post['type'] != "" ? intval($post['type']) : 1;
- $page = isset($post['page']) && $post['page'] != "" ? intval($post['page']) : 1;
- $size = isset($post['size']) && $post['size'] != "" ? intval($post['size']) : 10;
- if ($companyNo != "") {
- $condition[] = ["companyNo", "=", $companyNo];
- }
- // $condition[] = ["type", "=", $type];
- if($type==1){
- $field = Db::raw("if(type=1,codeNo,if(type=3,viceNo,'')) as keyno");
- $condition[]=['rela_form',"in",[1,2,3]];
- if ($codeNo != "") {
- $order = Db::name("order_info")->alias('a')->leftJoin("cfp_order_pool b","a.orderNo=b.orderNo and b.is_del=0")
- ->where("qrdNo","like","%{$codeNo}%")->column("a.orderNo");
- $condition[]=['codeNo|viceNo',"in",$order];
- }
- }else{
- if ($codeNo != "") {
- $condition[] = ["codeNo|viceNo", "like", "%{$codeNo}%"];
- }
- }
- if($type==2){
- $field = Db::raw("if(type=2,codeNo,if(type<>2,viceNo,'')) as keyno");
- $condition[]=['rela_form',"in",[1,4,5]];
- }
- if($type==3){
- $field = Db::raw("if(type=3,codeNo,if(type<>3,viceNo,'')) as keyno");
- $condition[]=['rela_form',"in",[2,3,4,5]];
- }
- $count = Db::name("assoc_list")->where($condition)->field("{$field}")->group("keyno")->count();
- $total = ceil($count / $size) > 1 ? ceil($count / $size) : 1;
- $page = $page >= $total ? intval($total) : $page;
- $list = Db::name("assoc_list")->where($condition)->field("{$field}")
- ->page(intval($page), $size)->group("keyno")->select();
- $data = [];
- foreach ($list as $value) {
- $data[] = $this->GetRela($type,$value['keyno']);
- }
- return app_show(0, "获取成功", ["list" => $data, "count" => $count]);
- }
- /**
- * @param int $type
- * @param $mainNo
- * @return array[]
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- private function GetRela($type,$assoc)
- {
- $condition = [["is_del", "=", 0]];
- $data = ["orderinfo" => [], "invinfo" => [], "tradeinfo" => [],"dashd"=>""];
- $order = [];
- $inv = [];
- $trad = [];
- $assocall = Db::name("assoc_list")->where([["is_del","=",0],['status',"=",3],['bstatus',"=",1],["codeNo|viceNo", "=",$assoc]])->select()->toArray();
- if ($type == 1) {
-
- if(!empty($assocall)){
- $condition[] = ["orderNo", "=", $assoc];
- $order[] = Db::name("order_pool")->where($condition)->field("orderNo,companyNo,sales_id,sales_name,total_amount,inv_status,fund_status,fund_fee,inv_fee,wfund_fee,winv_fee,addtime")->find();
- isset($orderdat) ?$order[]=$orderdat :'';
- foreach ($assocall as $value){
- if ($value["rela_form"] == 1) {
- $inv[] = Db::name("invoice_pool")->where("invNo", "=", $value["viceNo"])->field("invNo,inv_in,apply_id,apply_name,inv_value,trade_status,order_status,aorder_fee,atrade_fee,worder_fee,wtrade_fee,addtime,refund_status")->find();
- }
- if ($value["rela_form"] == 2) {
- $trad[] = Db::name("trade_list")->where("traNo", "=", $value["viceNo"])->field("traNo,companyNo,trade_out,trade_in,total_fee,inv_status,order_status,order_fee,inv_fee,worder_fee,winv_fee,addtime,refund_status")->find();
- }
- if($value["rela_form"] == 3){
- $trad[] = Db::name("trade_list")->where("traNo", "=", $value["codeNo"])->field("traNo,companyNo,trade_out,trade_in,total_fee,inv_status,order_status,order_fee,inv_fee,worder_fee,winv_fee,addtime,refund_status")->find();
- }
- }
- }
- }
- if ($type== 2) {
- $condition[] = ["invNo", "=", $assoc];
- $inv[] = Db::name("invoice_pool")->where($condition)->field("invNo,inv_in,apply_id,apply_name,inv_value,trade_status,order_status,aorder_fee,atrade_fee,worder_fee,wtrade_fee,refund_status,addtime")->find();
- if(!empty($assocall)){
- foreach ($assocall as $value){
- if ($value["rela_form"] == 1) {
- $order[] = Db::name("order_pool")->where("orderNo", "=", $value["codeNo"])->field("orderNo,companyNo,sales_id,sales_name,total_amount,inv_status,fund_status,fund_fee,inv_fee,wfund_fee,winv_fee,addtime")->find();
- }
- if ($value["rela_form"] == 4) {
- $trad[] = Db::name("trade_list")->where("traNo", "=", $value["viceNo"])->field("traNo,companyNo,trade_out,trade_in,total_fee,inv_status,order_status,order_fee,inv_fee,worder_fee,winv_fee,refund_status,addtime")->find();
- }
- if($value["rela_form"] == 5){
- $trad[] = Db::name("trade_list")->where("traNo", "=", $value["codeNo"])->field("traNo,companyNo,trade_out,trade_in,total_fee,inv_status,order_status,order_fee,inv_fee,worder_fee,winv_fee,refund_status,addtime")->find();
- }
- }
- }
- }
- if ($type== 3) {
- $condition[] = ["traNo", "=", $assoc];
- $trad[] = Db::name("trade_list")->where($condition)->field("traNo,companyNo,trade_out,trade_in,total_fee,inv_status,order_status,order_fee,inv_fee,worder_fee,winv_fee,refund_status,addtime")->find();
- if(!empty($assocall)){
- foreach ($assocall as $value){
- if ($value["rela_form"] == 2) {
- $order[] = Db::name("order_pool")->where("orderNo", "=", $value["codeNo"])->field("orderNo,companyNo,sales_id,sales_name,total_amount,inv_status,fund_status,fund_fee,inv_fee,wfund_fee,winv_fee,addtime")->find();
- }
- if ($value["rela_form"] == 3) {
- $order[] = Db::name("order_pool")->where("orderNo", "=", $value["viceNo"])->field("orderNo,companyNo,sales_id,sales_name,total_amount,inv_status,fund_status,fund_fee,inv_fee,wfund_fee,winv_fee,addtime")->find();
- }
- if ($value["rela_form"] == 4) {
- $inv[] = Db::name("invoice_pool")->where("invNo", "=", $value["codeNo"])->field("invNo,inv_in,apply_id,apply_name,inv_value,trade_status,order_status,aorder_fee,atrade_fee,worder_fee,wtrade_fee,refund_status,addtime")->find();
- }
- if($value["rela_form"] == 5){
- $inv[] = Db::name("invoice_pool")->where("invNo", "=", $value["viceNo"])->field("invNo,inv_in,apply_id,apply_name,inv_value,trade_status,order_status,aorder_fee,atrade_fee,worder_fee,wtrade_fee,refund_status,addtime")->find();
- }
- }
- }
- }
- if (!empty($order)) {
- foreach ($order as $val){
- $good = Db::name("order_info")->where([["orderNo", "=", $val['orderNo']], ["status", "=", 1]])
- ->select();
- $val['good'] = [];
- $orderno = [];
- foreach ($good as $key => $value) {
- $tep = Db::name("qrd_list")->where("sequenceNo", "=", $value["goodNo"])->field("id,sequenceNo,goodname,goodNo,brand,unit,taxPoint,num,goldprice,weight,price,total_fee,touser,gys,kehu,apay_fee,wpay_fee,ainv_fee,winv_fee,pay_status,inv_status,inv_num")
- ->find();
- $tep['goldprice'] = isset($tep['goldprice']) ? sprintf("%.2f", $tep['goldprice']) : "";
- $tep['price'] = isset($tep['price']) ? sprintf("%.2f", $tep['price']) : "";
- $tep['total_fee'] = isset($tep['total_fee']) ? sprintf("%.2f", $tep['total_fee']) : "";
- $tep['apay_fee'] = sprintf("%.2f", $tep['apay_fee']);
- $tep['wpay_fee'] = sprintf("%.2f", $tep['wpay_fee']);
- $tep['ainv_fee'] = sprintf("%.2f", $tep['ainv_fee']);
- $tep['winv_fee'] = sprintf("%.2f", $tep['winv_fee']);
- $tep['num'] = intval($tep['num']);
- $tep['inv_num'] = isset($tep['inv_num']) ? sprintf("%d", $tep['inv_num']) : "0";
- $val['good'][] = $tep;
- $orderno[$value['qrdNo']]['qrdNo']=$value['qrdNo'];
- isset($orderno[$value['qrdNo']]['total_fee']) ? $orderno[$value['qrdNo']]['total_fee']+=$value['total_fee'] : $orderno[$value['qrdNo']]['total_fee']=$value['total_fee'];
- isset($orderno[$value['qrdNo']]['afund_fee']) ? $orderno[$value['qrdNo']]['afund_fee']+=$value['afund_fee'] : $orderno[$value['qrdNo']]['afund_fee']=$value['afund_fee'];
- isset($orderno[$value['qrdNo']]['ainv_fee']) ? $orderno[$value['qrdNo']]['ainv_fee']+=$value['ainv_fee'] : $orderno[$value['qrdNo']]['ainv_fee']=$value['ainv_fee'];
- isset($orderno[$value['qrdNo']]['wfund_fee']) ? $orderno[$value['qrdNo']]['wfund_fee']+=$value['wfund_fee'] : $orderno[$value['qrdNo']]['wfund_fee']=$value['wfund_fee'];
- isset($orderno[$value['qrdNo']]['winv_fee']) ? $orderno[$value['qrdNo']]['winv_fee']+=$value['winv_fee'] : $orderno[$value['qrdNo']]['winv_fee']=$value['winv_fee'];
- isset($orderno[$value['qrdNo']]['inv_fee']) ? $orderno[$value['qrdNo']]['inv_fee']+=$value['winv_fee'] : $orderno[$value['qrdNo']]['inv_fee']=$value['inv_fee'];
- isset($orderno[$value['qrdNo']]['fund_fee']) ? $orderno[$value['qrdNo']]['fund_fee']+=$value['fund_fee'] : $orderno[$value['qrdNo']]['fund_fee']=$value['fund_fee'];
- }
- array_walk($orderno,function (&$value){
- $value['total_fee'] = round( $value['total_fee'],2);
- $value['afund_fee'] = round( $value['afund_fee'],2);
- $value['ainv_fee'] = round( $value['ainv_fee'],2);
- $value['wfund_fee'] = round( $value['wfund_fee'],2);
- $value['winv_fee'] = round( $value['winv_fee'],2);
- $value['inv_fee'] = round( $value['inv_fee'],2);
- $value['fund_fee'] = round( $value['fund_fee'],2);
- });
- $customer = Db::name("customer_info")->where("companyNo", "=", $val['companyNo'])->find();
- $val["companyName"] = $customer['companyName'];
- $val["qrdNo"] = array_values($orderno);
- $data["orderinfo"][] = $val;
- }
- }else{
- $data['dashd']="orderinfo";
- }
- if (!empty($inv)) {
- foreach ($inv as $val){
- $customer = Db::name("customer_info")->where("companyNo", "=", $val['inv_in'])->find();
- $val["companyName"] = $customer['companyName'];
- $data['invinfo'][] = $val;
- }
- }else{
- $data['dashd']="invinfo";
- }
- if (!empty($trad)) {
- foreach ($trad as $val){
- $customer = Db::name("customer_info")->where("companyNo", "=", $val['companyNo'])->find();
- $val["companyName"] = $customer['companyName'];
- $data['tradeinfo'][] = $val;
- }
- }else{
- $data['dashd']="tradeinfo";
- }
- return $data;
- }
- public function GetRelaList()
- {
- $post = $this->request->post();
- $token = isset($post['token']) ? trim($post['token']) : "";
- if ($token == "") {
- return error_show(101, 'token不能为空');
- }
- $effetc = VerifyTokens($token);
- if (!empty($effetc) && $effetc['code'] != 0) {
- return error_show($effetc['code'], $effetc['message']);
- }
- $type = isset($post['type']) && $post["type"] != "" ? intval($post['type']) : 1;
- $codeNo = isset($post['codeNo']) && $post['codeNo'] != "" ? trim($post['codeNo']) : "";
- if ($codeNo == "") {
- return error_show(1004, "参数codeNo 不能为空");
- }
- $condition = [["is_del", "=", "0"],['status',"=",3], ["codeNo|viceNo", "=", $codeNo]];
- $list = Db::name("assoc_list")->where( $condition)->field("id,codeNo,total_fee,balance,type,rela_form,cancel_total,viceNo,vice_total,vice_fee,cancel_fee,addtime,bstatus")
- ->select();
- $data=[];
- foreach ($list as $value){
- $value['qrdNo'] =[];
- if($value['type']==1){
- $order = Db::name("order_info")->where([["orderNo","=",$value['codeNo']],['status',"=",1]])
- ->field("sum(total_fee) as total_fee,sum(wfund_fee) as wfund_fee,sum(fund_fee) as fund_fee,sum(afund_fee) as afund_fee, sum(ainv_fee) as ainv_fee,sum(inv_fee) as inv_fee,sum(winv_fee) as winv_fee,qrdNo")->group('qrdNo')->select()->toArray();
- $value['qrdNo'] = $order;
- }
- if($value['rela_form']==3){
- $order = Db::name("order_info")->where([["orderNo","=",$value['viceNo']],['status',"=",1]])
- ->field("sum(total_fee) as total_fee,sum(wfund_fee) as wfund_fee,sum(fund_fee) as fund_fee,sum(afund_fee) as afund_fee, sum(ainv_fee) as ainv_fee,sum(inv_fee) as inv_fee,sum(winv_fee) as winv_fee,qrdNo")->group('qrdNo')->select()->toArray();
- $value['qrdNo'] = $order;
- }
- $data[]=$value;
- }
- return app_show(0, "获取成功", $data);
- }
- /**
- * @param $orderNo
- * @param $balance
- * @return bool
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- private function updateQrd($orderNo,$balance)
- {
- $orderinfo = Db::name("order_pool")->where([["orderNo", "=", $orderNo], ["is_del", "=", 0]])->find();
- if (empty($orderinfo)) {
- return false;
- }
- $orderlist = Db::name("order_info")->where([["orderNo", "=", $orderNo], ["status", "=", 1]])->select();
- if (empty($orderlist)) {
- return false;
- }
- foreach ($orderlist as $value) {
- if($balance==0){
- break;
- }
- if($value['wfund_fee'] == 0){
- continue;
- }
- $order_fee=0;
- if($value['wfund_fee']<=$balance){
- $order_fee = $value['wfund_fee'];
- $balance -=$value['wfund_fee'];
- $value['fund_fee'] += $value['wfund_fee'];
- $value['wfund_fee'] = 0;
- }else{
- $value['fund_fee'] += $balance;
- $value['wfund_fee']-= $balance;
- $order_fee = $balance;
- $balance=0;
- }
- $value['updatetime'] = date("Y-m-d H:i:s");
- $orde = Db::name("order_info")->save($value);
- if(!$orde){
- return false;
- }
- $qrdinfo = Db::name("qrd_info")->where([["sequenceNo", "=", $value['goodNo']]])->field("id,ShortText1617650701648,Number1618249202608,Number1618249205231,Number1618249146997,number1618249149738,ShortText1618559043560,number1618249258956,ShortText1618559274859,inving_fee,paying_fee")->find();
- if (($order_fee <= $qrdinfo['number1618249149738'])||($order_fee <= $qrdinfo['Number1618249146997']&& $orderinfo['type']==4)) {
- $qrdinfo['paying_fee'] += $order_fee;
- if($orderinfo['type']==4){
- $qrdinfo['Number1618249146997'] -= $order_fee;
- }else{
- $qrdinfo['number1618249149738'] -= $order_fee;
- }
- //$qrdinfo['number1618249258956'] += $value['good_num'];
- // $qrdinfo['ShortText1618559043560'] = $value['total_fee'] < $qrdinfo['number1618249149738'] ? "2" : "3";
- $qinfo = Db::name("qrd_info")->save($qrdinfo);
- if ($qinfo) {
- $qrdp = Db::name("qrd")->where([["sequenceNo", "=", $qrdinfo['ShortText1617650701648']]])->find();
- if (($qrdp['wpay_fee'] >= $order_fee) || ($qrdp['apay_fee'] >= $order_fee &&$orderinfo['type']==4 )) {
- if($orderinfo['type']==4) {
- $qrdp['apay_fee'] -= $order_fee;
- }else{
- $qrdp['wpay_fee'] -= $order_fee;
- }
- $qrdp['pay_fee'] += $order_fee;
- // $qrdp['inv_status'] = $qrdp['winv_fee'] == 0 ? 3 : 2;
- $qrd = Db::name("qrd")->save($qrdp);
- if(!$qrd){
- return false;
- }
- }else {
- return false;
- }
- }else {
- return false;
- }
- } else {
- return false;
- }
- }
- return true;
- }
- private function qrd_sure($orderNo,$balance){
- $orderinfo = Db::name("order_pool")->where([["orderNo", "=", $orderNo], ["is_del", "=", 0]])->find();
- if (empty($orderinfo)) {
- return false;
- }
- $orderlist = Db::name("order_info")->where([["orderNo", "=", $orderNo], ["status", "=", 1]])->select();
- if (empty($orderlist)) {
- return false;
- }
- foreach ($orderlist as $value) {
- if($balance==0){
- break;
- }
- if($value['fund_fee'] == 0){
- continue;
- }
- $order_fee=0;
- if($value['fund_fee']<=$balance){
- $order_fee = $value['fund_fee'];
- $balance -=$value['fund_fee'];
- $value['afund_fee'] += $value['fund_fee'];
- $value['fund_fee'] = 0;
- }else{
- $value['afund_fee'] += $balance;
- $value['fund_fee']-= $balance;
- $order_fee = $balance;
- $balance=0;
- }
- $value['updatetime'] = date("Y-m-d H:i:s");
- $orde = Db::name("order_info")->save($value);
- if(!$orde){
- return false;
- }
- $qrdinfo = Db::name("qrd_info")->where([["sequenceNo", "=", $value['goodNo']]])->field("id,ShortText1617650701648,Number1618249202608,Number1618249205231,Number1618249146997,number1618249149738,ShortText1618559043560,number1618249258956,ShortText1618559274859,inving_fee,paying_fee")->find();
- if ($order_fee <= $qrdinfo['paying_fee']) {
- $qrdinfo['paying_fee'] -= $order_fee;
- if($orderinfo['type']==4){
- $qrdinfo['number1618249149738'] += $order_fee;
- $qrdinfo['ShortText1618559043560'] = $qrdinfo['Number1618249146997']>0 ? "2" : "1";
- }else{
- $qrdinfo['Number1618249146997'] += $order_fee;
- $qrdinfo['ShortText1618559043560'] = $qrdinfo['number1618249149738']>0 ? "2" : "3";
- }
- $qinfo = Db::name("qrd_info")->save($qrdinfo);
- if ($qinfo) {
- $qrdp = Db::name("qrd")->where([["sequenceNo", "=", $qrdinfo['ShortText1617650701648']]])->find();
- if ($qrdp['pay_fee'] >= $order_fee) {
- if($orderinfo['type']==4){
- $qrdp['pay_fee'] -= $order_fee;
- $qrdp['wpay_fee'] += $order_fee;
- $qrdp['pay_status'] = $qrdp['apay_fee'] == 0 ? 1 : 2;
- }else{
- $qrdp['pay_fee'] -= $order_fee;
- $qrdp['apay_fee'] += $order_fee;
- $qrdp['pay_status'] = $qrdp['wpay_fee'] == 0 ? 3 : 2;
- }
- $qrd = Db::name("qrd")->save($qrdp);
- if(!$qrd){
- return false;
- }
- }else {
- return false;
- }
- }else {
- return false;
- }
- } else {
- return false;
- }
- }
- return true;
- }
- private function qrd_delet($orderNo,$balance){
- $orderinfo = Db::name("order_pool")->where([["orderNo", "=", $orderNo], ["is_del", "=", 0]])->find();
- if (empty($orderinfo)) {
- return false;
- }
- $orderlist = Db::name("order_info")->where([["orderNo", "=", $orderNo], ["status", "=", 1]])->select();
- if (empty($orderlist)) {
- return false;
- }
- foreach ($orderlist as $value) {
- if($balance==0){
- break;
- }
- if($value['fund_fee'] == 0){
- continue;
- }
- $order_fee=0;
- if($value['fund_fee']<=$balance){
- $order_fee = $value['fund_fee'];
- $balance -=$value['fund_fee'];
- $value['wfund_fee'] += $value['fund_fee'];
- $value['fund_fee'] = 0;
- }else{
- $value['fund_fee'] -= $balance;
- $value['wfund_fee']+= $balance;
- $order_fee = $balance;
- $balance=0;
- }
- $value['updatetime'] = date("Y-m-d H:i:s");
- $orde = Db::name("order_info")->save($value);
- if(!$orde){
- return false;
- }
- $qrdinfo = Db::name("qrd_info")->where([["sequenceNo", "=", $value['goodNo']]])->field("id,ShortText1617650701648,Number1618249202608,Number1618249205231,Number1618249146997,number1618249149738,ShortText1618559043560,number1618249258956,ShortText1618559274859,inving_fee,paying_fee")->find();
- if ($order_fee <= $qrdinfo['paying_fee']) {
- $qrdinfo['paying_fee'] -= $order_fee;
- if($orderinfo['type']==4){
- $qrdinfo['Number1618249146997'] += $order_fee;
- }else{
- $qrdinfo['number1618249149738'] += $order_fee;
- }
- //$qrdinfo['number1618249258956'] += $value['good_num'];
- // $qrdinfo['ShortText1618559043560'] = $value['total_fee'] < $qrdinfo['number1618249149738'] ? "2" : "3";
- $qinfo = Db::name("qrd_info")->save($qrdinfo);
- if ($qinfo) {
- $qrdp = Db::name("qrd")->where([["sequenceNo", "=", $qrdinfo['ShortText1617650701648']]])->find();
- if ($qrdp['pay_fee'] >= $order_fee) {
- if($orderinfo['type']==4){
- $qrdp['apay_fee'] += $order_fee;
- $qrdp['pay_fee'] -= $order_fee;
- }else{
- $qrdp['wpay_fee'] += $order_fee;
- $qrdp['pay_fee'] -= $order_fee;
- }
- // $qrdp['inv_status'] = $qrdp['winv_fee'] == 0 ? 3 : 2;
- $qrd = Db::name("qrd")->save($qrdp);
- if(!$qrd){
- return false;
- }
- }else {
- return false;
- }
- }else {
- return false;
- }
- } else {
- return false;
- }
- }
- return true;
- }
- /**
- * @param $orderNo
- * @param $balance
- * @return bool
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- private function updateQrd_inv($orderNo,$balance)
- {
- $orderinfo = Db::name("order_pool")->where([["orderNo", "=", $orderNo], ["is_del", "=", 0]])->find();
- if (empty($orderinfo)) {
- return false;
- }
- $orderlist = Db::name("order_info")->where([["orderNo", "=", $orderNo], ["status", "=", 1]])->select();
- if (empty($orderlist)) {
- return false;
- }
- foreach ($orderlist as $value) {
- if($balance==0){
- break;
- }
- if($value['winv_fee'] == 0){
- continue;
- }
- $order_fee=0;
- if($value['winv_fee']<=$balance){
- $order_fee = $value['winv_fee'];
- $balance -=$value['winv_fee'];
- $value['inv_fee'] += $value['winv_fee'];
- $value['winv_fee'] = 0;
- }else{
- $value['inv_fee'] += $balance;
- $value['winv_fee']-= $balance;
- $order_fee = $balance;
- $balance=0;
- }
- $value['updatetime'] = date("Y-m-d H:i:s");
- $orde = Db::name("order_info")->save($value);
- if(!$orde){
- return false;
- }
- $qrdinfo = Db::name("qrd_info")->where([["sequenceNo", "=", $value['goodNo']]])->field("id,ShortText1617650701648,Number1618249202608,Number1618249205231,Number1618249146997,number1618249149738,ShortText1618559043560,number1618249258956,ShortText1618559274859,inving_fee,paying_fee")->find();
- if (($order_fee <= $qrdinfo['Number1618249205231'])||($order_fee <=
- $qrdinfo['Number1618249202608']&&$orderinfo['type']==4)) {
- $qrdinfo['inving_fee'] += $order_fee;
- if($orderinfo['type']==4){
- $qrdinfo['Number1618249202608'] -= $order_fee;
- // $qrdinfo['number1618249258956'] += $value['good_num'];
- }else{
- $qrdinfo['Number1618249205231'] -= $order_fee;
- $qrdinfo['number1618249258956'] += $value['good_num'];
- }
- // $qrdinfo['ShortText1618559043560'] = $value['total_fee'] < $qrdinfo['number1618249149738'] ? "2" : "3";
- $qinfo = Db::name("qrd_info")->save($qrdinfo);
- if ($qinfo) {
- $qrdp = Db::name("qrd")->where([["sequenceNo", "=", $qrdinfo['ShortText1617650701648']]])->find();
- if(($qrdp['winv_fee'] >= $order_fee)|| ($qrdp['ainv_fee'] >= $order_fee &&$orderinfo['type']==4
- )) {
- if($orderinfo['type']==4){
- $qrdp['ainv_fee'] -= $order_fee;
- $qrdp['inv_fee'] += $order_fee;
- }else{
- $qrdp['winv_fee'] -= $order_fee;
- $qrdp['inv_fee'] += $order_fee;
- }
- // $qrdp['inv_status'] = $qrdp['winv_fee'] == 0 ? 3 : 2;
- $qrd = Db::name("qrd")->save($qrdp);
- if(!$qrd){
- return false;
- }
- }else {
- return false;
- }
- }else {
- return false;
- }
- } else {
- return false;
- }
- }
- return true;
- }
- /**
- * @param $orderNo
- * @param $balance
- * @return bool
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- private function qrd_sure_inv($orderNo,$balance){
- $orderinfo = Db::name("order_pool")->where([["orderNo", "=", $orderNo], ["is_del", "=", 0]])->find();
- if (empty($orderinfo)) {
- return false;
- }
- $orderlist = Db::name("order_info")->where([["orderNo", "=", $orderNo], ["status", "=", 1]])->select();
- if (empty($orderlist)) {
- return false;
- }
- foreach ($orderlist as $value) {
- if($balance==0){
- break;
- }
- if($value['inv_fee'] == 0){
- continue;
- }
- $order_fee=0;
- if($value['inv_fee']<=$balance){
- $order_fee = $value['inv_fee'];
- $balance -=$value['inv_fee'];
- $value['ainv_fee'] += $value['inv_fee'];
- $value['inv_fee'] = 0;
- }else{
- $value['ainv_fee'] += $balance;
- $value['inv_fee']-= $balance;
- $order_fee = $balance;
- $balance=0;
- }
- $value['updatetime'] = date("Y-m-d H:i:s");
- $orde = Db::name("order_info")->save($value);
- if(!$orde){
- return false;
- }
- $qrdinfo = Db::name("qrd_info")->where([["sequenceNo", "=", $value['goodNo']]])->field("id,ShortText1617650701648,Number1618249202608,Number1618249205231,Number1618249146997,number1618249149738,ShortText1618559043560,number1618249258956,ShortText1618559274859,inving_fee,paying_fee")->find();
- if (($order_fee <= $qrdinfo['inving_fee'])||($order_fee <= $qrdinfo['inving_fee']&&$orderinfo['type']==4
- )) {
- if($orderinfo['type']==4 ){
- $qrdinfo['inving_fee'] -= $order_fee;
- //$qrdinfo['number1618249149738'] -= $order_fee;
- $qrdinfo['Number1618249205231'] += $order_fee;
- //$qrdinfo['number1618249258956'] += $value['good_num'];
- $qrdinfo['ShortText1618559274859'] = $qrdinfo['Number1618249202608']>0 ? "2" : "1";
- }else{
- $qrdinfo['inving_fee'] -= $order_fee;
- //$qrdinfo['number1618249149738'] -= $order_fee;
- $qrdinfo['Number1618249202608'] += $order_fee;
- //$qrdinfo['number1618249258956'] += $value['good_num'];
- $qrdinfo['ShortText1618559274859'] = $qrdinfo['Number1618249205231']>0 ? "2" : "3";
- }
- $qinfo = Db::name("qrd_info")->save($qrdinfo);
- if ($qinfo) {
- $qrdp = Db::name("qrd")->where([["sequenceNo", "=", $qrdinfo['ShortText1617650701648']]])->find();
- if ($qrdp['inv_fee'] >= $order_fee || ($qrdp['inv_fee'] >= $order_fee &&$orderinfo['type']==4
- )) {
- if($orderinfo['type']==4){
- $qrdp['inv_fee'] -= $order_fee;
- $qrdp['winv_fee'] += $order_fee;
- $qrdp['inv_status'] = $qrdp['ainv_fee'] == 0 ? 1 : 2;
- }else{
- $qrdp['inv_fee'] -= $order_fee;
- $qrdp['ainv_fee'] += $order_fee;
- $qrdp['inv_status'] = $qrdp['winv_fee'] == 0 ? 3 : 2;
- }
- $qrd = Db::name("qrd")->save($qrdp);
- if(!$qrd){
- return false;
- }
- }else {
- return false;
- }
- }else {
- return false;
- }
- } else {
- return false;
- }
- }
- return true;
- }
- /**
- * @param $orderNo
- * @param $balance
- * @return bool
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- private function qrd_delet_inv($orderNo,$balance){
- $orderinfo = Db::name("order_pool")->where([["orderNo", "=", $orderNo], ["is_del", "=", 1]])->find();
- if (empty($orderinfo)) {
- return false;
- }
- $orderlist = Db::name("order_info")->where([["orderNo", "=", $orderNo], ["status", "=", 1]])->select();
- if (empty($orderlist)) {
- return false;
- }
- foreach ($orderlist as $value) {
- if($balance==0){
- break;
- }
- if($value['inv_fee'] == 0){
- continue;
- }
- $order_fee=0;
- if($value['inv_fee']<=$balance){
- $order_fee = $value['inv_fee'];
- $balance -=$value['inv_fee'];
- $value['winv_fee'] += $value['inv_fee'];
- $value['inv_fee'] = 0;
- }else{
- $value['inv_fee'] -= $balance;
- $value['winv_fee']+= $balance;
- $order_fee = $balance;
- $balance=0;
- }
- $value['updatetime'] = date("Y-m-d H:i:s");
- $orde = Db::name("order_info")->save($value);
- if(!$orde){
- return false;
- }
- $qrdinfo = Db::name("qrd_info")->where([["sequenceNo", "=", $value['goodNo']]])->field("id,ShortText1617650701648,Number1618249202608,Number1618249205231,Number1618249146997,number1618249149738,ShortText1618559043560,number1618249258956,ShortText1618559274859,inving_fee,paying_fee")->find();
- if ($order_fee <= $qrdinfo['inving_fee']) {
- $qrdinfo['inving_fee'] -= $order_fee;
- if($orderinfo['type']==4){
- $qrdinfo['Number1618249202608'] += $order_fee;
- // $qrdinfo['number1618249258956'] += $value['good_num'];
- }else{
- $qrdinfo['Number1618249205231'] += $order_fee;
- $qrdinfo['number1618249258956'] -= $value['good_num'];
- }
- // $qrdinfo['ShortText1618559043560'] = $value['total_fee'] < $qrdinfo['number1618249149738'] ? "2" : "3";
- $qinfo = Db::name("qrd_info")->save($qrdinfo);
- if ($qinfo) {
- $qrdp = Db::name("qrd")->where([["sequenceNo", "=", $qrdinfo['ShortText1617650701648']]])->find();
- if ($qrdp['inv_fee'] >= $order_fee) {
- if($orderinfo['type']==4){
- $qrdp['ainv_fee'] += $order_fee;
- }else{
- $qrdp['winv_fee'] += $order_fee;
- }
- $qrdp['inv_fee'] -= $order_fee;
- // $qrdp['inv_status'] = $qrdp['winv_fee'] == 0 ? 3 : 2;
- $qrd = Db::name("qrd")->save($qrdp);
- if(!$qrd){
- return false;
- }
- }else {
- return false;
- }
- }else {
- return false;
- }
- } else {
- return false;
- }
- }
- return true;
- }
- /**查询退款可关联订单
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function RefundByTrade(){
- $post = $this->request->post();
- $token = isset($post['token']) ? trim($post['token']) : "";
- if ($token == "") {
- return error_show(101, 'token不能为空');
- }
- $effetc = VerifyTokens($token);
- if (!empty($effetc) && $effetc['code'] != 0) {
- return error_show($effetc['code'], $effetc['message']);
- }
- // $type = isset($post['type']) && $post['type'] != "" ? intval($post['type']) : 1;
- $traNo =isset($post['traNo'])&& $post['traNo'] != "" ? trim($post['traNo']) : "";
- if($traNo==""){
- return error_show(1005,"参数traNo 不能为空");
- }
- $tradeinfo =Db::name("trade_list")->where([["traNo","=",$traNo],['is_del',"=",0]])->find();
- if(!$tradeinfo){
- return error_show(1005,"数据未找到");
- }
- if($tradeinfo['trade_type']!=1){
- return error_show(1005,"数据不是退款资金");
- }
- $refundlist = Db::name("refund")->where([["is_del","=",0],["backNo","=",$traNo],["refund_type","=",1]])
- ->select()->toArray();
- if(empty($refundlist)){
- return error_show(1006,"退款关联资金未找到");
- }
- $tradlist = array_column($refundlist,"relaNo");
- $condition = [["is_del","=",0],["codeNo|viceNo","in",$tradlist]];
- $condition[] = ["rela_form","in",[2,3]];
- $assoc = Db::name("assoc_list")->where($condition)->select()->toArray();
- if(empty($assoc)){
- return error_show(1005,"未找到关联数据");
- }
- $lsi=[];
- foreach ($assoc as $value){
- $temp=[];
- if($value['rela_form']==2){
- $temp['orderNo'] =$value['codeNo'];
- $temp['cancel'] =$value['cancel_fee'];
- $temp['is_all'] =0;
- }
- if($value['rela_form']==3){
- $temp['orderNo'] =$value['viceNo'];
- $temp['cancel'] =$value['cancel_fee'];
- $temp['is_all'] =1;
- }
- $lsi[]=$temp;
- }
- $orderno = array_column($lsi,"orderNo");
- $total_fee = array_sum(array_column($lsi,"cancel_fee"));
- $orderlist = Db::name("order_list")->where("orderNo","in",$orderno)->select()->toArray();
- $qrdlsit=[];
- if(!empty($orderno)){
- foreach ($orderlist as $value){
- if(!isset($qrdlsit[$value['qrdNo']])){
- $qrdlsit[$value['qrdNo']]= Db::name("qrd")->where([["sequenceNo","=",$value['qrdNo']]])
- ->field("sequenceNo,sales_name,sales_depart,customer,total_fee,wpay_fee,apay_fee,pay_fee,winv_fee,ainv_fee,inv_fee,inv_status,pay_status")->find();
- }
- $good = Db::name("qrd_list")->where([["sequenceNo","=",$value['goodNo']]])->field("id,sequenceNo,goodname,goodNo,brand,unit,taxPoint,num,goldprice,weight,price,total_fee,touser,gys,kehu,apay_fee,wpay_fee,ainv_fee,winv_fee,paying_fee,inving_fee,pay_status,inv_status,inv_num")
- ->find();
- // $good['price'] =isset($value['price']) ? sprintf("%.2f",$value['price']):"";
- $good['price'] =isset($value['price']) ? sprintf("%.2f",$value['price']):"";
- $good['total_fee'] =isset($value['total_fee']) ? sprintf("%.2f",$value['total_fee']):"";
- $good['apay_fee'] = sprintf("%.2f",$value['gafund_fee']);
- $good['wpay_fee'] = sprintf("%.2f",$value['gwfund_fee']);
- $good['ainv_fee'] = sprintf("%.2f",$value['gainv_fee']);
- $good['winv_fee'] = sprintf("%.2f",$value['gwinv_fee']);
- $good['num'] = intval($value['good_num']);
- // $good['inv_num'] = isset($good['inv_num']) ? sprintf("%d",$good['inv_num']):"0";
- foreach ($lsi as $val){
- if($value['orderNo']==$val['orderNo']){
- $good['isall'] = $val['is_all'];
- $good['orderNo'] = $val['orderNo'];
- }
- }
- $qrdlsit[$value['qrdNo']]['good'][]=$good;
- }
- }
- $data = ['orderlist'=>array_values($qrdlsit),"total_fee"=>$lsi];
- return app_show(0,"获取成功",$data);
- }
- /**
- * 退款关联可退款记录
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function AssocRefund(){
- $post = $this->request->post();
- $token = isset($post['token']) ? trim($post['token']) : "";
- if ($token == "") {
- return error_show(101, 'token不能为空');
- }
- $effetc = VerifyTokens($token);
- if (!empty($effetc) && $effetc['code'] != 0) {
- return error_show($effetc['code'], $effetc['message']);
- }
- $guserinfo =GetUserInfo($token);
- if(isset($guserinfo['code']) && $guserinfo['code']!=0){
- return error_show($guserinfo['code'],$guserinfo['message']);
- }
- $traNo = isset($post['traNo'])&& $post['traNo']!=""? trim($post['traNo']):"";
- if($traNo==""){
- return error_show(1005,"参数traNo 不能为空");
- }
- $tradeinfo = Db::name("trade_list")->where([['traNo',"=",$traNo],["is_del","=",0]])->find();
- if(empty($tradeinfo)){
- return error_show(1005,"未找到数据");
- }
- $companyNo = isset($post['companyNo']) && $post['companyNo'] != "" ? trim($post['companyNo']) : "";
- $userinfo = GetUserInfo($token);
- $username = "";
- if ($companyNo == "") {
- return error_show(1004, "参数companyNo 不能为空");
- }
- if (isset($userinfo['code']) && $userinfo['code'] == 0) {
- $username = isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname'] : "";
- }
- $customer = Db::name("customer_info")->where("companyNo", "=", $companyNo)->find();
- if (empty($customer)) {
- return error_show(1004, "未找到客户企业信息");
- }
- $good = isset($post['good']) && $post['good'] ? explode(",", $post['good']) : "";
- if ($good == "" && empty($good)) {
- return error_show(1004, "商品信息不能为空");
- }
- Db::startTrans();
- try {
- $orderinfo = [];
- $orderNo = makeNo('ORD');
- $total = 0;
- $fund_fee = 0;
- $wfund_fee = 0;
- $inv_fee = 0;
- $winv_fee = 0;
- foreach ($good as $value) {
- $temp = [];
- $temp['orderNo'] = $orderNo;
- $temp['goodNo'] = $value['goodNo'];
- $goocp = Db::name("qrd_list")->where("sequenceNo", "=", $value['goodNo'])->find();
- if (!$goocp) {
- continue;
- }
- $temp['good_name'] = $goocp['goodname'];
- $temp['qrdNo'] = $goocp['qrdNo'];
- $temp['brand'] = $goocp['brand'];
- $temp['unit'] = $goocp['unit'];
- $temp['good_num'] = $value['num'];
- $temp['price'] = $goocp['price'];
- $temp['total_fee'] = $value['total_fee'];
- $temp['wfund_fee'] = $value['total_fee'];
- $temp['winv_fee'] = $value['total_fee'];
- $temp['other_fee'] = 0;
- $temp['status'] = 1;
- $temp['remark'] = "";
- $temp['addtime'] = date("Y-m-d H:i:s");
- $temp['updatetime'] = date("Y-m-d H:i:s");
- $total += $value['total_fee'];
- $fund_fee += $value['apay_fee'];
- $winv_fee += $value['winv_fee'];
- $inv_fee += $value['ainv_fee'];
- $wfund_fee += $value['wpay_fee'];
- $orderinfo[] = $temp;
- }
- if($total!=$tradeinfo['worder_fee']){
- Db::rollback();
- return error_show(1004, "商品总额于资金不符");
- }
- $orderins = Db::name("order_info")->insertAll($orderinfo);
- if ($orderins) {
- $order = [
- "orderNo" => $orderNo,
- "companyNo" => $companyNo,
- "sales_id" => $effetc['data']['user']['id'],
- "sales_name" => $username,
- "total_amount" => $total,
- "inv_status" => 1,
- "fund_status" => 1,
- "fund_fee" => 0,
- "wfund_fee" => $total,
- "inv_fee" => 0,
- "winv_fee" => $total,
- "status" => 0,
- "type" => 3,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $orderpool = Db::name("order_pool")->insert($order, true);
- if ($orderpool > 0) {
- if ($tradeinfo != "" && is_array($tradeinfo)) {
- $rela = [];
- $assNo = makeNo("ASC");
- $cancel = 0;
- $balance = $tradeinfo["worder_fee"] > $total ? $total : $tradeinfo["worder_fee"];
- $total -= $balance;
- $sav=[
- "worder_fee" =>$tradeinfo['worder_fee']-$balance,
- "order_used" =>$tradeinfo['order_used']+$balance,
- "is_order" =>1,
- "updatetime" =>date("Y-m-d H:i:s")
- ];
- Db::name("trade_pool")->where([["traNo","=",$tradeinfo['traNo']]])->save($sav);
- $rela = [
- "assocNo" => $assNo,
- "viceNo" => $orderNo,
- "vice_total" => $order['total_amount'],
- "vice_fee" => $total,
- "cancel_fee" => $balance,
- "status" => 1,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $assoc = Db::name("assoc_rela")->insert($rela);
- if ($assoc) {
- $data = [
- "assocNo" => $assNo,
- "companyNo" => $companyNo,
- "type" => 3,
- "rela_form" => 3,
- "codeNo" => $tradeinfo["traNo"],
- "total_fee" => $tradeinfo['total_fee'],
- "balance" => $tradeinfo['worder_fee'],
- "cancel_total" => $balance,
- "status" => 1,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $realkey = Db::name("assoc_key")->insert($data);
- if ($realkey) {
- Db::name("order_pool")->where("orderNo", "=", $orderNo)->save
- (["wfund_fee" => $total,'fund_used'=>$balance, "updatetime" => date("Y-m-d H:i:s")]);
- $qrdup=$this->updateQrd($orderNo,$balance);
- if(!$qrdup){
- Db::rollback();
- return error_show(1004, "新建关联申请失败");
- }
- Db::commit();
- return app_show(0, "新建关联成功");
- }
- }
- Db::rollback();
- return error_show(1004, "新建关联申请失败");
- }
- }
- }
- 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
- * @throws \think\exception\DbException
- */
- public function RefundAssocInv(){
- $post = $this->request->post();
- $token = isset($post['token']) ? trim($post['token']) : "";
- if ($token == "") {
- return error_show(101, 'token不能为空');
- }
- $effetc = VerifyTokens($token);
- if (!empty($effetc) && $effetc['code'] != 0) {
- return error_show($effetc['code'], $effetc['message']);
- }
- $guserinfo =GetUserInfo($token);
- if(isset($guserinfo['code']) && $guserinfo['code']!=0){
- return error_show($guserinfo['code'],$guserinfo['message']);
- }
- // $companyNo = isset($post['tradeNo'])&&$post['tradeNo']!=""?trim($post['tradeNo']):"";
- $companyNo = isset($post['companyNo']) && $post['companyNo'] != "" ? trim($post['companyNo']) : "";
- $type = isset($post['type']) && $post['type'] != "" ? intval($post['type']) : 5;
- $tralog = isset($post['tralog']) && $post['tralog'] != "" ? $post['tralog'] : "";
- $invNo = isset($post['invNo']) && $post['invNo'] != "" ? $post['invNo'] : "";
- if (!in_array($type, [4, 5])) {
- return error_show(1004, "参数type 有误");
- }
- if ($invNo == "") {
- return error_show(1004, "缺少必要参数invNo");
- }
- if ($tralog == "") {
- return error_show(1004, "缺少必要参数tralog");
- }
- $inv = Db::name("invoice_pool")->where([["is_del", "=", 0], ["invNo", "=", $invNo]])->find();
- if (!$inv) {
- return error_show(1004, "未找到对应的发票数据");
- }
- if ($inv['type_check']!=5) {
- return error_show(1004, "发票不属于退票数据");
- }
- Db::startTrans();
- try {
- $rela = [];
- $trade = 0;
- $assNo = makeNo("ASC");
- foreach ($tralog as $value) {
- if(isset($value['traNo']) && isset($value['cancel'])){
- $trainfo = Db::name("trade_pool")->where([["traNo","=",$value['traNo']],["is_del","=",0]])
- ->find();
- if($trainfo['inv_fee']>=$value['cancel']){
- $trade+=$value['cancel'];
- $trainfo['inv_fee']-=$value['cancel'];
- $trainfo['inv_used']+=$value['cancel'];
- $trainfo['updatetime']=date("Y-m-d H:i:s");
- Db::name("trade_pool")->save($trainfo);
- $rela[] = [
- "assocNo" => $assNo,
- "viceNo" => $value['traNo'],
- "vice_total" => $trainfo['total_fee'],
- "vice_fee" => $value['inv_fee'],
- "cancel_fee" => $value['cancel'],
- "status" => 1,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- }else{
- Db::rollback();
- return error_show(1005,"资金核销金额不足");
- }
- }else{
- Db::rollback();
- return error_show(1005,"参数tralog 有误");
- }
- }
- if($inv['wtrade_fee']<$trade){
- Db::rollback();
- return error_show(1005,"发票核销余额不足");
- }
- $assoc = Db::name("assoc_rela")->insertAll($rela);
- if ($assoc) {
- $data = [
- "assocNo" => $assNo,
- "companyNo" => $companyNo,
- "type" => 2,
- "apply_id"=> $guserinfo["data"]["id"],
- "apply_name"=> $guserinfo["data"]["nickname"],
- "rela_form" =>4,
- "codeNo" => $tralog["invNo"],
- "total_fee" => $tralog['inv_value'],
- "balance" => $tralog['wtrade_fee']-$trade,
- "cancel_total" => $trade,
- "status" => 1,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $realkey = Db::name("assoc_key")->insert($data);
- if ($realkey) {
- $tralog['wtrade_fee'] -= $trade;
- $tralog['fund_used'] += $trade;
- $tralog['updatetime'] = date("Y-m-d H:i:s");
- Db::name("invoice_pool")->save($tralog);
- Db::commit();
- return app_show(0, "新建关联成功");
- }
- }
- Db::rollback();
- return error_show(1005,"新建关联失败");
- } catch (\Exception $e) {
- Db::rollback();
- return error_show(1006, $e->getMessage());
- }
- }
- /***
- *退票可关联数据 订单资金
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function RefundByInv(){
- $post = $this->request->post();
- $token = isset($post['token']) ? trim($post['token']) : "";
- if ($token == "") {
- return error_show(101, 'token不能为空');
- }
- $effetc = VerifyTokens($token);
- if (!empty($effetc) && $effetc['code'] != 0) {
- return error_show($effetc['code'], $effetc['message']);
- }
- // $type = isset($post['type']) && $post['type'] != "" ? intval($post['type']) : 1;
- $invNo =isset($post['invNo'])&& $post['invNo'] != "" ? trim($post['invNo']) : "";
- if($invNo==""){
- return error_show(1005,"参数invNo 不能为空");
- }
- $invinfo =Db::name("invoice_pool")->where([["invNo","=",$invNo],['is_del',"=",0]])->find();
- if(!$invinfo){
- return error_show(1005,"数据未找到");
- }
- if($invinfo['type_check']!=5){
- return error_show(1005,"数据不是退票数据");
- }
- $refundlist = Db::name("refund")->where([["is_del","=",0],["backNo","=",$invNo],["refund_type","=",2]])
- ->select()->toArray();
- if(empty($refundlist)){
- return error_show(1006,"退票关联发票未找到");
- }
- $tradlist = array_column($refundlist,"relaNo");
- $condition = [["is_del","=",0],["codeNo|viceNo","in",$tradlist]];
- $condition[] = ["rela_form","in",[1,4,5]];
- $assoc = Db::name("assoc_list")->where($condition)->select()->toArray();
- if(empty($assoc)){
- return error_show(1005,"未找到关联数据");
- }
- $lsi=[];
- foreach ($assoc as $value){
- $temp=[];
- if($value['rela_form']==4){
- $temp['traNo'] =$value['viceNo'];
- $temp['cancel'] =$value['cancel_fee'];
- $temp['is_all'] =1;
- $lsi["trade"][]=$temp;
- }
- if($value['rela_form']==5){
- $temp['traNo'] =$value['codeNo'];
- $temp['cancel'] =$value['cancel_fee'];
- $temp['is_all'] =1;
- $lsi["trade"][]=$temp;
- }
- if($value['rela_form']==1){
- $temp['orderNo'] =$value['codeNo'];
- $temp['cancel'] =$value['cancel_fee'];
- $temp['is_all'] =1;
- $lsi["order"][]=$temp;
- }
- }
- if(isset($lsi['order']) && !empty($lsi['order'])){
- $orderno = array_column($lsi['order'],"orderNo");
- $total_fee = array_sum(array_column($lsi['order'],"cancel_fee"));
- $orderlist = Db::name("order_list")->where("orderNo","in",$orderno)->select()->toArray();
- $qrdlsit=[];
- if(!empty($orderno)){
- foreach ($orderlist as $value){
- if(!isset($qrdlsit[$value['qrdNo']])){
- $qrdlsit[$value['qrdNo']]= Db::name("qrd")->where([["sequenceNo","=",$value['qrdNo']]])
- ->field("sequenceNo,sales_name,sales_depart,customer,total_fee,wpay_fee,apay_fee,pay_fee,winv_fee,ainv_fee,inv_fee,inv_status,pay_status")->find();
- }
- $good = Db::name("qrd_list")->where([["sequenceNo","=",$value['goodNo']]])->field("id,sequenceNo,goodname,goodNo,brand,unit,taxPoint,num,goldprice,weight,price,total_fee,touser,gys,kehu,apay_fee,wpay_fee,ainv_fee,winv_fee,paying_fee,inving_fee,pay_status,inv_status,inv_num")
- ->find();
- // $good['price'] =isset($value['price']) ? sprintf("%.2f",$value['price']):"";
- $good['price'] =isset($value['price']) ? sprintf("%.2f",$value['price']):"";
- $good['total_fee'] =isset($value['total_fee']) ? sprintf("%.2f",$value['total_fee']):"";
- $good['apay_fee'] = sprintf("%.2f",$value['gafund_fee']);
- $good['wpay_fee'] = sprintf("%.2f",$value['gwfund_fee']);
- $good['ainv_fee'] = sprintf("%.2f",$value['gainv_fee']);
- $good['winv_fee'] = sprintf("%.2f",$value['gwinv_fee']);
- $good['num'] = intval($value['good_num']);
- // $good['inv_num'] = isset($good['inv_num']) ? sprintf("%d",$good['inv_num']):"0";
- foreach ($lsi['order'] as $val){
- if($value['orderNo']==$val['orderNo']){
- $good['isall'] = $val['is_all'];
- $good['orderNo'] = $val['orderNo'];
- }
- }
- $qrdlsit[$value['qrdNo']]['good'][]=$good;
- }
- }
- $data = ['orderlist'=>array_values($qrdlsit),"total_fee"=>$lsi['order']];
- return app_show(0,"获取成功",$data);
- }
- if(isset($lsi['trade']) && !empty($lsi['trade'])){
- $tradeno = array_column($lsi['trade'],"traNo");
- $tradelist = Db::name("trade_list")->where("traNo","in",$tradeno)->select()->toArray();
- $kst=[];
- foreach ($tradelist as $value){
- $temp=[];
- $temp['id']=$value['id'];
- $temp['traNo']=$value['traNo'];
- $temp['companyNo']=$value['companyNo'];
- $customer = Db::name("customer_info")->where([["companyNo","=",$value['companyNo']]])->find();
- $temp['companyNo']=$value['companyNo'];
- $temp['companyName']=$customer['companyName'];
- $temp['total_fee']= $value['total_fee'];
- $temp['order_fee']= $value['order_fee'];
- $temp['order_used']= $value['order_used'];
- $temp['worder_fee']= $value['worder_fee'];
- $temp['inv_fee']= $value['inv_fee'];
- $temp['inv_used']= $value['inv_used'];
- $temp['winv_fee']= $value['winv_fee'];
- $temp['inv_status']= $value['inv_status'];
- $temp['order_status']= $value['order_status'];
- $temp['isall'] = 0;
- $temp['cancel'] = $value['inv_fee'];
- foreach ($lsi['order'] as $val){
- if($value['orderNo']==$val['orderNo']){
- $temp['isall'] = $val['is_all'];
- $temp['cancel'] = $val['cancel'];
- }
- }
- $kst[]=$temp;
- }
- $data = ['orderlist'=>$kst,"total_fee"=>$lsi['trade']];
- return app_show(0,"获取成功",$data);
- }
- }
- }
|