BonusController.php 103 KB

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