BonusController.php 52 KB

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