BonusController.php 103 KB

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