getUser(); $prize_num = request()->param('prize_num/d', 0); #抽几发 $goods_id = request()->param('goods_id/d', 0); #盒子ID #盒子信息 $goods = Goodsmodel::field('title,imgurl_detail,type,price,status,is_shou_zhe')->where(['id' => $goods_id]) ->find(); if (!$goods) { return $this->renderError("盒子不存在"); } if ($goods['status'] != 1) { return $this->renderError("盒子已下架"); } $goods['imgurl_detail'] = imageUrl($goods['imgurl_detail']); $price = $goods['price']; #抽奖数量 $goods['prize_num'] = $prize_num; $data = [ 'goods' => $goods, 'price' => round($price, 2), 'integral' => round($price * 100, 2), 'use_integral' => round($user['money2'], 2), 'money' => round($user['money'], 2), ]; return $this->renderSuccess("请求成功", $data); } /** * 下单 */ public function mall_orderbuy() { $user = $this->getUser(); if (empty($user['mobile'])) { return $this->renderError('请先绑定手机号', [], -9); } $ad_id = request()->header('adid'); $goods_id = request()->param('goods_id/d', 0); #盒子ID $prize_num = request()->param('prize_num/d', 0); #抽几发 #盒子信息 $goods = Goodsmodel::field('id,title,imgurl_detail,type,price,status,is_shou_zhe,choujiang_xianzhi,daily_xiangou')->where(['id' => $goods_id]) ->find(); if (!$goods) { return $this->renderError("盒子不存在"); } if ($goods['status'] != 1) { return $this->renderError("盒子已下架"); } if (!in_array($goods['type'], [2, 8, 9, 10])) { return $this->renderError("非法请求"); } $user_id = $this->getuserid(); $choujiang_xianzhi = $goods['choujiang_xianzhi']; if ($choujiang_xianzhi && $choujiang_xianzhi > 0) { // SELECT sum(price) FROM xinglanmh_shequt_test.`order` where user_id=4445 and status=1 $user_price = order::where('user_id', '=', $user_id)->where('status', '=', 1)->sum('price'); if ($user_price < $choujiang_xianzhi) { return $this->renderError("消费满" . $choujiang_xianzhi . "元可参与 已消费" . round($user_price, 2) . "元"); } } // 检查每日限购次数 if (isset($goods['daily_xiangou']) && $goods['daily_xiangou'] > 0) { // 计算今天的开始和结束时间戳 $today_start = strtotime(date('Y-m-d 00:00:00', time())); $today_end = strtotime(date('Y-m-d 23:59:59', time())); // 查询用户今天对该商品的购买次数 $today_buy_count = Order::where([ ['user_id', '=', $user_id], ['goods_id', '=', $goods_id], ['status', '=', 1], ['addtime', '>=', $today_start], ['addtime', '<=', $today_end] ])->count(); // 如果今日购买次数已达到限制,返回错误 if ($today_buy_count >= $goods['daily_xiangou']) { return $this->renderError("该商品每日限购" . $goods['daily_xiangou'] . "次,今日已购买" . $today_buy_count . "次"); } } $app_setting = getConfig('app_setting'); if ($app_setting) { $exchange_times = $app_setting["exchange_times"]; if ($exchange_times && $app_setting["exchange_times"] > 0) { // 计算今天的开始和结束时间戳 $today_start = strtotime(date('Y-m-d 00:00:00', time())); $today_end = strtotime(date('Y-m-d 23:59:59', time())); // 查询用户今天对该商品的购买次数 $today_buy_count = Order::where([ ['user_id', '=', $user_id], ['goods_id', '=', $goods_id], ['status', '=', 1], ['addtime', '>=', $today_start], ['addtime', '<=', $today_end] ])->count(); // 如果今日购买次数已达到限制,返回错误 if ($today_buy_count >= $exchange_times) { return $this->renderError("商城每日限购" . $exchange_times . "次,今日已购买" . $today_buy_count . "次"); } } } $where = []; $where[] = ['goods_id', '=', $goods_id]; if ($goods['type'] == 10) { $where[] = ['shang_id', 'between', [10, 33]]; $where[] = ['num', '=', 1]; } else { $where[] = ['num', '=', 0]; $where[] = ['real_pro', '>', 0]; $where[] = ['shang_id', 'between', self::$shang_prize_id]; } $is_goodslist = GoodsList::field('id') ->where($where) ->find(); if (!$is_goodslist) { return $this->renderError('暂无奖品信息'); } if ($prize_num != 1 && $prize_num != 3 && $prize_num != 5 && $prize_num != 10 && $prize_num != 50) { return $this->renderError("请求参数错误!!!"); } #盒子单价 $box_price = $goods['price']; $order_total = $box_price * 100; $integral = $user['money2']; if ($order_total > $integral) { return $this->renderError("余额不足!!!"); } $redis = (new \app\common\server\RedisHelper())->getRedis(); $redis_key = "kpw_mall_orderbuy" . '_' . $user['id']; $redis_key_info = $redis->get($redis_key); if ($redis_key_info) { return $this->renderError("当前操作太快了,请等待"); } else { $redis->set($redis_key, 1, 3); } Db::startTrans(); $num = 0; if ($goods['type'] == 10) { $num = 1; } $res = []; $order_num = create_order_no('MH_', 'order', 'order_num'); #创建订单 $res[] = $order_id = Order::insertGetId([ 'user_id' => $user['id'], 'order_num' => $order_num, 'order_total' => $box_price,#订单金额 'order_zhe_total' => 0,#订单折扣金额 'price' => 0,#微信支付 'use_money' => 0,#余额抵扣 'use_integral' => 0,#吧唧币抵扣 'use_score' => 0,#积分抵扣 'use_money2' => $order_total,#积分抵扣 'zhe' => 0,#会员折扣 'goods_id' => $goods_id, 'num' => $num, 'goods_price' => $goods['price'], 'goods_title' => $goods['title'], 'goods_imgurl' => $goods['imgurl_detail'], 'prize_num' => $prize_num, 'status' => 0, 'pay_type' => 1,#1微信 2支付宝 'order_type' => $goods['type'], 'addtime' => time(), 'coupon_id' => 0, 'use_coupon' => 0, #优惠券抵扣 'is_mibao' => 0, 'is_shou_zhe' => 0, 'ad_id' => $ad_id, 'click_id' => $user['click_id'] ]); #开盒子 $res[] = (new Notify($this->app))->infinite_shangchengshang_notice($user['id'], $order_id, $goods_id, $num); #结果集 $new_data = [ 'status' => 0, 'order_num' => $order_num, ]; if (resCheck($res)) { Db::commit(); #删除redis $redis->del($redis_key); return $this->renderSuccess("下单成功", $new_data); } else { Db::rollback(); #删除redis $redis->del($redis_key); return $this->renderError("购买失败,请刷新重试"); } } /** * 秘宝池下单 * @return \think\response\Json * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function infinite_mibao_orderbuy() { $user = $this->getUser(); if (empty($user['mobile'])) { return $this->renderError('请先绑定手机号', [], -9); } $goods_id = request()->param('goods_id/d', 0); #盒子ID $prize_num = request()->param('prize_num/d', 0); #抽几发 $is_mibao = request()->param('is_mibao/d', 0); //连击赏下 是否是抽的秘宝池 1是 0否 #盒子信息 $goods = Goodsmodel::field('id,title,imgurl_detail,type,price,status,choujiang_xianzhi,daily_xiangou')->where(['id' => $goods_id]) ->find(); if (!$goods) { return $this->renderError("盒子不存在"); } if ($goods['status'] != 1) { return $this->renderError("盒子已下架"); } if ($goods['type'] != 9) { return $this->renderError("非法请求"); } $user_id = $this->getuserid(); $choujiang_xianzhi = $goods['choujiang_xianzhi']; if ($choujiang_xianzhi && $choujiang_xianzhi > 0) { // SELECT sum(price) FROM xinglanmh_shequt_test.`order` where user_id=4445 and status=1 $user_price = order::where('user_id', '=', $user_id)->where('status', '=', 1)->sum('price'); if ($user_price < $choujiang_xianzhi) { return $this->renderError("消费满" . $choujiang_xianzhi . "元可参与 已消费" . round($user_price, 2) . "元"); } } // 检查每日限购次数 if (isset($goods['daily_xiangou']) && $goods['daily_xiangou'] > 0) { // 计算今天的开始和结束时间戳 $today_start = strtotime(date('Y-m-d 00:00:00', time())); $today_end = strtotime(date('Y-m-d 23:59:59', time())); // 查询用户今天对该商品的购买次数 $today_buy_count = Order::where([ ['user_id', '=', $user_id], ['goods_id', '=', $goods_id], ['status', '=', 1], ['addtime', '>=', $today_start], ['addtime', '<=', $today_end] ])->count(); // 如果今日购买次数已达到限制,返回错误 if ($today_buy_count >= $goods['daily_xiangou']) { return $this->renderError("该商品每日限购" . $goods['daily_xiangou'] . "次,今日已购买" . $today_buy_count . "次"); } } //秘宝池 $where = []; $where[] = ['goods_id', '=', $goods_id]; $where[] = ['num', '=', 0]; $where[] = ['real_pro', '>', 0]; $where[] = ['shang_id', 'between', self::$shang_prize_id]; $where[] = ['lian_ji_type', '=', 1]; $is_goodslist = GoodsList::field('id') ->where($where) ->find(); if (!$is_goodslist) { return $this->renderError('暂无奖品信息'); } $prize_num = intval($prize_num); if ($prize_num > 20) { return $this->renderError("一次最多购买20次"); } $user_mb_number = User::where(['id' => $user['id']])->value('mb_number'); if ($prize_num > $user_mb_number) { return $this->renderError("秘宝池抽奖次数不足"); } #盒子单价 $box_price = $goods['price']; #订单金额 微信支付金额 $order_total = $price = bcmul("$box_price", "$prize_num", 2); if ($price <= 0) { $price = 0; } $redis = (new \app\common\server\RedisHelper())->getRedis(); $redis_key = "kpw_infinite_orderbuy" . '_' . $user['id']; $redis_key_info = $redis->get($redis_key); if ($redis_key_info) { return $this->renderError("当前操作太快了,请等待"); } else { $redis->set($redis_key, 1, 2); } Db::startTrans(); $res = []; $order_num = create_order_no('MH_', 'order', 'order_num'); #创建订单 $res[] = $order_id = Order::insertGetId([ 'user_id' => $user['id'], 'order_num' => $order_num, 'order_total' => $order_total,#订单金额 'order_zhe_total' => 0,#订单折扣金额 'price' => 0,#微信支付 'use_money' => 0,#余额抵扣 'use_integral' => 0,#吧唧币抵扣 'use_score' => 0,#积分抵扣 'zhe' => 0,#会员折扣 'goods_id' => $goods_id, 'num' => 0, 'goods_price' => $goods['price'], 'goods_title' => $goods['title'], 'goods_imgurl' => $goods['imgurl_detail'], 'prize_num' => $prize_num, 'status' => 0, 'pay_type' => 1,#1微信 2支付宝 'order_type' => $goods['type'], 'addtime' => time(), 'coupon_id' => 0, 'use_coupon' => 0, #优惠券抵扣 'is_mibao' => $is_mibao ]); #开盒子 $res[] = (new Notify($this->app))->infinite_drawprize_notice($user['id'], $order_id, $goods_id); #结果集 $new_data = [ 'status' => 0, 'order_num' => $order_num, ]; if (resCheck($res)) { Db::commit(); #删除redis $redis->del($redis_key); return $this->renderSuccess("下单成功", $new_data); } else { Db::rollback(); #删除redis $redis->del($redis_key); return $this->renderError("购买失败,请刷新重试"); } } /** * 抽中的奖品 */ public function infinite_prizeorderlog() { $user = $this->getUser(); $order_num = request()->param('order_num', ''); $order_info = Order::field('id,goods_id,num,order_type') ->where('order_num', '=', $order_num) ->where('user_id', '=', $user['id']) ->find(); if (!$order_info) { return $this->renderError("支付异常,请刷新重试"); } #普通赏 $data = OrderList::field('id,user_id,shang_id,goodslist_id,goodslist_title,goodslist_imgurl,goodslist_money') ->append(['shang_title']) ->where('user_id', '=', $user['id']) ->where('order_id', '=', $order_info['id']) ->where('order_type', '=', $order_info['order_type']) ->order('goodslist_money desc, id asc') ->paginate(100)->each(function ($item) { $item['goodslist_imgurl'] = imageUrl($item['goodslist_imgurl']); return $item; }); $userCoupon = UserCoupon::field('id,level,title,num') ->where('user_id', '=', $user['id']) ->where('from_id', '=', $order_info['id']) ->order('level desc') ->find(); if ($userCoupon != null) { //1特级赏券 2终极赏券 3高级赏券 4普通赏券 if ($userCoupon['level'] == 1) { $userCoupon['level_text'] = '特级赏券'; $userCoupon['level_img'] = imageUrl('/storage/coupon/coupon_a.png'); } elseif ($userCoupon['level'] == 2) { $userCoupon['level_text'] = '终极赏券'; $userCoupon['level_img'] = imageUrl('/storage/coupon/coupon_b.png'); } elseif ($userCoupon['level'] == 3) { $userCoupon['level_text'] = '高级赏券'; $userCoupon['level_img'] = imageUrl('/storage/coupon/coupon_c.png'); } elseif ($userCoupon['level'] == 4) { $userCoupon['level_text'] = '普通赏券'; $userCoupon['level_img'] = imageUrl('/storage/coupon/coupon_d.png'); } } //重抽卡数量 $item_card_count = Db::name('user_item_card')->where(['user_id' => $user['id'], 'status' => 1])->count(); $new_data = [ 'user_info' => [ 'nickname' => $user['nickname'], 'headimg' => $user['headimg'], ], 'data' => $data->items(), 'item_card_count' => $item_card_count, 'user_coupon' => $userCoupon ]; return $this->renderSuccess("请求成功", $new_data); } /** * 无限令奖励 */ public function infinite_give_list() { $user = $this->getUser(); $thismonth = getConfig('give_time')['range_time']; $thismontharr = explode(' - ', $thismonth); #获取开始时间戳 $beginThismonth = strtotime($thismontharr[0]); #获取结束时间戳 $endThismonth = strtotime($thismontharr[1]); $consumption_total = Order::field('total') ->where('status', '=', 1) ->where('user_id', '=', $user['id']) ->where('addtime', 'BETWEEN', array($beginThismonth, $endThismonth)) ->where('order_type', '=', 2) ->sum('order_total'); #时间数据 消费 $other_data = [ 'time' => date('Y-m-d', $beginThismonth) . '-' . date('Y-m-d', $endThismonth), 'money' => $consumption_total, ]; #是否领取过当前时间戳 $time_int = $beginThismonth . '_' . $endThismonth; $give_money = Give::where('time_int', '=', $time_int)->order('id desc')->value('money'); $give_money = $give_money ? $give_money : 0; #奖品列表 $data = GoodsList::field('id,give_money,goods_id') ->append(['give_list']) ->where('goods_id', '=', 0) ->order('give_money asc,id asc') ->group('give_money') ->select()->toArray(); foreach ($data as &$value) { if ($give_money >= $value['give_money']) { $value['is'] = 1; } else { $value['is'] = 0; } } $new_data = [ 'other_data' => $other_data, 'data' => $data, ]; return $this->renderSuccess('请求成功', $new_data); } /** * 无限令领取接口 */ public function infinite_give_goods() { $user = $this->getUser(); $user_id = $user['id']; $thismonth = getConfig('give_time')['range_time']; $thismontharr = explode(' - ', $thismonth); #获取开始时间戳 $beginThismonth = strtotime($thismontharr[0]); #获取结束时间戳 $endThismonth = strtotime($thismontharr[1]); #是否领取过当前时间戳 $time_int = $beginThismonth . '_' . $endThismonth; $give_money = Give::where('time_int', '=', $time_int)->order('id desc')->value('money'); $give_money = $give_money ? $give_money : 0; #总消费 $consumption_total = Order::field('total') ->where('status', '=', 1) ->where('user_id', '=', $user['id']) ->where('addtime', 'BETWEEN', array($beginThismonth, $endThismonth)) ->where('order_type', '=', 2) ->sum('order_total'); if ($give_money >= $consumption_total) { return $this->renderError("暂无可领取奖品"); } #赠送商品 $give_goods = GoodsList::where(['goods_id' => 0]) ->where("give_money", '>', $give_money) ->where("give_money", '<=', $consumption_total) ->order('give_money asc,id asc') ->select()->toArray(); if (!$give_goods) { return $this->renderError("暂无可领取奖品"); } Db::startTrans(); $res = []; #符合赠送 $save_data = []; foreach ($give_goods as $value) { $save_data[] = [ 'order_id' => 0, 'user_id' => $user_id, 'status' => 0,#0未操作 1选择兑换 2选择发货 'goods_id' => 0, 'num' => 0, 'shang_id' => $value['shang_id'], 'goodslist_id' => $value['id'], 'goodslist_title' => $value['title'], 'goodslist_imgurl' => $value['imgurl'], 'goodslist_price' => $value['price'], 'goodslist_money' => $value['money'], 'goodslist_type' => $value['goods_type'], 'goodslist_sale_time' => $value['sale_time'], 'addtime' => time(), 'prize_code' => $value['prize_code'], 'order_type' => 6, ]; } $res[] = OrderList::insertAll($save_data); $res[] = Give::insert([ 'user_id' => $user_id, 'time_int' => $time_int, 'time_date' => date('Y-m-d H:i:s', $beginThismonth) . '_' . date('Y-m-d H:i:s', $endThismonth), 'money' => $consumption_total, 'addtime' => time(), ]); if (resCheck($res)) { Db::commit(); return $this->renderSuccess("领取成功"); } else { Db::rollback(); return $this->renderError("领取失败,请稍后重试"); } } //进行抽奖 public function do_draw() { $user = $this->getUser(); if (empty($user['mobile'])) { return $this->renderError('请先绑定手机号', [], -9); } $goods_id = request()->param('goods_id/d', 0); #盒子ID $prize_num = request()->param('prize_num/d', 1); #抽几发 #盒子信息 $goods = Goodsmodel::field('id,title,imgurl_detail,type,price,status,choujiang_xianzhi')->where(['id' => $goods_id]) ->find(); if (!$goods) { return $this->renderError("盒子不存在"); } if ($goods['status'] != 1) { return $this->renderError("盒子已下架"); } if ($goods['type'] != 7) { return $this->renderError("非法请求"); } $user_id = $this->getuserid(); $choujiang_xianzhi = $goods['choujiang_xianzhi']; if ($choujiang_xianzhi && $choujiang_xianzhi > 0) { // SELECT sum(price) FROM xinglanmh_shequt_test.`order` where user_id=4445 and status=1 $user_price = order::where('user_id', '=', $user_id)->where('status', '=', 1)->sum('price'); if ($user_price < $choujiang_xianzhi) { return $this->renderError("消费满" . $choujiang_xianzhi . "元可参与 已消费" . round($user_price, 2) . "元"); } } #奖品信息 $is_goodslist = GoodsList::field('id') ->where('goods_id', '=', $goods_id) ->where('num', '=', 0) ->where('real_pro', '>', 0) ->where('shang_id', 'between', self::$shang_prize_id) ->find(); if (!$is_goodslist) { return $this->renderError('暂无奖品信息'); } if ($prize_num != 1) { return $this->renderError("请求参数错误"); } $draw_num = $user['draw_num']; // var_dump($draw_num); // exit; if ($user['draw_num'] == 0 || bccomp("$draw_num", "$prize_num") < 0) { return $this->renderError("抽奖券不足,无法进行抽奖"); } $redis = (new \app\common\server\RedisHelper())->getRedis(); $redis_key = "kpw_infinite_orderbuy_draw" . '_' . $user['id']; $redis_key_info = $redis->get($redis_key); if ($redis_key_info) { return $this->renderError("当前操作太快了,请等待"); } else { $redis->set($redis_key, 1, 10); } Db::startTrans(); $res = []; $order_num = create_order_no('MH_', 'order', 'order_num'); #创建订单 $res[] = $order_id = Order::insertGetId([ 'user_id' => $user['id'], 'order_num' => $order_num, 'order_total' => 0,#订单金额 'order_zhe_total' => 0,#订单折扣金额 'price' => 0,#微信支付 'use_money' => 0,#余额抵扣 'use_integral' => 0,#吧唧币抵扣 'use_score' => 0,#积分抵扣 'zhe' => 0,#会员折扣 'goods_id' => $goods_id, 'num' => 0, 'goods_price' => $goods['price'], 'goods_title' => $goods['title'], 'goods_imgurl' => $goods['imgurl_detail'], 'prize_num' => $prize_num, 'status' => 0, 'pay_type' => 1,#1微信 2支付宝 'order_type' => $goods['type'], 'addtime' => time(), 'use_draw' => 1 ]); #开盒子 $res[] = (new Notify($this->app))->draw_drawprize_notice($user['id'], $order_id, $goods_id); #结果集 $new_data = [ 'status' => 0, 'order_num' => $order_num, ]; if (resCheck($res)) { Db::commit(); #删除redis $redis->del($redis_key); return $this->renderSuccess("下单成功", $new_data); } else { Db::rollback(); #删除redis $redis->del($redis_key); return $this->renderError("购买失败,请刷新重试"); } } /** * 重抽卡重抽 * @param Request $request * @return \think\response\Json * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function item_card_chou(Request $request) { $user = $this->getUser(); if (empty($user['mobile'])) { return $this->renderError('请先绑定手机号', [], -9); } $goods_id = request()->param('goods_id/d', 0); #盒子ID $order_list_ids = request()->param('order_list_ids', ""); #重抽的ID #盒子信息 $goods = Goodsmodel::field('id,title,imgurl_detail,type,price,status,choujiang_xianzhi')->where(['id' => $goods_id]) ->find(); if (!$goods) { return $this->renderError("盒子不存在"); } if ($goods['status'] != 1) { return $this->renderError("盒子已下架"); } $order_list_ids = explode(',', trim($order_list_ids)); if (empty($order_list_ids)) { return $this->renderError("参数错误"); } $user_id = $this->getuserid(); $choujiang_xianzhi = $goods['choujiang_xianzhi']; if ($choujiang_xianzhi && $choujiang_xianzhi > 0) { // SELECT sum(price) FROM xinglanmh_shequt_test.`order` where user_id=4445 and status=1 $user_price = order::where('user_id', '=', $user_id)->where('status', '=', 1)->sum('price'); if ($user_price < $choujiang_xianzhi) { return $this->renderError("消费满" . $choujiang_xianzhi . "元可参与 已消费" . round($user_price, 2) . "元"); } } $redis = (new \app\common\server\RedisHelper())->getRedis(); $redis_key = "item_card_chou" . '_' . $user['id']; $redis_key_info = $redis->get($redis_key); if ($redis_key_info) { return $this->renderError("当前操作太快了,请等待"); } else { $redis->set($redis_key, 1, 5); } $item_card_count = Db::name('user_item_card')->where(['user_id' => $user['id'], 'status' => 1])->whereNull('deltime')->count(); if (1 > $item_card_count) { return $this->renderError("重抽卡数量不足"); } foreach ($order_list_ids as $k => $v) { $order_list = OrderList::field('id')->where(['id' => $v, 'status' => 0])->find(); if (!$order_list) { return $this->renderError("数据错误"); } } Db::startTrans(); $res = []; $order_num = create_order_no('MH_', 'order', 'order_num'); #创建订单 $res[] = $order_id = Order::insertGetId([ 'user_id' => $user['id'], 'order_num' => $order_num, 'order_total' => 0,#订单金额 'order_zhe_total' => 0,#订单折扣金额 'price' => 0,#微信支付 'use_money' => 0,#余额抵扣 'use_integral' => 0,#吧唧币抵扣 'use_score' => 0,#积分抵扣 'zhe' => 0,#会员折扣 'goods_id' => $goods_id, 'num' => 0, 'goods_price' => $goods['price'], 'goods_title' => $goods['title'], 'goods_imgurl' => $goods['imgurl_detail'], 'prize_num' => count($order_list_ids), 'status' => 0, 'pay_type' => 1,#1微信 2支付宝 'order_type' => $goods['type'], 'addtime' => time(), 'use_item_card' => 1 // 'use_item_card' => count($order_list_ids) ]); #开盒子 $res[] = (new Notify($this->app))->item_card_notice($user['id'], $order_id, $goods_id); #判断是否发积分 发券 $order = Order::where(['id' => $order_id])->find(); $res[] = User::is_integral_coupon($order); $res[] = OrderList::where(['user_id' => $user['id']])->whereIn('id', $order_list_ids)->update(['is_chong' => 1, 'deltime' => time()]); #结果集 $new_data = [ 'status' => 0, 'order_num' => $order_num, ]; if (resCheck($res)) { Db::commit(); #删除redis $redis->del($redis_key); return $this->renderSuccess("重抽成功", $new_data); } else { Db::rollback(); #删除redis $redis->del($redis_key); return $this->renderError("重抽失败,请刷新重试"); } } /** *领主 */ public function ling_zhu_king(Request $request) { $goods_id = $request->param('goods_id'); $type = $request->param('type/d', 1); if (!isset($goods_id) && empty($goods_id)) { return $this->renderSuccess('参数错误'); } //查找当前领主 $goods = Db::name('goods')->field('king_user_id,lingzhu_fan,lingzhu_shang_id')->where([['id', '=', $goods_id]])->find(); $king_user = Db::name('user')->field('id,nickname,headimg')->where(['id' => $goods['king_user_id']])->find(); if ($goods && $goods['king_user_id'] && $king_user) { $king_user['headimg'] = imageUrl($king_user['headimg']); $goods_king_rank = Db::name('goods_king_rank')->field('order_list_id')->where(['user_id' => $goods['king_user_id'], 'goods_id' => $goods_id])->order('id desc')->limit(1)->find(); $order_list_id = $goods_king_rank ? $goods_king_rank['order_list_id'] : 0; $jiang_img = OrderList::field('goodslist_title,goodslist_imgurl')->where(['id' => $order_list_id])->find(); $king_user['jiang_title'] = $jiang_img ? $jiang_img['goodslist_title'] : ''; $king_user['jiang_img'] = $jiang_img ? imageUrl($jiang_img['goodslist_imgurl']) : ''; } else { $king_user = null; } if ($type == 1) { //挑战人数 $list = Db::name('goods_king_rank') ->alias('a') ->join('user b', 'a.user_id = b.id') ->field('a.user_id,b.nickname,b.headimg') ->where([['a.goods_id', '=', $goods_id]]) ->group('a.user_id') ->order('a.id', 'desc') ->paginate(20)->each(function ($item) { $item['headimg'] = imageUrl($item['headimg']); return $item; }); } elseif ($type == 2) { //领主记录 $list = Db::name('goods_king_rank') ->alias('a') ->join('user b', 'a.user_id = b.id') ->field('a.user_id,a.addtime,a.end_time,b.nickname,b.headimg') ->where([['a.goods_id', '=', $goods_id]]) ->order('a.id', 'desc') ->paginate(20)->each(function ($item) { $item['headimg'] = imageUrl($item['headimg']); $item['time'] = time_jian($item['addtime'], $item['end_time'] ? $item['end_time'] : time()); return $item; }); } $ling_goods_list = GoodsList::field('goods_id,shang_id,title,imgurl') ->append(['shang_info']) ->where(['goods_id' => $goods_id]) ->where(['shang_id' => $goods['lingzhu_shang_id']]) ->where(['num' => 0]) ->order('sort desc,shang_id asc,id asc') ->select(); foreach ($ling_goods_list as &$value) { $value['imgurl'] = imageUrl($value['imgurl']); } $data = []; $data['goods'] = $goods; $data['king_user'] = $king_user; $data['list'] = $list; $data['ling_goods_list'] = $ling_goods_list; return $this->renderSuccess('请求成功', $data); } }