BonusController.php 55 KB

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