添加网站文件
This commit is contained in:
60
application/api/logic/ActivityAreaLogic.php
Normal file
60
application/api/logic/ActivityAreaLogic.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
486
application/api/logic/AdLogic.php
Normal file
486
application/api/logic/AdLogic.php
Normal 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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
433
application/api/logic/AfterSaleLogic.php
Normal file
433
application/api/logic/AfterSaleLogic.php
Normal 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;
|
||||
}
|
||||
}
|
||||
107
application/api/logic/ArticleLogic.php
Normal file
107
application/api/logic/ArticleLogic.php
Normal 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;
|
||||
}
|
||||
}
|
||||
528
application/api/logic/BargainLogic.php
Normal file
528
application/api/logic/BargainLogic.php
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
198
application/api/logic/CartLogic.php
Normal file
198
application/api/logic/CartLogic.php
Normal 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];
|
||||
}
|
||||
|
||||
}
|
||||
60
application/api/logic/CollectLogic.php
Normal file
60
application/api/logic/CollectLogic.php
Normal 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();
|
||||
|
||||
}
|
||||
}
|
||||
571
application/api/logic/CouponLogic.php
Normal file
571
application/api/logic/CouponLogic.php
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
564
application/api/logic/DistributionLogic.php
Normal file
564
application/api/logic/DistributionLogic.php
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
72
application/api/logic/FootPrintLogic.php
Normal file
72
application/api/logic/FootPrintLogic.php
Normal 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'];
|
||||
}
|
||||
}
|
||||
178
application/api/logic/FreightLogic.php
Normal file
178
application/api/logic/FreightLogic.php
Normal 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;
|
||||
}
|
||||
}
|
||||
115
application/api/logic/GoodsCategoryLogic.php
Normal file
115
application/api/logic/GoodsCategoryLogic.php
Normal 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
354
application/api/logic/GoodsCommentLogic.php
Normal file
354
application/api/logic/GoodsCommentLogic.php
Normal 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();
|
||||
}
|
||||
|
||||
}
|
||||
329
application/api/logic/GoodsLogic.php
Normal file
329
application/api/logic/GoodsLogic.php
Normal 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];
|
||||
}
|
||||
}
|
||||
109
application/api/logic/HelpLogic.php
Normal file
109
application/api/logic/HelpLogic.php
Normal 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;
|
||||
}
|
||||
}
|
||||
145
application/api/logic/IndexLogic.php
Normal file
145
application/api/logic/IndexLogic.php
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
206
application/api/logic/LeadershipLogic.php
Normal file
206
application/api/logic/LeadershipLogic.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
696
application/api/logic/LoginLogic.php
Normal file
696
application/api/logic/LoginLogic.php
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
134
application/api/logic/LoginPasswordLogic.php
Normal file
134
application/api/logic/LoginPasswordLogic.php
Normal 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;
|
||||
}
|
||||
}
|
||||
276
application/api/logic/LuckdrawLogic.php
Normal file
276
application/api/logic/LuckdrawLogic.php
Normal 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;
|
||||
}
|
||||
}
|
||||
57
application/api/logic/MenuLogic.php
Normal file
57
application/api/logic/MenuLogic.php
Normal 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;
|
||||
}
|
||||
}
|
||||
1371
application/api/logic/OrderLogic.php
Normal file
1371
application/api/logic/OrderLogic.php
Normal file
File diff suppressed because it is too large
Load Diff
299
application/api/logic/PcLogic.php
Normal file
299
application/api/logic/PcLogic.php
Normal 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);
|
||||
}
|
||||
}
|
||||
54
application/api/logic/PointsLogic.php
Normal file
54
application/api/logic/PointsLogic.php
Normal 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('')
|
||||
}
|
||||
}
|
||||
}
|
||||
53
application/api/logic/PolicyLogic.php
Normal file
53
application/api/logic/PolicyLogic.php
Normal 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;
|
||||
}
|
||||
}
|
||||
138
application/api/logic/RechargeLogic.php
Normal file
138
application/api/logic/RechargeLogic.php
Normal 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;
|
||||
}
|
||||
}
|
||||
185
application/api/logic/RegionLogic.php
Normal file
185
application/api/logic/RegionLogic.php
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
134
application/api/logic/SeckillLogic.php
Normal file
134
application/api/logic/SeckillLogic.php
Normal 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];
|
||||
}
|
||||
}
|
||||
34
application/api/logic/ServiceLogic.php
Normal file
34
application/api/logic/ServiceLogic.php
Normal 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;
|
||||
}
|
||||
}
|
||||
134
application/api/logic/ShareLogic.php
Normal file
134
application/api/logic/ShareLogic.php
Normal 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;
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
268
application/api/logic/SignLogic.php
Normal file
268
application/api/logic/SignLogic.php
Normal 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,
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
44
application/api/logic/SmsLogic.php
Normal file
44
application/api/logic/SmsLogic.php
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
172
application/api/logic/StaffLogic.php
Normal file
172
application/api/logic/StaffLogic.php
Normal 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;
|
||||
}
|
||||
}
|
||||
124
application/api/logic/StaffOrderLogic.php
Normal file
124
application/api/logic/StaffOrderLogic.php
Normal 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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
121
application/api/logic/StaffgoodsLogic.php
Normal file
121
application/api/logic/StaffgoodsLogic.php
Normal 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;
|
||||
}
|
||||
}
|
||||
45
application/api/logic/SubscribeLogic.php
Normal file
45
application/api/logic/SubscribeLogic.php
Normal 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;
|
||||
}
|
||||
}
|
||||
502
application/api/logic/TeamLogic.php
Normal file
502
application/api/logic/TeamLogic.php
Normal 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];
|
||||
}
|
||||
}
|
||||
306
application/api/logic/UserAddressLogic.php
Normal file
306
application/api/logic/UserAddressLogic.php
Normal 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);
|
||||
}
|
||||
}
|
||||
139
application/api/logic/UserLevelLogic.php
Normal file
139
application/api/logic/UserLevelLogic.php
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
523
application/api/logic/UserLogic.php
Normal file
523
application/api/logic/UserLogic.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
126
application/api/logic/WeChatLogic.php
Normal file
126
application/api/logic/WeChatLogic.php
Normal 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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
162
application/api/logic/WithdrawLogic.php
Normal file
162
application/api/logic/WithdrawLogic.php
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user