SaasController.php 172 KB

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