|
@@ -74,8 +74,8 @@ class Order extends Base
|
|
|
->find();
|
|
|
if(empty($cl_info)) $this->error('优惠券不存在');
|
|
|
if($cl_info['past_at'] < date('Y-m-d H:i:s')) $this->error('优惠券已过期');
|
|
|
- if($cl_info['low_amount'] > bcsub($price_total,$price_express,2) ) $this->error('订单金额不够,在看看吧');
|
|
|
- if($cl_info['coupon_cash'] != $coupon_cash ) $this->error('优惠金额错误');
|
|
|
+ if($cl_info['low_amount'] > bcsub($price_total,$price_express,2) ) $this->error('订单金额不够,再看看吧');
|
|
|
+ if($cl_info['amount'] != $coupon_cash ) $this->error('优惠金额错误');
|
|
|
}
|
|
|
// 积分验证
|
|
|
$user = Db::table('store_member')->find($this->uid);
|
|
@@ -147,88 +147,140 @@ class Order extends Base
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
- * @title 生成订单
|
|
|
- * @desc 生成订单
|
|
|
+ * @title 生成订单(购物车)
|
|
|
+ * @desc 生成订单(购物车)
|
|
|
* @author qc
|
|
|
- * @url /api/Order/createOrder
|
|
|
+ * @url /api/Order/createOrderByTrolley
|
|
|
* @method POST
|
|
|
* @header name:Authorization require:1 desc:Token
|
|
|
- * @param name:s_id type:int require:1 default:-- desc:电影场次id
|
|
|
- * @param name:f_id type:int require:1 default:-- desc:电影id
|
|
|
- * @param name:price_total type:float require:1 default:-- desc:订单金额
|
|
|
- * @param name:total_num type:float require:1 default:-- desc:票总数
|
|
|
- * @param name:children_num type:int require:0 default:0 desc:儿童票数
|
|
|
- * @param name:children_price type:float require:0 default:0 desc:儿童票价
|
|
|
- * @param name:tel type:string require:1 default:0 desc:预留电话
|
|
|
- * @param name:remark type:string require:1 default:0 desc:备注
|
|
|
+ * @param name:ids type:string : default:1 desc:购物车记录id串(逗号分开)
|
|
|
+ * @param name:price_total type:float require:1 default:-- desc:支付金额(优惠后的商品金额+运费)
|
|
|
+ * @param name:price_goods type:float require:0 default:0 desc:商品总金额(没优惠的)
|
|
|
+ * @param name:price_express type:float require:0 default:0 desc:运费
|
|
|
+ * @param name:add_id type:int require:1 default:0 desc:收货地址id
|
|
|
+ * @param name:remark type:string require:0 default:0 desc:订单备注
|
|
|
+ * @param name:source type:int require:0 default:0 desc:商城的为0(默认),积分商城的值为1
|
|
|
+ * @param name:integral type:int require:0 default:0 desc:使用多少积分,source为1时必传
|
|
|
+ * @param name:int_cash type:float require:0 default:0 desc:积分抵扣多少钱,source为1时必传
|
|
|
+ * @param name:cl_id type:int require:0 default:0 desc:会员优惠券id,使用优惠券必传
|
|
|
+ * @param name:coupon_cash type:float require:0 default:0 desc:会员优惠券抵扣金额
|
|
|
+ * @return name:order_id type:int require:0 default:0 desc:成功时返回订单id
|
|
|
*/
|
|
|
- public function createOrder()
|
|
|
+ public function createOrderByTrolley()
|
|
|
{
|
|
|
- $s_id = input('post.s_id');//场次id
|
|
|
- $f_id = input('post.f_id');//电影id
|
|
|
- $price_total = input('post.price_total');//订单总金额
|
|
|
- $total_num = input('post.total_num');//订单总票数
|
|
|
- $ticket_price = input('post.ticket_price');//成人票价
|
|
|
- $children_num = input('post.children_num',0);//儿童票数
|
|
|
- $children_price = input('post.children_price',0);//儿童票价
|
|
|
- $remark = input('post.remark');
|
|
|
- $tel = input('post.tel');//场次id
|
|
|
- if($total_num == 0) $this->error('请选择购票数量');
|
|
|
- $screen = Db::table('film_info')
|
|
|
- ->alias('f')
|
|
|
- ->field('f.*,l.duration')
|
|
|
- ->join('film_list l','f.f_id = l.id')
|
|
|
- ->find($s_id);
|
|
|
- if($screen['surplus_num'] < $total_num) $this->error('余票不足');
|
|
|
- if(strtotime($screen['show_time']) - 600 < time()) $this->error('开场前10分钟已关闭售票');
|
|
|
- $screen['end_time'] = date('H:i',strtotime($screen['day_time'].' '.$screen['point_time'].":00") + $screen['duration']*60);
|
|
|
- $order_no = get_order_sn();
|
|
|
- $order_data=[
|
|
|
- 'order_no'=>$order_no,
|
|
|
+ $ids = input("post.ids");
|
|
|
+ $price_total = input("post.price_total");
|
|
|
+ $price_goods = input("post.price_goods");
|
|
|
+ $price_express = input("post.price_express");
|
|
|
+ $add_id = input("post.add_id");
|
|
|
+ $source = input("post.source",0);
|
|
|
+ $integral = input("post.integral",0);
|
|
|
+ $int_cash = input("post.int_cash",0);
|
|
|
+ $cl_id = input("post.cl_id",0);
|
|
|
+ $coupon_cash = input("post.coupon_cash",0);
|
|
|
+ $remark = input("post.remark",0);
|
|
|
+ if(!$ids) $this->error('请选择要结算的商品');
|
|
|
+ $trolley_arr = Db::table('shopping_trolley')
|
|
|
+ ->where(['uid'=>$this->uid,'id'=>explode(',',$ids)])
|
|
|
+ ->select();
|
|
|
+ $pro_info = [];$total_num = 0;$check_goods = true;
|
|
|
+ // 验证商品是否下架 && 获取订单商品详情
|
|
|
+ foreach ($trolley_arr as $tv) {
|
|
|
+ $goods_info = Db::table('store_goods')->field('id,spec,name')
|
|
|
+ ->where(['id'=>$tv['goods_id'],'is_deleted'=>0,'status'=>1])
|
|
|
+ ->find();
|
|
|
+ if(!empty($goods_info)){
|
|
|
+ $check_goods =false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ foreach (json_decode($tv['spec'],true) as $sv)
|
|
|
+ {
|
|
|
+ if($sv['goods_no'] == $tv['goods_no']) {
|
|
|
+ $pro_info[]=[
|
|
|
+ 'goods_id' =>$tv['goods_id'],
|
|
|
+ 'goods_no' =>$tv['goods_no'],
|
|
|
+ 'num' =>$tv['num'],
|
|
|
+ 'integral' =>$sv['integral'] * $tv['num'],
|
|
|
+ 'int_cash' =>'--',
|
|
|
+ 'sell_money'=>$sv['sell_money'],
|
|
|
+ 'spec_exp' =>$sv['spec_exp'],
|
|
|
+ 'spec_key' =>$sv['spec_key'],
|
|
|
+ ];
|
|
|
+ $total_num +=$tv['num'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!$check_goods) $this->error('所选商品已下架');
|
|
|
+ // 券验证
|
|
|
+ if($cl_id) {
|
|
|
+ $cl_info = Db::table('user_coupon_list')
|
|
|
+ ->where(['user_id'=>$this->uid,'id'=>$cl_id,'status'=>1])
|
|
|
+ ->find();
|
|
|
+ if(empty($cl_info)) $this->error('优惠券不存在');
|
|
|
+ if($cl_info['past_at'] < date('Y-m-d H:i:s')) $this->error('优惠券已过期');
|
|
|
+ if($cl_info['low_amount'] > bcsub($price_total,$price_express,2) ) $this->error('订单金额不够,再看看吧');
|
|
|
+ if($cl_info['amount'] != $coupon_cash ) $this->error('优惠金额错误');
|
|
|
+ }
|
|
|
+ // 积分验证
|
|
|
+ $user = Db::table('store_member')->find($this->uid);
|
|
|
+ if($integral && $user['integral'] < $integral) $this->error('积分余额不足');
|
|
|
+ $order_int =[
|
|
|
'uid'=>$this->uid,
|
|
|
- 'create_at'=>date('Y-m-d H:i:s'),
|
|
|
- 'create_tamp'=>time(),
|
|
|
- 's_id'=>$s_id,
|
|
|
- 'f_id'=>$f_id,
|
|
|
- 'price_total'=>$price_total,
|
|
|
- 'total_num'=>$total_num,
|
|
|
- 'children_num'=>$children_num,
|
|
|
- 'ticket_price'=>$ticket_price,
|
|
|
- 'remark'=>$remark,
|
|
|
- 'children_price'=>$children_price,
|
|
|
- 'tel'=>$tel,
|
|
|
- 's_info'=>json_encode($screen),
|
|
|
- 'year'=>date('Y'),
|
|
|
- 'month'=>date('m'),
|
|
|
- 'day'=>date('d'),
|
|
|
- 'hour'=>date('H')
|
|
|
+ 'order_no' => get_order_sn(),
|
|
|
+ 'price_total' => $price_total,
|
|
|
+ 'price_goods' => $price_goods,
|
|
|
+ 'price_express' => $price_express,
|
|
|
+ 'create_at' => date("Y-m-d H:i:s"),
|
|
|
+ 'address_id' =>$add_id,
|
|
|
+ 'source' =>$source,
|
|
|
+ 'integral' =>$integral,
|
|
|
+ 'int_cash' =>$int_cash,
|
|
|
+ 'coupon_id' =>$cl_id,
|
|
|
+ 'coupon_cash' =>$coupon_cash,
|
|
|
+ 'remark' =>$remark,
|
|
|
+ 'goods_num' =>$total_num,
|
|
|
+ 'pro_info' =>json_encode($pro_info)
|
|
|
];
|
|
|
Db::startTrans();
|
|
|
- $com = 1;// 是否提交事务
|
|
|
- $msg = '';
|
|
|
- $last_id = 0;
|
|
|
+ $msg= '';$com=true;
|
|
|
try{
|
|
|
- Db::table('film_info')->where('id', $s_id)->setDec('surplus_num', $total_num);//扣减余票
|
|
|
- Db::table('ticket_order')->insert($order_data);//
|
|
|
- $last_id = Db::getLastInsID();
|
|
|
+ // 生成订单
|
|
|
+ Db::table('store_order')->insert($order_int);
|
|
|
+ $order_id = Db::getLastInsID();
|
|
|
+ //扣减积分
|
|
|
+ if($integral){
|
|
|
+ Db::table('store_member')->where(['id'=>$this->uid])->setDec('integral',$integral);
|
|
|
+ //积分扣减记录
|
|
|
+ $integral_info=[
|
|
|
+ 'user_id'=> $this->uid,
|
|
|
+ 'create_at'=> date("Y-m-d H:i:s"),
|
|
|
+ 'integral'=> $integral * -1,
|
|
|
+ 'before'=> $user['integral'],
|
|
|
+ 'after'=> $user['integral'] - $integral,
|
|
|
+ 'desc'=> '积分抵现',
|
|
|
+ 'rel_id'=> $order_id,
|
|
|
+ ];
|
|
|
+ Db::table('integral_info')->insert($integral_info);
|
|
|
+ }
|
|
|
+ // 扣除券
|
|
|
+ if($cl_id) {
|
|
|
+ Db::table('user_coupon_list')->where(['id'=>$cl_id])->update(['status'=>2,'used_time'=>date('Y-m-d H:i:s')]);
|
|
|
+ }
|
|
|
Db::commit();
|
|
|
- }catch(\Exception $e){
|
|
|
+ }catch (\Exception $e){
|
|
|
Db::rollback();
|
|
|
+ $com=false;
|
|
|
$msg = $e->getMessage();
|
|
|
- $com= 0;
|
|
|
}
|
|
|
- if($com == 1){
|
|
|
- $this->success('生成订单成功',['id'=>$last_id]);
|
|
|
- } else{
|
|
|
+ if($com){
|
|
|
+ $this->success('ok',['order_id'=>$order_id]);
|
|
|
+ }else{
|
|
|
$this->error($msg);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* @title 获取订单详情
|
|
|
* @desc 获取订单详情
|