/** * 公共函数 */ function createCoupon($did, $oid) { $model = M("Coupon"); $coupon_no = $did . rand(10000, 99999); if ($model->where("coupon_no='{$coupon_no}'")->count()) { //重复 调用递归 return createCoupon($did, $oid); } else { $coupon['coupon_no'] = $coupon_no; $coupon['coupon_code'] = getRandStr(5, 1); $coupon['did'] = $did; $coupon['oid'] = $oid; $coupon['status'] = 1; $model->add($coupon); return; } }
protected function saveCoupon($detail) { $coupon = array(); for ($i = 0; $i < $detail['count']; $i++) { createCoupon($detail['did'], $detail['oid']); } }