12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211 |
- <?php
-
-
- namespace app\api\model\v1;
-
- use think\Db;
- use think\Cache;
- use think\Config;
-
-
- load_trait('controller/Jump');
-
- class Shop extends UserBase
- {
- use \traits\controller\Jump;
-
- private $miniproInfo = [];
-
-
- protected function initialize()
- {
-
- parent::initialize();
- $this->times = getTime();
- $dataConf = tpSetting("OpenMinicode.conf_".self::$provider, [], self::$lang);
- $this->miniproInfo = json_decode($dataConf, true);
- }
-
- public function getCartTotalNum()
- {
- $cart_total_num = 0;
- if (!empty($this->users_id)){
- $cart_total_num = Db::name('shop_cart')->where(['users_id' => $this->users_id])->sum('product_num');
- }
- return $cart_total_num;
- }
-
-
-
- public function ShopPageAddCart($post = [])
- {
- $post['product_id'] = intval($post['product_id']);
- $post['users_id'] = intval($post['users_id']);
- $post['product_num'] = intval($post['product_num']);
-
-
- $ArchivesWhere = [
- 'aid' => $post['product_id'],
- 'lang' => get_home_lang(),
- 'arcrank' => ['>=', 0]
- ];
- $count = Db::name('archives')->where($ArchivesWhere)->count();
-
- if (!empty($count)) {
-
- $CartWhere = [
- 'users_id' => $post['users_id'],
- 'product_id' => $post['product_id'],
- 'lang' => get_home_lang()
- ];
-
-
- $usersConfig = getUsersConfigData('shop');
- if (!empty($usersConfig['shop_open_spec'])) {
- $combiWhere = [
- 'aid' => $post['product_id'],
- 'spec_stock' => ['>', 0],
- ];
-
- $Field = 'spec_value_id, spec_stock';
- $SpecValue = Db::name('product_spec_value')->field($Field)->where($combiWhere)->order('value_id asc')->find();
- if (!empty($SpecValue)) {
- if ($SpecValue['spec_stock'] > 0) {
- $post['spec_value_id'] = $CartWhere['spec_value_id'] = $SpecValue['spec_value_id'];
- } else {
- $this->error('商品已售罄');
- }
- }
- }
-
-
- $ProductNum = Db::name('shop_cart')->field('product_num')->where($CartWhere)->getField('product_num');
- if (!empty($ProductNum)) {
-
- $ResultID = Db::name('shop_cart')->where($CartWhere)->setInc('product_num', $post['product_num']);
- } else {
-
- $data = [
- 'users_id' => $post['users_id'],
- 'product_id' => $post['product_id'],
- 'product_num' => $post['product_num'],
- 'spec_value_id' => empty($post['spec_value_id']) || 'undefined' == $post['spec_value_id'] ? '' : $post['spec_value_id'],
- 'selected' => 1,
- 'lang' => get_home_lang(),
- 'add_time' => getTime(),
- 'update_time' => getTime()
- ];
- $ResultID = Db::name('shop_cart')->add($data);
- }
- if (!empty($ResultID)) {
- $cart_total_num = Db::name('shop_cart')->where(['users_id' => $post['users_id']])->sum('product_num');
- $this->success('加入成功','',['cart_total_num'=>$cart_total_num]);
- } else {
- $this->error('加入失败');
- }
- } else {
- $this->error('商品已下架');
- }
- }
-
-
-
- public function ShopAddCart($post = [])
- {
- $post['product_id'] = intval($post['product_id']);
- $post['users_id'] = intval($post['users_id']);
- $post['product_num'] = intval($post['product_num']);
-
-
- $ArchivesWhere = [
- 'aid' => $post['product_id'],
- 'lang' => get_home_lang(),
- 'arcrank' => ['>=', 0]
- ];
- $count = Db::name('archives')->where($ArchivesWhere)->count();
-
- if (!empty($count)) {
-
- $CartWhere = [
- 'users_id' => $post['users_id'],
- 'product_id' => $post['product_id'],
- 'lang' => get_home_lang()
- ];
- if (!empty($post['discount_active_id'])){
- $CartWhere['discount_active_id'] = $post['discount_active_id'];
- }else{
- $CartWhere['discount_active_id'] = 0;
- }
-
-
- $usersConfig = getUsersConfigData('shop');
- if (!empty($post['spec_value_id']) && 'undefined' != $post['spec_value_id'] && !empty($usersConfig['shop_open_spec'])) {
- $CartWhere['spec_value_id'] = $post['spec_value_id'];
- }
-
-
- $ProductNum = Db::name('shop_cart')->field('product_num')->where($CartWhere)->getField('product_num');
- if (!empty($ProductNum)) {
-
- $ResultID = Db::name('shop_cart')->where($CartWhere)->setInc('product_num', $post['product_num']);
- } else {
-
- $data = [
- 'users_id' => $post['users_id'],
- 'product_id' => $post['product_id'],
- 'product_num' => $post['product_num'],
- 'spec_value_id' => empty($post['spec_value_id']) || 'undefined' == $post['spec_value_id'] ? '' : $post['spec_value_id'],
- 'selected' => 1,
- 'lang' => get_home_lang(),
- 'add_time' => getTime(),
- 'update_time' => getTime(),
- 'discount_active_id' => !empty($CartWhere['discount_active_id']) ? $CartWhere['discount_active_id'] : 0
- ];
- $ResultID = Db::name('shop_cart')->add($data);
- }
- if (!empty($ResultID)) {
- $totalCart = Db::name('shop_cart')->where(['users_id' => $post['users_id']])->sum('product_num');
- $this->success('加入成功','',['cart_total_num'=>$totalCart]);
- } else {
- $this->error('加入失败');
- }
- } else {
- $this->error('商品已下架');
- }
- }
-
-
- public function ShopCartDelete($param = [])
- {
- if (empty($param['users_id'])) $this->error('请先登录');
- if (empty($param['action'])) $this->error('数据错误,请重试');
- if ('[]' == $param['cart_id']) $this->error('选择要删除的商品');
- $where = [
- 'users_id' => intval($param['users_id']),
- 'cart_id' => ['IN', $param['cart_id']],
- ];
- $ResultID = Db::name('shop_cart')->where($where)->delete();
- if (!empty($ResultID)) {
- $totalCart = Db::name('shop_cart')->where(['users_id' => $param['users_id']])->sum('product_num');
- $this->success('操作成功','',['cart_total_num'=>$totalCart]);
- } else {
- $this->error('操作失败');
- }
- }
-
-
- public function ShopCartList($users_id = null, $level_discount = 100, $level_id = 0)
- {
- $result = [];
- $result['cart_list'] = [];
-
- if (!empty($users_id)) {
-
- $condition = [
- 'a.users_id' => $users_id,
- 'a.lang' => get_home_lang(),
- 'b.arcrank' => array('egt', 0)
- ];
- $field = 'a.*, b.aid, b.title, b.litpic, b.users_price, b.users_discount_type, b.stock_count, b.attrlist_id, c.spec_price, c.spec_stock';
- if ('v1.5.1' < getVersion()) {
- $field .= ',c.seckill_price, c.seckill_stock';
- }
- if ('v1.5.7' < getVersion()) {
- $field .= ',c.discount_price, c.discount_stock';
- }
-
- $ShopCart = Db::name("shop_cart")
- ->field($field)
- ->alias('a')
- ->join('__ARCHIVES__ b', 'a.product_id = b.aid', 'LEFT')
- ->join('__PRODUCT_SPEC_VALUE__ c', 'a.spec_value_id = c.spec_value_id and a.product_id = c.aid', 'LEFT')
- ->where($condition)
- ->order('a.selected desc, a.add_time desc')
- ->select();
-
- if (!empty($ShopCart)) {
-
- $ConfigData = getUsersConfigData('shop');
-
-
- $users_discount = strval($level_discount) / strval(100);
-
-
- $ShopCart = $this->OrderProductProcess($ShopCart, $ConfigData, $users_discount, $level_id);
- }
- $result['cart_list'] = $ShopCart;
- }
-
- $result['product'] = model('v1.Api')->getRecomProduct();
-
- return $result;
- }
-
-
- public function ShopCartNumAdd($param = [])
- {
- if (empty($param['users_id'])) $this->error('请先登录');
- if (empty($param['action']) || empty($param['product_id'])) $this->error('数据错误,请重试');
- $where = [
- 'users_id' => intval($param['users_id']),
- 'product_id' => intval($param['product_id']),
- ];
- if (!empty($param['spec_value_id']) && 'undefined' != $param['spec_value_id']) {
- $where['spec_value_id'] = $param['spec_value_id'];
- }
- $ResultID = Db::name('shop_cart')->where($where)->setInc('product_num');
- if (!empty($ResultID)) {
- $cart_total_num = Db::name('shop_cart')->where('users_id',$param['users_id'])->sum('product_num');
- $this->success('操作成功','',['cart_total_num'=>$cart_total_num]);
- } else {
- $this->error('操作失败');
- }
- }
-
-
- public function ShopCartNumLess($param = [])
- {
- if (empty($param['users_id'])) $this->error('请先登录');
- if (empty($param['action']) || empty($param['product_id'])) $this->error('数据错误,请重试');
- $where = [
- 'users_id' => intval($param['users_id']),
- 'product_id' => intval($param['product_id']),
- ];
- if (!empty($param['spec_value_id']) && 'undefined' != $param['spec_value_id']) {
- $where['spec_value_id'] = $param['spec_value_id'];
- }
- $product_num_tmp = Db::name('shop_cart')->where($where)->getField('product_num');
- if (!empty($product_num_tmp)) {
- if ($product_num_tmp > 1) {
- $ResultID = Db::name('shop_cart')->where($where)->setDec('product_num');
- if (!empty($ResultID)) {
- $cart_total_num = Db::name('shop_cart')->where('users_id',$param['users_id'])->sum('product_num');
- $this->success('操作成功','',['cart_total_num'=>$cart_total_num]);
- }
- } else {
- $this->error('数量至少一件!');
- }
- }
- $this->error('操作失败');
- }
-
-
- public function ShopCartSelected($param = [])
- {
- if (empty($param['users_id'])) $this->error('请先登录');
- if (empty($param['action']) || empty($param['product_id'])) $this->error('数据错误,请重试');
- $where = [
- 'users_id' => intval($param['users_id']),
- 'product_id' => intval($param['product_id']),
- ];
- if (!empty($param['spec_value_id']) && 'undefined' != $param['spec_value_id']) {
- $where['spec_value_id'] = $param['spec_value_id'];
- }
- $update = [
- 'selected' => $param['selected'] == 1 ? 0 : 1,
- 'update_time' => getTime()
- ];
- $ResultID = Db::name('shop_cart')->where($where)->update($update);
- if (!empty($ResultID)) {
- $this->success('操作成功');
- } else {
- $this->error('操作失败');
- }
- }
-
-
- public function ShopCartAllSelected($param = [])
- {
- if (empty($param['users_id'])) $this->error('请先登录');
- if (empty($param['action'])) $this->error('数据错误,请重试');
- $where = [
- 'users_id' => intval($param['users_id']),
- ];
- $update = [
- 'selected' => $param['all_selected'],
- 'update_time' => getTime()
- ];
- $ResultID = Db::name('shop_cart')->where($where)->update($update);
- if (!empty($ResultID)) {
- $this->success('操作成功');
- } else {
- $this->error('操作失败');
- }
- }
-
-
-
-
- public function ShopBuyNow($post = [])
- {
-
- $ArchivesWhere = [
- 'aid' => $post['product_id'],
- 'lang' => get_home_lang(),
- 'arcrank' => ['>=', 0]
- ];
- $count = Db::name('archives')->where($ArchivesWhere)->count();
-
- if (!empty($count)) {
-
- $querydata = [
- 'product_id' => $post['product_id'],
- 'product_num' => $post['product_num'],
- 'active_time_id' => isset($post['active_time_id']) ? $post['active_time_id'] : 0,
- 'discount_active_id' => isset($post['discount_active_id']) ? $post['discount_active_id'] : 0,
- ];
-
-
- if (!empty($post['spec_value_id']) && 'undefined' != $post['spec_value_id']) {
- $querydata['spec_value_id'] = $post['spec_value_id'];
- }
-
-
-
- $querystr = md5(json_encode($querydata));
-
-
- Cache::set($querystr, $querydata, 86400);
-
-
- if (1 == input('param.fenbao/d')) {
- $url = '?querystr=' . $querystr;
- } else {
- $url = '/pages/product_buy/index?querystr=' . $querystr;
- }
- $this->success('数据正确', $url, ['url'=>$url]);
- } else {
- $this->error('该商品不存在或已下架!');
- }
- }
-
-
- public function GetProductData($querystr = null, $users_id = null, $level_discount = 100, $users = [], $post = [])
- {
- if (empty($users_id)) $this->error('请先登录');
-
-
- $CacheData = Cache::get($querystr);
-
-
- $list = $this->GetBuyOrderList($CacheData, $users_id, $post);
- if (empty($list)) $this->error('链接失效,请重新下单');
-
-
- if (empty($CacheData)) {
- $logistics_type_arr = get_arr_column($list, 'logistics_type');
- if (empty($post['deliveryShow']) && empty($post['verifyShow']) && in_array(1, $logistics_type_arr)) {
- $post['deliveryShow'] = 1;
- }
- }
-
-
- $ConfigData = getUsersConfigData('shop');
-
-
- $users_discount = strval($level_discount) / strval(100);
- if (!empty($CacheData['active_time_id'])){
-
- $users_discount = 0;
- }
-
-
- $list = $this->OrderProductProcess($list, $ConfigData, $users_discount, $users['level_id']);
- if (empty($list)) $this->error('商品库存不足或已过期!');
-
-
-
- $GlobalInfo = $this->GetGlobalInfo($ConfigData, $CacheData);
-
-
-
- foreach ($list as $key => $value) {
-
- if ($value['users_price'] >= 0 && !empty($value['product_num'])) {
-
- $list[$key]['subtotal'] = unifyPriceHandle($value['users_price'] * $value['product_num']);
-
- $GlobalInfo['TotalAmount'] += $list[$key]['subtotal'];
- $GlobalInfo['TotalAmount'] = unifyPriceHandle($GlobalInfo['TotalAmount']);
-
- $GlobalInfo['TotalNumber'] += $value['product_num'];
-
-
- if (empty($value['prom_type'])) $GlobalInfo['PromType'] = 0;
- }
-
-
- if ('2' === $value['logistics_type']) $GlobalInfo['onlyVerify'] = true;
-
- if ('1' === $value['logistics_type']) $GlobalInfo['onlyDelivery'] = true;
-
- if ('1,2' === $value['logistics_type']) $GlobalInfo['allLogisticsType'] = true;
- }
-
-
-
- $address = Db::name('shop_address')->where('users_id', $users_id)->order('is_default desc')->find();
- if (!empty($address)) {
- $address['region']['province'] = $this->GetRegionName($address['province']);
- $address['region']['city'] = $this->GetRegionName($address['city']);
- $address['region']['district'] = $this->GetRegionName($address['district']);
- $address['region']['detail'] = $address['address'];
- $address['address_all'] = $address['region']['province'] . $address['region']['city'] . $address['region']['district'] . $address['region']['detail'];
-
- if (!empty($GlobalInfo['shop_open_shipping'])) {
-
- $where['province_id'] = $address['province'];
- $template_money = Db::name('shop_shipping_template')->where($where)->getField('template_money');
- if (0 == $template_money) {
- $where['province_id'] = 100000;
- $template_money = Db::name('shop_shipping_template')->where($where)->getField('template_money');
- }
- $address['template_money'] = $template_money;
-
- } else {
- $address['template_money'] = 0;
- }
- } else {
- $address['template_money'] = 0;
- }
-
-
-
- if (!empty($post['deliveryShow']) && 1 === intval($post['deliveryShow'])) {
-
- $GlobalInfo['PayTotalAmount'] = unifyPriceHandle($GlobalInfo['TotalAmount'] + $address['template_money']);
- } else {
- $GlobalInfo['PayTotalAmount'] = unifyPriceHandle($GlobalInfo['TotalAmount']);
- }
-
-
- $ResultData = [
- 'users' => $users,
- 'address' => $address,
- 'global_info' => $GlobalInfo,
- 'product_data' => $list
- ];
- $ResultData['coupon_data'] = $this->getOrderCoupon($list,$users_id);
- $coupon_ids = get_arr_column($ResultData['coupon_data'],'coupon_id');
- $ResultData['unuse_coupon_data'] = $this->getUnuseOrderCoupon($coupon_ids,$users_id);
- $this->success('数据正确', null, $ResultData);
- }
-
-
-
- public function getOrderCoupon($product_data,$user_id)
- {
- $aids = [];
- $aid_price = 0;
- $totol_price = 0;
- foreach ($product_data as $k => $v){
- if (!empty($v['stop_buy']) && 1 == $v['stop_buy']){
- continue;
- }
- if (!in_array($v['aid'],$aids)){
- $aids[] = $v['aid'];
- $aid_price += $v['subtotal'];
- }
- $totol_price += $v['subtotal'];
- }
- $where['a.users_id'] = $user_id;
- $where['a.start_time'] = ['<=',getTime()];
- $where['a.end_time'] = ['>=',getTime()];
- $where['a.use_status'] = 0;
- $where['b.coupon_id'] = ['>',1];
- $use_data = [];
-
- $data = Db::name('shop_coupon_use')
- ->alias('a')
- ->join('shop_coupon b','a.coupon_id = b.coupon_id','left')
- ->where($where)
- ->getAllWithIndex('use_id');
- $type_coupon_arr = [];
- if (!empty($data)){
- foreach ($data as $k => $v){
- if (1 == $v['coupon_form']){
- $v['coupon_form_name'] = '满减券';
- }
- $v['start_time'] = date('Y/m/d', $v['start_time']);
- $v['end_time'] = date('Y/m/d', $v['end_time']);
- switch ($v['coupon_type'])
- {
- case 2:
- $v['coupon_type_name'] = '指定商品';
-
- if (!empty($v['product_id'])){
- $product_arr = explode(",",$v['product_id']);
- $in = 0;
- foreach ($aids as $m){
- if (in_array($m,$product_arr) && $aid_price >= $v['conditions_use']){
-
- $in = 1;
- break;
- }
- }
- if (!empty($in)){
- $use_data[] = $v;
- }
- }
- break;
- case 3:
- $v['coupon_type_name'] = '指定分类';
-
- if (!empty($v['arctype_id'])){
- $arctype_arr = explode(",",$v['arctype_id']);
- $is_have = 0;
- foreach ($product_data as $key => $val){
- if (in_array($val['typeid'],$arctype_arr)){
- $is_have = 1;
- if (empty($v['goods_total_price'])){
- $v['goods_total_price'] = $val['subtotal'];
- }else{
- $v['goods_total_price'] += $val['subtotal'];
- }
- }
- }
- if (!empty($is_have)) $type_coupon_arr[] = $v;
- }
- break;
- default:
- $v['coupon_type_name'] = '全部商品';
- if ($totol_price >= $v['conditions_use']) {
- $use_data[] = $v;
- }
- break;
- }
- }
-
- if (!empty($type_coupon_arr)){
- foreach ($type_coupon_arr as $k => $v) {
- if ($v['goods_total_price'] >= $v['conditions_use']){
- unset($type_coupon_arr[$k]['goods_total_price']);
- $use_data[] = $v;
- }
- }
- }
- }
- return $use_data;
- }
-
-
- public function getUnuseOrderCoupon($coupon_ids = [],$users_id)
- {
-
- $where['a.users_id'] = $users_id;
- $where['a.use_status'] = 0;
- $where['a.end_time'] = ['>=',getTime()];
- $where['b.coupon_id'] = ['not in',$coupon_ids];
- $unuse_data = [];
-
- $data = Db::name('shop_coupon_use')
- ->alias('a')
- ->join('shop_coupon b','a.coupon_id = b.coupon_id','left')
- ->where($where)
- ->getAllWithIndex('use_id');
- if (!empty($data)){
- foreach ($data as $k => $v){
- if (1 == $v['coupon_form']){
- $v['coupon_form_name'] = '满减券';
- }
- $v['start_time'] = date('Y/m/d', $v['start_time']);
- $v['end_time'] = date('Y/m/d', $v['end_time']);
- switch ($v['coupon_type']) {
- case '1':
- $v['coupon_type_name'] = '全部商品';
- break;
- case '2';
- $v['coupon_type_name'] = '指定商品';
- break;
- case '3';
- $v['coupon_type_name'] = '指定分类';
- break;
- }
- $unuse_data[] = $v;
- }
- }
- return $unuse_data;
- }
-
-
- public function ShopOrderPay($post = [], $level_discount = 100, $level_id = 0, $usersData = [])
- {
-
- if (empty($post['users_id'])) $this->error('请先登录');
- if (1 != $post['prom_type']){
- if (empty($post['addr_id']) || $post['addr_id'] == 'undefined') $this->error('请添加收货地址');
- }
- if (empty($post['pay_type'])) $this->error('请选择支付方式');
-
-
- $ConfigData = getUsersConfigData('shop');
-
-
- $users_discount = strval($level_discount) / strval(100);
- if (isset($post['order_source']) && 20 == $post['order_source']) $users_discount = 0;
-
-
- $CacheData = Cache::get($post['querystr']);
- $list = $this->GetBuyOrderList($CacheData, $post['users_id'], $post);
- if (empty($list)) $this->error('链接失效,请重新下单');
-
-
- $list = $this->OrderProductProcess($list, $ConfigData, $users_discount, $level_id);
- if (empty($list)) $this->error('商品库存不足或已过期');
-
-
- $GlobalInfo = $this->GetGlobalInfo($ConfigData, $CacheData);
-
-
- foreach ($list as $key => $value) {
-
- if ($value['users_price'] >= 0 && !empty($value['product_num'])) {
-
- $GlobalInfo['TotalAmount'] += unifyPriceHandle($value['users_price'] * $value['product_num']);
- $GlobalInfo['TotalAmount'] = unifyPriceHandle($GlobalInfo['TotalAmount']);
-
- $GlobalInfo['TotalNumber'] += $value['product_num'];
-
-
- if (empty($value['prom_type'])) $GlobalInfo['PromType'] = 0;
- }
-
- }
-
-
- $AddrData = [];
- if (!empty($post['deliveryShow']) && 1 === intval($post['deliveryShow'])) {
-
- $AddrData = $this->GetUsersAddrData($post, $GlobalInfo['PromType']);
-
- $GlobalInfo['PayTotalAmount'] = unifyPriceHandle($GlobalInfo['TotalAmount'] + $AddrData['shipping_fee']);
- } else {
- $GlobalInfo['PayTotalAmount'] = unifyPriceHandle($GlobalInfo['TotalAmount']);
- }
-
-
- $PayAmount = $GlobalInfo['PayTotalAmount'];
-
-
- if (!empty($post['coupon_id'])){
- $coupon_where = [
- 'a.coupon_id'=>$post['coupon_id'],
- 'a.use_status'=>0,
- 'a.users_id' => $post['users_id'],
- ];
- $coupon_where['a.start_time'] = ['<=',getTime()];
- $coupon_where['a.end_time'] = ['>=',getTime()];
- $coupon_info = Db::name('shop_coupon_use')
- ->alias('a')
- ->join('shop_coupon b','a.coupon_id = b.coupon_id','left')
- ->where($coupon_where)
- ->find();
- if (!empty($coupon_info)){
- $PayAmount = $PayAmount-$coupon_info['coupon_price'] < 0 ? 0 : $PayAmount-$coupon_info['coupon_price'];
- }
- }
-
- if (2 == $post['pay_type']) {
- $UsersMoney = Db::name('users')->where('users_id', $post['users_id'])->getField('users_money');
- if ($GlobalInfo['PayTotalAmount'] > $UsersMoney) $this->error('您的余额不足,支付失败');
- }
-
-
- $time = getTime();
- $OrderData = [
- 'order_code' => date('Ymd') . $time . rand(10, 100),
- 'users_id' => $post['users_id'],
- 'order_status' => 0,
- 'add_time' => $time,
- 'payment_method' => 0,
- 'pay_time' => 0,
- 'pay_name' => 'wechat',
- 'wechat_pay_type' => 'WeChatInternal',
- 'order_terminal' => 3,
- 'pay_details' => '',
- 'order_total_amount' => $GlobalInfo['PayTotalAmount'],
- 'order_amount' => $PayAmount,
- 'order_total_num' => $GlobalInfo['TotalNumber'],
- 'prom_type' => $GlobalInfo['PromType'],
- 'order_source' => isset($post['order_source']) ? $post['order_source'] : 10,
- 'order_source_id' => isset($post['order_source_id']) ? $post['order_source_id'] : 0,
- 'virtual_delivery' => '',
- 'admin_note' => '',
- 'user_note' => $post['remark'],
- 'lang' => get_home_lang()
- ];
- if (!empty($coupon_info)) {
- $OrderData['coupon_id'] = $coupon_info['coupon_id'];
- $OrderData['use_id'] = $coupon_info['use_id'];
- $OrderData['coupon_price'] = $coupon_info['coupon_price'];
- }
-
- if (!empty($AddrData)) $OrderData = array_merge($OrderData, $AddrData);
-
-
- $OrderData = model('ShopPublicHandle')->orderSubmitPublicHandle($OrderData, $this->usersConfig, $this->users_id, $post, $list);
-
-
- if (9 === intval($post['pay_type'])) {
- $OrderData['pay_name'] = 'tikTokPay';
- $OrderData['wechat_pay_type'] = '';
- }
-
-
- $OrderId = Db::name('shop_order')->add($OrderData);
- if (!empty($OrderId)) {
- $OrderData['order_id'] = $OrderId;
-
-
- $OrderData = model('ShopPublicHandle')->orderCreatePublicHandle($OrderData, $this->usersConfig, $this->users_id, $post, $list);
-
-
- if (!empty($coupon_info)){
- $coupon_update = [
- 'coupon_id'=>$post['coupon_id'],
- 'use_status'=> 0,
- 'users_id' => $post['users_id'],
- ];
- Db::name('shop_coupon_use')->where($coupon_update)->update(['use_status'=> 1,'use_time'=>getTime(),'update_time'=>getTime()]);
- }
-
- $cart_ids = $UpSpecValue = [];
- $contains_virtual = 1;
- foreach ($list as $key => $value) {
- $attr_value = $attr_value_new = $spec_value = '';
-
-
- $attr_value = $this->ProductAttrProcessing($value);
-
- $attr_value_new = $this->ProductNewAttrProcessing($value);
-
- $spec_value = $this->ProductSpecProcessing($value);
-
-
- $ParamData = [
-
- 'attr_value' => htmlspecialchars($attr_value),
-
- 'attr_value_new' => htmlspecialchars($attr_value_new),
-
- 'spec_value' => htmlspecialchars($spec_value),
-
- 'spec_value_id' => $value['spec_value_id'],
-
- 'value_id' => $value['value_id'],
-
- ];
-
-
- $OrderDetailsData[] = [
- 'order_id' => $OrderId,
- 'users_id' => $post['users_id'],
- 'product_id' => $value['aid'],
- 'product_name' => $value['title'],
- 'num' => $value['product_num'],
- 'data' => serialize($ParamData),
- 'product_price' => $value['users_price'],
- 'prom_type' => $value['prom_type'],
- 'litpic' => $value['litpic'],
- 'add_time' => $time,
- 'lang' => get_home_lang()
- ];
-
-
- if (empty($GlobalInfo['submit_order_type'])) {
- array_push($cart_ids, $value['cart_id']);
- }
-
-
- $UpSpecValue[] = [
- 'aid' => $value['aid'],
- 'value_id' => $value['value_id'],
- 'quantity' => $value['product_num'],
- 'spec_value_id' => $value['spec_value_id'],
- 'order_source' => isset($post['order_source']) ? $post['order_source'] : 10,
- 'order_source_id' => isset($post['order_source_id']) ? $post['order_source_id'] : 0,
- ];
-
- if (in_array($value['prom_type'],[1,2,3])){
- $contains_virtual = 2;
- }
- }
- if (2 == $contains_virtual) {
- Db::name('shop_order')->where('order_id',$OrderId)->update(['contains_virtual'=>$contains_virtual]);
- }
-
- $DetailsId = Db::name('shop_order_details')->insertAll($OrderDetailsData);
- if (!empty($OrderId) && !empty($DetailsId)) {
-
- if (!empty($cart_ids)) Db::name('shop_cart')->where('cart_id', 'IN', $cart_ids)->delete();
-
-
- $this->ProductStockProcessing($UpSpecValue);
-
-
- AddOrderAction($OrderId, $post['users_id']);
-
-
- if (1 === intval($post['pay_type'])) {
- $weChatPay = $this->GetWechatAppletsPay($post['openid'], $OrderData['order_code'], $OrderData['order_amount']);
- $result = [
- 'WeChatPay' => $weChatPay,
- 'OrderData' => [
- 'order_id' => $OrderId,
- 'order_code' => $OrderData['order_code']
- ]
- ];
- $result['tmplData'] = [];
-
- $this->success('正在支付', null, $result);
- }
-
- else if (2 === intval($post['pay_type'])) {
- $pay_details = [
- 'unified_id' => $OrderId,
- 'unified_number' => $OrderData['order_code'],
- 'payment_amount' => $OrderData['order_amount'],
- 'payment_type' => '余额支付'
- ];
- $UpOrderData = [
- 'order_status' => 1,
- 'pay_name' => 'balance',
- 'wechat_pay_type' => '',
- 'pay_details' => serialize($pay_details),
- 'pay_time' => getTime(),
- 'update_time' => getTime()
- ];
- $ReturnID = Db::name('shop_order')->where('order_id', $OrderId)->update($UpOrderData);
- if (!empty($ReturnID)) {
- $UsersData = [
- 'users_money' => $UsersMoney - $OrderData['order_amount'],
- 'update_time' => getTime()
- ];
- $users_id = Db::name('users')->where('users_id', $post['users_id'])->update($UsersData);
- if (!empty($users_id)) {
-
- $getParam = [
- 'users_money' => $UsersMoney,
- 'users_id' => $post['users_id']
- ];
- UsersMoneyAction($OrderData['order_code'], $getParam, $OrderData['order_amount'], '订单支付');
-
-
- AddOrderAction($OrderId, $post['users_id'], 0, 1, 0, 1, '支付成功!', '会员使用余额完成支付!');
-
-
- $ShopModel = new \app\user\model\Pay();
- $Where = [
- 'lang' => get_home_lang(),
- 'users_id' => $post['users_id'],
- 'order_id' => $OrderId
- ];
- $ShopModel->afterVirtualProductPay($Where);
-
-
- eyou_statistics_data(2);
- eyou_statistics_data(3, $OrderData['order_amount']);
- $result['tmplData'] = [];
-
-
- $result['email'] = GetEamilSendData(tpCache('smtp'), $usersData, $OrderData, 1, 'balance');
-
-
- $result['mobile'] = GetMobileSendData(tpCache('sms'), $usersData, $OrderData, 1, 'balance');
-
-
- $OrderData['pay_method'] = '余额支付';
- SendNotifyMessage($OrderData, 5, 1, 0);
-
-
- $result['OrderData'] = $OrderData;
- $this->success('支付完成', '/pages/order/index', $result);
- }
- }
- }
-
- else if (9 === intval($post['pay_type'])) {
- $tikTokPay = model('TikTok')->getTikTokAppletsPay($OrderId, $OrderData['order_code'], $OrderData['order_amount'], $this->usersConfig['order_unpay_close_time']);
- $result = [
- 'tikTokPay' => $tikTokPay,
- 'OrderData' => [
- 'order_id' => $OrderId,
- 'order_code' => $OrderData['order_code']
- ]
- ];
-
-
-
-
-
-
-
-
- $result['tmplData'] = [];
-
- $this->success('正在支付', null, $result);
- }
- } else if (!empty($OrderId) && empty($DetailsId)) {
-
- Db::name('shop_order')->delete($OrderId);
- $this->error('订单生成失败,商品数据有误!');
- }
- }
- $this->error('订单生成失败,商品数据有误!');
- }
-
-
- public function create_verify_code($length = 12)
- {
- $chars = "0123456789";
- $char_len = strlen($chars);
- $verify_code = '';
- for ($i = 0; $i < $length; $i++) {
- $loop = mt_rand(0, ($char_len - 1));
- $verify_code .= $chars[$loop];
- }
- $is_have = Db::name('shop_order_verify')->where('verify_code',$verify_code)->count();
- if (!empty($is_have)){
- $verify_code = $this->create_verify_code(12);
- }
- return $verify_code;
- }
-
-
- public function WechatAppletsPayDealWith($PostData = [], $notify = false)
- {
- $OpenID = !empty($PostData['openid']) ? $PostData['openid'] : '';
- $UsersID = !empty($PostData['users_id']) ? $PostData['users_id'] : '';
- $OrderID = $PostData['order_id'];
- $OrderCode = $PostData['order_code'];
-
- if (!empty($OrderID) && !empty($OrderCode)) {
-
- $where = [
- 'users_id' => $UsersID,
- 'order_id' => $OrderID,
- 'order_code' => $OrderCode,
- ];
- $order = Db::name('shop_order')->where($where)->find();
-
- if (empty($order)) {
- $this->error('无效订单!');
- } else if (0 < $order['order_status']) {
-
- if ($notify === true) {
- return [
- 'code' => 1,
- 'msg' => 'ok',
- ];
- }
- else {
- $usersData = Db::name('users')->where('users_id', $UsersID)->find();
-
- $resultData['email'] = GetEamilSendData(tpCache('smtp'), $usersData, $order, 1, 'wechat');
-
- $resultData['mobile'] = GetMobileSendData(tpCache('sms'), $usersData, $order, 1, 'wechat');
- $this->success('支付完成', '/pages/order/index', $resultData);
- }
- }
-
-
- $time = getTime();
-
-
- $nonceStr = md5($time . $OpenID);
-
-
- $params = [
- 'appid' => $this->miniproInfo['appid'],
- 'mch_id' => $this->miniproInfo['mchid'],
- 'nonce_str' => $nonceStr,
- 'out_trade_no' => $OrderCode
- ];
-
-
- $params['sign'] = $this->ParamsSign($params, $this->miniproInfo['apikey']);
-
-
- $ParamsXml = $this->ParamsXml($params);
-
-
- $url = 'https://api.mch.weixin.qq.com/pay/orderquery';
- $result = $this->HttpsPost($url, $ParamsXml);
-
-
- $ResultData = $this->ResultXml($result);
-
-
- if (!empty($ResultData) && 'SUCCESS' == $ResultData['return_code'] && 'OK' == $ResultData['return_msg']) {
-
-
-
-
- if ('SUCCESS' == $ResultData['trade_state']) {
-
- $OrderWhere = [
- 'order_id' => $OrderID,
- 'users_id' => $order['users_id']
- ];
- $OrderData = [
- 'order_status' => 1,
- 'pay_details' => serialize($ResultData),
- 'pay_time' => getTime(),
- 'update_time' => getTime()
- ];
- $ResultID = Db::name('shop_order')->where($OrderWhere)->update($OrderData);
- if (!empty($ResultID)) {
-
- AddOrderAction($OrderID, $order['users_id'], 0, 1, 0, 1, '支付成功', '会员使用微信小程序完成支付');
-
-
- $ShopModel = new \app\user\model\Pay();
- $Where = [
- 'lang' => get_home_lang(),
- 'users_id' => $UsersID,
- 'order_id' => $OrderID
- ];
- $ShopModel->afterVirtualProductPay($Where);
-
-
- $order['pay_method'] = '微信支付';
- SendNotifyMessage($order, 5, 1, 0);
-
-
- $where = [
- 'users_id' => $UsersID,
- 'order_id' => $OrderID
- ];
- $data = Db::name('shop_order_details')->where($where)->getField('data');
- $data = !empty($data) ? unserialize($data) : [];
- $pointsGoodsBuyField = !empty($data['pointsGoodsBuyField']) ? json_decode($data['pointsGoodsBuyField'], true) : [];
- if (!empty($pointsGoodsBuyField['goodsTotalPoints'])) {
- $insert = [
- 'type' => 11,
- 'users_id' => $UsersID,
- 'score' => $pointsGoodsBuyField['goodsTotalPoints'],
- 'info' => '积分商城订单支付',
- 'remark' => '积分商城订单支付',
- ];
- addConsumObtainScores($insert, 1, false);
- }
-
-
- if ($notify === true) {
- return [
- 'code' => 1,
- 'msg' => 'ok',
- ];
- }
- else {
-
- eyou_statistics_data(2);
- eyou_statistics_data(3, $order['order_amount']);
-
- $usersData = Db::name('users')->where('users_id', $UsersID)->find();
-
- $resultData['email'] = GetEamilSendData(tpCache('smtp'), $usersData, $order, 1, 'wechat');
-
- $resultData['mobile'] = GetMobileSendData(tpCache('sms'), $usersData, $order, 1, 'wechat');
- $this->success('支付完成', '/pages/order/index', $resultData);
- }
- }
- }
- }
- }
- }
-
-
- public function OrderDirectPay($post = [])
- {
- $where = [
- 'users_id' => $post['users_id'],
- 'order_id' => $post['order_id'],
- 'order_code' => $post['order_code']
- ];
- $field = 'order_status, order_amount';
- $Result = Db::name('shop_order')->where($where)->field($field)->find();
- if (!empty($Result)) {
- if (0 == $Result['order_status']) {
- $Data = $this->GetWechatAppletsPay($post['openid'], $post['order_code'], $Result['order_amount']);
- $ResultData = [
- 'WeChatPay' => $Data,
- 'OrderData' => [
- 'order_id' => $post['order_id'],
- 'order_code' => $post['order_code']
- ]
- ];
- $url = '/pages/order/index';
- $this->success('正在支付', $url, $ResultData);
- } else if (in_array($Result['order_status'], [1, 2, 3])) {
- $this->success('订单已支付');
- } else if ($Result['order_status'] == 4) {
- $this->success('订单已过期');
- } else if ($Result['order_status'] == -1) {
- $this->success('订单已关闭');
- }
- }
- $this->error('订单不存在');
- }
-
-
- public function GetWechatAppletsPay($OpenID = null, $out_trade_no = null, $total_fee = null, $notify_url = '')
- {
- $notify_url = !empty($notify_url) ? $notify_url : url('api/v1.Api/wxpay_notify', [], true, true, 1, 1);
-
- $time = time();
-
-
- $nonceStr = md5($time . $OpenID);
-
-
- $params = [
- 'appid' => $this->miniproInfo['appid'],
- 'attach' => "微信小程序支付",
- 'body' => "商品支付",
- 'mch_id' => $this->miniproInfo['mchid'],
- 'nonce_str' => $nonceStr,
- 'notify_url' => $notify_url,
- 'openid' => $OpenID,
- 'out_trade_no' => $out_trade_no,
- 'spbill_create_ip' => $this->GetClientIP(),
- 'total_fee' => strval($total_fee * 100),
- 'trade_type' => 'JSAPI'
- ];
-
-
- $params['sign'] = $this->ParamsSign($params, $this->miniproInfo['apikey']);
-
-
- $ParamsXml = $this->ParamsXml($params);
-
-
- $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
- $result = $this->HttpsPost($url, $ParamsXml);
-
-
- $ResultData = $this->ResultXml($result);
-
-
- if ($ResultData['return_code'] == 'SUCCESS' && $ResultData['return_msg'] == 'OK') {
-
- $ReturnData = [
- 'prepay_id' => $ResultData['prepay_id'],
- 'nonceStr' => $nonceStr,
- 'timeStamp' => strval($time),
- 'return_code' => $ResultData['return_code']
- ];
-
- $ReturnData['paySign'] = $this->PaySign($this->miniproInfo['appid'], $params['nonce_str'], $ResultData['prepay_id'], $time);
- return $ReturnData;
- } else if ($ResultData['return_code'] == 'FAIL') {
- if ($ResultData['return_msg'] == '签名错误') {
- $ResultData['return_msg'] = '小程序支付配置不正确!';
- }
- return $ResultData;
- } else {
- return $ResultData;
- }
- }
-
- private function ParamsSign($values, $apikey)
- {
-
- ksort($values);
- $string = $this->ParamsUrl($values);
-
- $string = $string . '&key=' . $apikey;
-
- $string = md5($string);
-
- $result = strtoupper($string);
- return $result;
- }
-
- private function ParamsUrl($values)
- {
- $Url = '';
- foreach ($values as $k => $v) {
- if ($k != 'sign' && $v != '' && !is_array($v)) {
- $Url .= $k . '=' . $v . '&';
- }
- }
- return trim($Url, '&');
- }
-
- private function ParamsXml($values)
- {
- if (!is_array($values)
- || count($values) <= 0
- ) {
- return false;
- }
-
- $xml = "<xml>";
- foreach ($values as $key => $val) {
- if (is_numeric($val)) {
- $xml .= "<" . $key . ">" . $val . "</" . $key . ">";
- } else {
- $xml .= "<" . $key . "><![CDATA[" . $val . "]]></" . $key . ">";
- }
- }
- $xml .= "</xml>";
- return $xml;
- }
-
- private function ResultXml($xml)
- {
-
- @libxml_disable_entity_loader(true);
- return json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
- }
-
- private function GetClientIP()
- {
- if (getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
- $ip = getenv('HTTP_CLIENT_IP');
- } elseif (getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
- $ip = getenv('HTTP_X_FORWARDED_FOR');
- } elseif (getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
- $ip = getenv('REMOTE_ADDR');
- } elseif (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
- $ip = $_SERVER['REMOTE_ADDR'];
- }
- return preg_match('/[\d\.]{7,15}/', $ip, $matches) ? $matches [0] : '';
- }
-
- private function HttpsPost($url, $data)
- {
- $result = httpRequest($url, 'POST', $data);
- return $result;
-
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
-
- curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $result = curl_exec($ch);
- if (curl_errno($ch)) {
- return 'Errno: ' . curl_error($ch);
- }
- curl_close($ch);
- return $result;
- }
-
- private function PaySign($appid, $nonceStr, $prepay_id, $timeStamp)
- {
- $data = [
- 'appId' => $appid,
- 'nonceStr' => $nonceStr,
- 'package' => 'prepay_id=' . $prepay_id,
- 'signType' => 'MD5',
- 'timeStamp' => $timeStamp,
- ];
-
- ksort($data);
- $string = $this->ParamsUrl($data);
-
- $string = $string . '&key=' . $this->miniproInfo['apikey'];
-
- $string = md5($string);
-
- $result = strtoupper($string);
- return $result;
- }
-
-
- private function ProductStockProcessing($SpecValue = [])
- {
- if (!empty($SpecValue)) {
- $SpecUpData = [];
- $ArcUpData = [];
- foreach ($SpecValue as $key => $value) {
- if (!empty($value['value_id'])) {
- if (!empty($value['order_source']) && $value['order_source'] == 20){
-
- $SpecUpData[] = [
- 'value_id' => $value['value_id'],
- 'seckill_stock' => Db::raw('seckill_stock-' . ($value['quantity'])),
- 'seckill_sales_num' => Db::raw('seckill_sales_num+' . ($value['quantity'])),
- ];
- }else{
-
- $SpecUpData[] = [
- 'value_id' => $value['value_id'],
- 'spec_stock' => Db::raw('spec_stock-' . ($value['quantity'])),
- 'spec_sales_num' => Db::raw('spec_sales_num+' . ($value['quantity'])),
- ];
- $ArcUpData[] = [
- 'aid' => $value['aid'],
- 'stock_count' => Db::raw('stock_count-' . ($value['quantity'])),
- 'sales_num' => Db::raw('sales_num+' . ($value['quantity'])),
- 'sales_all' => Db::raw('sales_all+' . ($value['quantity'])),
- ];
- }
- } else {
- if ($value['order_source'] != 20){
-
- $ArcUpData[] = [
- 'aid' => $value['aid'],
- 'stock_count' => Db::raw('stock_count-' . ($value['quantity'])),
- 'sales_num' => Db::raw('sales_num+' . ($value['quantity'])),
- 'sales_all' => Db::raw('sales_all+' . ($value['quantity'])),
- ];
- }
- }
-
- if (!empty($value['order_source']) && $value['order_source'] == 20){
- $SharpUpData = [
- 'aid' => $value['aid'],
- 'seckill_stock' => Db::raw('seckill_stock-' . ($value['quantity'])),
- 'sales' => Db::raw('sales+' . ($value['quantity']))
- ];
- Db::name('sharp_goods')->where('aid',$value['aid'])->update($SharpUpData);
- Db::name('sharp_active_goods')
- ->where(['active_time_id'=>$value['order_source_id'],'aid'=> $value['aid']])
- ->update(['sales_actual'=>Db::raw('sales_actual+' . ($value['quantity']))]);
- }
- }
-
-
- if (!empty($SpecUpData)) {
- $ProductSpecValueModel = new \app\user\model\ProductSpecValue();
- $ProductSpecValueModel->saveAll($SpecUpData);
- }
-
-
- if (!empty($ArcUpData)) {
- $ArchivesModel = new \app\user\model\Archives();
- $ArchivesModel->saveAll($ArcUpData);
- }
- }
- }
-
-
- private function GetBuyOrderList($CacheData = [], $users_id = null, $post = [])
- {
- $list = [];
- if (!empty($CacheData)) {
-
- $where['a.aid'] = $CacheData['product_id'];
- if (!empty($CacheData['spec_value_id'])) $where['b.spec_value_id'] = $CacheData['spec_value_id'];
- $field = 'a.aid, a.typeid, a.title, a.litpic, a.users_price, a.users_discount_type, a.stock_count, a.prom_type, a.attrlist_id, a.logistics_type, b.value_id, b.aid as product_id, b.spec_value_id, b.spec_price, b.spec_stock';
- if ('v1.5.1' < getVersion()) {
- $field .= ',b.seckill_price, b.seckill_stock';
- }
- if ('v1.5.7' < getVersion()) {
- $field .= ',b.discount_price, b.discount_stock';
- }
- $list = Db::name('archives')->alias('a')->field($field)
- ->join('__PRODUCT_SPEC_VALUE__ b', 'a.aid = b.aid', 'LEFT')
- ->where($where)
- ->limit('0, 1')
- ->select();
- $list[0]['product_num'] = $CacheData['product_num'];
- if (isset($CacheData['active_time_id']) && !empty($CacheData['active_time_id'])){
- $list[0]['active_time_id'] = $CacheData['active_time_id'];
-
- $hour = date('H');
- $date = strtotime(date('Y-m-d'));
- $active_time = Db::name('sharp_active_time')
- ->alias('a')
- ->join('sharp_active b','a.active_id = b.active_id')
- ->where('b.active_date',$date)
- ->where('a.active_time',$hour)
- ->getField('active_time_id');
- if (empty($active_time) || $CacheData['active_time_id'] != $active_time){
- if (empty($list)) $this->error('秒杀活动已结束!');
- }
-
- $is_sku = Db::name('sharp_active_goods')
- ->alias('a')
- ->join('sharp_goods b','a.aid = b.aid')
- ->where('a.aid',$CacheData['product_id'])
- ->where('a.active_time_id',$CacheData['active_time_id'])
- ->getField('b.is_sku');
- $list[0]['is_sku'] = $is_sku;
- if (empty($is_sku)){
-
- $active_goods = Db::name('sharp_goods')->where('aid',$CacheData['product_id'])->field('seckill_price,seckill_stock')->find();
- if (!empty($active_goods)){
- $list[0]['users_price'] = $list[0]['seckill_price'] = $active_goods['seckill_price'];
- $list[0]['stock_count'] = $list[0]['seckill_stock'] = $active_goods['seckill_stock'];
- }
- }
- }elseif (isset($CacheData['discount_active_id']) && !empty($CacheData['discount_active_id'])){
- $list[0]['discount_active_id'] = $CacheData['discount_active_id'];
- $end_date = Db::name('discount_active')->where('active_id',$CacheData['discount_active_id'])->value('end_date');
- if ($end_date < getTime()){
- if (empty($list)) $this->error('活动已结束!');
- }
-
- $discount_goods = Db::name('discount_active_goods')
- ->alias('a')
- ->field('b.is_sku,b.discount_price,b.discount_stock')
- ->join('discount_goods b','a.aid = b.aid')
- ->where('a.aid',$CacheData['product_id'])
- ->where('a.active_id',$CacheData['discount_active_id'])
- ->find();
- $list[0]['is_sku'] = $discount_goods['is_sku'];
- if (empty($discount_goods['is_sku'])){
-
- $list[0]['users_price'] = $list[0]['discount_price'] = $discount_goods['discount_price'];
- $list[0]['stock_count'] = $list[0]['discount_stock'] = $discount_goods['discount_stock'];
- }
- }
- } else {
-
- $where = [
- 'a.users_id' => $users_id,
- 'a.lang' => get_home_lang(),
- 'a.selected' => 1,
- ];
- $list = Db::name('shop_cart')->field('a.*,b.typeid, b.aid, b.title, b.litpic, b.users_price, b.users_discount_type, b.stock_count, b.prom_type, b.attrlist_id, b.logistics_type, c.spec_price, c.spec_stock, c.value_id')
- ->alias('a')
- ->join('__ARCHIVES__ b', 'a.product_id = b.aid', 'LEFT')
- ->join('__PRODUCT_SPEC_VALUE__ c', 'a.spec_value_id = c.spec_value_id and a.product_id = c.aid', 'LEFT')
- ->where($where)
- ->select();
- $logistics_type_arr = get_arr_column($list,'logistics_type');
- if (empty($post['deliveryShow']) && empty($post['verifyShow']) && in_array(1,$logistics_type_arr)){
- $post['deliveryShow'] = 1;
- }
- foreach ($list as $key => $value) {
-
- if (!empty($post['verifyShow']) && 1 === intval($post['verifyShow'])) {
- if ('1' === $value['logistics_type']) unset($list[$key]);
- }
-
- else if (!empty($post['deliveryShow']) && 1 === intval($post['deliveryShow'])) {
- if ('2' === $value['logistics_type']) unset($list[$key]);
- }
- }
- }
-
- return $list;
- }
-
-
- private function OrderProductProcess($list = [], $ConfigData = [], $users_discount = 1, $level_id = 0)
- {
- foreach ($list as $key => $value) {
-
- $list[$key]['product_spec_list'] = !empty($value['spec_value_id']) ? model('ShopPublicHandle')->getGoodsSpecList($value) : [];
-
-
- if (!isset($ConfigData['shop_open_spec']) || empty($ConfigData['shop_open_spec'])) {
- $value['spec_value_id'] = $value['spec_price'] = $value['spec_stock'] = 0;
- $list[$key]['spec_value_id'] = $list[$key]['spec_price'] = $list[$key]['spec_stock'] = 0;
- }
-
-
-
- if (!empty($value['spec_value_id']) && 'undefined' != $value['spec_value_id'] && $value['spec_price'] >= 0) {
-
- $list[$key]['users_price'] = $value['users_price'] = $value['spec_price'];
- }
-
-
-
- $list[$key]['old_price'] = unifyPriceHandle($list[$key]['users_price']);
-
-
-
- if (!empty($users_discount) && 0 === intval($value['users_discount_type'])) {
-
- $list[$key]['users_price'] = unifyPriceHandle($value['users_price'] * $users_discount);
- }
-
- $list[$key]['discount_end_date'] = 0;
-
- if (!empty($value['discount_active_id'])) {
- if (empty($value['discount_price'])){
- $value['discount_price'] = Db::name('discount_goods')->where('aid',$value['aid'])->value('discount_price');
- }
- $list[$key]['users_price'] = $value['spec_price'] = $value['discount_price'];
- $list[$key]['discount_end_date'] = Db::name('discount_active')->where('active_id',$value['discount_active_id'])->value('end_date');
- }
-
-
-
- if (!empty($value['spec_stock'])) {
-
- $list[$key]['stock_count'] = $value['stock_count'] = $value['spec_stock'];
- }
- if ($value['product_num'] > $value['stock_count']) {
-
- $list[$key]['stock_count'] = $list[$key]['product_num'] = $value['stock_count'];
- }
-
-
-
- $list[$key]['litpic'] = $this->get_default_pic($value['litpic'], true);
-
-
- if (empty($list[$key]['product_spec']) && 1 === intval($value['users_discount_type']) && !empty($level_id)) {
- $list[$key]['users_price'] = model('ShopPublicHandle')->handleUsersDiscountPrice($value['aid'], $level_id);
- }
-
-
- if (empty($value['stock_count'])) {
- unset($list[$key]);
- continue;
- }
-
- }
-
- return $list;
- }
-
-
- private function GetGlobalInfo($ConfigData = [], $CacheData = [])
- {
- $GlobalInfo = [
-
- 'shop_prompt' => !empty($ConfigData['shop_prompt']) ? $ConfigData['shop_prompt'] : '',
-
- 'shop_open_offline' => !empty($ConfigData['shop_open_offline']) ? $ConfigData['shop_open_offline'] : 0,
-
- 'shop_open_shipping' => !empty($ConfigData['shop_open_shipping']) ? $ConfigData['shop_open_shipping'] : 0,
-
- 'TotalAmount' => 0,
-
- 'PayTotalAmount' => 0,
-
- 'TotalNumber' => 0,
-
- 'submit_order_type' => !empty($CacheData) ? 1 : 0,
-
- 'PromType' => 1,
-
- 'virtual_text1' => '1、该产品为虚拟产品,仅支持在线支付且无需选择收货地址及运费计算。',
- 'virtual_text2' => '2、若产品是充值类产品,请将您的手机号或需充值的卡号填入留言中。',
-
- 'onlyVerify' => false,
-
- 'onlyDelivery' => false,
-
- 'allLogisticsType' => false,
-
- ];
-
- return $GlobalInfo;
- }
-
-
- private function GetUsersAddrData($post = [], $PromType = 0)
- {
- $AddrData = [];
- if (0 == $PromType) {
-
- $AddrWhere = [
- 'addr_id' => $post['addr_id'],
- 'users_id' => $post['users_id'],
- 'lang' => get_home_lang()
- ];
- $AddressData = Db::name('shop_address')->where($AddrWhere)->find();
- if (empty($AddressData)) $this->error('收货地址不存在!');
-
- $shop_open_shipping = getUsersConfigData('shop.shop_open_shipping');
- $template_money = '0.00';
- if (!empty($shop_open_shipping)) {
-
- $where['province_id'] = $AddressData['province'];
- $template_money = Db::name('shop_shipping_template')->where($where)->getField('template_money');
- if (0 == $template_money) {
-
- $where['province_id'] = 100000;
- $template_money = Db::name('shop_shipping_template')->where($where)->getField('template_money');
- }
- }
- }
-
-
- $AddrData = [
- 'consignee' => !empty($AddressData['consignee']) ? $AddressData['consignee'] : '',
- 'country' => !empty($AddressData['country']) ? $AddressData['country'] : '',
- 'province' => !empty($AddressData['province']) ? $AddressData['province'] : '',
- 'city' => !empty($AddressData['city']) ? $AddressData['city'] : '',
- 'district' => !empty($AddressData['district']) ? $AddressData['district'] : '',
- 'address' => !empty($AddressData['address']) ? $AddressData['address'] : '',
- 'mobile' => !empty($AddressData['mobile']) ? $AddressData['mobile'] : '',
- 'shipping_fee' => !empty($template_money) ? $template_money : 0,
- ];
-
- return $AddrData;
- }
-
-
- private function ProductAttrProcessing($value = array())
- {
- $attr_value = '';
- $AttrWhere = [
- 'a.aid' => $value['aid'],
- 'b.lang' => get_home_lang()
- ];
- $attrData = Db::name('product_attr')
- ->alias('a')
- ->field('a.attr_value as value, b.attr_name as name')
- ->join('__PRODUCT_ATTRIBUTE__ b', 'a.attr_id = b.attr_id', 'LEFT')
- ->where($AttrWhere)
- ->order('b.sort_order asc, a.attr_id asc')
- ->select();
- foreach ($attrData as $val) {
- $attr_value .= $val['name'] . ':' . $val['value'] . '<br/>';
- }
- return $attr_value;
- }
-
-
- private function ProductNewAttrProcessing($value = array())
- {
- $attr_value = '';
- $where = [
- 'a.list_id' => $value['attrlist_id'],
- 'a.status' => 1,
- 'b.aid' => $value['aid']
- ];
- $attrData = Db::name('shop_product_attribute')
- ->alias('a')
- ->field('a.attr_name as name, b.attr_value as value')
- ->join('__SHOP_PRODUCT_ATTR__ b', 'a.attr_id = b.attr_id', 'LEFT')
- ->where($where)
- ->order('a.sort_order asc, a.attr_id asc')
- ->select();
- foreach ($attrData as $val) {
- $attr_value .= $val['name'] . ':' . $val['value'] . '<br/>';
- }
- return $attr_value;
- }
-
-
- private function ProductSpecProcessing($value = array())
- {
- $spec_value_s = '';
- if (!empty($value['spec_value_id'])) {
- $spec_value_id = explode('_', $value['spec_value_id']);
- if (!empty($spec_value_id)) {
- $SpecWhere = [
- 'aid' => $value['aid'],
- 'lang' => get_home_lang(),
- 'spec_value_id' => ['IN', $spec_value_id],
- ];
- $ProductSpecData = Db::name("product_spec_data")->where($SpecWhere)->field('spec_name,spec_value')->select();
- foreach ($ProductSpecData as $spec_value) {
- $spec_value_s .= $spec_value['spec_name'] . ':' . $spec_value['spec_value'] . '<br/>';
- }
- }
- }
- return $spec_value_s;
- }
-
-
-
- public function IsSoldOut($post = [])
- {
- if (!empty($post['product_id'])) {
- if (!empty($post['spec_value_id'])) {
- $SpecWhere = [
- 'aid' => $post['product_id'],
- 'lang' => get_home_lang(),
- 'spec_stock' => ['>', 0],
- 'spec_value_id' => $post['spec_value_id']
- ];
- $find_field = 'spec_stock';
- if (!empty($post['active_time_id'])){
- $find_field = 'seckill_stock';
- }
- if (!empty($post['discount_active_id'])){
- $find_field = 'discount_stock';
- }
- $spec_stock = Db::name('product_spec_value')->where($SpecWhere)->getField($find_field);
- if (empty($spec_stock)) {
- $this->error('商品已售罄!');
- }
- if ($spec_stock < $post['product_num']) {
- $this->error('商品最大库存:' . $spec_stock);
- }
-
- } else {
- $ArchivesWhere = [
- 'aid' => $post['product_id'],
- 'lang' => get_home_lang(),
- 'arcrank' => ['>=', 0]
- ];
- if (!empty($post['active_time_id'])){
- $stock_count = Db::name('sharp_goods')->where('aid',$post['product_id'])->getField('seckill_stock');
- }elseif (!empty($post['discount_active_id'])){
- $stock_count = Db::name('discount_goods')->where('aid',$post['product_id'])->getField('discount_stock');
- }else{
- $stock_count = Db::name('archives')->where($ArchivesWhere)->getField('stock_count');
- }
- if (empty($stock_count)) {
- $this->error('商品已售罄!');
- }
- if ($stock_count < $post['product_num']) {
- $this->error('商品最大库存:' . $stock_count);
- }
- }
- }
- }
-
-
-
-
- public function GetAllAddressList($users = [])
- {
- $ReturnData = [];
- $list = !empty($users['address_1588820149']) ? $users['address_1588820149'] : [];
- $default_id = !empty($users['address_default_1588820149']) ? $users['address_default_1588820149']['addr_id'] : 0;
- if (!empty($list)) {
-
- foreach ($list as $key => $value) {
- $list[$key]['provinceName'] = $this->GetRegionName($value['province']);
- $list[$key]['cityName'] = $this->GetRegionName($value['city']);
- $list[$key]['districtName'] = $this->GetRegionName($value['district']);
- }
-
-
- if (empty($default_id)) {
- $default_id = $list[0]['addr_id'];
- $where = [
- 'addr_id' => $default_id,
- 'users_id' => $this->users_id
- ];
- $update = [
- 'is_default' => 1,
- 'update_time' => getTime()
- ];
- Db::name('shop_address')->where($where)->update($update);
- }
- }
-
-
- $ReturnData = [
- 'list' => $list,
- 'default_id' => $default_id
- ];
-
- $this->success('查询成功', null, $ReturnData);
- }
-
-
- public function GetFindAddrDetail($post = [], $users = [])
- {
- if (!empty($users['address_1588820149'])) {
- $ResultData['detail'] = [];
- foreach ($users['address_1588820149'] as $key => $value) {
- if ($post['addr_id'] == $value['addr_id']) {
- $ResultData['detail'] = $value;
- break;
- }
- }
- if (!empty($ResultData)) {
-
- $ProvinceName = $this->ProcessingProvince($this->GetRegionName($ResultData['detail']['province']));
- $CityName = $this->GetRegionName($ResultData['detail']['city']);
- $DistrictName = $this->GetRegionName($ResultData['detail']['district']);
-
- $region = $ProvinceName . ',' . $CityName . ',' . $DistrictName;
- $ResultData['detail']['region'] = [
- 'province' => $ProvinceName,
- 'city' => $CityName,
- 'region' => $DistrictName
- ];
- $ResultData['region'] = explode(',', $region);
-
-
-
- $ProvinceName = $this->GetRegionName($ResultData['detail']['province']);
-
- $regionNew = $ProvinceName . ',' . $CityName . ',' . $DistrictName;
- $ResultData['detail']['regionNew'] = [
- 'province' => $ProvinceName,
- 'city' => $CityName,
- 'region' => $DistrictName
- ];
- $ResultData['regionNew'] = explode(',', $regionNew);
-
- $this->success('查询成功', null, $ResultData);
- }
- }
- $this->error('数据错误');
- }
-
-
- public function FindAddAddr($post = [], $users_id = null)
- {
- if (!empty($post['name']) && !empty($post['phone']) && !empty($post['region']) && !empty($users_id)) {
-
- $AddrData = $this->GetAddrData($post['region']);
-
- $AddData = [
- 'users_id' => $users_id,
- 'consignee' => $post['name'],
- 'country' => 1,
- 'province' => $AddrData['province'],
- 'city' => $AddrData['city'],
- 'district' => $AddrData['district'],
- 'address' => $post['detail'],
- 'mobile' => $post['phone'],
- 'lang' => get_home_lang(),
- 'add_time' => getTime(),
- 'update_time' => getTime()
- ];
- $ResultID = Db::name('shop_address')->add($AddData);
- if (!empty($ResultID)) $this->success('添加成功');
- }
- $this->error('数据错误');
- }
-
-
- public function FindEditAddr($post = [], $users_id = null)
- {
- if (!empty($post['name']) && !empty($post['phone']) && !empty($post['region']) && !empty($users_id)) {
-
- $AddrData = $this->GetAddrData($post['region']);
-
- $UpData = [
- 'users_id' => $users_id,
- 'consignee' => $post['name'],
- 'country' => 1,
- 'province' => $AddrData['province'],
- 'city' => $AddrData['city'],
- 'district' => $AddrData['district'],
- 'address' => $post['detail'],
- 'mobile' => $post['phone'],
- 'update_time' => getTime()
- ];
- $ResultID = Db::name('shop_address')->where('addr_id', $post['addr_id'])->update($UpData);
- if (!empty($ResultID)) $this->success('编辑成功');
- }
- $this->error('数据错误');
- }
-
-
- public function SetDefaultAddr($post = [], $users_id = null)
- {
- if (empty($post['addr_id']) || empty($users_id)) $this->error('请刷新重试');
-
- $where = [
- 'addr_id' => $post['addr_id'],
- 'users_id' => $users_id
- ];
- $update = [
- 'is_default' => 1,
- 'update_time' => getTime()
- ];
- $ResultID = Db::name('shop_address')->where($where)->update($update);
-
- if (!empty($ResultID)) {
-
- $where = [
- 'addr_id' => ['NEQ', $post['addr_id']],
- 'users_id' => $users_id
- ];
- $update = [
- 'is_default' => 0,
- 'update_time' => getTime()
- ];
- Db::name('shop_address')->where($where)->update($update);
-
- $this->success('更新成功');
- }
- $this->error('更新失败,请刷新重试');
- }
-
-
- public function FindDelAddr($post = [], $users_id = null)
- {
- if (!empty($post['addr_id']) && !empty($users_id)) {
- $where = [
- 'users_id' => $users_id,
- 'addr_id' => $post['addr_id']
- ];
- $ResultID = Db::name('shop_address')->where($where)->delete();
- if (!empty($ResultID)) $this->success('操作成功');
- }
- $this->error('数据错误');
- }
-
-
- private function GetAddrData($region = null)
- {
- $region = explode(',', $region);
- $province = substr($region[0], 0, 6);
- $ResultData['province'] = $this->GetRegionID(1, $province);
- $ResultData['city'] = $this->GetRegionID(2, $region[1], $ResultData['province']);
- $ResultData['district'] = $this->GetRegionID(3, $region[2], $ResultData['city']);
-
- return $ResultData;
- }
-
-
- private function GetRegionID($level = 1, $name = 1, $parent_id = 0)
- {
- $old_name = $name;
-
-
- if ($level > 1 && strlen($name) >= 9) {
- $name = preg_replace('/(省|市|县|区|乡|镇)$/i', '', $name);
- }
-
- $where = [
- 'level' => $level,
- 'parent_id' => $parent_id,
- 'name' => ['LIKE', "{$name}%"],
- ];
- $id = Db::name('region')->where($where)->getField('id');
- if (empty($id) && 2 <= $level) {
- $addData = [
- 'name' => $old_name,
- 'level' => $level,
- 'parent_id' => $parent_id,
- 'initial' => getFirstCharter($old_name),
- ];
- $id = Db::name('region')->insertGetId($addData);
- }
-
- return $id;
- }
-
-
- private function GetRegionName($id = 1)
- {
- $name = Db::name('region')->where('id', $id)->getField('name');
- return $name;
- }
-
-
- private function ProcessingProvince($province = null)
- {
- if (empty($province)) return $province;
- if ('山西' == $province) {
- $province = '山西省';
- } else if ('内蒙古' == $province) {
- $province = '内蒙古自治区';
- } else if ('广西' == $province) {
- $province = '广西壮族自治区';
- } else if ('西藏' == $province) {
- $province = '西藏自治区';
- } else if ('宁夏' == $province) {
- $province = '宁夏回族自治区';
- } else if ('新疆' == $province) {
- $province = '新疆维吾尔族自治区';
- } else if ('香港' == $province) {
- $province = '香港特别行政区';
- } else if ('澳门' == $province) {
- $province = '澳门特别行政区';
- } else if ('台湾' == $province) {
- $province = '台湾省';
- }
- return $province;
- }
-
-
-
-
-
- public function getOrderCount($users, $type = 'all')
- {
- if ($users === false) {
- return false;
- }
-
- $filter = [];
-
- switch ($type) {
- case 'all':
- break;
- case 'payment';
- $filter['order_status'] = 0;
- break;
- case 'delivery';
- $filter['order_status'] = 1;
- break;
- case 'received';
- $filter['order_status'] = 2;
- break;
- case 'complete';
- $filter['order_status'] = 3;
- break;
- }
-
- $filter['users_id'] = $users['users_id'];
- $filter['lang'] = get_home_lang();
- $count = Db::name('shop_order')
- ->where($filter)
- ->count();
-
- return $count;
- }
-
-
-
- public function getOrderList($users_id = 0, $type = 'all')
- {
-
- $where = [
- 'lang' => get_home_lang(),
- 'users_id' => intval($users_id),
- ];
-
- switch ($type) {
- case 'all':
- break;
- case 'payment';
- $where['order_status'] = 0;
- break;
- case 'delivery';
- $where['order_status'] = 1;
- break;
- case 'received';
- $where['order_status'] = 2;
- break;
- case 'complete';
- $where['order_status'] = 3;
-
- break;
- case 'close';
- $where['order_status'] = -1;
- break;
- }
- $result = Db::name('shop_order')->where($where)->order('order_id desc')->paginate(15, false, ['query' => request()->param()]);
- !empty($result) && $result = $result->toArray();
- $order_ids = get_arr_column($result['data'], 'order_id');
-
-
- $orderGoods = [];
- $where = [
- 'users_id' => intval($users_id),
- 'order_id' => ['IN', $order_ids],
- ];
- $goodsList = Db::name('shop_order_details')->where($where)->order('order_id desc')->select();
-
-
- if (!empty($goodsList)) {
- $weappInfo = model('ShopPublicHandle')->getWeappPointsShop();
- if (!empty($weappInfo)) {
-
- $pointsOrderModel = new \app\plugins\model\PointsOrder();
- $pointsGoodsBuyField = $pointsOrderModel->pointsGoodsOrderDetails($goodsList);
- }
- }
-
- foreach ($goodsList as $key => $_goods) {
- $_goods['product_price'] = unifyPriceHandle($_goods['product_price']);
-
- $_goods['product_spec_list'] = model('ShopPublicHandle')->getOrderGoodsSpecList($_goods);
- $_goods['litpic'] = $this->get_default_pic($_goods['litpic'], true);
- $orderGoods[$_goods['order_id']][] = $_goods;
- }
-
-
- $channeltype_row = \think\Cache::get('extra_global_channeltype');
- $channeltypeInfo = !empty($channeltype_row[2]) ? $channeltype_row[2] : [];
- $channel_ntitle = !empty($channeltypeInfo['ntitle']) ? $channeltypeInfo['ntitle'] : '商品';
-
- $pay_method_arr = config('global.pay_method_arr');
- $order_status_arr = config('global.order_status_arr');
- foreach ($result['data'] as $key => &$_order) {
- $_order['shipping_fee'] = unifyPriceHandle($_order['shipping_fee']);
- $_order['order_amount'] = unifyPriceHandle($_order['order_amount']);
- $_order['order_total_amount'] = unifyPriceHandle($_order['order_total_amount']);
- $_order['pay_name_text'] = !empty($pay_method_arr[$_order['pay_name']]) ? $pay_method_arr[$_order['pay_name']] : '未支付';
- $_order['order_status_text'] = $order_status_arr[$_order['order_status']];
- $_order['add_time'] = MyDate('Y-m-d H:i:s', $_order['add_time']);
- $_order['goods'] = !empty($orderGoods[$_order['order_id']]) ? $orderGoods[$_order['order_id']] : [];
- $_order['channel_ntitle'] = '商品';
- $_order['pointsGoodsBuyField'] = !empty($pointsGoodsBuyField[$_order['order_id']]) ? $pointsGoodsBuyField[$_order['order_id']] : [];
- }
- return $result;
- }
-
-
- public function orderCancel($order_id, $users_id)
- {
-
- $Where = [
- 'order_id' => $order_id,
- 'users_id' => $users_id,
- ];
-
- $Data = [
- 'order_status' => -1,
- 'update_time' => getTime(),
- ];
-
- $return = Db::name('shop_order')->where($Where)->update($Data);
- if (!empty($return)) {
-
- $use_id = Db::name('shop_order')->where($Where)->value('use_id');
- if (!empty($use_id)){
- $coupon_use = Db::name('shop_coupon_use')->where(['use_id'=>$use_id])->find();
- if (!empty($coupon_use)){
- if ($coupon_use['start_time'] <= getTime() && $coupon_use['end_time'] >= getTime()){
- $use_update = ['use_status'=>0];
- }else{
- $use_update = ['use_status'=>2];
- }
- $use_update['use_time'] = 0;
- $use_update['update_time'] = getTime();
- Db::name('shop_coupon_use')->where(['use_id'=>$use_id,'users_id' => $users_id])->update($use_update);
- }
- }
-
-
- $order_info = Db::name('shop_order')->where($Where)->find();
- $productSpecValue = new \app\user\model\ProductSpecValue;
- if (20 == $order_info['order_source']){
- $productSpecValue->SaveSharpStock($order_id, $users_id,$order_info);
- }else{
-
- $productSpecValue->SaveProducSpecValueStock($order_id, $users_id);
- }
-
-
- if (is_dir('./weapp/Seckill/')) {
- $SeckillRow = model('Weapp')->getWeappList('Seckill');
-
- if (!empty($SeckillRow) && 1 == intval($SeckillRow['status']) && !empty($order['is_seckill_order'])) {
-
- $weappSeckillLogic = new \weapp\Seckill\logic\SeckillLogic;
- $weappSeckillLogic->cancelOrderHandle($order_id, $users_id);
- }
- }
-
- AddOrderAction($order_id, $users_id, 0, 0, 0, 0, '订单取消!', '会员关闭订单!');
- $this->success('订单取消成功!');
- }
- }
-
-
- public function orderRemind($order_id = 0, $users_id = 0)
- {
- $post = input('post.');
-
- AddOrderAction($order_id, $users_id, 0, 1, 0, 1, '提醒成功!', '会员提醒管理员及时发货!');
- $this->success('提醒成功');
- }
-
-
- public function orderReceipt($order_id, $users_id)
- {
-
- $where = [
- 'order_id' => $order_id,
- 'users_id' => $users_id,
- ];
- $order = Db::name('shop_order')->where($where)->find();
- $orderStatus = empty($order['order_status']) ? 0 : intval($order['order_status']);
- if (2 === intval($orderStatus)) {
-
- $update = [
- 'order_status' => 3,
- 'confirm_time' => getTime(),
- 'update_time' => getTime(),
- ];
-
- $return = Db::name('shop_order')->where($where)->update($update);
- if (!empty($return)) {
-
- $update = [
- 'update_time' => getTime(),
- ];
-
- Db::name('shop_order_details')->where($where)->update($update);
-
-
- AddOrderAction($order_id, $users_id, 0, 3, 1, 1, '确认收货!', '会员已确认收到货物,订单完成!');
-
-
- if (is_dir('./weapp/DealerPlugin/')) {
-
- $data = model('Weapp')->getWeappList('DealerPlugin');
- if (!empty($data['status']) && 1 == $data['status']) {
-
- $dealerCommonLogic = new \weapp\DealerPlugin\logic\DealerCommonLogic;
- $dealerCommonLogic->dealerOrderSettlementExecute($order_id, $users_id);
- }
- }
-
-
- if (is_dir('./weapp/Seckill/')) {
- $SeckillRow = model('Weapp')->getWeappList('Seckill');
-
- if (!empty($SeckillRow) && 1 == intval($SeckillRow['status']) && !empty($order['is_seckill_order'])) {
-
- $weappSeckillLogic = new \weapp\Seckill\logic\SeckillLogic;
- $weappSeckillLogic->confirmOrderHandle($order_id, $users_id);
- }
- }
- $this->success('确认收货成功');
- } else {
- $this->error('101:订单异常,请刷新重试');
- }
- } else {
- $this->error('102:订单异常,请刷新重试');
- }
- }
-
-
-
- public function getOrderDetail($order_id, $users_id)
- {
-
- $Where = [
- 'order_id' => $order_id,
- 'users_id' => $users_id,
- ];
-
- $result = Db::name("shop_order")->where($Where)->find();
- if (empty($result)) {
- $this->error('订单不存在!');
- }
-
-
- $result['coupon_price'] = unifyPriceHandle($result['coupon_price']);
- $result['shipping_fee'] = unifyPriceHandle($result['shipping_fee']);
- $result['order_amount'] = unifyPriceHandle($result['order_amount']);
- $result['order_total_amount'] = unifyPriceHandle($result['order_total_amount']);
-
- $channeltype_row = \think\Cache::get('extra_global_channeltype');
- $channeltypeInfo = !empty($channeltype_row[2]) ? $channeltype_row[2] : [];
- $result['channel_ntitle'] = '商品';
-
- $order_status_arr = config('global.order_status_arr');
- $result['order_status_text'] = $order_status_arr[$result['order_status']];
-
- $pay_method_arr = config('global.pay_method_arr');
- $result['pay_name_text'] = !empty($pay_method_arr[$result['pay_name']]) ? $pay_method_arr[$result['pay_name']] : '未支付';
-
- $result['province_text'] = $this->GetRegionName($result['province'], 1);
- $result['city_text'] = $this->GetRegionName($result['city'], 2);
- $result['district_text'] = $this->GetRegionName($result['district'], 3);
-
- $result['add_time'] = MyDate('Y-m-d H:i:s', $result['add_time']);
-
- $result['TotalAmount'] = 0.00;
-
- $result['goods'] = Db::name("shop_order_details")->order('product_price desc, product_name desc')->where($Where)->select();
-
- $result['orderLog'] = Db::name('shop_order_log')->where('order_id', $order_id)->order('action_id desc')->select();
- foreach ($result['orderLog'] as $key => $value) {
- $result['orderLog'][$key]['add_time'] = MyDate('Y-m-d H:i:s', $value['add_time']);
- }
-
-
- $result['pointsGoodsBuyField'] = [];
- if (!empty($result['goods'])) {
- $weappInfo = model('ShopPublicHandle')->getWeappPointsShop();
- if (!empty($weappInfo)) {
-
- $pointsOrderModel = new \app\plugins\model\PointsOrder();
- $pointsGoodsBuyField = $pointsOrderModel->pointsGoodsOrderDetails($result['goods']);
- $result['pointsGoodsBuyField'] = !empty($pointsGoodsBuyField[$result['order_id']]) ? $pointsGoodsBuyField[$result['order_id']] : [];
- }
- }
-
-
- $result['verify'] = [];
- if (!empty($result['verify_id'])) {
- $weappInfo = model('ShopPublicHandle')->getWeappVerifyInfo();
- if (!empty($weappInfo)) {
-
- $verifyModel = new \app\plugins\model\Verify();
- $result['verify'] = $verifyModel->verifyOrderDetails($result);
- }
- }
-
-
- $virtual_delivery = '';
-
- $virtual_delivery_status = false;
-
- foreach ($result['goods'] as $key => $value) {
- $result['prom_type'] = $value['prom_type'];
- $result['goods'][$key]['product_price'] = unifyPriceHandle($value['product_price']);
- $result['goods'][$key]['product_spec_list'] = model('ShopPublicHandle')->getOrderGoodsSpecList($value);
-
-
- if ($value['prom_type'] == 2 && 2 <= intval($result['order_status'])) {
- $virtual_delivery_status = true;
-
-
-
- $netdisk = Db::name("product_netdisk")->where('aid', $value['product_id'])->find();
- if ($netdisk) {
-
- $virtual_delivery .= "网盘地址:" . $netdisk['netdisk_url'] . "";
- if (!empty($netdisk['netdisk_pwd'])) {
- $virtual_delivery .= "提取码:" . $netdisk['netdisk_pwd'] . "";
- }
- if (!empty($netdisk['unzip_pwd'])) {
- $virtual_delivery .= "解压密码:" . $netdisk['unzip_pwd'] . "";
- }
- $virtual_delivery .= "--------------------";
- }
- $result['netdisk'] = $netdisk;
- } else if ($value['prom_type'] == 3 && 2 <= intval($result['order_status'])) {
- $virtual_delivery_status = true;
-
-
-
- $netdisk = Db::name("product_netdisk")->where('aid', $value['product_id'])->find();
- if ($netdisk) {
-
- $virtual_delivery .= "文本内容:" . $netdisk['text_content'] . "";
- $virtual_delivery .= "--------------------";
- }
- $result['netdisk'] = $netdisk;
- } else if ($value['prom_type'] == 1) {
- $virtual_delivery_status = true;
-
- if (!empty($result['virtual_delivery'])) {
-
-
- $virtual_delivery .= filter_line_return($result['virtual_delivery'], '') . "";
- $virtual_delivery .= "--------------------";
- }
- }
- $result['virtual_delivery_status'] = $virtual_delivery_status;
- if ($virtual_delivery_status && !empty($virtual_delivery)) $result['virtual_delivery'] = $virtual_delivery;
-
-
- $ValueData = unserialize($value['data']);
- $spec_value = !empty($ValueData['spec_value']) ? htmlspecialchars_decode($ValueData['spec_value']) : '';
- $spec_value = !empty($spec_value) ? htmlspecialchars_decode($spec_value) : '';
-
-
-
-
-
-
- $result['goods'][$key]['data'] = trim(str_replace('<br/>', ';', $spec_value), ';');
-
-
-
-
-
-
- $result['goods'][$key]['new_data'] = trim(str_replace('<br/>', ';', $spec_value), ';');
-
-
- $result['goods'][$key]['litpic'] = $this->get_default_pic($value['litpic'], true);
-
- $result['goods'][$key]['subtotal'] = $value['product_price'] * $value['num'];
- $result['goods'][$key]['subtotal'] = unifyPriceHandle($result['goods'][$key]['subtotal']);
-
- $result['TotalAmount'] += $result['goods'][$key]['subtotal'];
- $result['TotalAmount'] = unifyPriceHandle($result['TotalAmount']);
- }
-
- $orderUnpayCloseTime = getUsersConfigData('order.order_unpay_close_time');
- $result['orderUnpayCloseTime'] = !empty($orderUnpayCloseTime) ? intval($orderUnpayCloseTime) / 60 : 0;
-
- return $result;
- }
-
-
-
- public function getOrderComment($order_id, $users_id)
- {
-
- $comment_count = Db::name('shop_order_comment')->where(['order_id' => $order_id, 'users_id' => $users_id, 'lang' => get_home_lang()])->count();
- if (!empty($comment_count)) {
- $this->error('该订单已经评价!');
- }
- $order_data = $this->getOrderDetail($order_id, $users_id);
-
- return $order_data['goods'];
- }
-
- public function getSaveComment($post, $users_id)
- {
- $order_id = intval($post['order_id']);
-
- $comment_count = Db::name('shop_order_comment')->where(['order_id' => $order_id, 'users_id' => $users_id])->count();
- if (!empty($comment_count)) {
- $this->error('该订单已经评价!');
- }
-
- if (!empty($post['formData'])) {
- $post['formData'] = json_decode(htmlspecialchars_decode($post['formData']), true);
- $insert = [];
- $detail_ids = [];
- $order_code = Db::name('shop_order')->where(['order_id'=>$order_id])->value('order_code');
- foreach ($post['formData'] as $k => $v) {
- $detail_ids[] = $v['order_details_id'];
- $uploadImg = '';
- if (!empty($v['uploaded'])) {
- $uploadImg = implode(',', $v['uploaded']);
- } else if (!empty($v['image_list'])) {
- $uploadImg = implode(',', $v['image_list']);
- }
- $insert[] = [
- 'upload_img' => serialize($uploadImg),
- 'total_score' => $v['score'],
- 'content' => serialize($v['content']),
- 'users_id' => $users_id,
- 'order_id' => $order_id,
- 'order_code' => $order_code,
- 'product_id' => $v['goods_id'],
- 'details_id' => $v['order_details_id'],
- 'add_time' => getTime(),
- 'update_time' => getTime(),
- ];
- }
- $insert_data = Db::name('shop_order_comment')->insertAll($insert);
- if ($insert_data) {
- Db::name('shop_order')
- ->where([
- 'order_id' => $order_id,
- 'users_id' => $users_id,
- 'order_status' => 3,
- ])
- ->update(['is_comment' => 1, 'update_time' => getTime()]);
-
- if (!empty($detail_ids)) {
- Db::name('shop_order_details')
- ->where('details_id', 'in', $detail_ids)
- ->where('users_id', $users_id)
- ->update(['is_comment' => 1, 'update_time' => getTime()]);
- }
- \think\Cache::clear('archives');
-
- $this->success('评价成功!');
- }
- }
- $this->error('评价失败!');
- }
-
-
-
- public function getGoodsCommentList($goods_id = 0 ,$score = 0 ,$page = 1 )
- {
- $field='a.*,u.nickname,u.head_pic';
-
- $condition = [
- 'a.product_id' => $goods_id,
- 'a.is_show' => 1,
- 'a.lang' => get_home_lang(),
- ];
- $score > 0 && $condition['total_score'] = $score;
-
- $pagesize = empty($pagesize) ? config('paginate.list_rows') : $pagesize;
- $cacheKey = 'api-'.md5(__CLASS__.__FUNCTION__.json_encode(func_get_args()));
- $result = cache($cacheKey);
- if (true || empty($result)) {
- $paginate = array(
- 'page' => $page,
- );
- $pages = Db::name('shop_order_comment')
- ->field($field)
- ->alias('a')
- ->join('users u','a.users_id = u.users_id')
- ->where($condition)
- ->order('a.add_time desc')
- ->paginate($pagesize, false, $paginate);
-
- $result = $pages->toArray();
-
- foreach ($result['data'] as $key => $val) {
- if ($val['is_anonymous'] == 1){
-
- $val['head_pic'] = get_head_pic();
- $val['nickname'] = '匿名用户';
- }else{
- if (empty($val['head_pic'])){
- $val['head_pic'] = get_head_pic();
- }
- }
- $val['head_pic'] = get_default_pic($val['head_pic'],true);
-
- if (isset($val['add_time'])) {
- $val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
- }
- if (!empty($val['upload_img'])){
- $val['upload_img'] = unserialize($val['upload_img']);
- $val['upload_img'] = explode(',',$val['upload_img']);
- foreach ($val['upload_img'] as $k => $v){
- $val['upload_img'][$k] = get_default_pic($v,true);
- }
- }
- if (!empty($val['content'])){
- $val['content'] = unserialize($val['content']);
- }
- $result['data'][$key] = $val;
- }
- $score_type = Db::name('shop_order_comment')
- ->where([
- 'product_id' => $goods_id,
- 'is_show' => 1,
- 'lang' => get_home_lang(),
- ])->field('count(*) as count,total_score')
- ->group('total_score')
- ->getAllWithIndex('total_score');
- $result['count']['goods'] = isset($score_type[1]) ? $score_type[1]['count'] : 0;
- $result['count']['middle'] = isset($score_type[2]) ? $score_type[2]['count'] : 0;
- $result['count']['bad'] = isset($score_type[3]) ? $score_type[3]['count'] : 0;
- $result['count']['all'] = $result['count']['goods']+$result['count']['middle']+$result['count']['bad'] ;
-
- cache($cacheKey, $result, null, 'getGoodsCommentList');
- }
- return $result;
- }
-
-
-
- public function GetSharpTabbar()
- {
- $time = strtotime(date('Y-m-d'));
- $hour = date('H');
- $where['b.status'] = 1;
- $where['a.status'] = 1;
- $where['b.is_del'] = 0;
-
- $active = Db::name('sharp_active_time')
- ->alias('a')
- ->field('a.*,b.active_date')
- ->join('sharp_active b','a.active_id = b.active_id')
- ->where($where)
- ->where('b.active_date', '>',$time)
- ->order('b.active_date asc,a.active_time asc')
- ->select();
-
- $data = Db::name('sharp_active_time')
- ->alias('a')
- ->field('a.*,b.active_date')
- ->join('sharp_active b','a.active_id = b.active_id')
- ->where($where)
- ->where('b.active_date', $time)
- ->where('a.active_time', '>=',$hour)
- ->order('active_time asc')
- ->select();
- if (!empty($data) && !empty($active)){
- $data[] = $active[0];
- }else if (empty($data) && !empty($active)){
- $data[] = $active;
- }
- $date = date('Y-m-d');
- foreach ($data as $k => $v){
- if ($v['active_time'] < 10){
- $v['active_time'] = '0'.$v['active_time'];
- }
- $active_time = $v['active_time'];
- $v['active_time'] = $v['active_time'].':00';
- $date_time = $date.' '.$v['active_time'];
- $time_plus = strtotime($date_time . "+1 hours");
- $time_plus = date('Y-m-d H:i',$time_plus);
- if ($time == $v['active_date']){
- if ($active_time == $hour){
- $v['status'] = 10;
- $arr = ['正在疯抢','已开抢','正在疯抢',$time_plus,$time_plus,$date_time];
- }else if ($active_time > $hour){
- $v['status'] = 20;
- $arr = [$v['active_time'].' 场预告','即将开抢','即将开抢',$date_time,$time_plus,$date_time];
- }
- }else{
- $v['status'] = 30;
- $arr = [$date_time.' 开始','预告',$date_time.' 开始',$date_time,$time_plus,$date_time];
- }
- $v['sharp_modular_text'] = $arr[0];
- $v['status_text'] = $arr[1];
- $v['status_text2'] = $arr[2];
- $v['count_down_time'] = $arr[3];
- $v['end_time'] = $arr[4];
- $v['start_time'] = $arr[5];
- $data[$k] = $v;
- }
- return $data;
- }
-
-
-
- public function GetSharpIndex( $tid = 0 , $page = 1 )
- {
- $pagesize = 10;
- $pagesize = empty($pagesize) ? config('paginate.list_rows') : $pagesize;
- $cacheKey = 'api-'.md5(__CLASS__.__FUNCTION__.json_encode(func_get_args()));
- $result = cache($cacheKey);
- if (true || empty($result)) {
- $paginate = array(
- 'page' => $page,
- );
- $pages = Db::name('sharp_active_goods')
- ->alias('a')
- ->field('c.*,b.litpic,b.title,a.*,b.users_price')
- ->join('archives b','a.aid = b.aid')
- ->join('sharp_goods c','a.sharp_goods_id = c.sharp_goods_id')
- ->where('a.active_time_id',$tid)
- ->paginate($pagesize, false, $paginate);
-
- $result = $pages->toArray();
-
- $aids = [];
- foreach ($result['data'] as $k => $v){
- $result['data'][$k]['litpic'] = get_default_pic($v['litpic'],true);
- if (1 == $v['is_sku']){
- $aids[] = $v['aid'];
- }
- }
-
-
- if (!empty($aids)) {
- $sku = Db::name('product_spec_value')
- ->field('*,min(seckill_price) as seckill_price')
- ->where('aid', 'in', $aids)
- ->group('aid')
- ->getAllWithIndex('aid');
- }
-
- foreach ($result['data'] as $k => $v){
- if (1 == $v['is_sku'] && !empty($sku[$v['aid']])){
- $v['seckill_price'] = $sku[$v['aid']]['seckill_price'];
- }
- $v['progress'] = 0;
- if (0 < $v['sales_actual']){
- $count_stock = $v['sales_actual']+$v['seckill_stock']+$v['virtual_sales'];
- $v['progress'] = intval(($v['sales_actual']+$v['virtual_sales'])/$count_stock*100);
- }else{
- if (0 < $v['virtual_sales']){
- $v['progress'] = intval($v['virtual_sales']/($v['virtual_sales']+$v['seckill_stock'])*100);;
- }
- }
- if (0 < $v['virtual_sales']){
- $v['sales_actual'] = $v['sales_actual'] +$v['virtual_sales'];
-
- }
- $result['data'][$k] = $v;
- }
-
- cache($cacheKey, $result, null, 'GetSharpIndex');
- }
- return $result;
- }
-
-
-
- public function orderExpress($express_name, $express_code, $express_order, $timestamp = '')
- {
- $data = [
- 'express_name' => $express_name,
- 'express_order' => $express_order
- ];
-
- $data['list'] = $this->orderExpressQuery($express_code, $express_order);
- if ($data['list'] === false) {
- $this->error('没有找到物流信息!');
- return false;
- }
- return $data;
- }
-
-
-
- private function orderExpressQuery($express_code, $express_order)
- {
-
- $cacheKey = 'api-'.md5(__CLASS__.__FUNCTION__.json_encode(func_get_args()));
- if ($data = Cache::get($cacheKey)) {
- return $data;
- }
-
-
- empty($timestamp) && $timestamp = getTime();
-
- $postData = [
- 'postid' => $express_order,
- 'id' => 1,
- 'valicode' => '',
- 'temp' => $timestamp,
- 'type' => $express_code,
- 'phone' => '',
- 'token' => '',
- 'platform' => 'MWWW',
- 'coname' => 'indexall',
- ];
- $expressUrl = "https://m.kuaidi100.com/query";
- $response = httpRequest($expressUrl, 'POST', $postData);
- $express = json_decode($response, true);
-
- if (!isset($express['message']) || $express['message'] != 'ok') {
- $msg = '查询失败';
- $this->error($msg);
- return false;
- }
-
-
-
-
-
-
-
- Cache::set($cacheKey, $express['data'], 300);
- return $express['data'];
- }
-
-
-
- private function orderExpressQuery2($express_code, $express_order)
- {
-
- $cacheKey = 'api-'.md5(__CLASS__.__FUNCTION__.json_encode(func_get_args()));
- if ($data = Cache::get($cacheKey)) {
- return $data;
- }
-
- $key = 'anFrVFyu8015';
- $customer = 'B972EB01B5B32404957BE09C8FE85A51';
-
- $postData = [
- 'customer' => $customer,
- 'param' => json_encode([
- 'resultv2' => '1',
- 'com' => $express_code,
- 'num' => $express_order
- ])
- ];
- $postData['sign'] = strtoupper(md5($postData['param'] . $key . $postData['customer']));
-
- $url = 'http://poll.kuaidi100.com/poll/query.do';
- $result = httpRequest($url, 'POST', $postData);
- $express = json_decode($result, true);
-
- if (isset($express['returnCode']) || !isset($express['data'])) {
- $msg = isset($express['message']) ? $express['message'] : '查询失败';
- $this->error($msg);
- return false;
- }
-
- Cache::set($cacheKey, $express['data'], 300);
- return $express['data'];
- }
-
-
-
- public function onOrderPayment($users, $order, $payType = 20)
- {
- if ($payType == 20) {
- return $this->onPaymentByWechat($users, $order);
- }
- return [];
- }
-
-
-
- protected function onPaymentByWechat($users, $order)
- {
-
- if (empty($this->miniproInfo['mchid']) || empty($this->miniproInfo['apikey'])) {
- return [
- 'code' => 0,
- 'msg' => '很抱歉,请在网站小程序后台,完善微信支付配置!',
- ];
- }
- $openid = Db::name('weapp_diyminipro_mall_users')->where(['users_id' => $users['users_id']])->getField('openid');
- $payment = $this->unifiedorder($order['order_code'], $openid, $order['order_amount']);
-
- return $payment;
- }
-
-
-
- public function unifiedorder($order_code, $openid, $totalFee)
- {
-
- $time = getTime();
-
- $nonceStr = md5($time . $openid);
-
-
- $params = [
- 'appid' => $this->miniproInfo['appid'],
- 'attach' => '微信小程序支付',
- 'body' => $order_code,
- 'mch_id' => $this->miniproInfo['mchid'],
- 'nonce_str' => $nonceStr,
- 'notify_url' => url('api/v1/Api/wxpay_notify', [], true, true, 1, 1),
- 'openid' => $openid,
- 'out_trade_no' => $order_code,
- 'spbill_create_ip' => clientIP(),
- 'total_fee' => $totalFee * 100,
- 'trade_type' => 'JSAPI',
- ];
-
- $params['sign'] = model('v1.User')->makeSign($params, $this->miniproInfo['apikey']);
-
- $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
- $result = httpRequest($url, 'POST', model('v1.User')->toXml($params));
- $prepay = model('v1.User')->fromXml($result);
-
- if ($prepay['return_code'] === 'FAIL') {
- return [
- 'code' => 0,
- 'msg' => "微信支付api:{$prepay['return_msg']}",
- ];
- }
- if ($prepay['result_code'] === 'FAIL') {
- return [
- 'code' => 0,
- 'msg' => "微信支付api:{$prepay['err_code_des']}",
- ];
- }
-
- $paySign = $this->makePaySign($this->miniproInfo['appid'], $params['nonce_str'], $prepay['prepay_id'], $time);
- return [
- 'prepay_id' => $prepay['prepay_id'],
- 'nonceStr' => $nonceStr,
- 'timeStamp' => (string)$time,
- 'paySign' => $paySign
- ];
- }
-
-
-
- private function makePaySign($appid, $nonceStr, $prepay_id, $timeStamp)
- {
- $data = [
- 'appId' => $appid,
- 'nonceStr' => $nonceStr,
- 'package' => 'prepay_id=' . $prepay_id,
- 'signType' => 'MD5',
- 'timeStamp' => $timeStamp,
- ];
-
- ksort($data);
- $string = model('v1.User')->toUrlParams($data);
-
- $string = $string . '&key=' . $this->miniproInfo['apikey'];
-
- $string = md5($string);
-
- $result = strtoupper($string);
- return $result;
- }
-
-
-
- public function GetMyCouponList($users_id, $type = 0)
- {
-
- $filter = [];
-
- $filter['a.use_status'] = $type;
-
- switch ($type) {
- case '0':
- $filter['a.end_time'] = ['>=',getTime()];
- break;
- case '1';
- break;
- case '2';
- unset($filter['a.use_status']);
- $filter['a.end_time'] = ['<',getTime()];
- break;
- }
- $filter['a.users_id'] = $users_id;
- $filter['b.coupon_id'] = ['>',0];
-
- $result = Db::name('shop_coupon_use')
- ->alias('a')
- ->join('shop_coupon b','a.coupon_id = b.coupon_id','left')
- ->where($filter)
- ->order('a.add_time desc')
- ->paginate(10, false, [
- 'query' => request()->param()
- ]);
- !empty($result) && $result = $result->toArray();
-
- foreach ($result['data'] as $k => $v ) {
- $v['coupon_form_name'] = '满减券';
- $v['start_time'] = date('Y/m/d',$v['start_time']);
- $v['end_time'] = date('Y/m/d',$v['end_time']);
- switch ($v['coupon_type']) {
- case '1':
- $v['coupon_type_name'] = '全部商品';
- break;
- case '2';
- $v['coupon_type_name'] = '指定商品';
- break;
- case '3';
- $v['coupon_type_name'] = '指定分类';
- break;
- }
- $result['data'][$k] = $v;
- }
-
- return $result;
- }
-
-
- public function GetCouponCenter($users_id)
- {
-
- $filter = [
- 'status' => 1
- ];
- $filter['start_date'] = ['<=',getTime()];
- $filter['end_date'] = ['>=',getTime()];
- $coupon_type = input('param.coupon_type/d');
- if (!empty($coupon_type)) $filter['coupon_type'] = $coupon_type;
-
- $result = Db::name('shop_coupon')
- ->where($filter)
- ->order('sort_order asc,coupon_id desc')
- ->paginate(6, false, [
- 'query' => request()->param()
- ]);
- if (!empty($result)) {
- $coupon_ids = [];
- $result = $result->toArray();
- foreach ($result['data'] as $k => $v ) {
- $coupon_ids[] = $v['coupon_id'];
- $v['coupon_form_name'] = '满减券';
- $v['start_date'] = date('Y/m/d',$v['start_date']);
- $v['end_date'] = date('Y/m/d',$v['end_date']);
- switch ($v['use_type']) {
- case '1':
- $v['use_start_time'] = date('Y/m/d',$v['use_start_time']);
- $v['use_end_time'] = date('Y/m/d',$v['use_end_time']);
- $v['use_type_name'] = $v['use_start_time'].'-'.$v['use_end_time'];
- break;
- case '2';
- $v['use_type_name'] = '领取'.$v['valid_days'].'天内有效';
- break;
- case '3';
- $v['use_type_name'] = '领取次日开始'.$v['valid_days'].'天内有效';
- break;
- }
- $result['data'][$k] = $v;
- }
- $have_where['users_id'] = $users_id;
- $have_where['coupon_id'] = ['in',$coupon_ids];
- $have_where['use_status'] = 0;
- $have = Db::name('shop_coupon_use')->where($have_where)->column('coupon_id');
- if (!empty($have)){
- foreach ($result['data'] as $k => $v ) {
- if (in_array($v['coupon_id'],$have)){
- $result['data'][$k]['geted'] = 1;
- }
- }
- }
- }
-
- return $result;
- }
-
-
- public function getUsersMoneyDetails($users = [], $param = [])
- {
- $where = [
- 'status' => ['IN', [2, 3]],
- 'users_id' => $param['users_id'],
- ];
- $UsersMoney = Db::name('users_money')->where($where)->order('moneyid desc')->select();
-
- $pay_cause_type_arr = Config::get('global.pay_cause_type_arr');
-
- $pay_status_arr = Config::get('global.pay_status_arr');
- foreach ($UsersMoney as $key => $value) {
- $value['status_name'] = $pay_status_arr[$value['status']];
- $value['add_time'] = MyDate('Y-m-d H:i:s', $value['add_time']);
- $value['cause_type_name'] = $pay_cause_type_arr[$value['cause_type']];
- $UsersMoney[$key] = $value;
- }
- $users['MoneyList'] = $UsersMoney;
-
-
- $this->success('查询成功', null, $users);
- }
-
-
- public function getUsersMoneyRecharge($param = [])
- {
- if (empty($param['usersMoney'])) $this->error('请输入充值金额');
-
-
- $cause_type = 1;
-
- $where = [
- 'status' => 1,
- 'cause_type' => $cause_type,
- 'users_id' => $param['users_id'],
- ];
- Db::name('users_money')->where($where)->delete();
-
-
- $where = [
- 'users_id' => $param['users_id']
- ];
- $UsersMoney = Db::name('users')->where($where)->getField('users_money');
-
-
- $time = getTime();
-
- $OrderNumber = date('Ymd') . $time . rand(10, 100);
-
- $pay_cause_type_arr = Config::get('global.pay_cause_type_arr');
-
- $insert = [
- 'users_id' => $param['users_id'],
- 'cause_type' => $cause_type,
- 'cause' => $pay_cause_type_arr[$cause_type],
- 'money' => $param['usersMoney'],
- 'users_money' => $UsersMoney + $param['usersMoney'],
- 'pay_method' => 'wechat',
- 'pay_details' => '',
- 'order_number' => $OrderNumber,
- 'status' => 1,
- 'add_time' => $time
- ];
-
- $insertID = Db::name('users_money')->insertGetId($insert);
- if (!empty($insertID)) {
- $openid = Db::name('wx_users')->where('users_id', $param['users_id'])->getField('openid');
- $Data = $this->GetWechatAppletsPay($openid, $OrderNumber, $param['usersMoney']);
- $ResultData = [
- 'WeChatPay' => $Data,
- 'OrderData' => [
- 'moneyid' => $insertID,
- 'order_number' => $OrderNumber
- ]
- ];
- $this->success('正在支付', null, $ResultData);
- } else {
- $this->error('充值失败');
- }
- }
-
-
- public function getUsersMoneyRechargePay($param = [])
- {
-
- $where = [
- 'cause_type' => 1,
- 'users_id' => $param['users_id'],
- 'moneyid' => $param['moneyid'],
- 'order_number' => $param['order_number'],
- ];
- $usersMoney = Db::name('users_money')->where($where)->find();
- if (empty($usersMoney)) $this->error('订单错误,刷新重试');
- if (1 !== intval($usersMoney['status'])) $this->error('订单已被处理,刷新重试');
-
-
- $openid = Db::name('wx_users')->where('users_id', $param['users_id'])->getField('openid');
-
-
- $WeChatPay = $this->GetWeChatPayDetails($openid, $param['order_number']);
-
-
- if (!empty($WeChatPay) && 'SUCCESS' == $WeChatPay['return_code'] && 'OK' == $WeChatPay['return_msg'] && 'SUCCESS' == $WeChatPay['trade_state']) {
-
- $update = [
- 'status' => 2,
- 'pay_details' => serialize($WeChatPay),
- 'update_time' => getTime(),
- ];
- $ResultID = Db::name('users_money')->where($where)->update($update);
- if (!empty($ResultID)) {
-
- $update = [
- 'users_money' => Db::raw('users_money+'.($usersMoney['money'])),
- ];
- $ResultID = Db::name('users')->where('users_id', $param['users_id'])->update($update);
- if (!empty($ResultID)) {
-
- $update = [
- 'status' => 3,
- 'update_time' => getTime(),
- ];
- Db::name('users_money')->where($where)->update($update);
-
-
- eyou_statistics_data(5, floatval($usersMoney['money']));
-
-
- $this->success('支付完成');
- }
- }
- $this->success('订单处理失败,请联系管理员');
- }
- }
-
-
- public function GetWeChatPayDetails($openid = 0, $orderCode = 0)
- {
-
- $time = getTime();
-
-
- $nonceStr = md5($time . $openid);
-
-
- $params = [
- 'appid' => $this->miniproInfo['appid'],
- 'mch_id' => $this->miniproInfo['mchid'],
- 'nonce_str' => $nonceStr,
- 'out_trade_no' => $orderCode
- ];
-
-
- $params['sign'] = $this->ParamsSign($params, $this->miniproInfo['apikey']);
-
-
- $ParamsXml = $this->ParamsXml($params);
-
-
- $url = 'https://api.mch.weixin.qq.com/pay/orderquery';
- $result = httpRequest($url, 'POST', $ParamsXml);
-
-
- $ResultData = $this->ResultXml($result);
-
- return $ResultData;
- }
-
-
- public function getOrderGoodsDetect($param = [])
- {
-
- $where = [
- 'users_id' => $param['users_id'],
- 'order_id' => $param['order_id'],
- 'details_id' => $param['details_id'],
- 'product_id' => $param['product_id']
- ];
- $field = 'details_id, order_id, users_id, product_id, apply_service, is_comment';
- $orderGoods = Db::name("shop_order_details")->where($where)->field($field)->find();
- if (empty($orderGoods)) $this->error('订单商品不存在');
- $orderGoods['service_id'] = 0;
-
-
- if ('service' == $param['use']) {
- if (!empty($orderGoods['apply_service'])) {
- $where['status'] = ['NEQ', 8];
- $orderGoods['service_id'] = Db::name('shop_order_service')->where($where)->getField('service_id');
- }
- } else if ('comment' == $param['use']) {
- if (!empty($orderGoods['is_comment'])) {
- $url = strval('/pages/article/view?aid=' . $param['product_id']);
- $this->success('订单商品已完成评价', $url, false);
- }
- }
-
-
- $this->success('检测完成', null, $orderGoods);
- }
-
-
- public function getOrderGoodsServiceList($param = [])
- {
- $where = [
- 'users_id' => $param['users_id'],
- ];
- if (!empty($param['serviceStatus']) && 1 == $param['serviceStatus']) {
- $where['status'] = ['IN', [1, 2, 4, 5]];
- } else if (!empty($param['serviceStatus']) && 2 == $param['serviceStatus']) {
- $where['status'] = ['IN', [6, 7]];
- }
- $field = 'service_id, service_type, users_id, product_name, product_img, status, add_time';
-
-
- $Query = request()->param();
-
- $result = Db::name('shop_order_service')->field($field)->where($where)->paginate(15, false, ['query' => $Query]);
- !empty($result) && $serviceData = $result->toArray();
-
- if (!empty($serviceData['data'])) {
- $orderServiceType = Config::get('global.order_service_type');
- $orderServiceStatus = Config::get('global.order_service_status');
- foreach ($serviceData['data'] as $key => $value) {
-
- $value['add_time'] = MyDate('Y-m-d H:i:s', $value['add_time']);
- $value['product_img'] = $this->get_default_pic($value['product_img'], true);
- $value['status_name'] = $orderServiceStatus[$value['status']];
- $value['service_type_name'] = $orderServiceType[$value['service_type']];
-
- $serviceData['data'][$key] = $value;
- }
- }
-
- $this->success('查询成功', null, $serviceData);
- }
-
-
- public function getOrderGoodsService($param = [])
- {
- $serviceData = $serviceDataLog = $expressData = [];
- if (!empty($param['service_id'])) {
-
- $where = [
- 'users_id' => $param['users_id'],
- 'service_id' => $param['service_id'],
- ];
- $serviceData = Db::name('shop_order_service')->where($where)->find();
- if (empty($serviceData)) $this->error('售后订单不存在');
- $uploadImg = explode(',', $serviceData['upload_img']);
- foreach ($uploadImg as $key => $value) {
- if (!empty($value)) {
- $uploadImg[$key] = $this->get_default_pic($value, true);
- } else {
- unset($serviceImg[$key]);
- }
- }
- $serviceData['upload_img'] = $uploadImg;
- $serviceData['add_time'] = MyDate('Y-m-d H:i:s', $serviceData['add_time']);
- $serviceData['product_img'] = $this->get_default_pic($serviceData['product_img'], true);
- $serviceData['status_name'] = Config::get('global.order_service_status')[$serviceData['status']];
- $serviceData['service_type_name'] = Config::get('global.order_service_type')[$serviceData['service_type']];
- $serviceData['admin_delivery'] = !empty($serviceData['admin_delivery']) ? unserialize($serviceData['admin_delivery']) : '';
- $serviceData['users_delivery'] = !empty($serviceData['users_delivery']) ? unserialize($serviceData['users_delivery']) : '';
-
-
- $where = [
- 'service_id' => $param['service_id'],
- ];
- $serviceDataLog = Db::name('shop_order_service_log')->order('log_id desc')->where($where)->select();
- foreach ($serviceDataLog as $key => $value) {
- if (!empty($value['users_id'])) {
- $serviceDataLog[$key]['name'] = '会员';
- } else if (!empty($value['admin_id'])) {
- $serviceDataLog[$key]['name'] = '商家';
- }
- $serviceDataLog[$key]['add_time'] = MyDate('Y-m-d H:i:s', $value['add_time']);
- }
-
-
- $expressData = Db::name('shop_express')->select();
-
-
- $param['order_id'] = $serviceData['order_id'];
- $param['product_id'] = $serviceData['product_id'];
- $param['details_id'] = $serviceData['details_id'];
- }
-
-
- $where = [
- 'a.users_id' => $param['users_id'],
- 'a.order_id' => $param['order_id'],
- 'a.details_id' => $param['details_id'],
- 'a.product_id' => $param['product_id']
- ];
- $field = 'a.users_id, a.order_id, b.order_code, a.details_id, a.product_id, a.product_name, a.product_price, a.num as product_num, a.litpic, a.apply_service, b.pay_time, b.consignee, b.mobile, b.province, b.city, b.district, b.address';
- $orderGoods = Db::name("shop_order_details")->alias('a')->join('__SHOP_ORDER__ b', 'a.order_id = b.order_id', 'LEFT')->where($where)->field($field)->find();
- if (empty($orderGoods)) $this->error('订单商品不存在');
-
-
- $orderGoods['litpic'] = $this->get_default_pic($orderGoods['litpic'], true);
- $orderGoods['pay_time'] = MyDate('Y-m-d H:i:s', $orderGoods['pay_time']);
- $Province = $this->GetRegionName($orderGoods['province']);
- $City = $this->GetRegionName($orderGoods['city']);
- $District = $this->GetRegionName($orderGoods['district']);
- $orderGoods['address'] = $Province . ' ' . $City . ' ' . $District . ' ' . $orderGoods['address'];
-
-
- $orderGoods['admin_addr'] = getUsersConfigData('addr');
-
-
- $orderGoods['express'] = $expressData;
-
-
- $orderGoods['service'] = $serviceData;
- $orderGoods['service_log'] = $serviceDataLog;
-
- $this->success('查询成功', null, $orderGoods);
- }
-
-
- public function addOrderGoodsService($param = [])
- {
-
- $formData = htmlspecialchars_decode($param['formData']);
- $formData = json_decode(htmlspecialchars_decode($formData), true);
-
-
- $where = [
- 'status' => ['NEQ', 8],
- 'users_id' => $param['users_id'],
- 'order_id' => $formData['order_id'],
- 'product_id' => $formData['product_id'],
- 'details_id' => $formData['details_id']
- ];
- $IsCount = Db::name('shop_order_service')->where($where)->count();
- if (!empty($IsCount)) $this->error('订单商品已申请售后');
-
- $time = getTime();
- $addService = [
- 'service_type' => !empty($formData['service_type']) ? intval($formData['service_type']) : 0,
- 'users_id' => intval($param['users_id']),
- 'order_id' => !empty($formData['order_id']) ? intval($formData['order_id']) : 0,
- 'order_code' => !empty($formData['order_code']) ? strval($formData['order_code']) : 0,
- 'details_id' => !empty($formData['details_id']) ? intval($formData['details_id']) : 0,
- 'product_id' => !empty($formData['product_id']) ? intval($formData['product_id']) : 0,
- 'product_name' => !empty($formData['product_name']) ? strval($formData['product_name']) : '',
- 'product_num' => !empty($formData['product_num']) ? intval($formData['product_num']) : 0,
- 'product_img' => !empty($formData['litpic']) ? strval($formData['litpic']) : '',
- 'content' => !empty($formData['content']) ? htmlspecialchars($formData['content']) : '',
- 'upload_img' => !empty($formData['uploaded'][0]) ? implode(',', $formData['uploaded']) : '',
- 'address' => strval($formData['address']),
- 'consignee' => !empty($formData['consignee']) ? $formData['consignee'] : '',
- 'mobile' => !empty($formData['mobile']) ? $formData['mobile'] : 0,
- 'refund_price' => !empty($formData['product_price']) ? $formData['product_price'] : 0,
- 'refund_code' => 'HH' . $time . rand(10,100),
- 'add_time' => $time,
- 'update_time' => $time,
- ];
- if (2 == $addService['service_type'] && !empty($addService['refund_price'])) $addService['refund_code'] = 'TK' . $time . rand(10,100);
- $ResultID = Db::name('shop_order_service')->insertGetId($addService);
-
-
- if (!empty($ResultID)) {
-
- $update = [
- 'details_id' => $addService['details_id'],
- 'apply_service' => 1,
- 'update_time' => getTime()
- ];
- Db::name('shop_order_details')->update($update);
-
-
- $LogNote = 1 == $addService['service_type'] ? '会员提交换货申请,待管理员审核!' : '会员提交退货申请,待管理员审核!';
- OrderServiceLog($ResultID, $addService['order_id'], $addService['users_id'], 0, $LogNote);
-
-
- $this->success('已申请,待审核');
- } else {
- $this->error('申请售后失败');
- }
- }
-
-
- public function cancelOrderGoodsService($param = [])
- {
-
- $where = [
- 'users_id' => $param['users_id'],
- 'service_id' => $param['service_id']
- ];
- $update = [
- 'status' => 8,
- 'update_time' => getTime(),
- ];
- $ResultID = Db::name('shop_order_service')->where($where)->update($update);
- if (!empty($ResultID)) {
-
- $where = [
- 'users_id' => $param['users_id'],
- 'details_id' => $param['details_id']
- ];
- $update = [
- 'apply_service' => 0,
- 'update_time' => getTime()
- ];
- Db::name('shop_order_details')->where($where)->update($update);
-
-
- $param['status'] = 8;
- $this->addOrderServiceLog($param);
- $this->success('取消成功');
- } else {
- $this->error('取消失败');
- }
- }
-
-
- public function addServiceUsersDelivery($param = [])
- {
-
- $usersDelivery = htmlspecialchars_decode($param['usersDelivery']);
- $usersDelivery = json_decode(htmlspecialchars_decode($usersDelivery), true);
-
-
- $where = [
- 'users_id' => $param['users_id'],
- 'service_id' => $param['service_id'],
- ];
- $update = [
- 'status' => 4,
- 'users_delivery' => !empty($usersDelivery) ? serialize($usersDelivery) : '',
- 'update_time' => getTime(),
- ];
- $ResultID = Db::name('shop_order_service')->where($where)->update($update);
- if (!empty($ResultID)) {
-
- $param['status'] = 4;
- $this->addOrderServiceLog($param);
- $this->success('提交物流成功');
- } else {
- $this->error('提交物流失败');
- }
- }
-
-
- private function addOrderServiceLog($param = [])
- {
- if (empty($param)) return false;
-
- if (2 == $param['status']) {
- $LogNote = '商家通过申请,等待会员将货物寄回商家!';
- } else if (3 == $param['status']) {
- $LogNote = '商家拒绝申请,请联系商家处理!';
- } else if (4 == $param['status']) {
- $LogNote = '会员已将货物发出,等待商家收货!';
- } else if (5 == $param['status']) {
- $LogNote = '商家已收到货物,待管理员进行退换货处理!';
- } else if (6 == $param['status']) {
- $LogNote = '商家已将新货物重新发出,换货完成,服务结束!';
- } else if (7 == $param['status']) {
- $LogNote = '商家已将金额、余额、积分退回,退款完成,服务结束!';
- } else if (8 == $param['status']) {
- $LogNote = '服务单被取消,服务结束!';
- }
- OrderServiceLog($param['service_id'], $param['order_id'], $param['users_id'], 0, $LogNote);
- }
-
-
-
- public function getOneDiscount($param = [])
- {
- $avtive_id = !empty($param['activeid']) ? intval($param['activeid']) : 0;
-
- $where['status'] = 1;
- $where['is_del'] = 0;
-
-
- if (!empty($avtive_id)){
- $where['active_id'] = $avtive_id;
- $active = Db::name('discount_active')->where($where)->find();
- }else{
- $where['start_date'] = ['<=',getTime()];
- $where['end_date'] = ['>=',getTime()];
-
- $active = Db::name('discount_active')->where($where)->find();
-
- if (empty($active)){
- $active = Db::name('discount_active')
- ->where('status',1)
- ->where('is_del',0)
- ->where('start_date','>',getTime())
- ->order('start_date asc')
- ->find();
- }
- }
- $return = [];
- if (!empty($active)){
- $return['active'] = $active;
-
- if ($active['start_date'] <= getTime()){
- $return['active']['active_status'] = 10;
- }else{
- $return['active']['active_status'] = 20;
- }
- $param['active_id'] = $return['active']['active_id'];
- $return['goodsList'] = $this->getDiscountGoodsList($param);
- }
- return $return;
- }
-
-
-
- public function getDiscountGoodsList($param = [])
- {
- $limit = !empty($param['limit']) ? intval($param['limit']) : 6;
- $active_id = $param['active_id'];
- $data = Db::name('discount_active_goods')
- ->alias('a')
- ->field('c.*,b.litpic,b.title,a.*,b.users_price')
- ->join('archives b','a.aid = b.aid')
- ->join('discount_goods c','a.discount_goods_id = c.discount_gid')
- ->where('a.active_id',$active_id)
- ->limit($limit)
- ->getAllWithIndex('aid');
- if (!empty($data)){
- $aids = [];
- foreach ($data as $k => $v){
- $data[$k]['litpic'] = get_default_pic($v['litpic'],true);
- if (1 == $v['is_sku']){
- $aids[] = $v['aid'];
- }
- }
-
- if (!empty($aids)){
- $sku = Db::name('product_spec_value')
- ->field('*,min(discount_price) as discount_price')
- ->where('aid','in',$aids)
- ->group('aid')
- ->getAllWithIndex('aid');
- }
-
- foreach ($data as $k => $v){
- if (1 == $v['is_sku'] && !empty($sku[$v['aid']])){
- $v['discount_price'] = $sku[$v['aid']]['discount_price'];
- }
- $v['progress'] = 0;
- if (0 < $v['sales_actual']){
- $count_stock = $v['sales_actual']+$v['discount_stock']+$v['virtual_sales'];
- $v['progress'] = intval(($v['sales_actual']+$v['virtual_sales'])/$count_stock*100);
- }else{
- if (0 < $v['virtual_sales']){
- $v['progress'] = intval($v['virtual_sales']/($v['virtual_sales']+$v['discount_stock'])*100);;
- }
- }
- if (0 < $v['virtual_sales']){
- $v['sales_actual'] = $v['sales_actual'] +$v['virtual_sales'];
-
- }
- $data[$k] = $v;
- }
- }
- return $data;
- }
-
-
-
- public function GetDiscountIndex($param = [])
- {
- $active_id = $param['active_id'];
- $page = !empty($param['page']) ? $param['page'] : 1;
- $pagesize = !empty($param['limit']) ? $param['limit'] : 20;
- $cacheKey = 'api-'.md5(__CLASS__.__FUNCTION__.json_encode(func_get_args()));
- $result = cache($cacheKey);
- if (true || empty($result)) {
- $paginate = array(
- 'page' => $page,
- );
- $pages = Db::name('discount_active_goods')
- ->alias('a')
- ->field('c.*,b.litpic,b.title,a.*,b.users_price')
- ->join('archives b','a.aid = b.aid')
- ->join('discount_goods c','a.discount_goods_id = c.discount_gid')
- ->where('a.active_id',$active_id)
- ->paginate($pagesize, false, $paginate);
-
- $result = $pages->toArray();
-
- $aids = [];
- foreach ($result['data'] as $k => $v){
- $result['data'][$k]['litpic'] = get_default_pic($v['litpic'],true);
- if (1 == $v['is_sku']){
- $aids[] = $v['aid'];
- }
- }
-
-
- if (!empty($aids)) {
- $sku = Db::name('product_spec_value')
- ->field('*,min(discount_price) as discount_price')
- ->where('aid', 'in', $aids)
- ->group('aid')
- ->getAllWithIndex('aid');
- }
-
- foreach ($result['data'] as $k => $v){
- if (1 == $v['is_sku'] && !empty($sku[$v['aid']])){
- $v['discount_price'] = $sku[$v['aid']]['discount_price'];
- }
- $v['progress'] = 0;
- if (0 < $v['sales_actual']){
- $count_stock = $v['sales_actual']+$v['discount_stock']+$v['virtual_sales'];
- $v['progress'] = intval(($v['sales_actual']+$v['virtual_sales'])/$count_stock*100);
- }else{
- if (0 < $v['virtual_sales']){
- $v['progress'] = intval($v['virtual_sales']/($v['virtual_sales']+$v['discount_stock'])*100);;
- }
- }
- if (0 < $v['virtual_sales']){
- $v['sales_actual'] = $v['sales_actual'] + $v['virtual_sales'];
-
- }
- $result['data'][$k] = $v;
- }
- if(1 == $page){
- $result['active'] = $this->GetDiscount($active_id);
- }
- cache($cacheKey, $result, null, 'GetDiscountIndex');
- }
-
- return $result;
- }
-
- public function GetDiscount($active_id = 0){
- $data = Db::name('discount_active')->where('active_id',$active_id)->find();
- if ($data['start_date'] <= getTime()){
- $data['active_status'] = 10;
- }else{
- $data['active_status'] = 20;
- }
- return $data;
- }
-
-
-
-
- public function upgradeUserLevel($param = [])
- {
- if (empty($param['type_id'])) $this->error('缺少升级类型');
- $users_type_manage = Db::name('users_type_manage')->where('type_id',$param['type_id'])->find();
-
- $cause_type = 0;
-
- $where = [
- 'status' => 1,
- 'cause_type' => $cause_type,
- 'users_id' => $this->users_id,
- ];
- Db::name('users_money')->where($where)->delete();
-
- $times = getTime();
-
- $where = [
- 'users_id' => $this->users_id
- ];
- $users = Db::name('users')->where($where)->find();
- $UsersMoney = $users['users_money'];
- $level_name = Db::name('users_level')->where('level_id',$users['level'])->value('level_name');
-
- $time = getTime();
-
- $OrderNumber = date('Ymd') . $time . rand(10, 100);
- $pay_detail = "会员当前级别为【{$level_name}】,使用微信支付【{$users_type_manage['type_name']}】,支付金额为{$users_type_manage['price']}";
-
- $insert = [
- 'users_id' => $this->users_id,
- 'cause_type' => $cause_type,
- 'cause' => serialize($users_type_manage),
- 'money' => $users_type_manage['price'],
- 'users_money' => $UsersMoney - $users_type_manage['price'],
- 'pay_method' => 'wechat',
- 'pay_details' => serialize($pay_detail),
- 'order_number' => $OrderNumber,
- 'level_id' => $users_type_manage['level_id'],
- 'status' => 1,
- 'add_time' => $time
- ];
-
- $insertID = Db::name('users_money')->insertGetId($insert);
- if (!empty($insertID)) {
- if ('wechat' == $param['pay_type']) {
-
- $openid = Db::name('wx_users')->where('users_id', $param['users_id'])->getField('openid');
- $notify_url = url('api/v1/Api/wxpay_notify_users', [], true, true, 1, 2);
- $Data = $this->GetWechatAppletsPay($openid, $OrderNumber, $users_type_manage['price'],$notify_url);
- $ResultData = [
- 'WeChatPay' => $Data,
- 'OrderData' => [
- 'moneyid' => $insertID,
- 'order_number' => $OrderNumber
- ]
- ];
- $this->success('正在支付', null, $ResultData);
- } else if ('balance' == $param['pay_type']) {
-
- if ($users['users_money'] < $users_type_manage['price']){
- $this->error('余额不足!');
- }
-
- $UpOrderData = [
- 'status' => 2,
- 'pay_name' => 'balance',
- 'update_time' => getTime()
- ];
- $ReturnID = Db::name('users_money')->where('order_number', $OrderNumber)->update($UpOrderData);
- if (!empty($ReturnID)) {
- $limit_arr = Config::get('global.admin_member_limit_arr');
-
- $day = $limit_arr[$users_type_manage['limit_id']]['maturity_days'];
- $users_update['level_maturity_days'] = Db::Raw('level_maturity_days +'.$day);
- if (empty($users['level_maturity_days'])){
- $users_update['open_level_time'] = getTime();
- }
- $users_update['level'] = $users_type_manage['level_id'];
- $users_update['update_time'] = getTime();
- $users_update['users_money'] = Db::Raw('users_money-'.$users_type_manage['price']);
- Db::name('users')->where('users_id', $param['users_id'])->update($users_update);
-
- $url = '/pages/user/index';
- $this->success('支付完成', $url);
- }
- }
- } else {
- $this->error('会员升级失败');
- }
- }
-
-
- public function handleUpgradeUserLevel($param = [])
- {
-
- $where = [
- 'cause_type' => 0,
- 'users_id' => $this->users_id,
- 'order_number' => $param['order_number'],
- ];
- $usersMoney = Db::name('users_money')->where($where)->find();
- if (empty($usersMoney)) $this->error('订单错误,刷新重试');
- if (1 !== intval($usersMoney['status'])) $this->error('订单已被处理,刷新重试');
-
-
- $openid = Db::name('wx_users')->where('users_id', $param['users_id'])->getField('openid');
-
-
- $WeChatPay = $this->GetWeChatPayDetails($openid, $param['order_number']);
-
-
- if (!empty($WeChatPay) && 'SUCCESS' == $WeChatPay['return_code'] && 'OK' == $WeChatPay['return_msg'] && 'SUCCESS' == $WeChatPay['trade_state']) {
-
- $update = [
- 'status' => 2,
- 'update_time' => getTime(),
- ];
- $ResultID = Db::name('users_money')->where($where)->update($update);
- if (!empty($ResultID)) {
- $usersMoney['cause'] = unserialize($usersMoney['cause']);
- $level_maturity_days = Db::name('users')->where('users_id', $param['users_id'])->value('level_maturity_days');
- $limit_arr = Config::get('global.admin_member_limit_arr');
-
- $day = $limit_arr[$usersMoney['cause']['limit_id']]['maturity_days'];
- $users_update['level_maturity_days'] = Db::Raw('level_maturity_days +'.$day);
- if (empty($level_maturity_days)){
- $users_update['open_level_time'] = getTime();
- }
- $users_update['level'] = $usersMoney['cause']['level_id'];
- $users_update['update_time'] = getTime();
- Db::name('users')->where('users_id', $param['users_id'])->update($users_update);
-
- $this->success('支付完成');
- }
- $this->success('订单处理失败,请联系管理员');
- }
- }
-
-
- public function WechatAppletsPayDealWithUsersMoney($PostData = [], $notify = false)
- {
- $OpenID = !empty($PostData['openid']) ? $PostData['openid'] : '';
- $UsersID = !empty($PostData['users_id']) ? $PostData['users_id'] : '';
- $order_number = $PostData['order_number'];
-
- if (!empty($moneyid) && !empty($order_number)) {
- $where = [
- 'users_id' => $UsersID,
- 'order_number' => $order_number,
- ];
-
- $order = Db::name('users_money')->where($where)->find();
-
- if (empty($order)) {
- $this->error('无效订单!');
- } else if (1 < $order['status']) {
-
- if ($notify === true) {
- return [
- 'code' => 1,
- 'msg' => 'ok',
- ];
- } else {
- $this->success('支付完成', '/pages/user/index');
- }
- }
-
-
- $time = getTime();
-
-
- $nonceStr = md5($time . $OpenID);
-
-
- $params = [
- 'appid' => $this->miniproInfo['appid'],
- 'mch_id' => $this->miniproInfo['mchid'],
- 'nonce_str' => $nonceStr,
- 'out_trade_no' => $order_number
- ];
-
-
- $params['sign'] = $this->ParamsSign($params, $this->miniproInfo['apikey']);
-
-
- $ParamsXml = $this->ParamsXml($params);
-
-
- $url = 'https://api.mch.weixin.qq.com/pay/orderquery';
- $result = $this->HttpsPost($url, $ParamsXml);
-
-
- $ResultData = $this->ResultXml($result);
-
-
- if (!empty($ResultData) && 'SUCCESS' == $ResultData['return_code'] && 'OK' == $ResultData['return_msg']) {
-
-
-
-
- if ('SUCCESS' == $ResultData['trade_state']) {
-
- $OrderWhere = [
- 'order_number' => $order_number,
- 'users_id' => $UsersID
- ];
- $OrderData = [
- 'status' => 2,
- 'update_time' => getTime()
- ];
- $ResultID = Db::name('users_money')->where($OrderWhere)->update($OrderData);
- if (!empty($ResultID)) {
- $order['cause'] = unserialize($order['cause']);
- $level_maturity_days = Db::name('users')->where('users_id', $UsersID)->value('level_maturity_days');
- $limit_arr = Config::get('global.admin_member_limit_arr');
-
- $day = $limit_arr[$order['cause']['limit_id']]['maturity_days'];
- $users_update['level_maturity_days'] = Db::Raw('level_maturity_days +'.$day);
- if (empty($level_maturity_days)){
- $users_update['open_level_time'] = getTime();
- }
- $users_update['level'] = $order['cause']['level_id'];
- $users_update['update_time'] = getTime();
- Db::name('users')->where('users_id', $UsersID)->update($users_update);
-
-
- if ($notify === true) {
- return [
- 'code' => 1,
- 'msg' => 'ok',
- ];
- } else {
- $url = '/pages/user/index';
- $this->success('支付完成', $url);
- }
- }
- }
- }
- }
- }
-
-
-
-
-
- public function buyMedia($param = [])
- {
- if (empty($param['aid'])) $this->error('缺少必要参数');
-
- $where = [
- 'order_status' => 0,
- 'users_id' => $this->users_id,
- ];
- Db::name('media_order')->where($where)->delete();
-
- $users = Db::name('users')
- ->field('a.*,b.discount')
- ->alias('a')
- ->join('users_level b','a.level = b.level_id','left')
- ->where('a.users_id',$this->users_id)
- ->find();
- $list = Db::name('archives')->where('aid',$param['aid'])->find();
- $price = unifyPriceHandle($list['users_price'] * ($users['discount'] / 100));
-
-
- $time = getTime();
- $OrderData = [
- 'order_code' => date('Y') . $time . rand(10,100),
- 'users_id' => $this->users_id,
- 'mobile' => !empty($users['mobile']) ?$users['mobile'] : '',
- 'order_status' => 0,
- 'order_amount' => $price,
- 'pay_time' => '',
- 'pay_name' => '',
- 'wechat_pay_type' => '',
- 'pay_details' => '',
- 'product_id' => $list['aid'],
- 'product_name' => $list['title'],
- 'product_litpic' => get_default_pic($list['litpic']),
- 'lang' => get_home_lang(),
- 'add_time' => $time,
- 'update_time' => $time
- ];
- $insertID = Db::name('media_order')->insertGetId($OrderData);
- if (!empty($insertID)) {
- if ('wechat' == $param['pay_type']) {
-
- $openid = Db::name('wx_users')->where('users_id', $param['users_id'])->getField('openid');
- $notify_url = url('api/v1/Api/wxpay_notify_media', [], true, true, 1, 2);
- $Data = $this->GetWechatAppletsPay($openid, $OrderData['order_code'], $price,$notify_url);
- $ResultData = [
- 'WeChatPay' => $Data,
- 'OrderData' => [
- 'order_id' => $insertID,
- 'order_code' => $OrderData['order_code']
- ]
- ];
- $this->success('正在支付', null, $ResultData);
- } else if ('balance' == $param['pay_type']) {
-
- if ($users['users_money'] < $price){
- $this->error('余额不足!');
- }
-
-
- $pay_details['unified_id'] = $insertID;
- $pay_details['unified_number'] = $OrderData['order_code'];
- $pay_details['payment_type'] = '余额支付';
- $pay_details['payment_amount'] = $price;
- $pay_details['transaction_type'] = 8;
-
- $UpOrderData = [
- 'order_status' => 1,
- 'pay_time' => getTime(),
- 'pay_name' => 'balance',
- 'pay_details' => serialize($pay_details),
- 'update_time' => getTime()
- ];
- $ReturnID = Db::name('media_order')->where('order_code', $OrderData['order_code'])->update($UpOrderData);
- if (!empty($ReturnID)) {
- $Where = [
- 'users_id' => $this->users_id
- ];
- $UsersData = [
- 'users_money' => Db::raw('users_money-'.$OrderData['order_amount']),
- 'update_time' => getTime()
- ];
- Db::name('users')->where($Where)->update($UsersData);
- UsersMoneyRecording($OrderData['order_code'], $users, $OrderData['order_amount'], '视频购买', 3);
- $url = '/pages/user/index';
- $this->success('支付完成', $url);
- }
- }
- } else {
- $this->error('会员升级失败');
- }
- }
-
-
- public function handleBuyMedia($param = [])
- {
-
- $where = [
- 'users_id' => $this->users_id,
- 'order_code' => $param['order_code'],
- ];
- $order = Db::name('media_order')->where($where)->find();
- if (empty($order)) $this->error('订单错误,刷新重试');
- if (0 !== intval($order['status'])) $this->error('订单已被处理,刷新重试');
-
-
- $openid = Db::name('wx_users')->where('users_id', $param['users_id'])->getField('openid');
-
-
- $WeChatPay = $this->GetWeChatPayDetails($openid, $param['order_code']);
-
-
- if (!empty($WeChatPay) && 'SUCCESS' == $WeChatPay['return_code'] && 'OK' == $WeChatPay['return_msg'] && 'SUCCESS' == $WeChatPay['trade_state']) {
-
-
- $pay_details['unified_id'] = $order['order_id'];
- $pay_details['unified_number'] = $order['order_code'];
- $pay_details['payment_type'] = '微信支付';
- $pay_details['payment_amount'] = $order['order_amount'];
- $pay_details['transaction_type'] = 8;
-
- $UpOrderData = [
- 'order_status' => 1,
- 'pay_time' => getTime(),
- 'pay_name' => 'wechat',
- 'wechat_pay_type' => 'WeChatScanCode',
- 'pay_details' => serialize($pay_details),
- 'update_time' => getTime()
- ];
- $return = Db::name('media_order')->where('order_code', $param['order_code'])->update($UpOrderData);
- if (!empty($return)) {
-
- $this->success('支付完成');
- }
- $this->success('订单处理失败,请联系管理员');
- }
- }
-
-
- public function WechatAppletsPayDealWithMedia($PostData = [], $notify = false)
- {
- $OpenID = !empty($PostData['openid']) ? $PostData['openid'] : '';
- $UsersID = !empty($PostData['users_id']) ? $PostData['users_id'] : '';
- $order_code = $PostData['order_code'];
-
- if (!empty($order_code)) {
- $where = [
- 'users_id' => $UsersID,
- 'order_code' => $order_code,
- ];
-
- $order = Db::name('media_order')->where($where)->find();
-
- if (empty($order)) {
- $this->error('无效订单!');
- } else if (0 < $order['status']) {
-
- if ($notify === true) {
- return [
- 'code' => 1,
- 'msg' => 'ok',
- ];
- } else {
- $this->success('支付完成', '/pages/user/index');
- }
- }
-
-
- $time = getTime();
-
-
- $nonceStr = md5($time . $OpenID);
-
-
- $params = [
- 'appid' => $this->miniproInfo['appid'],
- 'mch_id' => $this->miniproInfo['mchid'],
- 'nonce_str' => $nonceStr,
- 'out_trade_no' => $order_code
- ];
-
-
- $params['sign'] = $this->ParamsSign($params, $this->miniproInfo['apikey']);
-
-
- $ParamsXml = $this->ParamsXml($params);
-
-
- $url = 'https://api.mch.weixin.qq.com/pay/orderquery';
- $result = $this->HttpsPost($url, $ParamsXml);
-
-
- $ResultData = $this->ResultXml($result);
-
-
- if (!empty($ResultData) && 'SUCCESS' == $ResultData['return_code'] && 'OK' == $ResultData['return_msg']) {
-
-
-
-
- if ('SUCCESS' == $ResultData['trade_state']) {
-
- $OrderWhere = [
- 'order_code' => $order_code,
- 'users_id' => $UsersID
- ];
-
- $pay_details['unified_id'] = $order['order_id'];
- $pay_details['unified_number'] = $order['order_code'];
- $pay_details['payment_type'] = '微信支付';
- $pay_details['payment_amount'] = $order['order_amount'];
- $pay_details['transaction_type'] = 8;
-
- $UpOrderData = [
- 'order_status' => 1,
- 'pay_time' => getTime(),
- 'pay_name' => 'wechat',
- 'wechat_pay_type' => 'WeChatScanCode',
- 'pay_details' => serialize($pay_details),
- 'update_time' => getTime()
- ];
- $ResultID = Db::name('media_order')->where($OrderWhere)->update($UpOrderData);
- if (!empty($ResultID)) {
-
-
- if ($notify === true) {
- return [
- 'code' => 1,
- 'msg' => 'ok',
- ];
- } else {
- $url = '/pages/user/index';
- $this->success('支付完成', $url);
- }
- }
- }
- }
- }
- }
-
-
- }
|