BonusController.php 104 KB

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