BonusController.php 107 KB

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