BonusController.php 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012
  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,ORI_BONUS_QY,ORI_BONUS_YC,ORI_BONUS_VIP,ORI_BONUS_STANDARD,ORI_BONUS_BD,ORI_BONUS_TG,
  372. ORI_BONUS_XF,BONUS_TOTAL,MANAGE_TAX,BONUS_REAL,BONUS_INCOME,ORI_BONUS_YJ,ORI_BONUS_GX,ORI_BONUS_GL,RECONSUME_POINTS,
  373. LAST_DEC_LV,LAST_EMP_LV,EXCHANGE_POINTS,ORI_BONUS_BS,ORI_BONUS_BS_MNT,ORI_BONUS_BS_ABBR,ORI_BONUS_QUARTER,BONUS_TOURISM,BONUS_GARAGE')
  374. ->limit($showBonusPeriodNum)
  375. ->orderBy('PERIOD_NUM DESC')
  376. ->asArray()
  377. ->all();
  378. $sysConfig = Cache::getSystemConfig();
  379. //增加明细开关控制(0 只显示总奖金 1 全部显示)
  380. $flowBonusSwitch = Cache::getSystemConfig()['flowBonusSwitch']['VALUE'];
  381. $bonusSwitch = [
  382. 'welcomeBonusSwitch' => intval($sysConfig['openTG']['VALUE']),
  383. 'teamBonusSwitch' => intval($sysConfig['openQY']['VALUE']),
  384. 'stockistCommissionSwitch' => intval($sysConfig['openFW']['VALUE']),
  385. ];
  386. $result = [];
  387. foreach ($calcBonus as $key => $data) {
  388. if ($flowBonusSwitch) {
  389. $result[$key]['PERIOD_NUM'] = ['name' => '期数', 'value' => $data['PERIOD_NUM']];
  390. $result[$key]['LAST_DEC_NAME'] = ['name' => '级别', 'value' => Cache::getDecLevelConfig()[$data['LAST_DEC_LV']]['LEVEL_NAME']];
  391. $result[$key]['LAST_EMP_NAME'] = ['name' => '聘级', 'value' => Cache::getEmpLevelConfig()[$data['LAST_EMP_LV']]['LEVEL_NAME']];
  392. // 销售奖金,就是原来的推广奖金
  393. if ($sysConfig['openTG']['VALUE']) {
  394. $result[$key]['BONUS_TG'] = ['name' => '销售奖金', 'value' => Tool::formatPrice($data['ORI_BONUS_TG'])];
  395. }
  396. // 业绩奖金,就是原来的团队奖 并将业绩奖金改成绩效奖金
  397. if ($sysConfig['openQY']['VALUE']) {
  398. $result[$key]['ORI_BONUS_QY'] = ['name' => '业绩奖金', 'value' => Tool::formatPrice($data['ORI_BONUS_QY'])];
  399. }
  400. if ($sysConfig['openFW']['VALUE']) {
  401. $result[$key]['BONUS_BD'] = ['name' => '服务奖金', 'value' => Tool::formatPrice($data['ORI_BONUS_BD'])];
  402. }
  403. $result[$key]['ORI_BONUS_BS'] = ['name' => '管理奖金', 'value' => Tool::formatPrice($data['ORI_BONUS_BS'])];
  404. $result[$key]['ORI_BONUS_BS_MNT'] = ['name' => '管理奖金', 'value' => Tool::formatPrice($data['ORI_BONUS_BS_MNT'])];
  405. $result[$key]['ORI_BONUS_BS_ABBR'] = ['name' => '绩效奖金', 'value' => Tool::formatPrice($data['ORI_BONUS_BS_ABBR'])];
  406. $result[$key]['ORI_BONUS_QUARTER'] = ['name' => '季度奖金', 'value' => Tool::formatPrice($data['ORI_BONUS_QUARTER'] ?? 0)];
  407. $result[$key]['BONUS_TOTAL'] = ['name' => '合计', 'value' => Tool::formatPrice($data['BONUS_TOTAL'])];
  408. $result[$key]['BONUS_REAL'] = ['name' => '实发奖金', 'value' => Tool::formatPrice($data['BONUS_REAL'])];
  409. } else {
  410. $result[$key]['BONUS_TOTAL'] = ['name' => '总奖金', 'value' => Tool::formatPrice($data['BONUS_TOTAL'])];
  411. }
  412. }
  413. return static::notice(['tableData' => $result, 'tableKey' => '', 'bonusSwitch' => $bonusSwitch]);
  414. }
  415. /**
  416. * 历史累积奖金
  417. * @return mixed
  418. * @throws \yii\web\HttpException
  419. */
  420. public function actionHistoricalCumulativeBonus()
  421. {
  422. $calcBonus = CalcBonus::find()->where('USER_ID=:USER_ID AND IS_SENT=1', [':USER_ID' => \Yii::$app->user->id])
  423. ->select([
  424. 'IFNULL(SUM(ORI_BONUS_TG), 0.00) AS ORI_BONUS_TG',
  425. 'IFNULL(SUM(ORI_BONUS_QY), 0.00) AS ORI_BONUS_QY',
  426. 'IFNULL(SUM(ORI_BONUS_BD), 0.00) AS ORI_BONUS_BD',
  427. 'IFNULL(SUM(ORI_BONUS_BS), 0.00) AS ORI_BONUS_BS',
  428. 'IFNULL(SUM(ORI_BONUS_QUARTER), 0.00) AS ORI_BONUS_QUARTER',
  429. 'IFNULL(SUM(BONUS_TOTAL), 0.00) AS BONUS_TOTAL'
  430. ])
  431. ->asArray()
  432. ->one();
  433. // 增加明细开关控制(0 只显示总奖金 1 全部显示)
  434. $flowBonusSwitch = Cache::getSystemConfig()['flowBonusSwitch']['VALUE'];
  435. $sysConfig = Cache::getSystemConfig();
  436. $bonusSwitch = [
  437. 'welcomeBonusSwitch' => intval($sysConfig['openTG']['VALUE']),
  438. 'teamBonusSwitch' => intval($sysConfig['openQY']['VALUE']),
  439. 'stockistCommissionSwitch' => intval($sysConfig['openFW']['VALUE']),
  440. ];
  441. if ($calcBonus) {
  442. if ($flowBonusSwitch) {
  443. if ($sysConfig['openTG']['VALUE']) {
  444. $calcBonus['BONUS_TG'] = ['name' => '销售奖金', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_TG'])];
  445. } else {
  446. $calcBonus['BONUS_TG'] = ['name' => '销售奖金', 'value' => 0.00];
  447. }
  448. if ($sysConfig['openQY']['VALUE']) {
  449. $calcBonus['ORI_BONUS_QY'] = ['name' => '业绩奖金', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_QY'])];
  450. } else {
  451. $calcBonus['ORI_BONUS_QY'] = ['name' => '业绩奖金', 'value' => 0.00];
  452. }
  453. if ($sysConfig['openFW']['VALUE']) {
  454. $calcBonus['BONUS_BD'] = ['name' => '服务奖金', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_BD'])];
  455. } else {
  456. $calcBonus['BONUS_BD'] = ['name' => '服务奖金', 'value' => 0.00];
  457. }
  458. $calcBonus['ORI_BONUS_BS'] = ['name' => '蓝星奖', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_BS'])];
  459. $calcBonus['ORI_BONUS_QUARTER'] = ['name' => '季度奖金', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_QUARTER'])];
  460. }
  461. $calcBonus['BONUS_TOTAL'] = ['name' => '总奖金', 'value' => Tool::formatPrice($calcBonus['BONUS_TOTAL'])];
  462. }
  463. return static::notice(['tableData' => [$calcBonus], 'bonusSwitch' => $bonusSwitch]);
  464. }
  465. /**
  466. * 实时业绩
  467. * @return mixed
  468. * @throws \yii\web\HttpException
  469. */
  470. public function actionRealTimePerf() {
  471. $userId = \Yii::$app->user->id;
  472. $period = Period::instance();
  473. $newPerf = Perf::getPeriodNewPerf($userId);
  474. $weekData = [['PV_1L' => Tool::formatFrontPerf($newPerf['PV_1L']), 'PV_2L' => Tool::formatFrontPerf($newPerf['PV_2L']), 'PV_3L' => Tool::formatFrontPerf($newPerf['PV_3L'])]];
  475. $monthPerf = Perf::getMonthPerf($userId);
  476. $monthData = [['PV_1L' => Tool::formatFrontPerf($monthPerf['PV_1L']), 'PV_2L' => Tool::formatFrontPerf($monthPerf['PV_2L']), 'PV_3L' => Tool::formatFrontPerf($monthPerf['PV_3L'])]];
  477. $lastMonth = PerfMonth::getMonthPerf($period->getLastMonth()['yearMonth'], $userId);
  478. $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'])]];
  479. //是否合格
  480. // $lastChkStatus = '';
  481. // $lastMonthPerfChk = Cache::getSystemConfig()['lastMonthPerfChk']['VALUE'];
  482. // $lastArr = [$lastMonth['PV_1L_TOTAL'], $lastMonth['PV_2L_TOTAL'], $lastMonth['PV_3L_TOTAL'], $lastMonth['PV_4L_TOTAL'], $lastMonth['PV_5L_TOTAL']];
  483. // if (array_sum($lastArr) >= $lastMonthPerfChk) {
  484. // $lastChkStatus = '已合格';
  485. // }
  486. //判断大区
  487. // $bigLocation = array_search(max($lastArr), $lastArr) + 1;
  488. return static::notice(['weekData' => $weekData, 'monthData' => $monthData, 'lastData' => $lastData]);
  489. }
  490. /**
  491. * 近十期已挂网的期数
  492. * @return mixed
  493. * @throws \yii\web\HttpException
  494. */
  495. public function actionDecPeriod() {
  496. $showDecPeriodNum = Cache::getSystemConfig()['showDecPeriodNum']['VALUE'];
  497. $data = 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();
  498. return static::notice($data);
  499. }
  500. /**
  501. * 报单中心补助明细
  502. * @return mixed
  503. * @throws \yii\web\HttpException
  504. */
  505. public function actionFlowBt() {
  506. $periodNum = \Yii::$app->request->get('periodNum');
  507. $condition = '';
  508. $params = [];
  509. if (!$periodNum) {
  510. return static::notice(Yii::t('app', 'pleaseSelectThePeriod'), 400);
  511. }
  512. if ($periodNum) {
  513. $showDecPeriodNum = Cache::getSystemConfig()['showDecPeriodNum']['VALUE'];
  514. $periodNums = Period::find()->where('IS_SENT=:IS_SENT',[':IS_SENT' => Period::SEND_FINISH])->select('PERIOD_NUM')->limit($showDecPeriodNum)->orderBy('PERIOD_NUM DESC')->asArray()->all();
  515. if(!in_array($periodNum,array_column($periodNums,'PERIOD_NUM'))){
  516. return static::notice(Yii::t('app', 'cannotViewThisPeriod'), 400);
  517. }
  518. $condition .= ' AND PERIOD_NUM=:PERIOD_NUM';
  519. $params[':PERIOD_NUM'] = $periodNum;
  520. }
  521. $condition .= ' AND USER_ID=:USER_ID';
  522. $params[':USER_ID'] = \Yii::$app->user->id;
  523. $data = CalcBonusBT::lists($condition, $params, [
  524. 'select' => 'BT_TYPE,FROM_ORDER_SN,ORDER_TIME,PAY_PV,DELIVERY_AT,TRANSFER_AMOUNT,TRANSFER_AT,AMOUNT',
  525. 'from' => CalcBonusBT::tableName(),
  526. 'orderBy' => 'CREATED_AT DESC',
  527. ]);
  528. if ($data['list']) {
  529. foreach ($data['list'] as $key => $value) {
  530. $data['list'][$key]['BT_TYPE_NAME'] = CalcBonusBT::TYPE_NAME[$value['BT_TYPE']];
  531. foreach ($value as $k=>$item){
  532. if($item==0) $data['list'][$key][$k] ='';
  533. }
  534. }
  535. }
  536. return static::notice($data);
  537. }
  538. /**
  539. * 报单中心货补追溯
  540. * @return mixed
  541. * @throws \yii\web\HttpException
  542. */
  543. public function actionTraceFl() {
  544. $periodNum = \Yii::$app->request->get('periodNum');
  545. $condition = '';
  546. $params = [];
  547. if (!$periodNum) {
  548. return static::notice(Yii::t('app', 'pleaseSelectThePeriod'), 400);
  549. }
  550. if ($periodNum) {
  551. $showDecPeriodNum = Cache::getSystemConfig()['showDecPeriodNum']['VALUE'];
  552. $periodNums = Period::find()->where('IS_SENT=:IS_SENT',[':IS_SENT' => Period::SEND_FINISH])->select('PERIOD_NUM')->limit($showDecPeriodNum)->orderBy('PERIOD_NUM DESC')->asArray()->all();
  553. if(!in_array($periodNum,array_column($periodNums,'PERIOD_NUM'))){
  554. return static::notice(Yii::t('app', 'cannotViewThisPeriod'), 400);
  555. }
  556. $condition .= ' AND PERIOD_NUM=:PERIOD_NUM';
  557. $params[':PERIOD_NUM'] = $periodNum;
  558. }
  559. $condition .= ' AND USER_ID=:USER_ID';
  560. $params[':USER_ID'] = \Yii::$app->user->id;
  561. $data = CalcBonusFL::lists($condition, $params, [
  562. 'select' => 'DEC_SN,DEC_AT,DEC_PV,AMOUNT',
  563. 'from' => CalcBonusFL::tableName(),
  564. 'orderBy' => 'CREATED_AT DESC',
  565. ]);
  566. return static::notice($data);
  567. }
  568. /**
  569. * 查看所传期数的各项奖金
  570. * @return mixed
  571. * @throws \yii\db\Exception
  572. * @throws \yii\web\HttpException
  573. */
  574. public function actionBonusDetail() {
  575. $periodNum = \Yii::$app->request->get('periodNum');
  576. $period = Period::instance();
  577. $periodInfo = $period->setPeriodNum($periodNum);
  578. $yearMonth = $period->getYearMonth($periodNum);
  579. if (!$period->isSent($periodNum)) {
  580. return static::notice(Yii::t('app', 'cannotViewThisPeriod'), 400);
  581. }
  582. $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();
  583. return static::notice(['period' => $periodInfo, 'bonus' => $data]);
  584. }
  585. /**
  586. * 奖金流水
  587. * @return mixed
  588. * @throws \yii\web\HttpException
  589. */
  590. public function actionFlowBonus() {
  591. $yearMonth = \Yii::$app->request->get('yearMonth');
  592. if ($yearMonth) {
  593. if (!Date::isYearMonth($yearMonth)) {
  594. return static::notice(Yii::t('app', 'invalidParameter'), 400);
  595. }
  596. } else {
  597. $period = Period::instance();
  598. $yearMonth = $period->getNowYearMonth();
  599. }
  600. $data = FlowBonus::lists(' AND USER_ID=:USER_ID', [':USER_ID' => \Yii::$app->user->id], [
  601. 'useSlaves' => true,
  602. 'select' => 'AMOUNT,TOTAL,IS_INCR,REMARK,REMARK_IS_SHOW,PERIOD_NUM,CALC_MONTH,CREATED_AT',
  603. 'yearMonth' => $yearMonth,
  604. 'orderBy' => 'CREATED_AT DESC',
  605. ]);
  606. foreach ($data['list'] as $key => $value) {
  607. if($value['REMARK_IS_SHOW']==0) $data['list'][$key]['REMARK'] = '';
  608. }
  609. return static::notice($data);
  610. }
  611. /**
  612. * 提现列表
  613. * @return mixed
  614. * @throws \yii\base\Exception
  615. * @throws \yii\web\HttpException
  616. */
  617. public function actionWithdraw() {
  618. $yearMonth = \Yii::$app->request->get('yearMonth');
  619. if ($yearMonth) {
  620. if (!Date::isYearMonth($yearMonth)) {
  621. return static::notice(Yii::t('app', 'invalidParameter'), 400);
  622. }
  623. } else {
  624. $period = Period::instance();
  625. $yearMonth = $period->getNowYearMonth();
  626. }
  627. $data = Withdraw::lists('AND W.USER_ID=:USER_ID', [':USER_ID' => \Yii::$app->user->id], [
  628. 'useSlaves' => true,
  629. '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',
  630. 'from' => Withdraw::tableName() . ' AS W',
  631. 'join' => [
  632. ['LEFT JOIN', InvoiceAudit::tableName() . ' AS IA', 'W.ID=IA.WITHDRAW_ID'],
  633. ],
  634. 'yearMonth' => $yearMonth,
  635. 'orderBy' => 'W.CREATED_AT DESC',
  636. //'with' => 'openBank',
  637. ]);
  638. $auditStatus = array_column(\Yii::$app->params['auditStatus'], null, 'value');
  639. foreach ($data['list'] as $key => $value) {
  640. $baseInfo = Info::baseInfo($value['USER_ID']);
  641. $data['list'][$key]['USER_NAME'] = $baseInfo['USER_NAME'];
  642. $data['list'][$key]['REAL_NAME'] = $baseInfo['REAL_NAME'];
  643. $data['list'][$key]['STATUS_NAME'] = Withdraw::STATUS_NAME[$value['AUDIT_STATUS']];
  644. $data['list'][$key]['INVOICE_STATUS_NAME'] = isset($value['INVOICE_AUDIT_STATUS'])?$auditStatus[$value['INVOICE_AUDIT_STATUS']]['label']:'未传发票';
  645. }
  646. return static::notice($data);
  647. }
  648. /**
  649. * 提交提现申请
  650. * @return mixed
  651. * @throws \yii\db\Exception
  652. * @throws \yii\web\HttpException
  653. */
  654. public function actionWithdrawAdd() {
  655. if (\Yii::$app->request->isPost) {
  656. $formModel = new WithdrawForm();
  657. $formModel->scenario = 'addByUser';
  658. if ($formModel->load(\Yii::$app->request->post(), '') && $formModel->add()) {
  659. return static::notice(Yii::t('app', 'withdrawalApplicationHasBeenSubmitted'), 400);
  660. } else {
  661. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  662. }
  663. } else {
  664. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  665. }
  666. }
  667. /**
  668. * 提现退回
  669. * @return mixed
  670. * @throws \yii\db\Exception
  671. * @throws \yii\web\HttpException
  672. */
  673. public function actionWithdrawBack() {
  674. if (\Yii::$app->request->isPost) {
  675. $formModel = new WithdrawForm();
  676. $formModel->scenario = 'backByUser';
  677. if ($formModel->load(\Yii::$app->request->post(), '') && $formModel->backByUser()) {
  678. return static::notice(Yii::t('app', 'withdrawHasBeenBacked'));
  679. } else {
  680. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  681. }
  682. } else {
  683. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  684. }
  685. }
  686. /**
  687. * 判断并获取提现的会员信息
  688. * @return mixed
  689. * @throws \yii\web\HttpException
  690. */
  691. public function actionChkWithdrawUser() {
  692. $uid = \Yii::$app->user->id;
  693. if (!Info::isVerified($uid)) {
  694. return static::notice(Yii::t('app', 'withdrawDoesNotAllowedOfAuthentication'), 400);
  695. }
  696. $userInfo = UserInfo::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $uid], 'IS_BIND,IS_BIND_MAIN,IS_AUTO_WITHDRAW,REG_TYPE,TRANSFER_PROP');
  697. if ($userInfo['IS_BIND'] == 1 && $userInfo['IS_BIND_MAIN'] == 0) {
  698. return static::notice(Yii::t('app', 'withdrawDoesNotAllowedOfSubsidiaryMember'), 400);
  699. }
  700. if ($userInfo['IS_AUTO_WITHDRAW'] == 1) {
  701. return static::notice(Yii::t('app', 'autoWithdrawHasBeenOpened'), 400);
  702. }
  703. if (!Withdraw::allowWithdraw()) {
  704. return static::notice(Yii::t('app', 'withdrawNotAllowOfDate'), 400);
  705. }
  706. if (Withdraw::hasThisMonthWithdraw($uid)) {
  707. return static::notice(Yii::t('app', 'withdrawAllowOnceOfMonth'), 400);
  708. }
  709. if (Withdraw::existWaitAudit($uid)) {
  710. return static::notice(Yii::t('app', 'withdrawRecordHasNotVerify'), 400);
  711. }
  712. //是否显示服务协议
  713. $regType = RegType::findOneAsArray('ID=:ID', [':ID' => $userInfo['REG_TYPE']], 'IS_PACT');
  714. $path = \Yii::getAlias('@common/runtime/datas/pact.php');
  715. if (!file_exists($path)) {
  716. $oneData = '';
  717. } else {
  718. $oneData = include $path;
  719. }
  720. $isCanTransferProp = Cache::getSystemConfig()['isCanTransferProp']['VALUE'];
  721. if ($isCanTransferProp == 0) {
  722. $userInfo['WITHDRAW_PROP'] = 100;
  723. } else {
  724. $userInfo['WITHDRAW_PROP'] = 100 - $userInfo['TRANSFER_PROP'];
  725. }
  726. return static::notice(['userInfo' => $userInfo, 'isPact' => $regType['IS_PACT'], 'content' => $oneData['CONTENT']]);
  727. }
  728. /**
  729. * 归集附属会员奖金
  730. * @return mixed
  731. * @throws \yii\db\Exception
  732. * @throws \yii\web\HttpException
  733. */
  734. public function actionCollectBind() {
  735. $transferBonusForm = new TransferBonusForm();
  736. if ($totals=$transferBonusForm->collectBind(\Yii::$app->user->id)) {
  737. return static::notice(Yii::t('app', 'notionalPoolingAmountFinished') . $totals);
  738. } else {
  739. if($totals==0){
  740. return static::notice(Yii::t('app', 'notionalPoolingAmountFinished') . $totals);
  741. }else{
  742. return static::notice(Form::formatErrorsForApi($transferBonusForm->getErrors()), 400);
  743. }
  744. }
  745. }
  746. /**
  747. * 上传发票之前
  748. * @return mixed
  749. * @throws \yii\web\HttpException
  750. */
  751. public function actionInvoiceBeforeAdd() {
  752. $id = \Yii::$app->request->get('id');
  753. $withdraw = Withdraw::findOneAsArray('ID=:ID', [':ID' => $id]);
  754. if (!$withdraw) {
  755. return static::notice(Yii::t('app', 'dataDoesNotExists'), 400);
  756. }
  757. $uploadInvoiceTip = Cache::getSystemConfig()['uploadInvoiceTip']['VALUE'];
  758. if ($withdraw['AUDIT_STATUS'] == Withdraw::STATUS_APPLIED) {
  759. return static::notice(['addInvoiceTips' => $uploadInvoiceTip]);
  760. } else {
  761. return static::notice(Yii::t('app', 'withdrawDoesNotUploadInvoice'), 400);
  762. }
  763. }
  764. /**
  765. * 上传发票
  766. * @return mixed
  767. * @throws \yii\db\Exception
  768. * @throws \yii\web\HttpException
  769. */
  770. public function actionInvoiceAdd() {
  771. $id = \Yii::$app->request->get('id');
  772. $withdraw = Withdraw::findOneAsArray('ID=:ID', [':ID' => $id]);
  773. if (!$withdraw) {
  774. return static::notice(Yii::t('app', 'dataDoesNotExists'), 400);
  775. }
  776. if (\Yii::$app->request->isPost) {
  777. $formModel = new UploadForm();
  778. $formModel->scenario = 'invoiceFront';
  779. $formModel->file = UploadedFile::getInstanceByName('file');
  780. $formModel->withdrawId = $withdraw['ID'];
  781. $formModel->remark = '提现'.$withdraw['SN'].'发票';
  782. //$formModel->token = \Yii::$app->request->post('uploadToken');
  783. $formModel->token = \Yii::$app->request->request('uploadToken');
  784. if ($formModel->file && $formModel->upload()) {
  785. return static::notice(Yii::t('app', 'successfully'));
  786. } else {
  787. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  788. }
  789. }
  790. }
  791. /**
  792. * 显示上传的发票
  793. * @return mixed
  794. * @throws \yii\web\HttpException
  795. */
  796. public function actionInvoiceShow() {
  797. $id = \Yii::$app->request->get('id');
  798. $uploads = Uploads::findOneAsArray('ID=:ID', [':ID' => $id],'URL');
  799. if (!$uploads) {
  800. return static::notice(Yii::t('app', 'dataDoesNotExists'), 400);
  801. }
  802. return static::notice($uploads['URL']);
  803. }
  804. /**
  805. * 获取可用余额
  806. * @return mixed
  807. * @throws \yii\web\HttpException
  808. */
  809. public function actionAvailableBalance() {
  810. return static::notice(Balance::getAvailableBalance(\Yii::$app->user->id));
  811. }
  812. /**
  813. * 查看业绩
  814. * @return mixed
  815. * @throws \yii\web\HttpException
  816. */
  817. public function actionPerf() {
  818. $yearMonth = \Yii::$app->request->get('yearMonth');
  819. if ($yearMonth) {
  820. if (!Date::isYearMonth($yearMonth)) {
  821. return static::notice(Yii::t('app', 'invalidParameter'), 400);
  822. }
  823. } else {
  824. $period = Period::instance();
  825. $yearMonth = $period->getNowYearMonth();
  826. }
  827. $data = PerfPeriod::lists('AND P.USER_ID=:USER_ID AND PN.IS_SENT=1', [':USER_ID' => \Yii::$app->user->id], [
  828. 'select' => 'P.*',
  829. 'yearMonth' => $yearMonth,
  830. 'from' => PerfPeriod::tableName() . ' AS P',
  831. 'join' => [
  832. ['LEFT JOIN', Period::tableName() . ' AS PN', 'P.PERIOD_NUM=PN.PERIOD_NUM']
  833. ],
  834. 'orderBy' => 'P.PERIOD_NUM DESC',
  835. ]);
  836. $data['request']['yearMonth'] = $yearMonth;
  837. return static::notice($data);
  838. }
  839. /**
  840. * 转账列表
  841. * @return mixed
  842. * @throws \yii\web\HttpException
  843. */
  844. public function actionTransferList() {
  845. $type = \Yii::$app->request->get('type', 'out');
  846. if ($type == 'out') {
  847. $condition = ' AND T.FROM_UID=:USER_ID';
  848. } else {
  849. $condition = ' AND T.TO_UID=:USER_ID';
  850. }
  851. $params = [
  852. ':USER_ID' => \Yii::$app->user->id,
  853. ];
  854. $data = Transfer::lists($condition, $params, [
  855. 'select' => 'FUI.USER_NAME AS FROM_USER_NAME, TUI.USER_NAME AS TO_USER_NAME, T.AMOUNT, T.PERIOD_NUM, T.CREATED_AT',
  856. 'from' => Transfer::tableName() . ' AS T',
  857. 'join' => [
  858. ['LEFT JOIN', UserInfo::tableName() . ' AS FUI', 'FUI.USER_ID=T.FROM_UID'],
  859. ['LEFT JOIN', UserInfo::tableName() . ' AS TUI', 'TUI.USER_ID=T.TO_UID'],
  860. ],
  861. ]);
  862. return static::notice($data);
  863. }
  864. /**
  865. * 转账
  866. * @throws \yii\db\Exception
  867. * @throws \yii\web\HttpException
  868. */
  869. public function actionTransferAdd() {
  870. if (\Yii::$app->request->isPost) {
  871. $formModel = new TransferForm();
  872. if ($formModel->load(\Yii::$app->request->post(), '') && $formModel->transfer()) {
  873. return static::notice(Yii::t('app', 'successfully'));
  874. } else {
  875. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  876. }
  877. }
  878. }
  879. /**
  880. * 检查转账资格
  881. * @return mixed
  882. * @throws \yii\web\HttpException
  883. */
  884. public function actionChkTransferUser() {
  885. $uid = \Yii::$app->user->id;
  886. if (!Info::isVerified($uid)) {
  887. return static::notice(Yii::t('app', 'transferDoesNotAllowedOfAuthentication'), 400);
  888. }
  889. $userInfo = UserInfo::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $uid], 'ALLOW_TRANSFER,TRANSFER_PROP');
  890. if($userInfo['ALLOW_TRANSFER']==0){
  891. return static::notice(Yii::t('app', 'transferDoesNotAllowed'), 400);
  892. }
  893. $isCanTransferProp = Cache::getSystemConfig()['isCanTransferProp']['VALUE'];
  894. if($isCanTransferProp==0){
  895. $userInfo['TRANSFER_PROP']=100;
  896. }
  897. return static::notice(['userInfo' => $userInfo]);
  898. }
  899. /**
  900. * 房产积分列表
  901. * @return mixed
  902. * @throws \yii\web\HttpException
  903. */
  904. public function actionFcPoint() {
  905. $condition = ' AND USER_ID=:USER_ID';
  906. $params = [':USER_ID' => \Yii::$app->user->id];
  907. $yearMonth = \Yii::$app->request->get('yearMonth');
  908. if ($yearMonth) {
  909. if (!Date::isYearMonth($yearMonth)) {
  910. return static::notice(Yii::t('app', 'invalidParameter'), 400);
  911. }
  912. $condition .= ' AND CALC_MONTH=:CALC_MONTH';
  913. $params['CALC_MONTH'] = $yearMonth;
  914. }
  915. $data = ScoreMonth::lists($condition, $params, [
  916. 'from' => ScoreMonth::tableName(),
  917. 'orderBy' => 'ID DESC',
  918. ]);
  919. return static::notice($data);
  920. }
  921. /**
  922. * 查询可用期数
  923. * @return mixed
  924. * @throws HttpException
  925. */
  926. public function actionPeriod() {
  927. $nowTs = time();
  928. // 当前期
  929. $currentPeriod = Period::find()->where('START_TIME<:NOW_TIME', ['NOW_TIME' => $nowTs])->where('END_TIME>=:NOW_TIME', ['NOW_TIME' => $nowTs - 6])->asArray()->one();
  930. $data[] = $currentPeriod['PERIOD_NUM'];
  931. // 上一期是否封期
  932. $prevPeriodNum = $currentPeriod['PERIOD_NUM'] - 1;
  933. $prevPeriod = Period::find()->where('PERIOD_NUM=:PERIOD_NUM AND IS_SENT=0', [':PERIOD_NUM' => $prevPeriodNum])->asArray()->one();
  934. if ($prevPeriod) {
  935. $data[] = $prevPeriod['PERIOD_NUM'];
  936. }
  937. return static::notice(['data' => $data]);
  938. }
  939. }