Commit 2343da81 authored by luhongguang's avatar luhongguang

Merge branch 'colonel' of https://git.yidian-inc.com:8021/bp/goods into colonel

parents ca7ecb66 fd2b3522
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
namespace App\Exception\custom; namespace App\Exception\custom;
use App\Exception\BaseException; use App\Exception\BaseException;
class MarketingException extends BaseException class MarketingException extends BaseException
...@@ -17,6 +16,8 @@ class MarketingException extends BaseException ...@@ -17,6 +16,8 @@ class MarketingException extends BaseException
const COLONEL_APPLY_FAILED = 24; const COLONEL_APPLY_FAILED = 24;
const COLONEL_CONFIG_NULL = 25; const COLONEL_CONFIG_NULL = 25;
const COLONEL_LEVEL_SIX = 26; const COLONEL_LEVEL_SIX = 26;
const COLONEL_AUDIT_STATUS = 27;
const COLONEL_AUDIT_STATUS_FAILED = 28;
protected $cus = [ protected $cus = [
0 => '活动名称不能为空', 0 => '活动名称不能为空',
...@@ -46,5 +47,7 @@ class MarketingException extends BaseException ...@@ -46,5 +47,7 @@ class MarketingException extends BaseException
self::COLONEL_APPLY_FAILED => '团长申请失败', self::COLONEL_APPLY_FAILED => '团长申请失败',
self::COLONEL_CONFIG_NULL => "团长分销配置内容不能为空", self::COLONEL_CONFIG_NULL => "团长分销配置内容不能为空",
self::COLONEL_LEVEL_SIX => "档位最多设定6档", self::COLONEL_LEVEL_SIX => "档位最多设定6档",
self::COLONEL_AUDIT_STATUS => '团长审核状态错误',
self::COLONEL_AUDIT_STATUS_FAILED => '团长审核失败'
]; ];
} }
\ No newline at end of file
...@@ -10,6 +10,7 @@ namespace Validate; ...@@ -10,6 +10,7 @@ namespace Validate;
class ColonelApplyValidate extends BaseValidate class ColonelApplyValidate extends BaseValidate
{ {
protected $rule = [ protected $rule = [
'user_id' => 'require',
'phone' => 'isMobile', 'phone' => 'isMobile',
'contact_name' => 'require', 'contact_name' => 'require',
]; ];
......
<?php
namespace Validate;
class ColonelAuditValidate extends BaseValidate
{
protected $rule = [
'colonel_apply_id' => 'require',
'audit_status' => 'require',
];
protected $message = [
"colonel_apply_id" => "申请id不能为空",
"audit_status" => "审核状态不能为空",
];
}
<?php
/**
* Created by PhpStorm.
* User: pengfei@yidian-inc.com
* Date: 2021/8/23 1:46 下午
*/
namespace App\Models\marketing\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
class PindanActivityColonel extends MysqlBase
{
const TABLE_NAME = 'pindan_activity_colonel';
const CONFIG_INDEX = 'marketing';
const PRIMARY_KEY = 'colonel_id';
public static function insertRecord(array $column) : int
{
$id = self::insert($column);
return intval($id);
}
}
...@@ -11,24 +11,51 @@ use Api\PhpUtils\Mysql\MysqlBase; ...@@ -11,24 +11,51 @@ use Api\PhpUtils\Mysql\MysqlBase;
class PindanActivityColonelApply extends MysqlBase class PindanActivityColonelApply extends MysqlBase
{ {
const TABLE_NAME = 'pindan_activity_colonel'; const TABLE_NAME = 'pindan_activity_colonel_apply';
const CONFIG_INDEX = 'marketing'; const CONFIG_INDEX = 'marketing';
const PRIMARY_KEY = 'colonel_apply_id'; const PRIMARY_KEY = 'colonel_apply_id';
public static function insertRecord(array $colums) : int const STATUS_AUDIT = 0;//待审核
const STATUS_PASS = 1;//审核通过
const STATUS_REJECT = 2;//审核驳回
const DEFAULT_COLUMN = ['colonel_apply_id','user_id','phone','contact_name','take_place_name','province','city','area','location'];
public static function insertRecord(array $column) : int
{ {
$id = self::insert($colums); $id = self::insert($column);
return intval($id); return intval($id);
} }
public static function getRecord(array $where, array $colums = ['*']) public static function getRecord(array $where, $column = '*')
{
return self::get($column, $where);
}
public static function getPages(array $where = [], $column = '*', int $page, int $pageSize, array $orderBy = ['colonel_apply_id' => 'DESC'])
{ {
return self::get($colums, $where); if (empty($column)) {
$column = self::DEFAULT_COLUMN;
}
$data = $where;
$count = self::count([], $where);
if (empty($count)) {
return ['list' => [],'count' => 0];
}
if (!empty($page) && !empty($pageSize)) {
$offset = ($page - 1) * $pageSize;
$data['LIMIT'] = [$offset,$pageSize];
}
if (!empty($orderBy)) {
$data['ORDER'] = $orderBy;
}
$result = self::select($column, $data);
return ['result' => $result,'count' => $count];
} }
public static function existPhone(string $phone) : bool public static function existUser(string $userId) : bool
{ {
$exists = self::getRecord(['phone' => $phone],['colonel_apply_id']); $exist = self::getRecord(['user_id' => $userId], ['colonel_apply_id']);
return !empty($exists) ? true : false; return !empty($exist);
} }
} }
\ No newline at end of file
...@@ -55,4 +55,32 @@ class ColonelController extends Base ...@@ -55,4 +55,32 @@ class ColonelController extends Base
$data = PindanActivityColonelConfigService::colonelConfig($params); $data = PindanActivityColonelConfigService::colonelConfig($params);
return $this->success(["result"=>$data]); return $this->success(["result"=>$data]);
} }
/**
* Notes: 管理后台 - 申请团长审核列表
* User: pengfei@yidian-inc.com
* Date: 2021/8/23 2:17 下午
* @throws Exception
*/
public function manage_listAction()
{
$params = $this->params;
$manageList = ColonelService::getManageList($params);
return $this->success($manageList);
}
/**
* Notes: 管理后台 - 申请团长审核
* User: pengfei@yidian-inc.com
* Date: 2021/8/23 2:16 下午
* @throws \App\Exception\custom\MarketingException
*/
public function manage_auditAction()
{
$params = $this->params;
(new ColonelAuditValidate())->validate();
ColonelService::handleManageAudit($params['colonel_apply_id'], $params['audit_status']);
return $this->success();
}
} }
\ No newline at end of file
...@@ -8,7 +8,9 @@ ...@@ -8,7 +8,9 @@
namespace App\Services\marketing; namespace App\Services\marketing;
use App\Exception\custom\MarketingException; use App\Exception\custom\MarketingException;
use App\Models\marketing\mysql\PindanActivityColonel;
use App\Models\marketing\mysql\PindanActivityColonelApply; use App\Models\marketing\mysql\PindanActivityColonelApply;
use App\Models\user\mysql\UserWechatBind;
use Exception; use Exception;
class ColonelService class ColonelService
...@@ -21,14 +23,13 @@ class ColonelService ...@@ -21,14 +23,13 @@ class ColonelService
* @return int $applyId * @return int $applyId
* @throws MarketingException * @throws MarketingException
*/ */
public static function apply(array $params) : int public static function apply(array $params): int
{ {
$params['phone'] = (string)$params['phone']; if (PindanActivityColonelApply::existUser($params['user_id'])) {
// TODO 判断用户是否已经成为团长按照 user_id 判断
if (PindanActivityColonelApply::existPhone($params['phone'])) {
throw new MarketingException(MarketingException::COLONEL_APPLY_EXIST); throw new MarketingException(MarketingException::COLONEL_APPLY_EXIST);
} }
$colonelData = [ $colonelData = [
'user_id' => $params['user_id'],
'phone' => $params['phone'], 'phone' => $params['phone'],
'contact_name' => $params['contact_name'], 'contact_name' => $params['contact_name'],
'take_place_name' => $params['take_place_name'], 'take_place_name' => $params['take_place_name'],
...@@ -50,4 +51,118 @@ class ColonelService ...@@ -50,4 +51,118 @@ class ColonelService
throw new MarketingException(MarketingException::COLONEL_APPLY_FAILED); throw new MarketingException(MarketingException::COLONEL_APPLY_FAILED);
} }
} }
}
\ No newline at end of file
/**
* Notes: 团长申请列表-后台管理
* User: pengfei@yidian-inc.com
* Date: 2021/8/20 8:15 下午
* @param array $params
* @return array
*/
public static function getManageList(array $params): array
{
$params = self::getPageParams($params);
$result = PindanActivityColonelApply::getPages([], PindanActivityColonelApply::DEFAULT_COLUMN, $params['page'], $params['page_size']);
if (empty($result['count'])) {
return $result;
}
$userMap = self::getUserMap(array_column($result['result'], 'user_id'));
foreach ($result['result'] as &$applyVal) {
$applyVal['user_avatar'] = !empty($userMap[$applyVal['user_id']]['user_avatar']) ? $userMap[$applyVal['user_id']]['user_avatar'] : '';
}
unset($applyVal);
return $result;
}
/**
* Notes: 团长申请审核
* User: pengfei@yidian-inc.com
* Date: 2021/8/23 1:54 下午
* @param int $applyId
* @param int $auditStatus
* @return bool
* @throws MarketingException
*/
public static function handleManageAudit(int $applyId, int $auditStatus): bool
{
if (!in_array($auditStatus, [PindanActivityColonelApply::STATUS_PASS,PindanActivityColonelApply::STATUS_REJECT])) {
throw new MarketingException(MarketingException::COLONEL_AUDIT_STATUS);
}
$applyInfo = PindanActivityColonelApply::getRecord(['colonel_apply_id' => $applyId]);
if (empty($applyInfo) || $applyInfo['audit_status'] != PindanActivityColonelApply::STATUS_AUDIT) {
throw new MarketingException(MarketingException::COLONEL_AUDIT_STATUS);
}
try {
PindanActivityColonelApply::beginTransaction();
// 修改申请状态
$updateStatus = PindanActivityColonelApply::update(['audit_status' => $auditStatus], ['colonel_apply_id' => $applyId,'audit_status' => PindanActivityColonelApply::STATUS_AUDIT]);
if (empty($updateStatus)) {
throw new MarketingException(MarketingException::COLONEL_AUDIT_STATUS_FAILED);
}
// 审核成功,入库团长表
if ($auditStatus == PindanActivityColonelApply::STATUS_PASS) {
if (!self::handleAuditSuccess((array)$applyInfo)) {
throw new MarketingException(MarketingException::COLONEL_AUDIT_STATUS_FAILED);
}
}
return PindanActivityColonelApply::commit();
} catch (MarketingException $e) {
PindanActivityColonelApply::rollback();
throw new MarketingException(MarketingException::COLONEL_AUDIT_STATUS_FAILED);
}
}
/**
* Notes: 团长审核成功
* User: pengfei@yidian-inc.com
* Date: 2021/8/23 1:52 下午
* @param array $applyInfo
* @return int
*/
private static function handleAuditSuccess(array $applyInfo): int
{
// 入库团长表
$colonelData = [
'user_id' => $applyInfo['user_id'],
'phone' => $applyInfo['phone'],
'contact_name' => $applyInfo['contact_name'],
'take_place_pic' => $applyInfo['take_place_pic'],
'longitude' => $applyInfo['longitude'],
'latitude' => $applyInfo['latitude'],
'location' => $applyInfo['location'],
'address' => $applyInfo['address'],
'province' => $applyInfo['province'],
'city' => $applyInfo['city'],
'area' => $applyInfo['area']
];
return PindanActivityColonel::insertRecord($colonelData);
}
/**
* Notes: 获取用户信息
* User: pengfei@yidian-inc.com
* Date: 2021/8/20 8:16 下午
* @param array $userIds
* @return array
*/
private static function getUserMap(array $userIds): array
{
$userWechatList = UserWechatBind::getRecords(['user_id' => $userIds], ['user_id','user_nick','user_avatar']);
return array_column((array)$userWechatList, null, 'user_id');
}
/**
* Notes: 获取默认页码
* User: pengfei@yidian-inc.com
* Date: 2021/8/20 8:16 下午
* @param array $params
* @return int[]
*/
private static function getPageParams(array $params = []): array
{
$params['page'] = !empty($params['page']) ? $params['page'] : 1;
$params['page_size'] = !empty($params['page_size']) ? $params['page_size'] : 20;
return $params;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment