BonusController.php 42 KB

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