BonusController.php 53 KB

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