BonusController.php 107 KB

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