1.缺失信息提交

This commit is contained in:
2025-05-07 12:10:19 +08:00
parent 066c3c3420
commit 4da5dc858a
17 changed files with 2209 additions and 6 deletions

View File

@ -15,6 +15,7 @@
namespace app\common\logic;
use app\common\enum\user\AccountLogEnum;
use app\common\model\account\AccountLog;
use app\common\model\user\UserAccountLog;
use app\common\model\user\User;
@ -73,4 +74,62 @@ class AccountLogLogic extends BaseLogic
];
return UserAccountLog::create($data);
}
/**
* Notes:记录会员账户流水,如果变动类型是成长值,且是增加的,则调用更新会员等级方法。该方法应在添加用户账户后调用
* @author: cjh 2020/12/15 11:49
* @param int $user_id 用户id
* @param float $amount 变动数量
* @param int $change_type 变动类型1-增加2-减少
* @param int $source_type 来源类型
* @param string $remark 说明
* @param string $source_id 来源id
* @param string $source_sn 来源单号
* @param string $extra 额外字段说明
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public static function AccountRecord($user_id,$amount,$change_type,$source_type,$remark ='',$source_id ='',$source_sn='',$extra=''){
$user = User::get($user_id);
if(empty($user)){
return false;
}
$type = AccountLog::getChangeType($source_type);
$left_amount = '';
switch ($type){
case 'money':
$left_amount = $user->user_money;
break;
case 'integral':
$left_amount = $user->user_integral;
break;
case 'growth':
$left_amount = $user->user_growth;
break;
case 'earnings':
$left_amount = $user->earnings;
}
$account_log = new AccountLog();
$account_log->log_sn = createSn('account_log','log_sn','',4);
$account_log->user_id = $user_id;
$account_log->source_type = $source_type;
$account_log->source_id = $source_id;
$account_log->source_sn = $source_sn;
$account_log->change_amount = $amount;
$account_log->left_amount = $left_amount;
$account_log->remark = AccountLog::getRemarkDesc($source_type,$source_sn,$remark);
$account_log->extra = $extra;
$account_log->change_type = $change_type;
$account_log->create_time = time();
$account_log->save();
//更新会员等级
if($type === 'growth' && $change_type == 1){
UserLevelLogic::updateUserLevel($user_id);
}
return true;
}
}

View File

@ -0,0 +1,60 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\logic;
use app\common\model\distribution\Distribution;
use app\common\model\distribution\DistributionLevel;
use app\common\service\ConfigServer;
/**
* 分销基础信息逻辑层
* Class DistributionLogic
* @package app\common\logic
*/
class DistributionLogic
{
/**
* @notes 添加分销基础信息记录
* @param $userId
* @author Tab
*/
public static function add($userId)
{
// 默认分销会员等级
$defaultLevelId = DistributionLevel::where('is_default', 1)->value('id');
// 分销会员开通方式
$apply_condition = ConfigServer::get('distribution', 'apply_condition', 2);
$isDistribution = $apply_condition == 1 ? 1 : 0;
$data = [
'user_id' => $userId,
'level_id' => $defaultLevelId,
'is_distribution' => $isDistribution,
'is_freeze' => 0,
'remark' => '',
];
if($isDistribution) {
// 成为分销会员时间
$data['distribution_time'] = time();
}
Distribution::create($data);
}
}

View File

@ -0,0 +1,64 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\logic;
use think\facade\Db;
class UserLevelLogic{
/**
* note 用户升级 更新个人会员等级
* create_time 2020/11/26 18:52
*/
public static function updateUserLevel($id){
$user = Db::name('user')->where(['id'=>$id])->field('user_growth,level')->find();
$level = Db::name('user_level')
->where([['growth_value','<=',$user['user_growth']],['del','=',0]])
->order('growth_value desc')
->find();
if($level){
$growth_value = 0;
$user['level'] > 0 && $growth_value = Db::name('user_level')->where(['id'=>$user['level']])->value('growth_value');
if($level['growth_value'] > $growth_value){
Db::name('user')->where(['id'=>$id])->update(['level'=>$level['id'],'update_time'=>time()]);
}
}
return true;
}
/**
* note 用户升级 更新所有用户的等级
* create_time 2020/11/26 19:11
*/
public static function updateAllUserLevel($level_id){
$growth_value = Db::name('user_level')->where(['id'=>$level_id])->value('growth_value');
$no_update_user_ids = Db::name('user')->alias('U')
->join('user_level L','U.level = L.id')
->where('L.growth_value','>',$growth_value)
->column('U.id');
return Db::name('user')
->where([
['id','not in',$no_update_user_ids],
['del','=',0],
['user_growth','>=',$growth_value],
])->update(['level'=>$level_id,'update_time'=>time()]);
}
}

View File

@ -0,0 +1,70 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\model;
class Client_
{
const mnp = 1;//小程序
const oa = 2;//公众号
const ios = 3;
const android = 4;
const pc = 5;
const h5 = 6;//h5(非微信环境h5)
function getName($value)
{
switch ($value) {
case self::mnp:
$name = '小程序';
break;
case self::h5:
$name = 'h5';
break;
case self::ios:
$name = '苹果';
break;
case self::android:
$name = '安卓';
break;
case self::oa:
$name = '公众号';
break;
}
return $name;
}
public static function getClient($type = true)
{
$desc = [
self::pc => 'pc商城',
self::h5 => 'h5商城',
self::oa => '公众号商城',
self::mnp => '小程序商城',
self::ios => '苹果APP商城',
self::android => '安卓APP商城',
];
if ($type === true) {
return $desc;
}
return $desc[$type] ?? '未知';
}
}

View File

@ -0,0 +1,170 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\model\account;
use think\Model;
class AccountLog extends Model{
/*******************************
** 余额变动100~199
** 积分变动200~299
** 成长值变动300~399
** 佣金变动: 400~499
*******************************/
const admin_add_money = 100;
const admin_reduce_money = 101;
const recharge_money = 102;
const balance_pay_order = 103;
const cancel_order_refund = 104;
const after_sale_refund = 105;
const withdraw_to_balance = 106;
const user_transfer_inc_balance = 107;
const user_transfer_dec_balance = 108;
const luck_draw_inc_balance = 109;
const admin_add_integral = 200;
const admin_reduce_integral = 201;
const sign_in_integral = 202;
const recharge_give_integral = 203;
const order_add_integral = 204;
const register_add_integral = 205;
const invite_add_integral = 206;
const order_deduction_integral = 207;
const cancel_order_refund_integral = 208;
const luck_draw_integral = 209;
const deduct_order_first_integral = 210;
const order_goods_give_integral = 211;
const luck_draw_dec_integral = 212;
const admin_add_growth = 300;
const admin_reduce_growth = 301;
const sign_give_growth = 302;
const recharge_give_growth = 303;
const order_give_growth = 304;//下单赠送成长值
const withdraw_dec_earnings = 400;//提现扣减佣金
const withdraw_back_earnings = 401;//提现被拒绝返回佣金
const distribution_inc_earnings = 402;//分销订单结算增加佣金
const admin_inc_earnings = 403; //后台增加佣金
const admin_reduce_earnings = 404; //后台减少佣金
const money_change = [ //余额变动类型
self::admin_add_money,self::admin_reduce_money,self::recharge_money,self::balance_pay_order,self::cancel_order_refund,self::after_sale_refund
, self::withdraw_to_balance,self::user_transfer_inc_balance, self::user_transfer_dec_balance, self::luck_draw_inc_balance
];
const integral_change = [ //积分变动类型
self::admin_add_integral,self::admin_reduce_integral,self::sign_in_integral,self::recharge_give_integral,self::order_add_integral,self::invite_add_integral
, self::order_deduction_integral,self::register_add_integral,self::cancel_order_refund_integral,self::luck_draw_integral,self::deduct_order_first_integral
, self::order_goods_give_integral, self::luck_draw_dec_integral
];
const growth_change = [ //成长值变动类型
self::admin_add_growth,self::admin_reduce_growth,self::recharge_give_growth,self::sign_give_growth, self::order_give_growth
];
const earnings_change = [ //佣金变动
self::withdraw_dec_earnings, self::withdraw_back_earnings, self::distribution_inc_earnings, self::admin_inc_earnings, self::admin_reduce_earnings
];
public static function getAcccountDesc($from = true){
$desc = [
self::admin_add_money => '系统增加余额',
self::admin_reduce_money => '系统扣减余额',
self::recharge_money => '用户充值余额',
self::admin_add_integral => '系统增加积分',
self::admin_reduce_integral => '系统扣减积分',
self::sign_in_integral => '每日签到赠送积分',
self::recharge_give_integral => '充值赠送积分',
self::order_add_integral => '下单赠送积分',
self::order_deduction_integral => '下单积分抵扣',
self::register_add_integral => '注册赠送积分',
self::invite_add_integral => '邀请会员赠送积分',
self::admin_add_growth => '系统增加成长值',
self::admin_reduce_growth => '系统扣减成长值',
self::sign_give_growth => '每日签到赠送成长值',
self::recharge_give_growth => '充值赠送成长值',
self::balance_pay_order => '下单扣减余额',
self::cancel_order_refund => '取消订单退回余额',
self::after_sale_refund => '售后退回余额',
self::withdraw_to_balance => '佣金提现',
self::withdraw_dec_earnings => '提现扣减佣金',
self::withdraw_back_earnings => '拒绝提现返还佣金',
self::distribution_inc_earnings => '订单结算获得佣金',
self::cancel_order_refund_integral => '取消订单退回积分',
self::deduct_order_first_integral => '扣除首单积分',
self::luck_draw_integral => '积分抽奖中奖',
self::order_goods_give_integral => '购买商品赠送积分',
self::user_transfer_inc_balance => '会员转账(收入方)',
self::user_transfer_dec_balance => '会员转账(支出方)',
self::order_give_growth => '下单赠送成长值',
self::admin_inc_earnings => '后台增加佣金',
self::admin_reduce_earnings => '后台减少佣金',
self::luck_draw_dec_integral => '积分抽奖消耗积分',
self::luck_draw_inc_balance => '积分抽奖中奖余额',
];
if($from === true){
return $desc;
}
return $desc[$from] ?? '';
}
//返回变动类型
public static function getChangeType($from){
$type = '';
if(in_array($from,self::money_change)){
$type = 'money';
}
if(in_array($from,self::integral_change)){
$type = 'integral';
}
if(in_array($from,self::growth_change)){
$type = 'growth';
}
if(in_array($from,self::earnings_change)){
$type = 'earnings';
}
return $type;
}
public static function getRemarkDesc($from,$source_sn,$remark =''){
return $remark;
}
public static function getChangeAmountAttr($value,$data){
$amount = $value;
if(!in_array($data['source_type'],self::money_change)){
$amount = intval($value);
}
if($data['change_type'] == 1){
return '+'.$amount;
}
return '-'.$amount;
}
public static function getSourceTypeAttr($value,$data){
return self::getAcccountDesc($value);
}
public static function getcreateTimeAttr($value,$data){
if($value){
return date('Y-m-d H:i:s',$value);
}
return '';
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace app\common\model\distribution;
use think\Model;
use think\model\concern\SoftDelete;
class Distribution extends Model
{
use SoftDelete;
protected $deleteTime = 'delete_time';
public function getDistributionTimeAttr($value)
{
return empty($value) ? '' : date('Y-m-d H:i:s', $value);
}
}

View File

@ -0,0 +1,64 @@
<?php
namespace app\common\model\distribution;
use app\common\model\Distribution;
use think\Model;
use think\model\concern\SoftDelete;
class DistributionLevel extends Model
{
use SoftDelete;
protected $deleteTime = 'delete_time';
/**
* 升级条件允许的字段
* singleConsumptionAmount 单笔消费金额
* cumulativeConsumptionAmount 累计消费金额
* cumulativeConsumptionTimes 累计消费次数
* returnedCommission 已结算佣金收入
*/
const UPDATE_CONDITION_FIELDS = ['singleConsumptionAmount', 'cumulativeConsumptionAmount', 'cumulativeConsumptionTimes', 'returnedCommission'];
public static function getValueFiled($key)
{
switch($key) {
case 'singleConsumptionAmount':
case 'cumulativeConsumptionAmount':
case 'returnedCommission':
return 'value_decimal';
case 'cumulativeConsumptionTimes':
return 'value_int';
default:
return 'value_text';
}
}
public function getWeightsDescAttr($value, $data)
{
return $data['is_default'] ? $value . '级(默认等级)' : $value . '级';
}
public function getMembersNumAttr($value, $data)
{
$num = Distribution::where('level_id', $data['id'])->count();
return $num;
}
public static function getLevelName($levelId)
{
$level = self::field('name,weights')->findOrEmpty($levelId)->toArray();
if (empty($level)) {
return '';
}
return $level['name']. '(' . $level['weights'] . ')级';
}
public static function getLevelNameTwo($levelId)
{
$level = self::field('name,weights')->findOrEmpty($levelId)->toArray();
if (empty($level)) {
return '';
}
return $level['name'];
}
}

View File

@ -0,0 +1,269 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\model\noticesetting;
use think\Model;
/**
* 通知场景
* Class Notice
* @package app\common\model
*/
class NoticeSetting extends Model
{
protected $name = 'dev_notice_setting';
//设置json
// protected $json = ['variable', 'system_notice', 'sms_notice', 'oa_notice', 'mnp_notice'];
// protected $jsonAssoc = true;
//通知类型
const SYSTEM_NOTICE = 1;
const SMS_NOTICE = 2;
const OA_NOTICE = 3;
const MNP_NOTICE = 4;
//通知对象
const NOTICE_PLATFORM = 1; //通知平台
const NOTICE_USER = 2; //通知会员
const NOTICE_OTHER = 3; //通知游客(如新用户注册)
//通知会员
const ORDER_PAY_NOTICE = 100;//订单已支付
const ORDER_DELIVERY_NOTICE = 101;//订单已发货
const PLATFORM_PASS_REFUND_NOTICE = 102;//平台通过售后退款通知
const PLATFORM_REFUSE_REFUND_NOTICE = 103;//平台拒绝售后退款通知
const REGISTER_NOTICE = 104;//注册通知
const CHANGE_MOBILE_NOTICE = 105;//变更手机号短信通知
const GET_BACK_MOBILE_NOTICE = 106;//重置密码短信通知
const REGISTER_SUCCESS_NOTICE = 107;//注册成功
const INVITE_SUCCESS_NOTICE = 108;//邀请成功
const GET_EARNINGS_NOTICE = 109;//获得收益
const GET_GODE_LOGIN_NOTICE = 110;//验证码登录
const BIND_MOBILE_NOTICE = 111;//绑定手机号
const GET_BACK_PAY_CODE_NOTICE = 112;//找回支付密码
//通知平台
const USER_PAID_NOTICE_PLATFORM = 200;//会员支付下单通知平台
const AFTER_SALE_NOTICE_PLATFORM = 201;//会员发起售后退款通知
//订单相关场景
const ORDER_SCENE = [
self::ORDER_PAY_NOTICE,
self::ORDER_DELIVERY_NOTICE,
self::PLATFORM_PASS_REFUND_NOTICE,
self::PLATFORM_REFUSE_REFUND_NOTICE,
];
//通知平台的场景
const NOTICE_PLATFORM_SCENE = [
self::USER_PAID_NOTICE_PLATFORM,
self::AFTER_SALE_NOTICE_PLATFORM,
];
//通知会员的场景
const NOTICE_USER_SCENE = [
self::ORDER_PAY_NOTICE,
self::ORDER_DELIVERY_NOTICE,
self::PLATFORM_PASS_REFUND_NOTICE,
self::PLATFORM_REFUSE_REFUND_NOTICE,
self::CHANGE_MOBILE_NOTICE,
self::GET_BACK_MOBILE_NOTICE,
self::REGISTER_SUCCESS_NOTICE,
self::INVITE_SUCCESS_NOTICE,
self::GET_EARNINGS_NOTICE,
];
//通知游客(还不存在当前系统的人)
const NOTICE_OTHER_SCENE = [
self::REGISTER_NOTICE
];
//验证码的场景
const NOTICE_NEED_CODE = [
self::REGISTER_NOTICE,
self::CHANGE_MOBILE_NOTICE,
self::GET_BACK_MOBILE_NOTICE,
self::GET_GODE_LOGIN_NOTICE,
self::BIND_MOBILE_NOTICE,
self::GET_BACK_PAY_CODE_NOTICE,
];
//场景值-兼容旧短信场景逻辑
const SMS_SCENE = [
'DDZFTZ' => self::ORDER_PAY_NOTICE,
'DDFHTZ' => self::ORDER_DELIVERY_NOTICE,
'SJTYSHTK' => self::PLATFORM_PASS_REFUND_NOTICE,
'SJJJSHTK' => self::PLATFORM_REFUSE_REFUND_NOTICE,
'ZCYZ' => self::REGISTER_NOTICE,
'ZHMM' => self::GET_BACK_MOBILE_NOTICE,
'DDTZ' => self::USER_PAID_NOTICE_PLATFORM,
'SHTKDDTZ' => self::AFTER_SALE_NOTICE_PLATFORM,
'YZMDL' => self::GET_GODE_LOGIN_NOTICE,
'BGSJHM' => self::CHANGE_MOBILE_NOTICE,
'BDSJHM' => self::BIND_MOBILE_NOTICE,
'ZHZFMM' => self::GET_BACK_PAY_CODE_NOTICE,
];
/**
* Notes: 获取场景描述
* @param $state
* @return array|mixed|string
* @author 段誉(2021/4/26 16:15)
*/
public static function getSceneDesc($state)
{
$data = [
self::ORDER_PAY_NOTICE => '订单已支付',
self::ORDER_DELIVERY_NOTICE => '订单已发货',
self::PLATFORM_PASS_REFUND_NOTICE => '平台通过售后退款通知',
self::PLATFORM_REFUSE_REFUND_NOTICE => '平台拒绝售后退款通知',
self::REGISTER_NOTICE => '注册通知',
self::CHANGE_MOBILE_NOTICE => '变更手机号短信通知',
self::GET_BACK_MOBILE_NOTICE => '重置密码短信通知',
self::REGISTER_SUCCESS_NOTICE => '注册成功',
self::INVITE_SUCCESS_NOTICE => '邀请成功',
self::GET_EARNINGS_NOTICE => '获得收益',
self::GET_GODE_LOGIN_NOTICE => '验证码登录',
self::BIND_MOBILE_NOTICE => '绑定手机号',
self::GET_BACK_PAY_CODE_NOTICE => '找回支付密码',
self::USER_PAID_NOTICE_PLATFORM => '会员支付下单通知平台',
self::AFTER_SALE_NOTICE_PLATFORM => '会员发起售后退款通知',
];
if ($state === true) {
return $data;
}
return $data[$state] ?? '';
}
/**
* Notes: 根据场景获取跳转地址
* @param $scene
* @author 段誉(2021/4/27 17:01)
* @return array
*/
public static function getPathByScene($scene, $extra_id)
{
$page = '/pages/index/index'; // 小程序主页路径
$url = '/mobile/pages/index/index'; // 公众号主页路径
if (in_array($scene, self::ORDER_SCENE)) {
$url = '/mobile/pages/order_details/order_details?id='.$extra_id;
$page = '/pages/order_details/order_details?id='.$extra_id;
}
return ['url' => $url, 'page' => $page];
}
/**
* Notes: 场景名称
* @param $value
* @param $data
* @author 段誉(2021/4/26 16:56)
* @return array|mixed|string
*/
public function getSceneAttr($value, $data)
{
return self::getSceneDesc($value);
}
/**
* Notes: 场景变量
* @param $value
* @param $data
* @author 段誉(2021/4/26 17:07)
* @return mixed
*/
public function getVariableAttr($value, $data)
{
return $this->jsonToArr($value);
}
/**
* Notes: 系统消息
* @param $value
* @param $data
* @author 段誉(2021/4/26 17:18)
* @return array|mixed
*/
public function getSystemNoticeAttr($value, $data)
{
return $this->jsonToArr($value);
}
/**
* Notes: 短信消息
* @param $value
* @param $data
* @author 段誉(2021/4/26 17:25)
* @return array|mixed
*/
public function getSmsNoticeAttr($value, $data)
{
return $this->jsonToArr($value);
}
/**
* Notes: 公众号消息
* @param $value
* @param $data
* @author 段誉(2021/4/26 17:25)
* @return array|mixed
*/
public function getOaNoticeAttr($value, $data)
{
return $this->jsonToArr($value);
}
/**
* Notes: 小程序消息
* @param $value
* @param $data
* @author 段誉(2021/4/26 17:25)
* @return array|mixed
*/
public function getMnpNoticeAttr($value, $data)
{
return $this->jsonToArr($value);
}
public function jsonToArr($data)
{
return empty($data) ? [] : json_decode($data, JSON_UNESCAPED_UNICODE);
}
}

View File

@ -20,7 +20,8 @@ use app\common\enum\user\UserEnum;
use app\common\model\BaseModel;
use app\common\service\FileService;
use think\model\concern\SoftDelete;
use think\Model;
use think\facade\Db;
/**
* 用户模型
* Class User
@ -32,6 +33,16 @@ class User extends BaseModel
protected $deleteTime = 'delete_time';
public static function get(int $user_id)
{
$list = Db::name('user')->where("id",$user_id)->find();
// $objList = array_map(function ($item) {
// return (object) $item;
// }, $list);
return (object) $list;
// return $objList;
}
/**
* @notes 关联用户授权模型

View File

@ -0,0 +1,190 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\service;
use app\common\model\Client_;
use app\common\model\Pay;
use app\common\service\ConfigServer;
use think\Db;
use think\Exception;
class WeChatServer
{
/**
* 获取小程序配置
* @return array
*/
public static function getMnpConfig()
{
$config = [
'app_id' => ConfigServer::get('mnp', 'app_id'),
'secret' => ConfigServer::get('mnp', 'secret' ),
'mch_id' => ConfigServer::get('mnp', 'mch_id'),
'key' => ConfigServer::get('mnp', 'key'),
'response_type' => 'array',
'log' => [
'level' => 'debug',
'file' => '../runtime/log/wechat.log'
],
];
return $config;
}
/**
* 获取微信公众号配置
* @return array
*/
public static function getOaConfig()
{
$config = [
'app_id' => ConfigServer::get('oa', 'app_id'),
'secret' => ConfigServer::get('oa', 'secret'),
'mch_id' => ConfigServer::get('oa', 'mch_id'),
'key' => ConfigServer::get('oa', 'key'),
'token' => ConfigServer::get('oa', 'token',''),
'response_type' => 'array',
'log' => [
'level' => 'debug',
'file' => '../runtime/log/wechat.log'
],
];
return $config;
}
/**
* 获取微信开放平台应用配置
* @return array
*/
public static function getOpConfig()
{
$config = [
'app_id' => ConfigServer::get('op', 'app_id'),
'secret' => ConfigServer::get('op', 'secret'),
'response_type' => 'array',
'log' => [
'level' => 'debug',
'file' => '../runtime/log/wechat.log'
],
];
return $config;
}
/**
* 根据不同来源获取支付配置
*/
public static function getPayConfigBySource($order_source)
{
$notify_url = '';
switch ($order_source) {
case Client_::mnp:
$notify_url = url('payment/notifyMnp', '', '', true);
break;
case Client_::oa:
case Client_::pc:
case Client_::h5:
$notify_url = url('payment/notifyOa', '', '', true);
break;
case Client_::android:
case Client_::ios:
$notify_url = url('payment/notifyApp', '', '', true);
break;
}
$config = self::getPayConfig($order_source);
if (empty($config) ||
empty($config['key']) ||
empty($config['mch_id']) ||
empty($config['app_id']) ||
empty($config['secret'])
) {
throw new Exception('请在后台配置好微信支付');
}
return [
'config' => $config,
'notify_url' => $notify_url,
];
}
//===================================支付配置=======================================================
//微信支付设置 H5支付 appid 可以是公众号appid
public static function getPayConfig($client)
{
switch ($client) {
case Client_::mnp:
$appid = ConfigServer::get('mnp', 'app_id');
$secret = ConfigServer::get('mnp', 'secret');
break;
case Client_::oa:
case Client_::pc:
case Client_::h5:
$appid = ConfigServer::get('oa', 'app_id');
$secret = ConfigServer::get('oa', 'secret');
break;
case Client_::android:
case Client_::ios:
$appid = ConfigServer::get('op', 'app_id');
$secret = ConfigServer::get('op', 'secret');
break;
default:
$appid = '';
$secret = '';
}
$pay = Pay::where(['code' => 'wechat'])->find()->toArray();
$config = [
'app_id' => $appid,
'secret' => $secret,
'mch_id' => $pay['config']['mch_id'] ?? '',
'key' => $pay['config']['pay_sign_key'] ?? '',
'cert_path' => $pay['config']['apiclient_cert'] ?? '',
'key_path' => $pay['config']['apiclient_key'] ?? '',
'response_type' => 'array',
'log' => [
'level' => 'debug',
'file' => '../runtime/log/wechat.log'
],
];
if (is_cli()) {
$config['cert_path'] = ROOT_PATH.'/public/'.$pay['config']['apiclient_cert'];
$config['key_path'] = ROOT_PATH.'/public/'.$pay['config']['apiclient_key'];
}
return $config;
}
}