| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace bizHd\promote\services;
- use bizHd\base\services\BaseService;
- use common\components\error;
- use Yii;
- class GuaGuaAttendService extends BaseService
- {
-
- public static $baseFile = '\bizHd\promote\classes\GuaGuaAttendClass';
-
- //确认还有没抽奖机会,如果还有则用户抽奖次数+1 ssh 2019.8.10
- public static function confirmToAddTime($card, $userId, $sjId)
- {
- $id = $card['id'];
- $attend = GuaGuaAttendService::getByCondition(['cardId' => $id, 'userId' => $userId], true);
- if (empty($card['drawCount']) == false && isset($attend->num) && $card['drawCount'] <= $attend->num) {
- error::instance()->setError('你的抽奖次数已经用完了');
- return false;
- }
- if (empty($attend)) {
- //增加抽奖记录
-
- $addTime = time();
- $date = date("Y-m-d H:i:s");
- $data = ['sjId' => $sjId, 'userId' => $userId, 'cardId' => $id, 'num' => 1, 'addTime' => $addTime, 'createTime' => $date];
- self::add($data);
- //参与抽奖人数+1
- $drawUser = $card['drawUser'] + 1;
- GuaGuaService::updateById($id, ['drawUser' => $drawUser]);
- return true;
- }
- $attend->num += 1;
- $attend->save();
- return true;
- }
-
- //获取用户剩余刮卡次数 ssh 2019.8.10
- public static function getRemainNum($card, $userId)
- {
- //-1表示一直可以刮
- if (empty($card['drawCount'])) {
- return -1;
- }
- $id = $card['id'];
- $attend = self::getByCondition(['cardId' => $id, 'userId' => $userId]);
- $usedNum = isset($attend['num']) ? $attend['num'] : 0;
- return ($card['drawCount'] - $usedNum);
- }
-
- }
|