BonusController.php 108 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: leo
  5. * Date: 2018/2/24
  6. * Time: 下午12:48
  7. */
  8. namespace backendApi\modules\v1\controllers;
  9. use backendApi\modules\v1\models\AdminCountry;
  10. use backendApi\modules\v1\models\AdminRole;
  11. use backendApi\modules\v1\models\exportForms\BonusExportForm;
  12. use backendApi\modules\v1\models\lists\bonus\BalanceList;
  13. use backendApi\modules\v1\models\lists\bonus\FlowBalanceList;
  14. use backendApi\modules\v1\models\lists\bonus\FlowBonusList;
  15. use backendApi\modules\v1\models\lists\bonus\FlowExchangePointsList;
  16. use backendApi\modules\v1\models\lists\bonus\FlowReconsumePointsList;
  17. use backendApi\modules\v1\models\lists\bonus\FlowWalletList;
  18. use backendApi\modules\v1\models\lists\bonus\PerfMonthList;
  19. use backendApi\modules\v1\models\lists\bonus\PerfOrderList;
  20. use backendApi\modules\v1\models\lists\bonus\PerfPeriodList;
  21. use backendApi\modules\v1\models\lists\bonus\PerfStandardList;
  22. use backendApi\modules\v1\models\lists\bonus\PeriodBonusList;
  23. use backendApi\modules\v1\models\lists\bonus\ScoreMonthList;
  24. use backendApi\modules\v1\models\lists\bonus\TraceDownBdList;
  25. use backendApi\modules\v1\models\lists\bonus\TraceDownGlList;
  26. use backendApi\modules\v1\models\lists\bonus\TraceDownGxList;
  27. use backendApi\modules\v1\models\lists\bonus\TraceDownQyList;
  28. use backendApi\modules\v1\models\lists\bonus\TraceDownTgList;
  29. use backendApi\modules\v1\models\lists\bonus\TraceDownXfList;
  30. use backendApi\modules\v1\models\lists\bonus\TraceDownYcList;
  31. use backendApi\modules\v1\models\lists\bonus\TraceDownYjList;
  32. use backendApi\modules\v1\models\lists\bonus\TraceUpBdList;
  33. use backendApi\modules\v1\models\lists\bonus\TraceUpGlList;
  34. use backendApi\modules\v1\models\lists\bonus\TraceUpGxList;
  35. use backendApi\modules\v1\models\lists\bonus\TraceUpQyList;
  36. use backendApi\modules\v1\models\lists\bonus\TraceUpTgList;
  37. use backendApi\modules\v1\models\lists\bonus\TraceUpXfList;
  38. use backendApi\modules\v1\models\lists\bonus\TraceUpYcList;
  39. use backendApi\modules\v1\models\lists\bonus\TraceUpYjList;
  40. use backendApi\modules\v1\models\lists\bonus\UserPerfList;
  41. use common\helpers\Cache;
  42. use common\helpers\Tool;
  43. use common\helpers\user\Info;
  44. use common\helpers\user\Perf;
  45. use common\models\CalcBonus;
  46. use common\models\CFLXAudit;
  47. use common\models\forms\PerfAdjustmentForm;
  48. use common\models\forms\ResendQYForm;
  49. use common\models\forms\SendCFAndLXForm;
  50. use common\models\PerfMonth;
  51. use common\models\PerfOrder;
  52. use common\models\PerfPeriod;
  53. use common\models\ResendQYAudit;
  54. use common\models\User;
  55. use common\models\UserInfo;
  56. use common\models\UserNetwork;
  57. use common\models\UserPerf;
  58. use Yii;
  59. use common\helpers\Form;
  60. use common\models\FlowBonus;
  61. use common\models\forms\PeriodForm;
  62. use common\models\forms\UserBonusForm;
  63. use common\models\Period;
  64. use yii\db\Exception;
  65. use yii\web\HttpException;
  66. class BonusController extends BaseController {
  67. public $modelClass = FlowBonus::class;
  68. public function behaviors() {
  69. return parent::behaviors();
  70. }
  71. /**
  72. * 期数列表
  73. * @return mixed
  74. * @throws \yii\base\InvalidConfigException
  75. * @throws \yii\httpclient\Exception
  76. * @throws HttpException
  77. * @throws Exception
  78. */
  79. public function actionPeriod() {
  80. $filter = $this->filterCondition([
  81. 'periodNum' => 'PERIOD_NUM',
  82. 'year' => 'CALC_YEAR',
  83. 'month' => 'CALC_MONTH',
  84. ]);
  85. $condition = $filter['condition'];
  86. $params = $filter['params'];
  87. $periodObj = Period::instance();
  88. $nowPeriodNum = $periodObj->getNowPeriodNum();
  89. // $condition .= ' AND PERIOD_NUM<=:PERIOD_NUM AND STATUS=1';
  90. $condition .= ' AND STATUS=1';
  91. // $params[':PERIOD_NUM'] = $nowPeriodNum;
  92. $data = Period::lists($condition, $params, ['orderBy' => 'PERIOD_NUM ASC']);
  93. foreach ($data['list'] as $key => $value) {
  94. // 结算月
  95. $data['list'][$key]['CALC_YEAR_MONTH'] = $periodObj->getYearMonth($value['PERIOD_NUM']);
  96. // 结算
  97. $data['list'][$key]['IS_CAN_CALC'] = $periodObj->isCanCalc($value['PERIOD_NUM']);
  98. // 挂网
  99. $data['list'][$key]['IS_CAN_SENT'] = $periodObj->isCanSend($value['PERIOD_NUM']);
  100. // 日志
  101. $data['list'][$key]['IS_SHOW_LOG'] = $value['CALCULATED_AT'] > 0;
  102. }
  103. return static::notice($data);
  104. }
  105. /**
  106. * 结算
  107. * @return mixed
  108. * @throws HttpException
  109. */
  110. public function actionCalcPeriod() {
  111. $periodNum = \Yii::$app->request->get('periodNum');
  112. if (!$periodNum) {
  113. return static::notice('期数不存在', 400);
  114. }
  115. $formModel = new PeriodForm();
  116. $formModel->scenario = 'calc';
  117. if ($formModel->load(Yii::$app->request->get(), '') && $formModel->calcWebToAsync()) {
  118. return static::notice('结算已开始处理,请等待');
  119. } else {
  120. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  121. }
  122. }
  123. /**
  124. * 挂网
  125. * @return mixed
  126. * @throws HttpException
  127. */
  128. public function actionSendPeriod() {
  129. $periodNum = \Yii::$app->request->get('periodNum');
  130. if (!$periodNum) {
  131. return static::notice('期数不存在', 400);
  132. }
  133. $formModel = new PeriodForm();
  134. $formModel->scenario = 'send';
  135. if ($formModel->load(Yii::$app->request->get(), '') && $formModel->sendWebToAsync()) {
  136. return static::notice('挂网已开始处理,请等待');
  137. } else {
  138. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  139. }
  140. }
  141. /**
  142. * 查看业绩
  143. * @return mixed
  144. * @throws HttpException
  145. */
  146. public function actionPerf() {
  147. // 获取当前年月
  148. $period = Period::instance();
  149. $yearMonth = $period->getNowYearMonth();
  150. $yearMonth = Yii::$app->request->get('yearMonth', $yearMonth);
  151. //$filter = $this->filterCondition(Perf::tableName(), ['periodNum'=>'P.PERIOD_NUM', 'userName'=>'UI.USER_NAME']);
  152. $condition = '';
  153. $params = [];
  154. $data = PerfPeriod::lists($condition, $params, [
  155. 'select' => 'P.*, UI.USER_NAME',
  156. 'yearMonth' => $yearMonth,
  157. 'from' => PerfPeriod::tableName() . ' AS P',
  158. 'join' => [
  159. ['LEFT JOIN', UserInfo::tableName() . ' AS UI', 'P.USER_ID=UI.USER_ID']
  160. ],
  161. 'orderBy' => 'P.PERIOD_NUM DESC',
  162. ]);
  163. $data['request'] = [];
  164. $data['request']['yearMonth'] = $yearMonth;
  165. return static::notice($data);
  166. }
  167. /**
  168. * 奖金流水
  169. * @return mixed
  170. * @throws \yii\base\Exception
  171. * @throws HttpException
  172. */
  173. public function actionFlowBonus() {
  174. $filter = $this->filterCondition([
  175. 'USER_NAME' => 'U.USER_NAME',
  176. 'REAL_NAME' => 'U.REAL_NAME',
  177. 'IS_DEC' => 'U.IS_DEC',
  178. 'userIds' => 'USER_ID',
  179. 'CREATED_AT' => 'FB.CREATED_AT',
  180. 'PERIOD_NUM' => 'PERIOD_NUM',
  181. 'CALC_MONTH' => 'CALC_MONTH',
  182. 'DEAL_TYPE_NAME' => 'DEAL_TYPE_ID',
  183. 'LAST_DEC_LV_NAME' => 'LAST_DEC_LV',
  184. 'LAST_EMP_LV_NAME' => 'LAST_EMP_LV',
  185. 'AMOUNT' => 'AMOUNT',
  186. 'TOTAL' => 'TOTAL',
  187. 'ADMIN_NAME' => 'ADMIN_NAME',
  188. 'REMARK' => 'REMARK',
  189. 'TRANSFER_SN' => 'TRANSFER_SN',
  190. ]);
  191. $condition = $filter['condition'];
  192. $params = $filter['params'];
  193. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  194. if (!$isSuper) {
  195. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  196. $adminCountry = AdminCountry::getCountry($adminId);
  197. $quotedAdminCountry = array_map(function($item) {
  198. return "'" . addslashes($item) . "'";
  199. }, $adminCountry);
  200. $condition .= " AND U.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
  201. }
  202. $listObj = new FlowBonusList();
  203. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  204. return static::notice($data);
  205. }
  206. /**
  207. * 奖金流水
  208. * @return mixed
  209. * @throws \yii\db\Exception
  210. * @throws HttpException
  211. */
  212. public function actionFlowBonusExport() {
  213. $filter = $this->filterCondition([
  214. 'USER_NAME' => 'U.USER_NAME',
  215. 'REAL_NAME' => 'U.REAL_NAME',
  216. 'IS_DEC' => 'U.IS_DEC',
  217. 'userIds' => 'USER_ID',
  218. 'CREATED_AT' => 'FB.CREATED_AT',
  219. 'PERIOD_NUM' => 'PERIOD_NUM',
  220. 'CALC_MONTH' => 'CALC_MONTH',
  221. 'DEAL_TYPE_NAME' => 'DEAL_TYPE_ID',
  222. 'LAST_DEC_LV_NAME' => 'LAST_DEC_LV',
  223. 'LAST_EMP_LV_NAME' => 'LAST_EMP_LV',
  224. 'LAST_STATUS_NAME' => 'LAST_STATUS',
  225. 'AMOUNT' => 'AMOUNT',
  226. 'TOTAL' => 'TOTAL',
  227. 'ADMIN_NAME' => 'ADMIN_NAME',
  228. 'REMARK' => 'REMARK',
  229. 'TRANSFER_SN' => 'TRANSFER_SN',
  230. ]);
  231. $condition = $filter['condition'];
  232. $params = $filter['params'];
  233. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  234. if (!$isSuper) {
  235. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  236. $adminCountry = AdminCountry::getCountry($adminId);
  237. $quotedAdminCountry = array_map(function($item) {
  238. return "'" . addslashes($item) . "'";
  239. }, $adminCountry);
  240. $condition .= " AND U.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
  241. }
  242. $form = new BonusExportForm();
  243. $result = $form->run(['condition'=>$condition, 'params'=>$params], 'Bonus_Flow'); // 奖金流水
  244. if (!$result) {
  245. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  246. }
  247. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  248. }
  249. /**
  250. * 复消积分流水
  251. * @return mixed
  252. * @throws \yii\base\Exception
  253. * @throws HttpException
  254. */
  255. public function actionFlowRp() {
  256. $filter = $this->filterCondition([
  257. 'userIds' => 'USER_ID',
  258. 'CREATED_AT' => 'CREATED_AT',
  259. 'PERIOD_NUM' => 'PERIOD_NUM',
  260. 'CALC_MONTH' => 'CALC_MONTH',
  261. 'DEAL_TYPE_NAME' => 'DEAL_TYPE_ID',
  262. 'LAST_DEC_LV_NAME' => 'LAST_DEC_LV',
  263. 'LAST_EMP_LV_NAME' => 'LAST_EMP_LV',
  264. 'AMOUNT' => 'AMOUNT',
  265. 'TOTAL' => 'TOTAL',
  266. 'ADMIN_NAME' => 'ADMIN_NAME',
  267. 'REMARK' => 'REMARK',
  268. ]);
  269. $condition = $filter['condition'];
  270. $params = $filter['params'];
  271. $listObj = new FlowReconsumePointsList();
  272. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  273. return static::notice($data);
  274. }
  275. /**
  276. * 复消积分流水导出
  277. * @return mixed
  278. * @throws \yii\db\Exception
  279. * @throws HttpException
  280. */
  281. public function actionFlowRpExport() {
  282. $filter = $this->filterCondition([
  283. 'userIds' => 'USER_ID',
  284. 'CREATED_AT' => 'CREATED_AT',
  285. 'PERIOD_NUM' => 'PERIOD_NUM',
  286. 'CALC_MONTH' => 'CALC_MONTH',
  287. 'DEAL_TYPE_NAME' => 'DEAL_TYPE_ID',
  288. 'LAST_DEC_LV_NAME' => 'LAST_DEC_LV',
  289. 'LAST_EMP_LV_NAME' => 'LAST_EMP_LV',
  290. 'AMOUNT' => 'AMOUNT',
  291. 'TOTAL' => 'TOTAL',
  292. 'ADMIN_NAME' => 'ADMIN_NAME',
  293. 'REMARK' => 'REMARK',
  294. ]);
  295. $form = new BonusExportForm();
  296. $result = $form->run($filter, '复消积分流水');
  297. if (!$result) {
  298. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  299. }
  300. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  301. }
  302. /**
  303. * 会员余额流水
  304. * @return mixed
  305. * @throws \yii\base\Exception
  306. * @throws HttpException
  307. */
  308. public function actionFlowBalance() {
  309. $filter = $this->filterCondition([
  310. 'USER_NAME' => 'USER_NAME',
  311. 'REAL_NAME' => 'REAL_NAME',
  312. 'CALC_MONTH' => 'CALC_MONTH',
  313. 'PERIOD_NUM' => 'PERIOD_NUM',
  314. 'TRANSFER_SN' => 'TRANSFER_SN',
  315. 'CREATED_AT' => 'FW.CREATED_AT',
  316. 'AMOUNT' => 'AMOUNT',
  317. 'TOTAL' => 'TOTAL',
  318. 'REMARK' => 'REMARK',
  319. ]);
  320. $condition = $filter['condition'];
  321. $params = $filter['params'];
  322. $listObj = new FlowBalanceList();
  323. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  324. return static::notice($data);
  325. }
  326. /**
  327. * 会员余额流水导出
  328. * @return mixed
  329. * @throws \yii\db\Exception
  330. * @throws HttpException
  331. */
  332. public function actionFlowBalanceExport() {
  333. $filter = $this->filterCondition([
  334. 'USER_NAME' => 'USER_NAME',
  335. 'REAL_NAME' => 'REAL_NAME',
  336. 'CALC_MONTH' => 'CALC_MONTH',
  337. 'PERIOD_NUM' => 'PERIOD_NUM',
  338. 'TRANSFER_SN' => 'TRANSFER_SN',
  339. 'CREATED_AT' => 'FW.CREATED_AT',
  340. 'AMOUNT' => 'AMOUNT',
  341. 'TOTAL' => 'TOTAL',
  342. 'REMARK' => 'REMARK',
  343. ]);
  344. $form = new BonusExportForm();
  345. $result = $form->run($filter, '会员余额流水');
  346. if (!$result) {
  347. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  348. }
  349. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  350. }
  351. /**
  352. * 兑换积分流水
  353. * @return mixed
  354. * @throws \yii\base\Exception
  355. * @throws HttpException
  356. */
  357. public function actionFlowExchange() {
  358. $filter = $this->filterCondition([
  359. 'userIds' => 'USER_ID',
  360. 'CREATED_AT' => 'CREATED_AT',
  361. 'PERIOD_NUM' => 'PERIOD_NUM',
  362. 'CALC_MONTH' => 'CALC_MONTH',
  363. 'DEAL_TYPE_NAME' => 'DEAL_TYPE_ID',
  364. 'LAST_DEC_LV_NAME' => 'LAST_DEC_LV',
  365. 'LAST_EMP_LV_NAME' => 'LAST_EMP_LV',
  366. 'AMOUNT' => 'AMOUNT',
  367. 'TOTAL' => 'TOTAL',
  368. 'ADMIN_NAME' => 'ADMIN_NAME',
  369. 'REMARK' => 'REMARK',
  370. ]);
  371. $condition = $filter['condition'];
  372. $params = $filter['params'];
  373. $listObj = new FlowExchangePointsList();
  374. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  375. return static::notice($data);
  376. }
  377. /**
  378. * 兑换积分流水导出
  379. * @return mixed
  380. * @throws \yii\db\Exception
  381. * @throws HttpException
  382. */
  383. public function actionFlowExchangeExport() {
  384. $filter = $this->filterCondition([
  385. 'userIds' => 'USER_ID',
  386. 'CREATED_AT' => 'CREATED_AT',
  387. 'PERIOD_NUM' => 'PERIOD_NUM',
  388. 'CALC_MONTH' => 'CALC_MONTH',
  389. 'DEAL_TYPE_NAME' => 'DEAL_TYPE_ID',
  390. 'LAST_DEC_LV_NAME' => 'LAST_DEC_LV',
  391. 'LAST_EMP_LV_NAME' => 'LAST_EMP_LV',
  392. 'AMOUNT' => 'AMOUNT',
  393. 'TOTAL' => 'TOTAL',
  394. 'ADMIN_NAME' => 'ADMIN_NAME',
  395. 'REMARK' => 'REMARK',
  396. ]);
  397. $form = new BonusExportForm();
  398. $result = $form->run($filter, '兑换积分流水');
  399. if (!$result) {
  400. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  401. }
  402. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  403. }
  404. /**
  405. * 现金钱包流水
  406. * @return mixed
  407. * @throws \yii\base\Exception
  408. * @throws HttpException
  409. */
  410. public function actionFlowWallet() {
  411. $filter = $this->filterCondition([
  412. 'USER_NAME' => 'U.USER_NAME',
  413. 'REAL_NAME' => 'U.REAL_NAME',
  414. 'IS_DEC' => 'U.IS_DEC',
  415. 'userIds' => 'USER_ID',
  416. 'CREATED_AT' => 'CREATED_AT',
  417. 'PERIOD_NUM' => 'PERIOD_NUM',
  418. 'CALC_MONTH' => 'CALC_MONTH',
  419. 'AMOUNT' => 'AMOUNT',
  420. 'TOTAL' => 'TOTAL',
  421. 'ADMIN_NAME' => 'ADMIN_NAME',
  422. 'REMARK' => 'REMARK',
  423. ]);
  424. $condition = $filter['condition'];
  425. $params = $filter['params'];
  426. $listObj = new FlowWalletList();
  427. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  428. return static::notice($data);
  429. }
  430. /**
  431. * 现金钱包流水导出
  432. * @return mixed
  433. * @throws \yii\db\Exception
  434. * @throws HttpException
  435. */
  436. public function actionFlowWalletExport() {
  437. $filter = $this->filterCondition([
  438. 'USER_NAME' => 'U.USER_NAME',
  439. 'REAL_NAME' => 'U.REAL_NAME',
  440. 'IS_DEC' => 'U.IS_DEC',
  441. 'userIds' => 'USER_ID',
  442. 'CREATED_AT' => 'CREATED_AT',
  443. 'PERIOD_NUM' => 'PERIOD_NUM',
  444. 'CALC_MONTH' => 'CALC_MONTH',
  445. 'AMOUNT' => 'AMOUNT',
  446. 'TOTAL' => 'TOTAL',
  447. 'ADMIN_NAME' => 'ADMIN_NAME',
  448. 'REMARK' => 'REMARK',
  449. ]);
  450. $form = new BonusExportForm();
  451. $result = $form->run($filter, '现金钱包流水');
  452. if (!$result) {
  453. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  454. }
  455. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  456. }
  457. /**
  458. * 车房流水
  459. * @return mixed
  460. * @throws \yii\base\Exception
  461. * @throws HttpException
  462. */
  463. public function actionFlowCf() {
  464. $filter = $this->filterCondition([
  465. 'userIds' => 'USER_ID',
  466. 'CREATED_AT' => 'CREATED_AT',
  467. 'PERIOD_NUM' => 'PERIOD_NUM',
  468. 'CALC_MONTH' => 'CALC_MONTH',
  469. 'DEAL_TYPE_NAME' => 'DEAL_TYPE_ID',
  470. 'LAST_DEC_LV_NAME' => 'LAST_DEC_LV',
  471. 'LAST_EMP_LV_NAME' => 'LAST_EMP_LV',
  472. 'LAST_STATUS_NAME' => 'LAST_STATUS',
  473. 'AMOUNT' => 'AMOUNT',
  474. 'TOTAL' => 'TOTAL',
  475. 'ADMIN_NAME' => 'ADMIN_NAME',
  476. 'REMARK' => 'REMARK',
  477. ]);
  478. $condition = $filter['condition'];
  479. $params = $filter['params'];
  480. $listObj = new FlowCfList();
  481. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  482. return static::notice($data);
  483. }
  484. /**
  485. * 车房养老奖流水导出
  486. * @return mixed
  487. * @throws \yii\db\Exception
  488. * @throws HttpException
  489. */
  490. public function actionFlowCfExport() {
  491. $filter = $this->filterCondition([
  492. 'userIds' => 'USER_ID',
  493. 'CREATED_AT' => 'CREATED_AT',
  494. 'PERIOD_NUM' => 'PERIOD_NUM',
  495. 'CALC_MONTH' => 'CALC_MONTH',
  496. 'DEAL_TYPE_NAME' => 'DEAL_TYPE_ID',
  497. 'LAST_DEC_LV_NAME' => 'LAST_DEC_LV',
  498. 'LAST_EMP_LV_NAME' => 'LAST_EMP_LV',
  499. 'LAST_STATUS_NAME' => 'LAST_STATUS',
  500. 'AMOUNT' => 'AMOUNT',
  501. 'TOTAL' => 'TOTAL',
  502. 'ADMIN_NAME' => 'ADMIN_NAME',
  503. 'REMARK' => 'REMARK',
  504. ]);
  505. $form = new BonusExportForm();
  506. $result = $form->run($filter, '车房养老奖流水');
  507. if (!$result) {
  508. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  509. }
  510. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  511. }
  512. /**
  513. * 领袖分红流水
  514. * @return mixed
  515. * @throws \yii\base\Exception
  516. * @throws HttpException
  517. */
  518. public function actionFlowLx() {
  519. $filter = $this->filterCondition([
  520. 'userIds' => 'USER_ID',
  521. 'CREATED_AT' => 'CREATED_AT',
  522. 'PERIOD_NUM' => 'PERIOD_NUM',
  523. 'CALC_MONTH' => 'CALC_MONTH',
  524. 'DEAL_TYPE_NAME' => 'DEAL_TYPE_ID',
  525. 'LAST_DEC_LV_NAME' => 'LAST_DEC_LV',
  526. 'LAST_EMP_LV_NAME' => 'LAST_EMP_LV',
  527. 'LAST_STATUS_NAME' => 'LAST_STATUS',
  528. 'AMOUNT' => 'AMOUNT',
  529. 'TOTAL' => 'TOTAL',
  530. 'ADMIN_NAME' => 'ADMIN_NAME',
  531. 'REMARK' => 'REMARK',
  532. ]);
  533. $condition = $filter['condition'];
  534. $params = $filter['params'];
  535. $listObj = new FlowLxList();
  536. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  537. return static::notice($data);
  538. }
  539. /**
  540. * 导出
  541. * @return mixed
  542. * @throws \yii\db\Exception
  543. * @throws HttpException
  544. */
  545. public function actionFlowLxExport() {
  546. $filter = $this->filterCondition([
  547. 'userIds' => 'USER_ID',
  548. 'CREATED_AT' => 'CREATED_AT',
  549. 'PERIOD_NUM' => 'PERIOD_NUM',
  550. 'CALC_MONTH' => 'CALC_MONTH',
  551. 'DEAL_TYPE_NAME' => 'DEAL_TYPE_ID',
  552. 'LAST_DEC_LV_NAME' => 'LAST_DEC_LV',
  553. 'LAST_EMP_LV_NAME' => 'LAST_EMP_LV',
  554. 'LAST_STATUS_NAME' => 'LAST_STATUS',
  555. 'AMOUNT' => 'AMOUNT',
  556. 'TOTAL' => 'TOTAL',
  557. 'ADMIN_NAME' => 'ADMIN_NAME',
  558. 'REMARK' => 'REMARK',
  559. ]);
  560. $form = new BonusExportForm();
  561. $result = $form->run($filter, '领袖分红奖流水');
  562. if (!$result) {
  563. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  564. }
  565. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  566. }
  567. /**
  568. * 车房养老奖和领袖分红年度发放审核列表
  569. * @return mixed
  570. * @throws \yii\base\Exception
  571. * @throws HttpException
  572. */
  573. public function actionCfLxAuditList() {
  574. $filter = $this->filterCondition([
  575. 'userIds' => 'CFLXA.USER_ID',
  576. 'CF' => 'CFLXA.CF',
  577. 'LX' => 'CFLXA.LX',
  578. 'CREATE_ADMIN_NAME' => 'ADM.ADMIN_NAME',
  579. 'CREATED_AT' => 'CFLXA.CREATED_AT',
  580. 'AUDIT_ADMIN_NAME' => 'ADMA.ADMIN_NAME',
  581. 'AUDITED_AT' => 'CFLXA.AUDITED_AT',
  582. 'CREATE_REMARK' => 'CFLXA.CREATE_REMARK',
  583. 'filterStatus' => 'CFLXA.AUDIT_STATUS',
  584. ]);
  585. $condition = $filter['condition'];
  586. $params = $filter['params'];
  587. $listObj = new CfLxAuditList();
  588. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  589. return static::notice($data);
  590. }
  591. /**
  592. * 车房养老奖和领袖分红年度发放审核导出
  593. * @return mixed
  594. * @throws \yii\db\Exception
  595. * @throws HttpException
  596. */
  597. public function actionCfLxAuditExport() {
  598. $filter = $this->filterCondition([
  599. 'userIds' => 'CFLXA.USER_ID',
  600. 'CF' => 'CFLXA.CF',
  601. 'LX' => 'CFLXA.LX',
  602. 'CREATE_ADMIN_NAME' => 'ADM.ADMIN_NAME',
  603. 'CREATED_AT' => 'CFLXA.CREATED_AT',
  604. 'AUDIT_ADMIN_NAME' => 'ADMA.ADMIN_NAME',
  605. 'AUDITED_AT' => 'CFLXA.AUDITED_AT',
  606. 'CREATE_REMARK' => 'CFLXA.CREATE_REMARK',
  607. 'filterStatus' => 'CFLXA.AUDIT_STATUS',
  608. ]);
  609. $form = new BonusExportForm();
  610. $result = $form->run($filter, '年度奖金发放审核');
  611. if (!$result) {
  612. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  613. }
  614. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  615. }
  616. /**
  617. * 申请发放车房养老奖和领袖分红
  618. * @return mixed
  619. * @throws \yii\db\Exception
  620. * @throws HttpException
  621. */
  622. public function actionCfLxApply() {
  623. if (Yii::$app->request->isPost) {
  624. $formModel = new SendCFAndLXForm();
  625. $formModel->scenario = 'apply';
  626. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->apply()) {
  627. if(!empty($result['logs'])){
  628. return static::notice('申请成功,请在年度奖管理中审核');
  629. }else{
  630. return static::notice('申请失败,无符合发放条件会员',400);
  631. }
  632. } else {
  633. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  634. }
  635. }
  636. return static::notice('Illegal request', 400); // 非法请求
  637. }
  638. /**
  639. * 审核车房养老奖和领袖分红
  640. * @return mixed
  641. * @throws \yii\db\Exception
  642. * @throws HttpException
  643. */
  644. public function actionCfLxAudit() {
  645. $formModel = new SendCFAndLXForm();
  646. $formModel->scenario = 'audit';
  647. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->audit()) {
  648. return static::notice('审核年度奖申请完成');
  649. }
  650. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  651. }
  652. /**
  653. * 删除车房领袖审核信息
  654. * @return mixed
  655. * @throws \yii\db\Exception
  656. * @throws HttpException
  657. */
  658. public function actionCfLxAuditDelete() {
  659. $sendCFAndLXForm = new SendCFAndLXForm();
  660. $result = static::delete(CFLXAudit::class, function ($selected) use ($sendCFAndLXForm) {
  661. $sendCFAndLXForm->beforeDelete($selected);
  662. // Log::adminHandle('删除审核会员余额信息');
  663. }, function ($selected) use ($sendCFAndLXForm) {
  664. $sendCFAndLXForm->delete($selected);
  665. // Log::adminHandle('删除审核会员余额信息');
  666. }, true);
  667. return $result;
  668. }
  669. /**
  670. * 查看所传期数的各项奖金
  671. * @return mixed
  672. * @throws \yii\db\Exception
  673. * @throws HttpException
  674. */
  675. public function actionPeriodDetail() {
  676. $periodNum = \Yii::$app->request->get('periodNum');
  677. $period = Period::instance();
  678. $periodInfo = $period->setPeriodNum($periodNum);
  679. $yearMonth = $period->getYearMonth($periodNum);
  680. // $filter = $this->filterCondition('UT', [
  681. // 'userName' => 'UI.USER_NAME',
  682. // ]);
  683. $condition = '';
  684. $params = [];
  685. $condition .= ' AND C.PERIOD_NUM=:PERIOD_NUM';
  686. $params[':PERIOD_NUM'] = $periodNum;
  687. if (!$period->isClosed($periodNum)) {
  688. return static::notice('Cannot view this period'); // 该期不能查看
  689. }
  690. $data = CalcBonus::lists($condition, $params, [
  691. 'yearMonth' => $yearMonth,
  692. 'select' => 'C.*,UI.USER_NAME',
  693. 'from' => CalcBonus::tableName() . ' AS C',
  694. 'join' => [
  695. ['LEFT JOIN', UserInfo::tableName() . ' AS UI', 'C.USER_ID=UI.USER_ID'],
  696. ],
  697. 'orderBy' => 'C.CREATED_AT DESC',
  698. ]);
  699. $data['periodInfo'] = $periodInfo;
  700. return static::notice($data);
  701. }
  702. /**
  703. * 获取最新一期结算的奖金
  704. * @return mixed
  705. * @throws \yii\base\Exception
  706. * @throws \yii\db\Exception
  707. * @throws HttpException
  708. */
  709. public function actionNewPeriodBonus() {
  710. $periodNum = Period::calculatedMaxPeriodNum();
  711. $data = $this->_periodBonus($periodNum);
  712. return static::notice($data);
  713. }
  714. /**
  715. * 最新一期奖金导出
  716. * @return mixed
  717. * @throws \yii\db\Exception
  718. * @throws HttpException
  719. */
  720. public function actionNewPeriodBonusExport() {
  721. $filter = $this->filterCondition([
  722. 'LAST_USER_NAME' => 'CB.LAST_USER_NAME',
  723. 'LAST_REAL_NAME' => 'CB.LAST_REAL_NAME',
  724. 'LAST_DEC_LV_NAME' => 'CB.LAST_DEC_LV',
  725. 'LAST_EMP_LV_NAME' => 'CB.LAST_EMP_LV',
  726. 'LAST_MOBILE' => 'CB.LAST_MOBILE',
  727. 'LAST_PERIOD_AT' => 'CB.LAST_PERIOD_AT',
  728. 'LAST_CREATED_AT' => 'CB.LAST_CREATED_AT',
  729. 'LAST_REC_USER_NAME' => 'CB.LAST_REC_USER_NAME',
  730. 'LAST_REC_REAL_NAME' => 'CB.LAST_REC_REAL_NAME',
  731. 'LAST_CON_USER_NAME' => 'CB.LAST_CON_USER_NAME',
  732. 'LAST_CON_REAL_NAME' => 'CB.LAST_CON_REAL_NAME',
  733. 'BONUS_BD' => 'CB.BONUS_BD',
  734. 'BONUS_TG' => 'CB.BONUS_TG',
  735. 'BONUS_YJ' => 'CB.BONUS_YJ',
  736. 'BONUS_GX' => 'CB.BONUS_GX',
  737. // 'BONUS_GL' => 'CB.BONUS_BS',
  738. 'BONUS_GL' => 'CB.BONUS_GL',
  739. 'BONUS_QY' => 'CB.BONUS_QY',
  740. 'BONUS_YC' => 'CB.BONUS_YC',
  741. 'PV_1L' => 'CB.PV_1L',
  742. 'SURPLUS_1L' => 'CB.SURPLUS_1L',
  743. 'PV_2L' => 'CB.PV_2L',
  744. 'SURPLUS_2L' => 'CB.SURPLUS_2L',
  745. 'PV_3L' => 'CB.PV_3L',
  746. 'SURPLUS_3L' => 'CB.SURPLUS_3L',
  747. 'CALCULATED_AT' => 'CB.CALCULATED_AT',
  748. 'CALC_MONTH' => 'CB.CALC_MONTH',
  749. 'BONUS_QY_MONTH' => 'CB.BONUS_QY_MONTH',
  750. ]);
  751. $periodNum = Period::calculatedMaxPeriodNum();
  752. $period = Period::instance();
  753. $yearMonth = $period->getYearMonth($periodNum);
  754. $filter['condition'] .= ' AND PERIOD_NUM=:PERIOD_NUM';
  755. $filter['params'][':PERIOD_NUM'] = $periodNum;
  756. $form = new BonusExportForm();
  757. $result = $form->run(array_merge($filter, ['others'=>['yearMonth'=>$yearMonth]]), '最新奖金');
  758. if (!$result) {
  759. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  760. }
  761. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  762. }
  763. /**
  764. * 获取往期已结算的奖金
  765. * @return mixed
  766. * @throws \yii\db\Exception
  767. * @throws HttpException
  768. */
  769. public function actionOtherPeriodBonus() {
  770. $periodNumRequest = \Yii::$app->request->get('periodNum');
  771. if(!$periodNumRequest){
  772. $periodNum = Period::calculatedMaxPeriodNum();
  773. }else{
  774. $periodNum = explode(",", $periodNumRequest)[1];
  775. }
  776. $data = $this->_periodBonus($periodNum,false);
  777. if( isset($data['filterTypes']) && is_array($data['filterTypes']) ) {
  778. $data['filterTypes'] = array_merge(['periodNum'=>['isUserTable'=> false, 'name'=> \Yii::t('ctx', 'payCycle')]], $data['filterTypes']);
  779. }
  780. return static::notice($data);
  781. }
  782. /**
  783. * 往期奖金导出
  784. * @return mixed
  785. * @throws \yii\db\Exception
  786. * @throws HttpException
  787. */
  788. public function actionOtherPeriodBonusExport() {
  789. $filter = $this->filterCondition([
  790. 'periodNum' => 'CB.PERIOD_NUM',
  791. 'LAST_USER_NAME' => 'CB.LAST_USER_NAME',
  792. 'LAST_REAL_NAME' => 'CB.LAST_REAL_NAME',
  793. 'LAST_DEC_LV_NAME' => 'CB.LAST_DEC_LV',
  794. 'LAST_EMP_LV_NAME' => 'CB.LAST_EMP_LV',
  795. 'LAST_MOBILE' => 'CB.LAST_MOBILE',
  796. 'LAST_PERIOD_AT' => 'CB.LAST_PERIOD_AT',
  797. 'LAST_CREATED_AT' => 'CB.LAST_CREATED_AT',
  798. 'LAST_REC_USER_NAME' => 'CB.LAST_REC_USER_NAME',
  799. 'LAST_REC_REAL_NAME' => 'CB.LAST_REC_REAL_NAME',
  800. 'LAST_CON_USER_NAME' => 'CB.LAST_CON_USER_NAME',
  801. 'LAST_CON_REAL_NAME' => 'CB.LAST_CON_REAL_NAME',
  802. 'BONUS_BD' => 'CB.BONUS_BD',
  803. 'BONUS_TG' => 'CB.BONUS_TG',
  804. 'BONUS_YJ' => 'CB.BONUS_YJ',
  805. 'BONUS_GX' => 'CB.BONUS_GX',
  806. 'BONUS_GL' => 'CB.BONUS_GL',
  807. 'BONUS_QY' => 'CB.BONUS_QY',
  808. 'BONUS_YC' => 'CB.BONUS_YC',
  809. 'PV_1L' => 'CB.PV_1L',
  810. 'SURPLUS_1L' => 'CB.SURPLUS_1L',
  811. 'PV_2L' => 'CB.PV_2L',
  812. 'SURPLUS_2L' => 'CB.SURPLUS_2L',
  813. 'PV_3L' => 'CB.PV_3L',
  814. 'SURPLUS_3L' => 'CB.SURPLUS_3L',
  815. 'CALCULATED_AT' => 'CB.CALCULATED_AT',
  816. 'CALC_MONTH' => 'CB.CALC_MONTH',
  817. 'BONUS_QY_MONTH' => 'CB.BONUS_QY_MONTH',
  818. ]);
  819. $periodNumRequest = \Yii::$app->request->get('periodNum');
  820. if(!$periodNumRequest){
  821. $periodNum = Period::calculatedMaxPeriodNum();
  822. }else{
  823. $periodNum = explode(",", $periodNumRequest)[1];
  824. }
  825. $period = Period::instance();
  826. $yearMonth = $period->getYearMonth($periodNum);
  827. $condition = $filter['condition'];
  828. $params = $filter['params'];
  829. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  830. if (!$isSuper) {
  831. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  832. $adminCountry = AdminCountry::getCountry($adminId);
  833. $quotedAdminCountry = array_map(function($item) {
  834. return "'" . addslashes($item) . "'";
  835. }, $adminCountry);
  836. $condition .= " AND CU.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
  837. }
  838. $form = new BonusExportForm();
  839. $result = $form->run(array_merge(['condition'=>$condition, 'params'=>$params, 'others'=>['yearMonth'=>$yearMonth]]), 'Member Bonus'); // 往期奖金
  840. if (!$result) {
  841. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  842. }
  843. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  844. }
  845. /**
  846. * 获取筛选类型
  847. * @return mixed
  848. * @throws HttpException
  849. */
  850. public function actionOtherPeriodBonusFilterTypes(){
  851. $listObj = new PeriodBonusList();
  852. $filterTypes = $listObj->getFilterTypes();
  853. $filterTypes = array_merge(['periodNum'=>['isUserTable'=> false, 'name'=> \Yii::t('ctx', 'payCycle')]], $filterTypes);
  854. return static::notice($filterTypes);
  855. }
  856. /**
  857. * 期数对应的奖金
  858. * @param $periodNum
  859. * @param $periodFilter
  860. * @return array
  861. * @throws \yii\base\Exception
  862. * @throws \yii\db\Exception
  863. */
  864. private function _periodBonus($periodNum,$periodFilter = true) {
  865. $filter = $this->filterCondition([
  866. 'periodNum' => 'CB.PERIOD_NUM',
  867. 'LAST_USER_NAME' => 'CB.LAST_USER_NAME',
  868. 'LAST_REAL_NAME' => 'CB.LAST_REAL_NAME',
  869. 'LAST_DEC_LV_NAME' => 'CB.LAST_DEC_LV',
  870. 'LAST_EMP_LV_NAME' => 'CB.LAST_EMP_LV',
  871. 'LAST_ELITE_LV_NAME' => 'CB.LAST_ELITE_LV',
  872. 'LAST_PERIOD_AT' => 'CB.LAST_PERIOD_AT',
  873. 'LAST_CREATED_AT' => 'CB.LAST_CREATED_AT',
  874. 'CALC_MONTH' => 'CB.CALC_MONTH',
  875. 'BONUS_TOTAL' => 'CB.BONUS_TOTAL',
  876. 'BONUS_E' => 'CB.BONUS_E',
  877. 'BONUS_PE' => 'CB.BONUS_PE',
  878. 'BONUS_SE' => 'CB.BONUS_SE',
  879. 'BONUS_LB' => 'CB.BONUS_LB',
  880. 'BONUS_ST' => 'CB.BONUS_ST',
  881. 'BONUS_WB' => 'CB.BONUS_WB',
  882. 'BONUS_CAR' => 'CB.BONUS_CAR',
  883. 'BONUS_PB' => 'CB.BONUS_PB',
  884. ]);
  885. $period = Period::instance();
  886. $yearMonth = $period->getYearMonth($periodNum);
  887. $condition = $filter['condition'];
  888. $params = $filter['params'];
  889. if($periodFilter){
  890. $condition .= ' AND CB.PERIOD_NUM=:PERIOD_NUM';
  891. $params[':PERIOD_NUM'] = $periodNum;
  892. }
  893. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  894. if (!$isSuper) {
  895. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  896. $adminCountry = AdminCountry::getCountry($adminId);
  897. $quotedAdminCountry = array_map(function($item) {
  898. return "'" . addslashes($item) . "'";
  899. }, $adminCountry);
  900. $condition .= " AND CU.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
  901. }
  902. $listObj = new PeriodBonusList();
  903. return $listObj->getList(['condition'=>$condition, 'params'=>$params, 'others'=>['yearMonth'=>$yearMonth]]);
  904. }
  905. /**
  906. * 团队奖奖金向下追溯
  907. * @return mixed
  908. * @throws \yii\base\Exception
  909. * @throws \yii\db\Exception
  910. * @throws HttpException
  911. */
  912. public function actionTraceDownQy() {
  913. $periodNum = Yii::$app->request->get('periodNum');
  914. if (!$periodNum) return static::notice(\Yii::t('ctx', 'requirePeriods'), 400);
  915. $userName = Yii::$app->request->get('userName');
  916. if (!$userName) return static::notice(\Yii::t('ctx', 'requireMemberNumber'), 400);
  917. $period = Period::instance();
  918. if (!$period->isCalculated($periodNum)) {
  919. return static::notice([]);
  920. }
  921. $yearMonth = $period->getYearMonth($periodNum);
  922. $filter = $this->filterCondition([
  923. 'decType' => 'PO.DEC_TYPE',
  924. 'periodNum' => 'PO.PERIOD_NUM',
  925. ]);
  926. $qyFilter = $this->_qyFilterCondition($filter['request']);
  927. $filter = array_merge($filter, $qyFilter);
  928. $condition = $filter['condition'];
  929. $params = $filter['params'];
  930. $listObj = new TraceDownQyList();
  931. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params, 'others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]);
  932. return static::notice($data);
  933. }
  934. /**
  935. * 获取
  936. * @param $request
  937. * @return array|string[]
  938. */
  939. private function _qyFilterCondition($request) {
  940. //根据USER_NAME获取USER_ID
  941. $user = User::find()->select('ID')->where('USER_NAME=:USER_NAME', ['USER_NAME'=>$request['userName']])->asArray()->one();
  942. if( !$user ) return [];
  943. //找到这个会员的LOCATION_TAG
  944. $userNetwork = UserNetwork::find()->select(['LOCATION_TAG'])->where('USER_ID=:USER_ID', ['USER_ID'=>$user['ID']])->asArray()->one();
  945. $searchLocationTag = $userNetwork['LOCATION_TAG'];
  946. if( isset($request['location']) && $request['location'] ) {
  947. $searchLocationTag .= $request['location'];
  948. }
  949. return [
  950. 'LOCATION_TAG' => 'LIKE ' . $searchLocationTag . '%'
  951. ];
  952. }
  953. /**
  954. * 团队奖向下追溯导出
  955. * @return mixed
  956. * @throws \yii\db\Exception
  957. * @throws HttpException
  958. */
  959. public function actionTraceDownQyExport() {
  960. $periodNum = Yii::$app->request->get('periodNum');
  961. if (!$periodNum) return static::notice('请填写期数', 400);
  962. $userName = Yii::$app->request->get('userName');
  963. if (!$userName) return static::notice('请填写会员编号', 400);
  964. $period = Period::instance();
  965. if (!$period->isCalculated($periodNum)) {
  966. return static::notice([]);
  967. }
  968. $yearMonth = $period->getYearMonth($periodNum);
  969. $filter = $this->filterCondition([
  970. 'decType' => 'PO.DEC_TYPE',
  971. 'periodNum' => 'PO.PERIOD_NUM',
  972. ]);
  973. $qyFilter = $this->_qyFilterCondition($filter['request']);
  974. $filter = array_merge($filter, $qyFilter);
  975. $form = new BonusExportForm();
  976. $result = $form->run(array_merge($filter, ['others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]), '团队奖向下追溯');
  977. if (!$result) {
  978. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  979. }
  980. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  981. }
  982. /**
  983. * 团队奖向上追溯
  984. * @return mixed
  985. * @throws \yii\base\Exception
  986. * @throws HttpException
  987. */
  988. public function actionTraceUpQy() {
  989. $periodNum = Yii::$app->request->get('periodNum');
  990. if (!$periodNum) return static::notice('请填写期数', 400);
  991. if (!$userName = Yii::$app->request->get('userName')) return static::notice('请填写会员编号', 400);
  992. if(!$userId = Info::getUserIdByUserName($userName)) return static::notice('Member does not exist', 400); // 会员不存在
  993. //会员是否有业绩单
  994. if(!PerfOrder::find()->where('USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM',[':USER_ID'=>$userId,':PERIOD_NUM'=>$periodNum])->exists()){
  995. return static::notice('该会员本期没有业绩单', 400);
  996. }
  997. $listObj = new TraceUpQyList();
  998. $data = $listObj->getList(['condition'=>'', 'params'=>[], 'others'=>['userId'=>$userId, 'periodNum'=>$periodNum]]);
  999. return static::notice($data);
  1000. }
  1001. /**
  1002. * 团队奖向上追溯导出
  1003. * @return mixed
  1004. * @throws \yii\db\Exception
  1005. * @throws HttpException
  1006. */
  1007. public function actionTraceUpQyExport() {
  1008. $periodNum = Yii::$app->request->get('periodNum');
  1009. if (!$periodNum) return static::notice('请填写期数', 400);
  1010. if (!$userName = Yii::$app->request->get('userName')) return static::notice('请填写会员编号', 400);
  1011. if(!$userId = Info::getUserIdByUserName($userName)) return static::notice('Member does not exist', 400); // 会员不存在
  1012. //会员是否有业绩单
  1013. if(!PerfOrder::find()->where('USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM',[':USER_ID'=>$userId,':PERIOD_NUM'=>$periodNum])->exists()){
  1014. return static::notice('该会员本期没有业绩单', 400);
  1015. }
  1016. $form = new BonusExportForm();
  1017. $result = $form->run(array_merge(['condition'=>'', 'params'=>[]], ['others'=>['userId'=>$userId, 'periodNum'=>$periodNum]]), '团队奖向上追溯');
  1018. if (!$result) {
  1019. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1020. }
  1021. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  1022. }
  1023. /**
  1024. * 荣衔奖向下追溯
  1025. * @return mixed
  1026. * @throws \yii\base\Exception
  1027. * @throws \yii\db\Exception
  1028. * @throws HttpException
  1029. */
  1030. public function actionTraceDownYc() {
  1031. $periodNum = Yii::$app->request->get('periodNum');
  1032. if (!$periodNum) return static::notice([]);
  1033. $period = Period::instance();
  1034. $yearMonth = $period->getYearMonth($periodNum);
  1035. $filter = $this->filterCondition([
  1036. 'userName' => 'UI.USER_NAME',
  1037. 'periodNum' => 'CBY.PERIOD_NUM',
  1038. ]);
  1039. $condition = $filter['condition'];
  1040. $params = $filter['params'];
  1041. $listObj = new TraceDownYcList();
  1042. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params, 'others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]);
  1043. return static::notice($data);
  1044. }
  1045. /**
  1046. * 荣衔奖向下追溯导出
  1047. * @return mixed
  1048. * @throws \yii\db\Exception
  1049. * @throws HttpException
  1050. */
  1051. public function actionTraceDownYcExport() {
  1052. $periodNum = Yii::$app->request->get('periodNum');
  1053. if (!$periodNum) return static::notice([]);
  1054. $period = Period::instance();
  1055. $yearMonth = $period->getYearMonth($periodNum);
  1056. $filter = $this->filterCondition([
  1057. 'userName' => 'UI.USER_NAME',
  1058. 'periodNum' => 'CBY.PERIOD_NUM',
  1059. ]);
  1060. $form = new BonusExportForm();
  1061. $result = $form->run(array_merge($filter, ['others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]), '荣衔奖向下追溯');
  1062. if (!$result) {
  1063. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1064. }
  1065. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  1066. }
  1067. /**
  1068. * 服务奖向下追溯
  1069. * @return mixed
  1070. * @throws \yii\base\Exception
  1071. * @throws \yii\db\Exception
  1072. * @throws HttpException
  1073. */
  1074. public function actionTraceDownBd() {
  1075. $periodNum = Yii::$app->request->get('periodNum');
  1076. if (!$periodNum) return static::notice([]);
  1077. $period = Period::instance();
  1078. $yearMonth = $period->getYearMonth($periodNum);
  1079. $filter = $this->filterCondition([
  1080. 'userName' => 'UI.USER_NAME',
  1081. 'periodNum' => 'CBB.PERIOD_NUM',
  1082. ]);
  1083. $condition = $filter['condition'];
  1084. $params = $filter['params'];
  1085. $listObj = new TraceDownBdList();
  1086. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params, 'others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]);
  1087. return static::notice($data);
  1088. }
  1089. /**
  1090. * 服务奖向下追溯导出
  1091. * @return mixed
  1092. * @throws \yii\db\Exception
  1093. * @throws HttpException
  1094. */
  1095. public function actionTraceDownBdExport() {
  1096. $periodNum = Yii::$app->request->get('periodNum');
  1097. if (!$periodNum) return static::notice([]);
  1098. $period = Period::instance();
  1099. $yearMonth = $period->getYearMonth($periodNum);
  1100. $filter = $this->filterCondition([
  1101. 'userName' => 'UI.USER_NAME',
  1102. 'periodNum' => 'CBB.PERIOD_NUM',
  1103. ]);
  1104. $form = new BonusExportForm();
  1105. $result = $form->run(array_merge($filter, ['others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]), '服务奖向下追溯');
  1106. if (!$result) {
  1107. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1108. }
  1109. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  1110. }
  1111. /**
  1112. * 推广奖向下追溯
  1113. * @return mixed
  1114. * @throws \yii\base\Exception
  1115. * @throws \yii\db\Exception
  1116. * @throws HttpException
  1117. */
  1118. public function actionTraceDownTg() {
  1119. $periodNum = Yii::$app->request->get('periodNum');
  1120. if (!$periodNum) return static::notice([]);
  1121. $period = Period::instance();
  1122. $yearMonth = $period->getYearMonth($periodNum);
  1123. $filter = $this->filterCondition([
  1124. 'userName' => 'UI.USER_NAME',
  1125. 'periodNum' => 'CTG.PERIOD_NUM',
  1126. ]);
  1127. $condition = $filter['condition'];
  1128. $params = $filter['params'];
  1129. $listObj = new TraceDownTgList();
  1130. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params, 'others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]);
  1131. return static::notice($data);
  1132. }
  1133. /**
  1134. * 推广奖向下追溯导出
  1135. * @return mixed
  1136. * @throws \yii\db\Exception
  1137. * @throws HttpException
  1138. */
  1139. public function actionTraceDownTgExport() {
  1140. $periodNum = Yii::$app->request->get('periodNum');
  1141. if (!$periodNum) return static::notice([]);
  1142. $period = Period::instance();
  1143. $yearMonth = $period->getYearMonth($periodNum);
  1144. $filter = $this->filterCondition([
  1145. 'userName' => 'UI.USER_NAME',
  1146. 'periodNum' => 'CTG.PERIOD_NUM',
  1147. ]);
  1148. $form = new BonusExportForm();
  1149. $result = $form->run(array_merge($filter, ['others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]), '推广奖向下追溯');
  1150. if (!$result) {
  1151. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1152. }
  1153. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  1154. }
  1155. /**
  1156. * 消费奖向下追溯
  1157. * @return mixed
  1158. * @throws \yii\base\Exception
  1159. * @throws \yii\db\Exception
  1160. * @throws HttpException
  1161. */
  1162. public function actionTraceDownXf() {
  1163. $periodNum = Yii::$app->request->get('periodNum');
  1164. if (!$periodNum) return static::notice([]);
  1165. $period = Period::instance();
  1166. $yearMonth = $period->getYearMonth($periodNum);
  1167. $filter = $this->filterCondition([
  1168. 'userName' => 'UI.USER_NAME',
  1169. 'periodNum' => 'CXF.PERIOD_NUM',
  1170. ]);
  1171. $condition = $filter['condition'];
  1172. $params = $filter['params'];
  1173. $listObj = new TraceDownXfList();
  1174. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params, 'others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]);
  1175. return static::notice($data);
  1176. }
  1177. /**
  1178. * 消费奖向下追溯导出
  1179. * @return mixed
  1180. * @throws \yii\db\Exception
  1181. * @throws HttpException
  1182. */
  1183. public function actionTraceDownXfExport() {
  1184. $periodNum = Yii::$app->request->get('periodNum');
  1185. if (!$periodNum) return static::notice([]);
  1186. $period = Period::instance();
  1187. $yearMonth = $period->getYearMonth($periodNum);
  1188. $filter = $this->filterCondition([
  1189. 'userName' => 'UI.USER_NAME',
  1190. 'periodNum' => 'CXF.PERIOD_NUM',
  1191. ]);
  1192. $form = new BonusExportForm();
  1193. $result = $form->run(array_merge($filter, ['others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]), '推广奖向下追溯');
  1194. if (!$result) {
  1195. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1196. }
  1197. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  1198. }
  1199. /**
  1200. * 业绩奖向下追溯
  1201. * @return mixed
  1202. * @throws \yii\base\Exception
  1203. * @throws \yii\db\Exception
  1204. * @throws HttpException
  1205. */
  1206. public function actionTraceDownYj() {
  1207. $periodNum = Yii::$app->request->get('periodNum');
  1208. if (!$periodNum) return static::notice([]);
  1209. $period = Period::instance();
  1210. $yearMonth = $period->getYearMonth($periodNum);
  1211. $filter = $this->filterCondition([
  1212. 'userName' => 'UI.USER_NAME',
  1213. 'periodNum' => 'CYJ.PERIOD_NUM',
  1214. ]);
  1215. $condition = $filter['condition'];
  1216. $params = $filter['params'];
  1217. $listObj = new TraceDownYjList();
  1218. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params, 'others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]);
  1219. return static::notice($data);
  1220. }
  1221. /**
  1222. * 业绩奖向下追溯导出
  1223. * @return mixed
  1224. * @throws \yii\db\Exception
  1225. * @throws HttpException
  1226. */
  1227. public function actionTraceDownYjExport() {
  1228. $periodNum = Yii::$app->request->get('periodNum');
  1229. if (!$periodNum) return static::notice([]);
  1230. $period = Period::instance();
  1231. $yearMonth = $period->getYearMonth($periodNum);
  1232. $filter = $this->filterCondition([
  1233. 'userName' => 'UI.USER_NAME',
  1234. 'periodNum' => 'CYJ.PERIOD_NUM',
  1235. ]);
  1236. $form = new BonusExportForm();
  1237. $result = $form->run(array_merge($filter, ['others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]), '业绩奖向下追溯');
  1238. if (!$result) {
  1239. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1240. }
  1241. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  1242. }
  1243. /**
  1244. * 共享奖向下追溯
  1245. * @return mixed
  1246. * @throws \yii\base\Exception
  1247. * @throws \yii\db\Exception
  1248. * @throws HttpException
  1249. */
  1250. public function actionTraceDownGx() {
  1251. $periodNum = Yii::$app->request->get('periodNum');
  1252. if (!$periodNum) return static::notice([]);
  1253. $period = Period::instance();
  1254. $yearMonth = $period->getYearMonth($periodNum);
  1255. $filter = $this->filterCondition([
  1256. 'userName' => 'UI.USER_NAME',
  1257. 'periodNum' => 'CGX.PERIOD_NUM',
  1258. ]);
  1259. $condition = $filter['condition'];
  1260. $params = $filter['params'];
  1261. $listObj = new TraceDownGxList();
  1262. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params, 'others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]);
  1263. return static::notice($data);
  1264. }
  1265. /**
  1266. * 共享奖向下追溯导出
  1267. * @return mixed
  1268. * @throws \yii\db\Exception
  1269. * @throws HttpException
  1270. */
  1271. public function actionTraceDownGxExport() {
  1272. $periodNum = Yii::$app->request->get('periodNum');
  1273. if (!$periodNum) return static::notice([]);
  1274. $period = Period::instance();
  1275. $yearMonth = $period->getYearMonth($periodNum);
  1276. $filter = $this->filterCondition([
  1277. 'userName' => 'UI.USER_NAME',
  1278. 'periodNum' => 'CGX.PERIOD_NUM',
  1279. ]);
  1280. $form = new BonusExportForm();
  1281. $result = $form->run(array_merge($filter, ['others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]), '共享奖向下追溯');
  1282. if (!$result) {
  1283. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1284. }
  1285. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  1286. }
  1287. /**
  1288. * 管理奖向下追溯
  1289. * @return mixed
  1290. * @throws \yii\base\Exception
  1291. * @throws \yii\db\Exception
  1292. * @throws HttpException
  1293. */
  1294. public function actionTraceDownGl() {
  1295. $periodNum = Yii::$app->request->get('periodNum');
  1296. if (!$periodNum) return static::notice([]);
  1297. $period = Period::instance();
  1298. $yearMonth = $period->getYearMonth($periodNum);
  1299. $filter = $this->filterCondition([
  1300. 'userName' => 'UI.USER_NAME',
  1301. 'periodNum' => 'CGL.PERIOD_NUM',
  1302. ]);
  1303. $condition = $filter['condition'];
  1304. $params = $filter['params'];
  1305. $listObj = new TraceDownGlList();
  1306. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params, 'others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]);
  1307. return static::notice($data);
  1308. }
  1309. /**
  1310. * 管理奖向下追溯导出
  1311. * @return mixed
  1312. * @throws \yii\db\Exception
  1313. * @throws HttpException
  1314. */
  1315. public function actionTraceDownGlExport() {
  1316. $periodNum = Yii::$app->request->get('periodNum');
  1317. if (!$periodNum) return static::notice([]);
  1318. $period = Period::instance();
  1319. $yearMonth = $period->getYearMonth($periodNum);
  1320. $filter = $this->filterCondition([
  1321. 'userName' => 'UI.USER_NAME',
  1322. 'periodNum' => 'CGL.PERIOD_NUM',
  1323. ]);
  1324. $form = new BonusExportForm();
  1325. $result = $form->run(array_merge($filter, ['others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]), '管理奖向下追溯');
  1326. if (!$result) {
  1327. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1328. }
  1329. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  1330. }
  1331. /**
  1332. * 荣衔奖向上追溯
  1333. * @return mixed
  1334. * @throws \yii\base\Exception
  1335. * @throws \yii\db\Exception
  1336. * @throws HttpException
  1337. */
  1338. public function actionTraceUpYc() {
  1339. $periodNum = Yii::$app->request->get('periodNum');
  1340. if (!$periodNum) return static::notice([]);
  1341. $period = Period::instance();
  1342. $yearMonth = $period->getYearMonth($periodNum);
  1343. $filter = $this->filterCondition([
  1344. 'userName' => 'UI.USER_NAME',
  1345. 'periodNum' => 'CBY.PERIOD_NUM',
  1346. ]);
  1347. $condition = $filter['condition'];
  1348. $params = $filter['params'];
  1349. $listObj = new TraceUpYcList();
  1350. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params, 'others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]);
  1351. return static::notice($data);
  1352. }
  1353. /**
  1354. * 荣衔奖向上追溯导出
  1355. * @return mixed
  1356. * @throws \yii\db\Exception
  1357. * @throws HttpException
  1358. */
  1359. public function actionTraceUpYcExport() {
  1360. $periodNum = Yii::$app->request->get('periodNum');
  1361. if (!$periodNum) return static::notice([]);
  1362. $period = Period::instance();
  1363. $yearMonth = $period->getYearMonth($periodNum);
  1364. $filter = $this->filterCondition([
  1365. 'userName' => 'UI.USER_NAME',
  1366. 'periodNum' => 'CBY.PERIOD_NUM',
  1367. ]);
  1368. $form = new BonusExportForm();
  1369. $result = $form->run(array_merge($filter, ['others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]), '荣衔奖向上追溯');
  1370. if (!$result) {
  1371. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1372. }
  1373. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  1374. }
  1375. /**
  1376. * 服务奖向上追溯
  1377. * @return mixed
  1378. * @throws \yii\base\Exception
  1379. * @throws \yii\db\Exception
  1380. * @throws HttpException
  1381. */
  1382. public function actionTraceUpBd() {
  1383. $periodNum = Yii::$app->request->get('periodNum');
  1384. if (!$periodNum) return static::notice([]);
  1385. $period = Period::instance();
  1386. $yearMonth = $period->getYearMonth($periodNum);
  1387. $filter = $this->filterCondition([
  1388. 'userName' => 'UI.USER_NAME',
  1389. 'periodNum' => 'CBB.PERIOD_NUM',
  1390. ]);
  1391. $condition = $filter['condition'];
  1392. $params = $filter['params'];
  1393. $listObj = new TraceUpBdList();
  1394. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params, 'others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]);
  1395. return static::notice($data);
  1396. }
  1397. /**
  1398. * 服务奖向上追溯导出
  1399. * @return mixed
  1400. * @throws \yii\db\Exception
  1401. * @throws HttpException
  1402. */
  1403. public function actionTraceUpBdExport() {
  1404. $periodNum = Yii::$app->request->get('periodNum');
  1405. if (!$periodNum) return static::notice([]);
  1406. $period = Period::instance();
  1407. $yearMonth = $period->getYearMonth($periodNum);
  1408. $filter = $this->filterCondition([
  1409. 'userName' => 'UI.USER_NAME',
  1410. 'periodNum' => 'CBY.PERIOD_NUM',
  1411. ]);
  1412. $form = new BonusExportForm();
  1413. $result = $form->run(array_merge($filter, ['others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]), '荣衔奖向上追溯');
  1414. if (!$result) {
  1415. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1416. }
  1417. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  1418. }
  1419. /**
  1420. * 推广奖向上追溯
  1421. * @return mixed
  1422. * @throws \yii\base\Exception
  1423. * @throws \yii\db\Exception
  1424. * @throws HttpException
  1425. */
  1426. public function actionTraceUpTg() {
  1427. $periodNum = Yii::$app->request->get('periodNum');
  1428. if (!$periodNum) return static::notice([]);
  1429. $period = Period::instance();
  1430. $yearMonth = $period->getYearMonth($periodNum);
  1431. $filter = $this->filterCondition([
  1432. 'userName' => 'UI.USER_NAME',
  1433. 'periodNum' => 'CTG.PERIOD_NUM',
  1434. ]);
  1435. $condition = $filter['condition'];
  1436. $params = $filter['params'];
  1437. $listObj = new TraceUpTgList();
  1438. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params, 'others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]);
  1439. return static::notice($data);
  1440. }
  1441. /**
  1442. * 推广奖向上追溯导出
  1443. * @return mixed
  1444. * @throws \yii\db\Exception
  1445. * @throws HttpException
  1446. */
  1447. public function actionTraceUpTgExport() {
  1448. $periodNum = Yii::$app->request->get('periodNum');
  1449. if (!$periodNum) return static::notice([]);
  1450. $period = Period::instance();
  1451. $yearMonth = $period->getYearMonth($periodNum);
  1452. $filter = $this->filterCondition([
  1453. 'userName' => 'UI.USER_NAME',
  1454. 'periodNum' => 'CTG.PERIOD_NUM',
  1455. ]);
  1456. $form = new BonusExportForm();
  1457. $result = $form->run(array_merge($filter, ['others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]), '荣衔奖向上追溯');
  1458. if (!$result) {
  1459. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1460. }
  1461. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  1462. }
  1463. /**
  1464. * 消费奖向上追溯
  1465. * @return mixed
  1466. * @throws \yii\base\Exception
  1467. * @throws \yii\db\Exception
  1468. * @throws HttpException
  1469. */
  1470. public function actionTraceUpXf() {
  1471. $periodNum = Yii::$app->request->get('periodNum');
  1472. if (!$periodNum) return static::notice([]);
  1473. $period = Period::instance();
  1474. $yearMonth = $period->getYearMonth($periodNum);
  1475. $filter = $this->filterCondition([
  1476. 'userName' => 'UI.USER_NAME',
  1477. 'periodNum' => 'CXF.PERIOD_NUM',
  1478. ]);
  1479. $condition = $filter['condition'];
  1480. $params = $filter['params'];
  1481. $listObj = new TraceUpXfList();
  1482. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params, 'others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]);
  1483. return static::notice($data);
  1484. }
  1485. /**
  1486. * 推广奖向上追溯导出
  1487. * @return mixed
  1488. * @throws \yii\db\Exception
  1489. * @throws HttpException
  1490. */
  1491. public function actionTraceUpXfExport() {
  1492. $periodNum = Yii::$app->request->get('periodNum');
  1493. if (!$periodNum) return static::notice([]);
  1494. $period = Period::instance();
  1495. $yearMonth = $period->getYearMonth($periodNum);
  1496. $filter = $this->filterCondition([
  1497. 'userName' => 'UI.USER_NAME',
  1498. 'periodNum' => 'CXF.PERIOD_NUM',
  1499. ]);
  1500. $form = new BonusExportForm();
  1501. $result = $form->run(array_merge($filter, ['others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]), '荣衔奖向上追溯');
  1502. if (!$result) {
  1503. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1504. }
  1505. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  1506. }
  1507. /**
  1508. * 业绩奖向上追溯
  1509. * @return mixed
  1510. * @throws \yii\base\Exception
  1511. * @throws \yii\db\Exception
  1512. * @throws HttpException
  1513. */
  1514. public function actionTraceUpYj() {
  1515. $periodNum = Yii::$app->request->get('periodNum');
  1516. if (!$periodNum) return static::notice([]);
  1517. $period = Period::instance();
  1518. $yearMonth = $period->getYearMonth($periodNum);
  1519. $filter = $this->filterCondition([
  1520. 'userName' => 'UI.USER_NAME',
  1521. 'periodNum' => 'CYJ.PERIOD_NUM',
  1522. ]);
  1523. $condition = $filter['condition'];
  1524. $params = $filter['params'];
  1525. $listObj = new TraceUpYjList();
  1526. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params, 'others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]);
  1527. return static::notice($data);
  1528. }
  1529. /**
  1530. * 业绩奖向上追溯导出
  1531. * @return mixed
  1532. * @throws \yii\db\Exception
  1533. * @throws HttpException
  1534. */
  1535. public function actionTraceUpYjExport() {
  1536. $periodNum = Yii::$app->request->get('periodNum');
  1537. if (!$periodNum) return static::notice([]);
  1538. $period = Period::instance();
  1539. $yearMonth = $period->getYearMonth($periodNum);
  1540. $filter = $this->filterCondition([
  1541. 'userName' => 'UI.USER_NAME',
  1542. 'periodNum' => 'CYJ.PERIOD_NUM',
  1543. ]);
  1544. $form = new BonusExportForm();
  1545. $result = $form->run(array_merge($filter, ['others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]), '荣衔奖向上追溯');
  1546. if (!$result) {
  1547. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1548. }
  1549. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  1550. }
  1551. /**
  1552. * 共享奖向上追溯
  1553. * @return mixed
  1554. * @throws \yii\base\Exception
  1555. * @throws \yii\db\Exception
  1556. * @throws HttpException
  1557. */
  1558. public function actionTraceUpGx() {
  1559. $periodNum = Yii::$app->request->get('periodNum');
  1560. if (!$periodNum) return static::notice([]);
  1561. $period = Period::instance();
  1562. $yearMonth = $period->getYearMonth($periodNum);
  1563. $filter = $this->filterCondition([
  1564. 'userName' => 'UI.USER_NAME',
  1565. 'periodNum' => 'CGX.PERIOD_NUM',
  1566. ]);
  1567. $condition = $filter['condition'];
  1568. $params = $filter['params'];
  1569. $listObj = new TraceUpGxList();
  1570. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params, 'others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]);
  1571. return static::notice($data);
  1572. }
  1573. /**
  1574. * 共享奖向上追溯导出
  1575. * @return mixed
  1576. * @throws \yii\db\Exception
  1577. * @throws HttpException
  1578. */
  1579. public function actionTraceUpGxExport() {
  1580. $periodNum = Yii::$app->request->get('periodNum');
  1581. if (!$periodNum) return static::notice([]);
  1582. $period = Period::instance();
  1583. $yearMonth = $period->getYearMonth($periodNum);
  1584. $filter = $this->filterCondition([
  1585. 'userName' => 'UI.USER_NAME',
  1586. 'periodNum' => 'CGX.PERIOD_NUM',
  1587. ]);
  1588. $form = new BonusExportForm();
  1589. $result = $form->run(array_merge($filter, ['others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]), '荣衔奖向上追溯');
  1590. if (!$result) {
  1591. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1592. }
  1593. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  1594. }
  1595. /**
  1596. * 管理奖向上追溯
  1597. * @return mixed
  1598. * @throws \yii\base\Exception
  1599. * @throws \yii\db\Exception
  1600. * @throws HttpException
  1601. */
  1602. public function actionTraceUpGl() {
  1603. $periodNum = Yii::$app->request->get('periodNum');
  1604. if (!$periodNum) return static::notice([]);
  1605. $period = Period::instance();
  1606. $yearMonth = $period->getYearMonth($periodNum);
  1607. $filter = $this->filterCondition([
  1608. 'userName' => 'UI.USER_NAME',
  1609. 'periodNum' => 'CGL.PERIOD_NUM',
  1610. ]);
  1611. $condition = $filter['condition'];
  1612. $params = $filter['params'];
  1613. $listObj = new TraceUpGlList();
  1614. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params, 'others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]);
  1615. return static::notice($data);
  1616. }
  1617. /**
  1618. * 管理奖向上追溯导出
  1619. * @return mixed
  1620. * @throws \yii\db\Exception
  1621. * @throws HttpException
  1622. */
  1623. public function actionTraceUpGlExport() {
  1624. $periodNum = Yii::$app->request->get('periodNum');
  1625. if (!$periodNum) return static::notice([]);
  1626. $period = Period::instance();
  1627. $yearMonth = $period->getYearMonth($periodNum);
  1628. $filter = $this->filterCondition([
  1629. 'userName' => 'UI.USER_NAME',
  1630. 'periodNum' => 'CGL.PERIOD_NUM',
  1631. ]);
  1632. $form = new BonusExportForm();
  1633. $result = $form->run(array_merge($filter, ['others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]), '荣衔奖向上追溯');
  1634. if (!$result) {
  1635. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1636. }
  1637. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  1638. }
  1639. /**
  1640. * 复销奖向下追溯
  1641. * @return mixed
  1642. * @throws \yii\base\Exception
  1643. * @throws \yii\db\Exception
  1644. * @throws HttpException
  1645. */
  1646. public function actionTraceDownFx() {
  1647. $periodNum = Yii::$app->request->get('periodNum');
  1648. if (!$periodNum) return static::notice([]);
  1649. $period = Period::instance();
  1650. $yearMonth = $period->getYearMonth($periodNum);
  1651. $filter = $this->filterCondition([
  1652. 'userName' => 'UI.USER_NAME',
  1653. 'periodNum' => 'CBF.PERIOD_NUM',
  1654. ]);
  1655. $condition = $filter['condition'];
  1656. $params = $filter['params'];
  1657. $listObj = new TraceDownFxList();
  1658. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params, 'others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]);
  1659. return static::notice($data);
  1660. }
  1661. /**
  1662. * 复销奖向下追溯导出
  1663. * @return mixed
  1664. * @throws \yii\db\Exception
  1665. * @throws HttpException
  1666. */
  1667. public function actionTraceDownFxExport() {
  1668. $periodNum = Yii::$app->request->get('periodNum');
  1669. if (!$periodNum) return static::notice([]);
  1670. $period = Period::instance();
  1671. $yearMonth = $period->getYearMonth($periodNum);
  1672. $filter = $this->filterCondition([
  1673. 'userName' => 'UI.USER_NAME',
  1674. 'periodNum' => 'CBF.PERIOD_NUM',
  1675. ]);
  1676. $form = new BonusExportForm();
  1677. $result = $form->run(array_merge($filter, ['others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]), '复销奖向下追溯');
  1678. if (!$result) {
  1679. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1680. }
  1681. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  1682. }
  1683. /**
  1684. * 复销奖向上追溯
  1685. * @return mixed
  1686. * @throws \yii\base\Exception
  1687. * @throws \yii\db\Exception
  1688. * @throws HttpException
  1689. */
  1690. public function actionTraceUpFx() {
  1691. $periodNum = Yii::$app->request->get('periodNum');
  1692. if (!$periodNum) return static::notice([]);
  1693. $period = Period::instance();
  1694. $yearMonth = $period->getYearMonth($periodNum);
  1695. $filter = $this->filterCondition([
  1696. 'userName' => 'UI.USER_NAME',
  1697. 'periodNum' => 'CBF.PERIOD_NUM',
  1698. ]);
  1699. $condition = $filter['condition'];
  1700. $params = $filter['params'];
  1701. $listObj = new TraceUpFxList();
  1702. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params, 'others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]);
  1703. return static::notice($data);
  1704. }
  1705. /**
  1706. * 复销奖向上追溯导出
  1707. * @return mixed
  1708. * @throws \yii\db\Exception
  1709. * @throws HttpException
  1710. */
  1711. public function actionTraceUpFxExport() {
  1712. $periodNum = Yii::$app->request->get('periodNum');
  1713. if (!$periodNum) return static::notice([]);
  1714. $period = Period::instance();
  1715. $yearMonth = $period->getYearMonth($periodNum);
  1716. $filter = $this->filterCondition([
  1717. 'userName' => 'UI.USER_NAME',
  1718. 'periodNum' => 'CBF.PERIOD_NUM',
  1719. ]);
  1720. $form = new BonusExportForm();
  1721. $result = $form->run(array_merge($filter, ['others'=>['yearMonth'=>$yearMonth, 'periodNum'=>$periodNum]]), '复销奖向上追溯');
  1722. if (!$result) {
  1723. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1724. }
  1725. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  1726. }
  1727. /**
  1728. * 核算会员区域津贴
  1729. * @return mixed
  1730. * @throws \yii\db\Exception
  1731. * @throws HttpException
  1732. */
  1733. public function actionCalcQy() {
  1734. $periodNum = Yii::$app->request->get('periodNum');
  1735. $userName = Yii::$app->request->get('userName');
  1736. $period = Period::instance();
  1737. $yearMonth = $period->getYearMonth($periodNum);
  1738. if (!$userId = Info::getUserIdByUserName($userName)) {
  1739. return static::notice('Member does not exist', 400); // 会员不存在
  1740. }
  1741. $data = CalcBonus::findUseSlaves()->yearMonth($yearMonth)->where('PERIOD_NUM=:PERIOD_NUM AND USER_ID=:USER_ID', [':PERIOD_NUM' => $periodNum, ':USER_ID' => $userId])->asArray()->one();
  1742. if ($data) {
  1743. $data['REAL_NAME'] = Info::getUserRealNameByUserId($userId);
  1744. $data['LAST_DEC_LV_NAME'] = Cache::getDecLevelConfig()[$data['LAST_DEC_LV']]['LEVEL_NAME']??'';
  1745. $data['LAST_EMP_LV_NAME'] = Cache::getEmpLevelConfig()[$data['LAST_EMP_LV']]['LEVEL_NAME']??'';
  1746. $data['LAST_STATUS_NAME'] = Tool::paramConvert(Yii::$app->params['userStatus'])[$data['LAST_STATUS']]['label']??'';
  1747. $data['AUDIT_STATUS'] = false;
  1748. if ($resendQy = ResendQYAudit::find()->where('USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM AND (AUDIT_STATUS=:AUDIT_STATUS_UN OR AUDIT_STATUS=:AUDIT_STATUS_TRUE)', [':USER_ID' => $userId, ':PERIOD_NUM' => $periodNum, ':AUDIT_STATUS_UN' => \Yii::$app->params['auditStatus']['un']['value'], ':AUDIT_STATUS_TRUE' => \Yii::$app->params['auditStatus']['true']['value']])->asArray()->one()) {
  1749. $data['AUDIT_STATUS'] = $resendQy['AUDIT_STATUS'];
  1750. }
  1751. }
  1752. return static::notice($data);
  1753. }
  1754. /**
  1755. * 补发区域津贴列表
  1756. * @return mixed
  1757. * @throws \yii\base\Exception
  1758. * @throws HttpException
  1759. */
  1760. public function actionResendQyList() {
  1761. $filter = $this->filterCondition([
  1762. 'userIds' => 'USER_ID',
  1763. 'filterStatus' => 'RESEND_STATUS',
  1764. 'PERIOD_NUM' => 'PERIOD_NUM',
  1765. 'LAST_DEC_LV_NAME' => 'LAST_DEC_LV',
  1766. 'LAST_EMP_LV_NAME' => 'LAST_EMP_LV',
  1767. 'LAST_STATUS_NAME' => 'LAST_STATUS',
  1768. 'LAST_SUB_COM_NAME' => 'LAST_SUB_COM_ID',
  1769. 'LAST_AREA_NAME' => [
  1770. 'FIELD' => ['LAST_PROVINCE', 'LAST_CITY', 'LAST_COUNTY'],
  1771. 'BIND' => ['LAST_PROVINCE', 'LAST_CITY', 'LAST_COUNTY'],
  1772. ],
  1773. 'LAST_SYSTEM_NAME' => 'LAST_SYSTEM_ID',
  1774. 'BONUS_QY' => 'BONUS_QY',
  1775. 'SHOULD_QY' => 'SHOULD_QY',
  1776. 'QY_1L' => 'QY_1L',
  1777. 'SURPLUS_1L' => 'SURPLUS_1L',
  1778. 'QY_2L' => 'QY_2L',
  1779. 'SURPLUS_2L' => 'SURPLUS_2L',
  1780. 'QY_3L' => 'QY_3L',
  1781. 'SURPLUS_3L' => 'SURPLUS_3L',
  1782. 'QY_4L' => 'QY_4L',
  1783. 'SURPLUS_4L' => 'SURPLUS_4L',
  1784. 'QY_5L' => 'QY_5L',
  1785. 'SURPLUS_5L' => 'SURPLUS_5L',
  1786. 'SURPLUS_LS' => 'SURPLUS_LS',
  1787. 'QY_LS' => 'QY_LS',
  1788. ]);
  1789. $condition = $filter['condition'];
  1790. $params = $filter['params'];
  1791. $listObj = new ResendQyList();
  1792. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  1793. return static::notice($data);
  1794. }
  1795. /**
  1796. * 区域津贴补发列表导出
  1797. * @return mixed
  1798. * @throws \yii\db\Exception
  1799. * @throws HttpException
  1800. */
  1801. public function actionResendQyListExport() {
  1802. $filter = $this->filterCondition([
  1803. 'userIds' => 'USER_ID',
  1804. 'filterStatus' => 'RESEND_STATUS',
  1805. 'PERIOD_NUM' => 'PERIOD_NUM',
  1806. 'LAST_DEC_LV_NAME' => 'LAST_DEC_LV',
  1807. 'LAST_EMP_LV_NAME' => 'LAST_EMP_LV',
  1808. 'LAST_STATUS_NAME' => 'LAST_STATUS',
  1809. 'LAST_SUB_COM_NAME' => 'LAST_SUB_COM_ID',
  1810. 'LAST_AREA_NAME' => [
  1811. 'FIELD' => ['LAST_PROVINCE', 'LAST_CITY', 'LAST_COUNTY'],
  1812. 'BIND' => ['LAST_PROVINCE', 'LAST_CITY', 'LAST_COUNTY'],
  1813. ],
  1814. 'LAST_SYSTEM_NAME' => 'LAST_SYSTEM_ID',
  1815. 'BONUS_QY' => 'BONUS_QY',
  1816. 'SHOULD_QY' => 'SHOULD_QY',
  1817. 'QY_1L' => 'QY_1L',
  1818. 'SURPLUS_1L' => 'SURPLUS_1L',
  1819. 'QY_2L' => 'QY_2L',
  1820. 'SURPLUS_2L' => 'SURPLUS_2L',
  1821. 'QY_3L' => 'QY_3L',
  1822. 'SURPLUS_3L' => 'SURPLUS_3L',
  1823. 'QY_4L' => 'QY_4L',
  1824. 'SURPLUS_4L' => 'SURPLUS_4L',
  1825. 'QY_5L' => 'QY_5L',
  1826. 'SURPLUS_5L' => 'SURPLUS_5L',
  1827. 'SURPLUS_LS' => 'SURPLUS_LS',
  1828. 'QY_LS' => 'QY_LS',
  1829. ]);
  1830. $form = new BonusExportForm();
  1831. $result = $form->run($filter, '区域津贴补发列表');
  1832. if (!$result) {
  1833. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1834. }
  1835. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  1836. }
  1837. /**
  1838. * 补发区域津贴
  1839. * @return mixed
  1840. * @throws \yii\db\Exception
  1841. * @throws HttpException
  1842. */
  1843. public function actionResendQy() {
  1844. if (Yii::$app->request->isPost) {
  1845. $formModel = new ResendQYForm();
  1846. $formModel->scenario = 'apply';
  1847. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->apply()) {
  1848. if($result['logs']){
  1849. /*foreach ($result['logs'] as $k => $value) {
  1850. $userName = Info::getUserNameByUserId($value);
  1851. // Log::adminHandle('申请为会员' . $userName . '发放补发区域津贴', 0, $value, $userName);
  1852. }*/
  1853. return static::notice('申请成功,请在补发区域津贴审核管理中审核');
  1854. }else{
  1855. return static::notice('没有符合补发条件的记录',400);
  1856. }
  1857. } else {
  1858. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  1859. }
  1860. }
  1861. return static::notice('Illegal request', 400); // 非法请求
  1862. }
  1863. /**
  1864. * 补发审核表
  1865. * @return mixed
  1866. * @throws \yii\base\Exception
  1867. * @throws HttpException
  1868. */
  1869. public function actionResendQyAuditList() {
  1870. $filter = $this->filterCondition([
  1871. 'userIds' => 'RQYA.USER_ID',
  1872. 'filterStatus' => 'RQYA.AUDIT_STATUS',
  1873. 'SHOULD_BONUS' => 'RQYA.SHOULD_BONUS',
  1874. 'PERIOD_NUM' => 'RQYA.PERIOD_NUM',
  1875. 'CREATED_AT' => 'RQYA.CREATED_AT',
  1876. 'AUDITED_AT' => 'RQYA.AUDITED_AT',
  1877. 'RESEND_REMARK' => 'RQYA.RESEND_REMARK',
  1878. 'CREATE_ADMIN_NAME' => 'ADMC.ADMIN_NAME',
  1879. 'AUDIT_ADMIN_NAME' => 'ADMA.ADMIN_NAME',
  1880. ]);
  1881. $condition = $filter['condition'];
  1882. $params = $filter['params'];
  1883. $listObj = new ResendQyAuditList();
  1884. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  1885. return static::notice($data);
  1886. }
  1887. /**
  1888. * 补发审核表导出
  1889. * @return mixed
  1890. * @throws \yii\db\Exception
  1891. * @throws HttpException
  1892. */
  1893. public function actionResendQyAuditListExport() {
  1894. $filter = $this->filterCondition([
  1895. 'userIds' => 'RQYA.USER_ID',
  1896. 'filterStatus' => 'RQYA.AUDIT_STATUS',
  1897. 'SHOULD_BONUS' => 'RQYA.SHOULD_BONUS',
  1898. 'PERIOD_NUM' => 'RQYA.PERIOD_NUM',
  1899. 'CREATED_AT' => 'RQYA.CREATED_AT',
  1900. 'AUDITED_AT' => 'RQYA.AUDITED_AT',
  1901. 'RESEND_REMARK' => 'RQYA.RESEND_REMARK',
  1902. 'CREATE_ADMIN_NAME' => 'ADMC.ADMIN_NAME',
  1903. 'AUDIT_ADMIN_NAME' => 'ADMA.ADMIN_NAME',
  1904. ]);
  1905. $form = new BonusExportForm();
  1906. $result = $form->run($filter, '补发区域津贴审核列表');
  1907. if (!$result) {
  1908. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1909. }
  1910. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  1911. }
  1912. /**
  1913. * 审核补发区域津贴
  1914. * @return mixed
  1915. * @throws \yii\db\Exception
  1916. * @throws HttpException
  1917. */
  1918. public function actionResendQyAudit() {
  1919. $formModel = new ResendQYForm();
  1920. $formModel->scenario = 'audit';
  1921. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->audit()) {
  1922. /*foreach ($result['logs'] as $k => $value) {
  1923. $userName = Info::getUserNameByUserId($value);
  1924. // Log::adminHandle('审核为会员' . $userName . '补发区域津贴', 1, $value, $userName);
  1925. }*/
  1926. return static::notice('审核补发区域津贴成功');
  1927. }
  1928. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  1929. }
  1930. /**
  1931. * 删除补发区域津贴审核信息
  1932. * @return mixed
  1933. * @throws \yii\db\Exception
  1934. * @throws HttpException
  1935. */
  1936. public function actionResendQyAuditDelete() {
  1937. $resendQYForm = new ResendQYForm();
  1938. $result = static::delete(ResendQYAudit::class, function ($selected) use ($resendQYForm) {
  1939. $resendQYForm->beforeDelete($selected);
  1940. // Log::adminHandle('删除审核会员余额信息');
  1941. }, function ($selected) use ($resendQYForm) {
  1942. $resendQYForm->delete($selected);
  1943. // Log::adminHandle('删除审核会员余额信息');
  1944. }, true);
  1945. return $result;
  1946. }
  1947. /**
  1948. * 余额列表
  1949. * @return mixed
  1950. * @throws \yii\base\Exception
  1951. * @throws HttpException
  1952. */
  1953. public function actionBalanceList() {
  1954. $filter = $this->filterCondition([
  1955. 'USER_NAME' => 'UI.USER_NAME',
  1956. 'REAL_NAME' => 'UI.REAL_NAME',
  1957. 'IS_DEC' => 'UI.IS_DEC',
  1958. ]);
  1959. $condition = $filter['condition'];
  1960. $params = $filter['params'];
  1961. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  1962. if (!$isSuper) {
  1963. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  1964. $adminCountry = AdminCountry::getCountry($adminId);
  1965. $quotedAdminCountry = array_map(function($item) {
  1966. return "'" . addslashes($item) . "'";
  1967. }, $adminCountry);
  1968. $condition .= " AND UI.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
  1969. }
  1970. $listObj = new BalanceList();
  1971. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  1972. return static::notice($data);
  1973. }
  1974. /**
  1975. * 会员奖金余额导出
  1976. * @return mixed
  1977. * @throws \yii\db\Exception
  1978. * @throws HttpException
  1979. */
  1980. public function actionBalanceExport() {
  1981. $filter = $this->filterCondition([
  1982. 'USER_NAME' => 'UI.USER_NAME',
  1983. 'REAL_NAME' => 'UI.REAL_NAME',
  1984. 'IS_DEC' => 'UI.IS_DEC',
  1985. ]);
  1986. $condition = $filter['condition'];
  1987. $params = $filter['params'];
  1988. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  1989. if (!$isSuper) {
  1990. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  1991. $adminCountry = AdminCountry::getCountry($adminId);
  1992. $quotedAdminCountry = array_map(function($item) {
  1993. return "'" . addslashes($item) . "'";
  1994. }, $adminCountry);
  1995. $condition .= " AND UI.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
  1996. }
  1997. $form = new BonusExportForm();
  1998. $result = $form->run(['condition'=>$condition, 'params'=>$params], '会员奖金余额');
  1999. if (!$result) {
  2000. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  2001. }
  2002. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  2003. }
  2004. /**
  2005. * 报单中心店补/补贴追溯
  2006. * @return mixed
  2007. * @throws \yii\base\Exception
  2008. * @throws HttpException
  2009. */
  2010. public function actionTraceBt() {
  2011. $startPeriodNum = Yii::$app->request->get('startPeriodNum');
  2012. $endPeriodNum = Yii::$app->request->get('endPeriodNum');
  2013. if (!$startPeriodNum || !$endPeriodNum) return static::notice([]);
  2014. $filterStatus = Yii::$app->request->get('filterStatus');
  2015. $filter = $this->filterCondition([
  2016. 'userName' => 'UI.USER_NAME',
  2017. ]);
  2018. $condition = $filter['condition'];
  2019. $params = $filter['params'];
  2020. if ($startPeriodNum) {
  2021. $condition .= ' AND CBT.PERIOD_NUM>=:START_PERIOD_NUM';
  2022. $params[':START_PERIOD_NUM'] = $startPeriodNum;
  2023. }
  2024. if ($endPeriodNum) {
  2025. $condition .= ' AND CBT.PERIOD_NUM<=:END_PERIOD_NUM';
  2026. $params[':END_PERIOD_NUM'] = $endPeriodNum;
  2027. }
  2028. if ($filterStatus) {
  2029. $condition .= ' AND CBT.BT_TYPE=:BT_TYPE';
  2030. $params[':BT_TYPE'] = $filterStatus;
  2031. }
  2032. $listObj = new TraceBtList();
  2033. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  2034. return static::notice($data);
  2035. }
  2036. /**
  2037. * 报单中心补贴追溯导出
  2038. * @return mixed
  2039. * @throws \yii\db\Exception
  2040. * @throws HttpException
  2041. */
  2042. public function actionTraceBtExport() {
  2043. $startPeriodNum = Yii::$app->request->get('startPeriodNum');
  2044. $endPeriodNum = Yii::$app->request->get('endPeriodNum');
  2045. if (!$startPeriodNum || !$endPeriodNum) return static::notice([]);
  2046. $filterStatus = Yii::$app->request->get('filterStatus');
  2047. $filter = $this->filterCondition([
  2048. 'userName' => 'UI.USER_NAME',
  2049. ]);
  2050. $condition = $filter['condition'];
  2051. $params = $filter['params'];
  2052. if ($startPeriodNum) {
  2053. $condition .= ' AND CBT.PERIOD_NUM>=:START_PERIOD_NUM';
  2054. $params[':START_PERIOD_NUM'] = $startPeriodNum;
  2055. }
  2056. if ($endPeriodNum) {
  2057. $condition .= ' AND CBT.PERIOD_NUM<=:END_PERIOD_NUM';
  2058. $params[':END_PERIOD_NUM'] = $endPeriodNum;
  2059. }
  2060. if ($filterStatus) {
  2061. $condition .= ' AND CBT.BT_TYPE=:BT_TYPE';
  2062. $params[':BT_TYPE'] = $filterStatus;
  2063. }
  2064. $form = new BonusExportForm();
  2065. $result = $form->run(['condition'=>$condition, 'params'=>$params], '报单中心补贴追溯');
  2066. if (!$result) {
  2067. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  2068. }
  2069. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  2070. }
  2071. /**
  2072. * 报单中心货补追溯
  2073. * @return mixed
  2074. * @throws \yii\base\Exception
  2075. * @throws HttpException
  2076. */
  2077. public function actionTraceFl() {
  2078. $startPeriodNum = Yii::$app->request->get('startPeriodNum');
  2079. $endPeriodNum = Yii::$app->request->get('endPeriodNum');
  2080. if (!$startPeriodNum || !$endPeriodNum) return static::notice([]);
  2081. $filter = $this->filterCondition([
  2082. 'userName' => 'UI.USER_NAME',
  2083. ]);
  2084. $condition = $filter['condition'];
  2085. $params = $filter['params'];
  2086. if ($startPeriodNum) {
  2087. $condition .= ' AND CFL.PERIOD_NUM>=:START_PERIOD_NUM';
  2088. $params[':START_PERIOD_NUM'] = $startPeriodNum;
  2089. }
  2090. if ($endPeriodNum) {
  2091. $condition .= ' AND CFL.PERIOD_NUM<=:END_PERIOD_NUM';
  2092. $params[':END_PERIOD_NUM'] = $endPeriodNum;
  2093. }
  2094. $listObj = new TraceFlList();
  2095. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  2096. return static::notice($data);
  2097. }
  2098. /**
  2099. * 报单中心货补追溯导出
  2100. * @return mixed
  2101. * @throws \yii\db\Exception
  2102. * @throws HttpException
  2103. */
  2104. public function actionTraceFlExport() {
  2105. $startPeriodNum = Yii::$app->request->get('startPeriodNum');
  2106. $endPeriodNum = Yii::$app->request->get('endPeriodNum');
  2107. if (!$startPeriodNum || !$endPeriodNum) return static::notice([]);
  2108. $filter = $this->filterCondition([
  2109. 'userName' => 'UI.USER_NAME',
  2110. ]);
  2111. $condition = $filter['condition'];
  2112. $params = $filter['params'];
  2113. if ($startPeriodNum) {
  2114. $condition .= ' AND CFL.PERIOD_NUM>=:START_PERIOD_NUM';
  2115. $params[':START_PERIOD_NUM'] = $startPeriodNum;
  2116. }
  2117. if ($endPeriodNum) {
  2118. $condition .= ' AND CFL.PERIOD_NUM<=:END_PERIOD_NUM';
  2119. $params[':END_PERIOD_NUM'] = $endPeriodNum;
  2120. }
  2121. $form = new BonusExportForm();
  2122. $result = $form->run(['condition'=>$condition, 'params'=>$params], '报单中心货补追溯');
  2123. if (!$result) {
  2124. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  2125. }
  2126. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  2127. }
  2128. /**
  2129. * 区域业绩提成追溯
  2130. * @return mixed
  2131. * @throws \yii\base\Exception
  2132. * @throws HttpException
  2133. */
  2134. public function actionTraceFw() {
  2135. $startPeriodNum = Yii::$app->request->get('startPeriodNum');
  2136. $endPeriodNum = Yii::$app->request->get('endPeriodNum');
  2137. if (!$startPeriodNum || !$endPeriodNum) return static::notice([]);
  2138. $filter = $this->filterCondition([
  2139. 'userName' => 'UI.USER_NAME',
  2140. ]);
  2141. $condition = $filter['condition'];
  2142. $params = $filter['params'];
  2143. if ($startPeriodNum) {
  2144. $condition .= ' AND CFW.PERIOD_NUM>=:START_PERIOD_NUM';
  2145. $params[':START_PERIOD_NUM'] = $startPeriodNum;
  2146. }
  2147. if ($endPeriodNum) {
  2148. $condition .= ' AND CFW.PERIOD_NUM<=:END_PERIOD_NUM';
  2149. $params[':END_PERIOD_NUM'] = $endPeriodNum;
  2150. }
  2151. $listObj = new TraceFwList();
  2152. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  2153. return static::notice($data);
  2154. }
  2155. /**
  2156. * 区域业绩提成导出
  2157. * @return mixed
  2158. * @throws \yii\db\Exception
  2159. * @throws HttpException
  2160. */
  2161. public function actionTraceFwExport() {
  2162. $startPeriodNum = Yii::$app->request->get('startPeriodNum');
  2163. $endPeriodNum = Yii::$app->request->get('endPeriodNum');
  2164. if (!$startPeriodNum || !$endPeriodNum) return static::notice([]);
  2165. $filter = $this->filterCondition([
  2166. 'userName' => 'UI.USER_NAME',
  2167. ]);
  2168. $condition = $filter['condition'];
  2169. $params = $filter['params'];
  2170. if ($startPeriodNum) {
  2171. $condition .= ' AND CFW.PERIOD_NUM>=:START_PERIOD_NUM';
  2172. $params[':START_PERIOD_NUM'] = $startPeriodNum;
  2173. }
  2174. if ($endPeriodNum) {
  2175. $condition .= ' AND CFW.PERIOD_NUM<=:END_PERIOD_NUM';
  2176. $params[':END_PERIOD_NUM'] = $endPeriodNum;
  2177. }
  2178. $form = new BonusExportForm();
  2179. $result = $form->run(['condition'=>$condition, 'params'=>$params], '区域业绩提成追溯');
  2180. if (!$result) {
  2181. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  2182. }
  2183. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  2184. }
  2185. /**
  2186. * 业绩单
  2187. * @return mixed
  2188. * @throws \yii\base\Exception
  2189. * @throws HttpException
  2190. */
  2191. public function actionPerfOrder(){
  2192. $filter = $this->filterCondition([
  2193. 'PERIOD_NUM' => 'PO.PERIOD_NUM',
  2194. 'SN' => 'PO.SN',
  2195. 'DEC_STATUS_NAME' => 'PO.DEC_STATUS',
  2196. 'USER_NAME' => 'U.USER_NAME',
  2197. 'REAL_NAME' => 'U.REAL_NAME',
  2198. 'userIds' => 'PO.USER_ID',
  2199. 'filterType' => 'PO.DEC_TYPE',
  2200. 'LAST_REC_USER_NAME' => 'PO.LAST_REC_USER_NAME',
  2201. 'LAST_REC_REAL_NAME' => 'PO.LAST_REC_REAL_NAME',
  2202. 'PV' => 'PO.PV',
  2203. 'DEC_AMOUNT' => 'PO.DEC_AMOUNT',
  2204. 'DEC_SN' => 'PO.DEC_SN',
  2205. 'CREATED_AT' => 'PO.CREATED_AT',
  2206. ]);
  2207. $condition = $filter['condition'];
  2208. $params = $filter['params'];
  2209. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  2210. if (!$isSuper) {
  2211. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  2212. $adminCountry = AdminCountry::getCountry($adminId);
  2213. $quotedAdminCountry = array_map(function($item) {
  2214. return "'" . addslashes($item) . "'";
  2215. }, $adminCountry);
  2216. $condition .= " AND U.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
  2217. }
  2218. $listObj = new PerfOrderList();
  2219. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  2220. return static::notice($data);
  2221. }
  2222. /**
  2223. * 业绩单导出
  2224. * @return mixed
  2225. * @throws \yii\db\Exception
  2226. * @throws HttpException
  2227. */
  2228. public function actionPerfOrderExport() {
  2229. $filter = $this->filterCondition([
  2230. 'PERIOD_NUM' => 'PO.PERIOD_NUM',
  2231. 'SN' => 'PO.SN',
  2232. 'DEC_STATUS_NAME' => 'PO.DEC_STATUS',
  2233. 'userIds' => 'PO.USER_ID',
  2234. 'filterType' => 'PO.DEC_TYPE',
  2235. 'LAST_REC_USER_NAME' => 'PO.LAST_REC_USER_NAME',
  2236. 'LAST_REC_REAL_NAME' => 'PO.LAST_REC_REAL_NAME',
  2237. 'PV' => 'PO.PV',
  2238. 'DEC_AMOUNT' => 'PO.DEC_AMOUNT',
  2239. 'DEC_SN' => 'PO.DEC_SN',
  2240. 'LAST_SUB_COM_NAME' => 'PO.LAST_SUB_COM_ID',
  2241. 'LAST_SYSTEM_NAME' => 'PO.LAST_SYSTEM_ID',
  2242. 'LAST_AREA' => [
  2243. 'FIELD' => ['PO.LAST_PROVINCE', 'PO.LAST_CITY', 'PO.LAST_COUNTY'],
  2244. 'BIND' => ['LAST_PROVINCE', 'LAST_CITY', 'LAST_COUNTY'],
  2245. ],
  2246. 'DEC_USER_NAME' => 'DUI.USER_NAME',
  2247. 'LAST_DEC_DEC_LV_NAME' => 'PO.LAST_DEC_DEC_LV',
  2248. 'LAST_DEC_SUB_COM_NAME' => 'PO.LAST_DEC_SUB_COM_ID',
  2249. 'LAST_DEC_AREA' => [
  2250. 'FIELD' => ['PO.LAST_DEC_PROVINCE', 'PO.LAST_DEC_CITY', 'PO.LAST_DEC_COUNTY'],
  2251. 'BIND' => ['LAST_DEC_PROVINCE', 'LAST_DEC_CITY', 'LAST_DEC_COUNTY'],
  2252. ],
  2253. 'CREATED_AT' => 'PO.CREATED_AT',
  2254. 'CLOSED_AT' => 'PO.CLOSED_AT',
  2255. ]);
  2256. $condition = $filter['condition'];
  2257. $params = $filter['params'];
  2258. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  2259. if (!$isSuper) {
  2260. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  2261. $adminCountry = AdminCountry::getCountry($adminId);
  2262. $quotedAdminCountry = array_map(function($item) {
  2263. return "'" . addslashes($item) . "'";
  2264. }, $adminCountry);
  2265. $condition .= " AND U.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
  2266. }
  2267. $form = new BonusExportForm();
  2268. $result = $form->run(['condition'=>$condition, 'params'=>$params], '业绩单');
  2269. if (!$result) {
  2270. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  2271. }
  2272. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  2273. }
  2274. /**
  2275. * 月积分
  2276. * @return mixed
  2277. * @throws \yii\base\Exception
  2278. * @throws HttpException
  2279. */
  2280. public function actionScoreMonth(){
  2281. $filter = $this->filterCondition([
  2282. 'USER_NAME' => 'U.USER_NAME',
  2283. 'userIds' => 'SM.USER_ID',
  2284. 'CALC_MONTH' => 'SM.CALC_MONTH',
  2285. 'CREATED_AT' => 'SM.CREATED_AT',
  2286. ]);
  2287. $condition = $filter['condition'];
  2288. $params = $filter['params'];
  2289. $listObj = new ScoreMonthList();
  2290. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  2291. return static::notice($data);
  2292. }
  2293. /**
  2294. * 月积分导出
  2295. * @return mixed
  2296. * @throws \yii\db\Exception
  2297. * @throws HttpException
  2298. */
  2299. public function actionScoreMonthExport() {
  2300. $filter = $this->filterCondition([
  2301. 'USER_NAME' => 'U.USER_NAME',
  2302. 'userIds' => 'SM.USER_ID',
  2303. 'CALC_MONTH' => 'SM.CALC_MONTH',
  2304. 'CREATED_AT' => 'SM.CREATED_AT',
  2305. ]);
  2306. $condition = $filter['condition'];
  2307. $params = $filter['params'];
  2308. $form = new BonusExportForm();
  2309. $result = $form->run(['condition'=>$condition, 'params'=>$params], '月积分');
  2310. if (!$result) {
  2311. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  2312. }
  2313. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  2314. }
  2315. /**
  2316. * 月业绩
  2317. * @return mixed
  2318. * @throws \yii\base\Exception
  2319. * @throws HttpException
  2320. */
  2321. public function actionPerfMonth(){
  2322. $filter = $this->filterCondition([
  2323. 'USER_NAME' => 'U.USER_NAME',
  2324. 'REC_USER_NAME' => 'RU.USER_NAME',
  2325. 'userIds' => 'PM.USER_ID',
  2326. 'CALC_MONTH' => 'PM.CALC_MONTH',
  2327. 'CREATED_AT' => 'PM.CREATED_AT',
  2328. ]);
  2329. $condition = $filter['condition'];
  2330. $params = $filter['params'];
  2331. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  2332. if (!$isSuper) {
  2333. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  2334. $adminCountry = AdminCountry::getCountry($adminId);
  2335. $quotedAdminCountry = array_map(function($item) {
  2336. return "'" . addslashes($item) . "'";
  2337. }, $adminCountry);
  2338. $condition .= " AND U.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
  2339. }
  2340. $listObj = new PerfMonthList();
  2341. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  2342. return static::notice($data);
  2343. }
  2344. /**
  2345. * 月业绩导出
  2346. * @return mixed
  2347. * @throws \yii\db\Exception
  2348. * @throws HttpException
  2349. */
  2350. public function actionPerfMonthExport() {
  2351. $filter = $this->filterCondition([
  2352. 'USER_NAME' => 'U.USER_NAME',
  2353. 'REC_USER_NAME' => 'RU.USER_NAME',
  2354. 'userIds' => 'PM.USER_ID',
  2355. 'CALC_MONTH' => 'PM.CALC_MONTH',
  2356. 'CREATED_AT' => 'PM.CREATED_AT',
  2357. ]);
  2358. $condition = $filter['condition'];
  2359. $params = $filter['params'];
  2360. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  2361. if (!$isSuper) {
  2362. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  2363. $adminCountry = AdminCountry::getCountry($adminId);
  2364. $quotedAdminCountry = array_map(function($item) {
  2365. return "'" . addslashes($item) . "'";
  2366. }, $adminCountry);
  2367. $condition .= " AND U.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
  2368. }
  2369. $form = new BonusExportForm();
  2370. $result = $form->run(['condition'=>$condition, 'params'=>$params], '月业绩');
  2371. if (!$result) {
  2372. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  2373. }
  2374. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  2375. }
  2376. /**
  2377. * 期业绩
  2378. * @return mixed
  2379. * @throws \yii\base\Exception
  2380. * @throws HttpException
  2381. */
  2382. public function actionPerfPeriodList(){
  2383. $filter = $this->filterCondition([
  2384. 'USER_NAME' => 'U.USER_NAME',
  2385. 'userIds' => 'PP.USER_ID',
  2386. 'PERIOD_NUM' => 'PP.PERIOD_NUM',
  2387. 'CREATED_AT' => 'PP.CREATED_AT',
  2388. ]);
  2389. $condition = $filter['condition'];
  2390. $params = $filter['params'];
  2391. $listObj = new PerfPeriodList();
  2392. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  2393. return static::notice($data);
  2394. }
  2395. /**
  2396. * 期业绩导出
  2397. * @return mixed
  2398. * @throws \yii\db\Exception
  2399. * @throws HttpException
  2400. */
  2401. public function actionPerfPeriodListExport() {
  2402. $filter = $this->filterCondition([
  2403. 'USER_NAME' => 'U.USER_NAME',
  2404. 'userIds' => 'PP.USER_ID',
  2405. 'PERIOD_NUM' => 'PP.PERIOD_NUM',
  2406. 'CREATED_AT' => 'PP.CREATED_AT',
  2407. ]);
  2408. $condition = $filter['condition'];
  2409. $params = $filter['params'];
  2410. $form = new BonusExportForm();
  2411. $result = $form->run(['condition'=>$condition, 'params'=>$params], '期业绩');
  2412. if (!$result) {
  2413. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  2414. }
  2415. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  2416. }
  2417. /**
  2418. * 达标业绩
  2419. * @return mixed
  2420. * @throws \yii\base\Exception
  2421. * @throws HttpException
  2422. */
  2423. public function actionPerfStandard(){
  2424. $filter = $this->filterCondition([
  2425. 'USER_NAME' => 'U.USER_NAME',
  2426. 'REC_USER_NAME' => 'RU.USER_NAME',
  2427. 'userIds' => 'PS.USER_ID',
  2428. 'CALC_MONTH' => 'PS.CALC_MONTH',
  2429. 'CREATED_AT' => 'PS.CREATED_AT',
  2430. ]);
  2431. $condition = $filter['condition'];
  2432. $params = $filter['params'];
  2433. $listObj = new PerfStandardList();
  2434. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  2435. return static::notice($data);
  2436. }
  2437. /**
  2438. * 达标业绩导出
  2439. * @return mixed
  2440. * @throws \yii\db\Exception
  2441. * @throws HttpException
  2442. */
  2443. public function actionPerfStandardExport() {
  2444. $filter = $this->filterCondition([
  2445. 'USER_NAME' => 'U.USER_NAME',
  2446. 'REC_USER_NAME' => 'RU.USER_NAME',
  2447. 'userIds' => 'PS.USER_ID',
  2448. 'CALC_MONTH' => 'PS.CALC_MONTH',
  2449. 'CREATED_AT' => 'PS.CREATED_AT',
  2450. ]);
  2451. $condition = $filter['condition'];
  2452. $params = $filter['params'];
  2453. $form = new BonusExportForm();
  2454. $result = $form->run(['condition'=>$condition, 'params'=>$params], '达标业绩');
  2455. if (!$result) {
  2456. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  2457. }
  2458. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  2459. }
  2460. /**
  2461. * 会员实时业绩
  2462. * @return mixed
  2463. * @throws HttpException
  2464. */
  2465. public function actionRealTimePerf() {
  2466. $userName = Yii::$app->request->get('userName');
  2467. if (!$userId = Info::getUserIdByUserName($userName)) {
  2468. return static::notice('Member does not exist', 400); // 会员不存在
  2469. }
  2470. $period = Period::instance();
  2471. $newPerf = Perf::getPeriodNewPerf($userId);
  2472. $weekData = [['PV_1L' => $newPerf['PV_1L'], 'PV_2L' => $newPerf['PV_2L'], 'PV_3L' => $newPerf['PV_3L'], 'PV_4L' => $newPerf['PV_4L'], 'PV_5L' => $newPerf['PV_5L'], 'PV_PCS'=>Tool::formatPrice($newPerf['PV_PCS']), 'PV_PSS'=>Tool::formatPrice($newPerf['PV_PSS'])]];
  2473. $monthPerf = Perf::getMonthPerf($userId);
  2474. $monthData = [['PV_1L' => Tool::formatPrice($monthPerf['PV_1L']), 'PV_2L' => Tool::formatPrice($monthPerf['PV_2L']), 'PV_3L' => Tool::formatPrice($monthPerf['PV_3L']), 'PV_4L' => Tool::formatPrice($monthPerf['PV_4L']), 'PV_5L' => Tool::formatPrice($monthPerf['PV_5L']), 'PV_PCS'=>Tool::formatPrice($monthPerf['PV_PCS']), 'PV_PSS'=>Tool::formatPrice($monthPerf['PV_PSS'])]];
  2475. $lastMonth = PerfMonth::getMonthPerf($period->getLastMonth()['yearMonth'], $userId);
  2476. $lastData = [['PV_1L' => Tool::formatPrice($lastMonth['PV_1L_TOTAL']), 'PV_2L' => Tool::formatPrice($lastMonth['PV_2L_TOTAL']), 'PV_3L' => Tool::formatPrice($lastMonth['PV_3L_TOTAL']), 'PV_4L' => Tool::formatPrice($lastMonth['PV_4L_TOTAL']), 'PV_5L' => Tool::formatPrice($lastMonth['PV_5L_TOTAL']), 'PV_PCS'=>Tool::formatPrice($lastMonth['PV_PCS']), 'PV_PSS'=>Tool::formatPrice($lastMonth['PV_PSS']), 'PV_PSS_TOTAL'=>Tool::formatPrice($lastMonth['PV_PSS_TOTAL'])]];
  2477. //是否合格
  2478. // $lastChkStatus = '';
  2479. // $lastMonthPerfChk = Cache::getSystemConfig()['lastMonthPerfChk']['VALUE'];
  2480. // $lastArr = [$lastMonth['PV_1L_TOTAL'], $lastMonth['PV_2L_TOTAL'], $lastMonth['PV_3L_TOTAL'], $lastMonth['PV_4L_TOTAL'], $lastMonth['PV_5L_TOTAL']];
  2481. // if (array_sum($lastArr) >= $lastMonthPerfChk) {
  2482. // $lastChkStatus = '已合格';
  2483. // }
  2484. //判断大区
  2485. // $bigLocation = array_search(max($lastArr), $lastArr) + 1;
  2486. return static::notice(['weekData' => $weekData, 'monthData' => $monthData, 'lastData' => $lastData]);
  2487. }
  2488. /**
  2489. * 荣衔业绩
  2490. * @return mixed
  2491. * @throws HttpException
  2492. */
  2493. public function actionYcPerf() {
  2494. $userName = Yii::$app->request->get('userName');
  2495. if (!$userId = Info::getUserIdByUserName($userName)) {
  2496. return static::notice('Member does not exist', 400); // 会员不存在
  2497. }
  2498. $userPerfData = Perf::getUserPerf($userId);
  2499. $ycPerfList = [];
  2500. //查找推荐的子会员
  2501. $childrenList = UserInfo::findUseDbCalc()->select('USER_ID')->where('REC_UID=:REC_UID', [
  2502. 'REC_UID' => $userId
  2503. ])->asArray()->all();
  2504. $maxPvPss = 0;
  2505. $childSumPerf = 0;
  2506. foreach ($childrenList as $child) {
  2507. $childBaseUser = Info::getBaseUserById($child['USER_ID']);
  2508. if( !$childBaseUser ) continue;
  2509. $childPerfData = Perf::getUserPerf($child['USER_ID']);
  2510. if( !$childPerfData ) continue;
  2511. $childPvPcs = $childPerfData['PV_PCS_ZC'] + $childPerfData['PV_PCS_FX'];
  2512. $childPvPssTotal = $childPvPcs + $childPerfData['PV_PSS'];
  2513. $childSumPerf += $childPvPssTotal;
  2514. if( $childPvPssTotal >= $maxPvPss ) {
  2515. $maxPvPss = $childPvPssTotal;
  2516. }
  2517. $ycPerfList[] = [
  2518. 'USER_NAME'=>$childBaseUser['USER_NAME'],
  2519. 'REAL_NAME'=>$childBaseUser['REAL_NAME'],
  2520. 'PV_PCS' => $childPerfData['PV_PCS_ZC'] + $childPerfData['PV_PCS_FX'],
  2521. 'PV_PSS_TOTAL' => $childPerfData['PV_PSS_TOTAL'],
  2522. 'MAX_DEPART_PERF' => '-',
  2523. 'OTHER_DEPART_PERF' => '-',
  2524. 'PV_PSS_SUM_TOTAL' => round($childPerfData['PV_PCS_ZC'] + $childPerfData['PV_PCS_FX'] + $childPerfData['PV_PSS_TOTAL'],2),
  2525. ];
  2526. }
  2527. if( $userPerfData ) {
  2528. $baseUser = Info::getBaseUserById($userId);
  2529. $ycPerfData = [
  2530. 'USER_NAME'=>$baseUser['USER_NAME'],
  2531. 'REAL_NAME'=>$baseUser['REAL_NAME'],
  2532. 'PV_PCS' => $userPerfData['PV_PCS_ZC'] + $userPerfData['PV_PCS_FX'],
  2533. 'PV_PSS_TOTAL' => $userPerfData['PV_PSS_TOTAL'],
  2534. 'MAX_DEPART_PERF' => round($maxPvPss, 2),
  2535. 'OTHER_DEPART_PERF' => round($childSumPerf-$maxPvPss, 2),
  2536. 'PV_PSS_SUM_TOTAL' => round($userPerfData['PV_PCS_ZC'] + $userPerfData['PV_PCS_FX'] + $userPerfData['PV_PSS_TOTAL'],2),
  2537. ];
  2538. array_unshift($ycPerfList, $ycPerfData);
  2539. }
  2540. return static::notice(['ycPerfList' => $ycPerfList]);
  2541. }
  2542. /**
  2543. * 用户业绩
  2544. * @return mixed
  2545. * @throws HttpException
  2546. */
  2547. public function actionUserPerf() {
  2548. $filter = $this->filterCondition([
  2549. 'USER_NAME' => 'U.USER_NAME',
  2550. ]);
  2551. $condition = $filter['condition'];
  2552. $params = $filter['params'];
  2553. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  2554. if (!$isSuper) {
  2555. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  2556. $adminCountry = AdminCountry::getCountry($adminId);
  2557. $quotedAdminCountry = array_map(function($item) {
  2558. return "'" . addslashes($item) . "'";
  2559. }, $adminCountry);
  2560. $condition .= " AND U.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
  2561. }
  2562. $listObj = new UserPerfList();
  2563. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  2564. return static::notice($data);
  2565. }
  2566. /**
  2567. * 月业绩导出
  2568. * @return mixed
  2569. * @throws \yii\db\Exception
  2570. * @throws HttpException
  2571. */
  2572. public function actionUserPerfExport() {
  2573. $filter = $this->filterCondition([
  2574. 'USER_NAME' => 'U.USER_NAME',
  2575. ]);
  2576. $condition = $filter['condition'];
  2577. $params = $filter['params'];
  2578. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  2579. if (!$isSuper) {
  2580. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  2581. $adminCountry = AdminCountry::getCountry($adminId);
  2582. $quotedAdminCountry = array_map(function($item) {
  2583. return "'" . addslashes($item) . "'";
  2584. }, $adminCountry);
  2585. $condition .= " AND U.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
  2586. }
  2587. $form = new BonusExportForm();
  2588. $result = $form->run(['condition'=>$condition, 'params'=>$params], '用户业绩');
  2589. if (!$result) {
  2590. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  2591. }
  2592. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  2593. }
  2594. /**
  2595. * 自动提现(奖金)
  2596. *
  2597. */
  2598. public function actionAutoWithdraw() {
  2599. $withdrawLock = Cache::getWithdrawLock();
  2600. if ($withdrawLock!=0){
  2601. return static::notice(Form::formatErrorsForApi('已有进程在生成'), 400);
  2602. }else{
  2603. $formModel = new UserBonusForm();
  2604. $formModel->scenario = 'autoWithdraw';
  2605. if ($formModel->autoWithdrawWebToAsync()) {
  2606. return static::notice('生成提现单 已开始处理,请等待');
  2607. } else {
  2608. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  2609. }
  2610. }
  2611. }
  2612. /**
  2613. * 查询安置网下级会员和业绩、修改业绩
  2614. * @return mixed|void
  2615. * @throws HttpException
  2616. * @throws \yii\base\Exception
  2617. */
  2618. public function actionPerfAdjustment()
  2619. {
  2620. // 查询业绩
  2621. if (\Yii::$app->request->isGet) {
  2622. $memberCode = Yii::$app->request->get('memberCode');
  2623. $userId = Info::getUserIdByUserName(trim($memberCode));
  2624. // 查询传入会员业绩
  2625. $perfMarket = UserPerf::getPerfMarket($userId);
  2626. if ($perfMarket) {
  2627. // 查询传入会员的安置网下级
  2628. $memberList = UserNetwork::getFirstFloorChildren($userId);
  2629. $memberList = array_column($memberList, NULL, 'RELATIVE_LOCATION');
  2630. // 左腿1市场
  2631. $leftPerfUserName = (isset($memberList[1]) && $memberList[1]['USER_ID']) ? Info::getUserNameByUserId($memberList[1]['USER_ID']) : '';
  2632. // 右腿2市场
  2633. $rightPerfUserName = (isset($memberList[2]) && $memberList[2]['USER_ID']) ? Info::getUserNameByUserId($memberList[2]['USER_ID']) : '';
  2634. // 会员编号
  2635. $perfMarket['USER_NAME'] = $memberCode;
  2636. $perfMarket['SURPLUS_1L_USER_NAME'] = $leftPerfUserName;
  2637. $perfMarket['SURPLUS_2L_USER_NAME'] = $rightPerfUserName;
  2638. return static::notice(['allData' => $perfMarket]);
  2639. }
  2640. return static::notice('No data', 400);
  2641. } else if (\Yii::$app->request->isPost) {
  2642. $formModel = new PerfAdjustmentForm();
  2643. $formModel->scenario = 'perfAdjustment';
  2644. $post = \Yii::$app->request->post();
  2645. if ($formModel->load($post, '') && $formModel->perfAdjustment()) {
  2646. return static::notice('Successful');
  2647. } else {
  2648. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  2649. }
  2650. } else {
  2651. return static::notice('Illegal request', 400); // 非法请求
  2652. }
  2653. }
  2654. }