SaasController.php 172 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\controllers;
  8. use app\models\AboutArticle;
  9. use app\models\common\CommonUpload;
  10. use app\models\MerchantInfo;
  11. use app\models\ProfitSharingReceiver;
  12. use app\models\SaasUser;
  13. use app\models\Salesman;
  14. use app\models\SmsSetting;
  15. use app\models\Store;
  16. use app\models\User;
  17. use app\models\UploadConfig;
  18. use app\modules\admin\models\CostProfitListForm;
  19. use app\modules\admin\models\PlatformProfitCashForm;
  20. use app\modules\admin\models\ProfitReceiverForm;
  21. use app\modules\admin\models\ShareFinancialListForm;
  22. use app\modules\admin\models\ShareProfitListForm;
  23. use app\modules\admin\models\WechatConfigForm;
  24. use app\utils\Ocr\OcrApi;
  25. use Yii;
  26. use app\modules\admin\models\SaasForm;
  27. use app\models\Option;
  28. use yii\base\BaseObject;
  29. use yii\helpers\Json;
  30. use app\constants\OptionSetting;
  31. use app\models\Admin;
  32. use app\models\SharingReceiver;
  33. use \app\models\StorePrice;
  34. use Throwable;
  35. use yii\web\Response;
  36. use yii\base\InvalidConfigException;
  37. use yii\db\StaleObjectException;
  38. use yii\db\Exception;
  39. use app\models\SaasStoreReferral;
  40. use yii\base\NotSupportedException;
  41. use yii\base\InvalidArgumentException;
  42. use Exception as GlobalException;
  43. use app\models\Order;
  44. use app\models\SaasSupplierReferral;
  45. use app\models\SaasUserPriceLog;
  46. use app\models\Supplier;
  47. class SaasController extends BaseController
  48. {
  49. // 获取基础配置
  50. public function actionGetBaseSetting()
  51. {
  52. if (\Yii::$app->isSaas()) {
  53. $admin_logo = Option::get('admin_logo', 0, 'saas', '');
  54. $admin_copyright = Option::get('admin_copyright', 0, 'saas', '');
  55. $admin_name = Option::get('name', 0, 'saas', '');
  56. $help_logo = Option::get('help_logo', 0, 'saas', '');
  57. $describe = Option::get('describe', 0, 'saas', '');
  58. } else {
  59. $store_id = get_store_id();
  60. $admin_logo = Option::get('web_log', $store_id, 'web', '');
  61. $admin_copyright = Option::get('copyright', $store_id, 'web', '');
  62. $admin_name = Option::get('web_name', $store_id, 'web', '');
  63. $help_logo = Option::get('help_logo', $store_id, 'web', '');
  64. $describe = Option::get('describe', $store_id, 'web', '');
  65. $passport_bg = Option::get('passport_bg', $store_id, 'web', '');
  66. }
  67. return $this->asJson([
  68. 'code' => 0,
  69. 'msg' => 'success',
  70. 'data' => [
  71. 'admin_logo' => $admin_logo['value'],
  72. 'admin_copyright' => $admin_copyright['value'],
  73. 'admin_name' => $admin_name['value'],
  74. 'help_logo' => $help_logo['value'],
  75. 'describe' => $describe['value'],
  76. 'passport_bg' => $passport_bg['value'] ?? null
  77. ],
  78. ]);
  79. }
  80. public function actionSetPlatformAppParams() {
  81. try {
  82. if (\Yii::$app->request->isPost) {
  83. $key = [
  84. 'platform_app_store_android',
  85. 'platform_app_store_android_version',
  86. 'platform_app_store_ios',
  87. 'platform_app_logo',
  88. 'platform_app_bg',
  89. ];
  90. $params = post_params();
  91. $value = [
  92. $params['platform_app_store_android'],
  93. $params['platform_app_store_android_version'],
  94. $params['platform_app_store_ios'],
  95. $params['platform_app_logo'],
  96. $params['platform_app_bg'],
  97. ];
  98. Option::set($key, $value, 0, 'saas');
  99. return $this->asJson([
  100. 'code' => 0,
  101. 'msg' => ''
  102. ]);
  103. } else {
  104. $keys = [
  105. 'platform_app_store_android',
  106. 'platform_app_store_android_version',
  107. 'platform_app_store_ios',
  108. 'platform_app_logo',
  109. 'platform_app_bg',
  110. ];
  111. $data = Option::get($keys, 0, 'saas');
  112. if (empty($data)) {
  113. $data = [
  114. 'platform_app_store_android' => '',
  115. 'platform_app_store_android_version' => '',
  116. 'platform_app_store_ios' => '',
  117. 'platform_app_logo' => '',
  118. 'platform_app_bg' => '',
  119. ];
  120. } else {
  121. $arr = [];
  122. foreach ($data as $value) {
  123. $index = array_search($value['name'], $keys);
  124. unset($keys[$index]);
  125. $arr[$value['name']] = $value['value'];
  126. }
  127. foreach ($keys as $key) {
  128. $arr[$key] = '';
  129. }
  130. $data = $arr;
  131. }
  132. return $this->asJson([
  133. 'code' => 0,
  134. 'msg' => 'success',
  135. 'data' => $data,
  136. ]);
  137. }
  138. } catch (\Exception $e) {
  139. return $this->asJson([
  140. 'code' => 1,
  141. 'msg' => $e->getMessage()
  142. ]);
  143. }
  144. }
  145. public function actionOneStoreWechatSetting()
  146. {
  147. if (Yii::$app->request->getIsPost()) {
  148. $appid = post_params('one_store_wechat_appid', '');
  149. $secret = post_params('one_store_wechat_secret', '');
  150. $is_shenhe = post_params('one_store_is_shenhe', false);
  151. $switch_store = post_params('one_store_switch_store', false);
  152. $default_store = post_params('one_store_default_store', 0);
  153. $show_apply = post_params('one_store_hide_apply', 0);
  154. $one_store_lock_store = post_params('one_store_lock_store', 0);
  155. $mch_id = post_params('one_store_mch_id', '');
  156. $pay_key = post_params('one_store_pay_key', '');
  157. $apiclient_cert = post_params('one_store_apiclient_cert', '');
  158. $apiclient_key = post_params('one_store_apiclient_key', '');
  159. $apiclient_cert_url = post_params('one_store_apiclient_cert_url', '');
  160. $apiclient_key_url = post_params('one_store_apiclient_key_url', '');
  161. if (!empty($apiclient_cert_url)) {
  162. $apiclient_cert = file_get_contents($apiclient_cert_url);
  163. } else {
  164. if (!empty($apiclient_cert)) {
  165. $apiclient_cert_url = WechatConfigForm::handlePemFile($apiclient_cert);
  166. }
  167. }
  168. if (!empty($apiclient_key_url)) {
  169. $apiclient_key = file_get_contents($apiclient_key_url);
  170. } else {
  171. if (!empty($apiclient_key)) {
  172. $apiclient_key_url = WechatConfigForm::handlePemFile($apiclient_key);
  173. }
  174. }
  175. $app_appid = post_params('one_store_app_wechat_appid', '');
  176. $app_secret = post_params('one_store_app_wechat_secret', '');
  177. $app_mch_id = post_params('one_store_app_mch_id', '');
  178. $app_pay_key = post_params('one_store_app_pay_key', '');
  179. $app_apiclient_cert = post_params('one_store_app_apiclient_cert', '');
  180. $app_apiclient_key = post_params('one_store_app_apiclient_key', '');
  181. $app_apiclient_cert_url = post_params('one_store_app_apiclient_cert_url', '');
  182. $app_apiclient_key_url = post_params('one_store_app_apiclient_key_url', '');
  183. if (!empty($app_apiclient_cert_url)) {
  184. $app_apiclient_cert = file_get_contents($app_apiclient_cert_url);
  185. } else {
  186. if (!empty($app_apiclient_cert)) {
  187. $app_apiclient_cert_url = WechatConfigForm::handlePemFile($app_apiclient_cert);
  188. }
  189. }
  190. if (!empty($app_apiclient_key_url)) {
  191. $app_apiclient_key = file_get_contents($app_apiclient_key_url);
  192. } else {
  193. if (!empty($app_apiclient_key)) {
  194. $app_apiclient_key_url = WechatConfigForm::handlePemFile($app_apiclient_key);
  195. }
  196. }
  197. $one_store_app_android = post_params('one_store_app_android', '');//app下载地址 android版本
  198. $one_store_app_android_version = post_params('one_store_app_android_version', '');//安卓app版本
  199. $one_store_app_ios = post_params('one_store_app_ios', '');//app包下载地址 ios版本
  200. $one_store_wechat_h5_sub_mch_id = post_params('one_store_wechat_h5_sub_mch_id', '');
  201. $one_store_wechat_official_appid = post_params('one_store_wechat_official_appid', '');
  202. $one_store_wechat_official_secret = post_params('one_store_wechat_official_secret', '');
  203. $one_store_wechat_official_token = post_params('one_store_wechat_official_token', '');
  204. $one_store_wechat_official_auto_reply = post_params('one_store_wechat_official_auto_reply', '');
  205. $one_store_official_pay_key = post_params('one_store_official_pay_key', '');
  206. $one_store_official_apiclient_cert_url = post_params('one_store_official_apiclient_cert_url', '');
  207. $one_store_official_apiclient_key_url = post_params('one_store_official_apiclient_key_url', '');
  208. $one_store_official_apiclient_cert = post_params('one_store_official_apiclient_cert', '');
  209. $one_store_official_apiclient_key = post_params('one_store_official_apiclient_key', '');
  210. $one_store_wechat_official_sub_mch_id = post_params('one_store_wechat_official_sub_mch_id', '');
  211. if (!empty($one_store_official_apiclient_cert_url)) {
  212. $one_store_official_apiclient_cert = file_get_contents($one_store_official_apiclient_cert_url);
  213. } else {
  214. if (!empty($one_store_official_apiclient_cert)) {
  215. $one_store_official_apiclient_cert_url = WechatConfigForm::handlePemFile($one_store_official_apiclient_cert);
  216. }
  217. }
  218. if (!empty($one_store_official_apiclient_key_url)) {
  219. $one_store_official_apiclient_key = file_get_contents($one_store_official_apiclient_key_url);
  220. } else {
  221. if (!empty($one_store_official_apiclient_key)) {
  222. $one_store_official_apiclient_key_url = WechatConfigForm::handlePemFile($one_store_official_apiclient_key);
  223. }
  224. }
  225. //供应链App包上传以及版本管理
  226. $alipay = post_params('alipay');
  227. Option::set('one_store_alipay_config', json_encode($alipay), 0, 'saas');
  228. Option::set('one_store_wechat_appid', $appid, 0, 'saas');
  229. Option::set('one_store_wechat_secret', $secret, 0, 'saas');
  230. Option::set('one_store_is_shenhe', $is_shenhe ? 1 : 0, 0, 'saas');
  231. Option::set('one_store_switch_store', $switch_store ? 1 : 0, 0, 'saas');
  232. Option::set('one_store_default_store', $default_store, 0, 'saas');
  233. Option::set('one_store_mch_id', $mch_id, 0, 'saas');
  234. Option::set('one_store_pay_key', $pay_key, 0, 'saas');
  235. Option::set('one_store_apiclient_cert', $apiclient_cert, 0, 'saas');
  236. Option::set('one_store_apiclient_key', $apiclient_key, 0, 'saas');
  237. Option::set('one_store_apiclient_cert_url', $apiclient_cert_url, 0, 'saas');
  238. Option::set('one_store_apiclient_key_url', $apiclient_key_url, 0, 'saas');
  239. Option::set('one_store_hide_apply', $show_apply, 0, 'saas');
  240. Option::set('one_store_lock_store', $one_store_lock_store, 0, 'saas');
  241. //app配置
  242. Option::set('one_store_app_wechat_appid', $app_appid, 0, 'saas');
  243. Option::set('one_store_app_wechat_secret', $app_secret, 0, 'saas');
  244. Option::set('one_store_app_mch_id', $app_mch_id, 0, 'saas');
  245. Option::set('one_store_app_pay_key', $app_pay_key, 0, 'saas');
  246. Option::set('one_store_app_apiclient_cert', $app_apiclient_cert, 0, 'saas');
  247. Option::set('one_store_app_apiclient_key', $app_apiclient_key, 0, 'saas');
  248. Option::set('one_store_app_apiclient_cert_url', $app_apiclient_cert_url, 0, 'saas');
  249. Option::set('one_store_app_apiclient_key_url', $app_apiclient_key_url, 0, 'saas');
  250. Option::set('one_store_app_android', $one_store_app_android, 0, 'saas');
  251. Option::set('one_store_app_android_version', $one_store_app_android_version, 0, 'saas');
  252. Option::set('one_store_app_ios', $one_store_app_ios, 0, 'saas');
  253. Option::set('one_store_wechat_h5_sub_mch_id', $one_store_wechat_h5_sub_mch_id, 0, 'saas');
  254. //供应链
  255. Option::set('one_store_wechat_official_appid', $one_store_wechat_official_appid, 0, 'saas');
  256. Option::set('one_store_wechat_official_secret', $one_store_wechat_official_secret, 0, 'saas');
  257. Option::set('one_store_wechat_official_token', $one_store_wechat_official_token, 0, 'saas');
  258. Option::set('one_store_wechat_official_auto_reply', $one_store_wechat_official_auto_reply, 0, 'saas');
  259. Option::set('one_store_official_pay_key', $one_store_official_pay_key, 0, 'saas');
  260. Option::set('one_store_official_apiclient_cert_url', $one_store_official_apiclient_cert_url, 0, 'saas');
  261. Option::set('one_store_official_apiclient_key_url', $one_store_official_apiclient_key_url, 0, 'saas');
  262. Option::set('one_store_official_apiclient_cert', $one_store_official_apiclient_cert, 0, 'saas');
  263. Option::set('one_store_official_apiclient_key', $one_store_official_apiclient_key, 0, 'saas');
  264. Option::set('one_store_wechat_official_sub_mch_id', $one_store_wechat_official_sub_mch_id, 0, 'saas');
  265. return $this->asJson([
  266. 'code' => 0,
  267. 'msg' => '保存成功',
  268. ]);
  269. }
  270. $appid = Option::get('one_store_wechat_appid', 0, 'saas', '');
  271. $secret = Option::get('one_store_wechat_secret', 0, 'saas', '');
  272. $is_shenhe = Option::get('one_store_is_shenhe', 0, 'saas', 0);
  273. $switch_store = Option::get('one_store_switch_store', 0, 'saas', 0);
  274. $default_store = Option::get('one_store_default_store', 0, 'saas', 1)['value'];
  275. $mch_id = Option::get('one_store_mch_id', 0, 'saas', '');
  276. $pay_key = Option::get('one_store_pay_key', 0, 'saas', '');
  277. $apiclient_cert = Option::get('one_store_apiclient_cert', 0, 'saas', '');
  278. $apiclient_key = Option::get('one_store_apiclient_key', 0, 'saas', '');
  279. $apiclient_cert_url = Option::get('one_store_apiclient_cert_url', 0, 'saas', '')['value'];
  280. $apiclient_key_url= Option::get('one_store_apiclient_key_url', 0, 'saas', '')['value'];
  281. if (empty($apiclient_cert_url) && !empty($apiclient_cert['value'])) {
  282. $apiclient_cert_url = WechatConfigForm::handlePemFile($apiclient_cert['value']);
  283. }
  284. if (empty($apiclient_key_url) && !empty($apiclient_key['value'])) {
  285. $apiclient_key_url = WechatConfigForm::handlePemFile($apiclient_key['value']);
  286. }
  287. $alipay = Option::get('one_store_alipay_config', 0, 'saas', '')['value'];
  288. $show_apply = Option::get('one_store_hide_apply', 0, 'saas', '0');
  289. $one_store_lock_store = Option::get('one_store_lock_store', 0, 'saas', '0');
  290. $app_appid = Option::get('one_store_app_wechat_appid', 0, 'saas', '');
  291. $app_secret = Option::get('one_store_app_wechat_secret', 0, 'saas', '');
  292. $app_mch_id = Option::get('one_store_app_mch_id', 0, 'saas', '');
  293. $app_pay_key = Option::get('one_store_app_pay_key', 0, 'saas', '');
  294. $app_apiclient_cert = Option::get('one_store_app_apiclient_cert', 0, 'saas', '');
  295. $app_apiclient_key = Option::get('one_store_app_apiclient_key', 0, 'saas', '');
  296. $app_apiclient_cert_url = Option::get('one_store_app_apiclient_cert_url', 0, 'saas', '')['value'];
  297. $app_apiclient_key_url = Option::get('one_store_app_apiclient_key_url', 0, 'saas', '')['value'];
  298. if (empty($app_apiclient_cert_url) && !empty($app_apiclient_cert['value'])) {
  299. $app_apiclient_cert_url = WechatConfigForm::handlePemFile($app_apiclient_cert['value']);
  300. }
  301. if (empty($app_apiclient_key_url) && !empty($app_apiclient_key['value'])) {
  302. $app_apiclient_key_url = WechatConfigForm::handlePemFile($app_apiclient_key['value']);
  303. }
  304. $one_store_app_android = Option::get('one_store_app_android', 0, 'saas', '');
  305. $one_store_app_android_version = Option::get('one_store_app_android_version', 0, 'saas', '');
  306. $one_store_app_ios = Option::get('one_store_app_ios', 0, 'saas', '');
  307. $one_store_wechat_h5_sub_mch_id = Option::get('one_store_wechat_h5_sub_mch_id', 0, 'saas', '');
  308. $one_store_wechat_official_appid = Option::get('one_store_wechat_official_appid', 0, 'saas', '');
  309. $one_store_wechat_official_secret = Option::get('one_store_wechat_official_secret', 0, 'saas', '');
  310. $one_store_wechat_official_token = Option::get('one_store_wechat_official_token', 0, 'saas', '');
  311. $one_store_wechat_official_auto_reply = Option::get('one_store_wechat_official_auto_reply', 0, 'saas', '');
  312. //供应链公众号设置需要显示服务器地址以及支付目录
  313. $one_store_official_server_url = 'https://' . \Yii::$app->request->hostName . '/index.php?r=common/wechat-callback/index&store_id=0';
  314. $one_store_official_pay_url = 'https://' . \Yii::$app->request->hostName . '/';
  315. $one_store_official_pay_key = Option::get('one_store_official_pay_key', 0, 'saas', '');
  316. $one_store_official_apiclient_cert_url = Option::get('one_store_official_apiclient_cert_url', 0, 'saas', '');
  317. $one_store_official_apiclient_key_url = Option::get('one_store_official_apiclient_key_url', 0, 'saas', '');
  318. $one_store_official_apiclient_cert = Option::get('one_store_official_apiclient_cert', 0, 'saas', '');
  319. $one_store_official_apiclient_key = Option::get('one_store_official_apiclient_key', 0, 'saas', '');
  320. $one_store_wechat_official_sub_mch_id = Option::get('one_store_wechat_official_sub_mch_id', 0, 'saas', '');
  321. if (empty($alipay)) {
  322. $alipay = [
  323. 'aes_key' => '',
  324. 'alipay_public_key' => '',
  325. 'app_id' => '',
  326. 'app_private_key' => '',
  327. 'app_public_key' => '',
  328. 'name' => '',
  329. 'user_id' => '',
  330. 'one_store_is_shenhe' => false,
  331. 'one_store_lock_store' => 0
  332. ];
  333. } else {
  334. $alipay = json_decode($alipay, true);
  335. }
  336. return $this->asJson([
  337. 'code' => 0,
  338. 'msg' => 'success',
  339. 'data' => [
  340. 'one_store_wechat_appid' => $appid['value'],
  341. 'one_store_wechat_secret' => $secret['value'],
  342. 'one_store_is_shenhe' => (bool)$is_shenhe['value'],
  343. 'one_store_switch_store' => (bool)$switch_store['value'],
  344. 'one_store_default_store' => $default_store ?: '1',
  345. 'one_store_mch_id' => $mch_id['value'],
  346. 'one_store_pay_key' => $pay_key['value'],
  347. 'one_store_apiclient_cert' => $apiclient_cert['value'],
  348. 'one_store_apiclient_key' => $apiclient_key['value'],
  349. 'one_store_apiclient_cert_url' => $apiclient_cert_url,
  350. 'one_store_apiclient_key_url' => $apiclient_key_url,
  351. 'alipay' => $alipay,
  352. 'one_store_hide_apply' => (string)$show_apply['value'],
  353. 'one_store_lock_store' => (int)$one_store_lock_store['value'],
  354. 'one_store_app_wechat_appid' => $app_appid['value'],
  355. 'one_store_app_wechat_secret' => $app_secret['value'],
  356. 'one_store_app_mch_id' => $app_mch_id['value'],
  357. 'one_store_app_pay_key' => $app_pay_key['value'],
  358. 'one_store_app_apiclient_cert' => $app_apiclient_cert['value'],
  359. 'one_store_app_apiclient_key' => $app_apiclient_key['value'],
  360. 'one_store_app_apiclient_cert_url' => $app_apiclient_cert_url,
  361. 'one_store_app_apiclient_key_url' => $app_apiclient_key_url,
  362. 'one_store_app_android' => $one_store_app_android['value'],
  363. 'one_store_app_android_version' => $one_store_app_android_version['value'],
  364. 'one_store_app_ios' => $one_store_app_ios['value'],
  365. 'one_store_wechat_h5_sub_mch_id' => $one_store_wechat_h5_sub_mch_id['value'],
  366. 'one_store_wechat_official_appid' => $one_store_wechat_official_appid['value'],
  367. 'one_store_wechat_official_secret' => $one_store_wechat_official_secret['value'],
  368. 'one_store_wechat_official_token' => $one_store_wechat_official_token['value'],
  369. 'one_store_wechat_official_auto_reply' => $one_store_wechat_official_auto_reply['value'],
  370. 'one_store_official_server_url' => $one_store_official_server_url,
  371. 'one_store_official_pay_url' => $one_store_official_pay_url,
  372. 'one_store_official_pay_key' => $one_store_official_pay_key['value'],
  373. 'one_store_official_apiclient_cert_url' => $one_store_official_apiclient_cert_url['value'],
  374. 'one_store_official_apiclient_key_url' => $one_store_official_apiclient_key_url['value'],
  375. 'one_store_official_apiclient_cert' => $one_store_official_apiclient_cert['value'],
  376. 'one_store_official_apiclient_key' => $one_store_official_apiclient_key['value'],
  377. 'one_store_wechat_official_sub_mch_id' => $one_store_wechat_official_sub_mch_id['value'],
  378. ],
  379. ]);
  380. }
  381. /**
  382. * 设置联盟入驻协议
  383. *
  384. */
  385. public function actionUnionProtocol()
  386. {
  387. if (Yii::$app->request->getIsPost()) {
  388. $protocol = post_params('protocol', '');
  389. $describe = post_params('describe', '');
  390. $name = post_params('name', '');
  391. $logo = post_params('logo', '');
  392. $help_logo = post_params('help_logo', '');
  393. $union_client_loading_logo = post_params('union_client_loading_logo', '');
  394. $admin_logo = post_params('admin_logo', '');
  395. $admin_copyright = post_params('admin_copyright', '');
  396. $search_keyword = post_params('search_keyword', []);
  397. $lang = post_params('lang', 'zh-CN');
  398. $shenhe = post_params('shenhe', 0);
  399. $is_show_kefu_download = post_params('is_show_kefu_download', 1);
  400. // $tencent_map_key = post_params('tencent_map_key', '');
  401. Option::set('protocol', $protocol, 0, 'saas');
  402. Option::set('store_apply_agreement', $protocol, 0, 'saas');
  403. Option::set('describe', $describe, 0, 'saas');
  404. Option::set('name', $name, 0, 'saas');
  405. Option::set('logo', $logo, 0, 'saas');
  406. Option::set('help_logo', $help_logo, 0, 'saas');
  407. Option::set('union_client_loading_logo', $union_client_loading_logo, 0, 'saas');
  408. Option::set('admin_copyright', $admin_copyright, 0, 'saas');
  409. Option::set('admin_logo', $admin_logo, 0, 'saas');
  410. Option::set('lang', $lang, 0, 'saas');
  411. Option::set('lang', $lang, 0, 'saas');
  412. Option::set('search_keyword', json_encode($search_keyword), 0, 'saas');
  413. Option::set('shenhe', $shenhe, 0, 'saas');
  414. Option::set('is_show_kefu_download', $is_show_kefu_download, 0, 'saas');
  415. // Option::set('tencent_map_key', $tencent_map_key, 0, 'saas');
  416. return $this->asJson([
  417. 'code' => 0,
  418. 'msg' => '保存成功',
  419. ]);
  420. } else {
  421. $protocol = Option::get('protocol', 0, 'saas', '');
  422. $describe = Option::get('describe', 0, 'saas', '');
  423. $name = Option::get('name', 0, 'saas', '');
  424. $logo = Option::get('logo', 0, 'saas', '');
  425. $help_logo = Option::get('help_logo', 0, 'saas', '');
  426. $union_client_loading_logo = Option::get('union_client_loading_logo', 0, 'saas', '');
  427. $admin_logo = Option::get('admin_logo', 0, 'saas', '');
  428. $admin_copyright = Option::get('admin_copyright', 0, 'saas', '');
  429. $lang = Option::get('lang', 0, 'saas', 'zh-CN');
  430. $search_keyword = Option::get('search_keyword', 0, 'saas', json_encode([]));
  431. $shenhe = Option::get('shenhe', 0, 'saas', 0);
  432. $is_show_kefu_download = Option::get('is_show_kefu_download', 0, 'saas', 1);
  433. // $tencent_map_key = Option::get('tencent_map_key', 0, 'saas', '');
  434. return $this->asJson([
  435. 'code' => 0,
  436. 'msg' => 'success',
  437. 'data' => [
  438. 'protocol' => $protocol['value'],
  439. 'describe' => $describe['value'],
  440. 'name' => $name['value'],
  441. 'logo' => $logo['value'],
  442. 'help_logo' => $help_logo['value'],
  443. 'union_client_loading_logo' => $union_client_loading_logo['value'],
  444. 'admin_logo' => $admin_logo['value'],
  445. 'admin_copyright' => $admin_copyright['value'],
  446. 'lang' => $lang['value'],
  447. 'shenhe' => (int)$shenhe['value'],
  448. 'search_keyword' => json_decode($search_keyword['value']),
  449. 'is_show_kefu_download' => intval($is_show_kefu_download['value'])
  450. // 'tencent_map_key' => $tencent_map_key['value']
  451. ]
  452. ]);
  453. }
  454. }
  455. public function actionUnionProtocolStore()
  456. {
  457. if(\Yii::$app->isSaas()){
  458. // return;
  459. }
  460. if (Yii::$app->request->getIsPost()) {
  461. $describe = post_params('describe', '');
  462. $help_logo = post_params('help_logo', '');
  463. Option::set('describe', $describe, 0, 'saas');
  464. Option::set('help_logo', $help_logo, 0, 'saas');
  465. return $this->asJson([
  466. 'code' => 0,
  467. 'msg' => '保存成功',
  468. ]);
  469. } else {
  470. $describe = Option::get('describe', 0, 'saas', '');
  471. $help_logo = Option::get('help_logo', 0, 'saas', '');
  472. return $this->asJson([
  473. 'code' => 0,
  474. 'msg' => 'success',
  475. 'data' => [
  476. 'describe' => $describe['value'],
  477. 'help_logo' => $help_logo['value'],
  478. ]
  479. ]);
  480. }
  481. }
  482. public function actionSaasMapSetting() {
  483. $tencent_map_key = Option::get('tencent_map_key', 0, 'saas', '');
  484. if (Yii::$app->request->getIsPost()) {
  485. $tencent_map_key = post_params('tencent_map_key', '');
  486. $amap_key = post_params('amap_key', '');
  487. $amap_security_js_code = post_params('amap_security_js_code', '');
  488. $amap_service_host = post_params('amap_service_host', '');
  489. Option::set('tencent_map_key', $tencent_map_key, 0, 'saas');
  490. Option::set('amap_key', $amap_key, 0, 'saas');
  491. Option::set('amap_security_js_code', $amap_security_js_code, 0, 'saas');
  492. Option::set('amap_service_host', $amap_service_host, 0, 'saas');
  493. // 更新h5的腾讯地图key
  494. \app\utils\UpdateAfter::UpdateQQMapKey($tencent_map_key);
  495. return $this->asJson([
  496. 'code' => 0,
  497. 'msg' => '保存成功',
  498. ]);
  499. } else {
  500. $amap_key = Option::get('amap_key', 0, 'saas', '');
  501. $amap_security_js_code = Option::get('amap_security_js_code', 0, 'saas', '');
  502. $amap_service_host = Option::get('amap_service_host', 0, 'saas', '');
  503. return $this->asJson([
  504. 'code' => 0,
  505. 'msg' => 'success',
  506. 'data' => [
  507. 'tencent_map_key' => $tencent_map_key['value'],
  508. 'amap_key' => $amap_key['value'],
  509. 'amap_security_js_code' => $amap_security_js_code['value'],
  510. 'amap_service_host' => $amap_service_host['value'],
  511. ]
  512. ]);
  513. }
  514. }
  515. /**
  516. * 设置银行卡信息(服务商)
  517. *
  518. * @return void
  519. */
  520. public function actionBankSetting()
  521. {
  522. if (Yii::$app->request->getIsPost()) {
  523. $conf = post_params('conf', []);
  524. $set = SaasForm::bankSettingSave(1, 0, $conf);
  525. return $this->asJson([
  526. 'code' => 0,
  527. 'msg' => '保存成功',
  528. 'set' => $set,
  529. ]);
  530. } else {
  531. return $this->asJson([
  532. 'code' => 0,
  533. 'msg' => 'success',
  534. 'data' => SaasForm::bankSetting(1),
  535. 'store_id' => get_store_id(),
  536. ]);
  537. }
  538. }
  539. /**
  540. * 设置通联配置信息(服务商)
  541. *
  542. * @return void
  543. */
  544. public function actionYunstSetting()
  545. {
  546. if (Yii::$app->request->getIsPost()) {
  547. $conf = post_params('content', []);
  548. $set = SaasForm::yunstSettingSave(1, 0, $conf);
  549. return $this->asJson([
  550. 'code' => 0,
  551. 'msg' => '保存成功',
  552. 'set' => $set,
  553. ]);
  554. } else {
  555. return $this->asJson([
  556. 'code' => 0,
  557. 'msg' => 'success',
  558. 'data' => SaasForm::yunstSetting(1),
  559. 'store_id' => get_store_id(),
  560. ]);
  561. }
  562. }
  563. /**
  564. * 设置银行卡信息(店铺)
  565. *
  566. * @return void
  567. */
  568. public function actionStoreBankSetting()
  569. {
  570. $store_id = get_store_id();
  571. if (Yii::$app->request->getIsPost()) {
  572. $conf = post_params('conf', []);
  573. $set = SaasForm::bankSettingSave(0, $store_id, $conf);
  574. return $this->asJson([
  575. 'code' => 0,
  576. 'msg' => '保存成功',
  577. 'set' => $set,
  578. ]);
  579. } else {
  580. return $this->asJson([
  581. 'code' => 0,
  582. 'msg' => 'success',
  583. 'data' => SaasForm::bankSetting(0, $store_id),
  584. 'store_id' => get_store_id(),
  585. ]);
  586. }
  587. }
  588. /**
  589. * 设置线下转账信息(店铺)
  590. *
  591. * @return void
  592. */
  593. public function actionOfflineSetting()
  594. {
  595. $store_id = get_store_id();
  596. if (Yii::$app->request->getIsPost()) {
  597. $conf = post_params('conf', []);
  598. $set = SaasForm::offlineSettingSave($store_id, $conf);
  599. return $this->asJson([
  600. 'code' => 0,
  601. 'msg' => '保存成功',
  602. 'set' => $set,
  603. ]);
  604. } else {
  605. return $this->asJson([
  606. 'code' => 0,
  607. 'msg' => 'success',
  608. 'data' => ['conf' => SaasForm::offlineSetting($store_id)],
  609. 'store_id' => get_store_id(),
  610. ]);
  611. }
  612. }
  613. /**
  614. * 设置微信支付信息(服务商)
  615. *
  616. * @return void
  617. */
  618. public function actionWechatSetting()
  619. {
  620. if (Yii::$app->request->getIsPost()) {
  621. $sp_name = post_params('sp_name', '');
  622. $sp_appid = post_params('sp_appid', '');
  623. $sp_mch_id = post_params('sp_mch_id', '');
  624. $sp_key = post_params('sp_key', '');
  625. $sp_apiclient_cert = post_params('sp_apiclient_cert', '');
  626. $sp_apiclient_key = post_params('sp_apiclient_key', '');
  627. $sp_apiclient_cert_url = post_params('sp_apiclient_cert_url', '');
  628. $sp_apiclient_key_url = post_params('sp_apiclient_key_url', '');
  629. if (!empty($sp_apiclient_cert_url)) {
  630. $sp_apiclient_cert = file_get_contents($sp_apiclient_cert_url);
  631. } else {
  632. if (!empty($sp_apiclient_cert)) {
  633. $sp_apiclient_cert_url = WechatConfigForm::handlePemFile($sp_apiclient_cert);
  634. }
  635. }
  636. if (!empty($sp_apiclient_key_url)) {
  637. $sp_apiclient_key = file_get_contents($sp_apiclient_key_url);
  638. } else {
  639. if (!empty($sp_apiclient_key)) {
  640. $sp_apiclient_key_url = WechatConfigForm::handlePemFile($sp_apiclient_key);
  641. }
  642. }
  643. $platform_public_key = post_params('platform_public_key', '');
  644. $platform_public_key_id = post_params('platform_public_key_id', '');
  645. $platform_api_key = post_params('platform_api_key', '');
  646. $platform_serial_no = post_params('platform_serial_no', '');
  647. $pay_rate = post_params('pay_rate', '0.2');
  648. $pay_rate = sprintf('%.2f', $pay_rate); //保留两位
  649. //$pay_rate < 0.2 ||
  650. if ($pay_rate < 0 || $pay_rate > 0.6) {
  651. return $this->asJson([
  652. 'code' => 1,
  653. 'msg' => '默认支付费率应在0 ~ 0.6区间',
  654. ]);
  655. }
  656. Option::set([
  657. 'sp_name',
  658. 'sp_appid',
  659. 'sp_mch_id',
  660. 'sp_key',
  661. 'sp_apiclient_cert',
  662. 'sp_apiclient_key',
  663. 'sp_apiclient_cert_url',
  664. 'sp_apiclient_key_url',
  665. 'platform_public_key',
  666. 'platform_public_key_id',
  667. 'platform_api_key',
  668. 'platform_serial_no',
  669. 'pay_rate'
  670. ], [
  671. $sp_name,
  672. $sp_appid,
  673. $sp_mch_id,
  674. $sp_key,
  675. $sp_apiclient_cert,
  676. $sp_apiclient_key,
  677. $sp_apiclient_cert_url,
  678. $sp_apiclient_key_url,
  679. $platform_public_key,
  680. $platform_public_key_id,
  681. $platform_api_key,
  682. $platform_serial_no,
  683. $pay_rate
  684. ], 0, 'saas');
  685. return $this->asJson([
  686. 'code' => 0,
  687. 'msg' => '保存成功',
  688. ]);
  689. } else {
  690. $keys = [
  691. 'sp_name',
  692. 'sp_appid',
  693. 'sp_mch_id',
  694. 'sp_key',
  695. 'sp_apiclient_cert',
  696. 'sp_apiclient_key',
  697. 'sp_apiclient_cert_url',
  698. 'sp_apiclient_key_url',
  699. 'platform_public_key',
  700. 'platform_public_key_id',
  701. 'platform_api_key',
  702. 'platform_serial_no',
  703. 'pay_rate'
  704. ];
  705. $data = Option::get($keys, 0, 'saas');
  706. if (empty($data)) {
  707. $data = [
  708. 'sp_name' => '',
  709. 'sp_appid' => '',
  710. 'sp_mch_id' => '',
  711. 'sp_key' => '',
  712. 'sp_apiclient_cert' => '',
  713. 'sp_apiclient_key' => '',
  714. 'sp_apiclient_cert_url' => '',
  715. 'sp_apiclient_key_url' => '',
  716. 'platform_public_key'=>"",
  717. 'platform_public_key_id'=>"",
  718. 'platform_api_key'=>"",
  719. 'platform_serial_no'=>"",
  720. 'pay_rate' => '0.2'
  721. ];
  722. } else {
  723. $arr = [];
  724. foreach ($data as $value) {
  725. $index = array_search($value['name'], $keys);
  726. unset($keys[$index]);
  727. $arr[$value['name']] = $value['value'];
  728. }
  729. foreach ($keys as $key) {
  730. $arr[$key] = '';
  731. }
  732. if (empty($arr['sp_apiclient_cert_url']) && !empty($arr['sp_apiclient_cert'])) {
  733. $arr['sp_apiclient_cert_url'] = WechatConfigForm::handlePemFile($arr['sp_apiclient_cert']);
  734. }
  735. if (empty($arr['sp_apiclient_key_url']) && !empty($arr['sp_apiclient_key'])) {
  736. $arr['sp_apiclient_key_url'] = WechatConfigForm::handlePemFile($arr['sp_apiclient_key']);
  737. }
  738. $data = $arr;
  739. }
  740. return $this->asJson([
  741. 'code' => 0,
  742. 'msg' => 'success',
  743. 'data' => $data,
  744. ]);
  745. }
  746. }
  747. /**
  748. * 设置地址识别配置
  749. *
  750. * @return void
  751. */
  752. public function actionAddressRecognitionSetting()
  753. {
  754. if (Yii::$app->request->getIsPost()) {
  755. $kuaidi100_secret_key = post_params(OptionSetting::KUAIDI100_SECRET_KEY, '');
  756. $kuaidi100_secret_code = post_params(OptionSetting::KUAIDI100_SECRET_CODE, '');
  757. $kuaidi100_secret_secret = post_params(OptionSetting::KUAIDI100_SECRET_SECRET, '');
  758. $kuaidi100_secret_sign = post_params(OptionSetting::KUAIDI100_SECRET_SIGN, '');
  759. Option::set([
  760. OptionSetting::KUAIDI100_SECRET_KEY,
  761. OptionSetting::KUAIDI100_SECRET_CODE,
  762. OptionSetting::KUAIDI100_SECRET_SECRET,
  763. OptionSetting::KUAIDI100_SECRET_SIGN
  764. ], [
  765. $kuaidi100_secret_key,
  766. $kuaidi100_secret_code,
  767. $kuaidi100_secret_secret,
  768. $kuaidi100_secret_sign,
  769. ], 0, 'saas');
  770. return $this->asJson([
  771. 'code' => 0,
  772. 'msg' => '保存成功',
  773. ]);
  774. } else {
  775. $keys = [
  776. OptionSetting::KUAIDI100_SECRET_KEY,
  777. OptionSetting::KUAIDI100_SECRET_CODE,
  778. OptionSetting::KUAIDI100_SECRET_SECRET,
  779. OptionSetting::KUAIDI100_SECRET_SIGN,
  780. ];
  781. $data = Option::get($keys, 0, 'saas');
  782. if (empty($data)) {
  783. $data = [
  784. OptionSetting::KUAIDI100_SECRET_KEY => '',
  785. OptionSetting::KUAIDI100_SECRET_CODE => '',
  786. OptionSetting::KUAIDI100_SECRET_SECRET => '',
  787. OptionSetting::KUAIDI100_SECRET_SIGN => '',
  788. ];
  789. } else {
  790. $arr = [];
  791. foreach ($data as $value) {
  792. $index = array_search($value['name'], $keys);
  793. unset($keys[$index]);
  794. $arr[$value['name']] = $value['value'];
  795. }
  796. foreach ($keys as $key) {
  797. $arr[$key] = '';
  798. }
  799. $data = $arr;
  800. }
  801. return $this->asJson([
  802. 'code' => 0,
  803. 'msg' => 'success',
  804. 'data' => $data,
  805. ]);
  806. }
  807. }
  808. /**
  809. * 店铺缴费设置
  810. *
  811. * @return void
  812. */
  813. public function actionStoreReOrder()
  814. {
  815. if (Yii::$app->request->getIsPost()) {
  816. $open_price = post_params('open_price', '0.00');
  817. $profit = post_params('profit', '0.00');
  818. $renew_price = post_params('renew_price', '0.00');
  819. Option::set([
  820. 'open_price',
  821. 'profit',
  822. 'renew_price'
  823. ], [
  824. $open_price,
  825. $profit,
  826. $renew_price,
  827. ], 0, 'saas');
  828. return $this->asJson([
  829. 'code' => 0,
  830. 'msg' => '保存成功',
  831. ]);
  832. } else {
  833. $keys = [
  834. 'open_price',
  835. 'profit',
  836. 'renew_price'
  837. ];
  838. $data = Option::get($keys, 0, 'saas');
  839. if (empty($data)) {
  840. $data = [
  841. 'open_price' => '0.00',
  842. 'profit' => '0.00',
  843. 'renew_price' => '0.00'
  844. ];
  845. } else {
  846. $arr = [];
  847. foreach ($data as $value) {
  848. $index = array_search($value['name'], $keys);
  849. unset($keys[$index]);
  850. $arr[$value['name']] = $value['value'];
  851. }
  852. foreach ($keys as $key) {
  853. $arr[$key] = '';
  854. }
  855. $data = $arr;
  856. }
  857. return $this->asJson([
  858. 'code' => 0,
  859. 'msg' => 'success',
  860. 'data' => $data,
  861. ]);
  862. }
  863. }
  864. /**
  865. * 店铺让利比例设置
  866. *
  867. * @return void
  868. */
  869. public function actionStoreTransferProfitParams()
  870. {
  871. if (Yii::$app->request->getIsPost()) {
  872. $transfer_profit = post_params('transfer_profit', '0.00');
  873. Option::set([
  874. 'transfer_profit'
  875. ], [
  876. $transfer_profit
  877. ], -1, OptionSetting::SHARE_GROUP_NAME);
  878. return $this->asJson([
  879. 'code' => 0,
  880. 'msg' => '保存成功',
  881. ]);
  882. } else {
  883. $data = Option::get('transfer_profit', -1, OptionSetting::SHARE_GROUP_NAME)['value'];
  884. if (empty($data)) {
  885. $data = '0.00';
  886. } else {
  887. $data = json_decode($data, true);
  888. }
  889. return $this->asJson([
  890. 'code' => 0,
  891. 'msg' => 'success',
  892. 'data' => $data,
  893. ]);
  894. }
  895. }
  896. /**
  897. * 店铺分销默认设置
  898. *
  899. * @return void
  900. */
  901. public function actionStoreDefaultParams()
  902. {
  903. $data = Option::get(OptionSetting::SHARE_STORE_DEFAULT_SETTING, -1, OptionSetting::SHARE_GROUP_NAME)['value'];
  904. if (empty($data)) {
  905. $data = [
  906. 'store_share_switch' => '0',
  907. 'store_share_type' => '0',
  908. 'store_share_value' => '0'
  909. ];
  910. } else {
  911. $data = json_decode($data, true);
  912. }
  913. return $this->asJson([
  914. 'code' => 0,
  915. 'msg' => 'success',
  916. 'data' => $data,
  917. ]);
  918. }
  919. public function actionGetProfitSetting()
  920. {
  921. // $store_recharge_profit_model = Option::findOne(['name' => 'store_recharge_profit']);
  922. $store_profit_max_model = Option::findOne(['name' => 'store_profit_max']);
  923. $store_profit_min_model = Option::findOne(['name' => 'store_profit_min']);
  924. $store_send_min_model = Option::findOne(['name' => 'store_send_min']);
  925. // $store_send_profit_model = Option::findOne(['name' => 'store_send_profit']);
  926. $data = [
  927. // 'store_recharge_profit' => $store_recharge_profit_model->value,
  928. 'store_profit_max' => $store_profit_max_model->value,
  929. 'store_profit_min' => $store_profit_min_model->value,
  930. 'store_send_min' => $store_send_min_model->value,
  931. 'store_send_profit' => 100,
  932. ];
  933. return $this->asJson([
  934. 'code' => 0,
  935. 'msg' => 'success',
  936. 'data' => $data,
  937. ]);
  938. }
  939. /**
  940. * 联盟分销默认设置
  941. *
  942. * @return void
  943. */
  944. public function actionSaasDefaultParams()
  945. {
  946. $data = Option::get(OptionSetting::SHARE_SAAS_DEFAULT_SETTING, -1, OptionSetting::SHARE_GROUP_NAME)['value'];
  947. if (empty($data)) {
  948. $data = [
  949. 'is_rebate' => 0,
  950. 'level' => 1,
  951. 'level_one' => "0.00",
  952. 'level_three' => "0.00",
  953. 'level_two' => "0.00",
  954. 'price_type' => 0
  955. ];
  956. } else {
  957. $data = json_decode($data, true);
  958. }
  959. return $this->asJson([
  960. 'code' => 0,
  961. 'msg' => 'success',
  962. 'data' => $data,
  963. ]);
  964. }
  965. /**
  966. * 店铺推荐人分销默认设置
  967. *
  968. * @return void
  969. */
  970. public function actionSaasReferralDefaultParams()
  971. {
  972. $data = Option::get(OptionSetting::SHARE_SAAS_REFERRAL_DEFAULT_SETTING, -1, OptionSetting::SHARE_GROUP_NAME)['value'];
  973. if (empty($data)) {
  974. $data = [
  975. 'is_enable' => '0',
  976. 'referral_rebate' => '0'
  977. ];
  978. } else {
  979. $data = json_decode($data, true);
  980. }
  981. return $this->asJson([
  982. 'code' => 0,
  983. 'msg' => 'success',
  984. 'data' => $data,
  985. ]);
  986. }
  987. /**
  988. * 供货商推荐人分销默认设置
  989. *
  990. * @return void
  991. */
  992. public function actionSaasSupplierReferralDefaultParams()
  993. {
  994. $data = Option::get(OptionSetting::SHARE_SAAS_SUPPLIER_REFERRAL_DEFAULT_SETTING, -1, OptionSetting::SHARE_GROUP_NAME)['value'];
  995. if (empty($data)) {
  996. $data = [
  997. 'is_enable' => '0',
  998. 'referral_rebate' => '0'
  999. ];
  1000. } else {
  1001. $data = json_decode($data, true);
  1002. }
  1003. return $this->asJson([
  1004. 'code' => 0,
  1005. 'msg' => 'success',
  1006. 'data' => $data,
  1007. ]);
  1008. }
  1009. /**
  1010. * 消费返利分销默认设置
  1011. *
  1012. * @return void
  1013. */
  1014. public function actionSelfRebateDefaultParams()
  1015. {
  1016. $data = Option::get(OptionSetting::SHARE_SELF_REBATE_DEFAULT_SETTING, -1, OptionSetting::SHARE_GROUP_NAME)['value'];
  1017. if (empty($data)) {
  1018. $data = [
  1019. 'self_rebate_switch' => '0',
  1020. 'self_rebate_value' => '0'
  1021. ];
  1022. } else {
  1023. $data = json_decode($data, true);
  1024. }
  1025. return $this->asJson([
  1026. 'code' => 0,
  1027. 'msg' => 'success',
  1028. 'data' => $data,
  1029. ]);
  1030. }
  1031. /**
  1032. * 设置支付宝商盟小程序客户端
  1033. *
  1034. */
  1035. public function actionAlipayPlatformSetting()
  1036. {
  1037. if (Yii::$app->request->getIsPost()) {
  1038. $info = post_params();
  1039. $info = json_encode($info);
  1040. Option::set([
  1041. 'alipay_platform',
  1042. ], [
  1043. $info
  1044. ], 0, 'saas');
  1045. return $this->asJson([
  1046. 'code' => 0,
  1047. 'msg' => '保存成功',
  1048. ]);
  1049. }else{
  1050. $keys = [
  1051. 'alipay_platform'
  1052. ];
  1053. $data = Option::get($keys, 0, 'saas');
  1054. return $this->asJson([
  1055. 'code' => 0,
  1056. 'msg' => 'success',
  1057. 'data' => isset($data[0]) ? json_decode($data[0]['value'],true) : NULL
  1058. ]);
  1059. }
  1060. }
  1061. /**
  1062. * 设置支付宝服务商
  1063. *
  1064. */
  1065. public function actionAlipaySetting()
  1066. {
  1067. if (Yii::$app->request->getIsPost()) {
  1068. $alipay_appid = post_params('alipay_appid', '');
  1069. $alipay_public_key = post_params('alipay_public_key', '');
  1070. $alipay_app_public_key = post_params('alipay_app_public_key', '');
  1071. $alipay_app_private_key = post_params('alipay_app_private_key', '');
  1072. $alipay_user_id = post_params('alipay_user_id', '');
  1073. $alipay_aes_key = post_params('alipay_aes_key', '');
  1074. $name = post_params('alipay_name', '');
  1075. if (empty($alipay_user_id) || empty($name)) {
  1076. return $this->asJson([
  1077. 'code' => 1,
  1078. 'msg' => '务必完善企业名称和USER_ID'
  1079. ]);
  1080. }
  1081. Option::set([
  1082. 'alipay_appid',
  1083. 'alipay_public_key',
  1084. 'alipay_app_public_key',
  1085. 'alipay_app_private_key',
  1086. 'alipay_user_id',
  1087. 'alipay_name',
  1088. 'alipay_aes_key'
  1089. ], [
  1090. $alipay_appid,
  1091. $alipay_public_key,
  1092. $alipay_app_public_key,
  1093. $alipay_app_private_key,
  1094. $alipay_user_id,
  1095. $name,
  1096. $alipay_aes_key
  1097. ], 0, 'saas');
  1098. return $this->asJson([
  1099. 'code' => 0,
  1100. 'msg' => '保存成功',
  1101. ]);
  1102. } else {
  1103. $keys = [
  1104. 'alipay_appid',
  1105. 'alipay_public_key',
  1106. 'alipay_app_public_key',
  1107. 'alipay_app_private_key',
  1108. 'alipay_user_id',
  1109. 'alipay_name',
  1110. 'alipay_aes_key'
  1111. ];
  1112. $data = Option::get($keys, 0, 'saas');
  1113. if (empty($data)) {
  1114. $data = [
  1115. 'alipay_appid' => '',
  1116. 'alipay_public_key' => '',
  1117. 'alipay_app_public_key' => '',
  1118. 'alipay_app_private_key' => '',
  1119. 'alipay_user_id' => '',
  1120. 'alipay_name' => '',
  1121. 'alipay_aes_key'=>''
  1122. ];
  1123. } else {
  1124. $arr = [];
  1125. foreach ($data as $value) {
  1126. $index = array_search($value['name'], $keys);
  1127. unset($keys[$index]);
  1128. $arr[$value['name']] = $value['value'];
  1129. }
  1130. foreach ($keys as $key) {
  1131. $arr[$key] = '';
  1132. }
  1133. $data = $arr;
  1134. }
  1135. return $this->asJson([
  1136. 'code' => 0,
  1137. 'msg' => 'success',
  1138. 'data' => $data,
  1139. ]);
  1140. }
  1141. }
  1142. /**
  1143. * 设置微信支付信息(用于提现)
  1144. *
  1145. * @return void
  1146. */
  1147. public function actionWechatPlatformSetting()
  1148. {
  1149. if (Yii::$app->request->getIsPost()) {
  1150. $platform_app_appid = post_params('platform_app_appid', '');
  1151. $platform_appid = post_params('platform_appid', '');
  1152. $platform_mch_id = post_params('platform_mch_id', '');
  1153. $platform_key = post_params('platform_key', '');
  1154. $platform_apiclient_cert = post_params('platform_apiclient_cert', '');
  1155. $platform_apiclient_key = post_params('platform_apiclient_key', '');
  1156. $platform_apiclient_cert_url = post_params('platform_apiclient_cert_url', '');
  1157. $platform_apiclient_key_url = post_params('platform_apiclient_key_url', '');
  1158. $platform_pay_key = post_params('platform_pay_key', '');
  1159. $platform_gh_id = post_params('platform_gh_id', '');
  1160. if (!empty($platform_apiclient_cert_url)) {
  1161. $platform_apiclient_cert = file_get_contents($platform_apiclient_cert_url);
  1162. } else {
  1163. if (!empty($platform_apiclient_cert)) {
  1164. $platform_apiclient_cert_url = WechatConfigForm::handlePemFile($platform_apiclient_cert);
  1165. }
  1166. }
  1167. if (!empty($platform_apiclient_key_url)) {
  1168. $platform_apiclient_key = file_get_contents($platform_apiclient_key_url);
  1169. } else {
  1170. if (!empty($platform_apiclient_key)) {
  1171. $platform_apiclient_key_url = WechatConfigForm::handlePemFile($platform_apiclient_key);
  1172. }
  1173. }
  1174. Option::set([
  1175. 'platform_appid',
  1176. 'platform_mch_id',
  1177. 'platform_key',
  1178. 'platform_apiclient_cert',
  1179. 'platform_apiclient_key',
  1180. 'platform_apiclient_cert_url',
  1181. 'platform_apiclient_key_url',
  1182. 'platform_pay_key',
  1183. 'platform_app_appid',
  1184. 'platform_gh_id'
  1185. ], [
  1186. $platform_appid,
  1187. $platform_mch_id,
  1188. $platform_key,
  1189. $platform_apiclient_cert,
  1190. $platform_apiclient_key,
  1191. $platform_apiclient_cert_url,
  1192. $platform_apiclient_key_url,
  1193. $platform_pay_key,
  1194. $platform_app_appid,
  1195. $platform_gh_id
  1196. ], 0, 'saas');
  1197. return $this->asJson([
  1198. 'code' => 0,
  1199. 'msg' => '保存成功',
  1200. ]);
  1201. } else {
  1202. $keys = [
  1203. 'platform_appid',
  1204. 'platform_mch_id',
  1205. 'platform_key',
  1206. 'platform_apiclient_cert',
  1207. 'platform_apiclient_key',
  1208. 'platform_apiclient_cert_url',
  1209. 'platform_apiclient_key_url',
  1210. 'platform_pay_key',
  1211. 'platform_app_appid',
  1212. 'platform_gh_id'
  1213. ];
  1214. $data = Option::get($keys, 0, 'saas');
  1215. if (empty($data)) {
  1216. $data = [
  1217. 'platform_appid' => '',
  1218. 'platform_mch_id' => '',
  1219. 'platform_key' => ' ',
  1220. 'platform_apiclient_cert' => '',
  1221. 'platform_apiclient_key' => '',
  1222. 'platform_apiclient_cert_url' => '',
  1223. 'platform_apiclient_key_url' => '',
  1224. 'platform_pay_key' => '',
  1225. 'platform_app_appid' => '',
  1226. 'platform_gh_id' => ''
  1227. ];
  1228. } else {
  1229. $arr = [];
  1230. foreach ($data as $value) {
  1231. $index = array_search($value['name'], $keys);
  1232. unset($keys[$index]);
  1233. $arr[$value['name']] = $value['value'];
  1234. }
  1235. foreach ($keys as $key) {
  1236. $arr[$key] = '';
  1237. }
  1238. if (empty($arr['platform_apiclient_cert_url']) && !empty($arr['platform_apiclient_cert'])) {
  1239. $arr['platform_apiclient_cert_url'] = WechatConfigForm::handlePemFile($arr['platform_apiclient_cert']);
  1240. }
  1241. if (empty($arr['platform_apiclient_key_url']) && !empty($arr['platform_apiclient_key'])) {
  1242. $arr['platform_apiclient_key_url'] = WechatConfigForm::handlePemFile($arr['platform_apiclient_key']);
  1243. }
  1244. $data = $arr;
  1245. }
  1246. return $this->asJson([
  1247. 'code' => 0,
  1248. 'msg' => 'success',
  1249. 'data' => $data,
  1250. ]);
  1251. }
  1252. }
  1253. /**
  1254. * 设置商家小程序配置
  1255. *
  1256. * @return void
  1257. */
  1258. public function actionWechatPlatformMchSetting()
  1259. {
  1260. if (Yii::$app->request->getIsPost()) {
  1261. $platform_mch_is_shenhe = post_params('platform_mch_is_shenhe', false);
  1262. $platform_mch_appid = post_params('platform_mch_appid', '');
  1263. $platform_mch_key = post_params('platform_mch_key', '');
  1264. $platform_mch_id = post_params('platform_mch_id', '');
  1265. $platform_apiclient_cert = post_params('platform_apiclient_cert', '');
  1266. $platform_apiclient_key = post_params('platform_apiclient_key', '');
  1267. $platform_apiclient_cert_url = post_params('platform_apiclient_cert_url', '');
  1268. $platform_apiclient_key_url = post_params('platform_apiclient_key_url', '');
  1269. $platform_pay_key = post_params('platform_pay_key', '');
  1270. $platform_mch_api_key = post_params('platform_mch_api_key', '');
  1271. $platform_mch_api_serial_no = post_params('platform_mch_api_serial_no', '');
  1272. $platform_mch_public_key = post_params('platform_mch_public_key', '');
  1273. $platform_mch_public_key_id = post_params('platform_mch_public_key_id', '');
  1274. if (!empty($platform_apiclient_cert_url)) {
  1275. $platform_apiclient_cert = file_get_contents($platform_apiclient_cert_url);
  1276. } else {
  1277. if (!empty($platform_apiclient_cert)) {
  1278. $platform_apiclient_cert_url = WechatConfigForm::handlePemFile($platform_apiclient_cert);
  1279. }
  1280. }
  1281. if (!empty($platform_apiclient_key_url)) {
  1282. $platform_apiclient_key = file_get_contents($platform_apiclient_key_url);
  1283. } else {
  1284. if (!empty($platform_apiclient_key)) {
  1285. $platform_apiclient_key_url = WechatConfigForm::handlePemFile($platform_apiclient_key);
  1286. }
  1287. }
  1288. Option::set([
  1289. 'platform_mch_is_shenhe',
  1290. 'platform_mch_appid',
  1291. 'platform_mch_key',
  1292. 'platform_mch_id',
  1293. 'platform_apiclient_cert',
  1294. 'platform_apiclient_key',
  1295. 'platform_apiclient_cert_url',
  1296. 'platform_apiclient_key_url',
  1297. 'platform_mch_public_key',
  1298. 'platform_mch_public_key_id',
  1299. 'platform_pay_key',
  1300. 'platform_mch_api_key',
  1301. 'platform_mch_api_serial_no'
  1302. ], [
  1303. $platform_mch_is_shenhe,
  1304. $platform_mch_appid,
  1305. $platform_mch_key,
  1306. $platform_mch_id,
  1307. $platform_apiclient_cert,
  1308. $platform_apiclient_key,
  1309. $platform_apiclient_cert_url,
  1310. $platform_apiclient_key_url,
  1311. $platform_mch_public_key,
  1312. $platform_mch_public_key_id,
  1313. $platform_pay_key,
  1314. $platform_mch_api_key,
  1315. $platform_mch_api_serial_no
  1316. ], 0, 'saas');
  1317. return $this->asJson([
  1318. 'code' => 0,
  1319. 'msg' => '保存成功',
  1320. ]);
  1321. } else {
  1322. $keys = [
  1323. 'platform_mch_is_shenhe',
  1324. 'platform_mch_appid',
  1325. 'platform_mch_key',
  1326. 'platform_mch_id',
  1327. 'platform_apiclient_cert',
  1328. 'platform_apiclient_key',
  1329. 'platform_apiclient_cert_url',
  1330. 'platform_apiclient_key_url',
  1331. 'platform_mch_public_key',
  1332. 'platform_mch_public_key_id',
  1333. 'platform_pay_key',
  1334. 'platform_mch_api_key',
  1335. 'platform_mch_api_serial_no'
  1336. ];
  1337. $data = Option::get($keys, 0, 'saas');
  1338. if (empty($data)) {
  1339. $data = [
  1340. 'platform_mch_is_shenhe' => false,
  1341. 'platform_mch_appid' => '',
  1342. 'platform_mch_key' => '',
  1343. 'platform_mch_id' => '',
  1344. 'platform_apiclient_cert' => '',
  1345. 'platform_apiclient_key' => '',
  1346. 'platform_apiclient_cert_url' => '',
  1347. 'platform_apiclient_key_url' => '',
  1348. 'platform_mch_public_key'=>"",
  1349. 'platform_mch_public_key_id'=>"",
  1350. 'platform_pay_key' => '',
  1351. 'platform_mch_api_key' => '',
  1352. 'platform_mch_api_serial_no' => ''
  1353. ];
  1354. } else {
  1355. $arr = [];
  1356. foreach ($data as $value) {
  1357. $index = array_search($value['name'], $keys);
  1358. unset($keys[$index]);
  1359. $arr[$value['name']] = $value['value'];
  1360. }
  1361. foreach ($keys as $key) {
  1362. $arr[$key] = '';
  1363. }
  1364. if (empty($arr['platform_apiclient_cert_url']) && !empty($arr['platform_apiclient_cert'])) {
  1365. $arr['platform_apiclient_cert_url'] = WechatConfigForm::handlePemFile($arr['platform_apiclient_cert']);
  1366. }
  1367. if (empty($arr['platform_apiclient_key_url']) && !empty($arr['platform_apiclient_key'])) {
  1368. $arr['platform_apiclient_key_url'] = WechatConfigForm::handlePemFile($arr['platform_apiclient_key']);
  1369. }
  1370. $data = $arr;
  1371. }
  1372. if ($data['platform_mch_is_shenhe'] === '') {
  1373. $data['platform_mch_is_shenhe'] = false;
  1374. }
  1375. return $this->asJson([
  1376. 'code' => 0,
  1377. 'msg' => 'success',
  1378. 'data' => $data,
  1379. ]);
  1380. }
  1381. }
  1382. /**
  1383. * 设置联盟服务协议隐私政策配置
  1384. *
  1385. */
  1386. public function actionAllianceArticle()
  1387. {
  1388. if (Yii::$app->request->getIsPost()) {
  1389. $alliance_service_article = post_params('alliance_service_article', '');
  1390. $alliance_privacy_article = post_params('alliance_privacy_article', '');
  1391. $alliance_about_us_article = post_params('alliance_about_us_article', '');
  1392. $data = [
  1393. [
  1394. 'name' => '服务协议',
  1395. 'type' => AboutArticle::TYPE_SERVICE,
  1396. 'desc' => $alliance_service_article
  1397. ],
  1398. [
  1399. 'name' => '隐私政策',
  1400. 'type' => AboutArticle::TYPE_PRIVACY,
  1401. 'desc' => $alliance_privacy_article
  1402. ],
  1403. [
  1404. 'name' => '关于我们',
  1405. 'type' => AboutArticle::TYPE_ABOUT_US,
  1406. 'desc' => $alliance_about_us_article
  1407. ]
  1408. ];
  1409. foreach ($data as $item) {
  1410. $article = AboutArticle::find()->where(['type' => $item['type'], 'is_delete' => 0, 'store_id' => -1])->one();
  1411. $article = $article ?? new AboutArticle();
  1412. $article->store_id = -1;
  1413. $article->name = $item['name'];
  1414. $article->desc = $item['desc'];
  1415. $article->type = $item['type'];
  1416. $article->save();
  1417. }
  1418. return $this->asJson([
  1419. 'code' => 0,
  1420. 'msg' => '保存成功',
  1421. ]);
  1422. } else {
  1423. $alliance_service_article = AboutArticle::find()->where(['type' => AboutArticle::TYPE_SERVICE, 'is_delete' => 0])
  1424. ->select(['desc'])->asArray()->one();
  1425. $alliance_privacy_article = AboutArticle::find()->where(['type' => AboutArticle::TYPE_PRIVACY, 'is_delete' => 0])
  1426. ->select(['desc'])->asArray()->one();
  1427. $alliance_about_us_article = AboutArticle::find()->where(['type' => AboutArticle::TYPE_ABOUT_US, 'is_delete' => 0])
  1428. ->select(['desc'])->asArray()->one();
  1429. $data = [
  1430. 'alliance_service_article' => $alliance_service_article['desc'] ?? '',
  1431. 'alliance_privacy_article' => $alliance_privacy_article['desc'] ?? '',
  1432. 'alliance_about_us_article' => $alliance_about_us_article['desc'] ?? '',
  1433. ];
  1434. return $this->asJson([
  1435. 'code' => 0,
  1436. 'msg' => 'success',
  1437. 'data' => $data,
  1438. ]);
  1439. }
  1440. }
  1441. /**
  1442. * 设置支付宝第三方信息
  1443. *
  1444. * @return void
  1445. */
  1446. public function actionAliThirdSetting()
  1447. {
  1448. $ali_plugin_goodsDetail_key = OptionSetting::ALI_MINI_PLUGIN_goodsDetail;
  1449. if (Yii::$app->request->getIsPost()) {
  1450. $ali_template_token = post_params('ali_template_token', '');//消息验证token
  1451. $ali_template_aes = post_params('ali_template_aes','');//加密key
  1452. $ali_template_appid = post_params('ali_template_appid','');//模板小程序appid
  1453. $ali_template_store_id = post_params('ali_template_store_id','');//模板默认店铺id
  1454. $ali_template_mini_id = post_params('ali_template_mini_id','');//模板默认小程序id
  1455. $ali_plugin_goodsDetail = post_params($ali_plugin_goodsDetail_key, 1);
  1456. Option::set([
  1457. 'ali_template_store_id',
  1458. 'ali_template_mini_id',
  1459. 'ali_template_token',
  1460. 'ali_template_aes',
  1461. 'ali_template_appid',
  1462. $ali_plugin_goodsDetail_key,
  1463. ], [
  1464. $ali_template_store_id,
  1465. $ali_template_mini_id,
  1466. $ali_template_token,
  1467. $ali_template_aes,
  1468. $ali_template_appid,
  1469. $ali_plugin_goodsDetail,
  1470. ], 0, 'saas');
  1471. return $this->asJson([
  1472. 'code' => 0,
  1473. 'msg' => '保存成功',
  1474. ]);
  1475. } else {
  1476. $keys = [
  1477. 'ali_template_store_id',
  1478. 'ali_template_mini_id',
  1479. 'ali_template_token',
  1480. 'ali_template_aes',
  1481. 'ali_template_appid'
  1482. ];
  1483. $data = Option::get($keys, 0, 'saas');
  1484. if (empty($data)) {
  1485. $data = [
  1486. 'ali_template_store_id'=>'',
  1487. 'ali_template_mini_id'=>'',
  1488. 'ali_template_token'=>'',
  1489. 'ali_template_aes'=>'',
  1490. 'ali_template_appid'=>'',
  1491. $ali_plugin_goodsDetail_key => 1,
  1492. ];
  1493. } else {
  1494. $arr = [];
  1495. foreach ($data as $value) {
  1496. $index = array_search($value['name'], $keys);
  1497. unset($keys[$index]);
  1498. $arr[$value['name']] = $value['value'];
  1499. }
  1500. foreach ($keys as $key) {
  1501. $arr[$key] = '';
  1502. }
  1503. $data = $arr;
  1504. $ali_plugin_goodsDetail = Option::get($ali_plugin_goodsDetail_key, 0, 'saas', 1)['value'];
  1505. $data[$ali_plugin_goodsDetail_key] = $ali_plugin_goodsDetail;
  1506. }
  1507. return $this->asJson([
  1508. 'code' => 0,
  1509. 'msg' => 'success',
  1510. 'data' => $data,
  1511. ]);
  1512. }
  1513. }
  1514. /**
  1515. * 设置微信第三方信息
  1516. *
  1517. * @return void
  1518. */
  1519. public function actionWechatThirdSetting()
  1520. {
  1521. if (Yii::$app->request->getIsPost()) {
  1522. $platform_token = post_params('platform_token', '');//消息验证token
  1523. $platform_encodingAesKey = post_params('platform_encodingAesKey','');//加密key
  1524. $platform_phone = post_params('platform_phone','');//平台手机号
  1525. $platform_third_appid = post_params("platform_third_appid","");//三方平台Appid
  1526. $platform_third_secret = post_params("platform_third_secret","");//三方平台AppSecret
  1527. $platform_template_id = post_params("platform_template_id","");//三方平台模板ID
  1528. $platform_wechat_third_appid = post_params('platform_wechat_third_appid','');//三方绑定的小程序appid
  1529. $platform_wechat_b2b_store_min_rate = post_params('platform_wechat_b2b_store_min_rate','');//店铺内b2b优惠费率最低值
  1530. $platform_wechat_fuwu_appid = post_params('platform_wechat_fuwu_appid','wx2455c3e38caf34a0');//服务市场企业appid
  1531. $platform_wechat_fuwu_secret = post_params('platform_wechat_fuwu_secret','483b2c2357868b91825a415bbba45cc7');//服务市场企业secret
  1532. $platform_wechat_fuwu_serviceId = post_params('platform_wechat_fuwu_serviceId','');//三方绑定的视频号小店serviceId,多个用逗号隔开
  1533. $platform_wechat_fuwu_help_qrcode = post_params('platform_wechat_fuwu_help_qrcode','');//视频号小店指南-二维码
  1534. $platform_wechat_fuwu_help_tel = post_params('platform_wechat_fuwu_help_tel','');//视频号小店指南-电话
  1535. $platform_wechat_fuwu_help_link = post_params('platform_wechat_fuwu_help_link','');//视频号小店指南-文档链接
  1536. $local_sym_sn = post_params('local_sym_sn','');//对称密钥编号
  1537. $local_sym_key = post_params('local_sym_key','');//对称密钥密钥明文
  1538. $rsa_sn = post_params('rsa_sn','');//非对称密钥编号
  1539. $rsa_private_key = post_params('rsa_private_key','');//非对称密钥私玥
  1540. Option::set([
  1541. 'platform_token',
  1542. 'platform_encodingAesKey',
  1543. 'platform_phone',
  1544. "platform_third_appid",
  1545. "platform_third_secret",
  1546. "platform_template_id",
  1547. 'platform_wechat_third_appid',
  1548. 'platform_wechat_b2b_store_min_rate',
  1549. 'platform_wechat_fuwu_appid',
  1550. 'platform_wechat_fuwu_secret',
  1551. 'platform_wechat_fuwu_serviceId',
  1552. 'platform_wechat_fuwu_help_qrcode',
  1553. 'platform_wechat_fuwu_help_tel',
  1554. 'platform_wechat_fuwu_help_link',
  1555. ], [
  1556. $platform_token,
  1557. $platform_encodingAesKey,
  1558. $platform_phone,
  1559. $platform_third_appid,
  1560. $platform_third_secret,
  1561. $platform_template_id,
  1562. $platform_wechat_third_appid,
  1563. $platform_wechat_b2b_store_min_rate,
  1564. $platform_wechat_fuwu_appid,
  1565. $platform_wechat_fuwu_secret,
  1566. $platform_wechat_fuwu_serviceId,
  1567. $platform_wechat_fuwu_help_qrcode,
  1568. $platform_wechat_fuwu_help_tel,
  1569. $platform_wechat_fuwu_help_link,
  1570. ], 0, 'saas');
  1571. Option::set([
  1572. 'local_sym_sn',
  1573. 'local_sym_key',
  1574. 'rsa_sn',
  1575. 'rsa_private_key',
  1576. ], [
  1577. $local_sym_sn,
  1578. $local_sym_key,
  1579. $rsa_sn,
  1580. $rsa_private_key
  1581. ], 0, 'delivery');
  1582. return $this->asJson([
  1583. 'code' => 0,
  1584. 'msg' => '保存成功',
  1585. ]);
  1586. } else {
  1587. $keys = [
  1588. 'platform_token',
  1589. 'platform_encodingAesKey',
  1590. 'platform_phone',
  1591. 'platform_third_appid',
  1592. 'platform_third_secret',
  1593. 'platform_template_id',
  1594. 'platform_wechat_fuwu_appid',
  1595. 'platform_wechat_fuwu_secret',
  1596. 'platform_wechat_fuwu_serviceId',
  1597. 'platform_wechat_third_appid',
  1598. 'platform_wechat_b2b_store_min_rate',
  1599. 'platform_wechat_fuwu_help_qrcode',
  1600. 'platform_wechat_fuwu_help_tel',
  1601. 'platform_wechat_fuwu_help_link',
  1602. ];
  1603. $data = Option::get($keys, 0, 'saas');
  1604. if (empty($data)) {
  1605. $data = [
  1606. 'platform_token'=>'',
  1607. 'platform_encodingAesKey'=>'',
  1608. 'platform_phone'=>'',
  1609. 'platform_third_appid'=>"",
  1610. 'platform_third_secret'=>"",
  1611. 'platform_template_id'=>"",
  1612. 'platform_wechat_fuwu_appid'=>"",
  1613. 'platform_wechat_fuwu_secret'=>"",
  1614. 'platform_wechat_fuwu_serviceId'=>"",
  1615. 'platform_wechat_third_appid' => '',
  1616. 'platform_wechat_b2b_store_min_rate' => '',
  1617. 'platform_wechat_fuwu_help_qrcode' => '',
  1618. 'platform_wechat_fuwu_help_tel' => '',
  1619. 'platform_wechat_fuwu_help_link' => '',
  1620. ];
  1621. } else {
  1622. $arr = [];
  1623. foreach ($data as $value) {
  1624. $index = array_search($value['name'], $keys);
  1625. unset($keys[$index]);
  1626. $arr[$value['name']] = $value['value'];
  1627. }
  1628. foreach ($keys as $key) {
  1629. $arr[$key] = '';
  1630. }
  1631. $data = $arr;
  1632. }
  1633. $keys = [
  1634. 'local_sym_sn',
  1635. 'local_sym_key',
  1636. 'rsa_sn',
  1637. 'rsa_private_key'
  1638. ];
  1639. $delivery_data = Option::get($keys, 0, 'delivery');
  1640. if (empty($data)) {
  1641. $delivery_data = [
  1642. 'local_sym_sn' => '',
  1643. 'local_sym_key' => '',
  1644. 'rsa_sn' => '',
  1645. 'rsa_private_key' => '',
  1646. ];
  1647. } else {
  1648. $arr = [];
  1649. foreach ($delivery_data as $value) {
  1650. $index = array_search($value['name'], $keys);
  1651. unset($keys[$index]);
  1652. $arr[$value['name']] = $value['value'];
  1653. }
  1654. foreach ($keys as $key) {
  1655. $arr[$key] = '';
  1656. }
  1657. $delivery_data = $arr;
  1658. }
  1659. $data = array_merge($data, $delivery_data);
  1660. //服务url
  1661. $data['platform_wechat_fuwu_serviceUrl'] = \Yii::$app->request->hostInfo . "/index.php/wechat/fuwu-buyer-login";
  1662. // if($data['platform_wechat_fuwu_serviceId']){
  1663. $data['platform_wechat_fuwu_serviceId_qr'] = (new \app\modules\admin\models\WechatThirdForm())->serviceQrcode($data['platform_wechat_fuwu_serviceId']);
  1664. // }
  1665. return $this->asJson([
  1666. 'code' => 0,
  1667. 'msg' => 'success',
  1668. 'data' => $data,
  1669. ]);
  1670. }
  1671. }
  1672. /**
  1673. * 设置代理中心配置
  1674. */
  1675. public function actionAgencyConfig(){
  1676. if (Yii::$app->request->getIsPost()) {
  1677. $params = [
  1678. 'lowerLevelShop' => get_params('lowerLevelShop', ""),
  1679. 'lowerLevelShopIcon' => get_params('lowerLevelShopIcon', ""),
  1680. 'renewOrder' => get_params('renewOrder', ""),
  1681. 'renewOrderIcon' => get_params('renewOrderIcon', ""),
  1682. // 'Withdrawal' => get_params('Withdrawal', ""),
  1683. // 'WithdrawalIcon' => get_params('WithdrawalIcon', ""),
  1684. // 'commissionDetail' => get_params('commissionDetail', ""),
  1685. // 'commissionDetailIcon' => get_params('commissionDetailIcon', ""),
  1686. // 'WithdrawalLog' => get_params('WithdrawalLog', ""),
  1687. // 'WithdrawalLogIcon' => get_params('WithdrawalLogIcon', ""),
  1688. 'shopOrder' => get_params('shopOrder', ""),
  1689. 'shopOrderIcon' => get_params('shopOrderIcon', "")
  1690. ];
  1691. Option::set('agency_config', json_encode($params), 0, 'saas');
  1692. return $this->asJson([
  1693. 'code' => 0,
  1694. 'msg' => '保存成功',
  1695. ]);
  1696. }else{
  1697. $option = Option::get('agency_config', 0, 'saas');
  1698. $option = json_decode($option['value'], true);
  1699. $data = [
  1700. 'lowerLevelShop' => $option['lowerLevelShop'] ?: "",
  1701. 'lowerLevelShopIcon' => $option['lowerLevelShopIcon'] ?: "",
  1702. 'renewOrder' => $option['renewOrder'] ?: "",
  1703. 'renewOrderIcon' => $option['renewOrderIcon'] ?: "",
  1704. // 'Withdrawal' => $option['Withdrawal'] ?: "",
  1705. // 'WithdrawalIcon' => $option['WithdrawalIcon'] ?: "",
  1706. // 'commissionDetail' => $option['commissionDetail'] ?: "",
  1707. // 'commissionDetailIcon'=> $option['commissionDetailIcon'] ?: "",
  1708. // 'WithdrawalLog' => $option['WithdrawalLog'] ?: "",
  1709. // 'WithdrawalLogIcon' => $option['WithdrawalLogIcon'] ?: "",
  1710. 'shopOrder' => $option['shopOrder'] ?: "",
  1711. 'shopOrderIcon' => $option['shopOrderIcon'] ?: ""
  1712. ];
  1713. return $this->asJson([
  1714. 'code' => 0,
  1715. 'msg' => 'success',
  1716. 'data' => $data,
  1717. ]);
  1718. }
  1719. }
  1720. /**
  1721. * 设置产品代理中心配置
  1722. */
  1723. public function actionGoodsAgentPriceConfig(){
  1724. try {
  1725. if (Yii::$app->request->getIsPost()) {
  1726. $params = [
  1727. 'goods_agent_percent' => post_params('goods_agent_percent', "0.00"),
  1728. 'goods_agent_install_percent' => post_params('goods_agent_install_percent', ""),
  1729. ];
  1730. Option::set('goods_agent_price_config', json_encode($params), 0, 'saas');
  1731. return $this->asJson([
  1732. 'code' => 0,
  1733. 'msg' => '保存成功',
  1734. ]);
  1735. }else{
  1736. $option = Option::get('goods_agent_price_config', 0, 'saas');
  1737. if ($option['value']) {
  1738. $option = json_decode($option['value'], true);
  1739. }
  1740. $data = [
  1741. 'goods_agent_percent' => $option['goods_agent_percent'] ?: "0.00",
  1742. 'goods_agent_install_percent' => $option['goods_agent_install_percent'] ?: "0.00",
  1743. ];
  1744. return $this->asJson([
  1745. 'code' => 0,
  1746. 'msg' => 'success',
  1747. 'data' => $data,
  1748. ]);
  1749. }
  1750. } catch (\Exception $e) {
  1751. return $this->asJson([
  1752. 'code' => 1,
  1753. 'msg' => $e->getMessage(),
  1754. ]);
  1755. }
  1756. }
  1757. /**
  1758. * 设置代理中心配置
  1759. */
  1760. public function actionAgencyPriceConfig(){
  1761. if (Yii::$app->request->getIsPost()) {
  1762. $params = [
  1763. 'supplier_province_percent' => post_params('supplier_province_percent', ""),
  1764. 'supplier_city_percent' => post_params('supplier_city_percent', ""),
  1765. 'supplier_district_percent' => post_params('supplier_district_percent', ""),
  1766. 'model_type' => post_params('model_type', 0),//运营模式
  1767. 'province_percent' => post_params('province_percent', ""),
  1768. 'city_percent' => post_params('city_percent', ""),
  1769. 'district_percent' => post_params('district_percent', ""),
  1770. ];
  1771. Option::set('agency_price_config', json_encode($params), 0, 'saas');
  1772. return $this->asJson([
  1773. 'code' => 0,
  1774. 'msg' => '保存成功',
  1775. ]);
  1776. }else{
  1777. $option = Option::get('agency_price_config', 0, 'saas');
  1778. if ($option['value']) {
  1779. $option = json_decode($option['value'], true);
  1780. }
  1781. $data = [
  1782. 'province_percent' => $option['province_percent'] ?: "",
  1783. 'city_percent' => $option['city_percent'] ?: "",
  1784. 'district_percent' => $option['district_percent'] ?: "",
  1785. 'supplier_province_percent' => $option['supplier_province_percent'] ?: "",
  1786. 'supplier_city_percent' => $option['supplier_city_percent'] ?: "",
  1787. 'supplier_district_percent' => $option['supplier_district_percent'] ?: "",
  1788. 'model_type' => $option['model_type'] ?: 0
  1789. ];
  1790. return $this->asJson([
  1791. 'code' => 0,
  1792. 'msg' => 'success',
  1793. 'data' => $data,
  1794. ]);
  1795. }
  1796. }
  1797. /**
  1798. * 设置推广代理佣金配置
  1799. */
  1800. public function actionBdAgencyPriceConfig(){
  1801. $option = Option::get('bd_agency_price_config', 0, 'saas')['value'];
  1802. if ($option) {
  1803. $option = json_decode($option, true);
  1804. }
  1805. if (Yii::$app->request->getIsPost()) {
  1806. $option['bd_agent_percent'] = post_params('bd_agent_percent', "");
  1807. $option['supplier_bd_agent_percent'] = post_params('supplier_bd_agent_percent', "");
  1808. Option::set('bd_agency_price_config', json_encode($option), 0, 'saas');
  1809. return $this->asJson([
  1810. 'code' => 0,
  1811. 'msg' => '保存成功',
  1812. ]);
  1813. }else{
  1814. $data = [
  1815. 'bd_agent_percent' => $option['bd_agent_percent'] ?: 0,
  1816. 'supplier_bd_agent_percent' => $option['supplier_bd_agent_percent'] ?: 0,
  1817. ];
  1818. return $this->asJson([
  1819. 'code' => 0,
  1820. 'msg' => 'success',
  1821. 'data' => $data,
  1822. ]);
  1823. }
  1824. }
  1825. /**
  1826. * 设置商户分销
  1827. *
  1828. * @return void
  1829. */
  1830. public function actionStoreShareSetting()
  1831. {
  1832. if (Yii::$app->request->getIsPost()) {
  1833. $params = [
  1834. 'level' => post_params('level', 0),
  1835. 'is_rebate' => post_params('is_rebate', 0),
  1836. 'price_type' => post_params('price_type', 0),
  1837. 'level_one' => post_params('level_one', 0),
  1838. 'level_two' => post_params('level_two', 0),
  1839. 'level_three' => post_params('level_three', 0),
  1840. ];
  1841. Option::set('store_share', json_encode($params), 0, 'saas');
  1842. return $this->asJson([
  1843. 'code' => 0,
  1844. 'msg' => '保存成功',
  1845. ]);
  1846. } else {
  1847. $data = Option::get('store_share', 0, 'saas');
  1848. if (empty($data['value'])) {
  1849. $data = [
  1850. 'level' => 0,
  1851. 'is_rebate' => 0,
  1852. 'price_type' => 0,
  1853. 'level_one' => 0,
  1854. 'level_two' => 0,
  1855. 'level_three' => 0,
  1856. ];
  1857. } else {
  1858. $data = json_decode($data['value'], true);
  1859. }
  1860. return $this->asJson([
  1861. 'code' => 0,
  1862. 'msg' => 'success',
  1863. 'data' => $data,
  1864. ]);
  1865. }
  1866. }
  1867. public function actionProfitReceiver()
  1868. {
  1869. $form = new ProfitReceiverForm();
  1870. if (Yii::$app->request->getIsPost()) {
  1871. $form->attributes = post_params();
  1872. $form->ratio = post_params('ratio');
  1873. $form->max_amount = post_params('max_amount');
  1874. return $this->asJson($form->save());
  1875. }
  1876. $form->search_key = get_params('search_key');
  1877. return $this->asJson($form->search());
  1878. }
  1879. public function actionDeleteReceiver()
  1880. {
  1881. $res = ProfitSharingReceiver::find()->where(['store_id' => get_store_id(), 'id' => post_params('id'), 'is_delete' => 0])->one();
  1882. if (!$res) {
  1883. return $this->asJson([
  1884. 'code' => 1,
  1885. 'msg' => '未找到该记录'
  1886. ]);
  1887. }
  1888. $res->is_delete = 1;
  1889. if ($res->save()) {
  1890. return $this->asJson([
  1891. 'code' => 0,
  1892. 'msg' => '删除成功'
  1893. ]);
  1894. }
  1895. return $this->asJson([
  1896. 'code' => 1,
  1897. 'msg' => $res->errors[0]
  1898. ]);
  1899. }
  1900. /**
  1901. * 分帐记录情况
  1902. * @return \yii\web\Response
  1903. */
  1904. public function actionShareProfitRecord()
  1905. {
  1906. $form = new ShareProfitListForm();
  1907. $form->store_id = get_store_id();
  1908. $form->attributes = get_params();
  1909. return $this->asJson($form->search());
  1910. }
  1911. /**
  1912. * 财务列表
  1913. * @return \yii\web\Response
  1914. */
  1915. public function actionFinanciaList()
  1916. {
  1917. $params = get_params();
  1918. if (isset($params['isExprot'])) {
  1919. $params['isExport'] = 1;
  1920. }
  1921. $form = new ShareFinancialListForm();
  1922. $form->attributes = $params;
  1923. return $this->asJson($form->financialList());
  1924. }
  1925. /**
  1926. * 订单列表(成本价)
  1927. */
  1928. public function actionOrderCostProfitList() {
  1929. $form = new CostProfitListForm();
  1930. $form->store_id = get_store_id();
  1931. $form->attributes = get_params();
  1932. return $this->asJson($form->search());
  1933. }
  1934. /**
  1935. * 联盟佣金平台提现审核列表
  1936. * @return \yii\web\Response
  1937. */
  1938. public function actionProfitCash()
  1939. {
  1940. $form = new PlatformProfitCashForm();
  1941. $form->attributes = get_params();
  1942. return $this->asJson($form->search());
  1943. }
  1944. /**
  1945. * 审核
  1946. * @return \yii\web\Response
  1947. */
  1948. public function actionProfitCashAudit()
  1949. {
  1950. $form = new PlatformProfitCashForm();
  1951. $form->attributes = post_params();
  1952. return $this->asJson($form->audit());
  1953. }
  1954. /**
  1955. * 提现记录删除
  1956. * @return \yii\web\Response
  1957. */
  1958. public function actionProfitCashDel()
  1959. {
  1960. $form = new PlatformProfitCashForm();
  1961. $form->attributes = post_params();
  1962. return $this->asJson($form->del());
  1963. }
  1964. public function actionSmsSetting()
  1965. {
  1966. $default = [
  1967. 'id' => '',
  1968. 'secret' => '',
  1969. 'template' => '',
  1970. ];
  1971. if (Yii::$app->request->getIsPost()) {
  1972. $content = post_params('content', $default);
  1973. Option::set('sms', json_encode($content), 0, 'saas');
  1974. $SmsSetting = SmsSetting::findOne(['store_id' => -1]) ?: new SmsSetting();
  1975. $SmsSetting->AccessKeyId = $content['id'];
  1976. $SmsSetting->AccessKeySecret = $content['secret'];
  1977. $SmsSetting->sign = $content['template'];
  1978. $SmsSetting->store_id = -1;
  1979. $SmsSetting->created_at = time();
  1980. $SmsSetting->save();
  1981. return $this->asJson([
  1982. 'code' => 0,
  1983. 'msg' => '保存成功',
  1984. ]);
  1985. } else {
  1986. $content = Option::get('sms', 0, 'saas', json_encode($default));
  1987. return $this->asJson([
  1988. 'code' => 0,
  1989. 'msg' => 'success',
  1990. 'data' => json_decode($content['value']),
  1991. ]);
  1992. }
  1993. }
  1994. /**
  1995. * saas上传设置
  1996. */
  1997. public function actionUploadConfig()
  1998. {
  1999. $model = UploadConfig::findOne([
  2000. 'store_id' => 0,
  2001. 'is_delete' => 0,
  2002. ]);
  2003. if (!$model) {
  2004. $model = new UploadConfig();
  2005. }
  2006. $mho = Option::get(OptionSetting::MCH_HIDE_OSS, 0, 'saas', '0')['value'];
  2007. $runOverDefault = [
  2008. 'max_picture' => 10,
  2009. 'max_file' => 10,
  2010. 'over_picture' => 0,
  2011. 'over_file' => 0
  2012. ];
  2013. if (\Yii::$app->request->isPost) {
  2014. $mho = post_params('mch_hide_oss', 0);
  2015. Option::set(OptionSetting::MCH_HIDE_OSS, $mho, 0, 'saas');
  2016. $runOver = \post_params('runOver', $runOverDefault);
  2017. if (!isset($runOver['max_file'])) {
  2018. $runOver['max_file'] = $runOver['max_picture'];
  2019. }
  2020. if (!isset($runOver['over_file'])) {
  2021. $runOver['over_file'] = $runOver['over_picture'];
  2022. }
  2023. Option::set(OptionSetting::PLATFORM_UPLOAD_LIMIT, \json_encode($runOver), 0, 'saas');
  2024. $form = new CommonUpload();
  2025. $form->attributes = post_params();
  2026. $form->model = $model;
  2027. $form->store_id = 0;
  2028. return $this->asJson($form->save());
  2029. } else {
  2030. $model->aliyun = json_decode($model->aliyun, true);
  2031. $model->qcloud = json_decode($model->qcloud, true);
  2032. $model->qiniu = json_decode($model->qiniu, true);
  2033. $model->storage_type = !empty($model->storage_type) ? $model->storage_type : 'local';
  2034. $runOver = Option::get(OptionSetting::PLATFORM_UPLOAD_LIMIT, 0, 'saas', \json_encode($runOverDefault))['value'];
  2035. $runOver = \json_decode($runOver, true);
  2036. if (!isset($runOver['max_file'])) {
  2037. $runOver['max_file'] = $runOver['max_picture'];
  2038. }
  2039. if (!isset($runOver['over_file'])) {
  2040. $runOver['over_file'] = $runOver['over_picture'];
  2041. }
  2042. return $this->asJson([
  2043. 'code' => 0,
  2044. 'data' => $model,
  2045. 'mch_hide_oss' => $mho,
  2046. 'runOver' => $runOver,
  2047. ]);
  2048. }
  2049. }
  2050. /**
  2051. * 平台抖音小程序配置
  2052. *
  2053. */
  2054. public function actionBytedanceSetting()
  2055. {
  2056. if (Yii::$app->request->getIsPost()) {
  2057. $platform_appid = post_params('bytedance_platform_appid', '');
  2058. $platform_salt = post_params('bytedance_platform_salt', '');
  2059. $platform_token = post_params('bytedance_platform_token', '');
  2060. $platform_mch_id = post_params('bytedance_platform_mch_id', '');
  2061. $platform_key = post_params('bytedance_platform_key', '');
  2062. $platform_apiclient_cert = post_params('bytedance_platform_apiclient_cert', '');
  2063. $platform_apiclient_key = post_params('bytedance_platform_apiclient_key', '');
  2064. Option::set([
  2065. 'bytedance_platform_appid',
  2066. 'bytedance_platform_mch_id',
  2067. 'bytedance_platform_key',
  2068. 'bytedance_platform_apiclient_cert',
  2069. 'bytedance_platform_apiclient_key',
  2070. 'bytedance_platform_salt',
  2071. 'bytedance_platform_token',
  2072. ], [
  2073. $platform_appid,
  2074. $platform_mch_id,
  2075. $platform_key,
  2076. $platform_apiclient_cert,
  2077. $platform_apiclient_key,
  2078. $platform_salt,
  2079. $platform_token
  2080. ], 0, 'saas');
  2081. return $this->asJson([
  2082. 'code' => 0,
  2083. 'msg' => '保存成功',
  2084. ]);
  2085. } else {
  2086. $keys = [
  2087. 'bytedance_platform_appid',
  2088. 'bytedance_platform_mch_id',
  2089. 'bytedance_platform_key',
  2090. 'bytedance_platform_apiclient_cert',
  2091. 'bytedance_platform_apiclient_key',
  2092. 'bytedance_platform_salt',
  2093. 'bytedance_platform_token'
  2094. ];
  2095. $data = Option::get($keys, 0, 'saas');
  2096. if (empty($data)) {
  2097. $data = [
  2098. 'bytedance_platform_appid' => '',
  2099. 'bytedance_platform_mch_id' => '',
  2100. 'bytedance_platform_key' => '',
  2101. 'bytedance_platform_apiclient_cert' => '',
  2102. 'bytedance_platform_apiclient_key' => '',
  2103. 'bytedance_platform_salt' => '',
  2104. 'bytedance_platform_token' => ''
  2105. ];
  2106. } else {
  2107. $arr = [];
  2108. foreach ($data as $value) {
  2109. $index = array_search($value['name'], $keys);
  2110. unset($keys[$index]);
  2111. $arr[$value['name']] = $value['value'];
  2112. }
  2113. foreach ($keys as $key) {
  2114. $arr[$key] = '';
  2115. }
  2116. $data = $arr;
  2117. }
  2118. return $this->asJson([
  2119. 'code' => 0,
  2120. 'msg' => 'success',
  2121. 'data' => $data,
  2122. ]);
  2123. }
  2124. }
  2125. public function actionSalesman() {
  2126. $admin = get_admin();
  2127. $name = get_params('name');
  2128. $mobile = get_params('mobile');
  2129. $status = get_params('status', -1);
  2130. if (!in_array($status, [-1, 0, 1])) {
  2131. $status = -1;
  2132. }
  2133. // $query = Store::find()->alias('s')->leftJoin(['ss' => Salesman::tableName()], 's.salesman_id = ss.id')
  2134. // ->leftJoin(['su' => SaasUser::tableName()], 'su.id=ss.saas_user_id')
  2135. // ->where(['ss.is_delete' => 0])
  2136. // ->where(['<>', 's.salesman_id', 0])
  2137. // ->select('ss.id,ss.status,su.name,su.avatar,ss.created_at, su.mobile, s.name as store_name, s.logo as store_logo')->orderBy('s.id desc');
  2138. $query = Salesman::find()->alias('s')
  2139. ->leftJoin(['su' => SaasUser::tableName()], 'su.id=s.saas_user_id')
  2140. ->leftJoin(['a' => Admin::tableName()], 'a.id = s.admin_id')
  2141. ->where(['s.is_delete' => 0, 'a.type' => Admin::ADMIN_TYPE_BD_AGENT])
  2142. ->select('s.id,s.status,su.name,su.avatar,s.created_at,su.mobile,a.name as admin_name')
  2143. ->orderBy('s.created_at desc');
  2144. if ($admin->username != 'admin') {
  2145. $query->andWhere(['s.admin_id' => $admin->id]);
  2146. }
  2147. if ($name) {
  2148. $query->andWhere(['like', 'su.name', $name]);
  2149. }
  2150. if ($mobile) {
  2151. $query->andWhere(['like', 'su.mobile', $mobile]);
  2152. }
  2153. if ($status >= 0) {
  2154. $query->andWhere(['s.status' => $status]);
  2155. }
  2156. $list = pagination_make($query);
  2157. return $this->asJson([
  2158. 'code' => 0,
  2159. 'msg' => 'success',
  2160. 'data' => [
  2161. 'data' => $list['list'],
  2162. 'pageNo' => $list['pageNo'],
  2163. 'totalCount' => $list['totalCount'],
  2164. 'admin' => $admin
  2165. ]
  2166. ]);
  2167. }
  2168. // 修改业务员状态
  2169. public function actionSalesmanStatus()
  2170. {
  2171. $id = post_params('id');
  2172. $status = post_params('status');
  2173. if (!in_array($status, [0, 1])) {
  2174. return $this->asJson([
  2175. 'code' => 1,
  2176. 'msg' => 'status参数值只能是0或1',
  2177. ]);
  2178. }
  2179. $salesman = Salesman::findOne($id);
  2180. if (!$salesman) {
  2181. return $this->asJson([
  2182. 'code' => 1,
  2183. 'msg' => '业务员不存在',
  2184. ]);
  2185. }
  2186. $salesman->status = $status;
  2187. if (!$salesman->save()) {
  2188. return $this->asJson([
  2189. 'code' => 1,
  2190. 'msg' => $salesman->errors[0],
  2191. ]);
  2192. }
  2193. return $this->asJson([
  2194. 'code' => 0,
  2195. 'msg' => '操作成功',
  2196. ]);
  2197. }
  2198. public function actionSalesmanDel() {
  2199. $id = post_params('id');
  2200. $salesman = Salesman::findOne($id);
  2201. if (!$salesman) {
  2202. return $this->asJson([
  2203. 'code' => 1,
  2204. 'msg' => '业务员不存在',
  2205. ]);
  2206. }
  2207. $salesman->is_delete = 1;
  2208. if (!$salesman->save()) {
  2209. return $this->asJson([
  2210. 'code' => 1,
  2211. 'msg' => $salesman->errors[0],
  2212. ]);
  2213. }
  2214. SaasUser::updateAll(['is_salesman' => 0], ['id' => $salesman->saas_user_id]);
  2215. return $this->asJson([
  2216. 'code' => 0,
  2217. 'msg' => '删除成功',
  2218. ]);
  2219. }
  2220. public function actionSalesmanAdd() {
  2221. $admin = get_admin();
  2222. $admin_id = post_params('admin_id');
  2223. $saas_user_id = post_params('saas_user_id');
  2224. $status = post_params('status', 1);
  2225. if (!$saas_user_id || !in_array($status, [0, 1])) {
  2226. return $this->asJson([
  2227. 'code' => 1,
  2228. 'msg' => '参数有误',
  2229. ]);
  2230. }
  2231. $salesman = Salesman::findOne(['is_delete' => 0, 'saas_user_id' => $saas_user_id]);
  2232. if ($salesman) {
  2233. $admin_ = Admin::findOne(['id' => $salesman->admin_id, 'is_delete' => 0, 'type' => Admin::ADMIN_TYPE_BD_AGENT]);
  2234. if ($admin_) {
  2235. return $this->asJson([
  2236. 'code' => 1,
  2237. 'msg' => '业务员已存在',
  2238. ]);
  2239. }
  2240. $salesman->is_delete = 1;
  2241. $salesman->save();
  2242. }
  2243. $salesman = new Salesman();
  2244. if ($admin->username == 'admin' && $admin_id) {
  2245. $salesman->admin_id = $admin_id;
  2246. } else {
  2247. $salesman->admin_id = $admin->id;
  2248. }
  2249. $salesman->saas_user_id = $saas_user_id;
  2250. $salesman->status = $status;
  2251. if (!$salesman->save()) {
  2252. return $this->asJson([
  2253. 'code' => 1,
  2254. 'msg' => $salesman->errors[0],
  2255. ]);
  2256. }
  2257. SaasUser::updateAll(['is_salesman' => 1], ['id' => $saas_user_id]);
  2258. return $this->asJson([
  2259. 'code' => 0,
  2260. 'msg' => '添加成功',
  2261. ]);
  2262. }
  2263. public function actionOtherInfo() {
  2264. $store_apply_banner = Option::get('store_apply_banner', 0, 'saas', '')['value'];
  2265. $admin_copyright = Option::get('store_apply_agreement', 0, 'saas', '')['value'];
  2266. $store_apply_audit = Option::get('store_apply_audit', 0, 'saas', '0')['value'];
  2267. $store_apply_free = Option::get('store_apply_free', 0, 'saas', '0')['value'];
  2268. $store_apply_free_days = Option::get('store_apply_free_days', 0, 'saas', 5)['value'];
  2269. $store_apply_buy_type = Option::get('store_apply_buy_type', 0, 'saas', 'free')['value'];//free/once/renew
  2270. $store_apply_buy_money = Option::get('store_apply_buy_money', 0, 'saas', 0)['value'];
  2271. $admin_profit = Option::get('admin_profit', 0, 'saas', 0)['value'];
  2272. $store_apply_renew = Option::get('store_apply_renew', 0, 'saas', 'sys')['value']; //sys/custom
  2273. $sysPriceList = StorePrice::findOne(['is_delete' => 0, 'is_sys' => 1]);
  2274. if (!$sysPriceList) {
  2275. $this->handleSysPriceList();
  2276. }
  2277. $priceList = StorePrice::findAll(['is_delete' => 0]);
  2278. return $this->asJson([
  2279. 'code' => 0,
  2280. 'data' => [
  2281. 'store_apply_banner' => $store_apply_banner ? Json::decode($store_apply_banner) : [],
  2282. 'store_apply_agreement' => $admin_copyright,
  2283. 'store_apply_audit' => $store_apply_audit,
  2284. 'store_apply_free' => $store_apply_free,
  2285. 'store_apply_free_days' => $store_apply_free_days,
  2286. 'store_apply_buy_type' => $store_apply_buy_type,
  2287. 'store_apply_buy_money' => $store_apply_buy_money,
  2288. 'store_apply_renew' => $store_apply_renew,
  2289. 'priceList' => $priceList,
  2290. 'admin_profit' => $admin_profit
  2291. ]
  2292. ]);
  2293. }
  2294. public function handleSysPriceList() {
  2295. $sysPriceList = StorePrice::findOne(['is_delete' => 0, 'is_sys' => 1]);
  2296. if (!$sysPriceList) {
  2297. $arr = [
  2298. [
  2299. 'day' => 30,
  2300. 'price' => 0.00,
  2301. 'text' => '1个月'
  2302. ],
  2303. [
  2304. 'day' => 90,
  2305. 'price' => 0.00,
  2306. 'text' => '3个月'
  2307. ],
  2308. [
  2309. 'day' => 365,
  2310. 'price' => 0.00,
  2311. 'text' => '1年'
  2312. ],
  2313. ];
  2314. foreach ($arr as $item) {
  2315. $price_item = StorePrice::findOne(['is_delete' => 0, 'is_sys' => 1, 'days' => $item['day']]);
  2316. if (!$price_item) {
  2317. $price_item = new StorePrice();
  2318. $price_item->days = $item['day'];
  2319. $price_item->price = $item['price'];
  2320. $price_item->name = $item['text'];
  2321. $price_item->discount_name = '';
  2322. $price_item->used = 1;
  2323. $price_item->is_sys = 1;
  2324. $price_item->save();
  2325. }
  2326. }
  2327. }
  2328. }
  2329. public function actionSubmitOtherInfo() {
  2330. // $store_apply_banner = post_params('store_apply_banner', []);
  2331. // $store_apply_agreement = post_params('store_apply_agreement', '');
  2332. // Option::set('store_apply_banner', Json::encode($store_apply_banner), 0, 'saas');
  2333. // Option::set('store_apply_agreement', $store_apply_agreement, 0, 'saas');
  2334. Option::set('store_apply_audit', input_params('store_apply_audit', 0), 0, 'saas');
  2335. Option::set('store_apply_free', input_params('store_apply_free', 0), 0, 'saas');
  2336. Option::set('store_apply_free_days', input_params('store_apply_free_days', 0), 0, 'saas');
  2337. Option::set('store_apply_buy_type', input_params('store_apply_buy_type'), 0, 'saas');
  2338. Option::set('store_apply_buy_money', input_params('store_apply_buy_money', 0), 0, 'saas');
  2339. Option::set('store_apply_renew', input_params('store_apply_renew'), 0, 'saas');
  2340. Option::set('admin_profit', input_params('admin_profit'), 0, 'saas');
  2341. $priceList = input_params('priceList');
  2342. foreach ($priceList as $item) {
  2343. $model = StorePrice::findOne($item['id']);
  2344. $model->name = $item['name'];
  2345. $model->price = $item['price'];
  2346. $model->discount_name = $item['discount_name'];
  2347. $model->used = $item['used'];
  2348. $model->save();
  2349. }
  2350. return $this->asJson([
  2351. 'code' => 0,
  2352. 'msg' => '更新成功'
  2353. ]);
  2354. }
  2355. public function actionStorePriceAdd() {
  2356. $model = new StorePrice();
  2357. $id = input_params('id');
  2358. if($id){
  2359. $model = StorePrice::findOne($id);
  2360. }
  2361. $model->days = input_params('days');
  2362. $model->name = input_params('name');
  2363. $model->price = input_params('price');
  2364. $model->discount_name = input_params('discount_name');
  2365. $save = $model->save();
  2366. return $this->asJson([
  2367. 'code' => $save ? 0 : 1,
  2368. 'msg' => $save ? '成功' : '失败',
  2369. ]);
  2370. }
  2371. public function actionStorePriceDel() {
  2372. $model = StorePrice::findOne(input_params('id'));
  2373. $model->is_delete = 1;
  2374. $save = $model->save();
  2375. return $this->asJson([
  2376. 'code' => $save ? 0 : 1,
  2377. 'msg' => $save ? '删除成功' : '删除失败',
  2378. ]);
  2379. }
  2380. public function actionGetCloudApplyInfo() {
  2381. $cloud_apply_banner = Option::get('cloud_apply_banner', 0, 'saas', '')['value'];
  2382. $cloud_apply_agreement = Option::get('cloud_apply_agreement', 0, 'saas', '')['value'];
  2383. return $this->asJson([
  2384. 'code' => 0,
  2385. 'data' => [
  2386. 'cloud_apply_banner' => $cloud_apply_banner ? Json::decode($cloud_apply_banner) : [],
  2387. 'cloud_apply_agreement' => $cloud_apply_agreement
  2388. ]
  2389. ]);
  2390. }
  2391. public function actionSubmitCloudApplyInfo() {
  2392. $cloud_apply_banner = post_params('cloud_apply_banner', []);
  2393. $cloud_apply_agreement = post_params('cloud_apply_agreement', '');
  2394. Option::set('cloud_apply_banner', Json::encode($cloud_apply_banner), 0, 'saas');
  2395. Option::set('cloud_apply_agreement', $cloud_apply_agreement, 0, 'saas');
  2396. return $this->asJson([
  2397. 'code' => 0,
  2398. 'msg' => '更新成功'
  2399. ]);
  2400. }
  2401. public function actionMerchantList() {
  2402. $name = get_params('name');
  2403. $salesman = get_params('salesman');
  2404. $status = get_params('status');
  2405. $admin = get_admin();
  2406. $query = MerchantInfo::find()->alias('mi')->leftJoin(['su' => SaasUser::tableName()], 'su.id=mi.saas_user_id')
  2407. ->leftJoin(['s' => Store::tableName()], 's.id=mi.store_id')
  2408. ->where(['s.is_delete' => 0, 'mi.is_delete' => 0]);
  2409. if ($name) {
  2410. $query->andWhere(['or', ['like', 'mi.business_info', $name], ['like', 'mi.subject_info', $name]]);
  2411. }
  2412. if ($status != -1) {
  2413. $query->andWhere(['mi.status' => $status]);
  2414. }
  2415. if ($salesman) {
  2416. $query->andWhere(['like', 'su.name', $salesman]);
  2417. }
  2418. // 如果不是超级管理员,就查找业务员的进件列表
  2419. if ($admin->username != 'admin') {
  2420. $saas_user_id_arr = Salesman::find()->where(['admin_id' => $admin->id, 'is_delete' => 0, 'status' => 1])
  2421. ->select('saas_user_id')->column();
  2422. // $saas_user_id = empty($admin->saas_user_id) ? $admin->saas_user_id : -1;
  2423. $query->andWhere(['mi.saas_user_id' => $saas_user_id_arr ?: -1]);
  2424. }
  2425. $query->orderBy('mi.created_at desc, mi.updated_at desc')->select(['mi.*', 'su.name']);
  2426. $list = pagination_make($query);
  2427. foreach ($list['list'] as &$value) {
  2428. $value['store_logo'] = '';
  2429. $value['store_name'] = '';
  2430. if ($value['bind_store_id'] > 0) {
  2431. $store = Store::findOne($value['bind_store_id']);
  2432. if ($store) {
  2433. $value['store_logo'] = $store->logo;
  2434. $value['store_name'] = $store->name;
  2435. }
  2436. }
  2437. if (!empty($value['business_info'])) {
  2438. $business_info = Json::decode($value['business_info']);
  2439. $value['merchant_name'] = $business_info['merchant_shortname'];
  2440. } else {
  2441. $store = Store::findOne($value['bind_store_id']);
  2442. if ($store) {
  2443. $value['merchant_name'] = $store->name;
  2444. } else {
  2445. $value['merchant_name'] = '';
  2446. }
  2447. }
  2448. }
  2449. return $this->asJson([
  2450. 'code' => 0,
  2451. 'msg' => 'success',
  2452. 'data' => [
  2453. 'data' => $list['list'],
  2454. 'pageNo' => $list['pageNo'],
  2455. 'totalCount' => $list['totalCount'],
  2456. ]
  2457. ]);
  2458. }
  2459. /**
  2460. * ocr接口调用参数配置
  2461. * @return \yii\web\Response
  2462. */
  2463. public function actionOcrSetting()
  2464. {
  2465. $default = [
  2466. 'app_secret' => '',
  2467. 'app_key' => '',
  2468. ];
  2469. if (\Yii::$app->request->getIsPost()) {
  2470. $content = post_params('content', $default);
  2471. Option::set('ocr', json_encode($content), 0, 'saas');
  2472. return $this->asJson([
  2473. 'code' => 0,
  2474. 'msg' => '保存成功',
  2475. ]);
  2476. } else {
  2477. $content = Option::get('ocr', 0, 'saas', json_encode($default));
  2478. return $this->asJson([
  2479. 'code' => 0,
  2480. 'msg' => 'success',
  2481. 'data' => json_decode($content['value']),
  2482. ]);
  2483. }
  2484. }
  2485. /**
  2486. * 灵工接口调用参数配置
  2487. * @return \yii\web\Response
  2488. */
  2489. public function actionLgSetting()
  2490. {
  2491. $default = [
  2492. 'app_secret' => '',
  2493. 'app_key' => '',
  2494. ];
  2495. if (\Yii::$app->request->getIsPost()) {
  2496. $content = post_params('content', $default);
  2497. $store = Store::find()->where(['id'=> get_store_id()])->one();
  2498. $store->lg_mch_id = $content['lg_mch_id'];
  2499. $store->lg_project_code = $content['lg_project_code'];
  2500. $store->lg_park_code = $content['lg_park_code'];
  2501. $store->lg_pkey = $content['lg_pkey'];
  2502. $store->lg_key = $content['lg_key'];
  2503. if ($store->save()){
  2504. return $this->asJson([
  2505. 'code' => 0,
  2506. 'msg' => '保存成功',
  2507. ]);
  2508. }else{
  2509. return $this->asJson([
  2510. 'code' => 1,
  2511. 'msg' => '保存失败',
  2512. ]);
  2513. }
  2514. } else {
  2515. $store = Store::find()->where(['id'=> get_store_id()])->select('lg_mch_id,lg_project_code,lg_park_code,lg_pkey,lg_key')->asArray()->one();
  2516. return $this->asJson([
  2517. 'code' => 0,
  2518. 'msg' => 'success',
  2519. 'data' =>$store,
  2520. ]);
  2521. }
  2522. }
  2523. /**
  2524. * 云cloud接口调用参数配置
  2525. * @return \yii\web\Response
  2526. */
  2527. public function actionCloudSetting()
  2528. {
  2529. $default = [
  2530. 'name' => '',
  2531. 'pwd' => '',
  2532. 'rate' => '',
  2533. ];
  2534. if (\Yii::$app->request->getIsPost()) {
  2535. $post = post_params();
  2536. $domain = (new OptionSetting)->getCloudDomainName();
  2537. $url = $domain."/user/getToken";
  2538. $data =[];
  2539. $data['name'] = $post['name'];
  2540. $data['pwd'] = $post['pwd'];
  2541. // $response = cloud_post($url,$data);
  2542. // $response = json_decode($response,true);
  2543. // if($response['code'] != 0 || !$response['taken']){
  2544. // return $this->asJson([
  2545. // 'code' => 1,
  2546. // 'msg' => '保存失败',
  2547. // ]);
  2548. // }
  2549. // \Yii::$app->cache->set('cloud_admin_cache_token', $response['taken'], 2 * 24 * 3600);
  2550. // $data['access_token'] = $response['taken'];
  2551. $data['rate'] = isset($post['rate']) ? (float)$post['rate'] : 10;
  2552. $data['time'] = time();
  2553. Option::set('cloud', json_encode($data), 0, 'saas');
  2554. \Yii::$app->cache->delete('cloud_admin_cache_token');
  2555. get_platform_token();
  2556. return $this->asJson([
  2557. 'code' => 0,
  2558. 'msg' => 'success',
  2559. ]);
  2560. } else {
  2561. $content = Option::get('cloud', 0, 'saas', json_encode($default));
  2562. return $this->asJson([
  2563. 'code' => 0,
  2564. 'msg' => 'success',
  2565. 'data' => json_decode($content['value']),
  2566. ]);
  2567. }
  2568. }
  2569. // 云仓采购端配置自定义表单
  2570. public function actionCloudCustomForm()
  2571. {
  2572. try {
  2573. $default = [
  2574. 'name' => '',
  2575. 'pwd' => '',
  2576. 'rate' => '',
  2577. 'sale_day' => 0
  2578. ];
  2579. if (\Yii::$app->request->getIsPost()) {
  2580. $post = post_params();
  2581. // $domain = OptionSetting::CLOUD_DOMAIN_NAME;
  2582. // $url = $domain."/user/getToken";
  2583. $data =[];
  2584. $data['name'] = $post['name'];
  2585. $data['pwd'] = $post['pwd'];
  2586. $data['sale_day'] = $post['sale_day'];
  2587. // $response = cloud_post($url,$data);
  2588. // $response = json_decode($response,true);
  2589. // if ($response['code'] != 0 || !$response['taken']) {
  2590. // return $this->asJson([
  2591. // 'code' => 1,
  2592. // 'msg' => '保存失败',
  2593. // ]);
  2594. // }
  2595. // $data['access_token'] = $response['taken'];
  2596. // \Yii::$app->cache->set('cloud_admin_cache_token', $response['taken'], 2 * 24 * 3600);
  2597. $data['rate'] = isset($post['rate']) ? (float)$post['rate'] : 10;
  2598. $data['time'] = time();
  2599. Option::set('cloud', json_encode($data), 0, 'saas');
  2600. $cloud_domain_name = $post['cloud_domain_name'];
  2601. if ($cloud_domain_name) {
  2602. Option::set('cloud_domain_name', $cloud_domain_name, 0, 'cloud');
  2603. }
  2604. $list = post_params('list');
  2605. $supplier_list = post_params('supplier_list');
  2606. if (!$list) {
  2607. return $this->asJson([
  2608. 'code' => 1,
  2609. 'msg' => '缺少必要参数'
  2610. ]);
  2611. }
  2612. $cloud_apply_banner = post_params('cloud_apply_banner', []);
  2613. $cloud_supplier_banner = post_params('cloud_supplier_banner', []);
  2614. $cloud_apply_agreement = post_params('cloud_apply_agreement', '');
  2615. $cloud_supplier_apply_agreement = post_params('cloud_supplier_apply_agreement', '');
  2616. $is_supplier_set_price = post_params('is_supplier_set_price', 1);
  2617. Option::set('cloud_apply_banner', Json::encode($cloud_apply_banner), 0, 'saas');
  2618. Option::set('cloud_supplier_banner', Json::encode($cloud_supplier_banner), 0, 'saas');
  2619. Option::set('cloud_apply_agreement', $cloud_apply_agreement, 0, 'saas');
  2620. Option::set('cloud_supplier_apply_agreement', $cloud_supplier_apply_agreement, 0, 'saas');
  2621. Option::set('cloud_custom_form', json_encode($list), 0, 'saas');
  2622. Option::set('supplier_custom_form', json_encode($supplier_list), 0, 'saas');
  2623. Option::set('is_supplier_set_price', $is_supplier_set_price, 0, 'cloud');
  2624. return $this->asJson([
  2625. 'code' => 0,
  2626. 'msg' => '保存成功',
  2627. ]);
  2628. }
  2629. $cloud_apply_banner = Option::get('cloud_apply_banner', 0, 'saas', '')['value'];
  2630. $cloud_supplier_banner = Option::get('cloud_supplier_banner', 0, 'saas', '')['value'];
  2631. $cloud_apply_agreement = Option::get('cloud_apply_agreement', 0, 'saas', '')['value'];
  2632. $cloud_supplier_apply_agreement = Option::get('cloud_supplier_apply_agreement', 0, 'saas', '')['value'];
  2633. $content = Option::get('cloud', 0, 'saas', json_encode($default));
  2634. $list = Option::get('cloud_custom_form', 0, 'saas', json_encode([]));
  2635. $supplier_custom_form = Option::get('supplier_custom_form', 0, 'saas', json_encode([]));
  2636. $cloud_domain_name = Option::get('cloud_domain_name', 0, 'cloud', 'http://yuncang.tianxin100.vip')['value'];
  2637. $is_supplier_set_price = Option::get('is_supplier_set_price', 0, 'cloud', 1)['value'];
  2638. $content = json_decode($content['value'], true);
  2639. $content = array_merge($content, [
  2640. 'cloud_domain_name' => $cloud_domain_name
  2641. ]);
  2642. return $this->asJson([
  2643. 'code' => 0,
  2644. 'msg' => 'success',
  2645. 'data' => [
  2646. 'list' => json_decode($list['value']),
  2647. 'supplier_custom_form' => json_decode($supplier_custom_form['value']),
  2648. 'cloud_apply_banner' => $cloud_apply_banner ? Json::decode($cloud_apply_banner) : [],
  2649. 'cloud_supplier_banner' => $cloud_supplier_banner ? Json::decode($cloud_supplier_banner) : [],
  2650. 'cloud_apply_agreement' => $cloud_apply_agreement,
  2651. 'cloud_supplier_apply_agreement' => $cloud_supplier_apply_agreement,
  2652. 'is_supplier_set_price' => (int)$is_supplier_set_price,
  2653. 'content' => $content,
  2654. ]
  2655. ]);
  2656. } catch (\Exception $e) {
  2657. return $this->asJson([
  2658. 'code' => 1,
  2659. 'msg' => $e->getMessage()
  2660. ]);
  2661. }
  2662. }
  2663. /**
  2664. * 获取信息
  2665. * @return \yii\web\Response
  2666. */
  2667. public function actionOcrInfo() {
  2668. $type = post_params('type');
  2669. if (empty($type) || !in_array($type, OcrApi::$validType)) {
  2670. return $this->asJson([
  2671. 'code' => 1,
  2672. 'msg' => '类型参数错误'
  2673. ]);
  2674. }
  2675. $side = post_params('side');
  2676. if (empty($side) && $type == OcrApi::TYPE_ID_CARD) {
  2677. return $this->asJson([
  2678. 'code' => 1,
  2679. 'msg' => '身份证参数有误'
  2680. ]);
  2681. }
  2682. $url = post_params('url');
  2683. if (empty($url)) {
  2684. return $this->asJson([
  2685. 'code' => 1,
  2686. 'msg' => '图片地址为空'
  2687. ]);
  2688. }
  2689. try {
  2690. $ocr = new OcrApi(true);
  2691. switch ($type) {
  2692. case OcrApi::TYPE_LICENSE:
  2693. $res = $ocr->getBusinessLicense($url);
  2694. break;
  2695. case OcrApi::TYPE_ID_CARD:
  2696. $res = $ocr->getIDCard($url, $side);
  2697. break;
  2698. case OcrApi::TYPE_BANK:
  2699. $res = $ocr->getBankCard($url);
  2700. break;
  2701. }
  2702. if ($res['code'] == 0 && !empty($res['data'])) {
  2703. return $this->asJson($res);
  2704. }
  2705. return $this->asJson([
  2706. 'code' => -1,
  2707. 'msg' => '获取信息失败'
  2708. ]);
  2709. } catch (\Exception $e) {
  2710. return $this->asJson([
  2711. 'code' => -1,
  2712. 'msg' => $e->getMessage()
  2713. ]);
  2714. }
  2715. }
  2716. /**
  2717. * 获取积分赠送规则
  2718. */
  2719. public function actionGetIntegralRules()
  2720. {
  2721. $form = new SaasForm();
  2722. $form->attributes = post_params();
  2723. return $this->asJson($form->getInfo());
  2724. }
  2725. /**
  2726. * @return \yii\web\Response
  2727. * 获取列表
  2728. */
  2729. public function actionGetList()
  2730. {
  2731. $form = new SaasForm();
  2732. $form->attributes = post_params();
  2733. return $this->asJson($form->getRulesList());
  2734. }
  2735. /**
  2736. * 获取商城信息
  2737. */
  2738. public function actionGetStore()
  2739. {
  2740. $form = new SaasForm();
  2741. $form->attributes = post_params();
  2742. return $this->asJson($form->getStoreList());
  2743. }
  2744. /**
  2745. * 修改规则状态
  2746. */
  2747. public function actionSetStatus()
  2748. {
  2749. $form = new SaasForm();
  2750. $form->attributes = post_params();
  2751. return $this->asJson($form->SetStatus());
  2752. }
  2753. /**
  2754. * 店铺分销列表
  2755. * @return \yii\web\Response
  2756. */
  2757. public function actionStoreShareList()
  2758. {
  2759. $store_name = get_params('store_name');
  2760. $nickname = get_params('nickname');
  2761. $mobile = get_params('mobile');
  2762. $status = get_params('status', -1);
  2763. if (!in_array($status, [-1, 0, 1])) {
  2764. $status = -1;
  2765. }
  2766. $query = Store::find()->alias('s')->leftJoin(['a' => Admin::tableName()], 's.admin_id = a.id');
  2767. $query->where(['s.is_delete' => 0]);
  2768. if ($store_name) {
  2769. $query->andWhere(['like', 's.name', $store_name]);
  2770. }
  2771. if ($nickname) {
  2772. $query->andWhere(['like', 'a.name', $nickname]);
  2773. }
  2774. if ($mobile) {
  2775. $query->andWhere(['like', 'a.mobile', $mobile]);
  2776. }
  2777. if ($status > -1) {
  2778. $query->andWhere(['s.store_share_switch' => $status]);
  2779. }
  2780. $query->select('s.id, s.name as store_name, s.logo, a.name as nickname, a.mobile, s.store_share_switch, s.store_share_type, s.store_share_value');
  2781. $list = pagination_make($query);
  2782. $defaultSet = Option::get(OptionSetting::SHARE_STORE_DEFAULT_SETTING, -1, OptionSetting::SHARE_GROUP_NAME, '{}');
  2783. $defaultSet = json_decode($defaultSet['value'], true);
  2784. foreach ($list['list'] as &$item) {
  2785. $amount = SharingReceiver::find()->where([
  2786. 'store_id' => $item['id'],
  2787. 'from' => 0,
  2788. 'is_delete' => 0,
  2789. ])->sum('amount');
  2790. $item['income'] = $amount ?: '0.00';
  2791. $item['expenditure'] = '0.00';
  2792. $item['use_default'] = 0;
  2793. if($item['store_share_switch'] != 0 && $item['store_share_value'] == 0){
  2794. if(!empty($defaultSet['store_share_switch']) && !empty($defaultSet['store_share_value'])){
  2795. $item['store_share_value'] = $defaultSet['store_share_value'];
  2796. $item['use_default'] = 1;
  2797. }
  2798. }
  2799. }
  2800. return $this->asJson([
  2801. 'code' => 0,
  2802. 'msg' => 'success',
  2803. 'data' => [
  2804. 'defaultSet' => $defaultSet,
  2805. 'data' => $list['list'],
  2806. 'pageNo' => $list['pageNo'],
  2807. 'totalCount' => $list['totalCount'],
  2808. ]
  2809. ]);
  2810. }
  2811. /**
  2812. * 修改店铺间分销设置
  2813. * @return Response
  2814. * @throws InvalidConfigException
  2815. * @throws StaleObjectException
  2816. * @throws Exception
  2817. */
  2818. public function actionSetIntegralRules()
  2819. {
  2820. $form = new SaasForm();
  2821. $form->attributes = post_params();
  2822. return $this->asJson($form->save());
  2823. }
  2824. /**
  2825. * 修改店铺间分销设置
  2826. * @return Response
  2827. * @throws InvalidConfigException
  2828. * @throws StaleObjectException
  2829. * @throws Exception
  2830. */
  2831. public function actionStoreShareOption()
  2832. {
  2833. $store_id = post_params('store_id');
  2834. $store_share_switch = post_params('store_share_switch');
  2835. $store_share_type = post_params('store_share_type');
  2836. $store_share_value = post_params('store_share_value');
  2837. // $store_recharge_profit = post_params('store_recharge_profit');
  2838. $store_profit_max = post_params('store_profit_max');
  2839. $store_profit_min = post_params('store_profit_min');
  2840. $store_send_min = post_params('store_send_min');
  2841. // $store_send_profit = post_params('store_send_profit');
  2842. // Option::set('store_recharge_profit', $store_recharge_profit, 0);
  2843. Option::set('store_profit_max', $store_profit_max, 0);
  2844. Option::set('store_profit_min', $store_profit_min, 0);
  2845. Option::set('store_send_min', $store_send_min, 0);
  2846. // Option::set('store_send_profit', $store_send_profit, 0);
  2847. //默认配置
  2848. if(intval($store_id) === -1){
  2849. $json = json_encode([
  2850. 'store_share_switch' => $store_share_switch,
  2851. 'store_share_type' => $store_share_type,
  2852. 'store_share_value' => $store_share_value,
  2853. 'store_profit_max' => $store_profit_max,
  2854. 'store_profit_min' => $store_profit_min,
  2855. 'store_send_min' => $store_send_min,
  2856. // 'store_send_profit' => $store_send_profit,
  2857. // 'store_recharge_profit' => $store_recharge_profit,
  2858. ]);
  2859. $res = Option::set(OptionSetting::SHARE_STORE_DEFAULT_SETTING, $json, $store_id, OptionSetting::SHARE_GROUP_NAME);
  2860. if(!$res){
  2861. return $this->asJson([
  2862. 'code' => 1,
  2863. 'msg' => '默认配置编辑失败',
  2864. ]);
  2865. }
  2866. return $this->asJson([
  2867. 'code' => 0,
  2868. 'msg' => '默认配置编辑成功',
  2869. ]);
  2870. }
  2871. if (empty($store_id)) {
  2872. return $this->asJson([
  2873. 'code' => 1,
  2874. 'msg' => '缺少必要参数',
  2875. ]);
  2876. }
  2877. $store = Store::findOne($store_id);
  2878. if (!$store) {
  2879. return $this->asJson([
  2880. 'code' => 1,
  2881. 'msg' => '商城未找到',
  2882. ]);
  2883. }
  2884. if ($store_share_switch !== null) {
  2885. if (!in_array($store_share_switch, [0, 1])) {
  2886. return $this->asJson([
  2887. 'code' => 1,
  2888. 'msg' => '参数错误',
  2889. ]);
  2890. }
  2891. $store->store_share_switch = $store_share_switch;
  2892. }
  2893. if ($store_share_type !== null) {
  2894. if (!in_array($store_share_type, [0, 1])) {
  2895. return $this->asJson([
  2896. 'code' => 1,
  2897. 'msg' => '参数错误',
  2898. ]);
  2899. }
  2900. $store->store_share_type = $store_share_type;
  2901. }
  2902. if (isset($store_share_value)) {
  2903. $store->store_share_value = $store_share_value;
  2904. }
  2905. if (!union_share_scale_check($store)) {
  2906. return $this->asJson([
  2907. 'code' => 1,
  2908. 'msg' => '保存失败,分销比例超过100%',
  2909. ]);
  2910. }
  2911. if (!$store->save()) {
  2912. return $this->asJson([
  2913. 'code' => 1,
  2914. 'msg' => $store->errors[0],
  2915. ]);
  2916. }
  2917. return $this->asJson([
  2918. 'code' => 0,
  2919. 'msg' => '编辑成功',
  2920. ]);
  2921. }
  2922. /**
  2923. * 店铺间分销佣金明细
  2924. * @return Response
  2925. * @throws InvalidConfigException
  2926. * @throws Throwable
  2927. * @throws Exception
  2928. */
  2929. public function actionStoreShareLog()
  2930. {
  2931. $store_name = get_params('store_name');
  2932. $nickname = get_params('nickname');
  2933. $mobile = get_params('mobile');
  2934. $status = get_params('status', -1);
  2935. $start_date = get_params('start_date');
  2936. $end_date = get_params('end_date');
  2937. if (!in_array($status, [-1, 0, 1])) {
  2938. $status = -1;
  2939. }
  2940. $query = SharingReceiver::find()->alias('sr')->leftJoin(['s' => Store::tableName()], 'sr.store_id = s.id')
  2941. ->leftJoin(['su' => SaasUser::tableName()], 'sr.saas_id = su.id')
  2942. ->where(['sr.is_delete' => 0, 'sr.from' => SharingReceiver::FROM_STORE_TO_STORE]);
  2943. if ($store_name) {
  2944. $query->andWhere(['like', 's.name', $store_name]);
  2945. }
  2946. if ($nickname) {
  2947. $query->andWhere(['like', 'su.name', $nickname]);
  2948. }
  2949. if ($mobile) {
  2950. $query->andWhere(['like', 'su.mobile', $mobile]);
  2951. }
  2952. if ($status > -1) {
  2953. $query->andWhere(['sr.is_pay' => $status]);
  2954. }
  2955. if ($start_date) {
  2956. $query->andWhere(['>=', 'sr.created_at', strtotime($start_date)]);
  2957. }
  2958. if ($end_date) {
  2959. $query->andWhere(['<=', 'sr.created_at', strtotime($end_date)]);
  2960. }
  2961. $query->select('sr.id, sr.to_store_id, sr.order_no, s.name as store_name, sr.rate, sr.amount, sr.account, sr.is_pay, sr.created_at, sr.err_code_des ,sr.execute_type, sr.updated_at');
  2962. $list = pagination_make($query);
  2963. foreach ($list['list'] as &$item) {
  2964. //未改动前端 只调了数据
  2965. if ($item['to_store_id']) {
  2966. $store = Store::findOne($item['to_store_id']);
  2967. $item['avatar'] = $store->logo ?? '';
  2968. $item['name'] = $store->name ?? '';
  2969. }
  2970. $item['created_at'] = date("Y-m-d H:i", $item['created_at']);
  2971. }
  2972. return $this->asJson([
  2973. 'code' => 0,
  2974. 'msg' => 'success',
  2975. 'data' => [
  2976. 'data' => $list['list'],
  2977. 'pageNo' => $list['pageNo'],
  2978. 'totalCount' => $list['totalCount'],
  2979. ]
  2980. ]);
  2981. }
  2982. /**
  2983. * 联盟分销列表
  2984. * @return \yii\web\Response
  2985. */
  2986. public function actionSaasShareList()
  2987. {
  2988. $store_name = get_params('store_name');
  2989. $nickname = get_params('nickname');
  2990. $mobile = get_params('mobile');
  2991. $query = Store::find()->alias('s')->leftJoin(['a' => Admin::tableName()], 's.admin_id = a.id');
  2992. $query->where(['s.is_delete' => 0]);
  2993. if ($store_name) {
  2994. $query->andWhere(['like', 's.name', $store_name]);
  2995. }
  2996. if ($nickname) {
  2997. $query->andWhere(['like', 'a.name', $nickname]);
  2998. }
  2999. if ($mobile) {
  3000. $query->andWhere(['like', 'a.mobile', $mobile]);
  3001. }
  3002. $query->select('s.id, s.name as store_name, s.logo, a.name as nickname, a.mobile, s.share_setting');
  3003. $list = pagination_make($query);
  3004. foreach ($list['list'] as &$item) {
  3005. $amount = SharingReceiver::find()->where([
  3006. 'store_id' => $item['id'],
  3007. 'from' => 1,
  3008. 'is_delete' => 0,
  3009. ])->sum('amount');
  3010. $item['expenditure'] = $amount ?: '0.00';
  3011. if (empty($item['share_setting'])) {
  3012. $item['switch'] = 0;
  3013. $item['price_type'] = 0;
  3014. $item['level_one'] = '0.00';
  3015. $item['level_two'] = '0.00';
  3016. $item['level_three'] = '0.00';
  3017. $item['is_rebate'] = 0;
  3018. } else {
  3019. $option = json_decode($item['share_setting'], true);
  3020. $item['switch'] = $option['level'];
  3021. $item['price_type'] = $option['price_type'];
  3022. $item['level_one'] = $option['level_one'];
  3023. $item['level_two'] = $option['level_two'];
  3024. $item['level_three'] = $option['level_three'];
  3025. $item['is_rebate'] = $option['is_rebate'];
  3026. }
  3027. $item['use_default'] = 0;
  3028. if($item['switch'] != 0 && $item['level_one'] == 0 && $item['level_two'] == 0 && $item['level_three'] == 0){
  3029. $defaultSet = Option::get(OptionSetting::SHARE_SAAS_DEFAULT_SETTING, -1, OptionSetting::SHARE_GROUP_NAME, '{}');
  3030. $defaultSet = json_decode($defaultSet['value'], true);
  3031. if(!empty($defaultSet['level']) &&
  3032. (!empty($defaultSet['level_one']) || !empty($defaultSet['level_two']) || !empty($defaultSet['level_three']))){
  3033. $item['switch'] = $defaultSet['level'];
  3034. $item['price_type'] = $defaultSet['price_type'];
  3035. $item['level_one'] = $defaultSet['level_one'];
  3036. $item['level_two'] = $defaultSet['level_two'];
  3037. $item['level_three'] = $defaultSet['level_three'];
  3038. $item['is_rebate'] = $defaultSet['is_rebate'];
  3039. $item['use_default'] = 1;
  3040. }
  3041. }
  3042. }
  3043. //默认配置
  3044. $defaultSet = Option::get(OptionSetting::SHARE_SAAS_DEFAULT_SETTING, -1, OptionSetting::SHARE_GROUP_NAME, '{}');
  3045. return $this->asJson([
  3046. 'code' => 0,
  3047. 'msg' => 'success',
  3048. 'data' => [
  3049. 'defaultSet' => json_decode($defaultSet['value']),
  3050. 'data' => $list['list'],
  3051. 'pageNo' => $list['pageNo'],
  3052. 'totalCount' => $list['totalCount'],
  3053. ]
  3054. ]);
  3055. }
  3056. /**
  3057. * 联盟分销佣金明细
  3058. * @return Response
  3059. * @throws InvalidConfigException
  3060. * @throws Throwable
  3061. * @throws Exception
  3062. */
  3063. public function actionSaasShareLog()
  3064. {
  3065. $store_name = get_params('store_name');
  3066. $nickname = get_params('nickname');
  3067. $mobile = get_params('mobile');
  3068. $status = get_params('status', -1);
  3069. $start_date = get_params('start_date');
  3070. $end_date = get_params('end_date');
  3071. if (!in_array($status, [-1, 0, 1])) {
  3072. $status = -1;
  3073. }
  3074. $query = SharingReceiver::find()->alias('sr')->leftJoin(['s' => Store::tableName()], 'sr.store_id = s.id')
  3075. //->leftJoin(['su' => SaasUser::tableName()], 'sr.user_id = su.id')
  3076. ->leftJoin(['su' => SaasUser::tableName()], 'sr.saas_id = su.id')
  3077. ->where(['sr.is_delete' => 0, 'sr.from' => 1]);
  3078. if ($store_name) {
  3079. $query->andWhere(['like', 's.name', $store_name]);
  3080. }
  3081. if ($nickname) {
  3082. $query->andWhere(['like', 'su.name', $nickname]);
  3083. }
  3084. if ($mobile) {
  3085. $query->andWhere(['like', 'su.mobile', $mobile]);
  3086. }
  3087. if ($status > -1) {
  3088. $query->andWhere(['sr.is_pay' => $status]);
  3089. }
  3090. if ($start_date) {
  3091. $query->andWhere(['>=', 'sr.created_at', strtotime($start_date)]);
  3092. }
  3093. if ($end_date) {
  3094. $query->andWhere(['<=', 'sr.created_at', strtotime($end_date)]);
  3095. }
  3096. $query->select('sr.id, su.avatar, su.name, su.mobile, sr.order_no, s.name as store_name, sr.rate, sr.amount, sr.is_pay, sr.created_at, sr.err_code_des, sr.execute_type, sr.updated_at, sr.remark')->orderBy('sr.created_at desc');
  3097. $list = pagination_make($query);
  3098. foreach ($list['list'] as &$item) {
  3099. if(!$item['avatar'] && $item['id']){
  3100. $userInfo = User::find()->where(['id'=>$item['id'],'is_delete'=>0])->one();
  3101. if(!empty($userInfo) && !empty($userInfo->avatar_url)){
  3102. $item['avatar'] = $userInfo->avatar_url;
  3103. $item['name'] = $userInfo->nickname;
  3104. }
  3105. }
  3106. $item['created_at'] = date("Y-m-d H:i", $item['created_at']);
  3107. }
  3108. return $this->asJson([
  3109. 'code' => 0,
  3110. 'msg' => 'success',
  3111. 'data' => [
  3112. 'data' => $list['list'],
  3113. 'pageNo' => $list['pageNo'],
  3114. 'totalCount' => $list['totalCount'],
  3115. ]
  3116. ]);
  3117. }
  3118. /**
  3119. * 供货商推荐人列表
  3120. */
  3121. public function actionSupplierReferralList()
  3122. {
  3123. $supplier_name = get_params('supplier_name');
  3124. $nickname = get_params('nickname');
  3125. $mobile = get_params('mobile');
  3126. $status = get_params('status', -1);
  3127. if (!in_array($status, [-1, 0, 1])) {
  3128. $status = -1;
  3129. }
  3130. $query = SaasSupplierReferral::find()->alias('ssr')
  3131. ->leftJoin(['su' => SaasUser::tableName()], 'ssr.referral_id = su.id')
  3132. ->leftJoin(['s' => Supplier::tableName()], 'ssr.supplier_id = s.id');
  3133. $query->where(['s.is_delete' => 0]);
  3134. if ($supplier_name) {
  3135. $query->andWhere(['like', 's.name', $supplier_name]);
  3136. }
  3137. if ($nickname) {
  3138. $query->andWhere(['like', 'su.name', $nickname]);
  3139. }
  3140. if ($mobile) {
  3141. $query->andWhere(['like', 'su.mobile', $mobile]);
  3142. }
  3143. if ($status > -1) {
  3144. $query->andWhere(['ssr.is_enable' => $status]);
  3145. }
  3146. $query->orderBy('ssr.id DESC');
  3147. $query->select('ssr.id, ssr.supplier_id, ssr.referral_id, ssr.is_enable, s.supplier_name, s.logo as supplier_logo, s.phone as supplier_phone,
  3148. ssr.referral_rebate, su.avatar, su.name as nickname, su.mobile, su.id as user_id
  3149. ');
  3150. $list = pagination_make($query);
  3151. //默认配置
  3152. $defaultSet = Option::get(OptionSetting::SHARE_SAAS_SUPPLIER_REFERRAL_DEFAULT_SETTING, -1, OptionSetting::SHARE_GROUP_NAME, '{}')['value'];
  3153. $defaultSet = json_decode($defaultSet, true);
  3154. foreach ($list['list'] as &$item) {
  3155. $item['amount'] = SaasUserPriceLog::find()->where(['saas_id' => $item['referral_id'], 'amount_type' => SaasUserPriceLog::AMOUNT_TYPE_SUPPLIER_PARENT])->sum('amount') ?: '0.00';
  3156. $item['use_default'] = 0;
  3157. if($item['is_enable'] != 0 && $item['referral_rebate'] == 0){
  3158. if(!empty($defaultSet['is_enable']) && !empty($defaultSet['referral_rebate'])){
  3159. $item['referral_rebate'] = $defaultSet['referral_rebate'];
  3160. $item['use_default'] = 1;
  3161. }
  3162. }
  3163. }
  3164. return $this->asJson([
  3165. 'code' => 0,
  3166. 'msg' => 'success',
  3167. 'data' => [
  3168. 'defaultSet' => $defaultSet,
  3169. 'data' => $list['list'],
  3170. 'pageNo' => $list['pageNo'],
  3171. 'totalCount' => $list['totalCount'],
  3172. ]
  3173. ]);
  3174. }
  3175. /**
  3176. * 供货商推荐人新增编辑
  3177. */
  3178. public function actionEditSupplierReferral()
  3179. {
  3180. $id = post_params('id');
  3181. $supplier_id = post_params('supplier_id');
  3182. $is_enable = post_params('is_enable');
  3183. $referral_id = post_params('referral_id');
  3184. $referral_rebate = post_params('referral_rebate', '0.00');
  3185. if (!$id) {
  3186. $has = SaasSupplierReferral::findOne([
  3187. 'supplier_id' => $supplier_id
  3188. ]);
  3189. if($has){
  3190. return $this->asJson([
  3191. 'code' => 1,
  3192. 'msg' => '不能重复添加',
  3193. ]);
  3194. }
  3195. }
  3196. //默认配置
  3197. if(intval($supplier_id) === -1){
  3198. $json = json_encode([
  3199. 'is_enable' => $is_enable,
  3200. 'referral_rebate' => $referral_rebate,
  3201. ]);
  3202. $res = Option::set(OptionSetting::SHARE_SAAS_SUPPLIER_REFERRAL_DEFAULT_SETTING, $json, $supplier_id, OptionSetting::SHARE_GROUP_NAME);
  3203. if(!$res){
  3204. return $this->asJson([
  3205. 'code' => 1,
  3206. 'msg' => '默认配置编辑失败',
  3207. ]);
  3208. }
  3209. return $this->asJson([
  3210. 'code' => 0,
  3211. 'msg' => '默认配置编辑成功',
  3212. ]);
  3213. }
  3214. if (!in_array($is_enable, [0, 1])) {
  3215. return $this->asJson([
  3216. 'code' => 1,
  3217. 'msg' => '参数错误',
  3218. ]);
  3219. }
  3220. $supplier = Supplier::findOne($supplier_id);
  3221. if (!$supplier) {
  3222. return $this->asJson([
  3223. 'code' => 1,
  3224. 'msg' => '供货商不存在',
  3225. ]);
  3226. }
  3227. if ($id) {
  3228. $item = SaasSupplierReferral::findOne($id);
  3229. if ($is_enable !== null) {
  3230. $item->is_enable = $is_enable;
  3231. }
  3232. if (isset($referral_rebate)) {
  3233. $item->referral_rebate = $referral_rebate;
  3234. }
  3235. $item->save();
  3236. return $this->asJson([
  3237. 'code' => 0,
  3238. 'msg' => '编辑成功',
  3239. ]);
  3240. } else {
  3241. $saasUser = SaasUser::findOne($referral_id);
  3242. if (!$saasUser) {
  3243. return $this->asJson([
  3244. 'code' => 1,
  3245. 'msg' => '用户不存在',
  3246. ]);
  3247. }
  3248. $item = new SaasSupplierReferral();
  3249. $item->supplier_id = $supplier_id;
  3250. $item->referral_id = $referral_id;
  3251. $item->referral_rebate = $referral_rebate;
  3252. $item->is_enable = $is_enable;
  3253. $item->save();
  3254. return $this->asJson([
  3255. 'code' => 0,
  3256. 'msg' => '绑定成功',
  3257. ]);
  3258. }
  3259. return $this->asJson([
  3260. 'code' => 1,
  3261. 'msg' => '参数错误',
  3262. ]);
  3263. }
  3264. /**
  3265. * 推荐人列表
  3266. * @return Response
  3267. * @throws InvalidConfigException
  3268. * @throws Throwable
  3269. * @throws Exception
  3270. */
  3271. public function actionReferralList()
  3272. {
  3273. $store_name = get_params('store_name');
  3274. $nickname = get_params('nickname');
  3275. $mobile = get_params('mobile');
  3276. $status = get_params('status', -1);
  3277. $query = SaasStoreReferral::find()->alias('ssr')
  3278. ->leftJoin(['su' => SaasUser::tableName()], 'ssr.referral_id = su.id')
  3279. ->leftJoin(['s' => Store::tableName()], 'ssr.store_id = s.id');
  3280. $query->where(['s.is_delete' => 0, 'ssr.type' => 1]);
  3281. if ($store_name) {
  3282. $query->andWhere(['like', 's.name', $store_name]);
  3283. }
  3284. if ($nickname) {
  3285. $query->andWhere(['like', 'su.name', $nickname]);
  3286. }
  3287. if ($mobile) {
  3288. $query->andWhere(['like', 'su.mobile', $mobile]);
  3289. }
  3290. if (isset($status) && in_array($status, [0, 1])) {
  3291. $query->andWhere(['ssr.is_enable' => $status]);
  3292. }
  3293. $query->orderBy('ssr.id DESC');
  3294. $query->select('ssr.id, ssr.store_id, ssr.referral_id, ssr.is_enable, s.name as store_name, s.logo as store_logo, s.contact_tel,
  3295. ssr.referral_rebate, su.avatar, su.name as nickname, su.mobile, su.id as user_id
  3296. ');
  3297. $list = pagination_make($query);
  3298. foreach ($list['list'] as &$item) {
  3299. $item['amount'] = SharingReceiver::find()->where(['is_delete' => 0, 'saas_id' => $item['user_id'], 'from' => SharingReceiver::FROM_NEW_STORE_RECOMMEND])
  3300. ->sum('amount') ?: '0.00';
  3301. $item['use_default'] = 0;
  3302. if($item['is_enable'] != 0 && $item['referral_rebate'] == 0){
  3303. $defaultSet = Option::get(OptionSetting::SHARE_SAAS_REFERRAL_DEFAULT_SETTING, -1, OptionSetting::SHARE_GROUP_NAME, '{}');
  3304. $defaultSet = json_decode($defaultSet['value'], true);
  3305. if(!empty($defaultSet['is_enable']) && !empty($defaultSet['referral_rebate'])){
  3306. $item['referral_rebate'] = $defaultSet['referral_rebate'];
  3307. $item['use_default'] = 1;
  3308. }
  3309. }
  3310. }
  3311. //默认配置
  3312. $defaultSet = Option::get(OptionSetting::SHARE_SAAS_REFERRAL_DEFAULT_SETTING, -1, OptionSetting::SHARE_GROUP_NAME, '{}');
  3313. return $this->asJson([
  3314. 'code' => 0,
  3315. 'msg' => 'success',
  3316. 'data' => [
  3317. 'defaultSet' => json_decode($defaultSet['value']),
  3318. 'data' => $list['list'],
  3319. 'pageNo' => $list['pageNo'],
  3320. 'totalCount' => $list['totalCount'],
  3321. ]
  3322. ]);
  3323. }
  3324. /**
  3325. * 推荐人新增编辑
  3326. * @return Response
  3327. * @throws InvalidConfigException
  3328. * @throws StaleObjectException
  3329. * @throws Exception
  3330. * @throws NotSupportedException
  3331. * @throws InvalidArgumentException
  3332. * @throws GlobalException
  3333. */
  3334. public function actionEditReferral()
  3335. {
  3336. $id = post_params('id');
  3337. $store_id = post_params('store_id');
  3338. $is_enable = post_params('is_enable');
  3339. $referral_id = post_params('referral_id');
  3340. $referral_rebate = post_params('referral_rebate', '0.00');
  3341. if (!$id) {
  3342. $has = SaasStoreReferral::findOne([
  3343. 'store_id' => $store_id,
  3344. 'type' => 1
  3345. ]);
  3346. if($has){
  3347. return $this->asJson([
  3348. 'code' => 1,
  3349. 'msg' => '不能重复添加',
  3350. ]);
  3351. }
  3352. }
  3353. //默认配置
  3354. if(intval($store_id) === -1){
  3355. $json = json_encode([
  3356. 'is_enable' => $is_enable,
  3357. 'referral_rebate' => $referral_rebate,
  3358. ]);
  3359. $res = Option::set(OptionSetting::SHARE_SAAS_REFERRAL_DEFAULT_SETTING, $json, $store_id, OptionSetting::SHARE_GROUP_NAME);
  3360. if(!$res){
  3361. return $this->asJson([
  3362. 'code' => 1,
  3363. 'msg' => '默认配置编辑失败',
  3364. ]);
  3365. }
  3366. return $this->asJson([
  3367. 'code' => 0,
  3368. 'msg' => '默认配置编辑成功',
  3369. ]);
  3370. }
  3371. if (!in_array($is_enable, [0, 1])) {
  3372. return $this->asJson([
  3373. 'code' => 1,
  3374. 'msg' => '参数错误',
  3375. ]);
  3376. }
  3377. $store = Store::findOne($store_id);
  3378. if (!$store) {
  3379. return $this->asJson([
  3380. 'code' => 1,
  3381. 'msg' => '商城不存在',
  3382. ]);
  3383. }
  3384. $scale = union_share_scale($store, true);
  3385. if ($id) {
  3386. $item = SaasStoreReferral::findOne($id);
  3387. if ($is_enable !== null) {
  3388. $item->is_enable = $is_enable;
  3389. }
  3390. if (isset($referral_rebate)) {
  3391. // 检查比例是否超过100%
  3392. $referral = SaasStoreReferral::find()
  3393. ->where(['store_id' => $store->id, 'type' => 1])
  3394. ->andWhere(['<>', 'id', $id])
  3395. ->asArray()
  3396. ->all();
  3397. if (count($referral) > 0) {
  3398. foreach ($referral as $iitem) {
  3399. $scale += $iitem['referral_rebate'];
  3400. }
  3401. }
  3402. $scale += $referral_rebate;
  3403. if ($scale > 100) {
  3404. return $this->asJson([
  3405. 'code' => 1,
  3406. 'msg' => '编辑失败,分销比例超过100% 当前累计分销比例:' . $scale .'%',
  3407. ]);
  3408. }
  3409. $item->referral_rebate = $referral_rebate;
  3410. }
  3411. $item->save();
  3412. return $this->asJson([
  3413. 'code' => 0,
  3414. 'msg' => '编辑成功',
  3415. ]);
  3416. } else {
  3417. $saasUser = SaasUser::findOne($referral_id);
  3418. if (!$saasUser) {
  3419. return $this->asJson([
  3420. 'code' => 1,
  3421. 'msg' => '用户不存在',
  3422. ]);
  3423. }
  3424. // 检查比例是否超过100%
  3425. $referral = SaasStoreReferral::find()
  3426. ->where(['store_id' => $store->id, 'type' => 1])
  3427. ->asArray()
  3428. ->all();
  3429. if (count($referral) > 0) {
  3430. foreach ($referral as $item) {
  3431. $scale += $item['referral_rebate'];
  3432. }
  3433. }
  3434. $scale += $referral_rebate;
  3435. if ($scale > 100) {
  3436. return $this->asJson([
  3437. 'code' => 1,
  3438. 'msg' => '创建失败,分销比例超过100% 当前累计分销比例:' . $scale .'%',
  3439. ]);
  3440. }
  3441. $item = new SaasStoreReferral();
  3442. $item->store_id = $store_id;
  3443. $item->referral_id = $referral_id;
  3444. $item->referral_rebate = $referral_rebate;
  3445. $item->is_enable = $is_enable;
  3446. $item->type = 1;
  3447. $item->save();
  3448. return $this->asJson([
  3449. 'code' => 0,
  3450. 'msg' => '绑定成功',
  3451. ]);
  3452. }
  3453. return $this->asJson([
  3454. 'code' => 1,
  3455. 'msg' => '参数错误',
  3456. ]);
  3457. }
  3458. /**
  3459. * 删除绑定推荐人
  3460. * @return Response
  3461. * @throws InvalidConfigException
  3462. * @throws StaleObjectException
  3463. * @throws GlobalException
  3464. * @throws Throwable
  3465. */
  3466. public function actionDeleteReferral()
  3467. {
  3468. $id = post_params('id');
  3469. $item = SaasStoreReferral::findOne($id);
  3470. if (!$item) {
  3471. return $this->asJson([
  3472. 'code' => 1,
  3473. 'msg' => '数据不存在',
  3474. ]);
  3475. }
  3476. $item->delete();
  3477. return $this->asJson([
  3478. 'code' => 0,
  3479. 'msg' => '删除成功',
  3480. ]);
  3481. }
  3482. /**
  3483. * 删除绑定推荐人
  3484. * @return Response
  3485. * @throws InvalidConfigException
  3486. * @throws StaleObjectException
  3487. * @throws GlobalException
  3488. * @throws Throwable
  3489. */
  3490. public function actionDeleteSupplierReferral()
  3491. {
  3492. $id = post_params('id');
  3493. $item = SaasSupplierReferral::findOne($id);
  3494. if (!$item) {
  3495. return $this->asJson([
  3496. 'code' => 1,
  3497. 'msg' => '数据不存在',
  3498. ]);
  3499. }
  3500. $item->delete();
  3501. return $this->asJson([
  3502. 'code' => 0,
  3503. 'msg' => '删除成功',
  3504. ]);
  3505. }
  3506. /**
  3507. * 联盟推荐人佣金明细
  3508. * @return Response
  3509. * @throws InvalidConfigException
  3510. * @throws Throwable
  3511. * @throws Exception
  3512. */
  3513. public function actionReferralShareLog()
  3514. {
  3515. $store_name = get_params('store_name');
  3516. $nickname = get_params('nickname');
  3517. $mobile = get_params('mobile');
  3518. $status = get_params('status', -1);
  3519. $start_date = get_params('start_date');
  3520. $end_date = get_params('end_date');
  3521. $query = SharingReceiver::find()->alias('sr')->leftJoin(['s' => Store::tableName()], 'sr.store_id = s.id')
  3522. ->leftJoin(['su' => SaasUser::tableName()], 'sr.saas_id = su.id')
  3523. ->where(['sr.is_delete' => 0, 'sr.from' => SharingReceiver::FROM_NEW_STORE_RECOMMEND]);
  3524. if ($store_name) {
  3525. $query->andWhere(['like', 's.name', $store_name]);
  3526. }
  3527. if ($nickname) {
  3528. $query->andWhere(['like', 'su.name', $nickname]);
  3529. }
  3530. if ($mobile) {
  3531. $query->andWhere(['like', 'su.mobile', $mobile]);
  3532. }
  3533. if (isset($status) && in_array($status, [0, 1])) {
  3534. $query->andWhere(['ssr.is_enable' => $status]);
  3535. }
  3536. if ($start_date) {
  3537. $query->andWhere(['>=', 'sr.created_at', strtotime($start_date)]);
  3538. }
  3539. if ($end_date) {
  3540. $query->andWhere(['<=', 'sr.created_at', strtotime($end_date)]);
  3541. }
  3542. $query->select('sr.id, sr.saas_id, sr.user_id, su.avatar, su.name, su.mobile, sr.order_no, s.name as store_name, sr.rate, sr.amount, sr.is_pay, sr.created_at ,sr.err_code_des ,sr.execute_type, sr.updated_at');
  3543. $list = pagination_make($query);
  3544. foreach ($list['list'] as &$item) {
  3545. if(!$item['saas_id']){
  3546. $orderNoHead = substr($item['order_no'], 0, 2);
  3547. if($orderNoHead == 'SC'){
  3548. $order = \app\plugins\scanCodePay\models\Order::findOne(['order_no' => $item['order_no']]);
  3549. }else{
  3550. $order = Order::findOne(['order_no' => $item['order_no']]);
  3551. }
  3552. if($order->is_platform){
  3553. $userInfo = SaasUser::findOne($item['user_id']);
  3554. if(!empty($userInfo) && !empty($userInfo->avatar)){
  3555. $item['avatar'] = $userInfo->avatar;
  3556. $item['name'] = $userInfo->name;
  3557. $item['mobile'] = $userInfo->mobile;
  3558. }
  3559. }else{
  3560. $userInfo = User::findOne($item['user_id']);
  3561. if(!empty($userInfo) && !empty($userInfo->avatar_url)){
  3562. $item['avatar'] = $userInfo->avatar_url;
  3563. $item['name'] = $userInfo->nickname;
  3564. $item['mobile'] = $userInfo->binding;
  3565. }
  3566. }
  3567. }
  3568. $item['created_at'] = date("Y-m-d H:i", $item['created_at']);
  3569. }
  3570. return $this->asJson([
  3571. 'code' => 0,
  3572. 'msg' => 'success',
  3573. 'data' => [
  3574. 'data' => $list['list'],
  3575. 'pageNo' => $list['pageNo'],
  3576. 'totalCount' => $list['totalCount'],
  3577. ]
  3578. ]);
  3579. }
  3580. public function actionSupplierReferralShareLog()
  3581. {
  3582. $supplier_name = get_params('supplier_name');
  3583. $nickname = get_params('nickname');
  3584. $mobile = get_params('mobile');
  3585. $start_date = get_params('start_date');
  3586. $end_date = get_params('end_date');
  3587. $query = SaasUserPriceLog::find()->alias('sr')
  3588. ->leftJoin(['su' => SaasUser::tableName()], 'sr.saas_id = su.id')
  3589. ->leftJoin(['ssr' => SaasSupplierReferral::tableName()], 'ssr.referral_id = su.id')
  3590. ->leftJoin(['s' => Supplier::tableName()], 'ssr.supplier_id = s.id')
  3591. ->where(['sr.amount_type' => SaasUserPriceLog::AMOUNT_TYPE_SUPPLIER_PARENT]);
  3592. if ($supplier_name) {
  3593. $query->andWhere(['like', 's.name', $supplier_name]);
  3594. }
  3595. if ($nickname) {
  3596. $query->andWhere(['like', 'su.name', $nickname]);
  3597. }
  3598. if ($mobile) {
  3599. $query->andWhere(['like', 'su.mobile', $mobile]);
  3600. }
  3601. if ($start_date) {
  3602. $query->andWhere(['>=', 'sr.created_at', strtotime($start_date)]);
  3603. }
  3604. if ($end_date) {
  3605. $query->andWhere(['<=', 'sr.created_at', strtotime($end_date)]);
  3606. }
  3607. $query->select('sr.*, su.avatar, su.name, su.mobile, s.name as supplier_name');
  3608. $list = pagination_make($query);
  3609. foreach ($list['list'] as &$item) {
  3610. $item['created_at'] = date("Y-m-d H:i", $item['created_at']);
  3611. }
  3612. return $this->asJson([
  3613. 'code' => 0,
  3614. 'msg' => 'success',
  3615. 'data' => [
  3616. 'data' => $list['list'],
  3617. 'pageNo' => $list['pageNo'],
  3618. 'totalCount' => $list['totalCount'],
  3619. ]
  3620. ]);
  3621. }
  3622. /**
  3623. * 消费返利列表
  3624. * @return \yii\web\Response
  3625. */
  3626. public function actionStoreSelfRebateList()
  3627. {
  3628. $store_name = get_params('store_name');
  3629. $nickname = get_params('nickname');
  3630. $mobile = get_params('mobile');
  3631. $status = get_params('status', -1);
  3632. if (!in_array($status, [-1, 0, 1])) {
  3633. $status = -1;
  3634. }
  3635. $query = Store::find()->alias('s')->leftJoin(['a' => Admin::tableName()], 's.admin_id = a.id');
  3636. $query->where(['s.is_delete' => 0]);
  3637. if ($store_name) {
  3638. $query->andWhere(['like', 's.name', $store_name]);
  3639. }
  3640. if ($nickname) {
  3641. $query->andWhere(['like', 'a.name', $nickname]);
  3642. }
  3643. if ($mobile) {
  3644. $query->andWhere(['like', 'a.mobile', $mobile]);
  3645. }
  3646. if ($status > -1) {
  3647. $query->andWhere(['s.self_rebate_switch' => $status]);
  3648. }
  3649. $query->select('s.id, s.name as store_name, s.logo, a.name as nickname, a.mobile, s.self_rebate_switch, s.self_rebate_value');
  3650. $list = pagination_make($query);
  3651. foreach ($list['list'] as &$item) {
  3652. $amount = SharingReceiver::find()->where([
  3653. 'store_id' => $item['id'],
  3654. 'from' => 1,
  3655. 'is_delete' => 0,
  3656. ])->andWhere(['like', 'remark', '自购返利'])->sum('amount');
  3657. $item['income'] = $amount ?: '0.00';
  3658. $item['use_default'] = 0;
  3659. if($item['self_rebate_switch'] != 0 && $item['self_rebate_value'] == 0){
  3660. $defaultSet = Option::get(OptionSetting::SHARE_SELF_REBATE_DEFAULT_SETTING, -1, OptionSetting::SHARE_GROUP_NAME, '{}');
  3661. $defaultSet = json_decode($defaultSet['value'], true);
  3662. if(!empty($defaultSet['self_rebate_switch']) && !empty($defaultSet['self_rebate_value'])){
  3663. $item['self_rebate_value'] = $defaultSet['self_rebate_value'];
  3664. $item['use_default'] = 1;
  3665. }
  3666. }
  3667. }
  3668. //默认配置
  3669. $defaultSet = Option::get(OptionSetting::SHARE_SELF_REBATE_DEFAULT_SETTING, -1, OptionSetting::SHARE_GROUP_NAME, '{}');
  3670. return $this->asJson([
  3671. 'code' => 0,
  3672. 'msg' => 'success',
  3673. 'data' => [
  3674. 'defaultSet' => json_decode($defaultSet['value']),
  3675. 'data' => $list['list'],
  3676. 'pageNo' => $list['pageNo'],
  3677. 'totalCount' => $list['totalCount'],
  3678. ]
  3679. ]);
  3680. }
  3681. /**
  3682. * 编辑消费返利设置
  3683. * @return \yii\web\Response
  3684. * @throws \yii\base\InvalidConfigException
  3685. * @throws \yii\db\StaleObjectException
  3686. * @throws \yii\db\Exception
  3687. * @author Syan mzsongyan@gmail.com
  3688. * @date 2022-05-13
  3689. */
  3690. public function actionStoreSelfRebateOption()
  3691. {
  3692. $store_id = post_params('store_id');
  3693. $switch = post_params('switch');
  3694. $rate = post_params('rate');
  3695. //默认配置
  3696. if(intval($store_id) === -1){
  3697. $json = json_encode([
  3698. 'self_rebate_switch' => $switch,
  3699. 'self_rebate_value' => $rate,
  3700. ]);
  3701. $res = Option::set(OptionSetting::SHARE_SELF_REBATE_DEFAULT_SETTING, $json, $store_id, OptionSetting::SHARE_GROUP_NAME);
  3702. if(!$res){
  3703. return $this->asJson([
  3704. 'code' => 1,
  3705. 'msg' => '默认配置编辑失败',
  3706. ]);
  3707. }
  3708. return $this->asJson([
  3709. 'code' => 0,
  3710. 'msg' => '默认配置编辑成功',
  3711. ]);
  3712. }
  3713. if (!$store_id || $switch === null) {
  3714. return $this->asJson([
  3715. 'code' => 1,
  3716. 'msg' => '缺少必要参数',
  3717. ]);
  3718. }
  3719. if (!in_array($switch, [0, 1])) {
  3720. return $this->asJson([
  3721. 'code' => 1,
  3722. 'msg' => '参数错误',
  3723. ]);
  3724. }
  3725. $store = Store::findOne($store_id);
  3726. if (!$store) {
  3727. return $this->asJson([
  3728. 'code' => 1,
  3729. 'msg' => '商城不存在',
  3730. ]);
  3731. }
  3732. $store->self_rebate_switch = $switch;
  3733. if ($rate !== null) {
  3734. $store->self_rebate_value = $rate;
  3735. }
  3736. if (!union_share_scale_check($store)) {
  3737. return $this->asJson([
  3738. 'code' => 1,
  3739. 'msg' => '保存失败,分销比例不能超过100%',
  3740. ]);
  3741. }
  3742. if ($store->save()) {
  3743. return $this->asJson([
  3744. 'code' => 0,
  3745. 'msg' => '保存成功',
  3746. ]);
  3747. }
  3748. return $this->asJson([
  3749. 'code' => 1,
  3750. 'msg' => '保存失败',
  3751. ]);
  3752. }
  3753. /**
  3754. * 消费返利佣金明细
  3755. * @return \yii\web\Response
  3756. * @throws \yii\base\InvalidConfigException
  3757. * @throws \Throwable
  3758. * @throws \yii\db\Exception
  3759. * @author Syan mzsongyan@gmail.com
  3760. * @date 2022-05-13
  3761. */
  3762. public function actionStoreSelfRebateLog()
  3763. {
  3764. $store_name = get_params('store_name');
  3765. $nickname = get_params('nickname');
  3766. $mobile = get_params('mobile');
  3767. $status = get_params('status', -1);
  3768. $start_date = get_params('start_date');
  3769. $end_date = get_params('end_date');
  3770. if (!in_array($status, [-1, 0, 1])) {
  3771. $status = -1;
  3772. }
  3773. $query = SharingReceiver::find()->alias('sr')->leftJoin(['s' => Store::tableName()], 'sr.store_id = s.id')
  3774. //->leftJoin(['su' => SaasUser::tableName()], 'sr.user_id = su.id')
  3775. ->leftJoin(['su' => SaasUser::tableName()], 'sr.saas_id = su.id')
  3776. ->where(['sr.is_delete' => 0, 'sr.from' => 5]);
  3777. $query->andWhere(['like', 'sr.remark', '自购返利']);
  3778. if ($store_name) {
  3779. $query->andWhere(['like', 's.name', $store_name]);
  3780. }
  3781. if ($nickname) {
  3782. $query->andWhere(['like', 'su.name', $nickname]);
  3783. }
  3784. if ($mobile) {
  3785. $query->andWhere(['like', 'su.mobile', $mobile]);
  3786. }
  3787. if ($status > -1) {
  3788. $query->andWhere(['sr.is_pay' => $status]);
  3789. }
  3790. if ($start_date) {
  3791. $query->andWhere(['>=', 'sr.created_at', strtotime($start_date)]);
  3792. }
  3793. if ($end_date) {
  3794. $query->andWhere(['<=', 'sr.created_at', strtotime($end_date)]);
  3795. }
  3796. $query->select('sr.id, su.avatar, su.name, su.mobile, sr.order_no, s.name as store_name, sr.rate, sr.amount, sr.is_pay, sr.created_at, sr.err_code_des ,sr.execute_type, sr.updated_at , sr.created_at ');
  3797. $query->orderBy('sr.created_at desc');
  3798. $list = pagination_make($query);
  3799. foreach ($list['list'] as &$item) {
  3800. if(!$item['avatar'] && $item['id']){
  3801. $userInfo = User::find()->where(['id' => $item['id'], 'is_delete' => 0])->one();
  3802. if(!empty($userInfo) && !empty($userInfo->avatar_url)){
  3803. $item['avatar'] = $userInfo->avatar_url;
  3804. $item['name'] = $userInfo->nickname;
  3805. }
  3806. }
  3807. $item['created_at'] = date("Y-m-d H:i", $item['created_at']);
  3808. }
  3809. return $this->asJson([
  3810. 'code' => 0,
  3811. 'msg' => 'success',
  3812. 'data' => [
  3813. 'data' => $list['list'],
  3814. 'pageNo' => $list['pageNo'],
  3815. 'totalCount' => $list['totalCount'],
  3816. ]
  3817. ]);
  3818. }
  3819. //设置入驻协议
  3820. public function actionSaasProtocol() {
  3821. try {
  3822. if (\Yii::$app->request->isPost) {
  3823. $data = post_params();
  3824. //店铺入驻协议
  3825. if (!empty($data['store_apply_agreement'])) {
  3826. Option::set('store_apply_agreement', $data['store_apply_agreement'], 0, 'saas');
  3827. }
  3828. //采购申请协议
  3829. if (!empty($data['cloud_apply_agreement'])) {
  3830. Option::set('cloud_apply_agreement', $data['cloud_apply_agreement'], 0, 'saas');
  3831. }
  3832. //供货商入驻协议
  3833. if (!empty($data['cloud_supplier_apply_agreement'])) {
  3834. Option::set('cloud_supplier_apply_agreement', $data['cloud_supplier_apply_agreement'], 0, 'saas');
  3835. }
  3836. //区域管理协议
  3837. if (!empty($data['area_agent_apply_agreement'])) {
  3838. Option::set('area_agent_apply_agreement', $data['area_agent_apply_agreement'], 0, 'saas');
  3839. }
  3840. //推广代理申请协议
  3841. if (!empty($data['bd_agent_apply_agreement'])) {
  3842. Option::set('bd_agent_apply_agreement', $data['bd_agent_apply_agreement'], 0, 'saas');
  3843. }
  3844. //产品代理入驻协议
  3845. if (!empty($data['goods_agent_apply_agreement'])) {
  3846. Option::set('goods_agent_apply_agreement', $data['goods_agent_apply_agreement'], 0, 'saas');
  3847. }
  3848. return $this->asJson([
  3849. 'code' => 0,
  3850. 'msg' => "设置完成"
  3851. ]);
  3852. } else {
  3853. $keys = [
  3854. 'store_apply_agreement',
  3855. 'cloud_apply_agreement',
  3856. 'cloud_supplier_apply_agreement',
  3857. 'area_agent_apply_agreement',
  3858. 'bd_agent_apply_agreement',
  3859. 'goods_agent_apply_agreement',
  3860. ];
  3861. $data = Option::get($keys, 0, 'saas');
  3862. if (empty($data)) {
  3863. $data = [
  3864. 'store_apply_agreement' => '',
  3865. 'cloud_apply_agreement' => '',
  3866. 'cloud_supplier_apply_agreement' => '',
  3867. 'area_agent_apply_agreement' => '',
  3868. 'bd_agent_apply_agreement' => '',
  3869. 'goods_agent_apply_agreement' => ''
  3870. ];
  3871. } else {
  3872. $arr = [];
  3873. foreach ($data as $value) {
  3874. $index = array_search($value['name'], $keys);
  3875. unset($keys[$index]);
  3876. $arr[$value['name']] = $value['value'];
  3877. }
  3878. foreach ($keys as $key) {
  3879. $arr[$key] = '';
  3880. }
  3881. $data = $arr;
  3882. }
  3883. return $this->asJson([
  3884. 'code' => 0,
  3885. 'msg' => 'success',
  3886. 'data' => $data,
  3887. ]);
  3888. }
  3889. } catch (\Exception $e) {
  3890. return $this->asJson(
  3891. [
  3892. 'code' => 1,
  3893. 'msg' => $e->getMessage()
  3894. ]
  3895. );
  3896. }
  3897. }
  3898. public function actionWechatCashConfig() {
  3899. try {
  3900. $store_id = get_store_id();
  3901. if (\Yii::$app->request->isPost) {
  3902. $params = post_params();
  3903. $data = [
  3904. 'is_open' => $params['is_open'] ?: 1,//是否使用新版商家转账(申请后可以用)//https://pay.weixin.qq.com/doc/v3/merchant/4012711988
  3905. 'mch_id' => $params['mch_id'] ?: '',
  3906. 'appid' => $params['appid'] ?: '',
  3907. 'mch_private_key' => $params['mch_private_key'] ?: '',
  3908. 'mch_api_key' => $params['mch_api_key'] ?: '',
  3909. 'serial_no' => $params['serial_no'] ?: '',
  3910. 'mch_public_key' => $params['mch_public_key'] ?: '',
  3911. 'pay_public_key' => $params['pay_public_key'] ?: '',
  3912. 'pay_public_key_id' => $params['pay_public_key_id'] ?: '',
  3913. ];
  3914. Option::set('wechat_cash', json_encode($data), $store_id, 'store');
  3915. return $this->asJson([
  3916. 'code' => 0,
  3917. 'msg' => '保存成功'
  3918. ]);
  3919. } else {
  3920. $data = json_encode([
  3921. 'is_open' => 1,
  3922. 'mch_id' => '',
  3923. 'appid' => '',
  3924. 'mch_private_key' => '',
  3925. 'serial_no' => '',
  3926. 'mch_api_key' => '',
  3927. 'mch_public_key' => '',
  3928. 'pay_public_key' => '',
  3929. 'pay_public_key_id' => '',
  3930. ]);
  3931. $wechat_cash = Option::get('wechat_cash', $store_id, 'store')['value'];
  3932. if (!$wechat_cash) {
  3933. $wechat_cash = $data;
  3934. }
  3935. $wechat_cash = json_decode($wechat_cash, true);
  3936. if (!isset($wechat_cash['is_open'])) {
  3937. $wechat_cash['is_open'] = 1;
  3938. }
  3939. if (!isset($wechat_cash['mch_api_key'])) {
  3940. $wechat_cash['mch_api_key'] = '';
  3941. }
  3942. if (!isset($wechat_cash['mch_public_key'])) {
  3943. $wechat_cash['mch_public_key'] = '';
  3944. }
  3945. return $this->asJson([
  3946. 'code' => 0,
  3947. 'msg' => '获取成功',
  3948. 'data' => $wechat_cash
  3949. ]);
  3950. }
  3951. } catch (\Exception $e) {
  3952. return $this->asJson(
  3953. [
  3954. 'code' => 1,
  3955. 'msg' => $e->getMessage()
  3956. ]
  3957. );
  3958. }
  3959. }
  3960. public function actionStoreWechatCashConfig() {
  3961. try {
  3962. $store_id = get_store_id();
  3963. if (\Yii::$app->request->isPost) {
  3964. $params = post_params();
  3965. $data = [
  3966. 'is_open' => $params['is_open'] ?: '',//是否使用新版商家转账(申请后可以用)//https://pay.weixin.qq.com/doc/v3/merchant/4012711988
  3967. 'mch_id' => $params['mch_id'] ?: '',
  3968. 'appid' => $params['appid'] ?: '',
  3969. 'mch_private_key' => $params['mch_private_key'] ?: '',
  3970. 'mch_api_key' => $params['mch_api_key'] ?: '',
  3971. 'serial_no' => $params['serial_no'] ?: '',
  3972. 'mch_public_key' => $params['mch_public_key'] ?: '',
  3973. 'pay_public_key' => $params['pay_public_key'] ?: '',
  3974. 'pay_public_key_id' => $params['pay_public_key_id'] ?: '',
  3975. ];
  3976. Option::set('store_wechat_cash', json_encode($data), $store_id, 'store');
  3977. return $this->asJson([
  3978. 'code' => 0,
  3979. 'msg' => '保存成功'
  3980. ]);
  3981. } else {
  3982. $data = json_encode([
  3983. 'is_open' => 1,
  3984. 'mch_id' => '',
  3985. 'appid' => '',
  3986. 'mch_private_key' => '',
  3987. 'mch_api_key' => '',
  3988. 'serial_no' => '',
  3989. 'mch_public_key' => '',
  3990. 'pay_public_key' => '',
  3991. 'pay_public_key_id' => '',
  3992. ]);
  3993. $store_wechat_cash = Option::get('store_wechat_cash', $store_id, 'store')['value'];
  3994. if (!$store_wechat_cash) {
  3995. $store_wechat_cash = $data;
  3996. }
  3997. $store_wechat_cash = json_decode($store_wechat_cash, true);
  3998. if (!isset($store_wechat_cash['is_open'])) {
  3999. $store_wechat_cash['is_open'] = 1;
  4000. }
  4001. if (!isset($store_wechat_cash['mch_api_key'])) {
  4002. $store_wechat_cash['mch_api_key'] = '';
  4003. }
  4004. if (!isset($store_wechat_cash['mch_public_key'])) {
  4005. $store_wechat_cash['mch_public_key'] = '';
  4006. }
  4007. return $this->asJson([
  4008. 'code' => 0,
  4009. 'msg' => '获取成功',
  4010. 'data' => $store_wechat_cash
  4011. ]);
  4012. }
  4013. } catch (\Exception $e) {
  4014. return $this->asJson(
  4015. [
  4016. 'code' => 1,
  4017. 'msg' => $e->getMessage()
  4018. ]
  4019. );
  4020. }
  4021. }
  4022. public function actionProfitStrategyUpdate() {
  4023. $id = \Yii::$app->cache->get('profit_strategy_job_id');
  4024. if ($id && !\Yii::$app->queue->isDone($id)) {
  4025. \Yii::$app->queue->remove($id);
  4026. }
  4027. $id = \queue_push(new \app\jobs\SetProfitStrategyJob(), 0, 1);
  4028. \Yii::$app->cache->set('profit_strategy_job_id', $id);
  4029. return $this->asJson([
  4030. 'code' => 0,
  4031. 'msg' => '正在更新,请稍后'
  4032. ]);
  4033. }
  4034. //设置策略
  4035. public function actionProfitStrategy() {
  4036. try {
  4037. if (\Yii::$app->request->isPost) {
  4038. $params = post_params();
  4039. $data = [
  4040. 'service_charge_model' => $params['service_charge_model'] ?: 0,//服务收费模式
  4041. 'service_charge_rate' => $params['service_charge_rate'] ?: sprintf('%.2f', '0'),//抽成比例
  4042. 'is_risk_control' => $params['is_risk_control'] ?: 0,//是否开启风控
  4043. 'risk_control_model' => $params['risk_control_model'] ?: 0,//风控规则
  4044. // 'is_markup_protection' => $params['is_markup_protection'] ?: 0,//加价保护是否开启
  4045. // 'markup_protection_rules' => [//加价保护规则
  4046. // 'title' => $params['markup_protection_rules']['title'] ?: 0,//加价保护规则名称
  4047. // 'compare' => $params['markup_protection_rules']['compare'] ?: 0,
  4048. // 'price' => $params['markup_protection_rules']['price'] ?: sprintf('%.2f', '0'),
  4049. // 'operate' => $params['markup_protection_rules']['operate'] ?: 0,
  4050. // ]
  4051. ];
  4052. Option::set('platform_profit_strategy', json_encode($data), 0, 'store');
  4053. return $this->asJson([
  4054. 'code' => 0,
  4055. 'msg' => '保存成功'
  4056. ]);
  4057. } else {
  4058. $data = json_encode([
  4059. 'service_charge_model' => 0,//服务收费模式
  4060. 'service_charge_rate' => sprintf('%.2f', '0'),//抽成比例
  4061. 'is_risk_control' => 0,//是否开启风控
  4062. 'risk_control_model' => 0,//风控规则
  4063. // 'is_markup_protection' => 0,//加价保护是否开启
  4064. // 'markup_protection_rules' => [//加价保护规则
  4065. // 'title' => 0,//加价保护规则名称
  4066. // 'compare' => 0,
  4067. // 'price' => sprintf('%.2f', '0'),
  4068. // 'operate' => 0,
  4069. // ]
  4070. ]);
  4071. $wechat_cash = Option::get('platform_profit_strategy', 0, 'store')['value'];
  4072. if (!$wechat_cash) {
  4073. $wechat_cash = $data;
  4074. }
  4075. return $this->asJson([
  4076. 'code' => 0,
  4077. 'msg' => '获取成功',
  4078. 'data' => json_decode($wechat_cash, true)
  4079. ]);
  4080. }
  4081. } catch (\Exception $e) {
  4082. return $this->asJson(
  4083. [
  4084. 'code' => 1,
  4085. 'msg' => $e->getMessage()
  4086. ]
  4087. );
  4088. }
  4089. }
  4090. public function actionGetVersion() {
  4091. $type = get_params('type');
  4092. $key = 'store_dandianpu_version';
  4093. if ($type == 'merchant') {
  4094. $key = 'store_merchant_version';
  4095. }
  4096. $cache = cacheLock();
  4097. return $this->asJson([
  4098. 'code' => 0,
  4099. 'data' => [
  4100. 'version' => $cache->get($key) ?: '',
  4101. 'cyy_version' => cyy_version()
  4102. ]
  4103. ]);
  4104. }
  4105. // 判断供应链版本是否有h5端权限
  4106. public function actionCheckDandianpuHasH5()
  4107. {
  4108. $cliented = \Yii::$app->getAttr('client');
  4109. return $this->asJson([
  4110. 'code' => 0,
  4111. 'data' => \Yii::$app->prod_is_dandianpu() ? in_array('h5', $cliented['store']) : true,
  4112. ]);
  4113. }
  4114. }