Commit eacb5cd3 authored by luhongguang's avatar luhongguang

update:支付回调商品接口

parent b6253f2e
<?php
namespace Validate;
/**
* Class PaySuccessGoodsCallbackValidate
*
* @package Validate
*/
class PaySuccessGoodsCallbackValidate extends BaseValidate
{
protected $rule = [
'pay_order_id' => 'require',
'goods_sku_id' => 'require',
'num' => 'require',
];
protected $message = [
"pay_order_id" => "pay_order_id 不能为空",
"goods_sku_id" => "goods_sku_id 不能为空",
"num" => "商品数量不能为空",
];
}
\ No newline at end of file
<?php
namespace App\Models\goods\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
/**
* Class PaySuccessGoodsCallbackRecord
* 订单支付成功后商品回调记录
* @package App\Models\goods\mysql
*/
class PaySuccessGoodsCallbackRecord extends MysqlBase
{
const TABLE_NAME = 'pay_success_goods_callback_record';
const CONFIG_INDEX = 'goods';
const OPERATOR_RESULT_FAIL = 0;
const OPERATOR_RESULT_SUCCESS = 1;
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);
}
}
\ No newline at end of file
<?php
use App\Base\Cli;
use \App\Models\goods\mysql\GoodsSku;
class InitGoodsToEsController extends Cli
{
/**
* php public/cli.php InitGoodsToEs index
*/
public function IndexAction()
{
$goodsSkuIds = GoodsSku::select("goods_sku_id", ["goods_status" => 1]);
$request = $this->getRequest();
$params = $request->getParams();
$res = [
"data" => $params,
"code" => 0
];
$response = $this->getResponse();
$response->setBody(json_encode($res));
var_dump($goodsSkuIds);
// $this->getAllGoodsSkuId();
}
public function getAllGoodsSkuId()
{
$goodsSkuIds = GoodsSku::select("goods_sku_id", ["goods_status" => 1]);
var_dump($goodsSkuIds);
exit;
}
}
\ No newline at end of file
...@@ -12,6 +12,7 @@ use \Validate\GoodsInfoFeValidate; ...@@ -12,6 +12,7 @@ use \Validate\GoodsInfoFeValidate;
use \Validate\GoodsListCValidate; use \Validate\GoodsListCValidate;
use \Validate\OrderGoodsValidate; use \Validate\OrderGoodsValidate;
use \Validate\GoodsOnlineOfflineValidate; use \Validate\GoodsOnlineOfflineValidate;
use \Validate\PaySuccessGoodsCallbackValidate;
use \App\Services\goods\ElasticGoodService; use \App\Services\goods\ElasticGoodService;
...@@ -205,4 +206,18 @@ class GoodsController extends Base ...@@ -205,4 +206,18 @@ class GoodsController extends Base
$this->success(["result" => $data]); $this->success(["result" => $data]);
} }
/**
* 支付回调商品接口
* @throws \App\Exception\custom\GoodsException
* @throws \App\Exception\custom\InterfaceException
* @throws \App\Exception\custom\ParamException
*/
public function pay_success_callbackAction()
{
(new PaySuccessGoodsCallbackValidate())->validate();
$res = GoodsService::paySuccessGoodsCallback($this->params);
$this->success(["result" => $res]);
}
} }
\ No newline at end of file
...@@ -16,6 +16,7 @@ use App\Models\goods\mysql\GoodsSku; ...@@ -16,6 +16,7 @@ use App\Models\goods\mysql\GoodsSku;
use App\Models\goods\mysql\GoodsSkuSubShop; use App\Models\goods\mysql\GoodsSkuSubShop;
use App\Models\goods\mysql\GoodsSnapshot; use App\Models\goods\mysql\GoodsSnapshot;
use App\Models\goods\mysql\GoodsSpu; use App\Models\goods\mysql\GoodsSpu;
use App\Models\goods\mysql\PaySuccessGoodsCallbackRecord;
use App\Models\goods\mysql\Shop; use App\Models\goods\mysql\Shop;
use App\Models\shop\mysql\SubShop; use App\Models\shop\mysql\SubShop;
use App\Services\shop\ShopService; use App\Services\shop\ShopService;
...@@ -1094,4 +1095,56 @@ class GoodsService ...@@ -1094,4 +1095,56 @@ class GoodsService
} }
return $data; return $data;
} }
/**
* 支付成功后回调
* @param array $params
* @return bool
* @throws GoodsException
* @throws InterfaceException
*/
public static function paySuccessGoodsCallback($params = [])
{
$payOrderId = $params["pay_order_id"];
$goodsSkuId = $params["goods_sku_id"];
$num = $params["num"];
$record = PaySuccessGoodsCallbackRecord::getRecord([
"pay_order_id" => $payOrderId,
"goods_sku_id" => $goodsSkuId,
"operator_result" => PaySuccessGoodsCallbackRecord::OPERATOR_RESULT_SUCCESS]
);
if (empty($record)) {
GoodsSku::beginTransaction();
$goodsSku = GoodsSku::getRecord(["goods_sku_id"=>$goodsSkuId]);
if (empty($goodsSku)) {
throw new GoodsException(["cus" => 15]);
}
GoodsSku::save(["total_amount_sold" => $goodsSku["total_amount_sold"] + $num]
, ["goods_sku_id" => $goodsSkuId]);
PaySuccessGoodsCallbackRecord::insertRecord([
"pay_order_id" => $payOrderId,
"goods_sku_id" => $goodsSkuId,
"operator_result" => PaySuccessGoodsCallbackRecord::OPERATOR_RESULT_SUCCESS]
);
if (!GoodsSku::commit()) {
GoodsSku::rollback();
PaySuccessGoodsCallbackRecord::insertRecord([
"pay_order_id" => $payOrderId,
"goods_sku_id" => $goodsSkuId,
"operator_result" => PaySuccessGoodsCallbackRecord::OPERATOR_RESULT_FAIL]
);
return false;
}
//同步到es
self::updateGoodsInfoToEs($goodsSkuId);
}
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