Commit afd3967c authored by luhongguang's avatar luhongguang

update:增加拼单活动

parent 2ea3809a
...@@ -27,5 +27,6 @@ class MarketingException extends BaseException ...@@ -27,5 +27,6 @@ class MarketingException extends BaseException
13 => '商品在其他互动已勾选', 13 => '商品在其他互动已勾选',
14 => '开始时间不能大于等于结束时间', 14 => '开始时间不能大于等于结束时间',
15 => '分润比例不能大于50%', 15 => '分润比例不能大于50%',
16 => '当前填写的拼单活动名称已经存在',
]; ];
} }
\ No newline at end of file
<?php
namespace App\Models\goods\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
/**
* Class PindanGoodsSku
* 拼单商品sku信息表
* @package App\Models\goods\mysql
*/
class PindanGoodsSku extends MysqlBase
{
const TABLE_NAME = 'pindan_goods_sku';
const CONFIG_INDEX = 'goods';
const STATUS_AUDIT = 0;//待审核
const STATUS_PASS = 1;//审核通过
const STATUS_REJECT = 2;//审核驳回
const ONLINE_STATUS_NO_ONLINE = 0;//未上架
const ONLINE_STATUS_ONLINE = 1;//已上架
const ONLINE_STATUS_OFFLINE = 2;//已下架
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);
}
public static function getCount($where, $columns = "*")
{
return self::count($columns, $where);
}
}
\ No newline at end of file
...@@ -13,7 +13,7 @@ class Marketing extends MysqlBase ...@@ -13,7 +13,7 @@ class Marketing extends MysqlBase
const MARKETING_TYPE_FENXIAO = 1; const MARKETING_TYPE_FENXIAO = 1;
const MARKETING_TYPE_TUANGOU = 2; const MARKETING_TYPE_TUANGOU = 2;
const MARKETING_TYPE_MIAOSHA = 3; const MARKETING_TYPE_MIAOSHA = 3;
const MARKETING_TYPE_JIELONG = 4; const MARKETING_TYPE_PINDAN = 4;
public static function getRecord($where, $colums = []) public static function getRecord($where, $colums = [])
{ {
......
<?php
namespace App\Models\marketing\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
class MarketingPindan extends MysqlBase
{
const TABLE_NAME = 'marketing_pindan';
const CONFIG_INDEX = 'marketing';
const PRIMARY_KEY = 'marketing_pindan_id';
public static function getRecord($where, $colums = [])
{
if (empty($colums)) {
$colums = '*';
}
return self::get($colums, $where);
}
public static function getRecordMaster($where, $colums = [])
{
if (empty($colums)) {
$colums = '*';
}
return self::selectMaster($colums, $where);
}
public static function insertRecord($colums)
{
return self::insert($colums);
}
public static function updateRecord($colums, $where)
{
return self::update($colums, $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);
}
}
...@@ -8,7 +8,7 @@ use \Validate\MarketingGoodsRateValidate; ...@@ -8,7 +8,7 @@ use \Validate\MarketingGoodsRateValidate;
class MarketingController extends Base class MarketingController extends Base
{ {
public function get_marketing_listAction() public function get_marketing_listAction()
{ {
$params = $this->params; $params = $this->params;
...@@ -16,10 +16,10 @@ class MarketingController extends Base ...@@ -16,10 +16,10 @@ class MarketingController extends Base
$distributionList['result'] = $list; $distributionList['result'] = $list;
$this->success($distributionList); $this->success($distributionList);
} }
/** /**
* 营销列表 * 营销列表
* 后台管理 * 后台管理
*
*/ */
public function marketing_listAction() public function marketing_listAction()
{ {
...@@ -31,17 +31,16 @@ class MarketingController extends Base ...@@ -31,17 +31,16 @@ class MarketingController extends Base
/** /**
* 创建活动 * 创建活动
* 后台管理 * 后台管理
*
*/ */
public function add_marketingAction() public function add_marketingAction()
{ {
$params = $this->params; $params = $this->params;
$addMarketing = MarketingService::addMarketing($params); $addMarketing = MarketingService::addMarketing($params);
if (!empty($addMarketing)) { if (!empty($addMarketing)) {
$this->success(); $this->success();
} }
} }
/** /**
* op后台获取创建活动 * op后台获取创建活动
* 需要勾选的商品 * 需要勾选的商品
...@@ -57,7 +56,6 @@ class MarketingController extends Base ...@@ -57,7 +56,6 @@ class MarketingController extends Base
} }
/** /**
* 更新数据 * 更新数据
* 后台管理 * 后台管理
...@@ -70,9 +68,9 @@ class MarketingController extends Base ...@@ -70,9 +68,9 @@ class MarketingController extends Base
$where['marketing_id'] = !empty($params['marketing_id']) ? $params['marketing_id'] : ''; $where['marketing_id'] = !empty($params['marketing_id']) ? $params['marketing_id'] : '';
$param = []; $param = [];
if (empty($where['marketing_id'])) { if (empty($where['marketing_id'])) {
throw new MarketingException(['cus' => 6]); throw new MarketingException(['cus' => 6]);
} }
if (!empty($params['marketing_name'])) { if (!empty($params['marketing_name'])) {
$param['marketing_name'] = $params['marketing_name']; $param['marketing_name'] = $params['marketing_name'];
} }
...@@ -104,17 +102,17 @@ class MarketingController extends Base ...@@ -104,17 +102,17 @@ class MarketingController extends Base
if (!empty($params['end_time'])) { if (!empty($params['end_time'])) {
$param['end_time'] = $params['end_time']; $param['end_time'] = $params['end_time'];
} }
$srt = MarketingService::updateMarketing($param,$where); $srt = MarketingService::updateMarketing($param, $where);
if (!empty($srt)) { if (!empty($srt)) {
$this->success(); $this->success();
}else{ } else {
throw new MarketingException(['cus' => 7]); throw new MarketingException(['cus' => 7]);
} }
} }
/** /**
* 获取详情数据 * 获取详情数据
* 后台管理 * 后台管理
......
...@@ -3,14 +3,16 @@ ...@@ -3,14 +3,16 @@
namespace App\Services\marketing; namespace App\Services\marketing;
use App\Models\goods\mysql\PindanGoodsSku;
use App\Models\marketing\mysql\Marketing; use App\Models\marketing\mysql\Marketing;
use App\Models\marketing\mysql\MarketingGoods; use App\Models\marketing\mysql\MarketingGoods;
use App\Models\goods\mysql\GoodsSku; use App\Models\goods\mysql\GoodsSku;
use Api\PhpUtils\Validate\Validate;
use Api\PhpServices\Idgen\Idgen; use Api\PhpServices\Idgen\Idgen;
use App\Exception\custom\MarketingException; use App\Exception\custom\MarketingException;
use Api\PhpServices\Sensitive\Sensitive; use Api\PhpServices\Sensitive\Sensitive;
use App\Models\marketing\mysql\MarketingPindan;
use App\Services\common\CommonService; use App\Services\common\CommonService;
use Daemon\Goods;
class MarketingService class MarketingService
...@@ -188,8 +190,8 @@ class MarketingService ...@@ -188,8 +190,8 @@ class MarketingService
return []; return [];
} else if ($marketingType == Marketing::MARKETING_TYPE_MIAOSHA) { } else if ($marketingType == Marketing::MARKETING_TYPE_MIAOSHA) {
return []; return [];
} else if ($marketingType == Marketing::MARKETING_TYPE_JIELONG) { } else if ($marketingType == Marketing::MARKETING_TYPE_PINDAN) {
return self::addJielongMarketing($params); return self::addPindanMarketing($params);
} }
} }
...@@ -351,9 +353,94 @@ class MarketingService ...@@ -351,9 +353,94 @@ class MarketingService
} }
} }
private static function addJielongMarketing($params) /**
* 增加拼单活动
* @param $params
* @return \Api\PhpUtils\Mysql\MysqlBase
* @throws MarketingException
*/
private static function addPindanMarketing($params)
{ {
return []; $marketingName = !empty($params['marketing_name']) ? $params['marketing_name'] : '';
$pindanPic = !empty($params['pindan_pic']) ? $params['pindan_pic'] : '';
$pindanDesc = !empty($params['pindan_desc']) ? $params['pindan_desc'] : '';
$createUserEmail = !empty($params['op_cur_user']) ? $params['op_cur_user'] : '';
$startTime = !empty($params['start_time']) ? $params['start_time'] : '';
$endTime = !empty($params['end_time']) ? $params['end_time'] : '';
$type = Marketing::MARKETING_TYPE_PINDAN;
$goodsSkuId = !empty($params['goods_sku_id']) ? explode(",", $params['goods_sku_id']) : [];
$publishLifeAccountId = 111;
//重复判断
$marketing = Marketing::getRecord(["marketing_name" => $marketingName], ["marketing_id"]);
if (!empty($marketing)) {
$marketingPindan = MarketingPindan::getRecord(["marketing_id" => $marketing["marketing_id"]]);
if (!empty($marketingPindan) && $publishLifeAccountId == $marketingPindan["publish_life_account_id"]) {
throw new MarketingException(['cus' => 16]);
}
}
if (empty($goodsSkuId)) {
throw new MarketingException(['cus' => 12]);
}
//获取商品的最大最小值
$skuInfoList = PindanGoodsSku::getRecordMaster(["pindan_goods_sku_id" => $goodsSkuId]
, ["pindan_goods_sku_id", "goods_spu_id", "price"]);
$priceList = [];
foreach ($skuInfoList as $skuInfo) {
$priceList[] = $skuInfo["price"];
}
$uniquePriceList = array_unique($priceList);
sort($uniquePriceList);
$minPrice = $priceList[0];
$maxPrice = end($priceList);
Marketing::beginTransaction();
$marketingParams = [
'marketing_name' => $marketingName,
'start_time' => $startTime,
'end_time' => $endTime,
'online_status' => 1,
'marketing_type' => $type,
'update_user_email' => $createUserEmail,
'update_time' => date("Y-m-d H:i:s"),
'create_time' => date("Y-m-d H:i:s"),
];
$marketingId = Marketing::insertRecord($marketingParams);
if (empty($marketingId)) {
Marketing::rollback();
throw new MarketingException(['cus' => 5]);
}
$pindanParams = [
"marketing_id" => $marketingId,
"publish_life_account_id" => $publishLifeAccountId,
"pindan_pic" => $pindanPic,
"pindan_desc" => $pindanDesc,
"min_price" => $minPrice,
"max_price" => $maxPrice,
];
$pindanId = MarketingPindan::insertRecord($pindanParams);
if (empty($pindanId)) {
Marketing::rollback();
throw new MarketingException(['cus' => 5]);
}
$marketingGoods = [];
foreach ($skuInfoList as $key => $skuInfo) {
$marketingGoods[$key]["goods_spu_id"] = $skuInfo["goods_spu_id"];
$marketingGoods[$key]["goods_sku_id"] = $skuInfo["pindan_goods_sku_id"];
$marketingGoods[$key]["marketing_id"] = $marketingId;
}
MarketingGoods::save($marketingGoods);
if (!Marketing::commit()) {
Marketing::rollback();
throw new MarketingException(["cus" => 5]);
}
return $pindanId;
} }
/** /**
......
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