BonusController.php 51 KB

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