Commit 78a355b3 authored by luhongguang's avatar luhongguang

update: 团长分销下单退单逻辑

parent 2343da81
...@@ -18,6 +18,7 @@ class MarketingException extends BaseException ...@@ -18,6 +18,7 @@ class MarketingException extends BaseException
const COLONEL_LEVEL_SIX = 26; const COLONEL_LEVEL_SIX = 26;
const COLONEL_AUDIT_STATUS = 27; const COLONEL_AUDIT_STATUS = 27;
const COLONEL_AUDIT_STATUS_FAILED = 28; const COLONEL_AUDIT_STATUS_FAILED = 28;
const COMMIT_ERROR = 29;
protected $cus = [ protected $cus = [
0 => '活动名称不能为空', 0 => '活动名称不能为空',
...@@ -48,6 +49,7 @@ class MarketingException extends BaseException ...@@ -48,6 +49,7 @@ class MarketingException extends BaseException
self::COLONEL_CONFIG_NULL => "团长分销配置内容不能为空", self::COLONEL_CONFIG_NULL => "团长分销配置内容不能为空",
self::COLONEL_LEVEL_SIX => "档位最多设定6档", self::COLONEL_LEVEL_SIX => "档位最多设定6档",
self::COLONEL_AUDIT_STATUS => '团长审核状态错误', self::COLONEL_AUDIT_STATUS => '团长审核状态错误',
self::COLONEL_AUDIT_STATUS_FAILED => '团长审核失败' self::COLONEL_AUDIT_STATUS_FAILED => '团长审核失败',
self::COMMIT_ERROR => '事务commit失败',
]; ];
} }
...@@ -10,6 +10,9 @@ class PindanActivityInviteOrder extends MysqlBase ...@@ -10,6 +10,9 @@ class PindanActivityInviteOrder extends MysqlBase
const CONFIG_INDEX = 'marketing'; const CONFIG_INDEX = 'marketing';
const PRIMARY_KEY = 'invite_order_id'; const PRIMARY_KEY = 'invite_order_id';
const IS_REFUND_NO = 0;//未退款
const IS_REFUND_YES = 1;//已退款
public static function getRecord($where, $columns = [], $options = []) public static function getRecord($where, $columns = [], $options = [])
{ {
if (empty($columns)) { if (empty($columns)) {
......
<?php
namespace App\Models\marketing\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
class PindanActivityInviteOrderRefund extends MysqlBase
{
const TABLE_NAME = 'pindan_activity_invite_order_refund';
const CONFIG_INDEX = 'marketing';
const PRIMARY_KEY = 'invite_order_refund_id';
public static function getRecord($where, $columns = [], $options = [])
{
if (empty($columns)) {
$columns = '*';
}
return self::get($columns, $where, $options);
}
public static function getRecordMaster($where, $columns = [], $options = [])
{
if (empty($columns)) {
$columns = '*';
}
return self::selectMaster($columns, $where, $options);
}
public static function insertRecord($columns, $options = [])
{
return self::insert($columns, $options);
}
public static function updateRecord($columns, $where)
{
return self::update($columns, $where);
}
public static function save($data, $where = [], $options = [])
{
if (empty($where)) {
return self::insert($data, $options);
}
return self::update($data, $where);
}
public static function deleteRecord($where)
{
return self::delete($where);
}
}
\ No newline at end of file
...@@ -10,6 +10,7 @@ use App\Services\marketing\ColonelService; ...@@ -10,6 +10,7 @@ use App\Services\marketing\ColonelService;
use \Validate\ColonelApplyValidate; use \Validate\ColonelApplyValidate;
use \Validate\ColonelConfigValidate; use \Validate\ColonelConfigValidate;
use \App\Services\marketing\PindanActivityColonelConfigService; use \App\Services\marketing\PindanActivityColonelConfigService;
use \App\Services\marketing\PindanActivityInviteOrderService;
class ColonelController extends Base class ColonelController extends Base
{ {
...@@ -56,7 +57,6 @@ class ColonelController extends Base ...@@ -56,7 +57,6 @@ class ColonelController extends Base
return $this->success(["result"=>$data]); return $this->success(["result"=>$data]);
} }
/** /**
* Notes: 管理后台 - 申请团长审核列表 * Notes: 管理后台 - 申请团长审核列表
* User: pengfei@yidian-inc.com * User: pengfei@yidian-inc.com
...@@ -83,4 +83,26 @@ class ColonelController extends Base ...@@ -83,4 +83,26 @@ class ColonelController extends Base
ColonelService::handleManageAudit($params['colonel_apply_id'], $params['audit_status']); ColonelService::handleManageAudit($params['colonel_apply_id'], $params['audit_status']);
return $this->success(); return $this->success();
} }
/**
* 团长分销下单处理统计数据逻辑
* @throws \App\Exception\custom\MarketingException
*/
public function place_order_process_logicAction()
{
$params = $this->params;
$data = PindanActivityInviteOrderService::placeOrder($params);
return $this->success(["result"=>$data]);
}
/**
* 团长分销下单处理统计数据逻辑
* @throws \App\Exception\custom\MarketingException
*/
public function refund_order_process_logicAction()
{
$params = $this->params;
$data = PindanActivityInviteOrderService::refundOrder($params);
return $this->success(["result"=>$data]);
}
} }
\ No newline at end of file
...@@ -2,17 +2,110 @@ ...@@ -2,17 +2,110 @@
namespace App\Services\marketing; namespace App\Services\marketing;
use App\Exception\custom\MarketingException;
use App\Models\marketing\mysql\PindanActivityInviteOrder;
use App\Models\marketing\mysql\PindanActivityInviteOrderNum;
use App\Models\marketing\mysql\PindanActivityInviteOrderRefund;
class PindanActivityInviteOrderService class PindanActivityInviteOrderService
{ {
/**
* 团长分销下单逻辑
* @param array $params
* @return bool
* @throws MarketingException
*/
public static function placeOrder($params = []) public static function placeOrder($params = [])
{ {
$num = empty($params["num"]) ? 1 : $params["num"];
$inviteOrderData = [
"colonel_user_id" => $params["colonel_user_id"],
"user_id" => $params["user_id"],
"order_id" => $params["order_id"],
"refund_time" => null,
];
$inviteOrder = PindanActivityInviteOrder::selectMaster("*", $inviteOrderData, []);
if (!empty($inviteOrder)) {
return true;
}
$inviteOrderNumData = [
"colonel_user_id" => $params["colonel_user_id"],
"date" => date("Y-m-d"),
];
$inviteOrderNum = PindanActivityInviteOrderNum::selectMaster("*", $inviteOrderNumData, []);
PindanActivityInviteOrder::beginTransaction();
$addInviteOrderRes = PindanActivityInviteOrder::save($inviteOrderData);
if (!empty($inviteOrderNum)) {
$addInviteOrderNumRes = PindanActivityInviteOrderNum::save(["num[+]" => $num], ["invite_order_num_id" => $inviteOrderNum[0]["invite_order_num_id"]]);
} else {
$inviteOrderNumData["num"] = $num;
$addInviteOrderNumRes = PindanActivityInviteOrderNum::save($inviteOrderNumData);
}
if (empty($addInviteOrderRes) || empty($addInviteOrderNumRes) || !PindanActivityInviteOrder::commit()) {
PindanActivityInviteOrder::rollback();
throw new MarketingException(["cus" => MarketingException::COMMIT_ERROR]);
}
return true;
} }
/**
* 团长分销退单逻辑
* @param array $params
* @return bool
* @throws MarketingException
*/
public static function refundOrder($params = []) public static function refundOrder($params = [])
{ {
$orderId = $params["order_id"];
$orderItemIds = $params["order_item_id"];
$inviteOrder = PindanActivityInviteOrder::selectMaster("*", ["order_id"=>$orderId], []);
if (!empty($inviteOrder)) {
$inviteOrderData = [
"colonel_user_id" => $inviteOrder[0]["colonel_user_id"],
"user_id" => $inviteOrder[0]["user_id"],
"order_id" => $orderId,
];
$inviteOrderNumData = [
"colonel_user_id" => $inviteOrder[0]["colonel_user_id"],
"date" => date("Y-m-d"),
];
$refundData = [];
foreach ($orderItemIds as $key=>$orderItemId) {
$refund = PindanActivityInviteOrderRefund::getRecord(["order_item_id" => $orderItemId]);
if (empty($refund)) {
$refundData[$key]["order_id"] = $orderId;
$refundData[$key]["order_item_id"] = $orderItemId;
}
}
if (empty($refundData)) {
return true;
}
$num = count($refundData);
PindanActivityInviteOrder::beginTransaction();
PindanActivityInviteOrderRefund::insertRecord($refundData);
$addInviteOrderRes = PindanActivityInviteOrder::save([
"is_refund" => PindanActivityInviteOrder::IS_REFUND_YES,
"refund_time" => date("y-m-d H:i:s")
], $inviteOrderData);
$addInviteOrderNumRes = PindanActivityInviteOrderNum::save(["num[-]" => $num], $inviteOrderNumData);
if (empty($addInviteOrderRes) || empty($addInviteOrderNumRes) || !PindanActivityInviteOrder::commit()) {
PindanActivityInviteOrder::rollback();
throw new MarketingException(["cus" => MarketingException::COMMIT_ERROR]);
}
}
return true;
} }
} }
\ 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