BonusController.php 103 KB

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