添加:扫码兑换会员卡
This commit is contained in:
parent
d08680f3a9
commit
b93cfcfbea
|
|
@ -14,6 +14,7 @@ use app\common\repositories\system\groupData\GroupDataRepository;
|
|||
use crmeb\jobs\SendSmsJob;
|
||||
use crmeb\services\PayService;
|
||||
use FormBuilder\Factory\Elm;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
use think\facade\Queue;
|
||||
|
|
@ -58,23 +59,31 @@ class UserOrderRepository extends BaseRepository
|
|||
* @author xaboy
|
||||
* @day 2020/10/21
|
||||
*/
|
||||
public function add($res, $user, $params)
|
||||
{
|
||||
public function add($res, $user, $params){
|
||||
$order_sn = app()->make(StoreOrderRepository::class)->getNewOrderId(StoreOrderRepository::TYPE_SN_USER_ORDER);
|
||||
$data = [
|
||||
'title' => $res['value']['svip_name'],
|
||||
'link_id' => $res->group_data_id,
|
||||
'order_sn' => $order_sn,
|
||||
'pay_price' => $res['value']['price'],
|
||||
'order_info' => json_encode($res['value'],JSON_UNESCAPED_UNICODE),
|
||||
'uid' => $user->uid,
|
||||
'order_type' => self::TYPE_SVIP.$res['value']['svip_type'],
|
||||
'pay_type' => $res['value']['price'] == 0 ? 'free' : $params['pay_type'],
|
||||
'status' => 1,
|
||||
'other' => $user->is_svip == -1 ? 'first' : '',
|
||||
'bind_mer_id' => $params['bind_mer_id'] ?? '',
|
||||
'bind_staff_id' => $params['bind_staff_id'] ?? '',
|
||||
'title' => $res['value']['svip_name'],
|
||||
'link_id' => $res->group_data_id,
|
||||
'order_sn' => $order_sn,
|
||||
'pay_price' => $res['value']['price'],
|
||||
'order_info' => json_encode($res['value'],JSON_UNESCAPED_UNICODE),
|
||||
'uid' => $user->uid,
|
||||
'order_type' => self::TYPE_SVIP.$res['value']['svip_type'],
|
||||
'pay_type' => $res['value']['price'] == 0 ? 'free' : $params['pay_type'],
|
||||
'status' => 1,
|
||||
'other' => $user->is_svip == -1 ? 'first' : '',
|
||||
'bind_mer_id' => $params['bind_mer_id'] ?? '',
|
||||
'bind_staff_id' => $params['bind_staff_id'] ?? '',
|
||||
'exchange_code' => $params['exchange_code'] ?? '',
|
||||
'exchange_code_id' => $params['exchange_code_id'] ?? 0,
|
||||
];
|
||||
|
||||
// 判断:兑换不需要支付
|
||||
if($data['exchange_code_id'] > 0 && !empty($data['exchange_code'])){
|
||||
$data['pay_price'] = 0;
|
||||
$data['pay_type'] = 'free';
|
||||
}
|
||||
|
||||
$body = [
|
||||
'order_sn' => $order_sn,
|
||||
'pay_price' => $data['pay_price'],
|
||||
|
|
@ -86,6 +95,7 @@ class UserOrderRepository extends BaseRepository
|
|||
$type .= 'App';
|
||||
}
|
||||
if ($params['return_url'] && $type === 'alipay') $body['return_url'] = $params['return_url'];
|
||||
|
||||
$info = $this->dao->create($data);
|
||||
if ($data['pay_price']){
|
||||
try {
|
||||
|
|
@ -93,6 +103,10 @@ class UserOrderRepository extends BaseRepository
|
|||
$config = $service->pay($user);
|
||||
return app('json')->status($type, $config + ['order_id' => $info->order_id]);
|
||||
} catch (\Exception $e) {
|
||||
// 判断:兑换不需要支付
|
||||
if($data['exchange_code_id'] > 0 && !empty($data['exchange_code'])){
|
||||
throw new ValidateException($e->getMessage());
|
||||
}
|
||||
return app('json')->status('error', $e->getMessage(), ['order_id' => $info->order_id]);
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
namespace app\controller\api\user;
|
||||
|
||||
use app\common\model\user\UserOrder;
|
||||
use app\common\model\user\UserVipExchangeCode;
|
||||
use app\common\repositories\store\coupon\StoreCouponRepository;
|
||||
use app\common\repositories\store\order\StoreOrderRepository;
|
||||
use app\common\repositories\store\product\ProductRepository;
|
||||
|
|
@ -17,6 +18,7 @@ use app\common\repositories\user\MemberinterestsRepository;
|
|||
use app\common\repositories\user\UserBillRepository;
|
||||
use app\common\repositories\user\UserOrderRepository;
|
||||
use app\common\repositories\user\UserRepository;
|
||||
use app\common\repositories\user\VipExchangeCodeRepository;
|
||||
use crmeb\basic\BaseController;
|
||||
use app\common\repositories\user\FeedbackRepository;
|
||||
use think\App;
|
||||
|
|
@ -159,4 +161,55 @@ class Svip extends BaseController
|
|||
}
|
||||
return app('json')->success($data ?? ['count' => 0,'list' => []]);
|
||||
}
|
||||
/**
|
||||
* Common: 会员卡兑换
|
||||
* Author: wu-hui
|
||||
* Time: 2024/03/02 18:46
|
||||
* @param GroupDataRepository $groupDataRepository
|
||||
* @param UserOrderRepository $userOrderRepository
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function vipExchangeCode(GroupDataRepository $groupDataRepository, UserOrderRepository $userOrderRepository){
|
||||
// 参数获取
|
||||
$exchangeCode = $this->request->param('exchange_code', '');
|
||||
if(empty($exchangeCode)) throw new ValidateException('兑换码不存在!');
|
||||
$user = $this->request->userInfo();
|
||||
$uid = $this->request->uid();
|
||||
// 获取兑换码信息
|
||||
$exchangeCodeInfo = app()->make(VipExchangeCodeRepository::class)
|
||||
->getSearchModel(['exchange_code'=>$exchangeCode])
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
if(empty($exchangeCodeInfo)) throw new ValidateException('兑换码不存在!');
|
||||
if($exchangeCodeInfo['status'] == 0) throw new ValidateException('未激活!');
|
||||
if($exchangeCodeInfo['status'] == 2) throw new ValidateException('已使用!');
|
||||
// 下单并且使用
|
||||
$res = $groupDataRepository->getWhere(['group_data_id' => $exchangeCodeInfo['group_data_id'], 'status' => 1]);
|
||||
if (!$res) throw new ValidateException('会员卡不存在!');
|
||||
if ($user->is_svip == 3) throw new ValidateException('您已经是终身会员!');
|
||||
if ($user->is_svip !== -1 && $res['value']['svip_type'] == 1) throw new ValidateException('兑换失败,您已开通该类型会员!');
|
||||
// 模拟下单
|
||||
$params['pay_type'] = 'free';
|
||||
$params['return_url'] = '';
|
||||
$params['is_app'] = $this->request->isApp();
|
||||
$params['bind_mer_id'] = $exchangeCodeInfo['mer_id'] ?? 0;
|
||||
$params['bind_staff_id'] = $exchangeCodeInfo['staff_id'] ?? 0;
|
||||
$params['exchange_code'] = $exchangeCode;
|
||||
$params['exchange_code_id'] = $exchangeCodeInfo['id'];
|
||||
$userOrderRepository->add($res, $user, $params);
|
||||
// 开通成功 修改信息
|
||||
UserVipExchangeCode::where('id',$exchangeCodeInfo['id'])
|
||||
->update([
|
||||
'status' => 2,
|
||||
'use_time' => date("Y-m-d H:i:s",time()),
|
||||
'use_user_id' => $uid
|
||||
]);
|
||||
|
||||
return app('json')->success();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -329,6 +329,10 @@ Route::group('api/', function () {
|
|||
//付费会员购买
|
||||
Route::post('svip/pay/:id', 'api.user.Svip/createOrder');
|
||||
|
||||
// 付费会员兑换
|
||||
Route::post('sVip/vipExchangeCode', 'api.user.Svip/vipExchangeCode');
|
||||
|
||||
|
||||
//订单检查
|
||||
Route::group('order/v3', function () {
|
||||
Route::post('check', 'PointsOrder/beforCheck');
|
||||
|
|
@ -624,16 +628,6 @@ Route::group('api/', function () {
|
|||
})->prefix('api.Diy');
|
||||
|
||||
})->middleware(UserTokenMiddleware::class, false);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//微信支付回调
|
||||
Route::any('notice/wechat_pay', 'api.Common/wechatNotify')->name('wechatNotify');
|
||||
//微信支付回调
|
||||
|
|
|
|||
Loading…
Reference in New Issue