|
@@ -86,6 +86,45 @@ class Coupon extends Apic
|
|
|
}
|
|
|
|
|
|
//统一核销
|
|
|
+ public function gethexiao(){
|
|
|
+ $code = input('code','');
|
|
|
+ $code = explode('_',$code);
|
|
|
+ $action = $code[0];
|
|
|
+ $id = $code[1];
|
|
|
+
|
|
|
+ if($action != 'hexiaocoupon' && $action != 'hexiaoorder'){
|
|
|
+ $this->error('错误的核销码');
|
|
|
+ }
|
|
|
+
|
|
|
+ if($action == 'hexiaocoupon'){
|
|
|
+ $map = [
|
|
|
+ 'company_id' => $this->auth->company_id,
|
|
|
+ 'id' => $id,
|
|
|
+ 'remain' => ['gt',0],
|
|
|
+ ];
|
|
|
+ $check = Db::name('user_coupons')->field('id,coupon_name,coupon_info,endtime,getfrom')->where($map)->find();
|
|
|
+ if(!empty($check)){
|
|
|
+ $check['action'] = 'hexiaocoupon';
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $map = [
|
|
|
+ 'company_id' => $this->auth->company_id,
|
|
|
+ 'id' => $id,
|
|
|
+ 'ordertype' => 3,
|
|
|
+ 'status' => 2, //2=已支付,待处理
|
|
|
+ ];
|
|
|
+ $check = Db::name('order')->field('id,package_info,package_price')->where($map)->find();
|
|
|
+ if(!empty($check)){
|
|
|
+ $check['action'] = 'hexiaoorder';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->success(1,$check);
|
|
|
+
|
|
|
+ //$this->$action($id);
|
|
|
+ }
|
|
|
+
|
|
|
+ //统一核销
|
|
|
public function hexiao(){
|
|
|
$code = input('code','');
|
|
|
$code = explode('_',$code);
|
|
@@ -108,7 +147,7 @@ class Coupon extends Apic
|
|
|
];
|
|
|
|
|
|
Db::startTrans();
|
|
|
- $check = Db::name('user_coupons')->where($map)->find();
|
|
|
+ $check = Db::name('user_coupons')->where($map)->lock(true)->find();
|
|
|
if(empty($check)){
|
|
|
Db::rollback();
|
|
|
$this->error('不存在的卡券');
|
|
@@ -151,8 +190,30 @@ class Coupon extends Apic
|
|
|
|
|
|
|
|
|
//核销用户的套餐订单
|
|
|
- public function hexiaoorder(){
|
|
|
- $this->error('接口暂未完成');
|
|
|
+ public function hexiaoorder($order_id){
|
|
|
+ $map = [
|
|
|
+ 'company_id' => $this->auth->company_id,
|
|
|
+ 'id' => $order_id,
|
|
|
+ 'ordertype' => 3,
|
|
|
+ 'status' => 2, //2=已支付,待处理
|
|
|
+ ];
|
|
|
+
|
|
|
+ Db::startTrans();
|
|
|
+ $check = Db::name('order')->where($map)->lock(true)->find();
|
|
|
+ if(empty($check)){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('不存在的订单');
|
|
|
+ }
|
|
|
+
|
|
|
+ //数量减一
|
|
|
+ $rs = Db::name('order')->where($map)->update(['status'=>3,'hexiaotime'=>time()]);
|
|
|
+ if($rs === false){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('核销失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+ $this->success('订单核销完成');
|
|
|
}
|
|
|
|
|
|
}
|