1.缺失信息提交
This commit is contained in:
57
app/api/cache/TokenCache.php
vendored
Normal file
57
app/api/cache/TokenCache.php
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
<?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\api\cache;
|
||||
|
||||
|
||||
use app\common\cache\CacheBase;
|
||||
use think\facade\Db;
|
||||
use think\facade\Config;
|
||||
|
||||
class TokenCache extends CacheBase
|
||||
{
|
||||
|
||||
public function setTag()
|
||||
{
|
||||
return 'token';
|
||||
}
|
||||
|
||||
/**
|
||||
* 子类实现查出数据
|
||||
* @return mixed
|
||||
*/
|
||||
public function setData()
|
||||
{
|
||||
//刷新token过期时间
|
||||
$time = time();
|
||||
$expire_time = $time + Config::get('project.token_expire_time');
|
||||
Db::name('session')
|
||||
->where(['token' => $this->extend['token']])
|
||||
->update(['update_time' => $time, 'expire_time' => $expire_time]);
|
||||
|
||||
//返回用户信息
|
||||
$user_info = Db::name('user u')
|
||||
->join('session s', 'u.id=s.user_id')
|
||||
->where(['s.token' => $this->extend['token']])
|
||||
->field('u.*,s.token,s.client')
|
||||
->find();
|
||||
return $user_info;
|
||||
}
|
||||
}
|
||||
@ -21,7 +21,7 @@
|
||||
namespace app\api\controller;
|
||||
use app\api\logic\LoginLogic;
|
||||
use app\api\validate\WechatLoginValidate;
|
||||
use app\common\server\ConfigServer;
|
||||
use app\common\service\ConfigServer;
|
||||
|
||||
class AccountController extends BaseApiController
|
||||
{
|
||||
@ -250,10 +250,10 @@ class AccountController extends BaseApiController
|
||||
{
|
||||
$post = $this->request->post();
|
||||
if (empty($post['code']) || empty($post['nickname'])) {
|
||||
$this->_error('参数缺失');
|
||||
return $this->fail('参数缺失');
|
||||
}
|
||||
$data = LoginLogic::authLogin($post);
|
||||
$this->_success($data['msg'], $data['data'], $data['code'], $data['show']);
|
||||
return $this->success("登录成功",$data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
642
app/api/logic/DistributionLogic.php
Normal file
642
app/api/logic/DistributionLogic.php
Normal file
@ -0,0 +1,642 @@
|
||||
<?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\api\logic;
|
||||
|
||||
use app\common\logic\AccountLogLogic;
|
||||
use app\common\model\{AccountLog, AfterSale, DistributionOrder, NoticeSetting, Order, User};
|
||||
use app\common\service\{AreaServer, ConfigServer, UrlServer};
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use think\facade\Hook;
|
||||
|
||||
class DistributionLogic
|
||||
{
|
||||
/**
|
||||
* 填写邀请码
|
||||
* @param $code
|
||||
* @param $my_id
|
||||
* @return bool|string
|
||||
*/
|
||||
public static function code($code, $my_id)
|
||||
{
|
||||
try {
|
||||
Db::startTrans();
|
||||
|
||||
$my_leader = Db::name('user')
|
||||
->field(['id', 'first_leader', 'second_leader', 'third_leader', 'ancestor_relation'])
|
||||
->where(['distribution_code' => $code])
|
||||
->find();
|
||||
|
||||
//更新我的第一上级、第二上级、第三上级、关系链
|
||||
$my_leader_id = $my_leader['id'];
|
||||
$my_first_leader = $my_leader['first_leader'];
|
||||
$my_third_leader = $my_leader['second_leader'];
|
||||
$my_leader['ancestor_relation'] = boolval($my_leader['ancestor_relation']) ? $my_leader['ancestor_relation'] : '';
|
||||
$my_ancestor_relation = trim("{$my_leader_id},{$my_leader['ancestor_relation']}", ',');
|
||||
|
||||
$user = User::findOrEmpty($my_id);
|
||||
// 旧关系链
|
||||
if (!empty($user->ancestor_relation)) {
|
||||
$old_ancestor_relation = $user->id . ',' .$user->ancestor_relation;
|
||||
} else {
|
||||
$old_ancestor_relation = $user->id;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'first_leader' => $my_leader_id,
|
||||
'second_leader' => $my_first_leader,
|
||||
'third_leader' => $my_third_leader,
|
||||
'ancestor_relation' => $my_ancestor_relation,
|
||||
];
|
||||
Db::name('user')
|
||||
->where(['id' => $my_id])
|
||||
->update($data);
|
||||
|
||||
//更新我向下一级的第二上级、第三上级
|
||||
$data = [
|
||||
'second_leader' => $my_leader_id,
|
||||
'third_leader' => $my_first_leader,
|
||||
];
|
||||
Db::name('user')
|
||||
->where(['first_leader' => $my_id])
|
||||
->update($data);
|
||||
|
||||
//更新我向下二级的第三级
|
||||
$data = [
|
||||
'third_leader' => $my_leader_id,
|
||||
];
|
||||
Db::name('user')
|
||||
->where(['second_leader' => $my_id])
|
||||
->update($data);
|
||||
|
||||
|
||||
//更新与我相关的所有关系链
|
||||
Db::name('user')
|
||||
->where("find_in_set({$my_id},ancestor_relation)")
|
||||
->exp('ancestor_relation', "replace(ancestor_relation,'{$old_ancestor_relation}','" . trim("{$my_id},{$my_ancestor_relation}", ',') . "')")
|
||||
->update();
|
||||
|
||||
//邀请会员赠送积分
|
||||
$invited_award_integral = ConfigServer::get('marketing','invited_award_integral',0);
|
||||
if($invited_award_integral > 0){
|
||||
Db::name('user')->where(['id'=>$my_leader['id']])->setInc('user_integral',$invited_award_integral);
|
||||
AccountLogLogic::AccountRecord($my_leader['id'],$invited_award_integral,1, AccountLog::invite_add_integral);
|
||||
}
|
||||
|
||||
//消息通知
|
||||
Hook::listen('notice', [
|
||||
'user_id' => $my_leader_id,
|
||||
'lower_id' => $my_id,
|
||||
'scene' => NoticeSetting::INVITE_SUCCESS_NOTICE,
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 填写申请记录
|
||||
* @param $post
|
||||
* @param $user_id
|
||||
* @return bool|string
|
||||
*/
|
||||
public static function apple($post, $user_id)
|
||||
{
|
||||
try {
|
||||
$time = time();
|
||||
$data = [
|
||||
'user_id' => $user_id,
|
||||
'real_name' => $post['real_name'],
|
||||
'province' => $post['province'],
|
||||
'city' => $post['city'],
|
||||
'district' => $post['district'],
|
||||
'reason' => $post['reason'],
|
||||
'create_time' => $time,
|
||||
'update_time' => $time,
|
||||
];
|
||||
Db::name('distribution_member_apply')
|
||||
->insert($data);
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最新申请详情
|
||||
* @param $user_id
|
||||
* @return array|\PDOStatement|string|\think\Model|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function appleDetail($user_id)
|
||||
{
|
||||
$result = Db::name('distribution_member_apply')
|
||||
->field(['real_name', 'province', 'city', 'district', 'reason', 'status'])
|
||||
->where('user_id', $user_id)
|
||||
->order('id', 'desc')
|
||||
->find();
|
||||
|
||||
if (empty($result)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$result['province'] = AreaServer::getAddress($result['province']);
|
||||
$result['city'] = AreaServer::getAddress($result['city']);
|
||||
$result['district'] = AreaServer::getAddress($result['district']);
|
||||
switch ($result['status']) {
|
||||
case 0:
|
||||
$result['status_str'] = '已提交,等待客服审核...';
|
||||
break;
|
||||
case 1:
|
||||
$result['status_str'] = '';
|
||||
break;
|
||||
case 2:
|
||||
$result['status_str'] = '审核失败,请重新提交审核';
|
||||
break;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上级邀请人信息
|
||||
* @param $user_id
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function myLeader($user_id)
|
||||
{
|
||||
|
||||
$field = 'nickname,avatar,is_distribution,mobile,first_leader,distribution_code,earnings';
|
||||
|
||||
$user = Db::name('user')
|
||||
->field($field)
|
||||
->where(['id' => $user_id])
|
||||
->find();
|
||||
|
||||
$first_leader = Db::name('user')
|
||||
->field('nickname,mobile')
|
||||
->where(['id' => $user['first_leader']])
|
||||
->findOrEmpty();
|
||||
|
||||
$user['avatar'] = UrlServer::getFileUrl($user['avatar'], 'local');
|
||||
return [
|
||||
'user' => $user,
|
||||
'leader' => $first_leader,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 分销推广主页信息
|
||||
* @param $user_id
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function index($user_id)
|
||||
{
|
||||
$user_info = self::myLeader($user_id);//用户信息
|
||||
$fans = Db::name('user')
|
||||
->where('first_leader|second_leader', '=', $user_id)
|
||||
->count();
|
||||
|
||||
//今天的预估收益
|
||||
$today_earnings = Db::name('distribution_order_goods')
|
||||
->whereTime('create_time', 'today')
|
||||
->where(['status' => 1, 'user_id' => $user_id])
|
||||
->sum('money');
|
||||
|
||||
//本月预估收益
|
||||
$month_earnings = Db::name('distribution_order_goods')
|
||||
->whereTime('create_time', 'month')
|
||||
->where(['status' => 1, 'user_id' => $user_id])
|
||||
->sum('money');
|
||||
|
||||
//累计收益
|
||||
$history_earnings = Db::name('distribution_order_goods')
|
||||
->where(['status' => 2, 'user_id' => $user_id])
|
||||
->sum('money');
|
||||
|
||||
$data = [
|
||||
'user' => $user_info['user'],
|
||||
'leader' => $user_info['leader'],
|
||||
'fans' => $fans,//粉丝数量
|
||||
'able_withdrawal' => $user_info['user']['earnings'],//可提现佣金
|
||||
'today_earnings' => round($today_earnings, 2),//今天预估收益
|
||||
'month_earnings' => round($month_earnings, 2),//本月预估收益
|
||||
'history_earnings' => round($history_earnings, 2),//累计收益
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
//可提现佣金
|
||||
public static function getAbleWithdrawal($user_id)
|
||||
{
|
||||
$after_sale_time = ConfigServer::get('after_sale', 'refund_days');
|
||||
$time = time() - ($after_sale_time * 24 * 60 * 60);
|
||||
|
||||
//可提现佣金
|
||||
$orders = Db::name('order o')
|
||||
->field('o.id, d.money')
|
||||
->join('order_goods g', 'o.id = g.order_id')
|
||||
->join('distribution_order_goods d', 'd.order_goods_id = g.id')
|
||||
->where('o.create_time', '<', $time)
|
||||
->where('o.order_status', Order::STATUS_FINISH)
|
||||
->where('d.user_id', $user_id)
|
||||
->where('d.status', DistributionOrder::STATUS_WAIT_HANDLE)
|
||||
->select();
|
||||
|
||||
$able_withdrawal = 0;
|
||||
if (!$orders) {
|
||||
return $able_withdrawal;
|
||||
}
|
||||
|
||||
foreach ($orders as $order) {
|
||||
$check = Db::name('after_sale')
|
||||
->where(['order_id' => $order['id']])
|
||||
->where('status', 'in', [AfterSale::STATUS_WAIT_REFUND, AfterSale::STATUS_SUCCESS_REFUND])
|
||||
->find();
|
||||
|
||||
if ($check) {
|
||||
continue;
|
||||
}
|
||||
$able_withdrawal += $order['money'];
|
||||
}
|
||||
return $able_withdrawal;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分销订单列表(待返佣,已结算,已失效)
|
||||
* @param $user_id
|
||||
* @param $get
|
||||
* @return array|\PDOStatement|string|\think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function order($user_id, $get, $page, $size)
|
||||
{
|
||||
$where = [];
|
||||
$where[] = ['d.user_id', '=', $user_id];
|
||||
|
||||
$status = $get['status'] ?? 0;
|
||||
if ($status != 0) {
|
||||
$where[] = ['d.status', '=', $status];
|
||||
}
|
||||
|
||||
$field = 'o.order_sn, og.total_pay_price as pay_price, d.create_time, d.money, og.item_id, og.goods_num, d.status';
|
||||
|
||||
$count = Db::name('distribution_order_goods d')
|
||||
->field($field)
|
||||
->join('order_goods og', 'og.id = d.order_goods_id')
|
||||
->join('order o', 'o.id = og.order_id')
|
||||
->where($where)
|
||||
->count();
|
||||
|
||||
$lists = Db::name('distribution_order_goods d')
|
||||
->field($field)
|
||||
->join('order_goods og', 'og.id = d.order_goods_id')
|
||||
->join('order o', 'o.id = og.order_id')
|
||||
->where($where)
|
||||
->order('o.id desc')
|
||||
->page($page, $size)
|
||||
->select();
|
||||
|
||||
$item_ids = array_column($lists, 'item_id');
|
||||
$goods = Db::name('goods_item i')
|
||||
->join('goods g', 'i.goods_id = g.id')
|
||||
->where('i.id', 'in', $item_ids)
|
||||
->column('g.name, g.image, i.image as spec_image, i.spec_value_str', 'i.id');
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item_id = $item['item_id'];
|
||||
if (!isset($goods[$item_id])) {
|
||||
continue;
|
||||
}
|
||||
$info = $goods[$item_id];
|
||||
$item['goods_name'] = $info['name'];
|
||||
$item['spec_name'] = $info['spec_value_str'];
|
||||
$item['image'] = UrlServer::getFileUrl(empty($info['spec_image']) ? $info['image'] : $info['spec_image']);
|
||||
$item['status'] = DistributionOrder::getOrderStatus($item['status']);
|
||||
$item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'list' => $lists,
|
||||
'page' => $page,
|
||||
'size' => $size,
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $page, $size)
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 月度账单
|
||||
* @param $user_id
|
||||
* @param $get
|
||||
* @param $page
|
||||
* @param $size
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function getMonthBill($user_id, $page, $size)
|
||||
{
|
||||
$field = [
|
||||
"FROM_UNIXTIME(d.create_time,'%Y年%m月') as date",
|
||||
"FROM_UNIXTIME(d.create_time,'%Y') as year",
|
||||
"FROM_UNIXTIME(d.create_time,'%m') as month",
|
||||
'sum(d.money) as total_money',
|
||||
'count(o.id) as order_num'
|
||||
];
|
||||
$count = Db::name('distribution_order_goods d')
|
||||
->field($field)
|
||||
->join('order_goods g', 'g.id = d.order_goods_id')
|
||||
->join('order o', 'o.id = g.order_id')
|
||||
->where(['d.user_id' => $user_id])
|
||||
->where('d.status', 'in', [DistributionOrder::STATUS_WAIT_HANDLE, DistributionOrder::STATUS_SUCCESS])
|
||||
->group('date')
|
||||
->count();
|
||||
|
||||
$lists = Db::name('distribution_order_goods d')
|
||||
->field($field)
|
||||
->join('order_goods g', 'g.id = d.order_goods_id')
|
||||
->join('order o', 'o.id = g.order_id')
|
||||
->where(['d.user_id' => $user_id])
|
||||
->where('d.status', 'in', [DistributionOrder::STATUS_WAIT_HANDLE, DistributionOrder::STATUS_SUCCESS])
|
||||
->page($page, $size)
|
||||
->group('date')
|
||||
->select();
|
||||
|
||||
$data = [
|
||||
'list' => $lists,
|
||||
'page' => $page,
|
||||
'size' => $size,
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $page, $size)
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getMonth($get, $user_id, $page, $size)
|
||||
{
|
||||
$year = $get['year'] ?? date('Y');
|
||||
$month = $get['month'] ?? date('m');
|
||||
//指定月份
|
||||
list($y, $m, $t) = explode('-', date("$year-$month-t"));
|
||||
$time_range = [
|
||||
mktime(0, 0, 0, $m, 1, $y),
|
||||
mktime(23, 59, 59, $m, $t, $y)
|
||||
];
|
||||
|
||||
$field = 'o.order_sn, o.id as order_id, g.total_pay_price as pay_price, d.create_time, d.money, g.item_id, g.goods_num, d.status';
|
||||
|
||||
|
||||
$count = Db::name('distribution_order_goods')->alias('d')
|
||||
->field($field)
|
||||
->join('order_goods g', 'g.id = d.order_goods_id')
|
||||
->join('order o', 'o.id = g.order_id')
|
||||
->where(['d.user_id' => $user_id])
|
||||
->where('d.status', 'in', [DistributionOrder::STATUS_WAIT_HANDLE, DistributionOrder::STATUS_SUCCESS])
|
||||
->where('d.create_time', 'between time', $time_range)
|
||||
->count();
|
||||
|
||||
$lists = Db::name('distribution_order_goods')->alias('d')
|
||||
->field($field)
|
||||
->join('order_goods g', 'g.id = d.order_goods_id')
|
||||
->join('order o', 'o.id = g.order_id')
|
||||
->where(['d.user_id' => $user_id])
|
||||
->where('d.status', 'in', [DistributionOrder::STATUS_WAIT_HANDLE, DistributionOrder::STATUS_SUCCESS])
|
||||
->where('d.create_time', 'between time', $time_range)
|
||||
->page($page, $size)
|
||||
->select();
|
||||
|
||||
|
||||
$item_ids = array_column($lists, 'item_id');
|
||||
$goods = Db::name('goods_item i')
|
||||
->join('goods g', 'i.goods_id = g.id')
|
||||
->where('i.id', 'in', $item_ids)
|
||||
->column('g.name, g.image, i.image as spec_image, i.spec_value_str', 'i.id');
|
||||
|
||||
$total_money = 0;
|
||||
$order_ids = [];
|
||||
foreach ($lists as &$item) {
|
||||
$item_id = $item['item_id'];
|
||||
if (!isset($goods[$item_id])) {
|
||||
continue;
|
||||
}
|
||||
$info = $goods[$item_id];
|
||||
$item['goods_name'] = $info['name'];
|
||||
$item['spec_name'] = $info['spec_value_str'];
|
||||
$item['image'] = UrlServer::getFileUrl(empty($info['spec_image']) ? $info['image'] : $info['spec_image']);
|
||||
$item['status'] = DistributionOrder::getOrderStatus($item['status']);
|
||||
$item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
|
||||
$total_money += $item['money'];
|
||||
if (!in_array($item['order_id'], $order_ids)) {
|
||||
array_push($order_ids, $item['order_id']);
|
||||
}
|
||||
}
|
||||
|
||||
$data = [
|
||||
'year' => $year,
|
||||
'month' => $month,
|
||||
'total_money' => $total_money,
|
||||
'total_order' => count($order_ids),
|
||||
'list' => $lists,
|
||||
'page' => $page,
|
||||
'size' => $size,
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $page, $size)
|
||||
];
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc: 生成用户扩展表
|
||||
* @param $user_id
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function createUserDistribution($user_id)
|
||||
{
|
||||
$user_distribution = Db::name('user_distribution')
|
||||
->where(['user_id' => $user_id])
|
||||
->find();
|
||||
|
||||
if ($user_distribution) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'user_id' => $user_id,
|
||||
'distribution_order_num' => 0,
|
||||
'distribution_money' => 0,
|
||||
'fans' => 0,
|
||||
'create_time' => time(),
|
||||
];
|
||||
Db::name('user_distribution')->insert($data);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Desc: 取消订单后更新分销订单为已失效
|
||||
* @param $order_id
|
||||
* @throws Exception
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function setDistributionOrderFail($order_id)
|
||||
{
|
||||
//订单取消后更新分销订单为已失效状态
|
||||
return Db::name('distribution_order_goods d')
|
||||
->join('order_goods og', 'og.id = d.order_goods_id')
|
||||
->join('order o', 'o.id = og.order_id')
|
||||
->where('o.id', $order_id)
|
||||
->update([
|
||||
'd.status' => DistributionOrder::STATUS_ERROR,
|
||||
'd.update_time' => time(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 发生售后后,更新分销订单为已失效
|
||||
* @param $order_goods_id
|
||||
* @author 段誉(2021/5/13 17:38)
|
||||
* @return int|string
|
||||
* @throws Exception
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function setFailByAfterSale($order_goods_id)
|
||||
{
|
||||
return Db::name('distribution_order_goods')
|
||||
->where('order_goods_id', $order_goods_id)
|
||||
->update([
|
||||
'status' => DistributionOrder::STATUS_ERROR,
|
||||
'update_time' => time(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 根据后台设置返回当前生成用户的分销会员状态(设置了全员分销,新生成的用户即为分销会员)
|
||||
* @author 段誉(2021/4/7 14:48)
|
||||
* @return int
|
||||
*/
|
||||
public static function isDistributionMember()
|
||||
{
|
||||
$is_distribution = 0;
|
||||
//分销会员申请--1,申请分销; 2-全员分销;
|
||||
$distribution = ConfigServer::get('distribution', 'member_apply', 1);
|
||||
if ($distribution == 2) {
|
||||
$is_distribution = 1;
|
||||
}
|
||||
return $is_distribution;
|
||||
}
|
||||
|
||||
public static function fixAncestorRelation()
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$userList = User::select()->toArray();
|
||||
if (empty($userList)) {
|
||||
throw new \Exception('没有用户,无需修复');
|
||||
}
|
||||
|
||||
$updateEmptyData = [];
|
||||
$updateData = [];
|
||||
foreach($userList as $user) {
|
||||
$my_ancestor_relation = self::myAncestorRelation($user);
|
||||
$updateEmptyData[] = ['id' => $user['id'], 'ancestor_relation' => ''];
|
||||
$updateData[] = ['id' => $user['id'], 'ancestor_relation' => $my_ancestor_relation];
|
||||
}
|
||||
// 先清除所有关系链
|
||||
(new User())->saveAll($updateEmptyData);
|
||||
// 重新设置关系链
|
||||
(new User())->saveAll($updateData);
|
||||
|
||||
Db::commit();
|
||||
return [
|
||||
"flag" => true,
|
||||
"msg" => '修复成功'
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return [
|
||||
"flag" => false,
|
||||
"msg" => $e->getMessage()
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public static function myAncestorRelation($user)
|
||||
{
|
||||
if (empty($user['first_leader'])) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return trim(self::findAncestorRelation($user['first_leader']), ',');
|
||||
}
|
||||
|
||||
public static function findAncestorRelation($id, $flag = true)
|
||||
{
|
||||
static $ancestor_relation = '';
|
||||
if ($flag) {
|
||||
$ancestor_relation = '';
|
||||
}
|
||||
$ancestor_relation .= $id . ',';
|
||||
$user = User::findOrEmpty($id)->toArray();
|
||||
if (empty($user['first_leader'])) {
|
||||
return $ancestor_relation;
|
||||
}
|
||||
return self::findAncestorRelation($user['first_leader'], false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取背景海报
|
||||
* @return array
|
||||
* @author cjhao
|
||||
* @date 2021/11/29 12:00
|
||||
*/
|
||||
public static function getPoster(){
|
||||
$poster = ConfigServer::get('invite', 'poster', '/images/share/share_user_bg.png');
|
||||
$poster = empty($poster) ? $poster : UrlServer::getFileUrl($poster);
|
||||
return ['poster'=>$poster];
|
||||
}
|
||||
}
|
||||
@ -14,8 +14,17 @@
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use Alipay\EasySDK\Kernel\Factory;
|
||||
use app\api\cache\TokenCache;
|
||||
use app\api\service\UserServer;
|
||||
use app\common\cache\WebScanLoginCache;
|
||||
use app\common\logic\AccountLogLogic;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\account\AccountLog;
|
||||
use app\common\model\Client_;
|
||||
use app\common\service\WeChatServer;
|
||||
use app\common\service\ConfigServer;
|
||||
use EasyWeChat\Kernel\Exceptions\Exception;
|
||||
use app\api\service\{UserTokenService, WechatUserService};
|
||||
use app\common\enum\{LoginEnum, user\UserTerminalEnum, YesNoEnum};
|
||||
use app\common\service\{
|
||||
@ -27,7 +36,7 @@ use app\common\service\{
|
||||
wechat\WeChatRequestService
|
||||
};
|
||||
use app\common\model\user\{User, UserAuth};
|
||||
use think\facade\{Db, Config};
|
||||
use think\facade\{Cache, Db, Config};
|
||||
|
||||
/**
|
||||
* 登录逻辑
|
||||
@ -115,8 +124,173 @@ class LoginLogic extends BaseLogic
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static function authLogin($post)
|
||||
{
|
||||
try {
|
||||
//通过code获取微信 openid
|
||||
$response = self::getWechatResByCode($post);
|
||||
$response['headimgurl'] = $post['headimgurl'] ?? '';
|
||||
$response['nickname'] = $post['nickname'] ?? '';
|
||||
//通过获取到的openID或unionid获取当前 系统 用户id
|
||||
$user_id = self::getUserByWechatResponse($response);
|
||||
|
||||
} catch (Exception $e) {
|
||||
self::setError('登录失败:' . $e->getMessage());
|
||||
return false;
|
||||
} catch (\think\Exception $e) {
|
||||
self::setError('登录失败:' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty($user_id)) {
|
||||
$user_info = UserServer::createUser($response, Client_::mnp);
|
||||
} else {
|
||||
$user_info = UserServer::updateUser($response, Client_::mnp, $user_id);
|
||||
}
|
||||
|
||||
//验证用户信息
|
||||
$check_res = self::checkUserInfo($user_info);
|
||||
if (true !== $check_res) {
|
||||
return self::setError($check_res);
|
||||
|
||||
}
|
||||
|
||||
//创建会话
|
||||
$user_info['token'] = self::createSession($user_info['id'], Client_::mnp);
|
||||
|
||||
unset($user_info['id'], $user_info['disable']);
|
||||
return $user_info;
|
||||
}
|
||||
public static function registerAward($user_id){
|
||||
$register_award_integral_status = ConfigServer::get('marketing','register_award_integral_status',0);
|
||||
$register_award_coupon_status = ConfigServer::get('marketing','register_award_coupon_status',0);
|
||||
//赠送积分
|
||||
if($register_award_integral_status){
|
||||
$register_award_integral = ConfigServer::get('marketing','register_award_integral',0);
|
||||
//赠送的积分
|
||||
if($register_award_integral > 0){
|
||||
\think\Db::name('user')->where(['id'=>$user_id])->setInc('user_integral',$register_award_integral);
|
||||
AccountLogLogic::AccountRecord($user_id,$register_award_integral,1,AccountLog::register_add_integral,'');
|
||||
}
|
||||
}
|
||||
//注册账号,首次进入首页时领取优惠券
|
||||
$register_award_coupon = ConfigServer::get('marketing','register_award_coupon','');
|
||||
if($register_award_coupon_status && $register_award_coupon){
|
||||
Cache::tag('register_coupon')->set('register_coupon_'.$user_id,$register_award_coupon);
|
||||
}
|
||||
//会员等级
|
||||
$user_level = Db::name('user_level')->where(['del'=>0,'growth_value'=>0])->find();
|
||||
if($user_level){
|
||||
Db::name('user')->where(['id'=>$user_id])->update(['level'=>$user_level['id']]);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Notes: 根据code 获取微信信息(openid, unionid)
|
||||
* @param $post
|
||||
* @author 段誉(2021/4/19 16:52)
|
||||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
|
||||
* @throws Exception
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
|
||||
*/
|
||||
public static function getWechatResByCode($post)
|
||||
{
|
||||
// $config = WeChatServer::getMnpConfig();
|
||||
$response = (new WeChatMnpService())->getMnpResByCode($post['code']);
|
||||
// $app = Factory::miniProgram($config);
|
||||
// $response = $app->auth->session($post['code']);
|
||||
if (!isset($response['openid']) || empty($response['openid'])) {
|
||||
throw new Exception('获取openID失败');
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
/**
|
||||
* Notes: 根据微信返回信息查询当前用户id
|
||||
* @param $response
|
||||
* @author 段誉(2021/4/19 16:52)
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getUserByWechatResponse($response)
|
||||
{
|
||||
$user_id = Db::name('user_auth au')
|
||||
->join('user u', 'au.user_id=u.id')
|
||||
->where(['u.del' => 0])
|
||||
->where(function ($query) use ($response) {
|
||||
$query->whereOr(['au.openid' => $response['openid']]);
|
||||
if(isset($response['unionid']) && !empty($response['unionid'])){
|
||||
$query->whereOr(['au.unionid' => $response['unionid']]);
|
||||
}
|
||||
})
|
||||
->value('user_id');
|
||||
return $user_id;
|
||||
}
|
||||
public static function checkUserInfo($user_info)
|
||||
{
|
||||
if (empty($user_info)) {
|
||||
return '登录失败:user';
|
||||
}
|
||||
|
||||
if ($user_info['disable']) {
|
||||
return '账号已被禁用';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* 创建会话
|
||||
* @param $user_id
|
||||
* @param $client
|
||||
* @return string
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function createSession($user_id, $client)
|
||||
{
|
||||
|
||||
//清除之前缓存
|
||||
$token = Db::name('session')
|
||||
->where(['user_id' => $user_id, 'client' => $client])
|
||||
->value('token');
|
||||
if($token) {
|
||||
$token_cache = new TokenCache($token);
|
||||
$token_cache->del();
|
||||
}
|
||||
|
||||
$result = Db::name('session')
|
||||
->where(['user_id' => $user_id, 'client' => $client])
|
||||
->find();
|
||||
|
||||
$time = time();
|
||||
$expire_time = $time + Config::get('project.token_expire_time');
|
||||
$token = md5($user_id . $client . $time);
|
||||
$data = [
|
||||
'user_id' => $user_id,
|
||||
'token' => $token,
|
||||
'client' => $client,
|
||||
'update_time' => $time,
|
||||
'expire_time' => $expire_time,
|
||||
];
|
||||
|
||||
if (empty($result)) {
|
||||
Db::name('session')->insert($data);
|
||||
} else {
|
||||
Db::name('session')
|
||||
->where(['user_id' => $user_id, 'client' => $client])
|
||||
->update($data);
|
||||
}
|
||||
|
||||
//更新登录信息
|
||||
$login_ip = $ip = request()->ip();
|
||||
Db::name('user')
|
||||
->where(['id' => $user_id])
|
||||
->update(['login_time' => $time, 'login_ip' => $login_ip]);
|
||||
|
||||
//创建新的缓存
|
||||
(new TokenCache($token, ['token' => $token]))->set(300);
|
||||
return $token;
|
||||
}
|
||||
/**
|
||||
* @notes 退出登录
|
||||
* @param $userInfo
|
||||
|
||||
246
app/api/service/UserServer.php
Normal file
246
app/api/service/UserServer.php
Normal file
@ -0,0 +1,246 @@
|
||||
<?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\api\service;
|
||||
|
||||
|
||||
use app\api\logic\DistributionLogic;
|
||||
use app\api\logic\LoginLogic;
|
||||
use app\common\model\Client_;
|
||||
use app\common\model\noticesetting\NoticeSetting;
|
||||
use app\common\model\UserLevel;
|
||||
use app\common\service\storage\Driver as StorageDriver;
|
||||
use app\common\service\UrlServer;
|
||||
use think\facade\Db;
|
||||
use think\Exception;
|
||||
use app\common\service\ConfigServer;
|
||||
use think\facade\Hook;
|
||||
|
||||
|
||||
class UserServer
|
||||
{
|
||||
|
||||
/**
|
||||
* User: 意象信息科技 lr
|
||||
* Desc: 通过小程序创建用户信息
|
||||
* @param $response
|
||||
* @param $client
|
||||
* @return array|\PDOStatement|string|\think\Model|null
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function createUser($response, $client)
|
||||
{
|
||||
$user_info = [];
|
||||
try {
|
||||
$openid = $response['openid'];
|
||||
$unionid = $response['unionid'] ?? '';
|
||||
$avatar_url = $response['headimgurl'] ?? '';
|
||||
$nickname = $response['nickname'] ?? '';
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
// 获取存储引擎
|
||||
$config = [
|
||||
'default' => ConfigServer::get('storage', 'default', 'local'),
|
||||
'engine' => ConfigServer::get('storage_engine')
|
||||
];
|
||||
|
||||
$time = time(); //创建时间
|
||||
$avatar = ''; //头像路径
|
||||
|
||||
if (empty($avatar_url)) {
|
||||
$avatar = ConfigServer::get('website', 'user_image');
|
||||
} else {
|
||||
if ($config['default'] == 'local') {
|
||||
$file_name = md5($openid . $time) . '.jpeg';
|
||||
$avatar = download_file($avatar_url, 'uploads/user/avatar/', $file_name);
|
||||
} else {
|
||||
$avatar = 'uploads/user/avatar/' . md5($openid . $time) . '.jpeg';
|
||||
$StorageDriver = new StorageDriver($config);
|
||||
if (!$StorageDriver->fetch($avatar_url, $avatar)) {
|
||||
throw new Exception( '头像保存失败:'. $StorageDriver->getError());
|
||||
}
|
||||
}
|
||||
}
|
||||
$data = [
|
||||
'nickname' => $nickname,
|
||||
'sn' => create_user_sn(),
|
||||
'avatar' => $avatar,
|
||||
'create_time' => $time,
|
||||
'distribution_code' => generate_invite_code(),//分销邀请码
|
||||
'is_distribution' => DistributionLogic::isDistributionMember(),
|
||||
// 微信新用户
|
||||
'is_new_user' => 1,
|
||||
];
|
||||
|
||||
if (empty($nickname)) {
|
||||
$data['nickname'] = '用户'.$data['sn'];
|
||||
}
|
||||
|
||||
$user_id = Db::name('user')
|
||||
->insertGetId($data);
|
||||
|
||||
$data = [
|
||||
'user_id' => $user_id,
|
||||
'openid' => $openid,
|
||||
'create_time' => $time,
|
||||
'unionid' => $unionid,
|
||||
'client' => $client,
|
||||
];
|
||||
Db::name('user_auth')
|
||||
->insert($data);
|
||||
|
||||
//生成会员分销扩展表
|
||||
DistributionLogic::createUserDistribution($user_id);
|
||||
// 生成分销会员基础表
|
||||
\app\common\logic\DistributionLogic::add($user_id);
|
||||
//消息通知
|
||||
Hook::listen('notice', ['user_id' => $user_id, 'scene' => NoticeSetting::REGISTER_SUCCESS_NOTICE]);
|
||||
|
||||
//注册赠送优惠
|
||||
LoginLogic::registerAward($user_id);
|
||||
|
||||
Db::commit();
|
||||
|
||||
$user_info = Db::name('user')
|
||||
->field(['id', 'nickname', 'avatar', 'level', 'disable', 'distribution_code','is_new_user'])
|
||||
->where(['id' => $user_id])
|
||||
->find();
|
||||
if (empty($user_info['avatar'])) {
|
||||
$user_info['avatar'] = UrlServer::getFileUrl(ConfigServer::get('website', 'user_image'));
|
||||
} else {
|
||||
$user_info['avatar'] = UrlServer::getFileUrl($user_info['avatar']);
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
throw new Exception($e->getMessage());
|
||||
}
|
||||
|
||||
return $user_info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户信息
|
||||
* @param $response
|
||||
* @param $client
|
||||
* @param $user_id
|
||||
* @return array|\PDOStatement|string|\think\Model|null
|
||||
*/
|
||||
public static function updateUser($response, $client, $user_id)
|
||||
{
|
||||
$time = time();
|
||||
try {
|
||||
|
||||
$openid = $response['openid'];
|
||||
$unionid = $response['unionid'] ?? '';
|
||||
$avatar_url = $response['headimgurl'] ?? '';
|
||||
$nickname = $response['nickname'] ?? '';
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
//ios,android
|
||||
if (in_array($client, [Client_::ios, Client_::android])) {
|
||||
Db::name('user_auth')
|
||||
->where(['openid' => $openid])
|
||||
->update(['client' => $client]);
|
||||
}
|
||||
|
||||
//用户已存在,但是无该端的授权信息,保存数据
|
||||
$user_auth_id = Db::name('user_auth')
|
||||
->where(['user_id' => $user_id, 'openid' => $openid])
|
||||
->value('id');
|
||||
|
||||
if (empty($user_auth_id)) {
|
||||
$data = [
|
||||
'create_time' => $time,
|
||||
'openid' => $openid,
|
||||
'unionid' => $unionid,
|
||||
'user_id' => $user_id,
|
||||
'client' => $client,
|
||||
];
|
||||
Db::name('user_auth')
|
||||
->insert($data);
|
||||
}
|
||||
|
||||
$user_info = Db::name('user u')
|
||||
->field(['u.nickname', 'u.avatar', 'u.level', 'u.id', 'au.unionid'])
|
||||
->join('user_auth au', 'u.id=au.user_id')
|
||||
->where(['au.openid' => $openid])
|
||||
->find();
|
||||
|
||||
//无头像需要更新头像
|
||||
if (empty($user_info['avatar'])) {
|
||||
// 获取存储引擎
|
||||
$config = [
|
||||
'default' => ConfigServer::get('storage', 'default', 'local'),
|
||||
'engine' => ConfigServer::get('storage_engine')
|
||||
];
|
||||
|
||||
$avatar = ''; //头像路径
|
||||
if ($config['default'] == 'local') {
|
||||
$file_name = md5($openid . $time) . '.jpeg';
|
||||
$avatar = download_file($avatar_url, 'uploads/user/avatar/', $file_name);
|
||||
} else {
|
||||
$avatar = 'uploads/user/avatar/' . md5($openid . $time) . '.jpeg';
|
||||
$StorageDriver = new StorageDriver($config);
|
||||
if (!$StorageDriver->fetch($avatar_url, $avatar)) {
|
||||
throw new Exception( '头像保存失败:'. $StorageDriver->getError());
|
||||
}
|
||||
}
|
||||
|
||||
$data['avatar'] = $avatar;
|
||||
$data['update_time'] = $time;
|
||||
$data['nickname'] = $nickname;
|
||||
Db::name('user')
|
||||
->where(['id' => $user_info['id']])
|
||||
->update($data);
|
||||
}
|
||||
|
||||
//之前无unionid需要更新
|
||||
if (empty($user_info['unionid']) && isset($unionid)) {
|
||||
$data = [];
|
||||
$data['unionid'] = $unionid;
|
||||
$data['update_time'] = $time;
|
||||
Db::name('user_auth')
|
||||
->where(['user_id' => $user_info['id']])
|
||||
->update($data);
|
||||
}
|
||||
|
||||
$user_info = Db::name('user')
|
||||
->where(['id' => $user_info['id']])
|
||||
->field(['id', 'nickname', 'avatar', 'level', 'disable', 'distribution_code','is_new_user'])
|
||||
->find();
|
||||
|
||||
if (empty($user_info['avatar'])) {
|
||||
$user_info['avatar'] = UrlServer::getFileUrl(ConfigServer::get('website', 'user_image'));
|
||||
} else {
|
||||
$user_info['avatar'] = UrlServer::getFileUrl($user_info['avatar']);
|
||||
}
|
||||
Db::commit();
|
||||
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
throw new Exception($e->getMessage());
|
||||
}
|
||||
|
||||
return $user_info;
|
||||
}
|
||||
}
|
||||
@ -2,7 +2,7 @@
|
||||
// 应用公共文件
|
||||
use app\common\service\FileService;
|
||||
use think\helper\Str;
|
||||
|
||||
use think\facade\{Db, Config};
|
||||
/**
|
||||
* @notes 生成密码加密密钥
|
||||
* @param string $plaintext
|
||||
@ -122,6 +122,80 @@ function linear_to_tree($data, $sub_key_name = 'sub', $id_name = 'id', $parent_i
|
||||
return $tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成会员码
|
||||
* @return 会员码
|
||||
*/
|
||||
function create_user_sn($prefix = '', $length = 8)
|
||||
{
|
||||
$rand_str = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$rand_str .= mt_rand(0, 9);
|
||||
}
|
||||
$sn = $prefix . $rand_str;
|
||||
if (Db::name('user')->where(['sn' => $sn])->find()) {
|
||||
return create_user_sn($prefix, $length);
|
||||
}
|
||||
return $sn;
|
||||
}
|
||||
|
||||
//生成用户邀请码
|
||||
function generate_invite_code()
|
||||
{
|
||||
|
||||
$letter_all = range('A', 'Z');
|
||||
shuffle($letter_all);
|
||||
//排除I、O字母
|
||||
$letter_array = array_diff($letter_all, ['I', 'O', 'D']);
|
||||
//排除1、0
|
||||
$num_array = range('2', '9');
|
||||
shuffle($num_array);
|
||||
|
||||
$pattern = array_merge($num_array, $letter_array, $num_array);
|
||||
shuffle($pattern);
|
||||
$pattern = array_values($pattern);
|
||||
|
||||
$code = '';
|
||||
for ($i = 0; $i < 6; $i++) {
|
||||
$code .= $pattern[mt_rand(0, count($pattern) - 1)];
|
||||
}
|
||||
|
||||
$code = strtoupper($code);
|
||||
$check = Db::name('user')->where('distribution_code', $code)->find();
|
||||
if ($check) {
|
||||
return generate_invite_code();
|
||||
}
|
||||
return $code;
|
||||
}
|
||||
/**
|
||||
* User: 意象信息科技 mjf
|
||||
* Desc: 用时间生成订单编号
|
||||
* @param $table
|
||||
* @param $field
|
||||
* @param string $prefix
|
||||
* @param int $rand_suffix_length
|
||||
* @param array $pool
|
||||
* @return string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
function createSn($table, $field, $prefix = '', $rand_suffix_length = 4, $pool = [])
|
||||
{
|
||||
$suffix = '';
|
||||
for ($i = 0; $i < $rand_suffix_length; $i++) {
|
||||
if (empty($pool)) {
|
||||
$suffix .= rand(0, 9);
|
||||
} else {
|
||||
$suffix .= $pool[array_rand($pool)];
|
||||
}
|
||||
}
|
||||
$sn = $prefix . date('YmdHis') . $suffix;
|
||||
if (Db::name($table)->where($field, $sn)->find()) {
|
||||
return createSn($table, $field, $prefix, $rand_suffix_length, $pool);
|
||||
}
|
||||
return $sn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 删除目标目录
|
||||
|
||||
@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
60
app/common/logic/DistributionLogic.php
Normal file
60
app/common/logic/DistributionLogic.php
Normal 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);
|
||||
}
|
||||
}
|
||||
64
app/common/logic/UserLevelLogic.php
Normal file
64
app/common/logic/UserLevelLogic.php
Normal 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()]);
|
||||
|
||||
}
|
||||
}
|
||||
70
app/common/model/Client_.php
Normal file
70
app/common/model/Client_.php
Normal 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] ?? '未知';
|
||||
}
|
||||
}
|
||||
170
app/common/model/account/AccountLog.php
Normal file
170
app/common/model/account/AccountLog.php
Normal 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 '';
|
||||
}
|
||||
|
||||
}
|
||||
16
app/common/model/distribution/Distribution.php
Normal file
16
app/common/model/distribution/Distribution.php
Normal 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);
|
||||
}
|
||||
}
|
||||
64
app/common/model/distribution/DistributionLevel.php
Normal file
64
app/common/model/distribution/DistributionLevel.php
Normal 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'];
|
||||
}
|
||||
}
|
||||
269
app/common/model/noticesetting/NoticeSetting.php
Normal file
269
app/common/model/noticesetting/NoticeSetting.php
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
@ -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 关联用户授权模型
|
||||
|
||||
190
app/common/service/WeChatServer.php
Normal file
190
app/common/service/WeChatServer.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user