Browse Source

Merge branch 'phoenix' of http://120.24.33.109:11081/hyzjshwo/lanzu_api_hyperf into phoenix

master
lanzu_qinsheng 5 years ago
parent
commit
90d27601cc
  1. 2
      app/Constants/v3/ErrorCode.php
  2. 5
      app/Constants/v3/SmsTemplateCode.php
  3. 9
      app/Controller/v3/GoodsRecommendController.php
  4. 2
      app/Controller/v3/WithdrawController.php
  5. 13
      app/Service/v3/Implementations/FinancialRecordService.php
  6. 25
      app/Service/v3/Implementations/PaymentService.php
  7. 4
      app/Service/v3/Implementations/SearchService.php
  8. 21
      app/Service/v3/Implementations/SmsAliSendService.php
  9. 69
      app/Service/v3/Implementations/SmsAliService.php
  10. 4
      app/Service/v3/Interfaces/SmsSendServiceInterface.php
  11. 9
      app/Service/v3/Interfaces/SmsServiceInterface.php
  12. 2
      config/autoload/dependencies.php

2
app/Constants/v3/ErrorCode.php

@ -88,7 +88,7 @@ class ErrorCode extends AbstractConstants
/************************************/ /************************************/
/** /**
* @Message("支付失败")
* @Message("提现支付失败")
*/ */
const PAYMENT_FAIL = 651; const PAYMENT_FAIL = 651;

5
app/Constants/v3/SmsTemplateCode.php

@ -14,4 +14,9 @@ class SmsTemplateCode extends AbstractConstants
* @Message("短信验证码") * @Message("短信验证码")
*/ */
const ALI_VERIFY_CODE = 'SMS_201650612'; const ALI_VERIFY_CODE = 'SMS_201650612';
/**
* @Message("社区服务点奖励流水")
*/
const ALI_COMMUNITY_FINANCIAL = 'SMS_200690862';
} }

9
app/Controller/v3/GoodsRecommendController.php

@ -28,7 +28,11 @@ class GoodsRecommendController extends BaseController
$page = $this->request->input('page', 1); $page = $this->request->input('page', 1);
$pagesize = $this->request->input('pagesize', 10); $pagesize = $this->request->input('pagesize', 10);
$builder = Goods::query()->with('store')->where('market_id', $marketId);
$builder = Goods::query()->with('store')
->where('market_id', $marketId)
->where(function ($query) {
$query->where('inventory', '>', 0)->orWhere('is_infinite', '=', 1);
});
switch ($tab) { switch ($tab) {
case Tabs::APPLET_INDEX_RECOMMEND: case Tabs::APPLET_INDEX_RECOMMEND:
@ -67,6 +71,9 @@ class GoodsRecommendController extends BaseController
$goods = Goods::query() $goods = Goods::query()
->with(['store']) ->with(['store'])
->where('market_id', $marketId) ->where('market_id', $marketId)
->where(function ($query) {
$query->where('inventory', '>', 0)->orWhere('is_infinite', '=', 1);
})
->inRandomOrder() ->inRandomOrder()
->limit(20) ->limit(20)
->get()->toArray(); ->get()->toArray();

2
app/Controller/v3/WithdrawController.php

@ -194,7 +194,7 @@ class WithdrawController extends BaseController
'withdraw' => json_encode($withdraw), 'withdraw' => json_encode($withdraw),
'params' => json_encode(['balance' => $balance->balance, 'user_id' => $userId, 'store_id' => $storeId]), 'params' => json_encode(['balance' => $balance->balance, 'user_id' => $userId, 'store_id' => $storeId]),
]); ]);
throw new ErrorCodeException(ErrorCode::STORE_WITHDRAW_FAIL, $e->getMessage());
throw new ErrorCodeException(ErrorCode::STORE_WITHDRAW_FAIL);
} }
} }

13
app/Service/v3/Implementations/FinancialRecordService.php

@ -4,10 +4,9 @@ namespace App\Service\v3\Implementations;
use App\Constants\v3\UserType; use App\Constants\v3\UserType;
use App\Model\v3\FinancialRecord; use App\Model\v3\FinancialRecord;
use App\Model\v3\Store;
use App\Model\v3\UserBalance; use App\Model\v3\UserBalance;
use App\Service\v3\Interfaces\FinancialRecordServiceInterface; use App\Service\v3\Interfaces\FinancialRecordServiceInterface;
use App\Service\v3\Interfaces\SmsServiceInterface;
use App\Service\v3\Interfaces\SmsSendServiceInterface;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
class FinancialRecordService implements FinancialRecordServiceInterface class FinancialRecordService implements FinancialRecordServiceInterface
@ -15,9 +14,9 @@ class FinancialRecordService implements FinancialRecordServiceInterface
/** /**
* @Inject * @Inject
* @var SmsServiceInterface
* @var SmsSendServiceInterface
*/ */
protected $smsAliService;
protected $smsAliSendService;
public function ledgerAccounts($source_id, $money, $source_type, $money_type, $desc, $comment='') public function ledgerAccounts($source_id, $money, $source_type, $money_type, $desc, $comment='')
{ {
@ -87,7 +86,7 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$balance->save(); $balance->save();
// 发送短信 // 发送短信
$this->smsAliService->sendForCommunityFinancial($user_id, $money);
$this->smsAliSendService->doCommunityFinancial($user_id, $money);
} }
@ -115,7 +114,7 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$balance->save(); $balance->save();
// 发送短信 // 发送短信
$this->smsAliService->sendForCommunityFinancial($user_id, $money);
$this->smsAliSendService->doCommunityFinancial($user_id, $money);
} }
/** /**
@ -142,7 +141,7 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$balance->save(); $balance->save();
// 发送短信 // 发送短信
$this->smsAliService->sendForCommunityFinancial($user_id, $money);
$this->smsAliSendService->doCommunityFinancial($user_id, $money);
} }

25
app/Service/v3/Implementations/PaymentService.php

@ -13,13 +13,17 @@ use App\Model\v3\OrderMain;
use App\Model\v3\User; use App\Model\v3\User;
use App\Service\v3\Interfaces\GoodsActivityServiceInterface; use App\Service\v3\Interfaces\GoodsActivityServiceInterface;
use App\Service\v3\Interfaces\PaymentServiceInterface; use App\Service\v3\Interfaces\PaymentServiceInterface;
use App\Service\v3\Interfaces\SmsSendServiceInterface;
use EasyWeChat\Factory; use EasyWeChat\Factory;
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
use EasyWeChat\Kernel\Exceptions\InvalidConfigException; use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
use EasyWeChat\Kernel\Support\Collection; use EasyWeChat\Kernel\Support\Collection;
use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Exception\GuzzleException;
use Hyperf\DbConnection\Db; use Hyperf\DbConnection\Db;
use Hyperf\Guzzle\CoroutineHandler; use Hyperf\Guzzle\CoroutineHandler;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
use Hyperf\Redis\Redis;
use Hyperf\Utils\ApplicationContext;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use function AlibabaCloud\Client\json; use function AlibabaCloud\Client\json;
@ -31,6 +35,11 @@ class PaymentService implements PaymentServiceInterface
*/ */
protected $log; protected $log;
/**
* @var SmsSendServiceInterface
*/
protected $smsAliSendService;
public function do($globalOrderId, $money, $userId, $notifyUrl) public function do($globalOrderId, $money, $userId, $notifyUrl)
{ {
@ -94,7 +103,7 @@ class PaymentService implements PaymentServiceInterface
} }
/** /**
* 退款的整单,允许后台操作退款
* 退款的整单,用户申请的退款
* @param $globalOrderId * @param $globalOrderId
* @param $userId * @param $userId
* @return array|bool|Collection|object|ResponseInterface|string * @return array|bool|Collection|object|ResponseInterface|string
@ -147,7 +156,10 @@ class PaymentService implements PaymentServiceInterface
* @param $userName * @param $userName
* @param string $desc * @param string $desc
* @param string $checkName * @param string $checkName
* @return bool
* @throws GuzzleException * @throws GuzzleException
* @throws InvalidConfigException
* @throws InvalidArgumentException
*/ */
public function payToWx($money, $tradeNo, $openId, $userName, $desc = '', $checkName = 'NO_CHECK') public function payToWx($money, $tradeNo, $openId, $userName, $desc = '', $checkName = 'NO_CHECK')
{ {
@ -179,7 +191,16 @@ class PaymentService implements PaymentServiceInterface
'result' => json_encode($result), 'result' => json_encode($result),
'desc' => $desc 'desc' => $desc
]); ]);
throw new ErrorCodeException(ErrorCode::PAYMENT_FAIL, $result['err_code_des']);
throw new ErrorCodeException(ErrorCode::PAYMENT_FAIL);
// 如果是商户余额不足等原因,要发送短信给老总
$arr = ['NOTENOUGH','AMOUNT_LIMIT'];
if (in_array($result['error_code'], $arr)) {
$redis = ApplicationContext::getContainer()->get(Redis::class);
if (!$redis->exists('send_withdraw_refuse_reson_'.date('Ymd'))) {
$this->smsAliSendService->doWithdrawFail($result['error_code'], $result['error_code_des']);
}
}
} }
return true; return true;

4
app/Service/v3/Implementations/SearchService.php

@ -19,7 +19,9 @@ class SearchService implements \App\Service\v3\Interfaces\SearchServiceInterface
return $query->select(['id', 'logo', 'name']); return $query->select(['id', 'logo', 'name']);
}]) }])
->where(['market_id' => $params['market_id']]) ->where(['market_id' => $params['market_id']])
->where('inventory', '>', 0);
->where(function ($query) {
$query->where('inventory', '>', 0)->orWhere('is_infinite', '=', 1);
});;
if (isset($params['type_id']) && $params['type_id']) { if (isset($params['type_id']) && $params['type_id']) {
$typeIds = explode(',', $params['type_id']); $typeIds = explode(',', $params['type_id']);

21
app/Service/v3/Implementations/SmsAliSendService.php

@ -7,6 +7,8 @@ use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException; use AlibabaCloud\Client\Exception\ServerException;
use App\Constants\v3\ErrorCode; use App\Constants\v3\ErrorCode;
use App\Exception\ErrorCodeException; use App\Exception\ErrorCodeException;
use App\Model\v3\CsInfo;
use App\Model\v3\Market;
use Exception; use Exception;
use App\Commons\Log; use App\Commons\Log;
use App\Constants\v3\SmsTemplateCode; use App\Constants\v3\SmsTemplateCode;
@ -22,7 +24,7 @@ class SmsAliSendService implements SmsSendServiceInterface
*/ */
protected $log; protected $log;
public function do($tel, $template, $templateParams)
public function do($tel, $template, $templateParams, $signName = '')
{ {
try { try {
@ -41,7 +43,7 @@ class SmsAliSendService implements SmsSendServiceInterface
'query' => [ 'query' => [
'RegionId' => $aliSms['regionid'], 'RegionId' => $aliSms['regionid'],
'PhoneNumbers' => $tel, 'PhoneNumbers' => $tel,
'SignName' => $aliSms['sign_name'],
'SignName' => $signName ?: $aliSms['sign_name'],
'TemplateCode' => $template, 'TemplateCode' => $template,
'TemplateParam' => $templateParams, 'TemplateParam' => $templateParams,
], ],
@ -86,4 +88,19 @@ class SmsAliSendService implements SmsSendServiceInterface
// TODO: Implement removeVerifyCode() method. // TODO: Implement removeVerifyCode() method.
} }
public function doCommunityFinancial($userId, $money)
{
$csInfo = CsInfo::query()->where(['admin_user_id' => $userId])->first();
$market = Market::query()->where(['id' => $csInfo->market_id])->first();
$params = ['user_name' => $csInfo->name, 'market_name' => $market->name, 'money' => $money];
return $this->do($csInfo->phone, SmsTemplateCode::ALI_COMMUNITY_FINANCIAL, json_encode($params));
}
public function doWithdrawFail($errorCode, $errorCodeDes)
{
$params = ['code' => $errorCode];
return $this->do(18611745705, SmsTemplateCode::ALI_VERIFY_CODE, json_encode($params));
}
} }

69
app/Service/v3/Implementations/SmsAliService.php

@ -1,69 +0,0 @@
<?php
namespace App\Service\v3\Implementations;
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
use App\Commons\Log;
use App\Model\v3\CsInfo;
use App\Model\v3\Market;
use App\Service\v3\Interfaces\SmsServiceInterface;
use Hyperf\Di\Annotation\Inject;
class SmsAliService implements SmsServiceInterface
{
const TEMPLATE_COMMUNITY_FINANCIAL = 'SMS_200690862';
/**
* @Inject
* @var Log
*/
protected $log;
public function send($phone, $template, $templateParams, $signName='懒族生活')
{
$alisms = config('alisms');
AlibabaCloud::accessKeyClient($alisms['app_key'], $alisms['app_secret'])
->regionId($alisms['regionid'])
->asDefaultClient();
try {
$result = AlibabaCloud::rpc()
->product($alisms['product'])
// ->scheme('https') // https | http
->version('2017-05-25')
->action('SendSms')
->method('POST')
->host($alisms['host'])
->options([
'query' => [
'RegionId' => $alisms['regionid'],
'PhoneNumbers' => $phone,
'SignName' => $signName,
'TemplateCode' => $template,
'TemplateParam' => $templateParams,
],
])
->request();
return $result->toArray();
} catch (ClientException $e) {
$this->log->event('alisms', ['alisms_error_ClientException' => $e->getErrorMessage()]);
return false;
} catch (ServerException $e) {
$this->log->event('alisms', ['alisms_error_ServerException' => $e->getErrorMessage()]);
return false;
}
}
public function sendForCommunityFinancial($userId, $money)
{
$csInfo = CsInfo::query()->where(['admin_user_id' => $userId])->first();
$market = Market::query()->where(['id' => $csInfo->market_id])->first();
$params = ['user_name' => $csInfo->name, 'market_name' => $market->name, 'money' => $money];
return $this->send($csInfo->phone, self::TEMPLATE_COMMUNITY_FINANCIAL, json_encode($params));
}
}

4
app/Service/v3/Interfaces/SmsSendServiceInterface.php

@ -4,10 +4,12 @@ namespace App\Service\v3\Interfaces;
interface SmsSendServiceInterface interface SmsSendServiceInterface
{ {
public function do($tel, $template, $templateParams);
public function do($tel, $template, $templateParams, $signName = '');
public function check(); public function check();
public function undo(); public function undo();
public function doVerifyCode($tel, $code); public function doVerifyCode($tel, $code);
public function checkVerifyCode($tel, $code); public function checkVerifyCode($tel, $code);
public function undoVerifyCode($tel, $code); public function undoVerifyCode($tel, $code);
public function doCommunityFinancial($userId, $money);
public function doWithdrawFail($errorCode, $errorCodeDes);
} }

9
app/Service/v3/Interfaces/SmsServiceInterface.php

@ -1,9 +0,0 @@
<?php
namespace App\Service\v3\Interfaces;
interface SmsServiceInterface
{
public function send($phone, $template, $templateParams);
public function sendForCommunityFinancial($userId, $money);
}

2
config/autoload/dependencies.php

@ -77,7 +77,7 @@ return [
\App\Service\v3\Interfaces\SeparateAccountsServiceInterface::class => \App\Service\v3\Implementations\SeparateAccountsService::class, \App\Service\v3\Interfaces\SeparateAccountsServiceInterface::class => \App\Service\v3\Implementations\SeparateAccountsService::class,
\App\Service\v3\Interfaces\UserServiceInterface::class => \App\Service\v3\Implementations\UserService::class, \App\Service\v3\Interfaces\UserServiceInterface::class => \App\Service\v3\Implementations\UserService::class,
\App\Service\v3\Interfaces\CouponRebateServiceInterface::class => \App\Service\v3\Implementations\CouponRebateService::class, \App\Service\v3\Interfaces\CouponRebateServiceInterface::class => \App\Service\v3\Implementations\CouponRebateService::class,
\App\Service\v3\Interfaces\SmsServiceInterface::class => \App\Service\v3\Implementations\SmsAliService::class,
\App\Service\v3\Interfaces\SmsSendServiceInterface::class => \App\Service\v3\Implementations\SmsAliSendService::class,
\App\Service\v3\Interfaces\AttachmentServiceInterface::class => \App\Service\v3\Implementations\AttachmentService::class, \App\Service\v3\Interfaces\AttachmentServiceInterface::class => \App\Service\v3\Implementations\AttachmentService::class,
\App\JsonRpc\PrintServiceInterface::class => \App\JsonRpc\FeieService::class, \App\JsonRpc\PrintServiceInterface::class => \App\JsonRpc\FeieService::class,
\App\JsonRpc\LocationServiceInterface::class => \App\JsonRpc\LocationService::class, \App\JsonRpc\LocationServiceInterface::class => \App\JsonRpc\LocationService::class,

Loading…
Cancel
Save