1748153932 11 months ago
commit e121e4d5d1
  1. 63
      app/command/dayUserValue.php
  2. 54
      app/common/repositories/system/admin/PartnerRepository.php
  3. 7
      app/common/repositories/user/UserPartnerRepository.php
  4. 42
      app/controller/admin/system/admin/Partner.php
  5. 21
      app/controller/admin/user/User.php
  6. 2
      config/console.php
  7. 26
      crmeb/jobs/OrderPartnerJob.php

@ -0,0 +1,63 @@
<?php
declare (strict_types=1);
namespace app\command;
use Swoole\Coroutine\MySQL\Exception;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use app\common\model\user\User as userModel;
use think\console\Output;
use think\event\RouteLoaded;
use think\exception\ValidateException;
use think\facade\Cache;
use think\facade\Db;
use think\facade\Route;
use app\common\repositories\system\auth\MenuRepository;
// /www/server/php/74/bin/php /server/wwwroot/crmeb/think dayValue
class dayUserValue extends Command
{
protected function configure()
{
// 指令配置
$this->setName('dayUserValue')
->addArgument('dayValue', Argument::OPTIONAL, 'php think menu [1] / [2]')
->setDescription('用户每日兑换率生成');
}
protected function execute(Input $input, Output $output)
{
$config = systemConfig('brand_config');
$resConfig = [];
foreach (explode('/', $config) as $k => $v) {
$newConfig = explode(',', $v);
$resConfig[$k]['start'] = $newConfig[0];
$resConfig[$k]['end'] = $newConfig[1];
$resConfig[$k]['bili'] = $newConfig[2];
}
try {
$user = userModel::getDB()->where('status', 1)->select()->toArray();
foreach ($user as $k => $v) {
$growth_rate = 0;
$days = $v['super_days'] + 1;
foreach ($resConfig as $rk => $rv) {
if ($days >= $rv['start'] && $rv['bili'] > 0) {
$growth_rate = bcadd($v['growth_rate'], $rv['bili'], 2);
}
}
userModel::getDB()->where('uid', $v['uid'])->update(['super_days' => $days, 'growth_rate' => $growth_rate]);
}
} catch (\Exception $e) {
}
echo 'ok';
}
}

@ -16,6 +16,7 @@ namespace app\common\repositories\system\admin;
//附件
use app\common\dao\system\admin\PartnerDao;
use app\common\model\store\CityArea;
use app\common\model\system\admin\Partner;
use app\common\repositories\BaseRepository;
use app\common\model\user\UserPartner;
@ -76,7 +77,7 @@ class PartnerRepository extends BaseRepository
//生成角色
$info = $this->dao->create($data);
$userPartner = [];
for ($i = 1;$i <= $data['max_role_num']; $i++ ) {
for ($i = 1; $i <= $data['max_role_num']; $i++) {
$name = $i == 1 ? $data['name'] : $data['name'] . '_' . $i;
$userPartner[] = [
'partner_name' => $name,
@ -101,7 +102,46 @@ class PartnerRepository extends BaseRepository
*/
public function getDetail(int $id)
{
return $this->dao->get($id)->toArray();
try {
$data = $this->dao->get($id)->toArray();
$data['province_id'] = '';
$data['province_name'] = '';
$data['city_id'] = '';
$data['city_name'] = '';
$data['district_id'] = '';
$data['district_name'] = '';
if ($data['is_area'] == 1 && $data['area_id'] > 0) {
$area_data = CityArea::getDB()->where('id', $data['area_id'])->find()->toArray();
$ids = explode("/", $area_data['path']);
if ($area_data['level'] == 1) {
$data['province_id'] = (int)$data['area_id'];
$name_data = CityArea::getDB()->where('id', $data['province_id'])->find()->toArray();
$data['province_name'] = $name_data['name'];
} elseif ($area_data['level'] == 2) {
$data['province_id'] = (int)$ids[1];
$name_data = CityArea::getDB()->where('id', $data['province_id'])->find()->toArray();
$data['province_name'] = $name_data['name'];
$data['city_id'] = (int)$data['area_id'];
$name_data1 = CityArea::getDB()->where('id', $data['city_id'])->find()->toArray();
$data['city_name'] = $name_data1['name'];
} elseif ($area_data['level'] == 3) {
$data['province_id'] = (int)$ids[1];
$name_data = CityArea::getDB()->where('id', $data['province_id'])->find()->toArray();
$data['province_name'] = $name_data['name'];
$data['city_id'] = (int)$ids[2];
$name_data1 = CityArea::getDB()->where('id', $data['city_id'])->find()->toArray();
$data['city_name'] = $name_data1['name'];
$data['district_id'] = (int)$data['area_id'];
$name_data2 = CityArea::getDB()->where('id', $data['district_id'])->find()->toArray();
$data['district_name'] = $name_data2['name'];
}
}
return $data;
} catch (\Exception $e) {
print_r($e->getFile() . '-' . $e->getLine() . "-" . $e->getMessage());
}
}
/**
@ -118,10 +158,10 @@ class PartnerRepository extends BaseRepository
{
$old = $this->dao->get($id)->toArray();
if($old['name'] != $data['name']){
$list = UserPartner::getDB()->where('partner_id',$id)->select();
foreach($list as $k=>$v){
$name = str_replace($old['name'],$data['name'],$v['partner_name']);
if ($old['name'] != $data['name']) {
$list = UserPartner::getDB()->where('partner_id', $id)->select();
foreach ($list as $k => $v) {
$name = str_replace($old['name'], $data['name'], $v['partner_name']);
UserPartner::getDB()->where('id', $v['id'])->update(['partner_name' => $name]);
}
}
@ -144,7 +184,7 @@ class PartnerRepository extends BaseRepository
public function roleExists(int $id)
{
return UserPartner::getDB()->where('id', '=', $id)->where('uid','=','')->find();
return UserPartner::getDB()->where('id', '=', $id)->where('uid', '=', '')->find();
}

@ -73,17 +73,16 @@ class UserPartnerRepository extends BaseRepository
public function changePartnerForm($uid)
{
/** @var UserLabelRepository $make */
$list = $this->dao->getAll($uid)->column('partner_id') ?? [];
$list = UserPartner::getDB()->where('uid',$uid)->column('id') ?? [];
$data = ['partner_id' => $list, 'uid' => $uid];
$url = 'sys/user/partner/' . $uid;
$res = Elm::createForm($url, [
Elm::input('uid', '用户 ID', '')->disabled(true)->required(true),
Elm::selectMultiple('partner_id', '用户合作人角色')->options(function () {
$partnerForm = new PartnerDao();
$data = $partnerForm->getAll();
$data = UserPartner::getDB()->select()->toArray();
foreach ($data as $value => $label) {
$name = (string)$label['id'];
$value = $label['name'];
$value = $label['partner_name'];
$options[] = compact('value', 'name');
}
return $options;

@ -14,6 +14,7 @@
namespace app\controller\admin\system\admin;
use app\common\model\user\UserPartner;
use app\common\repositories\system\admin\PartnerRepository;
use crmeb\basic\BaseController;
use app\validate\admin\PartnerRoleValidate;
@ -49,10 +50,22 @@ class Partner extends BaseController
public function add(PartnerRoleValidate $validate)
{
$data = $this->request->params(['name', 'ratio', 'is_area', 'area_level',
'area_id', ['status', 1], ['type', 1], ['max_role_num', 1], 'brand_id', 'trade_id', 'region_id']);
'province_id', 'city_id', 'district_id', ['status', 1], ['type', 1], ['max_role_num', 1],
'brand_id', 'trade_id', 'region_id']);
$validate->check($data);
if ($data['is_area'] == 1 && $this->repository->fieldExists('area_id', $data['area_id'])) {
return app('json')->fail('该区域已经有了代理角色,请勿重复添加');
if ($data['is_area'] == 1) {
if (!empty($data['district_id'])) {
$data['area_id'] = $data['district_id'];
} elseif (!empty($data['city_id'])) {
$data['area_id'] = $data['city_id'];
} elseif (!empty($data['province_id'])) {
$data['area_id'] = $data['province_id'];
} else {
return app('json')->fail('请选择区域');
}
if ($this->repository->fieldExists('area_id', $data['area_id'])) {
return app('json')->fail('该区域已经有了代理角色,请勿重复添加');
}
}
if (
($data['type'] == 3 && empty($data['brand_id']))
@ -61,6 +74,9 @@ class Partner extends BaseController
) {
return app('json')->fail('请补全对应角色类型的关联数据');
}
unset($data['district_id']);
unset($data['province_id']);
unset($data['city_id']);
$this->repository->create($data);
return app('json')->success('添加成功');
}
@ -69,14 +85,22 @@ class Partner extends BaseController
{
$data = $this->request->params(['name', 'ratio', 'is_area', 'area_level',
'area_id', ['status', 1], ['type', 1], 'brand_id', 'trade_id', 'id', 'region_id']);
'province_id', 'city_id', 'district_id',
'area_id', ['status', 1], ['type', 1], 'brand_id', 'trade_id', 'id', 'region_id',
['max_role_num', 1]]);
$validate->check($data);
if ($data['is_area'] == 1) {
if (empty($data['area_id']) && empty($data['area_level'])) {
return app('json')->fail('请选择所属区域');
if (!empty($data['district_id'])) {
$data['area_id'] = $data['district_id'];
} elseif (!empty($data['city_id'])) {
$data['area_id'] = $data['city_id'];
} elseif (!empty($data['province_id'])) {
$data['area_id'] = $data['province_id'];
} else {
return app('json')->fail('请选择区域');
}
if ($this->repository->fieldExists('area_id', $data['area_id'], $data['id'])) {
if ($this->repository->fieldExists('area_id', $data['area_id'])) {
return app('json')->fail('该区域已经有了代理角色,请勿重复添加');
}
} else {
@ -90,7 +114,9 @@ class Partner extends BaseController
) {
return app('json')->fail('请补全对应角色类型的关联数据');
}
unset($data['district_id']);
unset($data['province_id']);
unset($data['city_id']);
$this->repository->update($data['id'], $data);
return app('json')->success('编辑成功');

@ -14,6 +14,8 @@
namespace app\controller\admin\user;
use app\common\model\system\admin\Partner;
use app\common\model\user\UserPartner;
use app\common\repositories\store\ExcelRepository;
use app\common\repositories\user\UserSpreadLogRepository;
use app\common\repositories\user\UserVisitRepository;
@ -616,13 +618,28 @@ class User extends BaseController
$id = (int)$this->request->param('uid', '');
if (!$this->repository->exists($id))
return app('json')->fail('数据不存在');
$is_cf = false;
foreach ($partner_id as $k => $value) {
$count = array_count_values($partner_id); // 统计每个元素的出现次数
if (isset($count[$value]) && $count[$value] > 1) {
$is_cf = true;
}
$partner_ids[$k] = (int)$value;
if (!$partnerRepository->exists((int)$value))
if (!$partnerRepository->exists((int)$value)) {
return app('json')->fail('所选合作人角色不存在');
}
$role_info = Partner::getDB()->where('id',$value)->find();
$role_count = UserPartner::getDB()->where('partner_id',$value)->count() ?? 0;
if($role_info->max_role_num <= $role_count){
return app('json')->fail('角色分配以到上限');
}
}
if($is_cf){
return app('json')->fail('请勿给用户设置重复的角色');
}
foreach ($user_role_id as $k => $value) {
$user_role_id[$k] = (int)$value;
$user_role_ids[$k] = (int)$value;
if (!$partnerRepository->roleExists((int)$value))
return app('json')->fail('该位置已分配,请重新选择');
}

@ -41,5 +41,7 @@ return [
'brand' => 'app\command\brand',
//社区贡献值结算
'dayValue' => 'app\command\dayValue',
//每日兑换率生成
'dayUserValue' => 'app\command\dayUserValue',
],
];

@ -28,6 +28,7 @@ use app\common\model\store\product\Spu;
use app\common\model\user\ValueContributionLog;
use app\common\model\store\order\StoreOrderContribute;
use app\common\repositories\user\UserAddressRepository;
use app\common\model\store\order\StoreOrderLevel;
class OrderPartnerJob implements JobInterface
{
@ -41,6 +42,7 @@ class OrderPartnerJob implements JobInterface
$bao_flowing = $mian_flowing = $ping_flowing = 0;
$brand_ids = $trade_ids = $user_log_data = [];
$admin_id = config('partner.gongxian_admin_id') ?? '';
//查询商品类型 -报单区 100% 免单区66.7% 平价区66.7%
$order_product = StoreOrderProduct::getDB()
->where('order_id', $data['order_id'])
@ -95,6 +97,7 @@ class OrderPartnerJob implements JobInterface
if ($has_contribute == false) {
throw new Exception('订单没有指定三种类型商品,不计入贡献值统计');
}
//读取品牌所属分类
if (!empty($brand_ids)) {
$brand_ids = array_unique($brand_ids);
@ -137,11 +140,27 @@ class OrderPartnerJob implements JobInterface
'ping_liushui' => $ping_flowing,
];
StoreOrderContribute::getDB()->insert($contribute_insert);
//读取消费等级增加生命值
$user_hb = 0;
$order_level = StoreOrderLevel::getDB()->order('level asc')->select();
if(!empty($order_level)){
foreach($order_level as $k=>$v){
if($total_price >= $v->min_price){
$user_hb = bcmul($total_price,$v->pay_hp,2);
break;
}
}
}
//订单角色贡献值-30%
$user_value = bcmul($total_price, 0.3, 2);
$user = User::getDB()->where('uid', $data['uid'])->find();
$user->all_value = bcadd($user->all_value, $user_value, 2);
//增加生命值
if(!empty($user_hb)){
$user->hp_value = bcadd($user->hp_value, $user_hb, 2);
}
$user->save();
$user_log_data[] = [
'type' => 6,
@ -374,4 +393,11 @@ class OrderPartnerJob implements JobInterface
{
// TODO: Implement failed() method.
}
//贡献值转增值积分
public function addValue($uid,$num,$user_start)
{
//读取用户当前贡献值增长率
}
}

Loading…
Cancel
Save