BonusController.php 55 KB

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