1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace app\admin\controller\ump;
- use app\admin\controller\AuthController;
- use app\models\user\User;
- use app\models\user\UserBill;
- use crmeb\services\UtilService as Util;
- use app\admin\model\user\UserPoint as UserPointModel;
- use think\facade\Route as Url;
- use crmeb\services\JsonService;
- /**
- * 优惠券控制器
- * Class StoreCategory
- * @package app\admin\controller\system
- */
- class Gacha extends AuthController
- {
- /**
- * @return mixed
- */
- public function index()
- {
- return $this->fetch();
- }
- public function gacha_list()
- {
- $where = Util::getMore([
- ['status', ''],
- ['page', 1],
- ['limit', 10],
- ]);
- JsonService::successlayui(\app\models\user\Gacha::getList($where));
- }
- public function deal($id)
- {
- $orderInfo = \app\models\user\Gacha::where('id', $id)->where('status', 0)->where('limit_time', '>=', time())->find();
- if (!$orderInfo) return app('json')->fail('核销的奖品不存在或已兑换或已过期');
- \app\models\user\Gacha::beginTrans();
- try {
- if ($orderInfo['award_type'] == 1) {
- User::bcInc($orderInfo['uid'], 'integral', $orderInfo['award'], 'uid');
- UserBill::expend('抽奖奖品', $orderInfo['uid'], 'integral', 'gacha_get', $orderInfo['award'], $orderInfo['id'], User::where('uid', $orderInfo['uid'])->value('integral'), '抽奖奖品兑换');
- }
- $orderInfo->status = 1;
- if ($orderInfo->save()) {
- \app\models\user\Gacha::commitTrans();
- return app('json')->success('核销成功');
- } else {
- \app\models\user\Gacha::rollbackTrans();
- return app('json')->fail('核销失败');
- }
- } catch (\Exception $e) {
- \app\models\user\Gacha::rollbackTrans();
- return app('json')->fail($e->getMessage());
- }
- }
- }
|