BonusController.php 42 KB

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