Commit a971875f authored by luhongguang's avatar luhongguang

update: 处理冲突

parents a8921578 d792760a
...@@ -22,26 +22,33 @@ class BaseException extends \Exception ...@@ -22,26 +22,33 @@ class BaseException extends \Exception
*/ */
public function __construct($params = []) public function __construct($params = [])
{ {
if (!is_array($params)) { if (empty($params)) {
return; return;
} }
if (!is_array($params)) {
return $this->setCusMsg($params);
}
$this->code = $params['code'] ?? Registry::get('config')->exception->user->code; $this->code = $params['code'] ?? Registry::get('config')->exception->user->code;
$this->msg = $params['msg'] ?? Registry::get('config')->exception->user->msg; $this->msg = $params['msg'] ?? Registry::get('config')->exception->user->msg;
if (isset($params['cus']) && $this->cus && isset($this->cus[intval($params['cus'])]) && $this->base_code) { if (isset($params['cus']) && $this->cus && isset($this->cus[intval($params['cus'])]) && $this->base_code) {
return $this->setCusMsg($params['cus']);
}
}
//每个服务都有自己的codePrefix public function setCusMsg($cus)
$appid = \Yaf\Application::app()->getConfig()->get("appid"); {
$codePrefix = \Yaconf::get('bizcode.prefix.' . $appid); //每个服务都有自己的codePrefix
$codePrefix = intval($codePrefix); $appid = \Yaf\Application::app()->getConfig()->get("appid");
$codePrefix = \Yaconf::get('bizcode.prefix.' . $appid);
$codePrefix = intval($codePrefix);
$cus_code = intval($params['cus']); $cus_code = intval($cus);
$base_code = intval($this->base_code); $base_code = intval($this->base_code);
$this->code = $codePrefix + $base_code + $cus_code; $this->code = $codePrefix + $base_code + $cus_code;
$this->msg = isset($params['data']) ? vsprintf($this->cus[$cus_code],$params['data']) : $this->cus[$cus_code]; $this->msg = isset($params['data']) ? vsprintf($this->cus[$cus_code],$params['data']) : $this->cus[$cus_code];
}
} }
public function __get($name): bool public function __get($name): bool
......
...@@ -13,6 +13,10 @@ class MarketingException extends BaseException ...@@ -13,6 +13,10 @@ class MarketingException extends BaseException
const LIFE_ACCOUNT_NO_EXIST = 16; const LIFE_ACCOUNT_NO_EXIST = 16;
const RELATION_ALREADY_EXIST = 17; const RELATION_ALREADY_EXIST = 17;
const TAKE_PLACE_NOT_EXIST = 20; const TAKE_PLACE_NOT_EXIST = 20;
const COLONEL_APPLY_EXIST = 23;
const COLONEL_APPLY_FAILED = 24;
const COLONEL_CONFIG_NULL = 25;
const COLONEL_LEVEL_SIX = 26;
protected $cus = [ protected $cus = [
0 => '活动名称不能为空', 0 => '活动名称不能为空',
...@@ -38,7 +42,9 @@ class MarketingException extends BaseException ...@@ -38,7 +42,9 @@ class MarketingException extends BaseException
self::TAKE_PLACE_NOT_EXIST => '自提点不存在', self::TAKE_PLACE_NOT_EXIST => '自提点不存在',
21 => "活动开始时间不能大于或者等于结束时间", 21 => "活动开始时间不能大于或者等于结束时间",
22 => "自提点不能为空", 22 => "自提点不能为空",
23 => "团长分销配置内容不能为空", self::COLONEL_APPLY_EXIST => '当前用户已提交团长申请',
24 => "档位最多设定6档", self::COLONEL_APPLY_FAILED => '团长申请失败',
self::COLONEL_CONFIG_NULL => "团长分销配置内容不能为空",
self::COLONEL_LEVEL_SIX => "档位最多设定6档",
]; ];
} }
\ No newline at end of file
...@@ -9,15 +9,26 @@ namespace App\Models\marketing\mysql; ...@@ -9,15 +9,26 @@ namespace App\Models\marketing\mysql;
use Api\PhpUtils\Mysql\MysqlBase; use Api\PhpUtils\Mysql\MysqlBase;
class PindanActivityColonelApply extends MysqlBase class PindanActivityColonel extends MysqlBase
{ {
const TABLE_NAME = 'pindan_activity_colonel_apply'; const TABLE_NAME = 'pindan_activity_colonel';
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) public static function insertRecord(array $colums) : int
{ {
return self::insert($colums); $id = self::insert($colums);
return intval($id);
} }
public static function getRecord(array $where, array $colums = ['*'])
{
return self::get($colums, $where);
}
public static function existPhone(string $phone) : bool
{
$exists = self::getRecord(['phone' => $phone],['colonel_apply_id']);
return !empty($exists) ? true : false;
}
} }
\ No newline at end of file
...@@ -8,20 +8,26 @@ ...@@ -8,20 +8,26 @@
namespace App\Services\marketing; namespace App\Services\marketing;
use App\Exception\custom\MarketingException; use App\Exception\custom\MarketingException;
use App\Models\marketing\mysql\PindanActivityColonelApply; use App\Models\marketing\mysql\PindanActivityColonel;
use Exception;
class ColonelService class ColonelService
{ {
/** /**
* Notes: 申请成为团长 * Notes: 申请成为团长
* User: pengfei@yidian-inc.com * User: pengfei@yidian-inc.com
* Date: 2021/8/20 3:38 下午 * Date: 2021/8/20 4:29 下午
* @param array $params * @param array $params
* @return \Api\PhpUtils\Mysql\MysqlBase * @return int $applyId
* @throws MarketingException * @throws MarketingException
*/ */
public static function apply(array $params) public static function apply(array $params) : int
{ {
$params['phone'] = (string)$params['phone'];
// TODO 判断用户是否已经成为团长按照 user_id 判断
if (PindanActivityColonel::existPhone($params['phone'])) {
throw new MarketingException(MarketingException::COLONEL_APPLY_EXIST);
}
$colonelData = [ $colonelData = [
'phone' => $params['phone'], 'phone' => $params['phone'],
'contact_name' => $params['contact_name'], 'contact_name' => $params['contact_name'],
...@@ -36,12 +42,12 @@ class ColonelService ...@@ -36,12 +42,12 @@ class ColonelService
'area' => $params['area'] ?? '', 'area' => $params['area'] ?? '',
]; ];
try { try {
if (!$applyId = PindanActivityColonelApply::insertRecord($colonelData)) { if (!$applyId = PindanActivityColonel::insertRecord($colonelData)) {
throw new MarketingException(['cus'=>5]); throw new MarketingException(MarketingException::COLONEL_APPLY_FAILED);
} }
return $applyId; return $applyId;
} catch (\MarketingException $e) { } catch (Exception $e) {
throw new MarketingException(['cus'=>5]); throw new MarketingException(MarketingException::COLONEL_APPLY_FAILED);
} }
} }
} }
\ No newline at end of file
...@@ -22,11 +22,11 @@ class PindanActivityColonelConfigService ...@@ -22,11 +22,11 @@ class PindanActivityColonelConfigService
$configList = json_decode($params["config"], true); $configList = json_decode($params["config"], true);
if (empty($configList)) { if (empty($configList)) {
throw new MarketingException(['cus' => 23]); throw new MarketingException(['cus' => MarketingException::COLONEL_CONFIG_NULL]);
} }
if (count($configList) > 6) { if (count($configList) > 6) {
throw new MarketingException(['cus' => 24]); throw new MarketingException(['cus' => MarketingException::COLONEL_LEVEL_SIX]);
} }
PindanActivityColonelConfig::beginTransaction(); PindanActivityColonelConfig::beginTransaction();
......
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