185 lines
6.2 KiB
PHP
Executable File
185 lines
6.2 KiB
PHP
Executable File
<?php
|
|
|
|
|
|
namespace app\admin\logic\distribution;
|
|
|
|
|
|
use app\common\basics\Logic;
|
|
use app\common\enum\DistributionPartnerEnum;
|
|
use app\common\logic\DistributionLogic;
|
|
use app\common\model\distribution\Distribution;
|
|
use app\common\model\distribution\DistributionMemberApply;
|
|
use app\common\model\distribution\DistributionPartner;
|
|
use app\common\model\distribution\DistributionStoreType;
|
|
use app\common\model\user\User;
|
|
use app\common\server\AreaServer;
|
|
use app\common\server\UrlServer;
|
|
use think\facade\Db;
|
|
|
|
class ApplyLogic extends Logic
|
|
{
|
|
/**
|
|
* @Notes: 分销申请列表
|
|
* @Author: 张无忌
|
|
* @param $get
|
|
* @return array
|
|
*/
|
|
public static function lists($get)
|
|
{
|
|
try {
|
|
$where[] = ['DMA.status', '=', $get['type'] ?? 0];
|
|
if (!empty($get['keyword']) and $get['keyword']) {
|
|
switch ($get['keyword_type']) {
|
|
case 'sn':
|
|
$where[] = ['U.sn', 'like', '%'.$get['keyword'].'%'];
|
|
break;
|
|
case 'nickname':
|
|
$where[] = ['U.nickname', 'like', '%'.$get['keyword'].'%'];
|
|
break;
|
|
case 'mobile':
|
|
$where[] = ['U.mobile', '=', $get['keyword']];
|
|
break;
|
|
}
|
|
}
|
|
|
|
$model = new DistributionMemberApply();
|
|
$lists = $model->field(['DMA.*'])->alias('DMA')
|
|
->where($where)
|
|
->with(['user.level'])
|
|
->join('user U', 'U.id = DMA.user_id')
|
|
->paginate([
|
|
'page' => $get['page'],
|
|
'list_rows' => $get['limit'],
|
|
'var_page' => 'page'
|
|
])->toArray();
|
|
|
|
foreach ($lists['data'] as &$item) {
|
|
if ($item['user']) {
|
|
$item['user']['avatar'] = UrlServer::getFileUrl($item['user']['avatar']);
|
|
$first_leader = Db::name("user")
|
|
->where("id", $item['user']['first_leader'])
|
|
->where("disable",0)
|
|
->where("del",0)
|
|
->find();
|
|
if($first_leader != null){
|
|
$item['user']['first_leader_real_name'] = $first_leader['real_name'];
|
|
}else{
|
|
$item['user']['first_leader_real_name'] = "";
|
|
}
|
|
}
|
|
|
|
$item['region'] = AreaServer::getAddress([
|
|
$item['province'],
|
|
$item['city'],
|
|
$item['district']]
|
|
);
|
|
}
|
|
|
|
return ['count'=>$lists['total'], 'lists'=>$lists['data']];
|
|
} catch (\Exception $e) {
|
|
return ['error'=>$e->getMessage()];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @Notes: 分销申请详细
|
|
* @Author: 张无忌
|
|
* @param $id
|
|
* @return array
|
|
*/
|
|
public static function detail($id)
|
|
{
|
|
$model = new DistributionMemberApply();
|
|
$detail = $model->field(true)
|
|
->with(['user.level'])
|
|
->findOrEmpty($id)
|
|
->toArray();
|
|
|
|
$detail['status_text'] = DistributionMemberApply::getApplyStatus($detail['status']);
|
|
$detail['region'] = AreaServer::getAddress([
|
|
$detail['province'],
|
|
$detail['city'],
|
|
$detail['district']]
|
|
);
|
|
|
|
if ($detail['partner_id'] > 0) {
|
|
$partner = DistributionPartner::where([
|
|
'id' => $detail['partner_id'],
|
|
'is_delete' => 0
|
|
])->find();
|
|
$detail['partner'] = DistributionPartnerEnum::getPartner($partner['type']);
|
|
$detail['partner_money'] = $partner['un_core_city_money'];
|
|
if (strpos($partner['city'], $detail['own_city']) !== false) {
|
|
$detail['partner_money'] = $partner['core_city_money'];
|
|
}
|
|
|
|
if ($detail['store_id'] > 0) {
|
|
$detail['store'] = DistributionStoreType::where([
|
|
'id' => $detail['store_id'],
|
|
'is_delete' => 0
|
|
])->field('title, money')->find();
|
|
}
|
|
}
|
|
|
|
return $detail;
|
|
}
|
|
|
|
/**
|
|
* @Notes: 审核分销申请
|
|
* @Author: 张无忌
|
|
* @param $post
|
|
* @return bool
|
|
*/
|
|
public static function audit($post)
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
if ($post['audit_status'] == 1) {
|
|
// 审核通过
|
|
$model = new DistributionMemberApply();
|
|
$apply = $model->field(true)->findOrEmpty((int)$post['id'])->toArray();
|
|
|
|
DistributionMemberApply::update([
|
|
'status' => $post['audit_status'],
|
|
'denial_reason' => $post['denial_reason'] ?? '',
|
|
'update_time' => time()
|
|
], ['id'=>(int)$post['id']]);
|
|
|
|
$distribution = Distribution::where('user_id', $apply['user_id'])->findOrEmpty()->toArray();
|
|
if (empty($distribution)) {
|
|
// 生成分销基础信息表
|
|
DistributionLogic::add($apply['user_id']);
|
|
}
|
|
// 更新分销基础信息表
|
|
Distribution::where('user_id', $apply['user_id'])->update([
|
|
'is_distribution' => 1,
|
|
'distribution_time' => time()
|
|
]);
|
|
} else {
|
|
// 审核拒绝
|
|
DistributionMemberApply::update([
|
|
'status' => $post['audit_status'],
|
|
'denial_reason' => $post['denial_reason'] ?? '',
|
|
'update_time' => time()
|
|
], ['id'=>(int)$post['id']]);
|
|
}
|
|
|
|
Db::commit();
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
Db::rollback();
|
|
static::$error = $e->getMessage();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static function get_unaudited_data()
|
|
{
|
|
$model = new DistributionMemberApply();
|
|
return $model->field(['DMA.*'])->alias('DMA')
|
|
->where(['status' => 0])
|
|
->with(['user.level'])
|
|
->join('user U', 'U.id = DMA.user_id')
|
|
->count();
|
|
}
|
|
} |