BonusSend.php 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: leo
  5. * Date: 2018/3/18
  6. * Time: 上午11:06
  7. */
  8. namespace common\helpers\bonus;
  9. use common\components\ActiveRecord;
  10. use common\helpers\DataBak;
  11. use common\helpers\Form;
  12. use common\helpers\Tool;
  13. use common\helpers\user\Balance;
  14. use common\helpers\user\Info;
  15. use common\helpers\user\Reconsume;
  16. use common\helpers\user\Status;
  17. use common\libs\api\sms\SmsApi;
  18. use common\libs\swoole\Process;
  19. use common\models\DealType;
  20. use common\models\PerfPeriod;
  21. use common\models\DecOrder;
  22. use common\models\EmployLevel;
  23. use common\models\UserBonus;
  24. use common\models\UserPerfMonthUpdate;
  25. use common\models\UserPeriodPoints;
  26. use common\models\UserWallet;
  27. use common\models\UserInfo;
  28. use common\models\UserPerf;
  29. use common\models\UserPerfUpdate;
  30. use common\models\UserTeamwork;
  31. use common\models\YearHighestEmpLv;
  32. use yii\base\BaseObject;
  33. use yii\base\StaticInstanceTrait;
  34. use common\helpers\Cache;
  35. use common\helpers\Date;
  36. use common\helpers\user\Cash;
  37. use common\models\CalcBonus;
  38. use common\models\CalcBonusBD;
  39. use common\models\CalcBonusBS;
  40. use common\models\CalcBonusGX;
  41. use common\models\CalcBonusQY;
  42. use common\models\CalcBonusTG;
  43. use common\models\FlowBonus;
  44. use common\models\PerfActiveUser;
  45. use common\models\PerfMonth;
  46. use common\models\User;
  47. use Yii;
  48. use common\models\Period;
  49. use common\models\Transfer;
  50. use yii\base\Exception;
  51. use yii\db\Expression;
  52. class BonusSend extends BaseObject {
  53. use StaticInstanceTrait;
  54. private $_limit = 1000;
  55. private $_appUserId = null;
  56. private $_sysConfig = [];
  57. private $_decLevelConfig = [];
  58. private $_empLevelConfig = [];
  59. private $_decRoleConfig = [];
  60. private $_errors = [];
  61. private $_periodNum = 0;
  62. private $_periodId;
  63. private $_isCalcMonth = 0;
  64. private $_isCalcYear = 0;
  65. private $_calcYear;
  66. private $_calcMonth;
  67. private $_calcYearMonth;
  68. private $_lastCalcYear;
  69. private $_lastCalcMonth;
  70. private $_lastCalcYearMonth;
  71. private $_workerId;
  72. private $_workerNum;
  73. public function init(int $periodNum = 0, $appUserId = null, $workerId = null, $workerNum = null) {
  74. parent::init();
  75. $this->_sysConfig = Cache::getSystemConfig();
  76. $this->_decLevelConfig = Cache::getDecLevelConfig();
  77. $this->_empLevelConfig = Cache::getEmpLevelConfig();
  78. $this->_decRoleConfig = CalcCache::getDecRoleConfig($this->_periodNum);
  79. $this->_periodNum = $periodNum;
  80. $this->_appUserId = $appUserId;
  81. $this->_workerId = $workerId;
  82. $this->_workerNum = $workerNum;
  83. }
  84. /**
  85. * 设置期数
  86. * @param int $periodNum
  87. * @return int
  88. */
  89. public function setPeriodNum(int $periodNum) {
  90. return $this->_periodNum = $periodNum;
  91. }
  92. /**
  93. * 获取期数
  94. * @return int
  95. */
  96. public function getPeriodNum() {
  97. return $this->_periodNum;
  98. }
  99. /**
  100. * 加入错误错误
  101. * @param $attr
  102. * @param $error
  103. */
  104. public function addError($attr, $error) {
  105. $this->_errors[$attr][] = $error;
  106. }
  107. /**
  108. * 获取错误信息
  109. * @return array
  110. */
  111. public function getErrors() {
  112. return $this->_errors;
  113. }
  114. /**
  115. * 进行奖金发放步骤
  116. * @return bool
  117. */
  118. public function sendStep() {
  119. try {
  120. $t1 = microtime(true);
  121. // 初始化
  122. $this->initTask();
  123. $t2 = microtime(true);
  124. echo('初始化完成,当前期数【' . $this->_periodNum . '】,耗时:' . round($t2 - $t1, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
  125. // 改变状态
  126. $this->setSendStatus('start');
  127. $t3 = microtime(true);
  128. echo('改变状态完成,耗时:' . round($t3 - $t2, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
  129. $this->_updatePercent(20);
  130. //Yii::$app->db->close();
  131. //Yii::$app->dbShop->close();
  132. // 更新聘级
  133. $this->updateEmpLevel();
  134. $this->_updatePercent(40);
  135. $t4 = microtime(true);
  136. echo('更新聘级完成,耗时:' . round($t4 - $t3, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
  137. // 发放奖金
  138. $this->sendBonusLoop();
  139. $this->_updatePercent(60);
  140. $t5 = microtime(true);
  141. echo('发放奖金完成,耗时:' . round($t5 - $t4, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
  142. // 更新会员上次报单级别
  143. // $this->updateUserDevLv();
  144. // $this->_updatePercent(80);
  145. $t6 = microtime(true);
  146. // echo('更新会员上次报单级别完成,耗时:' . round($t6 - $t5, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
  147. // 更新会员累计业绩
  148. $this->updateUserPerf();
  149. $this->_updatePercent(80);
  150. $t7 = microtime(true);
  151. echo('更新会员累计业绩完成,耗时:' . round($t7 - $t6, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
  152. $this->updateUserPerfMonth();
  153. $this->_updatePercent(90);
  154. $t8 = microtime(true);
  155. echo('更新会员累计月业绩完成,耗时:' . round($t8 - $t7, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
  156. // 更新活跃用户状态,更新为已处理
  157. // $this->updateActiveUser();
  158. // $this->_updatePercent(95);
  159. // $t9 = microtime(true);
  160. // echo('更新会员累计月业绩完成,耗时:' . round($t9 - $t8, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
  161. // 开启子进程去完成下面的循环发放和循环改聘级和循环更新累计业绩
  162. /*$process = new Process('sendBonus', 3);
  163. $process->run(function($workId, $pmid){
  164. $this->processStep($workId);
  165. });
  166. while (true){
  167. if($process->isFinish()) break;
  168. }
  169. unset($process);
  170. $this->_updatePercent(90);
  171. $t4 = microtime(true);
  172. echo('所有子进程的任务完成,耗时:'.round($t4 - $t3, 3).',内存使用:'.(round(memory_get_usage()/1024/1024, 3)).'MB'.PHP_EOL);*/
  173. echo('全部奖金发放完成,耗时:'.round($t7 - $t1, 3).',内存使用:'.(round(memory_get_usage()/1024/1024, 3)).'MB'.PHP_EOL);
  174. $this->_updatePercent(100);
  175. } catch (\Exception $e) {
  176. $this->addError('sendBonus', $e->getMessage());
  177. return false;
  178. }
  179. if (count($this->_errors) > 0) {
  180. return false;
  181. }
  182. return true;
  183. }
  184. /**
  185. * 需要多进程执行的任务
  186. * @param $workId
  187. * @throws \yii\db\Exception
  188. */
  189. public function processStep($workId = null) {
  190. if ($workId == 1 || $workId === null) {
  191. // 发放奖金
  192. $this->sendBonusLoop();
  193. }
  194. if ($workId == 2 || $workId === null) {
  195. // 更新聘级
  196. $this->updateEmpLevel();
  197. }
  198. if ($workId == 3 || $workId === null) {
  199. // 更新会员累计业绩
  200. $this->updateUserPerf();
  201. }
  202. Yii::$app->db->close();
  203. Yii::$app->dbShop->close();
  204. }
  205. /**
  206. * 初始化发放任务
  207. * @throws Exception
  208. */
  209. public function initTask() {
  210. $this->_errors = [];
  211. $periodNum = $this->_periodNum;
  212. // 获取传入期数的相关信息
  213. $periodObj = Period::instance();
  214. $periodDataArr = $periodObj->setPeriodNum($periodNum);
  215. $this->_periodId = $periodDataArr['ID'];
  216. $this->_isCalcMonth = $periodObj->isCalcMonth($periodNum);
  217. $this->_calcYear = $periodObj->getYear($periodNum);
  218. $this->_calcMonth = $periodObj->getMonth($periodNum);
  219. $this->_calcYearMonth = $periodObj->getYearMonth($periodNum);
  220. $lastYearMonthArr = $periodObj->getLastMonth($periodNum);
  221. $this->_lastCalcYear = $lastYearMonthArr['year'];
  222. $this->_lastCalcMonth = $lastYearMonthArr['month'];
  223. $this->_lastCalcYearMonth = $lastYearMonthArr['yearMonth'];
  224. }
  225. /**
  226. * 设置结算状态
  227. * @param $type
  228. * start|end|fail
  229. */
  230. public function setSendStatus($type) {
  231. Yii::$app->db->close();
  232. if ($type == 'start') {
  233. Period::updateAll(['IS_SENDING' => 1, 'SEND_STARTED_AT' => Date::nowTime()], 'PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $this->_periodNum]);
  234. } elseif ($type == 'end') {
  235. Period::updateAll(['IS_SENDING' => 0, 'IS_SENT' => Period::SEND_FINISH, 'SENT_AT' => Date::nowTime()], 'PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $this->_periodNum]);
  236. } elseif ($type == 'fail') {
  237. Period::updateAll(['IS_SENDING' => 0, 'IS_SENT' => Period::SEND_FAIL, 'SENT_AT' => 0], 'PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $this->_periodNum]);
  238. }
  239. }
  240. /**
  241. * 结束计算任务
  242. * @throws \yii\db\Exception
  243. */
  244. public function endTask() {
  245. CalcCache::clearAll($this->_periodNum);
  246. $this->setSendStatus('end');
  247. //@todo 先不备份数据
  248. // DataBak::backup($this->_periodNum);
  249. //发送复销短信
  250. // if ($this->_isCalcMonth && $this->_sysConfig['smsOpen']['VALUE']) {
  251. // $this->sendSmsLoop();
  252. // }
  253. }
  254. /**
  255. * 出现错误
  256. */
  257. public function errorTask() {
  258. $this->setSendStatus('fail');
  259. }
  260. /**
  261. * 发放奖金
  262. * @param int $page
  263. * @return bool
  264. * @throws \yii\db\Exception
  265. */
  266. public function sendBonusLoop($page=1) {
  267. echo sprintf("时间:[%s]数据库发奖,当前page为:【%s】" . PHP_EOL, date('Y-m-d H:i:s', time()), $page);
  268. $periodNum = $this->_periodNum;
  269. // 从奖金结算表中获取当期未发放的所有数据
  270. $allData = CalcBonus::findUseDbCalc()
  271. ->yearMonth($this->_calcYearMonth)
  272. ->where(
  273. '(IS_SENT=0 OR IS_SENT=2) AND CALC_MONTH=:CALC_MONTH AND PERIOD_NUM=:PERIOD_NUM',
  274. [':CALC_MONTH' => $this->_calcYearMonth, ':PERIOD_NUM' => $periodNum]
  275. )
  276. ->limit($this->_limit)
  277. ->asArray()
  278. ->all();
  279. if ($allData) {
  280. $transaction = Yii::$app->db->beginTransaction();
  281. try {
  282. foreach ($allData as $key => $data) {
  283. // 期奖金
  284. // $periodAmount = $data['BONUS_QY'] + $data['BONUS_YC'] + $data['BONUS_XF'] + $data['BONUS_BD'] + $data['BONUS_TG'] + $data['BONUS_YJ'] + $data['BONUS_GX'] + $data['BONUS_GL'];
  285. $periodAmount = $data['BONUS_REAL'];
  286. // 获取本期结算的管理员
  287. // $period = Period::findOneAsArray(['PERIOD_NUM'=>$periodNum]);
  288. // $updateAminId = $period['CALC_ADMIN_ID'];
  289. if ($periodAmount > 0) {
  290. Balance::changeUserBonus($data['USER_ID'], 'bonus', $periodAmount, [
  291. 'CALC_ID' => $data['ID'],
  292. 'REMARK' => 'From ' . $periodNum . '期',
  293. 'PERIOD_NUM' => $periodNum,
  294. 'QY' => $data['BONUS_QY'],
  295. 'FW' => $data['BONUS_FW'],
  296. 'YC' => $data['BONUS_YC'],
  297. 'VIP' => $data['BONUS_VIP'],
  298. 'BD' => $data['BONUS_BD'],
  299. 'TG' => $data['BONUS_TG'],
  300. 'YJ' => $data['BONUS_YJ'],
  301. 'GX' => $data['REAL_BONUS_GX'],
  302. 'GL' => $data['BONUS_GL'],
  303. 'BS' => $data['BONUS_BS'],
  304. 'ST' => $data['BONUS_ST'],
  305. 'ORI_QY' => $data['ORI_BONUS_QY'],
  306. 'ORI_YC' => $data['ORI_BONUS_YC'],
  307. 'ORI_VIP' => $data['ORI_BONUS_VIP'],
  308. 'ORI_STANDARD' => $data['ORI_BONUS_STANDARD'],
  309. 'ORI_BD' => $data['ORI_BONUS_BD'],
  310. 'ORI_TG' => $data['ORI_BONUS_TG'],
  311. 'ORI_YJ' => $data['ORI_BONUS_YJ'],
  312. 'ORI_GX' => $data['ORI_BONUS_GX'],
  313. 'ORI_GL' => $data['ORI_BONUS_GL'],
  314. 'ORI_BS' => $data['ORI_BONUS_BS'],
  315. 'ORI_ST' => $data['ORI_BONUS_ST'],
  316. //'RECONSUME_POINTS_TOTAL' => $data['RECONSUME_POINTS'], 2022/05/17 复消积分,直接发放到余额账户
  317. 'RECONSUME_POINTS_TOTAL' => $data['RECONSUME_POINTS'],
  318. 'EXCHANGE_POINTS_TOTAL' => $data['EXCHANGE_POINTS'],
  319. 'MANAGE_TAX' => $data['MANAGE_TAX'],
  320. 'BONUS_TOTAL' => $data['BONUS_TOTAL'],
  321. 'DEAL_TYPE_ID' => DealType::BONUS_SEND,
  322. 'SORT' => $key * 10,
  323. ]);
  324. // $this->_teamworkBonus($data['USER_ID'], $periodAmount, $key);
  325. }
  326. //发放重消积分
  327. if ($data['RECONSUME_POINTS'] > 0) {
  328. Balance::changeUserBonus($data['USER_ID'], 'reconsume_points', $data['RECONSUME_POINTS'], [
  329. 'CALC_ID' => $data['ID'],
  330. 'REMARK' => 'From ' . $periodNum . '期',
  331. 'PERIOD_NUM' => $periodNum,
  332. 'RECONSUME_POINTS' => $data['RECONSUME_POINTS'],
  333. 'DEAL_TYPE_ID' => DealType::RECONSUME_POINTS_SEND,
  334. ]);
  335. // 2022/05/17 复消积分,直接发放到余额账户
  336. // Cash::changeUserCash(
  337. // $data['USER_ID'],
  338. // 'CASH',
  339. // abs($data['RECONSUME_POINTS']),
  340. // [
  341. // 'TRANSFER_SN' => Transfer::generateSN(),
  342. // 'DEAL_TYPE_ID' => DealType::BONUS_SEND,
  343. // 'REMARK' => '复销点数发放'
  344. // ]
  345. // );
  346. }
  347. //发放兑换积分
  348. if ($data['EXCHANGE_POINTS'] > 0) {
  349. Balance::changeUserBonus($data['USER_ID'], 'exchange_points', $data['EXCHANGE_POINTS'], [
  350. 'CALC_ID' => $data['ID'],
  351. 'REMARK' => 'From ' . $periodNum . '期',
  352. 'PERIOD_NUM' => $periodNum,
  353. 'EXCHANGE_POINTS' => $data['EXCHANGE_POINTS'],
  354. 'DEAL_TYPE_ID' => DealType::EXCHANGE_POINTS_SEND,
  355. ]);
  356. }
  357. // 把记录标记为已发放状态
  358. CalcBonus::updateAll(['IS_SENT' => 1, 'SENT_AT' => Date::nowTime()], 'ID=:ID', [':ID' => $data['ID']]);
  359. unset($periodAmount, $key, $data);
  360. }
  361. $transaction->commit();
  362. } catch (Exception $e) {
  363. $transaction->rollBack();
  364. $this->addError('sendBonus', '奖金发放失败,原因:' . $e->getMessage());
  365. return false;
  366. }
  367. unset($allData, $transaction);
  368. $page++;
  369. return $this->sendBonusLoop($page);
  370. }
  371. unset($allData);
  372. return true;
  373. }
  374. /**
  375. * 蓝星奖金(即新的管理奖),更新会员聘级
  376. * @param int $offset
  377. * @return bool
  378. * @throws \yii\db\Exception
  379. */
  380. public function updateEmpLevel(int $offset = 0) {
  381. if ($this->_isCalcMonth) {
  382. $empLv = EmployLevel::getIdConvertLevelSortCache();
  383. $allData = CalcBonusBS::findUseDbCalc()
  384. ->yearMonth($this->_calcYearMonth)
  385. ->where(
  386. 'CALC_MONTH=:CALC_MONTH AND PERIOD_NUM=:PERIOD_NUM',
  387. [
  388. ':CALC_MONTH' => $this->_calcYearMonth,
  389. ':PERIOD_NUM' =>$this->_periodNum
  390. ]
  391. )
  392. ->orderBy('CREATED_AT DESC')
  393. ->groupBy('USER_ID')
  394. ->offset($offset)
  395. ->limit($this->_limit)
  396. ->all();
  397. //@todo 用户级别不变则不更新
  398. $defaultEmpLv = EmployLevel::getDefaultLevelId();
  399. if ($allData) {
  400. $transaction = Yii::$app->db->beginTransaction();
  401. try {
  402. foreach ($allData as $data) {
  403. //@todo 用户级别不变则不更新
  404. if( $data['LEVEL_ID'] === $defaultEmpLv ) continue;
  405. $nowBsEmpLv = $data['LEVEL_ID']; // 当前蓝星奖计算(即管理奖) 的等级
  406. $user = CalcCache::getUserInfo($data['USER_ID'], $this->_periodNum);
  407. $userEmpLv = $user['EMP_LV']; // 用户的历史最高聘级
  408. $userEmpLvSort = $empLv[$userEmpLv]; // 历史最高聘级的 级别值
  409. $nowBsEmpLvSort = $empLv[$nowBsEmpLv]; // 当前蓝星计算的聘级 级别值
  410. if ($nowBsEmpLvSort > $userEmpLvSort) {
  411. // 如果当前期的级别值大于历史最高级别,则更新用户表里的最高聘级
  412. User::updateAll(['EMP_LV' => $data['LEVEL_ID']], 'ID=:USER_ID', [':USER_ID' => $data['USER_ID']]);
  413. User::deleteBaseInfoFromRedis($data['USER_ID']);
  414. unset($data);
  415. } else {
  416. continue;
  417. }
  418. }
  419. $transaction->commit();
  420. } catch (Exception $e) {
  421. $transaction->rollBack();
  422. $this->addError('updateEmpLevel', '更新聘级失败,原因:' . $e->getMessage());
  423. return false;
  424. }
  425. unset($transaction, $allData, $defaultEmpLv);
  426. return $this->updateEmpLevel($offset + $this->_limit);
  427. }
  428. unset($allData);
  429. }
  430. return true;
  431. }
  432. // /**
  433. // * 更新会员聘级
  434. // * @param int $offset
  435. // * @return bool
  436. // * @throws \yii\db\Exception
  437. // */
  438. // public function updateEmpLevel(int $offset = 0) {
  439. // if ($this->_isCalcMonth) {
  440. // $allData = PerfMonth::findUseDbCalc()->yearMonth($this->_calcYearMonth)->where('CALC_MONTH=:CALC_MONTH', [':CALC_MONTH' => $this->_calcYearMonth])->offset($offset)->limit($this->_limit)->all();
  441. // //@todo 用户级别不变则不更新
  442. // $defaultEmpLv = EmployLevel::getDefaultLevelId();
  443. // if ($allData) {
  444. // $transaction = Yii::$app->db->beginTransaction();
  445. // try {
  446. // foreach ($allData as $data) {
  447. // //@todo 用户级别不变则不更新
  448. // if( $data['LAST_EMP_LV'] === $defaultEmpLv ) continue;
  449. // User::updateAll(['EMP_LV' => $data['LAST_EMP_LV']], 'ID=:USER_ID', [':USER_ID' => $data['USER_ID']]);
  450. // User::deleteBaseInfoFromRedis($data['USER_ID']);
  451. // unset($data);
  452. // }
  453. // $transaction->commit();
  454. // } catch (Exception $e) {
  455. // $transaction->rollBack();
  456. // $this->addError('updateEmpLevel', '更新聘级失败,原因:' . $e->getMessage());
  457. // return false;
  458. // }
  459. // unset($transaction, $allData, $defaultEmpLv);
  460. // return $this->updateEmpLevel($offset + $this->_limit);
  461. // }
  462. // unset($allData);
  463. // }
  464. // return true;
  465. // }
  466. // 更活跃会员,将is_send改成1
  467. public function updateActiveUser() {
  468. try {
  469. $ret = PerfActiveUser::updateAll(
  470. ['IS_SENT' => 1],
  471. 'PERIOD_NUM=:PERIOD_NUM AND IS_SENT=:IS_SENT',
  472. ['IS_SENT'=>0, 'PERIOD_NUM'=>$this->_periodNum]
  473. );
  474. return $ret;
  475. } catch(Exception $e) {
  476. $this->addError('updateActiveUser', '更新活跃会员业绩期处理状态失败,原因:' . $e->getMessage());
  477. return false;
  478. }
  479. }
  480. /**
  481. * 更新会员的累计业绩
  482. * @param int $offset
  483. * @return bool
  484. * @throws \yii\db\Exception
  485. */
  486. public function updateUserPerf(int $offset = 0) {
  487. $allData = PerfPeriod::findUseDbCalc()->yearMonth($this->_calcYearMonth)->where('PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $this->_periodNum])->orderBy('ID ASC')->offset($offset)->limit($this->_limit)->all();
  488. if ($allData) {
  489. $transaction = Yii::$app->db->beginTransaction();
  490. try {
  491. foreach ($allData as $data) {
  492. $isUpdate = false;
  493. if (UserPerf::findUseDbCalc()->where('USER_ID=:USER_ID', [':USER_ID' => $data['USER_ID']])->exists()) {
  494. // 判断本期是否已经更新过业绩
  495. if (!UserPerfUpdate::findUseDbCalc()->yearMonth($this->_calcYearMonth)->where('USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', [':USER_ID' => $data['USER_ID'], ':PERIOD_NUM' => $this->_periodNum])->exists()) {
  496. $isUpdate = true;
  497. // 更新业绩
  498. UserPerf::updateAll([
  499. 'PV_PCS_ZC' => new Expression('PV_PCS_ZC+' . $data['PV_PCS_ZC']),
  500. 'PV_PCS_YH' => new Expression('PV_PCS_YH+' . $data['PV_PCS_YH']),
  501. 'PV_PCS_ZG' => new Expression('PV_PCS_ZG+' . $data['PV_PCS_ZG']),
  502. 'PV_PCS_LS' => new Expression('PV_PCS_LS+' . $data['PV_PCS_LS']),
  503. 'PV_PCS_FX' => new Expression('PV_PCS_FX+' . $data['PV_PCS_FX']),
  504. 'PV_PSS' => new Expression('PV_PSS+' . $data['PV_PSS']),
  505. 'PV_PSS_TOTAL' => new Expression('PV_PSS_TOTAL+' . $data['PV_PSS']),
  506. 'PV_1L' => new Expression('PV_1L+' . $data['PV_1L']),
  507. 'PV_2L' => new Expression('PV_2L+' . $data['PV_2L']),
  508. 'PV_3L' => new Expression('PV_3L+' . $data['PV_3L']),
  509. 'PV_4L' => new Expression('PV_4L+' . $data['PV_4L']),
  510. 'PV_5L' => new Expression('PV_5L+' . $data['PV_5L']),
  511. 'SURPLUS_1L' => $data['SURPLUS_1L'],
  512. 'SURPLUS_2L' => $data['SURPLUS_2L'],
  513. 'SURPLUS_3L' => $data['SURPLUS_3L'],
  514. 'SURPLUS_4L' => $data['SURPLUS_4L'],
  515. 'SURPLUS_5L' => $data['SURPLUS_5L'],
  516. 'SURPLUS_1L_ZC' => $data['SURPLUS_1L_ZC'],
  517. 'SURPLUS_2L_ZC' => $data['SURPLUS_2L_ZC'],
  518. 'SURPLUS_3L_ZC' => $data['SURPLUS_3L_ZC'],
  519. 'SURPLUS_4L_ZC' => $data['SURPLUS_4L_ZC'],
  520. 'SURPLUS_5L_ZC' => $data['SURPLUS_5L_ZC'],
  521. 'SURPLUS_1L_FX' => $data['SURPLUS_1L_FX'],
  522. 'SURPLUS_2L_FX' => $data['SURPLUS_2L_FX'],
  523. 'SURPLUS_3L_FX' => $data['SURPLUS_3L_FX'],
  524. 'SURPLUS_4L_FX' => $data['SURPLUS_4L_FX'],
  525. 'SURPLUS_5L_FX' => $data['SURPLUS_5L_FX'],
  526. ], 'USER_ID=:USER_ID', [':USER_ID' => $data['USER_ID']]);
  527. }
  528. } else {
  529. $isUpdate = true;
  530. UserPerf::insertOne([
  531. 'USER_ID' => $data['USER_ID'],
  532. 'PV_PCS_ZC' => $data['PV_PCS_ZC'],
  533. 'PV_PCS_YH' => $data['PV_PCS_YH'],
  534. 'PV_PCS_ZG' => $data['PV_PCS_ZG'],
  535. 'PV_PCS_LS' => $data['PV_PCS_LS'],
  536. 'PV_PCS_FX' => $data['PV_PCS_FX'],
  537. 'PV_PSS' => $data['PV_PSS'],
  538. 'PV_PSS_TOTAL' => $data['PV_PSS'],
  539. 'PV_1L' => $data['PV_1L'],
  540. 'PV_2L' => $data['PV_2L'],
  541. 'PV_3L' => $data['PV_3L'],
  542. 'PV_4L' => $data['PV_4L'],
  543. 'PV_5L' => $data['PV_5L'],
  544. 'SURPLUS_1L' => $data['SURPLUS_1L'],
  545. 'SURPLUS_2L' => $data['SURPLUS_2L'],
  546. 'SURPLUS_3L' => $data['SURPLUS_3L'],
  547. 'SURPLUS_4L' => $data['SURPLUS_4L'],
  548. 'SURPLUS_5L' => $data['SURPLUS_5L'],
  549. 'SURPLUS_1L_ZC' => $data['SURPLUS_1L_ZC'],
  550. 'SURPLUS_2L_ZC' => $data['SURPLUS_2L_ZC'],
  551. 'SURPLUS_3L_ZC' => $data['SURPLUS_3L_ZC'],
  552. 'SURPLUS_4L_ZC' => $data['SURPLUS_4L_ZC'],
  553. 'SURPLUS_5L_ZC' => $data['SURPLUS_5L_ZC'],
  554. 'SURPLUS_1L_FX' => $data['SURPLUS_1L_FX'],
  555. 'SURPLUS_2L_FX' => $data['SURPLUS_2L_FX'],
  556. 'SURPLUS_3L_FX' => $data['SURPLUS_3L_FX'],
  557. 'SURPLUS_4L_FX' => $data['SURPLUS_4L_FX'],
  558. 'SURPLUS_5L_FX' => $data['SURPLUS_5L_FX'],
  559. 'CREATED_AT' => Date::nowTime(),
  560. ]);
  561. }
  562. if ($isUpdate) {
  563. // 变为已更新
  564. UserPerfUpdate::insertOne(['USER_ID' => $data['USER_ID'], 'PERIOD_NUM' => $this->_periodNum, 'P_CALC_MONTH' => Date::ociToDate($this->_calcYearMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH), 'CREATED_AT' => Date::nowTime()]);
  565. }
  566. unset($data, $isUpdate);
  567. }
  568. $transaction->commit();
  569. } catch (Exception $e) {
  570. $transaction->rollBack();
  571. $this->addError('updateUserPerf', '更新会员业绩失败,原因:' . $e->getMessage());
  572. return false;
  573. }
  574. unset($allData, $transaction);
  575. return $this->updateUserPerf($offset + $this->_limit);
  576. }
  577. unset($allData);
  578. return true;
  579. }
  580. /**
  581. * 更新会员的月剩余业绩
  582. * @param int $offset
  583. * @return bool
  584. * @throws \yii\db\Exception
  585. */
  586. public function updateUserPerfMonth(int $offset = 0) {
  587. // 月结,如果不是月结点,则直接退出
  588. if (!$this->_isCalcMonth) {
  589. return true;
  590. }
  591. $allData = PerfMonth::findUseDbCalc()->where('CALC_MONTH=:CALC_MONTH', [':CALC_MONTH' => $this->_calcYearMonth])->orderBy('ID ASC')->offset($offset)->limit($this->_limit)->all();
  592. if ($allData) {
  593. $transaction = Yii::$app->db->beginTransaction();
  594. try {
  595. foreach ($allData as $data) {
  596. $isUpdate = false;
  597. if (UserPerf::findUseDbCalc()->where('USER_ID=:USER_ID', [':USER_ID' => $data['USER_ID']])->exists()) {
  598. // 判断本期是否已经更新过业绩
  599. if (!UserPerfMonthUpdate::findUseDbCalc()->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH', [':USER_ID' => $data['USER_ID'], ':CALC_MONTH' => $this->_calcYearMonth])->exists()) {
  600. $isUpdate = true;
  601. // 更新业绩
  602. UserPerf::updateAll([
  603. 'VIP_SURPLUS_1L_ZC' => $data['VIP_SURPLUS_1L_ZC'],
  604. 'VIP_SURPLUS_2L_ZC' => $data['VIP_SURPLUS_2L_ZC'],
  605. 'VIP_SURPLUS_3L_ZC' => $data['VIP_SURPLUS_3L_ZC'],
  606. 'VIP_SURPLUS_4L_ZC' => $data['VIP_SURPLUS_4L_ZC'],
  607. 'VIP_SURPLUS_5L_ZC' => $data['VIP_SURPLUS_5L_ZC']
  608. ], 'USER_ID=:USER_ID', [':USER_ID' => $data['USER_ID']]);
  609. }
  610. } else {
  611. $isUpdate = true;
  612. UserPerf::insertOne([
  613. 'USER_ID' => $data['USER_ID'],
  614. 'VIP_SURPLUS_1L_ZC' => $data['VIP_SURPLUS_1L_ZC'],
  615. 'VIP_SURPLUS_2L_ZC' => $data['VIP_SURPLUS_2L_ZC'],
  616. 'VIP_SURPLUS_3L_ZC' => $data['VIP_SURPLUS_3L_ZC'],
  617. 'VIP_SURPLUS_4L_ZC' => $data['VIP_SURPLUS_4L_ZC'],
  618. 'VIP_SURPLUS_5L_ZC' => $data['VIP_SURPLUS_5L_ZC'],
  619. 'CREATED_AT' => Date::nowTime(),
  620. ]);
  621. }
  622. if ($isUpdate) {
  623. // 变为已更新
  624. UserPerfMonthUpdate::insertOne(['USER_ID' => $data['USER_ID'], 'CALC_MONTH' => $this->_calcYearMonth, 'CREATED_AT' => Date::nowTime()]);
  625. }
  626. unset($data, $isUpdate);
  627. }
  628. $transaction->commit();
  629. } catch (Exception $e) {
  630. $transaction->rollBack();
  631. $this->addError('updateUserPerf', '更新会员月业绩失败,原因:' . $e->getMessage());
  632. return false;
  633. }
  634. unset($allData, $transaction);
  635. return $this->updateUserPerfMonth($offset + $this->_limit);
  636. }
  637. unset($allData);
  638. return true;
  639. }
  640. /**
  641. * 检测复消积分是否过期
  642. * @return bool
  643. * @throws \yii\db\Exception
  644. */
  645. public function checkReconsumePointsExpired(int $offset = 0) {
  646. $periodNum = $this->_periodNum;
  647. //一期为7天,那么365天为52.14即53期
  648. $expiredPeriodNum = $periodNum - 53;
  649. if( $expiredPeriodNum <= 0 ) return true;
  650. //查询需要过期的期数
  651. $allData = UserPeriodPoints::find()->select('ID,USER_ID,REMAINDER_POINTS')->where('PERIOD_NUM<=:PERIOD_NUM AND EXPIRED=0', ['PERIOD_NUM'=>$expiredPeriodNum])->orderBy('ID ASC')->offset($offset)->limit($this->_limit)->asArray()->all();
  652. if( $allData ) {
  653. $transaction = Yii::$app->db->beginTransaction();
  654. try{
  655. //扣除钱包的复消积分
  656. foreach ($allData as $everyData) {
  657. //过期
  658. UserPeriodPoints::updateAll([
  659. 'REMAINDER_POINTS' => 0,
  660. 'EXPIRED' => 1,
  661. 'EXPIRED_PERIOD' => $periodNum,
  662. 'EXPIRED_AT' => Date::nowTime(),
  663. ], 'ID=:ID', ['ID'=>$everyData['ID']]);
  664. if( !isset($everyData['REMAINDER_POINTS']) || !$everyData['REMAINDER_POINTS'] ) continue;
  665. UserBonus::updateAllCounters([
  666. 'RECONSUME_POINTS' => (-1) * $everyData['REMAINDER_POINTS'],
  667. ], 'USER_ID=:USER_ID', $everyData['USER_ID']);
  668. unset($everyData);
  669. }
  670. unset($periodNum, $expiredPeriodNum, $allData);
  671. $transaction->commit();
  672. }catch (\Exception $e){
  673. $transaction->rollBack();
  674. $this->addError('checkReconsumePointsExpired', '检测过期在复消积分失败,原因:' . $e->getMessage());
  675. return false;
  676. }
  677. return $this->checkReconsumePointsExpired($offset + $this->_limit);
  678. }
  679. unset($allData);
  680. return true;
  681. }
  682. /**
  683. * 更新会员上次报单级别
  684. * @return bool
  685. */
  686. public function updateUserDevLv() {
  687. $transaction = Yii::$app->dbShop->beginTransaction();
  688. try {
  689. \Yii::$app->dbShop->createCommand()->update(User::tableName(), ['LAST_DEC_LV' => new Expression('DEC_LV'), 'LAST_DEC_LV_UPDATED_AT' => Date::nowTime(), 'LAST_DEC_LV_UPDATED_PERIOD' => $this->_periodNum], 'LAST_DEC_LV!=DEC_LV')->execute();
  690. $transaction->commit();
  691. } catch (Exception $e) {
  692. $transaction->rollBack();
  693. $this->addError('updateUserDevLv', '更新会员上次报单级别失败,原因:' . $e->getMessage());
  694. return false;
  695. }
  696. return true;
  697. }
  698. /**
  699. * 给商城会员增加货款
  700. * @param $userId
  701. * @param $amount
  702. * @param $remark
  703. * @throws Exception
  704. */
  705. private function _shopAddPaymentForGoods($userId, $amount, $remark) {
  706. $db = \Yii::$app->dbShop;
  707. $transaction = $db->beginTransaction();
  708. try {
  709. ActiveRecord::batchUpdate(['PAYMENT_FOR_GOODS' => new Expression('PAYMENT_FOR_GOODS+' . abs($amount))], 'USER_ID=:USER_ID', [':USER_ID' => $userId], '{{%USER_WALLET}}', 'dbShop');
  710. // 增加流水
  711. $flowInsertData[] = [
  712. 'USER_ID' => $userId,
  713. 'USER_NAME' => Cache::getUserBaseInfo($userId)['USER_NAME'],
  714. 'DEC_LV' => Cache::getUserBaseInfo($userId)['DEC_LV'],
  715. 'ORDER_SN' => null,
  716. 'AMOUNT' => $amount,
  717. 'CREATED_AT' => Date::nowTime(),
  718. 'PERIOD_AT' => $this->_periodNum,
  719. 'IS_INCR' => 1,
  720. 'REMARK' => $remark,
  721. 'PARTITION_DATE' => Date::ociToDate(),
  722. 'WALLET_TYPE' => 'payment_for_goods',
  723. 'FROM_TYPE' => 'incr',
  724. ];
  725. ActiveRecord::batchInsert($flowInsertData, '{{%FLOW_WALLET}}', 'dbShop');
  726. $transaction->commit();
  727. } catch (Exception $e) {
  728. $transaction->rollBack();
  729. throw new Exception($e->getMessage());
  730. }
  731. }
  732. /**
  733. * 更新百分比并发送
  734. * @param $percent
  735. */
  736. private function _updatePercent($percent) {
  737. // 把数据写入数据库中
  738. Period::updateAll(['SENT_PERCENT' => $percent], 'PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $this->_periodNum]);
  739. \Yii::$app->swooleAsyncTimer->pushAsyncPercentToAdmin($percent, ['MODEL' => 'PERIOD', 'ID' => $this->_periodId, 'FIELD' => 'SENT_PERCENT']);
  740. }
  741. /**
  742. * 更新最高聘级
  743. * @param $user_id
  744. * @return bool
  745. * @throws Exception
  746. */
  747. private function _updateHighestEmpLv($user_id) {
  748. $empLv = Info::getEmpLv($user_id);
  749. $highEmpLv = Info::getHighEmpLv($user_id);
  750. $empLvSort = EmployLevel::getSortById($empLv);
  751. $empLvHighSort = EmployLevel::getSortById($highEmpLv);
  752. if ($empLvHighYear = YearHighestEmpLv::findOneAsArray('USER_ID=:USER_ID AND YEAR=:YEAR', [':USER_ID' => $user_id, ':YEAR' => $this->_calcYear], 'HIGHEST_EMP_LV_SORT')) {
  753. if ($empLvSort > $empLvHighYear['HIGHEST_EMP_LV_SORT']) {
  754. YearHighestEmpLv::updateAll(['HIGHEST_EMP_LV' => $empLv, 'HIGHEST_EMP_LV_SORT' => $empLvSort, 'HIGHEST_EMP_LV_PERIOD' => $this->_periodNum, 'UPDATED_AT' => Date::nowTime()], 'USER_ID=:USER_ID AND YEAR=:YEAR', [':USER_ID' => $user_id, ':YEAR' => $this->_calcYear]);
  755. }
  756. } else {
  757. $yearHighest = new YearHighestEmpLv();
  758. $yearHighest->USER_ID = $user_id;
  759. $yearHighest->YEAR = $this->_calcYear;
  760. $yearHighest->HIGHEST_EMP_LV = $empLv;
  761. $yearHighest->HIGHEST_EMP_LV_SORT = $empLvSort;
  762. $yearHighest->HIGHEST_EMP_LV_PERIOD = $this->_periodNum;
  763. $yearHighest->CREATED_AT = Date::nowTime();
  764. if (!$yearHighest->save()) {
  765. throw new \yii\db\Exception(Form::formatErrorsForApi($yearHighest->getErrors()));
  766. }
  767. }
  768. if ($empLvSort > $empLvHighSort) {
  769. UserInfo::updateAll(['HIGHEST_EMP_LV' => $empLv, 'HIGHEST_EMP_LV_PERIOD' => $this->_periodNum], 'USER_ID=:USER_ID', [':USER_ID' => $user_id]);
  770. //发送历史最高聘级短信
  771. if($this->_sysConfig['smsEmpOpen']['VALUE']){
  772. if(in_array($empLvSort,explode(",",$this->_sysConfig['smsEmp']['VALUE']))){
  773. $realName = Info::getUserRealNameByUserId($user_id);
  774. $empLvDate = Date::convert();
  775. $empLvName = EmployLevel::getNameById($empLv);
  776. $content = str_replace(['{%REAL_NAME%}', '{%EMP_LV_DATE%}', '{%EMP_LV%}'], [$realName, $empLvDate, $empLvName], $this->_sysConfig['smsContent']['VALUE']);
  777. $params = [
  778. 'mobiles' => Info::getUserMobileByUserId($user_id),
  779. 'content' => $content,
  780. ];
  781. SmsApi::instance()->clearError();
  782. SmsApi::instance()->goSend($params);
  783. }
  784. }
  785. return true;
  786. }
  787. return false;
  788. }
  789. /**
  790. * 点位合作奖金
  791. * @param $userId
  792. * @param $amount
  793. * @param null $type
  794. * @return bool
  795. * @throws Exception
  796. * @throws \yii\db\Exception
  797. */
  798. private function _teamworkBonus($userId, $amount, $key) {
  799. if (!$teamwork = UserTeamwork::findAllAsArray('USER_ID!=:MAIN_UID AND MAIN_UID=:MAIN_UID AND IS_DEL=0', [':MAIN_UID' => $userId], 'USER_ID,DIVIDE_PERCENT')) return false;
  800. $fromUserInfo = CalcCache::getUserInfo($userId, $this->_periodNum);
  801. foreach ($teamwork as $value) {
  802. $bonus = Tool::formatPrice($amount * $value['DIVIDE_PERCENT'] * 0.01);
  803. if ($bonus <= 0) continue;
  804. $toUserInfo = CalcCache::getUserInfo($value['USER_ID'], $this->_periodNum);
  805. Balance::changeUserBonus($userId, 'bonus', -abs($bonus), ['SORT' => $key*10+1, 'DEAL_TYPE_ID' => DealType::TEAMWORK_TRANSFER_OUT, 'REMARK' => 'To:' . $toUserInfo['USER_NAME'] . ' Per:' . $value['DIVIDE_PERCENT'] . '%']);
  806. Balance::changeUserBonus($value['USER_ID'], 'bonus', abs($bonus), ['SORT' => $key*10+2, 'DEAL_TYPE_ID' => DealType::TEAMWORK_TRANSFER_IN, 'REMARK' => 'From: ' . $fromUserInfo['USER_NAME'] . ' Per:' . $value['DIVIDE_PERCENT'] . '%']);
  807. }
  808. }
  809. /**
  810. * 发送短信
  811. * @param int $offset
  812. * @return bool
  813. * @throws \yii\db\Exception
  814. */
  815. public function sendSmsLoop(int $offset = 0) {
  816. $allData = UserInfo::findUseDbCalc()->select('USER_ID,ALLOW_RECONSUME_SMS_TO')->where('ALLOW_RECONSUME_SMS=1')->offset($offset)->limit($this->_limit)->all();
  817. if ($allData) {
  818. $smsWallet = explode(",", $this->_sysConfig['smsWallet']['VALUE']);
  819. $smsFee = $this->_sysConfig['smsFee']['VALUE'];
  820. //获取剩余月份
  821. $period = Period::instance();
  822. $year = $period->getYear($this->_periodNum);
  823. $monthLeft = Period::getMonthLeft($this->_periodNum);
  824. $smsFee = Tool::formatPrice($smsFee * $monthLeft);
  825. $to = Date::yearEnd();
  826. $transaction = Yii::$app->db->beginTransaction();
  827. try {
  828. foreach ($allData as $data) {
  829. $userId = $data['USER_ID'];
  830. //过期续费
  831. if ($data['ALLOW_RECONSUME_SMS_TO'] < Date::nowTime()) {
  832. foreach ($smsWallet as $item) {
  833. //1奖金钱包2现金钱包
  834. if ($item == 1) {
  835. //看余额是否充足
  836. if (Balance::getAvailableBalance($userId) < $smsFee){
  837. UserInfo::updateAll(['ALLOW_RECONSUME_SMS' => 0], 'USER_ID=:USER_ID', [':USER_ID' => $userId]);
  838. continue;
  839. };
  840. Balance::changeUserBonus($userId, 'bonus', -abs($smsFee), ['DEAL_TYPE_ID' => DealType::SMS, 'REMARK' => $year . '年复销提醒短信服务费'], false);
  841. UserInfo::updateAll(['ALLOW_RECONSUME_SMS_TO' => $to], 'USER_ID=:USER_ID', [':USER_ID' => $userId]);
  842. $data['ALLOW_RECONSUME_SMS_TO'] = $to;
  843. break;
  844. } elseif ($item == 2) {
  845. throw new Exception('不存在此方式');
  846. break;
  847. }
  848. }
  849. }
  850. if ($data['ALLOW_RECONSUME_SMS_TO'] > Date::nowTime() && $mobile = Info::getUserMobileByUserId($userId)) {
  851. $realName = Info::getUserRealNameByUserId($userId);
  852. $reconsumPool = Reconsume::getUserReconsumePool($userId);
  853. $lastRechargeDate = $reconsumPool['toRechargeDate'];
  854. $isPass = $reconsumPool['isPass'] == 1 ? '合格' : '不合格';
  855. $month = $period->getNowMonth();
  856. $content = str_replace(['{%REAL_NAME%}', '{%LAST_RECHARGE_DATE%}', '{%MONTH%}', '{%IS_PASS%}'], [$realName, $lastRechargeDate, $month, $isPass], $this->_sysConfig['smsContent']['VALUE']);
  857. //todo 发短信函数 待测试
  858. $params = [
  859. 'mobiles' => $mobile,
  860. 'content' => $content,
  861. ];
  862. SmsApi::instance()->clearError();
  863. SmsApi::instance()->goSend($params);
  864. }
  865. unset($userId,$mobile,$realName,$reconsumPool,$lastRechargeDate,$isPass,$month,$content);
  866. }
  867. $transaction->commit();
  868. } catch (Exception $e) {
  869. $transaction->rollBack();
  870. return false;
  871. }
  872. unset($data);
  873. return $this->sendSmsLoop($offset + $this->_limit);
  874. }
  875. unset($allData);
  876. return true;
  877. }
  878. }