Commit 8b2538ef authored by pengfei's avatar pengfei

merge colonel

parents e7807c6a bac35162
...@@ -21,8 +21,10 @@ class MarketingException extends BaseException ...@@ -21,8 +21,10 @@ class MarketingException extends BaseException
const COLONEL_TAKE_PLACE_EXIST = 30; const COLONEL_TAKE_PLACE_EXIST = 30;
const COLONEL_TAKE_PLACE_PARAMS = 31; const COLONEL_TAKE_PLACE_PARAMS = 31;
const COLONEL_TAKE_PLACE_FAILED = 32; const COLONEL_TAKE_PLACE_FAILED = 32;
const COLONEL_APPLY_EXIST = 33; const COLONEL_AUDIT_STATUS_USE = 34;
const COLONEL_ADD_FAILED = 35;
const COLONEL_TAKE_PLACE_EDIT_FAILED = 36;
const COLONEL_APPLY_EXIST = 37;
protected $cus = [ protected $cus = [
0 => '活动名称不能为空', 0 => '活动名称不能为空',
...@@ -49,7 +51,6 @@ class MarketingException extends BaseException ...@@ -49,7 +51,6 @@ class MarketingException extends BaseException
21 => "活动开始时间不能大于或者等于结束时间", 21 => "活动开始时间不能大于或者等于结束时间",
22 => "自提点不能为空", 22 => "自提点不能为空",
23 => '分润金额+手续费不能大于售价金额', 23 => '分润金额+手续费不能大于售价金额',
self::COLONEL_APPLY_EXIST => '当前用户已提交团长申请',
self::COLONEL_APPLY_FAILED => '团长申请失败', self::COLONEL_APPLY_FAILED => '团长申请失败',
self::COLONEL_CONFIG_NULL => "团长分销配置内容不能为空", self::COLONEL_CONFIG_NULL => "团长分销配置内容不能为空",
self::COLONEL_LEVEL_SIX => "档位最多设定6档", self::COLONEL_LEVEL_SIX => "档位最多设定6档",
...@@ -59,6 +60,10 @@ class MarketingException extends BaseException ...@@ -59,6 +60,10 @@ class MarketingException extends BaseException
self::COLONEL_TAKE_PLACE_EXIST => '自提点名称已存在', self::COLONEL_TAKE_PLACE_EXIST => '自提点名称已存在',
self::COLONEL_TAKE_PLACE_PARAMS => '自提点信息不存在', self::COLONEL_TAKE_PLACE_PARAMS => '自提点信息不存在',
self::COLONEL_TAKE_PLACE_FAILED => '自提点添加失败', self::COLONEL_TAKE_PLACE_FAILED => '自提点添加失败',
self::COLONEL_APPLY_EXIST => '当前用户已提交团长申请',
self::COLONEL_AUDIT_STATUS_USE => '该团长已审核',
self::COLONEL_ADD_FAILED => '团长入库失败',
self::COLONEL_TAKE_PLACE_EDIT_FAILED => '修改团长自提点失败',
33 => '分润金额+手续费不能大于售价金额', 33 => '分润金额+手续费不能大于售价金额',
]; ];
} }
...@@ -12,6 +12,9 @@ class ColonelDistributorPayInfo extends MysqlBase ...@@ -12,6 +12,9 @@ class ColonelDistributorPayInfo extends MysqlBase
const TYPE_NEW_USER = 1; const TYPE_NEW_USER = 1;
const TYPE_FINISH_TARGET = 2; const TYPE_FINISH_TARGET = 2;
const STATUS_NOT_USE = 0;
const STATUS_USE = 1;
public static $typeDesc = [ public static $typeDesc = [
self::TYPE_NEW_USER => "邀请新用户", self::TYPE_NEW_USER => "邀请新用户",
......
<?php
namespace App\Base;
use Yaf\Controller_Abstract;
class Job extends Controller_Abstract
{
public function init() {
\Yaf\Dispatcher::getInstance()->disableView();
}
}
\ No newline at end of file
...@@ -3,14 +3,13 @@ ...@@ -3,14 +3,13 @@
use Api\PhpServices\Idgen\Idgen; use Api\PhpServices\Idgen\Idgen;
use Api\PhpUtils\Log\FileLog; use Api\PhpUtils\Log\FileLog;
use App\Base\Cli; use App\Base\Cli;
use \App\Models\marketing\mysql\ColonelDistributorColonel; use App\Models\marketing\mysql\ColonelDistributorColonel;
use \App\Models\marketing\mysql\ColonelDistributorInviteOrder; use App\Models\marketing\mysql\ColonelDistributorConfig;
use \App\Models\marketing\mysql\ColonelDistributorConfig; use App\Models\marketing\mysql\ColonelDistributorInviteOrderNum;
use \App\Models\marketing\mysql\ColonelDistributorInviteOrderNum; use App\Models\marketing\mysql\ColonelDistributorPayInfo;
use \App\Models\marketing\mysql\ColonelDistributorPayInfo; use App\Exception\custom\InterfaceException;
use \App\Exception\custom\InterfaceException;
use Api\PhpUtils\Http\HttpUtil; use Api\PhpUtils\Http\HttpUtil;
use \App\Models\user\mysql\UserWechatBind; use App\Models\user\mysql\UserWechatBind;
/** /**
* php public/cli.php colonelorder index * php public/cli.php colonelorder index
...@@ -35,84 +34,6 @@ class ColonelorderController extends Cli ...@@ -35,84 +34,6 @@ class ColonelorderController extends Cli
} }
} }
public function indexBakAction()
{
$userIdList = $this->getColonelUserIds();
ColonelDistributorPayInfo::beginTransaction();
if (!empty($userIdList)) {
$userIdCount = count($userIdList);
//每次100个用户
$length = 1;
$start = (int)ceil($userIdCount / $length);
$insertData = [];
for ($i = 0; $i < $start;) {
$userIds = array_slice($userIdList, $i, $length);
$today = date("Y-m-d");
$yesterday = date("Y-m-d", strtotime("-1 day"));
$startTime = $yesterday . " 16:00:00";
$endTime = $today . " 10:00:00";
$colonelConfig = $this->getColonelConfig($yesterday);
if (!empty($colonelConfig["data"])) {
$configList = json_decode($colonelConfig["data"], true);
//完成目标单数
$inviteOrderNumList = $this->getInviteOrderNum($userIds, $yesterday, $today);
foreach ($inviteOrderNumList as $orderNum) {
foreach ($configList as $config) {
if (!empty($orderNum["num"]) && $orderNum["num"] >= $config["assess_order_num"]) {
$payInfo = [
"colonel_user_id" => $orderNum["colonel_user_id"],
"date" => $yesterday,
"type" => ColonelDistributorPayInfo::TYPE_FINISH_TARGET,
"reward" => $config["reward_amount"] * 100,
"finish_num" => $config["assess_order_num"],
"invite_user_id" => 0,
"invite_user_nick" => "",
];
$insertData[] = $payInfo;
}
}
}
//新用户奖励
$inviteNewUserList = $this->getInviteNewUserList($userIds, $today);
if (!empty($inviteNewUserList)) {
$colonelUserIds = array_column($inviteNewUserList, "user_id");
$userNickList = $this->getUserList($colonelUserIds);
foreach ($inviteNewUserList as $newUser) {
$payInfo = [
"colonel_user_id" => $newUser["inviter_user_id"],
"date" => $yesterday,
"type" => ColonelDistributorPayInfo::TYPE_NEW_USER,
"reward" => 5 * 100,
"finish_num" => 1,
"invite_user_id" => $newUser["user_id"],
"invite_user_nick" => empty($userNickList[$newUser["user_id"]]["user_nick"]) ? "" : $userNickList[$newUser["user_id"]]["user_nick"],
];
$insertData[] = $payInfo;
}
}
}
$i = $i + $length;
}
if (!empty($insertData)) {
$data = $this->addIdgenId($insertData);
$res = $this->addColonelDistributorPayInfo($data);
if ($res === false) {
ColonelDistributorPayInfo::rollback();
FileLog::info("add_colonel_distributor_pay_info", sprintf("写入错误参数 %s", json_encode($data)));
}
}
}
if (!ColonelDistributorPayInfo::commit()) {
ColonelDistributorPayInfo::rollback();
}
}
public function indexAction() public function indexAction()
{ {
$userIdList = $this->getColonelUserIds(); $userIdList = $this->getColonelUserIds();
...@@ -127,8 +48,18 @@ class ColonelorderController extends Cli ...@@ -127,8 +48,18 @@ class ColonelorderController extends Cli
$batchPayInfoData[] = $this->getInviteOrderData($userIds); $batchPayInfoData[] = $this->getInviteOrderData($userIds);
// 邀请新用户奖励 // 邀请新用户奖励
$batchPayInfoData[] = $this->getInviteNewUserData($userIds); $batchPayInfoData[] = $this->getInviteNewUserData($userIds);
$colonelPayInfoData = array_merge($colonelPayInfoData,$batchPayInfoData); $colonelPayInfoData = array_merge($colonelPayInfoData, $batchPayInfoData);
} }
return $this->handleSavePayInfo($colonelPayInfoData);
}
/**
* 保存奖励信息
* @param $yesterday
* @return true
*/
public function handleSavePayInfo($colonelPayInfoData)
{
if (!empty($colonelPayInfoData)) { if (!empty($colonelPayInfoData)) {
$data = $this->addIdgenId($colonelPayInfoData); $data = $this->addIdgenId($colonelPayInfoData);
try { try {
...@@ -141,7 +72,7 @@ class ColonelorderController extends Cli ...@@ -141,7 +72,7 @@ class ColonelorderController extends Cli
} }
} catch (\Exception $e) { } catch (\Exception $e) {
ColonelDistributorPayInfo::rollback(); ColonelDistributorPayInfo::rollback();
FileLog::info("add_colonel_distributor_pay_info", $e->getMessage()); FileLog::info("add_colonel_distributor_pay_info", $e->getMessage());
} }
} }
return true; return true;
...@@ -236,17 +167,6 @@ class ColonelorderController extends Cli ...@@ -236,17 +167,6 @@ class ColonelorderController extends Cli
return $userIds; return $userIds;
} }
public function getInviteOrder($colonelUserIds, $startTime, $endTime)
{
return ColonelDistributorInviteOrder::select(["colonel_user_id", "user_id", "is_refund", "create_time"],
[
"colonel_user_id" => $colonelUserIds,
"create_time[>=]" => $startTime,
"create_time[<=]" => $endTime,
"is_refund" => 0,
], []);
}
/** /**
* 获取order num * 获取order num
* @param $colonelUserIds * @param $colonelUserIds
...@@ -256,12 +176,15 @@ class ColonelorderController extends Cli ...@@ -256,12 +176,15 @@ class ColonelorderController extends Cli
*/ */
public function getInviteOrderNum($colonelUserIds, $startTime, $endTime) public function getInviteOrderNum($colonelUserIds, $startTime, $endTime)
{ {
return ColonelDistributorInviteOrderNum::select(["colonel_user_id", "num", "date"], return ColonelDistributorInviteOrderNum::select(
["colonel_user_id", "num", "date"],
[ [
"colonel_user_id" => $colonelUserIds, "colonel_user_id" => $colonelUserIds,
"date[>=]" => $startTime, "date[>=]" => $startTime,
"date[<=]" => $endTime, "date[<=]" => $endTime,
], []); ],
[]
);
} }
/** /**
...@@ -329,5 +252,4 @@ class ColonelorderController extends Cli ...@@ -329,5 +252,4 @@ class ColonelorderController extends Cli
{ {
return ColonelDistributorPayInfo::save($data); return ColonelDistributorPayInfo::save($data);
} }
}
}
\ No newline at end of file
<?php <?php
use Api\PhpServices\Idgen\Idgen;
use Api\PhpUtils\Log\FileLog; use Api\PhpUtils\Log\FileLog;
use App\Base\Cli; use App\Base\Cli;
use \App\Models\marketing\mysql\ColonelDistributorColonel; use App\Models\marketing\mysql\ColonelDistributorPayInfo;
use \App\Models\marketing\mysql\ColonelDistributorInviteOrder; use App\Exception\custom\InterfaceException;
use \App\Models\marketing\mysql\ColonelDistributorConfig;
use \App\Models\marketing\mysql\ColonelDistributorInviteOrderNum;
use \App\Models\marketing\mysql\ColonelDistributorPayInfo;
use \App\Exception\custom\InterfaceException;
use Api\PhpUtils\Http\HttpUtil; use Api\PhpUtils\Http\HttpUtil;
use \App\Models\user\mysql\UserWechatBind;
/** /**
* php public/cli.php colonelwallet index * php public/cli.php colonelwallet index
...@@ -19,18 +13,15 @@ class ColonelwalletController extends Cli ...@@ -19,18 +13,15 @@ class ColonelwalletController extends Cli
{ {
public function indexAction() public function indexAction()
{ {
// $today = date("Y-m-d");
$yesterday = date("Y-m-d", strtotime("-1 day")); $yesterday = date("Y-m-d", strtotime("-1 day"));
$payInfoList = $this->getPayInfo($yesterday); $payInfoList = $this->getPayInfo($yesterday);
if (!empty($payInfoList)) { if (!empty($payInfoList)) {
$res = $this->toWallet($payInfoList); if ($this->toWallet($payInfoList)) {
if ($res) { if ($this->deductingInventory($payInfoList)) {
$this->deductingInventory($payInfoList); $this->handlePayInfoStatus(array_column($payInfoList, 'colonel_distributor_pay_info_id'));
}
} }
} }
} }
/** /**
...@@ -40,7 +31,7 @@ class ColonelwalletController extends Cli ...@@ -40,7 +31,7 @@ class ColonelwalletController extends Cli
*/ */
public function getPayInfo($date) public function getPayInfo($date)
{ {
$list = ColonelDistributorPayInfo::select("*", ["date" => $date], []); $list = ColonelDistributorPayInfo::select("*", ["date" => $date,'status' => ColonelDistributorPayInfo::STATUS_NOT_USE], []);
$data = []; $data = [];
if (!empty($list)) { if (!empty($list)) {
foreach ($list as $item) { foreach ($list as $item) {
...@@ -106,13 +97,22 @@ class ColonelwalletController extends Cli ...@@ -106,13 +97,22 @@ class ColonelwalletController extends Cli
$data["capital_pool_id"] = 2; $data["capital_pool_id"] = 2;
foreach ($payInfoList as $payInfo) { foreach ($payInfoList as $payInfo) {
if ($payInfo["type"] == ColonelDistributorPayInfo::TYPE_NEW_USER) {
$desc = "邀请新用户(".$payInfo["invite_user_nick"].")完成下单奖励";
}
if ($payInfo["type"] == ColonelDistributorPayInfo::TYPE_FINISH_TARGET) {
$desc = "完成".$payInfo["finish_num"]."单用户下单奖励";
}
$tmp = []; $tmp = [];
$tmp["op"] = 200; //200:团长奖励 $tmp["op"] = 200; //200:团长奖励
$tmp["user_id"] = $payInfo["colonel_user_id"]; $tmp["user_id"] = $payInfo["colonel_user_id"];
$tmp["amount"] = $payInfo["reward"]; $tmp["amount"] = $payInfo["reward"];
$tmp["third_order_id"] = $payInfo["colonel_distributor_pay_info_id"];
$tmp["third_order_id_type"] = $payInfo["type"];
$tmp["third_order_desc"] = $desc;
$data["body"][] = $tmp; $data["body"][] = $tmp;
} }
$res = HttpUtil::post($url, $data); $res = HttpUtil::post($url, $data, 100000, 3);
if ($res['code'] == 0 && isset($res['response']["result"])) { if ($res['code'] == 0 && isset($res['response']["result"])) {
$date = date("Y-m-d H:i:s"); $date = date("Y-m-d H:i:s");
FileLog::info("colonel_distributor_deducting_inventory", $date." 资金池授予用户奖励成功"); FileLog::info("colonel_distributor_deducting_inventory", $date." 资金池授予用户奖励成功");
...@@ -123,4 +123,12 @@ class ColonelwalletController extends Cli ...@@ -123,4 +123,12 @@ class ColonelwalletController extends Cli
return false; return false;
} }
} }
}
\ No newline at end of file /**
* 修改状态
*/
public function handlePayInfoStatus(array $payInfoIds)
{
return ColonelDistributorPayInfo::updateRecord(['status' => ColonelDistributorPayInfo::STATUS_USE], ['id' => $payInfoIds]);
}
}
<?php
use Api\PhpUtils\Http\Request;
use App\Base\Job;
use App\Exception\custom\InterfaceException;
use App\Models\goods\mysql\Category;
use \App\Models\goods\mysql\GoodsSku;
use \App\Services\goods\GoodsService;
use \App\Services\goods\ElasticGoodService;
use Api\PhpUtils\Log\DaemonLog;
use Api\PhpServices\JwUser\JwUser;
use App\Services\shop\ShopService;
/**
* 同步商品数据到es
* php public/cli.php goodstoes index
* Class GoodsToEsController
*/
class GoodstoesController extends Job
{
public function indexAction()
{
$this->initEsIndex();
$goodsSkuIds = $this->getGoodsSkuIdList();
$this->toEs($goodsSkuIds);
}
private function getGoodsSkuIdList()
{
return GoodsSku::select("goods_sku_id", ['LIMIT' => 10]);
}
private function toEs($goodsSkuIds)
{
if (!empty($goodsSkuIds)) {
foreach ($goodsSkuIds as $goodsSkuId) {
echo "当前正在同步的商品sku_id: $goodsSkuId \n";
$this->updateGoodsInfoToEs($goodsSkuId);
}
}
}
private function initEsIndex()
{
//删除原index
ElasticGoodService::deleteIndex();
//创建空index
ElasticGoodService::createIndex();
}
/**
* 写入到es
* @param $goodsSkuId
* @return array|callable
* @throws InterfaceException
*/
public function updateGoodsInfoToEs($goodsSkuId)
{
$goodsSkuInfoList = GoodsSku::getRecordMaster(["goods_sku_id" => $goodsSkuId]);
if (!empty($goodsSkuInfoList)) {
$goodsSkuInfo = $goodsSkuInfoList[0];
$nameList = Category::select("name", ["category_id" => [$goodsSkuInfo["category_1_id"], $goodsSkuInfo["category_2_id"]]]);
//生活号信息
$url = config('interface', 'merchant.lifeaccount.get_life_account_by_id');
if (empty($url)) {
throw new InterfaceException(['cus' => 0]);
}
$lifeAccountRes = (new Request())->get($url, ["life_account_id" => $goodsSkuInfo["life_account_id"]]);
//门店信息
$subShopList = ShopService::getRelationShop($goodsSkuId);
$latitude = empty($subShopList[0]["latitude"]) ? "" : $subShopList[0]["latitude"];
$longitude = empty($subShopList[0]["longitude"]) ? "" : $subShopList[0]["longitude"];
if (!empty($longitude) && !empty($latitude) && !empty($subShopList)) {
foreach ($subShopList as $subShop) {
$esId = $goodsSkuId."_".$subShop["sub_shop_id"];
$data = [
"goods_sku_id" => $goodsSkuInfo["goods_sku_id"],
"goods_desc_pic_url" => $goodsSkuInfo["desc_pic_url"],
"goods_name" => $goodsSkuInfo["goods_name"],
"inventory_rest" => $goodsSkuInfo["inventory_rest"],
"total_amount_sold" => $goodsSkuInfo["total_amount_sold"],
"original_price" => empty($goodsSkuInfo["original_price"]) ? "" : (string)($goodsSkuInfo["original_price"] / 100),
"price" => $goodsSkuInfo["price"] / 100,
"price_sort" => (int)$goodsSkuInfo["price"],
"audit_status" => $goodsSkuInfo["audit_status"],
"online_status" => $goodsSkuInfo["online_status"],
"desc" => $goodsSkuInfo["desc"],
"category_1_id" => $goodsSkuInfo["category_1_id"],
"category_2_id" => $goodsSkuInfo["category_2_id"],
"category_1_name" => $nameList[0],
"category_2_name" => $nameList[1],
"life_account_id" => $goodsSkuInfo["life_account_id"],
"life_account_name" => empty($lifeAccountRes["response"]["result"]["life_account_name"]) ? "" : $lifeAccountRes["response"]["result"]["life_account_name"],
"life_account_icon" => empty($lifeAccountRes["response"]["result"]["life_account_icon"]) ? "" : $lifeAccountRes["response"]["result"]["life_account_icon"],
"shop_name" => $subShop["shop_name"],
"shop_address" => $subShop["address"],
"shop_location" => $latitude.",".$longitude,
"update_time" => strtotime($goodsSkuInfo["update_time"]),
];
return ElasticGoodService::indexDoc($esId, $data);
}
}
}
}
}
\ No newline at end of file
...@@ -897,7 +897,7 @@ class GoodsService ...@@ -897,7 +897,7 @@ class GoodsService
if ($marketing["commission_mode"] == Marketing::COMMISSION_MODE_RATE) { if ($marketing["commission_mode"] == Marketing::COMMISSION_MODE_RATE) {
$commissionTotal = ($marketing["first_commission_value"] + $marketing["second_commission_value"]) / 10000 * $price; $commissionTotal = ($marketing["first_commission_value"] + $marketing["second_commission_value"]) / 10000 * $price;
if ($price < ($commissionTotal+$chargeFee)) { if ($price < ($commissionTotal+$chargeFee)) {
throw new MarketingException(['cus'=>23]); throw new MarketingException(['cus'=>33]);
} }
} }
...@@ -905,7 +905,7 @@ class GoodsService ...@@ -905,7 +905,7 @@ class GoodsService
if ($marketing["commission_mode"] == Marketing::COMMISSION_MODE_FIXED) { if ($marketing["commission_mode"] == Marketing::COMMISSION_MODE_FIXED) {
$commissionTotal = ($marketing["first_commission_value"] + $marketing["second_commission_value"]); $commissionTotal = ($marketing["first_commission_value"] + $marketing["second_commission_value"]);
if ($price < ($commissionTotal+$chargeFee)) { if ($price < ($commissionTotal+$chargeFee)) {
throw new MarketingException(['cus'=>23]); throw new MarketingException(['cus'=>33]);
} }
} }
} }
......
...@@ -150,7 +150,7 @@ class ColonelService ...@@ -150,7 +150,7 @@ class ColonelService
// 审核状态数据检测 // 审核状态数据检测
$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_USE);
} }
try { try {
ColonelDistributorColonelApply::beginTransaction(); ColonelDistributorColonelApply::beginTransaction();
...@@ -162,16 +162,16 @@ class ColonelService ...@@ -162,16 +162,16 @@ class ColonelService
// 审核成功 // 审核成功
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_ADD_FAILED);
} }
} }
if (!ColonelDistributorColonelApply::commit()) { if (!ColonelDistributorColonelApply::commit()) {
throw new MarketingException(MarketingException::COLONEL_AUDIT_STATUS_FAILED); throw new MarketingException(MarketingException::COMMIT_ERROR);
} }
return true; return true;
} catch (MarketingException $e) { } catch (MarketingException $e) {
ColonelDistributorColonelApply::rollback(); ColonelDistributorColonelApply::rollback();
throw new MarketingException(MarketingException::COLONEL_AUDIT_STATUS_FAILED); throw new MarketingException($e->getCode());
} }
} }
...@@ -222,15 +222,15 @@ class ColonelService ...@@ -222,15 +222,15 @@ class ColonelService
} }
// 修改自提点id // 修改自提点id
if (!ColonelDistributorColonel::updateRecord(['take_place_id' => $takePlaceId], $where)) { if (!ColonelDistributorColonel::updateRecord(['take_place_id' => $takePlaceId], $where)) {
throw new MarketingException(MarketingException::COLONEL_TAKE_PLACE_FAILED); throw new MarketingException(MarketingException::COLONEL_TAKE_PLACE_EDIT_FAILED);
} }
if (!ColonelDistributorColonel::commit()) { if (!ColonelDistributorColonel::commit()) {
throw new MarketingException(MarketingException::COLONEL_TAKE_PLACE_FAILED); throw new MarketingException(MarketingException::COMMIT_ERROR);
} }
return (int)$takePlaceId; return (int)$takePlaceId;
} catch (MarketingException $e) { } catch (MarketingException $e) {
ColonelDistributorColonel::rollback(); ColonelDistributorColonel::rollback();
throw new MarketingException(MarketingException::COLONEL_TAKE_PLACE_FAILED); throw new MarketingException($e->getCode());
} }
} }
......
...@@ -548,6 +548,25 @@ class MarketingService ...@@ -548,6 +548,25 @@ class MarketingService
throw new GoodsException(['cus' => 48]); throw new GoodsException(['cus' => 48]);
} }
} }
<<<<<<< HEAD
=======
}else{
//比例计算
if ($commissionMode == Marketing::COMMISSION_MODE_RATE) {
$commissionTotal = ($firstCommissionRate + $secondCommissionRate) / 10000 * $price;
if ($price < ($commissionTotal+$chargeFee)) {
throw new MarketingException(['cus'=>33]);
}
}
//固定金额
if ($commissionMode == Marketing::COMMISSION_MODE_FIXED) {
$commissionTotal = ($firstCommissionRate + $secondCommissionRate);
if ($price < ($commissionTotal+$chargeFee)) {
throw new MarketingException(['cus'=>33]);
}
}
>>>>>>> colonel
} }
$colums[$key]['marketing_id'] = $marketingId; $colums[$key]['marketing_id'] = $marketingId;
......
...@@ -19,107 +19,6 @@ class Colonelwallet implements DaemonServiceInterface ...@@ -19,107 +19,6 @@ class Colonelwallet implements DaemonServiceInterface
sleep(5); sleep(5);
return false; return false;
} }
\Yaf\Application::app()->bootstrap()->getDispatcher()->dispatch(new \Yaf\Request\Simple('', 'cli', 'colonelwallet', 'index', []));
$yesterday = date("Y-m-d", strtotime("-1 day"));
$payInfoList = $this->getPayInfo($yesterday);
if (!empty($payInfoList)) {
$res = $this->toWallet($payInfoList);
if ($res) {
$this->deductingInventory($payInfoList);
}
}
}
/**
* colonel_distributor_pay_info 数据
* @param $date
* @return array
*/
public function getPayInfo($date)
{
$list = ColonelDistributorPayInfo::select("*", ["date" => $date], []);
$data = [];
if (!empty($list)) {
foreach ($list as $item) {
//去重
$key = $item["colonel_user_id"].$item["date"].$item["type"].$item["finish_num"];
$data[$key] = $item;
}
$data = array_values($data);
}
return $data;
}
/**
* 写入钱包
*/
public function toWallet($payInfoList)
{
$url = config('interface', 'wallet.account.transfer');
if (empty($url)) {
throw new InterfaceException(['cus' => 0]);
}
$data = [];
foreach ($payInfoList as $payInfo) {
if ($payInfo["type"] == ColonelDistributorPayInfo::TYPE_NEW_USER) {
$desc = "邀请新用户(".$payInfo["invite_user_nick"].")完成下单奖励";
}
if ($payInfo["type"] == ColonelDistributorPayInfo::TYPE_FINISH_TARGET) {
$desc = "完成".$payInfo["finish_num"]."单用户下单奖励";
}
$tmp = [];
$tmp["user_id"] = $payInfo["colonel_user_id"];
$tmp["service_name"] = 11; //服务名字,10生活圈优惠券,11营销活动
$tmp["source_name"] = 1; //使用方名,1生活圈,2主端
$tmp["third_order_id"] = $payInfo["colonel_distributor_pay_info_id"];
$tmp["third_order_id_type"] = $payInfo["type"];
$tmp["third_order_desc"] = $desc;
$tmp["amount"] = $payInfo["reward"];
$tmp["extra"] = $payInfo;
$data[] = $tmp;
}
$res = HttpUtil::post($url, ["list" => $data]);
if ($res['code'] == 0 && isset($res['response']["result"])) {
$date = date("Y-m-d H:i:s");
FileLog::info("colonel_distributor_to_wallet", $date." 写入钱包成功");
return true;
} else {
$msg = json_encode(["list" => $data]);
FileLog::error("colonel_distributor_to_wallet", $msg, null, 'bp-server@yidian-inc.com');
return false;
}
}
/**
* 资金池授予用户奖励
*/
public function deductingInventory($payInfoList)
{
$url = config('interface', 'coupon.capitalpool.grant_user_amount');
if (empty($url)) {
throw new InterfaceException(['cus' => 0]);
}
$data["capital_pool_id"] = 2;
foreach ($payInfoList as $payInfo) {
$tmp = [];
$tmp["op"] = 200; //200:团长奖励
$tmp["user_id"] = $payInfo["colonel_user_id"];
$tmp["amount"] = $payInfo["reward"];
$data["body"][] = $tmp;
}
$res = HttpUtil::post($url, $data);
if ($res['code'] == 0 && isset($res['response']["result"])) {
$date = date("Y-m-d H:i:s");
FileLog::info("colonel_distributor_deducting_inventory", $date." 资金池授予用户奖励成功");
return true;
} else {
$msg = json_encode(["list" => $data]);
FileLog::error("colonel_distributor_deducting_inventory", $msg, null, 'bp-server@yidian-inc.com');
return false;
}
} }
} }
\ No newline at end of file
#!/usr/bin/env bash
DIST_FILE_NAME="*.tar.gz"
PROJECT_DIR="api.go2yd.com"
START_SCRIPT="./start_env/start_job.sh"
SYNC_DATA_OPERATIONS="
tar zxf *.tar.gz -C start_env/api.go2yd.com/htdocs/Website
"
DEST_FILE_NAME=""
DEST_FILE_PATH=""
BASE_IMAGE="docker2.yidian.com:5000/centos7/php72_without_nginx:20210621"
MAINTAINER="mengweifu \"mengweifu@yidian-inc.com\""
HOME_DIR="/home/services"
LOG_DIRS="
${HOME_DIR}/${PROJECT_DIR}/logs
"
DATA_DIRS="
"
type=command
command=bash docker run --rm -e LANG=en_US.UTF-8 -e TZ=Asia/Shanghai --net=bridge -h "`hostname`" --cap-add SYS_PTRACE --privileged docker2.yidian.com:5000/publish/bp-goods-azkaban-test-10-image /bin/bash -c "cd /home/services && sh start_job.sh test goodstoes index a=3&b=4"
#!/bin/bash
#
#set -xeuo pipefail # 参考: https://mp.weixin.qq.com/s/VmM_U4RefRBHwIw8NegC8Q
# 运行环境env
if [[ X"$1" == X"" ]]; then
echo "env cannot be empty"
exit 1
fi
# 任务名称
if [[ X"$2" == X"" ]]; then
echo "controller name cannot be empty"
exit 1
fi
# method名称
if [[ X"$3" == X"" ]]; then
echo "method name cannot be empty"
exit 1
fi
environment=${1}
#php.ini要根据环境去修改
if [[ X"${environment}" == X"prod" || X"${environment}" == X"prod_internal" ]];then
sed -i "s#yaf.environ=dev#yaf.environ=prod#g" ini/php.ini
elif [[ X"${environment}" == X"perf" || X"${environment}" == X"perf_internal" ]];then
sed -i "s#yaf.environ=dev#yaf.environ=perf#g" ini/php.ini
elif [[ X"${environment}" == X"test" || X"${environment}" == X"test_internal" ]];then
sed -i "s#yaf.environ=dev#yaf.environ=test#g" ini/php.ini
fi
\cp -f ini/php.ini /etc/php.ini
rsyslogd >/dev/null 2>&1
if [[ -e "/usr/share/zoneinfo/Asia/Shanghai" ]]; then
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
fi
# fix dir permissions
chmod -R 755 /home/services/api.go2yd.com/logs
sysctl -w net.core.somaxconn=65535
php api.go2yd.com/htdocs/Website/public/job.php "$2" "$3" "$4"
ret=$?
if [ $ret -ne 0 ]; then
echo "Build failed"
exit $ret
else
echo "Build success"
fi
exit 0
\ No newline at end of file
<?php
date_default_timezone_set("PRC");
ini_set("display_errors", "On");//打开错误提示
ini_set("error_reporting", E_ALL);//显示所有错误
/*
* cli入口脚本
* cli 配置文件:conf/cli.ini
* cli bootstrap:application/BootstrapCli.php ( 在cli.ini中配置
* 默认模块:modules/job
* 脚本位置:modules/job/controllers/xxx.php
* 调用方式:php job.php controller action "a=1&b=2"
* 测试脚本:php job.php test index "a=1&b=2"
*/
if (!substr(php_sapi_name(), 0, 3) == 'cli') {
die;
}
define('ROOT_PATH', realpath(__DIR__ . '/../'));
define('APPLICATION_PATH', realpath(__DIR__ . '/../'));
define('APP_START', microtime(true));
require APPLICATION_PATH . '/vendor/autoload.php';
require APPLICATION_PATH . '/application/library/helper.php';
$application = new Yaf\Application(APPLICATION_PATH . "/conf/cli.ini");
/**
* 获取模块/控制器/方法
*/
$module = "job";
$controller = $argv[1] ?? "";
$method = $argv[2] ?? "";
$param = $argv[3] ?? [];
if ($param) {
$param = convertUrlQuery($param);
}
$_SERVER['SERVER_NAME'] = 'job.goods';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$application->bootstrap()->getDispatcher()->dispatch(new Yaf\Request\Simple("", $module, $controller, $method, $param));
function convertUrlQuery($query)
{
$queryParts = explode('&', $query);
$params = array();
foreach ($queryParts as $param) {
$item = explode('=', $param);
$params[$item[0]] = $item[1];
}
return $params;
}
\ 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