BonusController.php 55 KB

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