BonusController.php 55 KB

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