Browse Source
Merge branch 'phoenix' of http://120.24.33.109:11081/hyzjshwo/lanzu_api_hyperf into phoenix
master
Merge branch 'phoenix' of http://120.24.33.109:11081/hyzjshwo/lanzu_api_hyperf into phoenix
master
23 changed files with 458 additions and 194 deletions
-
2app/Constants/v3/ErrorCode.php
-
5app/Constants/v3/SmsTemplateCode.php
-
10app/Constants/v3/SsdbKeys.php
-
5app/Controller/TestController.php
-
29app/Controller/v3/HomeController.php
-
33app/Controller/v3/NotifyController.php
-
2app/Controller/v3/WithdrawController.php
-
40app/JsonRpc/OrderService.php
-
4app/Model/v3/FinancialRecord.php
-
171app/Service/v3/Implementations/BadgeService.php
-
62app/Service/v3/Implementations/FinancialRecordService.php
-
28app/Service/v3/Implementations/OrderListService.php
-
2app/Service/v3/Implementations/OrderOfflineService.php
-
39app/Service/v3/Implementations/OrderOnlineService.php
-
25app/Service/v3/Implementations/PaymentService.php
-
21app/Service/v3/Implementations/SmsAliSendService.php
-
69app/Service/v3/Implementations/SmsAliService.php
-
64app/Service/v3/Interfaces/BadgeServiceInterface.php
-
23app/Service/v3/Interfaces/FinancialRecordServiceInterface.php
-
2app/Service/v3/Interfaces/OrderOfflineServiceInterface.php
-
4app/Service/v3/Interfaces/SmsSendServiceInterface.php
-
9app/Service/v3/Interfaces/SmsServiceInterface.php
-
3config/autoload/dependencies.php
@ -0,0 +1,171 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Service\v3\Implementations; |
||||
|
|
||||
|
use App\Constants\v3\OrderState; |
||||
|
use App\Service\v3\Interfaces\BadgeServiceInterface; |
||||
|
use Hyperf\Redis\Redis; |
||||
|
use Hyperf\Utils\ApplicationContext; |
||||
|
|
||||
|
class BadgeService implements BadgeServiceInterface |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* @inheritDoc |
||||
|
*/ |
||||
|
public function doByOrder($userId, $storeIds, $globalOrderId, $orderState) |
||||
|
{ |
||||
|
|
||||
|
switch ($orderState) { |
||||
|
case OrderState::UNPAID: # 待付款(用户)
|
||||
|
$this->sAddUserOrder('unpaid', $userId, $globalOrderId); |
||||
|
break; |
||||
|
|
||||
|
case OrderState::CANCELED: # 订单取消(用户)
|
||||
|
$this->sAddUserOrder('canceled', $userId, $globalOrderId); |
||||
|
|
||||
|
foreach ($storeIds as $key => &$storeId) { |
||||
|
$this->sAddStoreOrder('canceled', $storeId, $globalOrderId); |
||||
|
} |
||||
|
break; |
||||
|
|
||||
|
case OrderState::PAID: # 已付款(用户)
|
||||
|
$this->sAddUserOrder('receiving', $userId, $globalOrderId); |
||||
|
|
||||
|
foreach ($storeIds as $key => &$storeId) { |
||||
|
$this->sAddStoreOrder('paid', $storeId, $globalOrderId); |
||||
|
} |
||||
|
break; |
||||
|
|
||||
|
case OrderState::REFUNDING: # 用户申请退款
|
||||
|
case OrderState::REFUNDED: # 后台同意退款
|
||||
|
case OrderState::REFUND_REFUSE: # 后台拒绝退款
|
||||
|
$this->sAddUserOrder('refund', $userId, $globalOrderId); |
||||
|
|
||||
|
foreach ($storeIds as $key => &$storeId) { |
||||
|
$this->sAddStoreOrder('refund', $storeId, $globalOrderId); |
||||
|
} |
||||
|
break; |
||||
|
|
||||
|
case OrderState::REJECTION: # 后台拒单(后台)
|
||||
|
$this->sAddUserOrder('rejection', $userId, $globalOrderId); |
||||
|
|
||||
|
foreach ($storeIds as $key => &$storeId) { |
||||
|
$this->sAddStoreOrder('rejection', $storeId, $globalOrderId); |
||||
|
} |
||||
|
break; |
||||
|
|
||||
|
case OrderState::DELIVERY: # 后台接单(后台)
|
||||
|
$this->sAddUserOrder('receiving', $userId, $globalOrderId); |
||||
|
|
||||
|
foreach ($storeIds as $key => &$storeId) { |
||||
|
$this->sAddStoreOrder('delivery', $storeId, $globalOrderId); |
||||
|
} |
||||
|
break; |
||||
|
|
||||
|
case OrderState::COMPLETED: # 订单完成(用户或后台操作)
|
||||
|
case OrderState::EVALUATED: # 订单评价(用户)
|
||||
|
$this->sAddUserOrder('finish', $userId, $globalOrderId); |
||||
|
|
||||
|
foreach ($storeIds as $key => &$storeId) { |
||||
|
$this->sAddStoreOrder('finish', $storeId, $globalOrderId); |
||||
|
} |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public function allByUserOrder($userId) |
||||
|
{ |
||||
|
$redis = ApplicationContext::getContainer()->get(Redis::class); |
||||
|
return [ |
||||
|
'unpaid' => count($redis->sMembers('badge_unpaid_user_'.$userId)), |
||||
|
'receiving' => count($redis->sMembers('badge_receiving_user_'.$userId)), |
||||
|
'finish' => count($redis->sMembers('badge_finish_user_'.$userId)), |
||||
|
'refund' => count($redis->sMembers('badge_refund_user_'.$userId)), |
||||
|
'canceled' => count($redis->sMembers('badge_canceled_user_'.$userId)), |
||||
|
'rejection' => count($redis->sMembers('badge_rejection_store_'.$userId)), |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @inheritDoc |
||||
|
*/ |
||||
|
public function allByStoreOrder($storeId) |
||||
|
{ |
||||
|
$redis = ApplicationContext::getContainer()->get(Redis::class); |
||||
|
return [ |
||||
|
'paid' => count($redis->sMembers('badge_paid_store_'.$storeId)), |
||||
|
'delivery' => count($redis->sMembers('badge_delivery_store_'.$storeId)), |
||||
|
'finish' => count($redis->sMembers('badge_canceled_store_'.$storeId)), |
||||
|
'refund' => count($redis->sMembers('badge_refund_store_'.$storeId)), |
||||
|
'canceled' => count($redis->sMembers('badge_canceled_store_'.$storeId)), |
||||
|
'rejection' => count($redis->sMembers('badge_rejection_store_'.$storeId)), |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @inheritDoc |
||||
|
*/ |
||||
|
public function sAddUserOrder($badge, $userId, $globalOrderId) |
||||
|
{ |
||||
|
$redis = ApplicationContext::getContainer()->get(Redis::class); |
||||
|
$redis->sRem('badge_unpaid_user_'.$userId, $globalOrderId); # 移除用户待付款
|
||||
|
$redis->sRem('badge_receiving_user_'.$userId, $globalOrderId); # 移除用户待收货
|
||||
|
$redis->sRem('badge_finish_user_'.$userId, $globalOrderId); # 移除用户已完成
|
||||
|
$redis->sRem('badge_canceled_user_'.$userId, $globalOrderId); # 移除用户已取消
|
||||
|
$redis->sRem('badge_refund_user_'.$userId, $globalOrderId); # 移除用户退款售后
|
||||
|
$redis->sRem('badge_rejection_store_', $userId, $globalOrderId); # 移除用户拒单
|
||||
|
$redis->sAdd('badge_'.$badge.'_user_'.$userId, $globalOrderId); # 新增用户当前状态的值
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @inheritDoc |
||||
|
*/ |
||||
|
public function sAddStoreOrder($badge, $storeId, $globalOrderId) |
||||
|
{ |
||||
|
$redis = ApplicationContext::getContainer()->get(Redis::class); |
||||
|
$redis->sRem('badge_paid_store_'.$storeId, $globalOrderId); # 移除商户待接单
|
||||
|
$redis->sRem('badge_delivery_store_'.$storeId, $globalOrderId); # 移除商户待送达
|
||||
|
$redis->sRem('badge_finish_store_'.$storeId, $globalOrderId); # 移除商户已完成
|
||||
|
$redis->sRem('badge_canceled_store_'.$storeId, $globalOrderId); # 移除商户已取消
|
||||
|
$redis->sRem('badge_refund_store_'.$storeId, $globalOrderId); # 移除商户退款售后
|
||||
|
$redis->sRem('badge_rejection_store_', $storeId, $globalOrderId); # 移除商户拒单
|
||||
|
$redis->sAdd('badge_'.$badge.'_store_'.$storeId, $globalOrderId); # 新增用户当前状态的值
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @inheritDoc |
||||
|
*/ |
||||
|
public function clearUserOrder($userId, $badge = 'all') |
||||
|
{ |
||||
|
$redis = ApplicationContext::getContainer()->get(Redis::class); |
||||
|
if ($badge == 'all') { |
||||
|
$redis->del('badge_unpaid_user_'.$userId); # 移除用户待付款
|
||||
|
$redis->del('badge_receiving_user_'.$userId); # 移除用户待收货
|
||||
|
$redis->del('badge_finish_user_'.$userId); # 移除用户已完成
|
||||
|
$redis->del('badge_canceled_user_'.$userId); # 移除用户已取消
|
||||
|
$redis->del('badge_refund_user_'.$userId); # 移除用户退款售后
|
||||
|
$redis->del('badge_rejection_store_', $userId); # 移除用户拒单
|
||||
|
} else { |
||||
|
$redis->del('badge_'.$badge.'_user_'.$userId); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @inheritDoc |
||||
|
*/ |
||||
|
public function clearStoreOrder($storeId, $badge = 'all') |
||||
|
{ |
||||
|
$redis = ApplicationContext::getContainer()->get(Redis::class); |
||||
|
if ($badge == 'all') { |
||||
|
$redis->del('badge_paid_user_'.$storeId); # 移除商户待付款
|
||||
|
$redis->del('badge_delivery_user_'.$storeId); # 移除商户待收货
|
||||
|
$redis->del('badge_finish_user_'.$storeId); # 移除商户已完成
|
||||
|
$redis->del('badge_canceled_user_'.$storeId); # 移除商户已取消
|
||||
|
$redis->del('badge_refund_user_'.$storeId); # 移除商户退款售后
|
||||
|
$redis->del('badge_rejection_store_', $storeId); # 移除商户拒单
|
||||
|
} else { |
||||
|
$redis->del('badge_'.$badge.'_user_'.$storeId); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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)); |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,64 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Service\v3\Interfaces; |
||||
|
|
||||
|
interface BadgeServiceInterface |
||||
|
{ |
||||
|
/** |
||||
|
* 用户和商户首页订单角标 |
||||
|
* @param $userId |
||||
|
* @param $storeIds |
||||
|
* @param $globalOrderId |
||||
|
* @param $orderState |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function doByOrder($userId, $storeIds, $globalOrderId, $orderState); |
||||
|
|
||||
|
/** |
||||
|
* 用户订单角标 |
||||
|
* @param $userId |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function allByUserOrder($userId); |
||||
|
|
||||
|
/** |
||||
|
* 商户订单角标 |
||||
|
* @param $storeId |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function allByStoreOrder($storeId); |
||||
|
|
||||
|
/** |
||||
|
* 添加用户订单角标 |
||||
|
* @param $badge |
||||
|
* @param $userId |
||||
|
* @param $globalOrderId |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function sAddUserOrder($badge, $userId, $globalOrderId); |
||||
|
|
||||
|
/** |
||||
|
* 添加商户订单角标 |
||||
|
* @param $badge |
||||
|
* @param $storeId |
||||
|
* @param $globalOrderId |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function sAddStoreOrder($badge, $storeId, $globalOrderId); |
||||
|
|
||||
|
/** |
||||
|
* 清除用户角标 |
||||
|
* @param $userId |
||||
|
* @param string $badge |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function clearUserOrder($userId, $badge = 'all'); |
||||
|
|
||||
|
/** |
||||
|
* 清除商户角标 |
||||
|
* @param $storeId |
||||
|
* @param string $badge |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function clearStoreOrder($storeId, $badge = 'all'); |
||||
|
} |
||||
@ -1,9 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace App\Service\v3\Interfaces; |
|
||||
|
|
||||
interface SmsServiceInterface |
|
||||
{ |
|
||||
public function send($phone, $template, $templateParams); |
|
||||
public function sendForCommunityFinancial($userId, $money); |
|
||||
} |
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue