BonusController.php 52 KB

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