BonusController.php 53 KB

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