BonusController.php 46 KB

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