Commit bc3e64b8 authored by suntengda's avatar suntengda

Merge branch 'master' into tuancan

parents 644155a2 824b111a
...@@ -70,5 +70,6 @@ class GoodsException extends BaseException ...@@ -70,5 +70,6 @@ class GoodsException extends BaseException
49 => '库存不得小于已售库存', 49 => '库存不得小于已售库存',
self::RULE_LIMIT_ERROR => '单人可买上限填写错误', self::RULE_LIMIT_ERROR => '单人可买上限填写错误',
self::NOT_FIND_MARKETING => '找不到活动', self::NOT_FIND_MARKETING => '找不到活动',
52 => '过期时间不得小于等于上架开始时间',
]; ];
} }
\ No newline at end of file
...@@ -22,5 +22,8 @@ class UserException extends BaseException ...@@ -22,5 +22,8 @@ class UserException extends BaseException
8 => '绑定手机号失败', 8 => '绑定手机号失败',
9 => '该手机号已绑定其他用户不能重复绑定', 9 => '该手机号已绑定其他用户不能重复绑定',
10 => 'mysql 异常', 10 => 'mysql 异常',
11 => '头像昵称更新失败',
12 => '绑定手机号保存失败',
13 => '请求太频繁,稍后重试',
]; ];
} }
\ No newline at end of file
<?php
namespace Validate;
/**
* Class GoodsAuditValidate
*
* @package Validate
*/
class GoodsOnlineSiteValidate extends BaseValidate
{
protected $rule = [
'goods_spu_id' => 'require',
'online_type' => 'require',
];
protected $message = [
"goods_spu_id" => "商品id不能为空",
"online_type" => "设置类型不能为空",
];
}
\ No newline at end of file
...@@ -26,6 +26,14 @@ class UserWechatBind extends MysqlBase ...@@ -26,6 +26,14 @@ class UserWechatBind extends MysqlBase
return self::get($columns, $where); return self::get($columns, $where);
} }
public static function getRecordMaster($where, $columns = [])
{
if (empty($columns)) {
$columns = '*';
}
return self::getMaster($columns, $where);
}
public static function getRecords($where, $columns = []) public static function getRecords($where, $columns = [])
{ {
if (empty($columns)) { if (empty($columns)) {
...@@ -34,7 +42,7 @@ class UserWechatBind extends MysqlBase ...@@ -34,7 +42,7 @@ class UserWechatBind extends MysqlBase
return self::select($columns, $where); return self::select($columns, $where);
} }
public static function getRecordMaster($where, $columns = []) public static function getRecordsMaster ($where, $columns = [])
{ {
if (empty($columns)) { if (empty($columns)) {
$columns = '*'; $columns = '*';
......
...@@ -16,6 +16,7 @@ use \Validate\GoodsOnlineOfflineValidate; ...@@ -16,6 +16,7 @@ use \Validate\GoodsOnlineOfflineValidate;
use \Validate\PaySuccessGoodsCallbackValidate; use \Validate\PaySuccessGoodsCallbackValidate;
use \Validate\GoodsInitShopValidate; use \Validate\GoodsInitShopValidate;
use \Validate\PindanGoodsAddValidate; use \Validate\PindanGoodsAddValidate;
use \Validate\GoodsOnlineSiteValidate;
use \App\Services\goods\ElasticGoodService; use \App\Services\goods\ElasticGoodService;
use \App\Services\goods\MarketingPindanGoodsService; use \App\Services\goods\MarketingPindanGoodsService;
use \App\Models\marketing\mysql\Marketing; use \App\Models\marketing\mysql\Marketing;
...@@ -118,6 +119,20 @@ class GoodsController extends Base ...@@ -118,6 +119,20 @@ class GoodsController extends Base
$this->success(); $this->success();
} }
/**
* 修改商品定点上架设置
* @date 2021-08-25
* @license [license]
* @version [version]
*/
public function online_siteAction()
{
$params = $this->params;
(new GoodsOnlineSiteValidate())->validate();
GoodsService::onlineSite($params);
$this->success();
}
/** /**
* 审核通过/驳回 * 审核通过/驳回
*/ */
......
...@@ -157,11 +157,6 @@ class GoodsService ...@@ -157,11 +157,6 @@ class GoodsService
throw new GoodsException(['cus' => 2]); throw new GoodsException(['cus' => 2]);
} }
$spuId = $res[0]; $spuId = $res[0];
$checkName = self::checkGoodsName($spuData["goods_name"], $spuData["life_account_id"]);
if (!$checkName["can_use"]) {
throw new GoodsException(['cus' => 17]);
}
$spuParams = [ $spuParams = [
"goods_spu_id" => $spuId, "goods_spu_id" => $spuId,
"shop_id" => $shopId, "shop_id" => $shopId,
...@@ -255,11 +250,43 @@ class GoodsService ...@@ -255,11 +250,43 @@ class GoodsService
"inventory_rest" => $skuData["inventory"], "inventory_rest" => $skuData["inventory"],
"original_price" => empty($skuData["original_price"]) ? '' : $skuData["original_price"] * 100, "original_price" => empty($skuData["original_price"]) ? '' : $skuData["original_price"] * 100,
"price" => $skuData["price"] * 100, "price" => $skuData["price"] * 100,
"online_start_time" => empty($skuData["online_start_time"]) ? "" : $skuData["online_start_time"],
"online_end_time" => empty($skuData["online_end_time"]) ? "" : $skuData["online_end_time"],
"online_type" => empty($skuData["online_type"]) ? "" : $skuData["online_type"],
]; ];
if (!empty($skuData["setmeal"])) { if (!empty($skuData["setmeal"])) {
$skuParams["setmeal"] = $skuData["setmeal"]; $skuParams["setmeal"] = $skuData["setmeal"];
} }
$online_type = empty($skuData["online_type"]) ? 0 : $skuData["online_type"];
switch ($online_type) {
case 1:
$skuParams['online_status'] = 0;
$skuParams['online_start_time'] = date("Y-m-d H:i:s");
break;
case 2:
$skuParams['online_status'] = 0;
break;
case 3:
$skuParams['online_status'] = 0;
break;
default:
$skuParams['online_type'] = 1;
$skuParams['online_status'] = 0;
$skuParams['online_start_time'] = date("Y-m-d H:i:s");
break;
}
if (!empty($skuData["online_type"])) {
//立即上架和定时上架
if (in_array($skuData["online_type"], [1,2])) {
if ($skuData["expiration_time"] <= $skuData['online_start_time']) {
throw new GoodsException(["cus" => 52]);
}
}
}
GoodsSku::save($skuParams); GoodsSku::save($skuParams);
self::addGoodsSkuPicRecord($skuId, $skuData); self::addGoodsSkuPicRecord($skuId, $skuData);
return $skuId; return $skuId;
...@@ -408,6 +435,27 @@ class GoodsService ...@@ -408,6 +435,27 @@ class GoodsService
]; ];
} }
if ($status == GoodsSku::STATUS_PASS) {
$online_type = empty($sku["online_type"]) ? 0 : $sku["online_type"];
if ($online_type == 1) {
$statusData['online_status'] = GoodsSku::ONLINE_STATUS_ONLINE;
$statusData['online_start_time'] = date("Y-m-d H:i:s");
}
//定点上架
if ($online_type == 2) {
$onlineStartTime = empty($sku["online_start_time"]) ? 0 : strtotime($sku["online_start_time"]);
if ($onlineStartTime > time()) {
$statusData['online_status'] = GoodsSku::ONLINE_STATUS_OFFLINE;
}
}
//暂不上架
if ($online_type == 3) {
$statusData['online_status'] = GoodsSku::ONLINE_STATUS_OFFLINE;
}
}
GoodsSku::save($statusData, ["goods_sku_id" => $sku["goods_sku_id"]]); GoodsSku::save($statusData, ["goods_sku_id" => $sku["goods_sku_id"]]);
//商品操作记录 //商品操作记录
...@@ -480,8 +528,22 @@ class GoodsService ...@@ -480,8 +528,22 @@ class GoodsService
if ($onlineStatus == GoodsSku::ONLINE_STATUS_ONLINE && $sku["inventory_rest"] <= 0) { if ($onlineStatus == GoodsSku::ONLINE_STATUS_ONLINE && $sku["inventory_rest"] <= 0) {
throw new GoodsException(["cus" => 24]); throw new GoodsException(["cus" => 24]);
} }
$goodsSkuData = ["online_status" => $onlineStatus];
if ($onlineStatus == GoodsSku::ONLINE_STATUS_OFFLINE){
$goodsSkuData['online_type'] = 3;
$goodsSkuData['online_start_time'] = null;
$goodsSkuData['online_end_time'] = null;
}
if ($onlineStatus == GoodsSku::ONLINE_STATUS_ONLINE){
$goodsSkuData['online_type'] = 1;
$goodsSkuData['online_start_time'] = date("Y-m-d H:i:s");
}
$goodsSkuId = $sku["goods_sku_id"]; $goodsSkuId = $sku["goods_sku_id"];
GoodsSku::save(["online_status" => $onlineStatus], ["goods_sku_id" => $goodsSkuId]); GoodsSku::save($goodsSkuData, ["goods_sku_id" => $goodsSkuId]);
//商品操作记录 //商品操作记录
$record = [ $record = [
...@@ -512,6 +574,103 @@ class GoodsService ...@@ -512,6 +574,103 @@ class GoodsService
return true; return true;
} }
/**
* 设置商品上架
* @date 2021-08-25
* @copyright [copyright]
* @license [license]
* @version [version]
* @param $params [description]
* @return array [description]
*/
public static function onlineSite($params)
{
$goodsSpuId = $params["goods_spu_id"];
$onlineType = !empty($params["online_type"]) ? $params["online_type"] : 0;
$onlineStartTime = !empty($params["online_start_time"]) ? $params["online_start_time"] : null;
$onlineEndTime = !empty($params["online_end_time"]) ? $params["online_end_time"] : null;
GoodsSku::beginTransaction();
$goodsSkuList = GoodsSku::select("*", ["goods_spu_id" => $goodsSpuId]);
if (!empty($goodsSkuList)) {
foreach ($goodsSkuList as $sku) {
if ($sku["expiration_time"] < date("Y-m-d H:i:s")) {
throw new GoodsException(["cus" => 30]);
}
$goodsSkuId = $sku["goods_sku_id"];
$goodsSkuData = [
"online_type" => $onlineType,
"online_start_time" => $onlineStartTime,
"online_end_time" => $onlineEndTime
];
if ($onlineType == 1) {
if ($sku['audit_status'] == 1) {
$goodsSkuData['online_status'] = GoodsSku::ONLINE_STATUS_ONLINE;
}
$goodsSkuData['online_start_time'] = date("Y-m-d H:i:s");
}
//暂不上架
if ($onlineType == 3) {
//$goodsSkuData['audit_status'] = 0;
if ($sku['audit_status'] == 1) {
$goodsSkuData['online_status'] = GoodsSku::ONLINE_STATUS_OFFLINE;
}else{
$goodsSkuData['online_status'] = 0;
}
}
if ($onlineType == 2) {
$onlineStartTime = strtotime($goodsSkuData['online_start_time']);
if ($onlineStartTime > time()) {
if ($sku['audit_status'] == 1) {
$goodsSkuData['online_status'] = GoodsSku::ONLINE_STATUS_OFFLINE;
}else{
$goodsSkuData['online_status'] = 0;
}
}
}
//立即上架和定时上架
if (in_array($onlineType, [1,2])) {
if ($sku["expiration_time"] <= $goodsSkuData['online_start_time']) {
throw new GoodsException(["cus" => 52]);
}
}
$operatorId = empty($params["user_id"]) ? 0 : $params["user_id"];
$operatorName = !empty($params["user_name"]) ? $params["user_name"] : '';
//商品操作记录
$record = [
"goods_spu_id" => $goodsSpuId,
"goods_sku_id" => $goodsSkuId,
"operator_id" => $operatorId,
"operator_name" => $operatorName,
"goods_status" => $sku["audit_status"],
"online_status" => !empty($goodsSkuData['online_status']) ? $goodsSkuData['online_status'] : $sku["online_status"],
"before_version" => $sku["goods_version"],
"after_version" => $sku["goods_version"],
"note" => empty($params["rejected_reason"]) ? "" : $params["rejected_reason"],
];
GoodsOperationRecord::insertRecord($record);
GoodsSku::save($goodsSkuData, ["goods_sku_id" => $goodsSkuId]);
//上架的话,生成快照
self::addGoodsSnapshot($sku);
self::updateGoodsInfoToEs($goodsSkuId);
}
}
if (!GoodsSku::commit()) {
GoodsSku::rollback();
throw new GoodsException(["cus" => 11]);
}
return true;
}
/** /**
* 生成快照数据 * 生成快照数据
* @param $skuInfo * @param $skuInfo
...@@ -609,13 +768,6 @@ class GoodsService ...@@ -609,13 +768,6 @@ class GoodsService
*/ */
private static function editGoodsSpu($goodsSpu, $params = []) private static function editGoodsSpu($goodsSpu, $params = [])
{ {
$checkName = self::checkGoodsName($params["goods_name"], $goodsSpu["life_account_id"], $goodsSpu["goods_spu_id"]);
if (!$checkName["can_use"]) {
throw new GoodsException(['cus' => 17]);
}
return GoodsSpu::save([ return GoodsSpu::save([
"goods_name" => $params["goods_name"], "goods_name" => $params["goods_name"],
"desc_pic_url" => $params["desc_pic_url"], "desc_pic_url" => $params["desc_pic_url"],
...@@ -715,6 +867,28 @@ class GoodsService ...@@ -715,6 +867,28 @@ class GoodsService
$skuParams["setmeal"] = $params["setmeal"]; $skuParams["setmeal"] = $params["setmeal"];
} }
if (!empty($params["online_start_time"])) {
$skuParams['online_start_time'] = empty($params["online_start_time"]) ? "" : $params["online_start_time"];
}
if (!empty($params["online_end_time"])) {
$skuParams['online_end_time'] = empty($params["online_end_time"]) ? "" : $params["online_end_time"];
}
if (!empty($params["online_type"])) {
$skuParams['online_type'] = empty($params["online_type"]) ? 0 : $params["online_type"];
}
if (!empty($params["online_type"])) {
//立即上架和定时上架
if (in_array($params["online_type"], [1,2])) {
if ($skuData["expiration_time"] <= $skuParams['online_start_time']) {
throw new GoodsException(["cus" => 52]);
}
}
}
//商品操作记录 //商品操作记录
$record = [ $record = [
"goods_spu_id" => $skuData["goods_spu_id"], "goods_spu_id" => $skuData["goods_spu_id"],
...@@ -882,6 +1056,9 @@ class GoodsService ...@@ -882,6 +1056,9 @@ class GoodsService
$data["goods_info"]["clear_price"] = empty($sku["clear_price"]) ? "" : $sku["clear_price"] / 100; $data["goods_info"]["clear_price"] = empty($sku["clear_price"]) ? "" : $sku["clear_price"] / 100;
$data["goods_info"]["price"] = $sku["price"] / 100; $data["goods_info"]["price"] = $sku["price"] / 100;
$data["goods_info"]["inventory"] = $sku["inventory_rest"]; $data["goods_info"]["inventory"] = $sku["inventory_rest"];
$data["goods_info"]["online_type"] = $sku["online_type"];
$data["goods_info"]["online_start_time"] = $sku["online_start_time"];
$data["goods_info"]["online_end_time"] = $sku["online_end_time"];
$categoryNameList = Category::select("name", ["category_id" => [$sku["category_1_id"], $sku["category_2_id"]]]); $categoryNameList = Category::select("name", ["category_id" => [$sku["category_1_id"], $sku["category_2_id"]]]);
$data["goods_info"]["category_1_name"] = $categoryNameList[0]; $data["goods_info"]["category_1_name"] = $categoryNameList[0];
...@@ -1025,14 +1202,31 @@ class GoodsService ...@@ -1025,14 +1202,31 @@ class GoodsService
//是否是分销活动 //是否是分销活动
$runningMarketing = MarketingGoodsService::getRunningMarketing([$params["goods_sku_id"]]); $runningMarketing = MarketingGoodsService::getRunningMarketing([$params["goods_sku_id"]]);
$data["goods_info"]["is_fenxiao"] = false; $data["goods_info"]["is_fenxiao"] = false;
if (!empty($runningMarketing[$params["goods_sku_id"]])) { if (!empty($runningMarketing[$params["goods_sku_id"]])) {
$data["goods_info"]["is_fenxiao"] = true; $data["goods_info"]["is_fenxiao"] = true;
} }
$marketingInfoList = MarketingGoods::select(["marketing_id", "goods_sku_id"], ["goods_sku_id" => $params["goods_sku_id"]]);
$data["goods_info"]['goods_share_code'] = CommonService::getGoodsShareId($params); if (!empty($marketingInfoList)) {
foreach ($marketingInfoList as $marketingInfo) {
$marketingInfoIds[$marketingInfo["goods_sku_id"]] = $marketingInfo["marketing_id"];
}
$marketingIds = array_values($marketingInfoIds);
$now = date("Y-m-d H:i:s");
$resMarketingList = Marketing::select("*", ["start_time[<]" => $now, "end_time[>]" => $now, "marketing_id" => $marketingIds, "marketing_type" => Marketing::MARKETING_TYPE_FENXIAO]);
if (!empty($resMarketingList)) {
foreach ($resMarketingList as $res) {
$marketingList[$res["marketing_id"]] = $res;
}
}
}
$marketing = !empty($marketingList) ? current($marketingList) : [];
$data["goods_info"]['goods_share_code'] = CommonService::getGoodsShareId($params);
//当前人是否是团长 //当前人是否是团长
$data["goods_info"]["is_tuanzhang"] = false; $data["goods_info"]["is_tuanzhang"] = false;
if (!empty($params["user_id"])) { if (!empty($params["user_id"])) {
...@@ -1041,7 +1235,11 @@ class GoodsService ...@@ -1041,7 +1235,11 @@ class GoodsService
$data["goods_info"]["is_tuanzhang"] = true; $data["goods_info"]["is_tuanzhang"] = true;
if (!empty($runningMarketing)) { if (!empty($runningMarketing)) {
//分销返现多少钱 //分销返现多少钱
$data["goods_info"]["cash_back"] = sprintf("%.2f",$runningMarketing[$params["goods_sku_id"]] * $data["goods_info"]["price"]); if (!empty($marketing) && $marketing['commission_mode'] == 2) {
$data["goods_info"]["cash_back"] = (float)sprintf("%.2f",$runningMarketing[$params["goods_sku_id"]]);
}else{
$data["goods_info"]["cash_back"] = (float)sprintf("%.2f",$runningMarketing[$params["goods_sku_id"]] * $data["goods_info"]["price"]);
}
} }
} }
} }
...@@ -1092,13 +1290,23 @@ class GoodsService ...@@ -1092,13 +1290,23 @@ class GoodsService
$where['ORDER'] = ["create_time" => "DESC"]; $where['ORDER'] = ["create_time" => "DESC"];
$list = GoodsSku::select(["goods_spu_id", "goods_sku_id", "goods_name", "category_1_id", "category_2_id", "life_account_id", $list = GoodsSku::select(["goods_spu_id", "goods_sku_id", "goods_name", "category_1_id", "category_2_id", "life_account_id",
"publish_user_id", "update_time", "create_time", "audit_status", "online_status"], "publish_user_id", "update_time", "create_time", "audit_status", "online_status","online_start_time","online_end_time","online_type"],
$where); $where);
if (!empty($list)) { if (!empty($list)) {
foreach ($list as $key => $item) { foreach ($list as $key => $item) {
$nameList = Category::select("name", ["category_id" => [$item["category_1_id"], $item["category_2_id"]]]); $nameList = Category::select("name", ["category_id" => [$item["category_1_id"], $item["category_2_id"]]]);
$list[$key]["category_1_name"] = $nameList[0]; $list[$key]["category_1_name"] = $nameList[0];
$list[$key]["category_2_name"] = $nameList[1]; $list[$key]["category_2_name"] = $nameList[1];
if ($item['online_type'] == 3) {
$list[$key]["online_start_time"] = "";
$list[$key]["online_end_time"] = "";
}
if ($item['online_type'] == 1) {
$list[$key]["online_end_time"] = "";
}
} }
} }
return ["list" => $list, "count" => $count]; return ["list" => $list, "count" => $count];
......
...@@ -165,12 +165,6 @@ class MarketingPindanGoodsService ...@@ -165,12 +165,6 @@ class MarketingPindanGoodsService
*/ */
private static function addGoodsSku($spuData, $shopId, $skuData = []) private static function addGoodsSku($spuData, $shopId, $skuData = [])
{ {
$pindanSku = PindanGoodsSku::get("goods_sku_id", ["goods_name" => $skuData["goods_name"]
, "life_account_id" => $skuData["life_account_id"]]);
if (!empty($pindanSku)) {
throw new GoodsException(['cus' => 17]);
}
$res = GoodsService::getIdgenId(substr($shopId, -2), "goods"); $res = GoodsService::getIdgenId(substr($shopId, -2), "goods");
if (empty($res)) { if (empty($res)) {
throw new GoodsException(['cus' => 2]); throw new GoodsException(['cus' => 2]);
...@@ -267,11 +261,6 @@ class MarketingPindanGoodsService ...@@ -267,11 +261,6 @@ class MarketingPindanGoodsService
*/ */
private static function editGoodsSpu($goodsSpu, $params = []) private static function editGoodsSpu($goodsSpu, $params = [])
{ {
$checkName = GoodsService::checkGoodsName($params["goods_name"], $goodsSpu["life_account_id"], $goodsSpu["goods_spu_id"]);
if (!$checkName["can_use"]) {
throw new GoodsException(['cus' => 17]);
}
return GoodsSpu::save([ return GoodsSpu::save([
"desc_pic_url" => $params["desc_pic_url"], "desc_pic_url" => $params["desc_pic_url"],
"desc" => $params["desc"], "desc" => $params["desc"],
......
...@@ -150,12 +150,12 @@ class MarketingGoodsService ...@@ -150,12 +150,12 @@ class MarketingGoodsService
//比例 //比例
if (!empty($secondCommission) && $commissionMode == 1) { if (!empty($secondCommission) && $commissionMode == 1) {
$price = !empty($list[$i]['price']) ? $list[$i]['price'] : 0; $price = !empty($list[$i]['price']) ? $list[$i]['price'] : 0;
$list[$i]['share_price'] = substr(sprintf("%.4f",$secondCommission*$price/100),0,-2); $list[$i]['share_price'] = (float) substr(sprintf("%.4f",$secondCommission*$price/100),0,-2);
} }
//固定 //固定
if (!empty($commissionMode) && $commissionMode == 2) { if (!empty($commissionMode) && $commissionMode == 2) {
$list[$i]['share_price'] = substr(sprintf("%.4f",$secondCommission/100),0,-2); $list[$i]['share_price'] = (float) substr(sprintf("%.4f",$secondCommission),0,-2);
} }
$content = $userId .'_' .$value['marketing_id']; $content = $userId .'_' .$value['marketing_id'];
...@@ -195,9 +195,13 @@ class MarketingGoodsService ...@@ -195,9 +195,13 @@ class MarketingGoodsService
$data = []; $data = [];
foreach ($marketingInfoIds as $goodsSkuId => $marketingId) { foreach ($marketingInfoIds as $goodsSkuId => $marketingId) {
if (!empty($marketingList[$marketingId]["second_commission_value"])) { if (!empty($marketingList[$marketingId]["second_commission_value"]) && $marketingList[$marketingId]["commission_mode"] == 1) {
$data[$goodsSkuId] = substr(sprintf("%.4f", $marketingList[$marketingId]["second_commission_value"]/10000), 0, -2); $data[$goodsSkuId] = substr(sprintf("%.4f", $marketingList[$marketingId]["second_commission_value"]/10000), 0, -2);
} }
if (!empty($marketingList[$marketingId]["second_commission_value"]) && $marketingList[$marketingId]["commission_mode"] == 2) {
$data[$goodsSkuId] = substr(sprintf("%.4f", $marketingList[$marketingId]["second_commission_value"]/100), 0, -2);
}
} }
return $data; return $data;
} }
......
...@@ -518,6 +518,9 @@ class MarketingService ...@@ -518,6 +518,9 @@ class MarketingService
$clearPrice = !empty($value["clear_price"]) ? $value["clear_price"] : 0; $clearPrice = !empty($value["clear_price"]) ? $value["clear_price"] : 0;
$price = !empty($value["price"]) ? $value["price"] : 0; $price = !empty($value["price"]) ? $value["price"] : 0;
$chargeFee = !empty($price) ? (float)bcmul($price , self::CHARGEFEE,2) : 0; //手续费 (分) $chargeFee = !empty($price) ? (float)bcmul($price , self::CHARGEFEE,2) : 0; //手续费 (分)
if ($chargeFee < 1) {
$chargeFee = 0;
}
if (!empty($clearPrice) && $clearPrice > 0) { if (!empty($clearPrice) && $clearPrice > 0) {
if ($commissionMode == Marketing::COMMISSION_MODE_RATE) { if ($commissionMode == Marketing::COMMISSION_MODE_RATE) {
$commissionTotal = ($firstCommissionRate + $secondCommissionRate) / 10000 * $price; $commissionTotal = ($firstCommissionRate + $secondCommissionRate) / 10000 * $price;
......
...@@ -14,6 +14,8 @@ use Api\PhpServices\Idgen\Idgen; ...@@ -14,6 +14,8 @@ use Api\PhpServices\Idgen\Idgen;
use Api\PhpUtils\Redis\RedisUtil; use Api\PhpUtils\Redis\RedisUtil;
use Api\PhpServices\JwUser\JwUser; use Api\PhpServices\JwUser\JwUser;
use App\Services\common\CommonService; use App\Services\common\CommonService;
use Api\PhpUtils\Log\FileLog;
use Api\PhpUtils\Lock\FrequencyLockUtil;
class UserService class UserService
{ {
...@@ -26,9 +28,24 @@ class UserService ...@@ -26,9 +28,24 @@ class UserService
$code = !empty($params['code']) ? $params['code'] : '';//小程序授权code $code = !empty($params['code']) ? $params['code'] : '';//小程序授权code
$openid = !empty($params['openid']) ? $params['openid'] : '';//小程序授权code $openid = !empty($params['openid']) ? $params['openid'] : '';//小程序授权code
if (empty($code) && empty($openid)) { if (empty($code) && empty($openid)) {
FileLog::error("wechatLogin:获取参数为空", json_encode($params, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
throw new UserException(['cus' => 0]); throw new UserException(['cus' => 0]);
} }
$redis = RedisUtil::getInstance('cache');
$key = "wx_wechat_login_".$code;
$keyCode = "wx_wechat_login_code_".$code;
$lock = FrequencyLockUtil::isLocked($key,1,120);
if ($lock) {
sleep(1);
$user = $redis->get($keyCode);
if (!empty($user)) {
$user = json_decode($user,true);
}
FileLog::error("wechatLogin: lock", json_encode($user, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
FileLog::error("wechatLogin: lock--params", json_encode($params, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
return $user;
}
//需要授权微信 //需要授权微信
//if (empty($openid)) { //if (empty($openid)) {
...@@ -51,6 +68,7 @@ class UserService ...@@ -51,6 +68,7 @@ class UserService
if (empty($response) || array_key_exists('errcode', $response)) { if (empty($response) || array_key_exists('errcode', $response)) {
//throw new \Exception('获取openid失败:' . $response['errcode']); //throw new \Exception('获取openid失败:' . $response['errcode']);
FileLog::error("wechatLogin:获取openid失败", json_encode($params, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
throw new UserException(['cus' => 1]); throw new UserException(['cus' => 1]);
} }
//检查系统是已注册 //检查系统是已注册
...@@ -58,7 +76,7 @@ class UserService ...@@ -58,7 +76,7 @@ class UserService
//} //}
$user = UserWechatBind::getRecord(['openid' => $openid]); $user = UserWechatBind::getRecordMaster(['openid' => $openid]);
//如果系统不存在,用户信息,则注册新用户 //如果系统不存在,用户信息,则注册新用户
if (empty($user) && !empty($response)) { if (empty($user) && !empty($response)) {
$insert = [ $insert = [
...@@ -68,8 +86,13 @@ class UserService ...@@ -68,8 +86,13 @@ class UserService
'create_time' => date("Y-m-d H:i:s") 'create_time' => date("Y-m-d H:i:s")
]; ];
$newWechatId = UserWechatBind::save($insert); $sessionKey = !empty($response['session_key']) ? $response['session_key'] : '';
//$newWechatId = UserWechatBind::save($insert);
$newWechatId =UserWechatBind::insertDuplicate($insert, ['session_key' => $sessionKey,'create_time' => date("Y-m-d H:i:s")]);
if (!$newWechatId) { if (!$newWechatId) {
FileLog::error("wechatLogin:登陆创建用户失败", json_encode($params, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
FileLog::error("wechatLogin:登陆创建用户失败--insert", json_encode($insert, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
throw new UserException(['cus' => 2]); throw new UserException(['cus' => 2]);
} }
...@@ -78,17 +101,21 @@ class UserService ...@@ -78,17 +101,21 @@ class UserService
$user['session_key'] = $response['session_key']; $user['session_key'] = $response['session_key'];
}else{ }else{
if (empty($user)) { if (empty($user)) {
FileLog::error("wechatLogin:登陆创建用户失败-- 微信response", json_encode($response, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
throw new UserException(['cus' => 2]); throw new UserException(['cus' => 2]);
} }
if (empty($response)){
FileLog::error("wechatLogin:登陆创建用户失败-- 微信response 获取失败", json_encode($params, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
throw new UserException(['cus' => 2]);
}
$insert = [ $insert = [
'session_key' => !empty($response['session_key']) ? $response['session_key'] : '', 'session_key' => !empty($response['session_key']) ? $response['session_key'] : '',
]; ];
$newWechatId = UserWechatBind::save($insert,['openid' => $openid]); $newWechatId = UserWechatBind::save($insert,['openid' => $openid]);
} }
$user['third_session'] = self::generate3rdSession($openid); $user['third_session'] = self::generate3rdSession($openid);
$redis->set($keyCode, json_encode($user),120);
return $user; return $user;
} }
...@@ -102,47 +129,47 @@ class UserService ...@@ -102,47 +129,47 @@ class UserService
$appid = \Yaf\Registry::get('config')->wechat->appid; $appid = \Yaf\Registry::get('config')->wechat->appid;
if (!$encryptedData) { if (!$encryptedData) {
FileLog::error("bindPhone:encryptedData 为空", json_encode($params, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
throw new UserException(['cus' => 3]); throw new UserException(['cus' => 3]);
} }
if (!$iv) { if (!$iv) {
FileLog::error("bindPhone:iv 为空", json_encode($params, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
throw new UserException(['cus' => 4]); throw new UserException(['cus' => 4]);
} }
$userInfo = UserWechatBind::getRecord(['openid' => $openid]); $userInfo = UserWechatBind::getRecordMaster(['openid' => $openid]);
$sessionKey = !empty($userInfo['session_key']) ? $userInfo['session_key'] : ''; $sessionKey = !empty($userInfo['session_key']) ? $userInfo['session_key'] : '';
$openid = isset($userInfo['openid']) && $userInfo['openid'] ? $userInfo['openid'] : ''; $openid = isset($userInfo['openid']) && $userInfo['openid'] ? $userInfo['openid'] : '';
if (empty($userInfo) || !$sessionKey || !$openid) { if (empty($userInfo) || !$sessionKey || !$openid) {
FileLog::error("bindPhone:userInfo获取失败", json_encode($userInfo, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
throw new UserException(['cus' => 5]); throw new UserException(['cus' => 5]);
} }
//解密 //解密
$decryptData = []; $decryptData = [];
$wXBizDataCrypt = new WxBizDataCrypt($appid, $sessionKey); $wXBizDataCrypt = new WxBizDataCrypt($appid, $sessionKey);
$errCode = $wXBizDataCrypt->decryptData($encryptedData, $iv, $decryptData); $errCode = $wXBizDataCrypt->decryptData($encryptedData, $iv, $decryptData);
if ($errCode) { if ($errCode) {
FileLog::error("bindPhone:解密失败", json_encode($params, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
throw new UserException(['cus' => 6]); throw new UserException(['cus' => 6]);
} }
// 手机号解密成功 // 手机号解密失败
if (empty($decryptData['phoneNumber'])) { if (empty($decryptData['phoneNumber'])) {
FileLog::error("bindPhone:手机号解密失败", json_encode($params, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
FileLog::error("bindPhone:手机号解密失败--decryptData", json_encode($decryptData, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
throw new UserException(['cus' => 7]); throw new UserException(['cus' => 7]);
} }
$phoneNumber = strval($decryptData['phoneNumber']); $phoneNumber = strval($decryptData['phoneNumber']);
//判断是否已 //判断是否已
$user = UserWechatBind::getRecord(['phone' => $phoneNumber]); $user = UserWechatBind::getRecordMaster(['phone' => $phoneNumber]);
if (!empty($user) && $openid != $user['openid']) { if (!empty($user) && $openid != $user['openid']) {
FileLog::error("bindPhone:该手机号已绑定其他用户不能重复绑定", json_encode($params, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
FileLog::error("bindPhone:该手机号已绑定其他用户不能重复绑定--user", json_encode($user, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
throw new UserException(['cus' => 9]); throw new UserException(['cus' => 9]);
} }
...@@ -160,12 +187,16 @@ class UserService ...@@ -160,12 +187,16 @@ class UserService
]; ];
$bindStatus = UserWechatBind::save($update,['wechat_id' => $userInfo['wechat_id']]); $bindStatus = UserWechatBind::save($update,['wechat_id' => $userInfo['wechat_id']]);
if (empty($bindStatus)){
FileLog::error("bindPhone:绑定手机号保存失败", json_encode($update, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
throw new UserException(['cus' => 12]);
}
if (!$phoneNumber) { if (!$phoneNumber) {
FileLog::error("bindPhone:该手机号已绑定其他用户不能重复绑定--user", json_encode($user, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
throw new UserException(['cus' => 8]); throw new UserException(['cus' => 8]);
} }
CommonService::isNewUser($params);
$isNewUser = CommonService::isNewUser(['openid' => $openid]); $isNewUser = CommonService::isNewUser(['openid' => $openid]);
if (!empty($isNewUser) && $isNewUser['is_new_user'] == 1) { if (!empty($isNewUser) && $isNewUser['is_new_user'] == 1) {
$userInfo['is_pop_up'] = 1; $userInfo['is_pop_up'] = 1;
...@@ -211,10 +242,17 @@ class UserService ...@@ -211,10 +242,17 @@ class UserService
"city" => !empty($params['city']) ? $params['city'] : '', "city" => !empty($params['city']) ? $params['city'] : '',
"language" => !empty($params['language']) ? $params['language'] : '', "language" => !empty($params['language']) ? $params['language'] : '',
]; ];
$user = UserWechatBind::getRecordMaster(['openid' => $params['openid']]);
if (empty($user)){
$update['openid'] = $params['openid'];
$bindStatus = UserWechatBind::save($update);
}else{
$bindStatus = UserWechatBind::save($update,['openid' => $params['openid']]); $bindStatus = UserWechatBind::save($update,['openid' => $params['openid']]);
}
if (!$bindStatus) { if (!$bindStatus) {
throw new UserException(['cus' => 8]); FileLog::error("bindAvatar:绑定头像失败", json_encode($params, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
FileLog::error("bindAvatar:绑定头像失败--update", json_encode($update, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
throw new UserException(['cus' => 11]);
} }
return $update; return $update;
} }
......
...@@ -31,6 +31,6 @@ exception.sys.msg = "系统未定义异常,研发正在赶来的路上..." ...@@ -31,6 +31,6 @@ exception.sys.msg = "系统未定义异常,研发正在赶来的路上..."
[prod : common : exception] [prod : common : exception]
[pre : common : exception] [perf : common : exception]
[test : common : exception] [test : common : exception]
[dev : common : exception] [dev : common : exception]
\ No newline at end of file
...@@ -11,6 +11,6 @@ idgen.partner = "bp" ...@@ -11,6 +11,6 @@ idgen.partner = "bp"
idgen.key = "5cfdb867e96374c7883b31d6928cc4cb" idgen.key = "5cfdb867e96374c7883b31d6928cc4cb"
[prod : common] [prod : common]
[pre : common ] [perf : common ]
[test: common ] [test: common ]
[dev : common ] [dev : common ]
\ No newline at end of file
...@@ -29,8 +29,10 @@ class Goods implements DaemonServiceInterface ...@@ -29,8 +29,10 @@ class Goods implements DaemonServiceInterface
GoodsSku::save($colums, $where); GoodsSku::save($colums, $where);
//更新es //更新es
GoodsService::updateGoodsInfoToEs($where['goods_sku_id']); GoodsService::updateGoodsInfoToEs($where['goods_sku_id']);
} }
$this->onlineGoods();
$this->onlineOffGoods();
} }
...@@ -53,4 +55,65 @@ class Goods implements DaemonServiceInterface ...@@ -53,4 +55,65 @@ class Goods implements DaemonServiceInterface
GoodsService::updateGoodsInfoToEs($where['goods_sku_id']); GoodsService::updateGoodsInfoToEs($where['goods_sku_id']);
} }
} }
/**
*
* 自动上线
*/
public function onlineGoods()
{
sleep(2);
$orderData = [
'online_type' => 2,
'online_status' => [0,2],
'audit_status' => 1,
'online_start_time[<]' => date("Y-m-d H:i:s",time()),
'online_end_time[>]' => date("Y-m-d H:i:s",time()),
'LIMIT' => 100,
];
$goodsList = GoodsSku::getRecords($orderData);
DaemonLog::info('DaemonServiceOnline_goods', json_encode($goodsList));
foreach ($goodsList as $key => $value) {
$where = [];
$where['goods_sku_id'] = !empty($value['goods_sku_id']) ? $value['goods_sku_id'] : '';
$colums = [
'online_status' => 1,
];
GoodsSku::save($colums, $where);
//更新es
GoodsService::updateGoodsInfoToEs($where['goods_sku_id']);
}
}
/**
*
* 自动下架
*/
public function onlineOffGoods()
{
sleep(2);
$orderData = [
'online_type' => 2,
'online_status' => 1,
'audit_status' => 1,
'online_end_time[<]' => date("Y-m-d H:i:s",time()),
'LIMIT' => 100,
];
$goodsList = GoodsSku::getRecords($orderData);
DaemonLog::info('DaemonServiceOnlineOff_goods', json_encode($goodsList));
foreach ($goodsList as $key => $value) {
$where = [];
$where['goods_sku_id'] = !empty($value['goods_sku_id']) ? $value['goods_sku_id'] : '';
$colums = [
'online_status' => 2,
];
GoodsSku::save($colums, $where);
//更新es
GoodsService::updateGoodsInfoToEs($where['goods_sku_id']);
}
}
} }
\ 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