12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257 |
- <?php
- namespace App\Http\Controllers;
- use App\Events\CancelOrderEvent;
- use App\Events\EnoughFive;
- use App\Events\FinishAccount;
- use App\Events\AuthRefundTip;
- use App\Events\HelpOrderEvent;
- use App\Events\NewOrder;
- use App\Events\ReceivingEvent;
- use App\Events\RetailOutboundEvent;
- use App\Events\RestoreOutboundEvent;
- use App\Events\TipSendingEvent;
- use App\Events\TipPickUpEvent;
- use App\Http\Controllers\MiniSubController as Mini;
- use App\Models\Admin;
- use App\Models\Amount;
- use App\Models\BindRecomLog;
- use App\Models\OrderExpressW;
- use App\Models\AgentNo;
- use App\Models\ShowNumW;
- use App\Models\Verify;
- use App\Models\Warea;
- use App\Models\Select;
- use App\Models\OrderCancelW;
- use App\Models\OrderCodeW;
- use App\Models\OrderDetail;
- use App\Models\OrderRefund;
- use App\Models\OrderRefundW;
- use App\Models\VipLog;
- use App\Models\VipLogW;
- use App\Models\SettingW;
- use Carbon\Carbon;
- use Overtrue\EasySms\EasySms;
- use App\Handlers\RefundAmount;
- use App\Handlers\ExpressHandler;
- use App\Handlers\TencentHandler;
- use App\Handlers\UploadImg;
- use App\Models\Comment;
- use App\Models\Order;
- use App\Models\StoreGoods;
- use App\Models\InventoryW;
- use App\Models\IntegralW;
- use App\Models\See;
- use App\Models\Scan;
- use App\Models\User;
- use App\Models\Store;
- use App\Models\UserW;
- use App\Models\UserZ;
- use App\Models\OrderW;
- use App\Models\OrderShareW;
- use App\Models\TestUserW;
- use App\Models\AddressW;
- use App\Models\ZbsBasic;
- use App\Models\ZbsEnroll;
- use App\Models\OrderDetailW;
- use App\Models\StoreGoodsSku;
- use Illuminate\Http\Request;
- use Intervention\Image\Facades\Image;
- use EasyWeChat\Factory;
- use GuzzleHttp\Client;
- use Illuminate\Support\Facades\Auth;
- use DB;
- use Storage;
- use Cache;
- use Log;
- use Validator;
- use TencentCloud\Common\Credential;
- use TencentCloud\Common\Profile\ClientProfile;
- use TencentCloud\Common\Profile\HttpProfile;
- use TencentCloud\Common\Exception\TencentCloudSDKException;
- use TencentCloud\Ocr\V20181119\OcrClient;
- use TencentCloud\Ocr\V20181119\Models\IDCardOCRRequest;
- use SimpleSoftwareIO\QrCode\Facades\QrCode;
- use Qiniu\Auth as Auths;
- use Qiniu\Storage\UploadManager;
- use Qiniu\Storage\BucketManager;
- use App\Handlers\CompressImageHandler;
- class StoreController extends Controller{
- //获取店铺信息
- public function getStoreInfo()
- {
- $user_id=Auth::user()->id;
- $user=User::where('id',$user_id)->first();
- $data['is_delete'] = 0;
- if(!empty($user->deleted_at)){
- //获取账号余额
- $sub_mchid=Store::withTrashed()->where('is_failure',0)->where('user_id', $user_id)->value('sub_mchid');
- $mini=new Mini();
- $result=$mini->getAccount($sub_mchid);
- Log::info('------------------------------------------------------------------------------');
- Log::info($result);
- if($result['pending_amount']+$result['available_amount']==0){
- Log::info($user->mobile.'///'.$user->deleted_at.'///'.$result['pending_amount'].'///'.$result['available_amount']);
- return $this->error('450005','该商户账号已被删除');
- }
- $data['is_delete'] = 1;
- $store=Store::withTrashed()->where('is_failure',0)->where('is_failure',0)->where('user_id',Auth::user()->id)->first();
- }else{
- //正式版
- if($user->status==1){
- return $this->error('450001','该用户已被禁用');
- }
- if($user->cert_status <> 3){
- if($user->cert_status <> 6){
- return $this->error('450001','该账号未完成账号审核');
- }
- }
- if($user->service_status <> 0){
- return $this->error('450001','该账号未完成经销商审核');
- }
- if($user->in_group!=1){
- return $this->error('450001','该用户未完成政委审核');
- }
- if($user->freeze_status==1){
- return $this->error('450001','该用户已被冻结');
- }
- // if($user->status <> 0 || $user->cert_status <> 6 || $user->service_status <> 0){// || !empty($user->deleted_at)
- // return $this->error('450002','你无权访问该页面');
- // }
- $store=Store::where('user_id',Auth::user()->id)->first();
- $store_del=Store::withTrashed()->where('is_failure',0)->where('user_id',Auth::user()->id)->first();
- if(empty($store) && !empty($store_del)){
- return $this->error('450001','店铺已被删除');
- }
- if(empty($store) && empty($store_del)){
- Store::create([
- 'img'=>$user->headimgurl,
- 'name'=>$user->nickname,
- 'user_id'=>$user->id,
- 'phone'=>$user->mobile
- ]);
- $store=Store::where('user_id',Auth::user()->id)->first();
- }
- if($store->status==1){
- return $this->error('450004','店铺已禁用');
- }
- }
- //测试版
- // $test_user=TestUserW::pluck('phone')->toArray();
- // if(!in_array($user->mobile,$test_user)){
- // return $this->error('450002','你无权访问该页面');
- // }
- // ->select('id','name','phone','img','star','province','city','area','address','qr_code',
- // 'is_test','status','is_apply','applyment_state','is_business','is_dianjin','is_adverting')
- $arr_test=Store::getTest();
- if($user->headimgurl != $store->img){
- Log::info($store->img);
- $store->img=$user->headimgurl;
- }
- if($user->mobile != $store->phone){
- $store->phone=$user->mobile;
- }
- if($user->nickname != $store->name){
- $store->name=$user->nickname;
- }
- if($user->warea_id != $store->warea_id){
- $store->warea_id=$user->warea_id;
- $store->warea_name=Warea::where('id',$user->warea_id)->value('name');
- }
- if($user->level != $store->level){
- $store->level=$user->level;
- }
- $store->save();
- // $star=Comment::where('store_id',$store->id)->average('star');
- // $store->star=floor($star);
- if(in_array($store->id,$arr_test)){
- $store->is_test=1;
- }else{
- $store->is_test=0;
- }
- //测试跳转小程序
- if(in_array($user->mobile,['15138929587','15238617326','13030314383','18838980968'])){
- $user->mini_zbs=1;
- }else{
- $user->mini_zbs=0;
- }
- $no_pay=OrderW::where('store_id',$store->id)->where('is_pay',0)->where('apply_cancel',[0,1,3])->count();
- $no_refund=OrderRefundW::where('store_id',$store->id)->where('status',0)->count();
- $no_cancel=OrderCancelW::where('store_id',$store->id)->where('status',1)->count();
- $see_num=See::where('store_id',$store->id)->whereDate('created_at',date('Y-m-d'))->count();
- $order_num=OrderW::where('store_id',$store->id)->whereIn('apply_cancel',[0,1,3])->whereIn('is_refund',[0,1])
- ->where('is_pay',1)->whereDate('created_at',date('Y-m-d'))->count();
- $order_money=OrderW::where('store_id',$store->id)->whereIn('apply_cancel',[0,1,3])->whereIn('is_refund',[0,1])
- ->where('is_pay',1)->whereDate('created_at',date('Y-m-d'))->sum('account');
- $wait_send_num=OrderW::where('store_id',$store->id)->whereIn('apply_cancel',[0,1,3])->whereIn('is_refund',[0,1,2])
- ->where('is_pay',1)->where('status',1)->count();
- $show_num=ShowNumW::where('obj_id',$store->id)->where('obj_type',1)->where('type',1)->first();
- $data['show_num1']=0;
- if($show_num){
- if($show_num->num < 3){
- $data['show_num1']=1;
- $show_num->num += 1;
- $show_num->save();
- }
- }else{
- ShowNumW::create([
- 'obj_id'=>$store->id,
- 'obj_type'=>1,
- 'type'=>1,
- 'name'=>'首页操作视频',
- 'num'=>1,
- ]);
- }
- $order_money=round($order_money);
- // $data['user']=$user;
- $data['store']=$store;
- $data['wait_send_num']=$wait_send_num?$wait_send_num:0;
- $data['order_num']=$order_num?$order_num:0;
- $data['see_num']=$see_num?$see_num:0;
- $data['order_money']=$order_money?$order_money:'0';
- $data['no_pay']=$no_pay?$no_pay:'0';
- $data['no_auth']=$no_refund+$no_cancel;
- $home_operation_video=SettingW::where('key','home.operation.video')->value('value');
- $data['home_operation_video']=$home_operation_video;
- return $this->success($data);
- }
- //微店首页争霸赛元宝弹窗
- public function getZbsRank()
- {
- $start_time=ZbsBasic::where('keys','round_start_time')->value('value');
- $end_time=ZbsBasic::where('keys','round_end_time')->value('value');
- $season=ZbsBasic::where('keys','season')->value('value');
- $store = Store::where('user_id',Auth::user()->id)->first();
- // $user = UserZ::where('phone', $store->phone)->first();
- $user = UserZ::where('dwbs_id', $store->user_id)->first();
- if(empty($user)){
- Log::info('争霸赛不存在该用户'.$store->phone);
- $zbs['type']=2;
- $zbs['message']='争霸赛不存在该用户';
- return $this->success($zbs);
- }
- $now=Carbon::now()->timestamp;
- if($now>$start_time && $now<$end_time) { //在争霸赛期间
- // $uids = ZbsEnroll::where('season',$season)->where('is_refund',0)->where('status',0)->pluck('uid')->toArray();
- $uids = \Illuminate\Support\Facades\Cache::remember('uids',Carbon::now()->addHours(12),function()use($season){
- return ZbsEnroll::where('season',$season)->where('is_refund',0)->where('status',0)->pluck('uid')->toArray();
- });
- if(!in_array($user->id,$uids)){
- $zbs['type']=2;
- $zbs['message']='没有报名当前这届争霸赛';
- return $this->success($zbs);
- }
- $start_time=date("Y-m-d H:i:s",$start_time);
- $end_time=date("Y-m-d H:i:s",$end_time);
- $total = OrderW::where('store_id',$store->id)->whereBetween('created_at', [$start_time,$end_time])
- ->where('is_help',0)->where('is_pay',1)->whereIn('apply_cancel',[0,1,3])->whereIn('is_refund',[0,1,2])
- ->where('zbs_yb',0)->sum('total');
- if($total<=0){
- $zbs['type']=2;
- $zbs['message']='没有积分变化';
- return $this->success($zbs);
- }
- $score = $total * 10;
- $integrals = UserZ::where('integral', '>=', $user->integral)
- ->whereIn('id',$uids)
- ->orderByDesc('integral','id')->pluck('integral','id')->toArray();
- arsort($integrals);
- $keys0=array_keys($integrals);
- $rank0 = array_search($user->id, $keys0);
- $inte = $user->integral + $score;
- $integrals[$user->id] = $inte;
- arsort($integrals);
- $keys1=array_keys($integrals);
- $rank = array_search($user->id, $keys1);
- $ranking = $rank0 - $rank;
- if($ranking<=0){
- $ranking=0;
- }
- $zbs['type']=1;
- $zbs['message']='在争霸赛期间';
- $zbs['score'] = $score;
- $zbs['ranking']=$ranking;
- // $zbs['integrals'] = $integrals;
- OrderW::where('store_id',$store->id)->whereBetween('created_at', [$start_time,$end_time])
- ->where('is_help',0)->where('is_pay',1)->whereIn('apply_cancel',[0,1,3])->whereIn('is_refund',[0,1,2])
- ->where('zbs_yb',0)->update(['zbs_yb'=>1]);
- return $this->success($zbs);
- }else{
- //不在争霸赛期间
- $zbs['type']=2;
- $zbs['message']='不在争霸赛期间';
- return $this->success($zbs);
- }
- }
- public function getStoreData(){
- $user_id=Auth::user()->id;
- $user=User::where('id',$user_id)->first();
- $store=Store::where('user_id',Auth::user()->id)->first();
- if($user->headimgurl != $store->img){
- Log::info($store->img);
- $store->img=$user->headimgurl;
- $store->save();
- }
- if($user->mobile != $store->phone){
- $store->phone=$user->mobile;
- $store->save();
- }
- if($user->nickname != $store->name){
- $store->name=$user->nickname;
- $store->save();
- }
- // $star=Comment::where('store_id',$store->id)->average('star');
- // $store->star=floor($star);
- $no_pay=OrderW::where('store_id',$store->id)->where('is_pay',0)->where('apply_cancel',[0,1,3])->count();
- $no_refund=OrderRefundW::where('store_id',$store->id)->where('status',0)->count();
- $no_cancel=OrderCancelW::where('store_id',$store->id)->where('status',1)->count();
- $see_num=See::where('store_id',$store->id)->whereDate('created_at',date('Y-m-d'))->count();
- $order_num=OrderW::where('store_id',$store->id)->whereIn('apply_cancel',[0,1,3])->whereIn('is_refund',[0,1])
- ->where('is_pay',1)->whereDate('created_at',date('Y-m-d'))->count();
- $order_money=OrderW::where('store_id',$store->id)->whereIn('apply_cancel',[0,1,3])->whereIn('is_refund',[0,1])
- ->where('is_pay',1)->whereDate('created_at',date('Y-m-d'))->sum('account');
- $wait_send_num=OrderW::where('store_id',$store->id)->whereIn('apply_cancel',[0,1,3])->whereIn('is_refund',[0,1,2])
- ->where('is_pay',1)->where('status',1)->count();
- $order_money=round($order_money);
- $data['user']=$user;
- $data['store']=$store;
- $data['wait_send_num']=$wait_send_num?$wait_send_num:0;
- $data['order_num']=$order_num?$order_num:0;
- $data['see_num']=$see_num?$see_num:0;
- $data['order_money']=$order_money?$order_money:'0';
- $data['no_pay']=$no_pay?$no_pay:'0';
- $data['no_auth']=$no_refund+$no_cancel;
- return $this->success($data);
- }
- //获取商户个人信息
- public function getAgentInfo(){
- $store = Store::where('user_id',Auth::user()->id)->first();
- if(empty($store->idCard)){
- return $this->error('450001','店铺未认证');
- }
- $cre_num=$store->idCard;
- $year=substr($cre_num,6,4);
- if($year>1920 && $year<2020) {
- $year .= '-01-01';
- $age = Carbon::parse($year)->diffInYears();
- }else{
- $age = 0;
- }
- $num=substr($cre_num,16,1);
- if($num%2==0){
- $sex = '女';
- }else{
- $sex = '男';
- }
- $name=$store->username;
- $phone=$store->phone;
- switch(Auth::user()->level){
- case 1:
- $level='销售员';
- break;
- case 2:
- $level='经销商';
- break;
- default:
- $level='批发商';
- }
- $data=['username'=>$name,'sex'=>$sex,'age'=>$age,'phone'=>$phone,'level'=>$level,'cre_num'=>$cre_num];
- return $this->success($data);
- }
- //同意门店协议
- // public function setAgree()
- // {
- // $store=Store::where('user_id',Auth::user()->id)->first();
- // $store->is_agree=1;
- // $res=$store->save();
- // if($res){
- // return $this->success([]);
- // }else{
- // return $this->error();
- // }
- // }
- //修改店铺信息
- public function editStoreInfo(Request $request)
- {
- $input=$request->all();
- $rules=[
- 'name'=>'required|max:32'
- ];
- $message=[
- 'name.required'=>'用户名称不能为空.',
- 'name.max'=>'用户名称不能大于32个字符.'
- ];
- $validator = Validator::make($input,$rules,$message);
- if($validator->fails()){
- return $this->error('400013',$validator->errors()->first());
- }
- $store_id=$input['store_id'];
- $name=$input['name'];
- $res=Store::where('id',$store_id)->update(['name'=>$name]);
- if($res){
- return $this->success([]);
- }else{
- return $this->error();
- }
- }
- //修改手机号
- public function editSms(Request $request)
- {
- $rules=[
- 'phone'=>'required|regex:/^1[3456789][0-9]{9}$/',
- 'phone_code'=>'required|size:6',
- ];
- $message=[
- 'phone.required'=>'手机号不能为空.',
- 'phone.regex'=>'手机号格式有误.',
- 'phone_code.required'=>'验证码不能为空.',
- 'phone_code.size'=>'验证码为6位字符串.',
- ];
- $validator = Validator::make($request->input(),$rules,$message);
- if($validator->fails()){
- return $this->error('400013',$validator->errors()->first());
- }
- $phone=$request->input('phone');
- if($phone == Store::where('user_id',Auth::user()->id)->value('phone')){
- return $this->error('450001','新手机号不能与旧手机号相同');
- }
- if(Store::where('phone',$phone)->first()){
- return $this->error('450001','新手机号已绑定店铺');
- }
- $store_id=$request->input('store_id');
- $phone_code=$request->input('phone_code');
- $code=Cache::get('sms'.$phone);
- if($code==$phone_code){
- Cache::put('sms'.$phone,$code,-1);
- $res=Store::where('id',$store_id)->update(['phone'=>$phone]);
- if($res){
- return $this->success([]);
- }
- }else{
- return $this->error('450001','验证码有误');
- }
- return $this->error();
- }
- //校验手机验证码
- public function checkSms(Request $request)
- {
- $rules=[
- 'phone'=>'required|regex:/^1[3456789][0-9]{9}$/',
- 'phone_code'=>'required|size:6',
- ];
- $message=[
- 'phone.required'=>'手机号不能为空.',
- 'phone.regex'=>'手机号格式有误.',
- 'phone_code.required'=>'验证码不能为空.',
- 'phone_code.size'=>'验证码为6位字符串.',
- ];
- $validator = Validator::make($request->input(),$rules,$message);
- if($validator->fails()){
- return $this->error('400013',$validator->errors()->first());
- }
- $phone=$request->input('phone');
- $phone_code=$request->input('phone_code');
- $code=Cache::get('sms'.$phone);
- if($code==$phone_code){
- Cache::put('sms'.$phone,$code,-1);
- return $this->success([]);
- }else{
- return $this->error('450001','验证码有误');
- }
- }
- //发送验证码
- public function sendSms(Request $request){
- $rules=[
- 'phone'=>'required|regex:/^1[3456789][0-9]{9}$/'
- ];
- $message=[
- 'phone.required'=>'手机号不能为空.',
- 'phone.regex'=>'手机号格式有误.'
- ];
- $validator = Validator::make($request->input(),$rules,$message);
- if($validator->fails()){
- return $this->error('400013',$validator->errors()->first());
- }
- $phone=$request->input('phone');
- $config=config('easysms');
- $easySms = new EasySms($config);
- $code = mt_rand(100000,999999);
- $minute=5;
- if($request->input('type')=='card'){
- $content="【大卫博士】您正在绑定身份信息,{$code}为您的验证码,请于{$minute}分钟内填写。如非本人操作,请忽略本短信。 ";
- }else{
- $content="【大卫博士】您正在换绑手机号,{$code}为您的更换验证码,请于{$minute}分钟内填写。如非本人操作,请忽略本短信。";
- }
- Cache::put('sms'.$phone,$code,$minute*60);
- try{
- $easySms->send($phone, ['content' =>$content ]);
- } catch (\Overtrue\EasySms\Exceptions\NoGatewayAvailableException $exception) {
- $message = $exception->getException('qcloud')->getMessage();
- return $this->error(40013, $message == null ? '短信发送异常' : $message);
- }
- return $this->success([]);
- }
- //分享店铺信息
- public function shareStore()
- {
- $store=Store::where('user_id',Auth::user()->id)->first();
- $store->user=Auth::user();
- return $this->success($store);
- }
- //修改店铺图片
- public function uploadStoreImg(Request $request)
- {
- $path_url = 'public/store';
- $path = $request->file('img')->store($path_url);
- if($path){
- $store_id=$request->input('store_id');
- $url = env('APP_URL').Storage::url($path);
- $res=Store::where('id',$store_id)->update(['img'=>$url]);
- if ($res) {
- return $this->success($url);
- }
- }
- return $this->error();
- }
- //上传证件照片
- public function uploadCertImg(Request $request)
- {
- $paths='cert/'.date("Ymd").'/';
- $path_url = $paths.date("His").mt_rand(10000,99999).'.jpg';
- if(!is_dir($paths)){
- mkdir($paths,0755,true);
- }
- Log::info($path_url);
- $type=$request->input('type');//1人像面 2国徽面
- $file = $request->file('img');
- Log::info($file);
- $img=Image::make($file);
- Log::info(json_encode($img));
- // \Illuminate\Support\Facades\Log::error(1);
- if($img->filesize() > 1024*1024){
- $img->resize(800, null, function ($constraint) {
- $constraint->aspectRatio();
- })->save($path_url);
- }else{
- $img->save($path_url);
- }
- $path='/'.$img->basePath();
- if($path){
- $url = env('APP_URL').$path;
- Log::info('%%%%%%-----%%%%%%'.$url.'--'.$path.'---'.env('APP_URL'));
- }else{
- return $this->error('450001','证件上传失败');
- }
- try{
- // $certInfo=json_decode($this->getCertInfo($url),true);
- $tenCent = new TencentHandler();
- $certInfo=json_decode($tenCent->getCertInfo($url),true);
- }catch(\Exception $e){
- return $this->error('450001',$e->getMessage());
- }
- if(empty($certInfo)){
- return $this->error('450001','上传图片有误');
- }
- $AdvancedInfo=json_decode($certInfo['AdvancedInfo'],true);
- Log::info(Auth::user()->nickname.'身份证图片质量指数:'.$AdvancedInfo['Quality']);
- if($AdvancedInfo['Quality']<=55){
- return $this->error('450001','身份证图片模糊');
- }
- foreach($tenCent->AdvancedInfo() as $key=>$val){
- if(in_array($key,$AdvancedInfo['WarnInfos']))
- return $this->error('450001',$val);
- }
- if($type==1){
- if(empty($certInfo['Name'])){
- return $this->error('450001','请上传人像面图片');
- }else{
- Store::where('user_id',Auth::user()->id)->update(['cardImg1'=>$url]);
- }
- }elseif($type==2){
- if(empty($certInfo['Authority'])){
- return $this->error('450001','请上传国徽面图片');
- }else{
- Store::where('user_id',Auth::user()->id)->update(['cardImg2'=>$url]);
- }
- }else{
- return $this->error('450001','参数有误');
- }
- $certInfo['url']=$path;
- return $this->success($certInfo);
- }
- //上传证件照片--》七牛云
- public function uploadCertImgQiniuyun(Request $request)
- {
- $type=$request->input('type');//1人像面 2国徽面
- if (!$request->hasFile('img')) {
- return $this->error('450001','请上传文件');
- }
- //设置文件后缀白名单
- $allowExt = ["jpg","png","jpeg"];
- //获取文件
- $file = $request->file('img');
- // 获取七牛云配置信息
- $config = [
- 'driver' => 'qiniu',
- 'domain' => 'http://image.chuliu.cc', //七牛域名
- 'access_key' => 'cIbo9JAqHBgO6uw97gT5fJOlEHiTiGrpB84unVEn', //AccessKey
- 'secret_key' => '4f0nTNNrvzOsFc6Rz0GC5DntiJRnk2GcfkyJFNQp', //SecretKey
- 'bucket' => 'daweiboshi-app', //Bucket名字
- 'dirname'=> 'daweiboshi-app'
- ];
- // 构建鉴权对象
- $auth = new Auths($config['access_key'], $config['secret_key']);
- // 生成上传 Token
- $token = $auth->uploadToken($config['bucket']);
- //获取文件的绝对路径,但是获取到的在本地不能打开
- $filePath = $file->getRealPath();
- //获取文件的扩展名
- $ext = $file->getClientOriginalExtension();
- //获取上传文件的名称
- $ext_name = $file->getClientOriginalName();
- Log::info('上传文件的名称->'.$ext_name);
- //判断是否是Excel
- if (empty($ext) || !in_array(strtolower($ext), $allowExt)) {
- return $this->error('450001','不允许的文件类型');
- }
- // 新文件名
- $filename =date('His') . uniqid(mt_rand(10000,99999)) .'.'. $ext;
- $dirname=$config['dirname'];
- // 初始化 UploadManager 对象并进行文件的上传。
- $uploadMgr = new UploadManager();
- // 调用 UploadManager 的 putFile 方法进行文件的上传。
- $pathname= $dirname.'/'.date('Ymd').'/'.$filename;
- try{
- $uploadMgr->putFile($token, $pathname, $filePath);
- }catch(\Exception $e){
- return $this->error('450001',$e->getMessage(),$e->getMessage());
- }
- // 获取文件完整路径
- $url = $config['domain'].'/'.$pathname;
- Log::info($url);
- try{
- $tenCent = new TencentHandler();
- $certInfo=json_decode($tenCent->getCertInfo($url.'?imageView2/0/w/600/q/100'),true);
- }catch(\Exception $e){
- Log::info('图片识别错误111111');
- Log::info($e->getMessage());
- return $this->error('450001',$e->getMessage(),$e->getMessage());
- }
- if(empty($certInfo)){
- return $this->error('450001','上传图片有误','上传图片有误');
- }
- $AdvancedInfo=json_decode($certInfo['AdvancedInfo'],true);
- Log::info(Auth::user()->nickname.'身份证图片质量指数:'.$AdvancedInfo['Quality']);
- if($AdvancedInfo['Quality']<=55){
- return $this->error('450001','身份证图片模糊','身份证图片模糊');
- }
- foreach($tenCent->AdvancedInfo() as $key=>$val){
- if(in_array($key,$AdvancedInfo['WarnInfos'])){
- Log::info('111111错误111111--'.$val);
- return $this->error('450001',$val,$val);
- }
- }
- if($type==1){
- if(empty($certInfo['Name'])){
- return $this->error('450001','请上传人像面图片','请上传人像面图片');
- }else{
- Store::where('user_id',Auth::user()->id)->update(['cardImg1'=>$url]);
- }
- }elseif($type==2){
- if(empty($certInfo['Authority'])){
- return $this->error('450001','请上传国徽面图片','请上传国徽面图片');
- }else{
- Store::where('user_id',Auth::user()->id)->update(['cardImg2'=>$url]);
- }
- }else{
- return $this->error('450001','参数有误','参数有误');
- }
- $certInfo['url']='/'.$pathname;
- return $this->success($certInfo);
- }
- //上传证件照片--》压缩 七牛云
- public function uploadCertImgQny(Request $request)
- {
- $type= $request->input('type'); //1人像面 2国徽面
- $file= $request->file('img');
- if (!$request->hasFile('img')) {
- return $this->error('450001','请上传文件');
- }
- //设置文件后缀白名单
- $allowExt = ["jpg","png","jpeg"];
- //获取文件后缀名
- $ext = $file->getClientOriginalExtension();
- //判断文件格式是否正确
- if (empty($ext) || !in_array(strtolower($ext), $allowExt)) {
- return $this->error('450001','不允许上传的文件类型');
- }
- // 获取七牛云配置信息
- $config = [
- 'driver' => 'qiniu',
- 'domain' => 'http://image.chuliu.cc', //七牛域名
- 'access_key' => 'cIbo9JAqHBgO6uw97gT5fJOlEHiTiGrpB84unVEn', //AccessKey
- 'secret_key' => '4f0nTNNrvzOsFc6Rz0GC5DntiJRnk2GcfkyJFNQp', //SecretKey
- 'bucket' => 'daweiboshi-app', //Bucket名字
- 'dirname'=> 'daweiboshi-app'
- ];
- // 构建鉴权对象
- $auth = new Auths($config['access_key'], $config['secret_key']);
- // 生成上传 Token
- $token = $auth->uploadToken($config['bucket']);
- // 初始化 UploadManager 对象并进行文件的上传。
- $uploadMgr = new UploadManager();
- // 文件存储路径key
- $pathname= $config['dirname'].'/'.date('Ymd').'/'.date('His') . uniqid(mt_rand(10000,99999)) .'.'. $ext;
- Log::info('文件大小:'.$_FILES['img']['size']);
- if($_FILES['img']['size'] > 1024*1024){
- $handler= new CompressImageHandler();
- $contents= $handler->Upload();
- if(!$contents){
- return $this->error('450001','图片压缩失败');
- }
- // 调用 UploadManager 的 put 方法进行文件的上传。
- try{
- $uploadMgr->put($token, $pathname, $contents);
- }catch(\Exception $e){
- return $this->error('450001',$e->getMessage(),$e->getMessage());
- }
- }else{
- //获取文件的绝对路径,但是获取到的在本地不能打开
- $filePath = $file->getRealPath();
- // 调用 UploadManager 的 putFile 方法进行文件的上传。
- try{
- $uploadMgr->putFile($token, $pathname, $filePath);
- }catch(\Exception $e){
- return $this->error('450001',$e->getMessage(),$e->getMessage());
- }
- }
- // 获取文件完整路径
- $url = $config['domain'].'/'.$pathname;
- Log::info($url);
- try{
- $tenCent = new TencentHandler();
- $certInfo=json_decode($tenCent->getCertInfo($url),true);
- }catch(\Exception $e){
- Log::info('图片识别错误111');
- Log::info($e->getMessage());
- return $this->error('450001',$e->getMessage(),$e->getMessage());
- }
- if(empty($certInfo)){
- return $this->error('450001','上传图片有误','上传图片有误');
- }
- $AdvancedInfo=json_decode($certInfo['AdvancedInfo'],true);
- Log::info(Auth::user()->nickname.'身份证图片质量指数:'.$AdvancedInfo['Quality']);
- if($AdvancedInfo['Quality']<=55){
- return $this->error('450001','身份证图片模糊','身份证图片模糊');
- }
- foreach($tenCent->AdvancedInfo() as $key=>$val){
- if(in_array($key,$AdvancedInfo['WarnInfos'])){
- Log::info('111错误111--'.$val);
- return $this->error('450001',$val,$val);
- }
- }
- if($type==1){
- if(empty($certInfo['Name'])){
- return $this->error('450001','请上传人像面图片','请上传人像面图片');
- }else{
- Store::where('user_id',Auth::user()->id)->update(['cardImg1'=>$url]);
- }
- }elseif($type==2){
- if(empty($certInfo['Authority'])){
- return $this->error('450001','请上传国徽面图片','请上传国徽面图片');
- }else{
- Store::where('user_id',Auth::user()->id)->update(['cardImg2'=>$url]);
- }
- }else{
- return $this->error('450001','参数有误','参数有误');
- }
- $certInfo['url']='/'.$pathname;
- return $this->success($certInfo);
- }
- //上传活体人脸核身视频
- public function uploadFaceImg(Request $request){
- $path_url = 'public/cert/video/'.date('ymd');
- $path = $request->file('video')->store($path_url);
- if($path){
- $url = env('APP_URL').Storage::url($path);
- }else{
- return $this->error('450001','视频上传失败');
- }
- try{
- $tenCent = new TencentHandler();
- $certInfo=json_decode($tenCent->checkFaceId($idCard,$name,$url),true);
- }catch(\Exception $e){
- return $this->error('450001',$e->getMessage());
- }
- if(empty($certInfo) || $certInfo['Sim'] < 70){
- return $this->error('450001','认证失败');
- }
- if($certInfo['Result']=='Success' && $certInfo['Sim'] >= 70){
- return $this->success([]);
- }
- }
- //获取证件信息
- // public function getCertInfo($img)
- // {
- // $cred = new Credential(env('TENCENT_SECRETID'), env('TENCENT_SECRETKEY'));
- // $httpProfile = new HttpProfile();
- // $httpProfile->setEndpoint("ocr.tencentcloudapi.com");
- //
- // $clientProfile = new ClientProfile();
- // $clientProfile->setHttpProfile($httpProfile);
- // $client = new OcrClient($cred, "ap-beijing", $clientProfile);
- // $req = new IDCardOCRRequest();
- // $params = [
- // 'ImageUrl'=>$img,
- // 'Config' => json_encode(["CopyWarn"=>true,"BorderCheckWarn"=>true,"ReshootWarn"=>true,"DetectPsWarn"=>true,"TempIdWarn"=>true,"InvalidDateWarn"=>true,"Quality"=>true,"ReflectWarn"=>true])
- // ];//"CropIdCard"=>true,"CropPortrait"=>true,
- // $req->fromJsonString(json_encode($params));
- // $resp = $client->IDCardOCR($req);
- // return $resp->toJsonString();
- // }
- //活体人脸核身
- // public function checkFaceId($idCard,$name,$base)
- // {
- // $cred = new Credential(env('TENCENT_SECRETID'), env('TENCENT_SECRETKEY'));
- // $httpProfile = new HttpProfile();
- // $httpProfile->setEndpoint("faceid.tencentcloudapi.com");
- //
- // $clientProfile = new ClientProfile();
- // $clientProfile->setHttpProfile($httpProfile);
- // $client = new OcrClient($cred, "ap-beijing", $clientProfile);
- // $req = new IDCardOCRRequest();
- // $params = [
- // 'IdCard'=>$idCard,
- // 'Name'=>$name,
- // 'VideoBase64'=>$base,
- // 'LivenessType'=>'SILENT',//LIP为数字模式,ACTION为动作模式,SILENT为静默模式
- // ];
- // $req->fromJsonString(json_encode($params));
- // $resp = $client->IDCardOCR($req);
- // return $resp->toJsonString();
- // }
- //门店认证
- // public function certStore(Request $request)
- // {
- // $input=$request->all();
- // $rules=[
- // 'name'=>'required|max:32',
- // 'idCard'=>'required|size:18',
- // 'phone'=>'required|regex:/^1[3456789][0-9]{9}$/',
- // 'phone_code'=>'required|size:6',
- // ];
- // $message=[
- // 'name.required'=>'用户名称不能为空',
- // 'name.max'=>'用户名称不能大于32个字符',
- // 'idCard.required'=>'证件号不能为空',
- // 'idCard.size'=>'证件号为18个字符',
- // 'phone.required'=>'手机号不能为空.',
- // 'phone.regex'=>'手机号格式有误.',
- // 'phone_code.required'=>'验证码不能为空.',
- // 'phone_code.size'=>'验证码为6位字符串.',
- // ];
- // $validator = Validator::make($input,$rules,$message);
- // if($validator->fails()){
- // return $this->error('400013',$validator->errors()->first());
- // }
- // $store_id=$input['store_id'];
- // $idCard=$input['idCard'];
- // $name=$input['name'];
- // $phone=$input['phone'];
- // $phone_code=$input['phone_code'];
- // $card_name=$input['card_name'];
- // $card_no=$input['card_no'];
- // $code=Cache::get('sms'.$phone);
- // if($code!=$phone_code){
- // return $this->error('450001','验证码有误');
- // }
- // Cache::put('sms'.$phone,$code,-1);
- // if($name != $card_name || $idCard!=$card_no){
- // return $this->error('450001','证件信息与输入个人信息不一致');
- // }
- // if(Store::where('idCard',$card_no)->first()){
- // return $this->error('450001','证件信息已被绑定');
- // }
- // $store=Store::where('id',$store_id)->first();
- // if($store){
- // $store->idCard=$idCard;
- // $store->username=$name;
- // $store->is_cert=1;
- // }else{
- // return $this->error('450001','店铺信息有误');
- // }
- // try{
- // DB::Transaction(function()use($store,$idCard){
- // $user=User::where('id',$store->user_id)->first();
- // if($user){
- // $user->cre_num=$idCard;
- // $user->save();
- // }
- //
- // $store->save();
- //
- // },5);
- // return $this->success([]);
- // }catch(\Exception $e){
- // return $this->error($e->getMessage());
- // }
- // }
- //添加新用户
- public function addUser(Request $request){
- $area_code=$request->input('code','+86');
- $regex=Verify::where('code',$area_code)->value('preg');
- $rules=[
- 'phone'=>['required','regex:'.$regex]
- ];
- $message=[
- 'phone.required'=>'手机号不能为空.',
- 'phone.regex'=>'手机号格式有误.'
- ];
- $validator = Validator::make($request->input(),$rules,$message);
- if($validator->fails()){
- return $this->error('400013',$validator->errors()->first());
- }
- $agent_id = Auth::user()->id;
- $phone=$request->input('phone');
- $nickname=$request->input('nickname');
- $is_vip=$request->input('is_vip');
- $store = Store::where('user_id',$agent_id)->first();
- $agent=User::where('mobile',$phone)
- ->where(function($query){
- $query->where('cert_status',3)
- ->orWhere('cert_status',6);
- })
- ->where('service_status',0)->whereNull('deleted_at')->first();
- if($agent){
- return $this->error('450001','该手机号已注册,不能使用');
- }
- $user=UserW::where('phone',$phone)->first();
- try{
- DB::transaction(function()use(&$user,$phone,$nickname,$area_code,$store,$is_vip,$request){
- if(empty($user)){
- $user=UserW::create([
- 'area_code'=>$area_code,
- 'phone'=>$phone,
- 'name'=>$nickname?:$phone,
- 'avatar' => 'http://api.app.cliu.cc/public/uploads/logo.jpg',
- 'nickname'=>$nickname?:$phone
- ]);
- }
- $agent_id=Auth::user()->id;
- $store_id=Store::where('user_id',$agent_id)->value('id');
- if($request->input('province') && $request->input('city') && $request->input('area') && $request->input('address')){
- AddressW::create([
- 'name'=>$nickname?:$phone,
- 'area_code'=>$area_code,
- 'phone'=>$phone,
- 'user_id'=>$user->id,
- 'store_id'=>$store_id,
- 'province'=>$request->input('province'),
- 'city'=>$request->input('city'),
- 'area'=>$request->input('area'),
- 'address'=>$request->input('address'),
- 'is_default'=>$request->input('is_default',0),
- 'remark'=>$request->input('remark',null),
- 'type'=>2,
- ]);
- }
- if($is_vip==1){
- $user->is_vip=1;
- VipLogW::firstORCreate(['user_id'=>$user->id,'store_id'=>$store->id],['order_no'=>null,'type'=>1,'remark'=>'商户手动添加vip']);
- }else{
- $user->is_vip=0;
- }
- },5);
- return $this->success($user);
- }catch(\Exception $e){
- return $this->error($e->getMessage());
- }
- }
- //设置vip
- public function setVip(Request $request){
- $agent_id=Auth::user()->id;
- $user_id=$request->input('user_id');
- $store_id=Store::where('user_id',$agent_id)->value('id');
- VipLogW::firstORCreate(['user_id'=>$user_id,'store_id'=>$store_id],['order_no'=>null,'type'=>1,'remark'=>'商户手动设置vip']);
- return $this->success([]);
- }
- //取消vip
- public function cancelVip(Request $request){
- $agent_id=Auth::user()->id;
- $user_id=$request->input('user_id');
- $store_id=Store::where('user_id',$agent_id)->value('id');
- $vip=VipLogW::where('store_id',$store_id)->where('user_id',$user_id)->first();
- if(empty($vip)){
- return $this->error('450001','该客户不是vip');
- }
- $orders=OrderW::where('store_id',$store_id)->where('user_id',$user_id)->get();
- if(count($orders)>0){
- return $this->error('450001','该客户已下单,无法取消vip');
- }
- $vip=VipLogW::where('store_id',$store_id)->where('user_id',$user_id)->first();
- $vip->remark=!empty($vip->remark)?$vip->remark.'->商户删除':'商户删除';
- $vip->save();
- $vip->delete();
- return $this->success([]);
- }
- //获取用户数据信息
- public function getUserDataInfo()
- {
- $store_id = Store::where('user_id',Auth::user()->id)->value('id');
- //客户总数
- $user_num = OrderW::where('store_id', $store_id)
- ->where('is_pay',1)->groupBy('user_id')
- ->whereIn('apply_cancel',[0,1,3])
- ->whereIn('is_refund',[0,1,2])
- ->get()->count();
- //订单数量
- $order_num = OrderW::where('store_id', $store_id)
- ->whereIn('apply_cancel',[0,1,3])
- ->whereIn('is_refund',[0,1,2])
- ->where('is_pay',1)->count();
- //总交易额
- $sale_total = OrderW::where('store_id', $store_id)->where('is_pay',1)->sum('account');
- $sale_total = round($sale_total);
- //扫码用户
- $scan_user = Scan::with('user:id,nickname,avatar')->where('store_id', $store_id)
- ->orderByDesc('created_at')->limit(5)->get();
- $scan_num = Scan::has('user')->where('store_id', $store_id)->count();
- $scan_7_num = Scan::has('user')->where('store_id', $store_id)->whereBetween('created_at', [date("Y-m-d H:i", strtotime('-7 days')), date("Y-m-d H:i")])->count();
- //已购客户
- // $buy_num=UserW::whereHas('order', function ($query)use($store_id) {
- // $query->where('store_id', $store_id)->where('is_pay', 1);
- // })->get()->count();
- // $buy_user = OrderW::with('user:id,nickname,avatar,phone')
- // ->where('store_id',$store_id)->where('is_pay',1)
- // ->orderByDesc('created_at')->limit(5)->get();
- // $user_ids=UserW::where('store_id',$store_id)->pluck('id');
- $userInfo=OrderW::with('user:id,nickname,avatar,phone')->has('user')
- ->where('store_id',$store_id)->where('is_pay',1)
- ->select('user_id',DB::raw('sum(total) as total'),DB::raw('sum(account) as amount'))
- ->groupBy('user_id')->orderByDesc('amount')
- ->orderByDesc('total')->orderBy('user_id')
- ->limit(5)->get();
- $buy_7_num = OrderW::where('store_id', $store_id)
- ->whereBetween('created_at', [date("Y-m-d H:i", strtotime('-7 days')), date("Y-m-d H:i")])
- ->where('is_pay',1)
- ->count();
- $data['user_num'] = $user_num ? $user_num : 0;
- $data['sale_total'] = $sale_total ? $sale_total : 0;
- $data['scan_user'] = $scan_user ? $scan_user : [];
- $data['scan_num'] = $scan_num ? $scan_num : 0;
- $data['scan_7_num'] = $scan_7_num ? $scan_7_num : 0;
- // $data['buy_user'] = $buy_user ? $buy_user : [];
- // $data['buy_num'] = $buy_num ? $buy_num : 0;
- $data['order_num'] = $order_num ? $order_num : 0;
- $data['buy_7_num'] = $buy_7_num ? $buy_7_num : 0;
- $data['user_info'] = $userInfo;
- return $this->success($data);
- }
- //扫码用户查看更多
- public function getMoreScan(Request $request)
- {
- $input = $request->input();
- $page_index = $input['page_index'];
- $page_size = $input['page_size'];
- $num = $page_size * ($page_index - 1);
- $store_id = Store::where('user_id',Auth::user()->id)->value('id');
- $data=Scan::with('user:id,nickname,avatar')
- ->has('user')
- ->where('store_id', $store_id);
- $count=$data->count();
- $list=$data->orderByDesc('created_at')->skip($num)->limit($page_size)->get();
- return $this->success_list($list,'成功',$count);
- }
- //已购客户查看更多
- public function getMoreBuy(Request $request)
- {
- $input=$request->input();
- $page_index=$input['page_index'];
- $page_size=$input['page_size'];
- $num=$page_size*($page_index-1);
- $store_id = Store::where('user_id',Auth::user()->id)->value('id');
- // $data=UserW::withCount(['order'=>function($query){
- // $query->select(DB::raw("sum(account) as money"));
- // }])
- // ->where('store_id', $store_id)->having('order_count','>',0);
- $data=OrderW::with('user:id,nickname,avatar,phone')
- ->where('store_id',$store_id)->where('is_pay',1);
- $count=$data->get()->count();
- $list=$data->orderByDesc('created_at')->skip($num)->limit($page_size)
- ->get();
- return $this->success_list($list,'成功',$count);
- }
- //获取更多用户信息
- public function getMoreUserInfo(Request $request){
- $input=$request->input();
- $page_index=$input['page_index'];
- $page_size=$input['page_size'];
- $num=$page_size*($page_index-1);
- $store_id = Store::where('user_id',Auth::user()->id)->value('id');
- $data=OrderW::with('user:id,nickname,avatar,phone')->has('user')
- ->where('store_id',$store_id)->where('is_pay',1)
- ->select('user_id',DB::raw('sum(total) as total'),DB::raw('sum(account) as amount'))
- ->groupBy('user_id');
- $count=$data->get()->count();
- $list=$data->orderByDesc('amount')->orderByDesc('total')->orderBy('user_id')
- ->skip($num)->limit($page_size)->get();
- return $this->success_list($list,'成功',$count);
- }
- //获取用户所有订单
- public function getUserAllOrder(Request $request){
- $user_id=$request->input('user_id');
- $status=$request->input('status');
- $order_no=$request->input('order_no');
- $page_size=$request->input('page_size');
- $page_index=$request->input('page_index');
- $num=$page_size*($page_index-1);
- $where=[];
- if($status!='all'){
- $where['status']=$status;
- }
- $where['user_id']=$user_id;
- $data=OrderW::with(['user:id,nickname,phone','order_cancel'=>function($query){
- $query->where('using',1);}])
- ->where($where)
- ->whereIn('apply_cancel',[0,1,3])
- ->orderByDesc('id');
- if($order_no){
- $data->where('order_no','like','%'.$order_no.'%');
- }
- $count=$data->count();
- $orders=$data->skip($num)->take($page_size)->get();
- foreach($orders as $key=>$val){
- $goods_ids=OrderDetailW::where('order_no',$val->order_no)->groupBy('goods_id')->pluck('goods_id');
- $goods=[];
- foreach($goods_ids as $k=>$v){
- $goods[$k]=StoreGoods::where('id',$v)->first();
- $goods[$k]->sku=OrderDetailW::where('order_no',$val->order_no)->where('goods_id',$v)->get();
- }
- $orders[$key]->goods=$goods;
- }
- return $this->success_list($orders,'成功',$count);
- }
- //获取代为下单用户信息
- public function getUserInfo(Request $request)
- {
- $input=$request->all();
- $phone=$input['phone'];
- $user=UserW::where('phone',$phone)->first();
- if(empty($user)){
- return $this->error('450001','用户手机号有误');
- }
- if($user->status==1){
- return $this->error('450001','用户已被禁用');
- }
- return $this->success($user);
- }
- //获取用户所有收货地址
- public function getAllAddress(Request $request)
- {
- $input=$request->All();
- $agent_id=Auth::user()->id;
- $store_id=Store::where('user_id',$agent_id)->value('id');
- $address=AddressW::where('user_id',$input['id'])->whereIn('type',[1,2])->orderByDesc('is_default')->orderByDesc('created_at')->get();
- // $address=AddressW::where('user_id',$input['id'])->where('store_id',$store_id)->where('type',2)->orderByDesc('is_default')->orderByDesc('created_at')->get();
- return $this->success($address);
- }
- //获取收货地址
- public function getAddress(Request $request)
- {
- $input=$request->All();
- $agent_id=Auth::user()->id;
- $store_id=Store::where('user_id',$agent_id)->value('id');
- $data['address']=AddressW::where('user_id',$input['id'])->whereIn('type',[1,2])->orderByDesc('is_default')->orderByDesc('created_at')->first();
- // $data['address']=AddressW::where('user_id',$input['id'])->where('store_id',$store_id)->where('type',2)->orderByDesc('is_default')->orderByDesc('created_at')->first();
- $data['store']=Store::with('address_store')->where('user_id',Auth::user()->id)->first();
- return $this->success($data);
- }
- //添加收货地址
- public function addAddress(Request $request)
- {
- $input=$request->all();
- $regex=Verify::where('code',$request->input('areaCode','+86'))->value('preg');
- $rules=[
- 'name'=>'required|max:32',
- 'phone'=>['required','regex:'.$regex],
- 'province'=>'required',
- 'city'=>'required',
- 'area'=>'required',
- 'address'=>'required|max:255',
- ];
- $message=[
- 'name.required'=>'收货人不能为空.',
- 'name.max'=>'收货人姓名不能大于32个字符.',
- 'phone.required'=>'手机号不能为空.',
- 'phone.regex'=>'手机号格式有误.',
- 'province.required'=>'省不能为空.',
- 'city.required'=>'市不能为空.',
- 'area.required'=>'区/县不能为空.',
- 'address.required'=>'详细地址不能为空.',
- 'address.max'=>'详细地址不能大于255个字符.'
- ];
- $validator = Validator::make($input,$rules,$message);
- if($validator->fails()){
- return $this->error('400013',$validator->errors()->first());
- }
- $count=AddressW::where('user_id',$input['user_id'])->count();
- // if($count>=10){
- // return $this->error('450001','用户地址数量已达上限');
- // }
- if($input['is_default']==1){
- AddressW::where('user_id',$input['user_id'])->update(['is_default'=>0]);
- }
- $agent_id=Auth::user()->id;
- $store_id=Store::where('user_id',$agent_id)->value('id');
- $res=AddressW::create([
- 'name'=>$input['name'],
- 'area_code'=>$request->input('areaCode','+86'),
- 'phone'=>$input['phone'],
- 'user_id'=>$input['user_id'],
- 'store_id'=>$store_id,
- 'province'=>$input['province'],
- 'city'=>$input['city'],
- 'area'=>$input['area'],
- 'address'=>$input['address'],
- 'is_default'=>$input['is_default'],
- 'remark'=>$input['remark'],
- 'type'=>2,
- ]);
- if($res){
- return $this->success([]);
- }else{
- return $this->error();
- }
- }
- //修改收货地址
- public function updateAddress(Request $request)
- {
- $input=$request->all();
- $regex=Verify::where('code',$request->input('areaCode','+86'))->value('preg');
- $rules=[
- 'name'=>'required|max:32',
- 'phone'=>['required','regex:'.$regex],
- 'province'=>'required',
- 'city'=>'required',
- 'area'=>'required',
- 'address'=>'required|max:255',
- ];
- $message=[
- 'name.required'=>'收货人不能为空.',
- 'name.max'=>'收货人姓名不能大于32个字符.',
- 'phone.required'=>'手机号不能为空.',
- 'phone.regex'=>'手机号格式有误.',
- 'province.required'=>'省不能为空.',
- 'city.required'=>'市不能为空.',
- 'area.required'=>'区/县不能为空.',
- 'address.required'=>'详细地址不能为空.',
- 'address.max'=>'详细地址不能大于255个字符.'
- ];
- $validator = Validator::make($input,$rules,$message);
- if($validator->fails()){
- return $this->error('400013',$validator->errors()->first());
- }
- $address_id=$input['address_id'];
- $address=AddressW::where('id',$address_id)->first();
- if($input['is_default']==1){
- AddressW::where('user_id',$address->user_id)->update(['is_default'=>0]);
- }
- $res=AddressW::where('id',$address_id)->update([
- 'name'=>$input['name'],
- 'area_code'=>$request->input('areaCode','+86'),
- 'phone'=>$input['phone'],
- 'province'=>$input['province'],
- 'city'=>$input['city'],
- 'area'=>$input['area'],
- 'address'=>$input['address'],
- 'is_default'=>$input['is_default'],
- 'remark'=>$input['remark'],
- ]);
- if($res){
- return $this->success([]);
- }else{
- return $this->error();
- }
- }
- //删除收货地址
- public function destroyAddress(Request $request)
- {
- $res=AddressW::where('id',$request->input('id'))->delete();
- if($res){
- return $this->success([]);
- }else{
- return $this->error();
- }
- }
- //设为默认地址
- public function setDefaultAddress(Request $request)
- {
- $address=AddressW::where('id',$request->input('id'))->first();
- try{
- DB::connection('mysql_w')->transaction(function()use($address){
- if($address->is_default == 1) {
- $address->is_default = 0;
- $address->save();
- }else{
- $address->is_default = 1;
- $address->save();
- AddressW::where('user_id',$address->user_id)->whereNotIn('id',[$address->id])->update(['is_default'=>0]);
- }
- },5);
- return $this->success([]);
- }catch(\Exception $e){
- return $this->error($e->getMessage());
- }
- }
- //判断订单价格
- protected function getOrderPrice($user_id,$store_id,$num){
- $vipLog=VipLogW::where('user_id',$user_id)->where('store_id',$store_id)->first();
- if($vipLog){
- return 'vip_ed';//vip价格
- }else{
- if($num>=2){
- return 'vip_ing';//vip价格
- }else{
- return 'normal';//正常价
- }
- }
- }
- //记录下单时商户关系
- protected function saveAgentNoLog($user_id,$agent_id,$order_no){
- $one=$agent_id;
- $one_agent=User::where('id',$one)->first();
- $data=[];
- $data[0]['order_no'] = $order_no;
- $data[0]['user_id'] = $user_id;
- // $data[0]['agent_id'] = $one;
- $data[0]['level'] = $one_agent->level;
- $data[0]['nickname'] = $one_agent->nickname;
- $data[0]['phone'] = $one_agent->mobile;
- $data[0]['created_at'] = date("Y-m-d H:i:s");
- $data[0]['updated_at'] = date("Y-m-d H:i:s");
- if($one_agent->level==2 || $one_agent->level==1){
- $two=User::where('id',$one)->value('agent_id');
- $two_agent=User::where('id',$two)->first();
- $data[1]['order_no'] = $order_no;
- $data[1]['user_id'] = $user_id;
- // $data[1]['agent_id'] = $two;
- $data[1]['level'] = $two_agent->level;
- $data[1]['nickname'] = $two_agent->nickname;
- $data[1]['phone'] = $two_agent->mobile;
- $data[1]['created_at'] = date("Y-m-d H:i:s");
- $data[1]['updated_at'] = date("Y-m-d H:i:s");
- if($two_agent->level==2){
- $three=User::where('id',$two)->value('agent_id');
- $three_agent=User::where('id',$three)->first();
- $data[2]['order_no'] = $order_no;
- $data[2]['user_id'] = $user_id;
- // $data[2]['agent_id'] = $three;
- $data[2]['level'] = $three_agent->level;
- $data[2]['nickname'] = $three_agent->nickname;
- $data[2]['phone'] = $three_agent->mobile;
- $data[2]['created_at'] = date("Y-m-d H:i:s");
- $data[2]['updated_at'] = date("Y-m-d H:i:s");
- }
- }
- return $data;
- }
- public function CheckOrder(Request $request){
- $input=$request->all();
- $sku=$input['sku'];
- $user=UserW::find($input['user_id']);
- $store=Store::where('user_id',Auth::user()->id)->first();
- $time=Carbon::now()->addMonths(-2);
- $re=OrderW::where('user_id',$user->id)->where('is_pay',1)->where('apply_cancel',0)->where('store_id',$store->id)->where('created_at','>=',$time)->pluck('id');
- if (count($re)==0){
- return $this->success([]);
- }
- foreach ($sku as $k=>$v){
- $res=OrderDetailW::whereIn('order_id',$re)->where('sku_id',$v[0])->count();
- if ($res>0){
- return $this->error(50001,[],'您在2个月内已经购买过相同款式尺码的商品,确定要再次购买吗?');
- }
- }
- return $this->success([]);
- }
- //代下单或分享提交订单
- public function submitOrderInfo(Request $request)
- {
- $input=$request->all();
- Log::error($input);
- $sku=$input['sku'];
- $user=UserW::find($input['user_id']);
- $agent=User::find(Auth::user()->id);
- $store=Store::where('user_id',Auth::user()->id)->first();
- if(empty($store)){
- return $this->error('450001','店铺不存在或者已被删除');
- }
- if($store->status==1){
- return $this->error('450001','店铺已被禁用');
- }
- //判断用户是否存在介绍人
- if($user){
- if($user->recomer_id && $user->recomer_store_id==$store->id){
- $recomer_id=$user->recomer_id;
- $recomer_status=0;
- }else{
- $recomer_id=null;
- $recomer_status=0;
- }
- }else{
- return $this->error('450001','客户信息有误');
- }
- $store_id=$store->id;
- $remark=$input['remark'];
- $order_no=$this->order_no('dx');
- $account=$vip_account=$cost_account=$num=0;
- $data=$snapshot=[];
- foreach($sku as $key=>$val){
- if($val[1] > 0){
- $num += $val[1];
- }
- }
- $vip=$this->getOrderPrice($user->id,$store_id,$num);
- $arr_test=Store::getTest();
- foreach($sku as $key=>$val){
- $sku_info=[];
- $goodSku=StoreGoodsSku::with(['goods'])->where('id',$val[0])->first();
- if(!array_key_exists($goodSku->goods_id,$snapshot)){
- $snapshot[$goodSku->goods_id]['name']=$goodSku->goods->name;
- $snapshot[$goodSku->goods_id]['main_attr']=$goodSku->goods->main_attr;
- $snapshot[$goodSku->goods_id]['img']=$goodSku->goods->img;
- $snapshot[$goodSku->goods_id]['price']=$goodSku->goods->price;
- $snapshot[$goodSku->goods_id]['sku']=[];
- }
- if(in_array($store_id,$arr_test)){
- $storeInventory=InventoryW::where(['store_id'=>$store_id,'goods_id'=>$goodSku->goods_id,'sku_id'=>$val[0]])->lockForUpdate()->first();
- $storeInve_num=!empty($storeInventory)?$storeInventory->num:0;
- if($val[1] > $storeInve_num){
- return $this->error('450001','【'.$goodSku->goods->main_attr.'-'.$goodSku->type.'-'.$goodSku->size.'】库存不足');
- }
- }
- if(empty($goodSku)){
- return $this->error('450001','商品规格不存在,刷新页面重新下单');
- }
- if($agent->level==1){
- $cost_account += $goodSku->goods->super_price * $val[1];
- $data[$key]['cost_price']=$goodSku->goods->super_price;
- $data[$key]['cost_account']=$goodSku->goods->super_price * $val[1];
- }
- if($agent->level==2){
- $cost_account += $goodSku->goods->top_price * $val[1];
- $data[$key]['cost_price']=$goodSku->goods->top_price;
- $data[$key]['cost_account']=$goodSku->goods->top_price * $val[1];
- }
- if($agent->level==3){
- $cost_account += $goodSku->goods->crown_price * $val[1];
- $data[$key]['cost_price']=$goodSku->goods->crown_price;
- $data[$key]['cost_account']=$goodSku->goods->crown_price * $val[1];
- }
- if($vip=='vip_ed' || $vip=='vip_ing'){
- $data[$key]['price']=$goodSku->goods->vip_price;
- $sku_info['price']=$goodSku->goods->vip_price;
- $data[$key]['account']=$goodSku->goods->vip_price * $val[1];
- $account += $goodSku->goods->vip_price * $val[1];
- }else{
- $data[$key]['price']=$goodSku->goods->price;
- $sku_info['price']=$goodSku->goods->price;
- $data[$key]['account']=$goodSku->goods->price * $val[1];
- $account += $goodSku->goods->price * $val[1];
- }
- $data[$key]['origin_price']=$goodSku->goods->price;
- $data[$key]['order_no']=$order_no;
- $data[$key]['goods_id']=$goodSku->goods_id;
- $data[$key]['store_id']=$store_id;
- $data[$key]['user_id']=$user->id;
- $data[$key]['sku_id']=$goodSku->id;
- $data[$key]['num']=$val[1];
- $data[$key]['size']=$goodSku->size;
- $data[$key]['type']=$goodSku->type;
- $data[$key]['style']=1;
- $data[$key]['created_at']=date("Y-m-d H:i:s");
- $data[$key]['updated_at']=date("Y-m-d H:i:s");
- $sku_info['origin_price']=$goodSku->goods->price;
- $sku_info['sku_id']=$goodSku->id;
- $sku_info['num']=$val[1];
- $sku_info['size']=$goodSku->size;
- $sku_info['type']=$goodSku->type;
- array_push($snapshot[$goodSku->goods_id]['sku'],$sku_info);
- }
- $order_data=[
- 'order_no'=>$order_no,
- 'store_id'=>$store_id,
- 'user_id'=>$user->id,
- 'remark'=>$remark,
- 'is_help'=>1,
- 'op_id'=>Auth::user()->id,
- 'op_name'=>Auth::user()->nickname,
- // 'status'=>0,
- // 'is_pay'=>0,
- // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
- 'status'=>1,
- 'is_pay'=>1,//服务商产品权限冻结后下单即支付
- 'pay_money'=>$account,
- 'pay_type'=>3,//免支付
- 'pay_at'=>date("Y-m-d H:i:s"),
- // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
- 'is_tip_send'=>0,
- 'is_comment'=>0,
- 'total'=>$num,
- 'account'=>$account,
- 'cost_account'=>$cost_account,
- 'snapshot'=>json_encode($snapshot),
- 'recomer_id'=>$recomer_id,
- 'recomer_status'=>$recomer_status,
- 'address_id'=>$request->input('address_id',null),
- ];
- $agent_id=Store::where('id',$store_id)->value('user_id');
- $agent_data=$this->saveAgentNoLog($user->id,$agent_id,$order_no);
- DB::connection('mysql_w')->beginTransaction();
- try{
- $result=OrderW::create($order_data); //生成订单
- // Log::info($result);
- foreach($data as $k=>$v){
- $data[$k]['order_id']=$result->id;
- }
- OrderDetailW::insert($data); //生成订单商品详情
- AgentNo::insert( $agent_data); //账号关系
- DB::connection('mysql_w')->commit();
- // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
- //代下单通知客户
- $order=$result;
- $user=UserW::where('id',$order->user_id)->first();
- $agent_id=Store::where('id',$order->store_id)->value('user_id');
- $agent = User::where('id',$agent_id)->first();
- if($user->openId){
- $data['openid']=$user->openId;
- $data['data']=[
- 'first' =>'商户【'.$agent->nickname .'】已帮您下单成功,请及时查看订单',
- 'keyword1' => $order->order_no,
- // 'keyword2' => number_format($order->account, 2),
- 'keyword2' => '请联系线下收款',
- 'keyword3' => $order->op_name,
- 'keyword4' => $agent->mobile,
- 'remark' => '点击链接进入系统,查看详情',
- ];
- event(new HelpOrderEvent($data));
- }
- //代下单通知
- //新订单通知
- // $store=Store::where('id',$order->store_id)->first();
- // $user=User::where('id',$store->user_id)->first();
- if($agent->openid){
- $data['openid']=$agent->openid;
- $data['data']=[
- 'first' => '您有新的客户订单,请及时处理',
- 'keyword1' => $user->nickname,
- // 'keyword2' => number_format($order->account, 2),
- 'keyword2' => '请联系线下收款',
- 'keyword3' => $order->order_no,
- 'keyword4' => $order->created_at
- ];
- event(new NewOrder($data));
- }
- //用户vip变更
- $vipLog=VipLogW::where('user_id',$order->user_id)
- ->where('store_id',$order->store_id)->first();
- if(empty($vipLog) && $order->total>=2){
- VipLogW::create([
- 'user_id'=>$order->user_id,
- 'store_id'=>$store->id,
- 'order_no'=>$order->order_no,
- 'type'=>2,//购买两套,添加vip
- 'remark'=>'购买自动添加vip'
- ]);
- OrderW::where('order_no',$order->order_no)->update([
- 'vip'=>1
- ]);
- }
- // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
- return $this->success($order_no);
- }catch(\Exception $e){
- DB::connection('mysql_w')->rollback();
- return $this->error('450001','提交失败',$e->getMessage());
- }
- }
- //修改订单备注信息
- public function editOrderRemark(Request $request){
- $order_no=$request->input('order_no');
- $remark=$request->input('remark');
- $res=OrderW::where('order_no',$order_no)->update([
- 'remark'=>$remark
- ]);
- if($res){
- return $this->success([]);
- }else{
- return $this->error();
- }
- }
- //分享订单
- public function shareOrderInfo(Request $request)
- {
- $input=$request->all();
- $store_id=Store::where('user_id',Auth::user()->id)->value('id');
- $sku=$input['sku'];
- // $user=UserW::find($input['user_id']);
- $self_receive=$input['self_receive'];//不自提0 自提1
- if($self_receive==1){
- $address_id=Store::where('id',$store_id)->value('address_id');
- }else{
- $address_id=$input['address_id'];
- }
- $remark=$input['remark'];
- $order_no=$this->order_no('fx');
- $account=$vip_account=$num=0;
- $data=[];
- foreach($sku as $key=>$val){
- $goodSku=StoreGoodsSku::with(['goods'])->where('id',$val[0])->first();
- if(empty($goodSku)){
- return $this->error('450001','商品规格不存在,请重新分享');
- }
- $account += $goodSku->goods->price * $val[1];
- $num += $val[1];
- $data[$key]['order_no']=$order_no;
- $data[$key]['goods_id']=$goodSku->goods_id;
- $data[$key]['sku_id']=$goodSku->id;
- $data[$key]['num']=$val[1];
- $data[$key]['price']=$goodSku->goods->price;
- $data[$key]['account']=$goodSku->goods->price * $val[1];
- $data[$key]['size']=$goodSku->size;
- $data[$key]['type']=$goodSku->type;
- $data[$key]['created_at']=date("Y-m-d H:i:s");
- $data[$key]['updated_at']=date("Y-m-d H:i:s");
- }
- $order_data=[
- 'order_no'=>$order_no,
- 'store_id'=>$store_id,
- 'user_id'=>$input['user_id'],
- 'address_id'=>$address_id,
- 'self_receive'=>$self_receive,
- 'remark'=>$remark,
- 'op_id'=>Auth::user()->id,
- 'op_name'=>Auth::user()->nickname,
- 'total'=>$num,
- 'account'=>$account,
- ];
- DB::connection('mysql_w')->beginTransaction();
- try{
- OrderDetailW::insert($data);
- OrderShareW::create($order_data);
- DB::connection('mysql_w')->commit();
- return $this->success($order_no);
- }catch(\Exception $e){
- DB::connection('mysql_w')->rollback();
- return $this->error('450001','提交失败',$e->getMessage());
- }
- }
- //生成订单号
- public function order_no($type='dx')
- {
- if($type=='fx'){
- $prefix = 'FX';
- }else{
- $prefix = 'DX';
- }
- $timestamp=date('ymdHis') . substr(microtime(), 2, 6);
- $rand=mt_rand(10000, 99999);
- $order_no=$prefix . $timestamp . $rand;
- if(OrderW::where('order_no',$order_no)->first()){
- $this->order_no($type);
- }else{
- return $order_no;
- }
- }
- //审核订单取消
- public function authOrderCancel(Request $request){
- $id=$request->input('id');
- $type=$request->input('type');//2通过//3驳回
- $remark=$request->input('remark');
- DB::connection('mysql')->beginTransaction();
- DB::connection('mysql_w')->beginTransaction();
- try{
- $cancel=OrderCancelW::where('id',$id)->first();
- $cancel->status=$type;
- $cancel->remark=$remark;
- $cancel->save();
- $order=OrderW::where('id',$cancel->order_id)->first();
- $order->apply_cancel= $type;
- $order->cancel_at=date("Y-m-d H:i:s");
- $order->save();
- $first='取消订单被驳回';
- if($type==2){//同意取消
- //退款
- // $refund=new RefundAmount();
- // $res=$refund->refundAmount($cancel->order_id);
- // if($res[0]=='450001'){
- // return $this->error('450001',$res[1]);
- // }
- // if($res[0]=='450000'){
- // return $this->error('450001','取消订单退款失败',$res[1]);
- // }
- // // // // // // // // // // // // // // // // // // // // // //
- if($order->pay_type!=3){
- //退款
- $refund=new RefundAmount();
- $res=$refund->refundAmount($cancel->order_id);
- if($res[0]=='450001'){
- return $this->error('450001',$res[1]);
- }
- if($res[0]=='450000'){
- return $this->error('450001','取消订单退款失败',$res[1]);
- }
- }
- // // // // // // // // // // // // // // // // // // // // // //
- //判断是否剥夺vip
- if($order->vip==1){
- $orders=OrderW::where('user_id',$order->user_id)
- ->where('store_id',$order->store_id)
- ->where('is_pay',1)
- ->whereIn('apply_cancel',[0,1,3])
- ->whereIn('is_refund',[0,1])
- ->where('total','>=',2)
- ->where('created_at','>',$order->created_at)
- ->orderBy('created_at')->get();
- if(count($orders)>=1){
- OrderW::where('id',$orders[0]->id)->update([
- 'vip'=>1
- ]);
- }else{
- VipLogW::where('user_id',$order->user_id)->where('store_id',$order->store_id)->delete();
- }
- }
- //判断恢复库存
- $store=Store::withTrashed()->where('is_failure',0)->where('id',$order->store_id)->first();
- $level=User::where('id',$store->user_id)->value('level');
- if($level==3){
- event(new RestoreOutboundEvent($order->order_no));
- }
- $first='取消订单审核成功';
- }
- //取消订单通知
- $user=UserW::where('id',$order->user_id)->first();
- if($user->openId){
- $data['openid']=$user->openId;
- $data['data']=[
- 'first' => '您的订单:'.$order->order_no.$first,
- 'keyword1' => $user->nickname,
- 'keyword2' => $order->order_no,
- 'keyword3' => '已取消',
- 'keyword4' => $order->cancel_at
- ];
- event(new CancelOrderEvent($data));
- }
- DB::connection('mysql')->commit();
- DB::connection('mysql_w')->commit();
- return $this->success([]);
- }catch(\Exception $e){
- DB::connection('mysql')->rollback();
- DB::connection('mysql_w')->rollback();
- return $this->error('450001','失败',$e->getMessage());
- }
- }
- //商户取消订单
- public function cancelOrder(Request $request){
- $order_id=$request->input('order_id');
- $order=OrderW::where('id',$order_id)->first();
- // if($order->is_help==0){//用户自己下单
- // return $this->error('450001','用户自己下单商户不能取消');
- // }
- if($order->apply_cancel==1){
- return $this->error('450001','该订单正在审核中,不能再次取消');
- }
- if($order->apply_cancel==2){
- return $this->error('450001','该订单已取消,不能再次取消');
- }
- DB::connection('mysql')->beginTransaction();
- DB::connection('mysql_w')->beginTransaction();
- try {
- //退款
- if($order->is_pay==1){
- // $refund=new RefundAmount();
- // $res=$refund->refundAmount($order->id);
- // if($res[0]=='450001'){
- // return $this->error('450001',$res[1]);
- // }
- // if($res[0]=='450000'){
- // return $this->error('450001','退款失败',$res[1]);
- // }
- // // // // // // // // // // // // // // // // // // // // // //
- if($order->pay_type!=3){
- //退款
- $refund=new RefundAmount();
- $res=$refund->refundAmount($order->id);
- if($res[0]=='450001'){
- return $this->error('450001',$res[1]);
- }
- if($res[0]=='450000'){
- return $this->error('450001','退款失败',$res[1]);
- }
- }
- // // // // // // // // // // // // // // // // // // // // // //
- }
- //判断是否剥夺vip
- if($order->vip==1){
- $orders=OrderW::where('user_id',$order->user_id)
- ->where('store_id',$order->store_id)
- ->where('is_pay',1)
- ->whereIn('apply_cancel',[0,1,3])
- ->whereIn('is_refund',[0,1])
- ->where('total','>=',2)
- ->where('created_at','>',$order->created_at)
- ->orderBy('created_at')->get();
- if(count($orders)>=1){
- OrderW::where('id',$orders[0]->id)->update([
- 'vip'=>1
- ]);
- }else{
- VipLogW::where('user_id',$order->user_id)->where('store_id',$order->store_id)->delete();
- }
- }
- //判断恢复库存
- $store=Store::withTrashed()->where('is_failure',0)->where('id',$order->store_id)->first();
- $level=User::where('id',$store->user_id)->value('level');
- if($level==3){
- event(new RestoreOutboundEvent($order->order_no));
- }
- //取消订单
- OrderW::where('id', $order_id)->update([
- 'apply_cancel'=>2,
- 'cancel_at'=>date("Y-m-d H:i:s")
- ]);
- OrderCancelW::where('user_id',$order->user_id)
- ->where('store_id',$order->store_id)
- ->where('order_id',$order->id)->update(['using'=>0]);
- OrderCancelW::create([
- 'user_id' =>$order->user_id,
- 'store_id'=>$order->store_id,
- 'order_id'=>$order->id,
- 'status' =>2,
- 'using' =>1,
- 'type' =>2, //商户取消订单
- 'reason' =>'商户取消订单'
- ]);
- //取消订单通知
- $user=UserW::where('id',$order->user_id)->first();
- if($user->openId){
- $data['openid']=$user->openId;
- $data['data']=[
- 'first' => '您的订单:'.$order->order_no.'已被商户成功取消',
- 'keyword1' => $user->nickname,
- 'keyword2' => $order->order_no,
- 'keyword3' => '已取消',
- 'keyword4' => date("Y-m-d H:i:s")
- ];
- event(new CancelOrderEvent($data));
- }
- DB::connection('mysql')->commit();
- DB::connection('mysql_w')->commit();
- return $this->success([]);
- }catch(\Exception $e){
- DB::connection('mysql')->rollback();
- DB::connection('mysql_w')->rollback();
- return $this->error('450001','失败',$e->getMessage());
- }
- }
- //获取订单状态数量
- public function getOrderStatusNum(Request $request){
- $store=Store::withTrashed()->where('is_failure',0)->where('user_id',Auth::user()->id)->first();
- $user_id=$request->input('user_id');
- if($user_id){
- $where['user_id']=$user_id;
- }
- $where['store_id']=$store->id;
- $data=OrderW::where($where)->whereIn('apply_cancel',[0,1,3])->whereIn('is_refund',[0,1,2]);
- $data1=clone $data;
- $data2=clone $data;
- $data3=clone $data;
- $num['noPay']=$data->where('status',0)->count();
- $num['noSend']=$data1->where('status',1)->count();
- $num['noReceive']=$data2->where('status',2)->count();
- $num['Finish']=$data3->where('status',3)->count();
- //判断扫码发货还是立即发货,功能暂时未用到
- // if(in_array($store->phone,['15138929587','18838980968', '13030314383'])){//, '13030314383',
- // $num['is_code']=1;
- // }else{
- // $num['is_code']=0;
- // }
- return $this->success($num);
- }
- //获取订单列表
- public function getOrderList(Request $request)
- {
- $input=$request->all();
- $status=$input['status'];
- $page_index=$input['page_index'];
- $page_size=$input['page_size'];
- $order_no=$input['order_no'];
- $num=$page_size*($page_index-1);
- $where=$wheres=[];
- if($status!='all'){
- $where['status']=$status;
- }
- if($order_no){
- $wheres=function($query)use($order_no){
- $query->where('order_no','like','%'.$order_no.'%');
- };
- }
- $store=Store::where('user_id',Auth::user()->id)->first();
- $where['store_id']=$store->id;
- $data=OrderW::with(['user:id,nickname,phone','order_cancel'=>function($query){
- $query->where('using',1);}])->where($where)->where($wheres)->whereIn('apply_cancel',[0,1,3])
- ->whereIn('is_refund',[0,1,2])
- ->orderByDesc('updated_at')->orderByDesc('id');
- $count=$data->count();
- $orders=$data->skip($num)->take($page_size)->get();
- foreach($orders as $key=>$val){
- if($val->status==3 && $val->is_refund > 0){
- $order_refund = OrderRefundW::where('order_no',$val->order_no)->get();
- if($order_refund){
- $orders[$key]->refund_goods=$order_refund;
- }
- }
- $goods_ids=OrderDetailW::where('order_no',$val->order_no)->groupBy('goods_id')->pluck('goods_id');
- $goods=[];
- foreach($goods_ids as $k=>$v){
- $goods[$k]=StoreGoods::where('id',$v)->select('id','name','img','main_attr')->first();
- $goods[$k]->imgs=str_replace('http://','https://',$goods[$k]->img);
- $goods[$k]->sku=OrderDetailW::where('order_no',$val->order_no)
- ->where('goods_id',$v)->select('price','num')->get();
- }
- $goods_infos=OrderDetailW::with('goods:id,img,name,main_attr')->where('order_no',$val->order_no)
- ->groupBy('goods_id')->select(DB::raw('price','sum(num) as num'))->first();
- $orders[$key]->goods=$goods;
- }
- return $this->success_list($orders,'成功',$count);
- }
- //获取店铺所有介绍人
- public function getAllRecomer(Request $request){
- $input=$request->all();
- $user_id=Auth::user()->id;
- $store_id=Store::where('user_id',$user_id)->value('id');
- $user_ids=OrderW::where('store_id',$store_id)->groupBy('recomer_id')->pluck('recomer_id');
- $user=UserW::whereIn('id',$user_ids);
- $search_name=$input['search_name'];
- if(!empty($search_name)){
- $user->where(function($query)use($search_name){
- $query->where('nickname','like','%'.$search_name.'%')
- ->orWhere('phone','like','%'.$search_name.'%');
- });
- }
- $list=$user->get();
- foreach($list as $key=>$val){
- $uu=User::where('mobile',$val->phone)->first();
- if($uu){
- unset($list[$key]);
- }
- }
- return $this->success($list);
- }
- //绑定介绍人
- public function bindRecomer(Request $request){
- Log::info('打印接收数据');
- Log::info($request->input());
- $user_id=$request->input('id'); //介绍人id
- $order_id=$request->input('order_id'); //订单id
- $order=OrderW::where('id',$order_id)->first();
- if($user_id==$order->user_id){
- return $this->error('450001','介绍人与客户信息相同,不能绑定');
- }
- if(UserW::where('recomer_id',$order->user_id)->exists()){
- return $this->error('450001','该客户已是介绍人,不能绑定');
- }
- $userW=UserW::where('id',$order->user_id)->first();
- $user=User::where('mobile',$userW->phone)->first();
- if($user){
- return $this->error('450001','该客户已存在系统账号,不能绑定');
- }
- $recomW=UserW::where('id',$user_id)->first();//介绍人信息
- if($recomW->recomer_id){
- return $this->error('450001','该介绍人已被其他客户介绍,不能绑定');
- }
- $recomDWBS=User::where('mobile',$recomW->phone)->first();
- if($recomDWBS){
- return $this->error('450001','该介绍人已存在系统账号,不能绑定');
- }
- $store_id=$order->store_id;
- DB::beginTransaction();
- try{
- OrderW::where('user_id',$order->user_id)
- ->where('store_id',$store_id)
- ->update([
- 'recomer_id'=>$user_id,
- 'recomer_status'=>0
- ]);
- UserW::where('id',$order->user_id)->update([
- 'recomer_store_id'=>$store_id,
- 'recomer_id'=>$user_id,
- ]);
- BindRecomLog::create([
- 'user_id'=>$order->user_id,
- 'store_id'=>$store_id,
- 'recomer_id'=>$user_id,
- 'remark'=>'初次绑定',
- ]);
- DB::commit();
- return $this->success([]);
- }catch(\Exception $e){
- DB::rollBack();
- return $this->error('450001','',$e->getMessage());
- }
- }
- //更换绑定介绍人
- public function editBindRecomer(Request $request){
- $user_id=$request->input('id'); //介绍人id
- $order_id=$request->input('order_id'); //订单id
- $remark=$request->input('remark'); //换绑备注
- $order=OrderW::where('id',$order_id)->first();
- if($user_id==$order->user_id){
- return $this->error('450001','介绍人与客户信息相同,不能换绑');
- }
- if(UserW::where('recomer_id',$order->user_id)->exists()){
- return $this->error('450001','该客户已是介绍人,不能换绑');
- }
- $userW=UserW::where('id',$order->user_id)->first();
- if($userW->recomer_agent_id){
- return $this->error('450001','该客户介绍人已存在系统账号,不能换绑');
- }
- if($user_id==$userW->recomer_id){
- return $this->error('450001','介绍人信息没有变更,不能换绑');
- }
- $user=User::where('mobile',$userW->phone)->first();
- if($user){
- return $this->error('450001','该客户已存在系统账号,不能换绑');
- }
- $recomW=UserW::where('id',$user_id)->first();//介绍人信息
- if($recomW->recomer_id){
- return $this->error('450001','该介绍人已被其他客户介绍,不能换绑');
- }
- $recomDWBS=User::where('mobile',$recomW->phone)->first();
- if($recomDWBS){
- return $this->error('450001','该介绍人已存在系统账号,不能换绑');
- }
- $store_id=$order->store_id;
- DB::beginTransaction();
- try{
- OrderW::where('user_id',$order->user_id)
- ->where('store_id',$store_id)
- ->where(function($query){
- $query->whereIn('recomer_status',[0,1])->orWhereNull('recomer_status');
- })
- ->update([
- 'recomer_id'=>$user_id,
- 'recomer_status'=>0
- ]);
- UserW::where('id',$order->user_id)->update([
- 'recomer_store_id'=>$store_id,
- 'recomer_id'=>$user_id,
- ]);
- BindRecomLog::create([
- 'user_id'=>$order->user_id,
- 'store_id'=>$store_id,
- 'recomer_id'=>$user_id,
- 'remark'=>$remark,
- ]);
- DB::commit();
- return $this->success([]);
- }catch(\Exception $e){
- DB::rollBack();
- return $this->error('450001','',$e->getMessage());
- }
- }
- //获取订单列表
- public function getOrderList1(Request $request)
- {
- $input=$request->all();
- $status=$request->input('status','all');
- $page_index=$input['page_index'];
- $page_size=$input['page_size'];
- $order_no=$input['order_no'];
- $num=$page_size*($page_index-1);
- $where=$wheres=[];
- if($status!='all'){
- $where['status']=$status;
- }
- if($order_no){
- if(strlen($order_no)<=3 && is_numeric($order_no)){
- return $this->error('450001','请最少输入4个字搜索');
- }
- $user_ids=UserW::where(function($query)use($order_no){
- $query->where('phone','like','%'.$order_no.'%')->orwhere('nickname','like','%'.$order_no.'%');
- })->pluck('id');
- $wheres=function($query)use($order_no,$user_ids){
- $query->where('order_no','like','%'.$order_no.'%')->orWhereIn('user_id',$user_ids);
- };
- }
- $store=Store::where('user_id',Auth::user()->id)->first();
- $where['store_id']=$store->id;
- $data=OrderW::with(['user:id,nickname,phone','order_cancel'=>function($query){
- $query->where('using',1);}])->where($where)->where($wheres)->whereIn('apply_cancel',[0,1,3])
- ->whereIn('is_refund',[0,1,2])
- ->select('id','order_no','user_id','store_id','status','apply_cancel','is_refund','is_help','self_receive','total','account','is_pay','updated_at','created_at','snapshot')
- ->orderByDesc('updated_at')->orderByDesc('id');
- $count=$data->count();
- $orders=$data->skip($num)->take($page_size)->get();
- foreach($orders as $key=>$val){
- if($val->status==3 && $val->is_refund > 0){
- $order_refund = OrderRefundW::where('order_no',$val->order_no)->get();
- if($order_refund){
- $orders[$key]->refund_goods=$order_refund;
- }
- }
- $orders[$key]->goods=json_decode($val->snapshot,true);
- }
- return $this->success_list($orders,'成功',$count);
- }
- //获取订单列表
- public function getOrderLists(Request $request)
- {
- $input=$request->all();
- $status=$input['status'];
- $page_index=$input['page_index'];
- $page_size=$input['page_size'];
- $order_no=$input['order_no'];
- $num=$page_size*($page_index-1);
- $where=$wheres=[];
- if($status!='all'){
- $where['status']=$status;
- }
- if($order_no){
- $wheres=function($query)use($order_no){
- $query->where('order_no','like','%'.$order_no.'%');
- };
- }
- $store=Store::where('user_id',Auth::user()->id)->first();
- $where['store_id']=$store->id;
- $data=OrderW::with(['user:id,nickname,phone','order_cancel'=>function($query){
- $query->where('using',1);}])->where($where)->where($wheres)->whereIn('apply_cancel',[0,1,3])
- ->whereIn('is_refund',[0,1,2])
- ->orderByDesc('updated_at')->orderByDesc('id');
- $count=$data->count();
- $orders=$data->skip($num)->take($page_size)->get();
- foreach($orders as $key=>$val){
- if($val->status==3 && $val->is_refund > 0){
- $order_refund = OrderRefundW::where('order_no',$val->order_no)->get();
- if($order_refund){
- $orders[$key]->refund_goods=$order_refund;
- }
- }
- $goods=OrderDetailW::with('goods:id,img,name,main_attr')->where('order_id',$val->id)
- ->groupBy('goods_id')->select('goods_id','price',DB::raw('sum(num) as num'))->get();
- foreach($goods as $k=>$v){
- $goods[$k]->goods->imgs=str_replace('http://','https://',$v->goods->img);
- }
- $orders[$key]->goods=$goods;
- }
- return $this->success_list($orders,'成功',$count);
- }
- //获取退货订单详情
- public function getRefundOrderDetail(Request $request){
- $order_no=$request->input('order_no');
- $order_refund=OrderRefundW::where('order_no',$order_no)->get();
- foreach($order_refund as $key => $val){
- $goods_ids = OrderDetailW::where('order_no', $val->refund_no)->groupBy('goods_id')->pluck('goods_id');
- $goods = [];
- foreach ($goods_ids as $k => $v) {
- $goods[$k] = StoreGoods::where('id', $v)->first();
- $goods[$k]->sku = OrderDetailW::where('order_no', $val->refund_no)->where('goods_id', $v)->get();
- }
- $order_refund[$key]->goods=$goods;
- }
- return $this->success($order_refund);
- }
- //获取id订单信息
- public function getOrderInfo(Request $request)
- {
- $input=$request->all();
- $id=$input['id'];
- $order=OrderW::withTrashed()->with(['user:id,nickname,phone','address'])->where('id',$id)->first();
- $goods_ids=OrderDetailW::where('order_no',$order->order_no)->groupBy('goods_id')->pluck('goods_id');
- $goods=[];
- foreach($goods_ids as $key=>$val){
- $goods[$key]=StoreGoods::where('id',$val)->first();
- $goods[$key]->sku=OrderDetailW::where('order_no',$order->order_no)->where('goods_id',$val)->get();
- }
- $order->goods=$goods;
- return $this->success($order);
- }
- //根据订单号查询订单
- public function getOrderNoInfo(Request $request)
- {
- $input=$request->all();
- $order_no=$input['order_no'];
- $order=OrderW::withTrashed()->with(['order_cancel','user:id,nickname,phone,avatar','address','recomer:id,nickname,phone,avatar','store:id,name'])->where('order_no',$order_no)->first();
- $agent_id=Auth::user()->id;
- $store_id=Store::where('user_id',$agent_id)->value('id');
- if($store_id!=$order->store_id){
- return $this->error('450401','没有权限查看该订单');
- }
- if(empty($order)){
- return $this->error('450001','订单号有误');
- }
- $goods_ids=OrderDetailW::where('order_no',$order->order_no)->groupBy('goods_id')->pluck('goods_id');
- $goods=[];
- foreach($goods_ids as $key=>$val){
- $goods[$key]=StoreGoods::where('id',$val)->first();
- $goods[$key]->imgs=str_replace('http://','https://',$goods[$key]->img);
- $goods[$key]->sku=OrderDetailW::where('order_no',$order->order_no)->where('goods_id',$val)->get();
- }
- $order->goods=$goods;
- $order->code=OrderCodeW::where('order_id',$order->id)->get();
- //测试跳转详情显示元宝页面
- if(in_array($order->store_id,[ 99, 102, 105])){//,101,102,105
- $order->is_code=1;
- }else{
- $order->is_code=0;
- }
- return $this->success($order);
- }
- //回复评价
- public function addComment(Request $request){
- $input=$request->all();
- $rules=[
- 'content'=>'required|max:255',
- ];
- $message=[
- 'content.required'=>'评价内容不能为空.',
- 'content.max'=>'评价内容不能大于255个字符.'
- ];
- $validator = Validator::make($input,$rules,$message);
- if($validator->fails()){
- return $this->error('400013',$validator->errors()->first());
- }
- $store_id=Store::where('user_id',Auth::user()->id)->value('id');
- $res=Comment::create([
- 'content'=>$input['content'],
- 'comment_id'=>$input['comment_id'],
- 'store_id'=>$store_id,
- 'is_reply'=>2,
- 'is_see'=>0
- ]);
- if($res){
- return $this->success([]);
- }else{
- return $this->error();
- }
- }
- //查看所有评价
- public function getComment(Request $request){
- $input=$request->all();
- $page_index=$input['page_index'];
- $page_size=$input['page_size'];
- $num=$page_size*($page_index-1);
- $store_id=Store::where('user_id',Auth::user()->id)->value('id');
- $count= Comment::where('store_id',$store_id)->where('comment_id',0)->count();
- $list= Comment::with(['comment','store:id,name,img','user:id,avatar,nickname,phone'])
- ->where('store_id',$store_id)->where('comment_id',0)
- ->orderByDesc('id')
- ->skip($num)->take($page_size)->get();
- return $this->success_list($list,'',$count);
- }
- //用户自提
- public function oneSelfTake(Request $request){
- $order_no=$request->input('order_no');
- $order=OrderW::with('address')->where('order_no',$order_no)->first();
- $order->status=2; //已备货,可自提
- $order->express_time = date("Y-m-d H:i:s"); //备货完成时间
- $res=$order->save();
- if($res){
- /* 已备货通知 */
- $user=UserW::where('id',$order->user_id)->first();
- if($user->openId){
- $address=null;
- if($order->address){
- $address=$order->address->province.$order->address->city.$order->address->area.$order->address->address;
- }
- $mes['openid']=$user->openId;
- $mes['data']=[
- 'first' => '您的订单已完成备货,请前往提货',
- 'keyword1' => $order_no,
- 'keyword2' => $order->created_at,
- 'keyword3' => '已备货,可自提',
- 'keyword4' => $address,
- 'remark' => '点击链接进入系统,查看详情',
- ];
- event(new TipPickUpEvent($mes));
- }
- return $this->success([]);
- }else{
- return $this->error();
- }
- }
- //获取所有快递公司信息
- public function getExpressCode(){
- return $this->success(ExpressHandler::getExpressCode());
- }
- //识别扫码信息
- public function scanCodeInfo(Request $request)
- {
- $code=$request->input('code');
- if(!strpos($code,'://')){
- $info=Select::with('select_good')->select('id','good_select_id','security_code','code','is_lowest')->where('code',$code)->first();
- if(empty($info)){
- return $this->error('450001','未识别到二维码信息');
- }
- if($info->is_lowest==0){
- return $this->error('450001','请扫描单个包装盒二维码');
- }
- if(empty($info->good_select_id)){
- return $this->error('450001','该二维码没有绑定商品信息');
- }
- }else{
- $file=file_get_contents($code);
- Log::info('0000------------------0000--'.$code);
- preg_match('/<span>产品名称:<\/span> 大卫博士健康内裤((.*?))/',$file,$result);
- if(!in_array($result[1],['精装版','简约版','老人版','纯棉老人版','高腰版','青春版'])){
- return $this->error('450001','该二维码没有绑定商品信息');
- }
- switch($result[1]){
- case "精装版":
- $goods_id=1;
- break;
- case "简约版":
- $goods_id=2;
- break;
- case "老人版":
- case "高腰版":
- $goods_id=3;
- break;
- case "纯棉老人版":
- $goods_id=4;
- break;
- case "青春版":
- $goods_id=25;
- break;
- default:
- $goods_id=null;
- }
- $info['good_select_id']=$goods_id;
- $info['security_code']=substr($code,-12);;
- $info['code']=$code;
- }
- $code=substr($code,strrpos($code,'?bid='));
- $order_code = OrderCodeW::where('code',$code)->first();
- if($order_code){
- return $this->error('450001','该二维码已发货');
- }
- return $this->success($info);
- }
- //提交发货扫码信息
- public function submitScanCodeInfo(Request $request)
- {
- $order_no=$request->input('order_no');
- $code=$request->input('code');
- $order=OrderW::where('order_no',$order_no)->first();
- Log::info($code);
- Log::info($order_no);
- DB::beginTransaction();
- try{
- foreach($code as $val){
- if(strpos($val,'://')){
- $order_code = OrderCodeW::where('code',substr($val,strrpos($val,'?bid=')))->first();
- }else{
- $order_code = OrderCodeW::where('code',$val)->first();
- }
- if($order_code){
- if($order_code->order_id != $order->id){
- throw new Exception("二维码:".$order_code->security_code." 已发货");
- }
- }else{
- if(!strpos($val,'://')){
- $info=Select::with('select_good')->select('id','good_select_id','security_code','code','is_lowest')->where('code',$val)->first();
- OrderCodeW::create([
- 'store_id' => $order->store_id,
- 'user_id' => $order->user_id,
- 'order_id' => $order->id,
- 'code' => $val,
- 'security_code' => $info->security_code,
- 'good_select_id' => $info->good_select_id,
- 'good_name' => $info->select_good->good_name,
- ]);
- }else{
- $file=file_get_contents($val);
- preg_match('/<span>产品名称:<\/span> 大卫博士健康内裤((.*?))/',$file,$result);
- if(!in_array($result[1],['精装版','简约版','老人版','纯棉老人版','高腰版','青春版'])){
- throw new Exception("二维码没有绑定商品信息");
- }
- $security_code=substr($val,-12);
- switch($result[1]){
- case "精装版":
- $goods_id=1;
- break;
- case "简约版":
- $goods_id=2;
- break;
- case "老人版":
- case "高腰版":
- $goods_id=3;
- break;
- case "纯棉老人版":
- $goods_id=4;
- break;
- case "青春版":
- $goods_id=25;
- break;
- default:
- $goods_id=null;
- }
- OrderCodeW::create([
- 'store_id' => $order->store_id,
- 'user_id' => $order->user_id,
- 'order_id' => $order->id,
- 'code' => substr($val,strrpos($val,'?bid=')),
- 'security_code' => $security_code,
- 'good_select_id' => $goods_id,
- 'good_name' => '大卫博士'.$result[1],
- ]);
- }
- }
- }
- DB::commit();
- return $this->success([]);
- }catch(\Exception $e){
- DB::rollBack();
- Log::info($e->getMessage());
- return $this->error($e->getMessage());
- }
- }
- // 删除发货码
- public function deleteScanCode(Request $request)
- {
- $ids=$request->input('ids');
- $res=OrderCodeW::whereIn('id',$ids)->delete();
- if($res){
- return $this->success([]);
- }else{
- return $this->error();
- }
- }
- //获取客户所有订单
- public function getNoSendOrder(Request $request){
- $order_no=$request->input('order_no');
- $order=OrderW::where('order_no',$order_no)->first();
- $no_send_orders=OrderW::with('user:id,nickname,phone,avatar')
- ->where('store_id',$order->store_id)->where('user_id',$order->user_id)
- ->where('status',1)->whereIn('apply_cancel',[0,3])->get();
- foreach($no_send_orders as $key=>$val){
- $goods_ids=OrderDetailW::where('order_no',$val->order_no)->groupBy('goods_id')->pluck('goods_id');
- $goods=[];
- foreach($goods_ids as $k=>$v){
- $goods[$k]=StoreGoods::where('id',$v)->first();
- $goods[$k]->sku=OrderDetailW::where('order_no',$val->order_no)->where('goods_id',$v)->get();
- }
- $no_send_orders[$key]->goods=$goods;
- }
- return $this->success($no_send_orders);
- }
- //上传订单快递号
- public function addOrderExpressNo(Request $request){
- $input=$request->all();
- $rules=[
- 'express_no' =>'required',
- 'express_company'=>'required',
- 'express_time' =>'required'
- // 'address_id' =>'required'
- ];
- $message=[
- 'express_no.required' =>'发货单号不能为空.',
- 'express_company.required'=>'物流公司不能为空.',
- 'express_time.required' =>'发货时间不能为空.',
- // 'address_id.required' =>'收货地址不能为空.',
- ];
- $validator = Validator::make($input,$rules,$message);
- if($validator->fails()){
- return $this->error('400013',$validator->errors()->first());
- }
- $status=OrderW::where('order_no',$input['order_no'])->value('status');
- if($status > 1){
- return $this->error('450001','该订单已发货');
- }
- $prefix=mb_substr($input['express_no'],0,2);
- if(strtoupper($prefix)=='DD' || strtoupper($prefix)=='DX'){
- return $this->error('450001','物流单号不正确,你填的是订单号,请重新填写');
- }
- $order_nos=explode(',',$input['order_no']);
- // $address_id=$input['address_id'];
- $express_company=$input['express_company'];
- $express_code=$input['express_code'];
- $express_phone=$input['express_phone'];
- $express_time=$input['express_time'];
- $express_no=str_replace(' ','', $input['express_no']);
- $data=[
- // 'address_id'=>$address_id,
- 'self_receive'=>0,
- 'express_no'=>$express_no,
- 'express_company'=>$express_company,
- 'express_code'=>$express_code,
- 'express_state'=>0,
- 'express_phone'=>$express_phone,
- 'express_time'=>$express_time,
- 'status'=>2
- ];
- try{
- DB::connection('mysql_w')->transaction(function()use($order_nos,$data){
- OrderW::whereIn('order_no',$order_nos)->update($data);
- },5);
- $order=OrderW::with('address')->where('order_no',$order_nos[0])->first();
- $user=UserW::where('id',$order->user_id)->first();
- //已发货短信通知
- $phone=$user->phone;
- $config=config('easysms');
- $easySms = new EasySms($config);
- $express=$express_company.$express_no;
- $content="【大卫博士】您购买的大卫博士健康内裤已发货,快递单号是{$express},请注意查收。";
- try{
- $easySms->send($phone, ['content' =>$content ]);
- Log::info('物流发货短信正常:'.$phone);
- } catch (\Overtrue\EasySms\Exceptions\NoGatewayAvailableException $exception) {
- $message = $exception->getException('qcloud')->getMessage();
- Log::info('物流发货短信异常:'.json_encode($message));
- }
- //判断是否需要通知满5套
- // event(new EnoughFive($order->id));
- //已发货公众号通知
- if($user->openId){
- Log::info($user->openId);
- if($order->address){
- $address=$order->address->name.' '.$order->address->phone.' '.$order->address->province.$order->address->city.$order->address->area.$order->address->address;
- }else{
- $address='无收件信息';
- }
- $mes['openid']=$user->openId;
- $mes['data']=[
- 'first' => '您的订单已发货,请注意查收',
- 'keyword1' => $input['order_no'],
- 'keyword2' => $express_time,
- 'keyword3' => $express_company,
- 'keyword4' => $express_no,
- 'keyword5' => $address,
- ];
- Log::info(json_encode($mes));
- event(new TipSendingEvent($mes));
- }
- return $this->success([]);
- }catch(\Exception $e){
- return $this->error('450001',$e->getMessage());
- }
- // OrderExpressW::create([
- // 'order_no'=>$input['order_no'],
- // 'express_no'=>str_replace(' ','', $input['express_no']),
- // 'express_company'=>$input['express_company'],
- // 'express_code'=>$input['express_code'],
- // 'express_state'=>0,
- // 'express_phone'=>$input['express_phone'],
- // 'express_receive_time'=>null,
- // ]);
- }
- //查询订单物流信息
- public function getOrderExpress(Request $request){
- $order_no=$request->input('order_no');
- $order=OrderW::with('address')->where('order_no',$order_no)->first();
- if(empty($order)){
- return $this->error('450001','订单信息有误');
- }
- if($order->express_state==3){ //已签收
- $express=json_decode($order->express_info,true);
- }else{ //未签收
- $CustomerName = null;
- if($order->express_code =='SF'){
- $CustomerName = substr($order->express_phone,-4);
- }
- $express=new ExpressHandler();
- $express=$express->search($order->express_no, $order->express_code, $order->order_no, $CustomerName);
- $express=json_decode(json_encode($express),'true');
- if(isset($express['Traces']) && !empty($express['Traces'])){
- foreach ($express['Traces'] as $key=>$val){
- $express['Traces'][$key]['AcceptTime']=date("Y-m-d H:i:s",substr($val['AcceptTime'],0,strlen($val['AcceptTime'])-3));
- }
- OrderW::where('order_no',$order_no)->update([
- 'express_info'=>json_encode($express),
- 'express_receive_time'=>array_pop($express['Traces'])['AcceptTime'],
- 'express_state'=>$express['State']
- ]);
- }
- }
- $data['express']=$express;
- $data['express_state']=$order->express_state;
- $data['express_code']=$order->express_code;
- $data['express_company']=$order->express_company;
- $data['express_no']=$order->express_no;
- $data['express_time']=$order->express_time;
- $data['express_phone']=$order->express_phone;
- return $this->success($data);
- }
- //修改店铺地址
- public function editStoreAddress(Request $request){
- $user_id=Auth::user()->id;
- // $user=User::where('id',$user_id)->first();
- // $store_id=Store::where('user_id',$user_id)->value('id');
- $res=Store::where('user_id',$user_id)
- ->update([
- 'province'=>$request->input('province'),
- 'city'=>$request->input('city'),
- 'area'=>$request->input('area'),
- 'address'=>$request->input('address'),
- ]);
- // $address=AddressW::where('store_id',$store_id)->first();
- // if($address){
- // $address->province=$request->input('province');
- // $address->city=$request->input('city');
- // $address->area=$request->input('area');
- // $address->address=$request->input('address');
- // $res=$address->save();
- // }else{
- // $res=AddressW::create([
- // 'store_id'=>$store_id,
- // 'name'=>$user->nickname,
- // 'phone'=>$user->mobile,
- // 'province'=>$request->input('province'),
- // 'city'=>$request->input('city'),
- // 'area'=>$request->input('area'),
- // 'address'=>$request->input('address'),
- // 'is_default'=>0
- // ]);
- // }
- if($res){
- return $this->success([]);
- }else{
- return $this->error();
- }
- }
- //获取微信位置授权
- public function getSignPackage(){
- $app=app('wechat.official_account');
- $url='http://api.app.cliu.cc/api/gzh';
- $app->jssdk->setUrl($url);
- $data=$app->jssdk->buildConfig(
- array('onMenuShareAppMessage','onMenuShareTimeline',
- 'openLocation','getLocation','chooseImage',
- 'uploadImage', 'downloadImage','scanQRCode',
- 'updateAppMessageShareData', 'updateTimelineShareData','hideMenuItems'),
- $debug = false, $beta = false, $json = true,
- $openTagList = ['wx-open-launch-app']);
- return $this->success($data);
- }
- //根据经纬度获取地理位置信息
- public function getAddressInfo(Request $request){
- $location=$request->input('location');
- $key='b019688375d389c1e55150985e90f816';
- $client=new Client();
- $url='https://restapi.amap.com/v3/geocode/regeo?key='.$key.'&location='.$location;
- $result=$client->request('GET',$url);
- $res = json_decode($result->getBody()->getContents());
- return $this->success($res);
- }
- //提交退货订单
- public function submitRefundOrder(Request $request)
- {
- $sku = $request->input('sku');
- $reason = $request->input('reason');
- $reason_all = $request->input('reason_all');
- $img = $request->input('img');
- $origin_order_no=$request->input('origin_order_no');
- $origin_order=OrderW::where('order_no',$origin_order_no)->first();
- if($origin_order->is_refund==1){
- return $this->error('450001','该订单存在正在审核中的退货订单');
- }
- if($origin_order->is_refund==3){
- return $this->error('450001','该订单已全部退货');
- }
- $refund_no=OrderW::order_no('th');
- $account = $total = 0;
- $list = $sku_ids = [];
- foreach($sku as $key=>$val){
- if($val[1] > 0){
- $order_detail=OrderDetailW::with(['goods'])->where('id',$val[0])->first();
- if($order_detail->num < $val[1]){
- $num = $order_detail->num;
- }else{
- $num = $val[1];
- }
- $list[$key]['num']=$num;
- $list[$key]['price']=$order_detail->price;
- $list[$key]['account']=$order_detail->price * $num;
- $list[$key]['order_no']=$refund_no;
- $list[$key]['goods_id']=$order_detail->goods_id;
- $list[$key]['sku_id']=$order_detail->sku_id;
- $list[$key]['size']=$order_detail->size;
- $list[$key]['type']=$order_detail->type;
- $list[$key]['style']=2;
- $list[$key]['created_at']=date("Y-m-d H:i:s");
- $list[$key]['updated_at']=date("Y-m-d H:i:s");
- $total += $num;
- $account += $order_detail->price * $num;
- }
- }
- $data=[
- 'refund_no'=>$refund_no,
- 'order_no'=>$origin_order_no,
- 'store_id'=>$origin_order->store_id,
- 'user_id'=>$origin_order->user_id,
- 'reason'=>$reason,
- 'reason_all'=>$reason_all,
- 'total'=>$total,
- 'account'=>$account,
- 'img'=>json_encode($img),
- 'status'=>0,
- 'op_name'=> Auth::user()->nickname,
- 'op_type'=>2,
- 'remark'=>null,
- ];
- try{
- DB::connection('mysql_w')->transaction(function ()use($list,$data,$origin_order_no,$account){
- OrderDetailW::insert($list);
- OrderRefundW::create($data);
- OrderW::where('order_no',$origin_order_no)->update(['is_refund'=>1]);
- },5);
- //申请退货提醒
- $user=UserW::where('id',$origin_order->user_id)->first();
- if($user->openId){
- $data['openid']=$user->openId;
- $data['data']=[
- 'first' => '商户提交了新的退单信息',
- 'keyword1' => $origin_order->order_no,
- 'keyword2' => '商户退货,退款金额:'.number_format($account,2)
- ];
- event(new AuthRefundTip($data));
- }
- return $this->success($refund_no);
- }catch(\Exception $e){
- return $this->error('450001',$e->getMessage());
- }
- }
- //获取退款订单原始信息
- public function getOriginOrderInfo(Request $request)
- {
- $order_no=$request->input('order_no');
- $data=OrderW::with(['address','order_cancel'=>function($query){$query->where('using',1);},'store:id,name,img,phone']);
- $order=$data->where('order_no',$order_no)->first()->toArray();
- if(empty($order)){
- return $this->error('450001','订单不存在');
- }
- $goods_ids=OrderDetailW::where('order_no',$order['order_no'])->groupBy('goods_id')->pluck('goods_id');
- $goods=[];
- foreach($goods_ids as $key=>$val){
- $goods[$val]=StoreGoods::select('id','name','img','main_attr')->where('id',$val)->first()->toArray();
- $order_details=OrderDetailW::where('order_no',$order['order_no'])->where('goods_id',$val)->get()->toArray();
- if(count($order_details)>0){
- $sku=[];
- foreach($order_details as $k=>$v){
- $sku[$v['sku_id']]=$v;
- }
- $goods[$val]['sku']=$sku;
- $goods[$val]['price']=$order_details[0]['price'];
- }
- }
- $order['goods']=$goods;
- $refund_nos=OrderRefundW::where('order_no',$order_no)->whereIn('status',[0,1,3])->pluck('refund_no');
- $refund_goods_ids=OrderDetailW::whereIn('order_no',$refund_nos)->groupBy('goods_id')->pluck('goods_id');
- $refunds=[];
- foreach($refund_goods_ids as $key=>$val){
- $refunds[$val]=StoreGoods::select('id','name','img','main_attr')->where('id',$val)->first()->toArray();
- $refunds_details=OrderDetailW::select('goods_id','sku_id','type','size', DB::raw('sum(num) as num'))
- ->whereIn('order_no',$refund_nos)->where('goods_id',$val)->groupBy('sku_id')->get()->toArray();
- if(count($refunds_details)>0){
- $sku=[];
- foreach($refunds_details as $k=>$v){
- $sku[$v['sku_id']]=$v;
- }
- $refunds[$val]['sku']=$sku;
- }
- }
- $order['refunds']=$refunds;
- $products=[];
- foreach($goods as $key=>$val){
- $products[$key]= $goods[$key];
- $sku=[];
- foreach($val['sku'] as $k=>$v){
- if(empty($refunds[$key]['sku'][$k])){
- unset($products[$key]['sku']);
- $sku[$k]= $goods[$key]['sku'][$k];
- }else{
- if($goods[$key]['sku'][$k]['num'] > $refunds[$key]['sku'][$k]['num']){
- unset($products[$key]['sku']);
- $sku[$k] = $goods[$key]['sku'][$k];
- $sku[$k]['num']=$goods[$key]['sku'][$k]['num'] - $refunds[$key]['sku'][$k]['num'];
- }else{
- unset($products[$key]['sku']);
- }
- }
- }
- $products[$key]['sku']= $sku;
- if(empty($products[$key]['sku'])){
- unset($products[$key]);
- }
- }
- $order['products']=$products;
- return $this->success($order);
- }
- //上传退货图片
- public function uploadRefundOrderImg(Request $request){
- $path_url = 'public/refund';
- $path = $request->file('img')->store($path_url);
- if($path){
- $url = env('APP_URL'). Storage::url($path);
- return $this->success($url);
- }
- return $this->error();
- }
- //取消退货审核
- public function cancelRefundOrder(Request $request){
- $refund_id=$request->input('refund_id');
- $refund=OrderRefundW::where('id',$refund_id)->first();
- if(empty($refund)){
- return $this->error('450001','退货单不存在');
- }
- try{
- DB::connection('mysql_w')->transaction(function()use($refund){
- OrderRefundW::where('id',$refund->id)->delete();
- $auth_count=OrderRefundW::where('order_no',$refund->order_no)->where('status',0)->count();
- if($auth_count>=1){
- OrderW::where('order_no',$refund->order_no)->update([
- 'is_refund'=>1
- ]);
- }else{
- $count=OrderRefundW::where('order_no',$refund->order_no)->where('status',1)->count();
- if($count>=1){
- OrderW::where('order_no',$refund->order_no)->update([
- 'is_refund'=>2
- ]);
- }else{
- OrderW::where('order_no',$refund->order_no)->update([
- 'is_refund'=>0
- ]);
- }
- }
- },5);
- return $this->success([]);
- }catch(\Exception $e){
- return $this->error('450001',$e->getMessage());
- }
- }
- //上传签名图片
- public function uploadQianMingImg(Request $request){
- $base64_img=$request->input('img');
- Log::error('签名');
- // preg_match('/^(data:\s*image\/(\w+);base64,)/',$base64_img,$res);
- // $base64_img=base64_decode(str_replace($res[1],'', $base64_img));
- // 获取七牛云配置信息
- $config = [
- 'driver' => 'qiniu',
- 'domain' => 'http://image.chuliu.cc', //七牛域名
- 'access_key' => 'cIbo9JAqHBgO6uw97gT5fJOlEHiTiGrpB84unVEn', //AccessKey
- 'secret_key' => '4f0nTNNrvzOsFc6Rz0GC5DntiJRnk2GcfkyJFNQp', //SecretKey
- 'bucket' => 'daweiboshi-app', //Bucket名字
- 'dirname'=> 'daweiboshi-weidian'
- ];
- $auth = new Auths($config['access_key'], $config['secret_key']);
- // 生成上传 Token
- $token = $auth->uploadToken($config['bucket']);
- $filename=$this->randomKeys(18).'.jpg';
- $dirname=$config['dirname'];
- // 初始化 UploadManager 对象并进行文件的上传。
- $uploadMgr = new UploadManager();
- // 调用 UploadManager 的 putFile 方法进行文件的上传。
- $pathname= $dirname.'/qianming/'.date('Ymd').'/'.$filename;
- try{
- $uploadMgr->putFile($token, $pathname, $base64_img);
- }catch(\Exception $e){
- return $this->error('450001',$e->getMessage(),$e->getMessage());
- }
- // 获取文件完整路径
- $url = $config['domain'].'/'.$pathname;
- if ($url){
- return $this->success($url);
- }
- return $this->error();
- }
- function randomKeys($length){
- $pattern = '1234567890abcdefghijklmnopqrstuvwxyz';
- $key='';
- for($i=0;$i<$length;$i++)
- {
- $key .= $pattern{mt_rand(0,strlen($pattern)-1)};//生成php随机数
- }
- return $key;
- }
- //商户确认收货
- public function agentSureReceiveOrder(Request $request){
- $order_no=$request->input('order_no');
- $order=OrderW::where('order_no',$order_no)->first();
- if($order->status==3){
- return $this->error('450001','订单已完成');
- }
- try{
- DB::connection('mysql_w')->transaction(function()use($order_no,$order,$request){
- $order->status=3;
- $order->order_status=2;
- $order->self_receive=0;//收货
- $order->express_receive_time=date("Y-m-d H:i:s");//订单签收时间
- $order->save();
- },5);
- // event(new FinishAccount($order_no));
- // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
- if($order->pay_type != 3){
- event(new FinishAccount($order_no));
- }else{
- OrderW::where('order_no',$order->order_no)->update(['is_finish'=>1,'finish_no'=>$order->order_no]);
- }
- // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
- $user=UserW::where('id',$order->user_id)->first();
- //已签收短信通知
- $phone=$user->phone;
- $config=config('easysms');
- $easySms = new EasySms($config);
- $content="【大卫博士】您购买的大卫博士健康内裤被商户标记为确认签收。若已收到货物,请忽略此短信;若没有收到,请及时联系商户查询。 ";
- // $content="【大卫博士】您购买的大卫博士健康内裤被代理标记为确认签收。若已收到货物,请忽略此短信;若没有收到,请及时联系代理商查询。 ";
- try{
- $easySms->send($phone, ['content' =>$content ]);
- } catch (\Overtrue\EasySms\Exceptions\NoGatewayAvailableException $exception) {
- $message = $exception->getException('qcloud')->getMessage();
- Log::info('确认收货短信异常:'.json_encode($message));
- }
- return $this->success([]);
- }catch(\Exception $e){
- Log::info('签收失败2---'.json_encode($e->getMessage()));
- return $this->error('450001',$e->getMessage());
- }
- }
- //商户端确认收货,客户当面签收
- public function sureReceiveOrder(Request $request){
- $signature=$request->input('signature');
- $order_nos=explode(',',$request->input('order_no'));
- $ors=OrderW::whereIn('order_no',$order_nos)->where('status',3)->get();
- Log::info(';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;');
- Log::info($ors);
- if(count($ors)>0){
- return $this->error('450001','存在已完成订单');
- }
- Log::info(json_encode($request->input()));
- try{
- $order=OrderW::where('order_no',$order_nos[0])->first();
- $user=UserW::where('id',$order->user_id)->first();
- DB::connection('mysql_w')
- ->transaction(function()use($order_nos,$order,$user,$signature,$request){
- $info['status']=3;
- $info['order_status']=0;
- $info['self_receive']=1;//送货上门
- $info['express_receive_time']=date("Y-m-d H:i:s");//订单签收时间
- $info['signature']=$signature;
- //以下单所填地址为准
- // if(empty($order->address_id)){
- // $province=$request->input('province');
- // if(is_array($province) && !empty($province)){
- // $province=implode('',$province);
- // }
- // if(is_array($province) && empty($province)){
- // $province='';
- // }
- // $city=$request->input('city');
- // if(is_array($city) && !empty($city)){
- // $city=implode('',$city);
- // }
- // if(is_array($city) && empty($city)){
- // $city='';
- // }
- // $area=$request->input('area');
- // if(is_array($area) && !empty($area)){
- // $area=implode('',$area);
- // }
- // if(is_array($area) && empty($area)){
- // $area='';
- // }
- // Log::info('dddd-------dddd'.$province.'---'.$city.'---'.$area);
- //
- // $address=AddressW::where('user_id',$order->user_id)
- // ->where('province',$province)->where('city',$city)
- // ->where('area',$area)->first();
- // if($address){
- // $info['address_id']=$address->id;
- // }else{
- // $res=AddressW::create([
- // 'name'=>$user->nickname,
- // 'phone'=>$user->phone,
- // 'user_id'=>$order->user_id,
- // 'store_id'=>$order->store_id,
- // 'province'=>$province,
- // 'city'=>$city,
- // 'area'=>$area,
- // 'type'=>3,
- // 'is_default'=>0,
- // 'remark'=>'自动定位',
- // ]);
- // $info['address_id']=$res->id;
- // }
- // }
- OrderW::whereIn('order_no',$order_nos)->update($info);
- },5);
- foreach($order_nos as $val){
- // event(new FinishAccount($val));
- // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
- $oro=OrderW::where('order_no',$val)->first();
- if($oro->pay_type != 3){
- event(new FinishAccount($val));
- }else{
- OrderW::where('order_no',$val)->update(['is_finish'=>1,'finish_no'=>$val]);
- }
- // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
- }
- //已签收短信通知
- $phone=$user->phone;
- $config=config('easysms');
- $easySms = new EasySms($config);
- $content="【大卫博士】您购买的大卫博士健康内裤已由你本人确认签收,谢谢。";
- try{
- $easySms->send($phone, ['content' =>$content ]);
- Log::info('签收短信正常:'.$phone);
- } catch (\Overtrue\EasySms\Exceptions\NoGatewayAvailableException $exception) {
- $message = $exception->getException('qcloud')->getMessage();
- Log::info('签收短信异常:'.json_encode($message));
- }
- //判断是否需要通知满5套
- // event(new EnoughFive($order->id));
- //签收公众号提醒
- if($user->openId){
- $data['openid']=$user->openId;
- $data['data']=[
- 'first' => '您的订单已被当面签收,如果没有请联系商户',
- 'keyword1' => $request->input('order_no'),
- 'keyword2' => date('Y-m-d H:i:s')
- ];
- event(new ReceivingEvent($data));
- }
- return $this->success([]);
- }catch(\Exception $e){
- Log::info('签收失败1---'.$e->getMessage());
- return $this->error('450001',$e->getMessage());
- }
- }
- //获取客户信息
- public function getUser(Request $request){
- $user_id=$request->input('user_id');
- $user=UserW::where('id',$user_id)->first();
- $store_id=Store::where('user_id',Auth::user()->id)->value('id');
- $vip_log=VipLogW::where('user_id',$user->id)->where('store_id',$store_id)->first();
- if($vip_log){
- $user->is_vip=1;
- }else{
- $user->is_vip=0;
- }
- $orders=OrderW::where('store_id',$store_id)->where('user_id',$user_id)->get();
- if(count($orders)==0){//判断客户在店铺有没有单子
- $user->has_order=0;
- }else{
- $user->has_order=1;
- }
- if($user){
- return $this->success($user);
- }else{
- return $this->error();
- }
- }
- //修改客户信息
- public function editUser(Request $request){
- $rules=[
- 'name'=>'required|max:32',
- 'nickname'=>'required|max:32',
- 'remark'=>'max:255',
- 'phone'=>'required|regex:/^1[3456789][0-9]{9}$/'
- ];
- $message=[
- 'phone.required'=>'手机号不能为空.',
- 'phone.regex'=>'手机号格式有误.',
- 'name.required'=>'客户姓名不能为空.',
- 'name.max'=>'客户姓名最多32个字符.',
- 'nickname.required'=>'客户昵称不能为空.',
- 'nickname.max'=>'客户昵称最多32个字符.',
- 'remark.max'=>'备注最多255个字符.',
- ];
- $validator = Validator::make($request->input(),$rules,$message);
- if($validator->fails()){
- return $this->error('400013',$validator->errors()->first());
- }
- $user_id=$request->input('user_id');
- $res=UserW::where('id',$user_id)->update([
- 'name'=>$request->input('name'),
- 'phone'=>$request->input('phone'),
- 'nickname'=>$request->input('nickname'),
- 'sex'=>$request->input('sex'),
- 'remark'=>$request->input('remark'),
- ]);
- if($res){
- return $this->success([]);
- }else{
- return $this->error();
- }
- }
- //获取所有快递公司信息
- public function getExpressCompany(Request $request){
- $express=new ExpressHandler();
- $expressCode=$request->input('expressCode');
- $res=$express->getExpressCompany($expressCode);
- return $this->success($res);
- }
- //咨询客服,获取政委信息
- public function getServiceInfo()
- {
- $user_id=Auth::user()->id;
- $user=User::where('id',$user_id)->first();
- $admin_id=Warea::where('id',$user->warea_id)->value('admin_id');
- $admin=Admin::where('id',$admin_id)->first();
- return $this->success($admin);
- }
- //通过手机号获取证件图片
- public function getStoreCard(Request $request){
- // DB::connection()->enableQueryLog(); // 开启QueryLog
- $data=Store::query();
- $data->with('useraa:id,nickname,mobile,level,agent_id,crown_id,warea_id,deleted_at');
- $data->whereHas('useraa',function($query){
- $query->where('status',0)->where('cert_status',6)->whereNull('deleted_at')->where('service_status',0);
- });
- // $data->orderByDesc('user_id')->limit('1');
- return $data->count();
- // return $data->get();
- // \App\User::find(1);
- // return DB::getQueryLog();
- // $dwbs=UserZ::select(DB::raw('count(*) as count'),'dwbs_id')->groupBy('dwbs_id')->having('count','>',1)->pluck('dwbs_id');
- //// return $dwbs;
- // foreach($dwbs as $key=>$val){
- // if(!empty($val)){
- // $users=UserZ::where('dwbs_id',$val)->get();
- // foreach($users as $k=>$v){
- // $enroll=ZbsEnroll::query()->where('uid',$v->id)->where('season',31)->where('status',0)->first();
- // if($enroll){
- // $store_id=Store::where('user_id',$val)->value('id');
- // $list[$val.'--'.$store_id] = IntegralW::where('store_id',$store_id)->where('created_at','>','2021-09-13 00:00:00')->where('integral','>',0)->get();
- // }
- // }
- // }
- // }
- //
- // return $this->success($list);
- //
- // foreach($list as $key=>$val){
- // if(count($val)>0){
- // foreach($val as $k=>$v){
- // DB::transaction(function()use($v){
- // IntegralW::query()->where('id',$v->id)->update([
- // 'integral'=>0,
- // 'integral_double'=>0,
- // 'is_zbs'=>1
- // ]);
- // $store = Store::where('id',$v->store_id)->first();
- // $store->integral-=$v->integral;
- // $store->cycle_inte-=$v->integral;
- // $store->save();
- //
- // OrderW::where('order_no',$v->order_no)->update([
- // 'is_zbs'=>1
- // ]);
- // },5);
- // }
- // }
- // }
- // return $this->success($list);
- // $phone=$request->input('phone');
- // $data=Store::where('phone',$phone)->select('name','phone','cardImg1','cardImg2')->first();
- // $list['name']=$data->name;
- // $list['phone']=$data->phone;
- // $list['cardImg1']=env('APP_URL').$data->cardImg1;
- // $list['cardImg2']=env('APP_URL').$data->cardImg2;
- // return $this->success($list);
- }
- // public function changeInfo(Request $request){
- // $type=$request->input('type');
- // $n=$request->input('n');
- //
- // $ids=Amount::select('id','order_no','transaction_id',DB::raw('count(id) as c'))
- // ->groupBy('user_id','store_id','order_no','transaction_id','type','status','status_code','money','remark')
- // ->having('c','>',$n)
- // ->pluck('id');
- // if($type == 1){
- // return $ids;
- // }
- // if($type==2){
- // $a=Amount::query()->whereIn('id',$ids)->update(['deleted_at'=>date('Y-m-d H:i:s')]);
- // return $a;
- // }
- // }
- }
|