终版初始化
parent
a776f4c445
commit
6a99ae542b
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ use app\model\CouponMain;
|
||||||
use app\model\Deduction;
|
use app\model\Deduction;
|
||||||
use app\model\Redpack;
|
use app\model\Redpack;
|
||||||
use app\model\Score;
|
use app\model\Score;
|
||||||
|
use app\model\UsingRule;
|
||||||
use app\repository\AccountRepository;
|
use app\repository\AccountRepository;
|
||||||
use app\repository\BusinessRepository;
|
use app\repository\BusinessRepository;
|
||||||
use app\repository\CouponRepository;
|
use app\repository\CouponRepository;
|
||||||
|
@ -194,7 +195,7 @@ class Coupon extends Base
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//检查是否可以领取 0可领取 1已领取
|
//检查是否可以领取 0可领取 1已领取
|
||||||
AccountRepository::getInstance()->getCouponReceiveStatusText($account->user_code,$couponMain);//领取状态
|
AccountRepository::getInstance()->getCouponReceiveStatusText($account,$couponMain);//领取状态
|
||||||
}catch (RepositoryException $e){
|
}catch (RepositoryException $e){
|
||||||
return $this->json(4001,$e->getMessage());
|
return $this->json(4001,$e->getMessage());
|
||||||
}
|
}
|
||||||
|
@ -224,6 +225,7 @@ class Coupon extends Base
|
||||||
"is_verificated" => couponMain::COMMON_OFF,//版本 未知作用
|
"is_verificated" => couponMain::COMMON_OFF,//版本 未知作用
|
||||||
];
|
];
|
||||||
CouponRepository::getInstance()->receiveCoupon($data);
|
CouponRepository::getInstance()->receiveCoupon($data);
|
||||||
|
$couponMain->save(["received_count"=>Db::raw("received_count + 1")]);
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return $this->json();
|
return $this->json();
|
||||||
}catch (RepositoryException $e){
|
}catch (RepositoryException $e){
|
||||||
|
@ -260,7 +262,7 @@ class Coupon extends Base
|
||||||
}
|
}
|
||||||
|
|
||||||
$coupon = CouponRepository::getInstance()->findById($couponId,[],function ($q){
|
$coupon = CouponRepository::getInstance()->findById($couponId,[],function ($q){
|
||||||
return $q->with(["couponMain"]);
|
return $q->with(["couponMain","redpack"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
if($coupon->consumer_code != $account->user_code ){
|
if($coupon->consumer_code != $account->user_code ){
|
||||||
|
@ -276,14 +278,27 @@ class Coupon extends Base
|
||||||
if($coupon->on_shelf != CouponMain::on_shelf_on){
|
if($coupon->on_shelf != CouponMain::on_shelf_on){
|
||||||
return $this->json(4001, "优惠券下架");
|
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, "优惠券已过期");
|
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();
|
$business = BusinessRepository::getInstance()->getModel()->with(["agency"])->where(["code"=>$coupon->couponMain->business_code])->lock(true)->find();
|
||||||
if(empty($business)){
|
if(empty($business)){
|
||||||
return $this->json(4001, "商家不存在");
|
return $this->json(4001, "商家不存在");
|
||||||
|
@ -298,90 +313,111 @@ class Coupon extends Base
|
||||||
try {
|
try {
|
||||||
// 1. 修改优惠券状态
|
// 1. 修改优惠券状态
|
||||||
$coupon->save([
|
$coupon->save([
|
||||||
"is_verificated"=>CouponModel::is_verificated_on,
|
"is_verificated" => CouponModel::is_verificated_on,
|
||||||
"used_time"=>date("Y-m-d H:i:s" ,$time),
|
"used_time" => date("Y-m-d H:i:s" ,$time),
|
||||||
"verificate_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;
|
$deductionMoney = $coupon->couponMain->deduction_money;
|
||||||
$agencyMoney = ($deductionMoney/100) * $coupon->couponMain->commission_agency;
|
$agencyMoney = (($deductionMoney/100) * $coupon->couponMain->commission_agency);
|
||||||
$adminMoney = ($deductionMoney/100) * $coupon->couponMain->commission_admin;
|
$adminMoney = (($deductionMoney/100) * $coupon->couponMain->commission_admin);
|
||||||
$consumerMoney = ($deductionMoney/100) * $coupon->couponMain->commission_consumer;
|
$consumerMoney = (($deductionMoney/100) * $coupon->couponMain->commission_consumer);
|
||||||
|
$agencyMoney = round($agencyMoney,2); //四舍五入 精确到分
|
||||||
|
$adminMoney = round($adminMoney,2); //四舍五入 精确到分
|
||||||
|
$consumerMoney = round($consumerMoney,2); //四舍五入 精确到分
|
||||||
// 2. 写入优惠券流水
|
// 2. 写入优惠券流水
|
||||||
$couponBillData = [
|
$couponBillData = [
|
||||||
"coupon_main_id"=>$coupon->couponMain->id,
|
"coupon_main_id" =>$coupon->couponMain->id,
|
||||||
"coupon_id"=>$coupon->id,
|
"coupon_id" =>$coupon->id,
|
||||||
"user_code"=>$account->user_code,
|
"user_code" =>$account->user_code,
|
||||||
"agency_code"=>$business->agency_code,
|
"agency_code" =>$business->agency_code,
|
||||||
"commission_agency"=>$coupon->couponMain->commission_agency,
|
"commission_agency" =>$coupon->couponMain->commission_agency,
|
||||||
"commission_admin"=>$coupon->couponMain->commission_admin,
|
"commission_admin" =>$coupon->couponMain->commission_admin,
|
||||||
"commission_consumer"=>$coupon->couponMain->commission_consumer,
|
"commission_consumer" =>$coupon->couponMain->commission_consumer,
|
||||||
"money"=>$coupon->couponMain->money,
|
"money" =>$coupon->couponMain->money,
|
||||||
"agency_money"=>$agencyMoney,
|
"agency_money" =>$agencyMoney,
|
||||||
"admin_money"=>$adminMoney,
|
"admin_money" =>$adminMoney,
|
||||||
"consumer_money"=>$consumerMoney,
|
"consumer_money" =>$consumerMoney,
|
||||||
"lat"=>$lat,
|
"lat" =>$lat,
|
||||||
"lng"=>$lng,
|
"lng" =>$lng,
|
||||||
];
|
];
|
||||||
$couponBill = CouponBill::create($couponBillData);
|
$couponBill = CouponBill::create($couponBillData);
|
||||||
|
|
||||||
// 3. 写入商家扣费记录
|
// 3. 写入商家扣费记录
|
||||||
$deductionData = [
|
$deductionData = [
|
||||||
"money"=>$deductionMoney,
|
"money" => $deductionMoney,
|
||||||
"business_code"=>$business->code,
|
"business_code" => $business->code,
|
||||||
"business_name"=>$business->business_name,
|
"business_name" => $business->business_name,
|
||||||
"balance"=>$business->balance - $deductionMoney,
|
"balance" => $business->balance - $deductionMoney,
|
||||||
"reason"=> sprintf("[%s]验证优惠券[%s]扣除[%s]",$account->nick_name, $coupon->couponMain->name,$deductionMoney),
|
"reason" => sprintf("[%s]验证优惠券[%s]扣除[%s]",$account->nick_name, $coupon->couponMain->name,$deductionMoney),
|
||||||
"coupon_main_id"=> $coupon->couponMain->id,
|
"coupon_main_id" => $coupon->couponMain->id,
|
||||||
"coupon_id"=> $coupon->id,
|
"coupon_id" => $coupon->id,
|
||||||
"bill_id"=> $couponBill->id,
|
"bill_id" => $couponBill->id,
|
||||||
"create_time"=> date("Y-m-d H:i:s",$time),
|
"create_time" => date("Y-m-d H:i:s",$time),
|
||||||
];
|
];
|
||||||
Deduction::create($deductionData);
|
Deduction::create($deductionData);
|
||||||
|
|
||||||
//4. 商家扣钱
|
//4. 商家扣钱
|
||||||
$business->save(["balance"=>$business->balance - $deductionMoney]);
|
$business->save(["balance"=>Db::raw("balance - {$deductionMoney}")]);
|
||||||
|
|
||||||
//5. 渠道商加钱
|
//5. 渠道商加钱
|
||||||
if(isset($business->agency)&&$business->agency){
|
if(isset($business->agency) && $business->agency){
|
||||||
$business->agency->inc("balance",$agencyMoney)->update();
|
$business->agency->inc("balance",$agencyMoney)->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
//6. 用户提现到零钱
|
//6. 用户提现到零钱 写入红包记录
|
||||||
$RedpackData =[
|
if($consumerMoney > 0){
|
||||||
"mch_billno"=>createUuid(),
|
$payment = WechatPay::getInstance();
|
||||||
"openid"=>$account->open_id,
|
|
||||||
"user_code"=>$account->user_code,
|
|
||||||
"money"=>$consumerMoney*100,
|
|
||||||
];
|
|
||||||
$redpackModelData = Redpack::create($RedpackData);
|
|
||||||
$payment = WechatPay::getInstance();
|
|
||||||
|
|
||||||
$redpack = $payment->redpack;
|
//如果付款过一次了 就查询付款状态
|
||||||
$res = $redpackData = [
|
if(isset($coupon->redpack)&&$coupon->redpack){
|
||||||
'mch_billno' => $time.randomStr(0,10),
|
$result = $payment->transfer->queryBalanceOrder($coupon->redpack->mch_billno);
|
||||||
'send_name' => '红包',
|
//var_dump($result);
|
||||||
're_openid' => $redpackModelData->openid,
|
//企业付款成功
|
||||||
'total_num' => 1, //固定为1,可不传
|
if(isset($result["status"])&&$result["status"]=="SUCCESS"){
|
||||||
'total_amount' => $redpackModelData->money, //单位为分,不小于100
|
Db::commit();
|
||||||
'wishing' => '恭喜发财',
|
return $this->json();
|
||||||
'client_ip' => $this->request->ip(), //可不传,不传则由 SDK 取当前客户端 IP
|
}
|
||||||
'act_name' => '验证优惠券得红包',
|
Log::info("查询企业付款失败:".json_encode($result,JSON_UNESCAPED_UNICODE));
|
||||||
'remark' => '验证优惠券得红包',//测试备注
|
}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){
|
}catch (RepositoryException $e){
|
||||||
Db::rollback();
|
Db::rollback();
|
||||||
return $this->json(5001, "服务器错误");
|
return $this->json(5001, "Repository服务器错误");
|
||||||
}catch (\Exception $e){
|
}catch (\Exception $e){
|
||||||
echo $e->getMessage();
|
//echo $e->getMessage();
|
||||||
Db::rollback();
|
Db::rollback();
|
||||||
return $this->json(5002, "服务器错误");
|
return $this->json(5002, "服务器错误");
|
||||||
}
|
}
|
||||||
|
@ -462,7 +498,10 @@ class Coupon extends Base
|
||||||
$couponMain['money'] = floor($couponMain['money'] * 100) / 100;
|
$couponMain['money'] = floor($couponMain['money'] * 100) / 100;
|
||||||
$totalMoney = $couponMain['money'] * $couponMain['count'];
|
$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, '商家余额不足');
|
return $this->json(4001, '商家余额不足');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -706,4 +745,50 @@ class Coupon extends Base
|
||||||
|
|
||||||
return $this->json(0,"success",$couponMain->toArray());
|
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, "评分失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -8,11 +8,13 @@ use app\repository\BusinessRepository;
|
||||||
use app\repository\CouponRepository;
|
use app\repository\CouponRepository;
|
||||||
use app\service\File;
|
use app\service\File;
|
||||||
use app\service\Jwt;
|
use app\service\Jwt;
|
||||||
|
use app\service\Tool;
|
||||||
use app\service\wx\WechatApplets;
|
use app\service\wx\WechatApplets;
|
||||||
use app\validate\User as UserValidate;
|
use app\validate\User as UserValidate;
|
||||||
use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
|
use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
|
||||||
use Exception;
|
use Exception;
|
||||||
use think\exception\ValidateException;
|
use think\exception\ValidateException;
|
||||||
|
use think\facade\Config;
|
||||||
use think\response\Json;
|
use think\response\Json;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,7 +26,7 @@ use think\response\Json;
|
||||||
class User extends Base
|
class User extends Base
|
||||||
{
|
{
|
||||||
protected $noNeedLogin = [
|
protected $noNeedLogin = [
|
||||||
'login',
|
'login','checkNewAccount',"decodeMobile"
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,6 +42,8 @@ class User extends Base
|
||||||
'nick_name' => $this->request->param('nickName', ''),
|
'nick_name' => $this->request->param('nickName', ''),
|
||||||
'avatar_url' => $this->request->param('avatarUrl', ''),
|
'avatar_url' => $this->request->param('avatarUrl', ''),
|
||||||
'gender' => $this->request->param('gender', 0),
|
'gender' => $this->request->param('gender', 0),
|
||||||
|
'real_name' => $this->request->param('real_name/s', '',"trim"),
|
||||||
|
'mobile' => $this->request->param('mobile/s', ''),
|
||||||
];
|
];
|
||||||
|
|
||||||
$validate = new UserValidate();
|
$validate = new UserValidate();
|
||||||
|
@ -69,6 +73,12 @@ class User extends Base
|
||||||
$nowDate = date('Y-m-d H:i:s');
|
$nowDate = date('Y-m-d H:i:s');
|
||||||
|
|
||||||
if (!$account) {
|
if (!$account) {
|
||||||
|
if(empty($params['real_name'])){
|
||||||
|
return $this->json(4001, '真实姓名不能为空');
|
||||||
|
}
|
||||||
|
if(!is_mobile($params['mobile'])){
|
||||||
|
return $this->json(4001, '手机号格式错误');
|
||||||
|
}
|
||||||
// 自动注册
|
// 自动注册
|
||||||
$account = $repo->create([
|
$account = $repo->create([
|
||||||
'user_code' => createUuid(), // 用户UUID
|
'user_code' => createUuid(), // 用户UUID
|
||||||
|
@ -79,6 +89,8 @@ class User extends Base
|
||||||
'nick_name' => $params['nick_name'] ?: generateDefaultNickName(),
|
'nick_name' => $params['nick_name'] ?: generateDefaultNickName(),
|
||||||
'avatar_url' => $params['avatar_url'] ?: Account::DEFAULT_AVATAR,
|
'avatar_url' => $params['avatar_url'] ?: Account::DEFAULT_AVATAR,
|
||||||
'gender' => $params['gender'],
|
'gender' => $params['gender'],
|
||||||
|
'real_name' => $params['real_name'],
|
||||||
|
'mobile' => $params['mobile'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
} else {
|
} 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,"获取手机号失败");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -225,7 +225,11 @@ class Coupon extends Base
|
||||||
$data['money'] = floor($data['money'] * 100) / 100;
|
$data['money'] = floor($data['money'] * 100) / 100;
|
||||||
|
|
||||||
$totalMoney = $data['money'] * $data['count'];
|
$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, '商家余额不足');
|
return $this->json(4001, '商家余额不足');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,4 +41,8 @@ class Coupon extends Base
|
||||||
{
|
{
|
||||||
return $this->hasOne(Score::class, 'coupon_id', 'id');
|
return $this->hasOne(Score::class, 'coupon_id', 'id');
|
||||||
}
|
}
|
||||||
|
public function redpack()
|
||||||
|
{
|
||||||
|
return $this->hasOne(Redpack::class, 'coupon_id', 'id');
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -32,11 +32,13 @@ class CouponMain extends Base
|
||||||
{
|
{
|
||||||
return $this->hasOne(UsingRule::class, 'coupon_id',"id");
|
return $this->hasOne(UsingRule::class, 'coupon_id',"id");
|
||||||
}
|
}
|
||||||
|
//创建完成之后
|
||||||
public static function onAfterInsert( $obj)
|
public static function onAfterInsert( $obj)
|
||||||
{
|
{
|
||||||
$obj->sort = $obj->id;
|
$obj->sort = $obj->id;
|
||||||
$obj->using_count = $obj->count;
|
$obj->using_count = $obj->count;
|
||||||
$obj->received_count = 0;
|
$obj->received_count = 0;
|
||||||
|
$obj->verification_count = 0;
|
||||||
$obj->save();
|
$obj->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -79,7 +79,7 @@ class CouponRepository extends Repository
|
||||||
//创建优惠券使用规则
|
//创建优惠券使用规则
|
||||||
$usingRule["coupon_id"] = $couponMain->id;
|
$usingRule["coupon_id"] = $couponMain->id;
|
||||||
UsingRule::create($usingRule);
|
UsingRule::create($usingRule);
|
||||||
Business::where("code", $data["business_code"])->dec("balance", $totalMoney)->update();
|
//Business::where("code", $data["business_code"])->dec("balance", $totalMoney)->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -174,6 +174,7 @@ class DictionaryRepository extends Repository
|
||||||
}
|
}
|
||||||
return "<div class='disPaperList'><div class='circleOrange'>●</div>该优惠券可以在" . encodeCouponCycle($usingRule->cycle) . "进行使用</div>
|
return "<div class='disPaperList'><div class='circleOrange'>●</div>该优惠券可以在" . encodeCouponCycle($usingRule->cycle) . "进行使用</div>
|
||||||
<div class='disPaperList'><div class='circleOrange'>●</div>该优惠券可以在每天的" . $usingRule->day_start_time ."到" .$usingRule->day_end_time ."进行使用</div>
|
<div class='disPaperList'><div class='circleOrange'>●</div>该优惠券可以在每天的" . $usingRule->day_start_time ."到" .$usingRule->day_end_time ."进行使用</div>
|
||||||
|
<div class='disPaperList'><div class='circleOrange'>●</div>该优惠券每天一共可以领取". $usingRule->day_total ."张</div>
|
||||||
<div class='disPaperList'><div class='circleOrange'>●</div>该优惠券每天每人可以领取". $usingRule->person_day_total ."张</div>
|
<div class='disPaperList'><div class='circleOrange'>●</div>该优惠券每天每人可以领取". $usingRule->person_day_total ."张</div>
|
||||||
<div class='disPaperList'><div class='circleOrange'>●</div>该优惠券每人总共可以领取". $usingRule->person_total ."张</div>";
|
<div class='disPaperList'><div class='circleOrange'>●</div>该优惠券每人总共可以领取". $usingRule->person_total ."张</div>";
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,4 +50,60 @@ class Tool
|
||||||
{
|
{
|
||||||
return str_replace(' ', '', trim($str));
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,4 +49,28 @@ trait CouponMainTrait
|
||||||
->where("is_verificated",Coupon::is_verificated_on)
|
->where("is_verificated",Coupon::is_verificated_on)
|
||||||
->count();
|
->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;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,7 @@
|
||||||
namespace app\traits;
|
namespace app\traits;
|
||||||
|
|
||||||
use app\exception\RepositoryException;
|
use app\exception\RepositoryException;
|
||||||
|
use app\model\Account;
|
||||||
use app\model\CouponMain;
|
use app\model\CouponMain;
|
||||||
use app\model\UsingRule;
|
use app\model\UsingRule;
|
||||||
use think\Model;
|
use think\Model;
|
||||||
|
@ -102,7 +103,7 @@ trait CouponTrait
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查看某个优惠券的是否可以领取 0 可以领取 1 已领取不能再领取
|
* 查看某个优惠券的是否可以领取 0 可以领取 1 已领取不能再领取
|
||||||
* @param $accountCode
|
* @param Account $account
|
||||||
* @param CouponMain $couponMain
|
* @param CouponMain $couponMain
|
||||||
* @return void
|
* @return void
|
||||||
* @throws RepositoryException
|
* @throws RepositoryException
|
||||||
|
@ -110,11 +111,11 @@ trait CouponTrait
|
||||||
* @throws \think\db\exception\DbException
|
* @throws \think\db\exception\DbException
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
* @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)
|
$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)
|
$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")])
|
->whereTime("received_time","between",[date("Y-m-d 00:00:00"),date("Y-m-d 23:59:59")])
|
||||||
->count();
|
->count();
|
||||||
if($todayReceivesCount >= $usingRule->person_day_total ){
|
if($todayReceivesCount >= $usingRule->person_day_total ){
|
||||||
|
@ -147,10 +148,20 @@ trait CouponTrait
|
||||||
throw new RepositoryException("单人总限量达到上限");
|
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();
|
$time = time();
|
||||||
//一天的开始时间
|
//一天的开始时间
|
||||||
if(strtotime(date("Y-m-d " . $usingRule->day_start_time)) > $time){
|
if(strtotime(date("Y-m-d " . $usingRule->day_start_time)) > $time){
|
||||||
|
|
|
@ -16,7 +16,7 @@ class CouponRelease extends Validate
|
||||||
'end_time|结束时间' => 'require|date|checkEndTime',
|
'end_time|结束时间' => 'require|date|checkEndTime',
|
||||||
'name|优惠券名称' => 'require|length:3,32',
|
'name|优惠券名称' => 'require|length:3,32',
|
||||||
'money|金额' => 'require|>:0|<:5000',
|
'money|金额' => 'require|>:0|<:5000',
|
||||||
// 'deduction_money|扣除金额' => 'require|>=:0|<:5000',
|
'deduction_money|扣除金额' => 'require|>=:0.1|<:5000',
|
||||||
//'image_url|预览图' => '',
|
//'image_url|预览图' => '',
|
||||||
//'using_rule|使用规则' => '',
|
//'using_rule|使用规则' => '',
|
||||||
//'punishing_rule|处罚规则' => '',
|
//'punishing_rule|处罚规则' => '',
|
||||||
|
|
BIN
favicon.ico
BIN
favicon.ico
Binary file not shown.
Before Width: | Height: | Size: 66 KiB |
Binary file not shown.
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 4.2 KiB |
|
@ -1,6 +1,6 @@
|
||||||
{layout name="manager/layout" /}
|
{layout name="manager/layout" /}
|
||||||
<div class="layui-bg-gray" style="padding: 30px;">
|
<div class="layui-bg-gray" style="padding: 30px;">
|
||||||
<div class="layui-row layui-col-space15">
|
<div class="layui-row layui-col-space15 layui-hide">
|
||||||
<div class="layui-col-md3">
|
<div class="layui-col-md3">
|
||||||
<div class="layui-panel" style="border-radius: 8px;">
|
<div class="layui-panel" style="border-radius: 8px;">
|
||||||
<div class="layui-row layui-col-space20">
|
<div class="layui-row layui-col-space20">
|
||||||
|
@ -68,7 +68,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div class="layui-hide">
|
||||||
<br>
|
<br>
|
||||||
<blockquote class="layui-elem-quote" style="padding: 5px;">分销排行榜
|
<blockquote class="layui-elem-quote" style="padding: 5px;">分销排行榜
|
||||||
<a class="pull-right" href="javascript:;" layuimini-content-href="/manager/appointment" data-title="客户分析">查看全部</a>
|
<a class="pull-right" href="javascript:;" layuimini-content-href="/manager/appointment" data-title="客户分析">查看全部</a>
|
||||||
|
@ -84,31 +84,31 @@
|
||||||
<div class="layui-col-md7">
|
<div class="layui-col-md7">
|
||||||
<div class="layui-row">
|
<div class="layui-row">
|
||||||
<div class="layui-col-md2" style="text-align: center; padding: 40px 20px">
|
<div class="layui-col-md2" style="text-align: center; padding: 40px 20px">
|
||||||
<a href="javascript:;" layuimini-content-href="manager/account" data-title="用户管理">
|
<a href="javascript:;" layuimini-content-href="/manager/consumer/index" data-title="用户管理">
|
||||||
<i class="fa fa-user-circle-o" style="font-size: 500%;"></i>
|
<i class="fa fa-user-circle-o" style="font-size: 500%;"></i>
|
||||||
</a>
|
</a>
|
||||||
<div><span>用户管理</span></div>
|
<div><span>消费者管理</span></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="layui-col-md2" style="text-align: center; padding: 40px 20px">
|
<div class="layui-col-md2 layui-hide" style="text-align: center; padding: 40px 20px">
|
||||||
<a href="javascript:;" layuimini-content-href="manager/channel" data-title="渠道管理">
|
<a href="javascript:;" layuimini-content-href="manager/channel" data-title="渠道管理">
|
||||||
<i class="fa fa-road" style="font-size: 500%;"></i>
|
<i class="fa fa-road" style="font-size: 500%;"></i>
|
||||||
</a>
|
</a>
|
||||||
<div><span>渠道管理</span></div>
|
<div><span>渠道管理</span></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-col-md2" style="text-align: center; padding: 40px 20px">
|
<div class="layui-col-md2 layui-hide" style="text-align: center; padding: 40px 20px">
|
||||||
<a href="javascript:;" layuimini-content-href="manager/appointment" data-title="预约列表">
|
<a href="javascript:;" layuimini-content-href="manager/appointment" data-title="预约列表">
|
||||||
<i class="fa fa-american-sign-language-interpreting" style="font-size: 500%;"></i>
|
<i class="fa fa-american-sign-language-interpreting" style="font-size: 500%;"></i>
|
||||||
</a>
|
</a>
|
||||||
<div><span>预约管理</span></div>
|
<div><span>预约管理</span></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-col-md2" style="text-align: center; padding: 40px 20px">
|
<div class="layui-col-md2 layui-hide" style="text-align: center; padding: 40px 20px">
|
||||||
<a href="javascript:;" data-title="报告管理">
|
<a href="javascript:;" data-title="报告管理">
|
||||||
<i class="fa fa-newspaper-o" style="font-size: 500%;"></i>
|
<i class="fa fa-newspaper-o" style="font-size: 500%;"></i>
|
||||||
</a>
|
</a>
|
||||||
<div><span>报告管理</span></div>
|
<div><span>报告管理</span></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-col-md2" style="text-align: center; padding: 40px 20px">
|
<div class="layui-col-md2 layui-hide" style="text-align: center; padding: 40px 20px">
|
||||||
<a href="javascript:;" layuimini-content-href="manager/overview/customer" data-title="分销排行榜">
|
<a href="javascript:;" layuimini-content-href="manager/overview/customer" data-title="分销排行榜">
|
||||||
<i class="fa fa-bar-chart-o" style="font-size: 500%;"></i>
|
<i class="fa fa-bar-chart-o" style="font-size: 500%;"></i>
|
||||||
</a>
|
</a>
|
||||||
|
|
Loading…
Reference in New Issue