Browse Source

分账和服务商相关

master
weigang 5 years ago
parent
commit
469824eeb2
  1. 2
      app/Controller/CommunityController.php
  2. 3
      app/Controller/PaymentController.php
  3. 6
      app/Controller/PurchaseLimitController.php
  4. 30
      app/Controller/StoreController.php
  5. 2
      app/Controller/v3/CommunityController.php
  6. 34
      app/JsonRpc/AlismsService.php
  7. 17
      app/JsonRpc/SmsServiceInterface.php
  8. 6
      app/Model/FinancialRecord.php
  9. 12
      app/Model/MmInfo.php
  10. 13
      app/Model/MpInfo.php
  11. 47
      app/Model/Store.php
  12. 26
      app/Model/UserBalance.php
  13. 2
      app/Model/v3/FinancialRecord.php
  14. 13
      app/Model/v3/MmInfo.php
  15. 14
      app/Model/v3/MpInfo.php
  16. 83
      app/Request/StoreApplyEntryRequest.php
  17. 15
      app/Service/AdService.php
  18. 8
      app/Service/AttachmentService.php
  19. 2
      app/Service/DeviceServiceImp.php
  20. 228
      app/Service/FinancialRecordService.php
  21. 173
      app/Service/FinancialRecordServiceInterface.php
  22. 2
      app/Service/OrderService.php
  23. 92
      app/Service/PurchaseLimitService.php
  24. 2
      app/Service/PurchaseLimitServiceInterface.php
  25. 139
      app/Service/SeparateAccountsService.php
  26. 104
      app/Service/StoreService.php
  27. 11
      app/Service/StoreServiceInterface.php
  28. 5
      app/Service/UserCommunityBindService.php
  29. 203
      app/Service/v3/Implementations/FinancialRecordService.php
  30. 5
      app/Service/v3/Implementations/UserCommunityBindService.php
  31. 195
      app/Service/v3/Interfaces/FinancialRecordServiceInterface.php
  32. 2
      app/Service/v3/Interfaces/UserRelationBindServiceInterface.php
  33. 2
      config/autoload/dependencies.php

2
app/Controller/CommunityController.php

@ -22,7 +22,7 @@ class CommunityController extends BaseController
{ {
$data = $request->validated(); $data = $request->validated();
$jsonData = $data['json_data'] ?? json_encode([]); $jsonData = $data['json_data'] ?? json_encode([]);
$res = $this->userCommunityService->bindLimitByUser(UserRelationBind::BIND_TYPE_COMMUNITY, $data['source_id'], $data['user_id'], $jsonData);
$res = $this->userCommunityService->bind(UserRelationBind::BIND_TYPE_COMMUNITY, $data['source_id'], $data['user_id'], $jsonData);
return $this->success(['id' => $res->id]); return $this->success(['id' => $res->id]);
} }

3
app/Controller/PaymentController.php

@ -52,14 +52,13 @@ class PaymentController extends BaseController
//判断是否有购买多个特价商品 //判断是否有购买多个特价商品
$result = $this->purchaseLimitService->PurchaseLimit($orderGoods); $result = $this->purchaseLimitService->PurchaseLimit($orderGoods);
if(!$result){ if(!$result){
Db::rollBack();
$this->log->event(LogLabel::ORDER_LOG, ['msg'=> '支付失败,同一订单不能存在多个特价商品','global_order_id' => $orderMain->global_order_id]); $this->log->event(LogLabel::ORDER_LOG, ['msg'=> '支付失败,同一订单不能存在多个特价商品','global_order_id' => $orderMain->global_order_id]);
return $this->result(ErrorCode::PAY_FAILURE, $data,'同一订单不能存在多个特价商品'); return $this->result(ErrorCode::PAY_FAILURE, $data,'同一订单不能存在多个特价商品');
} }
$payMoney = bcmul(floatval($orderMain->money), 100, 0); $payMoney = bcmul(floatval($orderMain->money), 100, 0);
if (env('APP_ENV') != 'prod') { if (env('APP_ENV') != 'prod') {
$payMoney = 0.01;
$payMoney = 1;
} }
$result = $app->order->unify([ $result = $app->order->unify([

6
app/Controller/PurchaseLimitController.php

@ -22,6 +22,12 @@ class PurchaseLimitController extends BaseController
return $this->success($res); return $this->success($res);
} }
public function getBannerByMarketId()
{
$res = $this->purchaseLimitService->getBannerByMarketId($this->request->all());
return $this->success($res);
}
public function ssdbPurchaseRecord() public function ssdbPurchaseRecord()
{ {
$res = $this->purchaseLimitService->ssdbPurchaseRecord($this->request->all(),214,156813021196050432); $res = $this->purchaseLimitService->ssdbPurchaseRecord($this->request->all(),214,156813021196050432);

30
app/Controller/StoreController.php

@ -7,6 +7,10 @@ use Hyperf\DbConnection\Db;
use Hyperf\HttpServer\Annotation\AutoController; use Hyperf\HttpServer\Annotation\AutoController;
use OSS\Core\OssException; use OSS\Core\OssException;
use OSS\OssClient; use OSS\OssClient;
use App\Constants\ErrorCode;
use App\Request\StoreApplyEntryRequest;
use App\Service\StoreServiceInterface;
use Hyperf\Di\Annotation\Inject;
/** /**
* @AutoController() * @AutoController()
@ -15,6 +19,32 @@ use OSS\OssClient;
*/ */
class StoreController extends BaseController class StoreController extends BaseController
{ {
/**
* @Inject
* @var StoreServiceInterface
*/
protected $storeService;
/**
* 申请入驻
* 商户信息入驻+市场经理拉新记录
*/
public function applyEntry(StoreApplyEntryRequest $request)
{
$data = $request->validated();
$res = $this->storeService->entry($data);
if ($res !== true) {
return $this->result(ErrorCode::SAVE_FAILURE, $res, '申请失败,请稍后重试');
}
return $this->success('');
}
public function infoEdit() public function infoEdit()
{ {
$id = $this->request->input('id'); $id = $this->request->input('id');

2
app/Controller/v3/CommunityController.php

@ -23,7 +23,7 @@ class CommunityController extends BaseController
{ {
$data = $request->validated(); $data = $request->validated();
$jsonData = $data['json_data'] ?? json_encode([]); $jsonData = $data['json_data'] ?? json_encode([]);
$res = $this->userCommunityService->bindLimitByUser(UserRelationBind::BIND_TYPE_COMMUNITY, $data['source_id'], $data['user_id'], $jsonData);
$res = $this->userCommunityService->bind(UserRelationBind::BIND_TYPE_COMMUNITY, $data['source_id'], $data['user_id'], $jsonData);
return $this->success(['id' => $res->id]); return $this->success(['id' => $res->id]);
} }

34
app/JsonRpc/AlismsService.php

@ -0,0 +1,34 @@
<?php
namespace App\JsonRpc;
use App\Service\v3\Interfaces\SmsSendServiceInterface;
use Hyperf\RpcServer\Annotation\RpcService;
use Hyperf\Di\Annotation\Inject;
/**
* @RpcService(name="AlismsService", protocol="jsonrpc-http", server="jsonrpc-http", publishTo="")
* Class AliSmsService
* @package App\JsonRpc
*/
class AlismsService implements SmsServiceInterface
{
/**
* @Inject
* @var SmsSendServiceInterface
*/
private $smsAliSendService;
/**
* 阿里短信
* @param $phone
* @param $template
* @param $templateParams
* @param string $signName
* @return array|bool
*/
public function sent($phone, $template, $templateParams, $signName = '懒族生活')
{
return $this->smsAliSendService->do($phone, $template, $templateParams);
}
}

17
app/JsonRpc/SmsServiceInterface.php

@ -0,0 +1,17 @@
<?php
namespace App\JsonRpc;
interface SmsServiceInterface
{
/**
* @param $phone
* @param $template
* @param $templateParams
* @param string $signName
* @return mixed
*/
public function sent($phone, $template, $templateParams, $signName='懒族生活');
}

6
app/Model/FinancialRecord.php

@ -60,6 +60,12 @@ class FinancialRecord extends Model
const MONEY_TYPE_STORE_OL_ORDER_COMP = 6; // 商户线上订单完成收入 const MONEY_TYPE_STORE_OL_ORDER_COMP = 6; // 商户线上订单完成收入
const MONEY_TYPE_STORE_OFL_ORDER_COMP = 7; // 商户线下订单完成收入 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_MM_PLAT_NEW_USER = 9; // 市场经理发展新用户
const MONEY_TYPE_MM_PLAT_NEW_STORE = 10; // 市场经理发展新商户
const MONEY_TYPE_MP_PLAT_NEW_USER = 11; // 服务商发展新用户
const MONEY_TYPE_MP_PLAT_NEW_STORE = 12; // 服务商发展新商户
const MONEY_TYPE_MP_OL_ORDER = 13; // 服务商线上订单分账(线上订单完成)
const MONEY_TYPE_USER_OFL_ORDER = 100; // 用户线下支付订单 const MONEY_TYPE_USER_OFL_ORDER = 100; // 用户线下支付订单
const MONEY_TYPE_USER_OL_ORDER = 101; // 用户线上支付订单 const MONEY_TYPE_USER_OL_ORDER = 101; // 用户线上支付订单

12
app/Model/MmInfo.php

@ -0,0 +1,12 @@
<?php
namespace App\Model;
use Hyperf\Database\Model\SoftDeletes;
class MmInfo extends Model
{
use SoftDeletes;
protected $table = 'lanzu_mm_info';
}

13
app/Model/MpInfo.php

@ -0,0 +1,13 @@
<?php
namespace App\Model;
use Hyperf\Database\Model\SoftDeletes;
class MpInfo extends Model
{
use SoftDeletes;
protected $table = 'lanzu_mp_info';
}

47
app/Model/Store.php

@ -1,10 +1,57 @@
<?php <?php
declare (strict_types=1);
namespace App\Model; namespace App\Model;
/**
*/
class Store extends Model class Store extends Model
{ {
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'ims_cjdc_store'; protected $table = 'ims_cjdc_store';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'market_id',
'md_type',
'address',
'coordinates',
'details',
'link_name',
'link_tel',
'logo',
'fm_img',
'zm_img',
'yyzz',
'user_id',
'sq_id',
'admin_id',
'rz_time',
'mm_user_id',
'sq_time',
'rzdq_time',
'state',
'is_open',
'money',
'code',
'uniacid',
'zf_state',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [];
public $timestamps=false; public $timestamps=false;
} }

26
app/Model/UserBalance.php

@ -7,9 +7,29 @@ namespace App\Model;
*/ */
class UserBalance extends Model class UserBalance extends Model
{ {
const USER_TYPE_MP = 1;
const USER_TYPE_MM = 2;
const USER_TYPE_CS = 3;
/**
* 账户类型
*
* 总账
* 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;
/** /**
* The table associated with the model. * The table associated with the model.

2
app/Model/v3/FinancialRecord.php

@ -66,9 +66,9 @@ class FinancialRecord extends Model
const MONEY_TYPE_MM_PLAT_NEW_STORE = 10; // 市场经理发展新商户 const MONEY_TYPE_MM_PLAT_NEW_STORE = 10; // 市场经理发展新商户
const MONEY_TYPE_MP_PLAT_NEW_USER = 11; // 服务商发展新用户 const MONEY_TYPE_MP_PLAT_NEW_USER = 11; // 服务商发展新用户
const MONEY_TYPE_MP_PLAT_NEW_STORE = 12; // 服务商发展新商户 const MONEY_TYPE_MP_PLAT_NEW_STORE = 12; // 服务商发展新商户
const MONEY_TYPE_MP_OL_ORDER = 13; // 服务商线上订单分账(线上订单完成)
const MONEY_TYPE_USER_OL_ORDER_DIRECT_REFUND = 14; // 用户订单退款(直接退) const MONEY_TYPE_USER_OL_ORDER_DIRECT_REFUND = 14; // 用户订单退款(直接退)
const MONEY_TYPE_MP_OL_ORDER = 13; // 服务商线上订单分账(线上订单完成)
const MONEY_TYPE_USER_OFL_ORDER = 100; // 用户线下支付订单 const MONEY_TYPE_USER_OFL_ORDER = 100; // 用户线下支付订单
const MONEY_TYPE_USER_OL_ORDER = 101; // 用户线上支付订单 const MONEY_TYPE_USER_OL_ORDER = 101; // 用户线上支付订单
const MONEY_TYPE_MP_WITHDRAW = 102; // 服务商提现类型 const MONEY_TYPE_MP_WITHDRAW = 102; // 服务商提现类型

13
app/Model/v3/MmInfo.php

@ -0,0 +1,13 @@
<?php
namespace App\Model\v3;
use App\Model\Model;
use Hyperf\Database\Model\SoftDeletes;
class MmInfo extends Model
{
use SoftDeletes;
protected $table = 'lanzu_mm_info';
}

14
app/Model/v3/MpInfo.php

@ -0,0 +1,14 @@
<?php
namespace App\Model\v3;
use App\Model\Model;
use Hyperf\Database\Model\SoftDeletes;
class MpInfo extends Model
{
use SoftDeletes;
protected $table = 'lanzu_mp_info';
}

83
app/Request/StoreApplyEntryRequest.php

@ -0,0 +1,83 @@
<?php
declare(strict_types=1);
namespace App\Request;
use Hyperf\Validation\Request\FormRequest;
class StoreApplyEntryRequest 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 [
'name' => 'required|nonempty',
'market_id' => 'required|nonempty|integer',
'md_type' => 'required|nonempty|integer',
'address' => 'required|nonempty',
'coordinates' => 'required|nonempty',
'details' => 'required|nonempty',
'link_name' => 'required|nonempty',
'link_tel' => 'required|nonempty|tel',
'logo' => 'required|nonempty|image_if_file',
'fm_img' => 'required|nonempty|image_if_file|file_different_if_file:zm_img',
'zm_img' => 'required|nonempty|image_if_file|file_different_if_file:fm_img',
'yyzz' => 'required|nonempty|image_if_file',
'user_id' => 'required|nonempty|integer',
'rz_time' => 'required|nonempty|integer',
'mm_user_id' => 'nonempty|integer',
'id' => 'nonempty|integer',
];
}
public function messages(): array
{
return [
'*.nonempty' => ':attribute参数异常',
'logo.image' => ':attribute不是正常的图片',
'logo.*' => ':attribute未选择',
'fm_img.image' => ':attribute不是正常的图片',
'fm_img.file_different_if_file' => '身份证正反面不能相同',
'fm_img.*' => ':attribute未选择',
'zm_img.image' => ':attribute不是正常的图片',
'zm_img.file_different_if_file' => '身份证正反面不能相同',
'zm_img.*' => ':attribute未选择',
'yyzz.image' => ':attribute不是正常的图片',
'yyzz.*' => ':attribute未选择',
'link_tel.tel' => ':attribute格式不正确',
];
}
public function attributes(): array
{
return [
'name' => '商户名',
'market_id' => '市场ID',
'md_type' => '门店类型',
'address' => '门店地址',
'coordinates' => '门店经纬度',
'details' => '门店简介',
'link_name' => '联系人姓名',
'link_tel' => '联系人电话',
'logo' => '商户LOGO',
'fm_img' => '商户身份证反面',
'zm_img' => '商户身份证正面',
'yyzz' => '商户营业执照',
'user_id' => '申请用户ID',
'rz_time' => '入驻天数',
'mm_user_id' => '市场经理用户ID',
'id' => '门店ID',
];
}
}

15
app/Service/AdService.php

@ -11,12 +11,13 @@ class AdService implements AdServiceInterface
*/ */
public function banners() public function banners()
{ {
return Ad::query()->select(['id','title','logo','item','src','src2'])
->where([
'type' => Ad::TYPE_BANNER,
'status' => Ad::STATUS_YES
])
->orderBy('orderby', 'desc')
->get();
return [];
// return Ad::query()->select(['id','title','logo','item','src','src2'])
// ->where([
// 'type' => Ad::TYPE_BANNER,
// 'status' => Ad::STATUS_YES
// ])
// ->orderBy('orderby', 'desc')
// ->get();
} }
} }

8
app/Service/AttachmentService.php

@ -21,6 +21,10 @@ class AttachmentService implements AttachmentServiceInterface
$path = $this->getBasePath($path, $attachmenttype); $path = $this->getBasePath($path, $attachmenttype);
$fileName = $path . '/' . $fileHash . '.' . $file->getExtension(); $fileName = $path . '/' . $fileHash . '.' . $file->getExtension();
if ($filesystem->has($fileName)) {
return $fileName;
}
$stream = fopen($fileRealPath, 'r+'); $stream = fopen($fileRealPath, 'r+');
$filesystem->writeStream($fileName, $stream); $filesystem->writeStream($fileName, $stream);
fclose($stream); fclose($stream);
@ -45,6 +49,10 @@ class AttachmentService implements AttachmentServiceInterface
$path = $this->getBasePath($path); $path = $this->getBasePath($path);
$fileName = $path . '/' . $fileHash . '.' . $result[2]; $fileName = $path . '/' . $fileHash . '.' . $result[2];
if ($filesystem->has($fileName)) {
return $fileName;
}
$filesystem->write($fileName, $contents); $filesystem->write($fileName, $contents);
return $fileName; return $fileName;

2
app/Service/DeviceServiceImp.php

@ -112,7 +112,7 @@ class DeviceServiceImp implements DeviceServiceInterface
->where(['store_id' => $order['store_id'], 'is_bind' => SpeakerDevic::IS_BIND_YES]) ->where(['store_id' => $order['store_id'], 'is_bind' => SpeakerDevic::IS_BIND_YES])
->get() ->get()
->toArray(); ->toArray();
$msg = $order['type']==1 ? "{\"msg\":\"您有新的懒族外卖订单\"}" : "{\"msg\":\"微信到账".$order['money']."\"}";
$msg = $order['type']==1 ? "{\"msg\":\"您有新的懒族外卖订单\"}" : "{\"msg\":\"微信到账".floatval($order['money'])."\"}";
foreach ($device_names as $key => $dev_name) { foreach ($device_names as $key => $dev_name) {
$this->IOTService->pub($dev_name['device_name'], $msg); $this->IOTService->pub($dev_name['device_name'], $msg);
} }

228
app/Service/FinancialRecordService.php

@ -67,17 +67,17 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='新用户奖励',
$comment='社区服务点',
$user_type=FinancialRecord::USER_TYPE_CS, $user_type=FinancialRecord::USER_TYPE_CS,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_CS_PLAT_NEW_USER,
$desc='新用户奖励',
$comment='社区服务点'
$money_type=FinancialRecord::MONEY_TYPE_CS_PLAT_NEW_USER
) )
{ {
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
// 维护社区服务点余额 // 维护社区服务点余额
$balance = UserBalance::firstOrNew([ $balance = UserBalance::firstOrNew([
'user_type' => UserBalance::USER_TYPE_CS,
'user_type' => $user_type,
'source_id' => $user_id 'source_id' => $user_id
]); ]);
$balance->balance = bcadd($balance->balance, $money, 2); $balance->balance = bcadd($balance->balance, $money, 2);
@ -95,17 +95,17 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='新用户首单奖励',
$comment='社区服务点',
$user_type=FinancialRecord::USER_TYPE_CS, $user_type=FinancialRecord::USER_TYPE_CS,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_CS_FIRST_ORDER,
$desc='新用户首单奖励',
$comment='社区服务点'
$money_type=FinancialRecord::MONEY_TYPE_CS_FIRST_ORDER
) )
{ {
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
// 维护社区服务点余额 // 维护社区服务点余额
$balance = UserBalance::firstOrNew([ $balance = UserBalance::firstOrNew([
'user_type' => UserBalance::USER_TYPE_CS,
'user_type' => $user_type,
'source_id' => $user_id 'source_id' => $user_id
]); ]);
$balance->balance = bcadd($balance->balance, $money, 2); $balance->balance = bcadd($balance->balance, $money, 2);
@ -122,17 +122,17 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='用户订单分成',
$comment='社区服务点',
$user_type=FinancialRecord::USER_TYPE_CS, $user_type=FinancialRecord::USER_TYPE_CS,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_CS_OL_ORDER,
$desc='用户订单分成',
$comment='社区服务点'
$money_type=FinancialRecord::MONEY_TYPE_CS_OL_ORDER
) )
{ {
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
// 维护社区服务点余额 // 维护社区服务点余额
$balance = UserBalance::firstOrNew([ $balance = UserBalance::firstOrNew([
'user_type' => UserBalance::USER_TYPE_CS,
'user_type' => $user_type,
'source_id' => $user_id 'source_id' => $user_id
]); ]);
$balance->balance = bcadd($balance->balance, $money,2); $balance->balance = bcadd($balance->balance, $money,2);
@ -150,11 +150,11 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='新用户下单奖励',
$comment='用户当面付商户奖励',
$user_type=FinancialRecord::USER_TYPE_STORE, $user_type=FinancialRecord::USER_TYPE_STORE,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_STORE_PLAT_NEW_USER,
$desc='新用户下单奖励',
$comment='用户当面付商户奖励'
$money_type=FinancialRecord::MONEY_TYPE_STORE_PLAT_NEW_USER
) )
{ {
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
@ -162,6 +162,14 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$store = Store::query()->where(['user_id' => $user_id])->first(); $store = Store::query()->where(['user_id' => $user_id])->first();
$store->award_money = bcadd($store->award_money, $money, 2); $store->award_money = bcadd($store->award_money, $money, 2);
$store->save(); $store->save();
// 维护余额
$balance = UserBalance::firstOrNew([
'user_type' => $user_type,
'source_id' => $store->id
]);
$balance->balance = bcadd($balance->balance, $money, 2);
$balance->save();
} }
/** /**
@ -171,11 +179,11 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='用户店铺首单奖励',
$comment='用户当面付商户奖励',
$user_type=FinancialRecord::USER_TYPE_STORE, $user_type=FinancialRecord::USER_TYPE_STORE,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_STORE_FIRST_ORDER,
$desc='用户店铺首单奖励',
$comment='用户当面付商户奖励'
$money_type=FinancialRecord::MONEY_TYPE_STORE_FIRST_ORDER
) )
{ {
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
@ -183,6 +191,14 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$store = Store::query()->where(['user_id' => $user_id])->first(); $store = Store::query()->where(['user_id' => $user_id])->first();
$store->award_money = bcadd($store->award_money, $money, 2); $store->award_money = bcadd($store->award_money, $money, 2);
$store->save(); $store->save();
// 维护余额
$balance = UserBalance::firstOrNew([
'user_type' => $user_type,
'source_id' => $store->id
]);
$balance->balance = bcadd($balance->balance, $money, 2);
$balance->save();
} }
public function recordAll($user_id, $source_id, $money, $user_type=1, $source_type=0, $money_type=0, $desc='', $comment='') { public function recordAll($user_id, $source_id, $money, $user_type=1, $source_type=0, $money_type=0, $desc='', $comment='') {
@ -211,11 +227,11 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='用户下单(线下)',
$comment='用户下单',
$user_type=FinancialRecord::USER_TYPE_USER, $user_type=FinancialRecord::USER_TYPE_USER,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_USER_OFL_ORDER,
$desc='用户下单(线下)',
$comment='用户下单'
$money_type=FinancialRecord::MONEY_TYPE_USER_OFL_ORDER
) )
{ {
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
@ -228,11 +244,11 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='用户下单(线上)',
$comment='用户下单',
$user_type=FinancialRecord::USER_TYPE_USER, $user_type=FinancialRecord::USER_TYPE_USER,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_USER_OL_ORDER,
$desc='用户下单(线上)',
$comment='用户下单'
$money_type=FinancialRecord::MONEY_TYPE_USER_OL_ORDER
) )
{ {
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
@ -245,11 +261,11 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc = '线上外卖订单收入',
$comment = '用户订单完成',
$user_type = FinancialRecord::USER_TYPE_STORE, $user_type = FinancialRecord::USER_TYPE_STORE,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER, $source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_COMP,
$desc = '线上外卖订单收入',
$comment = '用户订单完成'
$money_type = FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_COMP
) )
{ {
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
@ -257,6 +273,14 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$store = Store::query()->where(['user_id' => $user_id])->first(); $store = Store::query()->where(['user_id' => $user_id])->first();
$store->store_wallet = bcadd($store->store_wallet, $money, 2); $store->store_wallet = bcadd($store->store_wallet, $money, 2);
$store->save(); $store->save();
// 维护余额
$balance = UserBalance::firstOrNew([
'user_type' => $user_type,
'source_id' => $store->id
]);
$balance->balance = bcadd($balance->balance, $money, 2);
$balance->save();
} }
/** /**
@ -266,14 +290,27 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc = '线下当面付订单收入',
$comment = '用户订单完成',
$user_type = FinancialRecord::USER_TYPE_STORE, $user_type = FinancialRecord::USER_TYPE_STORE,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER, $source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP,
$desc = '线下当面付订单收入',
$comment = '用户订单完成'
$money_type = FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP
) )
{ {
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $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();
// 维护余额
$balance = UserBalance::firstOrNew([
'user_type' => $user_type,
'source_id' => $store->id
]);
$balance->balance = bcadd($balance->balance, $money, 2);
$balance->save();
} }
/** /**
@ -284,13 +321,138 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc = '线上订单退款',
$comment = '线上订单退款到微信',
$user_type = FinancialRecord::USER_TYPE_USER, $user_type = FinancialRecord::USER_TYPE_USER,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER, $source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_USER_OL_ORDER_REFUND,
$desc = '线上订单退款',
$comment = '线上订单退款到微信'
$money_type = FinancialRecord::MONEY_TYPE_USER_OL_ORDER_REFUND
) )
{ {
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
} }
/**
* @inheritDoc
*/
public function mmAwardByPlatNewUser(
$user_id,
$source_id,
$money,
$desc = '发展新用户',
$comment = '市场经理发展新用户奖励',
$user_type = FinancialRecord::USER_TYPE_MM,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_MM_PLAT_NEW_USER
)
{
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
// 维护余额
$balance = UserBalance::firstOrNew([
'user_type' => $user_type,
'source_id' => $user_id
]);
$balance->balance = bcadd($balance->balance, $money, 2);
$balance->save();
}
/**
* @inheritDoc
*/
public function mmAwardByNewStore(
$user_id,
$source_id,
$money,
$desc = '发展新商户',
$comment = '市场经理发展新商户奖励',
$user_type = FinancialRecord::USER_TYPE_MM,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_MM_PLAT_NEW_STORE
)
{
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
// 维护余额
$balance = UserBalance::firstOrNew([
'user_type' => $user_type,
'source_id' => $user_id
]);
$balance->balance = bcadd($balance->balance, $money, 2);
$balance->save();
}
/**
* @inheritDoc
*/
public function mpAwardByPlatNewUser(
$user_id,
$source_id,
$money,
$desc = '服务商发展新用户',
$comment = '服务商发展新用户奖励',
$user_type = FinancialRecord::USER_TYPE_MP,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_MP_PLAT_NEW_USER
)
{
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
// 维护余额
$balance = UserBalance::firstOrNew([
'user_type' => $user_type,
'source_id' => $user_id
]);
$balance->balance = bcadd($balance->balance, $money, 2);
$balance->save();
}
/**
* @inheritDoc
*/
public function mpAwardByNewStore(
$user_id,
$source_id,
$money,
$desc = '服务商发展新商户',
$comment = '服务商发展新商户奖励',
$user_type = FinancialRecord::USER_TYPE_MP,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_MP_PLAT_NEW_STORE
)
{
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
// 维护余额
$balance = UserBalance::firstOrNew([
'user_type' => $user_type,
'source_id' => $user_id
]);
$balance->balance = bcadd($balance->balance, $money, 2);
$balance->save();
}
/**
* @inheritDoc
*/
public function mpSeparateAccountByOLOrderComp(
$user_id,
$source_id,
$money,
$desc = '服务商线上订单分账',
$comment = '服务商用户线上订单完成后分账',
$user_type = FinancialRecord::USER_TYPE_MP,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_MP_OL_ORDER
)
{
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
// 维护余额
$balance = UserBalance::firstOrNew([
'user_type' => $user_type,
'source_id' => $user_id
]);
$balance->balance = bcadd($balance->balance, $money, 2);
$balance->save();
}
} }

173
app/Service/FinancialRecordServiceInterface.php

@ -23,11 +23,11 @@ interface FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='新用户奖励',
$comment='',
$user_type=FinancialRecord::USER_TYPE_CS, $user_type=FinancialRecord::USER_TYPE_CS,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_CS_PLAT_NEW_USER,
$desc='新用户奖励',
$comment=''
$money_type=FinancialRecord::MONEY_TYPE_CS_PLAT_NEW_USER
); );
/** /**
@ -46,11 +46,11 @@ interface FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='新用户首单奖励',
$comment='',
$user_type=FinancialRecord::USER_TYPE_CS, $user_type=FinancialRecord::USER_TYPE_CS,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_CS_FIRST_ORDER,
$desc='新用户首单奖励',
$comment=''
$money_type=FinancialRecord::MONEY_TYPE_CS_FIRST_ORDER
); );
/** /**
@ -69,11 +69,11 @@ interface FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='用户订单分成',
$comment='',
$user_type=FinancialRecord::USER_TYPE_CS, $user_type=FinancialRecord::USER_TYPE_CS,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_CS_OL_ORDER,
$desc='用户订单分成',
$comment=''
$money_type=FinancialRecord::MONEY_TYPE_CS_OL_ORDER
); );
/** /**
@ -104,11 +104,11 @@ interface FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='新用户下单奖励',
$comment='',
$user_type=FinancialRecord::USER_TYPE_STORE, $user_type=FinancialRecord::USER_TYPE_STORE,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_STORE_PLAT_NEW_USER,
$desc='新用户下单奖励',
$comment=''
$money_type=FinancialRecord::MONEY_TYPE_STORE_PLAT_NEW_USER
); );
/** /**
@ -127,11 +127,11 @@ interface FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='用户店铺首单奖励',
$comment='',
$user_type=FinancialRecord::USER_TYPE_STORE, $user_type=FinancialRecord::USER_TYPE_STORE,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_STORE_FIRST_ORDER,
$desc='用户店铺首单奖励',
$comment=''
$money_type=FinancialRecord::MONEY_TYPE_STORE_FIRST_ORDER
); );
/** /**
@ -150,11 +150,11 @@ interface FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='用户下单(线下)',
$comment='',
$user_type=FinancialRecord::USER_TYPE_USER, $user_type=FinancialRecord::USER_TYPE_USER,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_USER_OFL_ORDER,
$desc='用户下单(线下)',
$comment=''
$money_type=FinancialRecord::MONEY_TYPE_USER_OFL_ORDER
); );
/** /**
@ -173,11 +173,11 @@ interface FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='用户下单(线上)',
$comment='',
$user_type=FinancialRecord::USER_TYPE_USER, $user_type=FinancialRecord::USER_TYPE_USER,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_USER_OL_ORDER,
$desc='用户下单(线上)',
$comment=''
$money_type=FinancialRecord::MONEY_TYPE_USER_OL_ORDER
); );
/** /**
@ -196,11 +196,11 @@ interface FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='线上外卖订单收入',
$comment='',
$user_type = FinancialRecord::USER_TYPE_STORE, $user_type = FinancialRecord::USER_TYPE_STORE,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER, $source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_COMP,
$desc='线上外卖订单收入',
$comment=''
$money_type = FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_COMP
); );
/** /**
@ -219,11 +219,11 @@ interface FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='线下当面付订单收入',
$comment='',
$user_type = FinancialRecord::USER_TYPE_STORE, $user_type = FinancialRecord::USER_TYPE_STORE,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER, $source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP,
$desc='线下当面付订单收入',
$comment=''
$money_type = FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP
); );
/** /**
@ -242,11 +242,124 @@ interface FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='线上订单退款',
$comment='',
$user_type = FinancialRecord::USER_TYPE_STORE, $user_type = FinancialRecord::USER_TYPE_STORE,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER, $source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP,
$desc='线上订单退款',
$comment=''
$money_type = FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP
);
/**
* 市场经理新用户
* @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
*/
public function mmAwardByPlatNewUser(
$user_id,
$source_id,
$money,
$desc = '市场经理发展新用户',
$comment = '',
$user_type = FinancialRecord::USER_TYPE_MM,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_MM_PLAT_NEW_USER
); );
/**
* 市场经理新商户
* @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 mmAwardByNewStore(
$user_id,
$source_id,
$money,
$desc = '市场经理发展新商户',
$comment = '市场经理发展新商户奖励',
$user_type = FinancialRecord::USER_TYPE_MM,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_MM_PLAT_NEW_STORE
);
/**
* 服务商新用户
* @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 mpAwardByPlatNewUser(
$user_id,
$source_id,
$money,
$desc = '服务商发展新用户',
$comment = '服务商发展新用户奖励',
$user_type = FinancialRecord::USER_TYPE_MP,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_MP_PLAT_NEW_USER
);
/**
* 服务商新商户
* @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 mpAwardByNewStore(
$user_id,
$source_id,
$money,
$desc = '服务商发展新商户',
$comment = '服务商发展新商户奖励',
$user_type = FinancialRecord::USER_TYPE_MP,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_MP_PLAT_NEW_STORE
);
/**
* 服务商线上订单分账
* @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 mpSeparateAccountByOLOrderComp(
$user_id,
$source_id,
$money,
$desc = '服务商线上订单分账',
$comment = '服务商用户线上订单完成后分账',
$user_type = FinancialRecord::USER_TYPE_MP,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_MP_OL_ORDER
);
} }

2
app/Service/OrderService.php

@ -664,7 +664,7 @@ class OrderService implements OrderServiceInterface
$goods->inventory = $goods->inventory - $goodsItem['number']; $goods->inventory = $goods->inventory - $goodsItem['number'];
} }
$goods->sales = $goods->sales - $goodsItem['number'];
$goods->sales = $goods->sales + $goodsItem['number'];
$goods->save(); $goods->save();
} }

92
app/Service/PurchaseLimitService.php

@ -15,30 +15,84 @@ use App\Commons\Log;
use Hyperf\Utils\ApplicationContext; use Hyperf\Utils\ApplicationContext;
use App\TaskWorker\SSDBTask; use App\TaskWorker\SSDBTask;
use App\Constants\SsdbKeysPrefix; use App\Constants\SsdbKeysPrefix;
use App\Model\Ad;
class PurchaseLimitService implements PurchaseLimitServiceInterface class PurchaseLimitService implements PurchaseLimitServiceInterface
{ {
/**
* @Inject
* @var ParamsTokenServiceInterface
*/
protected $paramsTokenService;
/**
* @Inject
* @var AdServiceInterface
*/
protected $adService;
public function getStoreIdByMarketId($params) 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 '';
$market_id = $params['market_id'] ?? 0;
//获取ssdb上的首页banner logo 列表
$logo_list = $this->paramsTokenService->analyze('banner_logo_list');
//获取ssdb上的首页banner 市场 列表
$market_list = $this->paramsTokenService->analyze('banner_market_list');
//根据前端指定的指获取店铺id 字符串 并拆分成数组
if(isset($market_list['market_id_'.$market_id]) && !empty($market_list['market_id_'.$market_id])) {
$store_list = $market_list['market_id_' . $market_id];
$store_list = explode(',', $store_list);
//遍历店铺
foreach ($store_list as $store_id) {
$banners[] = [
'id' => $store_id,
'item' => 1,
'item_text' => 'page',
'logo' => $logo_list['store_id_' . $store_id],
'redirect_url' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=' . $store_id,
'src' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=' . $store_id,
'src2' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=' . $store_id,
];
}
}else{
$banners = Ad::query()->select(['id','title','logo','item','src','src2'])
->where([
'type' => Ad::TYPE_BANNER,
'status' => Ad::STATUS_YES
])
->orderBy('orderby', 'desc')
->get();
}
return $banners;
}
public function getBannerByMarketId($params)
{
$market_id = $params['market_id'] ?? 0;
//获取ssdb上的首页banner logo 列表
$logo_list = $this->paramsTokenService->analyze('banner_logo_list');
//获取ssdb上的首页banner 市场 列表
$market_list = $this->paramsTokenService->analyze('banner_market_list');
//根据前端指定的指获取店铺id 字符串 并拆分成数组
if(isset($market_list['market_id_'.$market_id]) && !empty($market_list['market_id_'.$market_id])) {
$store_list = $market_list['market_id_' . $market_id];
$store_list = explode(',', $store_list);
//遍历店铺
foreach ($store_list as $store_id) {
$banners[] = [
'id' => $store_id,
'item' => 1,
'item_text' => 'page',
'logo' => $logo_list['store_id_' . $store_id],
'redirect_url' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=' . $store_id,
'src' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=' . $store_id,
'src2' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=' . $store_id,
];
}
}else{
$banners = $this->adService->banners();
}
return $banners;
} }
public function ssdbPurchaseRecord($data,$user_id,$global_order_id) public function ssdbPurchaseRecord($data,$user_id,$global_order_id)

2
app/Service/PurchaseLimitServiceInterface.php

@ -8,6 +8,8 @@ interface PurchaseLimitServiceInterface
{ {
public function getStoreIdByMarketId($params); public function getStoreIdByMarketId($params);
public function getBannerByMarketId($params);
public function ssdbPurchaseRecord($params,$user_id,$global_order_id); public function ssdbPurchaseRecord($params,$user_id,$global_order_id);
public function delSsdbPurchaseRecord($global_order_id); public function delSsdbPurchaseRecord($global_order_id);

139
app/Service/SeparateAccountsService.php

@ -4,7 +4,11 @@ namespace App\Service;
use App\Commons\Log; use App\Commons\Log;
use App\Constants\LogLabel; use App\Constants\LogLabel;
use App\Constants\SsdbKeysPrefix;
use App\Model\FinancialRecord; use App\Model\FinancialRecord;
use App\Model\Market;
use App\Model\MmInfo;
use App\Model\MpInfo;
use App\Model\Order; use App\Model\Order;
use App\Model\OrderMain; use App\Model\OrderMain;
use App\Model\ServiceReward; use App\Model\ServiceReward;
@ -14,8 +18,10 @@ use App\Model\SystemConfig;
use App\Model\UserBalance; use App\Model\UserBalance;
use App\Model\UserRelationBind; use App\Model\UserRelationBind;
use App\Model\Users; use App\Model\Users;
use App\TaskWorker\SSDBTask;
use Hyperf\DbConnection\Db; use Hyperf\DbConnection\Db;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
use Hyperf\Utils\ApplicationContext;
class SeparateAccountsService implements SeparateAccountsServiceInterface class SeparateAccountsService implements SeparateAccountsServiceInterface
{ {
@ -68,6 +74,7 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface
*/ */
public function orderOnlineCompleted($global_order_id) public function orderOnlineCompleted($global_order_id)
{ {
// 线上订单完成(用户点击确认收货完成/管理后台点击完成/配送员点击完成/自动收货等),进行相关分账 // 线上订单完成(用户点击确认收货完成/管理后台点击完成/配送员点击完成/自动收货等),进行相关分账
// 订单 // 订单
$orderMain = OrderMain::query() $orderMain = OrderMain::query()
@ -83,6 +90,8 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface
Db::beginTransaction(); Db::beginTransaction();
try { try {
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
// =======商户订单收入流水 / Start======= // =======商户订单收入流水 / Start=======
// 查询子订单 // 查询子订单
$orders = Order::query()->select(['id', 'money', 'user_id', 'store_id', 'pay_time']) $orders = Order::query()->select(['id', 'money', 'user_id', 'store_id', 'pay_time'])
@ -146,12 +155,81 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface
} }
// 账单分成 // 账单分成
if ($orderMain->type == OrderMain::ORDER_TYPE_ONLINE) {
$money = bcmul($orderMain->money, bcdiv($award['flow_reward'], 100, 6), 2); $money = bcmul($orderMain->money, bcdiv($award['flow_reward'], 100, 6), 2);
$this->financialRecordService->communitySeparateAccountsByOrderComp($communityBind->source_id, $global_order_id, $money); $this->financialRecordService->communitySeparateAccountsByOrderComp($communityBind->source_id, $global_order_id, $money);
} }
}
// =======社区服务点分账 / End======= // =======社区服务点分账 / End=======
// =======服务商、市场经理奖励分账 / Start=======
// 前提A:新用户下单并且订单完成(线上、线下都行)
// 奖励规则A:用户是平台新用户,奖励市场经理 1 元,服务商 0.5 元,如果是线上订单,服务商有6%的订单分成
// 前提B:新商户旗下产生 10 个新用户
// 奖励规则B:奖励市场经理 25 元,服务商 10 元(仅仅奖励一次)
// 前提C:用户线上下单并且订单完成
// 奖励规则C:奖励服务商账单 6% 分成
// 判断是新商户:入驻绑定的时候把关系存在SSDB
// =======服务商、市场经理奖励分账 / Start=======
$MmMpAwardConfig = [
'mm_new_user' => 1,
'mm_new_store' => 25,
'mp_new_user' => 0.5,
'mp_new_store' => 10,
'separate_rate' => 6,
'limit_new_user_number' => 10,
];
foreach ($orders as $key => &$order) {
// 当前订单(子)对应商户是否有市场经理绑定关系
$store = Store::query()->find($order['store_id']); // 商户
$mmInfo = MmInfo::query()->where(['user_id' => $store->mm_user_id])->first(); // 市场经理
$market = Market::query()->find($mmInfo->market_id); // 市场
$mpInfo = MpInfo::query()->find($market->mp_id); // 服务商
$ssdbName = 'mm_'.$mmInfo->id.'_award_'.$store->id;
// TODO 暂时在这里初始化
if (!$ssdb->exec('hexists', $ssdbName, 'is_awarded')) {
$ssdb->exec('hset', $ssdbName, 'is_awarded', 0);
}
if (!$ssdb->exec('hexists', $ssdbName, 'new_user_number')) {
$ssdb->exec('hset', $ssdbName, 'new_user_number', 0);
}
// 平台新用户
if ($this->userService->isPlatformNewUser($orderMain->user_id, $orderMain->id)) {
$ssdb->exec('hincr', $ssdbName, 'new_user_number', 1);
$this->financialRecordService->mmAwardByPlatNewUser($mmInfo->admin_user_id, $global_order_id, $MmMpAwardConfig['mm_new_user'], '发展新用户'); // 市场经理新用户奖励
$this->financialRecordService->mpAwardByPlatNewUser($mpInfo->admin_user_id, $global_order_id, $MmMpAwardConfig['mp_new_user'], '市场经理「'.$mmInfo->name.'」发展新用户'); // 服务商新用户奖励
}
$record = $ssdb->exec('hgetall', $ssdbName);
// 判断是否已经奖励过新拓展商户的奖励,没有的话判断新用户个数是否达到要求,进行奖励
if (
!empty($record)
&&$record['is_awarded']==0
&&$record['new_user_number']>=$MmMpAwardConfig['limit_new_user_number']
) { // 存在记录且未发放奖励,同时新用户数已经超过10
$ssdb->exec('hset', $ssdbName, 'is_awarded', 1);
$this->financialRecordService->mmAwardByNewStore($mmInfo->admin_user_id, $global_order_id, $MmMpAwardConfig['mm_new_store'], '发展新商户【'.$store->name.'】'); // 市场经理新商户奖励
$this->financialRecordService->mpAwardByNewStore($mpInfo->admin_user_id, $global_order_id, $MmMpAwardConfig['mp_new_store'], '市场经理「'.$mmInfo->name.'」发展新商户【'.$store->name.'】'); // 服务商新商户奖励
}
}
// 线上订单服务商分账
if ($orderMain->type == OrderMain::ORDER_TYPE_ONLINE) {
$money = bcmul($orderMain->money, bcdiv($MmMpAwardConfig['separate_rate'], 100, 6), 2);
$this->financialRecordService->mpSeparateAccountByOLOrderComp($mpInfo->admin_user_id, $global_order_id, $money);
}
// =======服务商、市场经理奖励分账 / End=======
Db::commit(); Db::commit();
return true; return true;
@ -242,7 +320,8 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface
$this->financialRecordService->storeAwardByPlatNewUserOFLOrder($store->user_id, $global_order_id, $awardAmount); $this->financialRecordService->storeAwardByPlatNewUserOFLOrder($store->user_id, $global_order_id, $awardAmount);
$needAward = true; $needAward = true;
} else {
}
else {
// 商户当日首单奖励 // 商户当日首单奖励
if ( if (
$this->userService->isStoreFirstOrderToday( $this->userService->isStoreFirstOrderToday(
@ -280,6 +359,64 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface
// =======线下订单支付完成商户分账 / End======= // =======线下订单支付完成商户分账 / End=======
// =======服务商、市场经理奖励分账 / Start=======
// 前提A:新用户下单并且订单完成(线上、线下都行)
// 奖励规则A:用户是平台新用户,奖励市场经理 1 元,服务商 0.5 元,如果是线上订单,服务商有6%的订单分成
// 前提B:新商户旗下产生 10 个新用户
// 奖励规则B:奖励市场经理 25 元,服务商 10 元(仅仅奖励一次)
// 前提C:用户线上下单并且订单完成
// 奖励规则C:奖励服务商账单 6% 分成
// 判断是新商户:入驻绑定的时候把关系存在SSDB
// =======服务商、市场经理奖励分账 / Start=======
$MmMpAwardConfig = [
'mm_new_user' => 1,
'mm_new_store' => 25,
'mp_new_user' => 0.5,
'mp_new_store' => 10,
'separate_rate' => 6,
'limit_new_user_number' => 10,
];
// 当前订单(子)对应商户是否有市场经理绑定关系
$store = Store::query()->find($order['store_id']); // 商户
$mmInfo = MmInfo::query()->where(['user_id' => $store->mm_user_id])->first(); // 市场经理
$market = Market::query()->find($mmInfo->market_id); // 市场
$mpInfo = MpInfo::query()->find($market->mp_id); // 服务商
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
$ssdbName = 'mm_'.$mmInfo->id.'_award_'.$store->id;
// TODO 暂时在这里初始化
if (!$ssdb->exec('hexists', $ssdbName, 'is_awarded')) {
$ssdb->exec('hset', $ssdbName, 'is_awarded', 0);
}
if (!$ssdb->exec('hexists', $ssdbName, 'new_user_number')) {
$ssdb->exec('hset', $ssdbName, 'new_user_number', 0);
}
// 平台新用户
if ($this->userService->isPlatformNewUser($orderMain->user_id, $orderMain->id)) {
$ssdb->exec('hincr', $ssdbName, 'new_user_number', 1);
$this->financialRecordService->mmAwardByPlatNewUser($mmInfo->admin_user_id, $global_order_id, $MmMpAwardConfig['mm_new_user'], '发展新用户'); // 市场经理新用户奖励
$this->financialRecordService->mpAwardByPlatNewUser($mpInfo->admin_user_id, $global_order_id, $MmMpAwardConfig['mp_new_user'], '市场经理「'.$mmInfo->name.'」发展新用户'); // 服务商新用户奖励
}
$record = $ssdb->exec('hgetall', $ssdbName);
// 判断是否已经奖励过新拓展商户的奖励,没有的话判断新用户个数是否达到要求,进行奖励
if (
!empty($record)
&&$record['is_awarded']==0
&&$record['new_user_number']>=$MmMpAwardConfig['limit_new_user_number']
) { // 存在记录且未发放奖励,同时新用户数已经超过10
$ssdb->exec('hset', $ssdbName, 'is_awarded', 1);
$this->financialRecordService->mmAwardByNewStore($mmInfo->admin_user_id, $global_order_id, $MmMpAwardConfig['mm_new_store'], '发展新商户【'.$store->name.'】'); // 市场经理新商户奖励
$this->financialRecordService->mpAwardByNewStore($mpInfo->admin_user_id, $global_order_id, $MmMpAwardConfig['mp_new_store'], '市场经理「'.$mmInfo->name.'」发展新新商户【'.$store->name.'】'); // 服务商新商户奖励
}
// =======服务商、市场经理奖励分账 / End=======
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {

104
app/Service/StoreService.php

@ -0,0 +1,104 @@
<?php
namespace App\Service;
use App\Constants\LogLabel;
use App\Constants\SsdbKeysPrefix;
use App\Model\Store;
use App\TaskWorker\SSDBTask;
use Hyperf\DbConnection\Db;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpMessage\Upload\UploadedFile;
use Hyperf\Utils\ApplicationContext;
use League\Flysystem\Filesystem;
class StoreService implements StoreServiceInterface
{
/**
* @Inject
* @var AttachmentServiceInterface
*/
protected $attachmentService;
/**
* @Inject
* @var Filesystem
*/
protected $filesystem;
public function entry($data)
{
Db::beginTransaction();
try {
// 文件上传
if ($data['logo'] instanceof UploadedFile) {
$data['logo'] = $this->attachmentService->formUpload($data['logo'], 'storelogo', $this->filesystem);
}
if ($data['fm_img'] instanceof UploadedFile) {
$data['fm_img'] = $this->attachmentService->formUpload($data['fm_img'], 'idcard', $this->filesystem);
}
if ($data['zm_img'] instanceof UploadedFile) {
$data['zm_img'] = $this->attachmentService->formUpload($data['zm_img'], 'idcard', $this->filesystem);
}
if ($data['yyzz'] instanceof UploadedFile) {
$data['yyzz'] = $this->attachmentService->formUpload($data['yyzz'], 'storelicense', $this->filesystem);
}
// 商户信息入库(需审核)
$store = Store::query()->updateOrCreate(
['id' => $data['id']],
[
'name' => $data['name'],
'market_id' => $data['market_id'],
'md_type' => $data['md_type'],
'address' => $data['address'],
'coordinates' => $data['coordinates'],
'details' => $data['details'],
'link_name' => $data['link_name'],
'link_tel' => $data['link_tel'],
'tel' => $data['link_tel'],
'logo' => $data['logo'],
'fm_img' => $data['fm_img'],
'zm_img' => $data['zm_img'],
'yyzz' => $data['yyzz'],
'user_id' => $data['user_id'],
'sq_id' => $data['user_id'],
'admin_id' => $data['user_id'],
'rz_time' => $data['rz_time'],
'mm_user_id' => $data['mm_user_id'],
'sq_time' => date('Y-m-d H:i:s'),
'rzdq_time' => date('Y-m-d H:i:s', time() + 1000 * 24 * 3600),
'state' => 1,
'is_open' => 1,
'money' => 0,
'code' => time() . rand(1000, 9999) . $data['user_id'],
'uniacid' => 2,
'zf_state' => 2,
]
);
Db::commit();
// 商户新用户等统计信息入SSDB
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
if (!$ssdb->exec('hexists', SsdbKeysPrefix::STORE_NEW_USER.$store->id, 'count')) {
if(false === $ssdb->exec('hset', SsdbKeysPrefix::STORE_NEW_USER.$store->id, ['count', 0])) {
$this->log->event(
LogLabel::SSDB_LOG,
['method' => 'hset-'.SsdbKeysPrefix::STORE_NEW_USER.$store->id, 'key' => SsdbKeysPrefix::STORE_NEW_USER.$store->id]
);
}
}
return true;
} catch (\Exception $e) {
Db::rollBack();
return $e->getMessage();
}
}
}

11
app/Service/StoreServiceInterface.php

@ -0,0 +1,11 @@
<?php
namespace App\Service;
interface StoreServiceInterface
{
/**
* 入驻
*/
public function entry($data);
}

5
app/Service/UserCommunityBindService.php

@ -25,7 +25,10 @@ class UserCommunityBindService implements UserRelationBindServiceInterface
public function bind($bind_type, $source_id, $user_id, $extra_data) public function bind($bind_type, $source_id, $user_id, $extra_data)
{ {
// TODO: Implement bind() method.
return UserRelationBind::query()->firstOrCreate(
['bind_type' => $bind_type, 'user_id' => $user_id],
['source_id' => $source_id, 'json_data' => $extra_data]
);
} }
public function isBinded($bind_type, $source_id, $user_id) public function isBinded($bind_type, $source_id, $user_id)

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

@ -69,11 +69,11 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='新用户奖励',
$comment='社区服务点',
$user_type=UserType::CS, $user_type=UserType::CS,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_CS_PLAT_NEW_USER,
$desc='新用户奖励',
$comment='社区服务点'
$money_type=FinancialRecord::MONEY_TYPE_CS_PLAT_NEW_USER
) )
{ {
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
@ -97,11 +97,11 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='新用户首单奖励',
$comment='社区服务点',
$user_type=UserType::CS, $user_type=UserType::CS,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_CS_FIRST_ORDER,
$desc='新用户首单奖励',
$comment='社区服务点'
$money_type=FinancialRecord::MONEY_TYPE_CS_FIRST_ORDER
) )
{ {
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
@ -124,11 +124,11 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='用户订单分成',
$comment='社区服务点',
$user_type=UserType::CS, $user_type=UserType::CS,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_CS_OL_ORDER,
$desc='用户订单分成',
$comment='社区服务点'
$money_type=FinancialRecord::MONEY_TYPE_CS_OL_ORDER
) )
{ {
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
@ -152,11 +152,11 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='新用户下单奖励',
$comment='用户当面付商户奖励',
$user_type=UserType::STORE, $user_type=UserType::STORE,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_STORE_PLAT_NEW_USER,
$desc='新用户下单奖励',
$comment='用户当面付商户奖励'
$money_type=FinancialRecord::MONEY_TYPE_STORE_PLAT_NEW_USER
) )
{ {
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
@ -176,11 +176,11 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='用户店铺首单奖励',
$comment='用户当面付商户奖励',
$user_type=UserType::STORE, $user_type=UserType::STORE,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_STORE_FIRST_ORDER,
$desc='用户店铺首单奖励',
$comment='用户当面付商户奖励'
$money_type=FinancialRecord::MONEY_TYPE_STORE_FIRST_ORDER
) )
{ {
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
@ -219,11 +219,11 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='用户下单(线下)',
$comment='用户下单',
$user_type=UserType::USER, $user_type=UserType::USER,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_USER_OFL_ORDER,
$desc='用户下单(线下)',
$comment='用户下单'
$money_type=FinancialRecord::MONEY_TYPE_USER_OFL_ORDER
) )
{ {
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
@ -236,11 +236,11 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='用户下单(线上)',
$comment='用户下单',
$user_type=UserType::USER, $user_type=UserType::USER,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_USER_OL_ORDER,
$desc='用户下单(线上)',
$comment='用户下单'
$money_type=FinancialRecord::MONEY_TYPE_USER_OL_ORDER
) )
{ {
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
@ -253,11 +253,11 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc = '线上外卖订单收入',
$comment = '用户订单完成',
$user_type = UserType::STORE, $user_type = UserType::STORE,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER, $source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_COMP,
$desc = '线上外卖订单收入',
$comment = '用户订单完成'
$money_type = FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_COMP
) )
{ {
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
@ -277,11 +277,11 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc = '线下当面付订单收入',
$comment = '用户订单完成',
$user_type = UserType::STORE, $user_type = UserType::STORE,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER, $source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP,
$desc = '线下当面付订单收入',
$comment = '用户订单完成'
$money_type = FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP
) )
{ {
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
@ -302,11 +302,11 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc = '线上订单退款',
$comment = '线上订单退款到微信',
$user_type = UserType::USER, $user_type = UserType::USER,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER, $source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_USER_OL_ORDER_REFUND,
$desc = '线上订单退款',
$comment = '线上订单退款到微信'
$money_type = FinancialRecord::MONEY_TYPE_USER_OL_ORDER_REFUND
) )
{ {
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
@ -340,11 +340,11 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc = '商户提现',
$comment = '商户提现打款',
$user_type = UserType::STORE, $user_type = UserType::STORE,
$source_type = FinancialRecord::SOURCE_TYPE_STORE_WITHDRAW, $source_type = FinancialRecord::SOURCE_TYPE_STORE_WITHDRAW,
$money_type = FinancialRecord::MONEY_TYPE_STORE_WITHDRAW,
$desc = '商户提现',
$comment = '商户提现打款'
$money_type = FinancialRecord::MONEY_TYPE_STORE_WITHDRAW
) )
{ {
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
@ -355,11 +355,11 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc = '商户线上订单退款(直接退)',
$comment = '商户线上订单退款(后台直接退)',
$user_type = UserType::STORE, $user_type = UserType::STORE,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER, $source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_DIRECT_REFUND,
$desc = '商户线上订单退款(直接退)',
$comment = '商户线上订单退款(后台直接退)'
$money_type = FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_DIRECT_REFUND
) )
{ {
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
@ -376,13 +376,138 @@ class FinancialRecordService implements FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc = '用户线上订单退款(直接退)',
$comment = '用户线上订单退款(后台直接退到微信)',
$user_type = UserType::USER, $user_type = UserType::USER,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER, $source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_USER_OL_ORDER_DIRECT_REFUND,
$desc = '用户线上订单退款(直接退)',
$comment = '用户线上订单退款(后台直接退到微信)'
$money_type = FinancialRecord::MONEY_TYPE_USER_OL_ORDER_DIRECT_REFUND
)
{
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
}
/**
* @inheritDoc
*/
public function mmAwardByPlatNewUser(
$user_id,
$source_id,
$money,
$desc = '发展新用户',
$comment = '市场经理发展新用户奖励',
$user_type = FinancialRecord::USER_TYPE_MM,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_MM_PLAT_NEW_USER
)
{
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
// 维护余额
$balance = UserBalance::query()->firstOrNew([
'user_type' => $user_type,
'source_id' => $user_id
]);
$balance->balance = bcadd($balance->balance, $money, 2);
$balance->save();
}
/**
* @inheritDoc
*/
public function mmAwardByNewStore(
$user_id,
$source_id,
$money,
$desc = '发展新商户',
$comment = '市场经理发展新商户奖励',
$user_type = FinancialRecord::USER_TYPE_MM,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_MM_PLAT_NEW_STORE
)
{
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
// 维护余额
$balance = UserBalance::query()->firstOrNew([
'user_type' => $user_type,
'source_id' => $user_id
]);
$balance->balance = bcadd($balance->balance, $money, 2);
$balance->save();
}
/**
* @inheritDoc
*/
public function mpAwardByPlatNewUser(
$user_id,
$source_id,
$money,
$desc = '服务商发展新用户',
$comment = '服务商发展新用户奖励',
$user_type = FinancialRecord::USER_TYPE_MP,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_MP_PLAT_NEW_USER
) )
{ {
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
// 维护余额
$balance = UserBalance::query()->firstOrNew([
'user_type' => $user_type,
'source_id' => $user_id
]);
$balance->balance = bcadd($balance->balance, $money, 2);
$balance->save();
}
/**
* @inheritDoc
*/
public function mpAwardByNewStore(
$user_id,
$source_id,
$money,
$desc = '服务商发展新商户',
$comment = '服务商发展新商户奖励',
$user_type = FinancialRecord::USER_TYPE_MP,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_MP_PLAT_NEW_STORE
)
{
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
// 维护余额
$balance = UserBalance::query()->firstOrNew([
'user_type' => $user_type,
'source_id' => $user_id
]);
$balance->balance = bcadd($balance->balance, $money, 2);
$balance->save();
}
/**
* @inheritDoc
*/
public function mpSeparateAccountByOLOrderComp(
$user_id,
$source_id,
$money,
$desc = '服务商线上订单分账',
$comment = '服务商用户线上订单完成后分账',
$user_type = FinancialRecord::USER_TYPE_MP,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_MP_OL_ORDER
)
{
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
// 维护余额
$balance = UserBalance::query()->firstOrNew([
'user_type' => $user_type,
'source_id' => $user_id
]);
$balance->balance = bcadd($balance->balance, $money, 2);
$balance->save();
} }
} }

5
app/Service/v3/Implementations/UserCommunityBindService.php

@ -26,7 +26,10 @@ class UserCommunityBindService implements UserRelationBindServiceInterface
public function bind($bind_type, $source_id, $user_id, $extra_data) public function bind($bind_type, $source_id, $user_id, $extra_data)
{ {
// TODO: Implement bind() method.
return UserRelationBind::query()->firstOrCreate(
['bind_type' => $bind_type, 'user_id' => $user_id],
['source_id' => $source_id, 'json_data' => $extra_data]
);
} }
public function isBinded($bind_type, $source_id, $user_id) public function isBinded($bind_type, $source_id, $user_id)

195
app/Service/v3/Interfaces/FinancialRecordServiceInterface.php

@ -8,6 +8,9 @@ use App\Model\v3\FinancialRecord;
interface FinancialRecordServiceInterface interface FinancialRecordServiceInterface
{ {
public function record($user_id, $record, $isLedger=false);
public function recordAll($user_id, $source_id, $money, $user_type=1, $source_type=0, $money_type=0, $desc='', $comment='');
/** /**
* 社区服务点新用户奖励 * 社区服务点新用户奖励
* @param $user_id * @param $user_id
@ -24,11 +27,11 @@ interface FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='新用户奖励',
$comment='',
$user_type=UserType::CS, $user_type=UserType::CS,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_CS_PLAT_NEW_USER,
$desc='新用户奖励',
$comment=''
$money_type=FinancialRecord::MONEY_TYPE_CS_PLAT_NEW_USER
); );
/** /**
@ -47,11 +50,11 @@ interface FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='新用户首单奖励',
$comment='',
$user_type=UserType::CS, $user_type=UserType::CS,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_CS_FIRST_ORDER,
$desc='新用户首单奖励',
$comment=''
$money_type=FinancialRecord::MONEY_TYPE_CS_FIRST_ORDER
); );
/** /**
@ -70,11 +73,11 @@ interface FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='用户订单分成',
$comment='',
$user_type=UserType::CS, $user_type=UserType::CS,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_CS_OL_ORDER,
$desc='用户订单分成',
$comment=''
$money_type=FinancialRecord::MONEY_TYPE_CS_OL_ORDER
); );
/** /**
@ -105,11 +108,11 @@ interface FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='新用户下单奖励',
$comment='',
$user_type=UserType::STORE, $user_type=UserType::STORE,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_STORE_PLAT_NEW_USER,
$desc='新用户下单奖励',
$comment=''
$money_type=FinancialRecord::MONEY_TYPE_STORE_PLAT_NEW_USER
); );
/** /**
@ -128,11 +131,11 @@ interface FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='用户店铺首单奖励',
$comment='',
$user_type=UserType::STORE, $user_type=UserType::STORE,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_STORE_FIRST_ORDER,
$desc='用户店铺首单奖励',
$comment=''
$money_type=FinancialRecord::MONEY_TYPE_STORE_FIRST_ORDER
); );
/** /**
@ -151,11 +154,11 @@ interface FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='用户下单(线下)',
$comment='',
$user_type=UserType::USER, $user_type=UserType::USER,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_USER_OFL_ORDER,
$desc='用户下单(线下)',
$comment=''
$money_type=FinancialRecord::MONEY_TYPE_USER_OFL_ORDER
); );
/** /**
@ -174,11 +177,11 @@ interface FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='用户下单(线上)',
$comment='',
$user_type=UserType::USER, $user_type=UserType::USER,
$source_type=FinancialRecord::SOURCE_TYPE_ORDER, $source_type=FinancialRecord::SOURCE_TYPE_ORDER,
$money_type=FinancialRecord::MONEY_TYPE_USER_OL_ORDER,
$desc='用户下单(线上)',
$comment=''
$money_type=FinancialRecord::MONEY_TYPE_USER_OL_ORDER
); );
/** /**
@ -197,11 +200,11 @@ interface FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='线上外卖订单收入',
$comment='',
$user_type = UserType::STORE, $user_type = UserType::STORE,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER, $source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_COMP,
$desc='线上外卖订单收入',
$comment=''
$money_type = FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_COMP
); );
/** /**
@ -220,11 +223,11 @@ interface FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='线下当面付订单收入',
$comment='',
$user_type = UserType::STORE, $user_type = UserType::STORE,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER, $source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP,
$desc='线下当面付订单收入',
$comment=''
$money_type = FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP
); );
/** /**
@ -243,11 +246,11 @@ interface FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='线上订单退款',
$comment='',
$user_type = UserType::STORE, $user_type = UserType::STORE,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER, $source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP,
$desc='线上订单退款',
$comment=''
$money_type = FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP
); );
/** /**
@ -279,32 +282,146 @@ interface FinancialRecordServiceInterface
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='商户提现',
$comment='',
$user_type = UserType::STORE, $user_type = UserType::STORE,
$source_type = FinancialRecord::SOURCE_TYPE_STORE_WITHDRAW, $source_type = FinancialRecord::SOURCE_TYPE_STORE_WITHDRAW,
$money_type = FinancialRecord::MONEY_TYPE_STORE_WITHDRAW,
$desc='商户提现',
$comment=''
$money_type = FinancialRecord::MONEY_TYPE_STORE_WITHDRAW
); );
public function storeRefundDirect( public function storeRefundDirect(
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='商户线上订单退款(直接退)',
$comment='',
$user_type = UserType::STORE, $user_type = UserType::STORE,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER, $source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_DIRECT_REFUND,
$desc='商户线上订单退款(直接退)',
$comment=''
$money_type = FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_DIRECT_REFUND
); );
public function userRefundDirect( public function userRefundDirect(
$user_id, $user_id,
$source_id, $source_id,
$money, $money,
$desc='用户线上订单退款(直接退)',
$comment='',
$user_type = UserType::USER, $user_type = UserType::USER,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER, $source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_USER_OL_ORDER_DIRECT_REFUND,
$desc='用户线上订单退款(直接退)',
$comment=''
$money_type = FinancialRecord::MONEY_TYPE_USER_OL_ORDER_DIRECT_REFUND
);
/**
* 市场经理新用户
* @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
*/
public function mmAwardByPlatNewUser(
$user_id,
$source_id,
$money,
$desc = '市场经理发展新用户',
$comment = '',
$user_type = FinancialRecord::USER_TYPE_MM,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_MM_PLAT_NEW_USER
);
/**
* 市场经理新商户
* @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 mmAwardByNewStore(
$user_id,
$source_id,
$money,
$desc = '市场经理发展新商户',
$comment = '市场经理发展新商户奖励',
$user_type = FinancialRecord::USER_TYPE_MM,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_MM_PLAT_NEW_STORE
);
/**
* 服务商新用户
* @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 mpAwardByPlatNewUser(
$user_id,
$source_id,
$money,
$desc = '服务商发展新用户',
$comment = '服务商发展新用户奖励',
$user_type = FinancialRecord::USER_TYPE_MP,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_MP_PLAT_NEW_USER
);
/**
* 服务商新商户
* @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 mpAwardByNewStore(
$user_id,
$source_id,
$money,
$desc = '服务商发展新商户',
$comment = '服务商发展新商户奖励',
$user_type = FinancialRecord::USER_TYPE_MP,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_MP_PLAT_NEW_STORE
);
/**
* 服务商线上订单分账
* @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 mpSeparateAccountByOLOrderComp(
$user_id,
$source_id,
$money,
$desc = '服务商线上订单分账',
$comment = '服务商用户线上订单完成后分账',
$user_type = FinancialRecord::USER_TYPE_MP,
$source_type = FinancialRecord::SOURCE_TYPE_ORDER,
$money_type = FinancialRecord::MONEY_TYPE_MP_OL_ORDER
); );
} }

2
app/Service/v3/Interfaces/UserRelationBindServiceInterface.php

@ -28,7 +28,7 @@ interface UserRelationBindServiceInterface
/** /**
* 绑定 * 绑定
* 始终绑定一个新的关系,如果这个关系(source_id=》user_id)存在则更新其他数据
* 始终绑定一个关系
* @param $bind_type * @param $bind_type
* @param $source_id * @param $source_id
* @param $user_id * @param $user_id

2
config/autoload/dependencies.php

@ -36,6 +36,8 @@ return [
\App\Service\WxRefundServiceInterface::class => \App\Service\WxRefundService::class, \App\Service\WxRefundServiceInterface::class => \App\Service\WxRefundService::class,
\App\Service\SmsServiceInterface::class => \App\Service\SmsAliService::class, \App\Service\SmsServiceInterface::class => \App\Service\SmsAliService::class,
\App\Service\OrderListServiceInterface::class => \App\Service\OrderListService::class, \App\Service\OrderListServiceInterface::class => \App\Service\OrderListService::class,
\App\Service\StoreServiceInterface::class => \App\Service\StoreService::class,
\App\JsonRpc\SmsServiceInterface::class => \App\JsonRpc\AlismsService::class,
\App\Service\v3\Interfaces\GoodsServiceInterface::class => \App\Service\v3\Implementations\GoodsService::class, \App\Service\v3\Interfaces\GoodsServiceInterface::class => \App\Service\v3\Implementations\GoodsService::class,
\App\Service\v3\Interfaces\SmsSendServiceInterface::class => \App\Service\v3\Implementations\SmsAliSendService::class, \App\Service\v3\Interfaces\SmsSendServiceInterface::class => \App\Service\v3\Implementations\SmsAliSendService::class,
\App\Service\v3\Interfaces\HelperServiceInterface::class => \App\Service\v3\Implementations\HelperService::class, \App\Service\v3\Interfaces\HelperServiceInterface::class => \App\Service\v3\Implementations\HelperService::class,

Loading…
Cancel
Save