@ -41,7 +41,7 @@ class Order extends Api
$this->success('succ');
}
$time = time();
foreach ($list as $key => $value) {
foreach ($list as $key => & $value) {
if ($value['id'] != $user['warehouse_id']) {
unset($list[$key]);
@ -52,7 +52,10 @@ class Order extends Api
if ($user['pid'] > 0) {
$value['is_allow_access'] = 1;
}
if (in_array($user['id'], [61])) {
$value['status'] ='normal';
$value['is_allow_access'] = 1;
}
}
$this->success('succ', array_values($list));
@ -239,6 +242,7 @@ class Order extends Api
$num = $this->request->post("num", 1);
$coupon_id = $this->request->post("coupon_id", 0);
$user_id = $this->auth->id;
$user = $this->auth->getUserinfo();
$address = Address::where('id', $address_id)->where('user_id', $user_id)->find();
if (!$address) {
$this->error("收货地址不存在");
@ -247,11 +251,19 @@ class Order extends Api
if (!$goods) {
$this->error("商品不存在");
}
$warehouse = Warehouse::where('id', $goods['warehouse_id'])->find();
$this->getBuyTime($warehouse, $user);
if (time() < strtotime ( $ warehouse [ ' start ' ] ) ) {
$this->error("抢购时间还没到!");
}
if (time() > strtotime($warehouse['end'])) {
$this->error("抢购时间已结束!");
}
//exit();
$order_amount = $goods['price'] * $num;
$coupon_price = 0;
$pay_amount = $order_amount - $coupon_price;
$order_sn = "ZH".date("YmdHis").rand(1000,9999);
//创建订单
@ -301,6 +313,9 @@ class Order extends Api
$obj->userCommission(0, $this->auth->getUserinfo(), $order_sn, $commission);
//更新商品状态为下架
Goods::where('id', $goods_id)->update(['status' => 'hidden', "updatetime" => time()]);
$this->success("succ");
}
/**
@ -317,7 +332,7 @@ class Order extends Api
if ($status != "") {
$where['status'] = ['in', explode(",", $status)];
} else {
$where['status'] = ['in', [0,1,3,4,5,6 ]];
$where['status'] = ['in', [0,1,3,4,5]];
}
$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();
@ -348,7 +363,7 @@ class Order extends Api
if ($status != "") {
$where['status'] = ['in', explode(",", $status)];
} else {
$where['status'] = ['in', [0,1,2,3,4,5,6, 7]];
$where['status'] = ['in', [0,1,2,3,4,5,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();
@ -441,11 +456,24 @@ class Order extends Api
$this->error("订单不存在");
}
$upData = ['updatetime' => time()];
if ($pay_voucher ) {
if ($status == 1 ) {
$upData['pay_voucher'] = $pay_voucher;
$upData['pay_time'] = time();
$upData['pay_method'] = $pay_method;
$upData['status'] = $status;
$detail = Detail::where("order_id", $id)->find();
//更新该商品的最后一个已上架的订单为已完成
$single = Db::name('order')->alias('order')
->join('order_detail detail', 'detail.order_id = order.id', 'left')
->field("order.id")
->where("goods_id", $detail['goods_id'])
->where("status", 7)
->order("order.id desc")
->find();
if ($single) {
OrderModel::where('id', $single['id'])->update(['status' => 6, "updatetime" =>time()]);
}
} else {
$upData['status'] = $status;
}
@ -475,9 +503,11 @@ class Order extends Api
$user_id = $user['id'];
$goods = Detail::where('order_id', $order_id)->find();
if (!$goods) {
$order = OrderModel::where("id", $order_id)->where('status', 2)->find();
if (!$goods || !$order) {
$this->error("订单不存在");
}
//商品是否上架
$goods_info = Goods::where('id', $goods['goods_id'])->where('status', 'hidden')->find();
if (!$goods_info) {
@ -512,8 +542,8 @@ class Order extends Api
$this->error("优惠卷已过期");
}
$coupon_price = $coupon['amount'] ?? 0;
OrderModel::where("id", $order_id)->update(['coupon_id' => $coupon_id, 'coupon_price' => $coupon_price]);
}
OrderModel::where("id", $order_id)->update(['coupon_id' => $coupon_id, 'coupon_price' => $coupon_price]);
$pay_sn = "NO".date("YmdHis").rand(1000,9999);
$fee = bcmul($order_amount, Config::get("site.entrustment_ratio") * 0.01, 2);
$pay_amount = $fee - $coupon_price;
@ -543,6 +573,7 @@ class Order extends Api
// var_dump($order_data);
// var_dump($params);
// exit();
//是否使用佣金
if ($use_commission) {
if ($pay_amount < $user['available_commission_amount']) {
$order_data['pay_source'] = 0;//佣金支付
@ -585,6 +616,17 @@ class Order extends Api
Detail::where("order_id", $order_id)->update(['commission_price' => $goods_price, "fee" => $fee, "dikou_price" => $user['available_commission_amount']]);
}
} else {
//写微信支付
$order_data['pay_source'] = 1;//微信支付
$order_data['out_trade_no'] = $pay_sn;//微信支付
$order_data['pay_amount'] = $pay_amount;
Db::name("pay_record")->insert($order_data);
//修改微信支付信息
$params['amount'] = $order_data['pay_amount'];
$params['orderid'] = $pay_sn;
Detail::where("order_id", $order_id)->update(['commission_price' => $goods_price, "fee" => $fee, "dikou_price" => 0]);
}
//$params['amount'] = 0.01;
try {