Commit 2a75bfae authored by luhongguang's avatar luhongguang

update: 分类标签逻辑接口

parent a1d611f4
...@@ -13,7 +13,8 @@ class MarketingException extends BaseException ...@@ -13,7 +13,8 @@ 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 BUSINESS_CIRCLE_IS_EXIST = 34; const BUSINESS_CIRCLE_IS_EXIST = 39;
const TAG_IS_EXIST = 40;
protected $cus = [ protected $cus = [
0 => '活动名称不能为空', 0 => '活动名称不能为空',
...@@ -41,5 +42,6 @@ class MarketingException extends BaseException ...@@ -41,5 +42,6 @@ class MarketingException extends BaseException
22 => "自提点不能为空", 22 => "自提点不能为空",
33 => '分润金额+手续费不能大于售价金额', 33 => '分润金额+手续费不能大于售价金额',
self::BUSINESS_CIRCLE_IS_EXIST => '此商圈名已经存在', self::BUSINESS_CIRCLE_IS_EXIST => '此商圈名已经存在',
self::TAG_IS_EXIST => '此分类标签已经存在',
]; ];
} }
\ No newline at end of file
<?php
namespace Validate;
/**
* Class Businesscircle
*
* @package Validate
*/
class BusinessCircleValidate extends BaseValidate
{
protected $rule = [
'business_circle_id' => 'require',
'business_circle_name' => 'require',
'longitude' => 'require',
'latitude' => 'require',
'location' => 'require',
];
protected $message = [
"business_circle_id" => "business_circle_id 不能为空",
'business_circle_name' => '商圈名称不能为空',
'longitude' => '经度不能为空',
'latitude' => '纬度不能为空',
'location' => '详细地址不能为空',
];
public function sceneDetail()
{
return $this->only(['business_circle_id'])->append("business_circle_id", "require");
}
public function sceneDelete()
{
return $this->only(['business_circle_id'])->append("business_circle_id", "require");
}
}
\ No newline at end of file
<?php
namespace Validate;
/**
* Class TagValidate
*
* @package Validate
*/
class TagValidate extends BaseValidate
{
protected $rule = [
'tag_id' => 'require',
'tag_name' => 'require',
];
protected $message = [
"tag_id" => "tag_id 不能为空",
"tag_name" => "tag_id 不能为空",
];
public function sceneDetail()
{
return $this->only(['tag_id'])->append("tag_id", "require");
}
public function sceneDelete()
{
return $this->only(['tag_id'])->append("tag_id", "require");
}
}
\ No newline at end of file
...@@ -10,6 +10,9 @@ class Tag extends MysqlBase ...@@ -10,6 +10,9 @@ class Tag extends MysqlBase
const CONFIG_INDEX = 'marketing'; const CONFIG_INDEX = 'marketing';
const PRIMARY_KEY = 'tag_id'; const PRIMARY_KEY = 'tag_id';
const STATUS_IS_DEL_NO = 0;
const STATUS_IS_DEL_YES = 1;
public static function getRecord($where, $columns = []) public static function getRecord($where, $columns = [])
{ {
if (empty($columns)) { if (empty($columns)) {
...@@ -18,6 +21,14 @@ class Tag extends MysqlBase ...@@ -18,6 +21,14 @@ class Tag extends MysqlBase
return self::get($columns, $where, []); return self::get($columns, $where, []);
} }
public static function getRecords($where, $columns = [])
{
if (empty($columns)) {
$columns = '*';
}
return self::select($columns, $where, []);
}
public static function getRecordMaster($where, $columns = []) public static function getRecordMaster($where, $columns = [])
{ {
if (empty($columns)) { if (empty($columns)) {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
use App\Base\Base; use App\Base\Base;
use \App\Services\marketing\BusinessCircleService; use \App\Services\marketing\BusinessCircleService;
use \Validate\MarketingInfoValidate; use \Validate\BusinessCircleValidate;
class BusinesscircleController extends Base class BusinesscircleController extends Base
{ {
...@@ -23,6 +23,8 @@ class BusinesscircleController extends Base ...@@ -23,6 +23,8 @@ class BusinesscircleController extends Base
*/ */
public function detailAction() public function detailAction()
{ {
(new BusinessCircleValidate())->scene("detail")->validate();
$params = $this->params; $params = $this->params;
$list = BusinessCircleService::businessCircleDetail($params); $list = BusinessCircleService::businessCircleDetail($params);
$this->success(["result" => $list]); $this->success(["result" => $list]);
...@@ -45,6 +47,8 @@ class BusinesscircleController extends Base ...@@ -45,6 +47,8 @@ class BusinesscircleController extends Base
*/ */
public function deleteAction() public function deleteAction()
{ {
(new BusinessCircleValidate())->scene("delete")->validate();
$params = $this->params; $params = $this->params;
$list = BusinessCircleService::businessCircleDelete($params); $list = BusinessCircleService::businessCircleDelete($params);
$this->success(["result" => $list]); $this->success(["result" => $list]);
......
<?php
use App\Base\Base;
use \App\Services\marketing\TagService;
use \Validate\TagValidate;
class TagController extends Base
{
/**
* 分类标签数据列表
* @throws Exception
*/
public function listAction()
{
$params = $this->params;
$list = TagService::getList($params);
$this->success(["result" => $list]);
}
/**
* 分类标签详情
* @throws Exception
*/
public function detailAction()
{
(new TagValidate())->scene("detail")->validate();
$params = $this->params;
$list = TagService::tagDetail($params);
$this->success(["result" => $list]);
}
/**
* 分类标签编辑(包括add 和 update)
* @throws Exception
*/
public function editAction()
{
$params = $this->params;
$list = TagService::tagEdit($params);
$this->success(["result" => $list]);
}
/**
* 分类标签删除(逻辑删除)
* @throws Exception
*/
public function deleteAction()
{
(new TagValidate())->scene("delete")->validate();
$params = $this->params;
$list = TagService::tagDelete($params);
$this->success(["result" => $list]);
}
}
\ No newline at end of file
<?php
/**
* Tag
* Class Tag
* @package App\Models\marketing\mysql
*/
namespace App\Services\marketing;
use App\Exception\custom\MarketingException;
use App\Models\marketing\mysql\Tag;
class TagService
{
/**
* 分类标签详情
* @param array $params
* @return \Api\PhpUtils\Mysql\MysqlBase
*/
public static function tagDetail($params = [])
{
return Tag::getRecord(["tag_id" => $params["tag_id"]]);
}
/**
* 分类标签编辑
* @param array $params
* @return \Api\PhpUtils\Mysql\MysqlBase
* @throws MarketingException
*/
public static function tagEdit($params = [])
{
$tagId = empty($params["tag_id"]) ? 0 : $params["tag_id"];
$data = [];
$data["tag_name"] = empty($params["tag_name"]) ? "" : $params["tag_name"];
$data["type"] = empty($params["type"]) ? 1 : $params["type"];
$data["is_delete"] = empty($params["is_delete"]) ? Tag::STATUS_IS_DEL_NO : $params["is_delete"];
if (!empty($tagId)) {
$tag = Tag::getRecordMaster(["tag_name" => $data["tag_name"], "tag_id[!]" => $tagId]);
if (!empty($tag)) {
throw new MarketingException(['cus' => MarketingException::TAG_IS_EXIST]);
}
$result = Tag::save($data, ["tag_id" => $tagId]);
} else {
$tag = Tag::getRecordMaster(["tag_name" => $data["tag_name"]]);
if (!empty($tag)) {
throw new MarketingException(['cus' => MarketingException::TAG_IS_EXIST]);
}
$result = Tag::save($data);
}
return $result;
}
/**
* 逻辑删除分类标签
* @param array $params
* @return \Api\PhpUtils\Mysql\MysqlBase
*/
public static function tagDelete($params = [])
{
$tagId = $params["tag_id"];
$data = [];
$data["is_delete"] = empty($params["is_delete"]) ? 0 : $params["is_delete"];
return Tag::save($data, ["tag_id" => $tagId]);
}
/**
* 分类标签列表
* @param array $params
* @return array
*/
public static function getList($params = [])
{
$params['page'] = !empty($params['page']) ? $params['page'] : 1;
$limit = !empty($params['page_size']) ? $params['page_size'] : 20;
$page = ($params['page'] - 1) * $limit;
$where = [];
if (!empty($params["tag_name"])) {
$where["tag_name[~]"] = $params["tag_name"];
}
$where['is_delete'] = Tag::STATUS_IS_DEL_NO;
$where['ORDER'] = ["tag_id" => "DESC"];
$where['LIMIT'] = [$page, $limit];
$list = Tag::getRecords($where);
unset($where['LIMIT']);
unset($where['ORDER']);
$count = Tag::count("*", $where);
return ['result' => $list, 'count' => $count];
}
}
\ No newline at end of file
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