添加网站文件

This commit is contained in:
2025-12-22 13:59:40 +08:00
commit 117aaf83d1
19468 changed files with 2111999 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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
application/api/cache/TokenCache.php vendored Normal file
View File

@@ -0,0 +1,57 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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;
}
}

View File

@@ -0,0 +1,21 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
return [
'default_return_type' => 'json',
];

View File

@@ -0,0 +1,22 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
return [
//token过期时间
'token_expire_time' => 3600 * 24 * 60,
];

View File

@@ -0,0 +1,558 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\api\controller;
use app\api\logic\LoginLogic;
use app\common\server\ConfigServer;
use app\common\server\WeChatServer;
use app\api\server\UserServer;
use app\api\cache\TokenCache;
use think\facade\Config;
use think\Db;
class Account extends ApiBase
{
public $like_not_need_login = ['register','applogin', 'login', 'mnplogin', 'codeurl', 'oalogin', 'oplogin','logout','smslogin', 'uinAppLogin', 'silentLogin', 'authLogin','stafflogin'];
/**
* 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']);
}
/**
* 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']);
}
public function getrandstr($length = 10){
$str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$len = strlen($str)-1;
$randstr = '';
for ($i=0;$i<$length;$i++) {
$num=mt_rand(0,$len);
$randstr .= $str[$num];
}
return $randstr;
}
//2021-0419 小程序新版登录调整
/**
* Notes: 小程序登录(旧系统用户,返回用户信息,否则返回空)
* @author 段誉(2021/4/19 16:50)
*/
public function silentLogin()
{
$post = $this->request->post();
if(!empty($post['login_type']) && $post['login_type'] == 'toutiao'){
return $this->silentLogin_toutiao($post);
}
if (empty($post['code'])) {
$this->_error('参数缺失');
}
$data = LoginLogic::silentLogin($post);
$this->_success($data['msg'], $data['data'], $data['code'], $data['show']);
}
public function silentLogin_toutiao($data){
$url='https://developer.toutiao.com/api/apps/v2/jscode2session';
$data=[
'appid'=>'tt0523739e9a12236501',
'secret'=>'58280e4f36d88e93d7a4be9f0e590b2302a462c5',
'code'=>$data['code'],
//'anonymous_code'=>$anonymousCode,
];
$res=$this->json_post($url,$data);
// array(3) {
// ["err_no"]=>
// int(0)
// ["err_tips"]=>
// string(7) "success"
// ["data"]=>
// array(5) {
// ["session_key"]=>
// string(24) "xDIPf7whhzHFz+5ppTanFA=="
// ["openid"]=>
// string(36) "_000dypj-umBDuy6oz-nKqesccbK29flyIws"
// ["anonymous_openid"]=>
// string(0) ""
// ["unionid"]=>
// string(36) "eb8fbd8b-4124-595d-abf4-9fbca7ef3611"
// ["dopenid"]=>
// string(0) ""
// }
// }
$res=json_decode($res,true);
if(empty($res['data']['openid'])){
$this->_error('登录失败:'.json_encode($res));
}
$openid = $res['data']['openid'];
$unionid = $res['data']['unionid'];
$user_id =Db::name('user_auth')->where('openid',$openid)->find();
$response['headimgurl'] = $this->getrandstr();
$response['headimgurl'] = 'https://web.dulmao.com/uploads/images/202404240124289ecef8304.png';
$response['openid'] = $openid;
$response['unionid'] = $unionid;
if (empty($user_id)) {
$user_info = UserServer::createUser($response,8);
} else {
$user_info = UserServer::updateUser($response,8, $user_id);
}
//验证用户信息
$check_res = self::checkUserInfo($user_info);
if (true !== $check_res) {
return $this->_error($check_res);
}
//创建会话
$user_info['token'] = self::createSession($user_info['id'], 8);
unset($user_info['id'], $user_info['disable']);
return $this->_success('登录成功', $user_info);
}
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 checkUserInfo($user_info)
{
if (empty($user_info)) {
return '登录失败:user';
}
if ($user_info['disable']) {
return '该用户被禁用';
}
return true;
}
public function json_post($url, $data = [])
{
//$data=http_build_query($data);
//$data=json_encode($data);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
if(!$data){
return 'data is null';
}
if(is_array($data))
{
$data = json_encode($data);
}
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_HTTPHEADER,array(
'Content-Type: application/json; charset=utf-8',
'Content-Length:' . strlen($data),
'Cache-Control: no-cache',
'Pragma: no-cache'
));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($curl);
$errorno = curl_errno($curl);
if ($errorno) {
return $errorno;
}
curl_close($curl);
return $res;
}
/**
* Notes: 小程序登录(新用户登录->需要提交昵称和头像参数)
* @author 段誉(2021/4/19 16:49)
*/
public function authLogin()
{
$post = $this->request->post();
$post['nickname'] = $this->getrandstr();
$post['headimgurl'] = 'https://web.dulmao.com/uploads/images/202404240124289ecef8304.png';
//|
if (empty($post['code']) || empty($post['nickname']) || empty($post['phone_code'])) {
$this->_error('参数缺失');
}
$phone = $this->code_phone($post['phone_code']);
$data = LoginLogic::authLogin($post,$phone);
$this->_success($data['msg'], $data['data'], $data['code'], $data['show']);
}
//获取手机号
public function code_phone($code){
$data['code'] = $code;
$config = WeChatServer::getMnpConfig();
$accessToken = '';
$cache = cache('wx_mini_token');
if(!empty($cache) && !empty($cache['token']) && $cache['exp'] > time()){
$accessToken = $cache['token'];
}else{
$token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$config['app_id']."&secret=".$config['secret']."";
$_accessToken = file_get_contents($token_url);
$_accessToken = json_decode($_accessToken);
if(!empty($_accessToken)){
$accessToken = $_accessToken->access_token;
cache('wx_mini_token',['token'=>$accessToken,'exp'=>time()+6000]);
}else{
$this->_error('获取token失败');
}
}
$url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=$accessToken";
$info = $this->http_request($url,json_encode($data),'json');
// 一定要注意转json否则汇报47001错误
$tmpinfo = json_decode($info,true);
if(empty($tmpinfo)){
$this->_error('获取手机号失败');
}
if(!empty($tmpinfo['errcode'])){
$this->_error($tmpinfo['errmsg']);
}
return $tmpinfo['phone_info']['phoneNumber'];
}
public function getAccessToken()
{
$appid = '填写自己的appID';
$secret = '填写自己的秘钥';
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
$res = curl_exec($ch);
curl_close($ch);
return $res;
exit();
}
//图片合法性验证
public function http_request($url, $data = null)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data)) {
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS,$data);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json'
));
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
// 获取手机号
public function getPhoneNumber(){
$tmp = $this->getAccessToken();
$tmptoken = json_decode($tmp);
$token = $tmptoken->access_token;
$data['code'] = $_GET['code'];//前端获取code
$url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=$token";
$info = $this->http_request($url,json_encode($data),'json');
// 一定要注意转json否则汇报47001错误
$tmpinfo = json_decode($info);
$code = $tmpinfo->errcode;
$phone_info = $tmpinfo->phone_info;
//手机号
$phoneNumber = $phone_info->phoneNumber;
if($code == '0'){
echo json_encode(['code'=>1,'msg'=>'请求成功','phoneNumber'=>$phoneNumber]);
die();
}else{
echo json_encode(['code'=>2,'msg'=>'请求失败']);
die();
}
}
//员工端登入接口
public function stafflogin(){
$get = $this->request->get();
//判断是不是员工
$pass=md5(md5($get['password']));
$phone=Db::name('staff')->where('mobile',$get['phone'])->where('password','like',$pass)->find();
if($phone){
$this->_success('登入成功',$phone);
}else{
$this->_error('登入失败,请检查账号和密码');
}
}
}

View File

@@ -0,0 +1,33 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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);
}
}

View File

@@ -0,0 +1,239 @@
<?php
namespace app\api\controller;
use app\api\logic\AdLogic;
use think\Db;
class Ad extends ApiBase
{
public $like_not_need_login = ['lists','channel','label','add_comost','add_comost','list_comost','follow_comost','comost_add','label_edit','comost_info','notice','position','position_list','vode_type','video_list','video_info','user_wages','user_wages_add','user_leave','fine','recruit','last_leave','last_fine','notice_list','leave','auth'];
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);
}
//获取客户的渠道
public function channel(){
$list=Db::name('staffchannel')->field('id,name')->select();
$this->_success('获取成功', $list);
}
//获取客户的标签
public function label(){
$list=Db::name('user_label')->field('id,name')->select();
$this->_success('获取成功', $list);
}
//增加客户的档案
public function add_comost(){
$get = $this->request->get();//获取到员工的ID
$phone=Db::name('user_address')->where('telephone',$get['mobile'])->find();
if($phone){
$this->_error('电话号码已存在');
}
$staff=Db::name('staff')->where('id',$get['staff_id'])->field('mobile')->find();
$admin=Db::name('admin')->where('phone',$staff['mobile'])->find();
if($admin){
$data=[
'contact' => $get['consignee'],
'telephone' => $get['mobile'],
'sex' => $get['sex'],
'address' => $get['adder'],
'pet' => $get['pet'],
'hbl' => $get['clas'],
'wx' => $get['wx'],
'brand_id' => $get['channels'],
'label_id' => $get['labels'],
'admin_id' => $admin['id'],
'createtime' => time(),
'updatetime' => time()
];
$inser=Db::name('user_address')->data($data)->insert();
$this->_success('增加客户数据成功');
}else{
$this->_error('增加数据失败');
}
}
//根据ID获取客户的归属
public function list_comost(){
$get = $this->request->get();//获取的到传递过来的参数
$lists = AdLogic::list_comost($get);
$this->_success('获取数据成功',$lists);
}
//根据订单id获取的跟进信息
public function follow_comost(){
$get = $this->request->get();//获取的到传递过来的参数
$lists = AdLogic::follow_comost($get);
$this->_success('获取数据成功',$lists);
}
//创建跟进的内容
public function comost_add(){
$get = $this->request->get();//获取的到传递过来的参数
$lists = AdLogic::comost_add($get);
$this->_success('增加跟进内容成功');
}
//修改客户的标签
public function label_edit(){
$get = $this->request->get();//获取的到传递过来的参数
$update=Db::name('user_address')->where('id',$get['uid'])->update(['label_id'=>$get['value']]);
$this->_success('修改渠道成功');
}
public function comost_info(){
$get = $this->request->get();//获取的到传递过来的参数
$list=Db::name('user_address')->where('id',$get['id'])->find();
if($list['sex']==0){
$list['sex']="";
}else{ $list['sex']="";}
if($list['pet']=0){
$list['pet']="";
}else{$list['pet']="";}
if($list['hbl']==0){
$list['hbl']="";
}else{ $list['hbl']="";}
if($list['wx']==0){
$list['wx']="";
}else{ $list['wx']="";}
$label=Db::name('user_label')->where('id',$list['label_id'])->field('name')->find();
if($label){
$list['label_name']= $label['name'];
}else{
$list['label_name']= '-';
}
$brand=Db::name('staffchannel')->where('id',$list['brand_id'])->field('name')->find();
if($brand){
$list['brand_name']= $brand['name'];
}else{
$list['brand_name']= '-';
}
$this->_success('获取数据成功',$list);
}
//获取首页最新公告俩条
public function notice(){
$lists = AdLogic::notice();
$this->_success('获取数据成功',$lists);
}
//获取招聘类型列表
public function position(){
$lists = AdLogic::position();
$this->_success('获取数据成功',$lists);
}
public function position_list(){
$get = $this->request->get();//获取的到传递过来的参数
$lists = AdLogic::position_list($get);
$this->_success('获取数据成功',$lists);
}
//获取视频的类型
public function vode_type(){
$lists = AdLogic::vode_type();
$this->_success('获取数据成功',$lists);
}
public function video_list(){
$get = $this->request->get();//获取的到传递过来的参数
$lists = AdLogic::video_list($get);
$this->_success('获取数据成功',$lists);
}
//根据id获取视频培训
public function video_info(){
$get = $this->request->get();//获取的到传递过来的参数
$lists = AdLogic::video_info($get);
$this->_success('获取数据成功',$lists);
}
//员工工资获取获取
public function user_wages(){
$get = $this->request->get();//获取的到传递过来的参数
$lists = AdLogic::user_wages($get);
$this->_success('获取数据成功',$lists);
}
//员工增加员工的工资
public function user_wages_add(){
$get = $this->request->get();//获取的到传递过来的参数
$lists = AdLogic::user_wages_add($get);
if($lists==-1){
$this->_error('工资已经提交请勿重复提交');
}
$this->_success('提交成功');
}
//获取请假的列表
public function user_leave(){
$get = $this->request->get();//获取的到传递过来的参数
$lists = AdLogic::user_leave($get);
$this->_success('获取数据成功',$lists);
}
//删除上一个月请假列表
public function last_leave(){
$get = $this->request->get();//获取的到传递过来的参数
$lists = AdLogic::last_leave($get);
$this->_success('获取数据成功',$lists);
}
//获取到员工的罚款记录
public function fine(){
$get = $this->request->get();//获取的到传递过来的参数
$lists = AdLogic::fine($get);
$this->_success('获取数据成功',$lists);
}
//获取员工上一个月罚款记录
public function last_fine(){
$get = $this->request->get();//获取的到传递过来的参数
$lists = AdLogic::last_fine($get);
$this->_success('获取数据成功',$lists);
}
//提交招聘的信息
public function recruit(){
$get = $this->request->get();//获取的到传递过来的参数
$lists = AdLogic::addrecruit($get);
$this->_success('提交成功等待人事回电');
}
//获取公告的内容
public function notice_list(){
$get = $this->request->get();//获取的到传递过来的参数
$lists = AdLogic::notice_list($get);
$this->_success('获取数据成功',$lists);
}
//员工提交请假申请
public function leave(){
$get = $this->request->get();//获取的到传递过来的参数
$data=Db::name('leavesd')
->where('staff_id',$get['staff_id'])
->where('time',strtotime($get['time']))
->where('addtime',$get['after'])
->find();
if($data){
$this->_error('日期已经请假');
}
$lists = AdLogic::addleave($get);
$this->_success('提交成功');
}
//获取员工权限
public function auth(){
$get = $this->request->get();
$lists = AdLogic::auth($get);
$this->_success('获取权限成功',$lists);
}
}

View File

@@ -0,0 +1,307 @@
<?php
namespace app\api\controller;
use app\api\logic\StaffOrderLogic;
use app\common\server\UrlServer;
use think\Db;
class Administration extends ApiBase
{
public $like_not_need_login = ['Nuorder','uNuorder','order_sn','countOrder','allcustom','orderdeail','infoOrder','typePay','conle','edit_order','edit_order','overtime'];
/**
* note 获取全部总订单数据
* create_time 2020/10/21 19:05
*/
public function Nuorder(){
$param = $this->request->get(); //接受传递过来的参数
$where=[];
if (!empty($param['search'])) {
if (preg_match('/^1[3-9]\d{9}$/', $param['search'])) {
$where[] = ['mobile', '=', $param['search']];
} else {
$where[] = ['consignee', 'LIKE', '%' . $param['search'] . '%'];
}
} else {
$where = [];
}
$data=Db::name('order')
->order('id', 'desc')
->where($where)
->page($param['page'], $param['limt'])
->select();
$filteredData = [];
foreach ($data as &$item){
$item['create_time'] = date('Y-m-d', $item['create_time']);
$goods=StaffOrderLogic::goods($item['goods_id']); //订单的商品
if($goods){
$item['goods_name']=$goods['name'];
$item['image']=$goods['image'];
$item['code']=$goods['code'];
}
$admin=StaffOrderLogic::admin($item['admin_id']);
if($admin){
$item['admin_name']=$admin['name'];
}
$count=StaffOrderLogic::order_sn($item['order_sn']); //统计总的条数
$item['order_wc']=$count; //统计完成次数
$item['order_dsy']=$item['code']-$count;
if (isset($param['currentTab'])) {
if ($param['currentTab'] === '0' && $item['order_dsy']>0) {
$filteredData[] = $item;
} elseif ($param['currentTab'] === '1' && $item['order_dsy']<=0) {
$filteredData[] = $item;
} elseif ($param['currentTab'] === '2') {
$filteredData[] = $item;
}
elseif (!isset($param['currentTab'])) {
$filteredData[] = $item;
}
} else {
$filteredData[] = $item;
}
}
$this->_success('获取数据成功',$filteredData);
}
/**
* note 获取的我的订单
* create_time 2020/10/21 19:05
*/
public function uNuorder(){
$param = $this->request->get(); //接受传递过来的参数
$where=[];
if (!empty($param['search'])) {
if (preg_match('/^1[3-9]\d{9}$/', $param['search'])) {
$where[] = ['mobile', '=', $param['search']];
} else {
$where[] = ['consignee', 'LIKE', '%' . $param['search'] . '%'];
}
} else {
$where = [];
}
$admin_id=Db::name('admin')
->alias('a')
->join('staff s','s.mobile=a.phone')
->where('s.id',$param['id'])
->field('a.id')
->find();
if($admin_id){
$data=Db::name('order')
->order('id', 'desc')
->where($where)
->where('admin_id', $admin_id['id'])
->page($param['page'], $param['limt'])
->select();
$filteredData = [];
foreach ($data as &$item){
$item['create_time'] = date('Y-m-d', $item['create_time']);
$goods=StaffOrderLogic::goods($item['goods_id']); //订单的商品
if($goods){
$item['goods_name']=$goods['name'];
$item['image']=$goods['image'];
$item['code']=$goods['code'];
}
$admin=StaffOrderLogic::admin($item['admin_id']);
if($admin){
$item['admin_name']=$admin['name'];
}
$count=StaffOrderLogic::order_sn($item['order_sn']); //统计总的条数
$item['order_wc']=$count; //统计完成次数
$item['order_dsy']=$item['code']-$count;
if (isset($param['currentTab'])) {
if ($param['currentTab'] === '0' && $item['order_dsy']>0) {
$filteredData[] = $item;
} elseif ($param['currentTab'] === '1' && $item['order_dsy']<=0) {
$filteredData[] = $item;
} elseif ($param['currentTab'] === '2') {
$filteredData[] = $item;
}
elseif (!isset($param['currentTab'])) {
$filteredData[] = $item;
}
} else {
$filteredData[] = $item;
}
}
$this->_success('获取成功',$data);
}else{
$this->_error("人员不存在");
}
}
/**
* note 根据订单编号查询订单
* create_time 2020/10/21 19:05
*/
public function order_sn(){
$param = $this->request->get(); //接受传递过来的参数
$where=[];
if (isset($param['staff_status']) && $param['staff_status'] !== '') {
switch ($param['staff_status']) {
case '4':
$where[] = ['abnormal', '=', 1];
break;
default:
$where[] = ['staff_status', '=', $param['staff_status']];
break;
}
}
$data=Db::name('order_exe')->alias('o')
->join('order s','s.order_sn=o.order_sn')
->where('o.order_sn',$param['order_sn'])
->where($where)
->field('o.*, s.goods_id, s.order_sn as s_order_sn,s.admin_id,s.address,o.staff_id,o.remark')
->order('o.id', 'desc')
->select();
foreach ($data as &$item){
$item['autotime']=date('Y-m-d',$item['autotime']);
$goods=StaffOrderLogic::goods($item['goods_id']); //订单的商品
if($goods){
$item['goods_name']=$goods['name'];
}
$staff=StaffOrderLogic::staff($item['staff_id']);
if($staff){
$item['staff_name']=$staff['name'];
$item['staff_phone']=$staff['mobile'];
}
}
$this->_success('获取成功',$data);
}
/**
* note 根据订单编号统计数据
* create_time 2020/10/21 19:05
*/
public function countOrder(){
$param = $this->request->get(); //接受传递过来的参数
$data['toder']=Db::name('order_exe')->where('order_sn',$param['order_sn'])->where('staff_status',0)->count();
$data['ardfs']=Db::name('order_exe')->where('order_sn',$param['order_sn'])->where('staff_status',1)->count();
$data['fwz']=Db::name('order_exe')->where('order_sn',$param['order_sn'])->where('staff_status',2)->count();
$data['fwywc']=Db::name('order_exe')->where('order_sn',$param['order_sn'])->where('staff_status',3)->count();
$data['ycorder']=Db::name('order_exe')->where('order_sn',$param['order_sn'])->where('abnormal',1)->count();
$this->_success('获取成功',$data);
}
/**
* note 获取到全部客户
* create_time 2020/10/21 19:05
*/
public function allcustom(){
$param = $this->request->get();
if (!empty($param['search'])) {
if (preg_match('/^1[3-9]\d{9}$/', $param['search'])) {
$where[] = ['telephone', '=', $param['search']];
} else {
$where[] = ['contact', 'LIKE', '%' . $param['search'] . '%'];
}
} else {
$where = [];
}
$data=Db::name('user_address')
->where($where)
->page($param['page'], $param['limt'])
->order('id desc')
->select();
foreach ($data as &$item){
$admin=StaffOrderLogic::admin($item['admin_id']); //获取到绑定管理员信息
if($admin){
$item['admin_name']=$admin['name'];
}else{
$item['admin_name']='-';
}
$conne=StaffOrderLogic::addqudao($item['brand_id']);
if($conne){
$item['channel_name']=$conne['name'];
}else{
$item['channel_name']='-';
}
$user=StaffOrderLogic::user($item['user_id']);
if($user){
$item['user_image']=UrlServer::getFileUrl($user['avatar']);
}
}
$this->_success('获取成功',$data);
}
/**
* note 根据订单编号获取到订单信息
* create_time 2020/10/21 19:05
*/
public function orderdeail(){
$param = $this->request->get();
$data=Db::name('order')->alias('o')
->join('goods g','o.goods_id=g.id')
->join('admin a','a.id=admin_id')
->join('orderchannel c','o.channel_id=c.id')
->where('o.id',$param['id'])
->field(['o.id','o.goods_id','g.id','g.name as goods_name','o.order_sn','o.create_time','o.consignee','o.mobile','o.address','a.name as admin_name','c.name as clan_name','o.pay_zd','o.pay_way','o.order_amount','o.gord_id','o.order_remarks'])
->find();
$data['create_time']=date('Y-m-d H:i:s');
$this->_success('获取成功',$data);
}
/**
* note 编辑订单功能
* create_time 2020/10/21 19:05
*/
public function infoOrder(){
$param = $this->request->get();
$data=Db::name('order')
->where('id',$param['id'])
->find();
$this->_success('获取成功',$data);
}
/**
* note 获取所有的支付渠道
* create_time 2020/10/21 19:05
*/
public function typePay(){
$data=Db::name('collection')->select();
$this->_success('获取成功',$data);
}
/**
* note 获取是有的订单渠道
* create_time 2020/10/21 19:05
*/
public function conle(){
$data=Db::name('orderchannel')->select();
$this->_success('获取成功',$data);
}
/**
* note 编辑订单的数据
* create_time 2020/10/21 19:05
*/
public function edit_order(){
$param = $this->request->get();
$data=StaffOrderLogic::edit_order($param); //统计总的条数
$this->_success('获取成功',$data);
}
/**
* note订单加时间的审批
* create_time 2020/10/21 19:05
*/
public function overtime(){
$param = $this->request->get();
$admin_id=Db::name('admin')
->alias('a')
->join('staff s','s.mobile=a.phone')
->where('s.id',$param['id'])
->field('a.id')
->find();
}
}

View File

@@ -0,0 +1,113 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\api\controller;
use think\Db;
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();
$order=Db::name('order')->where('id',$post['id'])->find();
if($order['refund_status']==2){
$this->_error('退款申请之中');
}
if($order['pay_status']!=1){
$this->_error('订单未支付,无法申请退款');
}
if($order['code']==0){
$this->_error('订单已完成,无法申请退款');
}
$ref=Db::name('order')->where('id',$post['id'])->update(['refund_status'=>2]);
$this->_success('申请成功');
}
}

View File

@@ -0,0 +1,153 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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);
}
}

View File

@@ -0,0 +1,56 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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);
}
}

View File

@@ -0,0 +1,133 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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('');
}
}

View File

@@ -0,0 +1,98 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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));
}
}

View File

@@ -0,0 +1,23 @@
<?php
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);
}
}

View File

@@ -0,0 +1,89 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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);
}
}

View File

@@ -0,0 +1,33 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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);
}
}

View File

@@ -0,0 +1,161 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\api\controller;
use app\api\logic\DistributionLogic;
use app\common\model\User;
class Distribution extends ApiBase
{
/**
* 填写邀请码
*/
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();
$page = $this->request->get('page_no', $this->page_no);
$size = $this->request->get('page_size', $this->page_size);
$this->_success('', DistributionLogic::order($this->user_id, $get, $page, $size));
}
/**
* 月度账单
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function monthBill()
{
$page = $this->request->get('page_no', $this->page_no);
$size = $this->request->get('page_size', $this->page_size);
$this->_success('', DistributionLogic::getMonthBill($this->user_id, $page, $size));
}
/**
* 月度账单明细
*/
public function monthDetail()
{
$get = $this->request->get();
$page = $this->request->get('page_no', $this->page_no);
$size = $this->request->get('page_size', $this->page_size);
$this->_success('', DistributionLogic::getMonth($get, $this->user_id, $page, $size));
}
/**
* Notes: 分销会员页面判断
* @author 段誉(2021/2/1 18:45)
*/
public function check()
{
$user = User::get($this->user_id);
if ($user['freeze_distribution'] == 1) {
$this->_error('您已被冻结');
}
if ($user['is_distribution'] == 1) {
$this->_success('', '', 10001);//已是分销会员
} else {
$this->_success('', '',20001);//未是分销会员
}
}
}

View File

@@ -0,0 +1,47 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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']);
}
}

View File

@@ -0,0 +1,18 @@
<?php
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);
}
}

View File

@@ -0,0 +1,73 @@
<?php
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('清理失败','');
}
}

View File

@@ -0,0 +1,21 @@
<?php
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);
}
}

View File

@@ -0,0 +1,118 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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 服务子订单的pl
* create_time 2020/11/11 15:14
*/
public function addOrderComment()
{
$post = $this->request->post();
$post['user_id'] = $this->user_id;
$result = GoodsCommentLogic::addOrderComment( $post,$this->user_id);
if($result === true){
$this->_success('评论成功');
}
}
/**
* note 获取到订单的详情
* create_time 2020/11/11 15:14
*/
public function OrderInfo()
{
$post = $this->request->post('id');
$result = GoodsCommentLogic::OrderInfo($post);
$this->_success('获取成功',$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('请选择评论的商品');
}
}

View File

@@ -0,0 +1,52 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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);
}
}

View File

@@ -0,0 +1,272 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册htp://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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;
use app\common\model\{NoticeSetting, SmsLog, SmsConfig};
use app\common\server\Alisms;
class Index extends ApiBase
{
public $like_not_need_login = ['test','sedx','lists','appInit', 'downLine', 'share', 'config','pcLists','goods_stay_time','send_sms','get_pege'];
//短信宝接口
public function sedx(){
$nowtime = time();
$s = strtotime(date('Y-m-d',$nowtime+86400));
$e = strtotime(date('Y-m-d',$s))+86399;
$where = [
['autotime','>=',$s],
['autotime','<=',$e],
];
$phons = Db::name('order_exe')
->where($where)
->where('status','<>',3)
->field('phone')
->select();
$apiUrl = "https://api.smsbao.com/sms?" . http_build_query([
'u' => 'connoryz',
'p' => '6ea341b75d96492396d98ac26a5b71e6',
'm' => '18285169381',
'c' => '测试短信内容', // 内容需要编码
]);
$result = file_get_contents($apiUrl);
if ($result === '0') {
echo '短信发送成功';
} else {
echo '短信发送失败';
}
dump($result);
}
//阿里云短信接口
public function send_sms(){
$config = SmsConfig::get(['status' => 1]);
if(!$config || !$config->app_key){
echo '短信未开启';
exit;
}
$config->sign ='哆啦猫家政';
$alisms = new Alisms($config);
$nowtime = time();
//明日起始时间
$s = strtotime(date('Y-m-d',$nowtime+86400));
$e = strtotime(date('Y-m-d',$s))+86399;
$where = [
['autotime','>=',$s],
['autotime','<=',$e],
];
$phons = Db::name('order_exe')
->where($where)
->where('status','<>',3)
->field('phone')
->select();
if(empty($phons)){
echo '暂无号码';
exit;
}
foreach ($phons as $v){
if(empty($v['phone'])) continue;
$res = $alisms->setMobile($v['phone'])
->setTemplateCode('SMS_492015079')
->sendSms();
}
echo '执行完成';
}
/**
* note 首页接口
* create_time 2020/10/21 19:05
*/
public function lists(){
$lists = IndexLogic::lists($this->user_id);
return $this->_success('',$lists);
}
public function get_pege(){
$id = $this->request->get('id');
$date=Db::name('pageweb')->where('id',$id)->find();
$this->_success('获取数据成功',$date);
}
public function goods_stay_time(){
$input = input();
if(empty($input['uid'])){
$this->_error('uid empty');
}
if(empty($input['goods_id'])){
$this->_error('goods_id empty');
}
if(empty($input['time'])){
$this->_error('time empty');
}
$uid = $input['uid'];
$goods_id = $input['goods_id'];
$time = $input['time'];
$data = [
'uid'=>$uid,
'goods_id'=>$goods_id,
'time'=>$time,
'add_time'=>time()
];
Db::name('goods_stay_time')->insert($data);
$this->_success('ok');
}
/**
* 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' => ''
]);
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
];
$this->_success('', $config);
}
}

View File

@@ -0,0 +1,122 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\api\controller;
use app\api\logic\LeadershipLogic;
use think\Db;
class Leadership extends ApiBase{
public $like_not_need_login = ['index','material_list','material_examine','material_notpass','finance_list','finance_examine','finance_notpass','addorder_list','addorder_examine','addorder_notpass','staff_list'];
/**
* Notes: pc端首页接口
* @author: 2021/3/5 12:00
*/
public function index(){
$lists = PcLogic::pcLists();
return $this->_success('',$lists);
}
//获取等待审核物料的数据列表
public function material_list(){
$get = $this->request->get(); //获取前端传递过来的数据
$list = LeadershipLogic::material_list($get);
$this->_success('获取成功',$list);
}
//点击审核通过
public function material_examine(){
$get = $this->request->get(); //获取前端传递过来的数据
$update=Db::name('erp_staff')->where('id',$get['id'])->update(['status'=>2]);
$this->_success('审核通过');
}
//点击审核不通过
public function material_notpass(){
$get = $this->request->get(); //获取前端传递过来的数据
$update=Db::name('erp_staff')->where('id',$get['id'])->update(['status'=>3,'reason'=>$get['data']]);
$this->_success('审核通过');
}
//获取报销的列表
public function finance_list(){
$get = $this->request->get(); //获取前端传递过来的数据
$list = LeadershipLogic::finance_list($get);
$this->_success('获取成功',$list);
}
//报销审核通过
public function finance_examine(){
$get= $this->request->get(); //获取前端传递过来的数据
$info=Db::name('finance')->where('id',$get['id'])->find();
$update=Db::name('finance')->where('id',$get['id'])->update(['status'=>2,'staff_id'=>$get['staff_id']]);
$order=Db::name('order_exe')->where('id',$info['order_id'])->update(['account'=>$info['pay']]);
$this->_success('审核通过');
}
//报销审核不通过的理由
public function finance_notpass(){
$get= $this->request->get(); //获取前端传递过来的数据
$update=Db::name('finance')->where('id',$get['id'])->update(['status'=>3,'reason'=>$get['data']]);
$this->_success('修改状态成功');
}
//获取报销的列表
public function addorder_list(){
$get = $this->request->get(); //获取前端传递过来的数据
$list = LeadershipLogic::addorder_list($get);
$this->_success('获取成功',$list);
}
//加时间通过代码
public function addorder_examine(){
$get= $this->request->get(); //获取前端传递过来的数据
$info=Db::name('order_timeadd')->where('id',$get['id'])->find();
$update=Db::name('order_timeadd')->where('id',$get['id'])->update(['status'=>2,'staff_id'=>$get['staff_id']]);
$order=Db::name('order_exe')->where('id',$info['orderid'])->update(['add'=>$info['minute']]);
$this->_success('审核通过');
}
//加时间审核不通过代码
public function addorder_notpass(){
$get= $this->request->get(); //获取前端传递过来的数据
$update=Db::name('order_timeadd')->where('id',$get['id'])->update(['status'=>3,'reason'=>$get['data']]);
$this->_success('修改状态成功');
}
//获取站长员工下面的信息
public function staff_list(){
$get= $this->request->get(); //获取前端传递过来的数据
$data=Db::name('leavesd')
->where('staff_id',$get['staff_id'])
->find();
if($data){
}
$list = LeadershipLogic::staff_list($get);
$this->_success('获取成功',$list);
}
}

View File

@@ -0,0 +1,103 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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');
if ($result === true) {
return LoginPasswordLogic::forget($post);
}
$this->_error($result);
}
}

View File

@@ -0,0 +1,43 @@
<?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()
{
$result = LuckdrawLogic::draw($this->user_id);
if ($result) {
$this->_success('OK', $result);
}
$error = LuckdrawLogic::getError() ?: '抽奖失败';
$this->_error($error);
}
}

View File

@@ -0,0 +1,33 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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);
return $this->_success('获取成功', $list);
}
}

View File

@@ -0,0 +1,42 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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));
}
}

View File

@@ -0,0 +1,917 @@
<?php
namespace app\api\controller;
use app\api\logic\OrderLogic;
use app\common\model\Client_;
use think\Db;
use app\common\server\WeChatServer;
use app\common\model\NoticeSetting;
use EasyWeChat\Factory;
/**
* 订单
* Class Order
* @package app\api\controller
*/
class Order extends ApiBase
{
public $like_not_need_login = ['wxmassin', 'lists', 'appInit', 'downLine', 'share', 'config','pcLists','getpege','ttorder'];
//抖音订单回调
public function ttorder(){
$ttPay = new ttPay();
$res = $ttPay->run('notify');
}
//订单列表
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 stafflist()
{
$type = $this->request->get('type', 'all');
$order_list = OrderLogic::stafflist($this->user_id, $type, $this->page_no, $this->page_size);
$this->_success('获取成功', $order_list);
}
//员工订单详情页面
public function numberlist()
{
$type = $this->request->get('type', 'all');
$tiem= $this->request->get();
if(isset($tiem['id'])){
$order_list = OrderLogic::timelist($this->user_id, $type,$tiem,$this->page_no, $this->page_size);
$this->_success('获取成功', $order_list);
}else{
$order_list = OrderLogic::numberlist($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;
// $openid = 'oehgp4zzyK34d3TgnXD1ytpeNRjI';
// //发送下单成功通知
// $template = [
// 'touser'=>$openid,
// 'template_id'=>'qTmpP2ZnGMpgAFgNsmcVMfTjCeSE7GXEQQaFTUERAuU',
// 'page'=>'',//点击模板消息 打开小程序页面
// 'data'=>[
// 'thing2'=>['value'=>'擦玻璃服务'],
// 'amount8'=>['value'=>'金额2元'],
// 'time10'=>['value'=>date('Y-m-d H:i',time())]
// ]
// ];
// $r = send_mini_template($template);
$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']);
}
if ($this->client != Client_::pc && empty($post['pay_way'])) {
$this->_error('请联系管理员配置支付方式');
}
$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);
}
//取消订单
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);
}
public function Get_Chinese_WeekDay($Join_Date)
{
$WeekDay = date('w', strtotime($Join_Date));
$WeekList = array('日', '一', '二', '三', '四', '五', '六');
return '星期' . $WeekList[$WeekDay];
}
public function get3day(){
$goods_id = $this->request->post('id');
$order=Db::name('order')->where('id',$goods_id)->find(); //获取到订单的信息
$goods=Db::name('goods')->where('id',$order['goods_id'])->find(); //获取到商品的信息
// $staff=Db::name('staff')->where('goods_id',$goods['brand_id'])->select(); //查询到所有的保洁师傅
// dump($staff);die;
$days = [];
$current = date('Y-m-d');
for($i = 1 ; $i <= 3 ;$i++){
$current = date("Y-m-d", strtotime($current . "+1 day"));
$days[] = $current;
}
$data = [];
foreach ($days as $k=>$v){
$start = strtotime($v); //开始时间
$end = strtotime($v.' 23:59:59'); //结束时间
//统计这个时间请假的用户的数据
$orders=Db::name('order_exe')->where('addtime',1)->where('autotime','>=',$start)->where('autotime','<=',$end)->whereNotNull('staff_id')->field('staff_id')->group('staff_id')->select(); //查询有订单的保洁师傅
$oneDimensionalArray = array_column($orders, 'staff_id'); // 根据自己的表格字段名修改'字段名'部分
$lent=Db::name('leave')->where('addtime',1)->where('time','>=',$start)->where('time','<=',$end)->whereNotNull('user_id')->field('user_id')->group('user_id')->select();
$lentuser = array_column($lent,'user_id');
//判断上午
$numbersw=Db::name('staff')
->where('onwork',1)
->where('goods_id',$goods['brand_id'])
->whereNotIn('id',$oneDimensionalArray) // $array为要比较的数组
->whereNotIn('id',$lentuser) // $array为要比较的数组
->count(); //获取到请假的人数
$order_numbersw=Db::name('order_exe')->where('autotime','>=',$start)->where('autotime','<=',$end)->where('staff_id',0)->where('addtime',1)->count();// 没有派单的保洁师
$numbersw=$numbersw-$order_numbersw;
//统计这个时间请假的用户的数据
$ordersxw=Db::name('order_exe')->where('addtime',2)->where('autotime','>=',$start)->where('autotime','<=',$end)->whereNotNull('staff_id')->field('staff_id')->group('staff_id')->select(); //查询有订单的保洁师傅
$oneDimensionalArrayxw= array_column($ordersxw, 'staff_id'); // 根据自己的表格字段名修改'字段名'部分
$lentxw=Db::name('leave')->where('addtime',2)->where('time','>=',$start)->where('time','<=',$end)->whereNotNull('user_id')->field('user_id')->group('user_id')->select();
$lentuserxw = array_column($lentxw,'user_id');
//判断下午
$numberxw=Db::name('staff')
->where('onwork',1)
->whereNotIn('id',$oneDimensionalArrayxw) // $array为要比较的数组
->where('goods_id',$goods['brand_id'])
->whereNotIn('id',$lentuserxw) // $array为要比较的数组
->count(); //获取到请假的人数
$order_numberxw=Db::name('order_exe')->where('autotime','>=',$start)->where('autotime','<=',$end)->where('staff_id',0)->where('addtime',2)->count();// 没有派单的保洁师
$numberxw=$numberxw-$order_numberxw;
if($numbersw>0){
$coied=false;
} else{
$coied=true;
}
if($numberxw>0){
$coiedxw=false;
} else{
$coiedxw=true;
}
$data[] = [
'date'=>$v,
'week'=>$this->Get_Chinese_WeekDay($v),
'hourLists'=>[
['hour'=>"上午",'select'=>false,'disabled'=>$coied,'selectDay'=>$v,'staffnumber'=>$numbersw],
['hour'=>'下午','select'=>false,'disabled'=>$coiedxw,'selectDay'=>$v,'staffnumber'=>$numberxw],
]
];
}
$data[0]['select'] = true;
$this->_success('获取成功', $data);
}
public function getday(){
$post = $this->request->post();
$order=Db::name('order')->where('id',$post['data']['id'])->find(); //获取到订单的信息
$goods=Db::name('goods')->where('id',$order['goods_id'])->find(); //获取到商品的信息
$day = $post['data']['day'];
$start = strtotime($day);
$end = strtotime($day.' 23:59:59');
//统计这个时间请假的用户的数据
$orders=Db::name('order_exe')->where('addtime',1)->where('autotime','>=',$start)->where('autotime','<=',$end)->whereNotNull('staff_id')->field('staff_id')->group('staff_id')->select(); //查询有订单的保洁师傅
$oneDimensionalArray = array_column($orders, 'staff_id'); // 根据自己的表格字段名修改'字段名'部分
$lent=Db::name('leave')->where('addtime',1)->where('time','>=',$start)->where('time','<=',$end)->whereNotNull('user_id')->field('user_id')->group('user_id')->select();
$lentuser = array_column($lent,'user_id');
$numbersw=Db::name('staff')
->where('onwork',1)
->where('goods_id',$goods['brand_id'])
->whereNotIn('id',$oneDimensionalArray) // $array为要比较的数组
->whereNotIn('id',$lentuser) // $array为要比较的数组
->count();
$order_numbersw=Db::name('order_exe')->where('autotime','>=',$start)->where('autotime','<=',$end)->where('staff_id',0)->where('addtime',1)->count();// 没有派单的保洁师
$numbersw=$numbersw-$order_numbersw;
//统计这个时间请假的用户的数据
$ordersxw=Db::name('order_exe')->where('addtime',2)->where('autotime','>=',$start)->where('autotime','<=',$end)->whereNotNull('staff_id')->field('staff_id')->group('staff_id')->select(); //查询有订单的保洁师傅
$oneDimensionalArrayxw= array_column($ordersxw, 'staff_id'); // 根据自己的表格字段名修改'字段名'部分
$lentxw=Db::name('leave')->where('addtime',2)->where('time','>=',$start)->where('time','<=',$end)->whereNotNull('user_id')->field('user_id')->group('user_id')->select();
$lentuserxw = array_column($lentxw,'user_id');
//判断下午
$numberxw=Db::name('staff')
->where('onwork',1)
->whereNotIn('id',$oneDimensionalArrayxw) // $array为要比较的数组
->whereNotIn('id',$lentuserxw) // $array为要比较的数组
->where('goods_id',$goods['brand_id'])
->count(); //获取到请假的人数
$order_numberxw=Db::name('order_exe')->where('autotime','>=',$start)->where('autotime','<=',$end)->where('staff_id',0)->where('addtime',2)->count();// 没有派单的保洁师
$numberxw=$numberxw-$order_numberxw;
if($numbersw>0){
$coied=false;
}else{
$coied=true;
}
if($numberxw>0){
$coiedxw=false;
}else{
$coiedxw=true;
}
$data[] = [
'date'=>$day,
'week'=>$this->Get_Chinese_WeekDay($day),
'hourLists'=>[
['hour'=>'上午','select'=>false,'disabled'=>$coied,'selectDay'=>$day,'staffnumber'=>$numbersw],
['hour'=>'下午','select'=>false,'disabled'=>$coiedxw,'selectDay'=>$day,'staffnumber'=>$numberxw],
]
];
$data[0]['select'] = true;
$this->_success('获取成功', $data);
}
public function sendgzhmsg($orderid = ''){
$uid = $this->user_id;
// $uid = 366;
$openids=Db::name('user_auth')->where('user_id',$uid)->find(); //获取用户的ID
$adder=Db::name('user_address')->where('user_id',$uid)->find();
// $openid = 'o_XDv5_Cq72XDOx1qvzq2kcaOYWA';
$openid = $openids['openid'];
$data = [
'touser'=>$openid,
'url'=>'',
'template_id'=>'MJBxsfAT18v9fQ8LYK2v1AF4iRkprNp1KPVm1ses64I', //模板id
'data'=>[
'time4'=>[
'value'=>date('Y-m-d H:i',time())
],
'thing1'=>[
'value'=>$adder['contact']
]
]
];
$config = WeChatServer::getOaConfig();
$app = Factory::officialAccount($config);
$r = $app->template_message->send($data);
return true;
}
public function shensatff($id){
dump($id);
}
public function putday(){
$post = $this->request->post();
$sw = $post['data']['hourLists'][0]['select'];
$xw = $post['data']['hourLists'][1]['select'];
$orderid=$post['data']['id']; //传递进来的订单id
$day = $post['data']['date'];
$order=Db::name('order')->where('id',$orderid)->find(); //获取到订单的基本信息
$goods=Db::name('goods')->where('id',$order['goods_id'])->find();
if($order['code']<=0){
$this->_error('订单次数已不足无法预约');
}
if($sw && $xw){
$code=Db::name('order')->where('id',$orderid)->find();
if($code['code']<=2){
return 20;
}else{
$data=[
'order_sn'=>$order['order_sn'], //订单编号
'create_time'=>time(),
// 'fworder_sn'=> $post['fworder_sn'],
'date'=>$day,
'xq'=>$this->Get_Chinese_WeekDay($day),
'type'=>3,
'status'=>0,
'addtime'=>1,
'autotime'=>strtotime($day),
];
$list=Db::name('order_exe')->data($data)->insert();
$datas=[
'order_sn'=>$order['order_sn'], //订单编号
'create_time'=>time(),
// 'fworder_sn'=> $post['fworder_sn'],
'date'=>$day,
'xq'=>$this->Get_Chinese_WeekDay($day),
'type'=>3,
'status'=>0,
'addtime'=>2,
'autotime'=>strtotime($day),
];
$list=Db::name('order_exe')->data($datas)->insert();
$order=Db::name('order')->where('id',$orderid)->update(['code'=>$order['code']-2]); //获取到订单的基本信息
$this->sendgzhmsg($day);
if($order['admin_id']!=NULL){
$admin=Db::name('admin')->where('id',$order['admin_id'])->find();
$openids=Db::name('user_auth')->where('user_id',$admin['user_id'])->find(); //获取用户的ID
//$time=date('Y-m-d',$orders['autotime']);
//$openid = 'o_XDv5_Cq72XDOx1qvzq2kcaOYWA';
$openid = $openids['openid'];
$data = [
'touser'=>$openid,
'url'=>'',
'template_id'=>'9ESlNoZweXTioNwyaDuSY9fIXCKhnrBi2Gu0Hl8cmAo', //模板id
'data'=>[
'keyword1'=>[
'value'=>$order['order_sn']
],
'keyword2'=>[
'value'=>$goods['name']
],
'keyword3'=>[
'value'=>$order['consignee']
],
'keyword4'=>[
'value'=>$order['mobile']
],
'keyword5'=>[
'value'=>$day
],
]
];
$config = WeChatServer::getOaConfig();
$app = Factory::officialAccount($config);
$r = $app->template_message->send($data);
}
$this->_success('预约成功,待上门', $list);
}
}
if($sw){
if($order>0){
$data=[
'order_sn'=>$order['order_sn'], //订单编号
'create_time'=>time(),
// 'fworder_sn'=> $post['fworder_sn'],
'date'=>$day,
'xq'=>$this->Get_Chinese_WeekDay($day),
'type'=>3,
'status'=>0,
'addtime'=>1,
'autotime'=>strtotime($day),
];
$list=Db::name('order_exe')->data($data)->insert();
$orderss=Db::name('order')->where('id',$orderid)->update(['code'=>$order['code']-1]); //获取到订单的基本信息
$this->sendgzhmsg($day);
if($order['admin_id']!=NULL){
$admin=Db::name('admin')->where('id',$order['admin_id'])->find();
$openids=Db::name('user_auth')->where('user_id',$admin['user_id'])->find(); //获取用户的ID
//$time=date('Y-m-d',$orders['autotime']);
//$openid = 'o_XDv5_Cq72XDOx1qvzq2kcaOYWA';
$openid = $openids['openid'];
$data = [
'touser'=>$openid,
'url'=>'',
'template_id'=>'9ESlNoZweXTioNwyaDuSY9fIXCKhnrBi2Gu0Hl8cmAo', //模板id
'data'=>[
'keyword1'=>[
'value'=>$order['order_sn']
],
'keyword2'=>[
'value'=>$goods['name']
],
'keyword3'=>[
'value'=>$order['consignee']
],
'keyword4'=>[
'value'=>$order['mobile']
],
'keyword5'=>[
'value'=>$day.'.8:00-12:00'
],
]
];
$config = WeChatServer::getOaConfig();
$app = Factory::officialAccount($config);
$r = $app->template_message->send($data);
}
$this->_success('预约成功,待上门', $list);
}else{
return 20;
}
}
if($xw){
if($order>0){
$data=[
'order_sn'=>$order['order_sn'], //订单编号
'create_time'=>time(),
// 'fworder_sn'=> $post['fworder_sn'],
'date'=>$day,
'xq'=>$this->Get_Chinese_WeekDay($day),
'type'=>3,
'status'=>0,
'addtime'=>2,
'autotime'=>strtotime($day),
];
$list=Db::name('order_exe')->data($data)->insert();
$order=Db::name('order')->where('id',$orderid)->update(['code'=>$order['code']-1]); //获取到订单的基本信息
$this->sendgzhmsg($day);
if($order['admin_id']!=NULL){
$admin=Db::name('admin')->where('id',$order['admin_id'])->find();
$openids=Db::name('user_auth')->where('user_id',$admin['user_id'])->find(); //获取用户的ID
//$time=date('Y-m-d',$orders['autotime']);
//$openid = 'o_XDv5_Cq72XDOx1qvzq2kcaOYWA';
$openid = $openids['openid'];
$data = [
'touser'=>$openid,
'url'=>'',
'template_id'=>'9ESlNoZweXTioNwyaDuSY9fIXCKhnrBi2Gu0Hl8cmAo', //模板id
'data'=>[
'keyword1'=>[
'value'=>$order['order_sn']
],
'keyword2'=>[
'value'=>$goods['name']
],
'keyword3'=>[
'value'=>$order['consignee']
],
'keyword4'=>[
'value'=>$order['mobile']
],
'keyword5'=>[
'value'=>$day.'.14:00-16:00'
],
]
];
$config = WeChatServer::getOaConfig();
$app = Factory::officialAccount($config);
$r = $app->template_message->send($data);
}
$this->_success('预约成功,待上门', $list);
}else{
return 20;
}
}
}
//保洁师开始接单
public function take(){
$order_id = $this->request->post('params');
$order=Db::name('order_exe')->where('id',$order_id)->find();
if($order['autotime']-time()>24*3600){
$this->_error('无法接单,未到时间');
}else{
$toke=Db::name('order_exe')->where('id', $order_id )->update(['status'=>1]);
$this->_success('接单成功');
}
}
//保洁师开始接单
public function wego(){
$order_id = $this->request->post('params');
$toke=Db::name('order_exe')->where('id', $order_id )->update(['status'=>1,'timeadd'=>time(),'staff_status'=>1]);
$this->_success('接单成功');
}
//保洁师结束服务
public function ends(){
$order_id = $this->request->post('params');
$toke=Db::name('order_exe')->where('id', $order_id )->update(['status'=>2,'timeout'=>time(),'staff_status'=>1]);
$this->_success('接单成功');
}
//订单的详情显示
public function orderinfo(){
$type = $this->request->post('type', 'all');
$post=$this->request->post();
$order_sn=$post['id']['order_sn'];
$order_list = OrderLogic::orderinfo($this->user_id, $type,$order_sn,$this->page_no, $this->page_size);
$this->_success('获取成功', $order_list);
}
//微信的通知
public function wxmassin(){
$start = strtotime(date("Y-m-d",strtotime("+1 day")));
$end =$start+24*3600-1;
$order=Db::name('order_exe')->where('autotime','>=',$start)->where('autotime','<=',$end)->where('staff_id','<>',0)->select();
foreach ($order as &$orders) {
$custom=Db::name('order')->where('order_sn',$orders['order_sn'])->find();
$goods=Db::name('goods')->where('id',$custom['goods_id'])->find();
$user=Db::name('staff')->where('id',$orders['staff_id'])->find();
if($orders['addtime']=1){
$timesw='上午';
}else{
$timesw='下午';
}
// $uid = 366;
$openids=Db::name('user_auth')->where('user_id',$user['user_id'])->find(); //获取用户的ID
$time=date('Y-m-d',$orders['autotime']);
// $openid = 'o_XDv5_Cq72XDOx1qvzq2kcaOYWA';
$openid = $openids['openid'];
$data = [
'touser'=>$openid,
'url'=>'',
'template_id'=>'YYsFPwTCrPcxi0JA_zg0xnz6uFaVAlobfTGvhQVDglE', //模板id
'data'=>[
'keyword1'=>[
'value'=>$goods['name']
],
'keyword2'=>[
'value'=> $time.$timesw
],
'keyword3'=>[
'value'=>$custom['address']
],
'keyword4'=>[
'value'=>$custom['consignee']
],
'keyword5'=>[
'value'=>$custom['mobile']
],
]
];
$config = WeChatServer::getOaConfig();
$app = Factory::officialAccount($config);
$r = $app->template_message->send($data);
}
}
public function getpege(){
$id = $this->request->get('id');
$date=Db::name('pageweb')->where('id',$id)->find();
$this->_success('获取数据成功',$date);
// dump($id);
}
}
Class ttPay{
private $api_url='https://developer.toutiao.com/api/apps/ecpay/v1/';
private $app_id;
private $token;
private $salt;
public function __construct() {
$this->app_id = 'tt0523739e9a12236501';
$this->token='123qazqweeesdflomswwe';
$this->salt='ejAuHvbI472euyhb34aVyLD92ll9tgZCqWnMi0tX';
}
public function run($action,$order = null){
$action=$action?$action:'order';
if(!in_array($action,['order','query','refund','settle','notify','set'])){
echo '非法请求';die;
}
return $this->$action($order);
}
//下单
private function order($order){
$data=[
'out_order_no'=>$order['order_sn'],
'total_amount'=>1,
'subject'=>'购买服务',
'body'=>'购买商品',
'valid_time'=>3600,
];
return $this->post('create_order',$data);
}
//查询订单
private function query(){
$data=[
'out_order_no'=>'2021110117254573565'
];
$res=$this->post('query_order',$data,false);
echo json_encode($res);die;
}
//订单退款
private function refund(){
$data=[
'out_order_no'=>'2021110118351347832',
'out_refund_no'=>$this->order_number(),
'reason'=>'退款原因',
'refund_amount'=>1,
];
$res=$this->post('create_refund',$data);
echo json_encode($res);die;
}
//订单分账
private function settle(){
$data=[
'out_order_no'=>'2021110118301265990',
'out_settle_no'=>$this->order_number(),
'settle_desc'=>'分账描述',
'settle_params'=>json_encode([]),//分润方参数 如[['merchant_uid'=>'商户号','amount'=>'10']] 可以有多个分账商户
];
$res=$this->post('settle',$data);
echo json_encode($res);die;
}
//支付设置回调测试
private function set(){
$content=file_get_contents('php://input');
$this->log('log.txt',$content);
}
//回调
private function notify(){
$content=input();
if(empty($content)) return false;
$this->log('notify.txt',json_encode($content));
if(is_array($content)){
$content=$content;
}else{
$content=json_decode($content,true);
}
$sign=$this->handler($content);
if(!empty($content['msg_signature']) && $sign==$content['msg_signature']){
if(is_array($content['msg'])){
$msg=$content['msg'];
}else{
$msg=json_decode($content['msg'],true);
}
if($content['type'] == 'payment'){
$order_sn = $msg['payment_order_no'];
Db::name('order')->where('order_sn',$order_sn)->update(['pay_status'=>1]);
}
//这里更新应用业务逻辑代码,使用$msg跟应用订单比对更新订单,可以用 $content['type']判断是支付回调还是退款回调payment支付回调 refund退款回调。
$res=['err_no'=>0,'err_tips'=>'success'];
echo json_encode($res);
exit;
}else{
echo '验签失败';
}
}
/**
* 测试订单号,实际应用根据自己应用实际生成
* @return string
*/
private function order_number(){
return date('YmdHis').rand(10000,99999);
}
/**
* 请求小程序平台服务端
* @param string $url 接口地址
* @param array $data 参数内容
* @param boolean $notify 是否有回调
* @return array
*/
private function post($method,$data,$notify=true){
$data['app_id']=$this->app_id;
$data['sign']=$this->sign($data);
$url=$this->api_url.$method;
$res=$this->http('POST',$url,json_encode($data),['Content-Type: application/json'],true);
return json_decode($res,true);
}
/**
* 回调验签
* @param array $map 验签参数
* @return stirng
*/
private function handler($map){
$rList = array();
array_push($rList, $this->token);
foreach($map as $k =>$v) {
if ( $k == "type" || $k=='msg_signature')
continue;
$value = trim(strval($v));
if ($value == "" || $value == "null")
continue;
array_push($rList, $value);
}
sort($rList,2);
return sha1(implode($rList));
}
/**
* 请求签名
* @param array $map 请求参数
* @return stirng
*/
private function sign($map) {
$rList = array();
foreach($map as $k =>$v) {
if ($k == "other_settle_params" || $k == "app_id" || $k == "sign" || $k == "thirdparty_id")
continue;
$value = trim(strval($v));
$len = strlen($value);
if ($len > 1 && substr($value, 0,1)=="\"" && substr($value,$len, $len-1)=="\"")
$value = substr($value,1, $len-1);
$value = trim($value);
if ($value == "" || $value == "null")
continue;
array_push($rList, $value);
}
array_push($rList, $this->salt);
sort($rList, 2);
return md5(implode('&', $rList));
}
/**
* 写日志
* @param string $path 日志路径
* @param string $content 内容
*/
private function log($path, $content){
$file=fopen($path, "a");
fwrite($file, date('Y-m-d H:i:s').'-----'.$content."\n");
fclose($file);
}
/**
* 网络请求
* @param stirng $method 请求模式
* @param stirng $url请求网关
* @param array $params 请求参数
* @param stirng $header 自定义头
* @param boolean $multi 文件上传
* @return array
*/
private function http( $method = 'GET', $url,$params,$header = array(), $multi = false){
$opts = array(
CURLOPT_TIMEOUT => 30,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_HTTPHEADER => $header
);
/* 根据请求类型设置特定参数 */
switch(strtoupper($method)){
case 'GET':
$opts[CURLOPT_URL] = $url . '?' . http_build_query($params);
break;
case 'POST':
//判断是否传输文件
$params = $multi ? $params : http_build_query($params);
$opts[CURLOPT_URL] = $url;
$opts[CURLOPT_POST] = 1;
$opts[CURLOPT_POSTFIELDS] = $params;
break;
default:
throw new Exception('不支持的请求方式!');
}
/* 初始化并执行curl请求 */
$ch = curl_init();
curl_setopt_array($ch, $opts);
$data = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
if($error) throw new Exception('请求发生错误:' . $error);
return $data;
}
}

View File

@@ -0,0 +1,182 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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\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();
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('订单不存在');
}
//已支付
if ($order['pay_status'] == Pay::ISPAID || $order['order_amount'] == 0) {
$this->_success('支付成功', ['order_id' => $order['id']], 10001);
}
$result = PaymentLogic::pay($post['from'], $order, $post['order_source']);
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: 小程序回调
* @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()
{
$get= $this->request->get('client');
$payModel = new Pay();
$pay = $payModel->where(['status' => 1])->order('sort')->hidden(['config'])->select()->toArray();
$client = true;
if($get) $client = false;
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(!$client){
// if($item['code'] == 'wechat' || $item['code'] == 'alipay'){
// unset($pay[$k]);
// }
// }
}
$this->_success('', array_values($pay));
}
}

View File

@@ -0,0 +1,70 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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);
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace app\api\controller;
use app\api\logic\PointsLogic;
use app\api\logic\UserLogic;
class Points extends ApiBase
{
public $like_not_need_login = ['classify',''];
/**
* 获取积分商品的分类
* @return mixed
*/
public function classify()
{
$lists = PointsLogic::classify();
$this->_success('获取数据成功',$lists);
}
/**
* 获取积分的商品内容
* @return mixed
*/
public function goodslist(){
$lists = PointsLogic::goodslist();
$this->_success('获取数据成功',$lists);
}
/**
*
* @return mixed
*/
public function goodsIofo(){
$id = $this->request->get('id');
$data = PointsLogic::goodsIofo($id);
$this->_success('获取数据成功',$data);
}
public function goodsSub(){
$data = $this->request->get();
$data['user_id']= $this->user_id;
$user_jf=UserLogic::getUserInfo($this->user_id);
if($user_jf['user_integral']<$data['price']){
$this->_error('积分不足');
}else{
$data = PointsLogic::goodsSub($data);
$this->_success('兑换成功',$data);
}
}
}

View File

@@ -0,0 +1,53 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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());
}
}

View File

@@ -0,0 +1,64 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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);
}
}

View File

@@ -0,0 +1,124 @@
<?php
namespace app\api\controller;
use app\api\logic\CartLogic;
use app\api\logic\RegionLogic;
use think\Db;
class Recruit extends ApiBase{
public $like_not_need_login = ['recruit_type','recruit_order','recruit_orderinfo','staff_list','recruit_index','recruit_listorder','add_order'];
public function recruit_type(){
$recruit_type=Db::name('staff_group')->select(); //获取部门信息
$recruitype=Db::name('recruitype')->select(); //获取招聘的类型
$recrui_monney=Db::name('recrui_monney')->select();
$data=[
'filterProject'=>$recruit_type,
'filterSubject'=>$recruitype,
'filterYear'=>$recrui_monney
];
return $this->_success('获取招聘类型成功',$data);
}
//站长端派单查询
public function recruit_order(){
$get = $this->request->get();//获取的电话查询
$data=RegionLogic::recruit_order($get);
return $this->_success('获取订单的数据成功',$data);
}
//根据id获取订单的基本
public function recruit_orderinfo(){
$get = $this->request->get();//获取订单的id
$info=Db::name('order')->where('id',$get['order_id'])->find();
return $this->_success('获取订单数据成功',$info);
}
//获取保洁师的基本
public function staff_list(){
$get = $this->request->get();//获取传递过来的时间
$get['datatime']=date('Y-m-d',$get['time']/1000); //获取提交过来日期
$timestamp = strtotime("today 14:00 am"); //上午的时间搓
$timestampxw = strtotime("today 18:00 am"); //上午的时间搓
//判断日期类型
if(time()>strtotime($get['datatime'])){
$this->_error('日期时间选择错误');
}
$data=RegionLogic::staff_list($get);
return $this->_success('获取保洁师',$data);
}
//首页获取站长端口数据统计
public function recruit_index(){
$get = $this->request->get();//传递过来的数据
$data=RegionLogic::recruit_index($get);
return $this->_success('获取订单的数据成功',$data);
}
//首页获取统计内容
public function recruit_listorder(){
$get = $this->request->get();//接受传递过来的参数
$data=RegionLogic::recruit_listorder($get);
return $this->_success('获取订单的数据成功',$data);
}
//站长创建子订单
public function add_order(){
$get = $this->request->get();//接受传递过来的参数
$orderinfo=Db::name('order')->where('id',$get['order_id'])->find();
$useradder=Db::name('user_address')->where('', $orderinfo['mobile'])->find();
//传递过来的时间转换
$selectime=date("Y-m-d",$get['time']/1000);
// 使用date()函数获取星期几的数字表示0-60 是星期天)
$weekdayNum = date('N', strtotime($selectime));
// 使用数组映射星期几的名称
$weekdays = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六','星期天'];
// 获取对应的星期名称
$weekdayName = $weekdays[$weekdayNum - 1];
if($orderinfo && $useradder){
$data=[
'order_sn' => $orderinfo['order_sn'],
'name' => $orderinfo['consignee'],
'phone' => $orderinfo['mobile'],
'admin' => $useradder['admin_id'],
'goods_id' => $orderinfo['goods_id'],
'channel_id' => $useradder['brand_id'],
'type' => $orderinfo['type_id'],
'autotime' => strtotime($selectime),
'xq' => $weekdayName,
'date' => $selectime,
'addtime' => $get['addtime'],
'staff_id' => $get['staff_id'],
'create_time' => time(),
'remark' => $get['remark'],
];
$inser=Db::name('order_exe')->data($data)->insert();
if($inser){
$update=Db::name('order')->where('order_sn',$orderinfo['order_sn'])->update(['code'=>$orderinfo['code']-1]);
return $this->_success('创建子订单成功');
}
}else{
$this->_error('创建子订单失败');
}
}
}

View File

@@ -0,0 +1,35 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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);
}
}

View File

@@ -0,0 +1,79 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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('缺少参数');
}
}

View File

@@ -0,0 +1,28 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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);
}
}

View File

@@ -0,0 +1,71 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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');
$client = $this->client;
$result = $this->validate(['id' => $id, 'url' => $url], 'app\api\validate\Bargain.share');
if (true === $result) {
$result = ShareLogic::shareBargain($this->user_id, $id, $url, $client);
$this->_success($result['msg'], $result['data'], $result['code']);
}
$this->_error($result);
}
}

View File

@@ -0,0 +1,90 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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){
$sign = SignLogic::sign($this->user_id);
$this->_success('签到成功',$sign);
}
$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);
}
}

View File

@@ -0,0 +1,52 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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('发送成功');
}
}

View File

@@ -0,0 +1,822 @@
<?php
namespace app\api\controller;
use app\api\logic\LoginLogic;
use app\api\logic\StaffLogic;
use app\common\server\ConfigServer;
use app\common\server\WeChatServer;
use app\api\server\UserServer;
use app\api\cache\TokenCache;
use think\facade\Config;
use app\api\model\{Coupon, Order, User,Orderexe};
use app\common\server\UrlServer;
use think\Db;
class Staff extends ApiBase
{
public $like_not_need_login = ['staff_user','order_list','staff_taking','order_start','start_tim','order_progress','complete','complete_time','timeorder','index','sement','addsement','listsement','numberement','editsement','addtime','addtimeinfo','addtimenumber','editaddtime','orderinfo','orderlist','staff_qjia','gettoken','get_urlcheme','count','abnormal'];
function gettoken(){
$appid = 'wxfa3cb402f088cbf8';
$secret = '563284ab0358e3ee0ada351fc96f045e';
$cache_token = cache("wx_1_token");
if($cache_token && $cache_token['expires_in'] > time()){
return $cache_token['access_token'];
}
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}";
$res = json_decode(file_get_contents($url),true);
$token = $res['access_token'];
$res['expires_in'] = time()+ $res['expires_in'] - 100;
cache('wx_1_token',$res);
return $token;
}
//获取链接
function get_urlcheme(){
$id = input('id');
$token = $this->gettoken();
$url1 = 'https://api.weixin.qq.com/wxa/generatescheme?access_token='.$token;
$ch = curl_init();
$data1 = array("path"=>"/pages/eval/eval", "query"=>"id=".$id,"env_version"=>"release");
$data = json_encode(array("expire_type"=>1,"expire_interval"=>5,"jump_wxa"=>$data1));
curl_setopt($ch, CURLOPT_URL, $url1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$p = (json_decode($output,true));
if(empty($p['openlink'])){
echo '生成链接失败:'.(!empty($p['errmsg'])?$p['errmsg']:'');
exit;
}
header("Location: {$p['openlink']}");
}
//员工的基本的信息
public function staff_user(){
$get = $this->request->get();//获取到员工的ID
$inof=Db::name('staff')->where('id',$get['staff_id'])->find();
$inof['staff_img']=UrlServer::getFileUrl($inof['image']);
if($inof){
$inof['ordermonth']=
Db::name('order_exe')
->where('staff_id', $get['staff_id'])
->whereTime('autotime', 'month')
->where('staff_status',3)
->count(); //拥挤当月完成订单
$inof['year']=Db::name('order_exe')
->where('staff_id', $get['staff_id'])
->whereTime('autotime', 'year')
->where('staff_status',3)
->count(); //拥挤本年完成订单
$inof['addtime']=Db::name('order_exe')->where('staff_id', $get['staff_id'])->whereTime('autotime', 'month')->where('staff_status',3)->count(); //拥挤本年完成订单
$inof['notfinish']=Db::name('order_exe')->where('staff_id', $inof['id'])->whereTime('autotime', 'month')->where('staff_status',3)->where('addtime',1)->sum('add')/60; //上午加时
$inof['finish']=Db::name('order_exe')->where('staff_id', $inof['id'])->whereTime('autotime', 'month')->where('staff_status',3)->where('addtime',2)->sum('add')/60;
$inof['amount']=Db::name('order_exe')->where('staff_id', $inof['id'])->whereTime('autotime', 'month')->where('staff_status',3)->sum('account');
return $this->_success('获取数据成功',$inof);
}
}
//首页的数据统计
public function index(){
$get = $this->request->get();//获取到员工的ID
// 计算明天的日期
$tomorrow = date('Y-m-d', strtotime('+1 day'));
$start = strtotime($tomorrow); //开始时间
$end = strtotime($tomorrow.' 23:59:59'); //结束时间
$tomorrows = date('Y-m-d', strtotime('+2 day'));
$starts = strtotime($tomorrows); //开始时间
$ends = strtotime($tomorrows.' 23:59:59'); //结束时间
$tomorrows= date('Y-m-d', strtotime('+2 day'));
$userinfo=Db::name('staff')->where('id',$get['uid'])->find();
$userinfo['dataorder']=Db::name('order_exe')->whereTime('autotime', 'today')->where('staff_id',$get['uid'])->count(); //统计今天的订单
$userinfo['tomorrow']=Db::name('order_exe')->where('autotime','>=',$start)->where('autotime','<=',$end)->where('staff_id',$get['uid'])->count(); //统计今天的订单
$userinfo['tomorrows']=Db::name('order_exe')->where('autotime','>=',$starts)->where('autotime','<=',$ends)->where('staff_id',$get['uid'])->count(); //统计今天的订单
return $this->_success('获取数据成功',$userinfo);
}
//获取等待接单
public function order_list(){
$get = $this->request->get();//获取到员工的ID
$lists=StaffLogic::order_list($get);
$this->_success('获取数据成功', $lists);
}
//获取等待接单
public function order_start(){
$get = $this->request->get();//获取到员工的ID
$order = new Orderexe();
$lists = $order->where('staff_id',$get['staff_id'])
->where('staff_status',$get['staff_status'])
->order('autotime desc')
->select();
foreach ($lists as $list){
$custom=Db::name('order')->where('order_sn',$list['order_sn'])->find();
$list['address']= $custom['address'];
$list['lat']= $custom['lat'];
$list['lng']= $custom['lng'];
$goods=Db::name('goods')->where('id',$custom['goods_id'])->find();
$list['goods_name']= $goods['name'];
if(intval(($list['autotime']-time())/86400)>1){
$list['jldate']=intval(($list['autotime']-time())/86400);
}else{
$list['jldate']='-';
}
$adder=Db::name('user_address')->where('telephone',$custom['mobile'])->find();
if($adder){
$admin=Db::name('admin')->where('id',$adder['admin_id'])->find();
if($admin){
$list['admin_name']=$admin['name'];
$list['admin_phone']=$admin['phone'];
}else{
$list['admin_name']='-';
$list['admin_phone']='-';
}
}
if($list['addtime']==1){
$list['sw']='上午';
$list['sw_time']='8:00-12:00';
}else{
$list['sw']='下午';
$list['sw_time']='14:00-18:00';
}
//查询其他用户
$more_where = [
['staff_id','<>',$get['staff_id']],
['order_sn','=',$list['order_sn']],
['autotime','=',$list['autotime']]
];
$more_users = $order->where($more_where)
->order('autotime desc')
->column('staff_id');
if(!empty($more_users)){
$list['users'] = Db::name('staff')->field('mobile,name,addr')->whereIn('id',$more_users)->select();
}
$list['autotime']=date("Y-m-d",$list['autotime']);
}
$this->_success('获取数据成功', $lists);
}
//已经开始的服务的订单
public function order_progress(){
$get = $this->request->get();//获取到员工的ID
$order = new Orderexe();
$lists = $order->where('staff_id',$get['staff_id'])
->where('staff_status',$get['staff_status'])
->order('autotime desc')
->select();
foreach ($lists as $list){
$custom=Db::name('order')->where('order_sn',$list['order_sn'])->find();
$list['address']= $custom['address'];
$list['lat']= $custom['lat'];
$list['lng']= $custom['lng'];
$goods=Db::name('goods')->where('id',$custom['goods_id'])->find();
$list['goods_name']= $goods['name'];
if(intval(($list['autotime']-time())/86400)>1){
$list['jldate']=intval(($list['autotime']-time())/86400);
}else{
$list['jldate']='-';
}
$adder=Db::name('user_address')->where('telephone',$custom['mobile'])->find();
if($adder){
$admin=Db::name('admin')->where('id',$adder['admin_id'])->find();
if($admin){
$list['admin_name']=$admin['name'];
$list['admin_phone']=$admin['phone'];
}else{
$list['admin_name']='-';
$list['admin_phone']='-';
}
}
if($list['addtime']==1){
$list['sw']='上午';
$list['sw_time']='8:00-12:00';
}else{
$list['sw']='下午';
$list['sw_time']='14:00-18:00';
}
//查询其他用户
$more_where = [
['staff_id','<>',$get['staff_id']],
['order_sn','=',$list['order_sn']],
['autotime','=',$list['autotime']]
];
$more_users = $order->where($more_where)
->order('autotime desc')
->column('staff_id');
if(!empty($more_users)){
$list['users'] = Db::name('staff')->field('mobile,name,addr')->whereIn('id',$more_users)->select();
}
$list['autotime']=date("Y-m-d",$list['autotime']);
}
$this->_success('获取数据成功', $lists);
}
//异常订单列表
public function abnormal(){
$get = $this->request->get();//获取到员工的ID
$order = new Orderexe();
$lists = $order->where('staff_id',$get['staff_id'])
->where('abnormal',$get['staff_status'])
->order('autotime desc')
->select();
foreach ($lists as $list){
$custom=Db::name('order')->where('order_sn',$list['order_sn'])->find();
$list['address']= $custom['address'];
$list['lat']= $custom['lat'];
$list['lng']= $custom['lng'];
$goods=Db::name('goods')->where('id',$custom['goods_id'])->find();
$list['goods_name']= $goods['name'];
if(intval(($list['autotime']-time())/86400)>1){
$list['jldate']=intval(($list['autotime']-time())/86400);
}else{
$list['jldate']='-';
}
$adder=Db::name('user_address')->where('telephone',$custom['mobile'])->find();
if($adder){
$admin=Db::name('admin')->where('id',$adder['admin_id'])->find();
if($admin){
$list['admin_name']=$admin['name'];
$list['admin_phone']=$admin['phone'];
}else{
$list['admin_name']='-';
$list['admin_phone']='-';
}
}
if($list['addtime']==1){
$list['sw']='上午';
$list['sw_time']='8:00-12:00';
}else{
$list['sw']='下午';
$list['sw_time']='14:00-18:00';
}
//查询其他用户
$more_where = [
['staff_id','<>',$get['staff_id']],
['order_sn','=',$list['order_sn']],
['autotime','=',$list['autotime']]
];
$more_users = $order->where($more_where)
->order('autotime desc')
->column('staff_id');
if(!empty($more_users)){
$list['users'] = Db::name('staff')->field('mobile,name,addr')->whereIn('id',$more_users)->select();
}
$list['autotime']=date("Y-m-d",$list['autotime']);
}
$this->_success('获取数据成功', $lists);
}
//获取当月的订单
public function complete(){
$get = $this->request->get();//获取到员工的ID
$order = new Orderexe();
$lists = $order->where('staff_id',$get['staff_id'])
->where('staff_status',3)
->whereTime('autotime','month')
->order('autotime desc')
->select();
foreach ($lists as $list){
$custom=Db::name('order')->where('order_sn',$list['order_sn'])->find();
$list['address']= $custom['address'];
$list['lat']= $custom['lat'];
$list['lng']= $custom['lng'];
$goods=Db::name('goods')->where('id',$custom['goods_id'])->find();
$list['goods_name']= $goods['name'];
if(intval(($list['autotime']-time())/86400)>1){
$list['jldate']=intval(($list['autotime']-time())/86400);
}else{
$list['jldate']='-';
}
$adder=Db::name('user_address')->where('telephone',$custom['mobile'])->find();
if($adder){
$admin=Db::name('admin')->where('id',$adder['admin_id'])->find();
if($admin){
$list['admin_name']=$admin['name'];
$list['admin_phone']=$admin['phone'];
}else{
$list['admin_name']='-';
$list['admin_phone']='-';
}
}
if($list['addtime']==1){
$list['sw']='上午';
$list['sw_time']='8:00-12:00';
}else{
$list['sw']='下午';
$list['sw_time']='14:00-18:00';
}
//查询其他用户
$more_where = [
['staff_id','<>',$get['staff_id']],
['order_sn','=',$list['order_sn']],
['autotime','=',$list['autotime']]
];
$more_users = $order->where($more_where)
->order('autotime desc')
->column('staff_id');
if(!empty($more_users)){
$list['users'] = Db::name('staff')->field('mobile,name,addr')->whereIn('id',$more_users)->select();
}
$list['autotime']=date("Y-m-d",$list['autotime']);
}
$this->_success('获取数据成功', $lists);
}
//保洁师开始接单
public function staff_taking(){
$get = $this->request->get();//获取子订单的iD
$taking=Db::name('order_exe')->where('id',$get['orderid'])->update(['staff_status'=>1]);
$this->_success('获取数据成功',$taking);
}
//保洁师开始开始服务
public function start_tim(){
$get = $this->request->get();//获取子订单的iD
$orderlist=Db::name('order_exe')->where('id',$get['orderid'])->find(); //获取订单的基本信息
if($orderlist['addtime']==1){ //派单上午订单
$selectime=date("Y-m-d",$orderlist['autotime']); //获取上午的时间
$timeStamp = strtotime($selectime . ' 07:30:00');
if($timeStamp<time()){
$start=Db::name('order_exe')->where('id',$get['orderid'])->update(['staff_status'=>2,'start_time'=>time(),'status'=>0]);
$this->_success('获取数据成功');
}else{
$this->_error('开始失败');
}
}else{
$selectime=date("Y-m-d",$orderlist['autotime']); //获取上午的时间
$timeStamp = strtotime($selectime . ' 13:30:00');
if($timeStamp<time()){
$start=Db::name('order_exe')->where('id',$get['orderid'])->update(['staff_status'=>2,'start_time'=>time(),'status'=>0]);
$this->_success('获取数据成功');
}else{
$this->_error('开始失败');
}
}
}
//保洁师确定订单服务已经完成
public function complete_time(){
$get = $this->request->get();//获取子订单的iD
$orderlist=Db::name('order_exe')->where('id',$get['orderid'])->find(); //获取订单的基本信息
if($orderlist['addtime']==1){ //派单上午订单
$selectime=date("Y-m-d",$orderlist['autotime']); //获取上午的时间
$timeStamp = strtotime($selectime . ' 11:30:00');
if($timeStamp<time()){
$start=Db::name('order_exe')->where('id',$get['orderid'])->update(['staff_status'=>3,'timeout'=>time(),'status'=>1]);
$this->_success('获取数据成功',$start);
}else{
$this->_error('开始失败');
}
}else{
$selectime=date("Y-m-d",$orderlist['autotime']); //获取上午的时间
$timeStamp = strtotime($selectime . ' 17:30:00');
if($timeStamp<time()){
$start=Db::name('order_exe')->where('id',$get['orderid'])->update(['staff_status'=>3,'start_time'=>time()]);
$this->_success('获取数据成功');
}else{
$this->_error('开始失败');
}
}
}
//员工排期订单的查询
public function timeorder(){
$get = $this->request->get();//获取子订单的iD
$order = new Orderexe();
$start = strtotime($get['ordertime']); //开始时间
$end = strtotime($get['ordertime'].'23:59:59'); //结束时间
$lists = $order->where('staff_id',$get['uid'])
->where('autotime','>=',$start)->where('autotime','<=',$end)
->order('autotime asc')
->select();
foreach ($lists as $list){
$custom=Db::name('order')->where('order_sn',$list['order_sn'])->find();
$list['address']= $custom['address'];
$list['lat']= $custom['lat'];
$list['lng']= $custom['lng'];
$goods=Db::name('goods')->where('id',$custom['goods_id'])->find();
$list['goods_name']= $goods['name'];
if(intval(($list['autotime']-time())/86400)>1){
$list['jldate']=intval(($list['autotime']-time())/86400);
}else{
$list['jldate']='-';
}
$list['autotime']=date("Y-m-d",$list['autotime']);
$adder=Db::name('user_address')->where('telephone',$custom['mobile'])->find();
if($adder){
$admin=Db::name('admin')->where('id',$adder['admin_id'])->find();
if($admin){
$list['admin_name']=$admin['name'];
$list['admin_phone']=$admin['phone'];
}else{
$list['admin_name']='-';
$list['admin_phone']='-';
}
}
if($list['addtime']==1){
$list['sw']='上午';
$list['sw_time']='8:00-12:00';
}else{
$list['sw']='下午';
$list['sw_time']='14:00-18:00';
}
}
$this->_success('获取数据成功', $lists);
}
//获取报销的类型
public function sement(){
$get = $this->request->get();//获取子订单的iD
$lists=Db::name('finance_type')->select(); //获取报销的类型
$this->_success('获取数据成功', $lists);
}
//增加保洁记录
public function addsement(){
$get = $this->request->get();//获取子订单的iD
$orderinfo=Db::name('order_exe')->where('id',$get['orderid'])->find();
$sement=Db::name('finance')->where('order_id',$get['orderid'])->find(); //查询报销订单重复
$data=[
'order_id'=>$get['orderid'],
'staff_id'=>$orderinfo['staff_id'],
'user_id'=>$orderinfo['staff_id'],
'status'=>1,
'pay'=>$get['money'],
'brand_id'=>$get['type'],
'remarks'=>$get['reak'],
'create_time'=>time()
];
if($sement){
$this->_error('报销单据已经重复');
}else{
$inser=Db::name('finance')->data($data)->insert();
if($inser){
$this->_success('增加报销单成功');
}
}
}
//根据订单获取报销的列表
public function listsement(){
$get = $this->request->get();
$where = [];
$where[] = ['order_id', '=', $get['order_id']];
if (isset($get['status']) && !empty($get['status'])) {
$where[] = ['status', '=', $get['status']];
}
$lists = Db::name('finance')->where($where)->select();
// 批量查询优化避免N+1查询
$orderIds = array_column($lists, 'order_id');
$brandIds = array_column($lists, 'brand_id');
// 批量获取订单信息
$orderExes = [];
if (!empty($orderIds)) {
$orderExes = Db::name('order_exe')
->where('id', 'in', $orderIds)
->column('*', 'id');
}
// 批量获取品牌信息
$financeTypes = [];
if (!empty($brandIds)) {
$financeTypes = Db::name('finance_type')
->where('id', 'in', $brandIds)
->column('*', 'id');
}
foreach ($lists as &$list){
// 安全获取订单信息
$order_exe = $orderExes[$list['order_id']] ?? [];
$list['order_sn'] = $order_exe['order_sn'] ?? '';
// 修复逻辑错误:= 改为 ==
if (isset($order_exe['addtime']) && $order_exe['addtime'] == 1) {
$list['sw'] = "8:00-12:00";
} else {
$list['sw'] = "14:00-16:00";
}
// 安全获取品牌信息
$type = $financeTypes[$list['brand_id']] ?? [];
$list['type_name'] = $type['name'] ?? '';
}
$this->_success('获取报销单数据', $lists);
}
//根据订单获取报销的列表
public function numberement(){
$get = $this->request->get();//获取子订单的iD
$lists=Db::name('finance')->where('order_id',$get['order_id'])->find();
$this->_success('获取报销单数据',$lists);
}
//员工修改报销的单据
public function editsement(){
$get = $this->request->get();//获取子订单的iD
$data=[
'order_id'=>$get['orderid'],
'status'=>1,
'pay'=>$get['money'],
'brand_id'=>$get['type'],
'remarks'=>$get['reak'],
'create_time'=>time()
];
$lists=Db::name('finance')->where('order_id',$get['orderid'])->data($data)->update();
$this->_success('修改报销单据成功',$lists);
}
//员工订单加时间
public function addtime(){
$get = $this->request->get();//获取子订单的iD
$info=Db::name('order_timeadd')->where('orderid',$get['orderid'])->find();
if($info){
$this->_error('订单已经加时');
}else{
$data=[
'orderid'=>$get['orderid'],
'status'=>1,
'minute'=>$get['minute'],
'remarks'=>$get['reak'],
'staff_id'=>$get['staff_id'],
'user_id'=>$get['staff_id'],
// 'pay_type'=>$get['type'],
'pay'=>$get['pay'],
'create_time'=>time()
];
$inser=Db::name('order_timeadd')->data($data)->insert();
if($inser){
$this->_success('增加服务加时成功');
}
}
}
//根据订单显示加时的详细详细
public function addtimeinfo(){
$get = $this->request->get();//获取子订单的iD
$result = StaffLogic::infoaddtim($get);
$this->_success('获取报销单数据',$result);
}
//更具订单显示详情
public function addtimenumber(){
$get = $this->request->get();//获取子订单的iD
$inof=Db::name('order_timeadd')->where('orderid',$get['orderid'])->find();
$this->_success('获取报销单数据',$inof);
}
//员工端口修改加时间
public function editaddtime(){
$get = $this->request->get();//获取子订单的iD
$update=Db::name('order_timeadd')->where('orderid',$get['orderid'])->where('status',1)->update(['minute'=>$get['minute'],'remarks'=>$get['reak'],'pay'=>$get['pay']]);
if($update){
$this->_success('修改成功',$update);
}else{
$this->_error('审核已经通过无法修改');
}
}
//根据订单ID 获取订单的基本信息
public function orderinfo(){
$get = $this->request->get();//获取到员工的ID
// dump($get);
// if (is_array($get['order_id'])) {
// $data = $get['order_id'];
// }else {
// $data = json_decode($get['order_id'], true);
// }
$orders=Db::name('order_timeadd')->where('orderid',$get['order_id'])->find(); //查询加时表格
$lists = Db::name('order_exe')->where('id',$get['order_id'])->find(); //查询子订单信息
if($lists){
$lists['autotime']=date("Y-m-d",$lists['autotime']);
if($lists['addtime']==1){
$lists['sw']='上午';
}else{
$lists['sw']='下午';
}
$goods= Db::name('order')->where('order_sn',$lists['order_sn'])->find(); //查询子订单信息
if($goods){
$lists['adder']= $goods['address'];
$lists['lat']= $goods['lat'];
$lists['lng']= $goods['lng'];
}else{
$lists['adder']= '-';
}
$goods=Db::name('goods')->where('id',$goods['goods_id'])->find();
$lists['goods_name']= $goods['name'];
$admin=Db::name('admin')->where('id',$lists['admin'])->find();
if($admin){
$lists['admin_name']=$admin['name'];
$lists['admin_phone']=$admin['phone'];
}else{
$lists['admin_name']='-';
$lists['admin_phone']='-';
}
if($orders){
$lists['add']=$orders['minute'];
}else{
$lists['add']=0;
}
}
$this->_success('获取数据成功', $lists);
}
//查询所有的订单接口
public function orderlist(){
$get = $this->request->get();//获取到员工的ID
$order = new Orderexe();
$where=[];
if($get['type']==1){
$date='year';
}else{
$date='month';
}
if($get['type']==3){
$where[]=['add', '>', 0];
$date='month';
}
if($get['type']==4){
$where[]=['account', '>', 0];
$date='month';
}
$lists = $order->where('staff_id',$get['staff_id'])->where($where)
->where('staff_status',3)
->whereTime('autotime',$date)
->order('autotime asc')
->select();
foreach ($lists as $list){
$custom=Db::name('order')->where('order_sn',$list['order_sn'])->find();
$list['address']= $custom['address'];
$list['lat']= $custom['lat'];
$list['lng']= $custom['lng'];
$goods=Db::name('goods')->where('id',$custom['goods_id'])->find();
$list['goods_name']= $goods['name'];
if(intval(($list['autotime']-time())/86400)>1){
$list['jldate']=intval(($list['autotime']-time())/86400);
}else{
$list['jldate']='-';
}
$list['autotime']=date("Y-m-d",$list['autotime']);
$adder=Db::name('user_address')->where('telephone',$custom['mobile'])->find();
if($adder){
$admin=Db::name('admin')->where('id',$adder['admin_id'])->find();
if($admin){
$list['admin_name']=$admin['name'];
$list['admin_phone']=$admin['phone'];
}else{
$list['admin_name']='-';
$list['admin_phone']='-';
}
}
if($list['addtime']==1){
$list['sw']='上午';
$list['sw_time']='8:00-12:00';
}else{
$list['sw']='下午';
$list['sw_time']='14:00-18:00';
}
}
$this->_success('获取数据成功', $lists);
}
public function staff_qjia(){
$get = $this->request->get();//获取提交的基本信息
$order=Db::name('order_exe')->where('autotime','>=',$get['start_time'])->where('autotime','<=',$get['end_time'])->where('staff_id',$get['staff_id'])->select(); //统计今天的订单
if($order){
$this->_error('无法请假有订单',$order);
}else{
$lent=Db::name('leave')->where('user_id',$get['staff_id'])->where('time','>=',$get['start_time'])->where('time','<=',$get['end_time'])->select();
if($lent){
$this->_error('请假数据重复',$lent);
}else{
$this->_success('',StaffLogic::leaveadd($get));
}
}
}
public function count(){
$order = new Orderexe();
$get = $this->request->get();//获取提交的基本信息
$today = date('Y-m-d');
// 计算明天的日期
$tomorrow = date('Y-m-d', strtotime($today . ' +1 day'));
$tomorrows = date('Y-m-d', strtotime($today . ' +2 day'));
$data['toder'] = $order->where('staff_id',$get['staff_id'])
->where('staff_status',0)
->whereTime('autotime', 'between', ["$today 00:00:00", "$tomorrow 23:59:59"])
->order('autotime desc')
->count();
$data['ardfs'] = $order->where('staff_id',$get['staff_id'])
->whereTime('autotime', 'between', ["$today 00:00:00", "$tomorrow 23:59:59"])
->where('staff_status',1)
->order('autotime desc')
->count();
$data['fwz'] = $order->where('staff_id',$get['staff_id'])
->where('staff_status',2)
->order('autotime desc')
->count();
$data['fwywc'] = $order->where('staff_id',$get['staff_id'])
->where('staff_status',3)
->whereTime('autotime','month')
->count();
$data['ycorder'] = $order->where('staff_id',$get['staff_id'])
->where('abnormal',1)
->whereTime('autotime','month')
->count();
$this->_success('获取数据成功',$data);
}
}

View File

@@ -0,0 +1,402 @@
<?php
namespace app\api\controller;
use app\api\logic\StaffgoodsLogic;
use app\common\server\UrlServer;
use app\api\model\{Orderexe};
use think\Db;
class Staffgoods extends ApiBase
{
public $like_not_need_login = ['goods_type','godds_list','addgoods','usergoods','staff_del','user_leave','user_addorder','user_finance','order_images','up_imgs','get_imgs','sub_orderlist','counts','order_list','orderinfos','order_sever','goods_info','order_wages','orderinfo_wages'];
//获取物料商品的分类
public function goods_type()
{
$goods_type=Db::name('material_type')->select();
return $this->_success('获取数据成功', $goods_type);
}
//获取物料的商品信息\
public function godds_list(){
$get = $this->request->get();//获取到员工的ID
$lists=StaffgoodsLogic::godds_list($get);
return $this->_success('获取数据成功', $lists);
}
public function goods_info(){
$id = $this->request->get('id');//获取到员工的ID
$lists=StaffgoodsLogic::goods_info($id);
return $this->_success('获取数据成功', $lists);
}
//员工申请物料
public function addgoods(){
$get = $this->request->get();//接受传递过来的参数
$lists=StaffgoodsLogic::addgoods($get);
return $this->_success('申请成功等待审核');
}
//我的物料申请记录
public function usergoods(){
$get = $this->request->get();//接受传递过来的参数
$data=Db::name('erp_staff')
->where('status',$get['status'])
->where('staff_id',$get['staff_id'])
->page($get['page'],$get['pageSize'])
->select();
foreach ($data as $key => $level){
$goods=Db::name('epr')->where('id',$level['goods_id'])->find();
$data[$key]['name']=$goods['name'];
$data[$key]['images']=UrlServer::getFileUrl($goods['abs_avatar']);;
$data[$key]['time']=date('Y-m-d H:i:s',$data[$key]['create_time']);
}
return $this->_success('获取数据成功过',$data);
}
//删除物料申请
public function staff_del(){
$get = $this->request->get();//接受传递过来的参数\
$del=Db::name('erp_staff')->where('id',$get['id'])->delete();
return $this->_success('删除成功');
}
//我的请假的数据
public function user_leave(){
$get = $this->request->get();//接受传递过来的参数
$data=Db::name('leave')
->where('status',0)
->where('user_id',$get['staff_id'])
->page($get['page'],$get['pageSize'])
->select();
foreach ($data as $key => $level){
$data[$key]['time']=date('Y-m-d',$data[$key]['time']);
if($data[$key]['addtime']==1){
$data[$key]['sw']='上午';
}else{
$data[$key]['sw']='下午';
}
}
return $this->_success('获取数据成功过',$data);
}
//我的加时订单显示列表
public function user_addorder(){
$get = $this->request->get();//接受传递过来的参数
$lists=Db::name('order_timeadd')
->where('status',$get['status'])
->where('staff_id',$get['staff_id'])
->page($get['page'],$get['pageSize'])
->select();
foreach ($lists as $k => $v){
$order=Db::name('order_exe')->where('id',$lists[$k]['orderid'])->field('order_sn,addtime')->find(); //获取子订单信息
if($order){
$order_info=Db::name('order')->where('order_sn',$order['order_sn'])->find();
if($order_info){
$lists[$k]['order_sn']=$order_info['order_sn'];
$lists[$k]['name']=$order_info['consignee'];
$lists[$k]['phone']=$order_info['mobile'];
$lists[$k]['address']= $order_info['address'];
$lists[$k]['lat']= $order_info['lat'];
$lists[$k]['lng']= $order_info['lng'];
}
$goods=Db::name('goods')->where('id',$order_info['goods_id'])->find();
$lists[$k]['goods_name']= $goods['name'];
if($order['addtime']==1){
$lists[$k]['sw']='上午';
$lists[$k]['sw_time']='8:00-12:00';
}else{
$lists[$k]['sw']='下午';
$lists[$k]['sw_time']='14:00-18:00';
}
}
}
return $this->_success('获取数据成功',$lists);
}
public function user_finance(){
$get = $this->request->get();//接受传递过来的参数
$lists=Db::name('finance')
->where('status',$get['status'])
->where('staff_id',$get['staff_id'])
->page($get['page'],$get['pageSize'])
->select();
foreach ($lists as $k => $v){
$order=Db::name('order_exe')->where('id',$lists[$k]['order_id'])->find(); //获取子订单信息
$order_info=Db::name('order')->where('order_sn',$order['order_sn'])->find();
$lists[$k]['order_sn']=$order_info['order_sn'];
$lists[$k]['name']=$order_info['consignee'];
$lists[$k]['phone']=$order_info['mobile'];
$goods=Db::name('goods')->where('id',$order_info['goods_id'])->find();
$lists[$k]['goods_name']= $goods['name'];
$lists[$k]['address']= $order_info['address'];
$lists[$k]['lat']= $order_info['lat'];
$lists[$k]['lng']= $order_info['lng'];
if($order['addtime']==1){
$lists[$k]['sw']='上午';
$lists[$k]['sw_time']='8:00-12:00';
}else{
$lists[$k]['sw']='下午';
$lists[$k]['sw_time']='14:00-18:00';
}
}
return $this->_success('获取数据成功过',$lists);
}
public function get_imgs(){
$input = input();
if(empty($input['order_id'])){
$this->_error('order_id 不能为空');
}
$data = Db::name('user_order_imges')->where('order_id',$input['order_id'])->find();
if(!$data){
return $this->_success('');
}
$data['image1'] = json_decode($data['image1'],true);
$data['image2'] = json_decode($data['image2'],true);
$data['image3'] = json_decode($data['image3'],true);
foreach ($data['image1'] as $k=>$v){
$data['image1'][$k]['url'] = 'https://web.dulmao.com'.$v['url'];
}
foreach ($data['image2'] as $k=>$v){
$data['image2'][$k]['url'] = 'https://web.dulmao.com'.$v['url'];
}
foreach ($data['image3'] as $k=>$v){
$data['image3'][$k]['url'] = 'https://web.dulmao.com'.$v['url'];
}
return $this->_success('保存成功',$data);
}
public function up_imgs(){
$input = input();
if(empty($input['data'])){
$this->_error('请上传图片');
}
$imgs = json_decode($input['data'],true);
$img1 = $imgs['img1'];
$img2 = $imgs['img2'];
$img3 = $imgs['img3'];
foreach ($img1 as $k=>$v){
$img1[$k]['url'] = str_replace('https://web.dulmao.com','',$v['url']);
}
foreach ($img2 as $k=>$v){
$img2[$k]['url'] = str_replace('https://web.dulmao.com','',$v['url']);
}
foreach ($img3 as $k=>$v){
$img3[$k]['url'] = str_replace('https://web.dulmao.com','',$v['url']);
}
$data = [
'image1'=>json_encode($img1),
'image2'=>json_encode($img2),
'image3'=>json_encode($img3),
'textarea'=>$input['textarea'],
'order_id'=>$input['order_id']
];
$info = Db::name('user_order_imges')->where('order_id',$input['order_id'])->find();
if($info){
Db::name('user_order_imges')->where('order_id',$input['id'])->update($data);
Db::name('order_exe')->where('id',$input['id'])->update(['is_images'=>1]);
}else{
Db::name('user_order_imges')->insert($data);
Db::name('order_exe')->where('id',$input['id'])->update(['is_images'=>1]);
}
return $this->_success('保存成功');
}
//上传服务的图片内容
public function order_images(){
$file = request()->file('file');
// 移动到框架应用根目录/public/uploads/ 目录下
if($file){
$info = $file->move(ROOT_PATH . '/uploads/webimges');
if($info){
// 成功上传后 获取上传信息
// 输出 jpg
// echo $info->getExtension();
// // 输出 20160820/42a79759f284b767dfcb2a0197904287.jpg
// echo $info->getSaveName();
// // 输出 42a79759f284b767dfcb2a0197904287.jpg
// echo $info->getFilename();
return json(['code'=>200,'data'=>'https://web.dulmao.com/uploads/webimges/'.$info->getSaveName()]);
}else{
return json(['code'=>0,'msg'=>$file->getError()]);
}
}
$this->_error("请上传文件");
}
//根据主订单编号获取到子订单
public function sub_orderlist(){
$get = $this->request->get();//接受传递过来的参数
$order = new Orderexe();
$lists =$order->where('order_sn',$get['order_sn'])
->where('staff_status',$get['status'])
->order('autotime desc')
->select();
foreach ($lists as $list){
$custom=Db::name('order')->where('order_sn',$list['order_sn'])->find();
$list['address']= $custom['address'];
$list['lat']= $custom['lat'];
$list['lng']= $custom['lng'];
$goods=Db::name('goods')->where('id',$custom['goods_id'])->find();
$list['goods_name']= $goods['name'];
if(intval(($list['autotime']-time())/86400)>1){
$list['jldate']=intval(($list['autotime']-time())/86400);
}else{
$list['jldate']='-';
}
$adder=Db::name('user_address')->where('telephone',$custom['mobile'])->find();
if($adder){
$admin=Db::name('admin')->where('id',$adder['admin_id'])->find();
if($admin){
$list['admin_name']=$admin['name'];
$list['admin_phone']=$admin['phone'];
}else{
$list['admin_name']='-';
$list['admin_phone']='-';
}
}
if($list['addtime']==1){
$list['sw']='上午';
$list['sw_time']='8:00-12:00';
}else{
$list['sw']='下午';
$list['sw_time']='14:00-18:00';
}
//查询其他用户
$list['autotime']=date("Y-m-d",$list['autotime']);
}
$this->_success('获取数据成功', $lists);
}
//主订单下面的子订单
public function counts(){
$order = new Orderexe();
$get = $this->request->get();//接受传递过来的参数
$data['toder'] = $order->where('order_sn',$get['order_sn'])
->where('staff_status',0)
->order('autotime desc')
->count();
$data['ardfs'] = $order->where('order_sn',$get['order_sn'])
->where('staff_status',1)
->order('autotime desc')
->count();
$data['fwz'] = $order->where('order_sn',$get['order_sn'])
->where('staff_status',2)
->count();
$data['fwywc'] = $order->where('order_sn',$get['order_sn'])
->where('staff_status',3)
->count();
$data['ycorder'] = $order->where('order_sn',$get['order_sn'])
->where('abnormal',1)
->count();
$this->_success('获取数据成功',$data);
}
//根据订单ID显示订单详情
public function orderinfos(){
$get = $this->request->get();//接受传递过来的参数
$orderinfo=Db::name('order')->where('id',$get['order_id'])->find();
$goods=Db::name('goods')->where('id',$orderinfo['goods_id'])->find();
$orderinfo['goods_name']= $goods['name'];
$orderinfo['create_time']=date('Y-m-d H:i:s', $orderinfo['create_time']);
$orderinfo['goods_images']=UrlServer::getFileUrl($goods['image']);
$this->_success('获取数据成功',$orderinfo);
}
//客户管家的主订单
public function order_list(){
$get = $this->request->get();//接受传递过来的参数
$staff=Db::name('staff')->where('id',$get['staff_id'])->field('mobile')->find();
$admin=Db::name('admin')->where('phone',$staff['mobile'])->find();
$lists =Db::name('order')->where('admin_id',$admin['id'])
->where('pay_status',1)
->limit(10)
->order('id desc')
->select();
foreach ($lists as $k => $v){
$goods=Db::name('goods')->where('id',$lists[$k]['goods_id'])->find();
$lists[$k]['goods_name']= $goods['name'];
$lists[$k]['slect_order']=Db::name('order_exe')->where('order_sn',$lists[$k]['order_sn'])->where('staff_status',3)->count();
$lists[$k]['time_payorder']= date('Y-m',$lists[$k]['create_time']);
$lists[$k]['dai_order']= $lists[$k]['number']-$lists[$k]['code'];
}
$this->_success('获取数据成功',$lists);
}
//订单的评价
public function order_sever(){
$get = $this->request->get();//接受传递过来的参数
$order=Db::name('order_exe')->where('id',$get['order_id'])->find(); //获取子订单的信息
$user=Db::name('order')->where('order_sn',$order['order_sn'])->find(); //获取主订单信息
$data=[
'name'=> $user['consignee'],
'phone'=> $user['mobile'],
'adders'=> $user['address'],
'order_id'=>$get['order_id'],
'staff_id'=>$order['staff_id'],
'score'=>$get['score'],
'eceives'=>$get['infoReceives'],
'eceivesd'=>$get['infoReceivesd'],
'content'=>$get['textareaValue'],
'create_time'=>time()
];
$where=Db::name('orderexe_evaluate')->where('order_id',$get['order_id'])->find();
if($where){
$this->_success('已经提交评价');
}else{
$inser=Db::name('orderexe_evaluate')->data($data)->insert();
$this->_success('评价内容提交成功');
}
}
//员工的工资单
public function order_wages(){
$get = $this->request->get();//接受传递过来的参数
$lists=StaffgoodsLogic::order_wages($get);
return $this->_success('获取数据成功', $lists);
}
//员工年卡订单
public function orderinfo_wages(){
$get = $this->request->get();//接受传递过来的参数
$lists=StaffgoodsLogic::orderinfo_wages($get);
return $this->_success('获取数据成功', $lists);
}
}

View File

@@ -0,0 +1,38 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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);
}
}

View File

@@ -0,0 +1,94 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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();
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace app\api\controller;
class Test extends ApiBase
{
public $like_not_need_login = ['sms'];
public function sms()
{
}
}

View File

@@ -0,0 +1,418 @@
<?php
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();
$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();
$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();
$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($result['code']) {
$this->_success($result['msg']);
}else{
$this->_error($result['msg']);
}
}
/**
* 判断会员是否有设置支付密码
*/
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')
->leftJoin('user u', 'u.id=ut.transfer_to_id')
->where('ut.transfer_from_id', $this->user_id)
->order('ut.create_time', 'desc')
->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('设置失败');
}
}
public function staffinfo(){
$result = Db::name('staff')->where('user_id', $this->user_id)->where('onwork',1)->find();
if($result){
$data['ordermonth']=Db::name('order_exe')->where('staff_id', $result['id'])->whereTime('autotime', 'month')->where('status',2)->count();
$data['finish']=Db::name('order_exe')->where('staff_id', $result['id'])->whereTime('autotime', 'month')->where('status',2)->where('addtime',1)->sum('add')/60; //上午加时间
$data['notfinish']=Db::name('order_exe')->where('staff_id', $result['id'])->whereTime('autotime', 'month')->where('status',2)->where('addtime',2)->sum('add')/60; //下午加时
$data['access']=Db::name('order_exe')->where('staff_id', $result['id'])->whereTime('autotime', 'month')->where('status',2)->sum('account'); //下午加时
$data['Integral']=$result['number'];
$data['abnormal']=Db::name('order_exe')->where('staff_id', $result['id'])->whereTime('autotime', 'month')->where('status',4)->count();
// $data=[
// 'ordermonth'=>$ordermonth
// ];
return $this->_success('是员工信息',$data);
}else{
return $this->_error('不是员工信息');
}
}
public function addtimeinfo(){
$post = $this->request->post();
$result = Db::name('order_exe')->where('id', $post['id']['id'])->find();
return $this->_success('获取成功', $result);
}
public function addtime(){
$post = $this->request->post();
$add = Db::name('order_exe')->where('id', $post['id']['id'])->find();
if($add['add']>0){
return $this->_error('已经申请加时');
}
$result = Db::name('order_exe')->where('id', $post['id']['id'])->update(['add'=>$post['money']]);
return $this->_success('加时间成功', $result);
}
public function accountinfo(){
$post = $this->request->post();
$result = Db::name('order_exe')->where('id', $post['id']['id'])->find();
return $this->_success('获取成功', $result);
}
public function addaccount(){
$post = $this->request->post();
$add = Db::name('order_exe')->where('id', $post['id']['id'])->find();
if($add['account']>0){
return $this->_error('已经申请报销');
}
$result = Db::name('order_exe')->where('id', $post['id']['id'])->update(['account'=>$post['money']]);
return $this->_success('加时间成功', $result);
}
public function staffsel(){
$post = $this->request->post();
$start = strtotime($post['day'][0]); //开始时间
$end = strtotime($post['day'][1].'23:59:59'); //结束时间
$result = Db::name('staff')->where('user_id', $this->user_id)->where('onwork',1)->find();
if($result){
$data['ordermonth']=Db::name('order_exe')->where('staff_id', $result['id'])->where('autotime','>=',$start)->where('autotime','<=',$end)->where('status',2)->count();
$data['finish']=Db::name('order_exe')->where('staff_id', $result['id'])->where('autotime','>=',$start)->where('autotime','<=',$end)->where('status',2)->where('addtime',1)->sum('add')/60; //上午加时间
$data['notfinish']=Db::name('order_exe')->where('staff_id', $result['id'])->where('autotime','>=',$start)->where('autotime','<=',$end)->where('status',2)->where('addtime',2)->sum('add')/60; //下午加时
$data['access']=Db::name('order_exe')->where('staff_id', $result['id'])->where('autotime','>=',$start)->where('autotime','<=',$end)->where('status',2)->sum('account'); //下午加时
$data['Integral']=$result['number'];
$data['abnormal']=Db::name('order_exe')->where('staff_id', $result['id'])->where('autotime','>=',$start)->where('autotime','<=',$end)->where('status',4)->count();
return $this->_success('获取数据成功',$data);
}
}
}

View File

@@ -0,0 +1,145 @@
<?php
namespace app\api\controller;
use app\api\logic\UserAddressLogic;
use think\Db;
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;
$adder=Db::name('user_address')->whereLike('telephone',$post['telephone'])->find(); //判断电话号码存在
if($adder){
$adderss=Db::name('user_address')->whereLike('telephone',$post['telephone'])->update(['user_id'=>$user_id]);
$this->_success('添加成功', $adderss);
}
$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);
}
}

View File

@@ -0,0 +1,28 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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);
}
}

View File

@@ -0,0 +1,63 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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('', ['config' => $result['data']]);
}
$this->_success('', ['config' => $result['data']]);
}
public function index()
{
WeChatLogic::index();
}
}

View File

@@ -0,0 +1,340 @@
<?php
namespace app\api\controller;
use app\api\logic\WebmasterLogic;
use app\common\server\UrlServer;
use think\Db;
class Webmaster extends ApiBase
{
public $like_not_need_login = ['staffList','Leaveapproval','leavethroug','leavethroug','reject','punishlists','punishthroug','punishreject','material','materialthroug','materialreject','Scheduling','occupy','occupy_del'];
/**
* note 获取站长下面的员工
* create_time 2020/10/21 19:05
*/
public function staffList(){
$param = $this->request->get();
$data = Db::name('staff')
->alias('s1')
->field('s1.*, s2.*')
->where('s1.id', $param['id'])
->where('s2.onwork',1)
->join('staff s2', 's1.grouping_id = s2.grouping_id')
->select();
$this->_success('获取数据成功', $data);
}
/**
* note 请假审批
* create_time 2020/10/21 19:05
*/
public function Leaveapproval(){
$param = $this->request->get();
$data = Db::name('staff')
->alias('s1')
->field('s1.*, s2.*')
->where('s1.id', $param['id'])
->where('s2.onwork',1)
->join('staff s2', 's1.grouping_id = s2.grouping_id')
->select();
if($data){
$ids = array_column($data, 'id');
$leave=Db::name('leavesd')
->whereIN('staff_id',$ids)
->where('status',$param['status'])
->order('id', 'asc')
->page($param['page'], $param['limt'])
->select();
foreach ($leave as &$item){
$item['time']=date('Y-m-d',$item['time']);
$item['create_time']=date('Y-m-d H:i:s',$item['create_time']);
}
$this->_success('获取数据成功', $leave);
}else{
$this->_error('获取数据失败');
}
}
/**
* note 请假审批通过
* create_time 2020/10/21 19:05
*/
public function leavethroug(){
$param = $this->request->post();
$data=Db::name('leavesd')->where('id',$param['id'])->update(['status'=>1]);
$this->_success('审批成功');
}
/**
* note 驳回请假
* create_time 2020/10/21 19:05
*/
public function reject(){
$param = $this->request->post();
$data=Db::name('leavesd')->where('id',$param['id'])->update(['status'=>2,'refuse'=>$param['refuse']]);
$this->_success('修改成功');
}
/**
* note 处罚的列表
* create_time 2020/10/21 19:05
*/
public function punishlists(){
$param = $this->request->get();
$data = Db::name('staff')
->alias('s1')
->field('s1.*, s2.*')
->where('s1.id', $param['id'])
->where('s2.onwork',1)
->join('staff s2', 's1.grouping_id = s2.grouping_id')
->select();
if($data){
$ids = array_column($data, 'id');
$punish=Db::name('fine')
->whereIN('staff_id',$ids)
->where('status',$param['status'])
->order('id', 'asc')
->page($param['page'], $param['limt'])
->select();
foreach($punish as &$item){
$item['create_time']=date("Y-m-d H:i:s");
$user=Db::name('order_exe')->where('id',$item['order_id'])->find();
$item['user_name']=$user['name'];
$item['user_phone']=$user['phone'];
$order=Db::name('order')->where('order_sn',$user['order_sn'])->find();
$item['user_adder']=$order['address'];
$staff=Db::name('staff')->where('id',$item['staff_id'])->find();
$item['staff_name']= $staff['name'];
$item['staff_phone']= $staff['mobile'];
}
$this->_success('获取数据成功', $punish);
}else{
$this->_error('网络错误');
}
}
/**
* note 审批处罚通过
* create_time 2020/10/21 19:05
*/
public function punishthroug(){
$param = $this->request->post();
$data=Db::name('fine')->where('id',$param['id'])->update(['status'=>1]);
$this->_success('审批成功');
}
/**
* note 驳回处罚的审核
* create_time 2020/10/21 19:05
*/
public function punishreject(){
$param = $this->request->post();
$data=Db::name('fine')->where('id',$param['id'])->update(['status'=>2]);
$this->_success('修改成功');
}
/**
* note 物料的申请列表
* create_time 2020/10/21 19:05
*/
public function material(){
$param = $this->request->post();
$param = $this->request->get();
$data = Db::name('staff')
->alias('s1')
->field('s1.*, s2.*')
->where('s1.id', $param['id'])
->where('s2.onwork',1)
->join('staff s2', 's1.grouping_id = s2.grouping_id')
->select();
if($data){
$ids = array_column($data, 'id');
$material=Db::name('erp_staff')
->whereIN('staff_id',$ids)
->where('status',$param['status'])
->order('id', 'asc')
->page($param['page'], $param['limt'])
->select();
foreach ($material as &$item){
$erp_goods=Db::name('epr')->where('id',$item['goods_id'])->find();
if($erp_goods){
$item['goods_name']= $erp_goods['name'];
$item['goods_img']=UrlServer::getFileUrl($erp_goods['abs_avatar']);
}else{
$item['goods_name']='-';
$item['goods_img']='-';
}
}
$this->_success('获取数据成功', $material);
}
}
/**
* note 无聊审批通过
* create_time 2020/10/21 19:05
*/
public function materialthroug(){
$param = $this->request->post();
$data=Db::name('erp_staff')->where('id',$param['id'])->update(['status'=>2]);
$this->_success('审批成功');
}
/**
* note 物料驳回申请
* create_time 2020/10/21 19:05
*/
public function materialreject(){
$param = $this->request->post();
$data=Db::name('erp_staff')->where('id',$param['id'])->update(['status'=>3,'reason'=>$param['reason']]);
$this->_success('修改成功');
}
/**
* note 员工排班
* create_time 2020/10/21 19:05
*/
public function Scheduling(){
$param = $this->request->get();
if (!isset($param['id']) || empty($param['id'])) {
throw new Exception('员工ID不能为空');
}
$where=[];
//判断检索框
$selval = trim($param['selval'] ?? '');
if (!empty($selval)) {
if (preg_match('/^1[3-9]\d{9}$/', $selval)) {
$where[] = ['s2.mobile', '=', $selval];
} else {
$where[] = ['s2.name', 'LIKE', '%' . $selval . '%'];
}
} else {
$where = [];
}
//判断时间的检索
if($param['startDate']){
$startTime = strtotime($param['startDate']); //开始时间
$endTime = strtotime($param['startDate'] . ' 23:59:59'); //结束时间
}else{
$startTime = strtotime(date('Y-m-d'));
$endTime = strtotime(date('Y-m-d') . ' 23:59:59');
}
$data = Db::name('staff')
->alias('s1')
->field('s1.*, s2.*')
->where('s1.id', $param['id'])
->where('s2.onwork',1)
->where($where)
->join('staff s2', 's1.grouping_id = s2.grouping_id')
->select();
foreach ($data as &$item){
$item['sw_order']=Db::name('order_exe')
->where('staff_id',$item['id'])
->whereBetween('autotime', [$startTime, $endTime])
->field('id')
->where('addtime',1)
->find();
$item['xw_order']=Db::name('order_exe')
->where('staff_id',$item['id'])
->whereBetween('autotime', [$startTime, $endTime])
->field('id')
->where('addtime',2)
->find();
$item['sw_zy']=Db::name('leave')
->where('user_id',$item['id'])
->whereBetween('time', [$startTime, $endTime])
->field('id')
->where('addtime',1)
->find();
$item['xw_zy']=Db::name('leave')
->where('user_id',$item['id'])
->whereBetween('time', [$startTime, $endTime])
->field('id')
->where('addtime',2)
->find();
$item['sw_qj']=Db::name('leavesd')
->where('staff_id',$item['id'])
->whereBetween('time', [$startTime, $endTime])
->where('status',1)
->where('addtime',1)
->field('id')
->find();
$item['xw_qj']=Db::name('leavesd')
->where('staff_id',$item['id'])
->whereBetween('time', [$startTime, $endTime])
->field('id')
->where('status',1)
->where('addtime',2)
->find();
}
$this->_success('获取数据成功',$data);
}
/**
* note 员工占用列表
* create_time 2020/10/21 19:05
*/
public function occupy(){
$param = $this->request->get();
if (!isset($param['id']) || empty($param['id'])) {
throw new Exception('站长ID不能为空');
}
$where=[];
$selval = trim($param['selval'] ?? '');
if (!empty($selval)) {
if (preg_match('/^1[3-9]\d{9}$/', $selval)) {
$where[] = ['phone','=',$selval];
} else {
$where[] = ['name', 'LIKE', '%' . $selval . '%'];
}
} else {
$where = [];
}
//检索框
$data = Db::name('staff')
->alias('s1')
->field('s1.*, s2.*')
->where('s1.id', $param['id'])
->where('s2.onwork',1)
->join('staff s2', 's1.grouping_id = s2.grouping_id')
->select();
if($data){
$ids = array_column($data, 'id');
$occupy=Db::name('leave')
->whereIN('user_id',$ids)
->where($where)
->order('id', 'desc')
->page($param['page'], $param['limt'])
->select();
foreach ($occupy as &$item){
$item['time']=date('Y-m-d',$item['time']);
$item['create_time']=date('Y-m-d H:i:s',$item['create_time']);
$admin=Db::name('admin')->where('id',$item['admin_id'])->find();
if($admin){
$item['admin_name']=$admin['name'];
}else{
$item['admin_name']='-';
}
$type=Db::name('leave_statype')->where('id',$item['type'])->find();
if($type){
$item['type_name']=$type['name'];
}else{
$item['type_name']='-';
}
}
}
$this->_success('修改成功', $occupy);
}
/**
* note 删除占用数据
* create_time 2020/10/21 19:05
*/
public function occupy_del(){
$param = $this->request->get();
$data=Db::name('leave')->where('id',$param['id'])->delete();
$this->_success('删除数据成功');
}
}

View File

@@ -0,0 +1,68 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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));
}
}

View File

@@ -0,0 +1,99 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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;
}
}

View File

@@ -0,0 +1,60 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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)
->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;
}
}

View File

@@ -0,0 +1,486 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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.*')
->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,
];
}
return $list;
}
public static function list_comost($get){
$staff=Db::name('staff')->where('id',$get['staff_id'])->find();
$admin=Db::name('admin')->where('phone',$staff['mobile'])->find();
$result = Db::name('user_address')->where('admin_id',$admin['id'])->select();
foreach ($result as $key => $k) {
if(is_null($result[$key]['brand_id'])){
$result[$key]['brand_name']='-';
}else{
$brand=Db::name('staffchannel')->where('id',$result[$key]['brand_id'])->find();
$result[$key]['brand_name']=$brand['name'];
}
if(is_null($result[$key]['label_id'])){
$result[$key]['label_name']='-';
}else{
$brand=Db::name('user_label')->where('id',$result[$key]['label_id'])->find();
if($brand){
$result[$key]['label_name']=$brand['name'];
}
}
}
return $result;
}
//增加跟进的内容
public static function follow_comost($get){
$result = Db::name('custom')
->where('custom_id',$get['id'])
->page($get['page'], $get['limit'])
->order('id desc')
->select();
foreach ($result as $key => $k) {
$result[$key]['time']=date('Y-m-d H:i:s',$result[$key]['create_time']);
$admin=Db::name('admin')->where('id',$result[$key]['admin_id'])->find();
if($admin){
$result[$key]['admin_name']=$admin['name'];
}
}
return $result;
}
public static function comost_add($get){
$staff=Db::name('staff')->where('id',$get['staff_id'])->find();
$admin=Db::name('admin')->where('phone',$staff['mobile'])->find();
$data=[
'admin_id'=>$admin['id'],
'connect' =>$get['reak'],
'custom_id'=>$get['orderid'],
'create_time'=>time()
];
return Db::name('custom')->data($data)->insert();
}
public static function notice(){
$lists=Db::name('staff_notice')->order('id asc')->limit(2)->select();
foreach ($lists as &$item){
$time1=time();
$daysDiff = abs(($time1 - $item['time']) / 86400);
if($daysDiff>10){
$item['date']=10;
}else{
$item['date']=intval($daysDiff);
}
}
return $lists;
}
public static function position(){
return Db::name('recruitype')->select();
}
public static function vode_type(){
return Db::name('video_type')->select();
}
public static function position_list($get){
$where=[];
if (isset($get['title']) && $get['title']) {
$where[] = ['name', 'like', '%' . $get['title'] . '%'];
}
if (isset($get['value']) && $get['value'] != '') {
$where[] = ['type_id', '=', $get['value']];
}
$data=Db::name('recrui')
->where($where)
->page($get['page'], $get['limit'])
->order('id desc')
->select();
foreach ($data as &$item) {
$type=Db::name('recruitype')->where('id',$item['type_id'])->find(); //获取岗位
$item['type_name']=$type['zpname'];
$salary=Db::name('recrui_salary')->where('id',$item['tment_id'])->find();
$item['salary_name']=$salary['name'];
$branch=Db::name('staff_group')->where('id',$item['branch_id'])->find();
$item['branch_name']=$branch['name'];
}
return $data;
}
public static function video_list($get){
$where=[];
if (isset($get['title']) && $get['title']) {
$where[] = ['name', 'like', '%' . $get['title'] . '%'];
}
if (isset($get['value']) && $get['value'] != '') {
$where[] = ['type_id', '=', $get['value']];
}
$data=Db::name('video')
->where($where)
->page($get['page'], $get['limit'])
->order('id desc')
->select();
foreach ($data as &$item) {
$type=Db::name('video_type')->where('id',$item['type_id'])->find(); //获取岗位
$item['type_name']=$type['title'];
$item['images']= UrlServer::getFileUrl($item['image']);
}
return $data;
}
public static function video_info($get){
return Db::name('video')->where('id',$get['id'])->find();
}
public static function user_wages($get){
$now = time();
$start_of_last_month = strtotime(date('Y-m-01 00:00:00', strtotime('-1 month', $now)));
$end_of_last_month = strtotime("last day of last month",$now); //上一个月结束时间搓
//总订单统计
$data['order']=Db::name('order_exe')
->where('staff_id',$get['user_id'])
->where('staff_status',3)
->whereTime('autotime','last month')
->count();
//上午的订单
$data['sw_orders']=Db::name('order_exe')
->where('staff_id',$get['user_id'])
->where('addtime',2)
->where('staff_status',3)
->whereTime('autotime','last month')
->count();
//下午的订单
$data['xw_orders']=Db::name('order_exe')
->where('staff_id',$get['user_id'])
->where('addtime',2)
->where('staff_status',3)
->whereTime('autotime','last month')
->count();
//报销的金额
$data['sement']=Db::name('finance')
->where('user_id',$get['user_id'])
->where('status',2)
->whereTime('create_time','last month')
->sum('pay');
//上午加时
$data['swaddtime']=Db::name('order_exe a')
->join('order_timeadd u','u.orderid=a.id')
->where('a.staff_id',$get['user_id'])
->where('a.autotime','>=',$start_of_last_month)
->where('a.autotime','<=',$end_of_last_month)
->where('u.status',2)
->where('a.addtime',1)
->sum('minute');
//下午加时
$data['xwaddtime']=Db::name('order_exe a')
->join('order_timeadd u','u.orderid=a.id')
->where('a.staff_id',$get['user_id'])
->where('a.autotime','>=',$start_of_last_month)
->where('a.autotime','<=',$end_of_last_month)
->where('u.status',2)
->where('a.addtime',2)
->sum('minute');
//请假代码
$data['leave']=Db::name('leavesd')
->where('staff_id',$get['user_id'])
->whereTime('time','last month')
->where('addtime','<>',2)
->count();
$number=Db::name('leavesd')
->where('staff_id',$get['user_id'])
->whereTime('time','last month')
->where('addtime',2)
->count();
$data['leaves']= $data['leave']/2+$number;
$data['fine']=Db::name('fine')
->where('staff_id',$get['user_id'])
->whereTime('create_time','last month')
->sum('score');
$data['abnormal']=Db::name('order_exe')
->where('staff_id',$get['user_id'])
->where('staff_status',3)
->where('abnormal',1)
->whereTime('autotime','last month')
->count();
$data['annual']=Db::name('order_abnormal')
->where('staff_id',$get['user_id'])
->whereTime('create_time','last month')
->count();
// 假设当前日期是2023-03-15
$current_date = date('Y-m-d');
// 获取上个月的第一天
$first_day_of_last_month = date('Y-m-01', strtotime($current_date . ' -1 month'));
// 获取上个月的最后一天
$last_day_of_last_month = date('Y-m-t', strtotime($first_day_of_last_month));
// 计算天数
$days_in_last_month = date('j', strtotime($last_day_of_last_month)) - date('j', strtotime($first_day_of_last_month)) + 1;
$data['lastdate']=$days_in_last_month-$data['leaves'];
return $data;
}
public static function user_wages_add($get){
$now = time();
// 获取上个月的时间戳
$lastMonthTimestamp = strtotime('-1 month', $now);
$staff=Db::name('staff')->where('id',$get['user_id'])->find();
$staff_uages=Db::name('staff_wages')
->where('staff_id',$get['user_id'])
->whereTime('last_addtime','last month')
->find();
if($staff_uages){
return -1;
}
$last_month_month = date('m') - 1;
if($last_month_month==0){
$last_month_month =12;
}
$data=[
'staff_name' => $staff['name'],
'staff_phone' => $staff['mobile'],
'total_orders' => $get['total_orders'],
'sw_orders' =>$get['sw_orders'],
'xw_orders' => $get['xw_orders'],
'finance' => $get['finance'],
'sw_addtime' =>$get['sw_addtime']/60,
'xw_addtime' => $get['xw_addtime']/60,
'leave' =>$get['leave']/2,
'attendance' =>$get['attendance'],
'staff_id' => $get['user_id'],
'status' =>$get['status'],
'break' =>$get['reake'],
'month' => $last_month_month,
'last_addtime' =>$lastMonthTimestamp,
'annual' =>$get['annual'],
'abnormal' =>$get['abnormal'],
'fine' =>$get['fine'],
'create_time' =>$now
];
return Db::name('staff_wages')->data($data)->insert();
}
public static function user_leave($get){
$lists=Db::name('leavesd')
->where('staff_id',$get['staff_id'])
->page($get['page'], $get['pageSize'])
->order('id desc')
->select();
foreach ($lists as &$item) {
if($item['addtime']==0){
$item['addtime']="上午";
$item['uration']=4;
}else if($item['addtime']==2){
$item['addtime']="全天";
$item['uration']=8;
}
else{
$item['addtime']="下午";
$item['uration']=4;
}
$item['create_time']=date('Y-m-d',$item['create_time']);
$item['time']=date('Y-m-d',$item['time']);
}
return $lists;
}
public static function last_leave($get){
$lists=Db::name('leave')
->where('user_id',$get['staff_id'])
->whereTime('time', 'last month')
->page($get['page'], $get['pageSize'])
->order('id desc')
->select();
foreach ($lists as &$item) {
$type=Db::name('leave_type')->where('id',$item['type'])->find(); //获取岗位
if($type){
$item['type_name']=$type['name'];
$item['create_time']=date('Y-m-d',$item['create_time']);
$item['time']=date('Y-m-d',$item['time']);
if($item['addtime']==1){
$item['addtime']="上午";
}else{
$item['addtime']="下午";
}
}
}
return $lists;
}
public static function fine($get){
$lists=Db::name('fine')
->where('staff_id',$get['staff_id'])
->page($get['page'], $get['pageSize'])
->order('id desc')
->select();
foreach ($lists as &$item) {
$type=Db::name('staff_fine')->where('id',$item['type_id'])->find(); //获取岗位
$item['type_name']=$type['name'];
$item['create_time']=date('Y-m-d',$item['create_time']);
}
return $lists;
}
public static function last_fine($get){
$lists=Db::name('fine')
->where('staff_id',$get['staff_id'])
->whereTime('create_time', 'last month')
->page($get['page'], $get['pageSize'])
->order('id desc')
->select();
foreach ($lists as &$item) {
$type=Db::name('staff_fine')->where('id',$item['type_id'])->find(); //获取岗位
$item['type_name']=$type['name'];
$item['create_time']=date('Y-m-d',$item['create_time']);
}
return $lists;
}
public static function addrecruit($get){
$get['crem_time']=time();
return Db::name('user_recruit')->data($get)->insert();
}
public static function notice_list($get){
$list=Db::name('staff_notice')
->page($get['page'], $get['pageSize'])
->order('id desc')
->select();
foreach ($list as &$item) {
$item['time']=date('Y-m-d',$item['time']);
}
return $list;
}
public static function addleave($get){
$staff=Db::name('staff')->where('id',$get['staff_id'])->find();
$data=[
'staff_id' =>$get['staff_id'],
'time' =>strtotime($get['time']),
'type' =>$get['type'],
'addtime' =>$get['after'],
'reak' =>$get['reak'],
'name' =>$staff['name'],
'phone' =>$staff['mobile'],
'create_time'=>time(),
];
return Db::name('leavesd')->data($data)->insert();
}
//获取员工的权限
public static function auth($param){
$role=Db::name('staff')->alias('s')
->join('staff_group g', 's.group_id = g.id')
->where('s.id',$param['staff_id'])
->field('g.rloe')
->find();
$roleArray = explode(',', $role['rloe']);
$data=Db::name('dev_staffauth')
->where('id','in', $roleArray)
->select();
return linear_to_tree($data);
}
}

View File

@@ -0,0 +1,433 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\api\logic;
use app\common\logic\{LogicBase, AfterSaleLogLogic};
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_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_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_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';
$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,
],
'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'],
'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)
{
$order=Db::name('order')->where('id',$order_id)->find();
$goods = Db::name('goods')
->where('id',$order['goods_id'])
->find();
$goods['image'] =isset($goods['image']) ? UrlServer::getFileUrl($goods['image']) : '';
$order['image']=$goods['image'];
$order['goods_name'] = $goods['name'];
return $order;
}
//上传退货快递信息
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')
->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)
{
$refund_status= Db::name('order')->where('id',$post['id'])->find();
return $refund_status;die;
// if($refund_status){
// return $refund_status;
// }else{
// return self::dataError('提交失败');
// }
// Db::startTrans();
// try {
/// $id = $post['id'];
// $after_sale = AfterSale::get($id); //获取订单的基本信息
/// $refund_status= Db::name('order')->where('id',$id)->update(['refund_status'=>2]);
/// dump($refund_status);
// if($refund_status){
// return self::dataSuccess('提交成功', ['after_sale_id' => $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();
// } 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;
}
}

View File

@@ -0,0 +1,107 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\api\logic;
use app\common\server\UrlServer;
use think\Db;
class ArticleLogic
{
public static function lists($id, $page, $size)
{
$where[] = [
['del', '=', 0],
['is_show', '=', 1],
];
if (!empty($id)) {
$where[] = ['cid', '=', $id];
}
$res = DB::name('article')
->where($where)
->field('id,title,synopsis,image,visit,create_time')
->order(['create_time' => '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]])
->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;
}
}

View File

@@ -0,0 +1,528 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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);
//砍价进度条
$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;
}
}

View File

@@ -0,0 +1,198 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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';
$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];
}
}

View File

@@ -0,0 +1,60 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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();
}
}

View File

@@ -0,0 +1,571 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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'] = $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']);
break;
case 3:
$coupon_item['use_time'] = $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']);
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){
if($coupon_item['use_time_start'] > $now || $coupon_item['use_time_end'] < $now){
$coupon_info['tips'] = '优惠券不在使用时间范围内';
$coupon['unusable'][] = $coupon_info;
continue;
}
}else{
if($coupon_item['use_time'] - $now <= 0){
$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;
}
}

View File

@@ -0,0 +1,564 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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_ancestor_relation = trim("{$my_leader_id},{$my_leader['ancestor_relation']}", ',');
$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,'{$my_id}','" . 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;
}
}

View File

@@ -0,0 +1,72 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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'];
}
}

View File

@@ -0,0 +1,178 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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;
}
/**
* 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;
}
}

View File

@@ -0,0 +1,115 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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;
//
// }
$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);
}
}

View File

@@ -0,0 +1,354 @@
<?php
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')
->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){
$comment['avatar'] = UrlServer::getFileUrl($comment['avatar']);
$comment['create_time'] = date('Y-m-d H:i:d',$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 addOrderComment($post ,$user_id){
$time =time();
$order_goods= db::name('order_comment')
->where(['order_sn'=>$post['id']])
->find();
if($order_goods){
return '商品已评论,请勿重复评论';
}
$comment_data= [
'user_id' => $user_id,
'order_sn' => $post['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('order_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_exe')->where('id',$post['id'])->update(['orderpl'=>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')
->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;
}
public static function OrderInfo($post){
return Db::name('order_comment')->where('order_sn',$post)->find();
}
}

View File

@@ -0,0 +1,329 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\api\logic;
use app\api\model\Goods;
use app\common\model\Footprint;
use app\common\model\TeamActivity;
use app\common\model\TeamFound;
use app\common\model\TeamGoodsItem;
use app\common\server\ConfigServer;
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']){
$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($goods){
//点击量
$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',
'click_count','price','market_price','is_collect','goods_spec','goods_image',
'goods_item','activity','member_price']);
//判断是否开启了拼团
if ($goods['is_team']) {
$resTeam = self::getTeam($goods);
// 如果活动没结束,则返回拼团数据, 否则把商品是否已开团状态改为,不是开团商品
if ($resTeam !== 100 and is_array($resTeam)) {
$goods['activity'] = $resTeam;
} else {
$goods['is_team'] = 0;
}
}
// 钩子-记录足迹(浏览商品)
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;
}
return [];
}
//好物优选
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];
}
}

View File

@@ -0,0 +1,109 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\api\logic;
use app\common\server\UrlServer;
use think\Db;
class HelpLogic
{
public static function lists($id, $page, $size)
{
$where[] = [
['del', '=', 0],
['is_show', '=', 1],
];
if (!empty($id)){
$where[] = ['cid', '=', $id];
}
$res = DB::name('help')
->where($where)
->field('id,title,synopsis,image,visit,create_time')
->order(['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]])
->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;
}
}

View File

@@ -0,0 +1,145 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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;
}
}

View File

@@ -0,0 +1,206 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\api\logic;
use app\common\model\Ad;
use app\common\server\UrlServer;
use think\Db;
class LeadershipLogic
{
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.*')
->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,
];
}
return $list;
}
//获取物料申请列表内容
public static function material_list($get){
$staff=Db::name('staff')->where('id',$get['staff_id'])->field('grouping_id')->find(); //获取员工基本信息
if($staff){
$grouping=Db::name('staff_grouping')->where('id',$staff['grouping_id'])->field('id')->find(); //获取到分组的ID
$stafflist=Db::name('staff')->where('grouping_id',$grouping['id'])->field('id')->select(); //获取部门下面的员工id
$flattenedArray = array_column($stafflist, 'id'); //二维数组转换一位数组
$count = Db::name('erp_staff')
->where('staff_id','in',$flattenedArray)
->where('status',$get['status'])
->count();
$lists = Db::name('erp_staff')
->where('staff_id','in',$flattenedArray)
->where('status',$get['status'])
->page($get['page'],$get['pageSize'])
->select();
foreach ($lists as &$item) {
$staffinfo=Db::name('staff')->where('id',$item['staff_id'])->field('name,mobile')->find();
$item['staff_name']=$staffinfo['name'];
$item['mobile']=$staffinfo['mobile'];
$item['create_time']=date("Y-m-d H:i:s",$item['create_time']);
$gooods=Db::name('epr')->where('id',$item['goods_id'])->find();
$item['goods_name']= $gooods['name'];
$item['images']=UrlServer::getFileUrl($gooods['abs_avatar']);
}
return ['count'=>$count , 'lists'=>$lists];
}
}
//获取报销的金额的数据列表
public static function finance_list($get){
$staff=Db::name('staff')->where('id',$get['staff_id'])->field('grouping_id')->find(); //获取员工基本信息
if($staff){
$grouping=Db::name('staff_grouping')->where('id',$staff['grouping_id'])->field('id')->find(); //获取到分组的ID
$stafflist=Db::name('staff')->where('grouping_id',$grouping['id'])->field('id')->select(); //获取部门下面的员工id
$flattenedArray = array_column($stafflist, 'id'); //二维数组转换一位数组
$lists = Db::name('finance')
->where('staff_id','in',$flattenedArray)
->where('status',$get['status'])
->page($get['page'],$get['pageSize'])
->select();
foreach ($lists as &$item) {
$item['create_time']=date("Y-m-d H:i:s",$item['create_time']);
$order=Db::name('order_exe')->where('id',$item['order_id'])->find();
$staffinfo=Db::name('staff')->where('id', $order['staff_id'])->field('name,mobile')->find();
if($order){
$item['name']= $order['name'];
$item['phone']= $order['phone'];
$item['order_sn']= $order['order_sn'];
}
if($order['addtime']=1){
$item['sw_time']="8:00-12:00";
}else{
$item['sw_time']="14:00-16:00";
}
$item['staff_name']=$staffinfo['name'];
$item['mobile']=$staffinfo['mobile'];
}
return $lists;
}
}
//获取报销的加时间订单列表
public static function addorder_list($get){
$staff=Db::name('staff')->where('id',$get['staff_id'])->field('grouping_id')->find(); //获取员工基本信息
if($staff){
$grouping=Db::name('staff_grouping')->where('id',$staff['grouping_id'])->field('id')->find(); //获取到分组的ID
$stafflist=Db::name('staff')->where('grouping_id',$grouping['id'])->field('id')->select(); //获取部门下面的员工id
$flattenedArray = array_column($stafflist, 'id'); //二维数组转换一位数组
$lists = Db::name('order_timeadd')
->where('staff_id','in',$flattenedArray)
->where('status',$get['status'])
->page($get['page'],$get['pageSize'])
->select();
foreach ($lists as &$item) {
$item['create_time']=date("Y-m-d H:i:s",$item['create_time']);
$order=Db::name('order_exe')->where('id',$item['orderid'])->find();
if($order){
$item['name']= $order['name'];
$item['phone']= $order['phone'];
$item['order_sn']= $order['order_sn'];
if($order['addtime']=1){
$item['sw_time']="8:00-12:00";
}else{
$item['sw_time']="14:00-16:00";
}
$staffinfo=Db::name('staff')->where('id',$order['staff_id'])->field('name,mobile')->find(); //员工传递过来的ID
if($staffinfo){
$item['staff_name']=$staffinfo['name'];
$item['mobile']=$staffinfo['mobile'];
}
}
}
return $lists;
}
}
public static function staff_list($get){
$staff=Db::name('staff')->where('id',$get['staff_id'])->field('grouping_id')->find(); //获取员工基本信息
if($staff){
$grouping=Db::name('staff_grouping')->where('id',$staff['grouping_id'])->field('id')->find(); //获取到分组的ID
$lists = Db::name('staff')
->where('grouping_id',$grouping['id'])
->where('onwork',1)
// ->page($get['page'],$get['pageSize'])
->select();
foreach ($lists as &$item) {
$item['year_number']=Db::name('order_exe')->where('staff_status',3)->whereTime('autotime','year')->where('staff_id',$item['id'])->count(); //今年订单
$item['month_number']=Db::name('order_exe')->where('staff_status',3)->whereTime('autotime','month')->where('staff_id',$item['id'])->count(); //当月订单
$item['addtime_number']=Db::name('order_exe')->where('staff_status',3)->whereTime('autotime','month')->where('staff_id',$item['id'])->SUM('add'); //当月报销
$item['account_number']=Db::name('order_exe')->where('staff_status',3)->whereTime('autotime','month')->where('staff_id',$item['id'])->SUM('account'); //当月加时
$item['leave_number']=Db::name('leave')->where('status',1)->whereTime('time','month')->where('user_id',$item['id'])->count()/2; //当月加时
$item['erp_number']=Db::name('erp_staff')->where('status',2)->whereTime('create_time','month')->where('staff_id',$item['id'])->SUM('number'); //当月加时
}
return $lists;
}
}
}

View File

@@ -0,0 +1,696 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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\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;
case 8:
$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);
//注册赠送
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);
}
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);
}
/**
* 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失败');
}
//unionid
// $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$config['app_id']}&secret={$config['secret']}&js_code={$post['code']}&grant_type=authorization_code";
// $data = file_get_contents($url);
// var_dump($data);
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,$phone)
{
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());
}
$response['mobile'] = $phone;
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);
}
}

View File

@@ -0,0 +1,134 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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;
}
}

View File

@@ -0,0 +1,276 @@
<?php
namespace app\api\logic;
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 = [
'limit' => ConfigServer::get('luckdraw', 'limit', 0),
'status' => ConfigServer::get('luckdraw', 'status', ''),
'rule' => ConfigServer::get('luckdraw', 'rule', 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', '=', 1)
->with('user')
->limit(20)->select();
foreach ($record as &$item) {
$nickname = self::hideStar($item['user']['nickname']);
$item['text'] = '恭喜'.$nickname.'抽中了'.$item['number'].$item['prize_name'];
unset($item['user_id']);
unset($item['prize_id']);
unset($item['prize_type']);
unset($item['prize_name']);
unset($item['prize_image']);
unset($item['number']);
unset($item['user']);
}
$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[] = json_decode("{}");
}
$prizeData[] = $lists[$i];
} else {
$prizeData[] = json_decode("{}");
}
}
return ['config'=>$config, 'surplus'=>$surplus, 'record'=>$record, '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']) : '';
if ($item['prize_type'] === 1) {
$item['prize_name'] = $item['prize_name'].'('.$item['number'].')';
}
}
$more = is_more($count, $page, $size);
return [
'list' => $record,
'count' => $count,
'page_no' => $page,
'page_size' => $size,
'more' => $more
];
}
/**
* Notes: 抽奖逻辑开始
* @author 张无忌(2021/1/26 17:00)
* @param $user_id
* @return array|bool
*/
public static function draw($user_id)
{
if (!$user_id) { static::$error = '请先登录后操作'; return false; }
$status = ConfigServer::get('luckdraw', 'status', 0);
if ($status == 0) {
static::$error = '抽奖活动已结束';
return false;
}
Db::startTrans();
try {
// 取得该用户今天抽奖次数
// 计算用户剩余抽奖次数
list($startDay, $endDay) = Time::today();
$recordCount = LuckdrawRecord::where([
['user_id', '=', $user_id],
['create_time', '>=', $startDay],
['create_time', '<', $endDay]
])->count('id');
$limit = ConfigServer::get('luckdraw', 'limit', 0);
$surplus = $limit - $recordCount;
$surplus = $surplus <= 0 ? 0 : $surplus;
if ($surplus <= 0) {
static::$error = '今天抽奖次数已用完';
return false;
}
// 获取正在进行抽奖的商品 (倒叙获取 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;
}
}
// 记录获得奖品信息
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'],
'create_time' => time(),
]);
// 分析奖品类型,如(积分, 优惠券等),给用户怎加对应获得的奖品
if ($inPrize['prize_type'] == 1) {
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));
}
Db::commit();
$text = ['', '恭喜您获得'.$inPrize['number'].'积分', '谢谢惠顾'];
// 返回抽奖结果
return [
'id' => $inPrize['id'],
'name' => $inPrize['name'],
'image' => UrlServer::getFileUrl($inPrize['image']),
'number' => $inPrize['number'],
'text' => $text[$inPrize['prize_type']],
'create_time' => date('Y-m-d H:i:s', time())
];
} 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;
}
}

View File

@@ -0,0 +1,57 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\api\logic;
use app\common\model\Menu_;
use app\common\server\ConfigServer;
use app\common\server\UrlServer;
use think\Db;
class MenuLogic
{
public static function getMenu($type)
{
$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) {
$menu_content = Menu_::getMenuContent($type, $menu['link_address']);
// if (!$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

View File

@@ -0,0 +1,299 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\api\logic;
use app\api\model\Goods;
use app\common\model\Ad;
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){
$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'],
'create_time' => time(),
];
return Db::name('user')->where(['id'=>$post['user_id']])->update($data);
}
}

View File

@@ -0,0 +1,54 @@
<?php
namespace app\api\logic;
use think\Db;
use think\Exception;
use app\common\server\UrlServer;
use app\api\logic\UserLogic;
class PointsLogic
{
//获取积分的分类
public static function classify(){
return Db::name('printer_type')->select();
}
//获取到积分的商品列表
public static function goodslist(){
$where=[];
$goods = Db::name('printer_goods')
->where($where)
->select();
foreach($goods as &$item){
$item['images']=UrlServer::getFileUrl($item['images']);
}
return $goods;
}
//根据ID获取到积分商品
public static function goodsIofo($id){
$data=Db::name('printer_goods')->where('id',$id)->find();
$data['images']=UrlServer::getFileUrl($data['images']);
return $data;
}
public static function goodsSub($data){
$data=[
'name' =>$data['name'],
'goods_id' =>$data['id'],
'price' =>$data['price'],
'number' =>1,
'user_id' =>$data['user_id'],
'create_time'=>time()
];
$insert=Db::name('printer_order')->data($data)->insert();
if($insert){
$user=UserLogic::getUserInfo($data['user_id']);
db::name('user')->where('id',$data['user_id'])->update(['user_integral'=>$user['user_integral']-$data['price']]);
// Db::name('printer_goods')->where('')
}
}
}

View File

@@ -0,0 +1,53 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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;
}
}

View File

@@ -0,0 +1,138 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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'],
'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;
}
}

View File

@@ -0,0 +1,185 @@
<?php
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;
}
}
//获取站长段的订单
public static function recruit_order($get){
$lists = Db::name('order')->where('mobile',$get['phone'])->select();
foreach ($lists as &$item){
$item['time_payorder']= date('Y-m',$item['create_time']);
$goods=Db::name('goods')->where('id',$item['goods_id'])->field('name')->find();
$item['goods_name']=$goods['name'];
$item['dai_order']=$item['number']-$item['code'];
$item['slect_order']=Db::name('order_exe')->where('order_sn',$item['order_sn'])->where('staff_status',3)->count();
}
return $lists;
}
//站长端口空余的保洁师
public static function staff_list($get){
$lists =Db::name('staff')->where('onwork',1)->select();
return $lists;
}
//站长派单数据统计
public static function recruit_index($get){
$today = date('Y-m-d');
$tomorrow = date('Y-m-d', strtotime($today . ' +1 day'));
$recruit=Db::name('staff_grouping')->where('admin_id',$get['uid'])->find();
$staff=Db::name('staff')->where('grouping_id',$recruit['id'])->field('id')->select(); //获取站长下面的员工
$Array = array_column($staff, 'id'); //二维数组转换一位数组
$data['unassigned']=Db::name('order_exe')
->where('staff_id','in',$Array)
->where('staff_status',0)
->whereTime('autotime', 'between', ["$today 00:00:00", "$tomorrow 23:59:59"])
->count(); //未接单的数据统计
$data['service']=Db::name('order_exe')
->where('staff_id','in',$Array)
->where('staff_status',1)
->whereTime('autotime', 'between', ["$today 00:00:00", "$tomorrow 23:59:59"])
->count(); //统计未点击开始
$data['start']=Db::name('order_exe')
->where('staff_id','in',$Array)
->where('staff_status',2)
->whereTime('autotime','today')
->count(); //统计待开始
$data['end']=Db::name('order_exe')
->where('staff_id','in',$Array)
->where('staff_status',3)
->whereTime('autotime','today')
->count(); //统计待完成
$data['number']=Db::name('order_exe')
->where('staff_id',0)
->whereTime('autotime','today')
->count(); //统计是有的未派单
$data['images']=Db::name('order_exe')
->where('staff_status',4)
->where('is_images',0)
->count(); //统计是有的未派单
$data['number']=Db::name('order_exe')
->where('staff_id',0)
->whereTime('autotime', 'between', ["$today 00:00:00", "$tomorrow 23:59:59"])
//->where('is_images',0)
->count(); //统计是有的未派单
return $data;
}
//首页统计所有的订单内容
public static function recruit_listorder($get){
$status=intval($get['status']);
$today = date('Y-m-d');
$tomorrow = date('Y-m-d', strtotime($today . ' +1 day'));
$recruit=Db::name('staff_grouping')->where('admin_id',$get['staff_id'])->find();
$staff=Db::name('staff')->where('grouping_id',$recruit['id'])->field('id')->select(); //获取站长下面的员工
$Array = array_column($staff, 'id'); //二维数组转换一位数组
if($status==0){
$lists=Db::name('order_exe')
->where('staff_status',$get['status'])
->where('staff_id','in',$Array)
// ->where($status==0,function($query){
// $query->whereTime('autotime', 'between', ["$today 00:00:00", "$tomorrow 23:59:59"]);
// })
// ->where($get['status']=1,function($query){
// $query->whereTime('autotime','today');
// })
->whereTime('autotime', 'between', ["$today 00:00:00", "$tomorrow 23:59:59"])
->select();
}
if($status==1){
$lists=Db::name('order_exe')
->where('staff_status',$get['status'])
->where('staff_id','in',$Array)
->whereTime('autotime', 'between', ["$today 00:00:00", "$tomorrow 23:59:59"])
->select();
}
if($status==2){
$lists=Db::name('order_exe')
->where('staff_status',$get['status'])
->where('staff_id','in',$Array)
->whereTime('autotime', 'today')
->select();
}
if($status==3){
$lists=Db::name('order_exe')
->where('staff_status',$get['status'])
->where('staff_id','in',$Array)
->whereTime('autotime', 'today')
->select();
}
if($status==4){
$lists=Db::name('order_exe')
->where('is_images',0)
->where('staff_id','in',$Array)
->whereTime('autotime', 'today')
->select();
}
if($status==5){
$lists=Db::name('order_exe')
->where('staff_id',0)
->whereTime('autotime', 'between', ["$today 00:00:00", "$tomorrow 23:59:59"])
->select();
}
foreach ($lists as $k => $v){
$order_info=Db::name('order')->where('order_sn',$lists[$k]['order_sn'])->find();
$lists[$k]['order_sn']=$order_info['order_sn'];
$lists[$k]['name']=$order_info['consignee'];
$lists[$k]['phone']=$order_info['mobile'];
$goods=Db::name('goods')->where('id',$order_info['goods_id'])->find();
$lists[$k]['goods_name']= $goods['name'];
$lists[$k]['address']= $order_info['address'];
$lists[$k]['lat']= $order_info['lat'];
$lists[$k]['lng']= $order_info['lng'];
if($lists[$k]['addtime']==1){
$lists[$k]['sw']='上午';
$lists[$k]['sw_time']='8:00-12:00';
}else{
$lists[$k]['sw']='下午';
$lists[$k]['sw_time']='14:00-18:00';
}
$staff=Db::name('staff')->where('id',$lists[$k]['staff_id'])->find();
if($staff){
$lists[$k]['staff_name']=$staff['name'];
$lists[$k]['staff_phone']=$staff['mobile'];
$lists[$k]['autotime']=date('Y-m-d',$lists[$k]['autotime']);
}
}
return $lists;
}
}

View File

@@ -0,0 +1,134 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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];
}
}

View File

@@ -0,0 +1,34 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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;
}
}

View File

@@ -0,0 +1,134 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\api\logic;
use app\common\logic\LogicBase;
use app\common\logic\QrCodeLogic;
use app\common\model\BargainLaunch;
use app\common\model\Client_;
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;
}
}

View File

@@ -0,0 +1,268 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\api\logic;
use app\common\logic\AccountLogLogic;
use app\common\model\AccountLog;
use app\common\server\UrlServer;
use think\Db;
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){
$sign_list = Db::name('sign_daily')
->where(['del'=>0])
->order('type asc,days asc')
->column('*','days');
$start_sign = current($sign_list); //第一次签到规则
$end_sign = end($sign_list); //最后一次签到规则
//签到记录
$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; //签到赠送的成长值
$sign_add = [];
$sign_day = 1; //累计签到天数
//有签到记录,说明之前有签到
if($last_sign){
$sign_day = $last_sign['days'] + 1;
$sign = $sign_list[$sign_day] ?? [];
$continuous_integral = 0; //连续签到奖励积分
$continuous_growth = 0; //连续签到奖励成长值
//累计签到天数,额外奖励
if($sign){
if($sign['integral_status'] && $sign['integral'] > 0){
$total_integral+=$sign['integral'];
}
if($sign['growth_status'] && $sign['growth'] > 0){
$total_growth+=$sign['growth'];
}
}
if($start_sign && $start_sign['integral_status'] && $start_sign['integral'] > 0){
$total_integral+=$start_sign['integral'];
}
if($start_sign && $start_sign['growth_status'] && $start_sign['growth'] > 0){
$total_growth+=$start_sign['growth'];
}
$sign_add = [
'user_id' => $user_id,
'days' => $sign_day,
'integral' => $total_integral,
'growth' => $total_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 && $one_day_sign['integral_status'] && $one_day_sign['integral'] > 0){
$total_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'];
}
//每天签到的奖励
if($start_sign && $start_sign['integral_status'] && $start_sign['integral'] > 0){
$total_integral+=$start_sign['integral'];
}
if($start_sign && $start_sign['growth_status'] && $start_sign['growth'] > 0){
$total_growth+=$start_sign['growth'];
}
$sign_add = [
'user_id' => $user_id,
'days' => $sign_day,
'integral' => $total_integral,
'growth' => $total_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);
}
return [
'integral' => $total_integral,
'growth' => $total_growth,
'days' => $sign_day,
];
}
}

View File

@@ -0,0 +1,44 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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();
}
}
}

View File

@@ -0,0 +1,172 @@
<?php
namespace app\api\logic;
use app\common\model\NoticeSetting;
use think\facade\Hook;
use think\Db;
use think\Exception;
use app\api\model\{Orderexe};
class StaffLogic{
//保洁师服务加时间显示列表
public static function infoaddtim($get){
$lists=Db::name('order_timeadd')->where('orderid',$get['order_id'])->select();
foreach ($lists as $key => $level){
$lists[$key]['create_time']=date("Y-m-d H:i:s",$level['create_time']);;
}
return $lists;
}
//员工请假的增加
public static function leaveadd($get){
$staff=Db::name('staff')->where('id',$get['staff_id'])->find();
// var_dump($post);
$starttime_h = date('H',strtotime($get['start_time']));
$enttime_h = date('H',strtotime($get['end_time']));
//处理0
$enttime_0 = date('H:i:s',strtotime($get['end_time']));
if($enttime_0 == '00:00:00'){
$get['end_time'] = date('Y-m-d',strtotime($get['end_time'])). '00:00:01';
}
$days = [];
$get['start_time']=date('Y-m-d H:i:s',$get['start_time']);
$get['end_time']=date('Y-m-d H:i:s',$get['end_time']);
$period = new \DatePeriod(
new \DateTime($get['start_time']),
new \DateInterval('P1D'),
new \DateTime($get['end_time'])
);
$len = 0;
foreach($period as $k=>$v){
$len++;
}
foreach($period as $k=>$v){
if($k == 0 && $starttime_h > 12){
$days[] = ['addtime'=>1,'time'=>$v->format('Y-m-d')];
continue;
}
if($k === ($len - 1) && $enttime_h < 12){
$days[] = ['addtime'=>1,'time'=>$v->format('Y-m-d')];
continue;
}
$days[] = ['addtime'=>1,'time'=>$v->format('Y-m-d')];
$days[] = ['addtime'=>2,'time'=>$v->format('Y-m-d')];
// echo $v->format('Y-m-d');
}
if(empty($days)){
return;
}
$data = [];
foreach($days as $v){
$data[] = [
'name'=> $staff['name'],
'phone'=>$staff['mobile'],
'user_id'=>$staff['id'],
'status'=>0,
'time'=>strtotime($v['time']),
'type'=>1,
'remark'=>'',
'addtime'=>$v['addtime'],
'create_time'=>time()
];
}
return Db::name('leave')->insertAll($data);
$data=[
'name'=> $staff['name'],
'phone'=>$staff['mobile'],
'user_id'=>$staff['id'],
'status'=>0,
'time'=>strtotime($post['end_time']),
'type'=>1,
'remark'=>'',
'addtime'=>$post['level'],
'create_time'=>time()
];
// return Db::name('leave')->insertGetId($data);
}
//员工订单的
public static function order_list($get){
$today = date('Y-m-d');
// 计算明天的日期
$tomorrow = date('Y-m-d', strtotime($today . ' +1 day'));
$tomorrows = date('Y-m-d', strtotime($today . ' +2 day'));
$order = new Orderexe();
$lists = $order->where('staff_id',$get['staff_id'])
->where('staff_status',$get['staff_status'])
->whereTime('autotime', 'between', ["$today 00:00:00", "$tomorrow 23:59:59"])
->order('autotime desc')
->select();
foreach ($lists as $list){
$custom=Db::name('order')->where('order_sn',$list['order_sn'])->find();
$list['address']= $custom['address'];
$list['lat']= $custom['lat'];
$list['lng']= $custom['lng'];
$goods=Db::name('goods')->where('id',$custom['goods_id'])->find();
$list['goods_name']= $goods['name'];
if(intval(($list['autotime']-time())/86400)>1){
$list['jldate']=intval(($list['autotime']-time())/86400);
}else{
$list['jldate']='-';
}
$adder=Db::name('user_address')->where('telephone',$custom['mobile'])->find();
if($adder){
$admin=Db::name('admin')->where('id',$adder['admin_id'])->find();
if($admin){
$list['admin_name']=$admin['name'];
$list['admin_phone']=$admin['phone'];
}else{
$list['admin_name']='-';
$list['admin_phone']='-';
}
}
if($list['addtime']==1){
$list['sw']='上午';
$list['sw_time']='8:00-12:00';
}else{
$list['sw']='下午';
$list['sw_time']='14:00-18:00';
}
//查询其他用户
$more_where = [
['staff_id','<>',$get['staff_id']],
['order_sn','=',$list['order_sn']],
['autotime','=',$list['autotime']]
];
$more_users = $order->where($more_where)
->whereTime('autotime', 'between', ["$today 00:00:00", "$tomorrow 23:59:59"])
->order('autotime desc')
->column('staff_id');
if(!empty($more_users)){
$list['users'] = Db::name('staff')->field('mobile,name,addr')->whereIn('id',$more_users)->select();
}
$list['autotime']=date("Y-m-d",$list['autotime']);
$list['number']=0;
}
return $lists;
}
}

View File

@@ -0,0 +1,124 @@
<?php
namespace app\api\logic;
use app\common\server\UrlServer;
use think\Db;
class StaffOrderLogic
{
/**
* note 根据id获取获取管理员
* create_time 2020/10/21 19:05
*/
public static function admin($id){
return Db::name('admin')->where('id',$id)->find();
}
/**
* note 根据id获取的商品
* create_time 2020/10/21 19:05
*/
public static function goods($id){
$goods=Db::name('goods')->where('id',$id)->find();
$goods['image']=UrlServer::getFileUrl($goods['image']);
return $goods;
}
/**
* note 根据订单编号获取子订单编号
* create_time 2020/10/21 19:05
*/
public static function order_sn($order_sn){
$count=Db::name('order_exe')
->where('order_sn',$order_sn)
->where('staff_status',3)
->count();
return $count;
}
/**
* note 查询已经完成的订单
* create_time 2020/10/21 19:05
*/
public static function wc_order($page,$limt,$param){
$where=[];
if (!empty($param['search'])) {
if (preg_match('/^1[3-9]\d{9}$/', $param['search'])) {
$where[] = ['mobile', '=', $param['search']];
} else {
$where[] = ['consignee', 'LIKE', '%' . $param['search'] . '%'];
}
} else {
$where = [];
}
$data=Db::name('order')
->order('id', 'desc')
->where($where)
->page($page,$limt)
->select();
$datas=[];
foreach ($data as &$item){
$item['create_time'] = date('Y-m-d', $item['create_time']);
$goods=self::goods($item['goods_id']); //订单的商品
if($goods){
$item['goods_name']=$goods['name'];
$item['image']=$goods['image'];
$item['code']=$goods['code'];
}
$admin=self::admin($item['admin_id']);
if($admin){
$item['admin_name']=$admin['name'];
}
$count=self::order_sn($item['order_sn']); //统计总的条数
$item['order_wc']=$count; //统计完成次数
$item['order_dsy']=$item['code']-$count;
if($item['order_dsy']==0){
$datas[]=$item;
}
}
return $datas;
}
/**
* note 获取客户的渠道
* create_time 2020/10/21 19:05
*/
public static function addqudao($id){
return Db::name('staffchannel')->where('id',$id)->find();
}
/**
* note 获取到用户的信息
* create_time 2020/10/21 19:05
*/
public static function user($user_id){
return Db::name('user')->where('id',$user_id)->find();
}
/**
* note 根据商品的id修改商品
* create_time 2020/10/21 19:05
*/
public static function edit_order($param){
if (empty($param['id']) || !is_numeric($param['id'])) {
throw new \Exception('订单ID无效');
}
$data=[
'consignee' => $param['consignee'],
'pay_zd' => $param['pay_zd'],
'gord_id' => $param['gord_id'],
'channel_id' => $param['channel_id'],
'order_amount' => $param['order_amount'],
'order_remarks' => $param['remark']
];
return Db::name('order')->where('id',$param['id'])->update($data);
}
/**
* note 根据ID获取到保洁的信息
* create_time 2020/10/21 19:05
*/
public static function staff($id){
return Db::name('staff')->where('id',$id)->field('id,name,mobile')->find();
}
}

View File

@@ -0,0 +1,121 @@
<?php
namespace app\api\logic;
use app\common\server\UrlServer;
use think\Db;
class StaffgoodsLogic
{
//获取物料的列表
public static function godds_list($get){
$lists=Db::name('epr')->where('type',$get['type_id'])->select();
foreach ( $lists as &$item){
$item['abs_avatar']=UrlServer::getFileUrl($item['abs_avatar']);
}
return $lists;
}
public static function goods_info($id){
$list=Db::name('epr')->where('id',$id)->select();
foreach ( $list as &$item){
$item['abs_avatar']=UrlServer::getFileUrl($item['abs_avatar']);
}
return $list;
}
public static function addgoods($get){
$data=[
'goods_id'=>$get['ids'],
'staff_id'=>$get['staff_id'],
'buynums' =>$get['count'],
'name'=>$get['shopName'],
'number'=>$get['count']*$get['price'],
'create_time'=>time(),
'price' =>$get['price']
];
return Db::name('erp_staff')->data($data)->insert();
}
public static function order_wages($get){
$where=[];
$where[] = ['staff_status', '=',3]; //判断完成订单
$where[]=['staff_id', '=',$get['staff_id']];
if($get['status']==1 && $get['status']!=''){
$where[]=['account', '>',0];
}
if($get['status']==2 && $get['status']!=''){
$where[]=['add', '>',0];
$where[]=['addtime', '=',1];
}
if($get['status']==3 && $get['status']!=''){
$where[]=['add', '>',0];
$where[]=['addtime', '=',2];
}
if($get['status']==7 && $get['status']!=''){
$where[]=['abnormal', '=',1];
}
$lists=Db::name('order_exe')
->where($where)
->whereTime('autotime', 'last month')
// ->page($get['page'],$get['pageSize'])
->select();
foreach ($lists as &$item){
$order_info=Db::name('order')->where('order_sn',$item['order_sn'])->find();
if($order_info){
$item['order_sn']=$order_info['order_sn'];
$item['name']=$order_info['consignee'];
$item['phone']=$order_info['mobile'];
$item['address']= $order_info['address'];
$item['lat']= $order_info['lat'];
$item['lng']= $order_info['lng'];
$item['autotime']=date('Y-m-d',$item['autotime']);
$goods=Db::name('goods')->where('id',$order_info['goods_id'])->find();
$item['goods_name']= $goods['name'];
if($item['addtime']==1){
$item['sw']='上午';
$item['sw_time']='8:00-12:00';
}else{
$item['sw']='下午';
$item['sw_time']='14:00-18:00';
}
}
}
return $lists;
}
public static function orderinfo_wages($get){
$lists=Db::name('order_exe a')
->join('order b','a.order_sn=b.order_sn')
->where(['a.staff_status'=>3,'a.staff_id'=>$get['staff_id']])
->where('b.number','>',3)
->whereTime('autotime', 'last month')
->select();
foreach ($lists as &$item){
$order_info=Db::name('order')->where('order_sn',$item['order_sn'])->find();
if($order_info){
$item['order_sn']=$order_info['order_sn'];
$item['name']=$order_info['consignee'];
$item['phone']=$order_info['mobile'];
$item['address']= $order_info['address'];
$item['lat']= $order_info['lat'];
$item['lng']= $order_info['lng'];
$item['autotime']=date('Y-m-d',$item['autotime']);
$goods=Db::name('goods')->where('id',$order_info['goods_id'])->find();
$item['goods_name']= $goods['name'];
if($item['addtime']==1){
$item['sw']='上午';
$item['sw_time']='8:00-12:00';
}else{
$item['sw']='下午';
$item['sw_time']='14:00-18:00';
}
}
}
return $lists;
}
}

View File

@@ -0,0 +1,45 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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;
}
}

View File

@@ -0,0 +1,502 @@
<?php
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\Order;
use app\common\model\Pay;
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;
/**
* 拼团逻辑
* 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 = [];
protected 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')
->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';
$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 = 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);
//拼团信息
$order_team = [
'found_id' => $post['found_id'] ?? 0,
'team_id' => $post['team_id'] ?? 0,
];
// dump($goods_lists[0]['goods_id']);
$order = OrderLogic::addOrder($user_id, $order_data, $client, $user_address,$goods_lists[0]['goods_id'],$order_team);
$order_id = $order['order_id'];
OrderLogic::addOrderGoods($order_id, $goods_lists);
OrderLogic::addOrderAfter($order_id, $user_id, $type = '', $order_data);
//支付方式为余额支付,扣除余额,更新订单状态,支付状态
if ($order_data['pay_way'] == Pay::BALANCE_PAY || $order_data['order_amount'] == 0){
PayNotifyLogic::handle('order', $order['order_sn'], []);
}
//短信通知
// Hook::listen('sms_send', [
// 'key' => 'DDTJTZ',
// 'mobile' => $user_address['telephone'],
// 'params' => [
// 'nickname' => self::$user['mobile'],
// 'order_sn' => $order['order_sn'],
// 'order_amount' => $order['order_amount']
// ],
// ]);
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)
{
if (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];
}
}

View File

@@ -0,0 +1,306 @@
<?php
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 ($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])
->select();
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'],
'createtime' => 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'],
'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'] || 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);
}
}

View File

@@ -0,0 +1,139 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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;
}
}

View File

@@ -0,0 +1,523 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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\DistributionOrder;
use app\common\model\Order;
use app\common\model\TeamFollow;
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;
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([
['id','>',$user->getData('level')],
['del','=',0]
])->order('growth_value asc')
->find();
$user['next_level_tips'] = '';
if($user_level){
$user['next_level_tips'] = '距离升级还差'.intval($user_level['growth_value'] - $user['user_growth']);
}
// 是否设置支付密码
$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']);
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')
->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,user_integral')
->find();
$info['create_time'] = date('Y-m-d H:i:s');
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]);
if($field == 'mobile' && !empty($value) && $user_id){
Db::name('order')->where('mobile',$value)->update(['user_id'=>$user_id]);
Db::name('user_address')->where('telephone',$value)->update(['user_id'=>$user_id]);
}
return $res;
}
//修改手机号
public static function changeMobile($user_id, $data)
{
$user = User::get($user_id);
$uop= Db::name('order')->where('mobile',$data['new_mobile'])->update(['user_id'=>$user_id]);
$user->mobile = $data['new_mobile'];
$user->save();
return $user;
}
//获取微信手机号
public static function getMobileByMnp($post)
{
try{
$config = WeChatServer::getMnpConfig();
$app = Factory::miniProgram($config);
$response = $app->auth->session($post['code']);
// throw new Exception();
$response = $app->encryptor->decryptData($response['session_key'], $post['iv'], $post['encrypted_data']);
return self::dataSuccess('', $response);
}catch(Exception $e) {
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)
{
$transferFrom = Db::name('user')->where('id', $data['user_id'])->find();
// 判断余额是否充足
if($transferFrom['user_money'] < $data['money']) {
return [
'code' => 0,
'msg' => '余额不足'
];
}
// 判断支付密码是否正确
if($transferFrom['pay_password'] != md5(trim($data['pay_password']))) {
return [
'code' => 0,
'msg' => '支付密码错误'
];
}
// 收款人是否存在
$transferTo = Db::name('user')->where('sn', $data['transferTo'])->find();
if(!$transferTo) {
$transferTo = Db::name('user')->where('mobile', $data['transferTo'])->find();
}
if(!$transferTo) {
return [
'code' => 0,
'msg' => '收款用户不存在'
];
}
// 不能自己转账给自己
if($transferFrom['id'] == $transferTo['id']) {
return [
'code' => 0,
'msg' => '不能自己转账给自己'
];
}
Db::startTrans();
try{
// 生成转账记录
$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 [
'code' => 1,
'msg' => '转账成功'
];
}catch(\Exception $e){
Db::rollback();
return [
'code' => 0,
'msg' => '转账失败'
];
}
}
/**
* 转账记录
*/
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;
}
}

View File

@@ -0,0 +1,126 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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'];
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()
{
if (isset($_GET['echostr'])) {
echo $_GET["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_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']) && $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();
}
}

View File

@@ -0,0 +1,162 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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'),
'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;
}
}

View File

@@ -0,0 +1,35 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
// +----------------------------------------------------------------------
// | 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,
];

View File

@@ -0,0 +1,31 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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');
}
}

View File

@@ -0,0 +1,37 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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');
}
}

View File

@@ -0,0 +1,44 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
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;
}
}

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