Commit a65c7e76 authored by 卢洪光's avatar 卢洪光

Merge branch 'feature_take_place_20210916' into 'pre_release'

Feature take place 20210916

See merge request bp/goods!74
parents 687de4f3 c80630c7
...@@ -26,6 +26,8 @@ class MarketingException extends BaseException ...@@ -26,6 +26,8 @@ class MarketingException extends BaseException
const COLONEL_TAKE_PLACE_EDIT_FAILED = 36; const COLONEL_TAKE_PLACE_EDIT_FAILED = 36;
const COLONEL_APPLY_EXIST = 37; const COLONEL_APPLY_EXIST = 37;
const COLONEL_DATE_ERROR = 38; const COLONEL_DATE_ERROR = 38;
const BUSINESS_CIRCLE_IS_EXIST = 39;
const TAG_IS_EXIST = 40;
protected $cus = [ protected $cus = [
0 => '活动名称不能为空', 0 => '活动名称不能为空',
...@@ -67,5 +69,7 @@ class MarketingException extends BaseException ...@@ -67,5 +69,7 @@ class MarketingException extends BaseException
self::COLONEL_TAKE_PLACE_EDIT_FAILED => '修改团长自提点失败', self::COLONEL_TAKE_PLACE_EDIT_FAILED => '修改团长自提点失败',
self::COLONEL_APPLY_EXIST => '当前用户已提交团长申请', self::COLONEL_APPLY_EXIST => '当前用户已提交团长申请',
self::COLONEL_DATE_ERROR => '当前日期的配置不能修改', self::COLONEL_DATE_ERROR => '当前日期的配置不能修改',
self::BUSINESS_CIRCLE_IS_EXIST => '此商圈名已经存在',
self::TAG_IS_EXIST => '此分类标签已经存在',
]; ];
} }
<?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
<?php
namespace App\Models\marketing\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
class BusinessCircle extends MysqlBase
{
const TABLE_NAME = 'business_circle';
const CONFIG_INDEX = 'marketing';
const PRIMARY_KEY = 'business_circle_id';
const STATUS_IS_DEL_NO = 0;
const STATUS_IS_DEL_YES = 1;
public static function getRecord($where, $columns = [])
{
if (empty($columns)) {
$columns = '*';
}
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 = [])
{
if (empty($columns)) {
$columns = '*';
}
return self::selectMaster($columns, $where, []);
}
public static function save($data, $where = [])
{
if (empty($where)) {
return self::insert($data, []);
}
return self::update($data, $where);
}
public static function deleteRecord($where)
{
return self::delete($where);
}
}
<?php
namespace App\Models\marketing\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
class Tag extends MysqlBase
{
const TABLE_NAME = 'tag';
const CONFIG_INDEX = 'marketing';
const PRIMARY_KEY = 'tag_id';
const STATUS_IS_DEL_NO = 0;
const STATUS_IS_DEL_YES = 1;
public static function getRecord($where, $columns = [])
{
if (empty($columns)) {
$columns = '*';
}
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 = [])
{
if (empty($columns)) {
$columns = '*';
}
return self::selectMaster($columns, $where, []);
}
public static function save($data, $where = [])
{
if (empty($where)) {
return self::insert($data, []);
}
return self::update($data, $where);
}
public static function deleteRecord($where)
{
return self::delete($where);
}
}
...@@ -19,42 +19,6 @@ class TakePlace extends MysqlBase ...@@ -19,42 +19,6 @@ class TakePlace extends MysqlBase
const STATUS_NORMAL = 0; // 正常 const STATUS_NORMAL = 0; // 正常
const STATUS_DELETE = 1; // 删除 const STATUS_DELETE = 1; // 删除
/**
* 获取
* @param $params
* @return mixed
*/
public static function searchList($params)
{
$lifeAccountId = $params['life_account_id'] ?? MarketingService::getPublicLifeAccountId();
$keywords = $params['keywords'] ?? '';
$offset = $params['offset'] ?? 0;
$limit = $params['limit'] ?? 20;
$takePlaceIds = $params['take_place_id'] ?? [];
if(!empty($takePlaceIds)) {
$where['take_place_id'] = $takePlaceIds;
}
if($lifeAccountId) {
$where['life_account_id'] = $lifeAccountId;
}
if($keywords) {
$where['OR'] = [
'take_place_name[~]' => $keywords,
'contact_name[~]' => $keywords,
];
}
$where['is_delete'] = TakePlace::STATUS_NORMAL;
$where['ORDER'] = ['take_place_id' => 'DESC'];
$where['LIMIT'] = [$offset, $limit];
$res['list'] = self::select('*', $where);
unset($where['ORDER'],$where['LIMIT']);
$res['total'] = self::count('*', $where);
return $res;
}
public static function getRecord(array $where, $column = '*') public static function getRecord(array $where, $column = '*')
{ {
return self::get($column, $where); return self::get($column, $where);
...@@ -70,4 +34,12 @@ class TakePlace extends MysqlBase ...@@ -70,4 +34,12 @@ class TakePlace extends MysqlBase
$exist = self::getRecord(['take_place_name' => $takePlaceName], ['take_place_id']); $exist = self::getRecord(['take_place_name' => $takePlaceName], ['take_place_id']);
return !empty($exist); return !empty($exist);
} }
public static function save($data, $where = [])
{
if (empty($where)) {
return self::insert($data, []);
}
return self::update($data, $where);
}
} }
<?php
use App\Base\Base;
use \App\Services\marketing\BusinessCircleService;
use \Validate\BusinessCircleValidate;
class BusinesscircleController extends Base
{
/**
* 商圈数据列表
* @throws Exception
*/
public function listAction()
{
$params = $this->params;
$list = BusinessCircleService::getList($params);
$this->success(["result" => $list]);
}
/**
* 商圈详情
* @throws Exception
*/
public function detailAction()
{
(new BusinessCircleValidate())->scene("detail")->validate();
$params = $this->params;
$list = BusinessCircleService::businessCircleDetail($params);
$this->success(["result" => $list]);
}
/**
* 商圈编辑(包括add 和 update)
* @throws Exception
*/
public function editAction()
{
$params = $this->params;
$list = BusinessCircleService::businessCircleEdit($params);
$this->success(["result" => $list]);
}
/**
* 商圈删除(逻辑删除)
* @throws Exception
*/
public function deleteAction()
{
(new BusinessCircleValidate())->scene("delete")->validate();
$params = $this->params;
$list = BusinessCircleService::businessCircleDelete($params);
$this->success(["result" => $list]);
}
}
\ No newline at end of file
...@@ -12,7 +12,7 @@ use App\Services\goods\GoodsService; ...@@ -12,7 +12,7 @@ use App\Services\goods\GoodsService;
class MarketinggoodsController extends Base class MarketinggoodsController extends Base
{ {
const KS3_BASE_URL = 'ks3-cn-beijing.ksyun.com'; const KS3_BASE_URL = 'ks3-cn-beijing.ksyuncs.com';
/** /**
* 获取全部生效营销活动商品列表 * 获取全部生效营销活动商品列表
* *
......
<?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
/**
* BusinessCircle
* Class BusinessCircle
* @package App\Models\marketing\mysql
*/
namespace App\Services\marketing;
use App\Exception\custom\MarketingException;
use App\Models\marketing\mysql\BusinessCircle;
class BusinessCircleService
{
/**
* 商圈详情
* @param array $params
* @return \Api\PhpUtils\Mysql\MysqlBase
*/
public static function businessCircleDetail($params = [])
{
return BusinessCircle::getRecord(["business_circle_id" => $params["business_circle_id"]]);
}
/**
* 商圈编辑
* @param array $params
* @return \Api\PhpUtils\Mysql\MysqlBase
* @throws MarketingException
*/
public static function businessCircleEdit($params = [])
{
$businessCircleId = empty($params["business_circle_id"]) ? 0 : $params["business_circle_id"];
$data = [];
$data["business_circle_name"] = empty($params["business_circle_name"]) ? "" : $params["business_circle_name"];
$data["longitude"] = empty($params["longitude"]) ? "" : $params["longitude"];
$data["latitude"] = empty($params["latitude"]) ? "" : $params["latitude"];
$data["location"] = empty($params["location"]) ? "" : $params["location"];
$data["is_delete"] = empty($params["is_delete"]) ? BusinessCircle::STATUS_IS_DEL_NO : $params["is_delete"];
if (!empty($businessCircleId)) {
$businessCircle = BusinessCircle::getRecordMaster(["business_circle_name" => $data["business_circle_name"], "business_circle_id[!]" => $businessCircleId]);
if (!empty($businessCircle)) {
throw new MarketingException(['cus' => MarketingException::BUSINESS_CIRCLE_IS_EXIST]);
}
$result = BusinessCircle::save($data, ["business_circle_id" => $businessCircleId]);
} else {
$businessCircle = BusinessCircle::getRecordMaster(["business_circle_name" => $data["business_circle_name"]]);
if (!empty($businessCircle)) {
throw new MarketingException(['cus' => MarketingException::BUSINESS_CIRCLE_IS_EXIST]);
}
$result = BusinessCircle::save($data);
}
return $result;
}
/**
* 逻辑删除商圈
* @param array $params
* @return \Api\PhpUtils\Mysql\MysqlBase
*/
public static function businessCircleDelete($params = [])
{
$businessCircleId = $params["business_circle_id"];
$data = [];
$data["is_delete"] = empty($params["is_delete"]) ? 0 : $params["is_delete"];
return BusinessCircle::save($data, ["business_circle_id" => $businessCircleId]);
}
/**
* 商圈列表
* @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["business_circle_name"])) {
$where["business_circle_name[~]"] = $params["business_circle_name"];
}
$where['is_delete'] = BusinessCircle::STATUS_IS_DEL_NO;
$where['ORDER'] = ["business_circle_id" => "DESC"];
$where['LIMIT'] = [$page, $limit];
$list = BusinessCircle::getRecords($where);
unset($where['LIMIT']);
unset($where['ORDER']);
$count = BusinessCircle::count("*", $where);
return ['list' => $list, 'count' => $count];
}
}
\ 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;
use App\Models\marketing\mysql\TakePlace;
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"];
$deleteRes = Tag::save($data, ["tag_id" => $tagId]);
if (!empty($data["is_delete"])) {
$takePlaceIds = TakePlace::getRecords(["tag_id" => $tagId], ["take_place_id"]);
if (!empty($takePlaceIds)) {
$ids = array_column($takePlaceIds, "take_place_id");
TakePlace::save(["tag_id" => 0], ["take_place_id" => $ids]);
}
}
return $deleteRes;
}
/**
* 分类标签列表
* @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