$memberId, 'couponCode'=>$data['virtual_code'], //虚拟商品编号 "quantity"=>$data['quantity'], //数量 ] ); if($checkCard['code']){ ds_json_encode(10001,$checkCard['msg']); return false; } $resData = []; $time = time(); foreach($checkCard['data'] as $k=>$v){ $resInfo = []; $resInfo['voucher_code'] = ''; $resInfo['voucher_pwd'] = ''; $resInfo['content'] = ''; if(!empty($v['couponCode'])){ $resInfo['voucher_type'] = 1; $resInfo['voucher_code'] = $v['couponCode']; if(!empty($v['couponPwd'])){ $resInfo['voucher_type'] = 2; $resInfo['voucher_pwd'] = $v['couponPwd']; } }else{ $resInfo['voucher_code'] = $v['couponCode']; } if(!empty($v['qrCode'])){ $resInfo['voucher_type'] = 3; $resInfo['content'] = $v['qrCode']; } $resInfo['desc'] = $v['couponName']; $resInfo['voucher_name'] = empty($v['couponName']) ? '' : $v['couponName']; $resInfo['create_time'] = $time; $resInfo['member_id'] = $memberId; $resInfo['voucher_status'] = $v['status']; $resInfo['start_time'] = strtotime($v['startDateTime']); $resInfo['expire_time'] = strtotime($v['endDateTime']); $resInfo['voucher_flag'] = $v['id']; $resInfo['tag_id'] = $data['order_id']; $resData[] = $resInfo; } if (empty($resData)) { return true; //为空直接返回true } $flagIds = array_column($resData, 'voucher_flag'); $flagList = Db::name('sub_voucher')->where([ ['voucher_flag', 'in', $flagIds] ])->column('voucher_flag'); if (!empty($flagList)) { //已经存在的 $str = "以下消费券:"; $flagStr = implode('、', $flagList); $showStr = $str . $flagStr . "。已经绑定过,请刷新后查看。"; // ds_json_encode(10001,$showStr); return true; } if (!empty($resData)) { $res = Db::name('sub_voucher')->insertAll($resData); if ($res) { return true; } else { ds_json_encode(10001, '消费券关联失败'); } } } }