BonusController.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: leo
  5. * Date: 2018/2/24
  6. * Time: 下午12:48
  7. */
  8. namespace frontendApi\modules\v1\controllers;
  9. use common\helpers\Cache;
  10. use common\helpers\Date;
  11. use common\helpers\Form;
  12. use common\helpers\LoggerTool;
  13. use common\helpers\Tool;
  14. use common\helpers\user\Balance;
  15. use common\helpers\user\Info;
  16. use common\helpers\user\Perf;
  17. use common\models\CalcBonus;
  18. use common\models\CalcBonusBSDefault;
  19. use common\models\CalcBonusBT;
  20. use common\models\CalcBonusFL;
  21. use common\models\Countries;
  22. use common\models\Currency;
  23. use common\models\DealType;
  24. use common\models\DeclarationLevel;
  25. use common\models\EliteLevel;
  26. use common\models\FlowBonus;
  27. use common\models\FlowCF;
  28. use common\models\FlowGaragePoints;
  29. use common\models\FlowLX;
  30. use common\models\FlowReconsumePoints;
  31. use common\models\FlowTourismPoints;
  32. use common\models\FlowVillaPoints;
  33. use common\models\FlowWallet;
  34. use common\models\forms\TransferForm;
  35. use common\models\forms\UploadForm;
  36. use common\models\forms\WithdrawForm;
  37. use common\models\InvoiceAudit;
  38. use common\models\PerfMonth;
  39. use common\models\PerfPeriod;
  40. use common\models\Period;
  41. use common\models\DecRole;
  42. use common\models\EmployLevel;
  43. use common\models\FlowExchangePoints;
  44. use common\models\RegType;
  45. use common\models\ScoreMonth;
  46. use common\models\Transfer;
  47. use common\models\Uploads;
  48. use common\models\UserBonus;
  49. use common\models\UserInfo;
  50. use common\models\UserPerformance;
  51. use common\models\UserWallet;
  52. use common\models\UserRelation;
  53. use common\models\Withdraw;
  54. use frontendApi\modules\v1\models\User;
  55. use Yii;
  56. use yii\web\HttpException;
  57. use yii\web\UploadedFile;
  58. class BonusController extends BaseController {
  59. public $modelClass = CalcBonus::class;
  60. /**
  61. * 我的账户
  62. * @return mixed
  63. * @throws \yii\web\HttpException
  64. */
  65. public function actionIndex() {
  66. $userId = \Yii::$app->user->id;
  67. $data = UserBonus::findUseSlaves()->select('BONUS')->where('USER_ID=:USER_ID', [':USER_ID' => $userId])->asArray()->one();
  68. if (!$data) {
  69. $data = [
  70. 'BONUS' => 0,
  71. ];
  72. }
  73. $data['CASH'] = 0;
  74. $cashWallet = UserWallet::findOneAsArray('USER_ID=:USER_ID', [':USER_ID'=>$userId], 'CASH');
  75. if($cashWallet){
  76. $data['CASH'] = $cashWallet['CASH'];
  77. }
  78. $user = User::getEnCodeInfo($userId);
  79. // 账户币种
  80. $country = Countries::getById($user['COUNTRY_ID']);
  81. $currency = Currency::getById($country['LOCAL_CURRENCY_ID']);
  82. // 绩效奖金
  83. $userPerformance = UserPerformance::getAmountByUserId($userId);
  84. $data['userPerformanceBonus'] = $userPerformance['AMOUNTS'] ?? 0;
  85. $wallet[] = ['walletType' => 'bonus', 'walletName' => Yii::t('app', 'memberBonus'), 'amount' => Tool::formatPrice($data['BONUS'])];//会员奖金
  86. $wallet[] = ['walletType' => 'cash', 'walletName' => Yii::t('app', 'memberEcoin'), 'amount' => Tool::formatPrice($data['CASH']), 'coin' => $currency['CODE']];//会员余额
  87. $wallet[] = ['walletType' => 'userPerformanceBonus', 'walletName' => Yii::t('app', 'userPerformanceBonus'), 'amount' => Tool::formatPrice($data['userPerformanceBonus']), 'coin' => $currency['CODE']];//绩效奖金
  88. $dealSwitch = isset(Cache::getSystemConfig()['dealSwitch']) ? Cache::getSystemConfig()['dealSwitch']['VALUE'] : '';
  89. return static::notice(['wallet' => $wallet,'dealSwitch'=>$dealSwitch]);
  90. }
  91. /**
  92. * 团队查询
  93. * @return mixed
  94. * @throws \yii\web\HttpException
  95. */
  96. public function actionTeams() {
  97. $userId = \Yii::$app->user->id;
  98. $period = Period::instance();
  99. // 查询最新一期未挂网期数
  100. $periodNum = $period->getTeamsPeriodNum();
  101. $month = $period->getTeamsYearMonth($periodNum);
  102. $periodData = Period::getInfoByPeriodNum($periodNum);
  103. // 判断此业绩期是否已经计算完成
  104. if ($periodData['IS_PREPARE'] != 4) {
  105. return static::notice(['user' => [],'team'=>[]]);
  106. }
  107. $userInfo = User::getEnCodeInfo($userId);
  108. $data = PerfMonth::fetchMonthPerf($month, $userId);
  109. $user[0] = [
  110. 'number' => $userInfo['USER_NAME'],
  111. 'name' => $userInfo['REAL_NAME'],
  112. 'user_perf' => 0, // 个人业绩
  113. 'team_perf' => 0, // 团队新增累计业绩
  114. 'total_perf' => 0, // 合计业绩
  115. 'perf_status' => '0', // 0 未达标 1为已达标
  116. 'perf_status_name' => 'Fail',
  117. ];
  118. if (!empty($data)) {
  119. $userCheck = PerfMonth::checkStatus($data['PV_PCS'] + $data['PV_PSS']);
  120. $user[0]['user_perf'] = $data['PV_PCS'];
  121. $user[0]['team_perf'] = $data['PV_PSS'];
  122. $user[0]['total_perf'] = $data['PV_PCS']+$data['PV_PSS'];
  123. $user[0]['perf_status'] = $userCheck ? '1' : $user[0]['perf_status'];
  124. $user[0]['perf_status_name'] = $userCheck ? 'Pass' : $user[0]['perf_status_name'];
  125. }
  126. $teamInfo = [];
  127. $calcAt = PerfMonth::find()->select(['CREATED_AT'])->where('CALC_MONTH=:CALC_MONTH', ['CALC_MONTH'=>$month])->asArray()->one();
  128. if(!$calcAt){
  129. $periodStartTime = $period->nowPeriodArr['START_TIME'];
  130. return static::notice(['user' => $user,'team'=>[],'calcAt' => $periodStartTime]);
  131. }
  132. // 查询此用户的推荐(开拓)团队一级信息
  133. $relation = UserRelation::getChildrenWithDeepAndLayer($userId, 1, 1, $periodNum);
  134. $userStatusFlag = false;
  135. if ($relation) {
  136. // 循环一级开拓用户
  137. foreach($relation as $k=>$v) {
  138. // 获取此用户预计算月业绩
  139. $relationPerf = PerfMonth::fetchMonthPerf($month, $v['USER_ID']);
  140. if (empty($relationPerf)) {
  141. $relationPerf['PV_PCS'] = 0;
  142. $relationPerf['PV_PSS'] = 0;
  143. }
  144. $relationCheck = PerfMonth::checkStatus($relationPerf['PV_PCS']+$relationPerf['PV_PSS']);
  145. $teamInfo[]['perf_status'] = $relationCheck ? '1' : '0';
  146. if ($relationCheck) {
  147. $userStatusFlag = true; // 只要有一个达标,则个人就达标
  148. $teamInfo[$k]['number'] = $v['USER_NAME'];
  149. $teamInfo[$k]['name'] = $v['REAL_NAME'];
  150. $teamInfo[$k]['user_perf'] = $relationPerf['PV_PCS'];
  151. $teamInfo[$k]['team_perf'] = $relationPerf['PV_PSS'];
  152. $teamInfo[$k]['total_perf'] = $relationPerf['PV_PCS']+$relationPerf['PV_PSS'];
  153. $teamInfo[$k]['perf_status'] = '1';
  154. $teamInfo[$k]['perf_status_name'] = 'Pass';
  155. } else {
  156. $teamInfo[$k]['number'] = $v['USER_NAME'];
  157. $teamInfo[$k]['name'] = $v['REAL_NAME'];
  158. $teamInfo[$k]['user_perf'] = $relationPerf['PV_PCS'];
  159. $teamInfo[$k]['team_perf'] = $relationPerf['PV_PSS'];
  160. $teamInfo[$k]['total_perf'] = $relationPerf['PV_PCS']+$relationPerf['PV_PSS'];
  161. $teamInfo[$k]['perf_status'] = '0';
  162. $teamInfo[$k]['perf_status_name'] = 'Fail';
  163. }
  164. }
  165. }
  166. if ($userStatusFlag === true) {
  167. $user[0]['perf_status'] = '1';
  168. $user[0]['perf_status_name'] = 'Pass';
  169. }
  170. return static::notice(['user' => $user,'team'=>$teamInfo,'calcAt' => $calcAt['CREATED_AT']]);
  171. }
  172. /**
  173. * 交易记录
  174. * @return mixed
  175. * @throws \yii\web\HttpException
  176. */
  177. public function actionWalletFlow(){
  178. $walletType = \Yii::$app->request->get('walletType');
  179. if(!in_array($walletType,['bonus', 'cash', 'userPerformanceBonus'])) {
  180. return static::notice('walletType error',400);
  181. }
  182. $dealType = \Yii::$app->request->get('dealType');
  183. $createAt = \Yii::$app->request->get('createAt');
  184. $remark = \Yii::$app->request->get('remark');
  185. // 获取可以查看几期流水
  186. $showFlowPeriodNum = Cache::getSystemConfig()['showFlowPeriodNum']['VALUE'];
  187. $periodArr = Period::getNearlyPeriodNum($showFlowPeriodNum);
  188. $condition = ' AND USER_ID=:USER_ID AND PERIOD_NUM>=:PERIOD_NUM_MIN AND PERIOD_NUM<=:PERIOD_NUM_MAX';
  189. $params = [':USER_ID' => \Yii::$app->user->id,':PERIOD_NUM_MIN' => min($periodArr), ':PERIOD_NUM_MAX'=> max($periodArr)];
  190. if($dealType){
  191. if($dealType==1){//增加
  192. $condition.=' AND IS_INCR=1 AND DEAL_TYPE_IS_PRESET=0';
  193. }elseif ($dealType==2){//扣除
  194. $condition.=' AND IS_INCR=0 AND DEAL_TYPE_IS_PRESET=0';
  195. }else if ($walletType != 'cash') {
  196. $condition.=' AND DEAL_TYPE_ID=:DEAL_TYPE';
  197. $params[':DEAL_TYPE'] = $dealType;
  198. }
  199. }
  200. if ($createAt) {
  201. $createAtStart = $createAt[0] ?? '';
  202. $createAtEnd = $createAt[1] ?? '';
  203. if ($createAtStart) {
  204. $condition .= " AND CREATED_AT>:CREATED_START";
  205. $params[':CREATED_START'] = Date::utcToTime($createAtStart);
  206. }
  207. if ($createAtEnd) {
  208. $condition .= " AND CREATED_AT<:CREATED_END";
  209. $params[':CREATED_END'] = Date::utcToTime($createAtEnd)+86399;
  210. }
  211. }
  212. if($remark){
  213. $condition .= " AND REMARK LIKE :REMARK";
  214. $params[':REMARK'] = '%'.$remark.'%';
  215. }
  216. $data = [];
  217. $dealLists=[];
  218. $dealTypes=[];
  219. if($walletType == 'bonus') {
  220. $dealLists = FlowBonus::find()->groupBy('DEAL_TYPE_ID')->select('DEAL_TYPE_ID')->where('USER_ID=:USER_ID',[':USER_ID'=>\Yii::$app->user->id])->asArray()->all();
  221. $data = FlowBonus::lists($condition, $params, [
  222. 'useSlaves' => true,
  223. 'select' => 'AMOUNT,TOTAL,IS_INCR,REMARK,REMARK_IS_SHOW,PERIOD_NUM,CALC_MONTH,CREATED_AT,DEAL_TYPE_ID,DEAL_TYPE_IS_PRESET',
  224. 'orderBy' => 'CREATED_AT DESC,SORT DESC',
  225. ]);
  226. }elseif ($walletType == 'cash'){
  227. $data = FlowWallet::lists($condition, $params, [
  228. 'select' => 'AMOUNT,TOTAL,IS_INCR,REMARK,PERIOD_NUM,CALC_MONTH,CREATED_AT',
  229. 'orderBy' => 'CREATED_AT DESC',
  230. ]);
  231. }else if ($walletType == 'userPerformanceBonus') {
  232. $condition = ' AND USER_ID=:USER_ID AND STATUS_ID<20 AND AMOUNTS>0';
  233. $params = [':USER_ID' => \Yii::$app->user->id];
  234. $data = UserPerformance::lists($condition, $params, [
  235. 'select' => 'ID,USER_ID,AMOUNTS,ORIGINAL,EXPIRED_AT',
  236. 'orderBy' => 'EXPIRED_AT ASC, CREATED_AT ASC',
  237. ]);
  238. } else {
  239. return static::notice('walletType error',400);
  240. }
  241. if($data && $walletType == 'bonus') {
  242. foreach ($data['list'] as $key => $value) {
  243. if ($value['DEAL_TYPE_IS_PRESET'] == 0) {
  244. $data['list'][$key]['DEAL_TYPE_NAME'] = $value['AMOUNT'] > 0 ? Yii::t('app', 'increase') : Yii::t('app', 'reduce');
  245. } else {
  246. $data['list'][$key]['DEAL_TYPE_NAME'] = DealType::getAllTypesForShow()[$value['DEAL_TYPE_ID']]['TYPE_NAME'] ?? '';
  247. }
  248. if ($value['REMARK_IS_SHOW'] == 0) $data['list'][$key]['REMARK'] = '';
  249. }
  250. }
  251. if ($dealLists && $walletType != 'userPerformanceBonus') {
  252. foreach ($dealLists as $key=>$value){
  253. if(!$value['DEAL_TYPE_ID']) continue;
  254. $dealType = DealType::getAllTypesForShow()[$value['DEAL_TYPE_ID']];
  255. if($dealType['IS_PRESET']==0){
  256. $dealTypes['1'] = Yii::t('app', 'increase');// 增加
  257. $dealTypes['2'] = Yii::t('app', 'reduce');// 扣除
  258. }else{
  259. $dealLists[$key]['DEAL_TYPE_NAME'] = $dealType['TYPE_NAME']??'';
  260. $dealTypes[$value['DEAL_TYPE_ID']] = $dealLists[$key]['DEAL_TYPE_NAME'];
  261. }
  262. }
  263. }
  264. $data['dealTypes'] = $dealTypes;
  265. unset($dealTypes);
  266. return static::notice($data);
  267. }
  268. /**
  269. * 最新奖金
  270. * @return mixed
  271. * @throws \yii\db\Exception
  272. * @throws \yii\web\HttpException
  273. */
  274. public function actionNew(){
  275. if(!$periodNum = \Yii::$app->request->get('periodNum')) {
  276. $periodNum = Period::sentMaxPeriodNum();
  277. }
  278. //是否近期期数
  279. $showFlowPeriodNum = Cache::getSystemConfig()['showFlowPeriodNum']['VALUE'];
  280. $periodArr = Period::getNearlySendPeriodNum($showFlowPeriodNum);
  281. if(!in_array($periodNum,$periodArr)) {
  282. return static::notice(Yii::t('app', 'cannotViewThisPeriod'), 400);
  283. }
  284. // 查询奖金
  285. $data = User::find()
  286. ->from(User::tableName().' AS U')
  287. ->join('LEFT JOIN', CalcBonus::tableName() . ' AS B','B.USER_ID = U.ID')
  288. ->select('U.ID AS USER_ID, U.USER_NAME, U.LAST_DEC_LV, B.LAST_EMP_LV, B.LAST_ELITE_LV, B.IS_ACTIVE, B.BONUS_E, B.BONUS_PE, B.BONUS_SE, B.BONUS_LB, B.BONUS_ST, B.BONUS_WB, B.BONUS_CAR, B.BONUS_TOTAL, B.BONUS_PB, B.BONUS_BB')
  289. ->where('USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', [':USER_ID' => \Yii::$app->user->id,':PERIOD_NUM'=>$periodNum])
  290. ->asArray()
  291. ->one();
  292. $result = [
  293. 'userName' => $data['USER_NAME'],
  294. 'period' => $periodNum,
  295. 'decLevel' => Cache::getDecLevelConfig()[($data['LAST_DEC_LV'] ?: DeclarationLevel::getDefaultLevelId())]['LEVEL_NAME'],
  296. 'empLevel' => Cache::getEmpLevelConfig()[($data['LAST_EMP_LV'] ?: EmployLevel::getDefaultLevelId())]['LEVEL_NAME'],
  297. 'eliteLevel' => Cache::getEliteLevelConfig()[($data['LAST_ELITE_LV'] ?: EliteLevel::getDefaultLevelId())]['LEVEL_NAME'],
  298. 'isActive' => $data['IS_ACTIVE'] ?? 0,
  299. 'eliteBonus' => Tool::formatPrice($data['BONUS_E']),
  300. 'proEliteBonus' => Tool::formatPrice($data['BONUS_PE']),
  301. 'superEliteBonus' => Tool::formatPrice($data['BONUS_SE']),
  302. 'leaderShipBonus' => Tool::formatPrice($data['BONUS_LB']),
  303. 'stockistBonus' => Tool::formatPrice($data['BONUS_ST']),
  304. 'welcomeBonus' => Tool::formatPrice($data['BONUS_WB']),
  305. 'carBonus' => Tool::formatPrice($data['BONUS_CAR']),
  306. 'totalBonus' => Tool::formatPrice($data['BONUS_TOTAL']),
  307. 'userPerformanceBonus' => Tool::formatPrice($data['BONUS_PB']),
  308. 'userBuilderBonus' => Tool::formatPrice($data['BONUS_BB']),
  309. ];
  310. return static::notice($result);
  311. }
  312. /**
  313. * 往期奖金
  314. * @return mixed
  315. * @throws \yii\web\HttpException
  316. */
  317. public function actionOther() {
  318. //获取可以查看几期奖金
  319. $showBonusPeriodNum = Cache::getSystemConfig()['showBonusPeriodNum']['VALUE'];
  320. $calcBonus = CalcBonus::find()->where('USER_ID=:USER_ID AND IS_SENT=1', [':USER_ID' => \Yii::$app->user->id])
  321. ->select('PERIOD_NUM,CALC_MONTH,LAST_DEC_LV,LAST_EMP_LV,LAST_ELITE_LV,BONUS_TOTAL,BONUS_E,BONUS_PE,BONUS_SE,BONUS_LB,BONUS_ST,BONUS_WB,BONUS_CAR,BONUS_PB,BONUS_BB')
  322. ->limit($showBonusPeriodNum)
  323. ->orderBy('PERIOD_NUM DESC')
  324. ->asArray()
  325. ->all();
  326. $result = [];
  327. foreach ($calcBonus as $data) {
  328. $result[] = [
  329. 'period' => $data['PERIOD_NUM'],
  330. 'eliteBonus' => Tool::formatPrice($data['BONUS_E']),
  331. 'proEliteBonus' => Tool::formatPrice($data['BONUS_PE']),
  332. 'superEliteBonus' => Tool::formatPrice($data['BONUS_SE']),
  333. 'leaderShipBonus' => Tool::formatPrice($data['BONUS_LB']),
  334. 'stockistBonus' => Tool::formatPrice($data['BONUS_ST']),
  335. 'welcomeBonus' => Tool::formatPrice($data['BONUS_WB']),
  336. 'carBonus' => Tool::formatPrice($data['BONUS_CAR']),
  337. 'totalBonus' => Tool::formatPrice($data['BONUS_TOTAL']),
  338. 'userPerformanceBonus' => Tool::formatPrice($data['BONUS_PB']),
  339. 'userBuilderBonus' => Tool::formatPrice($data['BONUS_BB']),
  340. ];
  341. }
  342. // 奖金明细开关控制(0 只显示总奖金 1 全部显示)
  343. $flowBonusSwitch = Cache::getSystemConfig()['flowBonusSwitch']['VALUE'] ?? 0;
  344. return static::notice(['tableData' => $result, 'flowBonusSwitch' => $flowBonusSwitch]);
  345. }
  346. /**
  347. * 历史累积奖金
  348. * @return mixed
  349. * @throws \yii\web\HttpException
  350. */
  351. public function actionHistoricalCumulativeBonus()
  352. {
  353. $calcBonus = CalcBonus::find()->where('USER_ID=:USER_ID AND IS_SENT=1', [':USER_ID' => \Yii::$app->user->id])
  354. ->select([
  355. 'IFNULL(SUM(BONUS_E), 0.00) AS BONUS_E',
  356. 'IFNULL(SUM(BONUS_PE), 0.00) AS BONUS_PE',
  357. 'IFNULL(SUM(BONUS_SE), 0.00) AS BONUS_SE',
  358. 'IFNULL(SUM(BONUS_ST), 0.00) AS BONUS_ST',
  359. 'IFNULL(SUM(BONUS_LB), 0.00) AS BONUS_LB',
  360. 'IFNULL(SUM(BONUS_WB), 0.00) AS BONUS_WB',
  361. 'IFNULL(SUM(BONUS_CAR), 0.00) AS BONUS_CAR',
  362. 'IFNULL(SUM(BONUS_PB), 0.00) AS BONUS_PB',
  363. 'IFNULL(SUM(BONUS_BB), 0.00) AS BONUS_BB',
  364. ])
  365. ->asArray()
  366. ->one();
  367. $data = [
  368. ['name' => 'eliteBonus', 'bonus' => $calcBonus['BONUS_E'] ?? '0'],
  369. ['name' => 'proEliteBonus', 'bonus' => $calcBonus['BONUS_PE'] ?? '0'],
  370. ['name' => 'superEliteBonus', 'bonus' => $calcBonus['BONUS_SE'] ?? '0'],
  371. ['name' => 'stockistBonus', 'bonus' => $calcBonus['BONUS_ST'] ?? '0'],
  372. ['name' => 'leaderShipBonus', 'bonus' => $calcBonus['BONUS_LB'] ?? '0'],
  373. ['name' => 'welcomeBonus', 'bonus' => $calcBonus['BONUS_WB'] ?? '0'],
  374. ['name' => 'carBonus', 'bonus' => $calcBonus['BONUS_CAR'] ?? '0'],
  375. ['name' => 'userPerformanceBonus', 'bonus' => $calcBonus['BONUS_PB'] ?? '0'],
  376. ['name' => 'userBuilderBonus', 'bonus' => $calcBonus['BONUS_BB'] ?? '0'],
  377. ];
  378. return static::notice(['tableData' => $data]);
  379. }
  380. /**
  381. * 实时业绩
  382. * @return mixed
  383. * @throws \yii\web\HttpException
  384. */
  385. public function actionRealTimePerf() {
  386. $userId = \Yii::$app->user->id;
  387. $period = Period::instance();
  388. $newPerf = Perf::getPeriodNewPerf($userId);
  389. $weekData = [['PV_1L' => Tool::formatFrontPerf($newPerf['PV_1L']), 'PV_2L' => Tool::formatFrontPerf($newPerf['PV_2L']), 'PV_3L' => Tool::formatFrontPerf($newPerf['PV_3L'])]];
  390. $monthPerf = Perf::getMonthPerf($userId);
  391. $monthData = [['PV_1L' => Tool::formatFrontPerf($monthPerf['PV_1L']), 'PV_2L' => Tool::formatFrontPerf($monthPerf['PV_2L']), 'PV_3L' => Tool::formatFrontPerf($monthPerf['PV_3L'])]];
  392. $lastMonth = PerfMonth::getMonthPerf($period->getLastMonth()['yearMonth'], $userId);
  393. $lastData = [['PV_1L' => Tool::formatFrontPerf($lastMonth['PV_1L_TOTAL']), 'PV_2L' => Tool::formatFrontPerf($lastMonth['PV_2L_TOTAL']), 'PV_3L' => Tool::formatFrontPerf($lastMonth['PV_3L_TOTAL'])]];
  394. //是否合格
  395. // $lastChkStatus = '';
  396. // $lastMonthPerfChk = Cache::getSystemConfig()['lastMonthPerfChk']['VALUE'];
  397. // $lastArr = [$lastMonth['PV_1L_TOTAL'], $lastMonth['PV_2L_TOTAL'], $lastMonth['PV_3L_TOTAL'], $lastMonth['PV_4L_TOTAL'], $lastMonth['PV_5L_TOTAL']];
  398. // if (array_sum($lastArr) >= $lastMonthPerfChk) {
  399. // $lastChkStatus = '已合格';
  400. // }
  401. //判断大区
  402. // $bigLocation = array_search(max($lastArr), $lastArr) + 1;
  403. return static::notice(['weekData' => $weekData, 'monthData' => $monthData, 'lastData' => $lastData]);
  404. }
  405. /**
  406. * 近十期已挂网的期数
  407. * @return mixed
  408. * @throws \yii\web\HttpException
  409. */
  410. public function actionDecPeriod() {
  411. $showDecPeriodNum = Cache::getSystemConfig()['showDecPeriodNum']['VALUE'];
  412. $calcBonus = Period::find()->where('IS_SENT=:IS_SENT',[':IS_SENT' => Period::SEND_FINISH])->select('PERIOD_NUM,END_TIME')->limit($showDecPeriodNum)->orderBy('PERIOD_NUM DESC')->asArray()->all();
  413. return static::notice($calcBonus);
  414. }
  415. /**
  416. * 报单中心补助明细
  417. * @return mixed
  418. * @throws \yii\web\HttpException
  419. */
  420. public function actionFlowBt() {
  421. $periodNum = \Yii::$app->request->get('periodNum');
  422. $condition = '';
  423. $params = [];
  424. if (!$periodNum) {
  425. return static::notice(Yii::t('app', 'pleaseSelectThePeriod'), 400);
  426. }
  427. if ($periodNum) {
  428. $showDecPeriodNum = Cache::getSystemConfig()['showDecPeriodNum']['VALUE'];
  429. $periodNums = Period::find()->where('IS_SENT=:IS_SENT',[':IS_SENT' => Period::SEND_FINISH])->select('PERIOD_NUM')->limit($showDecPeriodNum)->orderBy('PERIOD_NUM DESC')->asArray()->all();
  430. if(!in_array($periodNum,array_column($periodNums,'PERIOD_NUM'))){
  431. return static::notice(Yii::t('app', 'cannotViewThisPeriod'), 400);
  432. }
  433. $condition .= ' AND PERIOD_NUM=:PERIOD_NUM';
  434. $params[':PERIOD_NUM'] = $periodNum;
  435. }
  436. $condition .= ' AND USER_ID=:USER_ID';
  437. $params[':USER_ID'] = \Yii::$app->user->id;
  438. $data = CalcBonusBT::lists($condition, $params, [
  439. 'select' => 'BT_TYPE,FROM_ORDER_SN,ORDER_TIME,PAY_PV,DELIVERY_AT,TRANSFER_AMOUNT,TRANSFER_AT,AMOUNT',
  440. 'from' => CalcBonusBT::tableName(),
  441. 'orderBy' => 'CREATED_AT DESC',
  442. ]);
  443. if ($data['list']) {
  444. foreach ($data['list'] as $key => $value) {
  445. $data['list'][$key]['BT_TYPE_NAME'] = CalcBonusBT::TYPE_NAME[$value['BT_TYPE']];
  446. foreach ($value as $k=>$item){
  447. if($item==0) $data['list'][$key][$k] ='';
  448. }
  449. }
  450. }
  451. return static::notice($data);
  452. }
  453. /**
  454. * 报单中心货补追溯
  455. * @return mixed
  456. * @throws \yii\web\HttpException
  457. */
  458. public function actionTraceFl() {
  459. $periodNum = \Yii::$app->request->get('periodNum');
  460. $condition = '';
  461. $params = [];
  462. if (!$periodNum) {
  463. return static::notice(Yii::t('app', 'pleaseSelectThePeriod'), 400);
  464. }
  465. if ($periodNum) {
  466. $showDecPeriodNum = Cache::getSystemConfig()['showDecPeriodNum']['VALUE'];
  467. $periodNums = Period::find()->where('IS_SENT=:IS_SENT',[':IS_SENT' => Period::SEND_FINISH])->select('PERIOD_NUM')->limit($showDecPeriodNum)->orderBy('PERIOD_NUM DESC')->asArray()->all();
  468. if(!in_array($periodNum,array_column($periodNums,'PERIOD_NUM'))){
  469. return static::notice(Yii::t('app', 'cannotViewThisPeriod'), 400);
  470. }
  471. $condition .= ' AND PERIOD_NUM=:PERIOD_NUM';
  472. $params[':PERIOD_NUM'] = $periodNum;
  473. }
  474. $condition .= ' AND USER_ID=:USER_ID';
  475. $params[':USER_ID'] = \Yii::$app->user->id;
  476. $data = CalcBonusFL::lists($condition, $params, [
  477. 'select' => 'DEC_SN,DEC_AT,DEC_PV,AMOUNT',
  478. 'from' => CalcBonusFL::tableName(),
  479. 'orderBy' => 'CREATED_AT DESC',
  480. ]);
  481. return static::notice($data);
  482. }
  483. /**
  484. * 查看所传期数的各项奖金
  485. * @return mixed
  486. * @throws \yii\db\Exception
  487. * @throws \yii\web\HttpException
  488. */
  489. public function actionBonusDetail() {
  490. $periodNum = \Yii::$app->request->get('periodNum');
  491. $period = Period::instance();
  492. $periodInfo = $period->setPeriodNum($periodNum);
  493. $yearMonth = $period->getYearMonth($periodNum);
  494. if (!$period->isSent($periodNum)) {
  495. return static::notice(Yii::t('app', 'cannotViewThisPeriod'), 400);
  496. }
  497. $data = CalcBonus::findUseSlaves()->yearMonth($yearMonth)->select('BONUS_QY,BONUS_YC,BONUS_FX,BONUS_LS,BONUS_CF,BONUS_LX,BONUS_FL')->where('PERIOD_NUM=:PERIOD_NUM AND USER_ID=:USER_ID', [':PERIOD_NUM' => $periodNum, ':USER_ID' => \Yii::$app->user->id])->asArray()->one();
  498. return static::notice(['period' => $periodInfo, 'bonus' => $data]);
  499. }
  500. /**
  501. * 奖金流水
  502. * @return mixed
  503. * @throws \yii\web\HttpException
  504. */
  505. public function actionFlowBonus() {
  506. $yearMonth = \Yii::$app->request->get('yearMonth');
  507. if ($yearMonth) {
  508. if (!Date::isYearMonth($yearMonth)) {
  509. return static::notice(Yii::t('app', 'invalidParameter'), 400);
  510. }
  511. } else {
  512. $period = Period::instance();
  513. $yearMonth = $period->getNowYearMonth();
  514. }
  515. $data = FlowBonus::lists(' AND USER_ID=:USER_ID', [':USER_ID' => \Yii::$app->user->id], [
  516. 'useSlaves' => true,
  517. 'select' => 'AMOUNT,TOTAL,IS_INCR,REMARK,REMARK_IS_SHOW,PERIOD_NUM,CALC_MONTH,CREATED_AT',
  518. 'yearMonth' => $yearMonth,
  519. 'orderBy' => 'CREATED_AT DESC',
  520. ]);
  521. foreach ($data['list'] as $key => $value) {
  522. if($value['REMARK_IS_SHOW']==0) $data['list'][$key]['REMARK'] = '';
  523. }
  524. return static::notice($data);
  525. }
  526. /**
  527. * 提现列表
  528. * @return mixed
  529. * @throws \yii\base\Exception
  530. * @throws \yii\web\HttpException
  531. */
  532. public function actionWithdraw() {
  533. $yearMonth = \Yii::$app->request->get('yearMonth');
  534. if ($yearMonth) {
  535. if (!Date::isYearMonth($yearMonth)) {
  536. return static::notice(Yii::t('app', 'invalidParameter'), 400);
  537. }
  538. } else {
  539. $period = Period::instance();
  540. $yearMonth = $period->getNowYearMonth();
  541. }
  542. $data = Withdraw::lists('AND W.USER_ID=:USER_ID', [':USER_ID' => \Yii::$app->user->id], [
  543. 'useSlaves' => true,
  544. 'select' => 'W.ID,W.USER_ID,W.IS_AUTO_WITHDRAW,W.AMOUNT,W.AUDIT_STATUS,W.CREATED_AT,W.PAID_AT,W.PAY_TYPE,W.PAID_FAIL_REMARK,W.INVOICE_ID,IA.AMOUNT INVOICE_AMOUNT,IA.AUDIT_STATUS INVOICE_AUDIT_STATUS,IA.UPLOAD_ID',
  545. 'from' => Withdraw::tableName() . ' AS W',
  546. 'join' => [
  547. ['LEFT JOIN', InvoiceAudit::tableName() . ' AS IA', 'W.ID=IA.WITHDRAW_ID'],
  548. ],
  549. 'yearMonth' => $yearMonth,
  550. 'orderBy' => 'W.CREATED_AT DESC',
  551. //'with' => 'openBank',
  552. ]);
  553. $auditStatus = array_column(\Yii::$app->params['auditStatus'], null, 'value');
  554. foreach ($data['list'] as $key => $value) {
  555. $baseInfo = Info::baseInfo($value['USER_ID']);
  556. $data['list'][$key]['USER_NAME'] = $baseInfo['USER_NAME'];
  557. $data['list'][$key]['REAL_NAME'] = $baseInfo['REAL_NAME'];
  558. $data['list'][$key]['STATUS_NAME'] = Withdraw::STATUS_NAME[$value['AUDIT_STATUS']];
  559. $data['list'][$key]['INVOICE_STATUS_NAME'] = isset($value['INVOICE_AUDIT_STATUS'])?$auditStatus[$value['INVOICE_AUDIT_STATUS']]['label']:'未传发票';
  560. }
  561. return static::notice($data);
  562. }
  563. /**
  564. * 提交提现申请
  565. * @return mixed
  566. * @throws \yii\db\Exception
  567. * @throws \yii\web\HttpException
  568. */
  569. public function actionWithdrawAdd() {
  570. if (\Yii::$app->request->isPost) {
  571. $formModel = new WithdrawForm();
  572. $formModel->scenario = 'addByUser';
  573. if ($formModel->load(\Yii::$app->request->post(), '') && $formModel->add()) {
  574. return static::notice(Yii::t('app', 'withdrawalApplicationHasBeenSubmitted'), 400);
  575. } else {
  576. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  577. }
  578. } else {
  579. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  580. }
  581. }
  582. /**
  583. * 提现退回
  584. * @return mixed
  585. * @throws \yii\db\Exception
  586. * @throws \yii\web\HttpException
  587. */
  588. public function actionWithdrawBack() {
  589. if (\Yii::$app->request->isPost) {
  590. $formModel = new WithdrawForm();
  591. $formModel->scenario = 'backByUser';
  592. if ($formModel->load(\Yii::$app->request->post(), '') && $formModel->backByUser()) {
  593. return static::notice(Yii::t('app', 'withdrawHasBeenBacked'));
  594. } else {
  595. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  596. }
  597. } else {
  598. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  599. }
  600. }
  601. /**
  602. * 判断并获取提现的会员信息
  603. * @return mixed
  604. * @throws \yii\web\HttpException
  605. */
  606. public function actionChkWithdrawUser() {
  607. $uid = \Yii::$app->user->id;
  608. if (!Info::isVerified($uid)) {
  609. return static::notice(Yii::t('app', 'withdrawDoesNotAllowedOfAuthentication'), 400);
  610. }
  611. $userInfo = UserInfo::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $uid], 'IS_BIND,IS_BIND_MAIN,IS_AUTO_WITHDRAW,REG_TYPE,TRANSFER_PROP');
  612. if ($userInfo['IS_BIND'] == 1 && $userInfo['IS_BIND_MAIN'] == 0) {
  613. return static::notice(Yii::t('app', 'withdrawDoesNotAllowedOfSubsidiaryMember'), 400);
  614. }
  615. if ($userInfo['IS_AUTO_WITHDRAW'] == 1) {
  616. return static::notice(Yii::t('app', 'autoWithdrawHasBeenOpened'), 400);
  617. }
  618. if (!Withdraw::allowWithdraw()) {
  619. return static::notice(Yii::t('app', 'withdrawNotAllowOfDate'), 400);
  620. }
  621. if (Withdraw::hasThisMonthWithdraw($uid)) {
  622. return static::notice(Yii::t('app', 'withdrawAllowOnceOfMonth'), 400);
  623. }
  624. if (Withdraw::existWaitAudit($uid)) {
  625. return static::notice(Yii::t('app', 'withdrawRecordHasNotVerify'), 400);
  626. }
  627. //是否显示服务协议
  628. $regType = RegType::findOneAsArray('ID=:ID', [':ID' => $userInfo['REG_TYPE']], 'IS_PACT');
  629. $path = \Yii::getAlias('@common/runtime/datas/pact.php');
  630. if (!file_exists($path)) {
  631. $oneData = '';
  632. } else {
  633. $oneData = include $path;
  634. }
  635. $isCanTransferProp = Cache::getSystemConfig()['isCanTransferProp']['VALUE'];
  636. if ($isCanTransferProp == 0) {
  637. $userInfo['WITHDRAW_PROP'] = 100;
  638. } else {
  639. $userInfo['WITHDRAW_PROP'] = 100 - $userInfo['TRANSFER_PROP'];
  640. }
  641. return static::notice(['userInfo' => $userInfo, 'isPact' => $regType['IS_PACT'], 'content' => $oneData['CONTENT']]);
  642. }
  643. /**
  644. * 归集附属会员奖金
  645. * @return mixed
  646. * @throws \yii\db\Exception
  647. * @throws \yii\web\HttpException
  648. */
  649. public function actionCollectBind() {
  650. $transferBonusForm = new TransferBonusForm();
  651. if ($totals=$transferBonusForm->collectBind(\Yii::$app->user->id)) {
  652. return static::notice(Yii::t('app', 'notionalPoolingAmountFinished') . $totals);
  653. } else {
  654. if($totals==0){
  655. return static::notice(Yii::t('app', 'notionalPoolingAmountFinished') . $totals);
  656. }else{
  657. return static::notice(Form::formatErrorsForApi($transferBonusForm->getErrors()), 400);
  658. }
  659. }
  660. }
  661. /**
  662. * 上传发票之前
  663. * @return mixed
  664. * @throws \yii\web\HttpException
  665. */
  666. public function actionInvoiceBeforeAdd() {
  667. $id = \Yii::$app->request->get('id');
  668. $withdraw = Withdraw::findOneAsArray('ID=:ID', [':ID' => $id]);
  669. if (!$withdraw) {
  670. return static::notice(Yii::t('app', 'dataDoesNotExists'), 400);
  671. }
  672. $uploadInvoiceTip = Cache::getSystemConfig()['uploadInvoiceTip']['VALUE'];
  673. if ($withdraw['AUDIT_STATUS'] == Withdraw::STATUS_APPLIED) {
  674. return static::notice(['addInvoiceTips' => $uploadInvoiceTip]);
  675. } else {
  676. return static::notice(Yii::t('app', 'withdrawDoesNotUploadInvoice'), 400);
  677. }
  678. }
  679. /**
  680. * 上传发票
  681. * @return mixed
  682. * @throws \yii\db\Exception
  683. * @throws \yii\web\HttpException
  684. */
  685. public function actionInvoiceAdd() {
  686. $id = \Yii::$app->request->get('id');
  687. $withdraw = Withdraw::findOneAsArray('ID=:ID', [':ID' => $id]);
  688. if (!$withdraw) {
  689. return static::notice(Yii::t('app', 'dataDoesNotExists'), 400);
  690. }
  691. if (\Yii::$app->request->isPost) {
  692. $formModel = new UploadForm();
  693. $formModel->scenario = 'invoiceFront';
  694. $formModel->file = UploadedFile::getInstanceByName('file');
  695. $formModel->withdrawId = $withdraw['ID'];
  696. $formModel->remark = '提现'.$withdraw['SN'].'发票';
  697. //$formModel->token = \Yii::$app->request->post('uploadToken');
  698. $formModel->token = \Yii::$app->request->request('uploadToken');
  699. if ($formModel->file && $formModel->upload()) {
  700. return static::notice(Yii::t('app', 'successfully'));
  701. } else {
  702. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  703. }
  704. }
  705. }
  706. /**
  707. * 显示上传的发票
  708. * @return mixed
  709. * @throws \yii\web\HttpException
  710. */
  711. public function actionInvoiceShow() {
  712. $id = \Yii::$app->request->get('id');
  713. $uploads = Uploads::findOneAsArray('ID=:ID', [':ID' => $id],'URL');
  714. if (!$uploads) {
  715. return static::notice(Yii::t('app', 'dataDoesNotExists'), 400);
  716. }
  717. return static::notice($uploads['URL']);
  718. }
  719. /**
  720. * 获取可用余额
  721. * @return mixed
  722. * @throws \yii\web\HttpException
  723. */
  724. public function actionAvailableBalance() {
  725. return static::notice(Balance::getAvailableBalance(\Yii::$app->user->id));
  726. }
  727. /**
  728. * 查看业绩
  729. * @return mixed
  730. * @throws \yii\web\HttpException
  731. */
  732. public function actionPerf() {
  733. $yearMonth = \Yii::$app->request->get('yearMonth');
  734. if ($yearMonth) {
  735. if (!Date::isYearMonth($yearMonth)) {
  736. return static::notice(Yii::t('app', 'invalidParameter'), 400);
  737. }
  738. } else {
  739. $period = Period::instance();
  740. $yearMonth = $period->getNowYearMonth();
  741. }
  742. $data = PerfPeriod::lists('AND P.USER_ID=:USER_ID AND PN.IS_SENT=1', [':USER_ID' => \Yii::$app->user->id], [
  743. 'select' => 'P.*',
  744. 'yearMonth' => $yearMonth,
  745. 'from' => PerfPeriod::tableName() . ' AS P',
  746. 'join' => [
  747. ['LEFT JOIN', Period::tableName() . ' AS PN', 'P.PERIOD_NUM=PN.PERIOD_NUM']
  748. ],
  749. 'orderBy' => 'P.PERIOD_NUM DESC',
  750. ]);
  751. $data['request']['yearMonth'] = $yearMonth;
  752. return static::notice($data);
  753. }
  754. /**
  755. * 转账列表
  756. * @return mixed
  757. * @throws \yii\web\HttpException
  758. */
  759. public function actionTransferList() {
  760. $type = \Yii::$app->request->get('type', 'out');
  761. if ($type == 'out') {
  762. $condition = ' AND T.FROM_UID=:USER_ID';
  763. } else {
  764. $condition = ' AND T.TO_UID=:USER_ID';
  765. }
  766. $params = [
  767. ':USER_ID' => \Yii::$app->user->id,
  768. ];
  769. $data = Transfer::lists($condition, $params, [
  770. 'select' => 'FUI.USER_NAME AS FROM_USER_NAME, TUI.USER_NAME AS TO_USER_NAME, T.AMOUNT, T.PERIOD_NUM, T.CREATED_AT',
  771. 'from' => Transfer::tableName() . ' AS T',
  772. 'join' => [
  773. ['LEFT JOIN', UserInfo::tableName() . ' AS FUI', 'FUI.USER_ID=T.FROM_UID'],
  774. ['LEFT JOIN', UserInfo::tableName() . ' AS TUI', 'TUI.USER_ID=T.TO_UID'],
  775. ],
  776. ]);
  777. return static::notice($data);
  778. }
  779. /**
  780. * 转账
  781. * @throws \yii\db\Exception
  782. * @throws \yii\web\HttpException
  783. */
  784. public function actionTransferAdd() {
  785. if (\Yii::$app->request->isPost) {
  786. $formModel = new TransferForm();
  787. if ($formModel->load(\Yii::$app->request->post(), '') && $formModel->transfer()) {
  788. return static::notice(Yii::t('app', 'successfully'));
  789. } else {
  790. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  791. }
  792. }
  793. }
  794. /**
  795. * 检查转账资格
  796. * @return mixed
  797. * @throws \yii\web\HttpException
  798. */
  799. public function actionChkTransferUser() {
  800. $uid = \Yii::$app->user->id;
  801. if (!Info::isVerified($uid)) {
  802. return static::notice(Yii::t('app', 'transferDoesNotAllowedOfAuthentication'), 400);
  803. }
  804. $userInfo = UserInfo::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $uid], 'ALLOW_TRANSFER,TRANSFER_PROP');
  805. if($userInfo['ALLOW_TRANSFER']==0){
  806. return static::notice(Yii::t('app', 'transferDoesNotAllowed'), 400);
  807. }
  808. $isCanTransferProp = Cache::getSystemConfig()['isCanTransferProp']['VALUE'];
  809. if($isCanTransferProp==0){
  810. $userInfo['TRANSFER_PROP']=100;
  811. }
  812. return static::notice(['userInfo' => $userInfo]);
  813. }
  814. /**
  815. * 房产积分列表
  816. * @return mixed
  817. * @throws \yii\web\HttpException
  818. */
  819. public function actionFcPoint() {
  820. $condition = ' AND USER_ID=:USER_ID';
  821. $params = [':USER_ID' => \Yii::$app->user->id];
  822. $yearMonth = \Yii::$app->request->get('yearMonth');
  823. if ($yearMonth) {
  824. if (!Date::isYearMonth($yearMonth)) {
  825. return static::notice(Yii::t('app', 'invalidParameter'), 400);
  826. }
  827. $condition .= ' AND CALC_MONTH=:CALC_MONTH';
  828. $params['CALC_MONTH'] = $yearMonth;
  829. }
  830. $data = ScoreMonth::lists($condition, $params, [
  831. 'from' => ScoreMonth::tableName(),
  832. 'orderBy' => 'ID DESC',
  833. ]);
  834. return static::notice($data);
  835. }
  836. /**
  837. * 查询可用期数
  838. * @return mixed
  839. * @throws HttpException
  840. */
  841. public function actionPeriod() {
  842. $nowTs = time();
  843. // 当前期
  844. $currentPeriod = Period::find()->where('START_TIME<:NOW_TIME', ['NOW_TIME' => $nowTs])->where('END_TIME>=:NOW_TIME', ['NOW_TIME' => $nowTs - 6])->asArray()->one();
  845. $data[] = $currentPeriod['PERIOD_NUM'];
  846. // 上一期是否封期
  847. $prevPeriodNum = $currentPeriod['PERIOD_NUM'] - 1;
  848. $prevPeriod = Period::find()->where('PERIOD_NUM=:PERIOD_NUM AND IS_SENT=0', [':PERIOD_NUM' => $prevPeriodNum])->asArray()->one();
  849. if ($prevPeriod) {
  850. $data[] = $prevPeriod['PERIOD_NUM'];
  851. }
  852. return static::notice(['data' => $data]);
  853. }
  854. function actionSentUserPerformance()
  855. {
  856. if (\Yii::$app->request->isPost) {
  857. $param = \Yii::$app->request->post();
  858. foreach ($param as $value){
  859. UserPerformance::sentUserPerformanceApi($value['user_id'], $value['amount'], $value['period']);
  860. }
  861. return static::notice(Yii::t('app', 'successfully'));
  862. } else {
  863. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  864. }
  865. }
  866. }