BonusController.php 103 KB

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