BonusController.php 108 KB

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