BonusController.php 107 KB

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