Commit 0cec99db authored by luhongguang's avatar luhongguang

update: 处理冲突

parents cb8b641f b603b9b2
......@@ -19,6 +19,10 @@ class MarketingException extends BaseException
const COLONEL_AUDIT_STATUS = 27;
const COLONEL_AUDIT_STATUS_FAILED = 28;
const COMMIT_ERROR = 29;
const COLONEL_TAKE_PLACE_EXIST = 30;
const COLONEL_TAKE_PLACE_PARAMS = 31;
const COLONEL_TAKE_PLACE_FAILED = 32;
protected $cus = [
0 => '活动名称不能为空',
......@@ -51,5 +55,9 @@ class MarketingException extends BaseException
self::COLONEL_AUDIT_STATUS => '团长审核状态错误',
self::COLONEL_AUDIT_STATUS_FAILED => '团长审核失败',
self::COMMIT_ERROR => '事务commit失败',
self::COLONEL_TAKE_PLACE_EXIST => '自提点名称已存在',
self::COLONEL_TAKE_PLACE_PARAMS => '自提点信息不存在',
self::COLONEL_TAKE_PLACE_FAILED => '自提点添加失败',
];
}
<?php
/**
* Created by PhpStorm.
* User: pengfei@yidian-inc.com
* Date: 2021/8/24 1:32 下午
*/
namespace Validate;
class ColonelAddPoint extends BaseValidate
{
protected $rule = [
'colonel_apply_id' => 'require',
'longitude' => 'require',
'latitude' => 'require',
'location' => 'require',
'address' => 'require',
'province' => 'require',
'city' => 'require',
'area' => 'require',
'contact_name' => 'require',
'phone' => 'isMobile',
'take_place_name' => 'require',
];
protected $message = [
'colonel_apply_id' => '申请id不能为空',
'longitude' => '位置经度不能为空',
'latitude' => '位置纬度不能为空',
'location' => '自提点地址不能为空',
'address' => '详细地址不能为空',
'province' => '省份不能为空',
'city' => '城市不能为空',
'area' => '地区不能为空',
'contact_name' => '联系人不能为空',
'phone' => '请输入正确的手机号',
'take_place_name' => '自提点名称不能为空',
];
}
......@@ -16,8 +16,8 @@ class ColonelApplyValidate extends BaseValidate
];
protected $message = [
'user_id' => '用户id不能为空',
'phone' => '请输入正确的手机号',
'contact_name' => '联系人不能为空'
];
}
\ No newline at end of file
}
......@@ -17,9 +17,44 @@ class ColonelDistributorColonel extends MysqlBase
const COLONEL_SOURCE_APPLY = 1; //用户申请
const COLONEL_SOURCE_ADMIN = 2; //运营添加
const DEFAULT_COLUMN = ['colonel_id','user_id','take_place_id','phone','contact_name','colonel_distributor_code','colonel_source'];
public static function getRecord(array $where, $column = '*')
{
return self::get($column, $where);
}
public static function updateRecord(array $columns, array $where)
{
return self::update($columns, $where);
}
public static function insertRecord(array $column) : int
{
$id = self::insert($column);
return intval($id);
}
public static function getPages(array $where = [], $column = '*', int $page, int $pageSize, array $orderBy = ['colonel_apply_id' => 'DESC'])
{
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];
}
}
......@@ -10,6 +10,7 @@ use App\Services\marketing\ColonelService;
use \Validate\ColonelApplyValidate;
use \Validate\ColonelConfigValidate;
use \Validate\ColonelAuditValidate;
use \Validate\ColonelAddPoint;
use \App\Services\marketing\PindanActivityColonelConfigService;
use \App\Services\marketing\PindanActivityInviteOrderService;
......@@ -62,9 +63,20 @@ class ColonelController extends Base
* Notes: 管理后台 - 申请团长审核列表
* User: pengfei@yidian-inc.com
* Date: 2021/8/23 2:17 下午
* @throws Exception
*/
public function manage_listAction()
public function manage_colonel_apply_listAction()
{
$params = $this->params;
$manageList = ColonelService::getManageApplyList($params);
return $this->success($manageList);
}
/**
* Notes: 管理后台 - 团长审核列表
* User: pengfei@yidian-inc.com
* Date: 2021/8/24 3:09 下午
*/
public function manage_colonel_listAction()
{
$params = $this->params;
$manageList = ColonelService::getManageList($params);
......@@ -85,6 +97,32 @@ class ColonelController extends Base
return $this->success();
}
/**
* Notes: 管理后台 - 获取自提点信息
* User: pengfei@yidian-inc.com
* Date: 2021/8/24 2:43 下午
*/
public function manage_show_apply_pointAction()
{
$params = $this->params;
$colonelApply = ColonelService::getTakePlaceInfo($params['colonel_apply_id']);
return $this->success(['result' => $colonelApply]);
}
/**
* Notes: 管理后台 - 添加自提点信息
* User: pengfei@yidian-inc.com
* Date: 2021/8/24 2:44 下午
* @throws \App\Exception\custom\MarketingException
*/
public function manage_add_apply_pointAction()
{
$params = $this->params;
(new ColonelAddPoint())->validate();
ColonelService::handleAddTaskPlace($params);
return $this->success();
}
/**
* 团长分销下单处理统计数据逻辑
* @throws \App\Exception\custom\MarketingException
......@@ -117,4 +155,4 @@ class ColonelController extends Base
$data = PindanActivityColonelConfigService::getTaskData($params);
return $this->success(["result"=>$data]);
}
}
\ No newline at end of file
}
......@@ -62,7 +62,7 @@ class ColonelService
* @param array $params
* @return array
*/
public static function getManageList(array $params): array
public static function getManageApplyList(array $params): array
{
$params = self::getPageParams($params);
$result = ColonelDistributorColonelApply::getPages([], ColonelDistributorColonelApply::DEFAULT_COLUMN, $params['page'], $params['page_size']);
......@@ -77,6 +77,30 @@ class ColonelService
return $result;
}
/**
* Notes: 团长列表-后台管理
* User: pengfei@yidian-inc.com
* Date: 2021/8/24 3:04 下午
* @param array $params
* @return array
*/
public static function getManageList(array $params): array
{
$params = self::getPageParams($params);
$result = ColonelDistributorColonel::getPages([], ColonelDistributorColonel::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'] : '';
// TODO 昨日收益 总收益
}
unset($applyVal);
return $result;
}
/**
* Notes: 团长申请审核
* User: pengfei@yidian-inc.com
......@@ -97,8 +121,6 @@ class ColonelService
if (empty($applyInfo) || $applyInfo['audit_status'] != ColonelDistributorColonelApply::STATUS_AUDIT) {
throw new MarketingException(MarketingException::COLONEL_AUDIT_STATUS);
}
// 为了兼容 TakePlaceService:add 方法
$applyInfo['name'] = $applyInfo['take_place_name'];
try {
ColonelDistributorColonelApply::beginTransaction();
// 修改申请状态
......@@ -112,37 +134,89 @@ class ColonelService
throw new MarketingException(MarketingException::COLONEL_AUDIT_STATUS_FAILED);
}
}
return ColonelDistributorColonelApply::commit();
if (!ColonelDistributorColonelApply::commit()) {
throw new MarketingException(MarketingException::COLONEL_AUDIT_STATUS_FAILED);
}
return true;
} catch (MarketingException $e) {
ColonelDistributorColonelApply::rollback();
throw new MarketingException(MarketingException::COLONEL_AUDIT_STATUS_FAILED);
}
}
/**
* Notes: 获取自提点信息
* User: pengfei@yidian-inc.com
* Date: 2021/8/24 2:40 下午
* @param int $applyId
* @return array
*/
public static function getTakePlaceInfo(int $applyId): array
{
$where = [
'colonel_apply_id' => $applyId
];
$colonelApply = ColonelDistributorColonelApply::getRecord($where);
return (array)$colonelApply;
}
/**
* Notes: 添加自提点
* User: pengfei@yidian-inc.com
* Date: 2021/8/24 2:41 下午
* @param array $params
* @return int
* @throws MarketingException
*/
public static function handleAddTaskPlace(array $params): int
{
// 自提点名称检测
if (TakePlace::existTakePlaceName($params['take_place_name'])) {
throw new MarketingException(MarketingException::COLONEL_TAKE_PLACE_EXIST);
}
$where = [
'colonel_apply_id' => $params['colonel_apply_id']
];
// 自提点信息检测
if (!$colonelApply = ColonelDistributorColonelApply::getRecord($where)) {
throw new MarketingException(MarketingException::COLONEL_TAKE_PLACE_PARAMS);
}
$params['life_account_id'] = $colonelApply['life_account_id'];
$params['name'] = $params['take_place_name'];
try {
ColonelDistributorColonel::beginTransaction();
// 添加自提点
if (!$takePlaceId = TakePlaceService::add($params)) {
throw new MarketingException(MarketingException::COLONEL_TAKE_PLACE_FAILED);
}
// 修改自提点id
if (!ColonelDistributorColonel::updateRecord(['take_place_id' => $takePlaceId], $where)) {
throw new MarketingException(MarketingException::COLONEL_TAKE_PLACE_FAILED);
}
if (!ColonelDistributorColonel::commit()) {
throw new MarketingException(MarketingException::COLONEL_TAKE_PLACE_FAILED);
}
return (int)$takePlaceId;
} catch (MarketingException $e) {
ColonelDistributorColonel::rollback();
throw new MarketingException(MarketingException::COLONEL_TAKE_PLACE_FAILED);
}
}
/**
* Notes: 团长审核成功
* User: pengfei@yidian-inc.com
* Date: 2021/8/24 11:24 上午
* @param array $applyInfo
* @return int
* @throws MarketingException
*/
private static function handleAuditSuccess(array $applyInfo): int
{
// 入库自提点
if (!empty($applyInfo['take_place_name']) && !empty($applyInfo['longitude']) && !empty($applyInfo['location'])) {
// 自提点名称检测
if (!$takePlaceId = TakePlace::existTakePlaceName($applyInfo['take_place_name'])) {
if (!$takePlaceId = TakePlaceService::add($applyInfo)) {
return false;
}
}
}
// 入库团长表
$colonelData = [
'user_id' => $applyInfo['user_id'],
'colonel_apply_id' => $applyInfo['colonel_apply_id'],
'take_place_id' => $takePlaceId ?? '',
'take_place_id' => 0,
'life_account_id' => $applyInfo['life_account_id'],
'phone' => $applyInfo['phone'],
'contact_name' => $applyInfo['contact_name'],
......
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