BonusController.php 42 KB

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