From d93fbd78a2eec988d5c63b469471d17ab237c997 Mon Sep 17 00:00:00 2001 From: weigang Date: Mon, 10 Aug 2020 19:09:26 +0800 Subject: [PATCH 01/75] =?UTF-8?q?=E7=A4=BE=E5=8C=BA=E6=89=AB=E7=A0=81?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CommunityController.php | 26 ++++++++ .../ValidatorFactoryResolvedListener.php | 66 +++++++++++++++++++ app/Model/ActivityBind.php | 34 ++++++++++ app/Request/CommunityBindRequest.php | 46 +++++++++++++ app/Service/CommunityService.php | 30 +++++++++ app/Service/CommunityServiceInterface.php | 9 +++ config/autoload/dependencies.php | 3 +- config/routes.php | 1 + 8 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 app/Controller/CommunityController.php create mode 100644 app/Model/ActivityBind.php create mode 100644 app/Request/CommunityBindRequest.php create mode 100644 app/Service/CommunityService.php create mode 100644 app/Service/CommunityServiceInterface.php diff --git a/app/Controller/CommunityController.php b/app/Controller/CommunityController.php new file mode 100644 index 0000000..0505272 --- /dev/null +++ b/app/Controller/CommunityController.php @@ -0,0 +1,26 @@ +communityService->bind($request->validated()); + return $this->success(['id' => $res->id]); + } + +} diff --git a/app/Listener/ValidatorFactoryResolvedListener.php b/app/Listener/ValidatorFactoryResolvedListener.php index 0bfb047..7423594 100644 --- a/app/Listener/ValidatorFactoryResolvedListener.php +++ b/app/Listener/ValidatorFactoryResolvedListener.php @@ -4,6 +4,7 @@ namespace App\Listener; use Hyperf\DbConnection\Db; use Hyperf\Event\Contract\ListenerInterface; +use Hyperf\HttpMessage\Upload\UploadedFile; use Hyperf\Validation\Contract\ValidatorFactoryInterface; use Hyperf\Validation\Event\ValidatorFactoryResolved; @@ -80,5 +81,70 @@ class ValidatorFactoryResolvedListener implements ListenerInterface return $builder->exists(); }); + // 注册了 base64 验证器规则 + $validatorFactory->extend('base64', function ($attribute, $value, $parameters, $validator) { + + preg_match('/^(data:\s*image\/(\w+);base64,)/', $value, $result); + + if (empty($result)) { + return false; + } + + if ( + in_array('image', $parameters) + && !in_array($result[2], ['jpg','jpeg','png','gif','svg','bmp']) + ) { + return false; + } + + return true; + + }); + + // 注册了 ext_not_in 验证器规则 + $validatorFactory->extend('ext_not_in', function ($attribute, $value, $parameters, $validator) { + + if (empty($parameters)) { + $parameters = ['', 'php', 'exe', 'sql', 'sh', 'bat', 'py', 'go', 'c', 'cpp']; + } + return !in_array($value->getExtension(), $parameters); + + }); + + // 注册了 file_different_if_file 验证器规则 + // file_different_if_file:field 两文件字段不能是同一个文件 + $validatorFactory->extend('file_different_if_file', function ($attribute, $value, $parameters, $validator) { + + // 获取比较字段参数值 + $anotherFile = $validator->getData()[$parameters[0]]; + if (!($value instanceof UploadedFile && $anotherFile instanceof UploadedFile)) { + return true; + } + return md5_file($value->getRealPath()) !== md5_file($anotherFile->getRealPath()); + + }); + + // 注册了 tel 验证器规则 + // 手机号码验证器 + $validatorFactory->extend('tel', function ($attribute, $value, $parameters, $validator) { + return boolval(preg_match('/^1[3-9]\d{9}$/', $value)); + }); + + // 注册了 image_if_file 验证器规则 + // 如果是文件就必须是图片类型的 + $validatorFactory->extend('image_if_file', function ($attribute, $value, $parameters, $validator) { + + if (!($value instanceof UploadedFile)) { + return true; + } + + $rules = $validator->getRules(); + $rules[$attribute] = ['image']; + $validator->setRules($rules); + + return $validator->passes(); + + }); + } } \ No newline at end of file diff --git a/app/Model/ActivityBind.php b/app/Model/ActivityBind.php new file mode 100644 index 0000000..2f4dda0 --- /dev/null +++ b/app/Model/ActivityBind.php @@ -0,0 +1,34 @@ +attributes['json_data'] = json_encode(json_decode($value, true)); + } + +} \ No newline at end of file diff --git a/app/Request/CommunityBindRequest.php b/app/Request/CommunityBindRequest.php new file mode 100644 index 0000000..e207452 --- /dev/null +++ b/app/Request/CommunityBindRequest.php @@ -0,0 +1,46 @@ + 'required|nonempty', + 'source_id' => 'required|nonempty', + 'user_id' => 'required|nonempty|exists_enable:ims_cjdc_user,id', + 'json_data' => 'json', + ]; + } + + public function messages(): array + { + return [ + '*.nonempty' => ':attribute参数异常', + 'user_id.exists_enable' => '用户不存在', + ]; + } + + public function attributes(): array + { + return [ + + ]; + } +} diff --git a/app/Service/CommunityService.php b/app/Service/CommunityService.php new file mode 100644 index 0000000..6332750 --- /dev/null +++ b/app/Service/CommunityService.php @@ -0,0 +1,30 @@ +isBinded($data['bind_type'], $data['source_id'], $data['user_id'])) { + return $res; + } + return ActivityBind::query()->updateOrCreate( + ['bind_type' => $data['bind_type'], 'source_id' => $data['source_id'], 'user_id' => $data['user_id']], + ['json_data' => $data['json_data']] + ); + } + + public function isBinded($bind_type, $source_id, $user_id) + { + return ActivityBind::query() + ->select('id') + ->where(['bind_type' => $bind_type, 'source_id' => $source_id, 'user_id' => $user_id]) + ->first(); + } +} \ No newline at end of file diff --git a/app/Service/CommunityServiceInterface.php b/app/Service/CommunityServiceInterface.php new file mode 100644 index 0000000..de7f29d --- /dev/null +++ b/app/Service/CommunityServiceInterface.php @@ -0,0 +1,9 @@ + \App\Service\ServiceEvaluateService::class + \App\Service\ServiceEvaluateServiceInterface::class => \App\Service\ServiceEvaluateService::class, + \App\Service\CommunityServiceInterface::class => \App\Service\CommunityService::class, ]; diff --git a/config/routes.php b/config/routes.php index 706a9ab..a5c4985 100644 --- a/config/routes.php +++ b/config/routes.php @@ -23,4 +23,5 @@ Router::addGroup('/v1/',function (){ Router::post('ServiceEvaluate/isPersonnel', 'App\Controller\ServiceEvaluateController@isPersonnel'); Router::post('ServiceEvaluate/getPersonnelInfo', 'App\Controller\ServiceEvaluateController@getPersonnelInfo'); Router::post('ServiceEvaluate/getEvaluateList', 'App\Controller\ServiceEvaluateController@getEvaluateList'); + Router::post('Community/bind', 'App\Controller\CommunityController@bind'); }); \ No newline at end of file From e7caeaf4bd309df8cddd7974b54034ad469eb383 Mon Sep 17 00:00:00 2001 From: weigang Date: Tue, 11 Aug 2020 10:42:47 +0800 Subject: [PATCH 02/75] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=A4=BE=E5=8C=BA?= =?UTF-8?q?=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Middleware/Auth/ApiMiddleware.php | 2 +- app/Model/{ActivityBind.php => UserRelationBind.php} | 4 ++-- app/Service/CommunityService.php | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) rename app/Model/{ActivityBind.php => UserRelationBind.php} (86%) diff --git a/app/Middleware/Auth/ApiMiddleware.php b/app/Middleware/Auth/ApiMiddleware.php index ce06bff..44cf3fc 100644 --- a/app/Middleware/Auth/ApiMiddleware.php +++ b/app/Middleware/Auth/ApiMiddleware.php @@ -39,7 +39,7 @@ class ApiMiddleware implements MiddlewareInterface public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { - if (env('APP_ENV') == 'dev') { + if (env('APP_ENV') == 'dev' || env('APP_ENV') == 'local') { return $handler->handle($request); } diff --git a/app/Model/ActivityBind.php b/app/Model/UserRelationBind.php similarity index 86% rename from app/Model/ActivityBind.php rename to app/Model/UserRelationBind.php index 2f4dda0..1265197 100644 --- a/app/Model/ActivityBind.php +++ b/app/Model/UserRelationBind.php @@ -5,14 +5,14 @@ namespace App\Model; /** */ -class ActivityBind extends Model +class UserRelationBind extends Model { /** * The table associated with the model. * * @var string */ - protected $table = 'lanzu_activity_bind'; + protected $table = 'lanzu_user_relation_bind'; /** * The attributes that are mass assignable. * diff --git a/app/Service/CommunityService.php b/app/Service/CommunityService.php index 6332750..1b5aa2e 100644 --- a/app/Service/CommunityService.php +++ b/app/Service/CommunityService.php @@ -4,7 +4,7 @@ namespace App\Service; -use App\Model\ActivityBind; +use App\Model\UserRelationBind; class CommunityService implements CommunityServiceInterface { @@ -14,7 +14,7 @@ class CommunityService implements CommunityServiceInterface if ($res = $this->isBinded($data['bind_type'], $data['source_id'], $data['user_id'])) { return $res; } - return ActivityBind::query()->updateOrCreate( + return UserRelationBind::query()->updateOrCreate( ['bind_type' => $data['bind_type'], 'source_id' => $data['source_id'], 'user_id' => $data['user_id']], ['json_data' => $data['json_data']] ); @@ -22,7 +22,7 @@ class CommunityService implements CommunityServiceInterface public function isBinded($bind_type, $source_id, $user_id) { - return ActivityBind::query() + return UserRelationBind::query() ->select('id') ->where(['bind_type' => $bind_type, 'source_id' => $source_id, 'user_id' => $user_id]) ->first(); From 605ace63c986ad45e7c77c3be8c03c5ddb7484be Mon Sep 17 00:00:00 2001 From: weigang Date: Tue, 11 Aug 2020 11:27:47 +0800 Subject: [PATCH 03/75] fix --- app/Model/UserRelationBind.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Model/UserRelationBind.php b/app/Model/UserRelationBind.php index 1265197..f14f029 100644 --- a/app/Model/UserRelationBind.php +++ b/app/Model/UserRelationBind.php @@ -28,7 +28,7 @@ class UserRelationBind extends Model public function setJsonDataAttribute($value) { - $this->attributes['json_data'] = json_encode(json_decode($value, true)); + $this->attributes['json_data'] = $value ? json_encode(json_decode($value, true)) : ''; } } \ No newline at end of file From b2b021c80b4d54894d3f3a17c60f68b68f50b47f Mon Sep 17 00:00:00 2001 From: weigang Date: Wed, 19 Aug 2020 11:46:43 +0800 Subject: [PATCH 04/75] =?UTF-8?q?=E7=A4=BE=E5=8C=BA=E7=82=B9=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=BB=91=E5=AE=9A=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=86=85?= =?UTF-8?q?=E5=AE=B9=EF=BC=9A=E7=94=A8=E6=88=B7=E5=8F=AA=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CommunityController.php | 10 ++-- app/Model/UserRelationBind.php | 6 +++ app/Request/CommunityBindRequest.php | 1 - app/Service/CommunityService.php | 30 ------------ app/Service/CommunityServiceInterface.php | 9 ---- app/Service/UserCommunityBindService.php | 35 ++++++++++++++ .../UserRelationBindServiceInterface.php | 48 +++++++++++++++++++ config/autoload/dependencies.php | 2 +- config/routes.php | 1 - 9 files changed, 96 insertions(+), 46 deletions(-) delete mode 100644 app/Service/CommunityService.php delete mode 100644 app/Service/CommunityServiceInterface.php create mode 100644 app/Service/UserCommunityBindService.php create mode 100644 app/Service/UserRelationBindServiceInterface.php diff --git a/app/Controller/CommunityController.php b/app/Controller/CommunityController.php index 0505272..0caa660 100644 --- a/app/Controller/CommunityController.php +++ b/app/Controller/CommunityController.php @@ -4,8 +4,9 @@ declare(strict_types=1); namespace App\Controller; +use App\Model\UserRelationBind; use App\Request\CommunityBindRequest; -use App\Service\CommunityServiceInterface; +use App\Service\UserRelationBindServiceInterface; use Hyperf\Di\Annotation\Inject; class CommunityController extends BaseController @@ -13,13 +14,14 @@ class CommunityController extends BaseController /** * @Inject - * @var CommunityServiceInterface + * @var UserRelationBindServiceInterface */ - protected $communityService; + protected $userCommunityService; public function bind(CommunityBindRequest $request) { - $res = $this->communityService->bind($request->validated()); + $data = $request->validated(); + $res = $this->userCommunityService->bindLimitByUser(UserRelationBind::BIND_TYPE_COMMUNITY, $data['source_id'], $data['user_id'], $data['json_data']); return $this->success(['id' => $res->id]); } diff --git a/app/Model/UserRelationBind.php b/app/Model/UserRelationBind.php index f14f029..cf6615d 100644 --- a/app/Model/UserRelationBind.php +++ b/app/Model/UserRelationBind.php @@ -7,6 +7,12 @@ namespace App\Model; */ class UserRelationBind extends Model { + + /** + * 社区服务点类型 + */ + const BIND_TYPE_COMMUNITY = 1; + /** * The table associated with the model. * diff --git a/app/Request/CommunityBindRequest.php b/app/Request/CommunityBindRequest.php index e207452..6fe4841 100644 --- a/app/Request/CommunityBindRequest.php +++ b/app/Request/CommunityBindRequest.php @@ -22,7 +22,6 @@ class CommunityBindRequest extends FormRequest public function rules(): array { return [ - 'bind_type' => 'required|nonempty', 'source_id' => 'required|nonempty', 'user_id' => 'required|nonempty|exists_enable:ims_cjdc_user,id', 'json_data' => 'json', diff --git a/app/Service/CommunityService.php b/app/Service/CommunityService.php deleted file mode 100644 index 1b5aa2e..0000000 --- a/app/Service/CommunityService.php +++ /dev/null @@ -1,30 +0,0 @@ -isBinded($data['bind_type'], $data['source_id'], $data['user_id'])) { - return $res; - } - return UserRelationBind::query()->updateOrCreate( - ['bind_type' => $data['bind_type'], 'source_id' => $data['source_id'], 'user_id' => $data['user_id']], - ['json_data' => $data['json_data']] - ); - } - - public function isBinded($bind_type, $source_id, $user_id) - { - return UserRelationBind::query() - ->select('id') - ->where(['bind_type' => $bind_type, 'source_id' => $source_id, 'user_id' => $user_id]) - ->first(); - } -} \ No newline at end of file diff --git a/app/Service/CommunityServiceInterface.php b/app/Service/CommunityServiceInterface.php deleted file mode 100644 index de7f29d..0000000 --- a/app/Service/CommunityServiceInterface.php +++ /dev/null @@ -1,9 +0,0 @@ -updateOrCreate( + ['bind_type' => $bind_type, 'user_id' => $user_id], + ['source_id' => $source_id, 'json_data' => $extra_data] + ); + } + + public function bindLimitBySource($bind_type, $source_id, $user_id, $extra_data) + { + // TODO: Implement bindLimitBySource() method. + } + + public function bind($bind_type, $source_id, $user_id, $extra_data) + { + // TODO: Implement bind() method. + } + + public function isBinded($bind_type, $source_id, $user_id) + { + // TODO: Implement isBinded() method. + } +} \ No newline at end of file diff --git a/app/Service/UserRelationBindServiceInterface.php b/app/Service/UserRelationBindServiceInterface.php new file mode 100644 index 0000000..33eccc3 --- /dev/null +++ b/app/Service/UserRelationBindServiceInterface.php @@ -0,0 +1,48 @@ + \App\Service\FeiePrintService::class, \App\Service\MiniprogramServiceInterface::class => \App\Service\MiniprogramService::class, \App\Service\UserServiceInterface::class => \App\Service\UserService::class, - \App\Service\CommunityServiceInterface::class => \App\Service\CommunityService::class, + \App\Service\UserRelationBindServiceInterface::class => \App\Service\UserCommunityBindService::class, ]; diff --git a/config/routes.php b/config/routes.php index 3146d21..b68b0e4 100644 --- a/config/routes.php +++ b/config/routes.php @@ -54,7 +54,6 @@ Router::addGroup('/v1/',function (){ //小程序支付相关 Router::post('wxminipay/online', 'App\Controller\PaymentController@wxminiPayOnline'); Router::post('wxminipay/offline', 'App\Controller\PaymentController@wxminiPayOffline'); - Router::post('Community/bind', 'App\Controller\CommunityController@bind'); },['middleware' => [\App\Middleware\Auth\ApiMiddleware::class]]); Router::addGroup('/wechat/',function () { From cbb94cc7141250aa325d914b6645e57acb81c1ae Mon Sep 17 00:00:00 2001 From: weigang Date: Thu, 20 Aug 2020 19:07:56 +0800 Subject: [PATCH 05/75] =?UTF-8?q?=E7=A4=BE=E5=8C=BA=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=82=B9=E5=88=86=E8=B4=A6=E4=BB=A5=E5=8F=8A=E5=88=86=E8=B4=A6?= =?UTF-8?q?=E5=9F=BA=E7=A1=80=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Amqp/Consumer/couponRebateConsumer.php | 3 + app/Constants/ErrorCode.php | 5 + app/Constants/LogLabel.php | 5 + app/Controller/NotifyController.php | 2 +- app/JsonRpc/OrderService.php | 33 +++++ app/JsonRpc/OrderServiceInterface.php | 8 ++ app/Model/FinancialRecord.php | 89 +++++++++++++ app/Model/Model.php | 12 ++ app/Service/FinancialRecordService.php | 122 ++++++++++++++++++ .../FinancialRecordServiceInterface.php | 62 +++++++++ app/Service/SeparateAccountsService.php | 104 +++++++++++++++ .../SeparateAccountsServiceInterface.php | 28 ++++ app/Service/UserService.php | 2 +- app/Service/UserServiceInterface.php | 2 +- composer.json | 6 +- config/autoload/dependencies.php | 4 + config/autoload/server.php | 10 ++ 17 files changed, 493 insertions(+), 4 deletions(-) create mode 100644 app/JsonRpc/OrderService.php create mode 100644 app/JsonRpc/OrderServiceInterface.php create mode 100644 app/Model/FinancialRecord.php create mode 100644 app/Service/FinancialRecordService.php create mode 100644 app/Service/FinancialRecordServiceInterface.php create mode 100644 app/Service/SeparateAccountsService.php create mode 100644 app/Service/SeparateAccountsServiceInterface.php diff --git a/app/Amqp/Consumer/couponRebateConsumer.php b/app/Amqp/Consumer/couponRebateConsumer.php index a76f046..3417e2a 100644 --- a/app/Amqp/Consumer/couponRebateConsumer.php +++ b/app/Amqp/Consumer/couponRebateConsumer.php @@ -37,6 +37,9 @@ class couponRebateConsumer extends ConsumerMessage public function isEnable(): bool { + if(env('APP_ENV') == 'local') { + return false; + } return parent::isEnable(); } } diff --git a/app/Constants/ErrorCode.php b/app/Constants/ErrorCode.php index ca97510..62811c0 100644 --- a/app/Constants/ErrorCode.php +++ b/app/Constants/ErrorCode.php @@ -54,4 +54,9 @@ class ErrorCode extends AbstractConstants */ const PAY_FAILURE = 400; + /** + * @Message("Separate Accounts Error!") + */ + const SEPARATE_ACCOUNTS_ERROR = 700; + } diff --git a/app/Constants/LogLabel.php b/app/Constants/LogLabel.php index edcb57c..fe2253c 100644 --- a/app/Constants/LogLabel.php +++ b/app/Constants/LogLabel.php @@ -33,4 +33,9 @@ class LogLabel extends AbstractConstants * @Message("Order Log Label") */ const ORDER_LOG = 'order_log'; + + /** + * @Message("Separate Accounts Log Label") + */ + const SEPARATE_ACCOUNTS_LOG = 'separate_accounts_log'; } diff --git a/app/Controller/NotifyController.php b/app/Controller/NotifyController.php index 955db3f..2a8b094 100644 --- a/app/Controller/NotifyController.php +++ b/app/Controller/NotifyController.php @@ -332,7 +332,7 @@ class NotifyController extends BaseController StoreAccount::query()->insert(array_merge($recordBase, $record)); // 平台新用户奖励给商户 - $isStageNewUser = $this->userService->isStageNewUser($orderItem['user_id'], $orderMain->id); + $isStageNewUser = $this->userService->isPlatformNewUser($orderItem['user_id'], $orderMain->id); $needAward = false; $awardAmount = 0; if ($isStageNewUser) { diff --git a/app/JsonRpc/OrderService.php b/app/JsonRpc/OrderService.php new file mode 100644 index 0000000..6c25b92 --- /dev/null +++ b/app/JsonRpc/OrderService.php @@ -0,0 +1,33 @@ +separateAccService->orderOnlineCompleted($global_order_id); + return [ + "status" => 200, + "code" => $data ? 0 : ErrorCode::SEPARATE_ACCOUNTS_ERROR, + "result" => [], + "message" => $data ? '调用成功' : ErrorCode::getMessage(ErrorCode::SEPARATE_ACCOUNTS_ERROR) + ]; + } + +} \ No newline at end of file diff --git a/app/JsonRpc/OrderServiceInterface.php b/app/JsonRpc/OrderServiceInterface.php new file mode 100644 index 0000000..6292ffe --- /dev/null +++ b/app/JsonRpc/OrderServiceInterface.php @@ -0,0 +1,8 @@ +50是分账 + * + * MONEY_TYPE_PLAT_NEW_USER + * 社区服务点新用户奖励(线上订单完成) / 1 + * + * MONEY_TYPE_FIRST_ORDER + * 社区服务点新用户线上首单奖励(线上订单完成) / 2 + * + * MONEY_TYPE_OL_ORDER + * 社区服务点用户线上订单分账(线上订单完成) / 51 + */ + const MONEY_TYPE_PLAT_NEW_USER = 1; + const MONEY_TYPE_FIRST_ORDER = 2; + const MONEY_TYPE_OL_ORDER = 51; + + /** + * 状态 + */ + const STATUS_NORMAL = 1; + const STATUS_ABNORMAL = 2; + + /** + * The table associated with the model. + * + * @var string + */ + protected $table = 'lanzu_financial_record'; + /** + * The attributes that are mass assignable. + * + * @var array + */ + protected $fillable = [ + 'user_id', + 'user_type', + 'money', + 'money_type', + 'source_id', + 'source_type', + 'desc', + 'comment', + 'status', + ]; + /** + * The attributes that should be cast to native types. + * + * @var array + */ + protected $casts = []; +} \ No newline at end of file diff --git a/app/Model/Model.php b/app/Model/Model.php index f606652..fa03395 100644 --- a/app/Model/Model.php +++ b/app/Model/Model.php @@ -19,4 +19,16 @@ abstract class Model extends BaseModel implements CacheableInterface { use Cacheable; protected $dateFormat = 'U'; + + /** + * 设置表后缀 + * @param string $suffix + * @return $this + */ + public function suffix($suffix = ''): Model + { + $tableName = $this->getTable(); + $this->setTable($tableName.'_'.$suffix); + return $this; + } } diff --git a/app/Service/FinancialRecordService.php b/app/Service/FinancialRecordService.php new file mode 100644 index 0000000..061e297 --- /dev/null +++ b/app/Service/FinancialRecordService.php @@ -0,0 +1,122 @@ +record( + $user_id, + [ + 'user_id' => $user_id, + 'user_type' => $user_type, + 'money' => $money, + 'money_type' => $money_type, + 'source_id' => $source_id, + 'source_type' => $source_type, + 'desc' => $desc, + 'comment' => $comment, + 'status' => FinancialRecord::STATUS_NORMAL, + ] + ); + + $this->ledgerAccounts($source_id, $money, $source_type, $money_type, $desc, $comment); + } + + /** + * @inheritDoc + */ + public function communityAwardByPlatNewUserFirstOLOrder($user_id, $source_id, $money, $user_type=2, $source_type=1, $money_type=1, $desc='新用户首单奖励', $comment='') + { + $this->record( + $user_id, + [ + 'user_id' => $user_id, + 'user_type' => $user_type, + 'money' => $money, + 'money_type' => $money_type, + 'source_id' => $source_id, + 'source_type' => $source_type, + 'desc' => $desc, + 'comment' => $comment, + 'status' => FinancialRecord::STATUS_NORMAL, + ] + ); + + $this->ledgerAccounts($source_id, $money, $source_type, $money_type, $desc, $comment); + } + + /** + * @inheritDoc + */ + public function communitySeparateAccountsByOrderComp($user_id, $source_id, $money, $user_type=2, $source_type=1, $money_type=2, $desc='用户订单分成', $comment='') + { + $this->record( + $user_id, + [ + 'user_id' => $user_id, + 'user_type' => $user_type, + 'money' => $money, + 'money_type' => $money_type, + 'source_id' => $source_id, + 'source_type' => $source_type, + 'desc' => $desc, + 'comment' => $comment, + 'status' => FinancialRecord::STATUS_NORMAL, + ] + ); + + $this->ledgerAccounts($source_id, $money, $source_type, $money_type, $desc, $comment); + } + + public function ledgerAccounts($source_id, $money, $source_type, $money_type, $desc, $comment='') + { + return $this->record( + FinancialRecord::ACCOUNT_LEDGER, + [ + 'user_id' => FinancialRecord::ACCOUNT_LEDGER, + 'user_type' => FinancialRecord::USER_TYPE_LEDGER, + 'money' => $money, + 'money_type' => $money_type, + 'source_id' => $source_id, + 'source_type' => $source_type, + 'desc' => $desc, + 'comment' => $comment, + 'status' => FinancialRecord::STATUS_NORMAL, + ], + true + ); + } + + public function record($user_id, $record, $isLedger=false) + { + $financialRecord = new FinancialRecord(); + + if (!$isLedger) { + $mod = bcmod((string)$user_id, '5', 0); + $financialRecord->suffix($mod); + } + + return $financialRecord->fill( + [ + 'user_id' => $user_id, + 'user_type' => $record['user_type'], + 'money' => $record['money'], + 'money_type' => $record['money_type'], + 'source_id' => $record['source_id'], + 'source_type' => $record['source_type'], + 'desc' => $record['desc'], + 'comment' => $record['comment'], + 'status' => $record['status'], + ] + )->save(); + + } +} \ No newline at end of file diff --git a/app/Service/FinancialRecordServiceInterface.php b/app/Service/FinancialRecordServiceInterface.php new file mode 100644 index 0000000..4078043 --- /dev/null +++ b/app/Service/FinancialRecordServiceInterface.php @@ -0,0 +1,62 @@ +where(['global_order_id' => $global_order_id]) + ->whereIn('state', [OrderMain::ORDER_STATE_COMPLETE,OrderMain::ORDER_STATE_EVALUATED,OrderMain::ORDER_STATE_UNREFUND]) + ->first(); + + if (empty($orderMain)) { + return; + } + + Db::beginTransaction(); + try { + + // =======社区服务点分账 / Start======= + // 前提:用户线上下单并且订单完成 + // 奖励规则A:用户是平台新用户,奖励社区服务点平台新用户奖励x元+平台新用户首单奖励y元+订单商品金额z%的分成 + // 奖励规则B:用户是非新用户,奖励社区服务点订单实际支付金额z%的分成 + // =======社区服务点分账 / Start======= + + // 奖励/分账金额 TODO 届时查询出来一个配置 + $award = ['new_user' => 1, 'first_order' => 2, 'separate_rate' => 2]; + + // 当前用户的社区服务点绑定关系 + $communityBind = UserRelationBind::query() + ->where(['bind_type' => UserRelationBind::BIND_TYPE_COMMUNITY, 'user_id' => $orderMain->user_id]) + ->first(); + + // 平台新用户 + if ($this->userService->isPlatformNewUser($orderMain->user_id, $orderMain->id)) { + $this->financialRecordService->communityAwardByPlatNewUser($communityBind->source_id, $orderMain->global_order_id, $award['new_user']); + $this->financialRecordService->communityAwardByPlatNewUserFirstOLOrder($communityBind->source_id, $orderMain->global_order_id, $award['first_order']); + } + + // 账单分成 + $money = bcmul($orderMain->money, bcdiv($award['separate_rate'], 100, 6), 2); + $this->financialRecordService->communitySeparateAccountsByOrderComp($communityBind->source_id, $orderMain->global_order_id, $money); + + // =======社区服务点分账 / End======= + + Db::commit(); + return true; + + } catch (\Exception $e) { + + $this->log->event(LogLabel::SEPARATE_ACCOUNTS_LOG, ['exception' => $e->getMessage(), 'order_main' => json_encode($orderMain)]); + Db::rollBack(); + return false; + } + + } + + /** + * @inheritDoc + */ + public function orderOfflinePaid($global_order_id) + { + // TODO: Implement orderOfflinePaid() method. + } +} \ No newline at end of file diff --git a/app/Service/SeparateAccountsServiceInterface.php b/app/Service/SeparateAccountsServiceInterface.php new file mode 100644 index 0000000..c574735 --- /dev/null +++ b/app/Service/SeparateAccountsServiceInterface.php @@ -0,0 +1,28 @@ +where(['user_id' => $user_id]) diff --git a/app/Service/UserServiceInterface.php b/app/Service/UserServiceInterface.php index 2920d53..1e8f0fb 100644 --- a/app/Service/UserServiceInterface.php +++ b/app/Service/UserServiceInterface.php @@ -12,7 +12,7 @@ interface UserServiceInterface * @param $order_main_id * @return mixed */ - public function isStageNewUser($user_id, $order_main_id): bool; + public function isPlatformNewUser($user_id, $order_main_id): bool; public function saveUserUnionid($openid,$unionid); diff --git a/composer.json b/composer.json index 284593c..4cfe0dd 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,11 @@ "alibabacloud/iot": "^1.8", "hyperf/snowflake": "^2.0", "ext-bcmath": "*", - "overtrue/wechat": "~4.0" + "overtrue/wechat": "~4.0", + "hyperf/json-rpc": "^2.0", + "hyperf/rpc-server": "^2.0", + "hyperf/rpc-client": "^2.0", + "hyperf/consul": "^2.0" }, "require-dev": { "swoole/ide-helper": "^4.5", diff --git a/config/autoload/dependencies.php b/config/autoload/dependencies.php index a9ee1fb..760f9d0 100644 --- a/config/autoload/dependencies.php +++ b/config/autoload/dependencies.php @@ -27,4 +27,8 @@ return [ \App\Service\MiniprogramServiceInterface::class => \App\Service\MiniprogramService::class, \App\Service\UserServiceInterface::class => \App\Service\UserService::class, \App\Service\UserRelationBindServiceInterface::class => \App\Service\UserCommunityBindService::class, + \Hyperf\JsonRpc\JsonRpcTransporter::class => \Hyperf\JsonRpc\JsonRpcPoolTransporter::class, + \App\JsonRpc\OrderServiceInterface::class => \App\JsonRpc\OrderService::class, + \App\Service\FinancialRecordServiceInterface::class => \App\Service\FinancialRecordService::class, + \App\Service\SeparateAccountsServiceInterface::class => \App\Service\SeparateAccountsService::class, ]; diff --git a/config/autoload/server.php b/config/autoload/server.php index f44b083..1418f3a 100644 --- a/config/autoload/server.php +++ b/config/autoload/server.php @@ -25,6 +25,16 @@ return [ SwooleEvent::ON_REQUEST => [Hyperf\HttpServer\Server::class, 'onRequest'], ], ], + [ + 'name' => 'jsonrpc-http', + 'type' => Server::SERVER_HTTP, + 'host' => '0.0.0.0', + 'port' => 9505, + 'sock_type' => SWOOLE_SOCK_TCP, + 'callbacks' => [ + SwooleEvent::ON_REQUEST => [\Hyperf\JsonRpc\HttpServer::class, 'onRequest'], + ], + ], ], 'settings' => [ 'enable_coroutine' => true, From 4cdd4c8a510ed3b4f3cba3083b098c25aef786a7 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 21 Aug 2020 10:19:33 +0800 Subject: [PATCH 06/75] =?UTF-8?q?=E9=99=90=E8=B4=AD=E6=8E=A5=E5=8F=A3=20?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=20mock=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/ErrorCode.php | 5 ++++ app/Controller/PurchaseLimitController.php | 29 +++++++++++++++++++ app/Service/PurchaseLimitService.php | 17 +++++++++++ app/Service/PurchaseLimitServiceInterface.php | 10 +++++++ config/autoload/dependencies.php | 2 +- config/routes.php | 3 ++ 6 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 app/Controller/PurchaseLimitController.php create mode 100644 app/Service/PurchaseLimitService.php create mode 100644 app/Service/PurchaseLimitServiceInterface.php diff --git a/app/Constants/ErrorCode.php b/app/Constants/ErrorCode.php index ca97510..205e0b8 100644 --- a/app/Constants/ErrorCode.php +++ b/app/Constants/ErrorCode.php @@ -54,4 +54,9 @@ class ErrorCode extends AbstractConstants */ const PAY_FAILURE = 400; + /** + * @Message("Goods failure!") + */ + const GOODS_FAILURE = 700; + } diff --git a/app/Controller/PurchaseLimitController.php b/app/Controller/PurchaseLimitController.php new file mode 100644 index 0000000..d56ca24 --- /dev/null +++ b/app/Controller/PurchaseLimitController.php @@ -0,0 +1,29 @@ +purchaseLimitService->addShopCar($this->request->all()); + if (!$res) { + return $this->result(ErrorCode::GOODS_FAILURE, '', '商品已超过购买数量'); + } + return $this->success($res); + } + +} diff --git a/app/Service/PurchaseLimitService.php b/app/Service/PurchaseLimitService.php new file mode 100644 index 0000000..c6b1ffe --- /dev/null +++ b/app/Service/PurchaseLimitService.php @@ -0,0 +1,17 @@ + \App\Service\MqttSpeakerService::class, \App\Service\FeiePrintServiceInterface::class => \App\Service\FeiePrintService::class, \App\Service\MiniprogramServiceInterface::class => \App\Service\MiniprogramService::class, - \App\Service\UserServiceInterface::class => \App\Service\UserService::class, + \App\Service\PurchaseLimitServiceInterface::class => \App\Service\PurchaseLimitService::class, ]; diff --git a/config/routes.php b/config/routes.php index b68b0e4..b2093b6 100644 --- a/config/routes.php +++ b/config/routes.php @@ -54,6 +54,9 @@ Router::addGroup('/v1/',function (){ //小程序支付相关 Router::post('wxminipay/online', 'App\Controller\PaymentController@wxminiPayOnline'); Router::post('wxminipay/offline', 'App\Controller\PaymentController@wxminiPayOffline'); + + //加入购物车 + Router::post('PurchaseLimit/addShopCar', 'App\Controller\PurchaseLimitController@addShopCar'); },['middleware' => [\App\Middleware\Auth\ApiMiddleware::class]]); Router::addGroup('/wechat/',function () { From 9b06c4ffa2b4c44998b251f3036b3877bc1306e6 Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 21 Aug 2020 10:28:05 +0800 Subject: [PATCH 07/75] =?UTF-8?q?=E5=8E=BB=E6=8E=89ordernum=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Request/OrderOnlineRequest.php | 1 - app/Service/OrderService.php | 21 +++++++++------------ app/Service/OrderServiceInterface.php | 4 ++-- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/app/Request/OrderOnlineRequest.php b/app/Request/OrderOnlineRequest.php index 019cc99..b02144f 100644 --- a/app/Request/OrderOnlineRequest.php +++ b/app/Request/OrderOnlineRequest.php @@ -20,7 +20,6 @@ class OrderOnlineRequest extends BaseFormRequest public function rules(): array { return [ - 'order_num' => 'nonempty', 'delivery_no' => '', 'dada_fee' => 'nonempty', 'market_id' => 'required|nonempty|integer', diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index 3eab4a9..10a9936 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -40,17 +40,14 @@ class OrderService implements OrderServiceInterface { bcscale(6); - - // 订单判重 $dataMain = $data; - if ($orderMainId = $this->existsByOrderNum($data['order_num'])) { - return $orderMainId; - } - Db::beginTransaction(); try { + // TODO 这个字段后续可能不用了,之前由达达订单号从前端传上来 + $dataMain['order_num'] = 'o'.date('YmdHis').mt_rand(1000,9999); + // 计算当前订单可用红包优惠金额 $couponMoney = 0; $receiveCouponIds = []; @@ -403,7 +400,7 @@ class OrderService implements OrderServiceInterface 'code' => $globalRrderId, 'jj_note' => '', 'uniacid' => 2, - 'order_num' => 'dm'.date('YmdHis', time()) . rand(1111, 9999), + 'order_num' => 'dm'.date('YmdHis') . mt_rand(1000, 9999), 'money' => $data['money'], 'user_id' => $data['user_id'], 'store_ids' => $data['store_id'], @@ -417,7 +414,7 @@ class OrderService implements OrderServiceInterface // 子订单模型保存 $dataChild = [ 'uniacid' => 1, - 'order_num' => 's'.date('YmdHis', time()) . rand(1111, 9999), + 'order_num' => 's'.date('YmdHis') . mt_rand(1000, 9999), 'user_id' => $orderMain->user_id, 'store_id' => $data['store_id'], 'order_main_id' => $orderMainId, @@ -526,11 +523,11 @@ class OrderService implements OrderServiceInterface /** * 订单是否存在 - * @param $orderNum - * @return \Hyperf\Utils\HigherOrderTapProxy|mixed|void|null + * @param $global_order_id + * @return mixed|void|null */ - public function existsByOrderNum($orderNum) + public function existsByGlobalOrderId($global_order_id) { - return OrderMain::query()->where(['order_num' => $orderNum])->value('id'); + return OrderMain::query()->where(['order_num' => $global_order_id])->value('id'); } } \ No newline at end of file diff --git a/app/Service/OrderServiceInterface.php b/app/Service/OrderServiceInterface.php index 0d5e0a2..f059a31 100644 --- a/app/Service/OrderServiceInterface.php +++ b/app/Service/OrderServiceInterface.php @@ -21,9 +21,9 @@ interface OrderServiceInterface /** * 订单是否已经存在 - * @param $orderNum + * @param $global_order_id * @return mixed */ - public function existsByOrderNum($orderNum); + public function existsByGlobalOrderId($global_order_id); } \ No newline at end of file From 9daf4f9c3c227ec53db8340b71924d9b8073a36d Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 21 Aug 2020 10:28:58 +0800 Subject: [PATCH 08/75] Fix --- app/Service/OrderServiceInterface.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Service/OrderServiceInterface.php b/app/Service/OrderServiceInterface.php index f059a31..4fa6657 100644 --- a/app/Service/OrderServiceInterface.php +++ b/app/Service/OrderServiceInterface.php @@ -15,6 +15,7 @@ interface OrderServiceInterface /** * 线下订单下单 * 扫码支付 + * @param $data * @return mixed */ public function addOfflineOrder($data); From 7452ec5167bb87d3bd1b51e1fc0878fbf16b5950 Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 21 Aug 2020 15:52:31 +0800 Subject: [PATCH 09/75] =?UTF-8?q?=E7=A4=BE=E5=8C=BA=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=82=B9=E5=88=86=E8=B4=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/LogLabel.php | 5 +++ app/Controller/NotifyController.php | 33 +++-------------- app/Controller/PaymentController.php | 3 +- app/JsonRpc/OrderService.php | 49 +++++++++++++++++++++---- app/Model/OrderMain.php | 2 + app/Model/ServiceReward.php | 33 +++++++++++++++++ app/Service/FinancialRecordService.php | 6 +-- app/Service/OrderService.php | 48 ++++++++++++++++++++---- app/Service/OrderServiceInterface.php | 6 +++ app/Service/SeparateAccountsService.php | 32 ++++++++++------ 10 files changed, 159 insertions(+), 58 deletions(-) create mode 100644 app/Model/ServiceReward.php diff --git a/app/Constants/LogLabel.php b/app/Constants/LogLabel.php index fe2253c..04b91be 100644 --- a/app/Constants/LogLabel.php +++ b/app/Constants/LogLabel.php @@ -38,4 +38,9 @@ class LogLabel extends AbstractConstants * @Message("Separate Accounts Log Label") */ const SEPARATE_ACCOUNTS_LOG = 'separate_accounts_log'; + + /** + * @Message("Online Order Complete Log Label") + */ + const ONLINE_COMPLETE_LOG = 'online_complete_log'; } diff --git a/app/Controller/NotifyController.php b/app/Controller/NotifyController.php index 2a8b094..8376952 100644 --- a/app/Controller/NotifyController.php +++ b/app/Controller/NotifyController.php @@ -187,27 +187,14 @@ class NotifyController extends BaseController // 喇叭通知,兼容旧音响,MQTT+IOT $res = $this->mqttSpeakerService->speakToStore($orderMain->id); - $this->log->event( - LogLabel::PAY_NOTIFY_WXMINI, - ['fail_mqtt' => json_encode($res)] - ); $res = $this->deviceService->pubMsgToStoreByOrderMainId($orderMain->id); - $this->log->event( - LogLabel::PAY_NOTIFY_WXMINI, - ['fail_device' => json_encode($res)] - ); + // 公众号模板消息 $res = $this->miniprogramService->sendTemMsgForOnlineOrder($orderMain->id); - $this->log->event( - LogLabel::PAY_NOTIFY_WXMINI, - ['fail_mini' => json_encode($res)] - ); + // 打印订单,自动打印 TODO 后续优化调用逻辑 $res = $this->feiePrintService->feiePrint($orderMain->global_order_id); - $this->log->event( - LogLabel::PAY_NOTIFY_WXMINI, - ['fail_feie' => json_encode($res)] - ); + Db::commit(); return true; @@ -375,21 +362,11 @@ class NotifyController extends BaseController // 喇叭通知,兼容旧音响,MQTT+IOT $res = $this->mqttSpeakerService->speakToStore($orderMain->id); - $this->log->event( - LogLabel::PAY_NOTIFY_WXMINI, - ['fail_mqtt' => json_encode($res)] - ); $res = $this->deviceService->pubMsgToStoreByOrderMainId($orderMain->id); - $this->log->event( - LogLabel::PAY_NOTIFY_WXMINI, - ['fail_device' => json_encode($res)] - ); + // 公众号模板消息 $res = $this->miniprogramService->sendTemMsgForOfflineOrder($orderMain->id); - $this->log->event( - LogLabel::PAY_NOTIFY_WXMINI, - ['fail_mini' => json_encode($res)] - ); + Db::commit(); return true; diff --git a/app/Controller/PaymentController.php b/app/Controller/PaymentController.php index b2c6fba..9fc92ae 100644 --- a/app/Controller/PaymentController.php +++ b/app/Controller/PaymentController.php @@ -33,7 +33,8 @@ class PaymentController extends BaseController $result = $app->order->unify([ 'body' => '懒族生活 - 外卖下单', 'out_trade_no' => $orderMain->global_order_id, - 'total_fee' => bcmul(floatval($orderMain->money), 100, 0), + // 'total_fee' => bcmul(floatval($orderMain->money), 100, 0), + 'total_fee' => 1, 'notify_url' => config('site_host') . '/wechat/notify/wxminionline', 'trade_type' => 'JSAPI', 'openid' => $data['openid'], diff --git a/app/JsonRpc/OrderService.php b/app/JsonRpc/OrderService.php index 6c25b92..10cf513 100644 --- a/app/JsonRpc/OrderService.php +++ b/app/JsonRpc/OrderService.php @@ -2,10 +2,13 @@ namespace App\JsonRpc; +use App\Commons\Log; use App\Constants\ErrorCode; use App\Service\SeparateAccountsServiceInterface; +use Hyperf\DbConnection\Db; use Hyperf\RpcServer\Annotation\RpcService; use Hyperf\Di\Annotation\Inject; +use App\Constants\LogLabel; /** * @RpcService(name="OrderService", protocol="jsonrpc-http", server="jsonrpc-http", publishTo="") @@ -13,21 +16,51 @@ use Hyperf\Di\Annotation\Inject; class OrderService implements OrderServiceInterface { + /** + * @Inject + * @var Log + */ + protected $log; + + /** + * @Inject + * @var \App\Service\OrderServiceInterface + */ + protected $orderService; + /** * @Inject * @var SeparateAccountsServiceInterface */ - protected $separateAccService; + protected $separateAccountsService; public function onlineComplete($global_order_id) { - $data = $this->separateAccService->orderOnlineCompleted($global_order_id); - return [ - "status" => 200, - "code" => $data ? 0 : ErrorCode::SEPARATE_ACCOUNTS_ERROR, - "result" => [], - "message" => $data ? '调用成功' : ErrorCode::getMessage(ErrorCode::SEPARATE_ACCOUNTS_ERROR) - ]; + Db::beginTransaction(); + try { + + $this->orderService->onlineCompleted($global_order_id); + $this->separateAccountsService->orderOnlineCompleted($global_order_id); + + Db::commit(); + return [ + "status" => 200, + "code" => 0, + "result" => [], + "message" => '调用成功' + ]; + } catch (\Exception $e) { + + Db::rollBack(); + $this->log->event(LogLabel::ONLINE_COMPLETE_LOG, ['exception' => $e->getMessage()]); + return [ + "status" => 200, + "code" =>ErrorCode::SEPARATE_ACCOUNTS_ERROR, + "result" => [], + "message" => ErrorCode::getMessage(ErrorCode::SEPARATE_ACCOUNTS_ERROR) + ]; + } + } } \ No newline at end of file diff --git a/app/Model/OrderMain.php b/app/Model/OrderMain.php index 92213ad..dfb6d0d 100644 --- a/app/Model/OrderMain.php +++ b/app/Model/OrderMain.php @@ -32,6 +32,8 @@ class OrderMain extends Model const ORDER_STATE_REFUNDED = 9; // 拒绝退款 const ORDER_STATE_UNREFUND = 10; + // 完成状态组合 + const ORDER_STATE_FINISH = [self::ORDER_STATE_COMPLETE, self::ORDER_STATE_EVALUATED, self::ORDER_STATE_UNREFUND]; // 订单支付方式 // 微信支付 diff --git a/app/Model/ServiceReward.php b/app/Model/ServiceReward.php new file mode 100644 index 0000000..583ad0a --- /dev/null +++ b/app/Model/ServiceReward.php @@ -0,0 +1,33 @@ + 'array' + ]; +} \ No newline at end of file diff --git a/app/Service/FinancialRecordService.php b/app/Service/FinancialRecordService.php index 061e297..34680b3 100644 --- a/app/Service/FinancialRecordService.php +++ b/app/Service/FinancialRecordService.php @@ -10,7 +10,7 @@ class FinancialRecordService implements FinancialRecordServiceInterface /** * @inheritDoc */ - public function communityAwardByPlatNewUser($user_id, $source_id, $money, $user_type=2, $source_type=1, $money_type=1, $desc='新用户奖励', $comment='') + public function communityAwardByPlatNewUser($user_id, $source_id, $money, $user_type=2, $source_type=1, $money_type=1, $desc='新用户奖励', $comment='社区服务点') { $this->record( $user_id, @@ -33,7 +33,7 @@ class FinancialRecordService implements FinancialRecordServiceInterface /** * @inheritDoc */ - public function communityAwardByPlatNewUserFirstOLOrder($user_id, $source_id, $money, $user_type=2, $source_type=1, $money_type=1, $desc='新用户首单奖励', $comment='') + public function communityAwardByPlatNewUserFirstOLOrder($user_id, $source_id, $money, $user_type=2, $source_type=1, $money_type=1, $desc='新用户首单奖励', $comment='社区服务点') { $this->record( $user_id, @@ -56,7 +56,7 @@ class FinancialRecordService implements FinancialRecordServiceInterface /** * @inheritDoc */ - public function communitySeparateAccountsByOrderComp($user_id, $source_id, $money, $user_type=2, $source_type=1, $money_type=2, $desc='用户订单分成', $comment='') + public function communitySeparateAccountsByOrderComp($user_id, $source_id, $money, $user_type=2, $source_type=1, $money_type=2, $desc='用户订单分成', $comment='社区服务点') { $this->record( $user_id, diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index 10a9936..7aa31e1 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -12,7 +12,6 @@ use App\Model\Order; use App\Model\OrderGoods; use App\Model\OrderMain; use App\Model\SpecCombination; -use App\Model\Users; use Exception; use Hyperf\DbConnection\Db; use Hyperf\Snowflake\IdGeneratorInterface; @@ -89,10 +88,11 @@ class OrderService implements OrderServiceInterface // 统计订单中所有店铺当日订单数,做店铺订单序号 $countsArr = Order::query() - ->selectRaw('id, COUNT(*) AS count') + ->selectRaw('store_id, COUNT(*) AS count') ->whereIn('store_id', explode(',', $dataMain['store_ids'])) ->where(['type' => OrderMain::ORDER_TYPE_ONLINE]) ->whereBetween('time', [date('Y-m-d 00:00:00'), date('Y-m-d 23:59:59')]) + ->groupBy('store_id') ->get() ->toArray(); @@ -462,14 +462,13 @@ class OrderService implements OrderServiceInterface } } - - /** * 计算和校验当前订单可用红包及金额 * @param $couponIds * @param $orderAmount * @param $userId * @param $marketId + * @return int|string * @throws Exception */ protected function getCouponAmount($couponIds, $orderAmount, $userId, $marketId) @@ -522,12 +521,47 @@ class OrderService implements OrderServiceInterface } /** - * 订单是否存在 - * @param $global_order_id - * @return mixed|void|null + * @inheritDoc */ public function existsByGlobalOrderId($global_order_id) { return OrderMain::query()->where(['order_num' => $global_order_id])->value('id'); } + + /** + * @inheritDoc + */ + public function onlineCompleted($global_order_id) + { + Db::beginTransaction(); + try { + + // 主订单状态更新 + $orderMain = OrderMain::query() + ->where(['global_order_id' => $global_order_id, 'state' => OrderMain::ORDER_STATE_DELIVERY]) + ->first(); + + if (empty($orderMain)) { + Db::rollBack(); + return false; + } + + $orderMain->state = OrderMain::ORDER_STATE_COMPLETE; + $orderMain->save(); + + // 子订单状态更新 + $upChild = Order::query() + ->where(['order_main_id' => $orderMain->id]) + ->update(['state' => OrderMain::ORDER_STATE_COMPLETE]); + + Db::commit(); + return true; + } catch (Exception $e) { + + $this->log->event(LogLabel::ONLINE_COMPLETE_LOG, ['exception' => $e->getMessage()]); + Db::rollBack(); + return false; + } + + } } \ No newline at end of file diff --git a/app/Service/OrderServiceInterface.php b/app/Service/OrderServiceInterface.php index 4fa6657..92fa986 100644 --- a/app/Service/OrderServiceInterface.php +++ b/app/Service/OrderServiceInterface.php @@ -27,4 +27,10 @@ interface OrderServiceInterface */ public function existsByGlobalOrderId($global_order_id); + /** + * @param $global_order_id + * @return mixed + */ + public function onlineCompleted($global_order_id); + } \ No newline at end of file diff --git a/app/Service/SeparateAccountsService.php b/app/Service/SeparateAccountsService.php index 57852a8..4958584 100644 --- a/app/Service/SeparateAccountsService.php +++ b/app/Service/SeparateAccountsService.php @@ -5,6 +5,7 @@ namespace App\Service; use App\Commons\Log; use App\Constants\LogLabel; use App\Model\OrderMain; +use App\Model\ServiceReward; use App\Model\UserRelationBind; use Hyperf\DbConnection\Db; use Hyperf\Di\Annotation\Inject; @@ -62,23 +63,32 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface // 奖励规则B:用户是非新用户,奖励社区服务点订单实际支付金额z%的分成 // =======社区服务点分账 / Start======= - // 奖励/分账金额 TODO 届时查询出来一个配置 - $award = ['new_user' => 1, 'first_order' => 2, 'separate_rate' => 2]; - // 当前用户的社区服务点绑定关系 $communityBind = UserRelationBind::query() ->where(['bind_type' => UserRelationBind::BIND_TYPE_COMMUNITY, 'user_id' => $orderMain->user_id]) ->first(); - // 平台新用户 - if ($this->userService->isPlatformNewUser($orderMain->user_id, $orderMain->id)) { - $this->financialRecordService->communityAwardByPlatNewUser($communityBind->source_id, $orderMain->global_order_id, $award['new_user']); - $this->financialRecordService->communityAwardByPlatNewUserFirstOLOrder($communityBind->source_id, $orderMain->global_order_id, $award['first_order']); - } + if ($communityBind) { + + // 奖励/分账金额 + $award = ServiceReward::query()->where(['type' => ServiceReward::TYPE_COMMUNITY])->first(); + if (empty($award)) { + Db::rollBack(); + return false; + } - // 账单分成 - $money = bcmul($orderMain->money, bcdiv($award['separate_rate'], 100, 6), 2); - $this->financialRecordService->communitySeparateAccountsByOrderComp($communityBind->source_id, $orderMain->global_order_id, $money); + $award = $award->set_reward; + + // 平台新用户 + if ($this->userService->isPlatformNewUser($orderMain->user_id, $orderMain->id)) { + $this->financialRecordService->communityAwardByPlatNewUser($communityBind->source_id, $orderMain->global_order_id, $award['new_user_reward']); + $this->financialRecordService->communityAwardByPlatNewUserFirstOLOrder($communityBind->source_id, $orderMain->global_order_id, $award['first_reward']); + } + + // 账单分成 + $money = bcmul($orderMain->money, $award['flow_reward']); + $this->financialRecordService->communitySeparateAccountsByOrderComp($communityBind->source_id, $orderMain->global_order_id, $money); + } // =======社区服务点分账 / End======= From 0b99ced546ed6cab395918825f3b1221e8c2922a Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 21 Aug 2020 17:24:28 +0800 Subject: [PATCH 10/75] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=B4=AD=E7=89=A9?= =?UTF-8?q?=E8=BD=A6=E6=8E=A5=E5=8F=A3=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/PurchaseLimitController.php | 9 +++++++++ app/Service/PurchaseLimitService.php | 11 ++++++++++- app/Service/PurchaseLimitServiceInterface.php | 2 ++ config/routes.php | 1 + 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/Controller/PurchaseLimitController.php b/app/Controller/PurchaseLimitController.php index d56ca24..3f9abf7 100644 --- a/app/Controller/PurchaseLimitController.php +++ b/app/Controller/PurchaseLimitController.php @@ -26,4 +26,13 @@ class PurchaseLimitController extends BaseController return $this->success($res); } + public function updateShopCar() + { + $res = $this->purchaseLimitService->updateShopCar($this->request->all()); + if (!$res) { + return $this->result(ErrorCode::GOODS_FAILURE, '', '更新购物车失败'); + } + return $this->success($res); + } + } diff --git a/app/Service/PurchaseLimitService.php b/app/Service/PurchaseLimitService.php index c6b1ffe..88b3795 100644 --- a/app/Service/PurchaseLimitService.php +++ b/app/Service/PurchaseLimitService.php @@ -8,10 +8,19 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface { public function addShopCar($params) { - if($params['goods_id'] == 1561){ + if($params['good_id'] == 1561){ return false; }else{ return '加入购物车成功'; } } + + public function updateShopCar($params) + { + if($params['good_id'] == 1561){ + return false; + }else{ + return '更新购物车成功'; + } + } } \ No newline at end of file diff --git a/app/Service/PurchaseLimitServiceInterface.php b/app/Service/PurchaseLimitServiceInterface.php index 03e6f08..79f3df3 100644 --- a/app/Service/PurchaseLimitServiceInterface.php +++ b/app/Service/PurchaseLimitServiceInterface.php @@ -7,4 +7,6 @@ namespace App\Service; interface PurchaseLimitServiceInterface { public function addShopCar($params); + + public function updateShopCar($params); } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index b2093b6..28f4299 100644 --- a/config/routes.php +++ b/config/routes.php @@ -57,6 +57,7 @@ Router::addGroup('/v1/',function (){ //加入购物车 Router::post('PurchaseLimit/addShopCar', 'App\Controller\PurchaseLimitController@addShopCar'); + Router::post('PurchaseLimit/updateShopCar', 'App\Controller\PurchaseLimitController@updateShopCar'); },['middleware' => [\App\Middleware\Auth\ApiMiddleware::class]]); Router::addGroup('/wechat/',function () { From e91ba2239be2d136331b5eba5ed5233510847131 Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 21 Aug 2020 19:02:02 +0800 Subject: [PATCH 11/75] =?UTF-8?q?=E4=B8=8B=E5=8D=95=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E5=92=8C=E5=88=86=E8=B4=A6=EF=BC=9A=E7=94=A8=E6=88=B7=E3=80=81?= =?UTF-8?q?=E5=95=86=E6=88=B7=E3=80=81=E5=95=86=E6=88=B7=E5=A5=96=E5=8A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/LogLabel.php | 11 + app/Controller/NotifyController.php | 316 ++++++++++-------- app/Model/FinancialRecord.php | 11 +- app/Model/UserBalance.php | 33 ++ app/Service/FinancialRecordService.php | 186 +++++++---- .../FinancialRecordServiceInterface.php | 88 ++++- app/Service/OrderService.php | 136 ++++++++ app/Service/OrderServiceInterface.php | 15 + app/Service/SeparateAccountsService.php | 184 +++++++++- 9 files changed, 762 insertions(+), 218 deletions(-) create mode 100644 app/Model/UserBalance.php diff --git a/app/Constants/LogLabel.php b/app/Constants/LogLabel.php index 04b91be..d4b9f72 100644 --- a/app/Constants/LogLabel.php +++ b/app/Constants/LogLabel.php @@ -43,4 +43,15 @@ class LogLabel extends AbstractConstants * @Message("Online Order Complete Log Label") */ const ONLINE_COMPLETE_LOG = 'online_complete_log'; + + /** + * @Message("Online Paid Complete Log Label") + */ + const ONLINE_PAID_LOG = 'online_paid_log'; + + /** + * @Message("Offline Paid Complete Log Label") + */ + const OFFLINE_PAID_LOG = 'offline_paid_log'; + } diff --git a/app/Controller/NotifyController.php b/app/Controller/NotifyController.php index 8376952..1ddfb11 100644 --- a/app/Controller/NotifyController.php +++ b/app/Controller/NotifyController.php @@ -18,6 +18,8 @@ use App\Service\DeviceServiceInterface; use App\Service\FeiePrintServiceInterface; use App\Service\MiniprogramServiceInterface; use App\Service\MqttServiceInterface; +use App\Service\OrderServiceInterface; +use App\Service\SeparateAccountsServiceInterface; use App\Service\UserServiceInterface; use EasyWeChat\Factory; use Hyperf\DbConnection\Db; @@ -68,6 +70,18 @@ class NotifyController extends BaseController */ protected $couponRebateService; + /** + * @Inject + * @var OrderServiceInterface + */ + protected $orderService; + + /** + * @Inject + * @var SeparateAccountsServiceInterface + */ + protected $separateAccountsService; + public function wxminiOnline() { @@ -122,65 +136,68 @@ class NotifyController extends BaseController return true; } - // 修改订单、子订单状态 - $currentTime = time(); - $orderMain->state = OrderMain::ORDER_STATE_UNTAKE; - $orderMain->time_pay = $currentTime; - $orderMain->pay_time = date('Y-m-d H:i:s', $currentTime); - $orderMain->save(); - - $upOrder = Order::query() - ->where(['order_main_id' => $orderMain->id]) - ->update(['state' => OrderMain::ORDER_STATE_UNTAKE, 'pay_time' => $orderMain->pay_time]); - - // 更新商户销量 - $upStoreScore = Store::query() - ->whereIn('id', explode(',', $orderMain->store_ids)) - ->update(['score' => Db::raw('score+1')]); - - // 更新商品库存和销量 - $orders = Order::query()->select(['id', 'money', 'user_id', 'store_id', 'pay_time']) - ->where(['order_main_id' => $orderMain->id]) - ->get() - ->toArray(); - $orderGoods = OrderGoods::query()->select(['good_id AS id', 'number', 'combination_id']) - ->whereIn('order_id', array_values(array_column($orders, 'id'))) - ->get() - ->toArray(); - foreach ($orderGoods as $key => &$goodsItem) { - - $goods = Goods::find($goodsItem['id']); - - // 库存处理,有规格 - if ($goodsItem['combination_id']) { - $combination = SpecCombination::find($goodsItem['combination_id']); - $combination->number = $combination->number - $goodsItem['number']; - $combination->save(); - } else { - $goods->inventory = $goods->inventory - $goodsItem['number']; - } - - $goods->sales = $goods->sales - $goodsItem['number']; - $goods->save(); - - } - - // 月销流水 - $statistics = []; - foreach ($orders as $key => &$order) { - $statistics[] = [ - 'money' => $order['money'], - 'user_id' => $order['user_id'], - 'store_id' => $order['store_id'], - 'market_id' => $orderMain->market_id, - 'order_id' => $order['id'], - 'createtime' => strtotime($order['pay_time']), - ]; - } - - if (is_array($statistics) && !empty($statistics)) { - $inSalesStatistics = OrderSalesStatistic::query()->insert($statistics); - } + $this->orderService->onlinePaid($message['out_trade_no']); + $this->separateAccountsService->orderOnlinePaid($message['out_trade_no']); + + // // 修改订单、子订单状态 + // $currentTime = time(); + // $orderMain->state = OrderMain::ORDER_STATE_UNTAKE; + // $orderMain->time_pay = $currentTime; + // $orderMain->pay_time = date('Y-m-d H:i:s', $currentTime); + // $orderMain->save(); + // + // $upOrder = Order::query() + // ->where(['order_main_id' => $orderMain->id]) + // ->update(['state' => OrderMain::ORDER_STATE_UNTAKE, 'pay_time' => $orderMain->pay_time]); + // + // // 更新商户销量 + // $upStoreScore = Store::query() + // ->whereIn('id', explode(',', $orderMain->store_ids)) + // ->update(['score' => Db::raw('score+1')]); + // + // // 更新商品库存和销量 + // $orders = Order::query()->select(['id', 'money', 'user_id', 'store_id', 'pay_time']) + // ->where(['order_main_id' => $orderMain->id]) + // ->get() + // ->toArray(); + // $orderGoods = OrderGoods::query()->select(['good_id AS id', 'number', 'combination_id']) + // ->whereIn('order_id', array_values(array_column($orders, 'id'))) + // ->get() + // ->toArray(); + // foreach ($orderGoods as $key => &$goodsItem) { + // + // $goods = Goods::find($goodsItem['id']); + // + // // 库存处理,有规格 + // if ($goodsItem['combination_id']) { + // $combination = SpecCombination::find($goodsItem['combination_id']); + // $combination->number = $combination->number - $goodsItem['number']; + // $combination->save(); + // } else { + // $goods->inventory = $goods->inventory - $goodsItem['number']; + // } + // + // $goods->sales = $goods->sales - $goodsItem['number']; + // $goods->save(); + // + // } + // + // // 月销流水 + // $statistics = []; + // foreach ($orders as $key => &$order) { + // $statistics[] = [ + // 'money' => $order['money'], + // 'user_id' => $order['user_id'], + // 'store_id' => $order['store_id'], + // 'market_id' => $orderMain->market_id, + // 'order_id' => $order['id'], + // 'createtime' => strtotime($order['pay_time']), + // ]; + // } + // + // if (is_array($statistics) && !empty($statistics)) { + // $inSalesStatistics = OrderSalesStatistic::query()->insert($statistics); + // } // 优惠券返券 $this->couponRebateService->couponRebateInTask($orderMain->id); @@ -192,7 +209,7 @@ class NotifyController extends BaseController // 公众号模板消息 $res = $this->miniprogramService->sendTemMsgForOnlineOrder($orderMain->id); - // 打印订单,自动打印 TODO 后续优化调用逻辑 + // 打印订单,自动打印 $res = $this->feiePrintService->feiePrint($orderMain->global_order_id); Db::commit(); @@ -271,94 +288,97 @@ class NotifyController extends BaseController return true; } - // 修改订单、子订单状态 - $currentTime = time(); - $orderMain->state = OrderMain::ORDER_STATE_UNTAKE; - $orderMain->dm_state = OrderMain::ORDER_STATE_UNTAKE; - $orderMain->time_pay = $currentTime; - $orderMain->pay_time = date('Y-m-d H:i:s', $currentTime); - $orderMain->save(); - - $upOrder = Order::query() - ->where(['order_main_id' => $orderMain->id]) - ->update([ - 'state' => OrderMain::ORDER_STATE_UNTAKE, - 'dm_state' => OrderMain::ORDER_STATE_UNTAKE, - 'pay_time' => date('Y-m-d H:i:s', $currentTime) - ]); - - // 查询子订单,当面付目前实际上只有一个子订单 - $orders = Order::query()->select(['id', 'money', 'user_id', 'store_id', 'pay_time']) - ->where(['order_main_id' => $orderMain->id]) - ->get() - ->toArray(); - - // 商户钱包、流水资金、奖励、发布模板消息处理 - foreach ($orders as $key => $orderItem) { - - $recordBase = [ - 'user_id' => $orderItem['user_id'], - 'order_id' => $orderItem['id'], - 'store_id' => $orderItem['store_id'], - 'type' => 1, - 'time' => date('Y-m-d H:i:s', $currentTime), - 'add_time' => $currentTime, - ]; - - // 钱包 - $store = Store::find($orderItem['store_id']); - $store->store_wallet = bcadd($store->store_wallet, $orderItem['money'], 2); - $store->save(); - - // 流水 - $record = [ - 'money' => $orderItem['money'], - 'note' => '当面付订单收入', - 'category' => 2, - ]; - StoreAccount::query()->insert(array_merge($recordBase, $record)); - - // 平台新用户奖励给商户 - $isStageNewUser = $this->userService->isPlatformNewUser($orderItem['user_id'], $orderMain->id); - $needAward = false; - $awardAmount = 0; - if ($isStageNewUser) { - $awardAmount = SystemConfig::query()->where(['type' => 1, 'menu_name' => 'award_new_user'])->value('value'); - // 流水 - $record = [ - 'money' => $awardAmount, - 'note' => '新用户下单成功,平台奖励', - 'category' => 3, - ]; - $needAward = true; - } else { - $isStoreFirstOrderToday = $this->userService->isStoreFirstOrderToday($orderItem['user_id'],$orderItem['store_id'],$orderItem['id'], self::AWARD_LIMIT_AMOUNT); - if ($isStoreFirstOrderToday && $orderItem['money'] >= self::AWARD_LIMIT_AMOUNT) { - $awardAmount = SystemConfig::query()->where(['type' => 1, 'menu_name' => 'award_each_order'])->value('value'); - // 流水 - $record = [ - 'money' => $awardAmount, - 'note' => '用户下单成功,平台奖励', - 'category' => 4, - ]; - $needAward = true; - } - } - - if ($needAward && $awardAmount) { - // 奖励钱包 - $store->refresh(); - $store->award_money = bcadd($store->award_money, $awardAmount, 2); - $store->save(); - - // 流水 - StoreAccount::query()->insert(array_merge($recordBase, $record)); - - // 发布公众号消息 - $openid = Users::query()->where(['id' => $store['user_id']])->value('openid'); - $res = $this->miniprogramService->sendTemMsgForAward($record['money'], $record['note'], $openid, $recordBase['time']); - } - } + $orderPaid = $this->orderService->offlinePaid($message['out_trade_no']); + $separate = $this->separateAccountsService->orderOfflinePaid($message['out_trade_no']); + + // // 修改订单、子订单状态 + // $currentTime = time(); + // $orderMain->state = OrderMain::ORDER_STATE_UNTAKE; + // $orderMain->dm_state = OrderMain::ORDER_STATE_UNTAKE; + // $orderMain->time_pay = $currentTime; + // $orderMain->pay_time = date('Y-m-d H:i:s', $currentTime); + // $orderMain->save(); + // + // $upOrder = Order::query() + // ->where(['order_main_id' => $orderMain->id]) + // ->update([ + // 'state' => OrderMain::ORDER_STATE_UNTAKE, + // 'dm_state' => OrderMain::ORDER_STATE_UNTAKE, + // 'pay_time' => date('Y-m-d H:i:s', $currentTime) + // ]); + + // // 查询子订单,当面付目前实际上只有一个子订单 + // $orders = Order::query()->select(['id', 'money', 'user_id', 'store_id', 'pay_time']) + // ->where(['order_main_id' => $orderMain->id]) + // ->get() + // ->toArray(); + // + // // 商户钱包、流水资金、奖励、发布模板消息处理 + // foreach ($orders as $key => $orderItem) { + // + // $recordBase = [ + // 'user_id' => $orderItem['user_id'], + // 'order_id' => $orderItem['id'], + // 'store_id' => $orderItem['store_id'], + // 'type' => 1, + // 'time' => date('Y-m-d H:i:s', $currentTime), + // 'add_time' => $currentTime, + // ]; + // + // // 钱包 + // $store = Store::find($orderItem['store_id']); + // $store->store_wallet = bcadd($store->store_wallet, $orderItem['money'], 2); + // $store->save(); + // + // // 流水 + // $record = [ + // 'money' => $orderItem['money'], + // 'note' => '当面付订单收入', + // 'category' => 2, + // ]; + // StoreAccount::query()->insert(array_merge($recordBase, $record)); + // + // // 平台新用户奖励给商户 + // $isStageNewUser = $this->userService->isPlatformNewUser($orderItem['user_id'], $orderMain->id); + // $needAward = false; + // $awardAmount = 0; + // if ($isStageNewUser) { + // $awardAmount = SystemConfig::query()->where(['type' => 1, 'menu_name' => 'award_new_user'])->value('value'); + // // 流水 + // $record = [ + // 'money' => $awardAmount, + // 'note' => '新用户下单成功,平台奖励', + // 'category' => 3, + // ]; + // $needAward = true; + // } else { + // $isStoreFirstOrderToday = $this->userService->isStoreFirstOrderToday($orderItem['user_id'],$orderItem['store_id'],$orderItem['id'], self::AWARD_LIMIT_AMOUNT); + // if ($isStoreFirstOrderToday && $orderItem['money'] >= self::AWARD_LIMIT_AMOUNT) { + // $awardAmount = SystemConfig::query()->where(['type' => 1, 'menu_name' => 'award_each_order'])->value('value'); + // // 流水 + // $record = [ + // 'money' => $awardAmount, + // 'note' => '用户下单成功,平台奖励', + // 'category' => 4, + // ]; + // $needAward = true; + // } + // } + // + // if ($needAward && $awardAmount) { + // // 奖励钱包 + // $store->refresh(); + // $store->award_money = bcadd($store->award_money, $awardAmount, 2); + // $store->save(); + // + // // 流水 + // StoreAccount::query()->insert(array_merge($recordBase, $record)); + // + // // 发布公众号消息 + // $openid = Users::query()->where(['id' => $store['user_id']])->value('openid'); + // $res = $this->miniprogramService->sendTemMsgForAward($record['money'], $record['note'], $openid, $recordBase['time']); + // } + // } // 喇叭通知,兼容旧音响,MQTT+IOT $res = $this->mqttSpeakerService->speakToStore($orderMain->id); diff --git a/app/Model/FinancialRecord.php b/app/Model/FinancialRecord.php index d7343d2..0096c9a 100644 --- a/app/Model/FinancialRecord.php +++ b/app/Model/FinancialRecord.php @@ -7,6 +7,11 @@ namespace App\Model; */ class FinancialRecord extends Model { + /** + * 当面付商户首单奖励限制的订单金额 + */ + const OFL_FIRST_AWARD_LIMIT_AMOUNT = 3; + /** * 虚拟账户 */ @@ -50,7 +55,11 @@ class FinancialRecord extends Model */ const MONEY_TYPE_PLAT_NEW_USER = 1; const MONEY_TYPE_FIRST_ORDER = 2; - const MONEY_TYPE_OL_ORDER = 51; + const MONEY_TYPE_OL_ORDER = 3; + const MONEY_TYPE_STORE_PLAT_NEW_USER = 4; + const MONEY_TYPE_STORE_FIRST_ORDER = 5; + const MONEY_TYPE_USER_OFL_ORDER = 100; + const MONEY_TYPE_USER_OL_ORDER = 101; /** * 状态 diff --git a/app/Model/UserBalance.php b/app/Model/UserBalance.php new file mode 100644 index 0000000..62f988e --- /dev/null +++ b/app/Model/UserBalance.php @@ -0,0 +1,33 @@ +record( - $user_id, + return $this->record( + FinancialRecord::ACCOUNT_LEDGER, [ - 'user_id' => $user_id, - 'user_type' => $user_type, + 'user_id' => FinancialRecord::ACCOUNT_LEDGER, + 'user_type' => FinancialRecord::USER_TYPE_LEDGER, 'money' => $money, 'money_type' => $money_type, 'source_id' => $source_id, @@ -24,40 +25,107 @@ class FinancialRecordService implements FinancialRecordServiceInterface 'desc' => $desc, 'comment' => $comment, 'status' => FinancialRecord::STATUS_NORMAL, - ] + ], + true ); + } + + public function record($user_id, $record, $isLedger=false) + { + $financialRecord = new FinancialRecord(); + + if (!$isLedger) { + $mod = bcmod((string)$user_id, '5', 0); + $financialRecord->suffix($mod); + } + + return $financialRecord->fill( + [ + 'user_id' => $user_id, + 'user_type' => $record['user_type'], + 'money' => $record['money'], + 'money_type' => $record['money_type'], + 'source_id' => $record['source_id'], + 'source_type' => $record['source_type'], + 'desc' => $record['desc'], + 'comment' => $record['comment'], + 'status' => $record['status'], + ] + )->save(); - $this->ledgerAccounts($source_id, $money, $source_type, $money_type, $desc, $comment); } /** * @inheritDoc */ - public function communityAwardByPlatNewUserFirstOLOrder($user_id, $source_id, $money, $user_type=2, $source_type=1, $money_type=1, $desc='新用户首单奖励', $comment='社区服务点') + public function communityAwardByPlatNewUser($user_id, $source_id, $money, $user_type=2, $source_type=1, $money_type=1, $desc='新用户奖励', $comment='社区服务点') { - $this->record( - $user_id, - [ - 'user_id' => $user_id, - 'user_type' => $user_type, - 'money' => $money, - 'money_type' => $money_type, - 'source_id' => $source_id, - 'source_type' => $source_type, - 'desc' => $desc, - 'comment' => $comment, - 'status' => FinancialRecord::STATUS_NORMAL, - ] - ); + $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); + // 维护社区服务点余额 + $balance = UserBalance::firstOrNew([ + 'user_type' => UserBalance::USER_TYPE_CS, + 'source_id' => $source_id + ]); + $balance->balance = bcadd($balance->balance, $money); + $balance->save(); + } - $this->ledgerAccounts($source_id, $money, $source_type, $money_type, $desc, $comment); + /** + * @inheritDoc + */ + public function communityAwardByPlatNewUserFirstOLOrder($user_id, $source_id, $money, $user_type=2, $source_type=1, $money_type=2, $desc='新用户首单奖励', $comment='社区服务点') + { + $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); + // 维护社区服务点余额 + $balance = UserBalance::firstOrNew([ + 'user_type' => UserBalance::USER_TYPE_CS, + 'source_id' => $source_id + ]); + $balance->balance = bcadd($balance->balance, $money); + $balance->save(); + } + + /** + * @inheritDoc + */ + public function communitySeparateAccountsByOrderComp($user_id, $source_id, $money, $user_type=2, $source_type=1, $money_type=3, $desc='用户订单分成', $comment='社区服务点') + { + $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); + // 维护社区服务点余额 + $balance = UserBalance::firstOrNew([ + 'user_type' => UserBalance::USER_TYPE_CS, + 'source_id' => $source_id + ]); + $balance->balance = bcadd($balance->balance, $money); + $balance->save(); } + /** * @inheritDoc */ - public function communitySeparateAccountsByOrderComp($user_id, $source_id, $money, $user_type=2, $source_type=1, $money_type=2, $desc='用户订单分成', $comment='社区服务点') + public function storeAwardByPlatNewUserOFLOrder($user_id, $source_id, $money, $user_type=1, $source_type=1, $money_type=4, $desc='新用户下单奖励', $comment='用户当面付商户奖励') { + $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); + // 同时维护钱包 + $store = Store::query()->where(['user_id' => $user_id])->first(); + $store->award_money = bcadd($store->award_money, $money, 2); + $store->save(); + } + + /** + * @inheritDoc + */ + public function storeAwardByTodayFirstOFLOrder($user_id, $source_id, $money, $user_type=1, $source_type=1, $money_type=5, $desc='用户店铺首单奖励', $comment='用户当面付商户奖励') + { + $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); + // 同时维护钱包 + $store = Store::query()->where(['user_id' => $user_id])->first(); + $store->award_money = bcadd($store->award_money, $money, 2); + $store->save(); + } + + public function recordAll($user_id, $source_id, $money, $user_type=1, $source_type=0, $money_type=0, $desc='', $comment='') { $this->record( $user_id, [ @@ -76,47 +144,39 @@ class FinancialRecordService implements FinancialRecordServiceInterface $this->ledgerAccounts($source_id, $money, $source_type, $money_type, $desc, $comment); } - public function ledgerAccounts($source_id, $money, $source_type, $money_type, $desc, $comment='') + /** + * @inheritDoc + */ + public function userByOFLOrderPaid($user_id, $source_id, $money, $user_type=1, $source_type=1, $money_type=100, $desc='用户下单(线下)', $comment='用户下单') { - return $this->record( - FinancialRecord::ACCOUNT_LEDGER, - [ - 'user_id' => FinancialRecord::ACCOUNT_LEDGER, - 'user_type' => FinancialRecord::USER_TYPE_LEDGER, - 'money' => $money, - 'money_type' => $money_type, - 'source_id' => $source_id, - 'source_type' => $source_type, - 'desc' => $desc, - 'comment' => $comment, - 'status' => FinancialRecord::STATUS_NORMAL, - ], - true - ); + $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); } - public function record($user_id, $record, $isLedger=false) + /** + * @inheritDoc + */ + public function userByOLOrderPaid($user_id, $source_id, $money, $user_type=1, $source_type=1, $money_type=101, $desc='用户下单(线上)', $comment='用户下单') { - $financialRecord = new FinancialRecord(); - - if (!$isLedger) { - $mod = bcmod((string)$user_id, '5', 0); - $financialRecord->suffix($mod); - } + $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); + } - return $financialRecord->fill( - [ - 'user_id' => $user_id, - 'user_type' => $record['user_type'], - 'money' => $record['money'], - 'money_type' => $record['money_type'], - 'source_id' => $record['source_id'], - 'source_type' => $record['source_type'], - 'desc' => $record['desc'], - 'comment' => $record['comment'], - 'status' => $record['status'], - ] - )->save(); + /** + * @inheritDoc + */ + public function storeByOLOrderComp($user_id, $source_id, $money, $user_type = 1, $source_type = 1, $money_type = 6, $desc = '线上外卖订单收入', $comment = '用户订单完成') + { + $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); + // 同时维护钱包 + $store = Store::query()->where(['user_id' => $user_id])->first(); + $store->store_wallet = bcadd($store->store_wallet, $money, 2); + $store->save(); + } + /** + * @inheritDoc + */ + public function storeByOFLOrderComp($user_id, $source_id, $money, $user_type = 1, $source_type = 1, $money_type = 7, $desc = '线下当面付订单收入', $comment = '用户订单完成') + { + $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); } } \ No newline at end of file diff --git a/app/Service/FinancialRecordServiceInterface.php b/app/Service/FinancialRecordServiceInterface.php index 4078043..8a53628 100644 --- a/app/Service/FinancialRecordServiceInterface.php +++ b/app/Service/FinancialRecordServiceInterface.php @@ -31,7 +31,7 @@ interface FinancialRecordServiceInterface * @param string $desc * @return mixed */ - public function communityAwardByPlatNewUserFirstOLOrder($user_id, $source_id, $money, $user_type=2, $source_type=1, $money_type=1, $desc='新用户首单奖励', $comment=''); + public function communityAwardByPlatNewUserFirstOLOrder($user_id, $source_id, $money, $user_type=2, $source_type=1, $money_type=2, $desc='新用户首单奖励', $comment=''); /** * 社区服务点用户订单完成分账 @@ -45,7 +45,7 @@ interface FinancialRecordServiceInterface * @param string $desc * @return mixed */ - public function communitySeparateAccountsByOrderComp($user_id, $source_id, $money, $user_type=2, $source_type=1, $money_type=2, $desc='用户订单分成', $comment=''); + public function communitySeparateAccountsByOrderComp($user_id, $source_id, $money, $user_type=2, $source_type=1, $money_type=3, $desc='用户订单分成', $comment=''); /** * 收支总账 @@ -59,4 +59,88 @@ interface FinancialRecordServiceInterface */ public function ledgerAccounts($source_id, $money, $source_type, $money_type, $desc, $comment=''); + /** + * 商户线下用户支付新用户奖励 + * @param $user_id + * @param $source_id + * @param $money + * @param int $user_type + * @param int $source_type + * @param int $money_type + * @param string $desc + * @param string $comment + * @return mixed + */ + public function storeAwardByPlatNewUserOFLOrder($user_id, $source_id, $money, $user_type=1, $source_type=1, $money_type=4, $desc='新用户下单奖励', $comment=''); + + /** + * 商户线下用户支付用户当日首单奖励 + * @param $user_id + * @param $source_id + * @param $money + * @param int $user_type + * @param int $source_type + * @param int $money_type + * @param string $desc + * @param string $comment + * @return mixed + */ + public function storeAwardByTodayFirstOFLOrder($user_id, $source_id, $money, $user_type=1, $source_type=1, $money_type=5, $desc='用户店铺首单奖励', $comment=''); + + /** + * 用户线下订单支付流水 + * @param $user_id + * @param $source_id + * @param $money + * @param int $user_type + * @param int $source_type + * @param int $money_type + * @param string $desc + * @param string $comment + * @return mixed + */ + public function userByOFLOrderPaid($user_id, $source_id, $money, $user_type=1, $source_type=1, $money_type=100, $desc='用户下单(线下)', $comment=''); + + /** + * 用户线上订单支付流水 + * @param $user_id + * @param $source_id + * @param $money + * @param int $user_type + * @param int $source_type + * @param int $money_type + * @param string $desc + * @param string $comment + * @return mixed + */ + public function userByOLOrderPaid($user_id, $source_id, $money, $user_type=1, $source_type=1, $money_type=101, $desc='用户下单(线上)', $comment=''); + + /** + * 商户线上订单完成收入流水 + * @param $user_id + * @param $source_id + * @param $money + * @param int $user_type + * @param int $source_type + * @param int $money_type + * @param string $desc + * @param string $comment + * @return mixed + */ + public function storeByOLOrderComp($user_id, $source_id, $money, $user_type=1, $source_type=1, $money_type=6, $desc='线上外卖订单收入', $comment=''); + + /** + * 商户线下订单完成收入流水 + * @param $user_id + * @param $source_id + * @param $money + * @param int $user_type + * @param int $source_type + * @param int $money_type + * @param string $desc + * @param string $comment + * @return mixed + */ + public function storeByOFLOrderComp($user_id, $source_id, $money, $user_type=1, $source_type=1, $money_type=7, $desc='线下当面付订单收入', $comment=''); + } \ No newline at end of file diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index 7aa31e1..fd918bd 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -11,7 +11,9 @@ use App\Model\Goods; use App\Model\Order; use App\Model\OrderGoods; use App\Model\OrderMain; +use App\Model\OrderSalesStatistic; use App\Model\SpecCombination; +use App\Model\Store; use Exception; use Hyperf\DbConnection\Db; use Hyperf\Snowflake\IdGeneratorInterface; @@ -564,4 +566,138 @@ class OrderService implements OrderServiceInterface } } + + /** + * @inheritDoc + */ + public function onlinePaid($global_order_id) + { + Db::beginTransaction(); + try { + // 查询订单 + $orderMain = OrderMain::query() + ->where([ + 'global_order_id' => $global_order_id, + 'type' => OrderMain::ORDER_TYPE_ONLINE + ]) + ->first(); + + // 修改订单、子订单状态 + $currentTime = time(); + $orderMain->state = OrderMain::ORDER_STATE_UNTAKE; + $orderMain->time_pay = $currentTime; + $orderMain->pay_time = date('Y-m-d H:i:s', $currentTime); + $orderMain->save(); + + $upOrder = Order::query() + ->where(['order_main_id' => $orderMain->id]) + ->update(['state' => OrderMain::ORDER_STATE_UNTAKE, 'pay_time' => $orderMain->pay_time]); + + // 更新商户销量 + $upStoreScore = Store::query() + ->whereIn('id', explode(',', $orderMain->store_ids)) + ->update(['score' => Db::raw('score+1')]); + + // 更新商品库存和销量 + $orders = Order::query()->select(['id', 'money', 'user_id', 'store_id', 'pay_time']) + ->where(['order_main_id' => $orderMain->id]) + ->get() + ->toArray(); + $orderGoods = OrderGoods::query()->select(['good_id AS id', 'number', 'combination_id']) + ->whereIn('order_id', array_values(array_column($orders, 'id'))) + ->get() + ->toArray(); + foreach ($orderGoods as $key => &$goodsItem) { + + $goods = Goods::find($goodsItem['id']); + + // 库存处理,有规格 + if ($goodsItem['combination_id']) { + $combination = SpecCombination::find($goodsItem['combination_id']); + $combination->number = $combination->number - $goodsItem['number']; + $combination->save(); + } else { + $goods->inventory = $goods->inventory - $goodsItem['number']; + } + + $goods->sales = $goods->sales - $goodsItem['number']; + $goods->save(); + + } + + // 月销流水 + $statistics = []; + foreach ($orders as $key => &$order) { + $statistics[] = [ + 'money' => $order['money'], + 'user_id' => $order['user_id'], + 'store_id' => $order['store_id'], + 'market_id' => $orderMain->market_id, + 'order_id' => $order['id'], + 'createtime' => strtotime($order['pay_time']), + ]; + } + + if (is_array($statistics) && !empty($statistics)) { + $inSalesStatistics = OrderSalesStatistic::query()->insert($statistics); + } + + Db::commit(); + return true; + } catch (Exception $e) { + + $this->log->event(LogLabel::ONLINE_PAID_LOG, ['exception' => $e->getMessage()]); + Db::rollBack(); + return false; + } + } + + /** + * @inheritDoc + */ + public function offlinePaid($global_order_id) + { + Db::beginTransaction(); + try { + + // 主订单状态更新 + $orderMain = OrderMain::query() + ->where(['global_order_id' => $global_order_id, 'type' => OrderMain::ORDER_TYPE_OFFLINE]) + ->first(); + + if (empty($orderMain)) { + + $this->log->event( + LogLabel::PAY_NOTIFY_WXMINI, + ['order_not_found' => $global_order_id] + ); + Db::rollBack(); + return false; + } + + $currentTime = time(); + $orderMain->state = OrderMain::ORDER_STATE_UNTAKE; + $orderMain->dm_state = OrderMain::ORDER_STATE_UNTAKE; + $orderMain->time_pay = $currentTime; + $orderMain->pay_time = date('Y-m-d H:i:s', $currentTime); + $orderMain->save(); + + // 子订单状态更新 + $upOrder = Order::query() + ->where(['order_main_id' => $orderMain->id]) + ->update([ + 'state' => OrderMain::ORDER_STATE_UNTAKE, + 'dm_state' => OrderMain::ORDER_STATE_UNTAKE, + 'pay_time' => date('Y-m-d H:i:s', $currentTime) + ]); + + Db::commit(); + return true; + } catch (Exception $e) { + + $this->log->event(LogLabel::OFFLINE_PAID_LOG, ['exception' => $e->getMessage()]); + Db::rollBack(); + return false; + } + } } \ No newline at end of file diff --git a/app/Service/OrderServiceInterface.php b/app/Service/OrderServiceInterface.php index 92fa986..01cb413 100644 --- a/app/Service/OrderServiceInterface.php +++ b/app/Service/OrderServiceInterface.php @@ -28,9 +28,24 @@ interface OrderServiceInterface public function existsByGlobalOrderId($global_order_id); /** + * 订单完成 * @param $global_order_id * @return mixed */ public function onlineCompleted($global_order_id); + /** + * 线上订单支付完成 + * @param $global_order_id + * @return mixed + */ + public function onlinePaid($global_order_id); + + /** + * 线下订单支付完成 + * @param $global_order_id + * @return mixed + */ + public function offlinePaid($global_order_id); + } \ No newline at end of file diff --git a/app/Service/SeparateAccountsService.php b/app/Service/SeparateAccountsService.php index 4958584..994e1b4 100644 --- a/app/Service/SeparateAccountsService.php +++ b/app/Service/SeparateAccountsService.php @@ -4,8 +4,14 @@ namespace App\Service; use App\Commons\Log; use App\Constants\LogLabel; +use App\Model\FinancialRecord; +use App\Model\Order; use App\Model\OrderMain; use App\Model\ServiceReward; +use App\Model\Store; +use App\Model\StoreAccount; +use App\Model\SystemConfig; +use App\Model\UserBalance; use App\Model\UserRelationBind; use Hyperf\DbConnection\Db; use Hyperf\Di\Annotation\Inject; @@ -30,12 +36,30 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface */ protected $financialRecordService; + /** + * @Inject + * @var MiniprogramServiceInterface + */ + protected $miniprogramService; + /** * @inheritDoc */ public function orderOnlinePaid($global_order_id) { - // TODO: Implement orderOnlinePaid() method. + // 线上订单支付完成 + // 订单 + $orderMain = OrderMain::query() + ->where(['global_order_id' => $global_order_id]) + ->first(); + + if (empty($orderMain)) { + return false; + } + + // =======用户支付流水 / Start======= + $this->financialRecordService->userByOFLOrderPaid($orderMain->user_id, $orderMain->id, $orderMain->money); + // =======用户支付流水 / End======= } /** @@ -51,12 +75,47 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface ->first(); if (empty($orderMain)) { - return; + return false; } + $currentTime = time(); Db::beginTransaction(); try { + // =======商户订单收入流水 / Start======= + // 查询子订单 + $orders = Order::query()->select(['id', 'money', 'user_id', 'store_id', 'pay_time']) + ->where(['order_main_id' => $orderMain->id]) + ->get()->toArray(); + + foreach ($orders as $key => &$order) { + + // 商户 + $store = Store::find($order['store_id']); + + // 旧商户流水基础数据 TODO 直接移除或后续考虑移除 + $storeAccountBase = [ + 'user_id' => $order['user_id'], + 'order_id' => $order['id'], + 'store_id' => $order['store_id'], + 'type' => 1, + 'time' => date('Y-m-d H:i:s', $currentTime), + 'add_time' => $currentTime, + ]; + + // 旧商户流水 TODO 直接移除或后续考虑移除 + $storeAccount = [ + 'money' => $order['money'], + 'note' => '线上订单', + 'category' => 1, + ]; + StoreAccount::query()->insert(array_merge($storeAccountBase, $storeAccount)); + + // 新商户流水 + $this->financialRecordService->storeByOLOrderComp($store->user_id, $orderMain->id ,$order['money']); + } + // =======商户订单收入流水 / End======= + // =======社区服务点分账 / Start======= // 前提:用户线上下单并且订单完成 // 奖励规则A:用户是平台新用户,奖励社区服务点平台新用户奖励x元+平台新用户首单奖励y元+订单商品金额z%的分成 @@ -86,7 +145,7 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface } // 账单分成 - $money = bcmul($orderMain->money, $award['flow_reward']); + $money = bcmul($orderMain->money, bcdiv($award['flow_reward'], 100, 6), 2); $this->financialRecordService->communitySeparateAccountsByOrderComp($communityBind->source_id, $orderMain->global_order_id, $money); } @@ -109,6 +168,123 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface */ public function orderOfflinePaid($global_order_id) { - // TODO: Implement orderOfflinePaid() method. + // 线下订单支付完成 + // 订单 + $orderMain = OrderMain::query() + ->where(['global_order_id' => $global_order_id]) + ->first(); + + if (empty($orderMain)) { + return false; + } + + // 查询子订单,当面付目前实际上只有一个子订单 + $order = Order::query()->select(['id', 'money', 'user_id', 'store_id', 'pay_time']) + ->where(['order_main_id' => $orderMain->id]) + ->first(); + + if (empty($order)) { + return false; + } + + $currentTime = time(); + Db::beginTransaction(); + try { + + // =======用户支付流水 / Start======= + $this->financialRecordService->userByOFLOrderPaid($orderMain->user_id, $orderMain->id, $orderMain->money); + // =======用户支付流水 / End======= + + // =======线下订单支付完成商户分账 / Start======= + // 前提:用户线上下单并且支付完成 + // 奖励规则A:用户是平台新用户,奖励商户2元 + // 奖励规则B:用户是非新用户,但是是商户当日首单,奖励商户0.05元 + // =======线下订单支付完成商户分账 / Start======= + + // 旧商户订单流水基础数据 TODO 直接移除或后续考虑移除 + $storeAccountBase = [ + 'user_id' => $order->user_id, + 'order_id' => $order->id, + 'store_id' => $order->store_id, + 'type' => 1, + 'time' => date('Y-m-d H:i:s', $currentTime), + 'add_time' => $currentTime, + ]; + + // 旧商户订单流水 TODO 直接移除或后续考虑移除 + $storeAccount = [ + 'money' => $order->money, + 'note' => '当面付订单收入', + 'category' => 2, + ]; + StoreAccount::query()->insert(array_merge($storeAccountBase, $storeAccount)); + + // 商户 + $store = Store::find($order->store_id); + + // 新商户订单流水 + $this->financialRecordService->storeByOFLOrderComp($store->user_id, $orderMain->id, $order->money); + + $needAward = false; + $awardAmount = 0; + // 新用户商户奖励 + if ($this->userService->isPlatformNewUser($orderMain->user_id, $orderMain->id)) { + + $awardAmount = SystemConfig::query()->where(['type' => 1, 'menu_name' => 'award_new_user'])->value('value'); + // 旧商户流水 TODO 直接移除或后续考虑移除 + $storeAccount = [ + 'money' => $awardAmount, + 'note' => '新用户下单成功,平台奖励', + 'category' => 3, + ]; + // 新商户流水 + $this->financialRecordService->storeAwardByPlatNewUserOFLOrder($store->user_id, $orderMain->id, $awardAmount); + $needAward = true; + + } else { + // 商户当日首单奖励 + if ( + $this->userService->isStoreFirstOrderToday( + $order->user_id, + $order->store_id, + $order->id, + FinancialRecord::OFL_FIRST_AWARD_LIMIT_AMOUNT + ) + ) { + + $awardAmount = SystemConfig::query()->where(['type' => 1, 'menu_name' => 'award_each_order'])->value('value'); + // 旧商户流水 TODO 直接移除或后续考虑移除 + $storeAccount = [ + 'money' => $awardAmount, + 'note' => '用户下单成功,平台奖励', + 'category' => 4, + ]; + // 新商户流水 + $this->financialRecordService->storeAwardByTodayFirstOFLOrder($store->user_id, $orderMain->id, $awardAmount); + $needAward = true; + + } + } + + if ($needAward && $awardAmount) { + + // 旧商户流水 TODO 直接移除或后续考虑移除 + StoreAccount::query()->insert(array_merge($storeAccountBase, $storeAccount)); + + // 发模板消息 + $openid = Users::query()->where(['id' => $store['user_id']])->value('openid'); + $res = $this->miniprogramService->sendTemMsgForAward($storeAccount['money'], $storeAccount['note'], $openid, $storeAccountBase['time']); + } + + // =======线下订单支付完成商户分账 / End======= + + Db::commit(); + return true; + } catch (\Exception $e) { + + $this->log->event(LogLabel::SEPARATE_ACCOUNTS_LOG, ['exception' => $e->getMessage(), 'order_main' => json_encode($orderMain)]); + Db::rollBack(); + return false; + } } } \ No newline at end of file From 9c6694c2d6ca2b7e1bbe2efbb4048327d62beeb2 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 21 Aug 2020 19:09:02 +0800 Subject: [PATCH 12/75] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E8=B4=AD=E7=89=A9?= =?UTF-8?q?=E8=BD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/PurchaseLimitController.php | 6 ++ app/Model/Combination.php | 14 +++ app/Model/ShopCar.php | 14 +++ app/Service/PurchaseLimitService.php | 97 ++++++++++++++++++- app/Service/PurchaseLimitServiceInterface.php | 2 + config/routes.php | 1 + 6 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 app/Model/Combination.php create mode 100644 app/Model/ShopCar.php diff --git a/app/Controller/PurchaseLimitController.php b/app/Controller/PurchaseLimitController.php index 3f9abf7..69b2c48 100644 --- a/app/Controller/PurchaseLimitController.php +++ b/app/Controller/PurchaseLimitController.php @@ -35,4 +35,10 @@ class PurchaseLimitController extends BaseController return $this->success($res); } + public function test() + { + $res = $this->purchaseLimitService->test($this->request->all()); + return $this->success($res); + } + } diff --git a/app/Model/Combination.php b/app/Model/Combination.php new file mode 100644 index 0000000..b1e5833 --- /dev/null +++ b/app/Model/Combination.php @@ -0,0 +1,14 @@ +select('is_max','restrict_num','box_money','inventory','money') + ->first(); + + //获取购物车该商品购买数量 + $num = ShopCar::where([ + ['user_id', $params['user_id']], + ['good_id', $params['good_id']], + ]) + ->sum('num'); + //限购检验 + if($goods->restrict_num > 0 && $goods->restrict_num <= $num){ return false; + } + //获取规格表商品信息 + if($params['combination_id'] > 0) { + $combination = Combination::where([ + ['id', '=', $params['combination_id']], + ]) + ->select('wm_money', 'number') + ->first(); + $inventory = $combination->number; + $money = $combination->wm_money; }else{ - return '加入购物车成功'; + $inventory = $goods->inventory; + $money = $goods->money; + } + //库存校验 + if($goods->is_max == 2 && ($num + $params['num']) > $inventory) + { + return false; } + //更新购物车 + $exists = ShopCar::where([ + ['user_id', '=', $params['user_id']], + ['good_id', '=', $params['good_id']], + ['market_id','=',$params['market_id']], + ['combination_id','=', $params['combination_id']], + ]); + if($params['combination_id'] > 0) { + $exists->where('combination_id',$params['combination_id']); + } + $test = $exists->exists(); + if($test) + { + $update = ShopCar::where([ + ['user_id', '=', $params['user_id']], + ['good_id', '=', $params['good_id']], + ['market_id','=',$params['market_id']], + ]); + if($params['combination_id'] > 0) { + $update->where('combination_id',$params['combination_id']); + } + $update->increment('num', $params['num']); + }else{ + $son_id = empty($params['son_id']) ? 0 : $params['son_id']; + $dr_id = empty($params['dr_id']) ? 0 : $params['dr_id']; + $combination_id = empty($params['combination_id']) ? 0 : $params['combination_id']; + $qg_name = empty($params['qg_name']) ? ' ' : $params['qg_name']; + $qg_logo = empty($params['qg_logo']) ? ' ' :$params['qg_logo']; + ShopCar::insert( + [ + 'market_id' => $params['market_id'], + 'good_id' => $params['good_id'], + 'store_id' => $params['store_id'], + 'user_id' => $params['user_id'], + 'combination_id' => $combination_id, + 'num' => $params['num'], + 'spec' => $params['spec'], + 'son_id' => $son_id, + 'dr_id' => $dr_id, + 'qg_name' => $qg_name, + 'qg_logo' => $qg_logo, + 'money' => $money, + 'box_money' => $goods->box_money, + ] + ); + } + return $test; + // if($params['goods_id'] == 1561){ + // return false; + // }else{ + // return '加入购物车成功'; + // } } public function updateShopCar($params) @@ -23,4 +109,9 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface return '更新购物车成功'; } } + + public function test($params) + { + return $params; + } } \ No newline at end of file diff --git a/app/Service/PurchaseLimitServiceInterface.php b/app/Service/PurchaseLimitServiceInterface.php index 79f3df3..b460c81 100644 --- a/app/Service/PurchaseLimitServiceInterface.php +++ b/app/Service/PurchaseLimitServiceInterface.php @@ -9,4 +9,6 @@ interface PurchaseLimitServiceInterface public function addShopCar($params); public function updateShopCar($params); + + public function test($params); } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index 28f4299..254b0f7 100644 --- a/config/routes.php +++ b/config/routes.php @@ -58,6 +58,7 @@ Router::addGroup('/v1/',function (){ //加入购物车 Router::post('PurchaseLimit/addShopCar', 'App\Controller\PurchaseLimitController@addShopCar'); Router::post('PurchaseLimit/updateShopCar', 'App\Controller\PurchaseLimitController@updateShopCar'); + Router::post('PurchaseLimit/test', 'App\Controller\PurchaseLimitController@test'); },['middleware' => [\App\Middleware\Auth\ApiMiddleware::class]]); Router::addGroup('/wechat/',function () { From f45757de62881228490cc04eceee88d919cd6adf Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 21 Aug 2020 19:10:53 +0800 Subject: [PATCH 13/75] Fix --- app/Service/SeparateAccountsService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Service/SeparateAccountsService.php b/app/Service/SeparateAccountsService.php index 994e1b4..109dcd2 100644 --- a/app/Service/SeparateAccountsService.php +++ b/app/Service/SeparateAccountsService.php @@ -13,6 +13,7 @@ use App\Model\StoreAccount; use App\Model\SystemConfig; use App\Model\UserBalance; use App\Model\UserRelationBind; +use App\Model\Users; use Hyperf\DbConnection\Db; use Hyperf\Di\Annotation\Inject; From dd8a5504dba3a45d53f6bb00d2ae721b20d77f66 Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 21 Aug 2020 19:36:35 +0800 Subject: [PATCH 14/75] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E5=88=86=E8=B4=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/FinancialRecord.php | 27 +++++++++---------------- app/Model/UserBalance.php | 7 +++++-- app/Service/FinancialRecordService.php | 6 +++--- app/Service/SeparateAccountsService.php | 18 ++++++++--------- 4 files changed, 27 insertions(+), 31 deletions(-) diff --git a/app/Model/FinancialRecord.php b/app/Model/FinancialRecord.php index 0096c9a..b56adbe 100644 --- a/app/Model/FinancialRecord.php +++ b/app/Model/FinancialRecord.php @@ -42,24 +42,17 @@ class FinancialRecord extends Model const SOURCE_TYPE_ORDER = 1; /** - * 流水类型,大的分类,<=50是奖励,>50是分账 - * - * MONEY_TYPE_PLAT_NEW_USER - * 社区服务点新用户奖励(线上订单完成) / 1 - * - * MONEY_TYPE_FIRST_ORDER - * 社区服务点新用户线上首单奖励(线上订单完成) / 2 - * - * MONEY_TYPE_OL_ORDER - * 社区服务点用户线上订单分账(线上订单完成) / 51 + * 流水类型,大的分类,<100是奖励分账等收入项 >=100是提现消费等支出项 */ - const MONEY_TYPE_PLAT_NEW_USER = 1; - const MONEY_TYPE_FIRST_ORDER = 2; - const MONEY_TYPE_OL_ORDER = 3; - const MONEY_TYPE_STORE_PLAT_NEW_USER = 4; - const MONEY_TYPE_STORE_FIRST_ORDER = 5; - const MONEY_TYPE_USER_OFL_ORDER = 100; - const MONEY_TYPE_USER_OL_ORDER = 101; + const MONEY_TYPE_PLAT_NEW_USER = 1; // 社区服务点新用户奖励(线上订单完成) + const MONEY_TYPE_FIRST_ORDER = 2; // 社区服务点新用户线上首单奖励(线上订单完成) + const MONEY_TYPE_OL_ORDER = 3; // 社区服务点用户线上订单分账(线上订单完成) + const MONEY_TYPE_STORE_PLAT_NEW_USER = 4; // 商户平台新用户奖励 + const MONEY_TYPE_STORE_FIRST_ORDER = 5; // 商户当日首单奖励 + const MONEY_TYPE_STORE_OL_ORDER_COMP = 6; // 商户线上订单完成收入 + const MONEY_TYPE_STORE_OFL_ORDER_COMP = 7; // 商户线下订单完成收入 + const MONEY_TYPE_USER_OFL_ORDER = 100; // 用户线下支付订单 + const MONEY_TYPE_USER_OL_ORDER = 101; // 用户线上支付订单 /** * 状态 diff --git a/app/Model/UserBalance.php b/app/Model/UserBalance.php index 62f988e..3883747 100644 --- a/app/Model/UserBalance.php +++ b/app/Model/UserBalance.php @@ -3,7 +3,6 @@ declare (strict_types=1); namespace App\Model; -use Hyperf\DbConnection\Model\Model; /** */ class UserBalance extends Model @@ -23,7 +22,11 @@ class UserBalance extends Model * * @var array */ - protected $fillable = []; + protected $fillable = [ + 'source_id', + 'user_type', + 'balance' + ]; /** * The attributes that should be cast to native types. * diff --git a/app/Service/FinancialRecordService.php b/app/Service/FinancialRecordService.php index f6e5c80..574de5c 100644 --- a/app/Service/FinancialRecordService.php +++ b/app/Service/FinancialRecordService.php @@ -64,7 +64,7 @@ class FinancialRecordService implements FinancialRecordServiceInterface // 维护社区服务点余额 $balance = UserBalance::firstOrNew([ 'user_type' => UserBalance::USER_TYPE_CS, - 'source_id' => $source_id + 'source_id' => $user_id ]); $balance->balance = bcadd($balance->balance, $money); $balance->save(); @@ -79,7 +79,7 @@ class FinancialRecordService implements FinancialRecordServiceInterface // 维护社区服务点余额 $balance = UserBalance::firstOrNew([ 'user_type' => UserBalance::USER_TYPE_CS, - 'source_id' => $source_id + 'source_id' => $user_id ]); $balance->balance = bcadd($balance->balance, $money); $balance->save(); @@ -94,7 +94,7 @@ class FinancialRecordService implements FinancialRecordServiceInterface // 维护社区服务点余额 $balance = UserBalance::firstOrNew([ 'user_type' => UserBalance::USER_TYPE_CS, - 'source_id' => $source_id + 'source_id' => $user_id ]); $balance->balance = bcadd($balance->balance, $money); $balance->save(); diff --git a/app/Service/SeparateAccountsService.php b/app/Service/SeparateAccountsService.php index 109dcd2..4217a24 100644 --- a/app/Service/SeparateAccountsService.php +++ b/app/Service/SeparateAccountsService.php @@ -59,7 +59,7 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface } // =======用户支付流水 / Start======= - $this->financialRecordService->userByOFLOrderPaid($orderMain->user_id, $orderMain->id, $orderMain->money); + $this->financialRecordService->userByOFLOrderPaid($orderMain->user_id, $global_order_id, $orderMain->money); // =======用户支付流水 / End======= } @@ -113,7 +113,7 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface StoreAccount::query()->insert(array_merge($storeAccountBase, $storeAccount)); // 新商户流水 - $this->financialRecordService->storeByOLOrderComp($store->user_id, $orderMain->id ,$order['money']); + $this->financialRecordService->storeByOLOrderComp($store->user_id, $global_order_id ,$order['money']); } // =======商户订单收入流水 / End======= @@ -141,13 +141,13 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface // 平台新用户 if ($this->userService->isPlatformNewUser($orderMain->user_id, $orderMain->id)) { - $this->financialRecordService->communityAwardByPlatNewUser($communityBind->source_id, $orderMain->global_order_id, $award['new_user_reward']); - $this->financialRecordService->communityAwardByPlatNewUserFirstOLOrder($communityBind->source_id, $orderMain->global_order_id, $award['first_reward']); + $this->financialRecordService->communityAwardByPlatNewUser($communityBind->source_id, $global_order_id, $award['new_user_reward']); + $this->financialRecordService->communityAwardByPlatNewUserFirstOLOrder($communityBind->source_id, $global_order_id, $award['first_reward']); } // 账单分成 $money = bcmul($orderMain->money, bcdiv($award['flow_reward'], 100, 6), 2); - $this->financialRecordService->communitySeparateAccountsByOrderComp($communityBind->source_id, $orderMain->global_order_id, $money); + $this->financialRecordService->communitySeparateAccountsByOrderComp($communityBind->source_id, $global_order_id, $money); } // =======社区服务点分账 / End======= @@ -193,7 +193,7 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface try { // =======用户支付流水 / Start======= - $this->financialRecordService->userByOFLOrderPaid($orderMain->user_id, $orderMain->id, $orderMain->money); + $this->financialRecordService->userByOFLOrderPaid($orderMain->user_id, $global_order_id, $orderMain->money); // =======用户支付流水 / End======= // =======线下订单支付完成商户分账 / Start======= @@ -224,7 +224,7 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface $store = Store::find($order->store_id); // 新商户订单流水 - $this->financialRecordService->storeByOFLOrderComp($store->user_id, $orderMain->id, $order->money); + $this->financialRecordService->storeByOFLOrderComp($store->user_id, $global_order_id, $order->money); $needAward = false; $awardAmount = 0; @@ -239,7 +239,7 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface 'category' => 3, ]; // 新商户流水 - $this->financialRecordService->storeAwardByPlatNewUserOFLOrder($store->user_id, $orderMain->id, $awardAmount); + $this->financialRecordService->storeAwardByPlatNewUserOFLOrder($store->user_id, $global_order_id, $awardAmount); $needAward = true; } else { @@ -261,7 +261,7 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface 'category' => 4, ]; // 新商户流水 - $this->financialRecordService->storeAwardByTodayFirstOFLOrder($store->user_id, $orderMain->id, $awardAmount); + $this->financialRecordService->storeAwardByTodayFirstOFLOrder($store->user_id, $global_order_id, $awardAmount); $needAward = true; } From abdcf4193841292d0a149c391ae14312a1fc1670 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Mon, 24 Aug 2020 02:16:57 +0800 Subject: [PATCH 15/75] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=B4=AD=E7=89=A9?= =?UTF-8?q?=E8=BD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Request/ShopCarRequest.php | 43 ++++++++++++++++++++++++++++ app/Request/UpdateShopCarRequest.php | 43 ++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 app/Request/ShopCarRequest.php create mode 100644 app/Request/UpdateShopCarRequest.php diff --git a/app/Request/ShopCarRequest.php b/app/Request/ShopCarRequest.php new file mode 100644 index 0000000..64a7748 --- /dev/null +++ b/app/Request/ShopCarRequest.php @@ -0,0 +1,43 @@ + 'required|nonempty|integer|exists_enable:ims_cjdc_shopcar,id', + ]; + } + + public function messages(): array + { + return [ + 'id.exists_enable' => ':attribute不存在或被禁用', + 'service_personnel_id.*' => ':attribute信息不正确' + ]; + } + + public function attributes(): array + { + return [ + 'id' => '购物车记录', + ]; + } +} diff --git a/app/Request/UpdateShopCarRequest.php b/app/Request/UpdateShopCarRequest.php new file mode 100644 index 0000000..70bb274 --- /dev/null +++ b/app/Request/UpdateShopCarRequest.php @@ -0,0 +1,43 @@ + 'required|nonempty|integer|exists_enable:lanzu_service_personnel,id,status=1', + ]; + } + + public function messages(): array + { + return [ + 'service_personnel_id.exists_enable' => ':attribute不存在或被禁用', + 'service_personnel_id.*' => ':attribute信息不正确' + ]; + } + + public function attributes(): array + { + return [ + 'service_personnel_id' => '服务专员', + ]; + } +} From 299775702eec58a16559185368b8bd873d0787c9 Mon Sep 17 00:00:00 2001 From: weigang Date: Mon, 24 Aug 2020 10:40:07 +0800 Subject: [PATCH 16/75] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=A1=AE=E8=AE=A4?= =?UTF-8?q?=E6=94=B6=E8=B4=A7API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/OrderController.php | 55 ++++++++++++++++++++++++++++++ config/routes.php | 2 ++ 2 files changed, 57 insertions(+) diff --git a/app/Controller/OrderController.php b/app/Controller/OrderController.php index f26045d..669e19a 100644 --- a/app/Controller/OrderController.php +++ b/app/Controller/OrderController.php @@ -3,11 +3,15 @@ namespace App\Controller; use App\Constants\ErrorCode; +use App\Constants\LogLabel; +use App\Model\OrderMain; use App\Request\OrderOfflineRequest; use App\Request\OrderOnlineRequest; +use Hyperf\DbConnection\Db; use Hyperf\Di\Annotation\Inject; use App\Service\OrderServiceInterface; use Hyperf\HttpMessage\Stream\SwooleStream; +use Hyperf\Validation\ValidationException; class OrderController extends BaseController { @@ -35,4 +39,55 @@ class OrderController extends BaseController } return $this->success(['order_id' => $orderMainId]); } + + /** + * 用户完成订单-确认收货 + */ + public function userComp() + { + + $validator = $this->validationFactory->make( + $this->request->all(), + [ + 'user_id' => 'required|nonempty|integer', + 'order_id' => 'required|nonempty|numeric', + ], + [ + '*.*' => ':attribute 参数不正确', + ] + ); + + if ($validator->fails()) { + // Handle exception + throw new ValidationException($validator); + return; + } + + $userId = $this->request->input('user_id'); + $orderId = $this->request->input('order_id'); + $orderExist = OrderMain::query() + ->where(['id' => $orderId, 'state' => OrderMain::ORDER_STATE_DELIVERY, 'user_id' => $userId]) + ->exists(); + + if (!$orderExist) { + $this->log->event(LogLabel::ONLINE_COMPLETE_LOG, ['order_not_found' => 'order_not_found']); + return $this->result(ErrorCode::SEPARATE_ACCOUNTS_ERROR, '', '操作失败,订单异常或不存在'); + } + + Db::beginTransaction(); + try { + + $this->orderService->onlineCompleted($orderId); + $this->separateAccountsService->orderOnlineCompleted($orderId); + + Db::commit(); + return $this->success(['order_id' => $orderId]); + } catch (\Exception $e) { + + Db::rollBack(); + $this->log->event(LogLabel::ONLINE_COMPLETE_LOG, ['exception' => $e->getMessage()]); + return $this->result(ErrorCode::SEPARATE_ACCOUNTS_ERROR, '', '操作失败,请稍后重试'); + } + + } } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index b68b0e4..8cff5ab 100644 --- a/config/routes.php +++ b/config/routes.php @@ -54,6 +54,8 @@ Router::addGroup('/v1/',function (){ //小程序支付相关 Router::post('wxminipay/online', 'App\Controller\PaymentController@wxminiPayOnline'); Router::post('wxminipay/offline', 'App\Controller\PaymentController@wxminiPayOffline'); + + Router::post('Order/userComp', 'App\Controller\OrderController@userComp'); },['middleware' => [\App\Middleware\Auth\ApiMiddleware::class]]); Router::addGroup('/wechat/',function () { From 630a30bd414d157b5df069b52d53ff7c9c16b63e Mon Sep 17 00:00:00 2001 From: weigang Date: Mon, 24 Aug 2020 10:52:27 +0800 Subject: [PATCH 17/75] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=BA=BF=E4=B8=8A?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E6=B5=81=E6=B0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/FeiePrintService.php | 3 +++ app/Service/OrderService.php | 2 +- app/Service/SeparateAccountsService.php | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Service/FeiePrintService.php b/app/Service/FeiePrintService.php index 9f8f31d..114510b 100644 --- a/app/Service/FeiePrintService.php +++ b/app/Service/FeiePrintService.php @@ -37,6 +37,9 @@ class FeiePrintService implements FeiePrintServiceInterface ->orderBy('s.id') ->get() ->toArray(); + if (empty($data)) { + return ; + } foreach ($data as $key => &$item) { $item = (array)$item; } diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index fd918bd..6b02129 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -100,7 +100,7 @@ class OrderService implements OrderServiceInterface $storeOrderCounts = []; foreach ($countsArr as $key => &$row) { - $storeOrderCounts[$row['id']] = $row['count']; + $storeOrderCounts[$row['store_id']] = $row['count']; } // 循环处理订单总额、子订单总额、商品、商户订单等信息 diff --git a/app/Service/SeparateAccountsService.php b/app/Service/SeparateAccountsService.php index 4217a24..3f89a5c 100644 --- a/app/Service/SeparateAccountsService.php +++ b/app/Service/SeparateAccountsService.php @@ -59,7 +59,7 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface } // =======用户支付流水 / Start======= - $this->financialRecordService->userByOFLOrderPaid($orderMain->user_id, $global_order_id, $orderMain->money); + $this->financialRecordService->userByOLOrderPaid($orderMain->user_id, $global_order_id, $orderMain->money); // =======用户支付流水 / End======= } From bce935b3e045f4e1411867564694bee4c1305780 Mon Sep 17 00:00:00 2001 From: weigang Date: Mon, 24 Aug 2020 10:59:09 +0800 Subject: [PATCH 18/75] no message --- app/Controller/OrderController.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/Controller/OrderController.php b/app/Controller/OrderController.php index 669e19a..bec90c9 100644 --- a/app/Controller/OrderController.php +++ b/app/Controller/OrderController.php @@ -7,6 +7,7 @@ use App\Constants\LogLabel; use App\Model\OrderMain; use App\Request\OrderOfflineRequest; use App\Request\OrderOnlineRequest; +use App\Service\SeparateAccountsServiceInterface; use Hyperf\DbConnection\Db; use Hyperf\Di\Annotation\Inject; use App\Service\OrderServiceInterface; @@ -22,6 +23,12 @@ class OrderController extends BaseController */ protected $orderService; + /** + * @Inject + * @var SeparateAccountsServiceInterface + */ + protected $separateAccountsService; + public function addOnlineOrder(OrderOnlineRequest $request) { $orderMainId = $this->orderService->addOnlineOrder($request->validated()); From 3b788e2dbb1a76bb83ce98a717059addcfbaf412 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Mon, 24 Aug 2020 11:03:52 +0800 Subject: [PATCH 19/75] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=B4=AD=E7=89=A9?= =?UTF-8?q?=E8=BD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/PurchaseLimitController.php | 4 +- app/Service/PurchaseLimitService.php | 90 ++++++++++++++++++---- 2 files changed, 76 insertions(+), 18 deletions(-) diff --git a/app/Controller/PurchaseLimitController.php b/app/Controller/PurchaseLimitController.php index 69b2c48..581e871 100644 --- a/app/Controller/PurchaseLimitController.php +++ b/app/Controller/PurchaseLimitController.php @@ -29,8 +29,8 @@ class PurchaseLimitController extends BaseController public function updateShopCar() { $res = $this->purchaseLimitService->updateShopCar($this->request->all()); - if (!$res) { - return $this->result(ErrorCode::GOODS_FAILURE, '', '更新购物车失败'); + if (isset($res['error'])) { + return $this->result(ErrorCode::GOODS_FAILURE, '', $res['error']); } return $this->success($res); } diff --git a/app/Service/PurchaseLimitService.php b/app/Service/PurchaseLimitService.php index 29004fc..a0cc64b 100644 --- a/app/Service/PurchaseLimitService.php +++ b/app/Service/PurchaseLimitService.php @@ -26,14 +26,19 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface ]) ->sum('num'); //限购检验 - if($goods->restrict_num > 0 && $goods->restrict_num <= $num){ - return false; + if($goods->restrict_num > 0 && $goods->restrict_num <= $num) + { + $error = [ + 'error' => '超过商品限购数量' + ]; + return $error; } //获取规格表商品信息 - if($params['combination_id'] > 0) { + if($params['combination_id'] > 0) + { $combination = Combination::where([ - ['id', '=', $params['combination_id']], - ]) + ['id', '=', $params['combination_id']], + ]) ->select('wm_money', 'number') ->first(); $inventory = $combination->number; @@ -42,23 +47,26 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface $inventory = $goods->inventory; $money = $goods->money; } - //库存校验 + //库存校验 is_max 无限库存 if($goods->is_max == 2 && ($num + $params['num']) > $inventory) { - return false; + $error = [ + 'error' => '库存不足' + ]; + return $error; } //更新购物车 - $exists = ShopCar::where([ + $exists_sql = ShopCar::where([ ['user_id', '=', $params['user_id']], ['good_id', '=', $params['good_id']], ['market_id','=',$params['market_id']], ['combination_id','=', $params['combination_id']], ]); if($params['combination_id'] > 0) { - $exists->where('combination_id',$params['combination_id']); + $exists_sql->where('combination_id',$params['combination_id']); } - $test = $exists->exists(); - if($test) + $exists = $exists_sql->exists(); + if($exists) { $update = ShopCar::where([ ['user_id', '=', $params['user_id']], @@ -93,7 +101,7 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface ] ); } - return $test; + return true; // if($params['goods_id'] == 1561){ // return false; // }else{ @@ -103,11 +111,61 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface public function updateShopCar($params) { - if($params['good_id'] == 1561){ - return false; - }else{ - return '更新购物车成功'; + if($params['num'] <= 0) + { + ShopCar::where('id',$params['id'])->delete(); + }else { + $shop_car = ShopCar::where('id',$params['id']) + ->select('good_id','user_id') + ->first(); + //获取主表商品表信息 + $goods = Goods::where([ + ['id','=',$shop_car['good_id']], + ]) + ->select('is_max','restrict_num','box_money','inventory','money') + ->first(); + //获取购物车该商品购买数量 + $num = ShopCar::where([ + ['user_id', $shop_car['user_id']], + ['good_id', $shop_car['good_id']], + ]) + ->sum('num'); + //限购检验 + if($goods->restrict_num > 0 && $goods->restrict_num <= $num) + { + $error = [ + 'error' => '超过商品限购数量' + ]; + return $error; + } + if ($shop_car['combination_id'] > 0) + { + $combination = Combination::where([ + ['id', '=', $shop_car['combination_id']], + ]) + ->select('wm_money', 'number') + ->first(); + $inventory = $combination->number; + }else{ + $inventory = $goods->inventory; + } + //库存校验 is_max 无限库存 + if($goods->is_max == 2 && $params['num'] > $inventory) + { + $error = [ + 'error' => '库存不足' + ]; + return $error; + } + ShopCar::where('id',$params['id']) + ->update(['num' => $params['num']]); + return true; } + // if($params['good_id'] == 1561){ + // return false; + // }else{ + // return '更新购物车成功'; + // } } public function test($params) From c6614fa66e002966697317e0a0618f574fc60d09 Mon Sep 17 00:00:00 2001 From: weigang Date: Mon, 24 Aug 2020 11:16:10 +0800 Subject: [PATCH 20/75] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=AE=8C=E6=88=90API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/OrderController.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/Controller/OrderController.php b/app/Controller/OrderController.php index bec90c9..4896c6f 100644 --- a/app/Controller/OrderController.php +++ b/app/Controller/OrderController.php @@ -71,12 +71,12 @@ class OrderController extends BaseController } $userId = $this->request->input('user_id'); - $orderId = $this->request->input('order_id'); - $orderExist = OrderMain::query() + $orderId = $this->request->input('order_id'); // TODO 等新订单列表接口处理完毕后全面转换成global_order_id + $orderMain = OrderMain::query() ->where(['id' => $orderId, 'state' => OrderMain::ORDER_STATE_DELIVERY, 'user_id' => $userId]) - ->exists(); + ->first(); - if (!$orderExist) { + if (empty($orderMain)) { $this->log->event(LogLabel::ONLINE_COMPLETE_LOG, ['order_not_found' => 'order_not_found']); return $this->result(ErrorCode::SEPARATE_ACCOUNTS_ERROR, '', '操作失败,订单异常或不存在'); } @@ -84,11 +84,11 @@ class OrderController extends BaseController Db::beginTransaction(); try { - $this->orderService->onlineCompleted($orderId); - $this->separateAccountsService->orderOnlineCompleted($orderId); + $this->orderService->onlineCompleted($orderMain->global_order_id); + $this->separateAccountsService->orderOnlineCompleted($orderMain->global_order_id); Db::commit(); - return $this->success(['order_id' => $orderId]); + return $this->success(''); } catch (\Exception $e) { Db::rollBack(); From e79325832b3ab242d3f6cc7f7da4adcf4098509b Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Mon, 24 Aug 2020 11:33:02 +0800 Subject: [PATCH 21/75] Merge branch 'purchase_limit' into develop # Conflicts: # config/routes.php --- app/Controller/PurchaseLimitController.php | 4 +- app/Request/ShopCarRequest.php | 43 ---------------------- app/Request/UpdateShopCarRequest.php | 8 ++-- 3 files changed, 6 insertions(+), 49 deletions(-) delete mode 100644 app/Request/ShopCarRequest.php diff --git a/app/Controller/PurchaseLimitController.php b/app/Controller/PurchaseLimitController.php index 581e871..f1b96c7 100644 --- a/app/Controller/PurchaseLimitController.php +++ b/app/Controller/PurchaseLimitController.php @@ -20,8 +20,8 @@ class PurchaseLimitController extends BaseController public function addShopCar() { $res = $this->purchaseLimitService->addShopCar($this->request->all()); - if (!$res) { - return $this->result(ErrorCode::GOODS_FAILURE, '', '商品已超过购买数量'); + if (isset($res['error'])) { + return $this->result(ErrorCode::GOODS_FAILURE, '', $res['error']); } return $this->success($res); } diff --git a/app/Request/ShopCarRequest.php b/app/Request/ShopCarRequest.php deleted file mode 100644 index 64a7748..0000000 --- a/app/Request/ShopCarRequest.php +++ /dev/null @@ -1,43 +0,0 @@ - 'required|nonempty|integer|exists_enable:ims_cjdc_shopcar,id', - ]; - } - - public function messages(): array - { - return [ - 'id.exists_enable' => ':attribute不存在或被禁用', - 'service_personnel_id.*' => ':attribute信息不正确' - ]; - } - - public function attributes(): array - { - return [ - 'id' => '购物车记录', - ]; - } -} diff --git a/app/Request/UpdateShopCarRequest.php b/app/Request/UpdateShopCarRequest.php index 70bb274..64a7748 100644 --- a/app/Request/UpdateShopCarRequest.php +++ b/app/Request/UpdateShopCarRequest.php @@ -6,7 +6,7 @@ namespace App\Request; use Hyperf\Validation\Request\FormRequest; -class PersonnelRequest extends FormRequest +class UpdateShopCarRequest extends FormRequest { /** * Determine if the user is authorized to make this request. @@ -22,14 +22,14 @@ class PersonnelRequest extends FormRequest public function rules(): array { return [ - 'service_personnel_id' => 'required|nonempty|integer|exists_enable:lanzu_service_personnel,id,status=1', + 'id' => 'required|nonempty|integer|exists_enable:ims_cjdc_shopcar,id', ]; } public function messages(): array { return [ - 'service_personnel_id.exists_enable' => ':attribute不存在或被禁用', + 'id.exists_enable' => ':attribute不存在或被禁用', 'service_personnel_id.*' => ':attribute信息不正确' ]; } @@ -37,7 +37,7 @@ class PersonnelRequest extends FormRequest public function attributes(): array { return [ - 'service_personnel_id' => '服务专员', + 'id' => '购物车记录', ]; } } From c29fd47aa3bc44f1710b60427950d715bb6f2d52 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Mon, 24 Aug 2020 17:16:22 +0800 Subject: [PATCH 22/75] =?UTF-8?q?banner=20=20mock=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/PurchaseLimitController.php | 6 ++++++ app/Service/PurchaseLimitService.php | 18 ++++++++++++++++-- app/Service/PurchaseLimitServiceInterface.php | 2 ++ config/routes.php | 2 ++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/Controller/PurchaseLimitController.php b/app/Controller/PurchaseLimitController.php index f1b96c7..591ce00 100644 --- a/app/Controller/PurchaseLimitController.php +++ b/app/Controller/PurchaseLimitController.php @@ -35,6 +35,12 @@ class PurchaseLimitController extends BaseController return $this->success($res); } + public function getStoreIdByMarketId() + { + $res = $this->purchaseLimitService->getStoreIdByMarketId($this->request->all()); + return $this->success($res); + } + public function test() { $res = $this->purchaseLimitService->test($this->request->all()); diff --git a/app/Service/PurchaseLimitService.php b/app/Service/PurchaseLimitService.php index a0cc64b..3e0b515 100644 --- a/app/Service/PurchaseLimitService.php +++ b/app/Service/PurchaseLimitService.php @@ -48,7 +48,7 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface $money = $goods->money; } //库存校验 is_max 无限库存 - if($goods->is_max == 2 && ($num + $params['num']) > $inventory) + if($goods->is_max != Goods::INVENTORY_NOLIMIT && ($num + $params['num']) > $inventory) { $error = [ 'error' => '库存不足' @@ -150,7 +150,7 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface $inventory = $goods->inventory; } //库存校验 is_max 无限库存 - if($goods->is_max == 2 && $params['num'] > $inventory) + if($goods->is_max != Goods::INVENTORY_NOLIMIT && $params['num'] > $inventory) { $error = [ 'error' => '库存不足' @@ -168,6 +168,20 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface // } } + public function getStoreIdByMarketId($params) + { + $res = [ + 'id' => 7, + 'item' => 1, + 'item_text' => 'page', + 'logo' => 'http://lanzutest.lanzulive.com/attachment/images/2/2020/08/PY55Y3Mz17yJo17rv1Z7vImX1V5159.jpg', + 'redirect_url' => '/zh_cjdianc/pages/takeout/takeoutindex?store_id=123', + 'src' => '/zh_cjdianc/pages/takeout/takeoutindex?store_id=123', + 'src2' => '/zh_cjdianc/pages/takeout/takeoutindex?store_id=123', + ]; + return $res; + } + public function test($params) { return $params; diff --git a/app/Service/PurchaseLimitServiceInterface.php b/app/Service/PurchaseLimitServiceInterface.php index b460c81..4cbcaf3 100644 --- a/app/Service/PurchaseLimitServiceInterface.php +++ b/app/Service/PurchaseLimitServiceInterface.php @@ -10,5 +10,7 @@ interface PurchaseLimitServiceInterface public function updateShopCar($params); + public function getStoreIdByMarketId($params); + public function test($params); } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index 254b0f7..6f9ebdd 100644 --- a/config/routes.php +++ b/config/routes.php @@ -59,6 +59,8 @@ Router::addGroup('/v1/',function (){ Router::post('PurchaseLimit/addShopCar', 'App\Controller\PurchaseLimitController@addShopCar'); Router::post('PurchaseLimit/updateShopCar', 'App\Controller\PurchaseLimitController@updateShopCar'); Router::post('PurchaseLimit/test', 'App\Controller\PurchaseLimitController@test'); + Router::post('PurchaseLimit/getStoreIdByMarketId', 'App\Controller\PurchaseLimitController@getStoreIdByMarketId'); + Router::post('Order/userComp', 'App\Controller\OrderController@userComp'); },['middleware' => [\App\Middleware\Auth\ApiMiddleware::class]]); Router::addGroup('/wechat/',function () { From 842b54947dba4b82db0b84f07e4bf3bed5d8f280 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Mon, 24 Aug 2020 17:27:11 +0800 Subject: [PATCH 23/75] =?UTF-8?q?=E5=BA=97=E9=93=BAid=20=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/PurchaseLimitService.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Service/PurchaseLimitService.php b/app/Service/PurchaseLimitService.php index 3e0b515..3010d27 100644 --- a/app/Service/PurchaseLimitService.php +++ b/app/Service/PurchaseLimitService.php @@ -175,9 +175,9 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface 'item' => 1, 'item_text' => 'page', 'logo' => 'http://lanzutest.lanzulive.com/attachment/images/2/2020/08/PY55Y3Mz17yJo17rv1Z7vImX1V5159.jpg', - 'redirect_url' => '/zh_cjdianc/pages/takeout/takeoutindex?store_id=123', - 'src' => '/zh_cjdianc/pages/takeout/takeoutindex?store_id=123', - 'src2' => '/zh_cjdianc/pages/takeout/takeoutindex?store_id=123', + 'redirect_url' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=123', + 'src' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=123', + 'src2' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=123', ]; return $res; } From 4afe153948b739476624897f9bf080083eac85c6 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Mon, 24 Aug 2020 18:26:47 +0800 Subject: [PATCH 24/75] =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E8=B4=AD=E4=B9=B0?= =?UTF-8?q?=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/SsdbKeysPrefix.php | 5 ++++ app/Service/PurchaseLimitService.php | 25 +++++++++++++++++++ app/Service/PurchaseLimitServiceInterface.php | 2 ++ 3 files changed, 32 insertions(+) diff --git a/app/Constants/SsdbKeysPrefix.php b/app/Constants/SsdbKeysPrefix.php index bf76f9d..b29fa48 100644 --- a/app/Constants/SsdbKeysPrefix.php +++ b/app/Constants/SsdbKeysPrefix.php @@ -46,4 +46,9 @@ class SsdbKeysPrefix extends AbstractConstants * @Message("Coupon rebate List") */ const COUPON_REBATE_LIST = 'coupon_rebate_list_'; + + /** + * @Message("Coupon rebate List") + */ + const PURCHASE_LIMIT = 'purchase_limit_'; } diff --git a/app/Service/PurchaseLimitService.php b/app/Service/PurchaseLimitService.php index 3010d27..093b418 100644 --- a/app/Service/PurchaseLimitService.php +++ b/app/Service/PurchaseLimitService.php @@ -7,11 +7,26 @@ use Hyperf\DbConnection\Db; use App\Model\Goods; use App\Model\Combination; use App\Model\ShopCar; +use App\Constants\LogLabel; +use App\Commons\Log; +use Hyperf\Utils\ApplicationContext; +use App\TaskWorker\SSDBTask; +use App\Constants\SsdbKeysPrefix; class PurchaseLimitService implements PurchaseLimitServiceInterface { public function addShopCar($params) { + //获取ssdb购买记录 + $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); + $record_exists = $ssdb->exec('hexists',SsdbKeysPrefix::PURCHASE_LIMIT. date('Ymd') .'_'.$params['user_id'], $params['good_id']); + if($record_exists) + { + $error = [ + 'error' => '特价商品每日只能购买一次' + ]; + return $error; + } //获取主表商品表信息 $goods = Goods::where([ ['id','=',$params['good_id']], @@ -182,6 +197,16 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface return $res; } + public function ssdbPurchaseRecord($params) + { + $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); + //添加领取记录到ssdb + $data = [ + $order_id,$coupon->user_id, + ]; + $ssdb->exec('multi_hset', SsdbKeysPrefix::COUPON_REBATE_LIST.$coupon->send_user_id, $data); + } + public function test($params) { return $params; diff --git a/app/Service/PurchaseLimitServiceInterface.php b/app/Service/PurchaseLimitServiceInterface.php index 4cbcaf3..3b0d66d 100644 --- a/app/Service/PurchaseLimitServiceInterface.php +++ b/app/Service/PurchaseLimitServiceInterface.php @@ -12,5 +12,7 @@ interface PurchaseLimitServiceInterface public function getStoreIdByMarketId($params); + public function ssdbPurchaseRecord($params); + public function test($params); } \ No newline at end of file From 9f67970e23a5d8b96794827026ea43cc441f4304 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Mon, 24 Aug 2020 18:46:47 +0800 Subject: [PATCH 25/75] =?UTF-8?q?=E8=B4=AD=E4=B9=B0=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/SsdbKeysPrefix.php | 4 ++-- app/Service/PurchaseLimitService.php | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/Constants/SsdbKeysPrefix.php b/app/Constants/SsdbKeysPrefix.php index b29fa48..00e7bf1 100644 --- a/app/Constants/SsdbKeysPrefix.php +++ b/app/Constants/SsdbKeysPrefix.php @@ -48,7 +48,7 @@ class SsdbKeysPrefix extends AbstractConstants const COUPON_REBATE_LIST = 'coupon_rebate_list_'; /** - * @Message("Coupon rebate List") + * @Message("PURCHASE RECORD") */ - const PURCHASE_LIMIT = 'purchase_limit_'; + const PURCHASE_RECORD = 'purchase_record_'; } diff --git a/app/Service/PurchaseLimitService.php b/app/Service/PurchaseLimitService.php index 093b418..cc581bb 100644 --- a/app/Service/PurchaseLimitService.php +++ b/app/Service/PurchaseLimitService.php @@ -19,7 +19,7 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface { //获取ssdb购买记录 $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - $record_exists = $ssdb->exec('hexists',SsdbKeysPrefix::PURCHASE_LIMIT. date('Ymd') .'_'.$params['user_id'], $params['good_id']); + $record_exists = $ssdb->exec('hexists',SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$params['user_id'], $params['good_id']); if($record_exists) { $error = [ @@ -209,6 +209,12 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface public function test($params) { - return $params; + $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); + //添加领取记录到ssdb + $data = [ + '620',1561, + ]; + $test = $ssdb->exec('multi_hset', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_620', $data); + return $test; } } \ No newline at end of file From 1d5fb84b32d82493a21f15338f814421d4aede9f Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Tue, 25 Aug 2020 09:20:38 +0800 Subject: [PATCH 26/75] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=92=8C=E9=80=80=E6=AC=BEservice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/OrderController.php | 9 +++++++++ app/JsonRpc/OrderService.php | 24 ++++++++++++++++++++++++ app/Service/OrderService.php | 13 +++++++++++++ app/Service/OrderServiceInterface.php | 13 +++++++++++++ 4 files changed, 59 insertions(+) diff --git a/app/Controller/OrderController.php b/app/Controller/OrderController.php index 4896c6f..d91a1c8 100644 --- a/app/Controller/OrderController.php +++ b/app/Controller/OrderController.php @@ -97,4 +97,13 @@ class OrderController extends BaseController } } + + /** + * 用户取消订单 + */ + public function onlineCancel(){ + $globalOrderId = $this->request->input('global_order_id'); + return $this->success($this->orderService->onlineCancel($globalOrderId)); + } + } \ No newline at end of file diff --git a/app/JsonRpc/OrderService.php b/app/JsonRpc/OrderService.php index 10cf513..5ecdadf 100644 --- a/app/JsonRpc/OrderService.php +++ b/app/JsonRpc/OrderService.php @@ -63,4 +63,28 @@ class OrderService implements OrderServiceInterface } + /** + * 线上订单退款 + */ + public function onlineRefund($global_order_id){ + Db::beginTransaction(); + try{ + + return [ + "status" => 200, + "code" => 0, + "result" => $this->orderService->onlineRefund($global_order_id), + // 'result' => $global_order_id, + "message" => '' + ]; + } catch (\Exception $e){ + return [ + "status" => 200, + "code" => 0, + "result" => $this->orderService->onlineRefund($global_order_id), + // 'result' => $global_order_id, + "message" => '' + ]; + } + } } \ No newline at end of file diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index 6b02129..2f74461 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -700,4 +700,17 @@ class OrderService implements OrderServiceInterface return false; } } + + /** + * @inheritDoc + */ + public function onlineCancel($global_order_id){ + + } + /** + * @inheritDoc + */ + public function onlineRefund($global_order_id){ + return 123; + } } \ No newline at end of file diff --git a/app/Service/OrderServiceInterface.php b/app/Service/OrderServiceInterface.php index 01cb413..397bc2c 100644 --- a/app/Service/OrderServiceInterface.php +++ b/app/Service/OrderServiceInterface.php @@ -48,4 +48,17 @@ interface OrderServiceInterface */ public function offlinePaid($global_order_id); + /** + * 线上订单取消 + * @param $global_order_id + * @return mixed + */ + public function onlineCancel($global_order_id); + + /** + * 线上订单退款 + * @param $global_order_id + * @return mixed + */ + public function onlineRefund($global_order_id); } \ No newline at end of file From e6ba220d8a1f69f299b29c8c2cf4734a24a156a9 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Tue, 25 Aug 2020 11:31:41 +0800 Subject: [PATCH 27/75] =?UTF-8?q?=E9=80=80=E5=8D=95=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/OrderController.php | 4 +-- app/Model/CouponUserUse.php | 7 +++++ app/Service/CouponService.php | 37 ++++++++++++++++++++++++++ app/Service/CouponServiceInterface.php | 2 ++ app/Service/OrderService.php | 11 ++++++-- app/Service/OrderServiceInterface.php | 2 +- config/routes.php | 1 + 7 files changed, 59 insertions(+), 5 deletions(-) diff --git a/app/Controller/OrderController.php b/app/Controller/OrderController.php index d91a1c8..fb2ed20 100644 --- a/app/Controller/OrderController.php +++ b/app/Controller/OrderController.php @@ -102,8 +102,8 @@ class OrderController extends BaseController * 用户取消订单 */ public function onlineCancel(){ - $globalOrderId = $this->request->input('global_order_id'); - return $this->success($this->orderService->onlineCancel($globalOrderId)); + $OrderId = $this->request->input('order_id'); + return $this->success($this->orderService->onlineCancel($OrderId)); } } \ No newline at end of file diff --git a/app/Model/CouponUserUse.php b/app/Model/CouponUserUse.php index a8cfcf3..0d53a14 100644 --- a/app/Model/CouponUserUse.php +++ b/app/Model/CouponUserUse.php @@ -6,5 +6,12 @@ namespace App\Model; class CouponUserUse extends Model { + // 正常使用 + const COUPON_USE_STATE_USED = 1; + // 退回用户 + const COUPON_USE_STATE_CANCEL = 2; + + public $timestamps = false; + protected $table = 'ims_system_coupon_user_use'; } \ No newline at end of file diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index eb726f0..c2c016d 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -7,6 +7,7 @@ use Hyperf\DbConnection\Db; use App\Model\CouponUserRecType; use App\Model\Coupon; use App\Model\CouponRec; +use App\Model\CouponUserUse; use Hyperf\Utils\ApplicationContext; use App\TaskWorker\SSDBTask; use App\Constants\SsdbKeysPrefix; @@ -220,4 +221,40 @@ class CouponService implements CouponServiceInterface return $setRes&&$expireRes; } + /** + * 取消订单返券 + * @param $order_id + * @return bool + */ + public function refundOrderCoupons($order_id,$user_id){ + $coupon = CouponUserUse::where([ + ['order_main_id','=',$order_id], + ['status','=',CouponUserUse::COUPON_USE_STATE_USED], + ]) + ->select('id','user_receive_id','number') + ->first(); + // 返回用户优惠券数量并更新状态 + $res = Db::update("UPDATE ims_system_coupon_user_receive SET number_remain=number_remain+{$coupon->number}, status=IF(number=number_remain,0,1), update_time=".time()."" + ." WHERE id={$coupon->user_receive_id} AND number>=(number_remain+{$coupon->number})"); + + // 更新使用记录状态为已退回 + CouponUserUse::where([ + ['id','=',$coupon->id], + ['status','=',CouponUserUse::COUPON_USE_STATE_USED], + ]) + ->update([ + 'status' => CouponUserUse::COUPON_USE_STATE_CANCEL, + 'return_time' => time(), + 'update_time' => time(), + ]); + + //删除当日 redis 使用记录缓存 + $redis = ApplicationContext::getContainer()->get(Redis::class); + $remRes = $redis->sRem( + 'coupon_'.date('Ymd').'_used_'.$user_id, + $coupon->system_coupon_id + ); + return $res; + } + } \ No newline at end of file diff --git a/app/Service/CouponServiceInterface.php b/app/Service/CouponServiceInterface.php index bdd60c5..38355f2 100644 --- a/app/Service/CouponServiceInterface.php +++ b/app/Service/CouponServiceInterface.php @@ -27,4 +27,6 @@ interface CouponServiceInterface */ public function getOrderCanUseCoupons($orderAmount, $marketId, $userId, $fields=[], $type=1, $storeTypeIds=[0]); + public function refundOrderCoupons($order_id,$user_id); + } diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index 2f74461..56a7893 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -704,8 +704,14 @@ class OrderService implements OrderServiceInterface /** * @inheritDoc */ - public function onlineCancel($global_order_id){ - + public function onlineCancel($order_id){ + $order_main = OrderMain::where('id',$order_id) + ->select('global_order_id','user_id') + ->first(); + OrderMain::where('id',$order_id) + ->update(['state' => OrderMain::ORDER_STATE_CANCEL]); + $res = $this->couponService->refundOrderCoupons($order_id,$order_main->user_id); + return $res; } /** * @inheritDoc @@ -713,4 +719,5 @@ class OrderService implements OrderServiceInterface public function onlineRefund($global_order_id){ return 123; } + } \ No newline at end of file diff --git a/app/Service/OrderServiceInterface.php b/app/Service/OrderServiceInterface.php index 397bc2c..4834c91 100644 --- a/app/Service/OrderServiceInterface.php +++ b/app/Service/OrderServiceInterface.php @@ -53,7 +53,7 @@ interface OrderServiceInterface * @param $global_order_id * @return mixed */ - public function onlineCancel($global_order_id); + public function onlineCancel($order_id); /** * 线上订单退款 diff --git a/config/routes.php b/config/routes.php index 8cff5ab..b2e5598 100644 --- a/config/routes.php +++ b/config/routes.php @@ -50,6 +50,7 @@ Router::addGroup('/v1/',function (){ //订单相关 Router::post('Order/addOnline', 'App\Controller\OrderController@addOnlineOrder'); Router::post('Order/addOffline', 'App\Controller\OrderController@addOfflineOrder'); + Router::post('Order/onlineCancel', 'App\Controller\OrderController@onlineCancel'); //小程序支付相关 Router::post('wxminipay/online', 'App\Controller\PaymentController@wxminiPayOnline'); From 19b4636e0e7a03eb35f4228d731dcf0e9ce25fa8 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Tue, 25 Aug 2020 12:07:17 +0800 Subject: [PATCH 28/75] =?UTF-8?q?=E7=89=B9=E4=BB=B7=E5=95=86=E5=93=81--?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=E7=BA=BF=E4=B8=8A=E8=AE=A2=E5=8D=95=E9=80=80?= =?UTF-8?q?=E6=AC=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/LogLabel.php | 2 +- app/JsonRpc/OrderService.php | 12 +++-- app/Model/CouponUserRec.php | 8 +++ app/Model/CouponUserUse.php | 6 +++ app/Service/CouponService.php | 20 ++++++++ app/Service/CouponServiceInterface.php | 2 + app/Service/OrderService.php | 62 ++++++++++++++++++++++- app/Service/PayRefundService.php | 47 +++++++++++++++++ app/Service/PayRefundServiceInterface.php | 8 +++ 9 files changed, 160 insertions(+), 7 deletions(-) create mode 100644 app/Service/PayRefundService.php create mode 100644 app/Service/PayRefundServiceInterface.php diff --git a/app/Constants/LogLabel.php b/app/Constants/LogLabel.php index d4b9f72..072a6f7 100644 --- a/app/Constants/LogLabel.php +++ b/app/Constants/LogLabel.php @@ -53,5 +53,5 @@ class LogLabel extends AbstractConstants * @Message("Offline Paid Complete Log Label") */ const OFFLINE_PAID_LOG = 'offline_paid_log'; - + } diff --git a/app/JsonRpc/OrderService.php b/app/JsonRpc/OrderService.php index 5ecdadf..43abb2e 100644 --- a/app/JsonRpc/OrderService.php +++ b/app/JsonRpc/OrderService.php @@ -65,6 +65,8 @@ class OrderService implements OrderServiceInterface /** * 线上订单退款 + * 申请退款 state = 8 + * 退款成功 state = 9 */ public function onlineRefund($global_order_id){ Db::beginTransaction(); @@ -75,15 +77,15 @@ class OrderService implements OrderServiceInterface "code" => 0, "result" => $this->orderService->onlineRefund($global_order_id), // 'result' => $global_order_id, - "message" => '' + "message" => '退款成功' ]; } catch (\Exception $e){ + Db::rollBack(); return [ "status" => 200, - "code" => 0, - "result" => $this->orderService->onlineRefund($global_order_id), - // 'result' => $global_order_id, - "message" => '' + "code" => ErrorCode::ORDER_FAILURE, + "result" => [], + "message" => $e->getMessage() ]; } } diff --git a/app/Model/CouponUserRec.php b/app/Model/CouponUserRec.php index c5c2608..25afd2f 100644 --- a/app/Model/CouponUserRec.php +++ b/app/Model/CouponUserRec.php @@ -6,5 +6,13 @@ namespace App\Model; class CouponUserRec extends Model { + /* 状态 */ + // 未使用 + const STATE_UNUSED = 0; + // 使用部分 + const STATE_SOME = 1; + // 已用完 + const STATE_FINISH = 2; + protected $table = 'ims_system_coupon_user_receive'; } \ No newline at end of file diff --git a/app/Model/CouponUserUse.php b/app/Model/CouponUserUse.php index a8cfcf3..b333751 100644 --- a/app/Model/CouponUserUse.php +++ b/app/Model/CouponUserUse.php @@ -6,5 +6,11 @@ namespace App\Model; class CouponUserUse extends Model { + /* 状态 */ + // 正常使用 + const STATE_USE = 1; + // 已退回用户 + const STATE_REFUND = 2; + protected $table = 'ims_system_coupon_user_use'; } \ No newline at end of file diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index eb726f0..ce6acef 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -220,4 +220,24 @@ class CouponService implements CouponServiceInterface return $setRes&&$expireRes; } + /** + * 删除-优惠券今日使用的缓存 + * @param $userId + * @param $couponId + * @param $couponRecId + * @return bool + */ + function clearTodayCouponUsed($userId, $couponId) + { + + $redis = ApplicationContext::getContainer()->get(Redis::class); + + $res = $redis->sRem( + 'coupon_'.date('Ymd').'_used_'.$userId, + $couponId + ); + + return $res; + } + } \ No newline at end of file diff --git a/app/Service/CouponServiceInterface.php b/app/Service/CouponServiceInterface.php index bdd60c5..5dd2d84 100644 --- a/app/Service/CouponServiceInterface.php +++ b/app/Service/CouponServiceInterface.php @@ -27,4 +27,6 @@ interface CouponServiceInterface */ public function getOrderCanUseCoupons($orderAmount, $marketId, $userId, $fields=[], $type=1, $storeTypeIds=[0]); + + function clearTodayCouponUsed($userId, $couponId); } diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index 2f74461..50779c7 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -711,6 +711,66 @@ class OrderService implements OrderServiceInterface * @inheritDoc */ public function onlineRefund($global_order_id){ - return 123; + Db::beginTransaction(); + try { + + $time = time(); + // 主订单状态更新 + $orderMain = OrderMain::query() + ->where(['global_order_id' => $global_order_id, 'state' => OrderMain::ORDER_STATE_DELIVERY]) + ->first(); + + if (empty($orderMain)) { + Db::rollBack(); + return false; + } + + $orderMain->state = OrderMain::ORDER_STATE_REFUNDED; + $upOrderMain = $orderMain->save(); + + // 子订单状态更新 + $upChild = Order::query() + ->where(['order_main_id' => $orderMain->id]) + ->update(['state' => OrderMain::ORDER_STATE_REFUNDED]); + + /* 退还优惠券 */ + // 先查询是否正常使用优惠券 + // 修改状态,退还领取记录库存,删除ssdb缓存 + $couponUses = CouponUserUse::query() + ->select('id','system_coupon_id','user_id','number','user_receive_id') + ->where('order_main_id',$orderMain->id) + ->where('status',CouponUserUse::STATE_USE) + ->select(); + if(!empty($couponUse)){ + foreach($couponUses as $use){ + $use->status = CouponUserUse::STATE_USE; + $use->return_time = $time; + $use->update_time = $time; + $use->save(); + + $couponReceive = CouponUserRec::query() + ->where('id',$use->user_receive_id) + ->whereRaw('number >= number_remain+'.$use->number) + ->update([ + 'number_remain' => Db::raw('number_remain+'.$use->number), + 'status' => Db::raw('IF(number=number_remain,' . CouponUserRec::STATE_UNUSED . ',' . CouponUserRec::STATE_SOME . ')'), + 'update_time' => $time + ]); + + $clearUseRedis = $this->couponService->clearTodayCouponUsed($use->user_id,$use->system_coupon_id); + } + } + + // 退还订单金额到用户微信余额 + + + Db::commit(); + return true; + } catch (Exception $e) { + + $this->log->event(LogLabel::ORDER_LOG, ['msg'=> '订单退款','exception' => $e->getMessage()]); + Db::rollBack(); + return false; + } } } \ No newline at end of file diff --git a/app/Service/PayRefundService.php b/app/Service/PayRefundService.php new file mode 100644 index 0000000..27bd0d4 --- /dev/null +++ b/app/Service/PayRefundService.php @@ -0,0 +1,47 @@ + 0, + 'msg' => '退款成功' + ]; + + // 查询订单 + $orderMain = OrderMain::query() + ->select('id','code','order_num','money','state') + ->where('global_order_id',$global_order_id) + ->where('pay_type',OrderMain::ORDER_PAY_WX) + ->where(Db::raw('refund_time is null')) + ->first(); + if(empty($orderMain)){ + return ['status'=>1, 'msg'=>'订单不存在或已退款']; + } + $optional = []; + $result = $app->refund->byOutTradeNumber( + $orderMain->code, + $orderMain->code, + $orderMain->money * 100, + $orderMain->money * 100, + $optional + ); + return $result; + } + +} \ No newline at end of file diff --git a/app/Service/PayRefundServiceInterface.php b/app/Service/PayRefundServiceInterface.php new file mode 100644 index 0000000..7ca1de1 --- /dev/null +++ b/app/Service/PayRefundServiceInterface.php @@ -0,0 +1,8 @@ + Date: Tue, 25 Aug 2020 14:06:16 +0800 Subject: [PATCH 29/75] ssdb --- app/Service/PurchaseLimitService.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/Service/PurchaseLimitService.php b/app/Service/PurchaseLimitService.php index cc581bb..2afa354 100644 --- a/app/Service/PurchaseLimitService.php +++ b/app/Service/PurchaseLimitService.php @@ -200,11 +200,8 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface public function ssdbPurchaseRecord($params) { $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - //添加领取记录到ssdb - $data = [ - $order_id,$coupon->user_id, - ]; - $ssdb->exec('multi_hset', SsdbKeysPrefix::COUPON_REBATE_LIST.$coupon->send_user_id, $data); + $ssdb->exec('set', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$params['user_id'].'_'.$params['good_id'], $params['order_id']); + $ssdb->exec('expire', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$params['user_id'].'_'.$params['good_id'],60); } public function test($params) From b2eabe8a4a877cffb1dcd485c606cf6b1efae139 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Tue, 25 Aug 2020 15:01:31 +0800 Subject: [PATCH 30/75] =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6=20=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=88=86=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/PurchaseLimitController.php | 19 -- app/Controller/ShopCarController.php | 39 ++++ app/Service/PurchaseLimitService.php | 168 ---------------- app/Service/PurchaseLimitServiceInterface.php | 4 - app/Service/ShopCarService.php | 185 ++++++++++++++++++ app/Service/ShopCarServiceInterface.php | 12 ++ config/autoload/dependencies.php | 1 + config/routes.php | 9 +- 8 files changed, 242 insertions(+), 195 deletions(-) create mode 100644 app/Controller/ShopCarController.php create mode 100644 app/Service/ShopCarService.php create mode 100644 app/Service/ShopCarServiceInterface.php diff --git a/app/Controller/PurchaseLimitController.php b/app/Controller/PurchaseLimitController.php index 591ce00..37870db 100644 --- a/app/Controller/PurchaseLimitController.php +++ b/app/Controller/PurchaseLimitController.php @@ -16,25 +16,6 @@ class PurchaseLimitController extends BaseController */ protected $purchaseLimitService; - - public function addShopCar() - { - $res = $this->purchaseLimitService->addShopCar($this->request->all()); - if (isset($res['error'])) { - return $this->result(ErrorCode::GOODS_FAILURE, '', $res['error']); - } - return $this->success($res); - } - - public function updateShopCar() - { - $res = $this->purchaseLimitService->updateShopCar($this->request->all()); - if (isset($res['error'])) { - return $this->result(ErrorCode::GOODS_FAILURE, '', $res['error']); - } - return $this->success($res); - } - public function getStoreIdByMarketId() { $res = $this->purchaseLimitService->getStoreIdByMarketId($this->request->all()); diff --git a/app/Controller/ShopCarController.php b/app/Controller/ShopCarController.php new file mode 100644 index 0000000..8c6cb35 --- /dev/null +++ b/app/Controller/ShopCarController.php @@ -0,0 +1,39 @@ +shopCarService->addShopCar($this->request->all()); + if (isset($res['error'])) { + return $this->result(ErrorCode::GOODS_FAILURE, '', $res['error']); + } + return $this->success($res); + } + + public function updateShopCar() + { + $res = $this->shopCarService->updateShopCar($this->request->all()); + if (isset($res['error'])) { + return $this->result(ErrorCode::GOODS_FAILURE, '', $res['error']); + } + return $this->success($res); + } + +} diff --git a/app/Service/PurchaseLimitService.php b/app/Service/PurchaseLimitService.php index 2afa354..7434bb0 100644 --- a/app/Service/PurchaseLimitService.php +++ b/app/Service/PurchaseLimitService.php @@ -15,174 +15,6 @@ use App\Constants\SsdbKeysPrefix; class PurchaseLimitService implements PurchaseLimitServiceInterface { - public function addShopCar($params) - { - //获取ssdb购买记录 - $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - $record_exists = $ssdb->exec('hexists',SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$params['user_id'], $params['good_id']); - if($record_exists) - { - $error = [ - 'error' => '特价商品每日只能购买一次' - ]; - return $error; - } - //获取主表商品表信息 - $goods = Goods::where([ - ['id','=',$params['good_id']], - ]) - ->select('is_max','restrict_num','box_money','inventory','money') - ->first(); - - //获取购物车该商品购买数量 - $num = ShopCar::where([ - ['user_id', $params['user_id']], - ['good_id', $params['good_id']], - ]) - ->sum('num'); - //限购检验 - if($goods->restrict_num > 0 && $goods->restrict_num <= $num) - { - $error = [ - 'error' => '超过商品限购数量' - ]; - return $error; - } - //获取规格表商品信息 - if($params['combination_id'] > 0) - { - $combination = Combination::where([ - ['id', '=', $params['combination_id']], - ]) - ->select('wm_money', 'number') - ->first(); - $inventory = $combination->number; - $money = $combination->wm_money; - }else{ - $inventory = $goods->inventory; - $money = $goods->money; - } - //库存校验 is_max 无限库存 - if($goods->is_max != Goods::INVENTORY_NOLIMIT && ($num + $params['num']) > $inventory) - { - $error = [ - 'error' => '库存不足' - ]; - return $error; - } - //更新购物车 - $exists_sql = ShopCar::where([ - ['user_id', '=', $params['user_id']], - ['good_id', '=', $params['good_id']], - ['market_id','=',$params['market_id']], - ['combination_id','=', $params['combination_id']], - ]); - if($params['combination_id'] > 0) { - $exists_sql->where('combination_id',$params['combination_id']); - } - $exists = $exists_sql->exists(); - if($exists) - { - $update = ShopCar::where([ - ['user_id', '=', $params['user_id']], - ['good_id', '=', $params['good_id']], - ['market_id','=',$params['market_id']], - ]); - if($params['combination_id'] > 0) { - $update->where('combination_id',$params['combination_id']); - } - $update->increment('num', $params['num']); - }else{ - $son_id = empty($params['son_id']) ? 0 : $params['son_id']; - $dr_id = empty($params['dr_id']) ? 0 : $params['dr_id']; - $combination_id = empty($params['combination_id']) ? 0 : $params['combination_id']; - $qg_name = empty($params['qg_name']) ? ' ' : $params['qg_name']; - $qg_logo = empty($params['qg_logo']) ? ' ' :$params['qg_logo']; - ShopCar::insert( - [ - 'market_id' => $params['market_id'], - 'good_id' => $params['good_id'], - 'store_id' => $params['store_id'], - 'user_id' => $params['user_id'], - 'combination_id' => $combination_id, - 'num' => $params['num'], - 'spec' => $params['spec'], - 'son_id' => $son_id, - 'dr_id' => $dr_id, - 'qg_name' => $qg_name, - 'qg_logo' => $qg_logo, - 'money' => $money, - 'box_money' => $goods->box_money, - ] - ); - } - return true; - // if($params['goods_id'] == 1561){ - // return false; - // }else{ - // return '加入购物车成功'; - // } - } - - public function updateShopCar($params) - { - if($params['num'] <= 0) - { - ShopCar::where('id',$params['id'])->delete(); - }else { - $shop_car = ShopCar::where('id',$params['id']) - ->select('good_id','user_id') - ->first(); - //获取主表商品表信息 - $goods = Goods::where([ - ['id','=',$shop_car['good_id']], - ]) - ->select('is_max','restrict_num','box_money','inventory','money') - ->first(); - //获取购物车该商品购买数量 - $num = ShopCar::where([ - ['user_id', $shop_car['user_id']], - ['good_id', $shop_car['good_id']], - ]) - ->sum('num'); - //限购检验 - if($goods->restrict_num > 0 && $goods->restrict_num <= $num) - { - $error = [ - 'error' => '超过商品限购数量' - ]; - return $error; - } - if ($shop_car['combination_id'] > 0) - { - $combination = Combination::where([ - ['id', '=', $shop_car['combination_id']], - ]) - ->select('wm_money', 'number') - ->first(); - $inventory = $combination->number; - }else{ - $inventory = $goods->inventory; - } - //库存校验 is_max 无限库存 - if($goods->is_max != Goods::INVENTORY_NOLIMIT && $params['num'] > $inventory) - { - $error = [ - 'error' => '库存不足' - ]; - return $error; - } - ShopCar::where('id',$params['id']) - ->update(['num' => $params['num']]); - return true; - } - // if($params['good_id'] == 1561){ - // return false; - // }else{ - // return '更新购物车成功'; - // } - } - public function getStoreIdByMarketId($params) { $res = [ diff --git a/app/Service/PurchaseLimitServiceInterface.php b/app/Service/PurchaseLimitServiceInterface.php index 3b0d66d..c2626c4 100644 --- a/app/Service/PurchaseLimitServiceInterface.php +++ b/app/Service/PurchaseLimitServiceInterface.php @@ -6,10 +6,6 @@ namespace App\Service; interface PurchaseLimitServiceInterface { - public function addShopCar($params); - - public function updateShopCar($params); - public function getStoreIdByMarketId($params); public function ssdbPurchaseRecord($params); diff --git a/app/Service/ShopCarService.php b/app/Service/ShopCarService.php new file mode 100644 index 0000000..7b20bc8 --- /dev/null +++ b/app/Service/ShopCarService.php @@ -0,0 +1,185 @@ +get(SSDBTask::class); + $record_exists = $ssdb->exec('hexists',SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$params['user_id'], $params['good_id']); + if($record_exists) + { + $error = [ + 'error' => '特价商品每日只能购买一次' + ]; + return $error; + } + //获取主表商品表信息 + $goods = Goods::where([ + ['id','=',$params['good_id']], + ]) + ->select('is_max','restrict_num','box_money','inventory','money') + ->first(); + + //获取购物车该商品购买数量 + $num = ShopCar::where([ + ['user_id', $params['user_id']], + ['good_id', $params['good_id']], + ]) + ->sum('num'); + //限购检验 + if($goods->restrict_num > 0 && $goods->restrict_num <= $num) + { + $error = [ + 'error' => '超过商品限购数量' + ]; + return $error; + } + //获取规格表商品信息 + if($params['combination_id'] > 0) + { + $combination = Combination::where([ + ['id', '=', $params['combination_id']], + ]) + ->select('wm_money', 'number') + ->first(); + $inventory = $combination->number; + $money = $combination->wm_money; + }else{ + $inventory = $goods->inventory; + $money = $goods->money; + } + //库存校验 is_max 无限库存 + if($goods->is_max != Goods::INVENTORY_NOLIMIT && ($num + $params['num']) > $inventory) + { + $error = [ + 'error' => '库存不足' + ]; + return $error; + } + //更新购物车 + $exists_sql = ShopCar::where([ + ['user_id', '=', $params['user_id']], + ['good_id', '=', $params['good_id']], + ['market_id','=',$params['market_id']], + ['combination_id','=', $params['combination_id']], + ]); + if($params['combination_id'] > 0) { + $exists_sql->where('combination_id',$params['combination_id']); + } + $exists = $exists_sql->exists(); + if($exists) + { + $update = ShopCar::where([ + ['user_id', '=', $params['user_id']], + ['good_id', '=', $params['good_id']], + ['market_id','=',$params['market_id']], + ]); + if($params['combination_id'] > 0) { + $update->where('combination_id',$params['combination_id']); + } + $update->increment('num', $params['num']); + }else{ + $son_id = empty($params['son_id']) ? 0 : $params['son_id']; + $dr_id = empty($params['dr_id']) ? 0 : $params['dr_id']; + $combination_id = empty($params['combination_id']) ? 0 : $params['combination_id']; + $qg_name = empty($params['qg_name']) ? ' ' : $params['qg_name']; + $qg_logo = empty($params['qg_logo']) ? ' ' :$params['qg_logo']; + ShopCar::insert( + [ + 'market_id' => $params['market_id'], + 'good_id' => $params['good_id'], + 'store_id' => $params['store_id'], + 'user_id' => $params['user_id'], + 'combination_id' => $combination_id, + 'num' => $params['num'], + 'spec' => $params['spec'], + 'son_id' => $son_id, + 'dr_id' => $dr_id, + 'qg_name' => $qg_name, + 'qg_logo' => $qg_logo, + 'money' => $money, + 'box_money' => $goods->box_money, + ] + ); + } + return true; + // if($params['goods_id'] == 1561){ + // return false; + // }else{ + // return '加入购物车成功'; + // } + } + + public function updateShopCar($params) + { + if($params['num'] <= 0) + { + ShopCar::where('id',$params['id'])->delete(); + }else { + $shop_car = ShopCar::where('id',$params['id']) + ->select('good_id','user_id') + ->first(); + //获取主表商品表信息 + $goods = Goods::where([ + ['id','=',$shop_car['good_id']], + ]) + ->select('is_max','restrict_num','box_money','inventory','money') + ->first(); + //获取购物车该商品购买数量 + $num = ShopCar::where([ + ['user_id', $shop_car['user_id']], + ['good_id', $shop_car['good_id']], + ]) + ->sum('num'); + //限购检验 + if($goods->restrict_num > 0 && $goods->restrict_num <= $num) + { + $error = [ + 'error' => '超过商品限购数量' + ]; + return $error; + } + if ($shop_car['combination_id'] > 0) + { + $combination = Combination::where([ + ['id', '=', $shop_car['combination_id']], + ]) + ->select('wm_money', 'number') + ->first(); + $inventory = $combination->number; + }else{ + $inventory = $goods->inventory; + } + //库存校验 is_max 无限库存 + if($goods->is_max != Goods::INVENTORY_NOLIMIT && $params['num'] > $inventory) + { + $error = [ + 'error' => '库存不足' + ]; + return $error; + } + ShopCar::where('id',$params['id']) + ->update(['num' => $params['num']]); + return true; + } + // if($params['good_id'] == 1561){ + // return false; + // }else{ + // return '更新购物车成功'; + // } + } +} \ No newline at end of file diff --git a/app/Service/ShopCarServiceInterface.php b/app/Service/ShopCarServiceInterface.php new file mode 100644 index 0000000..7691a71 --- /dev/null +++ b/app/Service/ShopCarServiceInterface.php @@ -0,0 +1,12 @@ + \App\JsonRpc\OrderService::class, \App\Service\FinancialRecordServiceInterface::class => \App\Service\FinancialRecordService::class, \App\Service\SeparateAccountsServiceInterface::class => \App\Service\SeparateAccountsService::class, + \App\Service\ShopCarServiceInterface::class => \App\Service\ShopCarService::class, ]; diff --git a/config/routes.php b/config/routes.php index 6ddd543..a0f385c 100644 --- a/config/routes.php +++ b/config/routes.php @@ -51,17 +51,18 @@ Router::addGroup('/v1/',function (){ Router::post('Order/addOnline', 'App\Controller\OrderController@addOnlineOrder'); Router::post('Order/addOffline', 'App\Controller\OrderController@addOfflineOrder'); Router::post('Order/onlineCancel', 'App\Controller\OrderController@onlineCancel'); + Router::post('Order/userComp', 'App\Controller\OrderController@userComp'); //小程序支付相关 Router::post('wxminipay/online', 'App\Controller\PaymentController@wxminiPayOnline'); Router::post('wxminipay/offline', 'App\Controller\PaymentController@wxminiPayOffline'); - Router::post('Order/userComp', 'App\Controller\OrderController@userComp'); + //加入购物车 - Router::post('PurchaseLimit/addShopCar', 'App\Controller\PurchaseLimitController@addShopCar'); - Router::post('PurchaseLimit/updateShopCar', 'App\Controller\PurchaseLimitController@updateShopCar'); + Router::post('ShopCar/addShopCar', 'App\Controller\ShopCarController@addShopCar'); + Router::post('ShopCar/updateShopCar', 'App\Controller\ShopCarController@updateShopCar'); Router::post('PurchaseLimit/test', 'App\Controller\PurchaseLimitController@test'); Router::post('PurchaseLimit/getStoreIdByMarketId', 'App\Controller\PurchaseLimitController@getStoreIdByMarketId'); - Router::post('Order/userComp', 'App\Controller\OrderController@userComp'); + },['middleware' => [\App\Middleware\Auth\ApiMiddleware::class]]); Router::addGroup('/wechat/',function () { From 54a5e11b86109d81b6918bd210af5aacf05c4d80 Mon Sep 17 00:00:00 2001 From: weigang Date: Tue, 25 Aug 2020 16:17:51 +0800 Subject: [PATCH 31/75] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=92=8C=E7=94=A8=E6=88=B7=E7=B1=BB=E5=9E=8B=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E3=80=81=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/FinancialRecord.php | 16 ++- app/Service/FinancialRecordService.php | 99 +++++++++++++++-- .../FinancialRecordServiceInterface.php | 101 ++++++++++++++++-- 3 files changed, 194 insertions(+), 22 deletions(-) diff --git a/app/Model/FinancialRecord.php b/app/Model/FinancialRecord.php index b56adbe..9da433e 100644 --- a/app/Model/FinancialRecord.php +++ b/app/Model/FinancialRecord.php @@ -23,15 +23,23 @@ class FinancialRecord extends Model * 总账 * USER_TYPE_LEDGER / -1 * - * 用户/商户账户 + * 用户 * USER_TYPE_USER / 1 * * MP用户账户,服务商、市场经理、服务站点等 * USER_TYPE_MP / 2 + * USER_TYPE_MM / 3 + * USER_TYPE_CS / 4 + * + * 商户账户 + * USER_TYPE_STORE / 5 */ const USER_TYPE_LEDGER = -1; const USER_TYPE_USER = 1; const USER_TYPE_MP = 2; + const USER_TYPE_MM = 3; + const USER_TYPE_CS = 4; + const USER_TYPE_STORE = 5; /** * 关联类型 @@ -44,9 +52,9 @@ class FinancialRecord extends Model /** * 流水类型,大的分类,<100是奖励分账等收入项 >=100是提现消费等支出项 */ - const MONEY_TYPE_PLAT_NEW_USER = 1; // 社区服务点新用户奖励(线上订单完成) - const MONEY_TYPE_FIRST_ORDER = 2; // 社区服务点新用户线上首单奖励(线上订单完成) - const MONEY_TYPE_OL_ORDER = 3; // 社区服务点用户线上订单分账(线上订单完成) + const MONEY_TYPE_CS_PLAT_NEW_USER = 1; // 社区服务点新用户奖励(线上订单完成) + const MONEY_TYPE_CS_FIRST_ORDER = 2; // 社区服务点新用户线上首单奖励(线上订单完成) + const MONEY_TYPE_CS_OL_ORDER = 3; // 社区服务点用户线上订单分账(线上订单完成) const MONEY_TYPE_STORE_PLAT_NEW_USER = 4; // 商户平台新用户奖励 const MONEY_TYPE_STORE_FIRST_ORDER = 5; // 商户当日首单奖励 const MONEY_TYPE_STORE_OL_ORDER_COMP = 6; // 商户线上订单完成收入 diff --git a/app/Service/FinancialRecordService.php b/app/Service/FinancialRecordService.php index 574de5c..992f949 100644 --- a/app/Service/FinancialRecordService.php +++ b/app/Service/FinancialRecordService.php @@ -58,7 +58,16 @@ class FinancialRecordService implements FinancialRecordServiceInterface /** * @inheritDoc */ - public function communityAwardByPlatNewUser($user_id, $source_id, $money, $user_type=2, $source_type=1, $money_type=1, $desc='新用户奖励', $comment='社区服务点') + public function communityAwardByPlatNewUser( + $user_id, + $source_id, + $money, + $user_type=FinancialRecord::USER_TYPE_CS, + $source_type=FinancialRecord::SOURCE_TYPE_ORDER, + $money_type=FinancialRecord::MONEY_TYPE_CS_PLAT_NEW_USER, + $desc='新用户奖励', + $comment='社区服务点' + ) { $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); // 维护社区服务点余额 @@ -73,7 +82,16 @@ class FinancialRecordService implements FinancialRecordServiceInterface /** * @inheritDoc */ - public function communityAwardByPlatNewUserFirstOLOrder($user_id, $source_id, $money, $user_type=2, $source_type=1, $money_type=2, $desc='新用户首单奖励', $comment='社区服务点') + public function communityAwardByPlatNewUserFirstOLOrder( + $user_id, + $source_id, + $money, + $user_type=FinancialRecord::USER_TYPE_CS, + $source_type=FinancialRecord::SOURCE_TYPE_ORDER, + $money_type=FinancialRecord::MONEY_TYPE_CS_FIRST_ORDER, + $desc='新用户首单奖励', + $comment='社区服务点' + ) { $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); // 维护社区服务点余额 @@ -88,7 +106,16 @@ class FinancialRecordService implements FinancialRecordServiceInterface /** * @inheritDoc */ - public function communitySeparateAccountsByOrderComp($user_id, $source_id, $money, $user_type=2, $source_type=1, $money_type=3, $desc='用户订单分成', $comment='社区服务点') + public function communitySeparateAccountsByOrderComp( + $user_id, + $source_id, + $money, + $user_type=FinancialRecord::USER_TYPE_CS, + $source_type=FinancialRecord::SOURCE_TYPE_ORDER, + $money_type=FinancialRecord::MONEY_TYPE_CS_OL_ORDER, + $desc='用户订单分成', + $comment='社区服务点' + ) { $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); // 维护社区服务点余额 @@ -104,7 +131,16 @@ class FinancialRecordService implements FinancialRecordServiceInterface /** * @inheritDoc */ - public function storeAwardByPlatNewUserOFLOrder($user_id, $source_id, $money, $user_type=1, $source_type=1, $money_type=4, $desc='新用户下单奖励', $comment='用户当面付商户奖励') + public function storeAwardByPlatNewUserOFLOrder( + $user_id, + $source_id, + $money, + $user_type=FinancialRecord::USER_TYPE_STORE, + $source_type=FinancialRecord::SOURCE_TYPE_ORDER, + $money_type=FinancialRecord::MONEY_TYPE_STORE_PLAT_NEW_USER, + $desc='新用户下单奖励', + $comment='用户当面付商户奖励' + ) { $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); // 同时维护钱包 @@ -116,7 +152,16 @@ class FinancialRecordService implements FinancialRecordServiceInterface /** * @inheritDoc */ - public function storeAwardByTodayFirstOFLOrder($user_id, $source_id, $money, $user_type=1, $source_type=1, $money_type=5, $desc='用户店铺首单奖励', $comment='用户当面付商户奖励') + public function storeAwardByTodayFirstOFLOrder( + $user_id, + $source_id, + $money, + $user_type=FinancialRecord::USER_TYPE_STORE, + $source_type=FinancialRecord::SOURCE_TYPE_ORDER, + $money_type=FinancialRecord::MONEY_TYPE_STORE_FIRST_ORDER, + $desc='用户店铺首单奖励', + $comment='用户当面付商户奖励' + ) { $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); // 同时维护钱包 @@ -147,7 +192,16 @@ class FinancialRecordService implements FinancialRecordServiceInterface /** * @inheritDoc */ - public function userByOFLOrderPaid($user_id, $source_id, $money, $user_type=1, $source_type=1, $money_type=100, $desc='用户下单(线下)', $comment='用户下单') + public function userByOFLOrderPaid( + $user_id, + $source_id, + $money, + $user_type=FinancialRecord::USER_TYPE_USER, + $source_type=FinancialRecord::SOURCE_TYPE_ORDER, + $money_type=FinancialRecord::MONEY_TYPE_USER_OFL_ORDER, + $desc='用户下单(线下)', + $comment='用户下单' + ) { $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); } @@ -155,7 +209,16 @@ class FinancialRecordService implements FinancialRecordServiceInterface /** * @inheritDoc */ - public function userByOLOrderPaid($user_id, $source_id, $money, $user_type=1, $source_type=1, $money_type=101, $desc='用户下单(线上)', $comment='用户下单') + public function userByOLOrderPaid( + $user_id, + $source_id, + $money, + $user_type=FinancialRecord::USER_TYPE_USER, + $source_type=FinancialRecord::SOURCE_TYPE_ORDER, + $money_type=FinancialRecord::MONEY_TYPE_USER_OL_ORDER, + $desc='用户下单(线上)', + $comment='用户下单' + ) { $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); } @@ -163,7 +226,16 @@ class FinancialRecordService implements FinancialRecordServiceInterface /** * @inheritDoc */ - public function storeByOLOrderComp($user_id, $source_id, $money, $user_type = 1, $source_type = 1, $money_type = 6, $desc = '线上外卖订单收入', $comment = '用户订单完成') + public function storeByOLOrderComp( + $user_id, + $source_id, + $money, + $user_type = FinancialRecord::USER_TYPE_STORE, + $source_type = FinancialRecord::SOURCE_TYPE_ORDER, + $money_type = FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_COMP, + $desc = '线上外卖订单收入', + $comment = '用户订单完成' + ) { $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); // 同时维护钱包 @@ -175,7 +247,16 @@ class FinancialRecordService implements FinancialRecordServiceInterface /** * @inheritDoc */ - public function storeByOFLOrderComp($user_id, $source_id, $money, $user_type = 1, $source_type = 1, $money_type = 7, $desc = '线下当面付订单收入', $comment = '用户订单完成') + public function storeByOFLOrderComp( + $user_id, + $source_id, + $money, + $user_type = FinancialRecord::USER_TYPE_STORE, + $source_type = FinancialRecord::SOURCE_TYPE_ORDER, + $money_type = FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP, + $desc = '线下当面付订单收入', + $comment = '用户订单完成' + ) { $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); } diff --git a/app/Service/FinancialRecordServiceInterface.php b/app/Service/FinancialRecordServiceInterface.php index 8a53628..a8f13be 100644 --- a/app/Service/FinancialRecordServiceInterface.php +++ b/app/Service/FinancialRecordServiceInterface.php @@ -2,6 +2,8 @@ namespace App\Service; +use App\Model\FinancialRecord; + interface FinancialRecordServiceInterface { @@ -17,7 +19,16 @@ interface FinancialRecordServiceInterface * @param string $desc * @return mixed */ - public function communityAwardByPlatNewUser($user_id, $source_id, $money, $user_type=2, $source_type=1, $money_type=1, $desc='新用户奖励', $comment=''); + public function communityAwardByPlatNewUser( + $user_id, + $source_id, + $money, + $user_type=FinancialRecord::USER_TYPE_CS, + $source_type=FinancialRecord::SOURCE_TYPE_ORDER, + $money_type=FinancialRecord::MONEY_TYPE_CS_PLAT_NEW_USER, + $desc='新用户奖励', + $comment='' + ); /** * 社区服务点新用户线上首单奖励 @@ -31,7 +42,16 @@ interface FinancialRecordServiceInterface * @param string $desc * @return mixed */ - public function communityAwardByPlatNewUserFirstOLOrder($user_id, $source_id, $money, $user_type=2, $source_type=1, $money_type=2, $desc='新用户首单奖励', $comment=''); + public function communityAwardByPlatNewUserFirstOLOrder( + $user_id, + $source_id, + $money, + $user_type=FinancialRecord::USER_TYPE_CS, + $source_type=FinancialRecord::SOURCE_TYPE_ORDER, + $money_type=FinancialRecord::MONEY_TYPE_CS_FIRST_ORDER, + $desc='新用户首单奖励', + $comment='' + ); /** * 社区服务点用户订单完成分账 @@ -45,7 +65,16 @@ interface FinancialRecordServiceInterface * @param string $desc * @return mixed */ - public function communitySeparateAccountsByOrderComp($user_id, $source_id, $money, $user_type=2, $source_type=1, $money_type=3, $desc='用户订单分成', $comment=''); + public function communitySeparateAccountsByOrderComp( + $user_id, + $source_id, + $money, + $user_type=FinancialRecord::USER_TYPE_CS, + $source_type=FinancialRecord::SOURCE_TYPE_ORDER, + $money_type=FinancialRecord::MONEY_TYPE_CS_OL_ORDER, + $desc='用户订单分成', + $comment='' + ); /** * 收支总账 @@ -71,7 +100,16 @@ interface FinancialRecordServiceInterface * @param string $comment * @return mixed */ - public function storeAwardByPlatNewUserOFLOrder($user_id, $source_id, $money, $user_type=1, $source_type=1, $money_type=4, $desc='新用户下单奖励', $comment=''); + public function storeAwardByPlatNewUserOFLOrder( + $user_id, + $source_id, + $money, + $user_type=FinancialRecord::USER_TYPE_STORE, + $source_type=FinancialRecord::SOURCE_TYPE_ORDER, + $money_type=FinancialRecord::MONEY_TYPE_STORE_PLAT_NEW_USER, + $desc='新用户下单奖励', + $comment='' + ); /** * 商户线下用户支付用户当日首单奖励 @@ -85,7 +123,16 @@ interface FinancialRecordServiceInterface * @param string $comment * @return mixed */ - public function storeAwardByTodayFirstOFLOrder($user_id, $source_id, $money, $user_type=1, $source_type=1, $money_type=5, $desc='用户店铺首单奖励', $comment=''); + public function storeAwardByTodayFirstOFLOrder( + $user_id, + $source_id, + $money, + $user_type=FinancialRecord::USER_TYPE_STORE, + $source_type=FinancialRecord::SOURCE_TYPE_ORDER, + $money_type=FinancialRecord::MONEY_TYPE_STORE_FIRST_ORDER, + $desc='用户店铺首单奖励', + $comment='' + ); /** * 用户线下订单支付流水 @@ -99,7 +146,16 @@ interface FinancialRecordServiceInterface * @param string $comment * @return mixed */ - public function userByOFLOrderPaid($user_id, $source_id, $money, $user_type=1, $source_type=1, $money_type=100, $desc='用户下单(线下)', $comment=''); + public function userByOFLOrderPaid( + $user_id, + $source_id, + $money, + $user_type=FinancialRecord::USER_TYPE_USER, + $source_type=FinancialRecord::SOURCE_TYPE_ORDER, + $money_type=FinancialRecord::MONEY_TYPE_USER_OFL_ORDER, + $desc='用户下单(线下)', + $comment='' + ); /** * 用户线上订单支付流水 @@ -113,7 +169,16 @@ interface FinancialRecordServiceInterface * @param string $comment * @return mixed */ - public function userByOLOrderPaid($user_id, $source_id, $money, $user_type=1, $source_type=1, $money_type=101, $desc='用户下单(线上)', $comment=''); + public function userByOLOrderPaid( + $user_id, + $source_id, + $money, + $user_type=FinancialRecord::USER_TYPE_USER, + $source_type=FinancialRecord::SOURCE_TYPE_ORDER, + $money_type=FinancialRecord::MONEY_TYPE_USER_OL_ORDER, + $desc='用户下单(线上)', + $comment='' + ); /** * 商户线上订单完成收入流水 @@ -127,7 +192,16 @@ interface FinancialRecordServiceInterface * @param string $comment * @return mixed */ - public function storeByOLOrderComp($user_id, $source_id, $money, $user_type=1, $source_type=1, $money_type=6, $desc='线上外卖订单收入', $comment=''); + public function storeByOLOrderComp( + $user_id, + $source_id, + $money, + $user_type = FinancialRecord::USER_TYPE_STORE, + $source_type = FinancialRecord::SOURCE_TYPE_ORDER, + $money_type = FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_COMP, + $desc='线上外卖订单收入', + $comment='' + ); /** * 商户线下订单完成收入流水 @@ -141,6 +215,15 @@ interface FinancialRecordServiceInterface * @param string $comment * @return mixed */ - public function storeByOFLOrderComp($user_id, $source_id, $money, $user_type=1, $source_type=1, $money_type=7, $desc='线下当面付订单收入', $comment=''); + public function storeByOFLOrderComp( + $user_id, + $source_id, + $money, + $user_type = FinancialRecord::USER_TYPE_STORE, + $source_type = FinancialRecord::SOURCE_TYPE_ORDER, + $money_type = FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP, + $desc='线下当面付订单收入', + $comment='' + ); } \ No newline at end of file From c3ed8900ec5e647a42e3d8e77632bca0b4b6e0fd Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Tue, 25 Aug 2020 16:46:49 +0800 Subject: [PATCH 32/75] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E9=80=80=E6=AC=BE?= =?UTF-8?q?=E5=A4=84=E7=90=86--=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/LogLabel.php | 5 + app/Controller/NotifyPayRefundController.php | 107 ++++++++++++++++++ app/Model/CouponRec.php | 9 +- app/Model/CouponUserRec.php | 18 --- app/Model/FinancialRecord.php | 3 + app/Service/CouponService.php | 48 +++++++- app/Service/CouponServiceInterface.php | 1 + app/Service/OrderService.php | 106 +++++++++++------ ...yRefundService.php => WxRefundService.php} | 21 ++-- ...rface.php => WxRefundServiceInterface.php} | 2 +- 10 files changed, 252 insertions(+), 68 deletions(-) create mode 100644 app/Controller/NotifyPayRefundController.php delete mode 100644 app/Model/CouponUserRec.php rename app/Service/{PayRefundService.php => WxRefundService.php} (64%) rename app/Service/{PayRefundServiceInterface.php => WxRefundServiceInterface.php} (68%) diff --git a/app/Constants/LogLabel.php b/app/Constants/LogLabel.php index 072a6f7..8807da4 100644 --- a/app/Constants/LogLabel.php +++ b/app/Constants/LogLabel.php @@ -54,4 +54,9 @@ class LogLabel extends AbstractConstants */ const OFFLINE_PAID_LOG = 'offline_paid_log'; + /** + * @Message("Pay refund Log Label") + */ + const PAY_NOTIFY_REFUND = 'notify_refund'; + } diff --git a/app/Controller/NotifyPayRefundController.php b/app/Controller/NotifyPayRefundController.php new file mode 100644 index 0000000..1f1cb76 --- /dev/null +++ b/app/Controller/NotifyPayRefundController.php @@ -0,0 +1,107 @@ +request->getQueryParams(); + $post = $this->request->getParsedBody(); + $cookie = $this->request->getCookieParams(); + $files = $this->request->getUploadedFiles(); + $server = $this->request->getServerParams(); + $xml = $this->request->getBody()->getContents(); + + $app['request'] = new Request($get,$post,[],$cookie,$files,$server,$xml); + + /* 通知回调,进行业务处理 */ + $response = $app->handleRefundedNotify(function ($message, $fail) use ($app) { + + try { + /* --- 退款失败 --- */ + if ( + empty($message) + || !isset($message['result_code']) + || $message['result_code'] != 'SUCCESS' + ) { + // 错误日志 + $this->log->event( + LogLabel::PAY_NOTIFY_REFUND, + $message + ); + $fail('Unknown error but FAIL'); + } + + /* --- 退款成功 --- */ + // 退款返还优惠券 + $this->couponService->orderRefundCoupon($message['out_trade_no']); + // 添加用户的流水 + $orderMain = OrderMain::select('id','global_order_id')->where('code',$message['out_trade_no'])->first(); + + + } catch (Exception $e) { + + $this->log->event( + LogLabel::PAY_NOTIFY_REFUND, + ['exception_fail' => $e->getMessage()] + ); + $fail('Exception'); + } + }); + + return $this->response + ->withHeader('Content-Type', 'text/xml') + ->withStatus(200) + ->withBody(new SwooleStream($response->getContent())); + } +} \ No newline at end of file diff --git a/app/Model/CouponRec.php b/app/Model/CouponRec.php index 9e6e3e4..3a9cc62 100644 --- a/app/Model/CouponRec.php +++ b/app/Model/CouponRec.php @@ -6,8 +6,15 @@ use App\Model\Model; class CouponRec extends Model { - protected $table = 'ims_system_coupon_user_receive'; + /* 状态 */ + // 未使用 + const STATE_UNUSED = 0; + // 使用部分 + const STATE_SOME = 1; + // 已用完 + const STATE_FINISH = 2; + protected $table = 'ims_system_coupon_user_receive'; public function coupon() { diff --git a/app/Model/CouponUserRec.php b/app/Model/CouponUserRec.php deleted file mode 100644 index 25afd2f..0000000 --- a/app/Model/CouponUserRec.php +++ /dev/null @@ -1,18 +0,0 @@ -select('id','system_coupon_id','user_id','number','user_receive_id') + ->where('global_order_id',$global_order_id) + ->where('status',CouponUserUse::COUPON_USE_STATE_USED) + ->select(); + if(!empty($couponUse)){ + foreach($couponUses as $use){ + $use->status = CouponUserUse::COUPON_USE_STATE_USED; + $use->return_time = $time; + $use->update_time = $time; + $res = $use->save(); + + $couponReceive = CouponRec::query() + ->where('id',$use->user_receive_id) + ->whereRaw('number >= number_remain+'.$use->number) + ->update([ + 'number_remain' => Db::raw('number_remain+'.$use->number), + 'status' => Db::raw('IF(number=number_remain,' . CouponRec::STATE_UNUSED . ',' . CouponRec::STATE_SOME . ')'), + 'update_time' => $time + ]); + + $clearUseRedis = $this->clearTodayCouponUsed($use->user_id,$use->system_coupon_id); + } + } + + Db::commit(); + return true; + } catch (Exception $e) { + + $this->log->event(LogLabel::ORDER_LOG, ['msg'=> '订单退款','exception' => $e->getMessage()]); + Db::rollBack(); + return false; + } + return true; } } \ No newline at end of file diff --git a/app/Service/CouponServiceInterface.php b/app/Service/CouponServiceInterface.php index e4155d7..e3224f4 100644 --- a/app/Service/CouponServiceInterface.php +++ b/app/Service/CouponServiceInterface.php @@ -29,4 +29,5 @@ interface CouponServiceInterface public function refundOrderCoupons($order_id,$user_id); public function clearTodayCouponUsed($userId, $couponId); + public function orderRefundCoupon($global_order_id); } diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index 8d76e7c..99c7311 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -5,7 +5,7 @@ namespace App\Service; use App\Commons\Log; use App\Constants\LogLabel; use App\Model\Coupon; -use App\Model\CouponUserRec; +use App\Model\CouponRec; use App\Model\CouponUserUse; use App\Model\Goods; use App\Model\Order; @@ -19,6 +19,7 @@ use Hyperf\DbConnection\Db; use Hyperf\Snowflake\IdGeneratorInterface; use Hyperf\Utils\ApplicationContext; use Hyperf\Di\Annotation\Inject; +use App\Service\WxRefundServiceInterface; class OrderService implements OrderServiceInterface { @@ -34,6 +35,12 @@ class OrderService implements OrderServiceInterface */ protected $couponService; + /** + * @Inject + * @var WxRefundServiceInterface + */ + protected $wxRefundService; + /** * @inheritDoc */ @@ -280,7 +287,7 @@ class OrderService implements OrderServiceInterface } // 处理红包的使用 - $canUseCoupons = CouponUserRec::select(['id', 'user_id', 'number', 'number_remain', 'system_coupon_user_id']) + $canUseCoupons = CouponRec::select(['id', 'user_id', 'number', 'number_remain', 'system_coupon_user_id']) ->whereIn('id', $receiveCouponIds) ->get()->toArray(); if (is_array($canUseCoupons)&&!empty($canUseCoupons)) { @@ -312,7 +319,7 @@ class OrderService implements OrderServiceInterface $status = 0; } - $upRes = CouponUserRec::query()->where(['id' => $coupon['id']])->update(['number_remain' => $numberRemain, 'status' => $status]); + $upRes = CouponRec::query()->where(['id' => $coupon['id']])->update(['number_remain' => $numberRemain, 'status' => $status]); if (!$upRes) { Db::rollBack(); @@ -716,14 +723,16 @@ class OrderService implements OrderServiceInterface /** * @inheritDoc */ - public function onlineRefund($global_order_id){ + public function onlineRefund($global_order_id) + { Db::beginTransaction(); try { $time = time(); // 主订单状态更新 $orderMain = OrderMain::query() - ->where(['global_order_id' => $global_order_id, 'state' => OrderMain::ORDER_STATE_DELIVERY]) + ->select('id','global_order_id','state','pay_type') + ->where(['global_order_id' => $global_order_id, 'state' => OrderMain::ORDER_STATE_REFUNDING]) ->first(); if (empty($orderMain)) { @@ -736,40 +745,26 @@ class OrderService implements OrderServiceInterface // 子订单状态更新 $upChild = Order::query() - ->where(['order_main_id' => $orderMain->id]) + ->where('order_main_id' , $orderMain->id) + ->where('state',OrderMain::ORDER_STATE_REFUNDING) ->update(['state' => OrderMain::ORDER_STATE_REFUNDED]); - - /* 退还优惠券 */ - // 先查询是否正常使用优惠券 - // 修改状态,退还领取记录库存,删除ssdb缓存 - $couponUses = CouponUserUse::query() - ->select('id','system_coupon_id','user_id','number','user_receive_id') - ->where('order_main_id',$orderMain->id) - ->where('status',CouponUserUse::COUPON_USE_STATE_USED) - ->select(); - if(!empty($couponUse)){ - foreach($couponUses as $use){ - $use->status = CouponUserUse::COUPON_USE_STATE_USED; - $use->return_time = $time; - $use->update_time = $time; - $use->save(); - - $couponReceive = CouponUserRec::query() - ->where('id',$use->user_receive_id) - ->whereRaw('number >= number_remain+'.$use->number) - ->update([ - 'number_remain' => Db::raw('number_remain+'.$use->number), - 'status' => Db::raw('IF(number=number_remain,' . CouponUserRec::STATE_UNUSED . ',' . CouponUserRec::STATE_SOME . ')'), - 'update_time' => $time - ]); - - $clearUseRedis = $this->couponService->clearTodayCouponUsed($use->user_id,$use->system_coupon_id); - } + if(empty($upChild)){ + Db::rollBack(); + return false; } - // 退还订单金额到用户微信余额 + if($orderMain->pay_type == OrderMain::ORDER_PAY_WX){ + // 微信支付 微信退款 + $refundRes = $this->wxRefundService->wxPayRefund($global_order_id); + }else if($orderMain->pay_type == OrderMain::ORDER_PAY_BALANCE){ + // 余额支付 退款到用户余额 + // 返还优惠券 + $this->couponService->orderRefundCoupon($global_order_id); + // 添加用户流水 + } + Db::commit(); return true; } catch (Exception $e) { @@ -780,4 +775,47 @@ class OrderService implements OrderServiceInterface } } + /** + * 订单退款失败 + * 回退订单状态 + */ + public function onlineRefundFail($global_order_id) + { + Db::beginTransaction(); + try { + + $time = time(); + // 主订单状态更新 + $orderMain = OrderMain::query() + ->select('id','global_order_id','state','pay_type') + ->where(['global_order_id' => $global_order_id, 'state' => OrderMain::ORDER_STATE_REFUNDED]) + ->first(); + + if (empty($orderMain)) { + Db::rollBack(); + return false; + } + + $orderMain->state = OrderMain::ORDER_STATE_REFUNDING; + $upOrderMain = $orderMain->save(); + + // 子订单状态更新 + $upChild = Order::query() + ->where('order_main_id' , $orderMain->id) + ->where('state',OrderMain::ORDER_STATE_REFUNDED) + ->update(['state' => OrderMain::ORDER_STATE_REFUNDING]); + if(empty($upChild)){ + Db::rollBack(); + return false; + } + + Db::commit(); + return true; + } catch (Exception $e) { + + $this->log->event(LogLabel::ORDER_LOG, ['msg'=> '订单退款失败时处理状态9->8','exception' => $e->getMessage()]); + Db::rollBack(); + return false; + } + } } \ No newline at end of file diff --git a/app/Service/PayRefundService.php b/app/Service/WxRefundService.php similarity index 64% rename from app/Service/PayRefundService.php rename to app/Service/WxRefundService.php index 27bd0d4..b7e5c40 100644 --- a/app/Service/PayRefundService.php +++ b/app/Service/WxRefundService.php @@ -7,7 +7,7 @@ use EasyWeChat\Factory; use Hyperf\DbConnection\Db; use App\Constants\ErrorCode; -class PayRefundService implements PayRefundServiceInterface +class WxRefundService implements WxRefundServiceInterface { /** * 微信支付退款 @@ -18,29 +18,24 @@ class PayRefundService implements PayRefundServiceInterface $app = Factory::payment($config); $app['guzzle_handler'] = CoroutineHandler::class; - $result = [ - 'status' => 0, - 'msg' => '退款成功' - ]; - // 查询订单 $orderMain = OrderMain::query() - ->select('id','code','order_num','money','state') + ->select('id','global_order_id','order_num','money','state') ->where('global_order_id',$global_order_id) ->where('pay_type',OrderMain::ORDER_PAY_WX) ->where(Db::raw('refund_time is null')) ->first(); if(empty($orderMain)){ - return ['status'=>1, 'msg'=>'订单不存在或已退款']; + return false; } - $optional = []; + ; $result = $app->refund->byOutTradeNumber( - $orderMain->code, - $orderMain->code, - $orderMain->money * 100, + $orderMain->global_order_id, + $orderMain->global_order_id, $orderMain->money * 100, - $optional + $orderMain->money * 100 ); + return $result; } diff --git a/app/Service/PayRefundServiceInterface.php b/app/Service/WxRefundServiceInterface.php similarity index 68% rename from app/Service/PayRefundServiceInterface.php rename to app/Service/WxRefundServiceInterface.php index 7ca1de1..096c055 100644 --- a/app/Service/PayRefundServiceInterface.php +++ b/app/Service/WxRefundServiceInterface.php @@ -2,7 +2,7 @@ namespace App\Service; -interface PayRefundServiceInterface +interface WxRefundServiceInterface { public function wxPayRefund($global_order_id); } \ No newline at end of file From aeb45f7d21630515a279396930e9990439c2f2e0 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Tue, 25 Aug 2020 17:29:10 +0800 Subject: [PATCH 33/75] =?UTF-8?q?=E4=B8=8B=E5=8D=95=E6=88=90=E5=8A=9F=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=89=B9=E4=BB=B7=E5=95=86=E5=93=81=E8=B4=AD?= =?UTF-8?q?=E4=B9=B0=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/PurchaseLimitController.php | 6 ++++++ app/Service/CouponService.php | 18 +++++++++++++----- app/Service/CouponServiceInterface.php | 2 +- app/Service/OrderService.php | 15 +++++++++++---- app/Service/PurchaseLimitService.php | 16 ++++++++++++---- app/Service/PurchaseLimitServiceInterface.php | 2 +- app/Service/ShopCarService.php | 2 +- config/routes.php | 2 +- 8 files changed, 46 insertions(+), 17 deletions(-) diff --git a/app/Controller/PurchaseLimitController.php b/app/Controller/PurchaseLimitController.php index 37870db..0dd222c 100644 --- a/app/Controller/PurchaseLimitController.php +++ b/app/Controller/PurchaseLimitController.php @@ -22,6 +22,12 @@ class PurchaseLimitController extends BaseController return $this->success($res); } + public function ssdbPurchaseRecord() + { + $res = $this->purchaseLimitService->ssdbPurchaseRecord($this->request->all(),214); + return $this->success($res); + } + public function test() { $res = $this->purchaseLimitService->test($this->request->all()); diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index c5cb7bd..e0469f1 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -226,13 +226,18 @@ class CouponService implements CouponServiceInterface * @param $order_id * @return bool */ - public function refundOrderCoupons($order_id,$user_id){ + public function refundOrderCoupons($order_id){ $coupon = CouponUserUse::where([ - ['order_main_id','=',$order_id], - ['status','=',CouponUserUse::COUPON_USE_STATE_USED], - ]) + ['order_main_id','=',$order_id], + ['status','=',CouponUserUse::COUPON_USE_STATE_USED], + ]) ->select('id','user_receive_id','number') ->first(); + + if (empty($coupon)) { + return ''; + } + // 返回用户优惠券数量并更新状态 $res = Db::update("UPDATE ims_system_coupon_user_receive SET number_remain=number_remain+{$coupon->number}, status=IF(number=number_remain,0,1), update_time=".time()."" ." WHERE id={$coupon->user_receive_id} AND number>=(number_remain+{$coupon->number})"); @@ -249,9 +254,12 @@ class CouponService implements CouponServiceInterface ]); //删除当日 redis 使用记录缓存 + $order_main = OrderMain::where('id',$order_id) + ->select('global_order_id','user_id') + ->first(); $redis = ApplicationContext::getContainer()->get(Redis::class); $remRes = $redis->sRem( - 'coupon_'.date('Ymd').'_used_'.$user_id, + 'coupon_'.date('Ymd').'_used_'.$order_main->user_id, $coupon->system_coupon_id ); return $res; diff --git a/app/Service/CouponServiceInterface.php b/app/Service/CouponServiceInterface.php index e4155d7..5220320 100644 --- a/app/Service/CouponServiceInterface.php +++ b/app/Service/CouponServiceInterface.php @@ -27,6 +27,6 @@ interface CouponServiceInterface */ public function getOrderCanUseCoupons($orderAmount, $marketId, $userId, $fields=[], $type=1, $storeTypeIds=[0]); - public function refundOrderCoupons($order_id,$user_id); + public function refundOrderCoupons($order_id); public function clearTodayCouponUsed($userId, $couponId); } diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index 8d76e7c..afd19fc 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -34,6 +34,12 @@ class OrderService implements OrderServiceInterface */ protected $couponService; + /** + * @Inject + * @var PurchaseLimitServiceInterface + */ + protected $purchaseLimitService; + /** * @inheritDoc */ @@ -271,6 +277,9 @@ class OrderService implements OrderServiceInterface return '订单商品异常'; } + //判断是否有购买特价商品 + $this->purchaseLimitService->ssdbPurchaseRecord($orderGoods,$data['user_id'],$dataMain['global_order_id']); + // 修改总订单金额,金额是计算来的 // TODO 这部分其实可以结合处理优化一下,循环前后关联处理太多 $updateOrderMain = OrderMain::query()->where(['id' => $orderMainId])->update(['money' => $orderAmountTotal, 'total_money' => $dataMain['money']]); @@ -705,12 +714,10 @@ class OrderService implements OrderServiceInterface * @inheritDoc */ public function onlineCancel($order_id){ - $order_main = OrderMain::where('id',$order_id) - ->select('global_order_id','user_id') - ->first(); OrderMain::where('id',$order_id) ->update(['state' => OrderMain::ORDER_STATE_CANCEL]); - $res = $this->couponService->refundOrderCoupons($order_id,$order_main->user_id); + //撤销redis 用券记录 + $res = $this->couponService->refundOrderCoupons($order_id); return $res; } /** diff --git a/app/Service/PurchaseLimitService.php b/app/Service/PurchaseLimitService.php index 7434bb0..2b84faa 100644 --- a/app/Service/PurchaseLimitService.php +++ b/app/Service/PurchaseLimitService.php @@ -29,11 +29,19 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface return $res; } - public function ssdbPurchaseRecord($params) + public function ssdbPurchaseRecord($data,$user_id,$global_order_id) { - $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - $ssdb->exec('set', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$params['user_id'].'_'.$params['good_id'], $params['order_id']); - $ssdb->exec('expire', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$params['user_id'].'_'.$params['good_id'],60); + foreach ($data as $k => $v){ + if($v['money'] == 0.01){ + //添加特价商品购买记录到ssdb + $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); + $ssdb->exec('set', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$user_id.'_'.$v['good_id'], $global_order_id); + $end_timestamp = strtotime(date('Y-m-d').'23:59:59'); + $end_time = $end_timestamp - time(); + $ssdb->exec('expire', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$user_id.'_'.$v['good_id'],$end_time); + } + } + return true; } public function test($params) diff --git a/app/Service/PurchaseLimitServiceInterface.php b/app/Service/PurchaseLimitServiceInterface.php index c2626c4..8811fc6 100644 --- a/app/Service/PurchaseLimitServiceInterface.php +++ b/app/Service/PurchaseLimitServiceInterface.php @@ -8,7 +8,7 @@ interface PurchaseLimitServiceInterface { public function getStoreIdByMarketId($params); - public function ssdbPurchaseRecord($params); + public function ssdbPurchaseRecord($params,$user_id,$global_order_id); public function test($params); } \ No newline at end of file diff --git a/app/Service/ShopCarService.php b/app/Service/ShopCarService.php index 7b20bc8..a739846 100644 --- a/app/Service/ShopCarService.php +++ b/app/Service/ShopCarService.php @@ -19,7 +19,7 @@ class ShopCarService implements ShopCarServiceInterface { //获取ssdb购买记录 $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - $record_exists = $ssdb->exec('hexists',SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$params['user_id'], $params['good_id']); + $record_exists = $ssdb->exec('get',PURCHASE_RECORD. date('Ymd') .'_'.$params['user_id'].'_'.$params['good_id']); if($record_exists) { $error = [ diff --git a/config/routes.php b/config/routes.php index a0f385c..637d5ac 100644 --- a/config/routes.php +++ b/config/routes.php @@ -56,7 +56,7 @@ Router::addGroup('/v1/',function (){ //小程序支付相关 Router::post('wxminipay/online', 'App\Controller\PaymentController@wxminiPayOnline'); Router::post('wxminipay/offline', 'App\Controller\PaymentController@wxminiPayOffline'); - + //加入购物车 Router::post('ShopCar/addShopCar', 'App\Controller\ShopCarController@addShopCar'); Router::post('ShopCar/updateShopCar', 'App\Controller\ShopCarController@updateShopCar'); From 472108ba0f2ca95539363e1d7b53124c8975484d Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Tue, 25 Aug 2020 17:57:28 +0800 Subject: [PATCH 34/75] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E9=80=80=E6=AC=BE--?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=8C-=E6=B5=8B=E8=AF=951?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/NotifyPayRefundController.php | 38 +++++++------------ app/Model/FinancialRecord.php | 3 +- app/Model/Users.php | 6 +++ app/Service/FinancialRecordService.php | 18 +++++++++ .../FinancialRecordServiceInterface.php | 23 +++++++++++ app/Service/OrderService.php | 28 +++++++++++--- app/Service/UserService.php | 19 ++++++++++ app/Service/UserServiceInterface.php | 9 +++++ app/Service/WxRefundService.php | 3 +- 9 files changed, 114 insertions(+), 33 deletions(-) diff --git a/app/Controller/NotifyPayRefundController.php b/app/Controller/NotifyPayRefundController.php index 1f1cb76..b704d47 100644 --- a/app/Controller/NotifyPayRefundController.php +++ b/app/Controller/NotifyPayRefundController.php @@ -6,19 +6,11 @@ use App\Constants\LogLabel; use App\Model\OrderMain; -use App\Model\Users; -use App\Service\CouponRebateServiceInterface; -use App\Service\DeviceServiceInterface; -use App\Service\FeiePrintServiceInterface; -use App\Service\MiniprogramServiceInterface; -use App\Service\MqttServiceInterface; + use App\Service\OrderServiceInterface; -use App\Service\SeparateAccountsServiceInterface; -use App\Service\UserServiceInterface; +use App\Service\FinancialRecordServiceInterface; use EasyWeChat\Factory; -use Hyperf\DbConnection\Db; use Hyperf\Guzzle\CoroutineHandler; -use Exception; use Hyperf\Di\Annotation\Inject; use Hyperf\HttpMessage\Stream\SwooleStream; use Symfony\Component\HttpFoundation\Request; @@ -30,15 +22,9 @@ class NotifyPayRefundController extends BaseController /** * @Inject - * @var UserServiceInterface + * @var FinancialRecordServiceInterface */ - protected $userService; - - /** - * @Inject - * @var CouponRebateServiceInterface - */ - protected $couponRebateService; + protected $financialService; /** * @Inject @@ -83,13 +69,17 @@ class NotifyPayRefundController extends BaseController } /* --- 退款成功 --- */ - // 退款返还优惠券 - $this->couponService->orderRefundCoupon($message['out_trade_no']); + // 退款返还优惠券 + $this->couponService->orderRefundCoupon($message['out_trade_no']); // 添加用户的流水 - $orderMain = OrderMain::select('id','global_order_id')->where('code',$message['out_trade_no'])->first(); - - - } catch (Exception $e) { + $orderMain = OrderMain::select('id','global_order_id','money','user_id') + ->where('global_order_id',$message['out_trade_no']) + ->where('state',OrderMain::ORDER_STATE_REFUNDED) + ->first(); + if(!empty($orderMain)){ + $this->financialService->userByOLOrderRefund($orderMain->user_id, $orderMain->global_order_id, $orderMain->money); + } + } catch (\Exception $e) { $this->log->event( LogLabel::PAY_NOTIFY_REFUND, diff --git a/app/Model/FinancialRecord.php b/app/Model/FinancialRecord.php index 52ae8a2..2068055 100644 --- a/app/Model/FinancialRecord.php +++ b/app/Model/FinancialRecord.php @@ -59,8 +59,7 @@ class FinancialRecord extends Model const MONEY_TYPE_STORE_FIRST_ORDER = 5; // 商户当日首单奖励 const MONEY_TYPE_STORE_OL_ORDER_COMP = 6; // 商户线上订单完成收入 const MONEY_TYPE_STORE_OFL_ORDER_COMP = 7; // 商户线下订单完成收入 - - const MONEY_TYPE_USER_OL_ORDER_REFUND = 8; // 商户线下订单完成收入 + const MONEY_TYPE_USER_OL_ORDER_REFUND = 8; // 用户线上订单退款 const MONEY_TYPE_USER_OFL_ORDER = 100; // 用户线下支付订单 const MONEY_TYPE_USER_OL_ORDER = 101; // 用户线上支付订单 diff --git a/app/Model/Users.php b/app/Model/Users.php index 32cff4d..9ae2733 100644 --- a/app/Model/Users.php +++ b/app/Model/Users.php @@ -4,6 +4,12 @@ namespace App\Model; class Users extends Model { + // 用户账户(钱包)操作 增 + const WALLET_TYPE_INC = 1; + // 用户账户(钱包)操作 减 + const WALLET_TYPE_DEC = 2; + protected $table = 'ims_cjdc_user'; + public $timestamps = false; } \ No newline at end of file diff --git a/app/Service/FinancialRecordService.php b/app/Service/FinancialRecordService.php index 992f949..fe6a452 100644 --- a/app/Service/FinancialRecordService.php +++ b/app/Service/FinancialRecordService.php @@ -260,4 +260,22 @@ class FinancialRecordService implements FinancialRecordServiceInterface { $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); } + + /** + * @inheritDoc + * 订单退款(线上) + */ + public function userByOLOrderRefund( + $user_id, + $source_id, + $money, + $user_type = FinancialRecord::USER_TYPE_USER, + $source_type = FinancialRecord::SOURCE_TYPE_ORDER, + $money_type = FinancialRecord::MONEY_TYPE_USER_OL_ORDER_REFUND, + $desc = '线上订单退款', + $comment = '线上订单退款到微信' + ) + { + $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); + } } \ No newline at end of file diff --git a/app/Service/FinancialRecordServiceInterface.php b/app/Service/FinancialRecordServiceInterface.php index a8f13be..6c71e5b 100644 --- a/app/Service/FinancialRecordServiceInterface.php +++ b/app/Service/FinancialRecordServiceInterface.php @@ -226,4 +226,27 @@ interface FinancialRecordServiceInterface $comment='' ); + /** + * 线上订单退款流水 + * @param $user_id + * @param $source_id + * @param $money + * @param int $user_type + * @param int $source_type + * @param int $money_type + * @param string $desc + * @param string $comment + * @return mixed + */ + public function userByOLOrderRefund( + $user_id, + $source_id, + $money, + $user_type = FinancialRecord::USER_TYPE_STORE, + $source_type = FinancialRecord::SOURCE_TYPE_ORDER, + $money_type = FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP, + $desc='线上订单退款', + $comment='' + ); + } \ No newline at end of file diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index 99c7311..05654a8 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -20,6 +20,8 @@ use Hyperf\Snowflake\IdGeneratorInterface; use Hyperf\Utils\ApplicationContext; use Hyperf\Di\Annotation\Inject; use App\Service\WxRefundServiceInterface; +use App\Service\UserServiceInterface; +use App\Model\Users; class OrderService implements OrderServiceInterface { @@ -41,6 +43,12 @@ class OrderService implements OrderServiceInterface */ protected $wxRefundService; + /** + * @Inject + * @var UserServiceInterface + */ + protected $userService; + /** * @inheritDoc */ @@ -731,7 +739,7 @@ class OrderService implements OrderServiceInterface $time = time(); // 主订单状态更新 $orderMain = OrderMain::query() - ->select('id','global_order_id','state','pay_type') + ->select('id','global_order_id','state','pay_type','user_id','money') ->where(['global_order_id' => $global_order_id, 'state' => OrderMain::ORDER_STATE_REFUNDING]) ->first(); @@ -741,7 +749,10 @@ class OrderService implements OrderServiceInterface } $orderMain->state = OrderMain::ORDER_STATE_REFUNDED; - $upOrderMain = $orderMain->save(); + if(!$orderMain->save()){ + Db::rollBack(); + return false; + }; // 子订单状态更新 $upChild = Order::query() @@ -755,14 +766,21 @@ class OrderService implements OrderServiceInterface if($orderMain->pay_type == OrderMain::ORDER_PAY_WX){ // 微信支付 微信退款 - $refundRes = $this->wxRefundService->wxPayRefund($global_order_id); + if($this->wxRefundService->wxPayRefund($global_order_id)){ + Db::rollBack(); + return false; + }; }else if($orderMain->pay_type == OrderMain::ORDER_PAY_BALANCE){ // 余额支付 退款到用户余额 + if($this->userService->userWallet($orderMain->user_id,$orderMain->money,Users::WALLET_TYPE_INC)){ + Db::rollBack(); + return false; + }; // 返还优惠券 $this->couponService->orderRefundCoupon($global_order_id); // 添加用户流水 - + $this->financialService->userByOLOrderRefund($orderMain->user_id, $orderMain->global_order_id, $orderMain->money); } Db::commit(); @@ -813,7 +831,7 @@ class OrderService implements OrderServiceInterface return true; } catch (Exception $e) { - $this->log->event(LogLabel::ORDER_LOG, ['msg'=> '订单退款失败时处理状态9->8','exception' => $e->getMessage()]); + $this->log->event(LogLabel::ORDER_LOG, ['msg'=> '订单退款失败时处理状态9->8 ','exception' => $e->getMessage()]); Db::rollBack(); return false; } diff --git a/app/Service/UserService.php b/app/Service/UserService.php index 2cd5d94..1a75e3f 100644 --- a/app/Service/UserService.php +++ b/app/Service/UserService.php @@ -76,4 +76,23 @@ class UserService implements UserServiceInterface ->where('id', '!=', $current_order_id) ->exists(); } + + /** + * 用户账户(钱包) + * @inheritDoc + * $type 1增 2减 + */ + public function userWallet($userId,$money,$type) + { + $user = Users::select('id','wallet')->where('id',$userId)->lockForUpdate()->first(); + $res = false; + if(!empty($user) && is_numeric($money) && $money > 0){ + if($type == Users::WALLET_TYPE_INC){ + $res = $user->increment('wallet',$money); + }else if($type == Users::WALLET_TYPE_DEC){ + $res = $user->decrement('wallet',$money); + } + } + return $res; + } } \ No newline at end of file diff --git a/app/Service/UserServiceInterface.php b/app/Service/UserServiceInterface.php index 1e8f0fb..29c5066 100644 --- a/app/Service/UserServiceInterface.php +++ b/app/Service/UserServiceInterface.php @@ -26,4 +26,13 @@ interface UserServiceInterface */ public function isStoreFirstOrderToday($user_id, $store_id, $current_order_id, $limit_amount = 3); + /** + * 用户账户(钱包) + * @inheritDoc + * @param $userId + * @param $money + * @param $type 1增 2减 + * @return mixed + */ + public function userWallet($userId,$money,$type); } \ No newline at end of file diff --git a/app/Service/WxRefundService.php b/app/Service/WxRefundService.php index b7e5c40..bcd4a9c 100644 --- a/app/Service/WxRefundService.php +++ b/app/Service/WxRefundService.php @@ -27,8 +27,7 @@ class WxRefundService implements WxRefundServiceInterface ->first(); if(empty($orderMain)){ return false; - } - ; + }; $result = $app->refund->byOutTradeNumber( $orderMain->global_order_id, $orderMain->global_order_id, From 3ea7418a8a2fad97d9880e230b6c0022c7b66096 Mon Sep 17 00:00:00 2001 From: weigang Date: Tue, 25 Aug 2020 19:19:09 +0800 Subject: [PATCH 35/75] =?UTF-8?q?openid=E4=B8=BA=E7=A9=BA=E6=97=B6?= =?UTF-8?q?=E4=B8=8D=E5=8F=91=E9=80=81tempmsg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/MiniprogramService.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Service/MiniprogramService.php b/app/Service/MiniprogramService.php index 2816f69..c74c0ac 100644 --- a/app/Service/MiniprogramService.php +++ b/app/Service/MiniprogramService.php @@ -155,6 +155,10 @@ class MiniprogramService implements MiniprogramServiceInterface */ public function sendTempMsg($openid, $template_id, $data, $redirect_url = '', $applet_config = ['appid' => '', 'pagepath' => '']) { + if (empty($openid) || empty($template_id) || empty($data)) { + return ; + } + // 先拼个基础的 $template = [ 'touser' => $openid, From b532ae133cf7e9f7eac12af0a106db7ccdf07548 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Tue, 25 Aug 2020 19:27:39 +0800 Subject: [PATCH 36/75] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E9=80=80=E6=AC=BE--?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=A4=84=E7=90=86=E7=89=B9=E4=BB=B7=E5=95=86?= =?UTF-8?q?=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/NotifyPayRefundController.php | 11 ++++++++--- app/Service/CouponService.php | 2 +- app/Service/OrderService.php | 12 ++++++++++++ app/Service/OrderServiceInterface.php | 11 +++++++++++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/app/Controller/NotifyPayRefundController.php b/app/Controller/NotifyPayRefundController.php index b704d47..18176c6 100644 --- a/app/Controller/NotifyPayRefundController.php +++ b/app/Controller/NotifyPayRefundController.php @@ -69,13 +69,18 @@ class NotifyPayRefundController extends BaseController } /* --- 退款成功 --- */ - // 退款返还优惠券 - $this->couponService->orderRefundCoupon($message['out_trade_no']); - // 添加用户的流水 $orderMain = OrderMain::select('id','global_order_id','money','user_id') ->where('global_order_id',$message['out_trade_no']) ->where('state',OrderMain::ORDER_STATE_REFUNDED) ->first(); + + // 退款返还优惠券 + $this->couponService->orderRefundCoupon($message['out_trade_no']); + + // 删除特价商品缓存 + $this->orderService->clearTodayGoodPurchase($orderMain->user_id,1); + + // 添加用户的流水 if(!empty($orderMain)){ $this->financialService->userByOLOrderRefund($orderMain->user_id, $orderMain->global_order_id, $orderMain->money); } diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index 7339a43..b015c8d 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -262,7 +262,7 @@ class CouponService implements CouponServiceInterface * @param $couponId * @return bool */ - function clearTodayCouponUsed($userId, $couponId) + public function clearTodayCouponUsed($userId, $couponId) { $redis = ApplicationContext::getContainer()->get(Redis::class); diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index 05654a8..f46990c 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -22,6 +22,7 @@ use Hyperf\Di\Annotation\Inject; use App\Service\WxRefundServiceInterface; use App\Service\UserServiceInterface; use App\Model\Users; +use App\Constants\SsdbKeysPrefix; class OrderService implements OrderServiceInterface { @@ -779,6 +780,8 @@ class OrderService implements OrderServiceInterface // 返还优惠券 $this->couponService->orderRefundCoupon($global_order_id); + // 删除特价商品缓存 + $this->orderService->clearTodayGoodPurchase($orderMain->user_id,1); // 添加用户流水 $this->financialService->userByOLOrderRefund($orderMain->user_id, $orderMain->global_order_id, $orderMain->money); } @@ -836,4 +839,13 @@ class OrderService implements OrderServiceInterface return false; } } + + /** + * 删除特价商品缓存 + */ + public function clearTodayGoodPurchase($userId, $goodId) + { + $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); + return $ssdb->exec('hdel', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$userId, $goodId); + } } \ No newline at end of file diff --git a/app/Service/OrderServiceInterface.php b/app/Service/OrderServiceInterface.php index 4834c91..382f9e3 100644 --- a/app/Service/OrderServiceInterface.php +++ b/app/Service/OrderServiceInterface.php @@ -61,4 +61,15 @@ interface OrderServiceInterface * @return mixed */ public function onlineRefund($global_order_id); + + /** + * 订单退款失败 + * 回退订单状态 + */ + public function onlineRefundFail($global_order_id); + + /** + * 删除特价商品缓存 + */ + public function clearTodayGoodPurchase($userId, $goodId); } \ No newline at end of file From 70a34f60b0c8b337c7a79969a476608ae95deb77 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Tue, 25 Aug 2020 21:48:22 +0800 Subject: [PATCH 37/75] =?UTF-8?q?=E5=8D=95=E4=B8=AA=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=8F=AA=E8=83=BD=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=B8=AA=E7=89=B9?= =?UTF-8?q?=E4=BB=B7=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/ShopCarService.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/Service/ShopCarService.php b/app/Service/ShopCarService.php index a739846..dab1ef9 100644 --- a/app/Service/ShopCarService.php +++ b/app/Service/ShopCarService.php @@ -27,6 +27,20 @@ class ShopCarService implements ShopCarServiceInterface ]; return $error; } + //一个订单只能添加一个特价商品 + if($params['money'] == 0.01){ + $goods_exists = ShopCar::where([ + ['money','=',0.01], + ['user_id','=',$params['user_id']] + ]) + ->exists(); + if($goods_exists){ + $error = [ + 'error' => '一个订单只能添加一个特价商品' + ]; + return $error; + } + } //获取主表商品表信息 $goods = Goods::where([ ['id','=',$params['good_id']], From fa61e20d7565e4b03c7108edc70ec0b1002bbeff Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Tue, 25 Aug 2020 22:00:18 +0800 Subject: [PATCH 38/75] =?UTF-8?q?=E4=B8=80=E4=B8=AA=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=8F=AA=E8=83=BD=E8=B4=AD=E4=B9=B0=E4=B8=80=E4=B8=AA=E7=89=B9?= =?UTF-8?q?=E4=BB=B7=E5=95=86=E5=93=81=20=E4=BD=86=E6=98=AF=E5=90=8C?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E7=89=B9=E4=BB=B7=E5=95=86=E5=93=81=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E8=B4=AD=E4=B9=B0=E5=A4=9A=E4=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/ShopCarService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Service/ShopCarService.php b/app/Service/ShopCarService.php index dab1ef9..b017955 100644 --- a/app/Service/ShopCarService.php +++ b/app/Service/ShopCarService.php @@ -32,6 +32,7 @@ class ShopCarService implements ShopCarServiceInterface $goods_exists = ShopCar::where([ ['money','=',0.01], ['user_id','=',$params['user_id']] + ['good_id','=',$params['good_id']] ]) ->exists(); if($goods_exists){ From 58676c0b1fb2c5ad22d971c5276b036a621530f7 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 26 Aug 2020 00:42:34 +0800 Subject: [PATCH 39/75] =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=8F=AF=E7=94=A8?= =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CouponController.php | 62 ++------------------------ app/Service/CouponService.php | 60 ++++++++++++++++++++++++- app/Service/CouponServiceInterface.php | 2 +- app/Service/ShopCarService.php | 2 +- 4 files changed, 64 insertions(+), 62 deletions(-) diff --git a/app/Controller/CouponController.php b/app/Controller/CouponController.php index dc8ae7c..af85368 100644 --- a/app/Controller/CouponController.php +++ b/app/Controller/CouponController.php @@ -199,65 +199,9 @@ class CouponController extends BaseController $type = $this->request->input('type', 1); # 店铺类型id $storetypeId = $this->request->input('storetype_id', 0); - $storetypeIds = explode(',', str_replace(',', ',', $storetypeId)); - - $available = []; - $notAvailable = []; - - if ($this->empty($orderAmount) || $this->empty($userId)) { - return $this->success([ - 'available' => $available, - 'not_available' => array_values($notAvailable) - ]); - } - - // 获取用户优惠券 - $currentTime = time(); - - $data = Db::table('ims_system_coupon_user_receive as receive') - ->select([ - 'receive.id as receive_id', - 'receive.user_id', - 'receive.number_remain', - 'coupon.id', - 'coupon.title', - 'coupon.full_amount', - 'coupon.discounts', - 'coupon.usable_start_time', - 'coupon.usable_end_time', - 'coupon.discount_type' - ]) - ->join('ims_system_coupon_user as coupon', 'coupon.id', '=', 'receive.system_coupon_user_id') - ->where(['receive.user_id' => $userId]) - ->whereIn('receive.status', [0,1]) - ->where('receive.number_remain', '>', 0) - ->whereIn('coupon.type', [1,$type]) - ->where('coupon.full_amount', '<=', $orderAmount) - ->where('coupon.usable_start_time', '<=', $currentTime) - ->where('coupon.usable_end_time', '>=', $currentTime) - ->where('coupon.usable_number', '<=', Db::raw('receive.number_remain')) - ->where('coupon.market_id', 'in', [0, $marketId]) - ->whereIn('coupon.storetype_id', $storetypeIds) - ->orderByRaw('coupon.discounts DESC, coupon.full_amount DESC') - ->get(); - - // 分离用户今天用过的优惠券种类 - $container = ApplicationContext::getContainer(); - $redis = $container->get(Redis::class); - $couponIds = $redis->sMembers('coupon_'.date('Ymd').'_used_'.$userId); - - foreach ($data as $key => &$item) { - if (in_array($item->id, $couponIds)) { - $notAvailable[$item->id] = $item; - } else { - $available[] = $item; - } - } - - return $this->success([ - 'available' => $available, - 'not_available' => array_values($notAvailable) - ]); + + $res = $this->couponService->getUserAvailableCoupons($orderAmount,$userId,$marketId,$storetypeId); + return $this->success($res); } diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index e0469f1..57acfa4 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -154,9 +154,67 @@ class CouponService implements CouponServiceInterface * 获取用户当前订单可用的优惠券列表 * 按分类(1订单 等优惠)分组返回 */ - public function getUserAvailableCoupons() + public function getUserAvailableCoupons($orderAmount,$userId,$marketId,$storetypeId) { + $storetypeIds = explode(',', str_replace(',', ',', $storetypeId)); + $available = []; + $notAvailable = []; + + if ($this->empty($orderAmount) || $this->empty($userId)) { + return $this->success([ + 'available' => $available, + 'not_available' => array_values($notAvailable) + ]); + } + + // 获取用户优惠券 + $currentTime = time(); + + $data = Db::table('ims_system_coupon_user_receive as receive') + ->select([ + 'receive.id as receive_id', + 'receive.user_id', + 'receive.number_remain', + 'coupon.id', + 'coupon.title', + 'coupon.full_amount', + 'coupon.discounts', + 'coupon.usable_start_time', + 'coupon.usable_end_time', + 'coupon.discount_type' + ]) + ->join('ims_system_coupon_user as coupon', 'coupon.id', '=', 'receive.system_coupon_user_id') + ->where(['receive.user_id' => $userId]) + ->whereIn('receive.status', [0,1]) + ->where('receive.number_remain', '>', 0) + ->whereIn('coupon.type', [1,$type]) + ->where('coupon.full_amount', '<=', $orderAmount) + ->where('coupon.usable_start_time', '<=', $currentTime) + ->where('coupon.usable_end_time', '>=', $currentTime) + ->where('coupon.usable_number', '<=', Db::raw('receive.number_remain')) + ->where('coupon.market_id', 'in', [0, $marketId]) + ->whereIn('coupon.storetype_id', $storetypeIds) + ->orderByRaw('coupon.discounts DESC, coupon.full_amount DESC') + ->get(); + + // 分离用户今天用过的优惠券种类 + $container = ApplicationContext::getContainer(); + $redis = $container->get(Redis::class); + $couponIds = $redis->sMembers('coupon_'.date('Ymd').'_used_'.$userId); + + foreach ($data as $key => &$item) { + if (in_array($item->id, $couponIds)) { + $notAvailable[$item->id] = $item; + } else { + $available[] = $item; + } + } + + return [ + 'available' => $available, + 'not_available' => array_values($notAvailable) + ]; } /** diff --git a/app/Service/CouponServiceInterface.php b/app/Service/CouponServiceInterface.php index 5220320..bf82ab4 100644 --- a/app/Service/CouponServiceInterface.php +++ b/app/Service/CouponServiceInterface.php @@ -13,7 +13,7 @@ interface CouponServiceInterface public function getUserReceiveCouponList(); - public function getUserAvailableCoupons(); + public function getUserAvailableCoupons($orderAmount,$userId,$marketId,$storetypeId); /** * 当前订单可用优惠券列表 diff --git a/app/Service/ShopCarService.php b/app/Service/ShopCarService.php index b017955..6f0536d 100644 --- a/app/Service/ShopCarService.php +++ b/app/Service/ShopCarService.php @@ -31,7 +31,7 @@ class ShopCarService implements ShopCarServiceInterface if($params['money'] == 0.01){ $goods_exists = ShopCar::where([ ['money','=',0.01], - ['user_id','=',$params['user_id']] + ['user_id','=',$params['user_id']], ['good_id','=',$params['good_id']] ]) ->exists(); From 6aa253e70556109915a35fed5bb133ed3a126334 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 26 Aug 2020 00:48:06 +0800 Subject: [PATCH 40/75] =?UTF-8?q?=E5=8F=AF=E7=94=A8=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CouponController.php | 2 +- app/Service/CouponService.php | 2 +- app/Service/CouponServiceInterface.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Controller/CouponController.php b/app/Controller/CouponController.php index af85368..e7fd6c4 100644 --- a/app/Controller/CouponController.php +++ b/app/Controller/CouponController.php @@ -200,7 +200,7 @@ class CouponController extends BaseController # 店铺类型id $storetypeId = $this->request->input('storetype_id', 0); - $res = $this->couponService->getUserAvailableCoupons($orderAmount,$userId,$marketId,$storetypeId); + $res = $this->couponService->getUserAvailableCoupons($orderAmount,$userId,$marketId,$type,$storetypeId); return $this->success($res); } diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index 57acfa4..313f18d 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -154,7 +154,7 @@ class CouponService implements CouponServiceInterface * 获取用户当前订单可用的优惠券列表 * 按分类(1订单 等优惠)分组返回 */ - public function getUserAvailableCoupons($orderAmount,$userId,$marketId,$storetypeId) + public function getUserAvailableCoupons($orderAmount,$userId,$marketId,$type,$storetypeId) { $storetypeIds = explode(',', str_replace(',', ',', $storetypeId)); diff --git a/app/Service/CouponServiceInterface.php b/app/Service/CouponServiceInterface.php index bf82ab4..f272c42 100644 --- a/app/Service/CouponServiceInterface.php +++ b/app/Service/CouponServiceInterface.php @@ -13,7 +13,7 @@ interface CouponServiceInterface public function getUserReceiveCouponList(); - public function getUserAvailableCoupons($orderAmount,$userId,$marketId,$storetypeId); + public function getUserAvailableCoupons($orderAmount,$userId,$marketId,$type,$storetypeId); /** * 当前订单可用优惠券列表 From 5118008ef9d9ee168fa5d16697c150f0f254a595 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 26 Aug 2020 09:41:30 +0800 Subject: [PATCH 41/75] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponService.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index 5efe903..0d77114 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -161,11 +161,11 @@ class CouponService implements CouponServiceInterface $available = []; $notAvailable = []; - if ($this->empty($orderAmount) || $this->empty($userId)) { - return $this->success([ + if (empty($orderAmount) || empty($userId)) { + return [ 'available' => $available, 'not_available' => array_values($notAvailable) - ]); + ]; } // 获取用户优惠券 From 18de7a139d61cf797f3ef1fb733a5dbb8a29ac35 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Wed, 26 Aug 2020 10:21:27 +0800 Subject: [PATCH 42/75] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E9=80=80=E6=AC=BE--?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=A0=E9=99=A4=E7=89=B9=E4=BB=B7=E5=95=86?= =?UTF-8?q?=E5=93=81=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/NotifyPayRefundController.php | 19 +++++++++++++------ app/Service/CouponService.php | 2 +- app/Service/OrderService.php | 18 +++++++++--------- app/Service/WxRefundService.php | 17 +++++++++++++++-- config/autoload/dependencies.php | 1 + config/routes.php | 1 + 6 files changed, 40 insertions(+), 18 deletions(-) diff --git a/app/Controller/NotifyPayRefundController.php b/app/Controller/NotifyPayRefundController.php index 18176c6..24c12b1 100644 --- a/app/Controller/NotifyPayRefundController.php +++ b/app/Controller/NotifyPayRefundController.php @@ -14,6 +14,7 @@ use Hyperf\Guzzle\CoroutineHandler; use Hyperf\Di\Annotation\Inject; use Hyperf\HttpMessage\Stream\SwooleStream; use Symfony\Component\HttpFoundation\Request; +use App\Service\PurchaseLimitServiceInterface; class NotifyPayRefundController extends BaseController { @@ -32,6 +33,12 @@ class NotifyPayRefundController extends BaseController */ protected $orderService; + /** + * @Inject + * @var PurchaseLimitServiceInterface + */ + protected $purchaseLimitService; + /** * 微信退款回调 */ @@ -73,12 +80,12 @@ class NotifyPayRefundController extends BaseController ->where('global_order_id',$message['out_trade_no']) ->where('state',OrderMain::ORDER_STATE_REFUNDED) ->first(); - + // 退款返还优惠券 $this->couponService->orderRefundCoupon($message['out_trade_no']); // 删除特价商品缓存 - $this->orderService->clearTodayGoodPurchase($orderMain->user_id,1); + $this->purchaseLimitService->delSsdbPurchaseRecord($orderMain->id); // 添加用户的流水 if(!empty($orderMain)){ @@ -94,9 +101,9 @@ class NotifyPayRefundController extends BaseController } }); - return $this->response - ->withHeader('Content-Type', 'text/xml') - ->withStatus(200) - ->withBody(new SwooleStream($response->getContent())); + // return $this->response + // ->withHeader('Content-Type', 'text/xml') + // ->withStatus(200) + // ->withBody(new SwooleStream($response->getContent())); } } \ No newline at end of file diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index 5efe903..d6a2d9f 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -19,7 +19,7 @@ use Hyperf\Redis\Redis; class CouponService implements CouponServiceInterface { - /** + /** * @Inject * @var Log */ diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index 8bb7dec..57aadf3 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -776,23 +776,23 @@ class OrderService implements OrderServiceInterface if($orderMain->pay_type == OrderMain::ORDER_PAY_WX){ // 微信支付 微信退款 - if($this->wxRefundService->wxPayRefund($global_order_id)){ + if(!$this->wxRefundService->wxPayRefund($global_order_id)){ Db::rollBack(); return false; }; }else if($orderMain->pay_type == OrderMain::ORDER_PAY_BALANCE){ // 余额支付 退款到用户余额 - if($this->userService->userWallet($orderMain->user_id,$orderMain->money,Users::WALLET_TYPE_INC)){ - Db::rollBack(); - return false; - }; + // if($this->userService->userWallet($orderMain->user_id,$orderMain->money,Users::WALLET_TYPE_INC)){ + // Db::rollBack(); + // return false; + // }; // 返还优惠券 - $this->couponService->orderRefundCoupon($global_order_id); + // $this->couponService->orderRefundCoupon($global_order_id); // 删除特价商品缓存 - $this->orderService->clearTodayGoodPurchase($orderMain->user_id,1); + // $this->orderService->clearTodayGoodPurchase($orderMain->user_id,1); // 添加用户流水 - $this->financialService->userByOLOrderRefund($orderMain->user_id, $orderMain->global_order_id, $orderMain->money); + // $this->financialService->userByOLOrderRefund($orderMain->user_id, $orderMain->global_order_id, $orderMain->money); } Db::commit(); @@ -855,6 +855,6 @@ class OrderService implements OrderServiceInterface public function clearTodayGoodPurchase($userId, $goodId) { $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - return $ssdb->exec('hdel', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$userId, $goodId); + return $ssdb->exec('del', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$userId, $goodId); } } \ No newline at end of file diff --git a/app/Service/WxRefundService.php b/app/Service/WxRefundService.php index bcd4a9c..4ab53e2 100644 --- a/app/Service/WxRefundService.php +++ b/app/Service/WxRefundService.php @@ -6,9 +6,16 @@ use App\Model\OrderMain; use EasyWeChat\Factory; use Hyperf\DbConnection\Db; use App\Constants\ErrorCode; +use App\Commons\Log; class WxRefundService implements WxRefundServiceInterface { + /** + * @Inject + * @var Log + */ + protected $log; + /** * 微信支付退款 */ @@ -28,13 +35,19 @@ class WxRefundService implements WxRefundServiceInterface if(empty($orderMain)){ return false; }; + $options = [ + 'refund_desc' => '', + 'notify_url' => config('site_host') . '/wechat/notify/wxpayrefund' + ]; $result = $app->refund->byOutTradeNumber( $orderMain->global_order_id, $orderMain->global_order_id, $orderMain->money * 100, - $orderMain->money * 100 + $orderMain->money * 100, + $options ); - + + $this->log->event('wx_pay_refund',$result); return $result; } diff --git a/config/autoload/dependencies.php b/config/autoload/dependencies.php index 31e22ac..6eacba0 100644 --- a/config/autoload/dependencies.php +++ b/config/autoload/dependencies.php @@ -32,4 +32,5 @@ return [ \App\Service\FinancialRecordServiceInterface::class => \App\Service\FinancialRecordService::class, \App\Service\SeparateAccountsServiceInterface::class => \App\Service\SeparateAccountsService::class, \App\Service\ShopCarServiceInterface::class => \App\Service\ShopCarService::class, + \App\Service\WxRefundServiceInterface::class => \App\Service\WxRefundService::class, ]; diff --git a/config/routes.php b/config/routes.php index 2d0ef16..2a208a7 100644 --- a/config/routes.php +++ b/config/routes.php @@ -69,4 +69,5 @@ Router::addGroup('/v1/',function (){ Router::addGroup('/wechat/',function () { Router::post('notify/wxminionline', 'App\Controller\NotifyController@wxminiOnline'); Router::post('notify/wxminioffline', 'App\Controller\NotifyController@wxminiOffline'); + Router::post('notify/wxpayrefund', 'App\Controller\NotifyPayRefundController@wxPayRefund'); }); \ No newline at end of file From df2f13c58ba4c5129d6d079df42e530b2d12a4c8 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Wed, 26 Aug 2020 10:40:17 +0800 Subject: [PATCH 43/75] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E9=80=80=E6=AC=BE--?= =?UTF-8?q?=E4=BF=AE=E6=94=B92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/PurchaseLimitService.php | 2 +- app/Service/WxRefundService.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Service/PurchaseLimitService.php b/app/Service/PurchaseLimitService.php index dc7271d..2a3abeb 100644 --- a/app/Service/PurchaseLimitService.php +++ b/app/Service/PurchaseLimitService.php @@ -65,7 +65,7 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface ->toArray(); foreach ($goods as $k2 => $v2) { - $ssdb->exec('del', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$v1['user_id'].'_'.$v2['good_id'], $global_order_id); + $ssdb->exec('del', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$v1['user_id'].'_'.$v2['good_id'], $order->global_order_id); var_dump($v1['user_id']); var_dump($v1['good_id']); } diff --git a/app/Service/WxRefundService.php b/app/Service/WxRefundService.php index 4ab53e2..bbd2dd6 100644 --- a/app/Service/WxRefundService.php +++ b/app/Service/WxRefundService.php @@ -7,6 +7,7 @@ use EasyWeChat\Factory; use Hyperf\DbConnection\Db; use App\Constants\ErrorCode; use App\Commons\Log; +use Hyperf\Di\Annotation\Inject; class WxRefundService implements WxRefundServiceInterface { From d6990ccbaae4415317ee413daba7c7c5072e95da Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 26 Aug 2020 11:12:13 +0800 Subject: [PATCH 44/75] =?UTF-8?q?=E5=8F=96=E6=B6=88=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=20order=5Fid=20=E6=94=B9=E4=B8=BA=20global?= =?UTF-8?q?=5Forder=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/OrderController.php | 7 +++++-- app/Service/CouponService.php | 10 ++++++---- app/Service/CouponServiceInterface.php | 2 +- app/Service/OrderService.php | 8 ++++---- app/Service/OrderServiceInterface.php | 2 +- app/Service/PurchaseLimitService.php | 2 +- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/app/Controller/OrderController.php b/app/Controller/OrderController.php index fb2ed20..0d019f5 100644 --- a/app/Controller/OrderController.php +++ b/app/Controller/OrderController.php @@ -102,8 +102,11 @@ class OrderController extends BaseController * 用户取消订单 */ public function onlineCancel(){ - $OrderId = $this->request->input('order_id'); - return $this->success($this->orderService->onlineCancel($OrderId)); + $orderId = $this->request->input('order_id'); + $orderMain = OrderMain::where('id',$orderId) + ->select('global_order_id') + ->first(); + return $this->success($this->orderService->onlineCancel($orderMain->global_order_id)); } } \ No newline at end of file diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index dcb01ef..483bc72 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -2,6 +2,7 @@ namespace App\Service; +use App\Model\OrderMain; use Hyperf\Di\Annotation\Inject; use Hyperf\DbConnection\Db; use App\Model\CouponUserRecType; @@ -284,7 +285,11 @@ class CouponService implements CouponServiceInterface * @param $order_id * @return bool */ - public function refundOrderCoupons($order_id){ + public function refundOrderCoupons($global_order_id){ + $order_main = OrderMain::where('global_order_id',$global_order_id) + ->select('id','user_id') + ->first(); + $order_id = $order_main->id; $coupon = CouponUserUse::where([ ['order_main_id','=',$order_id], ['status','=',CouponUserUse::COUPON_USE_STATE_USED], @@ -312,9 +317,6 @@ class CouponService implements CouponServiceInterface ]); //删除当日 redis 使用记录缓存 - $order_main = OrderMain::where('id',$order_id) - ->select('global_order_id','user_id') - ->first(); $redis = ApplicationContext::getContainer()->get(Redis::class); $remRes = $redis->sRem( 'coupon_'.date('Ymd').'_used_'.$order_main->user_id, diff --git a/app/Service/CouponServiceInterface.php b/app/Service/CouponServiceInterface.php index 2789efb..4f60de4 100644 --- a/app/Service/CouponServiceInterface.php +++ b/app/Service/CouponServiceInterface.php @@ -27,7 +27,7 @@ interface CouponServiceInterface */ public function getOrderCanUseCoupons($orderAmount, $marketId, $userId, $fields=[], $type=1, $storeTypeIds=[0]); - public function refundOrderCoupons($order_id); + public function refundOrderCoupons($global_order_id); public function clearTodayCouponUsed($userId, $couponId); public function orderRefundCoupon($global_order_id); } diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index 57aadf3..fc3c3e0 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -729,13 +729,13 @@ class OrderService implements OrderServiceInterface /** * @inheritDoc */ - public function onlineCancel($order_id){ - OrderMain::where('id',$order_id) + public function onlineCancel($global_order_id){ + OrderMain::where('global_order_id',$global_order_id) ->update(['state' => OrderMain::ORDER_STATE_CANCEL]); //撤销redis 用券记录 - $res = $this->couponService->refundOrderCoupons($order_id); + $res = $this->couponService->refundOrderCoupons($global_order_id); //撤销特价商品购买记录 - $res = $this->purchaseLimitService->delSsdbPurchaseRecord($order_id); + $res = $this->purchaseLimitService->delSsdbPurchaseRecord($global_order_id); return $res; } /** diff --git a/app/Service/OrderServiceInterface.php b/app/Service/OrderServiceInterface.php index 382f9e3..a371378 100644 --- a/app/Service/OrderServiceInterface.php +++ b/app/Service/OrderServiceInterface.php @@ -53,7 +53,7 @@ interface OrderServiceInterface * @param $global_order_id * @return mixed */ - public function onlineCancel($order_id); + public function onlineCancel($global_order_id); /** * 线上订单退款 diff --git a/app/Service/PurchaseLimitService.php b/app/Service/PurchaseLimitService.php index 2a3abeb..41a531f 100644 --- a/app/Service/PurchaseLimitService.php +++ b/app/Service/PurchaseLimitService.php @@ -65,7 +65,7 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface ->toArray(); foreach ($goods as $k2 => $v2) { - $ssdb->exec('del', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$v1['user_id'].'_'.$v2['good_id'], $order->global_order_id); + $ssdb->exec('del', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$v1['user_id'].'_'.$v2['good_id']); var_dump($v1['user_id']); var_dump($v1['good_id']); } From 174044258171fea1d33873951bee505167a38870 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 26 Aug 2020 11:27:15 +0800 Subject: [PATCH 45/75] =?UTF-8?q?=E6=92=A4=E9=94=80=E7=89=B9=E4=BB=B7?= =?UTF-8?q?=E5=95=86=E5=93=81=E8=B4=AD=E4=B9=B0=E8=AE=B0=E5=BD=95=20?= =?UTF-8?q?=E4=BD=BF=E7=94=A8global=5Forder=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/PurchaseLimitService.php | 7 ++++++- app/Service/PurchaseLimitServiceInterface.php | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/Service/PurchaseLimitService.php b/app/Service/PurchaseLimitService.php index 41a531f..717e45e 100644 --- a/app/Service/PurchaseLimitService.php +++ b/app/Service/PurchaseLimitService.php @@ -4,6 +4,7 @@ namespace App\Service; use App\Model\Order; use App\Model\OrderGoods; +use App\Model\OrderMain; use Hyperf\Di\Annotation\Inject; use Hyperf\DbConnection\Db; use App\Model\Goods; @@ -46,8 +47,12 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface return true; } - public function delSsdbPurchaseRecord($order_id) + public function delSsdbPurchaseRecord($global_order_id) { + $order_main = OrderMain::where('global_order_id',$global_order_id) + ->select('id','user_id') + ->first(); + $order_id = $order_main->id; $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); $order = Order::query() ->where('order_main_id',$order_id) diff --git a/app/Service/PurchaseLimitServiceInterface.php b/app/Service/PurchaseLimitServiceInterface.php index 5c88b2c..f5e415b 100644 --- a/app/Service/PurchaseLimitServiceInterface.php +++ b/app/Service/PurchaseLimitServiceInterface.php @@ -10,7 +10,7 @@ interface PurchaseLimitServiceInterface public function ssdbPurchaseRecord($params,$user_id,$global_order_id); - public function delSsdbPurchaseRecord($order_id); + public function delSsdbPurchaseRecord($global_order_id); public function test($params); } \ No newline at end of file From 34cc643b6602d4127755a6aff63817c5d1699a2c Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 26 Aug 2020 11:56:18 +0800 Subject: [PATCH 46/75] =?UTF-8?q?=E4=B8=8B=E5=8D=95=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E7=89=B9=E4=BB=B7=E5=95=86=E5=93=81=E4=B8=8D=E7=BB=99=E7=94=A8?= =?UTF-8?q?=E5=88=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CouponController.php | 6 ++++-- app/Service/CouponService.php | 18 +++++++++++++++--- app/Service/CouponServiceInterface.php | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/Controller/CouponController.php b/app/Controller/CouponController.php index e7fd6c4..5caf76c 100644 --- a/app/Controller/CouponController.php +++ b/app/Controller/CouponController.php @@ -199,8 +199,10 @@ class CouponController extends BaseController $type = $this->request->input('type', 1); # 店铺类型id $storetypeId = $this->request->input('storetype_id', 0); - - $res = $this->couponService->getUserAvailableCoupons($orderAmount,$userId,$marketId,$type,$storetypeId); + # 购物车商品id + $carIds = $this->request->input('car_ids', 0); + + $res = $this->couponService->getUserAvailableCoupons($orderAmount,$userId,$marketId,$type,$storetypeId,$carIds); return $this->success($res); } diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index 483bc72..8363f31 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -3,6 +3,7 @@ namespace App\Service; use App\Model\OrderMain; +use App\Model\ShopCar; use Hyperf\Di\Annotation\Inject; use Hyperf\DbConnection\Db; use App\Model\CouponUserRecType; @@ -155,12 +156,23 @@ class CouponService implements CouponServiceInterface * 获取用户当前订单可用的优惠券列表 * 按分类(1订单 等优惠)分组返回 */ - public function getUserAvailableCoupons($orderAmount,$userId,$marketId,$type,$storetypeId) + public function getUserAvailableCoupons($orderAmount,$userId,$marketId,$type,$storetypeId,$carIds) { - $storetypeIds = explode(',', str_replace(',', ',', $storetypeId)); - $available = []; $notAvailable = []; + //如果存在特价商品 不给用券 + $carIdsArr = explode(',',$carIds); + $shopCarExists = ShopCar::whereIn('id',$carIdsArr) + ->where('money',0.01) + ->exists(); + if($shopCarExists){ + return [ + 'available' => $available, + 'not_available' => array_values($notAvailable) + ]; + } + + $storetypeIds = explode(',', str_replace(',', ',', $storetypeId)); if (empty($orderAmount) || empty($userId)) { return [ diff --git a/app/Service/CouponServiceInterface.php b/app/Service/CouponServiceInterface.php index 4f60de4..669e086 100644 --- a/app/Service/CouponServiceInterface.php +++ b/app/Service/CouponServiceInterface.php @@ -13,7 +13,7 @@ interface CouponServiceInterface public function getUserReceiveCouponList(); - public function getUserAvailableCoupons($orderAmount,$userId,$marketId,$type,$storetypeId); + public function getUserAvailableCoupons($orderAmount,$userId,$marketId,$type,$storetypeId,$carIds); /** * 当前订单可用优惠券列表 From 117e356d0ae0b226e39afca95e65423268d8d49e Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 26 Aug 2020 16:12:07 +0800 Subject: [PATCH 47/75] =?UTF-8?q?=E9=80=80=E5=8D=95=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=95=B4=E5=90=88=20=E6=9C=89=E5=A4=B1=E6=95=88=E4=BC=98?= =?UTF-8?q?=E6=83=A0=E5=88=B8=E6=97=B6=E8=BF=94=E5=9B=9E=E5=A4=B1=E6=95=88?= =?UTF-8?q?=E5=8E=9F=E5=9B=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/CouponUserUse.php | 6 ++++ app/Service/CouponService.php | 43 ++++++++++++++------------ app/Service/CouponServiceInterface.php | 2 +- app/Service/OrderService.php | 6 ++-- app/Service/PurchaseLimitService.php | 2 -- 5 files changed, 34 insertions(+), 25 deletions(-) diff --git a/app/Model/CouponUserUse.php b/app/Model/CouponUserUse.php index 0d53a14..76064ca 100644 --- a/app/Model/CouponUserUse.php +++ b/app/Model/CouponUserUse.php @@ -13,5 +13,11 @@ class CouponUserUse extends Model public $timestamps = false; + protected $fillable = [ + 'status', + 'return_time', + 'update_time' + ]; + protected $table = 'ims_system_coupon_user_use'; } \ No newline at end of file diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index 8363f31..d64b786 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -160,18 +160,6 @@ class CouponService implements CouponServiceInterface { $available = []; $notAvailable = []; - //如果存在特价商品 不给用券 - $carIdsArr = explode(',',$carIds); - $shopCarExists = ShopCar::whereIn('id',$carIdsArr) - ->where('money',0.01) - ->exists(); - if($shopCarExists){ - return [ - 'available' => $available, - 'not_available' => array_values($notAvailable) - ]; - } - $storetypeIds = explode(',', str_replace(',', ',', $storetypeId)); if (empty($orderAmount) || empty($userId)) { @@ -218,12 +206,27 @@ class CouponService implements CouponServiceInterface foreach ($data as $key => &$item) { if (in_array($item->id, $couponIds)) { + $item->msg = '今日已使用'; $notAvailable[$item->id] = $item; } else { $available[] = $item; } } + //如果存在特价商品 不给用券 + $carIdsArr = explode(',',$carIds); + $shopCarExists = ShopCar::whereIn('id',$carIdsArr) + ->where('money',0.01) + ->exists(); + if($shopCarExists){ + var_dump(1111); + foreach ($available as $k => $v) { + $v->msg = '特价商品不可使用'; + $notAvailable[$v->id] = $v; + } + $available = []; + } + return [ 'available' => $available, 'not_available' => array_values($notAvailable) @@ -334,7 +337,7 @@ class CouponService implements CouponServiceInterface 'coupon_'.date('Ymd').'_used_'.$order_main->user_id, $coupon->system_coupon_id ); - return $res; + return $remRes; } /* 删除-优惠券今日使用的缓存 @@ -359,19 +362,22 @@ class CouponService implements CouponServiceInterface * 先查询是否正常使用优惠券 * 修改状态,退还领取记录库存,删除ssdb缓存 */ - public function orderRefundCoupon($global_order_id) + public function orderRefundCoupons($global_order_id) { + $order_main = OrderMain::where('global_order_id',$global_order_id) + ->select('id','user_id') + ->first(); $time = time(); Db::beginTransaction(); try { $couponUses = CouponUserUse::query() ->select('id','system_coupon_id','user_id','number','user_receive_id') - ->where('global_order_id',$global_order_id) + ->where('order_main_id',$order_main->id) ->where('status',CouponUserUse::COUPON_USE_STATE_USED) - ->select(); - if(!empty($couponUse)){ + ->get(); + if(!empty($couponUses)){ foreach($couponUses as $use){ - $use->status = CouponUserUse::COUPON_USE_STATE_USED; + $use->status = CouponUserUse::COUPON_USE_STATE_CANCEL; $use->return_time = $time; $use->update_time = $time; $res = $use->save(); @@ -397,6 +403,5 @@ class CouponService implements CouponServiceInterface Db::rollBack(); return false; } - return true; } } \ No newline at end of file diff --git a/app/Service/CouponServiceInterface.php b/app/Service/CouponServiceInterface.php index 669e086..e7c54b5 100644 --- a/app/Service/CouponServiceInterface.php +++ b/app/Service/CouponServiceInterface.php @@ -29,5 +29,5 @@ interface CouponServiceInterface public function refundOrderCoupons($global_order_id); public function clearTodayCouponUsed($userId, $couponId); - public function orderRefundCoupon($global_order_id); + public function orderRefundCoupons($global_order_id); } diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index fc3c3e0..a1d5734 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -733,10 +733,10 @@ class OrderService implements OrderServiceInterface OrderMain::where('global_order_id',$global_order_id) ->update(['state' => OrderMain::ORDER_STATE_CANCEL]); //撤销redis 用券记录 - $res = $this->couponService->refundOrderCoupons($global_order_id); + $redisRes = $this->couponService->orderRefundCoupons($global_order_id); //撤销特价商品购买记录 - $res = $this->purchaseLimitService->delSsdbPurchaseRecord($global_order_id); - return $res; + $ssdbRes = $this->purchaseLimitService->delSsdbPurchaseRecord($global_order_id); + return $redisRes && $ssdbRes; } /** * @inheritDoc diff --git a/app/Service/PurchaseLimitService.php b/app/Service/PurchaseLimitService.php index 717e45e..8bbd222 100644 --- a/app/Service/PurchaseLimitService.php +++ b/app/Service/PurchaseLimitService.php @@ -71,8 +71,6 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface foreach ($goods as $k2 => $v2) { $ssdb->exec('del', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$v1['user_id'].'_'.$v2['good_id']); - var_dump($v1['user_id']); - var_dump($v1['good_id']); } } return true; From 579cd1fd60feba386a43c5fb0011ef9c8ebf58d9 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 26 Aug 2020 16:23:40 +0800 Subject: [PATCH 48/75] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E6=96=B9=E6=B3=95=20=E4=BF=AE=E6=94=B9=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8=E5=A4=B1=E6=95=88=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponService.php | 48 +---------------------------------- 1 file changed, 1 insertion(+), 47 deletions(-) diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index d64b786..10ab91d 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -219,9 +219,8 @@ class CouponService implements CouponServiceInterface ->where('money',0.01) ->exists(); if($shopCarExists){ - var_dump(1111); foreach ($available as $k => $v) { - $v->msg = '特价商品不可使用'; + $v->msg = '不可使用'; $notAvailable[$v->id] = $v; } $available = []; @@ -295,51 +294,6 @@ class CouponService implements CouponServiceInterface return $setRes&&$expireRes; } - /** - * 取消订单返券 - * @param $order_id - * @return bool - */ - public function refundOrderCoupons($global_order_id){ - $order_main = OrderMain::where('global_order_id',$global_order_id) - ->select('id','user_id') - ->first(); - $order_id = $order_main->id; - $coupon = CouponUserUse::where([ - ['order_main_id','=',$order_id], - ['status','=',CouponUserUse::COUPON_USE_STATE_USED], - ]) - ->select('id','user_receive_id','number') - ->first(); - - if (empty($coupon)) { - return ''; - } - - // 返回用户优惠券数量并更新状态 - $res = Db::update("UPDATE ims_system_coupon_user_receive SET number_remain=number_remain+{$coupon->number}, status=IF(number=number_remain,0,1), update_time=".time()."" - ." WHERE id={$coupon->user_receive_id} AND number>=(number_remain+{$coupon->number})"); - - // 更新使用记录状态为已退回 - CouponUserUse::where([ - ['id','=',$coupon->id], - ['status','=',CouponUserUse::COUPON_USE_STATE_USED], - ]) - ->update([ - 'status' => CouponUserUse::COUPON_USE_STATE_CANCEL, - 'return_time' => time(), - 'update_time' => time(), - ]); - - //删除当日 redis 使用记录缓存 - $redis = ApplicationContext::getContainer()->get(Redis::class); - $remRes = $redis->sRem( - 'coupon_'.date('Ymd').'_used_'.$order_main->user_id, - $coupon->system_coupon_id - ); - return $remRes; - } - /* 删除-优惠券今日使用的缓存 * @param $userId * @param $couponId From e37f4c2cad1fe2594302707e51d41d2a0eb71546 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 26 Aug 2020 16:30:19 +0800 Subject: [PATCH 49/75] =?UTF-8?q?=E7=89=B9=E4=BB=B7=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponService.php | 47 +------------------------- app/Service/CouponServiceInterface.php | 2 -- 2 files changed, 1 insertion(+), 48 deletions(-) diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index d64b786..bb4be10 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -219,9 +219,8 @@ class CouponService implements CouponServiceInterface ->where('money',0.01) ->exists(); if($shopCarExists){ - var_dump(1111); foreach ($available as $k => $v) { - $v->msg = '特价商品不可使用'; + $v->msg = '不可使用'; $notAvailable[$v->id] = $v; } $available = []; @@ -295,50 +294,6 @@ class CouponService implements CouponServiceInterface return $setRes&&$expireRes; } - /** - * 取消订单返券 - * @param $order_id - * @return bool - */ - public function refundOrderCoupons($global_order_id){ - $order_main = OrderMain::where('global_order_id',$global_order_id) - ->select('id','user_id') - ->first(); - $order_id = $order_main->id; - $coupon = CouponUserUse::where([ - ['order_main_id','=',$order_id], - ['status','=',CouponUserUse::COUPON_USE_STATE_USED], - ]) - ->select('id','user_receive_id','number') - ->first(); - - if (empty($coupon)) { - return ''; - } - - // 返回用户优惠券数量并更新状态 - $res = Db::update("UPDATE ims_system_coupon_user_receive SET number_remain=number_remain+{$coupon->number}, status=IF(number=number_remain,0,1), update_time=".time()."" - ." WHERE id={$coupon->user_receive_id} AND number>=(number_remain+{$coupon->number})"); - - // 更新使用记录状态为已退回 - CouponUserUse::where([ - ['id','=',$coupon->id], - ['status','=',CouponUserUse::COUPON_USE_STATE_USED], - ]) - ->update([ - 'status' => CouponUserUse::COUPON_USE_STATE_CANCEL, - 'return_time' => time(), - 'update_time' => time(), - ]); - - //删除当日 redis 使用记录缓存 - $redis = ApplicationContext::getContainer()->get(Redis::class); - $remRes = $redis->sRem( - 'coupon_'.date('Ymd').'_used_'.$order_main->user_id, - $coupon->system_coupon_id - ); - return $remRes; - } /* 删除-优惠券今日使用的缓存 * @param $userId diff --git a/app/Service/CouponServiceInterface.php b/app/Service/CouponServiceInterface.php index e7c54b5..33bf11b 100644 --- a/app/Service/CouponServiceInterface.php +++ b/app/Service/CouponServiceInterface.php @@ -26,8 +26,6 @@ interface CouponServiceInterface * @return mixed */ public function getOrderCanUseCoupons($orderAmount, $marketId, $userId, $fields=[], $type=1, $storeTypeIds=[0]); - - public function refundOrderCoupons($global_order_id); public function clearTodayCouponUsed($userId, $couponId); public function orderRefundCoupons($global_order_id); } From 3793706945c00f7c2b24f6a97db93bfe577e4bce Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Wed, 26 Aug 2020 16:38:19 +0800 Subject: [PATCH 50/75] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E9=80=80=E6=AC=BE--?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=97=AE=E9=A2=98-=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + app/Constants/LogLabel.php | 7 +++- app/Controller/NotifyPayRefundController.php | 44 +++++++++++++------- app/JsonRpc/OrderService.php | 34 ++++++++------- app/Service/CouponService.php | 4 +- app/Service/CouponServiceInterface.php | 2 +- app/Service/OrderService.php | 36 ++++++++++++++-- app/Service/WxRefundService.php | 33 ++++++++------- 8 files changed, 108 insertions(+), 54 deletions(-) diff --git a/.gitignore b/.gitignore index 9454e2b..0e78326 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ vendor/ .phpunit* /watch .vscode/ +config/cert/apiclient_cert_2.pem +config/cert/apiclient_key_2.pem diff --git a/app/Constants/LogLabel.php b/app/Constants/LogLabel.php index 8807da4..4b998b7 100644 --- a/app/Constants/LogLabel.php +++ b/app/Constants/LogLabel.php @@ -57,6 +57,11 @@ class LogLabel extends AbstractConstants /** * @Message("Pay refund Log Label") */ - const PAY_NOTIFY_REFUND = 'notify_refund'; + const WX_NOTIFY_REFUND = 'wx_notify_refund'; + + /** + * @Message("Pay refund Log Label") + */ + const WX_PAY_REFUND = 'wx_pay_refund'; } diff --git a/app/Controller/NotifyPayRefundController.php b/app/Controller/NotifyPayRefundController.php index 24c12b1..dbc9c53 100644 --- a/app/Controller/NotifyPayRefundController.php +++ b/app/Controller/NotifyPayRefundController.php @@ -15,6 +15,7 @@ use Hyperf\Di\Annotation\Inject; use Hyperf\HttpMessage\Stream\SwooleStream; use Symfony\Component\HttpFoundation\Request; use App\Service\PurchaseLimitServiceInterface; +use Hyperf\DbConnection\Db; class NotifyPayRefundController extends BaseController { @@ -44,6 +45,10 @@ class NotifyPayRefundController extends BaseController */ public function wxPayRefund() { + $this->log->event( + LogLabel::WX_NOTIFY_REFUND, + '进入回调' + ); $config = config('wxpay'); $app = Factory::payment($config); $app['guzzle_handler'] = CoroutineHandler::class; @@ -59,7 +64,10 @@ class NotifyPayRefundController extends BaseController /* 通知回调,进行业务处理 */ $response = $app->handleRefundedNotify(function ($message, $fail) use ($app) { - + $this->log->event( + LogLabel::WX_NOTIFY_REFUND, + $message + ); try { /* --- 退款失败 --- */ if ( @@ -69,41 +77,47 @@ class NotifyPayRefundController extends BaseController ) { // 错误日志 $this->log->event( - LogLabel::PAY_NOTIFY_REFUND, + LogLabel::WX_NOTIFY_REFUND, $message ); $fail('Unknown error but FAIL'); + return false; } /* --- 退款成功 --- */ $orderMain = OrderMain::select('id','global_order_id','money','user_id') ->where('global_order_id',$message['out_trade_no']) ->where('state',OrderMain::ORDER_STATE_REFUNDED) + ->where(Db::raw('refund_time is null')) ->first(); - - // 退款返还优惠券 - $this->couponService->orderRefundCoupon($message['out_trade_no']); - - // 删除特价商品缓存 - $this->purchaseLimitService->delSsdbPurchaseRecord($orderMain->id); - - // 添加用户的流水 + if(!empty($orderMain)){ + // 添加退款时间 + $orderMain->refund_time = time(); + $orderMain->save(); + + // 退款返还优惠券 + $this->couponService->orderRefundCoupons($orderMain->global_order_id); + + // 删除特价商品缓存 + $this->purchaseLimitService->delSsdbPurchaseRecord($orderMain->id); + + // 添加用户的流水 $this->financialService->userByOLOrderRefund($orderMain->user_id, $orderMain->global_order_id, $orderMain->money); } } catch (\Exception $e) { $this->log->event( - LogLabel::PAY_NOTIFY_REFUND, + LogLabel::WX_NOTIFY_REFUND, ['exception_fail' => $e->getMessage()] ); $fail('Exception'); } }); - // return $this->response - // ->withHeader('Content-Type', 'text/xml') - // ->withStatus(200) - // ->withBody(new SwooleStream($response->getContent())); + return $this->response + ->withHeader('Content-Type', 'text/xml') + ->withStatus(200) + ->withBody(new SwooleStream($response->getContent())); } } \ No newline at end of file diff --git a/app/JsonRpc/OrderService.php b/app/JsonRpc/OrderService.php index 43abb2e..68f754f 100644 --- a/app/JsonRpc/OrderService.php +++ b/app/JsonRpc/OrderService.php @@ -69,24 +69,26 @@ class OrderService implements OrderServiceInterface * 退款成功 state = 9 */ public function onlineRefund($global_order_id){ - Db::beginTransaction(); + $result = [ + "status" => 200, + "code" => ErrorCode::ORDER_FAILURE, + "result" => [], + "message" => '' + ]; try{ - - return [ - "status" => 200, - "code" => 0, - "result" => $this->orderService->onlineRefund($global_order_id), - // 'result' => $global_order_id, - "message" => '退款成功' - ]; + $res = $this->orderService->onlineRefund($global_order_id); + if($res){ + $result['code'] = 0; + $result['result'] = $res; + $result['message'] = '退款成功'; + }else{ + $result['result'] = $res; + $result['message'] = '退款失败'; + }; + } catch (\Exception $e){ - Db::rollBack(); - return [ - "status" => 200, - "code" => ErrorCode::ORDER_FAILURE, - "result" => [], - "message" => $e->getMessage() - ]; + $result['message'] = $e->getMessage(); } + return $result; } } \ No newline at end of file diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index d6a2d9f..dd1a8c7 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -323,7 +323,7 @@ class CouponService implements CouponServiceInterface return $res; } - /* 删除-优惠券今日使用的缓存 + /* 删除-优惠券今日使用的缓存 * @param $userId * @param $couponId * @return bool @@ -345,7 +345,7 @@ class CouponService implements CouponServiceInterface * 先查询是否正常使用优惠券 * 修改状态,退还领取记录库存,删除ssdb缓存 */ - public function orderRefundCoupon($global_order_id) + public function orderRefundCoupons($global_order_id) { $time = time(); Db::beginTransaction(); diff --git a/app/Service/CouponServiceInterface.php b/app/Service/CouponServiceInterface.php index 2789efb..4dc0584 100644 --- a/app/Service/CouponServiceInterface.php +++ b/app/Service/CouponServiceInterface.php @@ -29,5 +29,5 @@ interface CouponServiceInterface public function refundOrderCoupons($order_id); public function clearTodayCouponUsed($userId, $couponId); - public function orderRefundCoupon($global_order_id); + public function orderRefundCoupons($global_order_id); } diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index 57aadf3..58a7435 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -759,6 +759,7 @@ class OrderService implements OrderServiceInterface } $orderMain->state = OrderMain::ORDER_STATE_REFUNDED; + if(!$orderMain->save()){ Db::rollBack(); return false; @@ -773,13 +774,40 @@ class OrderService implements OrderServiceInterface Db::rollBack(); return false; } - + if($orderMain->pay_type == OrderMain::ORDER_PAY_WX){ + $data = [ + 'global_order_id' => $global_order_id, + 'money' => $orderMain->money + ]; // 微信支付 微信退款 - if(!$this->wxRefundService->wxPayRefund($global_order_id)){ + $refundRes = $this->wxRefundService->wxPayRefund($data); + var_dump($refundRes); + if( + empty($refundRes) + || !isset($refundRes['result_code']) + || $refundRes['result_code'] != 'SUCCESS' + ){ Db::rollBack(); return false; }; + + /* --- 退款成功 --- */ + $orderMain = $orderMain->fresh(); + if(empty($orderMain->refund_time)){ + // 添加退款时间 + $orderMain->refund_time = time(); + $orderMain->save(); + + // 退款返还优惠券 + $this->couponService->orderRefundCoupons($orderMain->global_order_id); + + // 删除特价商品缓存 + $this->purchaseLimitService->delSsdbPurchaseRecord($orderMain->id); + + // 添加用户的流水 + $this->financialService->userByOLOrderRefund($orderMain->user_id, $orderMain->global_order_id, $orderMain->money); + } }else if($orderMain->pay_type == OrderMain::ORDER_PAY_BALANCE){ // 余额支付 退款到用户余额 // if($this->userService->userWallet($orderMain->user_id,$orderMain->money,Users::WALLET_TYPE_INC)){ @@ -794,10 +822,10 @@ class OrderService implements OrderServiceInterface // 添加用户流水 // $this->financialService->userByOLOrderRefund($orderMain->user_id, $orderMain->global_order_id, $orderMain->money); } - + Db::commit(); return true; - } catch (Exception $e) { + } catch (\Exception $e) { $this->log->event(LogLabel::ORDER_LOG, ['msg'=> '订单退款','exception' => $e->getMessage()]); Db::rollBack(); diff --git a/app/Service/WxRefundService.php b/app/Service/WxRefundService.php index bbd2dd6..aba5531 100644 --- a/app/Service/WxRefundService.php +++ b/app/Service/WxRefundService.php @@ -5,9 +5,10 @@ namespace App\Service; use App\Model\OrderMain; use EasyWeChat\Factory; use Hyperf\DbConnection\Db; -use App\Constants\ErrorCode; use App\Commons\Log; +use App\Constants\LogLabel; use Hyperf\Di\Annotation\Inject; +use Hyperf\Guzzle\CoroutineHandler; class WxRefundService implements WxRefundServiceInterface { @@ -26,29 +27,31 @@ class WxRefundService implements WxRefundServiceInterface $app = Factory::payment($config); $app['guzzle_handler'] = CoroutineHandler::class; + $orderMain = $global_order_id; // 查询订单 - $orderMain = OrderMain::query() - ->select('id','global_order_id','order_num','money','state') - ->where('global_order_id',$global_order_id) - ->where('pay_type',OrderMain::ORDER_PAY_WX) - ->where(Db::raw('refund_time is null')) - ->first(); + // $orderMain = OrderMain::query() + // ->select('id','global_order_id','order_num','money','state') + // ->where('global_order_id',$global_order_id) + // ->where('pay_type',OrderMain::ORDER_PAY_WX) + // ->where(Db::raw('refund_time is null')) + // ->first()->toArray(); + if(empty($orderMain)){ return false; }; + $options = [ - 'refund_desc' => '', - 'notify_url' => config('site_host') . '/wechat/notify/wxpayrefund' + 'refund_desc' => '线上订单退款', + // 'notify_url' => config('site_host') . '/wechat/notify/wxpayrefund' ]; $result = $app->refund->byOutTradeNumber( - $orderMain->global_order_id, - $orderMain->global_order_id, - $orderMain->money * 100, - $orderMain->money * 100, + $orderMain['global_order_id'], + $orderMain['global_order_id'], + $orderMain['money'] * 100, + $orderMain['money'] * 100, $options ); - - $this->log->event('wx_pay_refund',$result); + $this->log->event(LogLabel::WX_PAY_REFUND,$result); return $result; } From 4d9870e8013fa3a77b7d1f071fe95e13d833cea0 Mon Sep 17 00:00:00 2001 From: weigang Date: Wed, 26 Aug 2020 16:50:00 +0800 Subject: [PATCH 51/75] =?UTF-8?q?=E6=88=91=E7=9A=84=E8=AE=A2=E5=8D=95/?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E8=87=AA=E5=8A=A8=E5=8F=96=E6=B6=88/?= =?UTF-8?q?=E7=A4=BE=E5=8C=BA=E6=9C=8D=E5=8A=A1=E7=82=B9=E4=BD=99=E9=A2=9D?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/LogLabel.php | 2 + app/Controller/OrderController.php | 15 +++++ app/Model/Market.php | 30 ++++++++++ app/Model/OrderMain.php | 3 + app/Request/UserOrdersRequest.php | 39 +++++++++++++ app/Service/FinancialRecordService.php | 6 +- app/Service/OrderService.php | 80 ++++++++++++++++++++++++++ app/Service/OrderServiceInterface.php | 17 ++++++ config/routes.php | 1 + 9 files changed, 190 insertions(+), 3 deletions(-) create mode 100644 app/Model/Market.php create mode 100644 app/Request/UserOrdersRequest.php diff --git a/app/Constants/LogLabel.php b/app/Constants/LogLabel.php index 8807da4..e4c5a30 100644 --- a/app/Constants/LogLabel.php +++ b/app/Constants/LogLabel.php @@ -59,4 +59,6 @@ class LogLabel extends AbstractConstants */ const PAY_NOTIFY_REFUND = 'notify_refund'; + const AUTO_CANCEL_USER_ORDER = 'auto_cancel_user_order_log'; + } diff --git a/app/Controller/OrderController.php b/app/Controller/OrderController.php index 0d019f5..df60d53 100644 --- a/app/Controller/OrderController.php +++ b/app/Controller/OrderController.php @@ -7,6 +7,7 @@ use App\Constants\LogLabel; use App\Model\OrderMain; use App\Request\OrderOfflineRequest; use App\Request\OrderOnlineRequest; +use App\Request\UserOrdersRequest; use App\Service\SeparateAccountsServiceInterface; use Hyperf\DbConnection\Db; use Hyperf\Di\Annotation\Inject; @@ -109,4 +110,18 @@ class OrderController extends BaseController return $this->success($this->orderService->onlineCancel($orderMain->global_order_id)); } + /** + * 用户订单 + * @param UserOrdersRequest $request + * @return \Psr\Http\Message\ResponseInterface + */ + public function userOnlineOrders(UserOrdersRequest $request) + { + $params = $request->validated(); + $this->orderService->onlineAutoCancelByUserId($params['user_id']); + $result = $this->orderService->userOnlineOrders($params['user_id'], $params['state'], $params['page'], $params['pagesize']); + + return $this->success($result); + } + } \ No newline at end of file diff --git a/app/Model/Market.php b/app/Model/Market.php new file mode 100644 index 0000000..4d1a2d0 --- /dev/null +++ b/app/Model/Market.php @@ -0,0 +1,30 @@ + 'required|nonempty|integer', + 'market_id' => 'required|nonempty|integer', + 'state' => 'required|integer', + 'page' => 'required|nonempty|integer', + 'pagesize' => 'required|nonempty|integer', + ]; + } + + public function messages(): array + { + return [ + '*.*' => ':attribute 参数不正确', + ]; + } +} diff --git a/app/Service/FinancialRecordService.php b/app/Service/FinancialRecordService.php index fe6a452..4fbfbee 100644 --- a/app/Service/FinancialRecordService.php +++ b/app/Service/FinancialRecordService.php @@ -75,7 +75,7 @@ class FinancialRecordService implements FinancialRecordServiceInterface 'user_type' => UserBalance::USER_TYPE_CS, 'source_id' => $user_id ]); - $balance->balance = bcadd($balance->balance, $money); + $balance->balance = bcadd($balance->balance, $money, 2); $balance->save(); } @@ -99,7 +99,7 @@ class FinancialRecordService implements FinancialRecordServiceInterface 'user_type' => UserBalance::USER_TYPE_CS, 'source_id' => $user_id ]); - $balance->balance = bcadd($balance->balance, $money); + $balance->balance = bcadd($balance->balance, $money, 2); $balance->save(); } @@ -123,7 +123,7 @@ class FinancialRecordService implements FinancialRecordServiceInterface 'user_type' => UserBalance::USER_TYPE_CS, 'source_id' => $user_id ]); - $balance->balance = bcadd($balance->balance, $money); + $balance->balance = bcadd($balance->balance, $money,2); $balance->save(); } diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index fc3c3e0..109cb1f 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -8,6 +8,7 @@ use App\Model\Coupon; use App\Model\CouponRec; use App\Model\CouponUserUse; use App\Model\Goods; +use App\Model\Market; use App\Model\Order; use App\Model\OrderGoods; use App\Model\OrderMain; @@ -857,4 +858,83 @@ class OrderService implements OrderServiceInterface $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); return $ssdb->exec('del', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$userId, $goodId); } + + /** + * @inheritDoc + */ + public function onlineAutoCancelByUserId($user_id) + { + Db::beginTransaction(); + try { + + $orders = OrderMain::query() + ->select(['id', 'global_order_id']) + ->where([ + 'user_id' => $user_id, + 'state' => OrderMain::ORDER_STATE_UNPAY + ]) + ->where('time_add', '<', (time()-900)) + ->get()->toArray(); + + foreach ($orders as $key => &$item) { + $order = OrderMain::query()->find($item['id']); + $order->state = OrderMain::ORDER_STATE_CANCEL; + $order->save(); + + $this->couponService->orderRefundCoupons($item['global_order_id']); + } + + Db::commit(); + return true; + } catch (Exception $e) { + + $this->log->event(LogLabel::AUTO_CANCEL_USER_ORDER, ['exception' => $e->getMessage()]); + Db::rollBack(); + return false; + } + + } + + /** + * @inheritDoc + */ + public function userOnlineOrders($user_id, $state, $page=1, $pagesize=10) + { + $builder = OrderMain::query() + ->where(['user_id' => $user_id, 'del' => OrderMain::ORDER_DEL_NO, 'type' => OrderMain::ORDER_TYPE_ONLINE]); + if ($state != 0) { + $state = explode(',', $state); + $builder = $builder->whereIn('state', $state); + } + $orders = $builder->get()->forPage($page, $pagesize)->toArray(); + + foreach ($orders as $key => &$order) { + // 市场名称 + $order['market_name'] = Market::query()->where(['id' => $order['market_id']])->value('name'); + + // 商品数量和第一个商品名、图 + $orderChildIds = Order::query()->select(['id'])->where(['order_main_id' => $order['id']])->get()->toArray(); + $orderChildIds = array_values(array_column($orderChildIds, 'id')); + $order['g_num'] = OrderGoods::query()->whereIn('order_id', $orderChildIds)->count(); + $goods = OrderGoods::query()->whereIn('order_id', $orderChildIds)->select(['name', 'img'])->first(); + $order['good_name'] = $goods->name; + // TODO 临时写死oss压缩类型 + $order['img'] = $this->switchImgToAliOss($goods->img); + } + + return $orders; + } + + public function switchImgToAliOss($path, $bucket = 'thumbnail_q50') + { + if (strpos($path, 'http') === false || strpos($path, 'https') === false) { + $path = 'https://img.lanzulive.com/' . $path; + } else { + $temp = explode('//', $path); + $temp = explode('/', $temp[1]); + unset($temp[0]); + $path = 'https://img.lanzulive.com/' . implode('/', $temp); + } + return $path . '!' . $bucket; + } } \ No newline at end of file diff --git a/app/Service/OrderServiceInterface.php b/app/Service/OrderServiceInterface.php index a371378..87990eb 100644 --- a/app/Service/OrderServiceInterface.php +++ b/app/Service/OrderServiceInterface.php @@ -72,4 +72,21 @@ interface OrderServiceInterface * 删除特价商品缓存 */ public function clearTodayGoodPurchase($userId, $goodId); + + /** + * 自动取消订单 + * 用户待付款订单超时15分钟未付款 + * @param $user_id + */ + public function onlineAutoCancelByUserId($user_id); + + /** + * 用户订单 + * @param $user_id + * @param $state + * @param int $page + * @param int $pagesize + * @return mixed + */ + public function userOnlineOrders($user_id, $state, $page=1, $pagesize=10); } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index 2a208a7..6a3dc03 100644 --- a/config/routes.php +++ b/config/routes.php @@ -52,6 +52,7 @@ Router::addGroup('/v1/',function (){ Router::post('Order/addOffline', 'App\Controller\OrderController@addOfflineOrder'); Router::post('Order/onlineCancel', 'App\Controller\OrderController@onlineCancel'); Router::post('Order/userComp', 'App\Controller\OrderController@userComp'); + Router::post('Order/userOnlineOrders', 'App\Controller\OrderController@userOnlineOrders'); //小程序支付相关 Router::post('wxminipay/online', 'App\Controller\PaymentController@wxminiPayOnline'); From 3c840930e0f901f885eda937141c6160ea7177bb Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 26 Aug 2020 16:50:07 +0800 Subject: [PATCH 52/75] =?UTF-8?q?=E7=89=B9=E4=BB=B7=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=94=AF=E4=B8=80=E4=BD=86=E6=98=AF=E4=B8=8D=E9=99=90=E5=88=B6?= =?UTF-8?q?=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/ShopCarService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Service/ShopCarService.php b/app/Service/ShopCarService.php index 6f0536d..893e826 100644 --- a/app/Service/ShopCarService.php +++ b/app/Service/ShopCarService.php @@ -32,7 +32,7 @@ class ShopCarService implements ShopCarServiceInterface $goods_exists = ShopCar::where([ ['money','=',0.01], ['user_id','=',$params['user_id']], - ['good_id','=',$params['good_id']] + ['good_id','!=',$params['good_id']] ]) ->exists(); if($goods_exists){ From 54c6697a9ca7ef0d5643f18e7e0592b6ae5c3342 Mon Sep 17 00:00:00 2001 From: weigang Date: Wed, 26 Aug 2020 16:57:44 +0800 Subject: [PATCH 53/75] =?UTF-8?q?=E5=95=86=E6=88=B7=E9=A6=96=E5=8D=95?= =?UTF-8?q?=E5=88=86=E8=B4=A6=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/SeparateAccountsService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Service/SeparateAccountsService.php b/app/Service/SeparateAccountsService.php index 3f89a5c..8cd5266 100644 --- a/app/Service/SeparateAccountsService.php +++ b/app/Service/SeparateAccountsService.php @@ -251,6 +251,7 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface $order->id, FinancialRecord::OFL_FIRST_AWARD_LIMIT_AMOUNT ) + && $order->money >= FinancialRecord::OFL_FIRST_AWARD_LIMIT_AMOUNT ) { $awardAmount = SystemConfig::query()->where(['type' => 1, 'menu_name' => 'award_each_order'])->value('value'); From 692b4ee2a7c555f4296235c8d3ee44c8f914be16 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 26 Aug 2020 17:03:24 +0800 Subject: [PATCH 54/75] =?UTF-8?q?=E7=89=B9=E4=BB=B7=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=AF=8F=E6=97=A5=E5=8F=AA=E8=83=BD=E8=B4=AD=E4=B9=B0=E4=B8=80?= =?UTF-8?q?=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/ShopCarService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Service/ShopCarService.php b/app/Service/ShopCarService.php index 893e826..f761187 100644 --- a/app/Service/ShopCarService.php +++ b/app/Service/ShopCarService.php @@ -19,7 +19,7 @@ class ShopCarService implements ShopCarServiceInterface { //获取ssdb购买记录 $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - $record_exists = $ssdb->exec('get',PURCHASE_RECORD. date('Ymd') .'_'.$params['user_id'].'_'.$params['good_id']); + $record_exists = $ssdb->exec('get',SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$params['user_id'].'_'.$params['good_id']); if($record_exists) { $error = [ From 547b10793b1c741c27867f2e72171af871f439f9 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Wed, 26 Aug 2020 17:14:07 +0800 Subject: [PATCH 55/75] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E9=80=80=E6=AC=BE--?= =?UTF-8?q?=E4=BF=AE=E6=94=B93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/OrderService.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index 7931b32..db8777a 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -23,6 +23,7 @@ use App\Service\WxRefundServiceInterface; use App\Service\UserServiceInterface; use App\Model\Users; use App\Constants\SsdbKeysPrefix; +use App\Service\PurchaseLimitServiceInterface; class OrderService implements OrderServiceInterface { @@ -56,6 +57,12 @@ class OrderService implements OrderServiceInterface */ protected $purchaseLimitService; + /** + * @Inject + * @var FinancialRecordServiceInterface + */ + protected $financialService; + /** * @inheritDoc */ @@ -745,8 +752,6 @@ class OrderService implements OrderServiceInterface { Db::beginTransaction(); try { - - $time = time(); // 主订单状态更新 $orderMain = OrderMain::query() ->select('id','global_order_id','state','pay_type','user_id','money') @@ -755,14 +760,14 @@ class OrderService implements OrderServiceInterface if (empty($orderMain)) { Db::rollBack(); - return false; + return '查询不到订单'; } $orderMain->state = OrderMain::ORDER_STATE_REFUNDED; if(!$orderMain->save()){ Db::rollBack(); - return false; + return '更新主订单失败'; }; // 子订单状态更新 @@ -772,7 +777,7 @@ class OrderService implements OrderServiceInterface ->update(['state' => OrderMain::ORDER_STATE_REFUNDED]); if(empty($upChild)){ Db::rollBack(); - return false; + return '更新子订单失败'; } if($orderMain->pay_type == OrderMain::ORDER_PAY_WX){ @@ -789,7 +794,7 @@ class OrderService implements OrderServiceInterface || $refundRes['result_code'] != 'SUCCESS' ){ Db::rollBack(); - return false; + return $refundRes; }; /* --- 退款成功 --- */ From 15dc401048d315324845583ac178f5df23665cdf Mon Sep 17 00:00:00 2001 From: weigang Date: Wed, 26 Aug 2020 17:30:05 +0800 Subject: [PATCH 56/75] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=88=91=E7=9A=84?= =?UTF-8?q?=E8=AE=A2=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CommunityController.php | 3 ++- app/Request/UserOrdersRequest.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Controller/CommunityController.php b/app/Controller/CommunityController.php index 0caa660..5fa8ca4 100644 --- a/app/Controller/CommunityController.php +++ b/app/Controller/CommunityController.php @@ -21,7 +21,8 @@ class CommunityController extends BaseController public function bind(CommunityBindRequest $request) { $data = $request->validated(); - $res = $this->userCommunityService->bindLimitByUser(UserRelationBind::BIND_TYPE_COMMUNITY, $data['source_id'], $data['user_id'], $data['json_data']); + $jsonData = $data['json_data'] ?? json_encode([]); + $res = $this->userCommunityService->bindLimitByUser(UserRelationBind::BIND_TYPE_COMMUNITY, $data['source_id'], $data['user_id'], $jsonData); return $this->success(['id' => $res->id]); } diff --git a/app/Request/UserOrdersRequest.php b/app/Request/UserOrdersRequest.php index d787e54..092f96e 100644 --- a/app/Request/UserOrdersRequest.php +++ b/app/Request/UserOrdersRequest.php @@ -24,7 +24,7 @@ class UserOrdersRequest extends FormRequest return [ 'user_id' => 'required|nonempty|integer', 'market_id' => 'required|nonempty|integer', - 'state' => 'required|integer', + 'state' => 'required', 'page' => 'required|nonempty|integer', 'pagesize' => 'required|nonempty|integer', ]; From f78ee03c79d192911738d97e8a1b30d720716933 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 26 Aug 2020 17:34:32 +0800 Subject: [PATCH 57/75] ssdb --- app/Constants/SsdbKeysPrefix.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Constants/SsdbKeysPrefix.php b/app/Constants/SsdbKeysPrefix.php index 00e7bf1..0801b10 100644 --- a/app/Constants/SsdbKeysPrefix.php +++ b/app/Constants/SsdbKeysPrefix.php @@ -49,6 +49,7 @@ class SsdbKeysPrefix extends AbstractConstants /** * @Message("PURCHASE RECORD") + * */ const PURCHASE_RECORD = 'purchase_record_'; } From 19852115e9b55647f8e6fa47842b4d8a340b5331 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Wed, 26 Aug 2020 17:48:37 +0800 Subject: [PATCH 58/75] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E9=80=80=E6=AC=BE--?= =?UTF-8?q?=E4=BF=AE=E6=94=B94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/NotifyPayRefundController.php | 7 +- app/JsonRpc/OrderService.php | 25 +++--- app/Service/OrderService.php | 82 +++++++++++--------- app/Service/PurchaseLimitService.php | 2 + app/Service/WxRefundService.php | 21 +++-- 5 files changed, 72 insertions(+), 65 deletions(-) diff --git a/app/Controller/NotifyPayRefundController.php b/app/Controller/NotifyPayRefundController.php index dbc9c53..dbeb6fa 100644 --- a/app/Controller/NotifyPayRefundController.php +++ b/app/Controller/NotifyPayRefundController.php @@ -1,12 +1,11 @@ [], "message" => '' ]; - try{ - $res = $this->orderService->onlineRefund($global_order_id); - if($res){ - $result['code'] = 0; - $result['result'] = $res; - $result['message'] = '退款成功'; - }else{ - $result['result'] = $res; - $result['message'] = '退款失败'; - }; - - } catch (\Exception $e){ - $result['message'] = $e->getMessage(); - } + + $res = $this->orderService->onlineRefund($global_order_id); + if($res['code'] > 0){ + $result['result'] = $res; + $result['message'] = '退款失败'; + }else{ + $result['code'] = 0; + $result['result'] = $res; + $result['message'] = '退款成功'; + }; + return $result; } } \ No newline at end of file diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index d32f54a..6db3f6c 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -761,14 +761,20 @@ class OrderService implements OrderServiceInterface if (empty($orderMain)) { Db::rollBack(); - return '查询不到订单'; + return [ + 'code' => 1, + 'msg' =>'查询不到订单' + ]; } $orderMain->state = OrderMain::ORDER_STATE_REFUNDED; if(!$orderMain->save()){ Db::rollBack(); - return '更新主订单失败'; + return [ + 'code' => 2, + 'msg' =>'更新主订单失败' + ]; }; // 子订单状态更新 @@ -778,64 +784,68 @@ class OrderService implements OrderServiceInterface ->update(['state' => OrderMain::ORDER_STATE_REFUNDED]); if(empty($upChild)){ Db::rollBack(); - return '更新子订单失败'; + return [ + 'code' => 3, + 'msg' =>'更新子订单失败' + ]; } if($orderMain->pay_type == OrderMain::ORDER_PAY_WX){ - $data = [ - 'global_order_id' => $global_order_id, - 'money' => $orderMain->money - ]; + // 微信支付 微信退款 - $refundRes = $this->wxRefundService->wxPayRefund($data); + $refundRes = $this->wxRefundService->wxPayRefund($orderMain->global_order_id); var_dump($refundRes); if( empty($refundRes) + || !$refundRes || !isset($refundRes['result_code']) || $refundRes['result_code'] != 'SUCCESS' ){ Db::rollBack(); return $refundRes; }; - - /* --- 退款成功 --- */ - $orderMain = $orderMain->fresh(); - if(empty($orderMain->refund_time)){ - // 添加退款时间 - $orderMain->refund_time = time(); - $orderMain->save(); - - // 退款返还优惠券 - $this->couponService->orderRefundCoupons($orderMain->global_order_id); - - // 删除特价商品缓存 - $this->purchaseLimitService->delSsdbPurchaseRecord($orderMain->id); - - // 添加用户的流水 - $this->financialService->userByOLOrderRefund($orderMain->user_id, $orderMain->global_order_id, $orderMain->money); - } }else if($orderMain->pay_type == OrderMain::ORDER_PAY_BALANCE){ + // 余额支付 退款到用户余额 - // if($this->userService->userWallet($orderMain->user_id,$orderMain->money,Users::WALLET_TYPE_INC)){ - // Db::rollBack(); - // return false; - // }; + if($this->userService->userWallet($orderMain->user_id,$orderMain->money,Users::WALLET_TYPE_INC)){ + Db::rollBack(); + return [ + 'code' => 4, + 'msg' =>'退款到用户余额失败' + ]; + }; + } - // 返还优惠券 - // $this->couponService->orderRefundCoupon($global_order_id); + /* --- 退款成功 --- */ + $orderMain = $orderMain->fresh(); + if(empty($orderMain->refund_time)){ + // 添加退款时间 + $orderMain->refund_time = time(); + $orderMain->save(); + + // 退款返还优惠券 + $this->couponService->orderRefundCoupons($orderMain->global_order_id); + // 删除特价商品缓存 - // $this->orderService->clearTodayGoodPurchase($orderMain->user_id,1); - // 添加用户流水 - // $this->financialService->userByOLOrderRefund($orderMain->user_id, $orderMain->global_order_id, $orderMain->money); + $this->purchaseLimitService->delSsdbPurchaseRecord($orderMain->global_order_id); + + // 添加用户的流水 + $this->financialService->userByOLOrderRefund($orderMain->user_id, $orderMain->global_order_id, $orderMain->money); } Db::commit(); - return true; + return [ + 'code' => 0, + 'msg' =>'退款成功' + ]; } catch (\Exception $e) { $this->log->event(LogLabel::ORDER_LOG, ['msg'=> '订单退款','exception' => $e->getMessage()]); Db::rollBack(); - return false; + return [ + 'code' => 5, + 'msg' => $e->getMessage() + ]; } } diff --git a/app/Service/PurchaseLimitService.php b/app/Service/PurchaseLimitService.php index 8bbd222..3c10a5a 100644 --- a/app/Service/PurchaseLimitService.php +++ b/app/Service/PurchaseLimitService.php @@ -52,7 +52,9 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface $order_main = OrderMain::where('global_order_id',$global_order_id) ->select('id','user_id') ->first(); + $order_id = $order_main->id; + $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); $order = Order::query() ->where('order_main_id',$order_id) diff --git a/app/Service/WxRefundService.php b/app/Service/WxRefundService.php index aba5531..7fe5362 100644 --- a/app/Service/WxRefundService.php +++ b/app/Service/WxRefundService.php @@ -27,14 +27,13 @@ class WxRefundService implements WxRefundServiceInterface $app = Factory::payment($config); $app['guzzle_handler'] = CoroutineHandler::class; - $orderMain = $global_order_id; // 查询订单 - // $orderMain = OrderMain::query() - // ->select('id','global_order_id','order_num','money','state') - // ->where('global_order_id',$global_order_id) - // ->where('pay_type',OrderMain::ORDER_PAY_WX) - // ->where(Db::raw('refund_time is null')) - // ->first()->toArray(); + $orderMain = OrderMain::query() + ->select('id','global_order_id','order_num','money','state') + ->where('global_order_id',$global_order_id) + ->where('pay_type',OrderMain::ORDER_PAY_WX) + ->where(Db::raw('refund_time is null')) + ->first()->toArray(); if(empty($orderMain)){ return false; @@ -45,10 +44,10 @@ class WxRefundService implements WxRefundServiceInterface // 'notify_url' => config('site_host') . '/wechat/notify/wxpayrefund' ]; $result = $app->refund->byOutTradeNumber( - $orderMain['global_order_id'], - $orderMain['global_order_id'], - $orderMain['money'] * 100, - $orderMain['money'] * 100, + $orderMain->global_order_id, + $orderMain->global_order_id, + $orderMain->money * 100, + $orderMain->money * 100, $options ); $this->log->event(LogLabel::WX_PAY_REFUND,$result); From 079f2e52554336f550d70af8c7e6f3f310cfd696 Mon Sep 17 00:00:00 2001 From: weigang Date: Wed, 26 Aug 2020 17:54:53 +0800 Subject: [PATCH 59/75] fix --- app/Controller/NotifyController.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Controller/NotifyController.php b/app/Controller/NotifyController.php index 1ddfb11..1073dc2 100644 --- a/app/Controller/NotifyController.php +++ b/app/Controller/NotifyController.php @@ -115,7 +115,7 @@ class NotifyController extends BaseController $message ); Db::rollBack(); - $fail('Unknown error but FAIL'); + return $fail('Unknown error but FAIL'); } // 查询订单 @@ -127,7 +127,7 @@ class NotifyController extends BaseController ->first(); // 订单不存在 - if (empty($orderMain)) { + if (empty($orderMain) || $orderMain->state == OrderMain::ORDER_STATE_DELIVERY) { $this->log->event( LogLabel::PAY_NOTIFY_WXMINI, ['global_order_id_fail' => $message['out_trade_no']] @@ -222,7 +222,7 @@ class NotifyController extends BaseController ['exception_fail' => $e->getMessage()] ); Db::rollBack(); - $fail('Exception'); + return $fail('Exception'); } }); @@ -267,7 +267,7 @@ class NotifyController extends BaseController $message ); Db::rollBack(); - $fail('Unknown error but FAIL'); + return $fail('Unknown error but FAIL'); } // 查询订单 @@ -397,7 +397,7 @@ class NotifyController extends BaseController ['exception_fail' => $e->getMessage()] ); Db::rollBack(); - $fail('Exception'); + return $fail('Exception'); } }); From 7b60fd0238079068d3c4ffb411e828c11ab8e02e Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 26 Aug 2020 18:16:06 +0800 Subject: [PATCH 60/75] =?UTF-8?q?=E7=89=B9=E4=BB=B7=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=8C=BA=E5=88=86=E5=B8=82=E5=9C=BA=20=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E4=BA=8B=E5=8A=A1=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/OrderController.php | 7 ++++++- app/Service/ShopCarService.php | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/Controller/OrderController.php b/app/Controller/OrderController.php index df60d53..0af4184 100644 --- a/app/Controller/OrderController.php +++ b/app/Controller/OrderController.php @@ -107,7 +107,12 @@ class OrderController extends BaseController $orderMain = OrderMain::where('id',$orderId) ->select('global_order_id') ->first(); - return $this->success($this->orderService->onlineCancel($orderMain->global_order_id)); + $res = $this->orderService->onlineCancel($orderMain->global_order_id); + if($res){ + return $this->success($res); + }else{ + return $this->result(ErrorCode::ORDER_FAILURE, '', '取消订单失败'); + } } /** diff --git a/app/Service/ShopCarService.php b/app/Service/ShopCarService.php index f761187..c4d598c 100644 --- a/app/Service/ShopCarService.php +++ b/app/Service/ShopCarService.php @@ -30,9 +30,10 @@ class ShopCarService implements ShopCarServiceInterface //一个订单只能添加一个特价商品 if($params['money'] == 0.01){ $goods_exists = ShopCar::where([ - ['money','=',0.01], ['user_id','=',$params['user_id']], - ['good_id','!=',$params['good_id']] + ['good_id','!=',$params['good_id']], + ['market_id','=',$params['market_id']], + ['money','=',0.01] ]) ->exists(); if($goods_exists){ From 3a90c0b9942b87074d9c61afcd12580c690e01f1 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 26 Aug 2020 18:21:58 +0800 Subject: [PATCH 61/75] =?UTF-8?q?=E5=8F=96=E6=B6=88=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/OrderService.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index 6db3f6c..3b0e76a 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -738,8 +738,11 @@ class OrderService implements OrderServiceInterface * @inheritDoc */ public function onlineCancel($global_order_id){ - OrderMain::where('global_order_id',$global_order_id) + $sqlRes = OrderMain::where('global_order_id',$global_order_id) ->update(['state' => OrderMain::ORDER_STATE_CANCEL]); + if(!$sqlRes){ + return false; + } //撤销redis 用券记录 $redisRes = $this->couponService->orderRefundCoupons($global_order_id); //撤销特价商品购买记录 From b05c228d4a1b1f1a6addfef6dfce7a689a3bc07a Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 26 Aug 2020 19:45:46 +0800 Subject: [PATCH 62/75] =?UTF-8?q?=E5=8F=96=E6=B6=88=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A0=A1=E9=AA=8C=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/OrderController.php | 6 +++-- app/Request/OnlineCancelRequest.php | 40 +++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 app/Request/OnlineCancelRequest.php diff --git a/app/Controller/OrderController.php b/app/Controller/OrderController.php index 0af4184..5aa7160 100644 --- a/app/Controller/OrderController.php +++ b/app/Controller/OrderController.php @@ -7,6 +7,7 @@ use App\Constants\LogLabel; use App\Model\OrderMain; use App\Request\OrderOfflineRequest; use App\Request\OrderOnlineRequest; +use App\Request\OnlineCancelRequest; use App\Request\UserOrdersRequest; use App\Service\SeparateAccountsServiceInterface; use Hyperf\DbConnection\Db; @@ -101,9 +102,10 @@ class OrderController extends BaseController /** * 用户取消订单 + * @param OnlineCancelRequest $request */ - public function onlineCancel(){ - $orderId = $this->request->input('order_id'); + public function onlineCancel(OnlineCancelRequest $request){ + $orderId = $request->input('order_id'); $orderMain = OrderMain::where('id',$orderId) ->select('global_order_id') ->first(); diff --git a/app/Request/OnlineCancelRequest.php b/app/Request/OnlineCancelRequest.php new file mode 100644 index 0000000..5cea6d8 --- /dev/null +++ b/app/Request/OnlineCancelRequest.php @@ -0,0 +1,40 @@ + 'required|nonempty|integer|exists:ims_cjdc_order_main,id', + ]; + } + + public function messages(): array + { + return [ + 'order_id.*' => ':attribute信息不正确', + ]; + } + + public function attributes(): array + { + return [ + 'order_id' => '订单号', + ]; + } +} From 0b68216cb09f36e2e0a78f3405a4f9d5c7b9008f Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Wed, 26 Aug 2020 20:18:05 +0800 Subject: [PATCH 63/75] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E9=80=80=E6=AC=BE--?= =?UTF-8?q?=E4=BF=AE=E6=94=B95-=E5=BE=AE=E4=BF=A1=E9=80=80=E6=AC=BE?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/OrderService.php | 1 - app/Service/WxRefundService.php | 57 ++++++++++++++++++++------------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index 3b0e76a..7c40f85 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -797,7 +797,6 @@ class OrderService implements OrderServiceInterface // 微信支付 微信退款 $refundRes = $this->wxRefundService->wxPayRefund($orderMain->global_order_id); - var_dump($refundRes); if( empty($refundRes) || !$refundRes diff --git a/app/Service/WxRefundService.php b/app/Service/WxRefundService.php index 7fe5362..6c7545e 100644 --- a/app/Service/WxRefundService.php +++ b/app/Service/WxRefundService.php @@ -9,6 +9,8 @@ use App\Commons\Log; use App\Constants\LogLabel; use Hyperf\Di\Annotation\Inject; use Hyperf\Guzzle\CoroutineHandler; +use Hyperf\Database\Exception\QueryException; +use App\Exception\BusinessException; class WxRefundService implements WxRefundServiceInterface { @@ -23,33 +25,42 @@ class WxRefundService implements WxRefundServiceInterface */ public function wxPayRefund($global_order_id) { - $config = config('wxpay'); - $app = Factory::payment($config); - $app['guzzle_handler'] = CoroutineHandler::class; - - // 查询订单 - $orderMain = OrderMain::query() - ->select('id','global_order_id','order_num','money','state') + try{ + $config = config('wxpay'); + $app = Factory::payment($config); + $app['guzzle_handler'] = CoroutineHandler::class; + + // 查询订单 + $orderMain = OrderMain::query() + ->select(['id','global_order_id','order_num','money','state']) ->where('global_order_id',$global_order_id) ->where('pay_type',OrderMain::ORDER_PAY_WX) - ->where(Db::raw('refund_time is null')) - ->first()->toArray(); + ->whereRaw('refund_time is null') + ->first(); - if(empty($orderMain)){ - return false; - }; + if(empty($orderMain)){ + return false; + }; - $options = [ - 'refund_desc' => '线上订单退款', - // 'notify_url' => config('site_host') . '/wechat/notify/wxpayrefund' - ]; - $result = $app->refund->byOutTradeNumber( - $orderMain->global_order_id, - $orderMain->global_order_id, - $orderMain->money * 100, - $orderMain->money * 100, - $options - ); + $options = [ + 'refund_desc' => '线上订单退款', + // 'notify_url' => config('site_host') . '/wechat/notify/wxpayrefund' + ]; + $result = $app->refund->byOutTradeNumber( + $orderMain->global_order_id, + $orderMain->global_order_id, + $orderMain->money * 100, + $orderMain->money * 100, + $options + ); + } catch (QueryException $e) { + $this->log->event(LogLabel::WX_PAY_REFUND,$e->getMessage()); + return false; + } catch (BusinessException $e){ + $this->log->event(LogLabel::WX_PAY_REFUND,$e->getMessage()); + return false; + } + $this->log->event(LogLabel::WX_PAY_REFUND,$result); return $result; } From 153e0235bdac5c3b93685e6b4be6cee203f60f95 Mon Sep 17 00:00:00 2001 From: weigang Date: Wed, 26 Aug 2020 21:10:54 +0800 Subject: [PATCH 64/75] =?UTF-8?q?=E7=A4=BE=E5=8C=BA=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=82=B9=E5=88=86=E8=B4=A6=E7=9F=AD=E4=BF=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/AdminUser.php | 29 +++++++++++ app/Model/CsInfo.php | 29 +++++++++++ app/Service/FinancialRecordService.php | 17 ++++++- app/Service/SmsAliService.php | 68 ++++++++++++++++++++++++++ app/Service/SmsServiceInterface.php | 9 ++++ composer.json | 3 +- config/autoload/dependencies.php | 1 + config/config.php | 7 +++ 8 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 app/Model/AdminUser.php create mode 100644 app/Model/CsInfo.php create mode 100644 app/Service/SmsAliService.php create mode 100644 app/Service/SmsServiceInterface.php diff --git a/app/Model/AdminUser.php b/app/Model/AdminUser.php new file mode 100644 index 0000000..d2ed2b6 --- /dev/null +++ b/app/Model/AdminUser.php @@ -0,0 +1,29 @@ +balance = bcadd($balance->balance, $money, 2); $balance->save(); + + // 发送短信 + $this->smsAliService->sendForCommunityFinancial($user_id, $money); + } /** @@ -101,6 +110,9 @@ class FinancialRecordService implements FinancialRecordServiceInterface ]); $balance->balance = bcadd($balance->balance, $money, 2); $balance->save(); + + // 发送短信 + $this->smsAliService->sendForCommunityFinancial($user_id, $money); } /** @@ -125,6 +137,9 @@ class FinancialRecordService implements FinancialRecordServiceInterface ]); $balance->balance = bcadd($balance->balance, $money,2); $balance->save(); + + // 发送短信 + $this->smsAliService->sendForCommunityFinancial($user_id, $money); } diff --git a/app/Service/SmsAliService.php b/app/Service/SmsAliService.php new file mode 100644 index 0000000..9c709f6 --- /dev/null +++ b/app/Service/SmsAliService.php @@ -0,0 +1,68 @@ +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(['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)); + } +} \ No newline at end of file diff --git a/app/Service/SmsServiceInterface.php b/app/Service/SmsServiceInterface.php new file mode 100644 index 0000000..7f69282 --- /dev/null +++ b/app/Service/SmsServiceInterface.php @@ -0,0 +1,9 @@ + \App\Service\SeparateAccountsService::class, \App\Service\ShopCarServiceInterface::class => \App\Service\ShopCarService::class, \App\Service\WxRefundServiceInterface::class => \App\Service\WxRefundService::class, + \App\Service\SmsServiceInterface::class => \App\Service\SmsAliService::class, ]; diff --git a/config/config.php b/config/config.php index ba75ad6..d416f7f 100644 --- a/config/config.php +++ b/config/config.php @@ -40,5 +40,12 @@ return [ 'wxtempmsg' => [ 'app_id' => env('APP_ID',''), 'secret' => env('APP_SECRET',''), + ], + 'alisms' => [ + 'app_key' => env('ALI_SMS_APP_KEY', ''), + 'app_secret' => env('ALI_SMS_APP_SECRET', ''), + 'regionid' => env('ALI_SMS_REGION_ID', ''), + 'product' => env('ALI_SMS_PRODUCT', ''), + 'host' => env('ALI_SMS_HOST', ''), ] ]; From d95945d27f2cbed7b9761c47b741a8429277e972 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 26 Aug 2020 21:17:57 +0800 Subject: [PATCH 65/75] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AE=A2=E5=8D=95=20?= =?UTF-8?q?=E4=BB=98=E6=AC=BE=20=E7=89=B9=E4=BB=B7=E5=95=86=E5=93=81?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E8=B6=85=E8=BF=87=E4=B8=80=E4=B8=AA=E6=8B=A6?= =?UTF-8?q?=E6=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/PurchaseLimitController.php | 2 +- app/Service/OrderService.php | 6 ++++++ app/Service/PurchaseLimitService.php | 14 ++++++++++++++ app/Service/PurchaseLimitServiceInterface.php | 2 ++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/Controller/PurchaseLimitController.php b/app/Controller/PurchaseLimitController.php index 32fca1f..4e9e3fe 100644 --- a/app/Controller/PurchaseLimitController.php +++ b/app/Controller/PurchaseLimitController.php @@ -36,7 +36,7 @@ class PurchaseLimitController extends BaseController public function test() { - $res = $this->purchaseLimitService->test($this->request->all()); + $res = $this->purchaseLimitService->PurchaseLimit($this->request->input('global_order_id')); return $this->success($res); } diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index 3b0e76a..a02634e 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -300,6 +300,12 @@ class OrderService implements OrderServiceInterface Db::rollBack(); return '订单商品异常'; } + //判断是否有购买多个特价商品 + $result = $this->purchaseLimitService->PurchaseLimit($orderGoods); + if(!$result){ + Db::rollBack(); + return '同一个订单不能购买多个特价商品'; + } //判断是否有购买特价商品 $this->purchaseLimitService->ssdbPurchaseRecord($orderGoods,$data['user_id'],$dataMain['global_order_id']); diff --git a/app/Service/PurchaseLimitService.php b/app/Service/PurchaseLimitService.php index 3c10a5a..cfb41ef 100644 --- a/app/Service/PurchaseLimitService.php +++ b/app/Service/PurchaseLimitService.php @@ -78,6 +78,20 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface return true; } + public function PurchaseLimit($orderGoods) + { + foreach ($orderGoods as $goods){ + $sum = 0; + if($goods['money'] == 0.01){ + if($sum > 0){ + return false; + } + $sum++; + } + } + return true; + } + public function test($params) { $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); diff --git a/app/Service/PurchaseLimitServiceInterface.php b/app/Service/PurchaseLimitServiceInterface.php index f5e415b..da0f536 100644 --- a/app/Service/PurchaseLimitServiceInterface.php +++ b/app/Service/PurchaseLimitServiceInterface.php @@ -12,5 +12,7 @@ interface PurchaseLimitServiceInterface public function delSsdbPurchaseRecord($global_order_id); + public function PurchaseLimit($orderGoods); + public function test($params); } \ No newline at end of file From 84d0d538acb7367e872099cc87fbc0f191076abc Mon Sep 17 00:00:00 2001 From: weigang Date: Wed, 26 Aug 2020 21:26:02 +0800 Subject: [PATCH 66/75] =?UTF-8?q?=E7=9F=AD=E4=BF=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/SmsAliService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Service/SmsAliService.php b/app/Service/SmsAliService.php index 9c709f6..6b98ed4 100644 --- a/app/Service/SmsAliService.php +++ b/app/Service/SmsAliService.php @@ -59,7 +59,7 @@ class SmsAliService implements SmsServiceInterface public function sendForCommunityFinancial($userId, $money) { - $csInfo = CsInfo::query()->where(['user_id' => $userId])->first(); + $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]; From 9c2da8289922d4c87a44d10a164e10e848f277de Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 26 Aug 2020 21:40:13 +0800 Subject: [PATCH 67/75] =?UTF-8?q?=E4=BB=98=E6=AC=BE=E6=A0=A1=E9=AA=8C=20?= =?UTF-8?q?=E5=90=8C=E4=B8=80=E8=AE=A2=E5=8D=95=E4=B8=8D=E8=83=BD=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=A4=9A=E4=B8=AA=E7=89=B9=E4=BB=B7=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/PaymentController.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app/Controller/PaymentController.php b/app/Controller/PaymentController.php index 9fc92ae..ec7d6d6 100644 --- a/app/Controller/PaymentController.php +++ b/app/Controller/PaymentController.php @@ -3,14 +3,23 @@ namespace App\Controller; use App\Constants\ErrorCode; +use App\Model\Order; +use App\Model\OrderGoods; use App\Model\OrderMain; use App\Request\WxminiPayRequest; +use App\Service\PurchaseLimitServiceInterface; use EasyWeChat\Factory; +use Hyperf\DbConnection\Db; use Hyperf\Guzzle\CoroutineHandler; class PaymentController extends BaseController { + /** + * @Inject + * @var PurchaseLimitServiceInterface + */ + protected $purchaseLimitService; public function wxminiPayOnline(WxminiPayRequest $request){ @@ -30,6 +39,22 @@ class PaymentController extends BaseController return $this->result(ErrorCode::PAY_FAILURE, $data,'订单不存在或已失效'); } + //查询订单商品信息 + $order = Order::query() + ->where('order_main_id',$data['order_id']) + ->select('id') + ->get() + ->toArray(); + $orderGoods = OrderGoods::query() + ->whereIn('order_id',$order) + ->get(); + //判断是否有购买多个特价商品 + $result = $this->purchaseLimitService->PurchaseLimit($orderGoods); + if(!$result){ + Db::rollBack(); + return '同一个订单不能购买多个特价商品'; + } + $result = $app->order->unify([ 'body' => '懒族生活 - 外卖下单', 'out_trade_no' => $orderMain->global_order_id, From aeb2db3cb0441ec0947c9ed82824c07ffed0e751 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 26 Aug 2020 21:53:02 +0800 Subject: [PATCH 68/75] =?UTF-8?q?=E5=A4=A7=E4=BA=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/PaymentController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Controller/PaymentController.php b/app/Controller/PaymentController.php index ec7d6d6..1355125 100644 --- a/app/Controller/PaymentController.php +++ b/app/Controller/PaymentController.php @@ -7,7 +7,7 @@ use App\Model\Order; use App\Model\OrderGoods; use App\Model\OrderMain; use App\Request\WxminiPayRequest; - +use Hyperf\Di\Annotation\Inject; use App\Service\PurchaseLimitServiceInterface; use EasyWeChat\Factory; use Hyperf\DbConnection\Db; From ede3b1478a377ec09e292b7daebc9db3514a2db5 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Thu, 27 Aug 2020 09:51:41 +0800 Subject: [PATCH 69/75] =?UTF-8?q?=E6=94=AF=E4=BB=98=20=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=8B=A6=E6=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/PaymentController.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Controller/PaymentController.php b/app/Controller/PaymentController.php index 1355125..c6c9788 100644 --- a/app/Controller/PaymentController.php +++ b/app/Controller/PaymentController.php @@ -12,7 +12,8 @@ use App\Service\PurchaseLimitServiceInterface; use EasyWeChat\Factory; use Hyperf\DbConnection\Db; use Hyperf\Guzzle\CoroutineHandler; - +use App\Constants\LogLabel; +use App\Commons\Log; class PaymentController extends BaseController { /** @@ -52,7 +53,8 @@ class PaymentController extends BaseController $result = $this->purchaseLimitService->PurchaseLimit($orderGoods); if(!$result){ Db::rollBack(); - return '同一个订单不能购买多个特价商品'; + $this->log->event(LogLabel::ORDER_LOG, ['msg'=> '支付失败,同一订单不能存在多个特价商品','global_order_id' => $orderMain->global_order_id]); + return $this->result(ErrorCode::PAY_FAILURE, $data,'同一订单不能存在多个特价商品'); } $result = $app->order->unify([ From 0a7b59e9747d00b16c2fe8804da4f6e1e77cfcf3 Mon Sep 17 00:00:00 2001 From: weigang Date: Thu, 27 Aug 2020 11:08:25 +0800 Subject: [PATCH 70/75] =?UTF-8?q?=E6=88=91=E7=9A=84=E5=AE=9A=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/AttachmentService.php | 13 +++++++++++++ app/Service/OrderService.php | 21 +++++++-------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/app/Service/AttachmentService.php b/app/Service/AttachmentService.php index 65ab9a4..a788e6c 100644 --- a/app/Service/AttachmentService.php +++ b/app/Service/AttachmentService.php @@ -70,4 +70,17 @@ class AttachmentService implements AttachmentServiceInterface $path .= '/'.date('Y').'/'.date('m').'/'.date('d'); return $baseDir.$path; } + + public function switchImgToAliOss($path, $bucket = 'thumbnail_q50') + { + if (strpos($path, 'http') === false || strpos($path, 'https') === false) { + $path = 'https://img.lanzulive.com/' . $path; + } else { + $temp = explode('//', $path); + $temp = explode('/', $temp[1]); + unset($temp[0]); + $path = 'https://img.lanzulive.com/' . implode('/', $temp); + } + return $path . '!' . $bucket; + } } \ No newline at end of file diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index bd6f500..daed1af 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -64,6 +64,12 @@ class OrderService implements OrderServiceInterface */ protected $financialService; + /** + * @Inject + * @var AttachmentServiceInterface + */ + protected $attachmentService; + /** * @inheritDoc */ @@ -972,22 +978,9 @@ class OrderService implements OrderServiceInterface $goods = OrderGoods::query()->whereIn('order_id', $orderChildIds)->select(['name', 'img'])->first(); $order['good_name'] = $goods->name; // TODO 临时写死oss压缩类型 - $order['img'] = $this->switchImgToAliOss($goods->img); + $order['img'] = $this->attachmentService->switchImgToAliOss($goods->img); } return $orders; } - - public function switchImgToAliOss($path, $bucket = 'thumbnail_q50') - { - if (strpos($path, 'http') === false || strpos($path, 'https') === false) { - $path = 'https://img.lanzulive.com/' . $path; - } else { - $temp = explode('//', $path); - $temp = explode('/', $temp[1]); - unset($temp[0]); - $path = 'https://img.lanzulive.com/' . implode('/', $temp); - } - return $path . '!' . $bucket; - } } \ No newline at end of file From e55ffc600d8002496c8d7ddcc9d42fed86fadeff Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Thu, 27 Aug 2020 11:41:01 +0800 Subject: [PATCH 71/75] =?UTF-8?q?=E7=89=B9=E4=BB=B7=E5=95=86=E5=93=81?= =?UTF-8?q?=E4=B8=8B=E5=8D=95=E6=94=AF=E4=BB=98=E6=8B=A6=E6=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/PaymentController.php | 2 +- app/Service/OrderService.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Controller/PaymentController.php b/app/Controller/PaymentController.php index c6c9788..c691ed6 100644 --- a/app/Controller/PaymentController.php +++ b/app/Controller/PaymentController.php @@ -51,7 +51,7 @@ class PaymentController extends BaseController ->get(); //判断是否有购买多个特价商品 $result = $this->purchaseLimitService->PurchaseLimit($orderGoods); - if(!$result){ + if($result > 1){ Db::rollBack(); $this->log->event(LogLabel::ORDER_LOG, ['msg'=> '支付失败,同一订单不能存在多个特价商品','global_order_id' => $orderMain->global_order_id]); return $this->result(ErrorCode::PAY_FAILURE, $data,'同一订单不能存在多个特价商品'); diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index 34ace3b..38802eb 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -308,7 +308,7 @@ class OrderService implements OrderServiceInterface } //判断是否有购买多个特价商品 $result = $this->purchaseLimitService->PurchaseLimit($orderGoods); - if($result > 0){ + if($result > 1){ Db::rollBack(); return '同一个订单不能购买多个特价商品'; } From 318547e9c86c30ddfd0a899c74d3278bbee7b21e Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Thu, 27 Aug 2020 13:10:40 +0800 Subject: [PATCH 72/75] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=8B=A6=E6=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/PaymentController.php | 2 +- app/Service/OrderService.php | 3 +-- app/Service/PurchaseLimitService.php | 7 +++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/Controller/PaymentController.php b/app/Controller/PaymentController.php index c691ed6..c6c9788 100644 --- a/app/Controller/PaymentController.php +++ b/app/Controller/PaymentController.php @@ -51,7 +51,7 @@ class PaymentController extends BaseController ->get(); //判断是否有购买多个特价商品 $result = $this->purchaseLimitService->PurchaseLimit($orderGoods); - if($result > 1){ + if(!$result){ Db::rollBack(); $this->log->event(LogLabel::ORDER_LOG, ['msg'=> '支付失败,同一订单不能存在多个特价商品','global_order_id' => $orderMain->global_order_id]); return $this->result(ErrorCode::PAY_FAILURE, $data,'同一订单不能存在多个特价商品'); diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index 38802eb..6bb990b 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -308,7 +308,7 @@ class OrderService implements OrderServiceInterface } //判断是否有购买多个特价商品 $result = $this->purchaseLimitService->PurchaseLimit($orderGoods); - if($result > 1){ + if(!$result){ Db::rollBack(); return '同一个订单不能购买多个特价商品'; } @@ -343,7 +343,6 @@ class OrderService implements OrderServiceInterface 'status' => 1, 'update_time' => 0, ]; - var_dump('$couponUse',$couponUse); $insertRes = CouponUserUse::query()->insert($couponUse); diff --git a/app/Service/PurchaseLimitService.php b/app/Service/PurchaseLimitService.php index 7c14fdd..a75b85e 100644 --- a/app/Service/PurchaseLimitService.php +++ b/app/Service/PurchaseLimitService.php @@ -80,13 +80,16 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface public function PurchaseLimit($orderGoods) { + $sum = 0; foreach ($orderGoods as $goods){ - $sum = 0; if($goods['money'] == 0.01){ + if($sum > 0){ + return false; + } $sum++; } } - return $sum; + return true; } public function test($params) From 51598033ffeb4a3a8acb1426baa309ef5107acc5 Mon Sep 17 00:00:00 2001 From: weigang Date: Thu, 27 Aug 2020 14:12:43 +0800 Subject: [PATCH 73/75] =?UTF-8?q?=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/OrderService.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index 38802eb..7685460 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -965,7 +965,9 @@ class OrderService implements OrderServiceInterface $state = explode(',', $state); $builder = $builder->whereIn('state', $state); } - $orders = $builder->get()->forPage($page, $pagesize)->toArray(); + $orders = $builder->orderBy('id', 'desc') + ->orderBy('state', 'asc') + ->get()->forPage($page, $pagesize)->toArray(); foreach ($orders as $key => &$order) { // 市场名称 From cf8c88c7aa9ee8002f8438d16f55af41fa7432f8 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Thu, 27 Aug 2020 14:43:13 +0800 Subject: [PATCH 74/75] =?UTF-8?q?=E8=BF=94=E5=9B=9E=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/PurchaseLimitService.php | 38 ++++++++++++++-------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/app/Service/PurchaseLimitService.php b/app/Service/PurchaseLimitService.php index c221b15..9568302 100644 --- a/app/Service/PurchaseLimitService.php +++ b/app/Service/PurchaseLimitService.php @@ -20,25 +20,25 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface { public function getStoreIdByMarketId($params) { - $res[] = [ - 'id' => 7, - 'item' => 1, - 'item_text' => 'page', - 'logo' => 'http://lanzutest.lanzulive.com/attachment/images/2/2020/08/PY55Y3Mz17yJo17rv1Z7vImX1V5159.jpg', - 'redirect_url' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=123', - 'src' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=123', - 'src2' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=123', - ]; - $res[] = [ - 'id' => 8, - 'item' => 1, - 'item_text' => 'page', - 'logo' => 'http://lanzutest.lanzulive.com/attachment/images/2/2020/08/PY55Y3Mz17yJo17rv1Z7vImX1V5159.jpg', - 'redirect_url' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=109', - 'src' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=109', - 'src2' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=109', - ]; - return $res; + // $res[] = [ + // 'id' => 7, + // 'item' => 1, + // 'item_text' => 'page', + // 'logo' => 'http://lanzutest.lanzulive.com/attachment/images/2/2020/08/PY55Y3Mz17yJo17rv1Z7vImX1V5159.jpg', + // 'redirect_url' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=123', + // 'src' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=123', + // 'src2' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=123', + // ]; + // $res[] = [ + // 'id' => 8, + // 'item' => 1, + // 'item_text' => 'page', + // 'logo' => 'http://lanzutest.lanzulive.com/attachment/images/2/2020/08/PY55Y3Mz17yJo17rv1Z7vImX1V5159.jpg', + // 'redirect_url' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=109', + // 'src' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=109', + // 'src2' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=109', + // ]; + return ''; } public function ssdbPurchaseRecord($data,$user_id,$global_order_id) From 7f14d1aefe882191f21f597838a3086d9e4e46ce Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Thu, 27 Aug 2020 15:01:13 +0800 Subject: [PATCH 75/75] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=95=B4=E7=90=86?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/PurchaseLimitController.php | 6 ------ app/Service/PurchaseLimitService.php | 10 ---------- app/Service/PurchaseLimitServiceInterface.php | 1 - config/routes.php | 2 +- 4 files changed, 1 insertion(+), 18 deletions(-) diff --git a/app/Controller/PurchaseLimitController.php b/app/Controller/PurchaseLimitController.php index 4e9e3fe..7bb2d22 100644 --- a/app/Controller/PurchaseLimitController.php +++ b/app/Controller/PurchaseLimitController.php @@ -34,10 +34,4 @@ class PurchaseLimitController extends BaseController return $this->success($res); } - public function test() - { - $res = $this->purchaseLimitService->PurchaseLimit($this->request->input('global_order_id')); - return $this->success($res); - } - } diff --git a/app/Service/PurchaseLimitService.php b/app/Service/PurchaseLimitService.php index 9568302..5fe5f02 100644 --- a/app/Service/PurchaseLimitService.php +++ b/app/Service/PurchaseLimitService.php @@ -101,14 +101,4 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface return true; } - public function test($params) - { - $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - //添加领取记录到ssdb - $data = [ - '620',1561, - ]; - $test = $ssdb->exec('multi_hset', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_620', $data); - return $test; - } } \ No newline at end of file diff --git a/app/Service/PurchaseLimitServiceInterface.php b/app/Service/PurchaseLimitServiceInterface.php index da0f536..9ff3184 100644 --- a/app/Service/PurchaseLimitServiceInterface.php +++ b/app/Service/PurchaseLimitServiceInterface.php @@ -14,5 +14,4 @@ interface PurchaseLimitServiceInterface public function PurchaseLimit($orderGoods); - public function test($params); } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index 6a3dc03..ca3dcf5 100644 --- a/config/routes.php +++ b/config/routes.php @@ -61,7 +61,7 @@ Router::addGroup('/v1/',function (){ //加入购物车 Router::post('ShopCar/addShopCar', 'App\Controller\ShopCarController@addShopCar'); Router::post('ShopCar/updateShopCar', 'App\Controller\ShopCarController@updateShopCar'); - Router::post('PurchaseLimit/test', 'App\Controller\PurchaseLimitController@test'); + Router::post('PurchaseLimit/delSsdbPurchaseRecord', 'App\Controller\PurchaseLimitController@delSsdbPurchaseRecord'); Router::post('PurchaseLimit/getStoreIdByMarketId', 'App\Controller\PurchaseLimitController@getStoreIdByMarketId');