BonusController.php 104 KB

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