Commit ab60db4e authored by pengfei's avatar pengfei

Merge branch 'colonel' into develop

parents 8521e4f0 d974dcc4
......@@ -59,7 +59,16 @@ class ColonelorderController extends Job
$this->getInviteOrderData($userIds, $colonelPayInfoData); // 完成目标单数
$this->getInviteNewUserData($userIds, $colonelPayInfoData); // 邀请新用户奖励
}
$this->handleSavePayInfo($colonelPayInfoData);
if (!empty($colonelPayInfoData)) {
try {
$this->loggerInfo('colonelPayInfoCount=' . count($colonelPayInfoData));
$colonelPayInfoData = $this->getFormatPayInfoData($colonelPayInfoData);
$this->handleSavePayInfo($colonelPayInfoData);
$this->loggerInfo('success');
} catch (Exception $e) {
$this->loggerError('error=' . $e->getMessage());
}
}
}
$this->loggerInfo('end');
}
......@@ -67,27 +76,23 @@ class ColonelorderController extends Job
/**
* Notes: 保存奖励信息
* User: pengfei@yidian-inc.com
* Date: 2021/9/3 4:34 下
* Date: 2021/9/7 10:40 上
* @param $colonelPayInfoData
* @throws Exception
*/
private function handleSavePayInfo($colonelPayInfoData)
{
$this->loggerInfo('colonelPayInfoCount=' . count($colonelPayInfoData));
if (!empty($colonelPayInfoData)) {
$data = $this->getFormatPayInfoData($colonelPayInfoData);
try {
ColonelDistributorPayInfo::beginTransaction();
if (!$this->addColonelDistributorPayInfo($data)) {
throw new Exception(sprintf("写入错误参数 %s", json_encode($data)));
}
if (!ColonelDistributorPayInfo::commit()) {
throw new Exception(sprintf("事务提交失败 %s", json_encode($data)));
}
$this->loggerInfo('success');
} catch (Exception $e) {
ColonelDistributorPayInfo::rollback();
$this->loggerError('error=' . $e->getMessage());
try {
ColonelDistributorPayInfo::beginTransaction();
if (!$this->addColonelDistributorPayInfo($colonelPayInfoData)) {
throw new Exception(sprintf("写入错误参数 %s", json_encode($colonelPayInfoData)));
}
if (!ColonelDistributorPayInfo::commit()) {
throw new Exception(sprintf("事务提交失败 %s", json_encode($colonelPayInfoData)));
}
} catch (Exception $e) {
ColonelDistributorPayInfo::rollback();
throw new Exception($e->getMessage());
}
}
......@@ -211,21 +216,26 @@ class ColonelorderController extends Job
/**
* Notes: 获取pay_info数据
* User: pengfei@yidian-inc.com
* Date: 2021/9/3 4:07 下
* Date: 2021/9/7 10:34 上
* @param $data
* @return array
* @throws Exception
*/
private function getFormatPayInfoData($data): array
{
$count = count($data);
$res = Idgen::get(appConfig('idgen.partner'), appConfig('idgen.key'), [], [
$httpParams = [
[
'type' => 'goods',
'number' => 00,
'count' => $count
]
]);
];
$res = Idgen::get(appConfig('idgen.partner'), appConfig('idgen.key'), [], $httpParams);
$ids = $res['id_datetime']['goods'] ?? [];
if ($count > count($ids)) {
throw new Exception('请求idgen服务失败,request:' . json_encode($httpParams) . ';response:' . json_encode($res));
}
foreach ($data as $key => $item) {
$data[$key]['pay_info_trade_id'] = $ids[$key];
}
......
......@@ -153,14 +153,15 @@ class ColonelService
}
// 审核状态数据检测
$applyInfo = ColonelDistributorColonelApply::getRecord(['colonel_apply_id' => $applyId]);
if (empty($applyInfo) || $applyInfo['audit_status'] != ColonelDistributorColonelApply::STATUS_AUDIT) {
if (empty($applyInfo) || $applyInfo['audit_status'] == ColonelDistributorColonelApply::STATUS_PASS) {
throw new MarketingException(MarketingException::COLONEL_AUDIT_STATUS_USE);
}
try {
ColonelDistributorColonelApply::beginTransaction();
// 修改申请状态
$updateStatus = ColonelDistributorColonelApply::updateRecord(['audit_status' => $auditStatus],
['colonel_apply_id' => $applyId, 'audit_status' => ColonelDistributorColonelApply::STATUS_AUDIT]);
['colonel_apply_id' => $applyId, 'audit_status' => ColonelDistributorColonelApply::STATUS_AUDIT]
);
if (empty($updateStatus)) {
throw new MarketingException(MarketingException::COLONEL_AUDIT_STATUS_FAILED);
}
......
......@@ -3,6 +3,7 @@
namespace App\Services\user;
use Api\PhpUtils\Mon\MonUtil;
use App\Models\user\mysql\UserWechatBind;
use Api\PhpUtils\Http\Request;
use App\Services\user\Weixin\WxBizDataCrypt;;
......@@ -29,36 +30,42 @@ class UserService
$code = !empty($params['code']) ? $params['code'] : '';//小程序授权code
$openid = !empty($params['openid']) ? $params['openid'] : '';//小程序授权code
if (empty($code) && empty($openid)) {
FileLog::error("wechatLogin:获取参数为空", json_encode($params, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
FileLog::error("wechatLogin:获取参数为空", json_encode($params, JSON_UNESCAPED_UNICODE), '', 'jianghaiming@yidian-inc.com');
throw new UserException(['cus' => 0]);
}
//需要授权微信
//if (empty($openid)) {
$appid = \Yaf\Registry::get('config')->wechat->appid;
$secret = \Yaf\Registry::get('config')->wechat->secret;
$grant_type = 'authorization_code';
$loginUrl = 'https://api.weixin.qq.com/sns/jscode2session';
//请求接口,获取用户openid
$params = [
'appid' => $appid,
'secret' => $secret,
'js_code' => $code,
'grant_type' => $grant_type,
];
$response = (new Request())->post($loginUrl, $params);
if ($response['code'] == 0) {
$response = $response['response'];
}
$appid = \Yaf\Registry::get('config')->wechat->appid;
$secret = \Yaf\Registry::get('config')->wechat->secret;
$grant_type = 'authorization_code';
$loginUrl = 'https://api.weixin.qq.com/sns/jscode2session';
//请求接口,获取用户openid
$params = [
'appid' => $appid,
'secret' => $secret,
'js_code' => $code,
'grant_type' => $grant_type,
];
$begin = microtime(true);
$response = (new Request())->post($loginUrl, $params);
if (empty($response) || array_key_exists('errcode', $response)) {
//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]);
}
//检查系统是已注册
$openid = !empty($response['openid']) ? $response['openid'] : '';
$end = microtime(true);
$totalTime = round(($end - $begin), 4) * 1000;
if ($response['code'] == 0) {
$response = $response['response'];
}
//mon打点
$env = Application::app()->environ() ?? "dev";
MonUtil::proxyMon($loginUrl, $response['code'], 'weixin_'.$env, $totalTime);
if (empty($response) || array_key_exists('errcode', $response)) {
//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]);
}
//检查系统是已注册
$openid = !empty($response['openid']) ? $response['openid'] : '';
//}
......@@ -75,34 +82,34 @@ class UserService
$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")]);
$newWechatId = UserWechatBind::insertDuplicate($insert, ['session_key' => $sessionKey, 'create_time' => date("Y-m-d H:i:s")]);
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');
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]);
}
$user['wechat_id'] = $newWechatId;
$user['openid'] = $response['openid'];
$user['session_key'] = $response['session_key'];
}else{
} else {
if (empty($user)) {
FileLog::error("wechatLogin:登陆创建用户失败-- 微信response", json_encode($response, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
FileLog::error("wechatLogin:登陆创建用户失败-- 微信response", json_encode($response, JSON_UNESCAPED_UNICODE), '', 'jianghaiming@yidian-inc.com');
throw new UserException(['cus' => 2]);
}
if (empty($response)){
FileLog::error("wechatLogin:登陆创建用户失败-- 微信response 获取失败", json_encode($params, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
if (empty($response)) {
FileLog::error("wechatLogin:登陆创建用户失败-- 微信response 获取失败", json_encode($params, JSON_UNESCAPED_UNICODE), '', 'jianghaiming@yidian-inc.com');
throw new UserException(['cus' => 2]);
}
$insert = [
'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);
return $user;
return $user;
}
/**
......@@ -117,9 +124,9 @@ class UserService
{
$openid = !empty($params['openid']) ? $params['openid'] : '';
$encryptedData = !empty($params['encryptedData']) ? $params['encryptedData'] : '';
$iv = !empty($params['iv']) ? $params['iv'] : '';
$iv = !empty($params['iv']) ? $params['iv'] : '';
$appid = \Yaf\Registry::get('config')->wechat->appid;
if (!$encryptedData) {
FileLog::error("bindPhone:encryptedData 为空", json_encode($params, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
throw new UserException(['cus' => 3]);
......@@ -204,7 +211,7 @@ class UserService
public static function userWechatBind($params)
{
$data['wechat_id[>]'] = 0;
if (!empty($params['openid'])) {
......@@ -218,7 +225,7 @@ class UserService
if (!empty($params['phone'])) {
$data['phone'] = $params['phone'];
}
$userList = UserWechatBind::getRecords($data);
return $userList;
}
......
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