Browse Source
Merge branch 'purchase_limit' into master
Merge branch 'purchase_limit' into master
# Conflicts: # config/autoload/dependencies.php # config/routes.phpmaster
63 changed files with 3485 additions and 309 deletions
-
2.gitignore
-
3app/Amqp/Consumer/couponRebateConsumer.php
-
10app/Constants/ErrorCode.php
-
33app/Constants/LogLabel.php
-
6app/Constants/SsdbKeysPrefix.php
-
29app/Controller/CommunityController.php
-
62app/Controller/CouponController.php
-
359app/Controller/NotifyController.php
-
122app/Controller/NotifyPayRefundController.php
-
96app/Controller/OrderController.php
-
34app/Controller/PaymentController.php
-
37app/Controller/PurchaseLimitController.php
-
39app/Controller/ShopCarController.php
-
91app/JsonRpc/OrderService.php
-
8app/JsonRpc/OrderServiceInterface.php
-
81app/Listener/ValidatorFactoryResolvedListener.php
-
29app/Model/AdminUser.php
-
14app/Model/Combination.php
-
9app/Model/CouponRec.php
-
10app/Model/CouponUserRec.php
-
13app/Model/CouponUserUse.php
-
29app/Model/CsInfo.php
-
101app/Model/FinancialRecord.php
-
30app/Model/Market.php
-
12app/Model/Model.php
-
5app/Model/OrderMain.php
-
33app/Model/ServiceReward.php
-
14app/Model/ShopCar.php
-
36app/Model/UserBalance.php
-
40app/Model/UserRelationBind.php
-
6app/Model/Users.php
-
45app/Request/CommunityBindRequest.php
-
40app/Request/OnlineCancelRequest.php
-
1app/Request/OrderOnlineRequest.php
-
43app/Request/UpdateShopCarRequest.php
-
39app/Request/UserOrdersRequest.php
-
142app/Service/CouponService.php
-
5app/Service/CouponServiceInterface.php
-
3app/Service/FeiePrintService.php
-
296app/Service/FinancialRecordService.php
-
252app/Service/FinancialRecordServiceInterface.php
-
4app/Service/MiniprogramService.php
-
495app/Service/OrderService.php
-
67app/Service/OrderServiceInterface.php
-
104app/Service/PurchaseLimitService.php
-
17app/Service/PurchaseLimitServiceInterface.php
-
292app/Service/SeparateAccountsService.php
-
28app/Service/SeparateAccountsServiceInterface.php
-
201app/Service/ShopCarService.php
-
12app/Service/ShopCarServiceInterface.php
-
68app/Service/SmsAliService.php
-
9app/Service/SmsServiceInterface.php
-
35app/Service/UserCommunityBindService.php
-
48app/Service/UserRelationBindServiceInterface.php
-
21app/Service/UserService.php
-
11app/Service/UserServiceInterface.php
-
68app/Service/WxRefundService.php
-
8app/Service/WxRefundServiceInterface.php
-
7composer.json
-
10config/autoload/dependencies.php
-
10config/autoload/server.php
-
7config/config.php
-
13config/routes.php
@ -0,0 +1,29 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
namespace App\Controller; |
|||
|
|||
use App\Model\UserRelationBind; |
|||
use App\Request\CommunityBindRequest; |
|||
use App\Service\UserRelationBindServiceInterface; |
|||
use Hyperf\Di\Annotation\Inject; |
|||
|
|||
class CommunityController extends BaseController |
|||
{ |
|||
|
|||
/** |
|||
* @Inject |
|||
* @var UserRelationBindServiceInterface |
|||
*/ |
|||
protected $userCommunityService; |
|||
|
|||
public function bind(CommunityBindRequest $request) |
|||
{ |
|||
$data = $request->validated(); |
|||
$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]); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,122 @@ |
|||
<?php |
|||
/** |
|||
* 本回调用不到 20200826 |
|||
*/ |
|||
namespace App\Controller; |
|||
|
|||
use App\Constants\LogLabel; |
|||
use App\Model\OrderMain; |
|||
use App\Service\OrderServiceInterface; |
|||
use App\Service\FinancialRecordServiceInterface; |
|||
use EasyWeChat\Factory; |
|||
use Hyperf\Guzzle\CoroutineHandler; |
|||
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 |
|||
{ |
|||
|
|||
const AWARD_LIMIT_AMOUNT = 3; |
|||
|
|||
/** |
|||
* @Inject |
|||
* @var FinancialRecordServiceInterface |
|||
*/ |
|||
protected $financialService; |
|||
|
|||
/** |
|||
* @Inject |
|||
* @var OrderServiceInterface |
|||
*/ |
|||
protected $orderService; |
|||
|
|||
/** |
|||
* @Inject |
|||
* @var PurchaseLimitServiceInterface |
|||
*/ |
|||
protected $purchaseLimitService; |
|||
|
|||
/** |
|||
* 微信退款回调 |
|||
*/ |
|||
public function wxPayRefund() |
|||
{ |
|||
$this->log->event( |
|||
LogLabel::WX_NOTIFY_REFUND, |
|||
'进入回调' |
|||
); |
|||
$config = config('wxpay'); |
|||
$app = Factory::payment($config); |
|||
$app['guzzle_handler'] = CoroutineHandler::class; |
|||
|
|||
$get = $this->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) { |
|||
$this->log->event( |
|||
LogLabel::WX_NOTIFY_REFUND, |
|||
$message |
|||
); |
|||
try { |
|||
/* --- 退款失败 --- */ |
|||
if ( |
|||
empty($message) |
|||
|| !isset($message['result_code']) |
|||
|| $message['result_code'] != 'SUCCESS' |
|||
) { |
|||
// 错误日志
|
|||
$this->log->event( |
|||
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(); |
|||
|
|||
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::WX_NOTIFY_REFUND, |
|||
['exception_fail' => $e->getMessage()] |
|||
); |
|||
$fail('Exception'); |
|||
} |
|||
}); |
|||
|
|||
return $this->response |
|||
->withHeader('Content-Type', 'text/xml') |
|||
->withStatus(200) |
|||
->withBody(new SwooleStream($response->getContent())); |
|||
} |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
namespace App\Controller; |
|||
|
|||
use Hyperf\Di\Annotation\Inject; |
|||
use App\Service\PurchaseLimitServiceInterface; |
|||
use App\Constants\ErrorCode; |
|||
class PurchaseLimitController extends BaseController |
|||
{ |
|||
|
|||
/** |
|||
* @Inject |
|||
* @var PurchaseLimitServiceInterface |
|||
*/ |
|||
protected $purchaseLimitService; |
|||
|
|||
public function getStoreIdByMarketId() |
|||
{ |
|||
$res = $this->purchaseLimitService->getStoreIdByMarketId($this->request->all()); |
|||
return $this->success($res); |
|||
} |
|||
|
|||
public function ssdbPurchaseRecord() |
|||
{ |
|||
$res = $this->purchaseLimitService->ssdbPurchaseRecord($this->request->all(),214,156813021196050432); |
|||
return $this->success($res); |
|||
} |
|||
|
|||
public function delSsdbPurchaseRecord() |
|||
{ |
|||
$res = $this->purchaseLimitService->delSsdbPurchaseRecord($this->request->input('order_id')); |
|||
return $this->success($res); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
namespace App\Controller; |
|||
|
|||
use App\Service\ShopCarService; |
|||
use Hyperf\Di\Annotation\Inject; |
|||
use App\Service\ShopCarServiceInterface; |
|||
use App\Constants\ErrorCode; |
|||
class ShopCarController extends BaseController |
|||
{ |
|||
|
|||
/** |
|||
* @Inject |
|||
* @var ShopCarServiceInterface |
|||
*/ |
|||
protected $shopCarService; |
|||
|
|||
|
|||
public function addShopCar() |
|||
{ |
|||
$res = $this->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); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,91 @@ |
|||
<?php |
|||
|
|||
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="") |
|||
*/ |
|||
class OrderService implements OrderServiceInterface |
|||
{ |
|||
|
|||
/** |
|||
* @Inject |
|||
* @var Log |
|||
*/ |
|||
protected $log; |
|||
|
|||
/** |
|||
* @Inject |
|||
* @var \App\Service\OrderServiceInterface |
|||
*/ |
|||
protected $orderService; |
|||
|
|||
/** |
|||
* @Inject |
|||
* @var SeparateAccountsServiceInterface |
|||
*/ |
|||
protected $separateAccountsService; |
|||
|
|||
public function onlineComplete($global_order_id) |
|||
{ |
|||
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) |
|||
]; |
|||
} |
|||
|
|||
} |
|||
|
|||
/** |
|||
* 线上订单退款 |
|||
* 申请退款 state = 8 |
|||
* 退款成功 state = 9 |
|||
*/ |
|||
public function onlineRefund($global_order_id){ |
|||
$result = [ |
|||
"status" => 200, |
|||
"code" => ErrorCode::ORDER_FAILURE, |
|||
"result" => [], |
|||
"message" => '' |
|||
]; |
|||
|
|||
$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; |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
<?php |
|||
|
|||
namespace App\JsonRpc; |
|||
|
|||
interface OrderServiceInterface |
|||
{ |
|||
|
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
<?php |
|||
|
|||
declare (strict_types=1); |
|||
namespace App\Model; |
|||
|
|||
use Hyperf\DbConnection\Model\Model; |
|||
/** |
|||
*/ |
|||
class AdminUser extends Model |
|||
{ |
|||
/** |
|||
* The table associated with the model. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $table = 'admin_users'; |
|||
/** |
|||
* The attributes that are mass assignable. |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $fillable = []; |
|||
/** |
|||
* The attributes that should be cast to native types. |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $casts = []; |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
<?php |
|||
|
|||
|
|||
namespace App\Model; |
|||
|
|||
|
|||
class Combination extends Model |
|||
{ |
|||
const INVENTORY_NOLIMIT = 1; |
|||
|
|||
protected $table = 'ims_cjdc_spec_combination'; |
|||
public $timestamps = false; |
|||
|
|||
} |
|||
@ -1,10 +0,0 @@ |
|||
<?php |
|||
|
|||
|
|||
namespace App\Model; |
|||
|
|||
|
|||
class CouponUserRec extends Model |
|||
{ |
|||
protected $table = 'ims_system_coupon_user_receive'; |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
<?php |
|||
|
|||
declare (strict_types=1); |
|||
namespace App\Model; |
|||
|
|||
use Hyperf\DbConnection\Model\Model; |
|||
/** |
|||
*/ |
|||
class CsInfo extends Model |
|||
{ |
|||
/** |
|||
* The table associated with the model. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $table = 'lanzu_cs_info'; |
|||
/** |
|||
* The attributes that are mass assignable. |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $fillable = []; |
|||
/** |
|||
* The attributes that should be cast to native types. |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $casts = []; |
|||
} |
|||
@ -0,0 +1,101 @@ |
|||
<?php |
|||
|
|||
declare (strict_types=1); |
|||
namespace App\Model; |
|||
|
|||
/** |
|||
*/ |
|||
class FinancialRecord extends Model |
|||
{ |
|||
/** |
|||
* 当面付商户首单奖励限制的订单金额 |
|||
*/ |
|||
const OFL_FIRST_AWARD_LIMIT_AMOUNT = 3; |
|||
|
|||
/** |
|||
* 虚拟账户 |
|||
*/ |
|||
const ACCOUNT_LEDGER = -1; |
|||
|
|||
/** |
|||
* 账户类型 |
|||
* |
|||
* 总账 |
|||
* 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; |
|||
|
|||
/** |
|||
* 关联类型 |
|||
* |
|||
* 订单 |
|||
* SOURCE_TYPE_ORDER / 1 |
|||
*/ |
|||
const SOURCE_TYPE_ORDER = 1; |
|||
|
|||
/** |
|||
* 流水类型,大的分类,<100是奖励分账等收入项 >=100是提现消费等支出项 |
|||
*/ |
|||
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; // 商户线上订单完成收入
|
|||
const MONEY_TYPE_STORE_OFL_ORDER_COMP = 7; // 商户线下订单完成收入
|
|||
const MONEY_TYPE_USER_OL_ORDER_REFUND = 8; // 用户线上订单退款
|
|||
|
|||
const MONEY_TYPE_USER_OFL_ORDER = 100; // 用户线下支付订单
|
|||
const MONEY_TYPE_USER_OL_ORDER = 101; // 用户线上支付订单
|
|||
|
|||
/** |
|||
* 状态 |
|||
*/ |
|||
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 = []; |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
<?php |
|||
|
|||
declare (strict_types=1); |
|||
namespace App\Model; |
|||
|
|||
/** |
|||
*/ |
|||
class Market extends Model |
|||
{ |
|||
/** |
|||
* The table associated with the model. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $table = 'ims_cjdc_market'; |
|||
/** |
|||
* The attributes that are mass assignable. |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $fillable = []; |
|||
/** |
|||
* The attributes that should be cast to native types. |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $casts = []; |
|||
|
|||
public $timestamps = false; |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
<?php |
|||
|
|||
declare (strict_types=1); |
|||
namespace App\Model; |
|||
|
|||
class ServiceReward extends Model |
|||
{ |
|||
/** |
|||
* 社区服务点 |
|||
*/ |
|||
const TYPE_COMMUNITY = 1; |
|||
|
|||
/** |
|||
* The table associated with the model. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $table = 'lanzu_service_reward'; |
|||
/** |
|||
* The attributes that are mass assignable. |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $fillable = []; |
|||
/** |
|||
* The attributes that should be cast to native types. |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $casts = [ |
|||
'set_reward' => 'array' |
|||
]; |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
<?php |
|||
|
|||
|
|||
namespace App\Model; |
|||
|
|||
|
|||
class ShopCar extends Model |
|||
{ |
|||
const INVENTORY_NOLIMIT = 1; |
|||
|
|||
protected $table = 'ims_cjdc_shopcar'; |
|||
public $timestamps = false; |
|||
|
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
<?php |
|||
|
|||
declare (strict_types=1); |
|||
namespace App\Model; |
|||
|
|||
/** |
|||
*/ |
|||
class UserBalance extends Model |
|||
{ |
|||
const USER_TYPE_MP = 1; |
|||
const USER_TYPE_MM = 2; |
|||
const USER_TYPE_CS = 3; |
|||
|
|||
/** |
|||
* The table associated with the model. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $table = 'lanzu_user_balance'; |
|||
/** |
|||
* The attributes that are mass assignable. |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $fillable = [ |
|||
'source_id', |
|||
'user_type', |
|||
'balance' |
|||
]; |
|||
/** |
|||
* The attributes that should be cast to native types. |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $casts = []; |
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
<?php |
|||
|
|||
declare (strict_types=1); |
|||
namespace App\Model; |
|||
|
|||
/** |
|||
*/ |
|||
class UserRelationBind extends Model |
|||
{ |
|||
|
|||
/** |
|||
* 社区服务点类型 |
|||
*/ |
|||
const BIND_TYPE_COMMUNITY = 1; |
|||
|
|||
/** |
|||
* The table associated with the model. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $table = 'lanzu_user_relation_bind'; |
|||
/** |
|||
* The attributes that are mass assignable. |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $fillable = ['bind_type', 'source_id', 'user_id', 'json_data']; |
|||
/** |
|||
* The attributes that should be cast to native types. |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $casts = []; |
|||
|
|||
public function setJsonDataAttribute($value) |
|||
{ |
|||
$this->attributes['json_data'] = $value ? json_encode(json_decode($value, true)) : ''; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
namespace App\Request; |
|||
|
|||
use Hyperf\Validation\Request\FormRequest; |
|||
|
|||
class CommunityBindRequest extends FormRequest |
|||
{ |
|||
/** |
|||
* Determine if the user is authorized to make this request. |
|||
*/ |
|||
public function authorize(): bool |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
/** |
|||
* Get the validation rules that apply to the request. |
|||
*/ |
|||
public function rules(): array |
|||
{ |
|||
return [ |
|||
'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 [ |
|||
|
|||
]; |
|||
} |
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
namespace App\Request; |
|||
|
|||
class OnlineCancelRequest extends BaseFormRequest |
|||
{ |
|||
/** |
|||
* Determine if the user is authorized to make this request. |
|||
*/ |
|||
public function authorize(): bool |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
/** |
|||
* Get the validation rules that apply to the request. |
|||
*/ |
|||
public function rules(): array |
|||
{ |
|||
return [ |
|||
'order_id' => 'required|nonempty|integer|exists:ims_cjdc_order_main,id', |
|||
]; |
|||
} |
|||
|
|||
public function messages(): array |
|||
{ |
|||
return [ |
|||
'order_id.*' => ':attribute信息不正确', |
|||
]; |
|||
} |
|||
|
|||
public function attributes(): array |
|||
{ |
|||
return [ |
|||
'order_id' => '订单号', |
|||
]; |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
namespace App\Request; |
|||
|
|||
use Hyperf\Validation\Request\FormRequest; |
|||
|
|||
class UpdateShopCarRequest extends FormRequest |
|||
{ |
|||
/** |
|||
* Determine if the user is authorized to make this request. |
|||
*/ |
|||
public function authorize(): bool |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
/** |
|||
* Get the validation rules that apply to the request. |
|||
*/ |
|||
public function rules(): array |
|||
{ |
|||
return [ |
|||
'id' => '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' => '购物车记录', |
|||
]; |
|||
} |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
namespace App\Request; |
|||
|
|||
use Hyperf\Validation\Request\FormRequest; |
|||
|
|||
class UserOrdersRequest extends FormRequest |
|||
{ |
|||
/** |
|||
* Determine if the user is authorized to make this request. |
|||
*/ |
|||
public function authorize(): bool |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
/** |
|||
* Get the validation rules that apply to the request. |
|||
*/ |
|||
public function rules(): array |
|||
{ |
|||
return [ |
|||
'user_id' => 'required|nonempty|integer', |
|||
'market_id' => 'required|nonempty|integer', |
|||
'state' => 'required', |
|||
'page' => 'required|nonempty|integer', |
|||
'pagesize' => 'required|nonempty|integer', |
|||
]; |
|||
} |
|||
|
|||
public function messages(): array |
|||
{ |
|||
return [ |
|||
'*.*' => ':attribute 参数不正确', |
|||
]; |
|||
} |
|||
} |
|||
@ -0,0 +1,296 @@ |
|||
<?php |
|||
|
|||
namespace App\Service; |
|||
|
|||
use App\Model\FinancialRecord; |
|||
use App\Model\Store; |
|||
use App\Model\UserBalance; |
|||
use Hyperf\Di\Annotation\Inject; |
|||
|
|||
class FinancialRecordService implements FinancialRecordServiceInterface |
|||
{ |
|||
|
|||
/** |
|||
* @Inject |
|||
* @var SmsServiceInterface |
|||
*/ |
|||
protected $smsAliService; |
|||
|
|||
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(); |
|||
|
|||
} |
|||
|
|||
/** |
|||
* @inheritDoc |
|||
*/ |
|||
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); |
|||
// 维护社区服务点余额
|
|||
$balance = UserBalance::firstOrNew([ |
|||
'user_type' => UserBalance::USER_TYPE_CS, |
|||
'source_id' => $user_id |
|||
]); |
|||
$balance->balance = bcadd($balance->balance, $money, 2); |
|||
$balance->save(); |
|||
|
|||
// 发送短信
|
|||
$this->smsAliService->sendForCommunityFinancial($user_id, $money); |
|||
|
|||
} |
|||
|
|||
/** |
|||
* @inheritDoc |
|||
*/ |
|||
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); |
|||
// 维护社区服务点余额
|
|||
$balance = UserBalance::firstOrNew([ |
|||
'user_type' => UserBalance::USER_TYPE_CS, |
|||
'source_id' => $user_id |
|||
]); |
|||
$balance->balance = bcadd($balance->balance, $money, 2); |
|||
$balance->save(); |
|||
|
|||
// 发送短信
|
|||
$this->smsAliService->sendForCommunityFinancial($user_id, $money); |
|||
} |
|||
|
|||
/** |
|||
* @inheritDoc |
|||
*/ |
|||
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); |
|||
// 维护社区服务点余额
|
|||
$balance = UserBalance::firstOrNew([ |
|||
'user_type' => UserBalance::USER_TYPE_CS, |
|||
'source_id' => $user_id |
|||
]); |
|||
$balance->balance = bcadd($balance->balance, $money,2); |
|||
$balance->save(); |
|||
|
|||
// 发送短信
|
|||
$this->smsAliService->sendForCommunityFinancial($user_id, $money); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* @inheritDoc |
|||
*/ |
|||
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); |
|||
// 同时维护钱包
|
|||
$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=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); |
|||
// 同时维护钱包
|
|||
$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, |
|||
[ |
|||
'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 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); |
|||
} |
|||
|
|||
/** |
|||
* @inheritDoc |
|||
*/ |
|||
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); |
|||
} |
|||
|
|||
/** |
|||
* @inheritDoc |
|||
*/ |
|||
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); |
|||
// 同时维护钱包
|
|||
$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 = 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); |
|||
} |
|||
|
|||
/** |
|||
* @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); |
|||
} |
|||
} |
|||
@ -0,0 +1,252 @@ |
|||
<?php |
|||
|
|||
namespace App\Service; |
|||
|
|||
use App\Model\FinancialRecord; |
|||
|
|||
interface FinancialRecordServiceInterface |
|||
{ |
|||
|
|||
/** |
|||
* 社区服务点新用户奖励 |
|||
* @param $user_id |
|||
* @param $source_id |
|||
* @param $money |
|||
* @param int $user_type |
|||
* @param int $source_type |
|||
* @param int $money_type |
|||
* @param string $comment |
|||
* @param string $desc |
|||
* @return mixed |
|||
*/ |
|||
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='' |
|||
); |
|||
|
|||
/** |
|||
* 社区服务点新用户线上首单奖励 |
|||
* @param $user_id |
|||
* @param $source_id |
|||
* @param $money |
|||
* @param int $user_type |
|||
* @param int $source_type |
|||
* @param int $money_type |
|||
* @param string $comment |
|||
* @param string $desc |
|||
* @return mixed |
|||
*/ |
|||
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='' |
|||
); |
|||
|
|||
/** |
|||
* 社区服务点用户订单完成分账 |
|||
* @param $user_id |
|||
* @param $source_id |
|||
* @param $money |
|||
* @param int $user_type |
|||
* @param int $source_type |
|||
* @param int $money_type |
|||
* @param string $comment |
|||
* @param string $desc |
|||
* @return mixed |
|||
*/ |
|||
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='' |
|||
); |
|||
|
|||
/** |
|||
* 收支总账 |
|||
* @param $source_id |
|||
* @param $money |
|||
* @param $source_type |
|||
* @param $money_type |
|||
* @param $desc |
|||
* @param string $comment |
|||
* @return mixed |
|||
*/ |
|||
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=FinancialRecord::USER_TYPE_STORE, |
|||
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, |
|||
$money_type=FinancialRecord::MONEY_TYPE_STORE_PLAT_NEW_USER, |
|||
$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=FinancialRecord::USER_TYPE_STORE, |
|||
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, |
|||
$money_type=FinancialRecord::MONEY_TYPE_STORE_FIRST_ORDER, |
|||
$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=FinancialRecord::USER_TYPE_USER, |
|||
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, |
|||
$money_type=FinancialRecord::MONEY_TYPE_USER_OFL_ORDER, |
|||
$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=FinancialRecord::USER_TYPE_USER, |
|||
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, |
|||
$money_type=FinancialRecord::MONEY_TYPE_USER_OL_ORDER, |
|||
$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 = FinancialRecord::USER_TYPE_STORE, |
|||
$source_type = FinancialRecord::SOURCE_TYPE_ORDER, |
|||
$money_type = FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_COMP, |
|||
$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 = FinancialRecord::USER_TYPE_STORE, |
|||
$source_type = FinancialRecord::SOURCE_TYPE_ORDER, |
|||
$money_type = FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP, |
|||
$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 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='' |
|||
); |
|||
|
|||
} |
|||
@ -0,0 +1,104 @@ |
|||
<?php |
|||
|
|||
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; |
|||
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 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 ''; |
|||
} |
|||
|
|||
public function ssdbPurchaseRecord($data,$user_id,$global_order_id) |
|||
{ |
|||
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 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) |
|||
->select('id','user_id') |
|||
->get() |
|||
->toArray(); |
|||
foreach ($order as $k1 => $v1){ |
|||
$goods = OrderGoods::query() |
|||
->where([ |
|||
['order_id','=',$v1['id']], |
|||
['money','=',0.01], |
|||
]) |
|||
->select('good_id') |
|||
->get() |
|||
->toArray(); |
|||
|
|||
foreach ($goods as $k2 => $v2) { |
|||
$ssdb->exec('del', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$v1['user_id'].'_'.$v2['good_id']); |
|||
} |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
public function PurchaseLimit($orderGoods) |
|||
{ |
|||
$sum = 0; |
|||
foreach ($orderGoods as $goods){ |
|||
if($goods['money'] == 0.01){ |
|||
if($sum > 0){ |
|||
return false; |
|||
} |
|||
$sum++; |
|||
} |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
<?php |
|||
|
|||
|
|||
namespace App\Service; |
|||
|
|||
|
|||
interface PurchaseLimitServiceInterface |
|||
{ |
|||
public function getStoreIdByMarketId($params); |
|||
|
|||
public function ssdbPurchaseRecord($params,$user_id,$global_order_id); |
|||
|
|||
public function delSsdbPurchaseRecord($global_order_id); |
|||
|
|||
public function PurchaseLimit($orderGoods); |
|||
|
|||
} |
|||
@ -0,0 +1,292 @@ |
|||
<?php |
|||
|
|||
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 App\Model\Users; |
|||
use Hyperf\DbConnection\Db; |
|||
use Hyperf\Di\Annotation\Inject; |
|||
|
|||
class SeparateAccountsService implements SeparateAccountsServiceInterface |
|||
{ |
|||
/** |
|||
* @Inject |
|||
* @var Log |
|||
*/ |
|||
protected $log; |
|||
|
|||
/** |
|||
* @Inject |
|||
* @var UserServiceInterface |
|||
*/ |
|||
protected $userService; |
|||
|
|||
/** |
|||
* @Inject |
|||
* @var FinancialRecordServiceInterface |
|||
*/ |
|||
protected $financialRecordService; |
|||
|
|||
/** |
|||
* @Inject |
|||
* @var MiniprogramServiceInterface |
|||
*/ |
|||
protected $miniprogramService; |
|||
|
|||
/** |
|||
* @inheritDoc |
|||
*/ |
|||
public function orderOnlinePaid($global_order_id) |
|||
{ |
|||
// 线上订单支付完成
|
|||
// 订单
|
|||
$orderMain = OrderMain::query() |
|||
->where(['global_order_id' => $global_order_id]) |
|||
->first(); |
|||
|
|||
if (empty($orderMain)) { |
|||
return false; |
|||
} |
|||
|
|||
// =======用户支付流水 / Start=======
|
|||
$this->financialRecordService->userByOLOrderPaid($orderMain->user_id, $global_order_id, $orderMain->money); |
|||
// =======用户支付流水 / End=======
|
|||
} |
|||
|
|||
/** |
|||
* @inheritDoc |
|||
*/ |
|||
public function orderOnlineCompleted($global_order_id) |
|||
{ |
|||
// 线上订单完成(用户点击确认收货完成/管理后台点击完成/配送员点击完成/自动收货等),进行相关分账
|
|||
// 订单
|
|||
$orderMain = OrderMain::query() |
|||
->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 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, $global_order_id ,$order['money']); |
|||
} |
|||
// =======商户订单收入流水 / End=======
|
|||
|
|||
// =======社区服务点分账 / Start=======
|
|||
// 前提:用户线上下单并且订单完成
|
|||
// 奖励规则A:用户是平台新用户,奖励社区服务点平台新用户奖励x元+平台新用户首单奖励y元+订单商品金额z%的分成
|
|||
// 奖励规则B:用户是非新用户,奖励社区服务点订单实际支付金额z%的分成
|
|||
// =======社区服务点分账 / Start=======
|
|||
|
|||
// 当前用户的社区服务点绑定关系
|
|||
$communityBind = UserRelationBind::query() |
|||
->where(['bind_type' => UserRelationBind::BIND_TYPE_COMMUNITY, 'user_id' => $orderMain->user_id]) |
|||
->first(); |
|||
|
|||
if ($communityBind) { |
|||
|
|||
// 奖励/分账金额
|
|||
$award = ServiceReward::query()->where(['type' => ServiceReward::TYPE_COMMUNITY])->first(); |
|||
if (empty($award)) { |
|||
Db::rollBack(); |
|||
return false; |
|||
} |
|||
|
|||
$award = $award->set_reward; |
|||
|
|||
// 平台新用户
|
|||
if ($this->userService->isPlatformNewUser($orderMain->user_id, $orderMain->id)) { |
|||
$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, $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) |
|||
{ |
|||
// 线下订单支付完成
|
|||
// 订单
|
|||
$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, $global_order_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, $global_order_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, $global_order_id, $awardAmount); |
|||
$needAward = true; |
|||
|
|||
} else { |
|||
// 商户当日首单奖励
|
|||
if ( |
|||
$this->userService->isStoreFirstOrderToday( |
|||
$order->user_id, |
|||
$order->store_id, |
|||
$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'); |
|||
// 旧商户流水 TODO 直接移除或后续考虑移除
|
|||
$storeAccount = [ |
|||
'money' => $awardAmount, |
|||
'note' => '用户下单成功,平台奖励', |
|||
'category' => 4, |
|||
]; |
|||
// 新商户流水
|
|||
$this->financialRecordService->storeAwardByTodayFirstOFLOrder($store->user_id, $global_order_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; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
<?php |
|||
|
|||
namespace App\Service; |
|||
|
|||
interface SeparateAccountsServiceInterface |
|||
{ |
|||
/** |
|||
* (线上)订单支付完成分账 |
|||
* @param $global_order_id |
|||
* @return mixed |
|||
*/ |
|||
public function orderOnlinePaid($global_order_id); |
|||
|
|||
/** |
|||
* (线上)订单确认完成分账 |
|||
* 用户确认或服务商(服务站确认) |
|||
* @param $global_order_id |
|||
* @return mixed |
|||
*/ |
|||
public function orderOnlineCompleted($global_order_id); |
|||
|
|||
/** |
|||
* (线下)订单支付完成分账 |
|||
* @param $global_order_id |
|||
* @return mixed |
|||
*/ |
|||
public function orderOfflinePaid($global_order_id); |
|||
} |
|||
@ -0,0 +1,201 @@ |
|||
<?php |
|||
|
|||
namespace App\Service; |
|||
|
|||
use Hyperf\Di\Annotation\Inject; |
|||
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 ShopCarService implements ShopCarServiceInterface |
|||
{ |
|||
public function addShopCar($params) |
|||
{ |
|||
//获取ssdb购买记录
|
|||
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); |
|||
$record_exists = $ssdb->exec('get',SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$params['user_id'].'_'.$params['good_id']); |
|||
if($record_exists) |
|||
{ |
|||
$error = [ |
|||
'error' => '特价商品每日只能购买一次' |
|||
]; |
|||
return $error; |
|||
} |
|||
//一个订单只能添加一个特价商品
|
|||
if($params['money'] == 0.01){ |
|||
$goods_exists = ShopCar::where([ |
|||
['user_id','=',$params['user_id']], |
|||
['good_id','!=',$params['good_id']], |
|||
['market_id','=',$params['market_id']], |
|||
['money','=',0.01] |
|||
]) |
|||
->exists(); |
|||
if($goods_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 '更新购物车成功';
|
|||
// }
|
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
<?php |
|||
|
|||
|
|||
namespace App\Service; |
|||
|
|||
|
|||
interface ShopCarServiceInterface |
|||
{ |
|||
public function addShopCar($params); |
|||
|
|||
public function updateShopCar($params); |
|||
} |
|||
@ -0,0 +1,68 @@ |
|||
<?php |
|||
|
|||
namespace App\Service; |
|||
|
|||
use AlibabaCloud\Client\AlibabaCloud; |
|||
use AlibabaCloud\Client\Exception\ClientException; |
|||
use AlibabaCloud\Client\Exception\ServerException; |
|||
use App\Commons\Log; |
|||
use App\Model\CsInfo; |
|||
use App\Model\Market; |
|||
use Hyperf\Di\Annotation\Inject; |
|||
|
|||
class SmsAliService implements SmsServiceInterface |
|||
{ |
|||
const TEMPLATE_COMMUNITY_FINANCIAL = 'SMS_200690862'; |
|||
|
|||
/** |
|||
* @Inject |
|||
* @var Log |
|||
*/ |
|||
protected $log; |
|||
|
|||
public function send($phone, $template, $templateParams, $signName='懒族生活') |
|||
{ |
|||
|
|||
$alisms = config('alisms'); |
|||
AlibabaCloud::accessKeyClient($alisms['app_key'], $alisms['app_secret']) |
|||
->regionId($alisms['regionid']) |
|||
->asDefaultClient(); |
|||
|
|||
try { |
|||
$result = AlibabaCloud::rpc() |
|||
->product($alisms['product']) |
|||
// ->scheme('https') // https | http
|
|||
->version('2017-05-25') |
|||
->action('SendSms') |
|||
->method('POST') |
|||
->host($alisms['host']) |
|||
->options([ |
|||
'query' => [ |
|||
'RegionId' => $alisms['regionid'], |
|||
'PhoneNumbers' => $phone, |
|||
'SignName' => $signName, |
|||
'TemplateCode' => $template, |
|||
'TemplateParam' => $templateParams, |
|||
], |
|||
]) |
|||
->request(); |
|||
return $result->toArray(); |
|||
} catch (ClientException $e) { |
|||
$this->log->event('alisms', ['alisms_error_ClientException' => $e->getErrorMessage()]); |
|||
return false; |
|||
} catch (ServerException $e) { |
|||
$this->log->event('alisms', ['alisms_error_ServerException' => $e->getErrorMessage()]); |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
public function sendForCommunityFinancial($userId, $money) |
|||
{ |
|||
|
|||
$csInfo = CsInfo::query()->where(['admin_user_id' => $userId])->first(); |
|||
$market = Market::query()->where(['id' => $csInfo->market_id])->first(); |
|||
|
|||
$params = ['user_name' => $csInfo->name, 'market_name' => $market->name, 'money' => $money]; |
|||
return $this->send($csInfo->phone, self::TEMPLATE_COMMUNITY_FINANCIAL, json_encode($params)); |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
<?php |
|||
|
|||
namespace App\Service; |
|||
|
|||
interface SmsServiceInterface |
|||
{ |
|||
public function send($phone, $template, $templateParams); |
|||
public function sendForCommunityFinancial($userId, $money); |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
<?php |
|||
|
|||
namespace App\Service; |
|||
|
|||
use App\Model\UserRelationBind; |
|||
|
|||
class UserCommunityBindService implements UserRelationBindServiceInterface |
|||
{ |
|||
|
|||
/** |
|||
* @inheritDoc |
|||
*/ |
|||
public function bindLimitByUser($bind_type, $source_id, $user_id, $extra_data) |
|||
{ |
|||
return UserRelationBind::query()->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.
|
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
<?php |
|||
|
|||
namespace App\Service; |
|||
|
|||
interface UserRelationBindServiceInterface |
|||
{ |
|||
/** |
|||
* 绑定 |
|||
* 依据用户绑定一个关系,即每次都是新的绑定关系,原来的绑定关系解除(user_id不变,更新其他) |
|||
* @param $bind_type |
|||
* @param $source_id |
|||
* @param $user_id |
|||
* @param $extra_data |
|||
* @return mixed |
|||
*/ |
|||
public function bindLimitByUser($bind_type, $source_id, $user_id, $extra_data); |
|||
|
|||
/** |
|||
* 绑定 |
|||
* 依据绑定人(根据bind_type确定)绑定一个关系,即每次都是新的绑定关系,原来的绑定关系解除(source_id不变,更新其他) |
|||
* @param $bind_type |
|||
* @param $source_id |
|||
* @param $user_id |
|||
* @param $extra_data |
|||
* @return mixed |
|||
*/ |
|||
public function bindLimitBySource($bind_type, $source_id, $user_id, $extra_data); |
|||
|
|||
/** |
|||
* 绑定 |
|||
* 始终绑定一个新的关系,如果这个关系(source_id=》user_id)存在则更新其他数据 |
|||
* @param $bind_type |
|||
* @param $source_id |
|||
* @param $user_id |
|||
* @param $extra_data |
|||
* @return mixed |
|||
*/ |
|||
public function bind($bind_type, $source_id, $user_id, $extra_data); |
|||
|
|||
/** |
|||
* 是否已经存在绑定关系 |
|||
* @param $bind_type |
|||
* @param $source_id |
|||
* @param $user_id |
|||
* @return mixed |
|||
*/ |
|||
public function isBinded($bind_type, $source_id, $user_id); |
|||
} |
|||
@ -0,0 +1,68 @@ |
|||
<?php |
|||
|
|||
namespace App\Service; |
|||
|
|||
use App\Model\OrderMain; |
|||
use EasyWeChat\Factory; |
|||
use Hyperf\DbConnection\Db; |
|||
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 |
|||
{ |
|||
/** |
|||
* @Inject |
|||
* @var Log |
|||
*/ |
|||
protected $log; |
|||
|
|||
/** |
|||
* 微信支付退款 |
|||
*/ |
|||
public function wxPayRefund($global_order_id) |
|||
{ |
|||
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) |
|||
->whereRaw('refund_time is null') |
|||
->first(); |
|||
|
|||
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 |
|||
); |
|||
} 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; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
<?php |
|||
|
|||
namespace App\Service; |
|||
|
|||
interface WxRefundServiceInterface |
|||
{ |
|||
public function wxPayRefund($global_order_id); |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue