From 0be9bc7143492baec6629a4db775ca6636f8b35d Mon Sep 17 00:00:00 2001 From: baji Date: Fri, 7 Mar 2025 13:32:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 89 ++++ app/api/controller/Mall.php | 778 +++++++++++++++++++++++++++++++ app/api/controller/Warehouse.php | 64 +-- app/api/route/app.php | 4 + 4 files changed, 904 insertions(+), 31 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 app/api/controller/Mall.php diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..7519989 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,89 @@ +{ + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Listen for Xdebug", + "type": "php", + "request": "launch", + "port": 9003 + }, + { + "name": "Launch currently open script", + "type": "php", + "request": "launch", + "program": "${file}", + "cwd": "${fileDirname}", + "port": 0, + "runtimeArgs": [ + "-dxdebug.start_with_request=yes" + ], + "env": { + "XDEBUG_MODE": "debug,develop", + "XDEBUG_CONFIG": "client_port=${port}" + } + }, + { + "name": "Launch Built-in web server", + "type": "php", + "request": "launch", + "runtimeArgs": [ + "-dxdebug.mode=debug", + "-dxdebug.start_with_request=yes", + "-S", + "localhost:0" + ], + "program": "", + "cwd": "${workspaceRoot}", + "port": 9003, + "serverReadyAction": { + "pattern": "Development Server \\(http://localhost:([0-9]+)\\) started", + "uriFormat": "http://localhost:%s", + "action": "openExternally" + } + }, + { + "name": "Launch built-in server and Debug", + "type": "php", + "request": "launch", + "noDebug": false, + "runtimeArgs": [ + "-S", + "localhost:8000", + "-t", + "." + ], + "cwd": "${workspaceRoot}/public", + "serverReadyAction": { + "action": "openExternally" + }, + "envFile": "../.env" + }, + { + "name": "Launch built-in server and Profile", + "type": "php", + "request": "launch", + "noDebug": true, + "runtimeArgs": [ + "-S", + "localhost:8000", + "-t", + "." + ], + "cwd": "${workspaceRoot}/public", + "serverReadyAction": { + "action": "openExternally" + }, + "envFile": "../.env", + "profile": true, + "openProfile": true + }, + { + "name": "Listen for Xdebug", + "type": "php", + "request": "launch" + } + ] +} \ No newline at end of file diff --git a/app/api/controller/Mall.php b/app/api/controller/Mall.php new file mode 100644 index 0000000..2a64e6d --- /dev/null +++ b/app/api/controller/Mall.php @@ -0,0 +1,778 @@ +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['integral'], 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')->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("非法请求"); + } + $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['integral']; + if ($order_total > $integral) { + return $this->renderError("吧唧币不足!!!"); + } + + + + $redis = new \Redis(); + $redis->connect('127.0.0.1', 6379); + $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' => $order_total,#吧唧币抵扣 + 'use_score' => 0,#积分抵扣 + '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_drawprize_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')->where(['id' => $goods_id]) + ->find(); + if (!$goods) { + return $this->renderError("盒子不存在"); + } + if ($goods['status'] != 1) { + return $this->renderError("盒子已下架"); + } + if ($goods['type'] != 9) { + return $this->renderError("非法请求"); + } + + //秘宝池 + $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 \Redis(); + $redis->connect('127.0.0.1', 6379); + $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')->where(['id' => $goods_id]) + ->find(); + if (!$goods) { + return $this->renderError("盒子不存在"); + } + if ($goods['status'] != 1) { + return $this->renderError("盒子已下架"); + } + if ($goods['type'] != 7) { + return $this->renderError("非法请求"); + } + + #奖品信息 + $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 \Redis(); + $redis->connect('127.0.0.1', 6379); + $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')->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("参数错误"); + } + + $redis = new \Redis(); + $redis->connect('127.0.0.1', 6379); + $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); + } + +} diff --git a/app/api/controller/Warehouse.php b/app/api/controller/Warehouse.php index 36c3be9..a8e20f0 100755 --- a/app/api/controller/Warehouse.php +++ b/app/api/controller/Warehouse.php @@ -1,5 +1,5 @@ where('status', '=', 0) ->where('goodslist_type', '=', 2) ->select()->toArray(); - foreach($linqi_list as $k=>$val){ - $sale_time = GoodsList::where(['id'=>$val['goodslist_id']])->value('sale_time'); - if(!empty($sale_time)){ - if($sale_time <= time()){ - OrderList::where(['id'=>$val['id'],'status'=>0,'user_id'=>$val['user_id'],'goodslist_type'=>2])->update(['goodslist_type'=>1]); + foreach ($linqi_list as $k => $val) { + $sale_time = GoodsList::where(['id' => $val['goodslist_id']])->value('sale_time'); + if (!empty($sale_time)) { + if ($sale_time <= time()) { + OrderList::where(['id' => $val['id'], 'status' => 0, 'user_id' => $val['user_id'], 'goodslist_type' => 2])->update(['goodslist_type' => 1]); } - }else{ - OrderList::where(['id'=>$val['id'],'status'=>0,'user_id'=>$val['user_id'],'goodslist_type'=>2])->where('goodslist_sale_time', '<=', time())->update(['goodslist_type'=>1]); + } else { + OrderList::where(['id' => $val['id'], 'status' => 0, 'user_id' => $val['user_id'], 'goodslist_type' => 2])->where('goodslist_sale_time', '<=', time())->update(['goodslist_type' => 1]); } } - + #自动变现货========================= $type = request()->param('type/d', 0); @@ -99,11 +99,11 @@ class Warehouse extends Base return imageUrl($value); }) ->withAttr('goodslist_money', function ($value, $data) { - return (float)$value; + return (float) $value * 100; }) ->group("prize_code") ->select()->toArray(); - foreach ($orderlist as $k => &$v){ + foreach ($orderlist as $k => &$v) { $v['order_list_ids'] = OrderList::where('goods_id', '=', $v['goods_id']) ->where('user_id', '=', $user_id) ->where('status', '=', 0) @@ -159,7 +159,7 @@ class Warehouse extends Base return imageUrl($value); }) ->withAttr('goodslist_money', function ($value, $data) { - return (float)$value; + return (float) $value * 100; }) ->withAttr('goodslist_sale_time', function ($value, $data) { return date('Y-m-d', $value); @@ -182,19 +182,19 @@ class Warehouse extends Base $whe[] = ['o.goods_title', 'like', '%' . $keyword . '%']; } if ($category_id) { - $whe[] = ['g.category_id',$category_id]; + $whe[] = ['g.category_id', $category_id]; } -// dd($whe); + // dd($whe); #卡册列表 $obj = Order::field('o.id,o.goods_id,o.goods_title,o.goods_imgurl,g.category_id')->alias('o') - ->join('goods g','g.id = o.goods_id') + ->join('goods g', 'g.id = o.goods_id') ->where('o.user_id', '=', $user_id) ->where('o.order_type', '=', 4); - if ($keyword){ + if ($keyword) { $obj->where('o.goods_title', 'like', '%' . $keyword . '%'); } - if ($category_id){ - $obj->where('g.category_id',$category_id); + if ($category_id) { + $obj->where('g.category_id', $category_id); } $list = $obj->order('o.id desc') ->group('o.goods_id') @@ -218,9 +218,9 @@ class Warehouse extends Base ->group('goodslist_id') ->count(); if ($buy_count > 0) { - $gailv = (float)bcdiv("$buy_count", "$all_count", 2); + $gailv = (float) bcdiv("$buy_count", "$all_count", 2); $gailv = bcmul("$gailv", "100", 2); - $gailv = (float)$gailv; + $gailv = (float) $gailv; } else { $gailv = 0; } @@ -276,7 +276,7 @@ class Warehouse extends Base return imageUrl($value); }) ->withAttr('goodslist_money', function ($value, $data) { - return (float)$value; + return (float) $value * 100; }) ->group("prize_code") ->select()->toArray(); @@ -286,7 +286,7 @@ class Warehouse extends Base $data_value['orderlist_total'] = $orderlist_total; $data_value['orderlist_length'] = count($orderlist); } - }else if($type == 5){ //无限赏 + } else if ($type == 5) { //无限赏 $keyword = request()->param('keyword', ''); #搜索 $whe = []; @@ -333,12 +333,12 @@ class Warehouse extends Base return imageUrl($value); }) ->withAttr('goodslist_money', function ($value, $data) { - return (float)$value; + return (float) $value * 100; }) ->group("prize_code") ->select()->toArray(); - foreach ($orderlist as $k => &$v){ + foreach ($orderlist as $k => &$v) { $v['order_list_ids'] = OrderList::where('goods_id', '=', $v['goods_id']) ->where('user_id', '=', $user_id) ->where('status', '=', 0) @@ -409,9 +409,9 @@ class Warehouse extends Base ->group('goodslist_id') ->count(); if ($buy_count > 0) { - $gailv = (float)bcdiv("$buy_count", "$all_count", 2); + $gailv = (float) bcdiv("$buy_count", "$all_count", 2); $gailv = bcmul("$gailv", "100", 2); - $gailv = (float)$gailv; + $gailv = (float) $gailv; } else { $gailv = 0; } @@ -638,8 +638,10 @@ class Warehouse extends Base 'choice_time' => time(), ]); #兑换金额 + $total_money *= 100; if ($total_money > 0) { - $res[] = User::changeMoney($user_id, $total_money, 4, '兑换获得'); + // $res[] = User::changeMoney($user_id, $total_money, 4, '兑换获得'); + User::changeIntegral($user_id, $total_money, 4, '兑换获得'); } if (resCheck($res)) { Db::commit(); @@ -700,14 +702,14 @@ class Warehouse extends Base #运费设置 $config = getConfig("base"); if ($type == 1) {#背包 - $free_post = (int)$config['free_post'];#发货数量 + $free_post = (int) $config['free_post'];#发货数量 $free_post = $free_post <= 0 ? 0 : $free_post; - $post_money = (int)$config['post_money'];#发货运费 + $post_money = (int) $config['post_money'];#发货运费 $post_money = $post_money <= 0 ? 0 : $post_money; } elseif ($type == 2) {#抽卡机 - $free_post = (int)$config['card_free_post'];#发货数量 + $free_post = (int) $config['card_free_post'];#发货数量 $free_post = $free_post <= 0 ? 0 : $free_post; - $post_money = (int)$config['card_post_money'];#发货运费 + $post_money = (int) $config['card_post_money'];#发货运费 $post_money = $post_money <= 0 ? 0 : $post_money; } #发货订单 diff --git a/app/api/route/app.php b/app/api/route/app.php index fc853ac..4991c9b 100755 --- a/app/api/route/app.php +++ b/app/api/route/app.php @@ -158,3 +158,7 @@ Route::any('generate_urllink','Index/generate_urllink'); Route::any('generate_urllinks','Index/generate_urllinks'); +// + +Route::any('mall_ordermoney', 'Mall/mall_ordermoney'); +Route::any('mall_orderbuy', 'Mall/mall_orderbuy'); \ No newline at end of file