diff --git a/app/common.php b/app/common.php index 52e6feb..911bfbd 100644 --- a/app/common.php +++ b/app/common.php @@ -872,4 +872,14 @@ if (!function_exists('encodeCouponCycle')) { } } - +if (!function_exists('is_mobile')) { + /** + * 判断手机号 + * @param string $num 要验证的手机号 + * @return bool + */ + function is_mobile($num) + { + return preg_match("/^1(3|4|5|6|7|8|9)\d{9}$/", $num); + } +} diff --git a/app/controller/api/Coupon.php b/app/controller/api/Coupon.php index bc759c9..1b60bff 100644 --- a/app/controller/api/Coupon.php +++ b/app/controller/api/Coupon.php @@ -9,6 +9,7 @@ use app\model\CouponMain; use app\model\Deduction; use app\model\Redpack; use app\model\Score; +use app\model\UsingRule; use app\repository\AccountRepository; use app\repository\BusinessRepository; use app\repository\CouponRepository; @@ -194,7 +195,7 @@ class Coupon extends Base try { //检查是否可以领取 0可领取 1已领取 - AccountRepository::getInstance()->getCouponReceiveStatusText($account->user_code,$couponMain);//领取状态 + AccountRepository::getInstance()->getCouponReceiveStatusText($account,$couponMain);//领取状态 }catch (RepositoryException $e){ return $this->json(4001,$e->getMessage()); } @@ -224,6 +225,7 @@ class Coupon extends Base "is_verificated" => couponMain::COMMON_OFF,//版本 未知作用 ]; CouponRepository::getInstance()->receiveCoupon($data); + $couponMain->save(["received_count"=>Db::raw("received_count + 1")]); Db::commit(); return $this->json(); }catch (RepositoryException $e){ @@ -260,7 +262,7 @@ class Coupon extends Base } $coupon = CouponRepository::getInstance()->findById($couponId,[],function ($q){ - return $q->with(["couponMain"]); + return $q->with(["couponMain","redpack"]); }); if($coupon->consumer_code != $account->user_code ){ @@ -276,14 +278,27 @@ class Coupon extends Base if($coupon->on_shelf != CouponMain::on_shelf_on){ return $this->json(4001, "优惠券下架"); } - if(strtotime($coupon->end_time) < $time){ + + + if(!isset($coupon->couponMain) || empty($coupon->couponMain)){ + return $this->json(4001, "商家优惠券信息错误"); + } + $usingRule = UsingRule::findOne(["coupon_id"=>$coupon->couponMain->id]); + if(empty($usingRule)){ + return $this->json(4001, "商家优惠券使用规则信息错误"); + } + if(strtotime($coupon->couponMain->end_time) < $time){ return $this->json(4001, "优惠券已过期"); } - if(!isset($coupon->couponMain)||empty($coupon->couponMain)){ - return $this->json(4001, "商家优惠券信息错误"); + //一天的开始时间 + if(strtotime(date("Y-m-d " . $usingRule->day_start_time)) > $time){ + return $this->json(4001, "请在当天{$usingRule->day_start_time}-{$usingRule->day_start_time}使用"); + } + //一天的结束时间 + if(strtotime(date("Y-m-d ".$usingRule->day_end_time)) < $time){ + return $this->json(4001, "请在当天{$usingRule->day_start_time}-{$usingRule->day_start_time}使用"); } - $business = BusinessRepository::getInstance()->getModel()->with(["agency"])->where(["code"=>$coupon->couponMain->business_code])->lock(true)->find(); if(empty($business)){ return $this->json(4001, "商家不存在"); @@ -298,90 +313,111 @@ class Coupon extends Base try { // 1. 修改优惠券状态 $coupon->save([ - "is_verificated"=>CouponModel::is_verificated_on, - "used_time"=>date("Y-m-d H:i:s" ,$time), - "verificate_time"=>date("Y-m-d H:i:s" ,$time) + "is_verificated" => CouponModel::is_verificated_on, + "used_time" => date("Y-m-d H:i:s" ,$time), + "verificate_time" => date("Y-m-d H:i:s" ,$time), + ]); + $coupon->couponMain->save([ + "verification_count" => Db::raw("verification_count + 1"),//已验证数量+1 + "using_count" => Db::raw("using_count - 1"),//进行中数量-1 ]); + //可分配金额 - $deductionMoney = $coupon->couponMain->deduction_money; - $agencyMoney = ($deductionMoney/100) * $coupon->couponMain->commission_agency; - $adminMoney = ($deductionMoney/100) * $coupon->couponMain->commission_admin; - $consumerMoney = ($deductionMoney/100) * $coupon->couponMain->commission_consumer; + $deductionMoney = $coupon->couponMain->deduction_money; + $agencyMoney = (($deductionMoney/100) * $coupon->couponMain->commission_agency); + $adminMoney = (($deductionMoney/100) * $coupon->couponMain->commission_admin); + $consumerMoney = (($deductionMoney/100) * $coupon->couponMain->commission_consumer); + $agencyMoney = round($agencyMoney,2); //四舍五入 精确到分 + $adminMoney = round($adminMoney,2); //四舍五入 精确到分 + $consumerMoney = round($consumerMoney,2); //四舍五入 精确到分 // 2. 写入优惠券流水 $couponBillData = [ - "coupon_main_id"=>$coupon->couponMain->id, - "coupon_id"=>$coupon->id, - "user_code"=>$account->user_code, - "agency_code"=>$business->agency_code, - "commission_agency"=>$coupon->couponMain->commission_agency, - "commission_admin"=>$coupon->couponMain->commission_admin, - "commission_consumer"=>$coupon->couponMain->commission_consumer, - "money"=>$coupon->couponMain->money, - "agency_money"=>$agencyMoney, - "admin_money"=>$adminMoney, - "consumer_money"=>$consumerMoney, - "lat"=>$lat, - "lng"=>$lng, + "coupon_main_id" =>$coupon->couponMain->id, + "coupon_id" =>$coupon->id, + "user_code" =>$account->user_code, + "agency_code" =>$business->agency_code, + "commission_agency" =>$coupon->couponMain->commission_agency, + "commission_admin" =>$coupon->couponMain->commission_admin, + "commission_consumer" =>$coupon->couponMain->commission_consumer, + "money" =>$coupon->couponMain->money, + "agency_money" =>$agencyMoney, + "admin_money" =>$adminMoney, + "consumer_money" =>$consumerMoney, + "lat" =>$lat, + "lng" =>$lng, ]; $couponBill = CouponBill::create($couponBillData); // 3. 写入商家扣费记录 $deductionData = [ - "money"=>$deductionMoney, - "business_code"=>$business->code, - "business_name"=>$business->business_name, - "balance"=>$business->balance - $deductionMoney, - "reason"=> sprintf("[%s]验证优惠券[%s]扣除[%s]",$account->nick_name, $coupon->couponMain->name,$deductionMoney), - "coupon_main_id"=> $coupon->couponMain->id, - "coupon_id"=> $coupon->id, - "bill_id"=> $couponBill->id, - "create_time"=> date("Y-m-d H:i:s",$time), + "money" => $deductionMoney, + "business_code" => $business->code, + "business_name" => $business->business_name, + "balance" => $business->balance - $deductionMoney, + "reason" => sprintf("[%s]验证优惠券[%s]扣除[%s]",$account->nick_name, $coupon->couponMain->name,$deductionMoney), + "coupon_main_id" => $coupon->couponMain->id, + "coupon_id" => $coupon->id, + "bill_id" => $couponBill->id, + "create_time" => date("Y-m-d H:i:s",$time), ]; Deduction::create($deductionData); //4. 商家扣钱 - $business->save(["balance"=>$business->balance - $deductionMoney]); + $business->save(["balance"=>Db::raw("balance - {$deductionMoney}")]); //5. 渠道商加钱 - if(isset($business->agency)&&$business->agency){ + if(isset($business->agency) && $business->agency){ $business->agency->inc("balance",$agencyMoney)->update(); } - //6. 用户提现到零钱 - $RedpackData =[ - "mch_billno"=>createUuid(), - "openid"=>$account->open_id, - "user_code"=>$account->user_code, - "money"=>$consumerMoney*100, - ]; - $redpackModelData = Redpack::create($RedpackData); - $payment = WechatPay::getInstance(); + //6. 用户提现到零钱 写入红包记录 + if($consumerMoney > 0){ + $payment = WechatPay::getInstance(); - $redpack = $payment->redpack; - $res = $redpackData = [ - 'mch_billno' => $time.randomStr(0,10), - 'send_name' => '红包', - 're_openid' => $redpackModelData->openid, - 'total_num' => 1, //固定为1,可不传 - 'total_amount' => $redpackModelData->money, //单位为分,不小于100 - 'wishing' => '恭喜发财', - 'client_ip' => $this->request->ip(), //可不传,不传则由 SDK 取当前客户端 IP - 'act_name' => '验证优惠券得红包', - 'remark' => '验证优惠券得红包',//测试备注 - // ... - ]; + //如果付款过一次了 就查询付款状态 + if(isset($coupon->redpack)&&$coupon->redpack){ + $result = $payment->transfer->queryBalanceOrder($coupon->redpack->mch_billno); + //var_dump($result); + //企业付款成功 + if(isset($result["status"])&&$result["status"]=="SUCCESS"){ + Db::commit(); + return $this->json(); + } + Log::info("查询企业付款失败:".json_encode($result,JSON_UNESCAPED_UNICODE)); + }else{ + $mch_billno = createUuid(); + $amount = $consumerMoney*100; + $toBalanceData = [ + 'partner_trade_no' =>$mch_billno,// 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号) + 'openid' => $account->open_id, + 'check_name' => 'NO_CHECK',// NO_CHECK:不校验真实姓名, FORCE_CHECK:强校验真实姓名 + 'amount' => $amount, //单位为分,不小于100 + 'desc' => '验证优惠券签到', + ]; + $result = $payment->transfer->toBalance($toBalanceData); + //var_dump($result); - $result = $redpack->sendNormal($redpackData); - var_dump($result); + //付款成功才提交 + if(isset($result['payment_no'])){ + Db::commit(); + return $this->json(); + } + Log::info("企业发起付款失败:".json_encode($result,JSON_UNESCAPED_UNICODE)); + } - Db::rollback(); + //默认回滚 + Db::rollback(); + return $this->json(5001, "验证失败,发放红包失败"); + } + Db::commit(); + return $this->json(); }catch (RepositoryException $e){ Db::rollback(); - return $this->json(5001, "服务器错误"); + return $this->json(5001, "Repository服务器错误"); }catch (\Exception $e){ - echo $e->getMessage(); + //echo $e->getMessage(); Db::rollback(); return $this->json(5002, "服务器错误"); } @@ -462,7 +498,10 @@ class Coupon extends Base $couponMain['money'] = floor($couponMain['money'] * 100) / 100; $totalMoney = $couponMain['money'] * $couponMain['count']; - if ($account->business["balance"] < $totalMoney) { + //未领取的优惠券 + $NotClaimedMoney = CouponRepository::getInstance()->getBusinessNotClaimedCoupon($account->business["code"]); + + if ($account->business["balance"] < ($totalMoney + $NotClaimedMoney)) { return $this->json(4001, '商家余额不足'); } @@ -706,4 +745,50 @@ class Coupon extends Base return $this->json(0,"success",$couponMain->toArray()); } + + /** + * 已使用优惠券 评分 + * */ + public function score() + { + $accountId = $this->request->user['user_id'] ?? 0; + $couponId = input("couponId/d",0); + $score = input("score/d",5); + + if($score > 5|| $score <= 0){ + return $this->json(4001, "参数错误"); + } + $account = AccountRepository::getInstance()->findById($accountId, [], function ($q) { + return $q->with(['business', 'parent']); + }); + + if(empty($account)){ + return $this->json(6001,"无效的用户"); + } + + $coupon = CouponRepository::getInstance()->findById($couponId,[],function ($q){ + return $q->with(["scoreModel"]); + }); + + if($coupon->consumer_code != $account->user_code ){ + return $this->json(4001, "参数错误"); + } + + if(isset($score->scoreModel) && $score->scoreModel){ + return $this->json(4001, "已经评论过了"); + } + try { + $coupon->scoreModel()->save([ + "user_code"=>$account->user_code, + "business_code"=>$coupon->business_code, + "score"=>$score, + "coupon_id"=>$coupon->id, + "create_time"=>date("Y-m-d H:i:s"), + ]); + return $this->json(); + }catch (RepositoryException| \Exception $e){ + return $this->json(4001, "评分失败"); + } + + } } \ No newline at end of file diff --git a/app/controller/api/User.php b/app/controller/api/User.php index b429a7b..470cd9f 100644 --- a/app/controller/api/User.php +++ b/app/controller/api/User.php @@ -8,11 +8,13 @@ use app\repository\BusinessRepository; use app\repository\CouponRepository; use app\service\File; use app\service\Jwt; +use app\service\Tool; use app\service\wx\WechatApplets; use app\validate\User as UserValidate; use EasyWeChat\Kernel\Exceptions\InvalidConfigException; use Exception; use think\exception\ValidateException; +use think\facade\Config; use think\response\Json; /** @@ -24,7 +26,7 @@ use think\response\Json; class User extends Base { protected $noNeedLogin = [ - 'login', + 'login','checkNewAccount',"decodeMobile" ]; /** @@ -40,6 +42,8 @@ class User extends Base 'nick_name' => $this->request->param('nickName', ''), 'avatar_url' => $this->request->param('avatarUrl', ''), 'gender' => $this->request->param('gender', 0), + 'real_name' => $this->request->param('real_name/s', '',"trim"), + 'mobile' => $this->request->param('mobile/s', ''), ]; $validate = new UserValidate(); @@ -69,6 +73,12 @@ class User extends Base $nowDate = date('Y-m-d H:i:s'); if (!$account) { + if(empty($params['real_name'])){ + return $this->json(4001, '真实姓名不能为空'); + } + if(!is_mobile($params['mobile'])){ + return $this->json(4001, '手机号格式错误'); + } // 自动注册 $account = $repo->create([ 'user_code' => createUuid(), // 用户UUID @@ -79,6 +89,8 @@ class User extends Base 'nick_name' => $params['nick_name'] ?: generateDefaultNickName(), 'avatar_url' => $params['avatar_url'] ?: Account::DEFAULT_AVATAR, 'gender' => $params['gender'], + 'real_name' => $params['real_name'], + 'mobile' => $params['mobile'], ]); } else { @@ -226,4 +238,61 @@ class User extends Base } } + //检查是新用户还是老用户 + public function checkNewAccount() + { + Config::load('extra/wechat', 'wechat'); + $config = config('wechat'); + $code = $this->request->param('code/s'); + $appId = $config["applets_appId"]??'';//appid + $appSecret = $config["applets_appSecret"]??'';//appsecret + $url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + . $appId + . '&secret=' + . $appSecret + . '&js_code=' + . $code + . '&grant_type=authorization_code'; + $data = json_decode(Tool::httpRequest($url, "get"), true); + //返回状态 + if (isset($data["openid"])) { + $account = AccountRepository::getInstance()->findByOpenID($data["openid"]); + if(empty($account)){ + return $this->json(0, "fail",["isNewAccount"=>true,"session_key"=>$data["session_key"]]); + } + return $this->json(0, "fail",["isNewAccount"=>false,"session_key"=>$data["session_key"]]); + } + return $this->json(0, "fail",["isNewAccount"=>true]); + } + + /** + * 解密手机号 + * */ + public function decodeMobile() + { + $params = input('post.'); + $rules = [ + 'encryptedData|加密数据' => 'require', + 'iv|IV' => 'require', + 'session_key|会话标识' => 'require', + ]; + + $validate = $this->validateByApi($params, $rules); + + if ($validate !== true) { + return $validate; + } + + // 解密手机相关数据 + $minApp = WechatApplets::getInstance(); + $sessionKey = $params['session_key'] ?? ''; + $decryptData = $minApp->encryptor->decryptData($sessionKey, $params['iv'], $params['encryptedData']); + $phone = $decryptData['phoneNumber'] ?? ''; // 通过iv和加密数据 解密出手机号 + + if ($phone) { + return $this->json(0,"success",["mobile"=>$phone]); + } + return $this->json(5001,"获取手机号失败"); + } + } \ No newline at end of file diff --git a/app/controller/manager/Coupon.php b/app/controller/manager/Coupon.php index d4fbf75..aaa3da8 100644 --- a/app/controller/manager/Coupon.php +++ b/app/controller/manager/Coupon.php @@ -225,7 +225,11 @@ class Coupon extends Base $data['money'] = floor($data['money'] * 100) / 100; $totalMoney = $data['money'] * $data['count']; - if ($business["balance"] < $totalMoney) { + + //未领取的优惠券 + $NotClaimedMoney = CouponRepository::getInstance()->getBusinessNotClaimedCoupon($account->business["code"]); + + if ($business["balance"] < ($totalMoney + $NotClaimedMoney)) { return $this->json(4001, '商家余额不足'); } diff --git a/app/model/Coupon.php b/app/model/Coupon.php index d9dd88f..e94324b 100644 --- a/app/model/Coupon.php +++ b/app/model/Coupon.php @@ -41,4 +41,8 @@ class Coupon extends Base { return $this->hasOne(Score::class, 'coupon_id', 'id'); } + public function redpack() + { + return $this->hasOne(Redpack::class, 'coupon_id', 'id'); + } } \ No newline at end of file diff --git a/app/model/CouponMain.php b/app/model/CouponMain.php index a5a95a4..46709ad 100644 --- a/app/model/CouponMain.php +++ b/app/model/CouponMain.php @@ -32,11 +32,13 @@ class CouponMain extends Base { return $this->hasOne(UsingRule::class, 'coupon_id',"id"); } + //创建完成之后 public static function onAfterInsert( $obj) { - $obj->sort = $obj->id; - $obj->using_count = $obj->count; - $obj->received_count = 0; + $obj->sort = $obj->id; + $obj->using_count = $obj->count; + $obj->received_count = 0; + $obj->verification_count = 0; $obj->save(); } } \ No newline at end of file diff --git a/app/repository/CouponRepository.php b/app/repository/CouponRepository.php index 6014051..048db46 100644 --- a/app/repository/CouponRepository.php +++ b/app/repository/CouponRepository.php @@ -79,7 +79,7 @@ class CouponRepository extends Repository //创建优惠券使用规则 $usingRule["coupon_id"] = $couponMain->id; UsingRule::create($usingRule); - Business::where("code", $data["business_code"])->dec("balance", $totalMoney)->update(); + //Business::where("code", $data["business_code"])->dec("balance", $totalMoney)->update(); } /** diff --git a/app/repository/DictionaryRepository.php b/app/repository/DictionaryRepository.php index 0660ea0..7e9cb1a 100644 --- a/app/repository/DictionaryRepository.php +++ b/app/repository/DictionaryRepository.php @@ -174,6 +174,7 @@ class DictionaryRepository extends Repository } return "
该优惠券可以在" . encodeCouponCycle($usingRule->cycle) . "进行使用
该优惠券可以在每天的" . $usingRule->day_start_time ."到" .$usingRule->day_end_time ."进行使用
+
该优惠券每天一共可以领取". $usingRule->day_total ."张
该优惠券每天每人可以领取". $usingRule->person_day_total ."张
该优惠券每人总共可以领取". $usingRule->person_total ."张
"; } diff --git a/app/service/Tool.php b/app/service/Tool.php index 89e7a0a..87c2f5b 100644 --- a/app/service/Tool.php +++ b/app/service/Tool.php @@ -50,4 +50,60 @@ class Tool { return str_replace(' ', '', trim($str)); } + + /** + * CURL请求 + * @param $url 请求url地址 + * @param $method 请求方法 get post + * @param null $postfields post数据数组 + * @param array $headers 请求header信息 + * @param bool|false $debug 调试开启 默认false + * @return mixed + */ + static function httpRequest($url, $method = "post", $postfields = null, $headers = array(), $debug = false) + { + $method = strtoupper($method); + $ci = curl_init(); + /* Curl settings */ + curl_setopt($ci, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); + curl_setopt($ci, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0"); + curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 60); /* 在发起连接前等待的时间,如果设置为0,则无限等待 */ + curl_setopt($ci, CURLOPT_TIMEOUT, 7); /* 设置cURL允许执行的最长秒数 */ + curl_setopt($ci, CURLOPT_RETURNTRANSFER, true); + switch ($method) { + case "POST": + curl_setopt($ci, CURLOPT_POST, true); + if (!empty($postfields)) { + $tmpdatastr = is_array($postfields) ? http_build_query($postfields) : $postfields; + curl_setopt($ci, CURLOPT_POSTFIELDS, $tmpdatastr); + } + break; + default: + curl_setopt($ci, CURLOPT_CUSTOMREQUEST, $method); /* //设置请求方式 */ + break; + } + $ssl = preg_match('/^https:\/\//i', $url) ? TRUE : FALSE; + curl_setopt($ci, CURLOPT_URL, $url); + if ($ssl) { + curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts + curl_setopt($ci, CURLOPT_SSL_VERIFYHOST, FALSE); // 不从证书中检查SSL加密算法是否存在 + } + curl_setopt($ci, CURLOPT_FOLLOWLOCATION, 1); + curl_setopt($ci, CURLOPT_MAXREDIRS, 2);/*指定最多的HTTP重定向的数量,这个选项是和CURLOPT_FOLLOWLOCATION一起使用的*/ + curl_setopt($ci, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ci, CURLINFO_HEADER_OUT, true); + $response = curl_exec($ci); + $requestinfo = curl_getinfo($ci); + if ($debug) { + echo "=====post data======\r\n"; + var_dump($postfields); + echo "=====info===== \r\n"; + print_r($requestinfo); + echo "=====response=====\r\n"; + print_r($response); + } + curl_close($ci); + return $response; + } + } diff --git a/app/traits/CouponMainTrait.php b/app/traits/CouponMainTrait.php index 278797e..b1fd56b 100644 --- a/app/traits/CouponMainTrait.php +++ b/app/traits/CouponMainTrait.php @@ -49,4 +49,28 @@ trait CouponMainTrait ->where("is_verificated",Coupon::is_verificated_on) ->count(); } + + /** + * 获取商户没有被领取的优惠券 需要扣除多少钱 + * */ + public function getBusinessNotClaimedCoupon($businessCode) + { + $date = date("Y-m-d"); + $totalDeductionMoney = 0; + $couponMain = CouponMain::where("business_code", $businessCode) + ->where("status", CouponMain::status_on) + ->where("on_shelf", CouponMain::on_shelf_on) + ->whereTime("start_time", "<=", $date) + ->whereTime("end_time", ">=", $date) + ->whereRaw(" verification_count < count ") + ->field("id,(deduction_money * (count - verification_count)) as total_deduction_money") + ->select() + ->toArray(); + + foreach ($couponMain as $item) { + $totalDeductionMoney += $item["total_deduction_money"]; + } + return $totalDeductionMoney; + + } } \ No newline at end of file diff --git a/app/traits/CouponTrait.php b/app/traits/CouponTrait.php index b3536ae..a4d1db9 100644 --- a/app/traits/CouponTrait.php +++ b/app/traits/CouponTrait.php @@ -3,6 +3,7 @@ namespace app\traits; use app\exception\RepositoryException; +use app\model\Account; use app\model\CouponMain; use app\model\UsingRule; use think\Model; @@ -102,7 +103,7 @@ trait CouponTrait /** * 查看某个优惠券的是否可以领取 0 可以领取 1 已领取不能再领取 - * @param $accountCode + * @param Account $account * @param CouponMain $couponMain * @return void * @throws RepositoryException @@ -110,11 +111,11 @@ trait CouponTrait * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - public function getCouponReceiveStatusText($accountCode,CouponMain $couponMain ) + public function getCouponReceiveStatusText(Account $account,CouponMain $couponMain ) { //没有领取记录就可以领取 $ReceiveCount = Coupon::where("coupon_id",$couponMain->id) - ->where("consumer_code",$accountCode)->count(); + ->where("consumer_code",$account->user_code)->count(); //确定使用规则 @@ -135,7 +136,7 @@ trait CouponTrait //单人日限量 $todayReceivesCount = Coupon::where("coupon_id",$couponMain->id) - ->where("consumer_code",$accountCode) + ->where("consumer_code",$account->user_code) ->whereTime("received_time","between",[date("Y-m-d 00:00:00"),date("Y-m-d 23:59:59")]) ->count(); if($todayReceivesCount >= $usingRule->person_day_total ){ @@ -147,10 +148,20 @@ trait CouponTrait throw new RepositoryException("单人总限量达到上限"); } + //白名单 + if(!empty($couponMain->white_list)){ + if (empty($account->real_name) || empty($account->mobile)) { + throw new RepositoryException("请先授权手机号和真实姓名"); + } + if (false === strpos($couponMain->white_list, $account->mobile . "-" . $account->real_name)) { + throw new RepositoryException("您没有在该优惠券白名单内"); + } + } - + //领取不做限制 使用才做限制 + return; $time = time(); //一天的开始时间 if(strtotime(date("Y-m-d " . $usingRule->day_start_time)) > $time){ diff --git a/app/validate/CouponRelease.php b/app/validate/CouponRelease.php index 9d5f740..ca7ebf9 100644 --- a/app/validate/CouponRelease.php +++ b/app/validate/CouponRelease.php @@ -16,7 +16,7 @@ class CouponRelease extends Validate 'end_time|结束时间' => 'require|date|checkEndTime', 'name|优惠券名称' => 'require|length:3,32', 'money|金额' => 'require|>:0|<:5000', -// 'deduction_money|扣除金额' => 'require|>=:0|<:5000', + 'deduction_money|扣除金额' => 'require|>=:0.1|<:5000', //'image_url|预览图' => '', //'using_rule|使用规则' => '', //'punishing_rule|处罚规则' => '', diff --git a/favicon.ico b/favicon.ico deleted file mode 100644 index 20232b9..0000000 Binary files a/favicon.ico and /dev/null differ diff --git a/public/favicon.ico b/public/favicon.ico index 20232b9..9656063 100644 Binary files a/public/favicon.ico and b/public/favicon.ico differ diff --git a/view/manager/index/dashboard.html b/view/manager/index/dashboard.html index 5ed5d16..821fa4a 100644 --- a/view/manager/index/dashboard.html +++ b/view/manager/index/dashboard.html @@ -1,6 +1,6 @@ {layout name="manager/layout" /}
-
+
@@ -68,7 +68,7 @@
-
+

分销排行榜 查看全部 @@ -84,31 +84,31 @@
- + -
用户管理
+
消费者管理
-
+
渠道管理
-
+
预约管理
-
+
报告管理
-
+