BonusController.php 48 KB

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