BonusController.php 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  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. //是否显示车房领袖
  85. // $showCFLX = true;
  86. // if ($data['CF'] <= 0 && $data['LX'] <= 0) {
  87. // $showCFLX = false;
  88. // //查看历史最高聘级是否到过五钻
  89. // if (EmployLevel::getSortById(Info::getHighEmpLv($userId)) >= 7) {
  90. // $showCFLX = true;
  91. // }
  92. // }
  93. $wallet[] = ['walletType' => 'bonus', 'walletName' => Yii::t('app', 'memberBonus'), 'amount' => Tool::formatPrice($data['BONUS'])];//会员奖金
  94. $wallet[] = ['walletType' => 'cash', 'walletName' => Yii::t('app', 'memberEcoin'), 'amount' => Tool::formatPrice($data['CASH']), 'coin' => $currency['CODE']];//会员余额
  95. // $wallet[] = ['walletType' => 'point', 'walletName' => '会员积分', 'amount' => Tool::formatPrice($data['RECONSUME_POINTS'])];
  96. // $wallet[] = ['walletType' => 'exchange', 'walletName' => 'Exchange points', 'amount' => Tool::formatPrice($data['EXCHANGE_POINTS'])];//兑换点数
  97. // $wallet[] = ['walletType' => 'tourism_points', 'walletName' => 'Travel points', 'amount' => Tool::formatPrice($data['TOURISM_POINTS'])];//旅游积分
  98. // $wallet[] = ['walletType' => 'garage_points', 'walletName' => Yii::t('app', 'carPoints'), 'amount' => Tool::formatPrice($data['GARAGE_POINTS'])];//车奖积分
  99. // $wallet[] = ['walletType' => 'villa_points', 'walletName' => Yii::t('app', 'villaPoints'), 'amount' => Tool::formatPrice($data['VILLA_POINTS'])];//房奖积分
  100. // if ($showCFLX) {
  101. // $wallet[] = ['walletType' => 'cf', 'walletName' => '福利积分一', 'amount' => Tool::formatPrice($data['CF'])];
  102. // $wallet[] = ['walletType' => 'lx', 'walletName' => '福利积分二', 'amount' => Tool::formatPrice($data['LX'])];
  103. // }
  104. //是否显示报单中心
  105. // $showBt = true;
  106. // $showFl = true;
  107. // $userInfo = User::getEnCodeInfo(\Yii::$app->user->id);
  108. // if ($userInfo['IS_DEC'] != 1) {
  109. // $showBt = false;
  110. // $showFl = false;
  111. // }else{
  112. // $sysConfig = Cache::getSystemConfig();
  113. // if(!$sysConfig['openBT']['VALUE']&&!$sysConfig['openPROD']['VALUE']) $showBt = false;
  114. // if(!$sysConfig['openFL']['VALUE']) $showFl = false;
  115. // $decRole = DecRole::find()->where('1=1')->indexBy('ID')->asArray()->all()[$userInfo['DEC_ROLE_ID']];
  116. // if ($decRole['GOODS_SUBSIDY'] <= 0) $showFl = false;
  117. // }
  118. $dealSwitch = isset(Cache::getSystemConfig()['dealSwitch']) ? Cache::getSystemConfig()['dealSwitch']['VALUE'] : '';
  119. return static::notice(['wallet' => $wallet,'dealSwitch'=>$dealSwitch]);
  120. }
  121. /**
  122. * 团队查询
  123. * @return mixed
  124. * @throws \yii\web\HttpException
  125. */
  126. public function actionTeams() {
  127. $userId = \Yii::$app->user->id;
  128. $period = Period::instance();
  129. // $periodNum = $period->getNowPeriodNum();
  130. // $month = $period->getNowYearMonth();
  131. // 查询最新一期已封期、未挂网期数
  132. $periodNum = $period->getTeamsPeriodNum();
  133. $month = $period->getTeamsYearMonth($periodNum);
  134. // 判断此业绩期是否已经完成生成了预计算业绩单,生成完毕才能看到
  135. $isPerfed = Period::checkPerf($periodNum);
  136. LoggerTool::debug(['calc-1', $isPerfed, $periodNum]);
  137. if (!$isPerfed) {
  138. return static::notice(['user' => [],'team'=>[]]);
  139. }
  140. // 判断当前时间,是否临近封期,否则隐藏
  141. LoggerTool::debug(['calc-2']);
  142. if ($periodNum % 2!=0) {
  143. return static::notice(['user' => [],'team'=>[]]);
  144. }
  145. $userInfo = User::getEnCodeInfo($userId);
  146. $data = PerfMonth::fetchMonthPerf($month, $userId);
  147. $user[0] = [
  148. 'number' => $userInfo['USER_NAME'],
  149. 'name' => $userInfo['REAL_NAME'],
  150. 'user_perf' => 0, // 个人业绩
  151. 'team_perf' => 0, // 团队新增累计业绩
  152. 'total_perf' => 0, // 合计业绩
  153. 'perf_status' => '0', // 0 未达标 1为已达标
  154. 'perf_status_name' => 'Fail',
  155. ];
  156. if (!empty($data)) {
  157. $userCheck = PerfMonth::checkStatus($data['PV_PCS']+$data['PV_PSS']);
  158. $user[0]['user_perf'] = $data['PV_PCS'];
  159. $user[0]['team_perf'] = $data['PV_PSS'];
  160. $user[0]['total_perf'] = $data['PV_PCS']+$data['PV_PSS'];
  161. $user[0]['perf_status'] = $userCheck ? '1' : $user[0]['perf_status'];
  162. $user[0]['perf_status_name'] = $userCheck ? 'Pass' : $user[0]['perf_status_name'];
  163. }
  164. $teamInfo = [];
  165. $calcAt = PerfMonth::find()->select(['CREATED_AT'])->where('CALC_MONTH=:CALC_MONTH', ['CALC_MONTH'=>$month])->asArray()->one();
  166. LoggerTool::debug(['calc-3']);
  167. if(!$calcAt){
  168. $periodStartTime = $period->nowPeriodArr['START_TIME'];
  169. return static::notice(['user' => $user,'team'=>[],'calcAt' => $periodStartTime]);
  170. }
  171. // 查询此用户的推荐(开拓)团队一级信息
  172. $relation = UserRelation::getChildrenWithDeepAndLayer($userId, 1, 1, $periodNum);
  173. $userStatusFlag = false;
  174. if ($relation) {
  175. // 循环一级开拓用户
  176. foreach($relation as $k=>$v) {
  177. // 获取此用户预计算月业绩
  178. $relationPerf = PerfMonth::fetchMonthPerf($month, $v['USER_ID']);
  179. if (empty($relationPerf)) {
  180. $relationPerf['PV_PCS'] = 0;
  181. $relationPerf['PV_PSS'] = 0;
  182. }
  183. $relationCheck = PerfMonth::checkStatus($relationPerf['PV_PCS']+$relationPerf['PV_PSS']);
  184. $teamInfo[]['perf_status'] = $relationCheck ? '1' : '0';
  185. if ($relationCheck) {
  186. $userStatusFlag = true; // 只要有一个达标,则个人就达标
  187. $teamInfo[$k]['number'] = $v['USER_NAME'];
  188. $teamInfo[$k]['name'] = $v['REAL_NAME'];
  189. $teamInfo[$k]['user_perf'] = $relationPerf['PV_PCS'];
  190. $teamInfo[$k]['team_perf'] = $relationPerf['PV_PSS'];
  191. $teamInfo[$k]['total_perf'] = $relationPerf['PV_PCS']+$relationPerf['PV_PSS'];
  192. $teamInfo[$k]['perf_status'] = '1';
  193. $teamInfo[$k]['perf_status_name'] = 'Pass';
  194. } else {
  195. $teamInfo[$k]['number'] = $v['USER_NAME'];
  196. $teamInfo[$k]['name'] = $v['REAL_NAME'];
  197. $teamInfo[$k]['user_perf'] = $relationPerf['PV_PCS'];
  198. $teamInfo[$k]['team_perf'] = $relationPerf['PV_PSS'];
  199. $teamInfo[$k]['total_perf'] = $relationPerf['PV_PCS']+$relationPerf['PV_PSS'];
  200. $teamInfo[$k]['perf_status'] = '0';
  201. $teamInfo[$k]['perf_status_name'] = 'Fail';
  202. }
  203. }
  204. }
  205. if ($userStatusFlag === true) {
  206. $user[0]['perf_status'] = '1';
  207. $user[0]['perf_status_name'] = 'Pass';
  208. }
  209. return static::notice(['user' => $user,'team'=>$teamInfo,'calcAt' => $calcAt['CREATED_AT']]);
  210. }
  211. /**
  212. * 交易记录
  213. * @return mixed
  214. * @throws \yii\web\HttpException
  215. */
  216. public function actionWalletFlow(){
  217. $walletType = \Yii::$app->request->get('walletType');
  218. if(!in_array($walletType,['bonus', 'cash', 'exchange'/**, 'tourism_points', 'garage_points', 'villa_points'*/])) return static::notice('walletType error',400);
  219. $dealType = \Yii::$app->request->get('dealType');
  220. $createAt = \Yii::$app->request->get('createAt');
  221. $remark = \Yii::$app->request->get('remark');
  222. //获取可以查看几期流水
  223. $showFlowPeriodNum = Cache::getSystemConfig()['showFlowPeriodNum']['VALUE'];
  224. $periodArr = Period::getNearlyPeriodNum($showFlowPeriodNum);
  225. $condition = ' AND USER_ID=:USER_ID AND PERIOD_NUM>=:PERIOD_NUM_MIN AND PERIOD_NUM<=:PERIOD_NUM_MAX';
  226. $params = [':USER_ID' => \Yii::$app->user->id,':PERIOD_NUM_MIN' => min($periodArr), ':PERIOD_NUM_MAX'=> max($periodArr)];
  227. if($dealType){
  228. if($dealType==1){//增加
  229. $condition.=' AND IS_INCR=1 AND DEAL_TYPE_IS_PRESET=0';
  230. }elseif ($dealType==2){//扣除
  231. $condition.=' AND IS_INCR=0 AND DEAL_TYPE_IS_PRESET=0';
  232. }else if ($walletType != 'cash') {
  233. $condition.=' AND DEAL_TYPE_ID=:DEAL_TYPE';
  234. $params[':DEAL_TYPE'] = $dealType;
  235. }
  236. }
  237. if ($createAt) {
  238. $createAtStart = $createAt[0] ?? '';
  239. $createAtEnd = $createAt[1] ?? '';
  240. if ($createAtStart) {
  241. $condition .= " AND CREATED_AT>:CREATED_START";
  242. $params[':CREATED_START'] = Date::utcToTime($createAtStart);
  243. }
  244. if ($createAtEnd) {
  245. $condition .= " AND CREATED_AT<:CREATED_END";
  246. $params[':CREATED_END'] = Date::utcToTime($createAtEnd)+86399;
  247. }
  248. }
  249. if($remark){
  250. $condition .= " AND REMARK LIKE :REMARK";
  251. $params[':REMARK'] = '%'.$remark.'%';
  252. }
  253. $data = [];
  254. $dealLists=[];
  255. $dealTypes=[];
  256. if($walletType == 'bonus') {
  257. $dealLists = FlowBonus::find()->groupBy('DEAL_TYPE_ID')->select('DEAL_TYPE_ID')->where('USER_ID=:USER_ID',[':USER_ID'=>\Yii::$app->user->id])->asArray()->all();
  258. $data = FlowBonus::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,SORT DESC',
  262. ]);
  263. // }elseif ($walletType == 'point'){
  264. // $dealLists = FlowReconsumePoints::find()->groupBy('DEAL_TYPE_ID')->select('DEAL_TYPE_ID')->where('USER_ID=:USER_ID',[':USER_ID'=>\Yii::$app->user->id])->asArray()->all();
  265. // $data = FlowReconsumePoints::lists($condition, $params, [
  266. // 'useSlaves' => true,
  267. // 'select' => 'AMOUNT,TOTAL,IS_INCR,REMARK,REMARK_IS_SHOW,PERIOD_NUM,CALC_MONTH,CREATED_AT,DEAL_TYPE_ID,DEAL_TYPE_IS_PRESET',
  268. // 'orderBy' => 'CREATED_AT DESC',
  269. // ]);
  270. }elseif ($walletType == 'cash'){
  271. $data = FlowWallet::lists($condition, $params, [
  272. 'select' => 'AMOUNT,TOTAL,IS_INCR,REMARK,PERIOD_NUM,CALC_MONTH,CREATED_AT',
  273. 'orderBy' => 'CREATED_AT DESC',
  274. ]);
  275. }else if ($walletType == 'exchange') {
  276. $dealLists = FlowExchangePoints::find()->groupBy('DEAL_TYPE_ID')->select('DEAL_TYPE_ID')->where('USER_ID=:USER_ID', [':USER_ID' => \Yii::$app->user->id])->asArray()->all();
  277. $data = FlowExchangePoints::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 == 'tourism_points') {
  283. // $dealLists = FlowTourismPoints::find()->groupBy('DEAL_TYPE_ID')->select('DEAL_TYPE_ID')->where('USER_ID=:USER_ID',[':USER_ID'=>\Yii::$app->user->id])->asArray()->all();
  284. // $data = FlowTourismPoints::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 == 'garage_points') {
  290. // $dealLists = FlowGaragePoints::find()->groupBy('DEAL_TYPE_ID')->select('DEAL_TYPE_ID')->where('USER_ID=:USER_ID',[':USER_ID'=>\Yii::$app->user->id])->asArray()->all();
  291. // $data = FlowGaragePoints::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 == 'villa_points') {
  297. // $dealLists = FlowVillaPoints::find()->groupBy('DEAL_TYPE_ID')->select('DEAL_TYPE_ID')->where('USER_ID=:USER_ID',[':USER_ID'=>\Yii::$app->user->id])->asArray()->all();
  298. // $data = FlowVillaPoints::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. }