From eeee1159d1a85bf8f037f29cef34f0a48619adac Mon Sep 17 00:00:00 2001 From: lqmac Date: Fri, 20 Oct 2023 00:39:52 +0800 Subject: [PATCH] 1 --- application/admin/controller/Order.php | 34 ++++++- application/admin/view/order/index.html | 13 ++- application/api/controller/Order.php | 123 ++++++++++++++++++------ public/assets/js/backend/order.js | 11 ++- 4 files changed, 144 insertions(+), 37 deletions(-) diff --git a/application/admin/controller/Order.php b/application/admin/controller/Order.php index 9c9696e..44510ea 100755 --- a/application/admin/controller/Order.php +++ b/application/admin/controller/Order.php @@ -4,6 +4,8 @@ namespace app\admin\controller; use app\common\controller\Backend; use app\admin\model\order\Detail; +use think\Db; +use think\Config; /** * * @@ -49,12 +51,42 @@ class Order extends Backend ->where($where) ->order($sort, $order) ->paginate($limit); + $site = Config::get("site"); foreach ($list as $k => &$v) { $v['detail']['goods_image'] = cdnurl($v['detail']['goods_image'], true); $v['createtime_text'] = date("Y-m-d H:i:s", $v['createtime']); $v['status_text'] = $this->model->getStatusList()[$v['status']] ?? ""; + $user = Db::name('user')->where('id', $v['buyer_id'])->field('pid')->find(); + $piduser = Db::name('user')->where('id', $user['pid'] ?? 0)->field('id,nickname')->find(); + $commission = bcmul($v['order_amount'], $site['primary_distribution'] * 0.01, 2); + $v['tuiguang'] = $piduser ? $piduser['nickname']."(".$commission.")" : ""; } - $result = array("total" => $list->total(), "rows" => $list->items()); + + $single = Db::name('order')->alias('order') + ->join('warehouse warehouse', 'order.warehouse_id = warehouse.id','left') + ->join('user user', 'user.id = order.buyer_id', 'left') + ->join('user user1', 'user1.id = order.seller_id', 'left') + ->join('order_detail detail', 'detail.order_id = order.id', 'left') + ->field("count(order.id) as order_count,sum(order.order_amount) as order_amount,sum(order.coupon_price) as coupon_price,count(distinct order.buyer_id) as user_count") + ->where($where) + ->find(); + // var_dump($single); + // exit; + $order_amount = $single['order_amount'] ?? 0; + $coupon_price = $single['coupon_price'] ?? 0; + $order_count = $single['order_count'] ?? 0; + $user_count = $single['user_count'] ?? 0; + + $result = array( + "total" => $list->total(), + "rows" => $list->items(), + "extend" => [ + 'order_amount' => bcdiv($order_amount, 1, 2), + 'coupon_price' => bcdiv($coupon_price, 1, 2), + 'order_count' => $order_count, + 'user_count' => $user_count, + ] + ); return json($result); } diff --git a/application/admin/view/order/index.html b/application/admin/view/order/index.html index 67b57d7..6913840 100755 --- a/application/admin/view/order/index.html +++ b/application/admin/view/order/index.html @@ -7,12 +7,19 @@
diff --git a/application/api/controller/Order.php b/application/api/controller/Order.php index 2cd5871..7992286 100755 --- a/application/api/controller/Order.php +++ b/application/api/controller/Order.php @@ -48,7 +48,10 @@ class Order extends Api continue; } - $value['is_allow_access'] = $this->userIsAllowAccess($user, $value, $time) > 0 ? 1 : 0; + $value['is_allow_access'] = 0; + if ($user['pid'] > 0) { + $value['is_allow_access'] = 1; + } } @@ -61,15 +64,20 @@ class Order extends Api * @param [type] $warehouse [description] * @return [type] [description] */ - public function userIsAllowAccess($user, $warehouse, $time){ + public function userIsAllowAccess($user, $warehouse, $goods, $time){ $advance_access_minute = $user['advance_access_minute'] * 60; $is_allow_access = 0; //是否在时间范围内 $start = strtotime($warehouse['start']); $end = strtotime($warehouse['end']); + $start_date = date("Y-m-d H:i:s",$start); + $end_date = date("Y-m-d H:i:s", $end); + $code = $start."-".$end; //仓库限制用户总抢购次数 if ($warehouse['limit_buy_num'] > 0) { - $count = Db::name('user_access_record')->where('user_id', $user['id'])->count(); + $count = Db::name('user_access_record')->where('user_id', $user['id'])->where('warehouse_id', $warehouse['id'])->where('code', $code)->count(); + // var_dump($count); + // exit(); if ($count > $warehouse['limit_buy_num']) { $is_allow_access = 0; return $is_allow_access; @@ -81,7 +89,7 @@ class Order extends Api if (($time + $advance_access_minute) >= $start && ($time + $advance_access_minute) <= $end) { //提前进入次数 - $count = Db::name('user_access_record')->where('user_id', $user['id'])->where('is_advance', 1)->count(); + $count = Db::name('user_access_record')->where('user_id', $user['id'])->where('warehouse_id', $warehouse['id'])->where('code', $code)->where('is_advance', 1)->count(); if ($user['advance_access_num'] == 0 || $count < $user['advance_access_num']) { $is_allow_access = 1; return $is_allow_access; @@ -92,7 +100,7 @@ class Order extends Api //正常进场 if ($time >= $start && $time <= $end) { //正常进入次数 - $count = Db::name('user_access_record')->where('user_id', $user['id'])->where('is_advance',0)->count(); + $count = Db::name('user_access_record')->where('user_id', $user['id'])->where('warehouse_id', $warehouse['id'])->where('code', $code)->where('is_advance',0)->count(); if ($user['buy_goods_num_per_day'] == 0 || $count < $user['buy_goods_num_per_day']) { $is_allow_access = 2; return $is_allow_access; @@ -103,6 +111,59 @@ class Order extends Api return $is_allow_access; } + /** + * 限制购买次数 + * [limitBuyNum description] + * @param [type] $user [description] + * @param [type] $warehouse [description] + * @return [type] [description] + */ + public function limitBuyNum($user, $warehouse){ + $is_allow_access = 0; + //是否在时间范围内 + $start = strtotime($warehouse['start']); + $end = strtotime($warehouse['end']); + $start_date = date("Y-m-d H:i:s",$start); + $end_date = date("Y-m-d H:i:s", $end); + $code = $start."-".$end; + //仓库限制用户总抢购次数 + $count = Db::name('user_access_record')->where('user_id', $user['id'])->where('warehouse_id', $warehouse['id'])->where('code', $code)->count(); + + if ($warehouse['limit_buy_num'] > 0 && $count > $warehouse['limit_buy_num']) { + $is_allow_access = 1; + return $is_allow_access; + } + + //提前进入次数 + $count = Db::name('user_access_record')->where('user_id', $user['id'])->where('warehouse_id', $warehouse['id'])->where('code', $code)->where('is_advance', 1)->count(); + if ($user['advance_access_num'] > 0 && $count > $user['advance_access_num']) { + $is_allow_access = 1; + return $is_allow_access; + } + + //正常进入次数 + $count = Db::name('user_access_record')->where('user_id', $user['id'])->where('warehouse_id', $warehouse['id'])->where('code', $code)->where('is_advance',0)->count(); + if ($user['buy_goods_num_per_day'] > 0 && $count > $user['buy_goods_num_per_day']) { + $is_allow_access = 1; + return $is_allow_access; + } + + + return $is_allow_access; + } + /** + * 获取购买时间 + * [getBuyTime description] + * @param [type] &$warehouse [description] + * @param [type] $user [description] + * @return [type] [description] + */ + public function getBuyTime(&$warehouse, $user){ + $advance_access_minute = $user['advance_access_minute'] * 60; + $time = strtotime($warehouse['start']) - $advance_access_minute; + + $warehouse['start'] = date("H:i", $time); + } /** * 商品列表 * [getGoodsList description] @@ -117,11 +178,12 @@ class Order extends Api if (!$warehouse) { $this->error("区域不存在"); } - $is_allow_access = $this->userIsAllowAccess($user, $warehouse, time()); - if ($is_allow_access == 0) { - $this->error("不允许进入抢购"); + $is_allow_access = $this->limitBuyNum($user, $warehouse); + // $is_allow_access = $this->userIsAllowAccess($user, $warehouse, time()); + if ($is_allow_access > 0 ) { + $this->error("抢购次数被限制"); } - $list = Goods::where('warehouse_id', $warehouse_id)->where('goods_type', 1)->order('id', 'desc')->paginate($this->request->param('list_rows', $limit))->each(function ($item, $key){ + $list = Goods::where('warehouse_id', $warehouse_id)->where('goods_type', 1)->where('owner_id', "<>", $user['id'])->order('status', 'desc')->order('id', 'desc')->paginate($this->request->param('list_rows', 20))->each(function ($item, $key){ $warehouse = Warehouse::where('id', $item['warehouse_id'])->find(); $owner = User::where('id', $item['owner_id'])->find(); $item['warehouse'] = $warehouse; @@ -145,11 +207,12 @@ class Order extends Api } $user = $this->auth->getUserinfo(); $warehouse = Warehouse::where('id', $info['warehouse_id'])->find(); - $is_allow_access = $this->userIsAllowAccess($user, $warehouse, time()); - if ($is_allow_access == 0) { - $this->error("不允许进入抢购"); - } + // $is_allow_access = $this->userIsAllowAccess($user, $warehouse, time()); + // if ($is_allow_access == 0) { + // $this->error("不允许进入抢购"); + // } $warehouse = Warehouse::where('id', $info['warehouse_id'])->find(); + $this->getBuyTime($warehouse, $user); $owner = User::where('id', $info['owner_id'])->find(); $info['warehouse'] = $warehouse; $info['owner'] = $owner; @@ -161,7 +224,7 @@ class Order extends Api $code = $start."-".$end; $info1 = Db::name('user_access_record')->where('warehouse_id', $info['warehouse_id'])->where('user_id', $user['id'])->where('code', $code)->count(); if (!$info1) { - Db::name('user_access_record')->insert(['user_id' => $user['id'],'warehouse_id' => $info['warehouse_id'],'code' => $code, "createtime"=>time(), 'is_advance' => $is_allow_access == 1 ? 1 : 2]); + Db::name('user_access_record')->insert(['user_id' => $user['id'],'warehouse_id' => $info['warehouse_id'],'code' => $code, "createtime"=>time(), 'is_advance' => $user['advance_access_minute'] > 0 ? 1 : 0]); } $this->success("succ", $info); } @@ -186,19 +249,7 @@ class Order extends Api } $order_amount = $goods['price'] * $num; $coupon_price = 0; - if ($coupon_id) { - // $coupon = UserCouponModel::with('coupon')->where('id', $coupon_id)->where('user_id', $user_id)->find(); - // if($order_amount < $coupon['enough']) { - // $this->error("不能使用优惠卷"); - // } - // if($coupon['use_time'] > 0) { - // $this->error("优惠卷已使用"); - // } - // if(strtotime($coupon['user_end_time']) < time()) { - // $this->error("优惠卷已过期"); - // } - // $coupon_price = $coupon['amount'] ?? 0; - } + $pay_amount = $order_amount - $coupon_price; @@ -265,6 +316,8 @@ class Order extends Api $where = []; if ($status != "") { $where['status'] = ['in', explode(",", $status)]; + } else { + $where['status'] = ['in', [0,1,3,4,5,6]]; } $list = OrderModel::where('seller_id', $user_id)->where($where)->order('id', 'desc')->paginate($this->request->param('list_rows', $limit))->each(function ($item, $key){ $order_goods = Detail::where('order_id', $item['id'])->select(); @@ -294,6 +347,8 @@ class Order extends Api $where = []; if ($status != "") { $where['status'] = ['in', explode(",", $status)]; + } else { + $where['status'] = ['in', [0,1,2,3,4,5,6,7]]; } $list = OrderModel::where('buyer_id', $user_id)->where($where)->order('id', 'desc')->paginate($this->request->param('list_rows', $limit))->each(function ($item, $key){ $order_goods = Detail::where('order_id', $item['id'])->select(); @@ -337,6 +392,7 @@ class Order extends Api $info['entrustment_ratio'] = Config::get("site.entrustment_ratio"); $seller = User::where('id', $info['seller_id'])->field(['id', 'username', 'nickname', 'mobile', 'avatar', 'score','sign_image','sign_status','alipay_image','wechat_image','buy_goods_num_per_day','advance_access_num','bank_realname','bank_mobile','bank_no','bank_address','reason','warehouse_id','advance_access_minute','deadline','pid','total_commission_amount','available_commission_amount'])->find(); $info['seller'] = $seller; + $info['pay_voucher'] = cdnurl($info['pay_voucher'], true); $this->success("succ", $info); } /** @@ -447,7 +503,7 @@ class Order extends Api if($coupon['use_time'] > 0) { $this->error("优惠卷已使用"); } - if(strtotime($coupon['user_end_time']) < time()) { + if(strtotime($coupon['use_end_time']) < time()) { $this->error("优惠卷已过期"); } $coupon_price = $coupon['amount'] ?? 0; @@ -488,10 +544,11 @@ class Order extends Api $order_data['status'] = 1;//佣金支付 Db::name("pay_record")->insert($order_data); //修改商品价格和归属人 - Goods::where('id', $goods['goods_id'])->update(['price' => $goods_price, 'owner_id' => $user_id,"updatetime" => time(),'status'=>'normal']); + Goods::where('id', $goods['goods_id'])->update(['price' => intval($goods_price), 'owner_id' => $user_id,"updatetime" => time(),'status'=>'normal']); //写入用户收益 $profit = bcmul($goods['goods_price'], (Config::get("site.entrusted_ratio") - Config::get("site.entrustment_ratio")) * 0.01, 2); + $profit = $profit + $coupon_price + $pay_amount; Record::create(["user_id" => $user_id, "type" => 2, "item_id" => $order_id,"amount"=> $profit]); //修改用户可用佣金 User::where('id', $user_id)->update(['available_commission_amount' => $user['available_commission_amount'] - $pay_amount,"profit_amount" =>$profit, "updatetime" => time()]); @@ -568,18 +625,20 @@ class Order extends Api Db::name("pay_record")->where('order_id', $order_id)->update(['status'=>1, "update_time"=>time()]); //修改商品价格和归属人 $goods_price = bcmul($goods['goods_price'], (Config::get("site.entrusted_ratio") * 0.01 + 1), 2); - Goods::where('id', $goods['goods_id'])->update(['price' => $goods_price, 'owner_id' => $user_id,"updatetime" => time(),"status"=>'normal']); + Goods::where('id', $goods['goods_id'])->update(['price' => intval($goods_price), 'owner_id' => $user_id,"updatetime" => time(),"status"=>'normal']); + $order_info = OrderModel::where("id", $order_id)->find(); //写入用户收益 $profit = bcmul($goods['goods_price'], (Config::get("site.entrusted_ratio") - Config::get("site.entrustment_ratio")) * 0.01, 2); - Record::create(["user_id" => $user_id, "type" => 2, "item_id" => $order_id,"amount"=> $profit]); + $profit = $profit + $order_info['coupon_price'] + $goods['dikou_price']; + Record::create(["user_id" => $user_id, "type" => 2, "item_id" => $order_id,"amount"=> $profit ]); //修改用户可用佣金 User::where('id', $user_id)->update(['available_commission_amount' => $user['available_commission_amount'] - $goods['dikou_price'],"profit_amount" => $user['profit_amount'] + $profit, "updatetime" => time()]); //更新订单状态 OrderModel::where("id", $order_id)->update(['status' => 7]); //使用优惠卷 - $order_info = OrderModel::where("id", $order_id)->find(); + if ($order_info['coupon_id']) { UserCouponModel::where('id', $order_info['coupon_id'])->update(['use_order_id'=>$order_id, "use_time"=>time()]); } diff --git a/public/assets/js/backend/order.js b/public/assets/js/backend/order.js index 1fb22b3..597f009 100755 --- a/public/assets/js/backend/order.js +++ b/public/assets/js/backend/order.js @@ -16,7 +16,15 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin }); var table = $("#table"); - + table.on('load-success.bs.table', function (e, data) { + //这里可以获取从服务端获取的JSON数据console.log(data);//这里我们手动设置底部的值 + $("#order_count").text(data.extend.order_count); + $("#order_amount").text(data.extend.order_amount); + $("#coupon_price").text(data.extend.coupon_price); + + $("#user_count").text(data.extend.user_count); + + }); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, @@ -69,6 +77,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin {field: 'user.mobile', title: __('购买人手机号'),visible:false,operate:"LIKE"}, {field: 'user1.mobile', title: __('售卖人手机号'),visible:false,operate:"LIKE"}, + {field: 'tuiguang', title: __('推广'), operate:false}, {field: 'order_amount', title: __('应付金额'), operate:'BETWEEN'}, {field: 'pay_amount', title: __('实付金额'), operate:'BETWEEN'}, {field: 'coupon_price', title: __('委托优惠金额'), operate:'BETWEEN'},