商户绑定一个用户

main
fengxinyhyl 11 months ago
parent cd0365c472
commit c2f55f5726
  1. 19
      app/common/repositories/system/merchant/MerchantRepository.php
  2. 197
      app/common/repositories/user/UserAssetsLogRepository.php
  3. 7
      app/controller/admin/system/merchant/Merchant.php
  4. 2
      app/controller/api/Auth.php

@ -28,6 +28,7 @@ use app\common\repositories\store\StoreCategoryRepository;
use app\common\repositories\system\attachment\AttachmentRepository;
use app\common\repositories\user\UserBillRepository;
use app\common\repositories\user\UserRelationRepository;
use app\common\repositories\user\UserRepository;
use app\common\repositories\user\UserVisitRepository;
use app\common\repositories\wechat\RoutineQrcodeRepository;
use crmeb\jobs\ClearMerchantStoreJob;
@ -235,6 +236,24 @@ class MerchantRepository extends BaseRepository
$make->createMerchantAccount($merchant, $account, $password);
app()->make(ShippingTemplateRepository::class)->createDefault($merchant->mer_id);
app()->make(ProductCopyRepository::class)->defaulCopyNum($merchant->mer_id);
/**
* @var UserRepository $userRepository
*/
$userRepository = \app()->make(UserRepository::class);
$user = $userRepository->searchOne(['phone' => $merchant['mer_phone']]);
if(empty($user)){
$userRepository->create("pc", [
'account' => $data['mer_phone'],
'mer_id' => $merchant['mer_id'],
'real_name' => $data['real_name'],
'phone' => $data['mer_phone'],
'pwd' => $userRepository->encodePassword(substr(md5(time() . random_int(10, 99)), 0, 8)),
]);
}else{
$userRepository->update($user['uid'], ['mer_id' => $merchant['mer_id']]);
}
return $merchant;
});
}

@ -18,6 +18,7 @@ use app\common\repositories\BaseRepository;
use app\common\repositories\store\product\ProductAssistRepository;
use app\common\repositories\store\product\ProductRepository;
use app\common\repositories\system\groupData\GroupDataRepository;
use app\common\repositories\system\merchant\MerchantCategoryRepository;
use app\common\repositories\system\merchant\MerchantRepository;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
@ -35,14 +36,16 @@ class UserAssetsLogRepository extends BaseRepository
const ASSET_TYPE_HUITONG = 4; // 惠通宝
const ASSET_TYPE_CONTRIBUTION = 5; // 贡献值
const CHANGE_TYPE_ORDER_GET = 1; // 订单获取
const CHANGE_TYPE_ORDER = 1; // 个人下单
const CHANGE_TYPE_SIGN = 2; // 签到
const CHANGE_TYPE_SHARE = 3; // 分红
const CHANGE_TYPE_ORDER_PAY = 4; // 订单消费
const CHANGE_TYPE_SPREAD = 5; // 推广
const CHANGE_TYPE_CULTIVATE = 6; // 培育
const CHANGE_TYPE_TRANSFER = 7; // 赠与
const CHANGE_TYPE_EXCHANGE = 8; // 兑换
const CHANGE_TYPE_SHARE = 3; // 消费积分兑换分红点
const CHANGE_TYPE_SHARE_GET = 4; // 分红点返佣
const CHANGE_TYPE_SPREAD_GET = 5; // 推广返佣
const CHANGE_TYPE_CULTIVATE = 6; // 培育奖
const CHANGE_TYPE_AGENT = 7; // 区域代理奖
const CHANGE_TYPE_HUITONG = 8; // 惠通宝兑换消费积分
const CHANGE_TYPE_HUITONG_TO = 9; // 转让他人
const CHANGE_TYPE_HUITONG_GET = 10; // 他人转让
const STATUS_FROZEN = 0; // 冻结
const STATUS_SUCCESS = 1; // 成功
@ -67,14 +70,16 @@ class UserAssetsLogRepository extends BaseRepository
public function getChangeType()
{
return array(
self::CHANGE_TYPE_ORDER_GET => "订单获取",
self::CHANGE_TYPE_SIGN => "签到",
self::CHANGE_TYPE_SHARE => "分红",
self::CHANGE_TYPE_ORDER_PAY => "订单消费",
self::CHANGE_TYPE_SPREAD => "推广",
self::CHANGE_TYPE_CULTIVATE => "培育",
self::CHANGE_TYPE_TRANSFER => "赠与",
self::CHANGE_TYPE_EXCHANGE => "兑换",
self::CHANGE_TYPE_ORDER => '个人下单',
self::CHANGE_TYPE_SIGN => '签到',
self::CHANGE_TYPE_SHARE => '消费积分兑换分红点',
self::CHANGE_TYPE_SHARE_GET => '分红点返佣',
self::CHANGE_TYPE_SPREAD_GET => '推广返佣',
self::CHANGE_TYPE_CULTIVATE => '培育奖',
self::CHANGE_TYPE_AGENT => '区域代理奖',
self::CHANGE_TYPE_HUITONG => '惠通宝兑换消费积分',
self::CHANGE_TYPE_HUITONG_TO => '转让他人',
self::CHANGE_TYPE_HUITONG_GET => '他人转让',
);
}
@ -155,37 +160,63 @@ class UserAssetsLogRepository extends BaseRepository
}
// 6. 商户和平台资产
// $this->merchantAndPlatformAssets($orderItem);
$this->merchantAndPlatformAssets($orderItem);
}
}
public function merchantAndPlatformAssets($orderItem){
/**
* @var MerchantRepository $merchantRepository
*/
$merchantRepository = app(MerchantRepository::class);
$merchant = $merchantRepository->get($orderItem['mer_id']);
if(empty($merchant)){
return;
}
public function merchantAndPlatformAssets($orderItem)
{
/**
* @var UserRepository $userRepository
*/
$userRepository = app(UserRepository::class);
$user = $userRepository->searchOne(['phone' => $merchant['mer_phone']]);
$logList = array();
$welfare = $huitong = $contribution = 0;
if($user){
$logList[] = array(
$user = $userRepository->searchOne(['mer_id' => $orderItem['mer_id']]);
if ($user) {
$logList = array();
$welfare = $consume = $huitong = $contribution = 0;
$consume = round($orderItem['total_price'] * $orderItem['commission_rate'] / 100, 2);
$consume = $this->_getValue($consume);
$logList[] = array(
'uid' => $user['uid'],
'asset_type' => self::ASSET_TYPE_CONSUME,
'type' => self::CHANGE_TYPE_ORDER,
'status' => self::STATUS_FROZEN,
'order_id' => $orderItem['order_id'],
'count' => $consume,
'mer_id' => $orderItem['mer_id'],
);
if($orderItem['integral']){
$welfare = round($orderItem['integral'] * (100 - $orderItem['commission_rate']) / 100, 2);
$welfare = $this->_getValue($welfare);
$logList[] = array(
'uid' => $user['uid'],
'asset_type' => self::ASSET_TYPE_WELFARE,
'type' => self::CHANGE_TYPE_ORDER,
'status' => self::STATUS_FROZEN,
'order_id' => $orderItem['order_id'],
'count' => $welfare,
'mer_id' => $orderItem['mer_id'],
);
}
$this->addLog($logList);
$this->userAssetsRepository->orderEvent($user['uid'], self::STATUS_FROZEN, compact('consume', 'welfare', 'huitong', 'contribution'));
}
if($orderItem['integral']){
$welfare = round($orderItem['integral'] * $orderItem['commission_rate'] / 100, 2);
$welfare = $this->_getValue($welfare);
$log = array(
'uid' => 0,
'asset_type' => self::ASSET_TYPE_WELFARE,
'type' => self::CHANGE_TYPE_ORDER_GET,
'type' => self::CHANGE_TYPE_ORDER,
'status' => self::STATUS_FROZEN,
'order_id' => $orderItem['order_id'],
'count' => $welfare,
'mer_id' => $merchant['id'],
'mer_id' => 0,
);
$this->addLog([$log]);
}
}
@ -203,17 +234,18 @@ class UserAssetsLogRepository extends BaseRepository
* @author zhangkxiang
* @editor
*/
public function recommendAssets($merId, $orderId, $config, $base){
$consume = $welfare = $huitong = $contribution = 0;
public function recommendAssets($merId, $orderId, $config, $base)
{
$consume = $welfare = $huitong = $contribution = 0;
/**
* @var MerchantRepository $merRepository
*/
$merRepository = app(MerchantRepository::class);
$merchant = $merRepository->get($merId);
$merchant = $merRepository->get($merId);
if (empty($merchant)) {
return;
}
if($merchant['spread_uid'] == 0){
if ($merchant['spread_uid'] == 0) {
return;
}
@ -221,40 +253,40 @@ class UserAssetsLogRepository extends BaseRepository
* @var UserRepository $userRepository
*/
$userRepository = app(UserRepository::class);
$user = $userRepository->get($merchant['spread_uid']);
$user = $userRepository->get($merchant['spread_uid']);
if (empty($user)) {
return;
}
$log= array(
$log = array(
'uid' => $user['uid'],
'asset_type' => self::ASSET_TYPE_WELFARE,
'type' => self::CHANGE_TYPE_ORDER_GET,
'type' => self::CHANGE_TYPE_SPREAD_GET,
'status' => self::STATUS_FROZEN,
'order_id' => $orderId,
);
if($user['agent_district_id']){
if ($user['agent_district_id']) {
// 区域代理
$orderWelfare = round($base * $config['welfare_agent_recommend'] / 100, 2);
$welfare = $this->_getValue($orderWelfare);
$ext = array('district_id' => $user['agent_district_id'], 'name' => "区域代理推荐商家");
}elseif ($user['group_id']){
$ext = array('district_id' => $user['agent_district_id'], 'name' => "区域代理推荐商家");
} elseif ($user['group_id']) {
// 项目经理
$orderWelfare = round($base * $config['welfare_project_recommend'] / 100, 2);
$welfare = $this->_getValue($orderWelfare);
$ext = array('group_id' => $user['group_id'], 'name' => "项目经理推荐商家");
}elseif ($user['mer_id']){
$ext = array('group_id' => $user['group_id'], 'name' => "项目经理推荐商家");
} elseif ($user['mer_id']) {
// 商家
$orderWelfare = round($base * $config['welfare_merchant_recommend'] / 100, 2);
$welfare = $this->_getValue($orderWelfare);
$ext = array('mer_id' => $user['mer_id'], 'name' => "商家推荐商家");
} else{
return ;
$ext = array('mer_id' => $user['mer_id'], 'name' => "商家推荐商家");
} else {
return;
}
$log['count'] = $welfare;
$log['ext'] = $ext;
$log['ext'] = $ext;
$this->addLog([$log]);
$this->userAssetsRepository->orderEvent($user['uid'], self::STATUS_FROZEN, compact('consume', 'welfare', 'huitong', 'contribution'));
@ -274,13 +306,14 @@ class UserAssetsLogRepository extends BaseRepository
* @author zhangkxiang
* @editor
*/
public function agentAssets($districtId, $orderId, $config, $base){
$consume = $welfare = $huitong = $contribution = 0;
public function agentAssets($districtId, $orderId, $config, $base)
{
$consume = $welfare = $huitong = $contribution = 0;
/**
* @var UserRepository $userRepository
*/
$userRepository = app(UserRepository::class);
$user = $userRepository->getWhere(array('agent_district_id' => $districtId));
$user = $userRepository->getWhere(array('agent_district_id' => $districtId));
if (empty($user)) {
return;
}
@ -291,11 +324,11 @@ class UserAssetsLogRepository extends BaseRepository
$logList[] = array(
'uid' => $user['uid'],
'asset_type' => self::ASSET_TYPE_WELFARE,
'type' => self::CHANGE_TYPE_ORDER_GET,
'type' => self::CHANGE_TYPE_AGENT,
'status' => self::STATUS_FROZEN,
'order_id' => $orderId,
'count' => $welfare,
'ext' => array('district_id' => $districtId, 'name' => "区域代理"),
'ext' => array('district_id' => $districtId, 'name' => "区域代理"),
);
$this->addLog($logList);
@ -337,7 +370,7 @@ class UserAssetsLogRepository extends BaseRepository
$logList[] = array(
'uid' => $userProject['uid'],
'asset_type' => self::ASSET_TYPE_WELFARE,
'type' => self::CHANGE_TYPE_ORDER_GET,
'type' => self::CHANGE_TYPE_CULTIVATE,
'status' => self::STATUS_FROZEN,
'order_id' => $orderId,
'count' => $welfare,
@ -345,11 +378,11 @@ class UserAssetsLogRepository extends BaseRepository
// 2. 项目经理的惠通宝
$orderHuitong = round($base * $config['huitong_project'] * $config['huitong_project_' . $group] / 10000, 2);
$huitong = $this->_getValue($orderHuitong);
$huitong = $this->_getValue($orderHuitong);
$logList[] = array(
'uid' => $userProject['uid'],
'asset_type' => self::ASSET_TYPE_HUITONG,
'type' => self::CHANGE_TYPE_ORDER_GET,
'type' => self::CHANGE_TYPE_CULTIVATE,
'status' => self::STATUS_FROZEN,
'order_id' => $orderId,
'count' => $huitong,
@ -357,11 +390,11 @@ class UserAssetsLogRepository extends BaseRepository
// 3. 项目经理的贡献值
$orderContribution = round($base * $config['contribution_project'] * $config['contribution_project_' . $group] / 10000, 2);
$contribution = $this->_getValue($orderContribution);
$contribution = $this->_getValue($orderContribution);
$logList[] = array(
'uid' => $userProject['uid'],
'asset_type' => self::ASSET_TYPE_CONTRIBUTION,
'type' => self::CHANGE_TYPE_ORDER_GET,
'type' => self::CHANGE_TYPE_CULTIVATE,
'status' => self::STATUS_FROZEN,
'order_id' => $orderId,
'count' => $contribution,
@ -413,11 +446,11 @@ class UserAssetsLogRepository extends BaseRepository
// 1. 项目经理的福利积分
$orderWelfare = round($base * $config['welfare_project'] / 100, 2);
$welfare = $this->_getValue($orderWelfare);
$welfare = $this->_getValue($orderWelfare);
$logList[] = array(
'uid' => $userProject['uid'],
'asset_type' => self::ASSET_TYPE_WELFARE,
'type' => self::CHANGE_TYPE_ORDER_GET,
'type' => self::CHANGE_TYPE_SPREAD_GET,
'status' => self::STATUS_FROZEN,
'order_id' => $orderId,
'count' => $welfare,
@ -425,11 +458,11 @@ class UserAssetsLogRepository extends BaseRepository
// 2. 项目经理的惠通宝
$orderHuitong = round($base * $config['huitong_project'] / 100, 2);
$huitong = $this->_getValue($orderHuitong);
$huitong = $this->_getValue($orderHuitong);
$logList[] = array(
'uid' => $userProject['uid'],
'asset_type' => self::ASSET_TYPE_HUITONG,
'type' => self::CHANGE_TYPE_ORDER_GET,
'type' => self::CHANGE_TYPE_SPREAD_GET,
'status' => self::STATUS_FROZEN,
'order_id' => $orderId,
'count' => $huitong,
@ -437,11 +470,11 @@ class UserAssetsLogRepository extends BaseRepository
// 3. 项目经理的贡献值
$orderContribution = round($base * $config['contribution_project'] / 100, 2);
$contribution = $this->_getValue($orderContribution);
$contribution = $this->_getValue($orderContribution);
$logList[] = array(
'uid' => $userProject['uid'],
'asset_type' => self::ASSET_TYPE_CONTRIBUTION,
'type' => self::CHANGE_TYPE_ORDER_GET,
'type' => self::CHANGE_TYPE_SPREAD_GET,
'status' => self::STATUS_FROZEN,
'order_id' => $orderId,
'count' => $contribution,
@ -474,7 +507,7 @@ class UserAssetsLogRepository extends BaseRepository
$logList[] = array(
'uid' => $orderItem['uid'],
'asset_type' => self::ASSET_TYPE_CONSUME,
'type' => self::CHANGE_TYPE_ORDER_GET,
'type' => self::CHANGE_TYPE_ORDER,
'status' => self::STATUS_FROZEN,
'order_id' => $orderItem['order_id'],
'count' => $orderItem['pay_price'],
@ -485,11 +518,11 @@ class UserAssetsLogRepository extends BaseRepository
if ($base) {
// 2. 本人的福利积分
$orderWelfare = round($base * 0.1, 2);
$welfare = $this->_getValue($orderWelfare);
$welfare = $this->_getValue($orderWelfare);
$logList[] = array(
'uid' => $orderItem['uid'],
'asset_type' => self::ASSET_TYPE_WELFARE,
'type' => self::CHANGE_TYPE_ORDER_GET,
'type' => self::CHANGE_TYPE_ORDER,
'status' => self::STATUS_FROZEN,
'order_id' => $orderItem['order_id'],
'count' => $welfare,
@ -497,11 +530,11 @@ class UserAssetsLogRepository extends BaseRepository
// 3. 本人的惠通宝
$orderHuitong = round($base * $config['huitong_user'] / 100, 2);
$huitong = $this->_getValue($orderHuitong);
$huitong = $this->_getValue($orderHuitong);
$logList[] = array(
'uid' => $orderItem['uid'],
'asset_type' => self::ASSET_TYPE_HUITONG,
'type' => self::CHANGE_TYPE_ORDER_GET,
'type' => self::CHANGE_TYPE_ORDER,
'status' => self::STATUS_FROZEN,
'order_id' => $orderItem['order_id'],
'count' => $huitong,
@ -509,11 +542,11 @@ class UserAssetsLogRepository extends BaseRepository
// 4. 本人的贡献值
$orderContribution = round($base * $config['contribution_user'] / 100, 2);
$contribution = $this->_getValue($orderContribution);
$contribution = $this->_getValue($orderContribution);
$logList[] = array(
'uid' => $orderItem['uid'],
'asset_type' => self::ASSET_TYPE_CONTRIBUTION,
'type' => self::CHANGE_TYPE_ORDER_GET,
'type' => self::CHANGE_TYPE_ORDER,
'status' => self::STATUS_FROZEN,
'order_id' => $orderItem['order_id'],
'count' => $contribution,
@ -524,8 +557,9 @@ class UserAssetsLogRepository extends BaseRepository
}
private function _getValue($value){
if($value < 0.01){
private function _getValue($value)
{
if ($value < 0.01) {
return 0.01;
}
return $value;
@ -543,7 +577,7 @@ class UserAssetsLogRepository extends BaseRepository
public function addLog($list)
{
foreach ($list as $key => $item) {
$list[$key]['ext'] = $item['ext'] ?? array();
$list[$key]['ext'] = $item['ext'] ?? array();
}
$this->dao->insertAll($list);
}
@ -564,15 +598,16 @@ class UserAssetsLogRepository extends BaseRepository
* @author zhangkxiang
* @editor
*/
public function list($uid, $where, $page, $limit){
$query = $this->dao->search($uid, $where);
$count = $query->count();
$data = $query->page($page, $limit)->select();
$list = array();
public function list($uid, $where, $page, $limit)
{
$query = $this->dao->search($uid, $where);
$count = $query->count();
$data = $query->page($page, $limit)->select();
$list = array();
$changeType = $this->getChangeType();
foreach ($data as $item){
foreach ($data as $item) {
$item['type'] = $changeType[$item['type']];
$list[] = $item;
$list[] = $item;
}
return compact('count', 'list');
}

@ -100,13 +100,6 @@ class Merchant extends BaseController
{
$data = $this->checkParam($validate);
$this->repository->createMerchant($data);
$userRepository = \app()->make(UserRepository::class);
$user = $userRepository->create("pc", [
'account' => $data['mer_phone'],
'real_name' => $data['real_name'],
'phone' => $data['mer_phone'],
'pwd' => $userRepository->encodePassword(substr(md5(time() . random_int(10, 99)), 0, 8)),
]);
return app('json')->success('添加成功');
}

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save