收银台相关验证码逻辑新增
This commit is contained in:
parent
98683fcc52
commit
8e82e40379
@ -12,7 +12,9 @@ use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\model\store_order\StoreOrder;
|
||||
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
||||
use app\common\model\store_product_unit\StoreProductUnit;
|
||||
use app\common\model\user\User;
|
||||
use app\common\service\pay\PayService;
|
||||
use app\common\service\SmsService;
|
||||
use Exception;
|
||||
use support\Cache;
|
||||
use think\facade\Db;
|
||||
@ -308,4 +310,26 @@ class StoreOrderLogic extends BaseLogic
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function dealSendSms($param)
|
||||
{
|
||||
$code = generateRandomCode();
|
||||
$phone = User::where('id',$param['uid'])->value('mobile');
|
||||
if(empty($phone)){
|
||||
throw new \Exception('用户未设置手机号');
|
||||
}
|
||||
$template = getenv('SMS_TEMPLATE');
|
||||
|
||||
$check =(new SmsService())->client($phone,$template,$code);
|
||||
if($check){
|
||||
$remark = $param['uid'].'_smsPay';
|
||||
Cache::set($remark,$code,5*60);
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -50,13 +50,18 @@ class SmsService
|
||||
try{
|
||||
$easySms = new EasySms($this->config);
|
||||
|
||||
$easySms->send($phone, [
|
||||
$res = $easySms->send($phone, [
|
||||
'content' => '您的验证码为: '.$code,
|
||||
'template' => $template,
|
||||
'data' => [
|
||||
'code' => $code
|
||||
],
|
||||
]);
|
||||
if($res && $res['aliyun']['status'] == 'success'){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}catch(NoGatewayAvailableException $e){
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
|
@ -405,6 +405,20 @@ if (!function_exists('haversineDistance')) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机验证码
|
||||
*/
|
||||
if (!function_exists('generateRandomCode')) {
|
||||
function generateRandomCode($length = 4) {
|
||||
$code = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$code .= random_int(0, 9);
|
||||
}
|
||||
return $code;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('reset_index')) {
|
||||
/**
|
||||
* 重置数组索引
|
||||
|
@ -24,7 +24,7 @@ class CartController extends BaseAdminController
|
||||
{
|
||||
$params = (new CartValidate())->post()->goCheck('StoreAdd');
|
||||
$adminInfo = $this->adminInfo;
|
||||
$params['uid'] = 0;
|
||||
$params['uid'] = $this->request->post('uid')??0;
|
||||
$params['staff_id'] = $adminInfo['admin_id'];
|
||||
$params['store_id'] = $adminInfo['store_id'];
|
||||
$result = Cart::where(['uid' => 0,'staff_id'=>$adminInfo['admin_id'], 'store_id' => $adminInfo['store_id'], 'product_id' => $params['product_id'], 'is_fail' => 0, 'is_pay' => 0])->find();
|
||||
|
@ -4,6 +4,7 @@ namespace app\store\controller\store_order;
|
||||
|
||||
use app\api\logic\order\OrderLogic;
|
||||
use app\api\validate\OrderValidate;
|
||||
use app\common\model\order\Cart;
|
||||
use app\store\lists\store_order\StoreOrderLists;
|
||||
use app\common\controller\Definitions;
|
||||
use app\common\enum\PayEnum;
|
||||
@ -15,6 +16,7 @@ use app\common\logic\store_order\StoreOrderLogic;
|
||||
use app\common\model\store_order\StoreOrder;
|
||||
use app\common\model\user_recharge\UserRecharge;
|
||||
use app\store\validate\store_order\StoreOrderValidate;
|
||||
use support\Cache;
|
||||
use support\Log;
|
||||
use Webman\RedisQueue\Redis;
|
||||
|
||||
@ -124,11 +126,26 @@ class StoreOrderController extends BaseAdminController
|
||||
return $this->data($res);
|
||||
}
|
||||
|
||||
|
||||
public function checkSms()
|
||||
{
|
||||
$params = (new StoreOrderValidate())->post()->goCheck('check');
|
||||
$res = (new StoreOrderLogic())->dealSendSms($params);
|
||||
if($res){
|
||||
return $this->success('发送成功',[],1,1);
|
||||
}else{
|
||||
return $this->fail('发送失败');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function createOrder()
|
||||
{
|
||||
$cartId = (array)$this->request->post('cart_id', []);
|
||||
$pay_type = (int)$this->request->post('pay_type');
|
||||
$addressId = (int)$this->request->post('address_id');
|
||||
$sms_code = $this->request->post('sms_code','');
|
||||
$auth_code = $this->request->post('auth_code'); //微信支付条码
|
||||
$params = $this->request->post();
|
||||
if ($auth_code == '' && $pay_type != PayEnum::CASH_PAY) {
|
||||
@ -137,6 +154,23 @@ class StoreOrderController extends BaseAdminController
|
||||
if (count($cartId) > 100) {
|
||||
return $this->fail('购物车商品不能超过100个');
|
||||
}
|
||||
|
||||
if($pay_type == PayEnum::PURCHASE_FUNDS && $sms_code){
|
||||
if(empty($cartId)){
|
||||
return $this->fail('缺失购物车数据');
|
||||
}
|
||||
$uid = Cart::where('id',$cartId[0])->value('uid');
|
||||
$remark = $uid.'_smsPay';
|
||||
$code = Cache::get($remark);
|
||||
if(empty($code)){
|
||||
return $this->fail('验证码过期请重新发送');
|
||||
}
|
||||
if ($code !== $sms_code) {
|
||||
return $this->fail('验证码错误');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$params['store_id'] = $this->request->adminInfo['store_id']; //当前登录的店铺id,用于判断是否是当前店铺的订单
|
||||
$order = StoreOrderLogic::createOrder($cartId, $addressId, null, $params);
|
||||
if ($order != false) {
|
||||
|
@ -81,4 +81,9 @@ class StoreOrderValidate extends BaseValidate
|
||||
return $this->only(['id','verify_code']);
|
||||
}
|
||||
|
||||
public function sceneCheck()
|
||||
{
|
||||
return $this->only(['uid']);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user