|
@@ -18,7 +18,7 @@ class MultiPkMall extends Base
|
|
|
public function initialize()
|
|
|
{
|
|
|
parent::initialize();
|
|
|
- parent::check_login();
|
|
|
+ //parent::check_login();
|
|
|
}
|
|
|
|
|
|
|
|
@@ -81,9 +81,7 @@ class MultiPkMall extends Base
|
|
|
if($pay_type == 2 && $user_info['crystal_cash'] < $price_total) throw new Exception('余额不足!');
|
|
|
if($pay_type == 3 && $price_total > 0 && bcadd($user_info['crystal'],$user_info['crystal_cash'],2) < $price_total) throw new Exception('余额不足!');
|
|
|
// 验证待pk位置,最多3个
|
|
|
- $check_num = Db::table('pk_draw')
|
|
|
- ->where(['goods_id'=>$goods_id,'pk_status'=>0,'full_num'=>4,'place'=>$place])
|
|
|
- ->count();
|
|
|
+ $check_num = Db::table('pk_draw')->where(['goods_id'=>$goods_id,'pk_status'=>0,'full_num'=>4,'place'=>$place])->count();
|
|
|
if($check_num >= 3 ) throw new Exception('该位置已满!');
|
|
|
|
|
|
// pk 防截胡
|
|
@@ -224,7 +222,7 @@ class MultiPkMall extends Base
|
|
|
if($base_award['base_crystal'] > 0 && $base_award['base_goods']) {
|
|
|
$lose_case = [];
|
|
|
array_map(function ($val)use(&$lose_case,$goods_id,$magic_day,$base_award){
|
|
|
- $lose_case = [
|
|
|
+ $lose_case[] = [
|
|
|
'order_id' => $val['order_id'],
|
|
|
'goods_id' => $goods_id,
|
|
|
'user_id' => $val['user_id'],
|
|
@@ -244,8 +242,8 @@ class MultiPkMall extends Base
|
|
|
Db::table('magic_case')->insertAll($lose_case);
|
|
|
}else{
|
|
|
$lose_case=[
|
|
|
- ['user_id'=>0,'order_id'=>0],
|
|
|
- ['user_id'=>0,'order_id'=>0],
|
|
|
+ ['user_id'=>$orange_team[0]['user_id'],'order_id'=>$orange_team[0]['order_id'],'case_name'=>''],
|
|
|
+ ['user_id'=>$orange_team[1]['user_id'],'order_id'=>$orange_team[1]['order_id'],'case_name'=>''],
|
|
|
];
|
|
|
}
|
|
|
|
|
@@ -269,7 +267,7 @@ class MultiPkMall extends Base
|
|
|
if($base_award['base_crystal'] > 0 && $base_award['base_goods']) {
|
|
|
$lose_case = [];
|
|
|
array_map(function ($val)use(&$lose_case,$goods_id,$magic_day,$base_award){
|
|
|
- $lose_case = [
|
|
|
+ $lose_case[] = [
|
|
|
'order_id' => $val['order_id'],
|
|
|
'goods_id' => $goods_id,
|
|
|
'user_id' => $val['user_id'],
|
|
@@ -289,8 +287,8 @@ class MultiPkMall extends Base
|
|
|
Db::table('magic_case')->insertAll($lose_case);
|
|
|
}else{
|
|
|
$lose_case=[
|
|
|
- ['user_id'=>0,'order_id'=>0],
|
|
|
- ['user_id'=>0,'order_id'=>0],
|
|
|
+ ['user_id'=>$red_team[0]['user_id'],'order_id'=>$red_team[0]['order_id'],'case_name'=>''],
|
|
|
+ ['user_id'=>$red_team[1]['user_id'],'order_id'=>$red_team[1]['order_id'],'case_name'=>''],
|
|
|
];
|
|
|
}
|
|
|
|
|
@@ -315,91 +313,22 @@ class MultiPkMall extends Base
|
|
|
];
|
|
|
Db::table('pk_multi_info')->insert($multi_info);
|
|
|
|
|
|
-
|
|
|
// 更新PK抽奖记录
|
|
|
- Db::table('pk_draw')->where('id','in',[$rank_draw[0]['id'],$rank_draw[1]['id']])->update(['pk_status'=>2]);
|
|
|
- Db::table('pk_draw')->where('id','in',[$rank_draw[2]['id'],$rank_draw[3]['id']])->update(['pk_status'=>1]);
|
|
|
- }else{
|
|
|
- // 更新库存 && 规格详情
|
|
|
- $goods_update['spec'] = json_encode($goods_spec);
|
|
|
- $goods_update['stock'] = $goods_info['stock'] - 1;
|
|
|
- Db::table('pk_goods')->where('id',$goods_info['id'])->update($goods_update);
|
|
|
- }
|
|
|
-
|
|
|
- // 能参与pk成功 start
|
|
|
- if(!empty($pk_draw)) {
|
|
|
-
|
|
|
- if($pk_draw['crystal'] >$draw_info['crystal'] || ($pk_draw['crystal'] == $draw_info['crystal'] && $pk_draw['code'] > $draw_info['code'])){
|
|
|
- $win_info = $pk_draw;
|
|
|
- $lose_info = $draw_info;
|
|
|
- }else{
|
|
|
- $win_info = $draw_info;
|
|
|
- $lose_info = $pk_draw;
|
|
|
+ Db::table('pk_draw')->where('id','in',[$rank_draw[0]['id'],$rank_draw[1]['id']])->update(['pk_status'=>$red_win?2:1]);
|
|
|
+ Db::table('pk_draw')->where('id','in',[$rank_draw[2]['id'],$rank_draw[3]['id']])->update(['pk_status'=>$red_win?1:2]);
|
|
|
+
|
|
|
+ foreach ($rank_draw as $fk=>$fv) {
|
|
|
+ if(in_array($fk,[0,1])) continue;
|
|
|
+ // 恢复库存
|
|
|
+ $goods_spec[$fv['spec_key']]['store_num']++;
|
|
|
+ $goods_info['stock']++;
|
|
|
}
|
|
|
- // 暴击值
|
|
|
- $win_case = [
|
|
|
- 'order_id' => $win_info['order_id'],
|
|
|
- 'goods_id' => $goods_id,
|
|
|
- 'user_id' => $win_info['user_id'],
|
|
|
- 'create_at' => date('Y-m-d H:i:s'),
|
|
|
- 'num' => 1,
|
|
|
- 'base_num' => 1,
|
|
|
- 'source' => 0,
|
|
|
- 'crystal' => $win_info['crystal'],
|
|
|
- 'case_name' => $win_info['case_name'],
|
|
|
- 'case_cover' => $win_info['case_cover'],
|
|
|
- 'past_at' => date('Y-m-d H:i:s',strtotime("+$magic_day days")),
|
|
|
- 'past_int' => strtotime("+$magic_day days"),
|
|
|
- 'color' => $win_info['color'],
|
|
|
- 'draw_id' => $win_info['id'],
|
|
|
- 'from' => 2,
|
|
|
- ];
|
|
|
- Db::table('magic_case')->insert($win_case);
|
|
|
- // 更新PK抽奖记录
|
|
|
- Db::table('pk_draw')->where('id',$win_info['id'])->update(['pk_status'=>2]);
|
|
|
- Db::table('pk_draw')->where('id',$lose_info['id'])->update(['pk_status'=>1]);
|
|
|
- // pk 输了是否有安慰奖
|
|
|
- if($base_award['base_crystal'] > 0 && $base_award['base_goods']) {
|
|
|
- $lose_case = [
|
|
|
- 'order_id' => $lose_info['order_id'],
|
|
|
- 'goods_id' => $goods_id,
|
|
|
- 'user_id' => $lose_info['user_id'],
|
|
|
- 'create_at' => date('Y-m-d H:i:s'),
|
|
|
- 'num' => 1,
|
|
|
- 'base_num' => 1,
|
|
|
- 'source' => 0,
|
|
|
- 'crystal' => $base_award['base_crystal'],
|
|
|
- 'case_name' => $base_award['base_goods'],
|
|
|
- 'case_cover' => $base_award['base_cover'],
|
|
|
- 'past_at' => date('Y-m-d H:i:s',strtotime("+$magic_day days")),
|
|
|
- 'past_int' => strtotime("+$magic_day days"),
|
|
|
- 'draw_id' => $lose_info['id'],
|
|
|
- 'from' => 2,
|
|
|
- ];
|
|
|
- Db::table('magic_case')->insert($lose_case);
|
|
|
- }
|
|
|
- // pk 记录
|
|
|
- $pk_info = [
|
|
|
- 'goods_id'=>$goods_id ,
|
|
|
- 'create_at'=>date('Y-m-d H:i:s') ,
|
|
|
- 'win_data' => json_encode($win_info),
|
|
|
- 'lose_data' => json_encode($lose_info),
|
|
|
- 'base_data'=> json_encode($base_award),
|
|
|
- 'win_order' => $win_info['order_id'],
|
|
|
- 'lose_order' => $lose_info['order_id'],
|
|
|
- 'win_user' => $win_info['user_id'],
|
|
|
- 'lose_user' => $lose_info['user_id'],
|
|
|
- ];
|
|
|
- Db::table('pk_info')->insert($pk_info);
|
|
|
- // 恢复库存
|
|
|
- $goods_spec[$lose_info['spec_key']]['store_num']++;
|
|
|
- $goods_info['stock']++;
|
|
|
$goods_update['pk_num'] = $goods_info['pk_num'] + 1;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ // 更新库存 && 规格详情
|
|
|
+ $goods_update['spec'] = json_encode($goods_spec);
|
|
|
+ $goods_update['stock'] = $goods_info['stock'] - 1;
|
|
|
+ Db::table('pk_goods')->where('id',$goods_info['id'])->update($goods_update);
|
|
|
Db::commit();
|
|
|
}catch (\Exception $e){
|
|
|
Db::rollback();
|
|
@@ -426,10 +355,9 @@ class MultiPkMall extends Base
|
|
|
}else{
|
|
|
$this->error($msg);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ // 获取pk胜利数据
|
|
|
public function getWinData($team,$win_key,$award_key,$goods_id,$rank_draw,$magic_day,$place = 0)
|
|
|
{
|
|
|
return [
|
|
@@ -527,18 +455,6 @@ class MultiPkMall extends Base
|
|
|
*/
|
|
|
public function getAllPkLog()
|
|
|
{
|
|
|
-
|
|
|
- /* $user_info = Db::table('store_member')->find($this->uid);
|
|
|
- $list = Db::table('pk_draw')->alias('p')
|
|
|
- ->field('p.id,p.user_id,p.goods_id,p.create_at,g.status as goods_status,g.is_deleted as goods_deleted,g.name as goods_name')
|
|
|
- ->where(['user_id'=>$this->uid,'pk_status'=>0])
|
|
|
- ->where('pk_status','in',[1,2])
|
|
|
- ->join('pk_goods g','g.id = p.goods_id','LEFT')
|
|
|
- ->order('p.id desc')
|
|
|
- ->select();
|
|
|
- $this->success('ok',['list'=>$list]);*/
|
|
|
-
|
|
|
-
|
|
|
$user_info = Db::table('store_member')->find($this->uid);
|
|
|
$list = Db::table('pk_info')->alias('p')
|
|
|
->field('p.id,p.goods_id,p.create_at,p.win_data,p.lose_data,p.win_user,p.lose_user,g.status as goods_status,g.is_deleted as goods_deleted,g.name as goods_name')
|