Reconsume.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: liyunlong
  5. * Date: 2019-01-30
  6. * Time: 14:21
  7. */
  8. namespace common\helpers\user;
  9. use common\helpers\Cache;
  10. use common\helpers\Date;
  11. use common\helpers\Tool;
  12. use common\models\PerfMonth;
  13. use common\models\Period;
  14. use common\models\ReconsumePool;
  15. use common\models\ReconsumePoolFlow;
  16. use common\models\DeclarationLevel;
  17. use common\models\EmployLevel;
  18. use common\models\User;
  19. use yii\base\Exception;
  20. use yii\db\Expression;
  21. class Reconsume {
  22. const TYPE_DEC = 1;
  23. const TYPE_CALC = 2;
  24. const TYPE_AUDIT_PV = 3;
  25. const TYPE_AUDIT_MONTH = 4;
  26. const TYPE_MANUAL = 5;
  27. const TYPE_RESEND_QY = 7;
  28. const TYPE = [
  29. 1 => ['label' => '报单预存', 'value' => 1],
  30. 2 => ['label' => '结算自动扣除', 'value' => 2],
  31. 3 => ['label' => '调整复销池余额', 'value' => 3],
  32. 4 => ['label' => '调整复销池月数', 'value' => 4],
  33. 5 => ['label' => '手工扣除月复销', 'value' => 5],
  34. //7 => ['label' => '补发区域津贴', 'value' => 7],
  35. ];
  36. /**
  37. * 可用复销余额
  38. * @param $userId
  39. * @return mixed
  40. */
  41. public static function getBalance($userId) {
  42. $oneData = ReconsumePool::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $userId], 'UNUSED_PV');
  43. return $oneData['UNUSED_PV'];
  44. }
  45. /**
  46. * 增加复销或扣除复销池的PV
  47. * @param $userId
  48. * @param $pv
  49. * @param array $params
  50. * @param bool $mustHasUser
  51. * 该参数主要用于批量报单,复销会员是新首购的新会员,数据库中不存在该会员,此时不能要求一定存在会员,然后先把复销池数据插进去
  52. * @return int
  53. * @throws Exception
  54. * @throws \yii\db\Exception
  55. */
  56. public static function changePoolPV($userId, $pv, $params = [], $mustHasUser = true) {
  57. if ($pv == 0) return 0;
  58. $period = Period::instance();
  59. if (!isset($params['PERIOD_NUM'])) {
  60. $periodNum = $period->getNowPeriodNum();
  61. } else {
  62. $periodNum = $params['PERIOD_NUM'];
  63. }
  64. $calcYearMonth = $period->getYearMonth($periodNum);
  65. // 查看是否有数据
  66. if (!ReconsumePool::find()->where('USER_ID=:USER_ID', [':USER_ID' => $userId])->exists()) {
  67. // 新建一条用户的复销池数据
  68. ReconsumePool::insertOne(['USER_ID' => $userId, 'CREATED_AT' => Date::nowTime()]);
  69. }
  70. // 如果扣除pv的话,检测是否够扣,不够扣,则返回0
  71. if ($pv < 0) {
  72. $oneDataBefore = ReconsumePool::find()->where('USER_ID=:USER_ID', [':USER_ID' => $userId])->asArray()->one();
  73. if ($oneDataBefore['UNUSED_PV'] < abs($pv)) {
  74. throw new Exception('复销池余额不足');
  75. }
  76. }
  77. $updateData = [];
  78. $updateData['UNUSED_PV'] = new Expression("UNUSED_PV + $pv");
  79. // 变更复销池Pv
  80. ReconsumePool::updateAll($updateData, 'USER_ID=:USER_ID', [':USER_ID' => $userId]);
  81. unset($updateData);
  82. // 获取变更完的数据
  83. $oneDataAfter = ReconsumePool::find()->where('USER_ID=:USER_ID', [':USER_ID' => $userId])->asArray()->one();
  84. // 记录流水
  85. if($mustHasUser){
  86. $userInfo = Info::baseInfo($userId);
  87. } else {
  88. $userInfo =[
  89. 'DEC_LV' => DeclarationLevel::getDefaultLevelId(),
  90. 'EMP_LV' => EmployLevel::getDefaultLevelId(),
  91. 'STATUS' => 1,
  92. ];
  93. }
  94. $flowInsertData = [
  95. 'RECONSUME_POOL_SN' => ReconsumePoolFlow::generateSN(),
  96. 'USER_ID' => $userId,
  97. 'LAST_DEC_LV' => $userInfo['DEC_LV'],
  98. 'LAST_EMP_LV' => $userInfo['EMP_LV'],
  99. 'LAST_STATUS' => $userInfo['STATUS'],
  100. 'DEAL_TYPE' => $params['DEAL_TYPE'],
  101. 'RECONSUME_POOL_TYPE' => ReconsumePoolFlow::POOL_TYPE_PV,
  102. 'DEDUCT_PV' => $pv,
  103. 'UNUSED_PV' => $oneDataAfter['UNUSED_PV'],
  104. 'UNUSED_MONTH' => $oneDataAfter['UNUSED_MONTH'],
  105. 'REMARK' => $params['REMARK'] ?? null,
  106. 'REMARK_IS_SHOW' => $params['REMARK_IS_SHOW'] ?? 1,
  107. 'PERIOD_NUM' => $periodNum,
  108. 'CALC_MONTH' => $calcYearMonth,
  109. 'P_CALC_MONTH' => Date::ociToDate($calcYearMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH),
  110. 'CREATED_AT' => Date::nowTime(),
  111. 'ADMIN_NAME' => $params['ADMIN_NAME'] ?? null,
  112. ];
  113. ReconsumePoolFlow::insertOne($flowInsertData);
  114. unset($flowInsertData);
  115. return $pv;
  116. }
  117. /**
  118. * 扣除月复销
  119. * @param $userId
  120. * @param $periodNum
  121. * @param array $params
  122. * @return bool
  123. * @throws \yii\db\Exception
  124. */
  125. public static function deductFx($userId, $periodNum, array $params = []) {
  126. $period = Period::instance();
  127. $calcYearMonth = $period->getYearMonth($periodNum);
  128. return self::deductFxByCalcMonth($userId, $calcYearMonth, $params);
  129. }
  130. /**
  131. * 通过结算月来扣复销
  132. * @param $userId
  133. * @param $calcYearMonth
  134. * @param array $params
  135. * @return bool
  136. * @throws Exception
  137. * @throws \yii\db\Exception
  138. */
  139. public static function deductFxByCalcMonth($userId, $calcYearMonth, array $params = []) {
  140. $sysConfig = Cache::getSystemConfig();
  141. $pv = $sysConfig['reConsumePerf']['VALUE'];
  142. // 看是否本月注册,本月注册不扣除@190904
  143. if(Status::isMonthJoin($userId,$calcYearMonth)) return true;
  144. // 查看是否有数据
  145. if (!ReconsumePool::find()->where('USER_ID=:USER_ID', [':USER_ID' => $userId])->exists()) {
  146. // 新建一条用户的复销池数据
  147. ReconsumePool::insertOne(['USER_ID' => $userId, 'CREATED_AT' => Date::nowTime()]);
  148. }
  149. // 查看这个月是否已经扣过了,如果扣过了就不在扣了!直接返回扣除过的业绩
  150. $isDeducted = ReconsumePoolFlow::find()->yearMonth($calcYearMonth)->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH AND IS_FX_DEDUCT=1', [':USER_ID' => $userId, ':CALC_MONTH' => $calcYearMonth])->asArray()->one();
  151. if ($isDeducted) {
  152. return true;
  153. }
  154. // 检测是否够扣,不够扣,则扣除月有效期
  155. $deductPv = 0;
  156. $deductMonth = 0;
  157. $oneDataBefore = ReconsumePool::find()->select('UNUSED_PV,UNUSED_MONTH')->where('USER_ID=:USER_ID', [':USER_ID' => $userId])->asArray()->one();
  158. if ($oneDataBefore['UNUSED_PV'] < abs($pv)) {
  159. if ($oneDataBefore['UNUSED_MONTH'] < abs(1)) {
  160. return false;
  161. } else {
  162. $deductMonth = 1;
  163. }
  164. } else {
  165. $deductPv = $pv;
  166. }
  167. $updateData = [];
  168. $updateData['UNUSED_PV'] = new Expression("UNUSED_PV - $deductPv");
  169. $updateData['UNUSED_MONTH'] = new Expression("UNUSED_MONTH - $deductMonth");
  170. // 变更复销池Pv
  171. ReconsumePool::updateAll($updateData, 'USER_ID=:USER_ID', [':USER_ID' => $userId]);
  172. // 获取变更完的数据
  173. $oneDataAfter = ReconsumePool::find()->where('USER_ID=:USER_ID', [':USER_ID' => $userId])->asArray()->one();
  174. // 获取该结算月的最大期数,即为结算月的期节点
  175. $periodNum = Period::getPeriodNumPointFromMonth(substr($calcYearMonth, 0, 4), intval(substr($calcYearMonth, 4, 2)));
  176. // 记录流水
  177. $userInfo = Info::baseInfo($userId);
  178. $flowInsertData = [
  179. 'RECONSUME_POOL_SN' => ReconsumePoolFlow::generateSN(),
  180. 'USER_ID' => $userId,
  181. 'LAST_DEC_LV' => $userInfo['DEC_LV'],
  182. 'LAST_EMP_LV' => $userInfo['EMP_LV'],
  183. 'LAST_STATUS' => $userInfo['STATUS'],
  184. 'DEAL_TYPE' => $params['DEAL_TYPE'],
  185. 'RECONSUME_POOL_TYPE' => $deductMonth != 0 ? ReconsumePoolFlow::POOL_TYPE_MONTH : ReconsumePoolFlow::POOL_TYPE_PV,
  186. 'DEDUCT_PV' => $deductPv == 0 ? 0 : -$deductPv,
  187. 'DEDUCT_MONTH' => $deductMonth == 0 ? 0 : -$deductMonth,
  188. 'UNUSED_PV' => $oneDataAfter['UNUSED_PV'],
  189. 'UNUSED_MONTH' => $oneDataAfter['UNUSED_MONTH'],
  190. 'IS_FX_DEDUCT' => 1,
  191. 'REMARK' => $params['REMARK'] ?? null,
  192. 'REMARK_IS_SHOW' => $params['REMARK_IS_SHOW'] ?? 1,
  193. 'PERIOD_NUM' => $periodNum,
  194. 'CALC_MONTH' => $calcYearMonth,
  195. 'P_CALC_MONTH' => Date::ociToDate($calcYearMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH),
  196. 'CREATED_AT' => Date::nowTime(),
  197. 'ADMIN_NAME' => $params['ADMIN_NAME'] ?? 'system',
  198. ];
  199. ReconsumePoolFlow::insertOne($flowInsertData);
  200. unset($oneDataBefore, $updateData, $oneDataAfter, $flowInsertData);
  201. return true;
  202. }
  203. /**
  204. * 查看该会员是否能扣除复销
  205. * @param $userId
  206. * @param $calcYearMonth
  207. * @return bool
  208. * @throws \yii\db\Exception
  209. */
  210. public static function isCanDeduct($userId, $calcYearMonth) {
  211. // 查看会员是否本月加入
  212. if (Status::isMonthJoin($userId, $calcYearMonth)) return false;
  213. // 会员未加入的结算月不允许扣除
  214. if (Status::afterMonthJoin($userId, $calcYearMonth)) return false;
  215. // 查看该结算月是否已经扣过
  216. return !(ReconsumePoolFlow::find()->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH AND IS_FX_DEDUCT=1', [':USER_ID' => $userId, ':CALC_MONTH' => $calcYearMonth])->exists());
  217. }
  218. /**
  219. * 是否有得奖资格
  220. * @param $userId
  221. * @param $calcYearMonth
  222. * @return bool
  223. * @throws \yii\db\Exception
  224. */
  225. public static function isCanGetBonus($userId, $calcYearMonth) {
  226. // 查看会员是否本月加入
  227. if (Status::isMonthJoin($userId, $calcYearMonth)) return true;
  228. // 查看会员上月是否已经扣除过复销
  229. $periodNum = Period::getPeriodNumPointFromMonth(substr($calcYearMonth, 0, 4), intval(substr($calcYearMonth, 4, 2)));
  230. $period = Period::instance();
  231. $lastMonth = $period->getLastMonth($periodNum);
  232. // 查看业绩表中该结算月的上个月是否有复销资格
  233. return PerfMonth::find()->yearMonth($lastMonth['yearMonth'])->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH AND FX_STATUS=1', [':USER_ID' => $userId, ':CALC_MONTH' => $lastMonth['yearMonth']])->exists();
  234. // return ReconsumePoolFlow::find()->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH AND IS_FX_DEDUCT=1', [':USER_ID'=>$userId, ':CALC_MONTH'=>$lastMonth['yearMonth']])->exists();
  235. }
  236. /**
  237. * 变化有效月数
  238. * @param $userId
  239. * @param $monthNum
  240. * @param array $params
  241. * @return int
  242. * @throws Exception
  243. * @throws \yii\db\Exception
  244. */
  245. public static function changePoolMonthNum($userId, $monthNum, array $params = []) {
  246. $periodNum = $params['periodNum'] ?? null;
  247. if ($monthNum == 0) return 0;
  248. $period = Period::instance();
  249. if (!$periodNum) {
  250. $periodNum = $period->getNowPeriodNum();
  251. }
  252. $calcYearMonth = $period->getYearMonth($periodNum);
  253. // 查看是否有数据
  254. if (!ReconsumePool::find()->where('USER_ID=:USER_ID', [':USER_ID' => $userId])->exists()) {
  255. // 新建一条用户的复销池数据
  256. ReconsumePool::insertOne(['USER_ID' => $userId, 'CREATED_AT' => Date::nowTime()]);
  257. }
  258. // 如果扣除pv的话,检测是否够扣,不够扣,则返回0
  259. if ($monthNum < 0) {
  260. $oneDataBefore = ReconsumePool::find()->where('USER_ID=:USER_ID', [':USER_ID' => $userId])->asArray()->one();
  261. if ($oneDataBefore['UNUSED_MONTH'] < abs($monthNum)) {
  262. throw new Exception('复销池剩余月数不足');
  263. }
  264. }
  265. // 增加月份数
  266. $updateData = [];
  267. $updateData['UNUSED_MONTH'] = new Expression("UNUSED_MONTH + $monthNum");
  268. // 变更复销池Pv
  269. ReconsumePool::updateAll($updateData, 'USER_ID=:USER_ID', [':USER_ID' => $userId]);
  270. // 获取变更完的数据
  271. $oneDataAfter = ReconsumePool::find()->where('USER_ID=:USER_ID', [':USER_ID' => $userId])->asArray()->one();
  272. // 记录流水
  273. $userInfo = Info::baseInfo($userId);
  274. $flowInsertData = [
  275. 'RECONSUME_POOL_SN' => ReconsumePoolFlow::generateSN(),
  276. 'USER_ID' => $userId,
  277. 'LAST_DEC_LV' => $userInfo['DEC_LV'],
  278. 'LAST_EMP_LV' => $userInfo['EMP_LV'],
  279. 'LAST_STATUS' => $userInfo['STATUS'],
  280. 'DEAL_TYPE' => $params['DEAL_TYPE'],
  281. 'RECONSUME_POOL_TYPE' => ReconsumePoolFlow::POOL_TYPE_MONTH,
  282. 'DEDUCT_MONTH' => $monthNum,
  283. 'UNUSED_PV' => $oneDataAfter['UNUSED_PV'],
  284. 'UNUSED_MONTH' => $oneDataAfter['UNUSED_MONTH'],
  285. 'REMARK' => $params['REMARK'] ?? null,
  286. 'REMARK_IS_SHOW' => $params['REMARK_IS_SHOW'] ?? 1,
  287. 'PERIOD_NUM' => $periodNum,
  288. 'CALC_MONTH' => $calcYearMonth,
  289. 'P_CALC_MONTH' => Date::ociToDate($calcYearMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH),
  290. 'CREATED_AT' => Date::nowTime(),
  291. 'ADMIN_NAME' => $params['ADMIN_NAME'] ?? null,
  292. ];
  293. ReconsumePoolFlow::insertOne($flowInsertData);
  294. unset($updateData, $oneDataAfter, $flowInsertData);
  295. return $monthNum;
  296. }
  297. /**
  298. * 获取复销剩余时间
  299. * @param $userId
  300. * @return array
  301. * @throws \yii\db\Exception
  302. */
  303. public static function getUserReconsumePool($userId) {
  304. $pool = ReconsumePool::findUseSlaves()->select('UNUSED_PV,UNUSED_MONTH')->where('USER_ID=:USER_ID', [':USER_ID' => $userId])->asArray()->one();
  305. if (!$pool) {
  306. $pool['UNUSED_PV'] = 0;
  307. $pool['UNUSED_MONTH'] = 0;
  308. /*return [
  309. 'unusedPV' => 0,
  310. 'unusedMonth' => 0,
  311. 'reConsumeTimes' => 0,
  312. 'toTime' => 0,
  313. 'toDate' => 0,
  314. ];*/
  315. }
  316. // 第一步 获取复销剩余总月数
  317. $systemConfig = Cache::getSystemConfig();
  318. $reConsumePerf = $systemConfig['reConsumePerf']['VALUE'];
  319. if ($reConsumePerf <= 0) {
  320. return ['unusedPV' => 0,
  321. 'unusedMonth' => 0,
  322. 'reConsumeTimes' => 0,
  323. 'toTime' => 0,
  324. 'toDate' => 0,
  325. 'isPass' => 0,
  326. ];
  327. }
  328. $reConsumeTimes = intval($pool['UNUSED_PV'] / $reConsumePerf);
  329. $reConsumeTimes += $pool['UNUSED_MONTH'];
  330. // 第二步 获取最近一次未挂网的结算月
  331. $period = Period::instance();
  332. $sentMaxPeriodNum = Period::sentMaxPeriodNum() + 1;
  333. $sentYear = $period->getYear($sentMaxPeriodNum);
  334. $sentMonth = Tool::numFix($period->getMonth($sentMaxPeriodNum), 2);
  335. $sentYearMonth = $period->getYearMonth($sentMaxPeriodNum);
  336. //看会员这个月是否复销
  337. if (ReconsumePoolFlow::find()->yearMonth($sentYearMonth)->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH AND IS_FX_DEDUCT=1', [':USER_ID' => $userId, ':CALC_MONTH' => $sentYearMonth])->asArray()->one()) {
  338. //已扣复销当前月15日为时间基点
  339. $baseDate = $sentYear . '-' . $sentMonth . '-15';
  340. $reConsumeTimes += 1;
  341. } else {
  342. //获取上一个结算月
  343. $lastMonth = $period->getLastMonth($sentMaxPeriodNum);
  344. $baseDate = $lastMonth['year'] . '-' . $lastMonth['month'] . '-15';
  345. //是否本月注册会员
  346. if (Status::isMonthJoin($userId, $sentYearMonth)) {
  347. $reConsumeTimes += 2;
  348. } //是否上月注册会员
  349. elseif (Status::isMonthJoin($userId, $lastMonth['yearMonth'])) {
  350. $reConsumeTimes += 1;
  351. } elseif (Status::afterMonthJoin($userId, $sentYearMonth)){
  352. $reConsumeTimes +=Period::getMonthNum($sentMaxPeriodNum,Info::getPeriodNumByUserId($userId));
  353. $reConsumeTimes +=1;
  354. } else {
  355. //是否扣复销
  356. if (!ReconsumePoolFlow::find()->yearMonth($lastMonth['yearMonth'])->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH AND IS_FX_DEDUCT=1', [':USER_ID' => $userId, ':CALC_MONTH' => $lastMonth['yearMonth']])->asArray()->one()) {
  357. //会员过期
  358. if ($reConsumeTimes <= 0) {
  359. //上一次扣复销的时间
  360. if ($flow = ReconsumePoolFlow::find()->select('PERIOD_NUM')->where('USER_ID=:USER_ID AND IS_FX_DEDUCT=1', [':USER_ID' => $userId])->orderBy('PERIOD_NUM DESC')->asArray()->one()) {
  361. $nextMonth = $period->getNextMonth($flow['PERIOD_NUM']);
  362. $overPeriod = Period::getPeriodPointFromMonth($nextMonth['year'], $nextMonth['month']);
  363. $toTime = $overPeriod['END_TIME'];
  364. $toPeriod = Period::getPeriodPointFromMonth($sentYear, $sentMonth);
  365. $toRechargeTime = $toPeriod['END_TIME'];
  366. return [
  367. 'unusedPV' => $pool['UNUSED_PV'],
  368. 'unusedMonth' => $pool['UNUSED_MONTH'],
  369. 'reConsumeTimes' => 0,
  370. 'toTime' => $toTime,
  371. 'toDate' => \date('Y-m-d', $toTime),
  372. 'toRechargeTime' => $toRechargeTime,
  373. 'toRechargeDate' => \date('Y-m-d', $toRechargeTime),
  374. 'isPass' => 0,
  375. ];
  376. } else {
  377. $nextMonth = $period->getNextMonth(Info::getPeriodNumByUserId($userId));
  378. $overPeriod = Period::getPeriodPointFromMonth($nextMonth['year'], $nextMonth['month']);
  379. $toTime = $overPeriod['END_TIME'];
  380. $toPeriod = Period::getPeriodPointFromMonth($sentYear, $sentMonth);
  381. $toRechargeTime = $toPeriod['END_TIME'];
  382. return [
  383. 'unusedPV' => $pool['UNUSED_PV'],
  384. 'unusedMonth' => $pool['UNUSED_MONTH'],
  385. 'reConsumeTimes' => 0,
  386. 'toTime' => $toTime,
  387. 'toDate' => \date('Y-m-d', $toTime),
  388. 'toRechargeTime' => $toRechargeTime,
  389. 'toRechargeDate' => \date('Y-m-d', $toRechargeTime),
  390. 'isPass' => 0,
  391. ];
  392. }
  393. } else {
  394. $baseDate = $lastMonth['year'] . '-' . $lastMonth['month'] . '-15';
  395. }
  396. }else{
  397. $reConsumeTimes += 1;
  398. }
  399. }
  400. }
  401. $calcTime = strtotime("+$reConsumeTimes month", strtotime($baseDate));
  402. //获取toTime结算月最后一期封期时间
  403. $toPeriod = Period::getPeriodFromTime($calcTime);
  404. $periodPoint = Period::getPeriodPointFromMonth($toPeriod['CALC_YEAR'], $toPeriod['CALC_MONTH']);
  405. $toTime = $periodPoint['END_TIME'];
  406. $toDate = $toTime?(\date('Y-m-d', $toTime)):'长期';
  407. $toRechargeTime = $periodPoint['END_TIME'];
  408. $toRechargeDate = $toRechargeTime?(\date('Y-m-d', $toRechargeTime)):'长期';
  409. unset($toPeriod, $toYear, $toMonth, $periodPoint);
  410. return [
  411. 'unusedPV' => $pool['UNUSED_PV'],
  412. 'unusedMonth' => $pool['UNUSED_MONTH'],
  413. 'reConsumeTimes' => $reConsumeTimes,
  414. 'toTime' => $toTime,
  415. 'toDate' => $toDate,
  416. 'toRechargeTime' => $toRechargeTime,
  417. 'toRechargeDate' => $toRechargeDate,
  418. 'isPass' => 1,
  419. ];
  420. }
  421. /**
  422. * 通过用户名获取会员复销池相关
  423. * @param $userName
  424. * @return array
  425. */
  426. public static function getUserReconsumePoolByUserName($userName) {
  427. return self::getUserReconsumePool(Info::getUserIdByUserName($userName));
  428. }
  429. /**
  430. * 不能扣除月复销的月份
  431. * @param $userId
  432. * @param int|null $year
  433. * @return array|\yii\db\ActiveRecord[]
  434. * @throws \yii\db\Exception
  435. */
  436. public static function cantDeductMonth($userId, int $year = null) {
  437. $period = Period::instance();
  438. $sentMaxPeriodNum = Period::sentMaxPeriodNum() + 1;
  439. if ($year === null) {
  440. $year = $period->getYear($sentMaxPeriodNum);
  441. }
  442. $allData = ReconsumePoolFlow::find()->select('CALC_MONTH')->where('USER_ID=:USER_ID AND CALC_MONTH>=:YEAR_START AND CALC_MONTH<=:YEAR_END AND IS_FX_DEDUCT=1', [':USER_ID' => $userId, ':YEAR_START' => intval($year . '01'), ':YEAR_END' => intval($year . '12')])->asArray()->all();
  443. //@190904 会员注册当月及以前都不能扣除
  444. $oneUser = User::find()->select('PERIOD_AT')->where('ID=:USER_ID', [':USER_ID'=>$userId])->asArray()->one();
  445. $period = Period::instance();
  446. $addYear = $period->getYear($oneUser['PERIOD_AT']);
  447. if($addYear==$year){
  448. $addMonth = $period->getMonth($oneUser['PERIOD_AT']);
  449. for($i=1;$i<=$addMonth;$i++){
  450. $allData[] = ['CALC_MONTH'=>$year.Tool::numFix($i, 2)];
  451. }
  452. }
  453. if($year == $period->getYear($sentMaxPeriodNum)){
  454. $sentMonth = $period->getMonth($sentMaxPeriodNum);
  455. for($i=$sentMonth;$i<=12;$i++){
  456. $allData[] = ['CALC_MONTH'=>$year.Tool::numFix($i, 2)];
  457. }
  458. }
  459. return $allData;
  460. }
  461. }