Commit 4664d311 authored by pengfei's avatar pengfei

update 团长分销活动

parent 5c8c000b
...@@ -14,6 +14,8 @@ class ColonelDistributorColonel extends MysqlBase ...@@ -14,6 +14,8 @@ class ColonelDistributorColonel extends MysqlBase
const TABLE_NAME = 'colonel_distributor_colonel'; const TABLE_NAME = 'colonel_distributor_colonel';
const CONFIG_INDEX = 'marketing'; const CONFIG_INDEX = 'marketing';
const PRIMARY_KEY = 'colonel_id'; const PRIMARY_KEY = 'colonel_id';
const COLONEL_SOURCE_APPLY = 1; //用户申请
const COLONEL_SOURCE_ADMIN = 2; //运营添加
public static function insertRecord(array $column) : int public static function insertRecord(array $column) : int
{ {
......
...@@ -49,4 +49,15 @@ class TakePlace extends MysqlBase ...@@ -49,4 +49,15 @@ class TakePlace extends MysqlBase
return $res; return $res;
} }
public static function getRecord(array $where, $column = '*')
{
return self::get($column, $where);
}
public static function existTakePlaceName(string $takePlaceName) : bool
{
$exist = self::getRecord(['take_place_name' => $takePlaceName], ['take_place_id']);
return !empty($exist);
}
} }
...@@ -10,6 +10,7 @@ namespace App\Services\marketing; ...@@ -10,6 +10,7 @@ namespace App\Services\marketing;
use App\Exception\custom\MarketingException; use App\Exception\custom\MarketingException;
use App\Models\marketing\mysql\ColonelDistributorColonel; use App\Models\marketing\mysql\ColonelDistributorColonel;
use App\Models\marketing\mysql\ColonelDistributorColonelApply; use App\Models\marketing\mysql\ColonelDistributorColonelApply;
use App\Models\marketing\mysql\TakePlace;
use App\Models\user\mysql\UserWechatBind; use App\Models\user\mysql\UserWechatBind;
use Exception; use Exception;
...@@ -30,6 +31,7 @@ class ColonelService ...@@ -30,6 +31,7 @@ class ColonelService
} }
$colonelData = [ $colonelData = [
'user_id' => $params['user_id'], 'user_id' => $params['user_id'],
'life_account_id' => MarketingService::getPublicLifeAccountId(),
'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'],
...@@ -86,13 +88,17 @@ class ColonelService ...@@ -86,13 +88,17 @@ class ColonelService
*/ */
public static function handleManageAudit(int $applyId, int $auditStatus): bool public static function handleManageAudit(int $applyId, int $auditStatus): bool
{ {
// 审核状态参数检测
if (!in_array($auditStatus, [ColonelDistributorColonelApply::STATUS_PASS,ColonelDistributorColonelApply::STATUS_REJECT])) { if (!in_array($auditStatus, [ColonelDistributorColonelApply::STATUS_PASS,ColonelDistributorColonelApply::STATUS_REJECT])) {
throw new MarketingException(MarketingException::COLONEL_AUDIT_STATUS); throw new MarketingException(MarketingException::COLONEL_AUDIT_STATUS);
} }
// 审核状态数据检测
$applyInfo = ColonelDistributorColonelApply::getRecord(['colonel_apply_id' => $applyId]); $applyInfo = ColonelDistributorColonelApply::getRecord(['colonel_apply_id' => $applyId]);
if (empty($applyInfo) || $applyInfo['audit_status'] != ColonelDistributorColonelApply::STATUS_AUDIT) { if (empty($applyInfo) || $applyInfo['audit_status'] != ColonelDistributorColonelApply::STATUS_AUDIT) {
throw new MarketingException(MarketingException::COLONEL_AUDIT_STATUS); throw new MarketingException(MarketingException::COLONEL_AUDIT_STATUS);
} }
// 为了兼容 TakePlaceService:add 方法
$applyInfo['name'] = $applyInfo['take_place_name'];
try { try {
ColonelDistributorColonelApply::beginTransaction(); ColonelDistributorColonelApply::beginTransaction();
// 修改申请状态 // 修改申请状态
...@@ -100,7 +106,7 @@ class ColonelService ...@@ -100,7 +106,7 @@ class ColonelService
if (empty($updateStatus)) { if (empty($updateStatus)) {
throw new MarketingException(MarketingException::COLONEL_AUDIT_STATUS_FAILED); throw new MarketingException(MarketingException::COLONEL_AUDIT_STATUS_FAILED);
} }
// 审核成功,入库团长表 // 审核成功
if ($auditStatus == ColonelDistributorColonelApply::STATUS_PASS) { if ($auditStatus == ColonelDistributorColonelApply::STATUS_PASS) {
if (!self::handleAuditSuccess((array)$applyInfo)) { if (!self::handleAuditSuccess((array)$applyInfo)) {
throw new MarketingException(MarketingException::COLONEL_AUDIT_STATUS_FAILED); throw new MarketingException(MarketingException::COLONEL_AUDIT_STATUS_FAILED);
...@@ -116,25 +122,32 @@ class ColonelService ...@@ -116,25 +122,32 @@ class ColonelService
/** /**
* Notes: 团长审核成功 * Notes: 团长审核成功
* User: pengfei@yidian-inc.com * User: pengfei@yidian-inc.com
* Date: 2021/8/23 1:52 下 * Date: 2021/8/24 11:24 上
* @param array $applyInfo * @param array $applyInfo
* @return int * @return int
* @throws MarketingException
*/ */
private static function handleAuditSuccess(array $applyInfo): int 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 = [ $colonelData = [
'user_id' => $applyInfo['user_id'], 'user_id' => $applyInfo['user_id'],
'colonel_apply_id' => $applyInfo['colonel_apply_id'],
'take_place_id' => $takePlaceId ?? '',
'life_account_id' => $applyInfo['life_account_id'],
'phone' => $applyInfo['phone'], 'phone' => $applyInfo['phone'],
'contact_name' => $applyInfo['contact_name'], 'contact_name' => $applyInfo['contact_name'],
'take_place_pic' => $applyInfo['take_place_pic'], 'colonel_distributor_code' => '', //TODO 生成活动码
'longitude' => $applyInfo['longitude'], 'colonel_source' => ColonelDistributorColonel::COLONEL_SOURCE_APPLY
'latitude' => $applyInfo['latitude'],
'location' => $applyInfo['location'],
'address' => $applyInfo['address'],
'province' => $applyInfo['province'],
'city' => $applyInfo['city'],
'area' => $applyInfo['area']
]; ];
return ColonelDistributorColonel::insertRecord($colonelData); return ColonelDistributorColonel::insertRecord($colonelData);
} }
......
...@@ -54,7 +54,8 @@ class TakePlaceService ...@@ -54,7 +54,8 @@ class TakePlaceService
public static function add($params) public static function add($params)
{ {
//验证life_account_id //验证life_account_id
if(isset($params['life_account_id'])) { $lifeAccountId = MarketingService::getPublicLifeAccountId();
if(isset($params['life_account_id']) && $params['life_account_id'] != $lifeAccountId) {
$url = config('interface', 'merchant.lifeaccount.get_life_account_by_id'); $url = config('interface', 'merchant.lifeaccount.get_life_account_by_id');
$lifeAccountRes = (new Request())->get($url, ["life_account_id" => $params["life_account_id"]]); $lifeAccountRes = (new Request())->get($url, ["life_account_id" => $params["life_account_id"]]);
...@@ -63,7 +64,6 @@ class TakePlaceService ...@@ -63,7 +64,6 @@ class TakePlaceService
} }
} }
$lifeAccountId = MarketingService::getPublicLifeAccountId();
$data['life_account_id'] = $params['life_account_id'] ?? $lifeAccountId; $data['life_account_id'] = $params['life_account_id'] ?? $lifeAccountId;
$data['take_place_name'] = $params['name']; $data['take_place_name'] = $params['name'];
$data['longitude'] = $params['longitude']; $data['longitude'] = $params['longitude'];
......
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