first commit

This commit is contained in:
云泽网
2025-07-27 21:42:34 +08:00
commit c1cce5ccb4
2779 changed files with 340042 additions and 0 deletions
@@ -0,0 +1,56 @@
<?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\behavior;
use think\Db;
use think\Request;
class AppEnd
{
/**
* 记录统计信息(用户访问量)
* @param Request $request
*/
public function run(Request $request)
{
try {
$ip = $request->ip();
$record = Db::name('stat')
->where('ip', '=', $ip)
->whereTime('create_time', 'today')
->find();
if ($record) {
Db::name('stat')
->where('id', $record['id'])
->setInc('count', 1);
} else {
$data = [
'ip' => $ip,
'count' => 1,
'create_time' => time()
];
Db::name('stat')->insert($data);
}
} catch (\Exception $e) {
}
}
}
+57
View 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\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
View File
@@ -0,0 +1,21 @@
<?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
// +----------------------------------------------------------------------
return [
'default_return_type' => 'json',
];
+22
View File
@@ -0,0 +1,22 @@
<?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
// +----------------------------------------------------------------------
return [
//token过期时间
'token_expire_time' => 3600 * 24 * 60,
];
@@ -0,0 +1,326 @@
<?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\controller;
use app\api\logic\LoginLogic;
use app\api\validate\WechatLoginValidate;
use app\common\server\ConfigServer;
class Account extends ApiBase
{
public $like_not_need_login = ['register','applogin', 'login', 'mnplogin', 'codeurl', 'oalogin', 'oplogin','logout','smslogin', 'uinAppLogin', 'silentLogin', 'authLogin'];
/**
* note 注册接口
* create_time 2020/10/23 18:42
*/
public function register(){
$post = $this->request->post();
$post['check_code'] = ConfigServer::get('register_setting', 'open', 0);
$result = $this->validate($post,'app\api\validate\Register');
if($result ===true){
$data = LoginLogic::register($post);
if($data){
$this->_success('注册成功',$data);
}
$this->_error('获取失败',$result,0);
}$this->_error($result,'',0);
}
/**
* showdoc
* @catalog 接口/账号
* @title 手机号账号登录
* @description 手机号账号登录
* @method post
* @url /account/login
* @return {"code":1,"msg":"登录成功","data":["token":"3237676fa733d73333341",//登录令牌"nickname":"好象cms-小林",//昵称"avatar":"http://b2c.yixiangonline.com/uploads/user/avatar/3f102df244d5b40f21c4b25dc321c5ab.jpeg",//头像url"level":0,//等级],"show":0,"time":"0.775400"}
* @param account 必填 string 账号或手机号
* @param id 必填 int 1-密码登录-2-验证码登录
* @param password 必填 string 密码
* @param client 必填 int 客户端类型:2-h53-ios4-android
* @return_param token string 登录令牌
* @return_param nickname string 昵称
* @return_param avatar string 头像
* @remark
* @number 1
*/
public function login()
{
$post = $this->request->post();
$check = $this->validate($post, 'app\api\validate\Login.password');
if (true !== $check) {
$this->_error($check);
}
$data = LoginLogic::login($post);
$this->_success('登录成功', $data);
}
/**
* 验证码登录
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function smsLogin(){
$post = $this->request->post();
$post['message_key'] = 'YZMDL';
$check = $this->validate($post, 'app\api\validate\Login.code');
if (true !== $check) {
$this->_error($check);
}
$data = LoginLogic::login($post);
$this->_success('登录成功', $data);
}
/**
* showdoc
* @catalog 接口/账号
* @title 小程序登录
* @description 小程序登录
* @method post
* @url /account/mnpLogin
* @return {"code":1,"msg":"登录成功","data":["token":"3237676fa733d73333341",//登录令牌"nickname":"好象cms-小林",//昵称"avatar":"http://b2c.yixiangonline.com/uploads/user/avatar/3f102df244d5b40f21c4b25dc321c5ab.jpeg",//头像url"level":0,//等级],"show":0,"time":"0.775400"}
* @param code 必填 string code
* @param iv 必填 string iv
* @param encrypted_data 必填 string encrypted_data
* @return_param token string 登录令牌
* @return_param nickname string 昵称
* @return_param avatar string 头像
* @remark
* @number 1
*/
public function mnpLogin()
{
$post = $this->request->post();
$check = $this->validate($post, 'app\api\validate\MnpLogin');
if (true !== $check) {
$this->_error($check);
}
$data = LoginLogic::mnpLogin($post);
$this->_success($data['msg'], $data['data'], $data['code'], $data['show']);
}
/**
* showdoc
* @catalog 接口/账号
* @title 获取获取向微信请求code的链接
* @description
* @method get
* @url /account/codeurl
* @param url 必填 varchar 前端当前url
* @return_param url string codeurl
* @remark 这里是备注信息
* @number 0
* @return {"code":1,"msg":"获取成功","data":{"url":'http://mp.weixin……'}}
*/
public function codeUrl()
{
$url = $this->request->get('url');
$this->_success('获取成功', ['url' => LoginLogic::codeUrl($url)], 1);
}
/**
* showdoc
* @catalog 接口/账号
* @title 微信H5登录
* @description 微信H5登录
* @method post
* @url /account/oalogin
* @return {"code":1,"msg":"登录成功","data":["token":"3237676fa733d73333341",//登录令牌"nickname":"好象cms-小林",//昵称"avatar":"http://b2c.yixiangonline.com/uploads/user/avatar/3f102df244d5b40f21c4b25dc321c5ab.jpeg",//头像url"level":0,//等级],"show":0,"time":"0.775400"}
* @param code 必填 string code
* @return_param token string 登录令牌
* @return_param nickname string 昵称
* @return_param avatar string 头像
* @remark
* @number 1
*/
public function oaLogin()
{
$post = $this->request->post();
$check = $this->validate($post, 'app\api\validate\OaLogin');
if (true !== $check) {
$this->_error($check);
}
$data = LoginLogic::oaLogin($post);
$this->_success($data['msg'], $data['data'], $data['code'], $data['show']);
}
/**
* showdoc
* @catalog 接口/账号
* @title 微信第三方app登录
* @description 微信第三方app登录
* @method post
* @url /account/oplogin
* @return {"code":1,"msg":"登录成功","data":["token":"3237676fa733d73333341",//登录令牌"nickname":"好象cms-小林",//昵称"avatar":"http://b2c.yixiangonline.com/uploads/user/avatar/3f102df244d5b40f21c4b25dc321c5ab.jpeg",//头像url"level":0,//等级],"show":0,"time":"0.775400"}
* @param code 必填 string code
* @param client 必填 int 客户端类型:3-ios4-android
* @return_param token string 登录令牌
* @return_param nickname string 昵称
* @return_param avatar string 头像
* @remark
* @number 1
*/
public function opLogin()
{
$post = $this->request->post();
$check = $this->validate($post, 'app\api\validate\OpLogin');
if (true !== $check) {
$this->_error($check);
}
$data = LoginLogic::opLogin($post);
$this->_success($data['msg'], $data['data'], $data['code']);
}
/**
* 退出登录
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function logout()
{
LoginLogic::logout($this->user_id, $this->client);
//退出登录只有成功
$this->_success();
}
/**
* Notes: uniapp微信登录
* @author 段誉(2021/3/16 16:00)
*/
public function uinAppLogin()
{
$post = $this->request->post();
$data = LoginLogic::uinAppLogin($post);
$this->_success($data['msg'], $data['data'], $data['code']);
}
//2021-0419 小程序新版登录调整
/**
* Notes: 小程序登录(旧系统用户,返回用户信息,否则返回空)
* @author 段誉(2021/4/19 16:50)
*/
public function silentLogin()
{
$post = $this->request->post();
if (empty($post['code'])) {
$this->_error('参数缺失');
}
$data = LoginLogic::silentLogin($post);
$this->_success($data['msg'], $data['data'], $data['code'], $data['show']);
}
/**
* Notes: 小程序登录(新用户登录->需要提交昵称和头像参数)
* @author 段誉(2021/4/19 16:49)
*/
public function authLogin()
{
$post = $this->request->post();
if (empty($post['code']) || empty($post['nickname'])) {
$this->_error('参数缺失');
}
$data = LoginLogic::authLogin($post);
$this->_success($data['msg'], $data['data'], $data['code'], $data['show']);
}
/**
* @notes 更新用户头像昵称
* @throws \think\Exception
* @throws \think\exception\PDOException
* @author ljj
* @date 2023/2/1 3:46 下午
*/
public function updateUser()
{
$post = $this->request->post();
if (!isset($post['avatar']) || empty($post['avatar'])) {
$this->_error('参数缺失');
}
if (!isset($post['nickname']) || empty($post['nickname'])) {
$this->_error('参数缺失');
}
$data = LoginLogic::updateUser($post,$this->user_id);
$this->_success($data['msg'], $data['data'], $data['code'], $data['show']);
}
/**
* @notes 小程序绑定微信
* @return void
* @author lbzy
* @datetime 2023-11-29 09:43:24
*/
public function mnpAuthLogin()
{
$params = $this->request->post();
if (empty($params['code'])) {
$this->_error('参数缺失');
}
$params['user_id'] = $this->user_id;
$result = (new LoginLogic())->mnpAuthLogin($params);
if ($result === false) {
$this->_error(LoginLogic::getError());
}
$this->_success('绑定成功');
}
/**
* @notes 公众号绑定微信
* @return void
* @author lbzy
* @datetime 2023-11-29 09:43:16
*/
public function oaAuthLogin()
{
$params = $this->request->post();
if (empty($params['code'])) {
$this->_error('参数缺失');
}
$params['user_id'] = $this->user_id;
$result = (new LoginLogic())->oaAuthLogin($params);
if ($result === false) {
$this->_error(LoginLogic::getError());
}
$this->_success('绑定成功');
}
}
@@ -0,0 +1,33 @@
<?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\controller;
use app\api\logic\ActivityAreaLogic;
class ActivityArea extends ApiBase
{
public $like_not_need_login = ['activityGoodsList'];
public function activityGoodsList()
{
$id = $this->request->get('id');
$list = ActivityAreaLogic::activityGoodsList($id, $this->page_no, $this->page_size);
$this->_success('获取成功', $list);
}
}
+59
View File
@@ -0,0 +1,59 @@
<?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\controller;
use app\api\logic\AdLogic;
class Ad extends ApiBase
{
public $like_not_need_login = ['lists'];
/**
* showdoc
* @catalog 接口/广告
* @title 获取广告列表
* @description 获取广告列表
* @method get
* @url ad/lists
* @param pid 必填 int 广告位id
* @param client 必填 int 终端,1-移动端商城;2-PC端商城
* @return_param image string 广告图片
* @return_param link_type int 广告类型:1-商场页面;2-商品页面;3-自定义类型
* @return_param link string 广告链接
* @return_param params string 参数
* @return_param is_tab int 是否tab页:1-是;0-否
* @remark
* @number 0
* @return {"code":1,"msg":"获取成功","data":{"lists":["http:\/\/www.likeb2b2c.com:20002\/uploads\/images\/20200706\/e4bdb.jpg","http:\/\/www.likeb2b2c.com:20002\/uploads\/images\/20200708\/893ae.jpg"]},"show":0,"time":"0.686155","debug":{"request":{"get":{"pid":"1"},"post":[],"header":{"connection":"keep-alive","accept-encoding":"gzip, deflate, br","host":"www.likeb2b2c.com:20002","postman-token":"f804bef0-b397-4590-a67f-b489830cd37b","accept":"*\/*","user-agent":"PostmanRuntime\/7.26.1","token":"ff0c66fe0c89fe1e9be591d82d551521","content-type":"","content-length":""}}}}
*/
public function lists()
{
$pid = $this->request->get('pid');
$client = $this->request->get('client', 1);
if ($pid) {
$list = AdLogic::lists($pid, $client);
} else {
$list = [];
}
$this->_success('获取成功', $list);
}
}
@@ -0,0 +1,59 @@
<?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\controller;
use app\api\logic\AdLogic;
class AdContent extends ApiBase
{
public $like_not_need_login = ['lists'];
/**
* showdoc
* @catalog 接口/广告
* @title 获取广告列表
* @description 获取广告列表
* @method get
* @url ad/lists
* @param pid 必填 int 广告位id
* @param client 必填 int 终端,1-移动端商城;2-PC端商城
* @return_param image string 广告图片
* @return_param link_type int 广告类型:1-商场页面;2-商品页面;3-自定义类型
* @return_param link string 广告链接
* @return_param params string 参数
* @return_param is_tab int 是否tab页:1-是;0-否
* @remark
* @number 0
* @return {"code":1,"msg":"获取成功","data":{"lists":["http:\/\/www.likeb2b2c.com:20002\/uploads\/images\/20200706\/e4bdb.jpg","http:\/\/www.likeb2b2c.com:20002\/uploads\/images\/20200708\/893ae.jpg"]},"show":0,"time":"0.686155","debug":{"request":{"get":{"pid":"1"},"post":[],"header":{"connection":"keep-alive","accept-encoding":"gzip, deflate, br","host":"www.likeb2b2c.com:20002","postman-token":"f804bef0-b397-4590-a67f-b489830cd37b","accept":"*\/*","user-agent":"PostmanRuntime\/7.26.1","token":"ff0c66fe0c89fe1e9be591d82d551521","content-type":"","content-length":""}}}}
*/
public function lists()
{
$pid = $this->request->get('pid');
$client = $this->request->get('client', 1);
if ($pid) {
$list = AdLogic::lists($pid, $client);
} else {
$list = [];
}
$this->_success('获取成功', $list);
}
}
@@ -0,0 +1,104 @@
<?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\controller;
use app\api\logic\AfterSaleLogic;
/**
* 售后
* Class Order
* @package app\api\controller
*/
class AfterSale extends ApiBase
{
public function lists()
{
$type = $this->request->get('type', 'normal');
$lists = AfterSaleLogic::lists($this->user_id, $type, $this->page_no, $this->page_size);
$this->_success('',$lists);
}
public function add()
{
$post = $this->request->post();
$post['user_id'] = $this->user_id;
$check = $this->validate($post, 'app\api\validate\AfterSale.add');
if (true !== $check) {
$this->_error($check);
}
return AfterSaleLogic::add($post, $this->user_id);
}
//售后商品信息
public function goodsInfo()
{
$get = $this->request->get();
$check = $this->validate($get, 'app\api\validate\AfterSale.info');
if (true !== $check) {
$this->_error($check);
}
$this->_success('', AfterSaleLogic::info($get['item_id'], $get['order_id']));
}
public function express()
{
$post = $this->request->post();
$check = $this->validate($post, 'app\api\validate\AfterSale.express');
if (true !== $check) {
$this->_error($check);
}
return AfterSaleLogic::express($this->user_id, $post);
}
public function cancel()
{
$post = $this->request->post();
$check = $this->validate($post, 'app\api\validate\AfterSale.cancel');
if (true !== $check) {
$this->_error($check);
}
AfterSaleLogic::cancel($this->user_id, $post);
$this->_success('撤销成功');
}
public function detail()
{
$get = $this->request->get();
$this->_success('', AfterSaleLogic::detail($get));
}
public function again()
{
$post = $this->request->post();
$check = $this->validate($post, 'app\api\validate\AfterSale.again');
if (true !== $check) {
$this->_error($check);
}
return AfterSaleLogic::again($this->user_id, $post);
}
}
@@ -0,0 +1,153 @@
<?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\controller;
use think\App;
use think\Controller;
use think\exception\HttpResponseException;
use think\facade\Config;
use think\facade\Debug;
use think\Response;
class ApiBase extends Controller
{
public $user_info = [];
public $user_id = null;
public $client = null;
public $page_no = 1;
public $page_size = 15;
public $like_not_need_login = [];
/**
* 底层控制器初始化
* ApiBase constructor.
* @param App|null $app
*/
public function __construct(App $app = null)
{
parent::__construct($app);
self::setValue();
}
/**
* User: 意象信息科技 lr
* Desc: 设置基础控制器属性值
*/
private function setValue()
{
//用户信息
$this->user_info = $this->request->user_info ?? [];
$this->user_id = $this->request->user_info['id'] ?? null;
$this->client = $this->request->user_info['client'] ?? null;
//分页参数
$page_no = (int)$this->request->get('page_no');
$this->page_no = $page_no && is_numeric($page_no) ? $page_no : $this->page_no;
$page_size = (int)$this->request->get('page_size');
$this->page_size = $page_size && is_numeric($page_size) ? $page_size : $this->page_size;
$this->page_size = min($this->page_size, 100);
}
/**
* User: 意象信息科技 lr
* Desc: 请求成功
* @param string $msg
* @param array $data
* @param int $code
* @param int $show
* @param array $header
*/
protected function _success($msg = '', $data = [], $code = 1, $show = 0, array $header = [])
{
$type = $this->getResponseType();
$time = Debug::getUseTime();
$result = [
'code' => $code,
'msg' => $msg,
'data' => $data,
'show' => $show,
'time' => $time,
];
if (Config::get('app_trace')) {
$result['debug'] = [
'request' => [
'get' => $this->request->get(),
'post' => $this->request->post(),
'header' => $this->request->header(),
]
];
}
$type = $this->getResponseType();
// 把跳转模板的渲染下沉,这样在 response_send 行为里通过getData()获得的数据是一致性的格式
if ('html' == strtolower($type)) {
$type = 'jump';
}
$response = Response::create($result, $type)->header($header)->options(['jump_template' => $this->app['config']->get('dispatch_success_tmpl')]);
throw new HttpResponseException($response);
}
/**
* User: 意象信息科技 lr
* Desc: 请求失败
* @param string $msg
* @param array $data
* @param int $code
* @param int $show
* @param array $header
*/
protected function _error($msg = '', $data = [], $code = 0, $show = 1, array $header = [])
{
$type = $this->getResponseType();
$time = Debug::getUseTime();
$result = [
'code' => $code,
'msg' => $msg,
'data' => $data,
'show' => $show,
'time' => $time,
];
if (Config::get('app_trace')) {
$result['debug'] = [
'request' => [
'get' => $this->request->get(),
'post' => $this->request->post(),
'header' => $this->request->header(),
]
];
}
if ('html' == strtolower($type)) {
$type = 'jump';
}
$response = Response::create($result, $type)->header($header)->options(['jump_template' => $this->app['config']->get('dispatch_error_tmpl')]);
throw new HttpResponseException($response);
}
}
@@ -0,0 +1,56 @@
<?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\controller;
use app\api\logic\ArticleLogic;
class Article extends ApiBase
{
public $like_not_need_login = ['lists', 'category', 'detail'];
public function lists()
{
$id = $this->request->get('id');
$article = ArticleLogic::lists($id, $this->page_no, $this->page_size);
$this->_success('获取成功', $article);
}
public function category()
{
$article = ArticleLogic::CategoryLists();
$this->_success('获取成功', $article);
}
public function detail()
{
$id = $this->request->get('id');
$client = $this->request->get('client',1);
if (!$id) {
$this->_error('参数缺失');
}
$article_detail = ArticleLogic::getArticleDetail($id,$client);
$this->_success('获取成功', $article_detail);
}
}
@@ -0,0 +1,133 @@
<?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\controller;
use app\api\logic\BargainLogic;
class Bargain extends ApiBase{
public $like_not_need_login = ['barginNumber', 'lists','detail','closeBargain'];
/**
* Notes:获取砍价成功人数
* @author: 2021/2/23 16:11
*/
public function barginNumber(){
$number = BargainLogic::barginNumber();
$this->_success('获取成功',$number);
}
/**
* Notes: 砍价列表
* @author: 2021/2/23 15:54
*/
public function lists(){
$list = BargainLogic::lists($this->page_no, $this->page_size);
$this->_success('获取成功',$list);
}
/**
* Notes:砍价活动详情
* @author: 2021/2/23 17:44
*/
public function detail(){
$bargain_id = $this->request->get('bargain_id');
$result = $this->validate(['bargain_id'=>$bargain_id],'app\api\validate\Bargain.detail');
if(true === $result){
$detail = BargainLogic::detail($bargain_id);
$this->_success('获取成功',$detail);
}
$this->_error($result);
}
/**
* Notes:发起砍价
* @author: 2021/2/23 18:43
*/
public function sponsor(){
$post_data = $this->request->post();
$result = $this->validate($post_data,'app\api\validate\Bargain.sponsor');
if(true === $result){
$data = BargainLogic::sponsor($post_data,$this->user_id);
$this->_success($data['msg'],$data['data'],$data['code'],$data['show']);
}
$this->_error($result);
}
/**
* Notes:砍价助力
* @author: 2021/2/25 18:21
*/
public function knife(){
$id = $this->request->post('id');
$result = $this->validate(['id'=>$id,'user_id'=>$this->user_id],'app\api\validate\Bargain.knife');
if(true === $result){
$data = BargainLogic::knife($id,$this->user_id);
$this->_success($data['msg'],$data['data'],$data['code'],$data['show']);
}
$this->_error($result);
}
/**
* Notes:砍价订单列表
* @author: 2021/2/24 17:15
*/
public function orderList(){
$type = $this->request->get('type','-1');
$list = BargainLogic::orderList($type,$this->user_id,$this->page_no,$this->page_size);
$this->_success('获取成功',$list);
}
/**
* Notes:砍价详情
* @author: 2021/2/24 15:36
*/
public function bargainDetail(){
$id = $this->request->get('id');
$result = $this->validate(['id'=>$id,'user_id'=>$this->user_id],'app\api\validate\Bargain.bargainDetail');
if(true === $result){
$detail = BargainLogic::bargainDetail($id,$this->user_id);
$this->_success('获取成功',$detail);
}
$this->_error($result);
}
/**
* Notes:关闭砍价订单
* @author: 2021/2/26 16:36
*/
public function closeBargain(){
$id = $this->request->post('id');
if($id){
BargainLogic::closeBargain($id);
}
$this->_success('');
}
}
@@ -0,0 +1,98 @@
<?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\controller;
use app\api\logic\CartLogic;
/**
* 购物车
* Class Cart
* @package app\api\controller
*/
class Cart extends ApiBase
{
public function lists()
{
$this->_success('', CartLogic::lists($this->user_id));
}
public function add()
{
$post = $this->request->post();
$check = $this->validate($post, 'app\api\validate\Cart.add');
if (true !== $check) {
$this->_error($check);
}
$res = CartLogic::add($post['item_id'], $post['goods_num'], $this->user_id);
if ($res === true) {
$this->_success('加入成功');
}
$this->_error($res);
}
public function change()
{
$post = $this->request->post();
$check = $this->validate($post, 'app\api\validate\Cart.change');
if ($check !== true) {
$this->_error($check);
}
$res = CartLogic::change($post['cart_id'], $post['goods_num']);
if ($res === true) {
$this->_success();
}
$this->_error($res);
}
public function del()
{
$post = $this->request->post();
$check = $this->validate($post, 'app\api\validate\Cart.del');
if (true !== $check) {
$this->_error($check);
}
if (CartLogic::del($post['cart_id'], $this->user_id)) {
$this->_success('删除成功');
}
$this->_error('删除失败');
}
public function selected()
{
$post = $this->request->post();
$check = $this->validate($post, 'app\api\validate\Cart.selected');
if (true !== $check) {
$this->_error($check);
}
CartLogic::selected($post, $this->user_id);
$this->_success();
}
public function num()
{
$this->_success('',CartLogic::cartNum($this->user_id));
}
}
@@ -0,0 +1,40 @@
<?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\controller;
use app\api\logic\CollectLogic;
class Collect extends ApiBase{
/**
* note 商品收藏列表
* create_time 2020/10/29 10:17
*/
public function getCollectGoods(){
$collect = CollectLogic::getCollectGoods($this->user_id,$this->page_no,$this->page_size);
$this->_success('获取成功',$collect);
}
/**
* note 商品收藏操作
* create_time 2020/10/29 10:17
*/
public function handleCollectGoods(){
$post = $this->request->post();
$collect = CollectLogic::handleCollectGoods($post,$this->user_id);
$this->_success('获取成功',$collect);
}
}
@@ -0,0 +1,89 @@
<?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\controller;
use app\api\logic\CouponLogic;
class Coupon extends ApiBase{
public $like_not_need_login = ['couponlist','getgoodscoupon'];
/**
* note 领券中心
* create_time 2020/10/22 12:06
*/
public function couponList(){
$coupon_list = CouponLogic::getCouponList($this->user_id);
$this->_success('获取成功',$coupon_list);
}
/**
* note 商品详情获取优惠券
* create_time 2020/10/22 18:14
*/
public function getGoodsCoupon(){
$id = $this->request->get('id');
$coupon_list = [];
if($id){
$coupon_list = CouponLogic::getGoodsCoupon($this->user_id,$id);
}
$this->_success('',$coupon_list);
}
/**
* note 领取优惠券
* create_time 2020/10/22 12:06
*/
public function getCoupon(){
$coupon_id = $this->request->post('id');
$result = $this->validate(['id'=>$coupon_id,'user_id'=>$this->user_id],'app\api\validate\GetCoupon');
if($result === true){
$result = CouponLogic::userGetCoupon($coupon_id,$this->user_id);
if($result == true){
$this->_success('领取成功','');
}
$result = '领取失败';
}
$this->_error($result);
}
/**
* note 我的优惠券
* create_time 2020/10/26 9:37
*/
public function myCoupon(){
$type = $this->request->get('type',1);
$coupon_list = CouponLogic::getMyCouponList($this->user_id,$type);
$this->_success('获取成功',$coupon_list);
}
/**
* note 下单获取优惠券
* create_time 2020/10/28 11:06
*/
public function orderCoupon(){
$goods = $this->request->post('goods');
$data = CouponLogic::orderCoupon($goods,$this->user_id);
$this->_success('获取成功',$data);
}
/**
* note 注册赠送优惠券
* create_time 2020/12/4 10:29
*/
public function registerSendCoupon(){
$list = CouponLogic::registerSendCoupon($this->user_id);
$this->_success('获取成功',$list);
}
}
@@ -0,0 +1,33 @@
<?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\controller;
class Dispatch extends ApiBase
{
public $like_not_need_login = ['_error'];
public function dispatch_error($msg = '', $code = 0)
{
return $this->_error($msg, [], $code);
}
}
@@ -0,0 +1,176 @@
<?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\controller;
use app\api\logic\DistributionLogic;
use app\common\model\User;
class Distribution extends ApiBase
{
public $like_not_need_login = ['fixAncestorRelation'];
/**
* 填写邀请码
*/
public function code()
{
$code = $this->request->post('code');
$data = [
'user_id' => $this->user_id,
'code' => $code,
];
$result = $this->validate($data, 'app\api\validate\DistributionCode');
if ($result !== true) {
$this->_error($result, [], 0, 0);
}
$result = DistributionLogic::code($code, $this->user_id);
if ($result !== true) {
$this->_error($result, [], 0, 0);
}
$this->_success();
}
/**
* 分销会员申请
*/
public function apple()
{
$post = $this->request->post();
$post['user_id'] = $this->user_id;
$result = $this->validate($post, 'app\api\validate\DistributionApply');
if ($result !== true) {
$this->_error($result);
}
$result = DistributionLogic::apple($post,$this->user_id);
if ($result !== true) {
$this->_error($result);
}
$this->_success();
}
/**
* 最新的分销会员申请详情
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function appleDetail()
{
$this->_success('',DistributionLogic::appleDetail($this->user_id));
}
/**
* User: 意象信息科技 mjf
* Desc: 我的分销上级
*/
public function myLeader()
{
$this->_success('', DistributionLogic::myLeader($this->user_id));
}
/**
* 分销推广主页信息
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function index()
{
$this->_success('', DistributionLogic::index($this->user_id));
}
/**
* 分销订单
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function order()
{
$get = $this->request->get();
$this->_success('', DistributionLogic::order($this->user_id, $get, $this->page_no, $this->page_size));
}
/**
* 月度账单
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function monthBill()
{
$this->_success('', DistributionLogic::getMonthBill($this->user_id, $this->page_no, $this->page_size));
}
/**
* 月度账单明细
*/
public function monthDetail()
{
$get = $this->request->get();
$this->_success('', DistributionLogic::getMonth($get, $this->user_id, $this->page_no, $this->page_size));
}
/**
* Notes: 分销会员页面判断
* @author 段誉(2021/2/1 18:45)
*/
public function check()
{
$distribution = \app\common\model\Distribution::where('user_id', $this->user_id)->findOrEmpty()->toArray();
if (!empty($distribution) && $distribution['is_distribution'] == 1) {
$this->_success('', '', 10001);//已是分销会员
} else {
$this->_success('', '',20001);//未是分销会员
}
}
/**
* 修复旧的关系链
*/
public function fixAncestorRelation()
{
$result = DistributionLogic::fixAncestorRelation();
if ($result['flag']) {
$this->_success($result['msg']);
}
$this->_error($result['msg']);
}
/**
* @notes 获取背景海报
* @return Json
* @author cjhao
* @date 2021/11/29 11:35
*/
public function getPoster()
{
$result = DistributionLogic::getPoster();
$this->_success('',$result);
}
}
@@ -0,0 +1,47 @@
<?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\controller;
use app\common\server\FileServer;
class File extends ApiBase
{
public $like_not_need_login = ['formImage','test'];
/**
* showdoc
* @catalog 接口/上传文件
* @title form表单方式上传图片
* @description 图片上传
* @method post
* @url /file/formimage
* @return param name string 图片名称
* @return param url string 文件地址
* @remark
* @number 1
* @return {"code":1,"msg":"上传文件成功","data":{"url":"http:\/\/likeb2b2c.yixiangonline.com\/uploads\/images\/user\/20200810\/3cb866f6bb30b7239d91582f7d9822d6.png","name":"2.png"},"show":0,"time":"0.283254","debug":{"request":{"get":[],"post":[],"header":{"content-length":"103132","content-type":"multipart\/form-data; boundary=--------------------------206668736604428806173438","connection":"keep-alive","accept-encoding":"gzip, deflate, br","host":"www.likeb2b2c.com:20002","postman-token":"1f8aa4dd-f53c-4d12-98b4-8d901ac847db","cache-control":"no-cache","accept":"*\/*","user-agent":"PostmanRuntime\/7.26.2"}}}}
*/
public function formImage()
{
$data = FileServer::userFormImage($this->user_id);
$this->_success($data['msg'], $data['data'], $data['code']);
}
}
@@ -0,0 +1,34 @@
<?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\controller;
use app\api\logic\FootPrintLogic;
class Footprint extends ApiBase
{
public $like_not_need_login = ['lists'];
public function lists()
{
$lists = FootPrintLogic::lists();
$this->_success('获取成功', $lists);
}
}
@@ -0,0 +1,90 @@
<?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\controller;
use app\api\logic\GoodsLogic;
class Goods extends ApiBase{
public $like_not_need_login = ['getgoodsdetail', 'getgoodslist','getbestlist','gethostlist','getsearchpage'];
/**
* note 商品列表
* create_time 2020/10/20 11:12
*/
public function getGoodsList(){
$get = $this->request->get();
$goods_list = GoodsLogic::getGoodsList($this->user_id, $get, $this->page_no, $this->page_size);
$this->_success('获取成功',$goods_list);
}
/**
* note 商品详情
* create_time 2020/10/20 11:12
*/
public function getGoodsDetail(){
$id = $this->request->get('id');
$goods = GoodsLogic::getGoodsDetail($this->user_id,$id);
if($goods){
$this->_success('获取成功',$goods);
}
$this->_error('商品不存在',[],0,0);
}
/**
* note 首页好物优选
* create_time 2020/10/21 19:04
*/
public function getBestList() {
$goods_list = GoodsLogic::getBestList($this->page_no, $this->page_size);
$this->_success('获取成功', $goods_list);
}
/**
* note 热销商品
* create_time 2020/11/17 9:52
*/
public function getHostList(){
$goods_list = GoodsLogic::getHostList($this->page_no, $this->page_size);
$this->_success('获取成功', $goods_list);
}
/**
* note 获取搜索页数据
* create_time 2020/10/22 16:01
*/
public function getSearchPage(){
$limit = $this->request->get('limit ',10);
$list = GoodsLogic::getSearchPage($this->user_id,$limit);
$this->_success('',$list);
}
/**
* note 清空搜索记录
* create_time 2020/12/18 10:26
*/
public function clearSearch(){
$result = GoodsLogic::clearSearch($this->user_id);
if($result){
$this->_success('清理成功','');
}
$this->_error('清理失败','');
}
}
@@ -0,0 +1,36 @@
<?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\controller;
use app\api\logic\GoodsCategoryLogic;
class GoodsCategory extends ApiBase{
public $like_not_need_login = ['lists'];
/**
* Notes:获取商品分类
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @author: 2021/3/6 18:49
*/
public function lists(){
$client = $this->request->get('client',1);
$cateogry = GoodsCategoryLogic::categoryThirdTree($client);
$this->_success('获取成功',$cateogry);
}
}
@@ -0,0 +1,84 @@
<?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\controller;
use app\api\logic\GoodsCommentLogic;
class GoodsComment extends ApiBase{
public $like_not_need_login = ['lists','category'];
/**
* note 商品评论分类
* create_time 2020/11/11 16:33
*/
public function category()
{
$get = $this->request->get();
$collect = GoodsCommentLogic::category($get);
$this->_success('获取成功', $collect);
}
/**
* note 商品评论列表
* create_time 2020/11/11 16:34
*/
public function lists(){
$get = $this->request->get();
$collect = GoodsCommentLogic::lists($get, $this->page_no, $this->page_size);
$this->_success('获取成功', $collect);
}
/**
* note 添加商品评论
* create_time 2020/11/11 15:14
*/
public function addGoodsComment()
{
$post = $this->request->post();
$post['user_id'] = $this->user_id;
$result = $this->validate($post, 'app\api\validate\GoodsComment');
if ($result === true) {
$result = GoodsCommentLogic::addGoodsComment( $post,$this->user_id);
if($result === true){
$this->_success('评论成功');
}
}
$this->_error($result);
}
/**
* note 获取未评论或已评论的订单商品列表
* create_time 2020/11/12 11:11
*/
public function getOrderGoods(){
$type = $this->request->get('type',1);
$list = GoodsCommentLogic::getOrderGoods($type,$this->user_id, $this->page_no, $this->page_size);
$this->_success('',$list);
}
/**
* note 获取评论的商品信息
* create_time 2020/11/13 14:45
*/
public function getGoods(){
$id = $this->request->get('id');
if($id){
$goods = GoodsCommentLogic::getGoods($id);
$this->_success('获取成功',$goods);
}
$this->_success('请选择评论的商品');
}
}
@@ -0,0 +1,52 @@
<?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\controller;
use app\api\logic\HelpLogic;
class Help extends ApiBase
{
public $like_not_need_login = ['lists', 'category', 'detail'];
public function lists()
{
$id = $this->request->get('id');
$article = HelpLogic::lists($id, $this->page_no, $this->page_size);
$this->_success('获取成功', $article);
}
public function category()
{
$help = HelpLogic::CategoryLists();
$this->_success('获取成功', $help);
}
public function detail()
{
$id = $this->request->get('id');
$client = $this->request->get('client',1);
$help_detail = HelpLogic::getHelpDetail($id,$client);
$this->_success('获取成功', $help_detail);
}
}
+185
View File
@@ -0,0 +1,185 @@
<?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\controller;
use app\api\logic\IndexLogic;
use app\common\model\Client_;
use app\common\model\MessageScene_;
use app\common\server\ConfigServer;
use app\common\server\UrlServer;
use think\facade\Hook;
use think\Db;
class Index extends ApiBase
{
public $like_not_need_login = ['test', 'lists', 'appInit', 'downLine', 'share', 'config','pcLists','copyright'];
/**
* note 首页接口
* create_time 2020/10/21 19:05
*/
public function lists(){
$lists = IndexLogic::lists($this->user_id);
return $this->_success('',$lists);
}
/**
* app下载链接 todo lr未完成
*/
public function downLine()
{
$get = $this->request->get();
$check = $this->validate($get, 'app\api\validate\App');
if (true !== $check) {
$this->_error($check);
}
if(isset($get['client']) && $get['client'] == Client_::ios){
$this->_success('', ['line' => ConfigServer::get('app', 'line_ios', '')]);
}else{
$this->_success('', ['line' => ConfigServer::get('app', 'line_android', '')]);
}
}
/**
* app初始化接口
* 苹果不允许单独只有微信第三方登录
*/
public function appInit()
{
$data = [
'wechat_login' => ConfigServer::get('app', 'wechat_login', '',0),//微信登录
//弹出协议
'agreement' => ConfigServer::get('app', 'agreement', '',1)
];
$this->_success('', $data);
}
/**
* Notes: 获取分享信息
* @author 张无忌(2021/1/20 17:04)
* @return array|mixed|string
*/
public function share()
{
$client = $this->request->get('client', Client_::mnp, 'intval');
$config = [];
switch ($client) {
case Client_::mnp:
$config = ConfigServer::get('share', 'mnp', [
'mnp_share_title' => '',
'mnp_share_image' => ''
]);
if (!empty($config['mnp_share_image']) and $config['mnp_share_image'] !== '') {
$config['mnp_share_image'] = UrlServer::getFileUrl($config['mnp_share_image']);
}
break;
case Client_::oa:
$config = ConfigServer::get('share', 'h5', [
'h5_share_title' => '',
'h5_share_intro' => '',
'h5_share_image' => ''
]);
if (!empty($config['h5_share_image']) and $config['h5_share_image'] !== '') {
$config['h5_share_image'] = UrlServer::getFileUrl($config['h5_share_image']);
}
break;
case Client_::android:
case Client_::ios:
$config = ConfigServer::get('share', 'app', [
'app_share_title' => '',
'app_share_intro' => '',
'app_share_image' => ''
]);
if (!empty($config['app_share_image']) and $config['app_share_image'] !== '') {
$config['app_share_image'] = UrlServer::getFileUrl($config['app_share_image']);
}
break;
}
return $this->_success('获取成功', $config);
}
/**
* Notes: 设置
* @author 段誉(2021/2/25 15:39)
*/
public function config()
{
$navigation = Db::name('dev_navigation')
->field('name,selected_icon,un_selected_icon')
->where('del', 0)
->order('id', 'desc')
->select();
foreach($navigation as &$item) {
$item['selected_icon'] = empty($item['selected_icon']) ? '' : UrlServer::getFileUrl($item['selected_icon']);
$item['un_selected_icon'] = empty($item['un_selected_icon']) ? '' : UrlServer::getFileUrl($item['un_selected_icon']);
}
$config = [
'register_setting' => ConfigServer::get('register_setting', 'open', 0),//注册设置-是否开启短信验证注册
'app_wechat_login' => ConfigServer::get('app', 'wechat_login', 0),//APP是否允许微信授权登录
'shop_login_logo' => UrlServer::getFileUrl(ConfigServer::get('website', 'shop_login_logo')),//移动端登录页logo
'web_favicon' => UrlServer::getFileUrl(ConfigServer::get('website', 'web_favicon')),//浏览器标签图标
'name' => ConfigServer::get('website', 'name'),//商城名称
'copyright_info' => ConfigServer::get('copyright', 'company_name'),//版权信息
'icp_number' => ConfigServer::get('copyright', 'number'),//ICP备案号
'icp_link' => ConfigServer::get('copyright', 'link'),//备案号链接
'app_agreement' => ConfigServer::get('app', 'agreement', 0),//app弹出协议
'ios_download' => ConfigServer::get('app', 'line_ios', ''),//ios_app下载链接
'android_download' => ConfigServer::get('app', 'line_android', ''),//安卓下载链接
'download_doc' => ConfigServer::get('app', 'download_doc', ''),//app下载文案
'cate_style' => ConfigServer::get('decoration', 'layout_no', 1),//分类页面风格
'index_setting' => [ // 首页设置
// 热销榜单
'logo' => ConfigServer::get('decoration', 'index_setting_logo', 1),
// 热销榜单
'hots' => ConfigServer::get('decoration', 'index_setting_hots', 1),
// 新品推荐
'news' => ConfigServer::get('decoration', 'index_setting_news', 1),
// 顶部背景图
'top_bg_image' => UrlServer::getFileUrl(ConfigServer::get('decoration', 'index_setting_top_bg_image', ''))
],
'center_setting' => [ // 个人中心设置
// 顶部背景图
'top_bg_image' => UrlServer::getFileUrl(ConfigServer::get('decoration', 'center_setting_top_bg_image', ''))
],
'navigation_setting' => [ // 底部导航设置
// 未选中文字颜色
'ust_color' => ConfigServer::get('decoration', 'navigation_setting_ust_color', '#000000'),
// 选中文字颜色
'st_color' => ConfigServer::get('decoration', 'navigation_setting_st_color', '#000000'),
// 顶部背景图
// 'top_bg_image' => UrlServer::getFileUrl(ConfigServer::get('decoration', 'navigation_setting_top_bg_image', ''))
],
// 首页底部导航菜单
'navigation_menu' => $navigation,
// 网站名称
'website_name' => ConfigServer::get('website', 'name')
];
$this->_success('', $config);
}
/**
* @notes 版权资质
* @author ljj
* @date 2022/2/22 3:09 下午
*/
public function copyright()
{
$result = IndexLogic::copyright();
$this->_success('', $result);
}
}
@@ -0,0 +1,48 @@
<?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\controller;
use app\api\logic\LiveRoomLogic;
/**
* 直播 控制器层
* Class LiveRoom
* @package app\api\controller
*/
class LiveRoom extends ApiBase
{
public $like_not_need_login = ['lists'];
/**
* @notes 获取直播信息列表
* @author heshihu
* @date 2021/10/14 10:08
*/
public function lists()
{
$live_room = LiveRoomLogic::lists($this->page_no, $this->page_size);
if(is_string($live_room)){
$this->_error($live_room);
}
$this->_success('获取成功', $live_room);
}
}
@@ -0,0 +1,103 @@
<?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\controller;
use app\api\logic\LoginPasswordLogic;
class LoginPassword extends ApiBase
{
public $like_not_need_login = ['check', 'checkcode', 'forget'];
/**
* showdoc
* @catalog 接口/登录注册
* @title 密码登录
* @description 密码登录
* @method post
* @url /login_password/check
* @param mobile 必填 int 手机号
* @param password 必填 varchar 密码
* @param client 选填 int 不填默认1小程序-2h5-3ios-4安卓
* @return_param token varchar token
* @remark
* @number 1
* @return {"code":1,"msg":"登录成功","data":{"token":"d2800867ac869c52a7a017b89209907d"},"show":0,"time":"0.125048","debug":{"request":{"get":[],"post":{"mobile":"13711515723","password":"123456czw"},"header":{"content-length":"288","content-type":"multipart\/form-data; boundary=--------------------------249270077524121393881040","connection":"keep-alive","accept-encoding":"gzip, deflate, br","host":"www.likeb2b2c.com:20002","postman-token":"883b6917-66c2-4995-a882-fbc5625bad33","accept":"*\/*","user-agent":"PostmanRuntime\/7.26.2","token":"ff0c66fe0c89fe1e9be591d82d551521"}}}}
*/
public function check()
{
$post = $this->request->post();
$result = $this->validate($post, 'app\api\validate\LoginPassword.add');
if ($result === true) {
$check = LoginPasswordLogic::check($post);
if ($check) {
$this->_error($check['msg'], $check['data'], $check['code']);
}
$this->_error('获取失败', $result, 0);
}
$this->_error($result, '', 0);
}
/**
* showdoc
* @catalog 接口/登录注册
* @title 验证码登录
* @description 验证码登录
* @method post
* @url /login_password/checkCode
* @param mobile 必填 int 手机号
* @param code 必填 varchar 验证码
* @param client 选填 int 不填默认1小程序-2h5-3ios-4安卓
* @return_param token varchar token
* @remark
* @number 1
* @return {"code":1,"msg":"登录成功","data":{"token":"c108d186a4e62bc3ac6004074930d43b"},"show":0,"time":"0.136925","debug":{"request":{"get":[],"post":{"mobile":"13711515723","code":"8888"},"header":{"content-length":"279","content-type":"multipart\/form-data; boundary=--------------------------405368968101365594543781","connection":"keep-alive","accept-encoding":"gzip, deflate, br","host":"www.likeb2b2c.com:20002","postman-token":"cd4c0d70-e3b5-4576-9f8d-58bbdb6f0e5f","accept":"*\/*","user-agent":"PostmanRuntime\/7.26.2","token":"ff0c66fe0c89fe1e9be591d82d551521"}}}}
*/
public function checkCode()
{
$post = $this->request->post();
$post['message_key'] = 'YZMDL';
$result = $this->validate($post, 'app\api\validate\LoginPassword.code');
if ($result === true) {
$check = LoginPasswordLogic::checkCode($post);
if ($check) {
$this->_error($check['msg'], $check['data'], $check['code']);
}
$this->_error('获取失败', $result, 0);
}
$this->_error($result, '', 0);
}
//忘记密码
public function forget()
{
$post = $this->request->post();
$post['message_key'] = 'ZHMM';
$result = $this->validate($post, 'app\api\validate\LoginPassword.forget');
if ($result === true) {
return LoginPasswordLogic::forget($post);
}
$this->_error($result);
}
}
@@ -0,0 +1,60 @@
<?php
namespace app\api\controller;
use app\api\logic\LuckdrawLogic;
class Luckdraw extends ApiBase
{
/**
* Notes: 抽奖奖品
* @author 张无忌(2021/1/26 16:07)
*/
public function prize()
{
$lists = LuckdrawLogic::getPrize($this->user_id);
$this->_success('OK', $lists);
}
/**
* Notes: 用户抽奖记录
* @author 张无忌(2021/1/26 16:14)
*/
public function record()
{
$lists = LuckdrawLogic::getUserRecord($this->user_id, $this->page_no, $this->page_size);
$this->_success('OK', $lists);
}
/**
* Notes: 抽奖 start
* @author 张无忌(2021/1/26 17:00)
*/
public function draw()
{
$check = $this->validate(['user_id' => $this->user_id],'app\api\validate\Luckdraw');
if (true !== $check) {
$this->_error($check);
}
$result = LuckdrawLogic::draw($this->user_id);
if ($result) {
$this->_success('OK', $result);
}
$error = LuckdrawLogic::getError() ?: '抽奖失败';
$this->_error($error);
}
/**
* @notes 中奖列表
* @author 段誉
* @date 2022/2/17 15:41
*/
public function winList()
{
$result = LuckdrawLogic::getWinList($this->page_no, $this->page_size);
$this->_success('OK', $result);
}
}
@@ -0,0 +1,33 @@
<?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\controller;
use app\api\logic\MenuLogic;
class Menu extends ApiBase
{
public $like_not_need_login = ['lists'];
public function lists()
{
$type = $this->request->get('type', 1);
$list = MenuLogic::getMenu($type,$this->user_info);
return $this->_success('获取成功', $list);
}
}
@@ -0,0 +1,42 @@
<?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\controller;
use app\common\logic\NoticeLogic;
class Notice extends ApiBase
{
//消息中心
public function index()
{
$this->_success('获取成功', NoticeLogic::index($this->user_id));
}
//列表
public function lists()
{
$type = $this->request->get('type');
$page = $this->request->get('page_no', $this->page_no);
$size = $this->request->get('page_size', $this->page_size);
$this->_success('获取成功', NoticeLogic::lists($this->user_id, $type, $page, $size));
}
}
+221
View File
@@ -0,0 +1,221 @@
<?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\controller;
use app\api\logic\OrderLogic;
use app\common\model\Client_;
use app\common\server\ConfigServer;
use app\common\server\WechatMiniExpressSendSyncServer;
use think\Db;
/**
* 订单
* Class Order
* @package app\api\controller
*/
class Order extends ApiBase
{
//订单列表
public function lists()
{
$type = $this->request->get('type', 'all');
$order_list = OrderLogic::getOrderList($this->user_id, $type, $this->page_no, $this->page_size);
$this->_success('获取成功', $order_list);
}
//下单接口
public function buy()
{
$post = $this->request->post();
$post['user_id'] = $this->user_id;
$post['client'] = $this->client;
$check = $this->validate($post, 'app\api\validate\Order.buy');
if (true !== $check) {
$this->_error($check);
}
$action = $post['action'];
$info = OrderLogic::info($post, $this->user_id);
if ($info['code'] == 0) {
$this->_error($info['msg']);
}
if ($action == 'info') {
$this->_success('', $info['data']);
}
$order = OrderLogic::add($this->user_id, $info['data'], $post);
return $order;
}
//订单详情
public function detail()
{
$order_id = $this->request->get('id');
if (!$order_id){
$this->_error('请选择订单');
}
$order_detail = OrderLogic::getOrderDetail($order_id, $this->user_id);
if (!$order_detail) {
$this->_error('订单不存在了!', '');
}
$this->_success('获取成功', $order_detail);
}
/**
* @notes 微信确认收货 获取详情
* @return \think\response\Json
* @author lbzy
* @datetime 2023-09-05 09:51:41
*/
function wxReceiveDetail()
{
return $this->_success('获取成功', OrderLogic::wxReceiveDetail(input('order_id/d'), $this->user_id));
}
//取消订单
public function cancel()
{
$order_id = $this->request->post('id');
if (empty($order_id)) {
$this->_error('参数错误');
}
return OrderLogic::cancel($order_id, $this->user_id);
}
//删除订单
public function del()
{
$order_id = $this->request->post('id');
if (empty($order_id)) {
$this->_error('参数错误');
}
return OrderLogic::del($order_id, $this->user_id);
}
//确认订单
public function confirm()
{
$order_id = $this->request->post('id');
if (empty($order_id)) {
$this->_error('参数错误');
}
return OrderLogic::confirm($order_id, $this->user_id);
}
public function orderTraces()
{
$order_id = $this->request->get('id');
$tips = '参数错误';
if ($order_id) {
$traces = OrderLogic::orderTraces($order_id, $this->user_id);
if ($traces) {
$this->_success('获取成功', $traces);
}
$tips = '暂无物流信息';
}
$this->_error($tips);
}
/**
* @notes 核销订单列表
* @author ljj
* @date 2021/8/18 3:58 下午
*/
public function verificationLists()
{
$type = $this->request->get('type',\app\common\model\Order::NOT_WRITTEN_OFF);
$lists = OrderLogic::verificationLists($type, $this->user_id, $this->page_no, $this->page_size);
$this->_success('获取成功', $lists);
}
/**
* @notes 提货核销
* @author ljj
* @date 2021/8/18 4:36 下午
*/
public function verification()
{
$post = $this->request->post();
$post['user_id'] = $this->user_id;
$check = $this->validate($post, 'app\api\validate\Order.verification');
if (true !== $check) {
$this->_error($check);
}
$result = OrderLogic::verification($post);
$this->_success('获取成功',$result);
}
/**
* @notes 确认提货
* @author ljj
* @date 2021/8/18 7:02 下午
*/
public function verificationConfirm()
{
$post = $this->request->post();
$post['user_id'] = $this->user_id;
$result = OrderLogic::verificationConfirm($post);
if (true !== $result) {
$this->_error($result);
}
$this->_success('提货成功');
}
/**
* @notes 获取配送方式
* @author ljj
* @date 2021/8/19 7:17 下午
*/
public function getDeliveryType()
{
$data = OrderLogic::getDeliveryType();
$this->_success('获取成功',$data);
}
/**
* @notes 微信同步发货 查询
* @return \think\response\Json
* @author lbzy
* @datetime 2023-09-07 15:27:17
*/
function wechatSyncCheck()
{
$id = $this->request->get('id');
$order = \app\common\model\Order::where('id', $id)->where('user_id', $this->user_id)->findOrEmpty();
$result = WechatMiniExpressSendSyncServer::wechatSyncCheck($order);
if (! $result) {
$this->_error('获取失败');
}
$this->_success('成功', $result);
}
}
@@ -0,0 +1,256 @@
<?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\controller;
use app\api\model\Order;
use app\common\model\Order as CommonOrder;
use app\common\model\Client_;
use app\common\server\AliPayServer;
use app\common\server\ConfigServer;
use app\common\server\WeChatPayServer;
use app\common\server\WeChatServer;
use app\common\logic\PaymentLogic;
use app\common\model\Pay;
use think\Db;
/**
* 支付逻辑
* Class Payment
* @package app\api\controller
*/
class Payment extends ApiBase
{
public $like_not_need_login = ['aliNotify', 'notifyMnp', 'notifyOa', 'notifyApp'];
/**
* Notes: 预支付
* @author 段誉(2021/2/23 14:33)
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function prepay()
{
$post = $this->request->post();
if(!isset($post['from']) || !isset($post['order_id']) || !isset($post['pay_way'])) {
$this->_error('参数缺失');
}
switch ($post['from']) {
case 'order':
$order = Order::get($post['order_id']);
if ($order['order_status'] == CommonOrder::STATUS_CLOSE || $order['del'] == 1) {
$this->_error('订单已关闭');
}
break;
case 'recharge':
$order = Db::name('recharge_order')->where(['id' => $post['order_id']])->find();
break;
}
//找不到订单
if (empty($order)) {
$this->_error('订单不存在');
}
// 变更支付方式
$order['pay_way'] = $post['pay_way'];
//已支付
if ($order['pay_status'] == Pay::ISPAID) {
$this->_success('支付成功', ['order_id' => $order['id']], 10000);
}
$result = PaymentLogic::pay($post['from'], $order, $this->client);
if (false === $result) {
$this->_error(PaymentLogic::getError(), ['order_id' => $order['id']], PaymentLogic::getReturnCode());
}
if (PaymentLogic::getReturnCode() != 0) {
$this->_success('', $result, PaymentLogic::getReturnCode());
}
$this->_success('', $result);
}
/**
* Notes: pc端预支付 NATIVE
* @author 段誉(2021/3/18 16:03)
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function pcPrepay()
{
$post = $this->request->post();
$order = Order::get($post['order_id']);
$order['pay_way'] = $post['pay_way'];
$return_msg = ['order_id' => $order['id'], 'order_amount' => $order['order_amount']];
//找不到订单
if (empty($order)) {
$this->_error('订单不存在');
}
if ($order['order_status'] == CommonOrder::STATUS_CLOSE || $order['del'] == 1) {
$this->_error('订单已关闭');
}
//已支付
if ($order['pay_status'] == Pay::ISPAID) {
$this->_success('支付成功', $return_msg, 10001);
}
$result = PaymentLogic::pcPay($order, $post['order_source']);
if (false === $result) {
$this->_error(PaymentLogic::getError(), $return_msg, PaymentLogic::getReturnCode());
}
if ($order['pay_way'] == Pay::BALANCE_PAY) {
$this->_success('支付成功', $return_msg, PaymentLogic::getReturnCode());
}
$return_msg['data'] = $result;
if (PaymentLogic::getReturnCode() != 0) {
$this->_success('支付成功', $return_msg, PaymentLogic::getReturnCode());
}
$this->_success('支付成功', $return_msg);
}
/**
* Notes: 小程序回调
* @author 段誉(2021/2/23 14:34)
*/
public function notifyMnp()
{
$config = WeChatServer::getPayConfig(Client_::mnp);
return WeChatPayServer::notify($config);
}
/**
* Notes: 公众号回调
* @author 段誉(2021/2/23 14:34)
*/
public function notifyOa()
{
$config = WeChatServer::getPayConfig(Client_::oa);
return WeChatPayServer::notify($config);
}
/**
* Notes: APP回调
* @author 段誉(2021/2/23 14:34)
*/
public function notifyApp()
{
$config = WeChatServer::getPayConfig(Client_::ios);
return WeChatPayServer::notify($config);
}
/**
* Notes: 支付宝回调
* @author 段誉(2021/3/23 11:37)
*/
public function aliNotify()
{
$data = $this->request->post();
$result = (new AliPayServer())->verifyNotify($data);
if (true === $result) {
echo 'success';
} else {
echo 'fail';
}
}
/**
* Notes:
* @author 段誉(2021/3/23 11:36)
* @return \think\Model[]
*/
public function payway()
{
$params = $this->request->get();
if(!isset($params['from']) || !isset($params['order_id'])) {
return $this->_error('参数缺失');
}
if($params['from'] == 'order') {
$order = Db::name('order')->where('id', $params['order_id'])->find();
}else if($params['from'] == 'recharge') {
$order = Db::name('recharge_order')->where('id', $params['order_id'])->find();
}
$payModel = new Pay();
$pay = $payModel->where(['status' => 1])->order('sort')->hidden(['config'])->select()->toArray();
foreach ($pay as $k => &$item) {
if ($item['code'] == 'wechat') {
$item['extra'] = '微信快捷支付';
$item['pay_way'] = Pay::WECHAT_PAY;
}
if ($item['code'] == 'balance') {
$user_money = Db::name('user')->where(['id' => $this->user_id])->value('user_money');
$item['extra'] = '可用余额:'.$user_money;
$item['pay_way'] = Pay::BALANCE_PAY;
}
if ($item['code'] == 'alipay') {
$item['extra'] = '';
$item['pay_way'] = Pay::ALI_PAY;
}
if (in_array($this->client, [Client_::mnp, Client_::oa]) && $item['code'] == 'alipay') {
unset($pay[$k]);
}
if($params['from'] == 'recharge' && $item['code'] == 'balance') {
unset($pay[$k]);
}
}
// 订单自动取消时间
$cancelTime = ConfigServer::get('trading', 'order_cancel');
if(empty($cancelTime)) {
// 前端检测为0时不显示倒计时
$cancelTime = 0;
}else{
// 订单创建时间 + 后台设置自动关闭未付款订单时长
$cancelTime = $order['create_time'] + intval($cancelTime) * 60;
}
$data = [
'pay' => array_values($pay),
'order_amount' => $order['order_amount'],
'cancel_time' => $cancelTime,
];
$this->_success('', $data);
}
}
+70
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\api\controller;
use app\api\logic\PcLogic;
class Pc extends ApiBase{
public $like_not_need_login = ['index','commonData','goodsList'];
/**
* Notes: pc端首页接口
* @author: 2021/3/5 12:00
*/
public function index(){
$lists = PcLogic::pcLists();
return $this->_success('',$lists);
}
/**
* Notes:pc广告公告数据
* @author: 2021/3/5 18:00
*/
public function commonData(){
return $this->_success('',PcLogic::commonData($this->user_id));
}
/**
* Notes:获取商品列表
* @author: 2021/3/5 17:19
*/
public function goodsList(){
$type = $this->request->get('type',1);
$sort_type = $this->request->get('sort_type','');
$sort = $this->request->get('sort','');
$name = $this->request->get('name','');
$category_id = $this->request->get('category_id','');
$list = PcLogic::goodsList($this->page_no,$this->page_size,$name,$category_id,$type,$sort_type,$sort);
return $this->_success('',$list);
}
/**
* Notes:修改用户信息
* @author: 2021/3/8 19:07
*/
public function changeUserInfo(){
$post = $this->request->post();
$post['user_id'] = $this->user_id;
$result = $this->validate($post,'app\api\validate\ChangeUserInfo.pc');
if(true === $result){
PcLogic::changeUserInfo($post);
return $this->_success('保存成功');
}
return $this->_error($result);
}
}
@@ -0,0 +1,53 @@
<?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\controller;
use app\api\logic\PolicyLogic;
class Policy extends ApiBase
{
public $like_not_need_login = ['service', 'privacy', 'aftersale'];
/**
* 服务协议
*/
public function service()
{
$this->_success('获取成功', PolicyLogic::service());
}
/**
* 隐私政策
*/
public function privacy()
{
$this->_success('获取成功', PolicyLogic::privacy());
}
/**
* 售后保障
*/
public function afterSale()
{
$this->_success('获取成功', PolicyLogic::afterSale());
}
}
@@ -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\api\controller;
use app\api\logic\RechargeLogic;
class Recharge extends ApiBase{
public $like_not_need_login = ['rechargetemplate'];
/**
* note 充值模板
* create_time 2020/10/24 15:56
*/
public function rechargeTemplate(){
$list = RechargeLogic::getTemplate();
$this->_success('',$list);
}
/**
* note 充值
* create_time 2020/10/24 15:56
*/
public function recharge(){
$post = $this->request->post();
$result = $this->validate($post,'app\api\validate\Recharge');
if($result === true){
$data = RechargeLogic::recharge($this->user_id,$this->client,$post);
if($data){
$this->_success('',$data);
}
$this->_error('信息获取错误');
}
$this->_error($result);
}
/**
* 充值记录
*/
public function rechargeRecord()
{
$get = $this->request->get();
$get['page_no'] = $get['page_no'] ?? $this->page_no;
$get['page_size'] = $get['page_size'] ?? $this->page_size;
$get['user_id'] = $this->user_id;
$result = RechargeLogic::rechargeRecord($get);
return $this->_success('',$result);
}
}
@@ -0,0 +1,35 @@
<?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\controller;
use app\api\logic\RegionLogic;
class Region extends ApiBase
{
public $like_not_need_login = ['lists'];
public function lists()
{
$lists = RegionLogic::lists();
$this->_success('获取成功', $lists);
}
}
@@ -0,0 +1,79 @@
<?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\controller;
use app\api\logic\SeckillLogic;
class Seckill extends ApiBase{
public $like_not_need_login = ['seckilltime','seckillgoods'];
/**
* showdoc
* @catalog 接口/营销
* @title 获取秒杀时间段
* @description 获取秒杀时间段
* @method get
* @url /seckill/seckillTime
* @return {"code":1,"msg":"获取成功","data":[{"id":"1","start_time":"08:00","end_time":"10:00","is_open":0,"tips":"已结束"},{"id":"2","start_time":"11:00","end_time":"14:00","is_open":1,"tips":"抢购中"},{"id":"3","start_time":"14:00","end_time":"18:00","is_open":0,"tips":"未开始"},{"id":"4","start_time":"20:00","end_time":"22:00","is_open":0,"tips":"未开始"}],"show":0,"time":"0.274701","debug":{"request":{"get":[],"post":[],"header":{"connection":"keep-alive","accept-encoding":"gzip, deflate, br","host":"www.likeb2b2c.com:20002","postman-token":"bd852ce3-cbe9-4c66-bb91-7e34eb223716","cache-control":"no-cache","accept":"*\/*","user-agent":"PostmanRuntime\/7.26.1","content-type":"","content-length":""}}}}
* @return_param id int 活动id
* @return_param start_time varchar 开始时间
* @return_param end_time varchar 结束时间
* @return_param status int 状态0-未开始,1-抢购中;2-已结束
* @return_param tips string 提示
* @remark
* @number 1
*/
public function seckillTime(){
$list = SeckillLogic::seckillTime();
$this->_success('获取成功',$list);
}
/**
* showdoc
* @catalog 接口/营销
* @title 获取秒杀商品
* @description 获取秒杀商品
* @method get
* @url /seckill/seckillGoods
* @return {"code":1,"msg":"获取成功","data":{"list":[{"name":"华为儿童手表3 pro智能电话中小学生天才男女孩防水可爱运动多功能视频拍照通话gps定位4g电信版官方旗舰店","id":"2","image":"http:\/\/www.likeb2b2c.com:20002\/uploads\/images\/20200709\/161c78cbefc68afbbb0e1856b1a9a596.png","min_price":"789.00","seckill_price":"720.00","sales_sum":"0"},{"name":"雀巢(Nestle)脆脆鲨 休闲零食 威化饼干巧克力味24*20g+8*20g","id":"7","image":"http:\/\/www.likeb2b2c.com:20002\/uploads\/images\/20200710\/cd7dfb551061f353ba53d21c2a2275c4.jpg","min_price":"42.99","seckill_price":"40.00","sales_sum":"0"}],"page":1,"size":15,"count":2,"more":0},"show":0,"time":"0.449604","debug":{"request":{"get":{"id":"2"},"post":[],"header":{"connection":"keep-alive","accept-encoding":"gzip, deflate, br","host":"www.likeb2b2c.com:20002","postman-token":"91999655-047e-4144-8de2-bedf1e3fac90","cache-control":"no-cache","accept":"*\/*","user-agent":"PostmanRuntime\/7.26.1","content-type":"","content-length":""}}}}
* @param id 必填 int 活动id
* @param page_no 选填 int 页码(默认第一页)
* @param page_size 选填 int 每页数量(默认15)
* @return_param name string 商品名称
* @return_param id int 商品id
* @return_param image array 商品图片
* @return_param min_price float 商品最小价
* @return_param sales_sum int 销量
* @return_param seckill_price float 商品秒杀价
* @return_param shop_id int 店铺id
* @remark
* @number 1
*/
public function seckillGoods(){
$id = $this->request->get('id');
if($id){
$list = SeckillLogic::seckillGoods($id,$this->page_no,$this->page_size);
$this->_success('获取成功',$list);
}
$this->_error('缺少参数');
}
}
@@ -0,0 +1,50 @@
<?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\controller;
use app\api\logic\SelffetchShopLogic;
class SelffetchShop extends ApiBase
{
/**
* @notes 查看自提门店列表
* @author ljj
* @date 2021/8/24 4:59 下午
*/
public function lists()
{
$params['longitude'] = $this->request->get('longitude', '113.280637');
$params['latitude'] = $this->request->get('latitude', '23.125178');
$lists = SelffetchShopLogic::lists($params, $this->page_no, $this->page_size);
$this->_success('获取成功', $lists);
}
/**
* @notes 获取百度地图密钥
* @author ljj
* @date 2021/8/24 5:01 下午
*/
public function getMapKey()
{
$result = SelffetchShopLogic::getMapKey();
$this->_success('获取成功', $result);
}
}
@@ -0,0 +1,28 @@
<?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\controller;
use app\api\logic\ServiceLogic;
class Service extends ApiBase {
public $like_not_need_login = ['lists'];
public function lists(){
$list = ServiceLogic::getConfig();
$this->_success('获取成功',$list);
}
}
@@ -0,0 +1,90 @@
<?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\controller;
use app\api\logic\ShareLogic;
use app\common\model\BargainLaunch;
class Share extends ApiBase
{
public function shareGoods()
{
$id = $this->request->get('id');
$url = $this->request->get('url');
$client = $this->client;
if ($id && $url) {
$result = ShareLogic::shareGoods($this->user_id, $id, $url, $client);
$this->_success($result['msg'], $result['data'], $result['code']);
}
$this->_error('缺少参数', '');
}
/**
* Notes: 用户分销海报
* @return array
* @author 段誉(2021/3/18 10:28)
*/
public function userPoster()
{
$url = $this->request->get('url');
$client = $this->client;
if (empty($client)) {
$this->_error('参数缺失');
}
$result = ShareLogic::getUserPoster($this->user_id, $url, $client);
return $result;
}
/**
* Notes:砍价分享
* @author: 2021/2/25 11:22
*/
public function shareBargain()
{
$id = $this->request->get('id');
$url = $this->request->get('url');
$result = $this->validate(['id' => $id, 'url' => $url], 'app\api\validate\Bargain.share');
if (true === $result) {
$result = ShareLogic::shareBargain($this->user_id, $id, $url, $this->client);
$this->_success($result['msg'], $result['data'], $result['code']);
}
$this->_error($result);
}
/**
* @notes 获取二维码
* @author cjhao
* @date 2021/11/25 10:47
*/
public function getMnQrcode()
{
$get = $this->request->get();
$result = $this->validate($get,'app\api\validate\MakeMnQrcode');
if(true === $result){
$result = ShareLogic::getMnQrcode($this->user_id,$get);
if(1 === $result['code']){
$this->_success('',$result['data']);
}
$this->_error($result['msg']);
}
$this->_error($result);
}
}
@@ -0,0 +1,92 @@
<?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\controller;
use app\api\logic\SignLogic;
use app\common\server\ConfigServer;
class sign extends ApiBase{
/**
* showdoc
* @catalog 接口/签到
* @title 获取签到列表
* @description 获取签到列表
* @method get
* @url /sign/lists
* @return {"code":1,"msg":"获取成功","data":{"lists":[{"days":"1","sign_time":null,"status":"0","integral":"22","growth":"552"},{"days":"2","sign_time":null,"status":"0","integral":"22","growth":"552"},{"days":"3","sign_time":null,"status":"0","integral":63,"growth":563},{"days":"4","sign_time":null,"status":"0","integral":66,"growth":596},{"days":"5","sign_time":null,"status":"0","integral":"22","growth":"552"},{"days":"6","sign_time":null,"status":"0","integral":66,"growth":574}],"message":{"user_integral":"5041","days":"0"}},"show":0,"time":"0.126686","debug":{"request":{"get":[],"post":[],"header":{"connection":"keep-alive","accept-encoding":"gzip, deflate, br","host":"www.likeb2b2c.com:20002","postman-token":"75a16271-edbd-4172-a238-a7d36ed07019","accept":"*\/*","user-agent":"PostmanRuntime\/7.26.2","token":"ff0c66fe0c89fe1e9be591d82d551521","content-type":"","content-length":""}}}}
* @return_param days int 天数列表
* @return_param sign_time int 签到时间
* @return_param status int 签到状态
* @return_param integral int 积分值
* @return_param growth int 成长值
* @return_param user_integral int 用户积分
* @return_param user_growth int 用户成长值
* @remark
* @number 1
*/
public function lists(){
$sign = SignLogic::lists($this->user_id);
$this->_success('获取成功',$sign);
}
/**
* showdoc
* @catalog 接口/签到
* @title 签到
* @description 签到
* @method get
* @url /sign/sign
* @return {"code":1,"msg":"获取成功","data":{"integral":"22","growth":"552","day":1},"show":0,"time":"0.201775","debug":{"request":{"get":[],"post":[],"header":{"connection":"keep-alive","accept-encoding":"gzip, deflate, br","host":"www.likeb2b2c.com:20002","postman-token":"1c4ef02d-b268-4ba7-a5df-c5b6a5f3d630","accept":"*\/*","user-agent":"PostmanRuntime\/7.26.2","token":"ff0c66fe0c89fe1e9be591d82d551521","content-type":"","content-length":""}}}}
* @return_param integral int 获得积分值
* @return_param growth int 获得成长值
* @return_param days int 连续天数
* @remark
* @number 1
*/
public function sign(){
$result = $this->validate(['user_id'=>$this->user_id],'app\api\validate\Sign');
if($result === true){
$result = SignLogic::sign($this->user_id);
if(is_array($result)){
$this->_success('签到成功',$result);
}
}
$this->_error($result);
}
/**
* showdoc
* @catalog 接口/签到
* @title 获取签到规则
* @description 获取签到规则
* @method get
* @url /sign/rule
* @return {"code":1,"msg":"获取成功","data":"1.每天签到可以获得每天签到奖励;\n2.每日最多可签到1次,断签则会重新计算连签天数,达到连续天数后即可获得连续奖励;\n3.活动以及奖励最终解释权归商家所有。\n","show":0,"time":"0.173280","debug":{"request":{"get":[],"post":[],"header":{"connection":"keep-alive","accept-encoding":"gzip, deflate, br","host":"www.likeb2b2c.com:20002","postman-token":"e8617112-b05d-4bea-a8d8-424a674f1c84","accept":"*\/*","user-agent":"PostmanRuntime\/7.26.2","token":"ff0c66fe0c89fe1e9be591d82d551521","content-type":"","content-length":""}}}}
* @return_param * text 规则
* @remark
* @number 1
*/
public function rule(){
$rule = ConfigServer::get('sign_rule','instructions','');
$this->_success('获取成功',$rule);
}
}
+52
View File
@@ -0,0 +1,52 @@
<?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\controller;
use app\api\logic\SmsLogic;
class Sms extends ApiBase{
public $like_not_need_login = ['send'];
/**
* showdoc
* @catalog 接口/短信
* @title 发送短信
* @description 发送短信
* @method post
* @url /sms/send
* @return {"code":1,"msg":"发送成功","data":[],"show":0,"time":"0.612711","debug":{"request":{"get":[],"post":{"mobile":"13172565144","key":"ZCYZ"},"header":{"content-length":"278","content-type":"multipart\/form-data; boundary=--------------------------990456238154467810004652","connection":"keep-alive","accept-encoding":"gzip, deflate, br","host":"www.likeb2b2c.com:20002","postman-token":"d517ed7f-5a49-46e2-b975-8828e0475501","cache-control":"no-cache","accept":"*\/*","user-agent":"PostmanRuntime\/7.26.3"}}}}
* @return_param id int 订单id
* @param mobile 必填 int 手机号码
* @param key 必填 int 事件:ZCYZ-注册验证;ZHMM-找回密码;YZMDL-验证码登录; BGSJHM-更换手机号;BDSJHM-绑定手机号码
* @remark 这里是备注信息
* @number 0
*/
public function send(){
$mobile = $this->request->post('mobile');
$key = $this->request->post('key','ZCYZ');
$result = $this->validate(['mobile'=>$mobile,'key'=>$key],'app\api\validate\SmsSend');
if($result !== true){
$this->_error($result);
}
$send_result = SmsLogic::send($mobile,$key, $this->user_id);
if($send_result !== true){
$this->_error($send_result);
}
$this->_success('发送成功');
}
}
@@ -0,0 +1,38 @@
<?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\controller;
use app\api\logic\SubscribeLogic;
class Subscribe extends ApiBase
{
public $like_not_need_login = ['lists'];
public function lists()
{
$scene = $this->request->get('scene');
if (!$scene) {
$this->_error('缺少场景scene参数');
}
$lists = SubscribeLogic::lists($scene);
return $this->_success('获取成功', $lists);
}
}
@@ -0,0 +1,90 @@
<?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\controller;
use app\api\logic\TeamLogic;
/**
* 拼团
* Class Team
* @package app\api\controller
*/
class Team extends ApiBase
{
public $like_not_need_login = ['teamGoodsList'];
// 拼团商品列表
public function teamGoodsList()
{
$lists = TeamLogic::getTeamGoodsList($this->page_no, $this->page_size);
if ($lists) {
$this->_success('获取成功', $lists);
} else {
$this->_error(TeamLogic::getError());
}
}
//参与拼团活动
public function buy()
{
$post = $this->request->post();
$post['user_id'] = $this->user_id;
$post['client'] = $this->client;
$check = $this->validate($post, 'app\api\validate\Team.add');
if (true !== $check) {
$this->_error($check);
}
TeamLogic::setUser($this->user_id);
TeamLogic::setTeamId($post['team_id']);
TeamLogic::setTeamGoodsItem($post['item_id']);
TeamLogic::setTeamGoodsNum($post['goods_num']);
TeamLogic::setIntegralConfig();
$info = TeamLogic::calculateInfo($post, $this->user_id);
if ($info === false){
$this->_error(TeamLogic::getError());
}
if($post['action'] == 'info'){
$this->_success('', $info);
}
$order = TeamLogic::buy($this->user_id, $info, $post);
if ($order === false){
$this->_error(TeamLogic::getError());
}
$this->_success('', $order);
}
//验证拼团
public function check()
{
$post = $this->request->post();
$post['user_id'] = $this->user_id;
$check = $this->validate($post, 'app\api\validate\Team.check');
if (true !== $check) {
$this->_error($check);
}
$this->_success();
}
}
@@ -0,0 +1,22 @@
<?php
namespace app\api\controller;
use app\admin\logic\WechatMerchantTransferLogic;
use app\admin\model\WithdrawApply;
class Test extends ApiBase
{
public $like_not_need_login = ['test'];
public function test()
{
$withdraw = WithdrawApply::where('id', 1)->findOrEmpty()->toArray();
$result = WechatMerchantTransferLogic::transfer($withdraw);
// $result = WechatMerchantTransferLogic::details($withdraw);
halt($result);
}
}
+363
View File
@@ -0,0 +1,363 @@
<?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\controller;
use app\api\logic\UserLogic;
use think\Db;
use app\common\server\UrlServer;
use app\api\logic\SmsLogic;
use app\common\logic\SmsLogic as CommonSmsLogic;
class User extends ApiBase
{
/**
* Notes:个人中心接口
* @author: 2021/3/10 10:13
*/
public function center()
{
$info = UserLogic::center($this->user_id);
$this->_success('获取成功', $info);
}
/**
* Notes:用户信息
* @author: 2021/3/10 10:13
*/
public function info()
{
$this->_success('获取成功', UserLogic::getUserInfo($this->user_id));
}
/**
* Notes:设置用户手机号码
* @author: 2021/3/10 10:13
*/
public function setInfo()
{
$data = $this->request->post();
$data['user_id'] = $this->user_id;
$check = $this->validate($data, 'app\api\validate\UpdateUser.set');
if (true !== $check) {
$this->_error($check);
}
UserLogic::setUserInfo($this->user_id, $data);
$this->_success('操作成功');
}
/**
* Notes:账户流水
* @author: 2021/3/10 10:13
*/
public function accountLog()
{
$source = $this->request->get('source');
$type = $this->request->get('type', 0);
$list = [];
if ($source) {
$list = UserLogic::accountLog($this->user_id, $source, $type, $this->page_no, $this->page_size);
}
$this->_success('获取成功', $list);
}
//更换手机号
public function changeMobile()
{
$data = $this->request->post();
//默认绑定手机号码
$data['message_key'] = 'BDSJHM';
$data['client'] = $this->client;
$validate = 'app\api\validate\ChangeMobile.binding';
//更换手机号码、替换短信key、验证规则
if (isset($data['action']) && 'change' == $data['action']) {
$data['message_key'] = 'BGSJHM';
$validate = 'app\api\validate\ChangeMobile';
}
$data['user_id'] = $this->user_id;
$check = $this->validate($data, $validate);
if (true !== $check) {
$this->_error($check);
}
$res = UserLogic::changeMobile($this->user_id, $data);
if ($res) {
$this->_success('操作成功');
}
$this->_error('操作失败');
}
//获取微信手机号
public function getMobile()
{
$post = $this->request->post();
$post['user_id'] = $this->user_id;
$check = $this->validate($post, 'app\api\validate\WechatMobile');
if (true !== $check) {
$this->_error($check);
}
return UserLogic::getMobileByMnp($post);
}
//我的粉丝
public function fans()
{
$get = $this->request->get();
$page = $this->request->get('page_no', $this->page_no);
$size = $this->request->get('page_size', $this->page_size);
$this->_success('', UserLogic::fans($this->user_id, $get, $page, $size));
}
/**
* note 我的钱包
* create_time 2020/11/27 16:58
*/
public function myWallet()
{
$info = UserLogic::myWallet($this->user_id);
$this->_success('获取成功', $info);
}
/**
* Notes: 我的拼团
* @author 张无忌(2021/1/14 18:43)
*/
public function myTeam()
{
$page = $this->request->get('page_no', $this->page_no);
$size = $this->request->get('page_size', $this->page_size);
$status = $this->request->get('status', -1);
$info = UserLogic::myTeam($this->user_id, $status, $page, $size);
$this->_success('获取成功', $info);
}
/**
* Notes: 更新微信的用户信息
* @author 段誉(2021/4/7 15:28)
*/
public function setWechatInfo()
{
$data = $this->request->post();
$check = $this->validate($data, 'app\api\validate\SetWechatUser');
if (true !== $check) {
$this->_error($check);
}
$res = UserLogic::updateWechatInfo($this->user_id, $data);
if (true === $res) {
$this->_success('操作成功');
}
$this->_error('操作失败');
}
/**
* 设置支付密码
*/
public function setPayPassword()
{
if ($this->request->isPost()) {
$data = $this->request->post();
$result = $this->validate($data, 'app\api\validate\User.setPayPassword');
if (true !== $result) {
$this->_error($result);
}
$data['user_id'] = $this->user_id;
$data['pay_password'] = md5(trim($data['pay_password']));
$result = UserLogic::setPassword($data);
if ($result) {
$this->_success('设置支付密码成功');
} else {
$this->_error('设置支付密码失败');
}
} else {
$this->_error('请求类型错误');
}
}
/**
* 会员转账
*/
public function transfer()
{
$data = $this->request->post();
$data['user_id'] = $this->user_id;
$result = $this->validate($data, 'app\api\validate\User.transfer');
if (true !== $result) {
$this->_error($result);
}
$data['user_id'] = $this->user_id;
$result = UserLogic::transfer($data);
if (true === $result) {
$this->_success('转账成功');
}
$this->_error(UserLogic::getError() ?? '转账失败');
}
/**
* 判断会员是否有设置支付密码
*/
public function hasPayPassword()
{
$payPassword = Db::name('user')->where('id', $this->user_id)->value('pay_password');
if ($payPassword) {
$this->_success('已设置支付密码');
} else {
// 应前端要求,未设置密码show返回0
$this->_error('未设置支付密码', [], 0, 0);
}
}
/**
* 转账记录
*/
public function transferRecord()
{
$get = $this->request->get();
$get['page_no'] = $get['page_no'] ?? $this->page_no;
$get['page_size'] = $get['page_size'] ?? $this->page_size;
$get['user_id'] = $this->user_id;
$get['type'] = $get['type'] ?? 'all';
$result = UserLogic::transferRecord($get);
$this->_success('', $result);
}
/**
* 最近转账(取最近3条)
*/
public function transferRecent()
{
$list = Db::name('user_transfer')->alias('ut')
->distinct(true)
->field('u.sn, u.nickname, u.avatar, ut.create_time')
->leftJoin('user u', 'u.id=ut.transfer_to_id')
->where('ut.transfer_from_id', $this->user_id)
->order('ut.create_time', 'desc')
->group('ut.transfer_to_id')
->limit(3)
->select();
foreach ($list as &$item) {
$item['avatar'] = UrlServer::getFileUrl($item['avatar']);
}
return $this->_success('', $list);
}
/**
* 收款会员信息
*/
public function transferToInfo()
{
$transferTo = $this->request->get('transferTo', '', 'trim');
if (!$transferTo) {
return $this->_error('收款会员信息不能为空');
}
$user = Db::name('user')->field('sn,nickname,avatar')->where('sn', $transferTo)->find();
if (!$user) {
$user = Db::name('user')->field('sn,nickname,avatar')->where('mobile', $transferTo)->find();
if (!$user) {
return $this->_error('收款会员不存在');
}
}
$user['avatar'] = UrlServer::getFileUrl($user['avatar']);
return $this->_success('', $user);
}
/**
* 修改支付密码
*/
public function changePayPassword()
{
$post = $this->request->post();
if (empty($post['origin_pay_password'])) {
return $this->_error('原支付密码不能为空');
}
if (empty($post['new_pay_password'])) {
return $this->_error('新支付密码不能为空');
}
$user = Db::name('user')->where('id', $this->user_id)->find();
if (md5(trim($post['origin_pay_password'])) != $user['pay_password']) {
return $this->_error('原支付密码错误');
}
$result = Db::name('user')->where('id', $this->user_id)->update([
'pay_password' => md5(trim($post['new_pay_password'])),
'update_time' => time()
]);
if ($result) {
return $this->_success('修改成功');
} else {
return $this->_error('修改失败');
}
}
/**
* 找回密码获取验证码
*/
public function send()
{
$mobile = $this->request->post('mobile');
$key = 'ZHZFMM'; // 找回支付密码
$result = $this->validate(['mobile' => $mobile, 'key' => $key], 'app\api\validate\SmsSend');
if ($result !== true) {
$this->_error($result);
}
$send_result = SmsLogic::send($mobile, $key);
if ($send_result !== true) {
$this->_error($send_result);
}
$this->_success('发送成功');
}
/**
* 找回支付密码
*/
public function retrievePayPassword()
{
$post = $this->request->post();
if (empty($post['mobile'])) {
return $this->_error('手机号码不能为空');
}
if (empty($post['code'])) {
return $this->_error('验证码不能为空');
}
if (empty($post['new_pay_password'])) {
return $this->_error('新支付密码不能为空');
}
$sms_logic = new CommonSmsLogic('ZHZFMM', $post['mobile'], $post['code']);
$check = $sms_logic->checkCode();
//检查验证码是否正确
if ($check !== true) {
return $this->_error('验证码错误');
}
//标记验证码已验证
$sms_logic->cancelCode();
// 设置新的支付密码
$result = Db::name('user')->where('id', $this->user_id)->update([
'update_time' => time(),
'pay_password' => md5(trim($post['new_pay_password']))
]);
if ($result) {
return $this->_success('设置成功');
} else {
return $this->_error('设置失败');
}
}
}
@@ -0,0 +1,157 @@
<?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\controller;
use app\api\logic\UserAddressLogic;
class UserAddress extends ApiBase
{
public $like_not_need_login = ['handleregion'];
//获取地址列表
public function lists()
{
$user_id = $this->user_id;
$result = UserAddressLogic::infoUserAddress($user_id);
$this->_success('获取成功', $result);
}
//获取一条地址详情
public function detail()
{
$get = $this->request->get();
$result = $this->validate($get, 'app\api\validate\UserAddress.one');
if ($result === true) {
$user_id = $this->user_id;
$result = UserAddressLogic::getOneAddress($user_id, $get);
if ($result) {
$this->_success('获取成功', $result);
}
$result = '获取失败';
}
$this->_error($result);
}
//获取默认地址
public function getDefault()
{
$user_id = $this->user_id;
$result = UserAddressLogic::getDefaultAddress($user_id);
if ($result) {
$this->_success('获取成功', $result);
}
$this->_error('获取失败');
}
//设置默认地址
public function setDefault()
{
$post = $this->request->post();
$result = $this->validate($post, 'app\api\validate\UserAddress.set');
if ($result === true) {
$user_id = $this->user_id;
$result = UserAddressLogic::setDefaultAddress($user_id, $post);
if ($result) {
$this->_success('设置成功', $result);
}
$result = '设置失败';
}
$this->_error($result);
}
//添加收货地址
public function add()
{
$post = $this->request->post();
$result = $this->validate($post, 'app\api\validate\UserAddress.add');
if ($result === true) {
$user_id = $this->user_id;
$result = UserAddressLogic::addUserAddress($user_id, $post);
if ($result) {
$this->_success('添加成功', $result);
}
$result = '添加失败';
}
$this->_error($result);
}
//更新收货地址
public function update()
{
$post = $this->request->post();
$result = $this->validate($post, 'app\api\validate\UserAddress.edit');
if ($result === true) {
$user_id = $this->user_id;
$result = UserAddressLogic::editUserAddress($user_id, $post);
if ($result) {
$this->_success('修改成功', $result);
}
$result = '修改失败';
}
$this->_error($result);
}
//删除收货地址
public function del()
{
$post = $this->request->post();
$result = $this->validate($post, 'app\api\validate\UserAddress.del');
if ($result === true) {
$user_id = $this->user_id;
$result = UserAddressLogic::delUserAddress($user_id, $post);
if ($result) {
$this->_success('删除成功', $result);
}
$result = '删除失败';
}
$this->_error($result);
}
//将省市区名称转换成省市区id
public function handleRegion()
{
$post = $this->request->post();
$result = $this->validate($post, 'app\api\validate\UserAddress.handleRegion');
if ($result === true) {
$province = $this->request->post('province');
$city = $this->request->post('city');
$district = $this->request->post('district');
$res = UserAddressLogic::handleRegion($province, $city, $district);
if ($res) {
$this->_success('获取成功', $res);
}
$result = '获取失败';
}
$this->_error($result);
}
}
@@ -0,0 +1,28 @@
<?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\controller;
use app\api\logic\UserLevelLogic;
class UserLevel extends ApiBase{
public function lists(){
$list = UserLevelLogic::lists($this->user_id);
$this->_success('获取成功',$list);
}
}
@@ -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\api\controller;
use app\api\logic\WeChatLogic;
class WeChat extends ApiBase
{
public $like_not_need_login = ['jsconfig', 'index'];
/**
* showdoc
* @catalog 接口列表/微信
* @title 微信JSSDK授权接口
* @description
* @method get
* @url we_chat/jsconfig
* @param url 必填 varchar 前端当前url
* @return_param appId string appid,公众号的唯一标识
* @return_param timestamp int 生成签名的时间戳
* @return_param nonceStr string 生成签名的随机串
* @return_param signature string 签名
* @return_param jsApiList array 需要使用的JS接口列表
* @remark allow_share: 传入1时,则返回允许分享到朋友圈的配置
* @number 0
* @return {"code":1,"msg":"获取成功","data":{"config":{"debug":true,"beta":false,"jsApiList":["onMenuShareTimeline","onMenuShareWeibo","openLocation","getLocation","chooseWXPay","updateTimelineShareData"],"appId":"wx9d4……","nonceStr":"Ge8wD……","timestamp":1592707100,"url":"http:\/\/dragon.yixiang……","signature":"8421cfbc……"}}}
*/
public function jsConfig()
{
$url = $this->request->get('url');
$result = WeChatLogic::jsConfig($url);
if ($result['code'] != 1) {
$this->_error( $result['msg'] ?? '', ['config' => $result['data']]);
}
$this->_success('', ['config' => $result['data']]);
}
public function index()
{
$params = $this->request->get();
WeChatLogic::index($params);
}
}
@@ -0,0 +1,68 @@
<?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\controller;
use app\api\logic\WithdrawLogic;
class Withdraw extends ApiBase
{
//提现申请
public function apply()
{
$post = $this->request->post();
$post['user_id'] = $this->user_id;
$check = $this->validate($post, 'app\api\validate\Withdraw.apply');
if (true !== $check) {
$this->_error($check);
}
return WithdrawLogic::apply($this->user_id, $post);
}
//提现配置
public function config()
{
$data = WithdrawLogic::config($this->user_id);
$this->_success('', $data);
}
//提现记录
public function records()
{
$get = $this->request->get();
$page = $this->request->get('page_no', $this->page_no);
$size = $this->request->get('page_size', $this->page_size);
$res = WithdrawLogic::records($this->user_id, $get, $page, $size);
$this->_success('', $res);
}
//提现详情
public function info()
{
$get = $this->request->get('');
$check = $this->validate($get, 'app\api\validate\Withdraw.info');
if (true !== $check) {
$this->_error($check);
}
$this->_success('', WithdrawLogic::info($get['id'], $this->user_id));
}
}
@@ -0,0 +1,100 @@
<?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\http\middleware;
use app\api\cache\TokenCache;
use app\api\validate\Token as TokenValidate;
class Login
{
/**
* 登录验证
* @param $request
* @param \Closure $next
* @return mixed|\think\response\Redirect
*/
public function handle($request, \Closure $next)
{
//允许跨域调用
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: Authorization, Sec-Fetch-Mode, DNT, X-Mx-ReqToken, Keep-Alive, User-Agent, If-Match, If-None-Match, If-Unmodified-Since, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Accept-Language, Origin, Accept-Encoding,Access-Token,token");
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, post');
header('Access-Control-Max-Age: 1728000');
header('Access-Control-Allow-Credentials:true');
if (strtoupper($request->method()) == "OPTIONS") {
return response();
}
$token = $request->header('token');
//无需登录
if ($this->isNotNeedLogin($request) && empty($token)) {
return $next($request);
}
//token验证
$token_cache = new TokenCache($token, ['token' => $token]);
//token缓存,直接通过
if (!$token_cache->isEmpty()) {
$request->user_info = $token_cache->get(600);
return $next($request);
}
//token验证,并生成缓存
$token_validate = new TokenValidate();
$result = $token_validate->check(['token' => $token]);
if ($result === true) {
$request->user_info = $token_cache->set(600);
return $next($request);
}
//无需要登录,带token的情况
if ($this->isNotNeedLogin($request) && $token) {
return $next($request);
}
//登录失败
action('dispatch/dispatch_error', ['msg' => $token_validate->getError(), 'code' => -1]);
}
/**
* 是否免登录验证
* @param $request
* @return bool
*/
private function isNotNeedLogin($request)
{
$data = app()->controller($request->controller())->like_not_need_login;
if (empty($data)) {
return false;
}
$action = strtolower($request->action());
$data = array_map('strtolower', $data);
if (!in_array($action, $data)) {
return false;
}
return true;
}
}
@@ -0,0 +1,61 @@
<?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\api\model\Goods;
use think\Db;
class ActivityAreaLogic
{
public static function activityGoodsList($id, $page, $size)
{
$where[] = ['AG.del', '=', 0];
$where[] = ['G.del', '=', 0];
$where[] = ['G.status', '=', 1];
$where[] = ['activity_id', '=', $id];
$goods = new Goods();
$count = $goods->alias('G')
->join('activity_goods AG', 'G.id = AG.goods_id')
->where($where)
->count();
$list = $goods->alias('G')
->join('activity_goods AG', 'G.id = AG.goods_id')
->where($where)
->page($page, $size)
->field('G.id,G.name,G.image,G.min_price as price,sales_sum+virtual_sales_sum as sales_sum,G.market_price,AG.activity_id')
->select();
$more = is_more($count, $page, $size); //是否有下一页
$data = [
'list' => $list,
'page_no' => $page,
'page_size' => $size,
'count' => $count,
'more' => $more
];
return $data;
}
}
+69
View File
@@ -0,0 +1,69 @@
<?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\model\Ad;
use app\common\server\UrlServer;
use think\Db;
class AdLogic
{
public static function lists($pid, $client)
{
$ad_list = Db::name('ad a')
->join('ad_position ap', 'a.pid = ap.id')
->where(['pid' => $pid, 'ap.client' => $client, 'a.status' => 1, 'a.del' => 0, 'ap.status' => 1, 'ap.del' => 0])
->field('a.*')
->order(['sort' => 'desc', 'id' => 'desc'])
->select();
$list = [];
foreach ($ad_list as $key => $ad) {
$url = $ad['link'];
$is_tab = 0;
$params = [];
switch ($ad['link_type']) {
case 1:
$page = Ad::getLinkPage($ad['client'], $ad['link']);
$url = $page['path'];
$is_tab = $page['is_tab'] ?? 0;
break;
case 2:
$goods_path = Ad::getGoodsPath($ad['client']);
$url = $goods_path;
$params = [
'id' => $ad['link'],
];
break;
}
$list[] = [
'image' => UrlServer::getFileUrl($ad['image']),
'link' => $url,
'link_type' => $ad['link_type'],
'params' => $params,
'is_tab' => $is_tab,
'sort' => $ad['sort'],
];
}
return $list;
}
}
@@ -0,0 +1,427 @@
<?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\{LogicBase, AfterSaleLogLogic, OrderGoodsLogic};
use app\common\model\{AfterSale, AfterSaleLog, Goods, NoticeSetting, Order, OrderGoods};
use app\common\server\AreaServer;
use app\common\server\ConfigServer;
use app\common\server\UrlServer;
use think\Db;
use think\Exception;
use think\facade\Hook;
/**
* 售后
* Class AfterSaleLogic
* @package app\api\logic
*/
class AfterSaleLogic extends LogicBase
{
public static function lists($user_id, $type, $page, $size)
{
$where = [];
$where[] = ['o.user_id', '=', $user_id];
$data = $result = [];
switch ($type) {
case 'normal':
$where[] = ['g.refund_status', '=', OrderGoods::REFUND_STATUS_NO];
$where[] = ['o.order_status', 'in', [Order::STATUS_WAIT_DELIVERY, Order::STATUS_WAIT_RECEIVE, Order::STATUS_FINISH]];
$order = new Order();
$count = $order->alias('o')
->field('o.id,o.confirm_take_time,o.order_status,o.create_time')
->join('order_goods g', 'g.order_id = o.id')
->with(['orderGoods' => function ($query) {
$query->where('refund_status', OrderGoods::REFUND_STATUS_NO);
}])
->where($where)
->group('o.id')
->count();
$lists = $order
->alias('o')
->field('o.id,o.confirm_take_time,o.order_status,o.create_time')
->join('order_goods g', 'g.order_id = o.id')
->with(['orderGoods' => function ($query) {
$query->where('refund_status', OrderGoods::REFUND_STATUS_NO);
}])
->where($where)
->group('o.id')
->order('o.id desc')
->page($page, $size)
->select();
foreach ($lists as $item) {
$result = [
'order_id' => $item['id'],
];
$order_goods = [];
foreach ($item['order_goods'] as $k1 => $good) {
$goods = [
'goods_id' => $good['goods_id'],
'item_id' => $good['item_id'],
'goods_name' => '',
'goods_num' => $good['goods_num'],
'goods_price' => $good['goods_price'],
'image' => '',
];
$goods_data = json_decode($good['goods_info'], true);
$goods['spec_value_str'] = $goods_data['spec_value_str'];
$goods['goods_name'] = $goods_data['goods_name'];
$goods['image'] = empty($goods_data['spec_image']) ? UrlServer::getFileUrl($goods_data['image']) : UrlServer::getFileUrl($goods_data['spec_image']);
$order_goods[] = $goods;
}
$result['order_goods'] = $order_goods;
$result['after_sale']['desc'] = '';
$result['after_sale']['able_apply'] = 1;
if (self::checkAfterSaleDate($item) === false) {
$result['after_sale']['desc'] = '该商品已超过售后期';
$result['after_sale']['able_apply'] = 0;
}
$time = $item['confirm_take_time'] ?? $item->getData('create_time');
$result['time'] = date('Y-m-d H:i', $time);
$data[] = $result;
}
$list = ['list' => $data, 'page' => $page, 'size' => $size, 'count' => $count, 'more' => is_more($count, $page, $size)];
return $list;
break;
case 'apply':
$where[] = ['g.refund_status', 'in', [OrderGoods::REFUND_STATUS_APPLY, OrderGoods::REFUND_STATUS_WAIT]];
$where[] = ['o.order_status', 'in', [Order::STATUS_WAIT_DELIVERY, Order::STATUS_WAIT_RECEIVE, Order::STATUS_FINISH]];
$where[] = ['a.del', '=', 0];
break;
case 'finish':
$where[] = ['g.refund_status', '=', OrderGoods::REFUND_STATUS_SUCCESS];
$where[] = ['a.del', '=', 0];
$where[] = ['o.order_status', 'in', [Order::STATUS_WAIT_DELIVERY, Order::STATUS_WAIT_RECEIVE, Order::STATUS_FINISH, Order::STATUS_CLOSE]];
break;
}
$field = 'g.order_id,g.goods_id,g.item_id,g.goods_num,g.goods_price,g.goods_info,a.status,a.refund_type,a.id as after_sale_id,a.create_time,a.refund_price';
$count = Db::name('order_goods g')
->field($field)
->join('order o', 'g.order_id = o.id')
->join('after_sale a', 'a.order_goods_id = g.id', 'left')
->where($where)
->group('g.id')
->count();
$lists = Db::name('order_goods g')
->field($field)
->join('order o', 'g.order_id = o.id')
->join('after_sale a', 'a.order_goods_id = g.id', 'left')
->where($where)
->group('g.id')
->order('a.id desc')
->page($page, $size)
->select();
foreach ($lists as $k => $item) {
$goods_data = json_decode($item['goods_info'], true);
$goods_name = $goods_data['goods_name'];
$image = empty($goods_data['spec_image']) ? UrlServer::getFileUrl($goods_data['image']) : UrlServer::getFileUrl($goods_data['spec_image']);
$result = [
'order_id' => $item['order_id'],
'order_goods' => [[
'goods_id' => $item['goods_id'],
'item_id' => $item['item_id'],
'goods_name' => $goods_name,
'goods_num' => $item['goods_num'],
'goods_price' => $item['goods_price'],
'image' => $image,
'spec_value_str' => $goods_data['spec_value_str'],
]],
'after_sale' => [
'after_sale_id' => $item['after_sale_id'],
'status' => $item['status'],
'refund_type' => $item['refund_type'],
'status_text' => AfterSale::getStatusDesc($item['status']),
'type_text' => AfterSale::getRefundTypeDesc($item['refund_type']),
'desc' => AfterSale::getStatusDesc($item['status']),
'able_apply' => 1,
'refund_price' => $item['refund_price'],
],
'time' => date('Y-m-d H:i', $item['create_time']),
];
$data[] = $result;
}
$list = [
'list' => $data,
'page' => $page,
'size' => $size,
'count' => $count,
'more' => is_more($count, $page, $size)
];
return $list;
}
//验证(收货后多少天内才可申请售后/或已发货,未收货). 售后日志
public static function add($post, $user_id)
{
Db::startTrans();
try {
//1,增加售后记录
$order_goods = Db::name('order_goods g')
->field('g.id,g.goods_num,g.total_pay_price,g.order_id,g.refund_status,g.goods_id')
->join('order o', 'o.id = g.order_id')
->where(['order_id' => $post['order_id'], 'g.item_id' => $post['item_id']])
->find();
$data = [
'sn' => createSn('after_sale', 'sn', '', 4),
'user_id' => $user_id,
'order_id' => $order_goods['order_id'],
'order_goods_id' => $order_goods['id'],
'item_id' => $post['item_id'],
'goods_id' => $order_goods['goods_id'],
'goods_num' => $order_goods['goods_num'],
'refund_reason' => trim($post['reason']),
'refund_remark' => isset($post['remark']) ? trim($post['remark']) : '',
'refund_image' => isset($post['img']) ? $post['img'] : '',
'refund_type' => $post['refund_type'],
'refund_price' => $order_goods['total_pay_price'] + OrderGoodsLogic::getRefundExpressMoney($order_goods['id']),
'create_time' => time(),
];
$after_sale_id = Db::name('after_sale')->insertGetId($data);
//2,更改订单商品,退款状态为申请退款
Db::name('order_goods')
->where('id', $order_goods['id'])
->update(['refund_status' => OrderGoods::REFUND_STATUS_APPLY]);
//记录日志
AfterSaleLogLogic::record(
AfterSaleLog::TYPE_USER,
AfterSaleLog::USER_APPLY_REFUND,
$post['order_id'],
$after_sale_id,
$user_id,
AfterSaleLog::USER_APPLY_REFUND
);
$order_contact_mobile = ConfigServer::get('order_message', 'order_contact_mobile' );
//平台短信通知
if($order_contact_mobile){
Hook::listen('sms_send',[
'key' => NoticeSetting::AFTER_SALE_NOTICE_PLATFORM,
'mobile' => $order_contact_mobile,
'params' => [
'order_sn' => $data['sn'],
],
]);
}
Db::commit();
return self::dataSuccess('提交成功', ['after_sale_id' => $after_sale_id]);
} catch (Exception $e) {
Db::rollback();
return self::dataError($e->getMessage());
}
}
//详情
public static function info($item_id, $order_id)
{
$goods = Db::name('order_goods')
->where(['order_id' => $order_id, 'item_id' => $item_id])
->hidden('spec_value_ids,create_time')
->find();
$info = json_decode($goods['goods_info'], true);
$goods['goods_name'] = $info['goods_name'];
$goods['spec_value'] = $info['spec_value_str'];
$goods['image'] = isset($info['image']) ? UrlServer::getFileUrl($info['image']) : '';
$goods['refund_express_money'] = OrderGoodsLogic::getRefundExpressMoney($goods['id']);
$data = [
'goods' => $goods,
'reason' => AfterSale::getReasonLists(),
];
return $data;
}
//上传退货快递信息
public static function express($user_id, $post)
{
$id = $post['id'];
$after_sale = AfterSale::get($id);
$after_sale->express_name = $post['express_name'];
$after_sale->invoice_no = $post['invoice_no'];
$after_sale->express_remark = isset($post['express_remark']) ? trim($post['express_remark']) : null;
$after_sale->express_image = isset($post['express_image']) ? $post['express_image'] : null;
$after_sale->status = AfterSale::STATUS_WAIT_RECEIVE_GOODS;//售后状态
$after_sale->save();
//记录日志
AfterSaleLogLogic::record(
AfterSaleLog::TYPE_USER,
AfterSaleLog::USER_SEND_EXPRESS,
$after_sale['order_id'],
$id,
$user_id,
AfterSaleLog::USER_SEND_EXPRESS
);
return self::dataSuccess('提交成功', ['after_sale_id' => $id]);
}
//撤销申请
public static function cancel($user_id, $post)
{
$id = $post['id'];
$after_sale = AfterSale::get($id);
$after_sale->del = 1;
$after_sale->update_time = time();
$after_sale->save();
//2,更改订单商品,退款状态为申请退款
$order_goods = OrderGoods::get(['id' => $after_sale['order_goods_id']]);
$order_goods->refund_status = OrderGoods::REFUND_STATUS_NO;
$order_goods->save();
//记录日志
AfterSaleLogLogic::record(
AfterSaleLog::TYPE_USER,
AfterSaleLog::USER_CANCEL_REFUND,
$after_sale['order_id'],
$id,
$user_id,
AfterSaleLog::USER_CANCEL_REFUND
);
}
//售后详情
public static function detail($get)
{
$after_sale = new \app\api\model\AfterSale();
$detail = $after_sale
->field('id,sn,order_goods_id,refund_reason,refund_image,refund_type,refund_price,create_time,status,refund_remark')
->with(['order_goods'])
->where(['id' => $get['id'], 'del' => 0])
->find();
if (!$detail) {
return [];
}
$detail['refund_image'] = UrlServer::getFileUrl($detail['refund_image']);
$detail['status_text'] = AfterSale::getStatusDesc($detail['status']);
$detail['create_time'] = date('Y-m-d H:i:s', $detail['create_time']);
$goods = json_decode($detail['order_goods']['goods_info'], true);
$image = $goods['image'];
$spec_image = $goods['spec_image'];
$detail['order_goods']['image'] = empty($spec_image) ? $image : $spec_image;
$detail['order_goods']['goods_name'] = $goods['goods_name'];
$detail['order_goods']['spec_value'] = $goods['spec_value_str'];
$detail['refund_type_text'] = AfterSale::getRefundTypeDesc($detail['refund_type']);
$shop_province = ConfigServer::get('shop', 'province_id', '');
$shop_city = ConfigServer::get('shop', 'city_id', '');
$shop_district = ConfigServer::get('shop', 'district_id', '');
$shop_address = ConfigServer::get('shop', 'address', '');
$address = AreaServer::getAddress([$shop_province, $shop_city, $shop_district], $shop_address);
$shop = [
'contact' => ConfigServer::get('shop', 'contact', ''),
'mobile' => ConfigServer::get('shop', 'mobile', ''),
'address' => $address
];
$detail['shop'] = $shop;
return $detail;
}
//重新申请;商家拒绝才可以重新申请
public static function again($user_id, $post)
{
Db::startTrans();
try {
$id = $post['id'];
$after_sale = AfterSale::get($id);
$after_sale->refund_type = $post['refund_type'];
$after_sale->refund_reason = trim($post['reason']);
$after_sale->refund_remark = isset($post['remark']) ? trim($post['remark']) : '';
$after_sale->refund_image = isset($post['img']) ? $post['img'] : '';
$after_sale->status = AfterSale::STATUS_APPLY_REFUND;
$after_sale->save();
//2,更改订单商品,退款状态为申请退款
$order_goods = OrderGoods::get(['id' => $after_sale['order_goods_id']]);
$order_goods->refund_status = OrderGoods::REFUND_STATUS_APPLY;
$order_goods->save();
//记录日志
AfterSaleLogLogic::record(
AfterSaleLog::TYPE_USER,
AfterSaleLog::USER_AGAIN_REFUND,
$after_sale['order_id'],
$id,
$user_id,
AfterSaleLog::USER_AGAIN_REFUND
);
Db::commit();
return self::dataSuccess('提交成功', ['after_sale_id' => $id]);
} catch (Exception $e) {
Db::rollback();
return self::dataError($e->getMessage());
}
}
//检查是否在售后时间内
public static function checkAfterSaleDate($order)
{
$now = time();
$refund_days = ConfigServer::get('after_sale', 'refund_days', 0, 0);
if ($refund_days == 0) {
return true;
}
if ($order['order_status'] == \app\common\model\Order::STATUS_FINISH) {
$check_time = strtotime('+' . $refund_days . 'day', $order['confirm_take_time']);
if ($now > $check_time) {
return false;
}
}
return true;
}
}
@@ -0,0 +1,110 @@
<?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\server\UrlServer;
use think\Db;
class ArticleLogic
{
public static function lists($id, $page, $size)
{
$where[] = [
['a.del', '=', 0],
['a.is_show', '=', 1],
['c.del', '=', 0],
['c.is_show', '=', 1],
];
if (!empty($id)) {
$where[] = ['cid', '=', $id];
}
$res = DB::name('article')->alias('a')
->join('article_category c', 'c.id = a.cid')
->where($where)
->field('a.id,a.title,a.synopsis,a.image,a.visit,a.create_time')
->order(['a.id' => 'desc']);
$count = $res->count();
$article = $res->page($page, $size)->select();
foreach ($article as &$item) {
$item['create_time'] = date('Y-m-d ', $item['create_time']);
$item['image'] = UrlServer::getFileUrl($item['image']);
}
$more = is_more($count, $page, $size);
return [
'list' => $article,
'count' => $count,
'page_no' => $page,
'page_size' => $size,
'more' => $more
];
}
public static function CategoryLists()
{
$res = DB::name('article_category')
->where(['del' => 0])
->where('is_show', 1)
->field('id,name')
->select();
return $res;
}
public static function getArticleDetail($id,$client)
{
DB::name('article')
->where(['id' => $id, 'del' => 0])
->setInc('visit');
$res = DB::name('article')
->where(['del' => 0, 'id' => $id])
->field('id,title,image,visit,create_time,content')
->order(['create_time' => 'desc'])
->find();
$preg = '/<img.*?src="((?!(https|http)).*?)".*?\/?>/i';
$local_url = UrlServer::getFileUrl();
$res['content'] = preg_replace($preg, '<img src="' . $local_url . '${1}" />', $res['content']);
$res['create_time'] = date('Y-m-d ', $res['create_time']);
$res['image'] = UrlServer::getFileUrl($res['image']);
$recommend_list = [];
if(2 == $client){
$recommend_list = Db::name('article')
->where([['del','=','0'], ['id','<>',$id], ['is_show', '=', 1]])
->field('id,title,image,visit')
->order('visit desc')
->limit(5)
->select();
foreach ($recommend_list as $key => $recommend){
$recommend_list[$key]['image'] = UrlServer::getFileUrl($recommend['image']);
}
}
$res['recommend_list'] = $recommend_list;
return $res;
}
}
@@ -0,0 +1,531 @@
<?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\LogicBase;
use app\common\model\BargainLaunch;
use app\common\server\ConfigServer;
use app\common\server\UrlServer;
use think\Db;
use think\Exception;
class BargainLogic extends LogicBase {
/**
* Notes:获取砍价成功人数
* @return float|string
* @author: 2021/2/23 16:13
*/
public static function barginNumber()
{
return Db::name('bargain_launch')
->where(['status'=>1])
->count();
}
/**
* Notes:砍价列表
* @param $page int 分页
* @param $size int 分页条数
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @author: 2021/2/23 16:09
*/
public static function lists($page,$size){
$now = time();
$where[] = ['B.del','=',0];
$where[] = ['B.status','=',1];
$where[] = ['activity_start_time','<',$now];
$where[] = ['activity_end_time','>',$now];
$bargain_count = Db::name('bargain')->alias('B')
->join('Goods G','B.goods_id = G.id')
->where($where)
->count();
$bargain_list = Db::name('bargain')->alias('B')
->join('Goods G','B.goods_id = G.id')
->where($where)
->page($page,$size)
->order('id desc')
->field('B.id,B.bargain_min_price as activity_price,G.id as goods_id,G.name,G.image,G.min_price as price')
->withAttr('image',function ($value,$data){
return UrlServer::getFileUrl($value);
})
->select();
$more = is_more($bargain_count,$page,$size); //是否有下一页
$data = [
'list' => $bargain_list,
'page_no' => $page,
'page_size' => $size,
'count' => $bargain_count,
'more' => $more
];
return $data;
}
/**
* Notes:砍价活动详情
* @param $bargain_id int 砍价活动id
* @return array|\PDOStatement|string|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @author: 2021/2/23 18:02
*/
public static function detail($bargain_id){
$detail = Db::name('bargain')->alias('B')
->join('goods G','B.goods_id = G.id')
->where(['B.id'=>$bargain_id])
->field('B.id,B.bargain_min_price as activity_price,G.id as goods_id,G.name,G.image,G.min_price as price')
->withAttr('image',function ($value,$data){
return UrlServer::getFileUrl($value);
})
->find();
$detail['goods_item'] = Db::name('bargain_item')->alias('BI')
->join('goods_item GI','BI.item_id = GI.id')
->where(['BI.goods_id'=>$detail['goods_id']])
->field('BI.floor_price as activity_price,GI.id,GI.image,GI.price,GI.spec_value_ids,GI.spec_value_str')
->select();
$spec_list = Db::name('goods_spec')
->where(['goods_id'=>$detail['goods_id']])
->column('*','id');
$spec_value_list = Db::name('goods_spec_value')
->where(['goods_id'=>$detail['goods_id']])
->select();
foreach ($spec_value_list as $spec_value){
if(isset($spec_list[$spec_value['spec_id']])){
$spec_list[$spec_value['spec_id']]['spec_value'][] = $spec_value;
}
}
foreach ($detail['goods_item'] as $key => $goods_item){
if(empty($goods_item['image'])){
$goods_item['image'] = $detail['image'];
}
$detail['goods_item'][$key]['image'] = UrlServer::getFileUrl($goods_item['image']);
}
$detail['goods_spec'] = array_values($spec_list);
//前端渲染状态
$detail['status'] = -1;
//提示字段
$detail['bargain_tips'] = '您正在发起砍价';
$detail['simple_tips'] = '邀请好友帮忙砍价,砍至'.$detail['activity_price'].'即可发货';
return $detail;
}
/**
* Notes:发起砍价
* @param $post_data array 活动id、规格id
* @param $user_id int 用户id
* @return int|string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @author: 2021/2/24 11:29
*/
public static function sponsor($post_data,$user_id){
Db::startTrans();
try {
//商品规格信息
$goods_item = Db::name('goods_item')->alias('GI')
->join('goods G','G.id = GI.goods_id')
->where(['GI.id'=>$post_data['item_id']])
->field('G.name,G.image as goods_iamge,GI.id as item_id,GI.image,GI.spec_value_str,GI.price')
->find();
$bargain = Db::name('bargain')->alias('B')
->join('bargain_item BI','B.id = BI.bargain_id')
->where(['B.id'=>$post_data['bargain_id'],'BI.item_id'=>$post_data['item_id'],'B.del'=>0])
->field('B.*,BI.floor_price,BI.item_id,BI.first_knife_price')
->find();
$now = time();
//砍到价格
$current_price = $goods_item['price'] - $bargain['first_knife_price'];
$status = BargainLaunch::conductStatus;
$payment_limit_time = 0;
$bargain_end_time = 0;
//首刀砍掉后小于零,或低于底价
if($current_price <= $bargain['floor_price'] || $current_price <= 0){
//标记砍价成功
$status = BargainLaunch::successStatus;
//砍价的价格低于低价、重新计算每刀价格
if($current_price < $bargain['floor_price']){
$current_price = $bargain['floor_price'];
$bargain['first_knife_price'] = $goods_item['price'] - $current_price;
}
//砍价成功后的付款时间(秒)
$payment_limit_time = ConfigServer::get('bargain', 'payment_limit_time', 0) * 60;
if($payment_limit_time > 0){
$payment_limit_time = $now + $payment_limit_time;
}
$bargain_end_time = $now;
}
$diff_price = round($current_price - $bargain['floor_price'],2);
$bargain_launch = [
'bargain_id' => $bargain['id'],
'goods_id' => $bargain['goods_id'],
'user_id' => $user_id,
'order_id' => '',
'goods_snap' => json_encode($goods_item), //规格信息
'bargain_snap' => json_encode($bargain), //砍价信息
'help_number' => 0, //助力次数
'bargain_price' => $bargain['floor_price'], //商品活动低价
'current_price' => $current_price, //当前砍到的价格
'launch_start_time' => $now, //砍价发起时间
'launch_end_time' => $now + $bargain['time_limit'] * 3600,//砍价结束时间
'bargain_end_time' => $bargain_end_time, //最后的砍价时间
'payment_limit_time' => $payment_limit_time, //最后的付款时间
'status' => $status, //当前砍价状态
];
//写入发起砍价表
$bargain_launch_id = Db::name('bargain_launch')
->insertGetId($bargain_launch);
$bargain_knife = [
'bargain_id' => $bargain['id'],
'launch_id' => $bargain_launch_id,
'user_id' => $user_id,
'surplus_price' => $current_price,
'help_price' => $bargain['first_knife_price'],
'help_time' => $now
];
//写入砍价记录表
Db::name('bargain_knife')
->insert($bargain_knife);
//更新助力次数
Db::name('bargain_launch')->where('id',$bargain_launch_id)->update(['help_number'=>['inc',1]]);
//砍价进度条
$progress = round($bargain['floor_price'] / $current_price,2);
Db::commit();
return data_success('发起砍价成功',['id'=>$bargain_launch_id,'knife_price'=>$bargain['first_knife_price'],'diff_price'=>$diff_price,'progress'=>$progress]);
}catch (Exception $e) {
Db::rollback();
return data_error('发起砍价失败:'.$e->getMessage(),'');
}
}
/**
* Notes:助力
* @param $id int 砍价订单id
* @param $user_id int 用户id
* @return array|bool
* @author: 2021/2/25 19:08
*/
public static function knife($id,$user_id){
Db::startTrans();
try {
$now = time();
$bargain_launch = new BargainLaunch();
$bargain_launch = $bargain_launch
->where(['id' => $id])
->find();
$bargain_snap = $bargain_launch['bargain_snap'];
//每刀随机金额
if (1 == $bargain_snap['knife_type']) {
$knife__price_array = explode(',', $bargain_launch['bargain_snap']['knife_price']);
$knife_price = round(random_float(array_pop($knife__price_array), array_pop($knife__price_array)), 2);
} else { //每刀固定金额
$knife_price = $bargain_launch['bargain_snap']['knife_price'];
}
//商品的低价
$low_price = $bargain_launch['bargain_price'];
//砍价后的金额
$knife_after_price = $bargain_launch['current_price'] - $knife_price;
$status = BargainLaunch::conductStatus; //砍价状态
$payment_limit_time = 0; //砍价成功后的付款时间
$bargain_end_time = 0; //最后的砍刀时间
//如果砍价后低于低价,按当前的价格-低价来得到每刀金额,并标记砍价成功
if ($knife_after_price <= $low_price) {
//砍价成功后的付款时间(秒)
$payment_limit_time = ConfigServer::get('bargain', 'payment_limit_time', 0) * 60;
$status = BargainLaunch::successStatus;
if($payment_limit_time > 0){
$payment_limit_time = $now + $payment_limit_time;
}
$bargain_end_time = $now;
$knife_price = round($bargain_launch['current_price'] - $low_price,2); //砍价的金额 = 当前砍到的价格 - 低价
$knife_after_price = $low_price; //砍价后更新为低价
}
//写入砍价助力表
$knife_data = [
'bargain_id' => $bargain_snap['id'], //活动id
'launch_id' => $bargain_launch['id'], //订单id
'user_id' => $user_id, //用户id
'surplus_price' => $knife_after_price, //助力后的价格
'help_price' => $knife_price, //助力的金额
'help_time' => $now,
];
Db::name('bargain_knife')->insert($knife_data);
//更新砍价进度
$bargain_launch->help_number = ['inc', 1]; //助力次数+1
$bargain_launch->current_price = $knife_after_price; //助力后的价格
$bargain_launch->status = $status; //砍价状态
//砍价成功 限制多少时间内付款
if($payment_limit_time > 0 ){
$bargain_launch->payment_limit_time = $payment_limit_time;
}
if($bargain_end_time > 0){
$bargain_launch->bargain_end_time = $bargain_end_time;
}
$bargain_launch->save();
//进度条、剩余差价
$progress = round($bargain_snap['floor_price'] / $knife_after_price,2);
$diff_price = round($knife_after_price - $bargain_snap['floor_price'],2);
Db::commit();
return data_success('助力成功',['status'=>$status,'knife_price'=>$knife_price,'diff_price'=>$diff_price,'progress'=>$progress]);
}catch (Exception $e) {
Db::rollback();
return data_error('助力失败:'.$e->getMessage(),'');
}
}
/**
* Notes:砍价订单
* @param $type int 类型
* @param $user_id int 用户id
* @param $page int 分页
* @param $size int 分页条数
* @author: 2021/2/24 16:08
*/
public static function orderList($type,$user_id,$page,$size){
$where[] = ['user_id','=',$user_id];
if('-1' != $type){
$where[] = ['status','=',$type];
}
$bargain_launch = new BargainLaunch();
$order_count = $bargain_launch
->where($where)
->count();
$order_list = $bargain_launch
->where($where)
->page($page,$size)
->order('id desc')
->append(['item_id','btn_tips','bargain_tips','image','name','price','spec_value_str','status_text','create_time'])
->visible(['id','bargain_id','goods_id','item_id','image','name','price','spec_value_str','order_id','current_price','buy_btn','bargain_btn','pay_btn','status_text','create_time'])
->select();
$more = is_more($order_count,$page,$size); //是否有下一页
$data = [
'list' => $order_list,
'page_no' => $page,
'page_size' => $size,
'count' => $order_count,
'more' => $more
];
return $data;
}
/**
* Notes:砍价详情页
* @param $id int 订单id
* @param $user_id int 用户id
* @author: 2021/2/24 18:07
*/
public static function bargainDetail($id,$user_id){
$bargain_launch = new BargainLaunch();
$bargain_launch = $bargain_launch
->where(['id'=>$id])
->with('bargain_knife.user')
->append(['item_id','image','name','price','spec_value_str','over_time','diff_price','activity_price','progress','knife_list','knife_price','share_titles','share_intros'])
->find();
//砍价快照
$bargain_snap = $bargain_launch['bargain_snap'];
$bargain_launch = $bargain_launch->visible(['id','bargain_id','user_id','goods_id','item_id','order_id','name','image','price','spec_value_str','current_price','floor_price','diff_price','progress','knife_list','status','knife_price','share_titles','share_intros','payment_limit_time'])
->hidden(['bargain_knife'])->toArray();
$user_info = current($bargain_launch['knife_list']);
$now = time();
//好友点击分享行为按钮
$sponsor_btn = 0; //我也要砍价按钮
$knife_btn = 0; //帮忙砍一刀按钮
//查看自己砍价行为按钮
$direct_buy_btn = 0; //直接购买按钮
$buy_btn = 0; //立即购买按钮
$invite_btn = 0; //邀请好友按钮
$order_btn = 0; //查看订单按钮
//提示语,通用
$bargain_tips = ''; //砍价提示,最上方提示
$simple_tips = ''; //提示,砍价提示下方提示
$status_tips = ''; //状态提示
//分享用户的头像
$bargain_launch['share_avatar'] = '';
//显示按钮:查看自己的砍价、好友点击分享进来
if($bargain_launch['user_id'] != $user_id){ //好友点击分享进来
$bargain_launch['status'] = 5;//标记为好友邀请进来的
//我也要砍价按钮
$sponsor_btn = 1;
$bargain_tips = '来自'.$user_info['nickname'].'的分享';
$bargain_launch['share_avatar'] = $user_info['avatar'];
$simple_tips = '谢谢您的助力,动动手指帮我砍一刀';
if($bargain_launch['over_time'] <= $now || 1 == $bargain_launch['status'] || 2 == $bargain_launch['status']){
$status_tips = '砍价已结束,去看看其他商品吧~';
}else{
$bargain_knife = Db::name('bargain_knife')->where(['launch_id'=>$bargain_launch['id'],'user_id'=>$user_id])->find();
if(empty($bargain_knife)){
//帮忙砍一刀按钮
$knife_btn = 1;
}
}
}else{//自己的砍价
$simple_tips = '邀请好友帮砍价,砍至'.$bargain_snap['floor_price'].'即可发货';
//砍价进行中
if(0 == $bargain_launch['status'] && $bargain_launch['over_time'] > $now){
//邀请好友按钮
$invite_btn = 1;
$bargain_tips = '砍价中';
if(2 == $bargain_snap['payment_where']){
//显示直接购买按钮
$direct_buy_btn = 1;
}
$status_tips = '砍价中';
}
//砍价成功
if(1 == $bargain_launch['status'] || (2 == $bargain_snap['payment_where'] && $bargain_launch['over_time'] <= $now)){
$bargain_tips = '砍价成功';
$status_tips = '恭喜您,砍价成功';
//砍价成功,没有超过付款时间,且没有下单的,显示购买按钮
$buy_btn = 1;
if($bargain_launch['order_id'] || ($bargain_launch['payment_limit_time'] && $bargain_launch['payment_limit_time'] < $now)){
$buy_btn = 0;
if($bargain_launch['payment_limit_time'] && $bargain_launch['payment_limit_time'] < $now){
$status_tips = '已超过下单时间,无法下单';
}
}
//已下单
if($bargain_launch['order_id']){
$order_btn = 1;
}
}
//砍价失败
if(($bargain_launch['over_time'] <= $now && 1 != $bargain_launch['status'] && 2 != $bargain_snap['payment_where']) || 2 == $bargain_launch['status']){
$bargain_tips = '砍价失败';
$status_tips = '非常遗憾,砍价失败';
}
}
$bargain_launch['sponsor_btn'] = $sponsor_btn;
$bargain_launch['knife_btn'] = $knife_btn;
$bargain_launch['direct_buy_btn'] = $direct_buy_btn;
$bargain_launch['buy_btn'] = $buy_btn;
$bargain_launch['invite_btn'] = $invite_btn;
$bargain_launch['order_btn'] = $order_btn;
$bargain_launch['bargain_tips'] = $bargain_tips;
$bargain_launch['simple_tips'] = $simple_tips;
$bargain_launch['status_tips'] = $status_tips;
return $bargain_launch;
}
/**
* Notes:关闭砍价订单
* @param $id int 活动订单id
* @return bool
* @author: 2021/2/26 16:36
*/
public static function closeBargain($id){
$bargain_launch = new BargainLaunch();
$bargain_launch = $bargain_launch
->where(['id'=>$id])
->find();
//标记砍价结束
if($bargain_launch['launch_end_time'] < time() && 0 == $bargain_launch['status']){
//任意金额购买标记成功
if(2 == $bargain_launch['bargain_snap']['payment_where']){
$status = 1;
}else{//砍到低价
$status = 2;
if($bargain_launch['bargain_price'] > $bargain_launch['current_price']){
$status = 1;
}
}
$bargain_launch->status = $status;
$bargain_launch->save();
}
return true;
}
}
+198
View File
@@ -0,0 +1,198 @@
<?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\api\model\Cart;
use app\common\model\Footprint;
use app\common\server\UrlServer;
use think\Db;
use think\facade\Hook;
class CartLogic
{
//添加购物车
public static function add($item_id, $goods_num, $user_id)
{
$goods = Db::name('goods g')
->field('i.goods_id')
->join('goods_item i', 'i.goods_id = g.id')
->where('i.id', $item_id)
->find();
$time = time();
$where = [
'user_id' => $user_id,
'item_id' => $item_id,
];
$info = Cart::where($where)->find();
$cart_num = $goods_num + (isset($info) ? $info['goods_num'] : 0);
if (self::checkStock($item_id, $cart_num)) {
return '很抱歉,商品库存不足';
}
if ($info) {
//购物车内已有该商品
$update_data = [
'goods_num' => $goods_num + $info['goods_num'],
'update_time' => $time,
];
$res = Db::name('cart')
->where('id', $info['id'])
->update($update_data);
} else {
//新增购物车记录
$data = [
'user_id' => $user_id,
'goods_id' => $goods['goods_id'],
'goods_num' => $goods_num,
'item_id' => $item_id,
'create_time' => $time,
];
$res = Db::name('cart')->insert($data);
}
if (!$res) {
return '添加失败';
}
// 钩子-记录足迹(添加购物车)
Hook::listen('footprint', [
'type' => Footprint::add_cart,
'user_id' => $user_id,
'foreign_id' => $goods['goods_id'] //商品ID
]);
return true;
}
//删除购物车
public static function del($cart_id, $user_id)
{
return Db::name('cart')->where(['id' => $cart_id, 'user_id' => $user_id])->delete();
}
//变动购物车数量
public static function change($cart_id, $goods_num)
{
$cart = Db::name('cart')->where(['id' => $cart_id])->find();
if (self::checkStock($cart['item_id'], $goods_num)) {
return '很抱歉,库存不足';
}
if ($goods_num <= 0) {
$goods_num = 1;
}
$update = [
'update_time' => time(),
'goods_num' => $goods_num,
];
Db::name('cart')->where(['id' => $cart_id])->update($update);
return true;
}
//购物车选中状态
public static function selected($post, $user_id)
{
return Db::name('cart')
->where(['id' => $post['cart_id'], 'user_id' => $user_id])
->update(['selected' => $post['selected'], 'update_time' => time()]);
}
//检查库存
public static function checkStock($item_id, $goods_num)
{
$item_info = Db::name('goods_item')
->where('id', $item_id)->find();
if ($goods_num > $item_info['stock']) {
return true;
}
return false;
}
//列表
public static function lists($user_id)
{
$field = 'g.name,g.image,g.id as goods_id,g.status as g_status,g.del as g_del,
i.spec_value_str,i.price,i.image as item_image,c.goods_num,c.selected,c.id as cart_id,c.item_id,i.stock as item_stock';
$carts = Db::name('cart c')
->field($field)
->join('goods g', 'g.id = c.goods_id')
->join('goods_item i', 'i.id = c.item_id')
->where('c.user_id', $user_id)
->order('c.create_time desc')
->select();
$goods_num = 0;
$total = 0;
$lists = [];
foreach ($carts as $k1 => $cart) {
$cart_img = empty($cart['item_image']) ? $cart['image'] : $cart['item_image'];
$cart['img'] = UrlServer::getFileUrl($cart_img);
$cart['cart_status'] = 0;
if ($cart['g_status'] == 0) {
$cart['cart_status'] = 1;
}
if ($cart['g_del'] == 1) {
$cart['cart_status'] = 2;
}
$cart['sub_price'] = 0;
if ($cart['selected'] == Cart::IS_SELECTED && $cart['cart_status'] == 0) {
$goods_num += $cart['goods_num'];
$total += $cart['price'] * $cart['goods_num'];
$cart['sub_price'] = round($cart['price'] * $cart['goods_num'], 2);
}
$cart['selected'] = intval($cart['selected']);
unset($cart['image'], $cart['item_image']);
$lists[] = $cart;
}
return [
'lists' => $lists,
'total_amount' => round($total, 2),
'total_num' => $goods_num,
];
}
//获取购物车数量
public static function cartNum($user_id)
{
$num = Db::name('cart')->alias('c')
->join('goods g', 'g.id = c.goods_id')
->join('goods_item i', 'i.id = c.item_id')
->where('c.user_id', $user_id)
->sum('goods_num');
return ['num' => $num ?? 0];
}
}
@@ -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\api\logic;
use app\api\model\Goods;use think\Db;
class CollectLogic{
public static function getCollectGoods($user_id,$page,$size){
$goods = new Goods();
$count = $goods->alias('g')
->leftJoin('goods_collect c','g.id=c.goods_id')
->where(['g.del' => 0,'status'=>1,'user_id'=>$user_id])
->count();
$list = $goods->alias('g')
->leftJoin('goods_collect c','g.id=c.goods_id')
->where(['g.del' => 0,'user_id'=>$user_id])
->field('g.id,name,image,min_price as price')
->order('c.id desc')
->page($page, $size)
->select();
$more = is_more($count,$page,$size); //是否有下一页
return [
'list' => $list,
'count' => $count,
'page_no' => $page,
'page_size' => $size,
'more' =>$more
];
}
public static function handleCollectGoods($post,$user_id){
if($post['is_collect']==1){
$data =[
'user_id'=>$user_id,
'goods_id'=>$post['goods_id'],
'create_time'=>time(),
];
return Db::name('goods_collect')->insert($data);
}
return Db::name('goods_collect')->where(['goods_id'=>$post['goods_id']])->delete();
}
}
@@ -0,0 +1,576 @@
<?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\api\model\Coupon;
use app\common\model\Footprint;
use app\common\server\ConfigServer;
use think\Db;
use think\facade\Cache;
use think\facade\Hook;
use think\helper\Time;
class CouponLogic{
public static function getCouponList($user_id){
//更新过期优惠券
\app\common\logic\CouponLogic::couponClose($user_id);
$coupon = new Coupon();
$now = time();
$where[] = ['del','=',0];
$where[] = ['status','=',1];
$where[] = ['get_type','=',1];
$where[] = ['send_time_start','<=',$now];
$where[] = ['send_time_end','>=',$now];
$coupon_list = $coupon
->where($where)
->order('id desc')
->select();
$user_coupon = [];
if($user_id){
$user_coupon = Db::name('coupon_list')
->where(['user_id'=>$user_id,'del'=>0])
->select();
}
$user_coupon_ids = array_column($user_coupon,'coupon_id');
foreach ($coupon_list as &$item){
//是否已领取
$item['is_get'] = 0;
//优惠券类型
$item['coupon_type'] = '全场通用';
//优惠券使用时间
$item['use_time_tips'] = '';
$item['use_condition'] = '无金额门槛';
if(in_array($item['id'],$user_coupon_ids)){
$item['is_get'] = 1;
}
if($item['use_goods_type'] == 2){
$item['coupon_type'] = '指定商品可用';
}
if($item['use_goods_type'] == 3){
$item['coupon_type'] = '定商品不可用';
}
if($item['condition_type'] == 2){
$item['use_condition'] = '满'.floatval($item['condition_money']).'元减'.floatval($item['money']);
}
switch ($item['use_time_type']){
case 2:
$item['use_time'] = time()+86400*$item['use_time'];
$item['use_time_tips'] = '有效期至:'.date('Y.m.d H:i',$item['use_time']);
break;
case 3:
$item['use_time'] = time() + 86400 * $item['use_time']+86400;
$item['use_time_tips'] = '有效期至:'.date('Y.m.d H:i',$item['use_time']);
break;
default:
$item['use_time_tips'] = date('Y.m.d H:i',$item['use_time_start']).'-'.date('Y.m.d H:i',$item['use_time_end']);
}
}
$coupon_list->visible(['id','name','money','is_get','coupon_type','use_time_tips','use_condition']);
return $coupon_list;
}
public static function getGoodsCoupon($user_id,$id){
$now = time();
$where = [
['get_type','=',1],
['status','=',1],
['del','=',0],
['send_time_start','<=',$now],
['send_time_end','>=',$now],
];
$coupon = new Coupon();
$coupon_list = $coupon
->where($where)
->field('id,name,money,condition_type,condition_money,use_time,use_time_start,use_time_end,use_time_type,use_goods_type')
->with(['coupon_goods'])
->select()->toArray();
$user_coupon = [];
$lists = [];
if($user_id){
$user_coupon = Db::name('coupon_list')
->where(['user_id'=>$user_id,'del'=>0])
->select();
}
$user_coupon_ids = array_column($user_coupon,'coupon_id');
foreach ($coupon_list as $item){
if($item['use_goods_type'] == 2 || $item['use_goods_type'] == 3){
$goods_ids = array_column($item['coupon_goods'],'goods_id');
$exist_id = in_array($id,$goods_ids);
if($item['use_goods_type'] == 2 && !$exist_id){
continue;
}
if($item['use_goods_type'] == 3 && $exist_id){
continue;
}
}
$coupons['id'] = $item['id'];
$coupons['name'] = $item['name'];
$coupons['money'] = $item['money'];
//是否已领取
$coupons['is_get'] = 0;
//优惠券使用时间
$coupons['use_time_tips'] = '';
//使用使用类型
switch ($item['use_goods_type']){
case 1:
$coupons['coupon_type'] = '全场可用';
break;
case 2:
$coupons['coupon_type'] = '指定商品可用';
break;
case 3:
$coupons['coupon_type'] = '指定商品不可用';
break;
}
//优惠券有效期
switch ($item['use_time_type']){
case 2:
$coupons['use_time'] = time()+86400*$item['use_time'];
$coupons['use_time_tips'] = '有效期至:'.date('Y.m.d H:i',$coupons['use_time']);
break;
case 3:
$coupons['use_time'] = time() + 86400 * $item['use_time']+86400;
$coupons['use_time_tips'] = '有效期至:'.date('Y.m.d H:i',$coupons['use_time']);
break;
default:
$coupons['use_time_tips'] = date('Y.m.d H:i',$item['use_time_start']).'-'.date('Y.m.d H:i',$item['use_time_end']);
}
$coupons['use_condition'] = '无金额门槛';
if(in_array($item['id'],$user_coupon_ids)){
$coupons['is_get'] = 1;
}
if($item['condition_type'] == 2){
$coupons['use_condition'] = '满'.floatval($item['condition_money']).'元减'.floatval($item['money']);
}
$lists[] = $coupons;
}
return $lists;
}
//我的优惠券
public static function getMyCouponList($user_id,$type){
$coupon = new Coupon();
$where[] = ['user_id','=',$user_id];
$where[] = ['cl.del','=',0];
if($type != ''){
$where[] = ['cl.status','=',$type];
}
$coupon_list = $coupon->alias('c')
->join('coupon_list cl','c.id = cl.coupon_id')
->field('user_id,coupon_id,coupon_code,cl.create_time,
c.id,c.name,c.money,c.condition_type,c.condition_money,
c.send_total_type,c.send_total,c.use_time_type,c.use_time_start,c.use_time_end,c.use_time,
c.get_type,c.get_num_type,c.get_num,c.use_goods_type')
->with('couponGoods')
->order('cl.id desc')
->where($where)
->select();
$goods_list = Db::name('goods')->where(['del'=>0])->column('name','id');
foreach ($coupon_list as &$item){
$goods_name_array = [];
//优惠券使用时间
$item['use_time_tips'] = '';
$item['use_condition'] = '满'.floatval($item['condition_money']).'元减'.floatval($item['money']);
/*********************************优惠券可用范围************************************************/
$item['coupon_type'] = '全场通用';
$item['tips'] = '';
switch ($item['use_goods_type']){
case 1:
$item['coupon_type'] = '全场通用';
$item['tips'] = '';
break;
case 2:
$item['coupon_type'] = '指定商品可用';
$goods_ids = array_column($item['coupon_goods']->toarray(),'goods_id');
$goods_name_array = array_intersect_key($goods_list,array_flip($goods_ids));
$item['tips'] ='商品'.implode('、',$goods_name_array).'可用';
break;
case 3:
$item['coupon_type'] = '指定商品可用';
$goods_ids = array_column($item['coupon_goods']->toarray(),'goods_id');
$goods_name_array = array_intersect_key($goods_list,array_flip($goods_ids));
$item['tips'] ='商品'.implode('、',$goods_name_array).'可用';
break;
}
//使用门槛
if($item['condition_type'] == 1){
$item['use_condition'] = '无金额门槛';
}
/*********************************优惠券使用时间***********************************/
$item['use_time_tips'] = '';
switch ($item['use_time_type']){
case 2:
$item['use_time'] = $item['create_time']+86400*$item['use_time'];
$item['use_time_tips'] = '有效期至:'.date('Y.m.d H:i',$item['use_time']);
break;
case 3:
$item['use_time'] = $item['create_time'] + 86400 * $item['use_time']+86400;
$item['use_time_tips'] = '有效期至:'.date('Y.m.d H:i',$item['use_time']);
break;
default:
$item['use_time_tips'] = date('Y.m.d H:i',$item['use_time_start']).'-'.date('Y.m.d H:i',$item['use_time_end']);
}
}
$coupon_list->hidden(['coupon_goods'])->visible(['id','name','money','coupon_code','coupon_type','tips','use_time_tips','use_condition']);
return $coupon_list;
}
//领取优惠券
public static function userGetCoupon($coupon_id,$user_id){
$now = time();
//生成券码
$coupon_code = create_coupon_code();
$add_data = [
'user_id' => $user_id,
'coupon_id' => $coupon_id,
'coupon_code' => $coupon_code,
'status' => 0,
'create_time' => $now,
'update_time' => $now,
'del' => 0,
];
$result = Db::name('coupon_list')->insert($add_data);
if ($result) {
// 钩子-记录足迹(领取优惠券)
Hook::listen('footprint', [
'type' => Footprint::receive_coupon,
'user_id' => $user_id,
'foreign_id' => $coupon_id //优惠券ID
]);
}
return $result;
}
//下单获取优惠券
public static function orderCoupon($goods,$user_id){
//更新过期优惠券
\app\common\logic\CouponLogic::couponClose($user_id);
$coupon = [
'usable' => [],//可用
'unusable' => [],//不可用
];
if($goods){
$coupon_model = new Coupon();
//找出自己的优惠券
$my_coupon = $coupon_model->alias('c')
->join('coupon_list cl','cl.coupon_id = c.id')
->where(['user_id'=>$user_id,'c.del'=>0,'cl.del'=>0,'cl.status'=>0])
->field('c.*,cl.id as cl_id,cl.create_time as get_coupon_time')
->order('cl.id desc')
->select()->toArray();
//数组切换成对应的索引:[2=>1] 2=item_id
$item_num = array_column($goods,'num','item_id');
//找出下单的商品信息
$item_ids = array_column($goods,'item_id');
//找出下单的商品对应的价格
$goods_price_array = Db::name('goods_item')->alias('gi')
->join('goods g','gi.goods_id = g.id')
->where(['gi.id'=>$item_ids])
->column('gi.*,g.is_member','gi.id');
//会员折扣价格
$level_discount = Db::name('user u')
->join('user_level l', 'u.level = l.id')
->where('u.id', $user_id)
->value('discount');
$seckill_list = SeckillLogic::getSeckillGoods();
$seckill_goods = $seckill_list['seckill_goods'];
//会员折扣价(优先级最高且不和其他活动重叠) > 活动价格
foreach ($goods_price_array as $key => $item) {
if ($item['is_member'] == 1 && $level_discount > 0) {
$goods_price_array[$key]['price'] = round($item['price'] * $level_discount / 10, 2);
continue;
}
if(isset($seckill_goods[$item['id']])){
$goods_price_array[$key]['price'] = $seckill_goods[$item['id']]['price'];
continue;
}
}
if($my_coupon){
//处理优惠券信息
foreach ($my_coupon as &$coupon_item){
/*****************拼接优惠券信息**********************/
//优惠券类型
$coupon_item['coupon_type'] = '全场店铺可用';
//优惠券使用时间
$coupon_item['use_time_tips'] = '';
$coupon_item['use_condition'] = '满'.floatval($coupon_item['condition_money']).'减'.floatval($coupon_item['money']);
//优惠券使用范围
switch ($coupon_item['use_goods_type']){
case 1:
$coupon_item['coupon_type'] = '全场通用';
break;
case 2:
$coupon_item['coupon_type'] = '指定商品可用';
break;
case 3:
$coupon_item['coupon_type'] = '指定商品不可用';
break;
}
if($coupon_item['condition_type'] == 1){
$coupon_item['use_condition'] = '无金额门槛';
}
//优惠券使用时间
$coupon_item['use_time_tips'] = '';
switch ($coupon_item['use_time_type']){
case 2:
$coupon_item['use_time_start'] = $coupon_item['get_coupon_time']+86400;
$coupon_item['use_time_end'] = $coupon_item['get_coupon_time']+86400*$coupon_item['use_time'];
$coupon_item['use_time_tips'] = '有效期至:'.date('Y.m.d H:i',$coupon_item['use_time_end']);
break;
case 3:
$coupon_item['use_time_start'] = $coupon_item['get_coupon_time'] + 86400;
$coupon_item['use_time_end'] = $coupon_item['get_coupon_time'] + 86400 * $coupon_item['use_time']+86400;
$coupon_item['use_time_tips'] = '有效期至:'.date('Y.m.d H:i',$coupon_item['use_time_end']);
break;
default:
$coupon_item['use_time_tips'] = date('Y.m.d H:i',$coupon_item['use_time_start']).'-'.date('Y.m.d H:i',$coupon_item['use_time_end']);
}
/*****************优惠券不可用和可用**********************/
$coupon_item['tips'] = '';
$coupon_info = [
'id' => $coupon_item['cl_id'],
'coupon_id' => $coupon_item['id'],
'name' => $coupon_item['name'],
'money' => $coupon_item['money'],
'get_coupon_time' => $coupon_item['get_coupon_time'],
'use_time_tips' => $coupon_item['use_time_tips'],
'use_condition' => $coupon_item['use_condition'],
'coupon_type' => $coupon_item['coupon_type'],
'tips' => $coupon_item['tips'],
];
//验证优惠券是否过期
$now = time();
if($coupon_item['use_time_type'] == 1 || $coupon_item['use_time_type'] == 3){
if($coupon_item['use_time_start'] > $now || $coupon_item['use_time_end'] < $now){
$coupon_info['tips'] = '优惠券不在使用时间范围内';
$coupon['unusable'][] = $coupon_info;
continue;
}
}
if ($coupon_item['use_time_type'] == 2) {
if ($now >= $coupon_item['use_time_end']) {
$coupon_info['tips'] = '优惠券不在使用时间范围内';
$coupon['unusable'][] = $coupon_info;
continue;
}
}
//当前优惠券的商品id
$goods_ids = array_column($goods_price_array,'goods_id');
//优惠券商品
$coupon_goods = Db::name('coupon_goods')->where(['coupon_id' => $coupon_item['id']])->column('goods_id');
$intersect_goods = array_intersect($goods_ids,$coupon_goods);
if($goods_price_array){
//全部商品可用,满足金额可用
if($coupon_item['use_goods_type'] == 1 && $coupon_item['condition_type'] == 2){
$total_price = 0;
foreach ($goods as $goods_item){
$price = isset($goods_price_array[$goods_item['item_id']]) ? $goods_price_array[$goods_item['item_id']]['price'] : 0;
$total_price += $price * $goods_item['num'];
}
if($total_price < $coupon_item['condition_money']){
$coupon_info['tips'] = '所结算的商品中未满足使用的金额';
$coupon['unusable'][] = $coupon_info;
continue;
}
}
//指定商品可用
if($coupon_item['use_goods_type'] == 2) {
if(empty($intersect_goods)){
$coupon_info['tips'] = '所结算的商品中未包含指定商品';
$coupon['unusable'][] = $coupon_info;
continue;
}
//满足金额可用
if($intersect_goods && $coupon_item['condition_type'] == 2){
$total_price = 0;
foreach ($intersect_goods as $goods_item){
foreach ($goods_price_array as $price_item){
if($price_item['goods_id'] == $goods_item){
$num = $item_num[$price_item['id']] ?? 0;
$total_price += $price_item['price'] * $num;
}
}
}
if($total_price < $coupon_item['condition_money']){
$coupon_info['tips'] = '所结算的商品中未满足使用的金额';
$coupon['unusable'][] = $coupon_info;
continue;
}
}
}
//指定商品不可用
if($coupon_item['use_goods_type'] == 3) {
//无门槛使用
if($intersect_goods){
$coupon_info['tips'] = '所结算的商品中包含指定不可用商品';
$coupon['unusable'][] = $coupon_info;
continue;
}
//满足金额可用
if(empty($intersect_goods) && $coupon_item['condition_type'] == 2){
$diff_goods = array_diff($goods_ids,$coupon_goods);
$total_price = 0;
foreach ($diff_goods as $goods_item){
foreach ($goods_price_array as $price_item){
if($price_item['goods_id'] == $goods_item){
$num = $item_num[$price_item['id']] ?? 0;
$total_price += $price_item['price'] * $num;
}
}
}
if($total_price < $coupon_item['condition_money']){
$coupon_info['tips'] = '所结算的商品中未满足使用的金额';
$coupon['unusable'][] = $coupon_info;
continue;
}
}
}
$coupon['usable'][] = $coupon_info;
}else{
$coupon_info['tips'] = '所结算的商品中未包含指定商品';
$coupon['unusable'][] = $coupon_info;
}
}
}
}
return $coupon;
}
/**
* note 注册赠送优惠券
* create_time 2020/12/3 17:43
*/
public static function registerSendCoupon($user_id){
$now = time();
$coupon_list = [];
$cache_name = 'register_coupon_'.$user_id;
$register_coupon = Cache::get($cache_name);
//可领取注册优惠券
if($register_coupon){
//领取优惠券的id
$register_award_coupon = ConfigServer::get('marketing','register_award_coupon',[]);
if($register_award_coupon){
$register_award_coupon = explode(',', $register_award_coupon);
$list = Db::name('coupon')
->where(['id'=>$register_award_coupon,'get_type'=>2,'status'=>1,'del'=>0])
->select();
foreach ($list as $coupon){
$use_goods_type = '';
switch ($coupon['use_goods_type']){
case 1:
$use_goods_type = '全场通用';
break;
case 2:
$use_goods_type = '指定商品可用';
break;
case 3:
$use_goods_type = '指定商品不可用';
break;
}
$coupon_list[] = [
'id' => $coupon['id'],
'name' => $coupon['name'],
'money' => $coupon['money'],
'use_goods_type'=> $use_goods_type,
];
//判断该优惠券是否可领取
if( $coupon['send_total_type'] === 2){
$total_get_coupon = Db::name('coupon_list')->where(['coupon_id'=>$coupon['id']])->count();
if($total_get_coupon >= $coupon['send_total']){
continue;
}
}
if($coupon['get_num_type'] !== 1 ){
$where[] = ['coupon_id','=',$coupon['id']];
$where[] = ['user_id','=',$user_id];
if($coupon['get_num_type'] === 3){
list($today_start,$end_start) = Time::today();
$where[] = ['create_time','between time',[$today_start,$end_start]];
}
$total_get_coupon = Db::name('coupon_list')->where($where)->count();
if($total_get_coupon >= $coupon['get_num']){
continue;
}
}
//生成券码
$coupon_code = create_coupon_code();
$add_data = [
'user_id' => $user_id,
'coupon_id' => $coupon['id'],
'coupon_code' => $coupon_code,
'status' => 0,
'create_time' => $now,
'update_time' => $now,
'del' => 0,
];
Db::name('coupon_list')->insert($add_data);
}
}
Cache::rm($cache_name);
}
return $coupon_list;
}
}
@@ -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\server\{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];
}
}
@@ -0,0 +1,72 @@
<?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\model\FootprintRecord;
use app\common\server\ConfigServer;
class FootPrintLogic
{
public static function lists()
{
$config = ConfigServer::get('footprint',0);
if (empty($config['footprint_status']) or $config['footprint_status'] === 0) {
return ['time'=>time(), 'lists'=>[]];
}
$where = [];
if ($config['footprint_duration'] and $config['footprint_duration'] > 0) {
$duration = ($config['footprint_duration'] * 60);
$time = time() - $duration; //获取多少分钟前
$where = [
['create_time', '>=', $time]
];
}
$model = new FootprintRecord();
$lists = $model->field(true)->where($where)
->with(['user'=>function($query){
$query->withAttr('nickname', function ($value){
if (mb_strlen($value) > 4) {
return mb_substr($value, 0, 4).'**';
}
return $value;
});
}])->order('id', 'desc')
->limit(50)
->append(['time'])->select();
foreach ($lists as &$item) {
$item['template'] = self::getTemplate($item);
unset($item['user_id']);
unset($item['foreign_id']);
}
return ['time'=>time(), 'lists'=>$lists];
}
// 获取模板
private static function getTemplate($data)
{
$nickname = $data['user']['nickname'].' ';
$time = $data['time'];
return $nickname.$time.$data['template'];
}
}
@@ -0,0 +1,178 @@
<?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\model\Freight;
use think\Db;
/**
* 运费逻辑
* Class FreightLogic
* @package app\api\logic
*/
class FreightLogic
{
/**
* User: 意象信息科技 mjf
* Desc: 计算运费
* @param $goods
* @param $user_address
* @return float|int
*/
public static function calculateFreight($goods, $user_address)
{
$shipping_price = 0;
$template_list = [];
if (empty($user_address)){
return $shipping_price;
}
foreach ($goods as $good){
//统一邮费
if ($good['free_shipping_type'] == 2){
$shipping_price += round($good['free_shipping'] * $good['goods_num'], 2);
}
//指定运费模板
if ($good['free_shipping_type'] == 3 && $good['free_shipping_template_id'] > 0){
$template_list[$good['free_shipping_template_id']][] = $good;
}
}
foreach ($template_list as $template_id => $template_goods) {
$temp = [];
$temp['template_id'] = $template_id;
$temp['total_volume'] = 0;
$temp['total_weight'] = 0;
$temp['goods_num'] = 0;
foreach ($template_goods as $template_good) {
$temp['total_volume'] += $template_good['volume'] * $template_good['goods_num'];
$temp['total_weight'] += $template_good['weight'] * $template_good['goods_num'];
$temp['goods_num'] += $template_good['goods_num'];
}
$shipping_price += self::calculate($temp, $user_address);
}
return $shipping_price < 0 ? 0 : $shipping_price;
}
/**
* User: 意象信息科技 mjf
* Desc: 计算运费
* @param $data
* @param $user_address
* @return float|int
*/
public static function calculate($data, $user_address)
{
$shipping_price = 0;
$freight = FreightLogic::getFreightsByAddress($data['template_id'], $user_address);
if (empty($freight)){
return $shipping_price;
}
$unit = 0;
//按重量计算
if ($freight['charge_way'] == Freight::CHARGE_WAY_WEIGHT){
$unit = $data['total_weight'];
}
//按件数计算
if ($freight['charge_way'] == Freight::CHARGE_WAY_PIECE){
$unit = $data['goods_num'];
}
//按体积计算
if ($freight['charge_way'] == Freight::CHARGE_WAY_VOLUME){
$unit = $data['total_volume'];
}
if($unit > $freight['first_unit'] && $freight['continue_unit'] > 0){
$left = ceil(($unit - $freight['first_unit']) / $freight['continue_unit']);//取整
return $freight['first_money'] + $left * $freight['continue_money'];
}else{
return $freight['first_money'];
}
}
/**
* User: 意象信息科技 mjf
* Desc: 通过用户地址获取运费模板
* @param $address
*/
public static function getFreightsByAddress($template_id, $address)
{
$district_id = $address['district_id'];
$city_id = $address['city_id'];
$province_id = $address['province_id'];
$freights = Db::name('freight')->alias('f')
->join('freight_config c', 'c.freight_id = f.id')
->where('f.id', $template_id)
->order(['f.id' => 'desc', 'c.id' => 'desc'])
->select();
foreach ($freights as $freight) {
$region_ids = explode(',', $freight['region']);
if (in_array($district_id, $region_ids)) {
return $freight;
}
if (in_array($city_id, $region_ids)) {
return $freight;
}
if (in_array($province_id, $region_ids)) {
return $freight;
}
if ($freight['region'] = 'all'){
$national_freight = $freight;
}
}
//会员的省市区id在商家的运费模板(指定地区)中找不到,查一下商家的全国运费模板
return $national_freight;
}
/**
* User: 意象信息科技 mjf
* Desc: 模板中指定地区id是否存在
* @param $freights
* @param $region_id
* @return bool|mixed
*/
public static function isExistRegionId($freights, $region_id)
{
foreach ($freights as $freight) {
$region_ids = explode(',', $freight['region']);
if (in_array($region_id, $region_ids)) {
return $freight;
}
}
return false;
}
}
@@ -0,0 +1,116 @@
<?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\server\UrlServer;
use think\Db;
use think\facade\Cache;
class GoodsCategoryLogic{
/**
* Notes:获取商品分类接口
* @param $client int 终端:1-移动端;2-pc端
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @author: 2021/3/6 18:49
*/
public static function categoryThirdTree($client){
$cache = Cache::get('goods_category_'.$client);
if ($cache) {
return $cache;
}
$lists = Db::name('goods_category')->where(['is_show'=>1,'del'=>0,'level'=>1])->order('sort desc')->column('id,name,pid,image,level','id');
$level2 = Db::name('goods_category')->where(['is_show'=>1,'del'=>0,'level'=>2])->order('sort desc')->column('id,name,pid,image,level','id');
$level3 = Db::name('goods_category')->where(['is_show'=>1,'del'=>0,'level'=>3])->order('sort desc')->field('id,name,pid,image,level')->select();
//挂载第二级
foreach ($level3 as $list3){
if(isset($level2[$list3['pid']])){
$list3['image'] = UrlServer::getFileUrl($list3['image']);
$list3['type'] = 1;
$level2[$list3['pid']]['sons'][] = $list3;
}
}
//挂载第一级、并移除没有下级的二级分类
foreach ($level2 as $key2 => $list2){
// if(!isset($list2['sons'])){
// unset($level2[$key2]);
// continue;
// }
if(isset($lists[$list2['pid']])){
$list2['type'] = 1;
$list2['image'] = UrlServer::getFileUrl($list2['image']);
$lists[$list2['pid']]['sons'][] = $list2;
}
}
//移除没有完整的三级分类
foreach ($lists as $key1 => $list1){
// if(!isset($list1['sons'])){
// unset($lists[$key1]);
// continue;
//
// }
if(!isset($list1['sons'])){
$lists[$key1]['sons'] = [];
}
$lists[$key1]['image'] = UrlServer::getFileUrl($list1['image']);
$lists[$key1]['type'] = 1;
}
//pc端不显示品牌
if(1 == $client){
$goods_brand = Db::name('goods_brand')
->where(['del'=>0,'is_show'=>1])
->field('id,name,image')
->order('sort desc,id desc')
->select();
if($goods_brand){
foreach ($goods_brand as &$brand_item){
$brand_item['type'] = 0;
$brand_item['image'] = UrlServer::getFileUrl($brand_item['image']);
}
$brand = [
'id' => 0,
'name' => '品牌推荐',
'type' => 0,
'sons' =>[
[
'id' => 0,
'name' => '热门品牌',
'type' => 0,
'sons' => $goods_brand,
]
],
];
array_unshift($lists,$brand);
}
}
Cache::set('goods_category_'.$client, array_values($lists));
return array_values($lists);
}
}
@@ -0,0 +1,336 @@
<?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\model\Order;
use app\common\model\Pay;
use app\common\server\UrlServer;
use think\Db;
class GoodsCommentLogic{
//列表
public static function lists($get,$page, $size)
{
$where= [];
$where[] = ['gc.goods_id','=',$get['goods_id']];
switch ($get['id']){
case 1://晒图
$where[]= ['i.uri','not null',''];
break;
case 2://好评
$where[]= ['goods_comment','>',3];
break;
case 3://中评
$where[]= ['goods_comment','=',3];
break;
case 4://差评
$where[]= ['goods_comment','<',3];
break;
}
$comment_count = Db::name('goods_comment')->alias('gc')
->leftJoin('goods_comment_image i','gc.id = i.goods_comment_id')
->join('goods_item gi','gi.id = gc.item_id')
->leftJoin('user u','u.id = gc.user_id')
->where(['gc.del'=>0,'gc.status'=>1])
->where($where)
->group('gc.id')
->count();
$comment_lists = Db::name('goods_comment')->alias('gc')
->leftJoin('goods_comment_image i','gc.id = i.goods_comment_id')
->leftJoin('goods_item gi','gi.id = gc.item_id')
->leftJoin('user u','u.id = gc.user_id')
->where(['gc.del'=>0,'gc.status'=>1])
->where($where)
->page($page,$size)
->field('gc.id,goods_comment,service_comment,express_comment,comment,description_comment,reply,gc.create_time,u.nickname,avatar,gi.spec_value_str,virtual_data')
->group('gc.id')
->order('gc.id desc')
->select();
$iamge_list = [];
$comment_id = array_column($comment_lists,'id');
if($comment_id){
$iamge_list = Db::name('goods_comment_image')
->where(['goods_comment_id'=>$comment_id])
->field('goods_comment_id,uri')
->select();
}
foreach ($comment_lists as &$comment){
// 虚拟评论
if (empty($comment['user_id']) && !empty($comment['virtual_data'])) {
$virtual_data = json_decode($comment['virtual_data'], JSON_UNESCAPED_UNICODE);
$comment['avatar'] = $virtual_data['avatar'] ?? '';
$comment['nickname'] = $virtual_data['nickname'] ?? '';
$comment['create_time'] = $virtual_data['comment_time'] ?? time();
}
$comment['avatar'] = UrlServer::getFileUrl($comment['avatar']);
$comment['create_time'] = date('Y-m-d H:i:s',$comment['create_time']);
$comment['image'] = [];
foreach ($iamge_list as $image){
if($comment['id'] == $image['goods_comment_id']){
$comment['image'][] = UrlServer::getFileUrl($image['uri']);
}
}
if(empty($comment['comment'])){
$comment['comment'] = '此用户没有填写评论';
}
if (empty($comment['spec_value_str'])){
$comment['spec_value_str'] = '';
}
}
//好评总数
$good_count = Db::name('goods_comment')
->where(['del'=>0,'status'=>1,'goods_id'=>$get['goods_id']])
->where('goods_comment','>',3)
->count();
//总评论数
$all_count = Db::name('goods_comment')
->where(['del'=>0,'status'=>1,'goods_id'=>$get['goods_id']])
->where('status',1)
->count();
if($all_count == 0){
$score ='100%';
}else{
$score = round($good_count/$all_count*100,2).'%';
}
$more = is_more($comment_count,$page,$size); //是否有下一页
return [
'list' => $comment_lists,
'count' => $comment_count,
'percent' => $score,
'page_no' => $page,
'page_size' => $size,
'more' => $more
];
}
//提交评论
public static function addGoodsComment($post ,$user_id){
$time =time();
$order_goods= db::name('order_goods')
->where(['id'=>$post['id'],'is_comment'=>0])
->field('goods_id,item_id')
->find();
if(empty($order_goods)){
return '商品已评论,请勿重复评论';
}
$comment_data= [
'order_goods_id' =>$post['id'],
'user_id' => $user_id,
'goods_id' => $order_goods['goods_id'],
'item_id' => $order_goods['item_id'],
'goods_comment' => $post['goods_comment'],
'description_comment' => $post['description_comment'],
'service_comment' => $post['service_comment'],
'express_comment' => $post['express_comment'],
'create_time' =>$time,
];
isset($post['comment']) && $comment_data['comment'] = $post['comment'];
$comment_id = Db::name('goods_comment')->insertGetId($comment_data);
if(!$comment_id){
return '评论失败,请重新提交';
}
if(isset($post['image']) && $post['image']){
foreach ($post['image'] as $image_val){
$image[]= ['uri'=>$image_val,'goods_comment_id'=>$comment_id];
}
Db::name('goods_comment_image')->insertAll($image);
}
Db::name('order_goods')->where('id',$post['id'])->update(['is_comment'=>1]);
return true;
}
//分类列表
public static function category($get){
$all_count = Db::name('goods_comment')
->where(['del'=>0,'status'=>1,'goods_id'=>$get['goods_id']])
->where('status',1)
->count();
$good_count = Db::name('goods_comment')
->where(['del'=>0,'status'=>1,'goods_id'=>$get['goods_id']])
->where('goods_comment','>',3)
->count();
$medium_count = Db::name('goods_comment')
->where(['del'=>0,'status'=>1,'goods_id'=>$get['goods_id']])
->where('goods_comment','=',3)
->count();
$bad_count = Db::name('goods_comment')
->where(['del'=>0,'status'=>1,'goods_id'=>$get['goods_id']])
->where('goods_comment','<',3)
->count();
$image_count = Db::name('goods_comment')->alias('g')
->rightJoin('goods_comment_image i','i.goods_comment_id=g.id')
->where(['del'=>0,'status'=>1,'goods_id'=>$get['goods_id']])
->where('uri','not null')
->group('goods_comment_id')
->count();
$avg_score = Db::name('goods_comment')
->where(['del'=>0,'status'=>1,'goods_id'=>$get['goods_id']])
->avg('goods_comment');
if($all_count == 0){
$score ='100%';
$avg_score = 5;
}else{
$score = round($good_count/$all_count*100,2).'%';
$avg_score = round($avg_score,1);
}
return ['comment'=>
[
[
'name' => '全部',
'id' => 0,
'count' => $all_count
],
[
'name' => '晒图',
'id' => 1,
'count' => $image_count
],
[
'name' => '好评',
'id' => 2,
'count' => $good_count
],
[
'name' => '中评',
'id' => 3,
'count' => $medium_count
],
[
'name' => '差评',
'id' => 4,
'count' => $bad_count
]
] ,
'percent' => $score,
'avg_score' => $avg_score,
];
}
//订单商品列表
public static function getOrderGoods($type,$user_id,$page,$size){
$where[] = ['O.order_status','=',Order::STATUS_FINISH];
$where[] = ['O.del','=',0];
$where[] = ['O.user_id','=',$user_id];
if($type == 1) {
$where[] = ['is_comment', '=',0];
}else{
$where[] = ['is_comment', '=',1];
}
$order_goods_count = Db::name('order')->alias('O')
->join('order_goods OG','O.id = OG.order_id')
->join('goods G','OG.goods_id = G.id')
->where($where)
->count();
$order_goods_list = Db::name('order')->alias('O')
->join('order_goods OG','O.id = OG.order_id')
->join('goods G','OG.goods_id = G.id')
->where($where)
->field('OG.id,OG.goods_id,item_id,OG.goods_price,goods_num,G.image,G.name as goods_name,OG.goods_info,G.del,G.status')
->page($page,$size)
->order('O.id desc')
->select();
$goods_comment = [];
if($type == 2 && $order_goods_list) {
$order_goods_ids = array_column($order_goods_list, 'id');
$goods_comment_list = Db::name('goods_comment')
->where(['order_goods_id' => $order_goods_ids, 'del' => 0])
->column('goods_comment,comment,create_time,id', 'order_goods_id');
}
foreach ($order_goods_list as &$goods) {
$goods['image'] = UrlServer::getFileUrl($goods['image']);
$goods['goods_comment'] = '';
$goods['comment'] = '';
$goods['create_time'] = '';
if (isset($goods_comment_list[$goods['id']])) {
$goods_comment = $goods_comment_list[$goods['id']];
$goods['goods_comment'] = $goods_comment['goods_comment'];
$goods['comment'] = $goods_comment['comment'] ?: '此用户没有填写评论';
$goods['create_time'] = date('Y-m-d H:i:s', $goods_comment['create_time']);
$goods['comment_image'] = Db::name('goods_comment_image')->where(['goods_comment_id' => $goods_comment['id']])->column('uri');
foreach ($goods['comment_image'] as &$uri){
$uri = UrlServer::getFileUrl($uri);
}
}
//商品规格名称
$goods_snapshot = json_decode($goods['goods_info'], true);
$goods['spec_value_str'] = $goods_snapshot['spec_value_str'];
unset($goods['goods_info']);
}
$more = is_more($order_goods_count, $page, $size); //是否有下一页
return [
'list' => $order_goods_list,
'count' => $order_goods_count,
'page_no' => $page,
'page_size' => $size,
'more' => $more
];
}
//商品评论
public static function getGoods($id){
$goods = Db::name('order_goods')->alias('og')
->join('goods g','og.goods_id = g.id')
->where(['og.id'=>$id,'del'=>0,'og.is_comment'=>0])
->field('og.id,g.id as goods_id,name,image,og.goods_price,goods_num,og.goods_info,og.total_pay_price,og.total_price')
->find();
if($goods){
$goods['image'] = UrlServer::getFileUrl( $goods['image']);
$goods_snapshot = json_decode($goods['goods_info'], true);
$goods['spec_value_str'] = $goods_snapshot['spec_value_str'];
unset($goods['goods_info']);
}
return $goods;
}
}
+401
View File
@@ -0,0 +1,401 @@
<?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\api\model\Goods;
use app\common\model\Distribution;
use app\common\model\DistributionGoods;
use app\common\model\DistributionLevel;
use app\common\model\Footprint;
use app\common\model\GoodsBrand;
use app\common\model\TeamActivity;
use app\common\model\TeamFound;
use app\common\model\TeamGoodsItem;
use app\common\server\ConfigServer;
use app\common\server\UrlServer;
use think\Db;
use think\facade\Hook;
class GoodsLogic{
//商品列表
public static function getGoodsList($user_id,$get,$page,$size){
$where = [];
$order = [];
$where[] = ['status','=',1];
$where[] = ['del','=',0];
$goods = new Goods();
//品牌筛选
if(isset($get['brand_id']) && $get['brand_id']) {
$where[] = ['brand_id', '=', $get['brand_id']];
}
//分类筛选
if(isset($get['category_id']) && $get['category_id']){
$where[] = ['first_category_id|second_category_id|third_category_id','=',$get['category_id']];
}
//关键词搜索
if(isset($get['keyword']) && $get['keyword']){
// 优先查品牌 然后再查询商品
$band_ids = GoodsBrand::where('is_show', 1)->where('name', 'like', "%{$get['keyword']}%")->column('id');
if ($band_ids) {
$where[] = function ($query) use($band_ids, $get) {
$query->where('brand_id', 'in', $band_ids)->whereOr('name', 'like', "%{$get['keyword']}%");
};
} else {
$where[] = [ 'name', 'like', "%{$get['keyword']}%" ];
}
//记录关键词
if($user_id){
self::recordKeyWord(trim($get['keyword']),$user_id);
}
}
//销量排序
if(isset($get['sales_sum']) && $get['sales_sum']){
$order['sales_sum'] = $get['sales_sum'];
}
//价格排序
if(isset($get['price']) && $get['price']){
$order['min_price'] = $get['price'];
}
$order['sort'] = 'desc';
$order['id'] = 'desc';
$goods_count = $goods
->where($where)
->count();
$goods_list = $goods
->where($where)
->page($page,$size)
->order($order)
->field('id,name,image,min_price as price,market_price,sales_sum+virtual_sales_sum as sales_sum,sort')
->select();
$more = is_more($goods_count,$page,$size); //是否有下一页
$data = [
'list' => $goods_list,
'page_no' => $page,
'page_size' => $size,
'count' => $goods_count,
'more' => $more
];
return $data;
}
//记录搜索关键词
public static function recordKeyWord($keyword,$user_id){
$record = Db::name('search_record')->where(['user_id'=>$user_id,'keyword'=>$keyword,'del'=>0])->find();
if($record){
return Db::name('search_record')->where(['id'=>$record['id']])->update(['count'=>Db::raw('count+1'),'update_time'=>time()]);
}
return Db::name('search_record')->insert(['user_id'=>$user_id,'keyword'=>$keyword]);
}
//商品详情
public static function getGoodsDetail($user_id,$id){
$goods = Goods::get(['id'=>$id,'status'=>1],['goods_image','goods_item']);
if(empty($goods)){
return [];
}
//点击量
$goods->click_count = $goods->click_count + 1;
$goods->save();
$goods->sales_sum += $goods->virtual_sales_sum;
$goods->is_collect = 0;
$goods->member_price = 0;
$goods->append(['order_give_integral', 'commission_price']);
//检查商品是否整在参加活动,如果正在参加活动替换商品的价格为活动价
$goods = self::checkActivity($goods);
if($user_id) {
//是否收藏
$collect = Db::name('goods_collect')->where(['user_id'=>$user_id,'goods_id'=>$id])->find();
$goods->is_collect= $collect ? 1 : 0;
//会员折扣
$member_discount = Db::name('user_level l')
->join('user u', 'u.level = l.id')
->where(['u.id' => $user_id])
->value('discount');
$price_array = [];
//处理会员折扣价格
if ($goods->is_member > 0 && $member_discount > 0) {
//会员价格
foreach ($goods->goods_item as $item => $value){
$goods->goods_item[$item]['member_price'] = 0;
if($member_discount){
$member_price = round($value['price'] * $member_discount / 10,2);
$goods->goods_item[$item]['member_price'] = $member_price;
$price_array[] = $member_price;
}
}
$price_array && $goods->member_price = min($price_array);
}
//多规格,按最高的价格计算积分
if($price_array && 2 === $goods->give_integral_type){
$price = $price_array ? max($price_array) : $goods->max_price;
$goods->order_give_integral = intval($price * $goods->give_integral / 100);
}
}
//猜你喜欢
$goods->Like();
//商品规格
$goods->GoodsSpec();
$goods->append(['comment'])->hidden(['Spec','GoodsSpecValue'])
->visible(['id','name','image','video','stock','remark','content','sales_sum','poster',
'click_count','min_price','max_price','market_price','is_collect','goods_spec','goods_image',
'goods_item','activity','member_price','is_express','is_selffetch','market_price']);
$market_price_array = array_column($goods->goods_item->toarray(),'market_price');
$goods->market_price = max($market_price_array);
$price_array = array_column($goods->goods_item->toarray(),'price');
$goods->min_price = min($price_array);
$goods->max_price = max($price_array);
$goods->poster = !empty($goods->poster) ? UrlServer::getFileUrl($goods->poster) : '';
// 商品虚拟浏览量
$goods->click_count += $goods->virtual_click;
//判断是否开启了拼团
if ($goods['is_team']) {
$resTeam = self::getTeam($goods);
// 如果活动没结束,则返回拼团数据, 否则把商品是否已开团状态改为,不是开团商品
if ($resTeam !== 100 and is_array($resTeam)) {
$goods['activity'] = $resTeam;
} else {
$goods['is_team'] = 0;
}
}
// 预估佣金
$goods = $goods->toArray();
$goods['distribution'] = self::getDistribution($id, $user_id);
// 钩子-记录足迹(浏览商品)
Hook::listen('footprint', [
'type' => Footprint::browse_goods,
'user_id' => $user_id,
'foreign_id' => $id //商品ID
]);
Db::name('goods_click')->insert([
'user_id' => $user_id,
'goods_id' => $id,
'create_time' => time(),
]);
return $goods;
}
//好物优选
public static function getBestList($page,$size){
$goods = new Goods();
$goods_count = $goods
->where(['del'=>0,'status'=>1,'is_best'=>1])
->count();
$goods_list = $goods
->where(['del'=>0,'status'=>1,'is_best'=>1])
->field('id,name,image,min_price as price,market_price')
->order('sort desc,id desc')
->page($page,$size)
->select();
$more = is_more($goods_count,$page,$size); //是否有下一页
$data = [
'list' => $goods_list,
'page_no' => $page,
'page_size' => $size,
'count' => $goods_count,
'more' => $more
];
return $data;
}
//热门推荐
public static function getHostList($page,$size){
$goods = new Goods();
$goods_count = $goods
->where(['del'=>0,'status'=>1])
->count();
$goods_list = $goods
->where(['del'=>0,'status'=>1])
->field('id,name,image,min_price as price,market_price,sales_sum+virtual_sales_sum as sales_sum,click_count,sort')
->order('sales_sum desc,click_count desc, sort desc')
->page($page,$size)
->select();
$more = is_more($goods_count,$page,$size); //是否有下一页
$data = [
'list' => $goods_list,
'page_no' => $page,
'page_size' => $size,
'count' => $goods_count,
'more' => $more
];
return $data;
}
//搜索记录
public static function getSearchPage($user_id,$limit){
$history_list = Db::name('search_record')
->where(['user_id'=>$user_id,'del'=>0])
->limit($limit)
->order('id desc')
->column('keyword');
$hot_lists = ConfigServer::get('hot_search','hot_keyword',[]);
return[
'history_lists' => $history_list,
'hot_lists' => $hot_lists,
];
}
//检查商品是否正在参加活动
public static function checkActivity($goods){
$goods['activity'] = [];
$seckill = SeckillLogic::getSeckillGoods();
if($seckill['seckill_goods']){
$seckill_goods_ids = array_column($seckill['seckill_goods'],'goods_id');
if($seckill['seckill_goods'] && in_array($goods['id'],$seckill_goods_ids)){
$goods['activity'] = [
'type' => 1,
'info' => $seckill['seckill'],
];
foreach ($goods['goods_item'] as &$item){
if(isset($seckill['seckill_goods'][$item['id']])){
$item['price'] = $seckill['seckill_goods'][$item['id']]['price'];
}
}
}
}
return $goods;
}
//清空搜索记录
public static function clearSearch($user_id){
return Db::name('search_record')
->where(['user_id'=>$user_id])
->update(['del'=>1,'update_time'=>time()]);
}
// 获取拼团内容
private static function getTeam($goods)
{
// 查询拼团活动信息
$teamActivityModel = new TeamActivity();
$team = $teamActivityModel->field(true)
->where(['del'=>0, 'status'=>1, 'goods_id'=>$goods['id']])->find();
// 判断是否已到活动时间 (为真则活动结束)
if ($team['end_time'] <= time()) {
Goods::where(['id'=>$goods['id']])->update([ 'is_team' => 0 ]);
return 10;
}
// 查询规格信息
$teamGoodsItem = new TeamGoodsItem();
$team_item = $teamGoodsItem->field(true)
->where('team_id', '=', $team['team_id'])
->where('goods_id','=', $team['goods_id'])->select();
$team_spec_price = [];
foreach ($team_item as $item) {
$team_spec_price[intval($item['item_id'])] = $item['team_price'];
}
// 重置商品规格价格 为 拼团活动规格的价格
$goods_item = $goods['goods_item'];
foreach ($goods_item as &$item) {
$item['team_price'] = $team_spec_price[$item['id']];
}
$goods['goods_item'] = $goods_item;
unset($team['status']);
unset($team['del']);
unset($team['create_time']);
// 获取该商品正在开的团,但是还不够人的团
$teamFoundModel = new TeamFound();
$team_found = $teamFoundModel->field('id,team_id,found_time,found_end_time,
nickname,avatar,join,need')
->where('team_id', '=', $team['team_id'])
->where('status', '=', 0)
->where('found_end_time', '>', time())
->limit(10)
->select()->toArray();
return ['type'=>2, 'team'=>$team, 'team_found'=>$team_found];
}
/**
* 计算最高可得预估佣金
* @param $goodsId
* @param $userId
* @return array
*/
public static function getDistribution($goodsId, $userId)
{
$earnings = 0;
$goods = \app\common\model\Goods::findOrEmpty($goodsId)->toArray();
$distributionGoods = DistributionGoods::where('goods_id', $goodsId)->select()->toArray();
if(!empty($distributionGoods) && $distributionGoods[0]['is_distribution'] && $distributionGoods[0]['rule'] == 2) {
foreach($distributionGoods as $item) {
$earnings = max($earnings, round($goods['max_price'] * $item['first_ratio'] / 100, 2));
$earnings = max($earnings, round($goods['max_price'] * $item['second_ratio'] / 100, 2));
}
}
if(!empty($distributionGoods) && $distributionGoods[0]['is_distribution'] && $distributionGoods[0]['rule'] == 1) {
$levels = DistributionLevel::select()->toArray();
foreach($levels as $item) {
$earnings = max($earnings, round($goods['max_price'] * $item['first_ratio'] / 100, 2));
$earnings = max($earnings, round($goods['max_price'] * $item['second_ratio'] / 100, 2));
}
}
// 详情页是否显示佣金
$isShow = ConfigServer::get('distribution', 'is_show_earnings', 0);
if ($isShow) {
// 详情页佣金可见用户 0-全部用户 1-分销商
$scope = ConfigServer::get('distribution', 'show_earnings_scope', 0);
$user = Distribution::where(['user_id' => $userId])->findOrEmpty()->toArray();
if ($scope && empty($user['is_distribution'])) {
$isShow = 0;
}
}
return [
'is_show' => $isShow,
'earnings' => $earnings
];
}
}
+112
View File
@@ -0,0 +1,112 @@
<?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\server\UrlServer;
use think\Db;
class HelpLogic
{
public static function lists($id, $page, $size)
{
$where[] = [
['h.del', '=', 0],
['h.is_show', '=', 1],
['c.is_show', '=', 1],
['c.del', '=', 0],
];
if (!empty($id)){
$where[] = ['cid', '=', $id];
}
$res = DB::name('help')->alias('h')
->join('help_category c', 'c.id = h.cid')
->where($where)
->field('h.id,h.title,h.synopsis,h.image,h.visit,h.create_time')
->order(['h.create_time' => 'desc']);
$help_count = $res->count();
$help = $res->page($page, $size)->select();
foreach ($help as &$item) {
$item['create_time'] = date('Y-m-d ', $item['create_time']);
$item['image'] = UrlServer::getFileUrl($item['image']);
}
$more = is_more($help_count, $page, $size); //是否有下一页
return [
'list' => $help,
'count' => $help_count,
'page_no' => $page,
'page_size' => $size,
'more' => $more
];
}
public static function CategoryLists()
{
$res = DB::name('help_category')
->where('is_show', 1)
->where(['del' => 0])
->field('id,name');
return $res->select();
}
public static function getHelpDetail($id,$client)
{
DB::name('help')
->where(['id' => $id, 'del' => 0])
->setInc('visit');
$res = DB::name('help')
->where(['id' => $id, 'del' => 0])
->field('id,title,image,visit,create_time,content')
->order(['create_time' => 'desc'])
->find();
$preg = '/(<img .*?src=")[^https|^http](.*?)(".*?>)/is';
$local_url = UrlServer::getFileUrl() . '/';
$res['content'] = preg_replace($preg, "\${1}$local_url\${2}\${3}", $res['content']);
$res['create_time'] = date('Y-m-d ', $res['create_time']);
$res['image'] = UrlServer::getFileUrl($res['image']);
$recommend_list = [];
if(2 == $client){
$recommend_list = Db::name('help')
->where([['del','=','0'], ['id','<>',$id], ['is_show', '=', 1]])
->field('id,title,image,visit')
->order('visit desc')
->limit(5)
->select();
foreach ($recommend_list as $key => $recommend){
$recommend_list[$key]['image'] = UrlServer::getFileUrl($recommend['image']);
}
}
$res['recommend_list'] = $recommend_list;
return $res;
}
}
+166
View File
@@ -0,0 +1,166 @@
<?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\api\model\Coupon;
use app\api\model\Goods;
use app\common\model\Ad;
use app\common\model\Footprint;
use app\common\server\ConfigServer;
use app\common\server\UrlServer;
use think\Db;
use think\facade\Hook;
class IndexLogic{
public static function lists($user_id){
// 钩子-记录足迹(访问商城)
Hook::listen('footprint', [
'type' => Footprint::enter_mall,
'user_id' => $user_id
]);
//新闻
$news = Db::name('article')
->where(['del'=>0,'is_notice'=>1,'is_show'=>1])
->order('create_time desc')
->field('id,title')
->limit(3)
->select();
if($news){
$news[0]['is_new'] = 1;
}
$default_image = UrlServer::getFileUrl(ConfigServer::get('website', 'goods_image', ''));
//优惠券
$coupon = new Coupon();
$now = time();
$where[] = ['del','=',0];
$where[] = ['status','=',1];
$where[] = ['get_type','=',1];
$where[] = ['send_time_start','<=',$now];
$where[] = ['send_time_end','>=',$now];
$coupon_list = $coupon->where($where)
->field('id,money,condition_type,condition_money')
->limit(9)
->order('id desc')
->select();
$my_coupon = [];
if($user_id){
$my_coupon = Db::name('coupon_list')->where(['del'=>0,'user_id'=>$user_id])->column('coupon_id');
}
foreach ($coupon_list as &$coupon_item){
$coupon_item['is_get'] = 0;
$coupon_item['use_condition'] = '无金额门槛';
//标记已领取
if(in_array($coupon_item['id'],$my_coupon)){
$coupon_item['is_get'] = 1;
}
if($coupon_item['condition_type'] == 2){
$coupon_item['use_condition'] = '满'.floatval($coupon_item['condition_money']) .'元减'.floatval($coupon_item['money']);
}
}
$coupon_list->hidden(['condition_money','condition_type']);
//活动专区
$activity_area = Db::name('activity_area')->field('id,name,title,image')->where(['del'=>0,'status'=>1])->select();
foreach ($activity_area as &$area_item){
$area_item['image'] = UrlServer::getFileUrl($area_item['image']);
}
//秒杀活动
$seckill = SeckillLogic::getSeckill();
if($seckill){
$seckill['goods'] = Db::name('goods g')
->join('seckill_goods sg','g.id = sg.goods_id')
->where(['seckill_id'=>$seckill['id'],'g.del'=>0,'sg.del'=>0,'status'=>1,])
->group('sg.goods_id')
->order('sg.sales_sum,sg.id desc')
->limit(9)
->field('g.id,g.name,g.image,g.min_price,sg.price as seckill_price,sg.sales_sum')
->select();
foreach ($seckill['goods'] as &$seckill_item ){
// 传入默认商品主图
if(empty( $seckill_item['image'])){
$seckill_item['image'] = $default_image;
}else{
$seckill_item['image'] = UrlServer::getFileUrl($seckill_item['image']);
}
}
}else{
$seckill['goods'] = [];
}
//商城logo
$shop_logo =UrlServer::getFileUrl(ConfigServer::get('website', 'shop_logo','/static/common/image/default/shop_logo.png')).'?=v1';
//新品推荐
$goods = new Goods();
$new_goods = $goods
->where(['del'=>0,'status'=>1,'is_new'=>1])
->field('id,name,image,min_price as price,market_price,sales_sum+virtual_sales_sum as sales_sum')
->order('sort desc,id desc')
->limit(5)
->select();
$mall_logo =UrlServer::getFileUrl(ConfigServer::get('website', 'mall_logo', '')).'?=v1';
//热销榜单
$host_goods = $goods
->where(['del'=>0,'status'=>1])
->field('id,name,image,min_price as price,market_price,sales_sum+virtual_sales_sum as sales_sum')
->order('sales_sum DESC,click_count DESC')
->limit(5)
->select();
$list = [
'news' => $news,
'shop_logo' => $shop_logo,
'coupon' => $coupon_list,
'activity_area' => $activity_area,
'seckill' => $seckill,
'host_goods' => $host_goods,
'new_goods' => $new_goods,
'mall_logo' => $mall_logo
];
return $list;
}
/**
* @notes 版权资质
* @param $shop_id
* @return int|mixed|string|null
* @author ljj
* @date 2022/2/22 3:09 下午
*/
public static function copyright()
{
$business_license = ConfigServer::get('copyright', 'business_license');
$other_qualifications = ConfigServer::get('copyright', 'other_qualifications',[]);
if (!empty($business_license)) {
array_unshift($other_qualifications,$business_license);
}
if (!empty($other_qualifications)) {
foreach ($other_qualifications as &$val) {
$val = UrlServer::getFileUrl($val);
}
}
return $other_qualifications;
}
}
@@ -0,0 +1,80 @@
<?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\server\WeChatServer;
use EasyWeChat\Factory;
/**
* 直播 逻辑层
* Class LiveRoom
* @package app\api\controller
*/
class LiveRoomLogic
{
/**
* @notes 获取直播信息列表
* @param $page
* @param $size
* @return array|string
* @author heshihu
* @date 2021/10/14 10:08
*/
public static function lists($page, $size)
{
$config = WeChatServer::getMnpConfig();
$app = Factory::miniProgram($config);
$result = $app->live->getRooms($page-1, $size);
if ($result['errcode'] != 0) {
return $result['errcode'] . '' . $result['errmsg'];
}
$liveStatus = [101=>'直播中', 102=>'未开始', 103=>'已结束', 104=>'禁播', 105=>'暂停', 106=>'异常', 107=>'已过期'];
$data = [];
foreach ($result['room_info'] as $item) {
$data[] = [
'name' => $item['name'],
'roomid' => $item['roomid'],
'cover_img' => $item['cover_img'],
'anchor_name' => $item['anchor_name'],
'status' => $item['live_status'],
'live_status' => $liveStatus[$item['live_status']],
'goods' => count($item['goods']),
'start_time' => date('Y-m-d H:i:s', $item['start_time']),
'end_time' => date('Y-m-d H:i:s', $item['end_time'])
];
}
$more = is_more($result['total'], $page, $size); //是否有下一页
return [
'list' => $data,
'count' => $result['total'],
'page_no' => $page,
'page_size' => $size,
'more' => $more
];
}
}
+797
View File
@@ -0,0 +1,797 @@
<?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\api\cache\TokenCache;
use app\api\model\User;
use app\api\server\UserServer;
use app\common\logic\AccountLogLogic;
use app\common\model\AccountLog;
use app\common\model\NoticeSetting;
use app\common\model\UserAuth;
use app\common\model\UserLevel;
use app\common\server\FileServer;
use app\common\server\WeChatServer;
use app\common\logic\LogicBase;
use app\common\model\Client_;
use app\common\server\ConfigServer;
use app\common\server\UrlServer;
use EasyWeChat\Factory;
use EasyWeChat\Kernel\Exceptions\Exception;
use Requests;
use think\Db;
use think\facade\Config;
use think\facade\Cache;
use think\facade\Hook;
class LoginLogic extends LogicBase
{
public static function register($post){
$client =Client_::mnp;
switch ($post['client']){
case 2:
$client = Client_::oa;
break;
case 3:
$client = Client_::ios;
break;
case 4:
$client = Client_::android;
break;
case 5:
$client = Client_::pc;
break;
case 6:
$client = Client_::h5;
break;
}
$time = time();
$salt = substr(md5($time . $post['mobile']), 0, 4);//随机4位密码盐
$password = create_password($post['password'], $salt);//生成密码
$user_data = [
'avatar' => ConfigServer::get('website', 'user_image'),
'sn' => create_user_sn(),
'mobile' => $post['mobile'],
'salt' => $salt,
'password' => $password,
'create_time' => $time,
'distribution_code' => generate_invite_code(),//分销邀请码
'is_distribution' => DistributionLogic::isDistributionMember(),//是否为分销会员
];
$user_data['nickname'] = '用户'.$user_data['sn'];
$user = new User();
$user->save($user_data);
$token = self::createSession($user->id, $client);
//生成会员分销扩展表
DistributionLogic::createUserDistribution($user->id);
// 生成分销会员基础表
\app\common\logic\DistributionLogic::add($user->id);
//注册赠送
self::registerAward($user->id);
//消息通知
Hook::listen('notice', [
'user_id' => $user->id,
'scene' => NoticeSetting::REGISTER_SUCCESS_NOTICE,
]);
return $token;
}
/**
* User: 意象信息科技 lr
* Desc: 小程序登录
* @param $post
* @return array|\PDOStatement|string|\think\Model|null
* @throws Exception
* @throws \EasyWeChat\Kernel\Exceptions\DecryptException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public static function mnpLogin($post)
{
//微信调用
try {
$config = WeChatServer::getMnpConfig();
$app = Factory::miniProgram($config);
$response = $app->auth->session($post['code']);
if (!isset($response['openid']) || empty($response['openid'])) {
throw new Exception('获取openID失败');
}
} catch (Exception $e) {
return self::dataError('登录失败:' . $e->getMessage());
}catch (\think\Exception $e){
return self::dataError('登录失败:' . $e->getMessage());
}
//添加或更新用户
$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');
if (empty($user_id)) {
$user_info = UserServer::createUser($response, Client_::mnp);
} else {
$user_info = UserServer::updateUser($response, Client_::mnp, $user_id);
}
if ($user_info['disable']) {
return self::dataError('账号已被禁用');
}
if (empty($user_info)) {
return self::dataError('登录失败:user');
}
//创建会话
$user_info['token'] = self::createSession($user_info['id'], Client_::mnp);
unset($user_info['id']);
unset($user_info['disable']);
return self::dataSuccess('登录成功', $user_info);
}
/**
* 获取code的url
* @param $url
* @return string
*/
public static function codeUrl($url)
{
$config = WeChatServer::getOaConfig();
$app = Factory::officialAccount($config);
$response = $app
->oauth
->scopes(['snsapi_userinfo'])
->redirect($url)
->getTargetUrl();
return $response;
}
/**
* User: 意象信息科技 lr
* Desc: 微信公众号登录
* @param $post
* @return array|\PDOStatement|string|\think\Model|null
* @throws Exception
* @throws \EasyWeChat\Kernel\Exceptions\DecryptException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public static function oaLogin($post)
{
//微信调用
try {
$config = WeChatServer::getOaConfig();
$app = Factory::officialAccount($config);
$response = $app
->oauth
->scopes(['snsapi_userinfo'])
->getAccessToken($post['code']);
if (!isset($response['openid']) || empty($response['openid'])) {
throw new Exception();
}
$user = $app->oauth->user($response);
$user = $user->getOriginal();
} catch (Exception $e) {
return self::dataError('登录失败:' . $e->getMessage());
}catch (\think\Exception $e){
return self::dataError('登录失败:' . $e->getMessage());
}
//添加或更新用户
$user_id = Db::name('user_auth au')
->join('user u', 'au.user_id=u.id')
->where(['u.del' => 0])
->where(function ($query) use ($user) {
$query->whereOr(['au.openid' => $user['openid']]);
if(isset($user['unionid']) && !empty($user['unionid'])){
$query->whereOr(['au.unionid' => $user['unionid']]);
}
})
->value('user_id');
if (empty($user_id)) {
$user_info = UserServer::createUser($user, Client_::oa);
} else {
$user_info = UserServer::updateUser($user, Client_::oa, $user_id);
}
if (empty($user_info)) {
return self::dataError('登录失败:user');
}
if ($user_info['disable']) {
return self::dataError('账号已被禁用');
}
//创建会话
$user_info['token'] = self::createSession($user_info['id'], Client_::oa);
unset($user_info['id']);
unset($user_info['disable']);
return self::dataSuccess('登录成功', $user_info);
}
/**
* User: 意象信息科技 lr
* Desc: 微信第三方app登录
* @param $post
* @return array|\PDOStatement|string|\think\Model|null
* @throws Exception
* @throws \EasyWeChat\Kernel\Exceptions\DecryptException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public static function opLogin($post)
{
//微信调用
try {
$config = WeChatServer::getOpConfig();
$app = Factory::officialAccount($config);
$response = $app
->oauth
->scopes(['snsapi_userinfo'])
->getAccessToken($post['code']);
$app->access_token->setToken($response->offsetGet('access_token'));
//sdk不支持app登录,直接调用微信接口
$requests = Requests::get('https://api.weixin.qq.com/sns/userinfo?openid=' . 'openid=' . $response->offsetGet('openid') . '&access_token=' . $response->offsetGet('access_token')
);
$user = json_decode($requests->body, true);
} catch (Exception $e) {
return self::dataError('登录失败:' . $e->getMessage());
}catch (\think\Exception $e){
return self::dataError('登录失败:' . $e->getMessage());
}
//添加或更新用户
$user_id = Db::name('user_auth au')
->join('user u', 'au.user_id=u.id')
->where(['u.del' => 0])
->where(function ($query) use ($user) {
$query->whereOr(['au.openid' => $user['openid']])
->whereOr(['au.unionid' => $user['unionid']]);
})
->value('user_id');
if (empty($user_id)) {
$user_info = UserServer::createUser($user, $post['client']);
} else {
$user_info = UserServer::updateUser($user, $post['client'], $user_id);
}
if (empty($user_info)) {
return self::dataError('登录失败:user');
}
if ($user_info['disable']) {
return self::dataError('账号已被禁用');
}
//创建会话
$user_info['token'] = self::createSession($user_info['id'], $post['client']);
unset($user_info['id']);
unset($user_info['disable']);
return self::dataSuccess('登录成功', $user_info);
}
/**
* app登录
* @param $post
* @return array|\PDOStatement|string|\think\Model|null
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public static function login($post)
{
$user_info = Db::name('user')
->field(['id', 'nickname', 'avatar', 'level', 'disable', 'distribution_code'])
->where(['account|mobile' => $post['account']])
->find();
$user_info['token'] = self::createSession($user_info['id'], $post['client']);
if (empty($user_info['avatar'])) {
$user_info['avatar'] = UrlServer::getFileUrl(ConfigServer::get('website', 'user_image'));
} else {
$user_info['avatar'] = UrlServer::getFileUrl($user_info['avatar']);
}
return $user_info;
}
/**
* 退出登录
* @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 logout($user_id, $client)
{
return self::expirationSession($user_id, $client);
}
/**
* 设置会话过期
* @param $user_id
* @param $client
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
public static function expirationSession($user_id, $client)
{
$time = time();
$token = Db::name('session')
->where(['user_id' => $user_id, 'client' => $client])
->value('token');
$token_cache = new TokenCache($token);
$token_cache->del();
return Db::name('session')
->where(['user_id' => $user_id, 'client' => $client])
->update(['update_time' => $time, 'expire_time' => $time]);
}
/**
* 创建会话
* @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;
}
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){
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: uniApp微信登录
* @param $post
* @author 段誉(2021/3/16 16:17)
* @return array
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public static function uinAppLogin($post)
{
//微信调用
try {
if (empty($post['openid']) || empty($post['access_token']) || empty($post['client'])){
throw new \think\Exception('参数缺失');
}
//sdk不支持app登录,直接调用微信接口
$requests = Requests::get('https://api.weixin.qq.com/sns/userinfo?openid=' . 'openid=' . $post['openid'] . '&access_token=' . $post['access_token']);
$user = json_decode($requests->body, true);
} catch (Exception $e) {
return self::dataError('登录失败:' . $e->getMessage());
}catch (\think\Exception $e){
return self::dataError('登录失败:' . $e->getMessage());
}
//添加或更新用户
$user_id = Db::name('user_auth au')
->join('user u', 'au.user_id=u.id')
->where(['u.del' => 0])
->where(function ($query) use ($user) {
$query->whereOr(['au.openid' => $user['openid']])
->whereOr(['au.unionid' => $user['unionid']]);
})
->value('user_id');
if (empty($user_id)) {
$user_info = UserServer::createUser($user, $post['client']);
} else {
$user_info = UserServer::updateUser($user, $post['client'], $user_id);
}
//验证用户信息
$check_res = self::checkUserInfo($user_info);
if (true !== $check_res) {
return self::dataError($check_res);
}
//创建会话
$user_info['token'] = self::createSession($user_info['id'], $post['client']);
unset($user_info['id']);
unset($user_info['disable']);
return self::dataSuccess('登录成功', $user_info);
}
/**
* 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;
}
/**
* 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();
$app = Factory::miniProgram($config);
$response = $app->auth->session($post['code']);
if (!isset($response['openid']) || empty($response['openid'])) {
throw new Exception('获取openID失败');
}
return $response;
}
/**
* Notes: 检车用户信息
* @param $user_info
* @author 段誉(2021/4/19 16:54)
* @return bool|string
*/
public static function checkUserInfo($user_info)
{
if (empty($user_info)) {
return '登录失败:user';
}
if ($user_info['disable']) {
return '账号已被禁用';
}
return true;
}
/**
* Notes: 旧用户登录
* @param $post
* @author 段誉(2021/4/19 16:57)
* @return array
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public static function silentLogin($post)
{
try {
//通过code获取微信 openid
$response = self::getWechatResByCode($post);
//通过获取到的openID或unionid获取当前 系统 用户id
$user_id = self::getUserByWechatResponse($response);
} catch (Exception $e) {
return self::dataError('登录失败:' . $e->getMessage());
} catch (\think\Exception $e) {
return self::dataError('登录失败:' . $e->getMessage());
}
if (empty($user_id)) {
//系统中没有用户-调用authlogin接口生成新用户
return self::dataSuccess('', []);
} else {
$user_info = UserServer::updateUser($response, Client_::mnp, $user_id);
}
//验证用户信息
$check_res = self::checkUserInfo($user_info);
if (true !== $check_res) {
return self::dataError($check_res);
}
//创建会话
$user_info['token'] = self::createSession($user_info['id'], Client_::mnp);
unset($user_info['id'], $user_info['disable']);
return self::dataSuccess('登录成功', $user_info);
}
/**
* Notes: 新用户登录
* @param $post
* @author 段誉(2021/4/19 16:57)
* @return array
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
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) {
return self::dataError('登录失败:' . $e->getMessage());
} catch (\think\Exception $e) {
return self::dataError('登录失败:' . $e->getMessage());
}
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::dataError($check_res);
}
//创建会话
$user_info['token'] = self::createSession($user_info['id'], Client_::mnp);
unset($user_info['id'], $user_info['disable']);
return self::dataSuccess('登录成功', $user_info);
}
/**
* @notes 更新用户头像昵称
* @param $post
* @param $user_id
* @return array
* @throws \think\Exception
* @throws \think\exception\PDOException
* @author ljj
* @date 2023/2/1 3:45 下午
*/
public static function updateUser($post,$user_id)
{
// $user = Db::name('user')->where(['id'=>$user_id])->find();
// if ($user['is_new_user'] == 0) {
// return self::dataError('非新用户无法使用此接口更新用户信息');
// }
Db::name('user')->where(['id'=>$user_id])->update(['nickname'=>$post['nickname'],'avatar'=>UrlServer::setFileUrl($post['avatar']),'is_new_user'=>0]);
return self::dataSuccess('操作成功');
}
/**
* @notes 小程序端绑定微信
* @param array $params
* @return bool
* @author lbzy
* @datetime 2023-11-29 10:57:29
*/
public function mnpAuthLogin(array $params)
{
try {
//通过code获取微信openid
$config = WeChatServer::getMnpConfig();
$app = Factory::miniProgram($config);
$response = $app->auth->session($params['code']);
if (empty($response['openid'])) {
throw new Exception('获取openID失败');
}
$userAuth = UserAuth::where('openid', $response['openid'])->findOrEmpty();
if (isset($userAuth['id'])) {
if ($userAuth['user_id'] == $params['user_id']) {
return true;
}
throw new \Exception('该微信已绑定其他用户');
}
UserAuth::create([
'user_id' => $params['user_id'],
'openid' => $response['openid'],
'create_time' => time(),
'unionid' => $response['unionid'] ?? '',
'client' => Client_::mnp,
]);
return true;
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 公众号端绑定微信
* @param array $params
* @return bool
* @author lbzy
* @datetime 2023-11-29 10:57:24
*/
public function oaAuthLogin(array $params)
{
try {
//通过code获取微信openid
$config = WeChatServer::getOaConfig();
$app = Factory::officialAccount($config);
$response = $app
->oauth
->scopes(['snsapi_userinfo'])
->getAccessToken($params['code']);
if (empty($response['openid'])) {
throw new Exception();
}
$userAuth = UserAuth::where('openid', $response['openid'])->findOrEmpty();
if (isset($userAuth['id'])) {
if ($userAuth['user_id'] == $params['user_id']) {
return true;
}
throw new \Exception('该微信已绑定其他用户');
}
UserAuth::create([
'user_id' => $params['user_id'],
'openid' => $response['openid'],
'create_time' => time(),
'unionid' => $response['unionid'] ?? '',
'client' => Client_::oa,
]);
return true;
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
}
@@ -0,0 +1,134 @@
<?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\model\Client_;
use app\common\logic\LogicBase;
use think\Db;
use think\facade\Config;
class LoginPasswordLogic extends LogicBase
{
// 手机+密码登录
public static function check($post)
{
$client = Client_::mnp;
if (isset($post['client']) && $post['client'] == 1) {
$client = Client_::mnp;
} elseif (isset($post['client']) && $post['client'] == 2) {
$client = Client_::oa;
} elseif (isset($post['client']) && $post['client'] == 3) {
$client = Client_::ios;
} elseif (isset($post['client']) && $post['client'] == 4) {
$client = Client_::android;
}
$account = db::name('user')
->where(['mobile' => $post['mobile'], 'del' => 0])
->find();
$salt = $account['salt'];
$password = create_password($post['password'], $salt);//生成密码
if ($password == $account['password'] && $account) {
//创建会话
$user_info['token'] = LoginLogic::createSession($account['id'], $client);
return self::dataSuccess('登录成功', $user_info);
} elseif (!$account) {
return self::dataError('账号不存在');
} elseif ($password != $account['password']) {
return self::dataError('密码不正确');
}
return false;
}
//todo 手机+验证码登录
public static function checkCode($post)
{
$client = Client_::mnp;
if (isset($post['client']) && $post['client'] == 1) {
$client = Client_::mnp;
} elseif (isset($post['client']) && $post['client'] == 2) {
$client = Client_::oa;
} elseif (isset($post['client']) && $post['client'] == 3) {
$client = Client_::ios;
} elseif (isset($post['client']) && $post['client'] == 4) {
$client = Client_::android;
}
$account = db::name('user')
->where(['mobile' => $post['mobile'], 'del' => 0])
->find();
//验证码
if ($account) {
$user_info['token'] = LoginLogic::createSession($account['id'], $client);
return self::dataSuccess('登录成功', $user_info);
} elseif (!$account) {
return self::dataError('账号不存在');
}
return false;
}
//忘记密码
public static function forget($post)
{
$client = self::getClient($post);
$account = Db::name('user')
->where(['mobile' => $post['mobile'], 'del' => 0])
->find();
if (!$account) {
return self::dataError('账号不存在');
}
//更新密码
$password = create_password($post['password'], $account['salt']);//生成密码
if ($account['password'] == $password) {
return self::dataError('密码未改动');
}
$data = [
'password' => $password,
'update_time' => time(),
];
Db::name('user')
->where(['id' => $account['id'], 'del' => 0])
->update($data);
$token = LoginLogic::createSession($account['id'], $client);
return self::dataSuccess('修改成功', ['token' => $token]);
}
public static function getClient($post)
{
$client = $post['client'] ?? Client_::mnp;
$client_arr = array_keys(Client_::getClient(true));
if (in_array($client, $client_arr)) {
return $client;
}
return Client_::mnp;
}
}
@@ -0,0 +1,453 @@
<?php
namespace app\api\logic;
use app\api\model\Coupon;
use app\common\logic\AccountLogLogic;
use app\common\model\AccountLog;
use app\common\model\Luckdraw;
use app\common\model\LuckdrawRecord;
use app\common\model\User;
use app\common\server\ConfigServer;
use app\common\server\UrlServer;
use think\Db;
use think\helper\Time;
class LuckdrawLogic
{
protected static $error; //错误信息
/**
* Notes: 错误错误信息
* @author 张无忌(2021/1/12 16:01)
* @return mixed
*/
public static function getError()
{
return self::$error;
}
/**
* Notes: 获取抽奖的奖品
* @author 张无忌(2021/1/26 15:12)
* @param $user_id
* @return array
*/
public static function getPrize($user_id)
{
$where = [
['is_delete', '=', 0],
['status', '=', 1]
];
// 获取配置信息
$config = [
'need' => ConfigServer::get('luckdraw', 'need', 0),
'limit' => ConfigServer::get('luckdraw', 'limit', 0),
'status' => ConfigServer::get('luckdraw', 'status', ''),
'rule' => ConfigServer::get('luckdraw', 'rule', 0),
'show_win' => ConfigServer::get('luckdraw', 'show_win', 0)
];
// 计算用户剩余抽奖次数
list($startDay, $endDay) = Time::today();
$recordCount = LuckdrawRecord::where([
['user_id', '=', $user_id],
['create_time', '>=', $startDay],
['create_time', '<', $endDay]
])->count('id');
$surplus = $config['limit'] - $recordCount;
$surplus = $surplus <= 0 ? 0 : $surplus;
// 获取历史抽奖记录列表
$record = LuckdrawRecord::order('id', 'desc')
->where('prize_type', '<>', Luckdraw::PRIZE_NOT_WIN)
->with('user')
->append(['prize_name'])
->limit(20)->select();
$recordData = [];
foreach ($record as $item) {
$nickname = self::hideStar($item['user']['nickname']);
$recordData[] = [
'id' => $item['id'],
'text' => '恭喜'.$nickname.'抽中了'.Luckdraw::getPrizeNameDesc($item['prize_type'], $item['number']),
'create_time' => $item['create_time'],
];
}
$model = new Luckdraw();
$lists = $model->field('id,prize_type,name,image,number')
->order(['sort'=>'desc'])
->where($where)->limit(8)
->select();
foreach ($lists as &$item) {
$item['url'] = $item['image'] ? UrlServer::getFileUrl($item['image']) : '';
if ($item['prize_type'] == 1) {
$item['name'] = $item['number'].$item['name'];
}
unset($item['image']);
unset($item['prize_type']);
}
$prizeData = [];
for ($i=0; $i<8; $i++) {
if (!empty($lists[$i])) {
if ($i == 4) {
$prizeData[] = ['name' => self::getPrizeBtn($config['need'])];
}
$prizeData[] = $lists[$i];
} else {
$prizeData[] = json_decode("{}");
}
}
$user = User::findOrEmpty($user_id);
return [
'user_integral' => $user['user_integral'],
'config' => $config,
'surplus' => $surplus,
'record' => $recordData,
'list' => $prizeData
];
}
/**
* Notes: 获取用户抽奖记录
* @param $user_id
* @param $page
* @param $size
* @author 张无忌(2021/1/26 16:13)
* @return array
*/
public static function getUserRecord($user_id, $page, $size)
{
$count = LuckdrawRecord::where(['user_id'=>(int)$user_id])->count();
$record = LuckdrawRecord::order('id', 'desc')
->where(['user_id'=>(int)$user_id])
->order('id', 'desc')
->page($page, $size)
->select();
foreach ($record as &$item) {
$item['prize_image'] = $item['prize_image'] ? UrlServer::getFileUrl($item['prize_image']) : '';
$item['send_tips'] = !$item['is_send'] && $item['prize_type'] != Luckdraw::PRIZE_NOT_WIN ? '自动领取失败,请联系客服人员' : '';
$item['need_tips'] = !empty($item['need_integral']) ? '-'.$item['need_integral'].'积分': '';
}
return [
'list' => $record,
'count' => $count,
'page_no' => $page,
'page_size' => $size,
'more' => is_more($count, $page, $size)
];
}
/**
* Notes: 抽奖逻辑开始
* @author 张无忌(2021/1/26 17:00)
* @param $user_id
* @return array|bool
*/
public static function draw($user_id)
{
Db::startTrans();
try {
// 每次抽奖需要消耗积分
$need = ConfigServer::get('luckdraw', 'need', 0);
// 扣减积分
if ($need > 0) {
User::where(['id' => $user_id])->setDec('user_integral', $need);
AccountLogLogic::AccountRecord(
$user_id, $need, 2,
AccountLog::luck_draw_dec_integral,
AccountLog::getAcccountDesc(AccountLog::luck_draw_dec_integral)
);
}
// 中奖奖品
$inPrize = self::randomLottery();
// 分析奖品类型,如(积分,优惠券,余额等),给用户增加对应获得的奖品
$sendPrizeInfo = self::sendPrize($inPrize, $user_id);
// 记录获得奖品信息
LuckdrawRecord::create([
'user_id' => $user_id,
'prize_id' => $inPrize['id'],
'prize_type' => $inPrize['prize_type'],
'prize_name' => $inPrize['name'],
'prize_image' => $inPrize['image'],
'number' => $inPrize['number'],
'is_send' => $sendPrizeInfo['flag'] ? 1 : 0,
'remark' => $sendPrizeInfo['tips'] ?? '',
'need_integral' => $need,
'create_time' => time(),
]);
Db::commit();
$text = '恭喜您获得' . Luckdraw::getPrizeNameDesc($inPrize['prize_type'], $inPrize['number']);
// 返回抽奖结果
return [
'id' => $inPrize['id'],
'name' => $inPrize['name'],
'image' => UrlServer::getFileUrl($inPrize['image']),
'number' => $inPrize['number'],
'text' => $text,
'create_time' => date('Y-m-d H:i:s', time()),
'error' => $sendPrizeInfo['flag'] ? '' : '自动领取失败,请联系客服'
];
} catch (\Exception $e) {
Db::rollback();
static::$error = $e->getMessage();
return false;
}
}
/**
* Notes: 取出中奖的奖品
* @param $prize_arr
* @author 张无忌(2021/1/26 18:37)
* @return int|mixed
*/
public static function getPrizeRange($prize_arr)
{
$rid = 0; //中奖的产品ID
$weight = 0; //中奖几率 (所有商品累计)
foreach ($prize_arr as $val) {
$weight += $val['probability']; //概率数组的总概率精度
}
shuffle($prize_arr);
foreach ($prize_arr as $key => $value) {
$randNum = mt_rand(1, $weight);
if ($randNum <= $value['probability']) { // 1 2 3 200
$rid = $value['id'];
break;
} else {
$weight -= $value['probability'];
}
}
return $rid; //中奖项
}
// 截取字符串
private static function hideStar($str)
{
if (mb_strlen($str) >= 3) {
return '**' . mb_substr($str, 2);
}
if (mb_strlen($str) == 1) {
return '**' . $str;
}
if (mb_strlen($str) == 2) {
return '**' . mb_substr($str, 1);
}
return $str;
}
/**
* @notes 随机抽奖
* @return array|mixed
* @author 段誉
* @date 2022/2/15 18:11
*/
public static function randomLottery()
{
// 获取正在进行抽奖的商品 (倒叙获取 8个 与api接口保持一致)
$model = new Luckdraw();
$prize = $model->field('id,prize_type,name,image,number,probability')
->order(['sort'=>'desc'])
->where(['is_delete'=>0, 'status'=>1])->limit(8)
->select()->toArray();
// 获得中奖ID
$rid = self::getPrizeRange($prize);
// 根据ID获得中奖信息
$inPrize = [];
foreach ($prize as $item) {
if ($item['id'] == $rid) {
$inPrize = $item;
break;
}
}
return $inPrize;
}
/**
* @notes 发送奖品
* @param $inPrize
* @param $user_id
* @return array
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @author 段誉
* @date 2022/2/15 17:45
*/
public static function sendPrize($inPrize, $user_id)
{
$flag = true;
$tips = '发奖成功';
// 中奖积分
if ($inPrize['prize_type'] == Luckdraw::PRIZE_INTEGRAL) {
User::where(['id' => $user_id])->setInc('user_integral', $inPrize['number']);
AccountLogLogic::AccountRecord(
$user_id, $inPrize['number'], 1,
AccountLog::luck_draw_integral,
AccountLog::getAcccountDesc(AccountLog::luck_draw_integral)
);
}
// 中奖余额
if ($inPrize['prize_type'] == Luckdraw::PRIZE_BALANCE) {
User::where(['id' => $user_id])->setInc('user_money', $inPrize['number']);
AccountLogLogic::AccountRecord(
$user_id, $inPrize['number'], 1,
AccountLog::luck_draw_inc_balance,
AccountLog::getAcccountDesc(AccountLog::luck_draw_inc_balance)
);
}
// 中奖优惠券
if ($inPrize['prize_type'] == Luckdraw::PRIZE_COUPON) {
$coupon = Coupon::findOrEmpty($inPrize['number'])->toArray();
$res = self::sendCoupon($user_id, $coupon);
if (true !== $res) {
$flag = false;
$tips = $res;
}
}
return ['flag' => $flag, 'tips' => $tips];
}
/**
* @notes 发送优惠券奖品
* @param $user_id
* @param $coupon
* @return bool|string
* @author 段誉
* @date 2022/2/15 17:45
*/
public static function sendCoupon($user_id, $coupon)
{
if ($coupon['status'] == 0) {
return '优惠券已失效,不能发放';
}
// send_total_type 发送总量类型:1-不限制;2-限制张数
if ($coupon['send_total_type'] == 2) {
if ($coupon['send_total'] < 1) {
return '优惠券发放总数量,超出库存数量,不能发放';
} else {
Coupon::update(['send_total' => ['dec', 1]], ['id' => $coupon['id']]);
}
}
// 指定用户发放
Db::name('coupon_list')->insert([
'user_id' => $user_id,
'coupon_id' => $coupon['id'],
'status' => 0,
'coupon_code' => create_coupon_code(),
'create_time' => time(),
]);
return true;
}
/**
* @notes 抽奖按钮
* @param $need_integral
* @return string
* @author 段誉
* @date 2022/2/15 18:47
*/
public static function getPrizeBtn($need_integral)
{
$btn = '开始抽奖';
if ($need_integral > 0) {
$btn = '消耗' . $need_integral . '积分';
}
return $btn;
}
/**
* @notes 中奖列表
* @param $params
* @param $page
* @param $size
* @return array
* @author 段誉
* @date 2022/2/17 15:23
*/
public static function getWinList($page, $size)
{
$where = [
['prize_type', '<>', Luckdraw::PRIZE_NOT_WIN],
];
$count = LuckdrawRecord::where($where)->count();
$lists = LuckdrawRecord::where($where)
->order('id', 'desc')
->page($page, $size)
->select()
->toArray();
foreach ($lists as &$item) {
$item['title'] = self::formatTitleWin($item);
$item['prize_image'] = !empty($item['prize_image']) ? UrlServer::getFileUrl($item['prize_image']) : '';
}
$data = [
'list' => $lists,
'count' => $count,
'page_no' => $page,
'page_size' => $size,
'more' => is_more($count, $page, $size)
];
return $data;
}
/**
* @notes 格式化中奖名单标题
* @param $item
* @return string
* @author 段誉
* @date 2022/2/17 15:23
*/
private static function formatTitleWin($item)
{
$title = "恭喜";
$userName = User::where('id', $item['user_id'])->value('nickname');
// 隐私处理
$userName = '**' . mb_substr($userName, -1 , 1);
$title .= $userName . '抽中了';
if ($item['prize_type'] == Luckdraw::PRIZE_INTEGRAL) {
$title .= $item['number'] . '积分';
}
if ($item['prize_type'] == Luckdraw::PRIZE_COUPON) {
$couponName = Coupon::where('id', $item['number'])->value('name');
$title .= empty($couponName) ? '优惠券' : $couponName;
}
if ($item['prize_type'] == Luckdraw::PRIZE_BALANCE) {
$title .= $item['number'] . '元';
}
return $title;
}
}
@@ -0,0 +1,63 @@
<?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\model\Menu_;
use app\common\model\SelffetchVerifier;
use app\common\server\ConfigServer;
use app\common\server\UrlServer;
use think\Db;
class MenuLogic
{
public static function getMenu($type,$user_info)
{
$list = Db::name('menu_decorate')
->where(['decorate_type' => $type, 'del' => 0, 'is_show' => 1])
->field('name,image,link_type,link_address')
->order('sort desc')
->select();
$menu_list = [];
$is_open = ConfigServer::get('distribution', 'is_open', 1);
foreach ($list as $key => $menu) {
//未登录时不显示核销订单入口,登陆用户非核销员时不显示核销订单入口
if (($menu['link_address'] == Menu_::centre_writeoff_order && empty($user_info)) || ($menu['link_address'] == Menu_::centre_writeoff_order && !empty($user_info) && empty(SelffetchVerifier::where(['user_id'=>$user_info['id'],'status'=>1,'del'=>0])->select()->toArray()))) {
continue;
}
$menu_content = Menu_::getMenuContent($type, $menu['link_address']);
if ($menu_content && !$is_open && 2 === $menu_content['menu_type']) {
continue;
}
//处理图标
$menu_list[] = [
'name' => $menu['name'],
'image' => UrlServer::getFileUrl($menu['image']),
'link' => $menu_content['link'] ?? $menu['link_address'],
'is_tab' => $menu_content['is_tab'] ?? '',
'link_type' => $menu_content['link_type'] ?? $menu['link_type'],
];
}
return $menu_list;
}
}
File diff suppressed because it is too large Load Diff
+308
View File
@@ -0,0 +1,308 @@
<?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\api\model\Goods;
use app\common\model\Ad;
use app\common\model\GoodsBrand;
use app\common\server\ConfigServer;
use app\common\server\UrlServer;
use think\Db;
class PcLogic{
/**
* Notes:pc端首页接口
* @return array
* @author: 2021/3/5 12:02
*/
public static function pcLists(){
$goods = new Goods();
//热销榜单
$host_list = $goods
->where(['del'=>0,'status'=>1])
->field('id,name,image,min_price as price,market_price,sales_sum+virtual_sales_sum as sales_sum')
->order('sales_sum desc,click_count desc')
->limit(10)
->select();
//新品推荐
$new_list = $goods
->where(['del'=>0,'status'=>1,'is_new'=>1])
->field('id,name,image,min_price as price,market_price,sales_sum+virtual_sales_sum as sales_sum')
->order('id desc,sort desc')
->limit(10)
->select();
//好物优选
$best_list = $goods
->where(['del'=>0,'status'=>1,'is_best'=>1])
->field('id,name,image,min_price as price,market_price,sales_sum+virtual_sales_sum as sales_sum')
->order('id desc,sort desc')
->limit(10)
->select();
$ad_list = Db::name('ad a')
->join('ad_position ap', 'a.pid = ap.id')
->where(['pid' =>[18,19,20,21],'a.status' => 1,'a.del' => 0,'ap.status' => 1,'ap.del' => 0])
->order('a.id desc')
->field('a.*')
->select();
$host_ad = []; //热销榜单广告
$new_ad = []; //新品推荐广告
$best_ad = []; //好物优选广告
$category_ad = []; //分类广告
foreach ($ad_list as $ad){
$url = $ad['link'];
$is_tab = 0;
$params = [];
switch ($ad['link_type']) {
case 1:
$page = Ad::getLinkPage($ad['client'], $ad['link']);
$url = $page['path'];
$is_tab = $page['is_tab'] ?? 0;
break;
case 2:
$goods_path = Ad::getGoodsPath($ad['client']);
$url = $goods_path;
$params = [
'id' => $ad['link'],
];
break;
}
//首页热销榜单广告
if(empty($host_ad) && 18 == $ad['pid']){
$host_ad = [
'image' => UrlServer::getFileUrl($ad['image']),
'link' => $url,
'link_type' => $ad['link_type'],
'params' => $params,
'is_tab' => $is_tab,
];
}
//首页新品推荐广告
if(empty($new_ad) && 19 == $ad['pid']){
$new_ad = [
'image' => UrlServer::getFileUrl($ad['image']),
'link' => $url,
'link_type' => $ad['link_type'],
'params' => $params,
'is_tab' => $is_tab,
];
}
//首页好物优选广告
if(empty($best_ad) && 20 == $ad['pid']){
$best_ad = [
'image' => UrlServer::getFileUrl($ad['image']),
'link' => $url,
'link_type' => $ad['link_type'],
'params' => $params,
'is_tab' => $is_tab,
];
}
//首页分类广告
if(21 == $ad['pid']){
$category_ad[$ad['category_id']] = [
'image' => UrlServer::getFileUrl($ad['image']),
'link' => $url,
'link_type' => $ad['link_type'],
'params' => $params,
'is_tab' => $is_tab,
];
}
}
//分类信息
$goods_category = new \app\admin\model\GoodsCategory();
$goods_category_list = $goods_category
->where(['del'=>0, 'level'=>1,'is_recommend'=>1])
->with(['sons'])
->field('id,name')
->select();
$category_list = [];
foreach ($goods_category_list as $key => $goods_category){
$sons = [];
$goods_list = $goods
->where(['first_category_id'=>$goods_category['id'],'del'=>0,'status'=>1])
->field('id,name,image,min_price as price,market_price,sales_sum+virtual_sales_sum as sales_sum')
->limit(8)
->select();
foreach ($goods_category['sons'] as $son){
$sons[] = [
'id' => $son['id'],
'name' => $son['name'],
];
}
$ad = $category_ad[$goods_category['id']] ?? [];
$category_list[] = [
'id' => $goods_category['id'],
'name' => $goods_category['name'],
'ad' => $ad,
'sons' => $sons,
'goods_list'=> $goods_list,
];
}
$list = [
'host_ad' => $host_ad,
'host_list' => $host_list,
'new_ad' => $new_ad,
'new_list' => $new_list,
'best_ad' => $best_ad,
'best_list' => $best_list,
'category_list' => $category_list,
];
return $list;
}
/**
* Notes:pc端获取公共数据
* @param $user_id int 用户id
* @return array
* @author: 2021/3/5 17:47
*/
public static function commonData($user_id){
$article = Db::name('article')
->where(['del'=>0,'is_notice'=>1,'is_show'=>1])
->order('create_time desc')
->field('id,title')
->limit(3)
->select();
$cart_num = 0;
$coupon_num = 0;
$nickname = '';
if($user_id){
$cart_num = Db::name('cart')->where(['user_id'=>$user_id])->sum('goods_num');
$coupon_num = Db::name('coupon_list')->where(['user_id'=>$user_id,'del'=>0,'status'=>0])->count();
$nickname = Db::name('user')->where(['id'=>$user_id])->value('nickname');
}
return [
'article' => $article,
'logo' => UrlServer::getFileUrl(ConfigServer::get('website', 'pc_logo')),
'name' => ConfigServer::get('website', 'name',''),
'cart_num' => $cart_num,
'coupon_num' => $coupon_num,
'nickname' => $nickname,
'oa_qr_code' => UrlServer::getFileUrl(ConfigServer::get('oa', 'qr_code', '')),
'mnp_qr_code' => UrlServer::getFileUrl(ConfigServer::get('mnp', 'qr_code', '')),
];
}
/**
* Notes:获取商品列表
* @param $page int 页码
* @param $size int 每页数量
* @param $name string 商品名称
* @param $category_id int 分类id
* @param $type int 类型:1-热销榜单;2-新品推荐;3-好物优选
* @param $sort_type string 筛选类型:sales_sum-销量筛选;price-价格筛选
* @param $sort string 排序方式:desc-降序;asc-升序
* @return array
* @author: 2021/3/6 9:57
*/
public static function goodsList($page,$size,$name,$category_id,$type,$sort_type,$sort){
$where[] = ['del','=',0];
$where[] = ['status','=',1];
//按商品名称搜索
if($name){
// 优先查品牌 然后再查询商品
$band_ids = GoodsBrand::where('is_show', 1)->where('name', 'like', "%{$name}%")->column('id');
if ($band_ids) {
$where[] = function ($query) use($band_ids, $name) {
$query->where('brand_id', 'in', $band_ids)->whereOr('name', 'like', "%{$name}%");
};
} else {
$where[] = [ 'name', 'like', "%{$name}%" ];
}
}
//按商品分类搜索
if($category_id){
$where[] = ['first_category_id|second_category_id|third_category_id','=',$category_id];
}
//按类型筛选
if(1 != $type){
switch ($type){
case 2:
$where[] = ['is_new','=',1];
break;
case 3:
$where[] = ['is_best','=',1];
break;
}
}
//按排序条件显示
$order = [];
if($sort_type && $sort){
$order = [$sort_type=>$sort];
}
$goods = new Goods();
$count = $goods
->where($where)
->count();
$list = $goods
->where($where)
->field('id,name,image,min_price as price,market_price,sales_sum+virtual_sales_sum as sales_sum')
->order($order)
->page($page, $size)
->select();
$more = is_more($count, $page, $size); //是否有下一页
return [
'list' => $list,
'page' => $page,
'size' => $size,
'count' => $count,
'more' => $more
];
}
/**
* Notes:修改用户信息
* @param $post array 用户信息
* @return int|string
* @throws \think\Exception
* @throws \think\exception\PDOException
* @author: 2021/3/8 19:07
*/
public static function changeUserInfo($post){
$data = [
'nickname' => $post['nickname'],
'sex' => $post['sex'],
'update_time' => time(),
];
return Db::name('user')->where(['id'=>$post['user_id']])->update($data);
}
}
@@ -0,0 +1,53 @@
<?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\server\UrlServer;
use app\common\server\ConfigServer;
class PolicyLogic
{
public static function service()
{
$service = ConfigServer::get('policy', 'service', '');
$preg = '/<img.*?src="((?!(https|http)).*?)".*?\/?>/i';
$local_url = UrlServer::getFileUrl();
$res = preg_replace($preg, '<img src="' . $local_url . '${1}" />', $service);
return $res;
}
public static function privacy()
{
$privacy = ConfigServer::get('policy', 'privacy', '');
$preg = '/<img.*?src="((?!(https|http)).*?)".*?\/?>/i';
$local_url = UrlServer::getFileUrl();
$res = preg_replace($preg, '<img src="' . $local_url . '${1}" />', $privacy);
return $res;
}
public static function afterSale()
{
$after_sale = ConfigServer::get('policy', 'after_sale', '');
$preg = '/<img.*?src="((?!(https|http)).*?)".*?\/?>/i';
$local_url = UrlServer::getFileUrl();
$res = preg_replace($preg, '<img src="' . $local_url . '${1}" />', $after_sale);
return $res;
}
}
@@ -0,0 +1,138 @@
<?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\model\Pay;
use app\common\server\ConfigServer;
use think\Db;
class RechargeLogic{
public static function getTemplate(){
$list = Db::name('recharge_template')
->where(['del'=>0])
->order('sort desc')
->field('id,money,give_money,is_recommend')
->select();
foreach ($list as &$item){
$item['tips'] = '';
if($item['give_money'] > 0){
$item['tips'] = '充'.intval($item['money']).'赠送'.intval($item['give_money']).'元';
}
}
return $list;
}
public static function recharge($user_id,$client,$post){
$give_integral= ConfigServer::get('recharge', 'give_integral', 0);
$give_growth = ConfigServer::get('recharge', 'give_growth', 0);
//选择运费模板
if(isset($post['id'])){
$template = Db::name('recharge_template')
->where(['del'=>0,'id'=>$post['id']])
->field('id,money,give_money')
->find();
$money = $template['money'];
$give_money = $template['give_money'];
}else{//自定义充值金额
$template = Db::name('recharge_template')
->where(['del'=>0,'money'=>$post['money']])
->field('id,money,give_money')
->find();
$money = $post['money'];
$give_money = 0;
if($template){
$money = $template['money'];
$give_money = $template['give_money'];
}
}
//赠送的积分和成长值
$integral = $money * $give_integral;
$growth = $money * $give_growth;
$integral = $integral > 0 ? intval($integral) : 0;
$growth = $growth > 0 ? intval($growth) : 0;
$add_order = [
'user_id' => $user_id,
'order_sn' => createSn('recharge_order','order_sn'),
'order_amount' => $money,
'order_source' => $client,
'pay_status' => Pay::UNPAID, //待支付状态;
'pay_way' => $post['pay_way'] ?? 1,
'template_id' => $template['id'] ?? 0,
'give_money' => $give_money,
'give_integral' => $integral,
'give_growth' => $growth,
'create_time' => time(),
];
$id = Db::name('recharge_order')->insertGetId($add_order);
if($id){
return Db::name('recharge_order')->where(['id'=>$id])->field('id,order_sn,give_integral,give_growth')->find();
}
return [];
}
/**
* 充值记录
*/
public static function rechargeRecord($get)
{
$list = Db::name('recharge_order')
->field('order_sn, order_amount, give_money, create_time')
->where([
'user_id' => $get['user_id'],
'pay_status' => 1
])
->order('create_time', 'desc')
->page($get['page_no'], $get['page_size'])
->select();
$count = Db::name('recharge_order')
->where([
'user_id' => $get['user_id'],
'pay_status' => 1
])
->count();
foreach($list as &$item) {
$item['create_time'] = date('Y-m-d h:i:s', $item['create_time']);
if($item['give_money'] > 0) {
$item['desc'] = '充值'. $item['order_amount'] . '赠送' . $item['give_money'];
}else{
$item['desc'] = '充值'. $item['order_amount'];
}
$item['total'] = $item['order_amount'] + $item['give_money']; // 充值金额 + 赠送金额
}
$result = [
'count' => $count,
'list' => $list,
'more' => is_more($count, $get['page_no'], $get['page_size']),
'count' => $count,
'page_no' => $get['page_no'],
'page_size' => $get['page_size']
];
return $result;
}
}
@@ -0,0 +1,43 @@
<?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 think\Db;
use think\facade\Cache;
class RegionLogic
{
public static function lists()
{
$cache = Cache::get('dev_region_tree');
if ($cache) {
return $cache;
} else {
$lists = Db::name('dev_region')
->field('id as value,parent_id as pid,name as label')
->select();
$lists = linear_to_tree($lists, 'children', 'value');
Cache::set('dev_region_tree', $lists);
return $lists;
}
}
}
@@ -0,0 +1,134 @@
<?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\server\ConfigServer;
use app\common\server\UrlServer;
use think\Db;
class SeckillLogic{
public static function seckillTime(){
$time_list = Db::name('seckill_time')
->where(['del'=>0])
->order('start_time asc')
->field('id,start_time,end_time')
->select();
$now = time();
foreach ($time_list as &$item){
$item['status'] = 2;
$item['tips'] = '';
$start_time = strtotime(date('Y-m-d'.$item['start_time']));
$end_time = strtotime(date('Y-m-d'.$item['end_time']));
if($now >= $end_time ){
$item['tips'] = '已结束';
}
if($start_time <= $now && $now < $end_time){
$item['status'] = 1;
$item['tips'] = '抢购中';
}
if($start_time >= $now){
$item['tips'] = '未开始';
$item['status'] = 0;
}
}
return $time_list;
}
public static function seckillGoods($id,$page,$size){
$where[] = ['g.del','=',0];
$where[] = ['sg.del','=',0];
$where[] = ['g.status','=',1];
$where[] = ['sg.seckill_id','=',$id];
$goods_count = Db::name('goods g')
->join('seckill_goods sg','g.id = sg.goods_id')
->group('sg.goods_id')
->order('sg.sales_sum desc')
->where($where)
->count();
$goods_list = Db::name('goods g')
->join('seckill_goods sg','g.id = sg.goods_id')
->where($where)
->group('sg.goods_id')
->order('sg.sales_sum,sg.id desc')
->page($page,$size)
->field('g.id,g.name,g.image,g.min_price,sg.price as seckill_price,sg.sales_sum')
->select();
$default_image = UrlServer::getFileUrl(ConfigServer::get('website', 'goods_image', ''));
foreach ($goods_list as &$item){
// 传入默认商品主图
if(empty( $item['image'])) {
$item['image'] = $default_image;
}else{
$item['image'] = UrlServer::getFileUrl($item['image']);
}
}
$more = is_more($goods_count,$page,$size); //是否有下一页
$data = [
'list' => $goods_list,
'page' => $page,
'size' => $size,
'count' => $goods_count,
'more' => $more
];
return $data;
}
//获取当前的秒杀时段
public static function getSeckill(){
$seckill_time = Db::name('seckill_time')
->where(['del'=>0])
->order('start_time asc')
->field('id,start_time,end_time')
->select();
$seckill = [];
$now = time();
foreach ($seckill_time as $item){
$start_time = strtotime(date('Y-m-d'.$item['start_time']));
$end_time = strtotime(date('Y-m-d'.$item['end_time']));
if($start_time <= $now && $now < $end_time){
$item['end_time'] = $end_time;
$seckill = $item;
break;
}
}
return $seckill;
}
//获取当前的秒杀信息和秒杀商品
public static function getSeckillGoods(){
$seckill = self::getSeckill();
$seckill_goods = [];
if($seckill){
$seckill_goods = Db::name('seckill_goods')
->where(['seckill_id'=>$seckill['id'],'del'=>0])
->column('id as seckill_goods_id,price,goods_id','item_id');
}
return ['seckill'=>$seckill,'seckill_goods'=>$seckill_goods];
}
}
@@ -0,0 +1,83 @@
<?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\model\SelffetchShop;
use app\common\server\ConfigServer;
class SelffetchShopLogic
{
/**
* @notes 查看自提门店列表
* @param $params
* @param $page
* @param $size
* @return array
* @author ljj
* @date 2021/8/24 4:58 下午
*/
public static function lists($params, $page, $size)
{
$longitude = $params['longitude'];
$latitude = $params['latitude'];
$distance = "round((6378.138*2*asin(sqrt(pow(sin(( {$latitude} *pi()/180-latitude*pi()/180)/2),2)+cos( {$latitude} *pi()/180)*cos(latitude*pi()/180)* pow(sin(( {$longitude} *pi()/180-longitude*pi()/180)/2),2)))*1000))/1000";
$count = SelffetchShop::field(['id' => 'id', 'name' => 'name', $distance => 'distance','mobile' => 'mobile', 'business_start_time' => 'business_start_time','business_end_time' => 'business_end_time','province' => 'province','city' => 'city','district' => 'district','address' => 'address','longitude' => 'longitude','latitude' => 'latitude'])->where(['del'=>0,'status'=>1])->count();
$lists = SelffetchShop::field(['id' => 'id', 'name' => 'name', $distance => 'distance','mobile' => 'mobile', 'business_start_time' => 'business_start_time','business_end_time' => 'business_end_time','province' => 'province','city' => 'city','district' => 'district','address' => 'address','longitude' => 'longitude','latitude' => 'latitude'])
->append(['shop_address'])
->hidden(['province','city','district','address'])
->where(['del'=>0,'status'=>1])
->order(['distance' => 'asc'])
->page($page, $size)
->select();
foreach ($lists as &$item) {
$item['distance'] = round($item['distance'], 2) . 'km';
$item['business_status'] = 1;
// if (strtotime($item['business_start_time']) <= time() && strtotime($item['business_end_time']) >= time()) {
// $item['business_status'] = 1;
// }
}
return [
'list' => $lists,
'count' => $count,
'page' => $page,
'size' => $size,
'more' => is_more($count, $page, $size)
];
}
/**
* @notes 获取地图密钥
* @return array
* @author 段誉
* @date 2022/1/17 14:29
*/
public static function getMapKey()
{
return [
'tx_map_key' => ConfigServer::get('map','tx_map_key',''),
];
}
}
@@ -0,0 +1,34 @@
<?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\server\ConfigServer;
use app\common\server\UrlServer;
class ServiceLogic{
public static function getConfig(){
$config = [
'wechat' => ConfigServer::get('service','wechat',''),
'phone' => ConfigServer::get('service','phone',''),
'time' => ConfigServer::get('service','time',''),
'image' => ConfigServer::get('service','image',''),
];
$config['image'] = UrlServer::getFileUrl($config['image']);
return $config;
}
}
+176
View File
@@ -0,0 +1,176 @@
<?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\LogicBase;
use app\common\logic\QrCodeLogic;
use app\common\model\Bargain;
use app\common\model\BargainLaunch;
use app\common\model\Client_;
use app\common\server\QrCodeServer;
use app\common\server\UrlServer;
use think\Db;
class ShareLogic extends LogicBase
{
//商品分销海报
public static function shareGoods($user_id, $goods_id, $url, $client)
{
$qr_code_logic = new QrCodeLogic();
$goods = Db::name('goods')->where(['id' => $goods_id])->find();
$result = '';
if ($goods) {
$user = Db::name('user')->where(['id' => $user_id])->find();
switch ($client) {
case Client_::mnp: //小程序
$url_type = 'path';
break;
case Client_::oa: //公众号.
case Client_::h5: //H5.
$url_type = 'url';
$url = url($url, '', '', true) . '?' . http_build_query(['id' => $goods_id, 'invite_code' => $user['distribution_code']]);
break;
case Client_::android:
case Client_::ios:
$url_type = 'url';
$url = url($url, '', '', true) . '?' . http_build_query(['id' => $goods_id, 'invite_code' => $user['distribution_code'], 'isapp' => 1]);
}
$result = $qr_code_logic->makeGoodsPoster($user, $goods, $url, $url_type);
}
return $result;
}
//获取用户分享海报
public static function getUserPoster($user_id, $url, $client)
{
//判断用户是否已有生成二维码分享海报
$user = Db::name('user')->where(['id' => $user_id])->find();
$url_type = 'url';
$invite_code_text = 'distribution_app_qr_code';
if ($client == Client_::mnp || $client == Client_::oa) {
if (empty($url)) {
return self::dataError('参数缺失');
}
}
switch ($client) {
case Client_::mnp:
$url_type = 'path';
$invite_code_text = 'distribution_mnp_qr_code';
$content = $url;
break;
case Client_::oa:
case Client_::h5:
$invite_code_text = 'distribution_h5_qr_code';
$url = request()->domain() . $url;
$content = $url . '?invite_code=' . $user['distribution_code'];
break;
case Client_::ios:
case Client_::android:
$content = url('index/index/app', '', '', true);
break;
default:
return self::dataError('系统错误');
}
$qr_code_logic = new QrCodeLogic();
$poster = $qr_code_logic->makeUserPoster($user, $content, $url_type, $client);
if ($poster['status'] != 1) {
return self::dataError($poster['msg']);
}
$poster_url = $poster['data'];
//更新user表
Db::name('user')->where(['id' => $user_id])->update([$invite_code_text => $poster_url]);
return self::dataSuccess('', ['url' => UrlServer::getFileUrl($poster_url)]);
}
//砍价分销海报
public static function shareBargain($user_id, $id, $url, $client)
{
$user = Db::name('user')->where(['id' => $user_id])->find();
switch ($client) {
case Client_::mnp: //小程序
$url_type = 'path';
break;
case Client_::h5: //H5.
case Client_::oa: //公众号.
$url_type = 'url';
$url = url($url, '', '', true) . '?' . 'id=' . $id;
break;
case Client_::android:
case Client_::ios:
$url_type = 'url';
$url = url($url, '', '', true) . '?' . http_build_query(['id' => $id, 'isapp' => 1]);
}
$bargain_launch = new BargainLaunch();
$bargain_launch = $bargain_launch->where(['id' => $id])->find()->toarray();
$qr_code_logic = new QrCodeLogic();
$result = $qr_code_logic->makeBargainPoster($user, $bargain_launch, $url, $url_type);
return $result;
}
/**
* @notes 获取小程序码
* @param int $user_id
* @param array $get
* @author cjhao
* @date 2021/11/25 10:52
*/
public static function getMnQrcode(int $user_id, array $get)
{
$type = $get['type'] ?? 0;
$scene = null;
$extra = [];
if(2 != $type) {
//用户分销码
$distribution_code = Db::name('user')->where(['id' => $user_id])->value('distribution_code');
$scene = 'invite_code='.$distribution_code;
if(1 == $type){
$scene .= '&id='.$get['id'];
}
} else {
$launch = BargainLaunch::where(['id'=>$get['id']])->value('bargain_id');
$extra = Bargain::where(['id' => $launch])
->field('share_title,share_intro')
->find()->toArray();
$scene = 'id='.$get['id'];
}
$param = [
'page' => $get['url'],
'scene' => $scene
];
return QrCodeServer::makeMpWechatQrcode($param,'base64', $extra);
}
}
+290
View File
@@ -0,0 +1,290 @@
<?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;
use app\common\server\UrlServer;
use think\Db;
use think\Exception;
use think\helper\Time;
use app\common\server\ConfigServer;
class SignLogic
{
/**
* note 每日签到
* create_time 2020/12/3 16:06
*/
public static function lists($user_id){
//用户信息
$user = Db::name('user')
->where(['id'=>$user_id])
->field('id,nickname,avatar,user_integral')
->find();
$user['avatar'] = UrlServer::getFileUrl($user['avatar']);
$user['today_sign'] = 0;
$today_sign = Db::name('user_sign')
->where(['del'=>0 , 'user_id'=>$user_id])
->whereTime('sign_time', 'today')
->find();
list($today_start,$today_end) = Time::today();
//今天是否已签到
$today_sign && $user['today_sign'] = 1;
//今天签到赠送的积分
$today_sign_integral = 0;
//昨天是否签到
$yester_sign = Db::name('user_sign')
->where(['del'=>0 , 'user_id'=>$user_id])
->whereTime('sign_time', 'yesterday')
->find();
//昨天没签到,则签到中断重新计算连续天数
if(!$yester_sign){
Db::name('user_sign')
->where(['del'=>0,'user_id'=>$user_id])
->where('sign_time','<',$today_start)
->update(['del'=> 1,'update_time'=>time()]);
}
//签到规则
$sign_list = Db::name('sign_daily')
->where(['del'=>0])
->order('type asc,days asc')
->column('*','days');
$sign_total_days = '';
$days_list = [];
if($sign_list){
$start_sign = current($sign_list); //第一次签到规则
$end_sign = end($sign_list); //最后一次签到规则
//每天赠送的积分
$everyday_send_integral = 0;
$start_sign['integral_status'] && $everyday_send_integral = $start_sign['integral'];
//累计签到的总天数
$sign_total_days = Db::name('user_sign')
->where(['del'=>0,'user_id'=>$user_id])
->order('id desc')
->value('days');
for($days = 1; $days <= $end_sign['days'] ;$days++){
$send_integral = $everyday_send_integral;
//连接签到赠送的积分
if(isset($sign_list[$days]) && $sign_list[$days]['integral_status'] ){
$send_integral = $everyday_send_integral + $sign_list[$days]['integral'];
}
//合并数据
$days_list[$days] = [
'days' => $days,
'status' => 0,
'integral' => $send_integral,
'growth' => 0,
];
$total_sin_days = $end_sign['days']; //可连续签到的最大天数
//更新签到天数之前的签到状态
if($days === $sign_total_days){
$today_sign_integral = $send_integral;//今天签到获得的积分
for ($sign_day = $days;$sign_day >= 1;$sign_day--){
$days_list[$sign_day]['status'] = 1;
}
}
//如果连续签到天数大于总天数,则全部标记为已签到状态
if($sign_total_days > $total_sin_days){
$days_list[$days]['status'] = 1;
}
}
}
$user['days'] = $sign_total_days ?: 0;
//赚积分
$make_inegral = [];
$make_inegral[] = [
'name' => '每日签到',
'status' => $user['today_sign'],
'integral' => $today_sign_integral,
'type' => 1,//类型,主要用前端显示图标
];
$order_award_integral = ConfigServer::get('marketing','order_award_integral',0);
$invited_award_integral = ConfigServer::get('marketing','invited_award_integral',0);
//下单奖励
if($order_award_integral > 0){
$today_order_award = Db::name('account_log')
->where(['user_id'=>$user_id,'source_type'=>AccountLog::order_add_integral])
->whereTime('create_time',[$today_start,$today_end])
->find();
$make_inegral[] = [
'name' => '下单任意商品',
'status' => $today_order_award ? 1 : 0,
'integral' => $order_award_integral,
'type' => 2,
];
}
//邀请奖励
if($invited_award_integral > 0){
$total_invited_award = Db::name('account_log')
->where(['user_id'=>$user_id,'source_type'=>AccountLog::invite_add_integral])
->whereTime('create_time',[$today_start,$today_end])
->find();
$make_inegral[] = [
'name' => '成功邀请1位好友',
'status' => $total_invited_award ? 1 : 0,
'integral' => $invited_award_integral,
'type' => 3,
];
}
return [
'user' => $user,
'sign_list' => array_values($days_list),
'make_inegral' => $make_inegral,
];
}
//签到接口
public static function sign($user_id){
try{
Db::startTrans();
$sign_list = Db::name('sign_daily')
->where(['del'=>0,'type'=>2])
->order('type asc,days asc')
->column('*','days');
//签到记录
$last_sign = Db::name('user_sign')
->where(['del'=>0,'user_id'=>$user_id])
->order('id desc')
->find();
$now = time();
$total_integral = 0; //签到赠送的积分
$total_growth = 0; //签到赠送的成长值
$continuous_integral = 0; //连续签到积分
$continuous_growth = 0; //连续签到成长值
$sign_day = 1; //累计签到天数
//每天签到的奖励
$everyday_sign = Db::name('sign_daily')
->where(['del'=>0,'type'=>1])
->find();
//有签到记录,说明之前有签到
if($last_sign){
$sign_day = $last_sign['days'] + 1;
$sign = $sign_list[$sign_day] ?? [];
//累计签到天数,额外奖励
if($sign){
if($sign['integral_status'] && $sign['integral'] > 0){
$total_integral+=$sign['integral'];
$continuous_integral = $sign['integral'];
}
if($sign['growth_status'] && $sign['growth'] > 0){
$total_growth+=$sign['growth'];
$continuous_growth =$sign['growth'];
}
}
//每天签到奖励
if($everyday_sign){
if($everyday_sign['integral_status'] && $everyday_sign['integral'] > 0){
$total_integral+=$everyday_sign['integral'];
}
if($everyday_sign && $everyday_sign['growth_status'] && $everyday_sign['growth'] > 0){
$total_growth+=$everyday_sign['growth'];
}
}
$sign_add = [
'user_id' => $user_id,
'days' => $sign_day,
'integral' => $everyday_sign['integral'],
'growth' => $everyday_sign['growth'],
'continuous_integral' => $continuous_integral,
'continuous_growth' => $continuous_growth,
'sign_time' => $now,
'create_time' => $now,
];
}else{
//连续一天的奖励
$one_day_sign = $sign_list['1'] ?? [];
if($one_day_sign){
if($one_day_sign['integral_status'] && $one_day_sign['integral'] > 0){
$total_integral+=$one_day_sign['integral'];
$continuous_integral = $one_day_sign['integral'];
}
if($one_day_sign && $one_day_sign['growth_status'] && $one_day_sign['growth'] > 0){
$total_growth+=$one_day_sign['growth'];
$continuous_growth = $one_day_sign['growth'];
}
}
if($everyday_sign){
if($everyday_sign['integral_status'] && $everyday_sign['integral'] > 0){
$total_integral+=$everyday_sign['integral'];
}
if($everyday_sign['growth_status'] && $everyday_sign['growth'] > 0){
$total_growth+=$everyday_sign['growth'];
}
}
$sign_add = [
'user_id' => $user_id,
'days' => $sign_day,
'integral' => $everyday_sign['integral_status'] ? $everyday_sign['integral'] : 0,
'continuous_integral' => $continuous_integral,
'growth' => $everyday_sign['growth_status'] ? $everyday_sign['growth'] : 0,
'continuous_growth' => $continuous_growth,
'sign_time' => $now,
'create_time' => $now,
];
}
Db::name('user_sign')->insert($sign_add);
if($total_integral){
Db::name('user')
->where(['del'=>0 , 'id'=>$user_id])
->setInc('user_integral',$total_integral);
AccountLogLogic::AccountRecord($user_id,$total_integral,1, AccountLog::sign_in_integral);
}
if($total_growth){
//用户成长值
Db::name('user')
->where(['del'=>0 , 'id'=>$user_id])
->setInc('user_growth',$total_growth);
AccountLogLogic::AccountRecord($user_id,$total_growth,1,AccountLog::sign_give_growth);
}
Db::commit();
return [
'integral' => $total_integral,
'growth' => $total_growth,
'days' => $sign_day,
];
}catch (Exception $e){
Db::rollback();
return $e->getMessage();
}
}
}
+44
View File
@@ -0,0 +1,44 @@
<?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\model\NoticeSetting;
use think\facade\Hook;
class SmsLogic{
public static function send($mobile,$key, $user_id = 0){
try{
$code = create_sms_code(4);
$send_data = [
'key' => NoticeSetting::SMS_SCENE[$key],
'mobile' => $mobile,
'params' => ['code'=>$code]
];
if (!empty($user_id)) {
$send_data['user_id'] = $user_id;
}
Hook::listen('sms_send',$send_data);
return true;
} catch (\Exception $e) {
return $e->getMessage();
}
}
}
@@ -0,0 +1,45 @@
<?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\model\NoticeSetting;
class SubscribeLogic
{
public static function lists($scene)
{
$where = [
['mnp_notice', '<>', ''],
['type', '=', 1]
];
$lists = NoticeSetting::where($where)->field('mnp_notice')->limit(3)->select()->toArray();
$template_id = [];
foreach ($lists as $item) {
if (isset($item['mnp_notice']['status']) && $item['mnp_notice']['status'] != 1) {
continue;
}
$template_id[] = $item['mnp_notice']['template_id'] ?? '';
}
return $template_id;
}
}
+556
View File
@@ -0,0 +1,556 @@
<?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\IntegralLogic;
use app\common\logic\LogicBase;
use app\common\logic\PayNotifyLogic;
use app\common\model\Client_;
use app\common\model\Goods;
use app\common\model\GoodsItem;
use app\common\model\Order;
use app\common\model\Order as CommonOrder;
use app\common\model\Pay;
use app\common\model\SelffetchShop;
use app\common\model\Team;
use app\common\model\TeamActivity;
use app\common\model\TeamFollow;
use app\common\model\TeamFound;
use app\common\model\TeamGoodsItem;
use app\common\model\User;
use app\common\server\ConfigServer;
use app\common\server\UrlServer;
use think\Db;
use think\Exception;
use think\facade\Hook;
use think\facade\Validate;
/**
* 拼团逻辑
* Class TeamLogic
* @package app\api\logic
*/
class TeamLogic extends LogicBase
{
private static $team_goods;
private static $team_id;
private static $goods_num;
private static $user_id;
private static $user;
private static $integral_switch;
private static $integral_config;
private static $integral_limit;
private static $team_found_id = 0;
private static $team_found = [];
private static $team_activity = [];
public static $error; //错误信息
/**
* Notes: 错误错误信息
* @author 张无忌(2021/1/12 16:01)
* @return mixed
*/
public static function getError()
{
return self::$error;
}
/**
* Notes: 获取拼团商品列表
* @param $page
* @param $size
* @author 张无忌(2021/1/14 11:39)
* @return TeamActivity[]|array
*/
public static function getTeamGoodsList($page, $size)
{
try {
$teamActivityModel = new TeamActivity();
$where = [
['t.del', '=', 0],
['t.status', '=', 1],
['t.end_time', '>', time()],
['g.del', '=', 0],
['g.status', '=', 1],
];
$count = $teamActivityModel->where($where)->alias('t')
->join('Goods g', 'g.id = t.goods_id')
->count();
$lists = $teamActivityModel->field('g.name,g.image,g.max_price,g.min_price,
t.team_id,t.goods_id,t.sales_sum,t.people_num,t.team_max_price,t.team_min_price,t.end_time,g.is_express,g.is_selffetch')
->where($where)->alias('t')
->join('Goods g', 'g.id = t.goods_id')
->page($page, $size)
->select();
foreach ($lists as &$item) {
$item['image'] = UrlServer::getFileUrl($item['image']);
}
return [
'list' => $lists,
'page_no' => $page,
'page_size' => $size,
'count' => $count,
'more' => is_more($count, $page, $size)
];
} catch (\Exception $e) {
static::$error = '获取拼团商品异常';
return [];
}
}
public static function setUser($user_id)
{
self::$user_id = $user_id;
self::$user = User::get($user_id);
}
public static function setTeamId($team_id)
{
self::$team_id = $team_id;
}
public static function setTeamGoodsItem($item_id)
{
$team_goods = new TeamGoodsItem();
$field = 'i.id as item_id,g.id as goods_id,g.name as goods_name,g.status,g.del,g.image,i.stock,
g.free_shipping_type,g.free_shipping,g.free_shipping_template_id,g.image, i.image as spec_image,
i.spec_value_str,i.spec_value_ids,i.price as item_price,i.image as spec_image,i.volume,
i.weight,g.third_category_id,i.price as original_price,tg.team_id,tg.team_price as goods_price,g.is_express,g.is_selffetch';
$goods = $team_goods->alias('tg')
->field($field)
->join('goods_item i', 'i.id = tg.item_id')
->join('goods g', 'g.id = i.goods_id')
->where(['item_id' => $item_id, 'tg.del' => 0, 'team_id' => self::$team_id])
->find();
$image_str = empty($goods['spec_image']) ? $goods['image'] : $goods['spec_image'];
$goods['image_str'] = UrlServer::getFileUrl($image_str);
$goods['discount_price'] = 0;
$goods['integral_price'] = 0;
self::$team_goods = $goods;
self::$team_activity = TeamActivity::where(['team_id' => self::$team_id])->find();
}
public static function setTeamGoodsNum($goods_num)
{
self::$goods_num = $goods_num;
}
public static function setTeamFound($found_id)
{
if ($found_id > 0){
self::$team_found_id = $found_id;
self::$team_found = TeamFound::get($found_id);
}
}
public static function setIntegralConfig()
{
self::$integral_switch = IntegralLogic::isIntegralInOrder(self::$team_goods) ? 1 : 0;
self::$integral_config = ConfigServer::get('marketing', 'integral_deduction_money', 0);
self::$integral_limit = ConfigServer::get('marketing', 'integral_deduction_limit', 0);
}
/**
* Desc: 拼团订单结算详情
* @param $post
* @param $user_id
* @return array
*/
public static function calculateInfo($post, $user_id)
{
try{
$found_id = $post['found_id'] ?? 0;
self::setTeamFound($found_id);
$goods = self::$team_goods;
$goods['goods_num'] = self::$goods_num;
$goods_lists[] = $goods;
$total_goods_price = self::$team_goods['goods_price'] * self::$goods_num;//商品总金额
//用户地址
$user_address = UserAddressLogic::getOrderUserAddress($post, $user_id);
//运费
$total_shipping_price = ($post['delivery_type'] == CommonOrder::DELIVERY_STATUS_SELF) ? 0 :FreightLogic::calculateFreight($goods_lists, $user_address);
//$total_shipping_price = FreightLogic::calculateFreight($goods_lists, $user_address);
//订单金额
$total_amount = $total_goods_price + $total_shipping_price;
//订单应付金额
$order_amount = $total_amount;
if ($order_amount <= 0){
$order_amount = 0;
}
$result = [
'order_type' => Order::TEAM_ORDER,
'goods_lists' => array_values($goods_lists),
'coupon_id' => $post['coupon_id'] ?? 0,
'total_num' => self::$goods_num,//订单总数量
'total_goods_price' => round($total_goods_price, 2),//订单商品总价
'total_amount' => round($total_amount, 2),//订单总价(商品价格,运费,优惠券等)
'order_amount' => round($order_amount, 2),//订单应付价格
'address' => $user_address,
'discount_amount' => 0,//优惠券抵扣金额
'integral_amount' => 0,//积分抵扣金额
'shipping_price' => round($total_shipping_price, 2),//运费
'remark' => $post['remark'] ?? '',
'pay_way' => $post['pay_way'] ?? Pay::WECHAT_PAY,
'user_money' => self::$user['user_money'],//用户余额
'user_use_integral' => 0,//用户使用积分
'user_integral' => self::$user['user_integral'],//用户拥有积分
'integral_limit' => self::$integral_limit,// 积分抵扣限制(满多少积分可用)
'integral_switch' => self::$integral_switch,//积分抵扣开关
'integral_config' => self::$integral_config,//积分抵扣配置
'team_need' => self::$team_activity['people_num'] ?? 0,//成团人数
];
return $result;
} catch (Exception $e){
static::$error = $e->getMessage();
return false;
}
}
/**
* Desc:添加拼团订单
* @param $user_id
* @param $order_data
* @param $client
* @return array
*/
public static function buy($user_id, $order_data, $post)
{
Db::startTrans();
try {
$client = $post['client'];
$goods_lists = $order_data['goods_lists'];
$user_address = $order_data['address'];
self::addTeamOrderCheck($order_data,$post);
if ($post['delivery_type'] == CommonOrder::DELIVERY_STATUS_SELF && empty($post['selffetch_shop_id'])) {
throw new Exception('自提门店不能为空');
}
// if (isset($post['selffetch_shop_id']) && !empty($post['selffetch_shop_id'])) {
// $selffetch_shop = SelffetchShop::find($post['selffetch_shop_id'])->toArray();
// if (strtotime($selffetch_shop['business_start_time']) > time() || strtotime($selffetch_shop['business_end_time']) < time()) {
// throw new Exception('不在门店营业时间,无法下单');
// }
// }
if ($post['delivery_type'] == CommonOrder::DELIVERY_STATUS_SELF && empty($post['consignee'])) {
throw new Exception('取货人不能为空');
}
if ($post['delivery_type'] == CommonOrder::DELIVERY_STATUS_SELF && empty($post['mobile'])) {
throw new Exception('联系电话不能为空');
}
if ($post['delivery_type'] == CommonOrder::DELIVERY_STATUS_SELF && !Validate::mobile($post['mobile'])) {
throw new Exception('联系电话格式不正确');
}
//验证订单商品是否支持对应的配送方式
$is_express = ConfigServer::get('delivery_type', 'is_express', 1);
$is_selffetch = ConfigServer::get('delivery_type', 'is_selffetch', 0);
$goods_id = GoodsItem::where('id','=', $post['item_id'])->value('goods_id');
$goods = Goods::where('id','=', $goods_id)->find()->toArray();
//门店自提
if ($post['delivery_type'] == CommonOrder::DELIVERY_STATUS_SELF) {
if ($is_selffetch == 0) {
throw new Exception('暂未开启门店自提配送方式');
}
if ($goods['is_selffetch'] == 0) {
throw new Exception('商品不支持门店自提!');
}
}elseif ($post['delivery_type'] == CommonOrder::DELIVERY_STATUS_EXPRESS) { //快递配送
if ($is_express == 0) {
throw new Exception('暂未开启快递配送方式');
}
if ($goods['is_express'] == 0) {
throw new Exception('商品不支持快递配送!');
}
}
$extra = [
'delivery_type'=>$post['delivery_type'],
'selffetch_shop_id'=>($post['delivery_type'] == CommonOrder::DELIVERY_STATUS_SELF) ? $post['selffetch_shop_id'] : '',
'consignee'=>($post['delivery_type'] == CommonOrder::DELIVERY_STATUS_SELF) ? $post['consignee'] : '',
'mobile'=>($post['delivery_type'] == CommonOrder::DELIVERY_STATUS_SELF) ? $post['mobile'] : '',
'found_id' => $post['found_id'] ?? 0,
'team_id' => $post['team_id'] ?? 0,
];
$order = OrderLogic::addOrder($user_id, $order_data, $client, $user_address, $extra);
$order_id = $order['order_id'];
OrderLogic::addOrderGoods($order_id, $goods_lists);
OrderLogic::addOrderAfter($order_id, $user_id, $type = '', $order_data);
Db::commit();
return ['order_id' => $order_id, 'type' => 'order'];
} catch (Exception $e) {
Db::rollback();
self::$error = $e->getMessage();
return false;
}
}
/**
* Desc: 开团或参团验证
* @param $order_data
* @throws Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public static function addTeamOrderCheck($order_data,$post)
{
// if (empty($order_data['address'])) {
// throw new Exception('请选择收货地址');
// }
if ($post['delivery_type'] != CommonOrder::DELIVERY_STATUS_SELF && empty($order_data['address'])) {
throw new Exception('请选择收货地址');
}
//余额支付,是否满足支付金额
if ($order_data['pay_way'] == Pay::BALANCE_PAY){
$user_money = self::$user['user_money'];
if($user_money < $order_data['order_amount']){
throw new Exception('账户余额不足');
}
}
//用户当前积分 - 用户使用的积分
if ($order_data['user_use_integral'] > 0){
if (self::$user['user_integral'] < $order_data['user_use_integral']){
throw new Exception('积分不足');
}
}
}
/**
* Desc: 参加拼团,做团员
* @param $order_id
* @param $found_id
* @param $user_id
* @param bool $is_found
* @throws Exception
*/
public static function addTeamFollow($order_id, $found_id, $user_id, $is_found = false)
{
$found = TeamFound::get($found_id);
$user = User::get($user_id);
$team_follow = new TeamFollow();
$follow_data = [
'follow_user_id' => $user_id,
'follow_user_nickname' => $user['nickname'],
'follow_user_avatar' => $user['avatar'],
'follow_time' => time(),
'order_id' => $order_id,
'found_id' => $found_id,
'team_id' => $found['team_id'],
'type' => $is_found ? 1 : 0,
];
$team_follow->insertGetId($follow_data);
TeamFound::where(['id' => $found_id])->setInc('join', 1);
}
/**
* User: 意象信息科技 mjf
* Desc: 开启新的拼团, 做团长
* @param $order_id
* @param $user_id
* @param $team_id
* @return int|string
*/
public static function addTeamFound($order_id, $user_id, $team_id)
{
$user = User::get($user_id);
$team_activity = TeamActivity::get(['team_id' => $team_id]);
$team_found = new TeamFound();
$found_data = [
'sn' => createSn('team_found', 'sn', '', 4),
'found_time' => time(),
'found_end_time' => time() + intval($team_activity['time_limit'] * 60 * 60),//time_limit 小时
'user_id' => $user_id,
'team_id' => $team_id,
'nickname' => $user['nickname'],
'avatar' => $user['avatar'],
'order_id' => $order_id,
'need' => $team_activity['people_num'],
];
return $team_found->insertGetId($found_data);
}
/**
* Desc: 已支付拼团订单后,更新拼团状态
* @param $order_id
* @throws Exception
*/
public static function updateTeam($order_id)
{
$order = Order::get($order_id);
$team_found = TeamFound::where(['id' => $order['team_found_id']])->find();
self::incTeamGoodsSale($order_id, $order['team_id']);
//订单中没有选中团
if($order['team_found_id'] <= 0){
//没有选中的团时,开通一个新团做团长
return self::openNewTeamFound($order, $order['team_id']);
}
//订单中已有选中团 -> 已满员
if ($team_found['join'] == $team_found['need']){
//没有位置, 找一个随机的团加入, 没有团则开一个新团做团长
$rand_found_id = self::unFinishedTeam($team_found['team_id']);
if ($rand_found_id === false){
//没有随机团,创建新团做团长
return self::openNewTeamFound($order, $team_found['team_id']);
}
//加入随机团
self::addTeamFollow($order_id, $rand_found_id, $order['user_id']);
self::updateTeamStatus($rand_found_id);
return $rand_found_id;
}
//订单中已有选中团 -> 加入团
self::addTeamFollow($order_id, $order['team_found_id'], $order['user_id']);
self::updateTeamStatus($order['team_found_id']);
return $order['team_found_id'];
}
/**
* Desc: 拼团商品增加销量
* @param $order_id
* @param $team_id
* @throws Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public static function incTeamGoodsSale($order_id, $team_id)
{
$order_goods = Db::name('order_goods')->where(['order_id' => $order_id])->find();
Db::name('team_activity')
->where(['goods_id' => $order_goods['goods_id'], 'team_id' => $team_id])
->setInc('sales_sum', $order_goods['goods_num']);
Db::name('team_goods_item')
->where(['team_id' => $team_id, 'item_id' => $order_goods['item_id']])
->setInc('sales_sum', $order_goods['goods_num']);
}
/**
* User: 意象信息科技 mjf
* Desc: 更新拼团参与状态
* @param $found_id
*/
public static function updateTeamStatus($found_id)
{
$found = TeamFound::get($found_id);
//人数凑齐,拼团成功
if ($found['join'] == $found['need']){
$found->status = Team::STATUS_SUCCESS;
$found->team_end_time = time();
$found->save();
TeamFollow::where(['found_id' => $found_id])->update(['status' => Team::STATUS_SUCCESS, 'team_end_time' => time()]);
}
}
/**
* Desc: 开一个新的团
* @param $order
* @param $team_id
* @throws Exception
*/
public static function openNewTeamFound($order, $team_id)
{
$found_id = self::addTeamFound($order['id'], $order['user_id'], $team_id);
self::addTeamFollow($order['id'], $found_id, $order['user_id'], true);
//更新订单关联拼团id
self::updateOrderTeamFound($order['id'], $found_id);
return $found_id;
}
/**
* User: 意象信息科技 mjf
* Desc: 更新订单关联拼团id
* @param $order_id
* @param $found_id
* @return int|string
* @throws Exception
* @throws \think\exception\PDOException
*/
public static function updateOrderTeamFound($order_id, $found_id)
{
return Db::name('order')->where(['id' => $order_id])->update(['team_found_id' => $found_id]);
}
/**
* Desc: 未成的团id
* @param $team_id
* @return bool
*/
public static function unFinishedTeam($team_id)
{
$founds = TeamFound::where(['status' => Team::STATUS_WAIT_SUCCESS, 'team_id' => $team_id])->column('id');
if (!$founds){
return false;
}
$key = array_rand($founds, 1);
return $founds[$key];
}
}
@@ -0,0 +1,340 @@
<?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\server\AreaServer;
use think\Db;
use think\Exception;
class UserAddressLogic
{
/**
* 获取用户地址信息
* @param $user_id
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public static function infoUserAddress($user_id){
$info = Db::name('user_address')
->where(['user_id'=>$user_id,'del'=>0])
->field('id,contact,telephone,province_id,city_id,district_id,address,is_default')
->select();
foreach ($info as &$item) {
$item['province'] = AreaServer::getAddress($item['province_id']);
$item['city'] = AreaServer::getAddress($item['city_id']);
$item['district'] = AreaServer::getAddress($item['district_id']);
}
return $info;
}
/**
* 获取一条地址信息
* @param $user_id
* @param $get
* @return array|\PDOStatement|string|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public static function getOneAddress($user_id,$get) {
$info = Db::name('user_address')
->where(['id'=>$get['id'],'user_id'=>$user_id,'del'=>0])
->field('id,contact,telephone,province_id,city_id,district_id,address,is_default')
->find();
$info['province'] = AreaServer::getAddress($info['province_id']);
$info['city'] = AreaServer::getAddress($info['city_id']);
$info['district'] = AreaServer::getAddress($info['district_id']);
return $info;
}
/**
* 获取默认地址
* @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 getDefaultAddress($user_id){
$info = Db::name('user_address')
->where(['is_default'=>1,'user_id'=>$user_id,'del'=>0])
->field('id,contact,telephone,province_id,city_id,district_id,address,is_default')
->find();
if (!$info){
return [];
}
$info['province'] = AreaServer::getAddress($info['province_id']);
$info['city'] = AreaServer::getAddress($info['city_id']);
$info['district'] = AreaServer::getAddress($info['district_id']);
return $info;
}
/**
* 设置默认地址
* @param $user_id
* @param $post
* @return int|string
*/
public static function setDefaultAddress($user_id,$post){
try {
Db::startTrans();
Db::name('user_address')
->where(['del'=> 0 ,'user_id'=>$user_id])
->update(['is_default'=>0]);
$result = Db::name('user_address')
->where(['id'=>$post['id'],'del'=> 0 ,'user_id'=>$user_id])
->update(['is_default'=>1]);
Db::commit();
} catch (Exception $e) {
Db::rollback();
return false;
}
return $result;
}
/**
* 添加收货地址
* @param $user_id
* @param $post
* @return int|string
*/
public static function addUserAddress($user_id,$post) {
try {
Db::startTrans();
if (isset($post['is_default']) && $post['is_default'] == 1){
Db::name('user_address')
->where(['del'=> 0 ,'user_id'=>$user_id])
->update(['is_default'=>0]);
}else{
$is_first = Db::name('user_address')
->where(['del'=> 0 ,'user_id'=>$user_id])
->find();
if (empty($is_first)){
$post['is_default'] = 1;
}
}
$data = [
'user_id' => $user_id,
'contact' => $post['contact'],
'telephone' => $post['telephone'],
'province_id' => $post['province_id'],
'city_id' => $post['city_id'],
'district_id' => $post['district_id'],
'address' => $post['address'],
'is_default' => $post['is_default'] ?? 0,
'create_time' => time()
];
$result = Db::name('user_address')->insert($data);
Db::commit();
} catch (Exception $e) {
Db::rollback();
return $e->getMessage();
}
return $result;
}
/**
* 编辑用户地址
* @param $user_id
* @param $post
* @return int|string
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
public static function editUserAddress($user_id,$post) {
try {
Db::startTrans();
if ($post['is_default'] == 1){
Db::name('user_address')
->where(['del'=> 0 ,'user_id'=>$user_id])
->update(['is_default'=>0]);
}
$data = [
'contact' => $post['contact'],
'telephone' => $post['telephone'],
'province_id' => $post['province_id'],
'city_id' => $post['city_id'],
'district_id' => $post['district_id'],
'address' => $post['address'],
'is_default' => $post['is_default'] ?? 0,
'update_time' => time()
];
$result = Db::name('user_address')
->where(['id'=>$post['id'],'del'=> 0 ,'user_id'=>$user_id])
->update($data);
Db::commit();
} catch (Exception $e) {
Db::rollback();
return false;
}
return $result;
}
/**
* 删除用户地址
* @param $user_id
* @param $post
* @return int|string
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
public static function delUserAddress($user_id,$post) {
$data = [
'del' => 1,
'update_time' => time()
];
return Db::name('user_address')
->where(['id'=>$post['id'],'del'=>0,'user_id'=>$user_id])
->update($data);
}
/**
* 获取省市区id
* @param $province
* @param $city
* @param $district
* @return array
*/
public static function handleRegion($province,$city,$district){
if (!$province || !$city || !$district){
return [];
}
$result = [];
$result['province'] = self::handleRegionField($province,1);
if (!$result['province']){
return [];
}
$result['city'] = self::handleRegionField($city,2);
$result['district'] = self::handleRegionField($district,3);
return $result;
}
/**
* 获取对应省,市,区的id
* @param $keyword
* @param int $level
* @return mixed|string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public static function handleRegionField($keyword, $level = 1){
$data = '';
$list = Db::name('dev_region')->where('level',$level)->select();
foreach ($list as $k => $v){
if ($keyword == $v['name']){
$data = $v['id'];
}
}
if (empty($data)) {
foreach ($list as $k => $v) {
if (strpos($v['name'], $keyword) !== false) {
$data = $v['id'];
}
}
if (empty($data)) {
foreach ($list as $v) {
if (strpos($keyword, $v['name']) !== false) {
$data = $v['id'];
}
}
}
}
return $data;
}
/**
* User: 意象信息科技 mjf
* Desc: 获取用户指定id的地址
* @param $address
* @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 getUserAddressById($address, $user_id)
{
$info = Db::name('user_address')
->where(['id' => $address, 'user_id' => $user_id, 'del' => 0])
->field('id,contact,telephone,province_id,city_id,district_id,address,is_default')
->find();
if (!$info) {
return [];
}
$info['province'] = AreaServer::getAddress($info['province_id']);
$info['city'] = AreaServer::getAddress($info['city_id']);
$info['district'] = AreaServer::getAddress($info['district_id']);
return $info;
}
//获取订单用户地址
/**
* User: 意象信息科技 mjf
* Desc: 获取下单时用户地址
* @param $data
* @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 getOrderUserAddress($data, $user_id)
{
if (isset($data['address_id']) && $data['address_id'] != 0){
return self::getUserAddressById($data['address_id'], $user_id);
}
return self::getDefaultAddress($user_id);
}
}
@@ -0,0 +1,139 @@
<?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 function AlibabaCloud\Client\value;
use app\common\server\ConfigServer;
use app\common\server\UrlServer;
use think\Db;
class UserLevelLogic{
/**
* note 会员等级
* create_time 2020/11/26 18:47
*/
public static function lists($id){
$user_level_list = Db::name('user_level')
->where(['del'=>0])
->order('growth_value asc')
->field('id,name,growth_value,image,background_image,privilege')
->select();
$user = Db::name('user')->where(['id'=>$id])->field('id,nickname,avatar,level,user_growth')->find();
$privilege_list = Db::name('user_privilege')->where(['del'=>0])->column('name,image','id');
$current_level_name = '';
$level_list = [];
$current_key = '';
foreach ($user_level_list as $key => $level){
$level_privilege = [];
$current_level_status = -1;
$current_growth_tips = '当前成长值 '.$user['user_growth'];
$image = UrlServer::getFileUrl($level['image']);
$background_image = UrlServer::getFileUrl($level['background_image']);
$diff_growth = $level['growth_value'] - $user['user_growth'] > 0 ? $level['growth_value'] - $user['user_growth'] :0;
$diff_growth_tips = '还需'.$diff_growth.'可升级';
$diff_growth_percent = 0;
//等级权益
if($level['privilege']){
$privileges = explode(',',$level['privilege']);
foreach ($privileges as $privilege){
$user_privilege = $privilege_list[$privilege] ?? [];
$user_privilege && $user_privilege['image'] = UrlServer::getFileUrl($user_privilege['image']);
$user_privilege && $level_privilege[] = $user_privilege;
}
}
//当前等级
if($user['level'] === $level['id']){
$current_level_name = $level['name'];
$current_level_status = 1;
$current_key = $key;
$diff_growth_tips = '';
//下个等级
$next_level = $user_level_list[$key+1] ?? [];
if($next_level){
$diff_growth_percent = round($user['user_growth'] / $next_level['growth_value'],2);
}
}
$level_list[] = [
'name' => $level['name'],
'current_level_status' => $current_level_status,
'current_growth_tips' => $current_growth_tips,
'image' => $image,
'background_image' => $background_image,
'diff_growth_tips' => $diff_growth_tips,
'level_privilege' => $level_privilege,
'diff_growth_percent' => $diff_growth_percent,
];
}
foreach ($level_list as $level_key => $list){
if($level_key >= $current_key){
break;
}
$level_list[$level_key]['current_level_status'] = 0;
$level_list[$level_key]['current_growth_tips'] = '';
$level_list[$level_key]['diff_growth_tips'] = '';
}
$sign_daily = Db::name('sign_daily')
->where(['del'=>0])
->order('type,days asc')
->select();
//成长值规则
$rule = '';
$give_growth = ConfigServer::get('recharge', 'give_growth', 0);
if($give_growth > 0){
$rule.='1.使用余额充值,每元赠送'.$give_growth."成长值。".PHP_EOL;
}
$rule .='2.';
foreach ($sign_daily as $sign){
if( 1 == $sign['type'] && 0 == $sign['days'] && $sign['growth_status'] && $sign['growth']){
$rule.= '会员每天签到,赠送' .$sign['growth']. "成长值;";
}
if( 2 == $sign['type'] && $sign['growth_status'] && $sign['growth']){
$rule.= '会员连续签到'.$sign['days'].'天,赠送'.$sign['growth']."成长值;";
}
}
$rule.= PHP_EOL;
//合并数据
$list = [
'user' => [
'nickname' => $user['nickname'],
'avatar' => UrlServer::getFileUrl($user['avatar']),
'level_name' => $current_level_name,
'user_growth' => $user['user_growth'],
],
'level_list' => $level_list,
'growth_rule' => $rule,
];
return $list;
}
}
+544
View File
@@ -0,0 +1,544 @@
<?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\api\model\User;
use app\common\logic\LogicBase;
use app\common\logic\NoticeLogic;
use app\common\model\AccountLog;
use app\common\model\AfterSale;
use app\common\model\Client_;
use app\common\model\DistributionOrder;
use app\common\model\Order;
use app\common\model\TeamFollow;
use app\common\model\UserAuth;
use app\common\server\ConfigServer;
use app\common\server\storage\Driver as StorageDriver;
use app\common\server\UrlServer;
use app\common\server\WeChatServer;
use EasyWeChat\Factory;
use EasyWeChat\Kernel\Exceptions\Exception;
use think\Db;
use app\common\logic\AccountLogLogic;
use think\facade\Cache;
class UserLogic extends LogicBase
{
public static function center($user_id)
{
$user = User::get($user_id);
//待支付
$user->wait_pay = Db::name('order')->where(['del' => 0, 'user_id' => $user_id, 'order_status' => Order::STATUS_WAIT_PAY, 'pay_status' => 0])->count();
//待发货
$user->wait_delivery = Db::name('order')->where(['del' => 0, 'user_id' => $user_id, 'order_status' => [Order::STATUS_WAIT_DELIVERY], 'pay_status' => 1])->count();
//待收货
$user->wait_take = Db::name('order')->where(['del' => 0, 'user_id' => $user_id, 'order_status' => [Order::STATUS_WAIT_RECEIVE], 'pay_status' => 1])->count();
//待评论
$user->wait_comment = Db::name('order o')
->join('order_goods og', 'o.id = og.order_id')
->where(['del' => 0, 'user_id' => $user_id, 'order_status' => Order::STATUS_FINISH, 'is_comment' => 0])
->count('og.id');
//售后中
$user->after_sale = Db::name('after_sale')
->where(['del' => 0, 'user_id' => $user_id])
->where('status', '<>', AfterSale::STATUS_SUCCESS_REFUND)
->count();
$user->coupon = Db::name('coupon_list')->where(['user_id' => $user_id, 'del' => 0, 'status' => 0])->count();
//分销开关
$user->distribution_setting = ConfigServer::get('distribution', 'is_open', 1);
//消息数量
$user->notice_num = NoticeLogic::unRead($user_id) ? 1 : 0;
//下个会员等级提示
$user_level = Db::name('user_level')
->where([
['growth_value', '>', $user->user_growth],
['del', '=', 0]
])->order('growth_value asc')
->find();
$user['next_level_tips'] = '';
if ($user_level) {
$diff_growth_value = intval($user_level['growth_value'] - $user['user_growth']);
$diff_growth_value > 0 && $user['next_level_tips'] = '距离升级还差' . $diff_growth_value;
}
// 是否设置支付密码
$user['hasPayPassword'] = $user['pay_password'] ? 1 : 0;
$user->visible(['id', 'nickname', 'sn', 'avatar', 'mobile', 'hasPayPassword', 'next_level_tips', 'user_money', 'total_order_amount', 'total_recharge_amount',
'coupon', 'user_integral', 'level', 'wait_pay', 'wait_take', 'wait_delivery',
'wait_comment', 'after_sale', 'distribution_setting', 'distribution_code', 'notice_num','is_new_user']);
return $user;
}
public static function accountLog($user_id, $source, $type, $page, $size)
{
$source_type = '';
$where[] = ['user_id', '=', $user_id];
switch ($source) {
case 1:
$source_type = AccountLog::money_change;
break;
case 2:
$source_type = AccountLog::integral_change;
break;
case 3:
$source_type = AccountLog::growth_change;
}
$where[] = ['source_type', 'in', $source_type];
if ($type) {
$where[] = ['change_type', '=', $type];
}
$accountLog = new AccountLog();
$count = $accountLog
->where($where)
->count();
$list = $accountLog
->where($where)
->page($page, $size)
->order('id desc')
->field('id,change_amount,source_type,change_type,create_time,remark')
->select();
$more = is_more($count, $page, $size); //是否有下一页
$data = [
'list' => $list,
'page_no' => $page,
'page_size' => $size,
'count' => $count,
'more' => $more
];
return $data;
}
//获取用户信息
public static function getUserInfo($user_id)
{
$info = User::where(['id' => $user_id])
->field('id,sn,nickname,avatar,mobile,sex,create_time')
->find();
$info['create_time'] = date('Y-m-d H:i:s', $info['create_time']);
$info['oa_auth'] = UserAuth::where('user_id', $user_id)->where(Client_::oa)->value('id') ? 1: 0;
$info['mnp_auth'] = UserAuth::where('user_id', $user_id)->where(Client_::mnp)->value('id') ? 1: 0;
return $info;
}
//设置个人信息
public static function setUserInfo($user_id, $data)
{
$field = $data['field'];
$value = $data['value'];
$res = Db::name('user')
->where(['id' => $user_id])
->update([$field => $value]);
return $res;
}
//修改手机号
public static function changeMobile($user_id, $data)
{
$user = User::get($user_id);
$user->mobile = $data['new_mobile'];
$user->save();
return $user;
}
//获取微信手机号
public static function getMobileByMnp($post)
{
Db::startTrans();
try {
$config = WeChatServer::getMnpConfig();
$app = Factory::miniProgram($config);
$response = $app->auth->session($post['code']);
if (!isset($response['session_key'])) {
throw new Exception();
}
$response = $app->encryptor->decryptData($response['session_key'], $post['iv'], $post['encrypted_data']);
$isExist = User::where([
['mobile', '=', $response['phoneNumber']],
['id', '<>', $post['user_id']]
])->find();
if (!empty($isExist)) {
throw new Exception('手机号已被其他账号绑定');
}
User::where(['id' => $post['user_id']])->update(['mobile' => $response['phoneNumber']]);
Db::commit();
return self::dataSuccess('操作成功');
} catch (Exception $e) {
Db::rollback();
return self::dataError('失败:' . $e->getMessage());
}
}
//我的粉丝列表
public static function fans($user_id, $get, $page, $size)
{
$where = [];
if (isset($get['keyword']) && $get['keyword'] != '') {
$where[] = ['nickname|mobile', 'like', '%' . $get['keyword'] . '%'];
}
//查询条件
$type = $get['type'] ?? 'all';
switch ($type) {
case 'first':
$where[] = ['first_leader', '=', $user_id];
break;
case 'second':
$where[] = ['second_leader', '=', $user_id];
break;
default:
$where[] = ['first_leader|second_leader', '=', $user_id];
}
$field = 'u.id, avatar, nickname, mobile, u.create_time, order_num as fans_order,
order_amount as fans_money, fans as fans_team';
$count = Db::name('user u')
->field($field)
->leftJoin('user_distribution d', 'd.user_id = u.id')
->where($where)
->count();
$lists = Db::name('user u')
->field($field)
->leftJoin('user_distribution d', 'd.user_id = u.id')
->where($where)
->page($page, $size)
->order(self::fansListsSort($get))
->select();
foreach ($lists as &$item) {
$item['avatar'] = UrlServer::getFileUrl($item['avatar']);
$item['fans_team'] = $item['fans_team'] ?? 0;
$item['fans_order'] = $item['fans_order'] ?? 0;
$item['fans_money'] = $item['fans_money'] ?? 0;
$item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
unset($item['fans'], $item['distribution_order_num'], $item['distribution_money']);
}
$data = [
'list' => $lists,
'page' => $page,
'size' => $size,
'count' => $count,
'more' => is_more($count, $page, $size)
];
return $data;
}
//粉丝列表排序
public static function fansListsSort($get)
{
if (isset($get['fans']) && $get['fans'] != '') {
return ['fans_team' => $get['fans'], 'u.id' => 'desc'];
}
if (isset($get['money']) && $get['money'] != '') {
return ['fans_money' => $get['money'], 'u.id' => 'desc'];
}
if (isset($get['order']) && $get['order'] != '') {
return ['fans_order' => $get['order'], 'u.id' => 'desc'];
}
return ['u.id' => 'desc'];
}
public static function myWallet($user_id)
{
$info = Db::name('user')
->where(['id' => $user_id])
->field('user_money,total_order_amount,total_recharge_amount,user_growth')
->find();
$info['open_racharge'] = ConfigServer::get('recharge', 'open_racharge', 0);
return $info;
}
public static function myTeam($user_id, $status, $page, $size)
{
$where = [
['follow_user_id', '=', (int)$user_id]
];
if ($status !== -1 and $status !== '-1') {
$where[] = ['f.status', '=', (int)$status];
}
$teamFollowModel = new TeamFollow();
$count = $teamFollowModel->where($where)->alias('f')->count();
$lists = $teamFollowModel->alias('f')
->field('g.name,g.image,gi.image as spec_image,gi.spec_value_str,gi.goods_id,og.goods_price,
o.total_amount,o.order_amount,o.total_num,o.pay_status,a.start_time,a.end_time,
tf.need,tf.found_time,tf.found_end_time,tf.team_end_time,f.follow_time,
f.id,f.order_id,f.type,f.status')
->where($where)
->order('id', 'desc')
->join('order o', 'o.id = f.order_id')
->join('order_goods og', 'og.order_id = o.id')
->join('goods g', 'g.id = og.goods_id')
->join('goods_item gi', 'gi.id = og.item_id')
->join('team_found tf', 'tf.id = f.found_id')
->join('team_activity a', 'a.team_id = f.team_id')
->page($page, $size)
->select();
$status_text = ['拼团中', '拼团成功', '拼团失败'];
foreach ($lists as &$item) {
$item['image'] = UrlServer::getFileUrl($item['image']);
$item['spec_image'] = $item['spec_image'] ? UrlServer::getFileUrl($item['spec_image']) : $item['image'];
$item['type_text'] = $item['type'] ? '团长' : '团员';
$item['status_text'] = $status_text[$item['status']];
$item['team_end_time'] = $item['team_end_time'] ? date('Y-m-d H:i:s', $item['team_end_time']) : '';
$item['follow_time'] = date('Y-m-d H:i:s', $item['follow_time']);
}
return [
'list' => $lists,
'page' => $page,
'size' => $size,
'count' => $count,
'more' => is_more($count, $page, $size)
];
}
//更新微信信息
public static function updateWechatInfo($user_id, $post)
{
Db::startTrans();
try {
$time = time();
$avatar_url = $post['avatar'];
$nickanme = $post['nickname'];
$sex = $post['sex'];
$config = [
'default' => ConfigServer::get('storage', 'default', 'local'),
'engine' => ConfigServer::get('storage_engine')
];
$avatar = ''; //头像路径
if ($config['default'] == 'local') {
$file_name = md5($user_id . $time . rand(10000, 99999)) . '.jpeg';
$avatar = download_file($avatar_url, 'uploads/user/avatar/', $file_name);
} else {
$avatar = 'uploads/user/avatar/' . md5($user_id . $time . rand(10000, 99999)) . '.jpeg';
$StorageDriver = new StorageDriver($config);
if (!$StorageDriver->fetch($avatar_url, $avatar)) {
throw new Exception('头像保存失败:' . $StorageDriver->getError());
}
}
$user = new User;
$user->save([
'nickname' => $nickanme,
'avatar' => $avatar,
'sex' => $sex
], ['id' => $user_id]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
return $e->getMessage();
}
}
/**
* 设置支付密码
*/
public static function setPassword($data)
{
return Db::name('user')->where('id', $data['user_id'])->update([
'pay_password' => $data['pay_password'],
'update_time' => time()
]);
}
/**
* 分销会员转账
*/
public static function transfer($data)
{
$lockKey = 'transfer_' . $data['user_id'];
if (Cache::get($lockKey)) {
self::$error = '操作频繁';
return false;
} else {
Cache::set($lockKey, $data['money'], 60);
}
Db::startTrans();
try {
$transferFrom = Db::name('user')->where('id', $data['user_id'])->find();
// 判断余额是否充足
if ($transferFrom['user_money'] < $data['money']) {
throw new \Exception('余额不足');
}
// 判断支付密码是否正确
if ($transferFrom['pay_password'] != md5(trim($data['pay_password']))) {
throw new \Exception('支付密码错误');
}
// 收款人是否存在
$transferTo = Db::name('user')->where('sn', $data['transferTo'])->find();
if (!$transferTo) {
$transferTo = Db::name('user')->where('mobile', $data['transferTo'])->find();
}
if (!$transferTo) {
throw new \Exception('收款用户不存在');
}
// 不能自己转账给自己
if ($transferFrom['id'] == $transferTo['id']) {
throw new \Exception('不能自己转账给自己');
}
// 生成转账记录
$transferId = Db::name('user_transfer')->insertGetId([
'transfer_sn' => createSn('user_transfer', 'transfer_sn'),
'transfer_from_id' => $transferFrom['id'],
'transfer_to_id' => $transferTo['id'],
'money' => $data['money'],
'create_time' => time()
]);
// 减 转账人 余额
Db::name('user')->where('id', $transferFrom['id'])->setDec('user_money', $data['money']);
// 记录 转账人 余额变动
AccountLogLogic::AccountRecord($transferFrom['id'], $data['money'], 2, AccountLog::user_transfer_dec_balance, '会员转账支出', $transferId);
// 加 收款人 余额
Db::name('user')->where('id', $transferTo['id'])->setInc('user_money', $data['money']);
// 记录 收款人 余额变动
AccountLogLogic::AccountRecord($transferTo['id'], $data['money'], 1, AccountLog::user_transfer_inc_balance, '会员转账收入', $transferId);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::$error = $e->getMessage();
return false;
} finally {
Cache::rm($lockKey);
}
}
/**
* 转账记录
*/
public static function transferRecord($get)
{
switch ($get['type']) {
case 'all': // 全部(用户信息单独获取)
$list = Db::name('user_transfer')
->where('transfer_from_id', $get['user_id'])
->whereOr('transfer_to_id', $get['user_id'])
->page($get['page_no'], $get['page_size'])
->order('create_time', 'desc')
->select();
$count = Db::name('user_transfer')
->where('transfer_from_id', $get['user_id'])
->whereOr('transfer_to_id', $get['user_id'])
->count();
break;
case 'in': // 收入
$list = Db::name('user_transfer')->alias('ut')
->field('ut.*, u.nickname, u.avatar, u.sn')
->leftJoin('user u', 'ut.transfer_from_id = u.id') // 转账人信息
->where('ut.transfer_to_id', $get['user_id'])
->page($get['page_no'], $get['page_size'])
->order('ut.create_time', 'desc')
->select();
$count = Db::name('user_transfer')
->where('transfer_to_id', $get['user_id'])
->count();
break;
case 'out': // 支出
$list = Db::name('user_transfer')->alias('ut')
->field('ut.*, u.nickname, u.avatar, u.sn')
->leftJoin('user u', 'ut.transfer_to_id = u.id') // 收款人信息
->where('ut.transfer_from_id', $get['user_id'])
->page($get['page_no'], $get['page_size'])
->order('ut.create_time', 'desc')
->select();
$count = Db::name('user_transfer')
->where('transfer_from_id', $get['user_id'])
->count();
break;
}
// 全部(获取用户信息)
if ($get['type'] == 'all') {
foreach ($list as &$item) {
if ($item['transfer_from_id'] == $get['user_id']) {
// 自己为转账人,需获得收款人信息
$user = Db::name('user')->where('id', $item['transfer_to_id'])->find();
$item['nickname'] = $user['nickname'] ?? '';
$item['avatar'] = $user['avatar'] ?? '';
$item['sn'] = $user['sn'] ?? '';
} else if ($item['transfer_to_id'] == $get['user_id']) {
// 自己为收款人,需获得转款人信息
$user = Db::name('user')->where('id', $item['transfer_from_id'])->find();
$item['nickname'] = $user['nickname'] ?? '';
$item['avatar'] = $user['avatar'] ?? '';
$item['sn'] = $user['sn'] ?? '';
}
}
}
// 格式化数据
foreach ($list as &$item) {
$item['avatar'] = UrlServer::getFileUrl($item['avatar']);
$item['create_time'] = date('Y-m-d h:i:s', $item['create_time']);
if ($item['transfer_from_id'] == $get['user_id']) {
$item['type'] = 0;
$item['typeDesc'] = '支出';
} else {
$item['type'] = 1;
$item['typeDesc'] = '收入';
}
}
$result = [
'count' => $count,
'list' => $list,
'more' => is_more($count, $get['page_no'], $get['page_size']),
'page_no' => $get['page_no'],
'page_size' => $get['page_size']
];
return $result;
}
}
@@ -0,0 +1,150 @@
<?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\model\WeChat;
use app\common\server\WeChatServer;
use EasyWeChat\Kernel\Exceptions\Exception;
use EasyWeChat\Kernel\Messages\Text;
use EasyWeChat\Factory;
use think\Db;
class WeChatLogic
{
/**
* 获取微信配置
* @param $url
* @return array|string
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public static function jsConfig($url)
{
$config = WeChatServer::getOaConfig();
$app = Factory::officialAccount($config);
$url = urldecode($url);
$app->jssdk->setUrl($url);
$apis = [
'onMenuShareTimeline',
'onMenuShareAppMessage',
'onMenuShareQQ',
'onMenuShareWeibo',
'onMenuShareQZone',
'openLocation',
'getLocation',
'chooseWXPay',
'updateAppMessageShareData',
'updateTimelineShareData',
'openAddress',
'scanQRCode'
];
try {
$data = $app->jssdk->getConfigArray($apis, $debug = false, $beta = false);
return data_success('', $data);
} catch (Exception $e) {
return data_error('公众号配置出错' . $e->getMessage());
}
}
public static function index($params)
{
if (isset($params['echostr'])) {
echo $params["echostr"];
exit;
}
//微信配置
$config = WeChatServer::getOaConfig();
$app = Factory::officialAccount($config);
$app->server->push(function ($message) {
switch ($message['MsgType']) {
case WeChat::msg_type_event: //关注事件
switch ($message['Event']) {
case WeChat::msg_event_subscribe:
$reply_content = Db::name('wechat_reply')
->where(['reply_type' => WeChat::msg_event_subscribe, 'status' => 1, 'del' => 0])
->value('content');
//关注回复空的话,找默认回复
if (empty($reply_content)) {
$reply_content = Db::name('wechat_reply')
->where(['reply_type' => WeChat::msg_type_default, 'status' => 1, 'del' => 0])
->value('content');
}
if ($reply_content) {
$text = new Text($reply_content);
return $text;
}
break;
case WeChat::msg_event_click: // 点击事件
$reply_content = Db::name('wechat_reply')->where([
'reply_type' => WeChat::msg_type_text,
'status' => 1,
'del' => 0,
'keyword' => $message['EventKey']
])->value('content');
if (!empty($reply_content)) {
$text = new Text($reply_content);
return $text;
}
break;
}
case WeChat::msg_type_text://消息类型
$reply_list = Db::name('wechat_reply')
->where(['reply_type' => WeChat::msg_type_text, 'status' => 1, 'del' => 0])
->order('sort asc')
->select();
$reply_content = '';
foreach ($reply_list as $reply) {
switch ($reply['matching_type']) {
case 1://全匹配
$reply['keyword'] === $message['Content'] && $reply_content = $reply['content'];
break;
case 2://模糊匹配
stripos($reply['keyword'], $message['Content']) !== false && $reply_content = $reply['content'];
break;
}
}
//消息回复为空的话,找默认回复
if (empty($reply_content)) {
$reply_content = Db::name('wechat_reply')
->where(['reply_type' => WeChat::msg_type_default, 'status' => 1, 'del' => 0])
->value('content');
}
if ($reply_content) {
$text = new Text($reply_content);
return $text;
}
break;
}
});
$response = $app->server->serve();
$response->send();
}
}
@@ -0,0 +1,163 @@
<?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, LogicBase};
use app\common\model\{AccountLog, User, Withdraw};
use app\common\server\ConfigServer;
use think\Db;
use think\Exception;
/**
* 提现
* Class WithdrawLogic
* @package app\api\logic
*/
class WithdrawLogic extends LogicBase
{
//基础配置
public static function config($user_id)
{
$user = Db::name('user')->where('id', $user_id)->find();
$config = [
'able_withdraw' => $user['earnings'],
'min_withdraw' => ConfigServer::get('withdraw', 'min_withdraw', 0),//最低提现金额;
'max_withdraw' => ConfigServer::get('withdraw', 'max_withdraw', 0),//最高提现金额;
'poundage_percent' => ConfigServer::get('withdraw', 'poundage', 0),//提现手续费;
];
$types = ConfigServer::get('withdraw', 'type', [1]); //提现方式,若未设置默认为提现方式为钱包
// 封装提现方式
$config['type'] = [];
if($types) {
foreach($types as $value) {
$config['type'][] = [
'name' => Withdraw::getTypeDesc($value),
'value' => $value
];
}
}
return $config;
}
//申请提现
public static function apply($user_id, $post)
{
Db::startTrans();
try{
//提现手续费
$poundage = 0;
if ($post['type'] != Withdraw::TYPE_BALANCE){
$poundage_config = ConfigServer::get('withdraw', 'poundage', 0);
$poundage = $post['money'] * $poundage_config / 100;
}
$data = [
'sn' => createSn('withdraw_apply', 'sn'),
'batch_no' => createSn('withdraw_apply', 'batch_no','SJZZ'),
'user_id' => $user_id,
'type' => $post['type'],
'account' => $post['account'] ?? '',
'real_name' => $post['real_name'] ?? '',
'money' => $post['money'],
'left_money' => $post['money'] - $poundage,
'money_qr_code' => $post['money_qr_code'] ?? '',
'remark' => $post['remark'] ?? '',
'bank' => $post['bank'] ?? '',
'subbank' => $post['subbank'] ?? '',
'poundage' => $poundage,
'status' => 1, // 待提现
'create_time' => time(),
];
$withdraw_id = Db::name('withdraw_apply')->insertGetId($data);
//提交申请后,扣减用户的佣金
$user = User::get($user_id);
$user->earnings = ['dec', $post['money']];
$user->save();
//增加佣金变动记录
AccountLogLogic::AccountRecord(
$user_id,
$post['money'],
2,
AccountLog::withdraw_dec_earnings,
'',
$withdraw_id,
$data['sn']
);
Db::commit();
return self::dataSuccess('', ['id' => $withdraw_id]);
}catch (Exception $e){
Db::rollback();
return self::dataError($e->getMessage());
}
}
//提现记录
public static function records($user_id, $get, $page, $size)
{
$count = Db::name('withdraw_apply')
->where(['user_id' => $user_id])
->count();
$lists = Db::name('withdraw_apply')
->where(['user_id' => $user_id])
->order('create_time desc')
->select();
foreach ($lists as &$item){
$item['desc'] = '提现至'.Withdraw::getTypeDesc($item['type']);
$item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
$item['status_text'] = Withdraw::getStatusDesc($item['status']);
}
$data = [
'list' => $lists,
'page' => $page,
'size' => $size,
'count' => $count,
'more' => is_more($count, $page, $size)
];
return $data;
}
//提现详情
public static function info($id, $user_id)
{
$info = Db::name('withdraw_apply')
->field('status, sn, create_time, type, money, left_money, poundage')
->where(['id' => $id, 'user_id' => $user_id])
->find();
if (!$info){
return [];
}
$info['create_time'] = date('Y-m-d H:i:s', $info['create_time']);
$info['typeDesc'] = Withdraw::getTypeDesc($info['type']);
$info['statusDesc'] = Withdraw::getStatusDesc($info['status']);
return $info;
}
}
+35
View File
@@ -0,0 +1,35 @@
<?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
// +----------------------------------------------------------------------
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// +----------------------------------------------------------------------
// | 中间件配置
// +----------------------------------------------------------------------
return [
// 默认中间件命名空间
'login' => app\api\http\middleware\Login::class,
];
@@ -0,0 +1,31 @@
<?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\model;
use think\Model;
class AfterSale extends Model
{
public function orderGoods()
{
return $this->hasOne('order_goods','id','order_goods_id')
->field('id,goods_id,item_id,total_pay_price,goods_num,goods_price,goods_info,total_price');
}
}
+37
View File
@@ -0,0 +1,37 @@
<?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\model;
use think\Model;
class Cart extends Model
{
protected $name = 'cart';
const IS_SELECTED = 1;//选中
const NO_SELECTED = 0;//未选中
public function goods()
{
return $this->hasOne('Goods', 'goods_id', 'goods_id');
}
}
+44
View File
@@ -0,0 +1,44 @@
<?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\model;
use think\Db;
use think\Model;
class Coupon extends Model
{
public function couponGoods()
{
return $this->hasMany('couponGoods', 'coupon_id', 'id');
}
//通过(coupon_list)获取优惠券信息
public static function getCouponByClId($coupon_id)
{
$result = Db::name('coupon c')
->join('coupon_list cl', 'c.id = cl.coupon_id')
->where(['cl.id ' => $coupon_id, 'c.del' => 0, 'cl.del' => 0, 'cl.status' => 0])
->field('c.*')
->find();
return $result;
}
}
@@ -0,0 +1,24 @@
<?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\model;
use think\Model;
class CouponGoods extends Model{
}
+225
View File
@@ -0,0 +1,225 @@
<?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\model;
use app\common\model\DistributionGoods;
use app\common\server\ConfigServer;
use app\common\server\UrlServer;
use think\Db;
use think\Model;
class Goods extends Model{
//商品图片
public function getImageAttr($value,$data){
if($value){
return UrlServer::getFileUrl($value);
}
return $value;
}
//商品视频
public function getVideoAttr($value,$data){
if($value){
return UrlServer::getFileUrl($value);
}
return $value;
}
//商品详情
public function getContentAttr($value,$data){
$preg = '/(<img .*?src=")[^https|^http](.*?)(".*?>)/is';
$local_url = UrlServer::getFileUrl('/');
return preg_replace($preg, "\${1}$local_url\${2}\${3}",$value);
}
//商品库存
public function getStockAttr($value,$data){
if($data['is_show_stock']){
return $value;
}
return true;
}
//商品轮播图
public function GoodsImage(){
return $this->hasMany('GoodsImage','goods_id','id')->field('goods_id,uri');
}
public function Spec()
{
return $this->hasMany('GoodsSpec', 'goods_id', 'id');
}
public function GoodsItem(){
return $this->hasMany('GoodsItem', 'goods_id', 'id')->field('id,goods_id,image,spec_value_ids,spec_value_str,market_price,price,stock');
}
public function GoodsSpecValue(){
return $this->hasMany('GoodsSpecValue','goods_id','id');
}
public function GoodsSpec()
{
$spec = $this->Spec->toArray();
$spec_value = $this->GoodsSpecValue;
$spec = array_column($spec,null,'id');
$goods_item = $this->getAttr('goods_item');
//将商品价格替换成商品规格价
// $this->setAttr('price',$goods_item[0]['price']);
// $this->setAttr('market_price',$goods_item[0]['market_price']);
//拼接规格
foreach ($spec_value as $item){
if(isset($spec[$item['spec_id']])){
$spec[$item['spec_id']]['spec_value'][]= $item;
}
}
$this->setAttr('goods_spec',array_values($spec));
//规格图片为空则替换商品主图
foreach ($goods_item as $item_key => $item_value){
if(empty($item_value['image'])){
$goods_item[$item_key]['image'] = $this->getAttr('image');
}
}
$this->setAttr('goods_item',$goods_item);
}
public function Like(){
$goods = new self();
$like_list = $goods->where(['del'=>0,'is_like'=>1,'status'=>1])->field('id,name,image,min_price as price,market_price')->orderRaw('rand()')->limit(5)->select();
$this->setAttr('like',$like_list);
}
//下单赠送积分
public function getOrderGiveIntegralAttr($value,$data)
{
$data['give_integral'] = empty($data['give_integral']) ? 0 : $data['give_integral'];
if (1 === $data['give_integral_type']) {
return intval($data['give_integral']);
}
return intval($data['max_price'] * $data['give_integral'] / 100);
}
public function getCommentAttr($value,$data){
$comment = [];
$goods_comment = Db::name('goods_comment g')
->leftjoin('user u','g.user_id = u.id')
->where(['goods_id'=>$data['id'],'g.del'=>0,'g.status'=>1])
->order('g.id desc')
->field('g.id,user_id,item_id,comment,g.create_time,nickname,avatar,virtual_data')
->find();
if($goods_comment){
// 虚拟评论
if (empty($goods_comment['user_id']) && !empty($goods_comment['virtual_data'])) {
$virtual_data = json_decode($goods_comment['virtual_data'], JSON_UNESCAPED_UNICODE);
$goods_comment['avatar'] = $virtual_data['avatar'] ?? '';
$goods_comment['nickname'] = $virtual_data['nickname'] ?? '';
$goods_comment['create_time'] = $virtual_data['comment_time'] ?? time();
}
//好评人数
$goods_count = Db::name('goods_comment')
->where(['goods_id'=>$data['id'],'del'=>0])
->where('goods_comment','>',3)
->count();
//总评论人数
$comment_count = Db::name('goods_comment')
->where(['goods_id'=>$data['id'],'del'=>0])
->count();
//评论图片
$comment_image = Db::name('goods_comment_image')->where(['goods_comment_id'=>$goods_comment])->column('uri');
$comment = $goods_comment;
$comment['goods_rate'] = round(($goods_count/$comment_count)*100, 2).'%';
$comment['avatar'] = UrlServer::getFileUrl($comment['avatar']);
$comment['spec_value_str'] = '';
$comment['create_time'] = date('Y-m-d H:i:s',$comment['create_time']);
foreach ($comment_image as &$image_item){
$image_item = UrlServer::getFileUrl($image_item);
}
$comment['image'] = $comment_image;
foreach ($this->goods_item as $item){
if($item['id'] == $comment['item_id']){
$comment['spec_value_str'] = $item['spec_value_str'];
}
}
if(empty($comment['comment'])){
$comment['comment'] = '此用户没有填写评论';
}
}
return $comment;
}
//详情页显示佣金金额
public function getCommissionPriceAttr($value, $data)
{
$open_distribution = ConfigServer::get('distribution', 'is_open', 1);
$show_commission = ConfigServer::get('distribution', 'show_commission', 0);
$first_ratio = empty($data['first_ratio']) ? 0 : $data['first_ratio'];
if ($open_distribution && $show_commission && $data['is_commission'] && $first_ratio > 0) {
$money = round($first_ratio * $data['max_price'] / 100, 2);
if ($money > 0) {
return $money;
}
}
return 0;
}
/**
* @notes 商品是否参与分销
* @param $value
* @return string
* @author Tab
*/
public function getDistributionFlagAttr($value)
{
$data = DistributionGoods::where('goods_id', $value)->findOrEmpty()->toArray();
if (!empty($data) && $data['is_distribution'] == 1) {
return true;
}
return false;
}
/**
* @notes 分销状态搜索器
* @param $query
* @param $value
* @param $data
* @author Tab
*/
public function searchIsDistributionAttr($query, $value, $data)
{
// 不参与分销
if (isset($data['is_distribution']) && $data['is_distribution'] == '0') {
// 先找出参与分销的商品id
$ids = DistributionGoods::where('is_distribution', 1)->column('goods_id');
if (!empty($ids)) {
// 在搜索条件中将它们排除掉
$query->where('id', 'not in', $ids);
}
}
// 参与分销
if (isset($data['is_distribution']) && $data['is_distribution'] == '1') {
// 先找出参与分销的商品id
$ids = DistributionGoods::where('is_distribution', 1)->column('goods_id');
if (!empty($ids)) {
// 在搜索条件中使用它们来进行过滤
$query->where('id', 'in', $ids);
}
}
}
}
@@ -0,0 +1,27 @@
<?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\model;
use app\common\server\UrlServer;
use think\Model;
class GoodsImage extends Model{
public function getUriAttr($value,$data){
return UrlServer::getFileUrl($value);
}
}
@@ -0,0 +1,30 @@
<?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\model;
use app\common\server\UrlServer;
use think\Model;
class GoodsItem extends Model {
public function getImageAttr($value,$data){
if($value){
return UrlServer::getFileUrl($value);
}
return $value;
}
}
@@ -0,0 +1,26 @@
<?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\model;
use think\Model;
class GoodsSpec extends Model {
public function GoodsSpecValue(){
return $this->hasMany('GoodsSpecValue','spec_id','id');
}
}
@@ -0,0 +1,27 @@
<?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\model;
use think\Model;
class GoodsSpecValue extends Model {
public function GoodsSepc(){
return $this->hasMany('GoodsSpec', 'goods_id', 'id');
}
}
+251
View File
@@ -0,0 +1,251 @@
<?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\model;
use app\common\model\Pay;
use app\common\server\AreaServer;
use app\common\server\ConfigServer;
use think\Db;
use think\Model;
use app\common\model\Order as CommonOrder;
class Order extends Model
{
protected $name = 'order';
/*
* 下单时间
*/
public function getCreateTimeAttr($value, $data)
{
return date('Y-m-d H:i:s', $value);
}
/*
* 付款时间
*/
public function getPayTimeAttr($value, $data)
{
if ($value) {
return date('Y-m-d H:i:s', $value);
}
return '';
}
/*
* 发货时间
*/
public function getShippingTimeAttr($value, $data)
{
if ($value) {
return date('Y-m-d H:i:s', $value);
}
return '';
}
/*
* 取消时间
*/
public function getCancelTimeAttr($value, $data)
{
if ($value) {
return date('Y-m-d H:i:s', $value);
}
return '';
}
/*
* 确认收货时间
*/
public function getConfirmTakeTimeAttr($value, $data)
{
if ($value) {
return date('Y-m-d H:i:s', $value);
}
return '';
}
/*
* 支付方式
*/
public function getPayWayTextAttr($value, $data)
{
return Pay::getPayWay($data['pay_way']);
}
public function orderGoods()
{
return $this->hasMany('order_goods', 'order_id', 'id');
}
public function getGoodsCountAttr($value, $data)
{
return count($this->order_goods);
}
/*
* 返回是否显示支付按钮
*/
public function getPayBtnAttr($value, $data)
{
$btn = 0;
if ($data['order_status'] == CommonOrder::STATUS_WAIT_PAY && $data['pay_status'] == Pay::UNPAID) {
$btn = 1;
}
return $btn;
}
/*
* 返回是否显示取消订单按钮
*/
public function getCancelBtnAttr($value, $data)
{
$btn = 0;
//多长时间内允许客户取消
if ($data['pay_status'] == Pay::ISPAID) {
$cancel_limit = ConfigServer::get('trading', 'customer_cancel_limit', 0);
$limit_time = $data['pay_time'] + $cancel_limit * 60;
if ($limit_time < time()) {
return $btn = 0;
}
}
if (($data['order_status'] == CommonOrder::STATUS_WAIT_PAY && $data['pay_status'] == Pay::UNPAID)
|| ($data['pay_status'] == Pay::ISPAID && $data['order_status'] == CommonOrder::STATUS_WAIT_DELIVERY)) {
$btn = 1;
}
return $btn;
}
/*
* 返回是否显示物流按钮
*/
public function getDeliveryBtnAttr($value, $data)
{
$btn = 0;
if ($data['order_status'] == CommonOrder::STATUS_WAIT_RECEIVE && $data['pay_status'] == Pay::ISPAID && $data['shipping_status'] == 1 && $data['delivery_type'] != CommonOrder::DELIVERY_STATUS_SELF) {
$btn = 1;
}
if ($data['order_status'] == CommonOrder::STATUS_FINISH && $data['pay_status'] == Pay::ISPAID && $data['shipping_status'] == 1 && $data['delivery_type'] != CommonOrder::DELIVERY_STATUS_SELF) {
$btn = 1;
}
return $btn;
}
/*
* 返回是否显示确认收货按钮
*/
public function getTakeBtnAttr($value, $data)
{
$btn = 0;
if ($data['order_status'] == CommonOrder::STATUS_WAIT_RECEIVE && $data['pay_status'] == Pay::ISPAID && $data['shipping_status'] == 1 && $data['delivery_type'] != CommonOrder::DELIVERY_STATUS_SELF) {
$btn = 1;
}
return $btn;
}
/*
* 返回是否显示删除按钮
*/
public function getDelBtnAttr($value, $data)
{
$btn = 0;
if (
($data['order_status'] == CommonOrder::STATUS_CLOSE && $data['pay_status'] == Pay::UNPAID) ||
($data['order_status'] == CommonOrder::STATUS_CLOSE && $data['pay_status'] == Pay::REFUNDED)
) {
$btn = 1;
}
return $btn;
}
/*
* 返回是否显示已完成按钮
*/
public function getFinishBtnAttr($value, $data)
{
$btn = 0;
if ($data['order_status'] == CommonOrder::STATUS_FINISH && $data['pay_status'] == Pay::ISPAID) {
$btn = 1;
}
return $btn;
}
/*
* 返回是否显示去评论按钮
*/
public function getCommentBtnAttr($value, $data)
{
$btn = 0;
$comment_count = 0;
if ($data['pay_status'] == Pay::ISPAID && $data['order_status'] == CommonOrder::STATUS_FINISH) {
$btn = 1;
foreach ($this->order_goods as $item) {
if ($item['is_comment'] == 1) {
$comment_count += 1;
};
}
if (count($this->orderGoods) == $comment_count) {
$btn = 0;
}
}
return $btn;
}
/*
* 返回是否显示申请退款按钮
*/
public function getRefundBtnAttr($value, $data)
{
$btn = 0;
$refund_days = $data['confirm_take_time'] + ConfigServer::get('after_sale', 'refund_days', '', 0) * 86400;
$now = time();
//订单已完成、在售后期内。未申请退款、
if ($data['order_status'] == CommonOrder::STATUS_FINISH && $refund_days > $now && $data['refund_status'] = \app\common\model\OrderGoods::REFUND_STATUS_NO) {
$btn = 1;
}
return $btn;
}
//收货地址
public function getDeliveryAddressAttr($value, $data)
{
$region_desc = AreaServer::getAddress([$data['province'], $data['city'], $data['district']], $data['address']);
return $region_desc;
}
public function getOrderCancelTimeAttr($value, $data)
{
$end_time = '';
if ($data['order_status'] == 0 && $data['pay_status'] == 0) {
$order_cancel_time = ConfigServer::get('trading', 'order_cancel', 30);
$end_time = $data['create_time'] + $order_cancel_time * 60;
}
return $end_time;
}
}

Some files were not shown because too many files have changed in this diff Show More