where('id', $uid)->field('id,path,xz_num,coupon_num')->find(); // 老马的下级不能转赠 if (strpos($user_info['path'], '7493430') !== false){ sr_throw('失败,请联系上面团队长'); } if ($uid == 7493430){ sr_throw('失败,请联系上面团队长'); } $dfgoods_info = Db::name('third_xzgoods')->where('prodoct_id', $prodoct_id)->findOrEmpty(); if (!$dfgoods_info){ sr_throw('参数错误'); } if ($dfgoods_info['type'] != 2){ sr_throw('参数错误'); } // 手续费 // $scale = env('XZTHIRD.XZ_EXCHARGE_SCALE', 5); $scale = get_user_shouxufei($uid); $cur_xzmoney = Db::name('system_config')->where('name', 'xz_cur_money')->where('group', 'xzconfig')->value('value'); $xz_num = getXzPirceWithPrice($cur_xzmoney, $dfgoods_info['sale_price']); $shouxu_num = number_format($xz_num*$scale/100, '2', '.', ''); $need_num = $xz_num + $shouxu_num; // sr_throw($need_num); if ($user_info['xz_num'] < $need_num){ sr_throw('星钻不足,兑换失败'); } if ($user_info['xz_num'] < ($need_num + 10)){ sr_throw('兑换失败,账户必须还有十个星钻剩余'); } // 抢购值 $need_couponnum = $dfgoods_info['spec']/10; if ($user_info['coupon_num'] < $need_couponnum){ sr_throw('抢购值不足,需'.$need_couponnum.'个抢购值'); } if (Db::name('thirdxz_hforder')->where('uid', $uid)->whereDay('create_time', 'today')->find()){ sr_throw('今日已兑换,请明天再来'); } // $limit = 30; // // 每天三十份 // if (Db::name('thirdxz_hforder')->whereDay('create_time', 'today')->count('id') > $limit-1){ // sr_throw('今日平台限量已达到'.$limit.'份,明日在来哦~~'); // } if (Db::name('thirdxz_hforder')->whereTime('create_time', 'month')->where('status', 2)->where('uid', $uid)->find()){ sr_throw('充值失败,每个美康用户每月只能兑换一次'); } // if (Db::name('thirdxz_hforder')->whereTime('create_time', 'month')->where('status', 2)->where('mobile', $mobile)->find()){ sr_throw('充值失败,每个手机号码每月只能兑换一次'); } // 添加订单表 $insert_id = self::insertGetId([ 'df_ordersn'=>creatDfOrderSn($uid), 'third_xzid'=>$dfgoods_info['id'], 'prodoct_id'=>$prodoct_id, 'create_time'=>sr_getcurtime(time()), 'uid'=>$uid, 'account'=>$account, 'address'=>$address, 'xz_num'=>$xz_num, 'mobile'=>$mobile, 'shouxu'=>$shouxu_num, 'price'=>$dfgoods_info['spec'], 'expect_time'=>sr_getcurtime(strtotime('+5 day'), 'Y-m-d') ]); // 扣除星钻 edit_user_xz(17, $uid, $need_num, $insert_id, $shouxu_num); // 扣除抢购值 edit_user_couponnum(4, $uid, $need_couponnum); } }