123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- <?php
- namespace app\admin\controller\sms;
- use app\model\Member;
- use app\model\MemberBenefit;
- use app\model\MemberQuota;
- use support\Redis;
- use support\Request;
- use Hhink\WebmanSms\Sms;
- class SmsController
- {
- const KEY_PREFIX = 'SMS:CODE:';
- /**
- * @Desc 核销验证码
- * @Author Gorden
- * @Date 2024/6/4 8:46
- *
- * @param Request $request
- * @return \support\Response
- */
- public function sendSmsCodeByQuota(Request $request)
- {
- $memberId = $request->post('member_id', []);
- $componentId = $request->post('component_id', []);
- $nbr = $request->post('nbr');
- if (!$memberId || !$componentId) {
- return json_fail("参数异常");
- }
- $quotas = MemberQuota::where('join_quota_member_id', $memberId[0])
- ->where('join_member_rule_added_component_id', $componentId[0])
- ->where('member_quota_status', 'PENDING')
- ->limit($nbr)
- ->get()
- ->toArray();
- if (count($quotas) < intval($nbr)) {
- return json_fail("可核销数量不足");
- }
- try {
- $member = Member::find(current($memberId));
- $mobile = $member->member_mobile;
- $code = random_string(6, 'number');
- $key = self::KEY_PREFIX . 'QUOTA:' . $mobile;
- Redis::set($key, $code);
- Redis::expire($key, 600);
- Sms::app()->send($mobile, [
- 'template' => 'SMS_469030007',
- 'data' => [
- 'code' => $code
- ],
- ]);
- } catch (\Exception $e) {
- dump($e->getMessage());
- return json_fail("短信发送失败,请稍后重试");
- }
- return json_success('success');
- }
-
- public function sendSmsCodeByBenefit(Request $request)
- {
- $memberId = $request->post('member_id', '');
- $benefitId = $request->post('benefit_id', '');
- $nbr = $request->post('nbr');
- if (!$memberId || !$benefitId) {
- return json_fail("参数异常");
- }
- $benefit = MemberBenefit::where('member_benefit_id', $benefitId)
- ->where('join_benefit_member_id', $memberId)
- ->first();
- if (!$benefit) {
- return json_fail("权益不存在");
- }
- if (($benefit->member_benefit_limit_count - $benefit->member_benefit_used_count) < intval($nbr)) {
- return json_fail("可核销数量不足");
- }
- try {
- $member = Member::find($memberId);
- $mobile = $member->member_mobile;
- $code = random_string(6, 'number');
- $key = self::KEY_PREFIX . 'QUOTA:' . $mobile;
- Redis::set($key, $code);
- Redis::expire($key, 600);
- Sms::app()->send($mobile, [
- 'template' => 'SMS_469030007',
- 'data' => [
- 'code' => $code
- ],
- ]);
- } catch (\Exception $e) {
- dump($e->getMessage());
- return json_fail("短信发送失败,请稍后重试");
- }
- return json_success('success');
- }
-
- public function sendSmsCodeByWriteOff(Request $request)
- {
- $memberId = $request->post('member_id', '');
-
- try {
- $member = Member::find($memberId);
- $mobile = $member->member_mobile;
- $code = random_string(6, 'number');
- $key = self::KEY_PREFIX . 'WRITE_OFF:' . $mobile;
- Redis::set($key, $code);
- Redis::expire($key, 600);
- Sms::app()->send($mobile, [
- 'template' => 'SMS_469030007',
- 'data' => [
- 'code' => $code
- ],
- ]);
- } catch (\Exception $e) {
- dump($e->getMessage());
- return json_fail("短信发送失败,请稍后重试");
- }
- return json_success('success');
- }
- public function sendSmsByOrderPay(Request $request)
- {
- $memberId = $request->post('member_id', '');
-
- try {
- $member = Member::find($memberId);
- $mobile = $member->member_mobile;
- $code = random_string(6, 'number');
- $key = self::KEY_PREFIX . 'ORDER_PAY:' . $mobile;
- Redis::set($key, $code);
- Redis::expire($key, 600);
- Sms::app()->send($mobile, [
- 'template' => 'SMS_469030007',
- 'data' => [
- 'code' => $code
- ],
- ]);
- } catch (\Exception $e) {
- dump($e->getMessage());
- return json_fail("短信发送失败,请稍后重试");
- }
- return json_success('success');
- }
-
- /**
- * 餐饮核销验证码
- */
- public function dishesWriteOffCode(Request $request)
- {
- $memberId = $request->post('member_id', '');
-
- try {
- $member = Member::find($memberId);
- $mobile = $member->member_mobile;
- $code = random_string(6, 'number');
- $key = self::KEY_PREFIX . 'DISHES:' . $mobile;
- Redis::set($key, $code);
- Redis::expire($key, 600);
- Sms::app()->send($mobile, [
- 'template' => 'SMS_469030007',
- 'data' => [
- 'code' => $code
- ],
- ]);
- } catch (\Exception $e) {
- dump($e->getMessage());
- return json_fail("短信发送失败,请稍后重试");
- }
- return json_success('success');
- }
- }
|