文件
mashangyoujiu/Application/Common/Business/XcxUser.class.php

159 行
5.0 KiB
PHP
可执行文件

<?php
namespace Common\Business;
use Common\Model\RetailSmallProgramUserModel;
use ShopCoupon\Model\ShopCouponRecordModel;
//[1.8.50]
/**
* 小程序用户类
* Class XcxUser
* [
* 根据会员id获取小程序用户信息 basisVipIdGetUser
* 根据的用户商家券的id获取openid basisCouponIdGetOpenid
* 小程序用户插入服务商下的openid modifyServiceOpenid
* 小程序用户列表 getXcxUserList
* ]
* @package Common\Business
*/
class XcxUser
{
/**
* 根据会员id获取小程序用户信息
* @param $param
* [
* merchant_id
* vip_id
* ]
* @return mixed
*/
public function basisVipIdGetUser($param)
{
try {
$xcxUserModel = new RetailSmallProgramUserModel();
$user = $xcxUserModel->getFind([
'merchant_id' => $param['merchant_id'],
'vid' => $param['vip_id']
]);
if (!empty($user)) {
return callBack(statusCode()['success'], "查询成功", $user);
} else {
return callBack(statusCode()['error'], "该会员未授权小程序");
}
} catch (\Exception $e) {
return callBack(statusCode()['error'], "该会员未授权小程序");
}
}
/**
* 根据的用户商家券的id获取openid
* @param $param
* [
* coupon_id 用户的商家券id
* ]
* @return mixed
*/
public function basisCouponIdGetOpenid($param)
{
$ShopCouponRecordModel = new ShopCouponRecordModel();
$xcx_info = $ShopCouponRecordModel->basisIdGetOpenid("x.service_openid,x.openid,x.ordinary_openid", [
's.id' => $param['coupon_id']
]);
return callBack(statusCode()['success'], "查询成功", ['xcx_info' => $xcx_info]);
}
/**
* 小程序用户插入服务商下的openid
* @param $param
* [
* xcx_id 小程序用户id
* openid 服务商获取的openid
* user_type 1普通支付模式 2服务商支付模式
* ]
* @return mixed
*/
public function modifyServiceOpenid($param)
{
switch ($param['user_type']) {
case 1:
//商户公众号
$data = [
'ordinary_openid' => $param['openid']
];
break;
case 2:
//服务商公众号
$data = [
'service_openid' => $param['openid']
];
break;
}
if (!empty($data)) {
$xcxUserModel = new RetailSmallProgramUserModel();
$xcxUserModel->updateOrder([
'id' => $param['xcx_id']
], $data);
return callBack(statusCode()['success'], "成功");
} else {
return callBack(statusCode()['success'], "openid修改失败");
}
}
/**
* 小程序用户列表
* @param $param
* [
* merchant_id
* vipSearchText 名称手机号
* page
* limit
* type 1商户小程序授权过 2商户公众号授权过 3服务商公众号授权过
* ]
* @return mixed
*/
public function getXcxUserList($param)
{
$page = $param['page'] ? $param['page'] : 1;
$limit = $param['limit'] ? $param['limit'] : 10;
$where = [
'x.merchant_id' => $param['merchant_id'],
];
if (!empty($param['vipSearchText'])) {
$param['vipSearchText'] = trim($param['vipSearchText']);
$where['v.name|v.nickname|v.mobile_phone'] = ['like', "%{$param['vipSearchText']}%"];
}
switch ($param['type']) {
case 1:
//用户在商户小程序授权过
$where['x.openid'] = ['neq', ''];
break;
case 2:
//用户在商户公众号授权过
$where['x.ordinary_openid'] = ['neq', ''];
break;
case 3:
//服务商公众号授权过
$where['x.service_openid'] = ['neq', ''];
break;
}
$fields = 'x.id,x.vid as vip_id,x.nickname as xcx_nickname,x.openid,x.service_openid,x.ordinary_openid,v.nickname,v.name,v.mobile_phone';
$xcxUserModel = new RetailSmallProgramUserModel();
$list = $xcxUserModel->getXcxUserList($fields, $where, $page, $limit);
if (!empty($list)) {
$count = $xcxUserModel->getXcxUserCount($where);
foreach ($list as &$val) {
if (empty($val['vip_id'])) {
$val['name'] = '非会员';
} else {
$val['name'] = $val['name'] ? $val['name'] : ($val['nickname'] ? $val['nickname'] : $val['xcx_nickname']);
}
}
}
return callBack(statusCode()['success'], "查询成功", ['list' => $list, 'count' => $count]);
}
}