配置修改
This commit is contained in:
@ -36,6 +36,9 @@ use app\common\server\UrlServer;
|
||||
use app\common\basics\Logic;
|
||||
use app\common\logic\AccountLogLogic;
|
||||
use app\common\model\AccountLog;
|
||||
use app\common\server\WeChatServer;
|
||||
use EasyWeChat\Factory;
|
||||
use EasyWeChat\Kernel\Http\StreamResponse;
|
||||
use think\Exception;
|
||||
use think\facade\Db;
|
||||
|
||||
@ -90,6 +93,7 @@ class DistributionLogic extends Logic
|
||||
*/
|
||||
public static function apply($post)
|
||||
{
|
||||
|
||||
$time = time();
|
||||
$data = [
|
||||
'user_id' => $post['user_id'],
|
||||
@ -101,9 +105,12 @@ class DistributionLogic extends Logic
|
||||
'reason' => $post['reason'],
|
||||
'status' => 0, // 待审核
|
||||
'create_time' => $time,
|
||||
'update_time' => $time,
|
||||
'update_time' => $time
|
||||
];
|
||||
return DistributionMemberApply::create($data);
|
||||
$result = DistributionMemberApply::create($data);
|
||||
$url = self::makeMpWechatQrcode($post['user_id']);
|
||||
User::update(['url'=>$url],['id'=>$post['user_id']]);
|
||||
return $result;
|
||||
}
|
||||
/**
|
||||
* 申请分销会员
|
||||
@ -234,7 +241,7 @@ class DistributionLogic extends Logic
|
||||
*/
|
||||
public static function myLeader($userId)
|
||||
{
|
||||
$field = 'nickname,avatar,is_distribution,mobile,first_leader,distribution_code,earnings';
|
||||
$field = 'url,nickname,avatar,is_distribution,mobile,first_leader,distribution_code,earnings';
|
||||
|
||||
$user = User::field($field)->where(['id' => $userId, 'del'=>0])->findOrEmpty();
|
||||
|
||||
@ -354,7 +361,52 @@ class DistributionLogic extends Logic
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 扫码微信二维码
|
||||
*/
|
||||
public static function wxCode($post,$user_id)
|
||||
{
|
||||
try {
|
||||
Db::startTrans();
|
||||
|
||||
$firstLeader = User::field(['id', 'first_leader', 'second_leader', 'third_leader', 'ancestor_relation','user_integral'])
|
||||
->where(['id' => $post['user_id']])
|
||||
->findOrEmpty();
|
||||
if($firstLeader->isEmpty()) {
|
||||
throw new \think\Exception('无效的二维码');
|
||||
}
|
||||
$user = User::where(['user_id' => $user_id])
|
||||
->find();
|
||||
if($user['first_leader'] != 0) {
|
||||
throw new \think\Exception('已扫码');
|
||||
}
|
||||
// 上级
|
||||
$first_leader_id = $firstLeader['id'];
|
||||
$data = [
|
||||
'first_leader' => $first_leader_id,
|
||||
'update_time' => time()
|
||||
];
|
||||
|
||||
// 更新当前用户的分销关系
|
||||
User::where(['id' => $post['user_id']])->update($data);
|
||||
//通知用户
|
||||
event('Notice', [
|
||||
'scene' => NoticeEnum::INVITE_SUCCESS_NOTICE,
|
||||
'params' => [
|
||||
'user_id' => $first_leader_id,
|
||||
'lower_id' => $post['user_id'],
|
||||
'join_time' => date('Y-m-d H:i:s', time())
|
||||
]
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 分销订单
|
||||
*/
|
||||
@ -606,4 +658,68 @@ class DistributionLogic extends Logic
|
||||
return ['poster'=>$poster];
|
||||
|
||||
}
|
||||
// 生成分销推广二维码
|
||||
public static function makeMpWechatQrcode($user_id, string $type = 'url', array $extra = [])
|
||||
{
|
||||
try {
|
||||
$width = 430;
|
||||
// 'env_version' => 'trial',
|
||||
// $envVersion = 'develop';
|
||||
$envVersion = 'release';
|
||||
$page = "pages/index/index";
|
||||
$save_dir = public_path() . 'uploads/wxqrcode/';
|
||||
// 确保目录存在
|
||||
if (!is_dir($save_dir)) {
|
||||
mkdir($save_dir, 0755, true);
|
||||
}
|
||||
$file_name = time() . '.png';
|
||||
$config = WeChatServer::getMnpConfig();
|
||||
$app = Factory::miniProgram($config);
|
||||
|
||||
$response = $app->app_code->getUnlimit('user_id='.$user_id, [
|
||||
// 'scene' => 'type=1',
|
||||
'page' => $page,
|
||||
'width' => $width,
|
||||
'auto_color' => false,
|
||||
'line_color' => ['r' => 0, 'g' => 0, 'b' => 0],
|
||||
'is_hyaline' => false,
|
||||
'env_version' => $envVersion,
|
||||
'check_path' => false,
|
||||
]);
|
||||
|
||||
if(is_array($response) && 41030 === $response['errcode']){
|
||||
|
||||
//开启错误提示,小程序未发布和页面不存在,返回提示
|
||||
if (41030 === $response['errcode']) {
|
||||
return '所传page页面不存在,或者小程序没有发布';
|
||||
}
|
||||
return $response['errmsg'];
|
||||
}
|
||||
|
||||
$contents = $response->getBody()->getContents();
|
||||
switch ($type){
|
||||
case 'file':
|
||||
if ($response instanceof StreamResponse) {
|
||||
$file_name = $response->saveAs($save_dir, $file_name);
|
||||
$contents = $save_dir . $file_name;
|
||||
}
|
||||
break;
|
||||
case 'url': // 保存并返回完整URL
|
||||
$full_path = $save_dir . $file_name;
|
||||
file_put_contents($full_path, $contents);
|
||||
// 生成完整的可访问URL(根据实际域名调整)
|
||||
$contents = request()->domain() . '/uploads/wxqrcode/' . $file_name;
|
||||
break;
|
||||
case 'base64':
|
||||
$mp_base64 = chunk_split(base64_encode($contents));
|
||||
$contents = 'data:image/png;base64,' . $mp_base64;
|
||||
break;
|
||||
}
|
||||
return data_success('',['qr_code'=>$contents, 'extra' => $extra]);
|
||||
|
||||
|
||||
} catch (\EasyWeChat\Kernel\Exceptions\Exception $e){
|
||||
return data_error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user