|
@@ -19,7 +19,8 @@ class Eggnew extends Api
|
|
|
* 获取本期奖池列表
|
|
|
*/
|
|
|
public function getThisJackpot() {
|
|
|
- $jackId = \app\common\model\EggJackpot::where(["status"=>1])->value("id");
|
|
|
+ $type = input('type',1);
|
|
|
+ $jackId = \app\common\model\EggJackpot::where(["status"=>1,'type'=>$type])->value("id");
|
|
|
$egggiftModel = new \app\common\model\EggGift();
|
|
|
$where = [];
|
|
|
$where["Jackpot_id"] = $jackId;
|
|
@@ -28,90 +29,12 @@ class Eggnew extends Api
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 购买锤子
|
|
|
- */
|
|
|
- public function buyHammer() {
|
|
|
- // 接口防并发
|
|
|
- if (!$this->apiLimit(1, 2000)) {
|
|
|
- $this->error(__('Operation frequently'));
|
|
|
- }
|
|
|
-
|
|
|
- $num = $this->request->request("num");
|
|
|
- if($num <=0) {
|
|
|
- $this->error("购买数量不能小于0!");
|
|
|
- }
|
|
|
- $user_id = $this->auth->id;
|
|
|
- $hammerPrice = config("site.hammerPrice");
|
|
|
- if($hammerPrice <=0) {
|
|
|
- $this->error("系统配置出错!");
|
|
|
- }
|
|
|
- $userModel = new \app\common\model\User;
|
|
|
- $userInfo = $userModel->where('id',$user_id)->lock(true)->find();
|
|
|
-
|
|
|
- $money = $hammerPrice*$num;
|
|
|
- // 判断用户钻石余额是否充足
|
|
|
- if($userInfo->jewel < $money) {
|
|
|
- $this->error("您的钻石余额不足!",null,100);
|
|
|
- }
|
|
|
-
|
|
|
- $userjewellogModel = new \app\common\model\UserJewelLog();
|
|
|
- Db::startTrans();
|
|
|
- try{
|
|
|
- $userjewel = $userInfo->jewel;
|
|
|
- // 添加购买订单
|
|
|
- $data = [];
|
|
|
- $data["user_id"] = $user_id;
|
|
|
- $data["price"] = $hammerPrice;
|
|
|
- $data["number"] = $num;
|
|
|
- $data["money"] = $money;
|
|
|
- $data["createtime"] = time();
|
|
|
- $res1 = \app\common\model\EggOrder::insert($data);
|
|
|
- // 为用户增加锤子
|
|
|
- $res2 = $userInfo->setInc("hammer",$num);
|
|
|
- // 扣除用户钻石并生成钻石变动记录
|
|
|
- $where = [];
|
|
|
- $where["id"] = $user_id;
|
|
|
- $res3 = $userInfo->setDec("jewel",$money);
|
|
|
- $res4 = $userjewellogModel->addUserJewelLog($user_id, $money, "-", $userjewel, "购买{$num}锤", 2);
|
|
|
-
|
|
|
- $redis = new Redis();
|
|
|
- $redisconfig = config("redis");
|
|
|
- $redis->connect($redisconfig["host"], $redisconfig["port"]);
|
|
|
- if ($redisconfig['redis_pwd']) {
|
|
|
- $redis->auth($redisconfig['redis_pwd']);
|
|
|
- }
|
|
|
- if($redisconfig['redis_selectdb'] > 0){
|
|
|
- $redis->select($redisconfig['redis_selectdb']);
|
|
|
- }
|
|
|
- for($i=1;$i<=$num;$i++) {
|
|
|
- $val = date("YmdHis").$i;
|
|
|
- $redis->lpush("hammer_num_".$user_id,$val);
|
|
|
- }
|
|
|
-
|
|
|
- if($res1 && $res2 && $res3 && $res4) {
|
|
|
- Db::commit();
|
|
|
- $this->success("购买成功!");
|
|
|
- } else {
|
|
|
- $this->error("购买失败!");
|
|
|
- }
|
|
|
- }catch (ValidateException $e) {
|
|
|
- Db::rollback();
|
|
|
- $this->error($e->getMessage());
|
|
|
- } catch (PDOException $e) {
|
|
|
- Db::rollback();
|
|
|
- $this->error($e->getMessage());
|
|
|
- } catch (Exception $e) {
|
|
|
- Db::rollback();
|
|
|
- $this->error($e->getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
* 查找下一个奖池
|
|
|
*/
|
|
|
- public function getNextJackpot($jackpot_id) {
|
|
|
- $jackpotIds = \app\common\model\EggJackpot::order("id","asc")->column("id");
|
|
|
+ private function getNextJackpot($jackpot_id) {
|
|
|
+ $type = \app\common\model\EggJackpot::where(['id'=>$jackpot_id])->value('type');
|
|
|
+
|
|
|
+ $jackpotIds = \app\common\model\EggJackpot::order('weigh asc,id asc')->where('type',$type)->column("id");
|
|
|
$next = 0;
|
|
|
foreach($jackpotIds as $k => $v) {
|
|
|
if($v == $jackpot_id) {
|
|
@@ -395,12 +318,10 @@ class Eggnew extends Api
|
|
|
*/
|
|
|
public function getBaseInfo() {
|
|
|
$user_id = $this->auth->id;
|
|
|
- // 本人拥有锤子个数
|
|
|
- $hammerNum = \app\common\model\User::where(["id"=>$user_id])->value("hammer");
|
|
|
+
|
|
|
// 构建数据
|
|
|
$data = [];
|
|
|
- $data["hammerNum"] = $hammerNum;
|
|
|
- $data["hammerPrice"] = config("site.hammerPrice");
|
|
|
+ $data["jewel"] = $this->auth->jewel;
|
|
|
$data["playdetail"] = config("site.playdetail");
|
|
|
$this->success("获取成功!",$data);
|
|
|
}
|