first commit
This commit is contained in:
@@ -0,0 +1,276 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\logic;
|
||||
use app\admin\model\User;
|
||||
use app\api\model\Order;
|
||||
use app\api\model\OrderGoods;
|
||||
use app\common\model\AccountLog;
|
||||
use app\common\model\DistributionOrder;
|
||||
use think\Db;
|
||||
use think\helper\Time;
|
||||
|
||||
class AccountLogLogic
|
||||
{
|
||||
|
||||
public static function lists($get)
|
||||
{
|
||||
$source_type = '';
|
||||
$where = [];
|
||||
switch ($get['type']){//记录类型
|
||||
case 1://余额变动
|
||||
$source_type = AccountLog::money_change;
|
||||
break;
|
||||
case 2://积分变动
|
||||
$source_type = AccountLog::integral_change;
|
||||
break;
|
||||
case 3://成长值变动
|
||||
$source_type = AccountLog::growth_change;
|
||||
}
|
||||
if(isset($get['order_source']) && $get['order_source']){
|
||||
$source_type = $get['order_source'];
|
||||
}
|
||||
|
||||
$where[] = ['source_type','in',$source_type];
|
||||
if(isset($get['change_type']) && $get['change_type']){
|
||||
$where[] = ['source_type','=',$get['change_type']];
|
||||
}
|
||||
if(isset($get['keyword']) && $get['keyword']){
|
||||
$where[] = [$get['keyword_type'],'like','%'.$get['keyword'].'%'];
|
||||
}
|
||||
if (isset($get['start_time']) && $get['start_time'] && isset($get['end_time']) && $get['end_time']) {
|
||||
$where[] = ['a.create_time', 'between', [strtotime($get['start_time']), strtotime($get['end_time'])]];
|
||||
}
|
||||
|
||||
if(isset($get['create_end']) && $get['create_end']!=''){
|
||||
$where[] = ['ro.create_time','<=',strtotime($get['create_end'])];
|
||||
}
|
||||
|
||||
$count = Db::name('account_log')->alias('a')
|
||||
->join('user u','a.user_id = u.id')
|
||||
->where($where)
|
||||
->count();
|
||||
|
||||
$list = Db::name('account_log')->alias('a')
|
||||
->join('user u','a.user_id = u.id')
|
||||
->where($where)
|
||||
->page($get['page'],$get['limit'])
|
||||
->order('a.id desc')
|
||||
->field('a.*,nickname,sn,mobile')
|
||||
->select();
|
||||
|
||||
foreach ($list as &$item){
|
||||
$item['source_type_desc'] = AccountLog::getAcccountDesc($item['source_type']);
|
||||
$item['create_time'] = date('Y-m-d H:i:s',$item['create_time']);
|
||||
// 获取来源单号
|
||||
$item['order_sn'] = Db::name('order')->where(['del'=>0, 'id'=>$item['source_id']])->value('order_sn');
|
||||
// + -
|
||||
$item['change_amount'] = $item['change_type'] == 1 ? "+{$item['change_amount']}" : "-{$item['change_amount']}";
|
||||
}
|
||||
return ['count'=>$count,'lists'=>$list];
|
||||
}
|
||||
|
||||
/**
|
||||
* note 每个资金记录页面的的变动类型
|
||||
* create_time 2020/11/23 9:55
|
||||
*/
|
||||
public static function orderSourceList($type){
|
||||
$list = [];
|
||||
switch ($type){
|
||||
case 1:
|
||||
$list = [
|
||||
[
|
||||
'source' => AccountLog::balance_pay_order,
|
||||
'name' => '订单支付',
|
||||
],
|
||||
[
|
||||
'source' => AccountLog::admin_add_money.','.AccountLog::recharge_money,
|
||||
'name' => '钱包充值',
|
||||
],
|
||||
[
|
||||
'source' => AccountLog::withdraw_to_balance,
|
||||
'name' => '佣金提现',
|
||||
],
|
||||
|
||||
];
|
||||
break;
|
||||
case 2:
|
||||
$list = [
|
||||
[
|
||||
'source' => AccountLog::register_add_integral,
|
||||
'name' => '关注赠送积分',
|
||||
],
|
||||
[
|
||||
'source' => AccountLog::invite_add_integral,
|
||||
'name' => '邀请赠送积分',
|
||||
],
|
||||
[
|
||||
'source' => AccountLog::sign_in_integral,
|
||||
'name' => '签到赠送积分',
|
||||
],
|
||||
[
|
||||
'source' => AccountLog::recharge_give_integral,
|
||||
'name' => '充值赠送积分',
|
||||
],
|
||||
[
|
||||
'source' => AccountLog::order_add_integral,
|
||||
'name' => '消费赠送积分',
|
||||
],
|
||||
[
|
||||
'source' => AccountLog::order_deduction_integral,
|
||||
'name' => '订单抵扣积分',
|
||||
],
|
||||
|
||||
];
|
||||
break;
|
||||
case 3:
|
||||
$list = [
|
||||
[
|
||||
'source' => AccountLog::sign_give_growth,
|
||||
'name' => '签到赠送成长值',
|
||||
],
|
||||
[
|
||||
'source' => AccountLog::recharge_give_growth,
|
||||
'name' => '充值赠送成长值',
|
||||
],
|
||||
[
|
||||
'source' => AccountLog::order_give_growth,
|
||||
'name' => '下单赠送成长值',
|
||||
],
|
||||
];
|
||||
break;
|
||||
}
|
||||
return $list;
|
||||
|
||||
}
|
||||
|
||||
public static function getTime(){
|
||||
$today = array_map(function ($time) {
|
||||
return date('Y-m-d H:i:s', $time);
|
||||
}, Time::today());
|
||||
$yesterday = array_map(function ($time) {
|
||||
return date('Y-m-d H:i:s', $time);
|
||||
}, Time::yesterday());
|
||||
|
||||
$days_ago7 = array_map(function ($time) {
|
||||
return date('Y-m-d H:i:s', $time);
|
||||
}, Time::dayToNow(7));
|
||||
|
||||
$days_ago30 = array_map(function ($time) {
|
||||
return date('Y-m-d H:i:s', $time);
|
||||
}, Time::dayToNow(30, true));
|
||||
$time = [
|
||||
'today' => $today,
|
||||
'yesterday' => $yesterday,
|
||||
'days_ago7' => $days_ago7,
|
||||
'days_ago30' => $days_ago30,
|
||||
];
|
||||
return $time;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//佣金记录
|
||||
public static function getDistributionLog($get)
|
||||
{
|
||||
$where = [];
|
||||
if (!empty($get['distribution_keyword_type']) and !empty($get['distribution_keyword']) and $get['distribution_keyword']) {
|
||||
switch ($get['distribution_keyword_type']) {
|
||||
case 'order_sn':
|
||||
$order_ids = Order::field('id,order_sn')->where('order_sn', $get['distribution_keyword'])->column('id');
|
||||
$og_ids = OrderGoods::field('id,order_id')->whereIn('id', $order_ids)->column('id');
|
||||
$where[] = ['order_goods_id', 'in', $og_ids];
|
||||
break;
|
||||
case 'nickname':
|
||||
$user_ids = User::field('id,sn,nickname')->where('nickname', 'like', '%'.$get['distribution_keyword'].'%')->column('id');
|
||||
$where[] = ['user_id', 'in', $user_ids];
|
||||
break;
|
||||
case 'user_sn':
|
||||
$user_ids = User::field('id,sn,nickname')->where('sn', 'like', '%'.$get['distribution_keyword'].'%')->column('id');
|
||||
$where[] = ['user_id', 'in', $user_ids];
|
||||
break;
|
||||
case 'mobile':
|
||||
$user_ids = User::field('id,sn,mobile')->where('mobile', '=', $get['distribution_keyword'])->column('id');
|
||||
$where[] = ['user_id', 'in', $user_ids];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($get['distribution_status']) and is_numeric($get['distribution_status'])) {
|
||||
$where[] = ['d.status', '=', $get['distribution_status']];
|
||||
}
|
||||
if (!empty($get['distribution_start_time']) and $get['distribution_start_time']) {
|
||||
$where[] = ['d.create_time', '>=', strtotime($get['distribution_start_time'])];
|
||||
}
|
||||
if (!empty($get['distribution_end_time']) and $get['distribution_end_time']) {
|
||||
$where[] = ['d.create_time', '<=', strtotime($get['distribution_end_time'])];
|
||||
}
|
||||
|
||||
// 查询结果
|
||||
$count = DistributionOrder::where($where)->alias('d')
|
||||
->join('order_goods og', 'order_goods_id = og.id')
|
||||
->count();
|
||||
$lists = DistributionOrder::field('d.*, og.order_id')
|
||||
->where($where)->alias('d')
|
||||
->join('order_goods og', 'order_goods_id = og.id')
|
||||
->with('user')
|
||||
->withAttr('order', function ($value, $data) {
|
||||
return Order::field('id,order_sn,order_amount')->where(['id'=>$data['order_id']])->find();
|
||||
})
|
||||
->page($get['page'], $get['limit'])
|
||||
->append(['order'])
|
||||
->order('d.id desc')
|
||||
->select();
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['status_text'] = DistributionOrder::getOrderStatus($item['status']);
|
||||
$item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
|
||||
}
|
||||
return ['count'=>$count, 'lists'=>$lists];
|
||||
}
|
||||
|
||||
|
||||
//佣金统计
|
||||
public static function withdrawTotalCount($get)
|
||||
{
|
||||
// 今天开始和结束时间戳
|
||||
list($startToday, $endToday) = Time::today();
|
||||
// 本月开始和结束时间戳
|
||||
list($startMonth, $endMonth) = Time::month();
|
||||
|
||||
if ($get['type'] == 'distribution') {
|
||||
// 获取分销佣金总计
|
||||
$distributionToday = DistributionOrder::where('status', 'in', [DistributionOrder::STATUS_WAIT_HANDLE, DistributionOrder::STATUS_SUCCESS])
|
||||
->where('create_time', '>=', $startToday)
|
||||
->where('create_time', '<=', $endToday)
|
||||
->sum('money');
|
||||
|
||||
$distributionMonth = DistributionOrder::where('status', 'in', [DistributionOrder::STATUS_WAIT_HANDLE, DistributionOrder::STATUS_SUCCESS])
|
||||
->where('create_time', '>=', $startMonth)
|
||||
->where('create_time', '<=', $endMonth)
|
||||
->sum('money');
|
||||
|
||||
$distributionTotal = DistributionOrder::where('status', 'in', [DistributionOrder::STATUS_WAIT_HANDLE, DistributionOrder::STATUS_SUCCESS])
|
||||
->sum('money');
|
||||
|
||||
return ['today'=>$distributionToday, 'month'=>$distributionMonth, 'total'=>$distributionTotal];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\logic;
|
||||
use app\common\server\UrlServer;
|
||||
use think\Db;
|
||||
|
||||
class ActivityAreaLogic{
|
||||
/**
|
||||
* note 活动专区列表
|
||||
* create_time 2020/11/24 11:23
|
||||
*/
|
||||
public static function areaLists($get){
|
||||
$count = Db::name('activity_area')
|
||||
->where(['del'=>0])
|
||||
->count();
|
||||
|
||||
$lists = Db::name('activity_area')
|
||||
->where(['del'=>0])
|
||||
->page($get['page'], $get['limit'])
|
||||
->select();
|
||||
foreach ($lists as &$item){
|
||||
$item['status_desc'] = '下架';
|
||||
$item['status'] && $item['status_desc'] = '上架';
|
||||
$item['image'] = UrlServer::getFileUrl($item['image']);
|
||||
}
|
||||
|
||||
return ['count'=>$count,'lists'=>$lists];
|
||||
|
||||
}
|
||||
/**
|
||||
* note 活动专区商品
|
||||
* create_time 2020/11/24 11:24
|
||||
*/
|
||||
public static function goodsLists($get){
|
||||
$where[] = ['AG.del','=',0];
|
||||
$where[] = ['AA.del','=',0];
|
||||
if(isset($get['name']) && $get['name']){
|
||||
$where[] = ['G.name','like','%'.$get['name'].'%'];
|
||||
}
|
||||
if(isset($get['activity_id']) && $get['activity_id']){
|
||||
$where[] = ['AA.id','=',$get['activity_id']];
|
||||
}
|
||||
|
||||
$count = Db::name('activity_goods')->alias('AG')
|
||||
->join('activity_area AA','AG.activity_id = AA.id')
|
||||
->join('goods G','AG.Goods_id = G.id')
|
||||
->where($where)
|
||||
->count();
|
||||
|
||||
|
||||
$lists = Db::name('activity_goods')->alias('AG')
|
||||
->join('activity_area AA','AG.activity_id = AA.id')
|
||||
->join('goods G','AG.Goods_id = G.id')
|
||||
->where($where)
|
||||
->field('AG.id,AG.goods_id,AG.activity_id,AA.name,AA.status,G.id,G.name,G.image')
|
||||
->page($get['page'], $get['limit'])
|
||||
->order('AG.id desc')
|
||||
->select();
|
||||
$activity_lisst = Db::name('activity_area')
|
||||
->where(['del'=>0])
|
||||
->column('name,status','id');
|
||||
foreach ($lists as &$item){
|
||||
$item['activity_name'] = '';
|
||||
$item['status_desc'] = '下架';
|
||||
|
||||
if(isset($activity_lisst[$item['activity_id']])){
|
||||
$item['activity_name'] = $activity_lisst[$item['activity_id']]['name'];
|
||||
$activity_lisst[$item['activity_id']]['status'] && $item['status_desc'] = '上架';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ['count'=>$count,'lists'=>$lists];
|
||||
}
|
||||
|
||||
/**
|
||||
* note 获取全部的活动专区
|
||||
* create_time 2020/11/24 12:01
|
||||
*/
|
||||
public static function getActivityList(){
|
||||
return Db::name('activity_area')
|
||||
->where(['del'=>0])
|
||||
->column('name','id');
|
||||
|
||||
}
|
||||
/**
|
||||
* note 添加活动专区
|
||||
* create_time 2020/11/24 12:01
|
||||
*/
|
||||
public static function addActivity($post){
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'title' => $post['title'],
|
||||
'image' => $post['image'],
|
||||
'status' => $post['status'],
|
||||
'del' => 0,
|
||||
'create_time' => time(),
|
||||
];
|
||||
return Db::name('activity_area')->insert($data);
|
||||
}
|
||||
/**
|
||||
* note 编辑活动专区
|
||||
* create_time 2020/11/24 12:02
|
||||
*/
|
||||
public static function editActivity($post){
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'title' => $post['title'],
|
||||
'image' => $post['image'],
|
||||
'status' => $post['status'],
|
||||
'update_time' => time(),
|
||||
];
|
||||
return Db::name('activity_area')->where(['id'=>$post['id']])->update($data);
|
||||
}
|
||||
/**
|
||||
* note 删除活动专区
|
||||
* create_time 2020/11/24 12:02
|
||||
*/
|
||||
public static function delActivity($id){
|
||||
Db::name('activity_area')->where(['id'=>$id])->update(['update_time'=>time(),'del'=>1]);
|
||||
Db::name('activity_goods')->where(['activity_id'=>$id])->update(['update_time'=>time(),'del'=>1]);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* note 获取活动商品详情
|
||||
* create_time 2020/11/25 10:40
|
||||
*/
|
||||
public static function getActivity($id){
|
||||
$activity = Db::name('activity_area')->where(['id'=>$id])->find();
|
||||
$activity['image'] = UrlServer::getFileUrl($activity['image']);
|
||||
return $activity;
|
||||
}
|
||||
|
||||
/**
|
||||
* note 添加活动商品
|
||||
* create_time 2020/11/25 10:40
|
||||
*/
|
||||
public static function addGoods($post)
|
||||
{
|
||||
return Db::name('activity_goods')->insert([
|
||||
'activity_id' => $post['activity_id'],
|
||||
'goods_id' => $post['goods_id'][0],
|
||||
'del' => 0,
|
||||
'create_time' => time(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* note 编辑活动商品
|
||||
* create_time 2020/11/25 10:40
|
||||
*/
|
||||
public static function editGoods($post){
|
||||
$new = time();
|
||||
$update_data = [
|
||||
'activity_id' => $post['activity_id'],
|
||||
'update_time' => $new,
|
||||
];
|
||||
|
||||
return Db::name('activity_goods')
|
||||
->where(['id'=>$post['id'],'activity_id'=>$post['activity_id']])
|
||||
->update($update_data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* note 删除活动商品
|
||||
* create_time 2020/11/25 10:40
|
||||
*/
|
||||
public static function delGoods($goods_id,$activity_id){
|
||||
$update_data = [
|
||||
'update_time' => time(),
|
||||
'del' => 1,
|
||||
];
|
||||
return Db::name('activity_goods')->where(['del'=>0,'goods_id'=>$goods_id,'activity_id'=>$activity_id])->update($update_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* note 获取活动商品详情
|
||||
* create_time 2020/11/25 10:41
|
||||
*/
|
||||
public static function getActivityGoods($goods_id,$activity_id){
|
||||
$activity_list = Db::name('activity_goods')->alias('AG')
|
||||
->join('goods_item GI','AG.item_id = GI.id')
|
||||
->where(['activity_id'=>$activity_id,'AG.goods_id'=>$goods_id])
|
||||
->field('AG.*,GI.price,GI.spec_value_str,GI.image,GI.price')
|
||||
->select();
|
||||
|
||||
$goods_id = $activity_list[0]['goods_id'];
|
||||
$goods = Db::name('goods')->where(['del'=>0,'id'=>$goods_id])->field('image,name')->find();
|
||||
|
||||
foreach ($activity_list as &$item){
|
||||
$item['name'] = $goods['name'];
|
||||
if(empty($item['image'])){
|
||||
$item['image'] = $goods['image'];
|
||||
}
|
||||
}
|
||||
return $activity_list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,306 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\common\model\Ad;
|
||||
use app\admin\model\AdPosition;
|
||||
use app\common\server\UrlServer;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
|
||||
class AdLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* 广告管理列表
|
||||
* @param $get
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
$ad = new Ad();
|
||||
$where = [];
|
||||
$where[] = ['del', '=', 0];
|
||||
if ($get['client'] != '') {
|
||||
$where[] = ['client', '=', $get['client']];
|
||||
}
|
||||
if (isset($get['keyword']) && $get['keyword']) {
|
||||
$where[] = ['name', 'like', '%' . $get['keyword'] . '%'];
|
||||
}
|
||||
|
||||
if (isset($get['pid']) && $get['pid'] != '') {
|
||||
$where[] = ['pid', '=', $get['pid']];
|
||||
}
|
||||
|
||||
$ad_count = $ad
|
||||
->where($where)
|
||||
->count();
|
||||
$ad_list = $ad->where($where)
|
||||
->page($get['page'], $get['limit'])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select();
|
||||
|
||||
$position = AdPosition::where('del', 0)->column('id,name', 'id');
|
||||
|
||||
foreach ($ad_list as $item) {
|
||||
$item['image'] = UrlServer::getFileUrl($item['image']);
|
||||
|
||||
$url = '';
|
||||
$item['client_name'] = Ad::getAdTypeDesc($item['client']);
|
||||
if (isset($position[$item['pid']])) {
|
||||
$item['position_name'] = $position[$item['pid']];
|
||||
}
|
||||
switch ($item['link_type']) {
|
||||
case 1:
|
||||
$page = Ad::getLinkPage($item['client'], $item['link']);
|
||||
$url = '商城页面:' . $page['name'];
|
||||
break;
|
||||
case 2:
|
||||
$goods = Db::name('goods g')
|
||||
->where(['g.id' => $item['link']])
|
||||
->field('g.name,min_price,max_price')
|
||||
->find();
|
||||
if ($goods) {
|
||||
$price = '¥' . $goods['max_price'];
|
||||
if ($goods['max_price'] !== $goods['min_price']) {
|
||||
$price = '¥' . $goods['min_price'] . '~' . $goods['max_price'];
|
||||
}
|
||||
$url = '商品页面:' . $goods['name'] . '价格:' . $price;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
$url = '自定义链接:' . $item['link'];
|
||||
}
|
||||
$item['link'] = $url;
|
||||
|
||||
|
||||
}
|
||||
return ['count' => $ad_count, 'list' => $ad_list];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param $post
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function add($post)
|
||||
{
|
||||
|
||||
$ad = new Ad();
|
||||
|
||||
$post['type'] = isset($post['type']) ? $post['type'] : 1;
|
||||
$post['status'] = isset($post['status']) ? $post['status'] : 0;
|
||||
$post['link_type'] = isset($post['link_type']) ? $post['link_type'] : '';
|
||||
$link = '';
|
||||
|
||||
switch ($post['link_type']) {
|
||||
case '1':
|
||||
$link = $post['page'];
|
||||
break;
|
||||
case '2':
|
||||
$link = $post['goods_id'];
|
||||
break;
|
||||
case '3':
|
||||
$link = $post['url'];
|
||||
break;
|
||||
}
|
||||
$time = time();
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'client' => $post['client'],
|
||||
'pid' => $post['pid'],
|
||||
'image' => $post['image'],
|
||||
'link_type' => $post['link_type'],
|
||||
'link' => $link,
|
||||
'status' => $post['status'],
|
||||
'category_id' => $post['category_id'] ?? 0,
|
||||
'create_time' => $time,
|
||||
'sort' => $post['sort'] ?? 50,
|
||||
];
|
||||
|
||||
return $ad->allowField(true)->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param $post
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function edit($post)
|
||||
{
|
||||
$ad = new Ad();
|
||||
$post['type'] = isset($post['type']) ? $post['type'] : 1;
|
||||
$post['status'] = isset($post['status']) ? $post['status'] : 0;
|
||||
$post['link_type'] = isset($post['link_type']) ? $post['link_type'] : '';
|
||||
$time = time();
|
||||
$link = '';
|
||||
switch ($post['link_type']) {
|
||||
case '1':
|
||||
$link = $post['page'];
|
||||
break;
|
||||
case '2':
|
||||
$link = $post['goods_id'];
|
||||
break;
|
||||
case '3':
|
||||
$link = $post['url'];
|
||||
break;
|
||||
}
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'client' => $post['client'],
|
||||
'pid' => $post['pid'],
|
||||
'image' => $post['image'],
|
||||
'link_type' => $post['link_type'],
|
||||
'link' => $link,
|
||||
'category_id' => $post['category_id'] ?? 0,
|
||||
'status' => $post['status'],
|
||||
'update_time' => $time,
|
||||
'sort' => $post['sort'] ?? 50,
|
||||
];
|
||||
return $ad->allowField(true)->save($data, ['id' => $post['id']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param $delData
|
||||
* @return int|string
|
||||
* @throws Exception
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function del($id, $client)
|
||||
{
|
||||
$data = [
|
||||
'del' => 1,
|
||||
'update_time' => time(),
|
||||
];
|
||||
return Db::name('ad')->where(['client' => $client, 'del' => 0, 'id' => $id])->update($data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 广告表信息
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public static function info($id)
|
||||
{
|
||||
$ad = new Ad();
|
||||
$info = $ad::get(['id' => $id]);
|
||||
$info['goods'] = '';
|
||||
if ($info['link_type'] == 2) {
|
||||
$goods = Db::name('goods g')
|
||||
->where(['g.id' => $info['link']])
|
||||
->field('g.id, g.name, g.image, min_price, max_price')
|
||||
->find();
|
||||
$price = '¥' . $goods['max_price'];
|
||||
if ($goods['max_price'] !== $goods['min_price']) {
|
||||
$price = '¥' . $goods['min_price'] . '~' . $goods['max_price'];
|
||||
}
|
||||
$goods['price'] = $price;
|
||||
$goods['image'] = UrlServer::getFileUrl($goods['image']);
|
||||
$info['goods'] = $goods;
|
||||
}
|
||||
$info['abs_image'] = UrlServer::getFileUrl($info['image']);
|
||||
|
||||
$info['position_desc'] = '';
|
||||
if (isset($info['pid'])) {
|
||||
$position = Db::name('ad_position')
|
||||
->field('width, height')
|
||||
->where(['id' => $info['pid']])
|
||||
->find();
|
||||
$info['position_desc'] = '建议上传广告图片宽*高, '.$position['width'].'px*'.$position['height'].'px';
|
||||
}
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取广告位置列表
|
||||
* @return array
|
||||
*/
|
||||
public static function infoPosition($client)
|
||||
{
|
||||
$position_list = Db::name('ad_position')
|
||||
->where(['client' => $client, 'status' => 1, 'del' => 0])
|
||||
->group('name')
|
||||
->column('id,name', 'id');
|
||||
asort($position_list);
|
||||
return $position_list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更改状态
|
||||
* @param $get
|
||||
* @return int|string
|
||||
* @throws Exception
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function switchStatus($get)
|
||||
{
|
||||
$data = [
|
||||
'status' => $get['status'],
|
||||
'update_time' => time(),
|
||||
];
|
||||
return Db::name('ad')->where(['client' => $get['client'], 'del' => 0, 'id' => $get['id']])->update($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取相应广告位置尺寸
|
||||
* @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 imgSize($get)
|
||||
{
|
||||
$img_size = Db::name('ad_position')
|
||||
->where(['id' => $get['id'], 'del' => 0])
|
||||
->field('width,height')
|
||||
->find();
|
||||
return $img_size;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes:筛选首页推荐分类
|
||||
* @return array|\PDOStatement|string|\think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
* @author: 2021/3/6 12:01
|
||||
*/
|
||||
public static function getGoodsCategory(){
|
||||
return Db::name('goods_category')->where(['level'=>1,'is_recommend'=>1])->field('id,name')->select();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
use app\admin\model\AdPosition;
|
||||
use app\common\model\Ad;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
|
||||
class AdPositionLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* 广告管理列表
|
||||
* @param $get
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
$ad_position = new AdPosition();
|
||||
$where = [];
|
||||
$where[] = ['del', '=', 0];
|
||||
|
||||
if ($get['client'] != '') {
|
||||
if ($get['client'] == 3) {
|
||||
$where[] = ['client', ['=', 3], ['=', 4], 'or'];
|
||||
} else {
|
||||
$where[] = ['client', '=', $get['client']];
|
||||
}
|
||||
}
|
||||
if (isset($get['keyword']) && $get['keyword']) {
|
||||
$where[] = ['name', 'like', '%' . $get['keyword'] . '%'];
|
||||
}
|
||||
|
||||
if (isset($get['attr']) && $get['attr'] != '') {
|
||||
$where[] = ['attr', '=', $get['attr']];
|
||||
}
|
||||
|
||||
$ad_position_count = $ad_position
|
||||
->where($where)
|
||||
->count();
|
||||
$ad_position_list = $ad_position
|
||||
->where($where)
|
||||
->page($get['page'], $get['limit'])
|
||||
->select();
|
||||
|
||||
|
||||
foreach ($ad_position_list as $item) {
|
||||
$item['client_name'] = Ad::getAdTypeDesc($item['client']);
|
||||
|
||||
}
|
||||
return ['count' => $ad_position_count, 'list' => $ad_position_list];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param $post
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function addAdPosition($post)
|
||||
{
|
||||
|
||||
$ad_position = new AdPosition();
|
||||
$post['status'] = isset($post['status']) ? $post['status'] : 0;
|
||||
|
||||
$time = time();
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'width' => $post['width'],
|
||||
'height' => $post['height'],
|
||||
'status' => $post['status'],
|
||||
'client' => $post['client'],
|
||||
'attr' => 0,
|
||||
'create_time' => $time,
|
||||
|
||||
];
|
||||
|
||||
return $ad_position->allowField(true)->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param $post
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function editAdPosition($post)
|
||||
{
|
||||
$ad_position = new AdPosition();
|
||||
|
||||
$post['status'] = isset($post['status']) ? $post['status'] : 0;
|
||||
|
||||
|
||||
$time = time();
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'width' => $post['width'],
|
||||
'height' => $post['height'],
|
||||
'status' => $post['status'],
|
||||
'attr' => $post['attr'],
|
||||
'update_time' => $time,
|
||||
|
||||
];
|
||||
|
||||
return $ad_position->allowField(true)->save($data, ['id' => $post['id']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param $delData
|
||||
* @return int|string
|
||||
* @throws Exception
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function del($delData, $client, $attr)
|
||||
{
|
||||
|
||||
if (is_array($attr)) {
|
||||
foreach ($attr as $key => $val) {
|
||||
if ($val == 1) {
|
||||
unset($delData[$key]);
|
||||
}
|
||||
}
|
||||
} elseif ($attr == 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (is_array($delData)) {
|
||||
$pid = Db::name('ad')
|
||||
->where(['client' => $client, 'pid' => $delData, 'del' => 0])
|
||||
->select();
|
||||
if (!empty($pid)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$pid = Db::name('ad')
|
||||
->where(['client' => $client, 'pid' => $delData, 'del' => 0])
|
||||
->find();
|
||||
if (!empty($pid)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$data = [
|
||||
'del' => 1,
|
||||
'update_time' => time(),
|
||||
];
|
||||
$result = Db::name('ad_position')->where(['client' => $client, 'id' => $delData, 'del' => 0])->update($data);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 广告表信息
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public static function info($id)
|
||||
{
|
||||
|
||||
$ad_position = new AdPosition();
|
||||
$info = $ad_position::get(['id' => $id]);
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更改状态
|
||||
* @param $get
|
||||
* @return int|string
|
||||
* @throws Exception
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function switchStatus($get)
|
||||
{
|
||||
$data = [
|
||||
'status' => $get['status'],
|
||||
'update_time' => time(),
|
||||
];
|
||||
return Db::name('ad_position')
|
||||
->where(['client' => $get['client'], 'id' => $get['id'], 'del' => 0])
|
||||
->update($data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
use app\admin\server\LoginServer;
|
||||
use think\Db;
|
||||
|
||||
class AdminLogic
|
||||
{
|
||||
/**
|
||||
* 管理员列表
|
||||
* @param $get
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
$role_id_name = Db::name('role')
|
||||
->column('name', 'id');
|
||||
|
||||
$where[] = ['del', '=', 0];
|
||||
if (isset($get['role_id']) && $get['role_id']) {
|
||||
$where[] = ['role_id', '=', $get['role_id']];
|
||||
}
|
||||
if (isset($get['name']) && $get['name']) {
|
||||
$where[] = ['name', 'like', "%{$get['name']}%"];
|
||||
}
|
||||
if (isset($get['account']) && $get['account']) {
|
||||
$where[] = ['account', 'like', "%{$get['account']}%"];
|
||||
}
|
||||
|
||||
$admin_count = Db::name('admin')
|
||||
->where($where)
|
||||
->count();
|
||||
$admin_lists = Db::name('admin')
|
||||
->where($where)
|
||||
->field(['id', 'root', 'name', 'account', 'role_id', 'create_time', 'login_time', 'login_ip', 'disable'])
|
||||
->select();
|
||||
foreach ($admin_lists as $k => $v) {
|
||||
if ($v['root'] == 1) {
|
||||
$admin_lists[$k]['role'] = '超级管理员';
|
||||
} else {
|
||||
$admin_lists[$k]['role'] = $role_id_name[$v['role_id']];
|
||||
}
|
||||
$admin_lists[$k]['create_time_str'] = date('Y-m-d H:i:s', $v['create_time']);
|
||||
$admin_lists[$k]['login_time'] = empty($v['login_time']) ? '' : date('Y-m-d H:i:s', $v['login_time']);
|
||||
$admin_lists[$k]['login_state'] = LoginServer::isLogin($v['id']) ? 1 : 0;
|
||||
}
|
||||
return ['count' => $admin_count, 'lists' => $admin_lists];
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员信息
|
||||
* @param $admin_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 info($admin_id)
|
||||
{
|
||||
return Db::name('admin')->where(['id' => $admin_id])->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色信息
|
||||
* @return array|\PDOStatement|string|\think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function roleLists()
|
||||
{
|
||||
return Db::name('role')
|
||||
->where(['del' => 0])
|
||||
->field(['id', 'name'])
|
||||
->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加管理员
|
||||
* @param $post
|
||||
* @return mixed
|
||||
*/
|
||||
public static function addAdmin($post)
|
||||
{
|
||||
$time = time();
|
||||
$salt = substr(md5($time . $post['name']), 0, 4);//随机4位密码盐
|
||||
$password = create_password($post['password'], $salt);//生成密码
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'root' => 0,
|
||||
'account' => $post['account'],
|
||||
'password' => $password,
|
||||
'salt' => $salt,
|
||||
'role_id' => $post['role_id'],
|
||||
'create_time' => $time,
|
||||
'disable' => $post['disable']
|
||||
];
|
||||
return Db::name('admin')->insert($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑管理员
|
||||
* @param $post
|
||||
* @return mixed
|
||||
*/
|
||||
public static function editAdmin($post)
|
||||
{
|
||||
$time = time();
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'account' => $post['account'],
|
||||
'role_id' => $post['role_id'],
|
||||
'update_time' => $time,
|
||||
'disable' => $post['disable']
|
||||
];
|
||||
|
||||
if ($post['password']) {
|
||||
$salt = Db::name('admin')->where(['id' => $post['id']])->value('salt');
|
||||
$data['password'] = create_password($post['password'], $salt);//生成密码
|
||||
}
|
||||
|
||||
$role_id = Db::name('admin')->where(['id' => $post['id']])->value('role_id');
|
||||
if ($post['disable'] == 1 || $role_id != $post['role_id']) {
|
||||
//禁用管理员并强制下线
|
||||
LoginServer::setState($post['id'], false);
|
||||
}
|
||||
|
||||
return Db::name('admin')->where(['id' => $post['id']])->update($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除管理员
|
||||
* @param $admin_id
|
||||
* @return int|string
|
||||
* @throws \think\Exception
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function delAdmin($admin_id)
|
||||
{
|
||||
$time = time();
|
||||
return Db::name('admin')
|
||||
->where(['id' => $admin_id, 'del' => 0])
|
||||
->update(['account' => $time . '_' . $admin_id, 'del' => 1]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,455 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\api\logic\DistributionLogic;
|
||||
use app\common\logic\AccountLogLogic;
|
||||
use app\common\logic\OrderRefundLogic;
|
||||
use app\common\server\AreaServer;
|
||||
use app\common\server\ConfigServer;
|
||||
use app\common\server\UrlServer;
|
||||
use app\common\server\WeChatServer;
|
||||
use app\common\logic\AfterSaleLogLogic;
|
||||
use app\common\logic\PaymentLogic;
|
||||
use app\common\model\{AccountLog, AfterSale, AfterSaleLog, Goods, MessageScene_, NoticeSetting, Order, OrderGoods, Pay};
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use think\facade\Env;
|
||||
use think\facade\Hook;
|
||||
|
||||
class AfterSaleLogic
|
||||
{
|
||||
/**
|
||||
* Notes: 列表
|
||||
* @param $get
|
||||
* @author 段誉(2021/1/30 16:56)
|
||||
* @return array
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
$after_sale = new AfterSale();
|
||||
$where = [];
|
||||
|
||||
$where[] = ['a.del', '=', 0];
|
||||
|
||||
// 订单类型
|
||||
if (isset($get['type']) && $get['type'] !== '') {
|
||||
$where[] = ['status', '=', intval($get['type'])];
|
||||
}
|
||||
|
||||
// 订单搜索
|
||||
if (!empty($get['search_key']) && !empty($get['keyword'])) {
|
||||
$keyword = addslashes(trim($get['keyword']));
|
||||
switch ($get['search_key']) {
|
||||
case 'sn':
|
||||
$where[] = ['a.sn', 'like', '%' . $keyword . '%'];
|
||||
break;
|
||||
case 'order_sn':
|
||||
$where[] = ['o.order_sn', 'like', '%' . $keyword . '%'];
|
||||
break;
|
||||
case 'goods_name':
|
||||
$where[] = ['g.goods_name', 'like', '%' . $keyword . '%'];
|
||||
break;
|
||||
case 'user_sn':
|
||||
$where[] = ['u.sn', 'like', '%' . $keyword . '%'];
|
||||
break;
|
||||
case 'nickname':
|
||||
$where[] = ['u.nickname', 'like', '%' . $keyword . '%'];
|
||||
break;
|
||||
case 'user_mobile':
|
||||
$where[] = ['u.mobile', 'like', '%' . $keyword . '%'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 状态过滤
|
||||
if (isset($get['status']) && $get['status'] !== '') {
|
||||
$where[] = ['a.status', '=', intval($get['status'])];
|
||||
}
|
||||
|
||||
// 下单时间
|
||||
if (isset($get['start_time']) && $get['start_time'] !== '') {
|
||||
$where[] = ['a.create_time', '>=', strtotime($get['start_time'])];
|
||||
}
|
||||
if (isset($get['end_time']) && $get['end_time'] !== '') {
|
||||
$where[] = ['a.create_time', '<=', strtotime($get['end_time'])];
|
||||
}
|
||||
|
||||
$field = 'a.id,a.sn,a.status,a.order_id,a.order_goods_id,
|
||||
a.user_id,a.refund_type,a.create_time,a.refund_price,
|
||||
o.order_status,o.pay_way';
|
||||
|
||||
// 使用预编译查询
|
||||
$count = $after_sale
|
||||
->alias('a')
|
||||
->join('order o', 'o.id = a.order_id')
|
||||
->join('user u', 'u.id = a.user_id')
|
||||
->join('order_goods g', 'g.id = a.order_goods_id')
|
||||
->with(['order_goods', 'user', 'order'])
|
||||
->where($where)
|
||||
->group('a.id')
|
||||
->count();
|
||||
|
||||
$page = max(1, intval($get['page']));
|
||||
$limit = max(1, intval($get['limit']));
|
||||
|
||||
$lists = $after_sale
|
||||
->alias('a')
|
||||
->field($field)
|
||||
->join('order o', 'o.id = a.order_id')
|
||||
->join('user u', 'u.id = a.user_id')
|
||||
->join('order_goods g', 'g.id = a.order_goods_id')
|
||||
->with(['order_goods', 'user', 'order'])
|
||||
->where($where)
|
||||
->page($page, $limit)
|
||||
->order('a.id desc')
|
||||
->append(['user.base_avatar', 'order_goods.base_image'])
|
||||
->group('a.id')
|
||||
->select();
|
||||
|
||||
foreach ($lists as $key => $list) {
|
||||
$lists[$key]['order']['pay_way'] = Pay::getPayWay($list['order']['pay_way']);
|
||||
$lists[$key]['order']['order_status_text'] = Order::getOrderStatus($list['order']['order_status']);
|
||||
$lists[$key]['refund_type'] = AfterSale::getRefundTypeDesc($list['refund_type']);
|
||||
$lists[$key]['create_time'] = date('Y-m-d H:i:s', $list['create_time']);
|
||||
$lists[$key]['status'] = AfterSale::getStatusDesc($list['status']);
|
||||
|
||||
foreach ($list['order_goods'] as $ko => $good) {
|
||||
$info = json_decode($good['goods_info'], true);
|
||||
$lists[$key]['order_goods'][$ko]['goods_name'] = $info['goods_name'];
|
||||
$lists[$key]['order_goods'][$ko]['spec_value'] = $info['spec_value_str'];
|
||||
$lists[$key]['order_goods'][$ko]['image'] = empty($info['spec_image']) ?
|
||||
UrlServer::getFileUrl($info['image']) : UrlServer::getFileUrl($info['spec_image']);
|
||||
}
|
||||
}
|
||||
return ['count' => $count, 'lists' => $lists];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 详情
|
||||
* @param $id
|
||||
* @author 段誉(2021/1/30 16:56)
|
||||
* @return array
|
||||
*/
|
||||
public static function getDetail($id)
|
||||
{
|
||||
$after_sale = new AfterSale();
|
||||
$result = $after_sale
|
||||
->with(['order_goods', 'user', 'order', 'logs'])
|
||||
->where('id', $id)
|
||||
->find()->toArray();
|
||||
|
||||
$result['refund_type_text'] = AfterSale::getRefundTypeDesc($result['refund_type']);
|
||||
$result['status_text'] = AfterSale::getStatusDesc($result['status']);
|
||||
$result['order']['pay_way'] = Pay::getPayWay($result['order']['pay_way']);
|
||||
$result['order']['order_status'] = Order::getOrderStatus($result['order']['order_status']);
|
||||
$result['order']['delivery_type_text'] = Order::getDeliveryType($result['order']['delivery_type']);
|
||||
$result['create_time'] = date('Y-m-d H:i:s', $result['create_time']);
|
||||
|
||||
foreach ($result['order_goods'] as &$good) {
|
||||
$info = json_decode($good['goods_info'], true);
|
||||
$good['goods_name'] = $info['goods_name'];
|
||||
$good['spec_value'] = $info['spec_value_str'];
|
||||
$good['image'] = empty($info['spec_image']) ?
|
||||
UrlServer::getFileUrl($info['image']) : UrlServer::getFileUrl($info['spec_image']);
|
||||
}
|
||||
|
||||
foreach ($result['order_goods'] as &$good) {
|
||||
$info = json_decode($good['goods_info'], true);
|
||||
$good['goods_name'] = $info['goods_name'];
|
||||
$good['spec_value'] = $info['spec_value_str'];
|
||||
$good['image'] = empty($info['spec_image']) ?
|
||||
UrlServer::getFileUrl($info['image']) : UrlServer::getFileUrl($info['spec_image']);
|
||||
}
|
||||
|
||||
foreach ($result['logs'] as &$log){
|
||||
$log['create_time'] = date('Y-m-d H:i:s', $log['create_time']);
|
||||
|
||||
$log['log_img'] = '';
|
||||
$log['log_remark'] = '';
|
||||
switch ($log['channel']){
|
||||
//会员申请售后
|
||||
case AfterSaleLog::USER_APPLY_REFUND:
|
||||
$log['log_img'] = empty($result['refund_image']) ? '' : UrlServer::getFileUrl($result['refund_image']);
|
||||
$refund_reason = empty($result['refund_reason']) ? '未知' : $result['refund_reason'];
|
||||
$refund_remark = empty($result['refund_remark']) ? '暂无' : $result['refund_remark'];
|
||||
$log['log_remark'] = '退款原因('.$refund_reason.')'.'退款说明('.$refund_remark.')';
|
||||
break;
|
||||
//会员发快递
|
||||
case AfterSaleLog::USER_SEND_EXPRESS:
|
||||
$log['log_img'] = empty($result['express_image']) ? '' : UrlServer::getFileUrl($result['express_image']);
|
||||
$express_name = $result['express_name'];
|
||||
$invoice_no = $result['invoice_no'];
|
||||
$express_remark = empty($result['express_remark']) ? '暂无' : $result['express_remark'];
|
||||
$log['log_remark'] = '快递公司('.$express_name.')'.'单号('.$invoice_no.')'.'备注说明('.$express_remark.')';
|
||||
break;
|
||||
//商家拒绝退款 //商家拒绝收货
|
||||
case AfterSaleLog::SHOP_REFUSE_REFUND:
|
||||
case AfterSaleLog::SHOP_REFUSE_TAKE_GOODS:
|
||||
$admin_remark = empty($result['admin_remark']) ? '暂无' : $result['admin_remark'];
|
||||
$log['log_remark'] = '备注:'.$admin_remark;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$result['shop_address'] = self::getShopAddress();
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 商家同意售后
|
||||
* @param $id
|
||||
* @param $admin_id
|
||||
* @author 段誉(2021/1/30 16:56)
|
||||
*/
|
||||
public static function agree($id, $admin_id)
|
||||
{
|
||||
$after_sale = AfterSale::get($id);
|
||||
|
||||
$after_sale->update_time = time();
|
||||
//仅退款
|
||||
if ($after_sale['refund_type'] == AfterSale::TYPE_ONLY_REFUND) {
|
||||
$after_sale->status = AfterSale::STATUS_WAIT_REFUND;//更新为等待退款状态
|
||||
}
|
||||
|
||||
//退款退货
|
||||
if ($after_sale['refund_type'] == AfterSale::TYPE_REFUND_RETURN) {
|
||||
$after_sale->status = AfterSale::STATUS_WAIT_RETURN_GOODS;//更新为商品待退货状态
|
||||
}
|
||||
|
||||
$after_sale->save();
|
||||
//记录日志
|
||||
AfterSaleLogLogic::record(
|
||||
AfterSaleLog::TYPE_SHOP,
|
||||
AfterSaleLog::SHOP_AGREE_REFUND,
|
||||
$after_sale['order_id'],
|
||||
$after_sale['id'],
|
||||
$admin_id,
|
||||
AfterSaleLog::SHOP_AGREE_REFUND
|
||||
);
|
||||
|
||||
// 仅退款;更新订单商品为等待退款
|
||||
if ($after_sale['refund_type'] == AfterSale::TYPE_ONLY_REFUND) {
|
||||
$order_goods = OrderGoods::get(['id' => $after_sale['order_goods_id']]);
|
||||
$order_goods->refund_status = OrderGoods::REFUND_STATUS_WAIT;//等待退款
|
||||
$order_goods->save();
|
||||
}
|
||||
|
||||
$mobile = Db::name('order')->where(['id'=>$after_sale->order_id])->value('mobile');
|
||||
//发送短信
|
||||
$nickname = Db::name('user')->where(['id' => $after_sale->user_id])->value('nickname');
|
||||
Hook::listen('sms_send', [
|
||||
'key' => NoticeSetting::PLATFORM_PASS_REFUND_NOTICE,
|
||||
'mobile' => $mobile,
|
||||
'user_id' => $after_sale['user_id'],
|
||||
'params' => ['nickname' => $nickname, 'order_sn' => $after_sale->sn],
|
||||
]);
|
||||
|
||||
//消息通知
|
||||
Hook::listen('notice', [
|
||||
'user_id' => $after_sale['user_id'],
|
||||
'order_id' => $after_sale['order_id'],
|
||||
'refund_amount' => $after_sale['refund_price'],
|
||||
'scene' => NoticeSetting::PLATFORM_PASS_REFUND_NOTICE,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 商家拒绝
|
||||
* @param $post
|
||||
* @param $admin_id
|
||||
* @author 段誉(2021/1/30 16:56)
|
||||
*/
|
||||
public static function refuse($post, $admin_id)
|
||||
{
|
||||
$id = $post['id'];
|
||||
$after_sale = AfterSale::get($id);
|
||||
$after_sale->update_time = time();
|
||||
$after_sale->status = AfterSale::STATUS_REFUSE_REFUND;//更新为拒绝退款状态
|
||||
$after_sale->admin_remark = isset($post['remark']) ? $post['remark'] : '';
|
||||
$after_sale->save();
|
||||
//记录日志
|
||||
AfterSaleLogLogic::record(
|
||||
AfterSaleLog::TYPE_SHOP,
|
||||
AfterSaleLog::SHOP_REFUSE_REFUND,
|
||||
$after_sale['order_id'],
|
||||
$after_sale['id'],
|
||||
$admin_id,
|
||||
AfterSaleLog::SHOP_REFUSE_REFUND
|
||||
);
|
||||
$nickname = Db::name('user')->where(['id' => $after_sale->user_id])->value('nickname');
|
||||
$mobile = Db::name('order')->where(['id'=>$after_sale->order_id])->value('mobile');
|
||||
//发送短信
|
||||
Hook::listen('sms_send', [
|
||||
'key' => NoticeSetting::PLATFORM_REFUSE_REFUND_NOTICE,
|
||||
'mobile' => $mobile,
|
||||
'user_id' => $after_sale['user_id'],
|
||||
'params' => ['nickname' => $nickname, 'order_sn' => $after_sale->sn],
|
||||
]);
|
||||
|
||||
//消息通知
|
||||
Hook::listen('notice', [
|
||||
'user_id' => $after_sale['user_id'],
|
||||
'order_id' => $after_sale['order_id'],
|
||||
'scene' => NoticeSetting::PLATFORM_REFUSE_REFUND_NOTICE,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 商家收货
|
||||
* @param $post
|
||||
* @param $admin_id
|
||||
* @author 段誉(2021/1/30 16:56)
|
||||
*/
|
||||
public static function takeGoods($post, $admin_id)
|
||||
{
|
||||
$id = $post['id'];
|
||||
$after_sale = AfterSale::get($id);
|
||||
$after_sale->update_time = time();
|
||||
$after_sale->status = AfterSale::STATUS_WAIT_REFUND;//更新为等待退款状态
|
||||
$after_sale->save();
|
||||
//记录日志
|
||||
AfterSaleLogLogic::record(
|
||||
AfterSaleLog::TYPE_SHOP,
|
||||
AfterSaleLog::SHOP_TAKE_GOODS,
|
||||
$after_sale['order_id'],
|
||||
$after_sale['id'],
|
||||
$admin_id,
|
||||
AfterSaleLog::SHOP_TAKE_GOODS
|
||||
);
|
||||
//更新订单商品为等待退款状态
|
||||
$order_goods = OrderGoods::get(['id' => $after_sale['order_goods_id']]);
|
||||
$order_goods->refund_status = OrderGoods::REFUND_STATUS_WAIT;//等待退款
|
||||
$order_goods->save();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 商家拒绝收货
|
||||
* @param $post
|
||||
* @param $admin_id
|
||||
* @author 段誉(2021/1/30 16:57)
|
||||
*/
|
||||
public static function refuseGoods($post, $admin_id)
|
||||
{
|
||||
$id = $post['id'];
|
||||
$after_sale = AfterSale::get($id);
|
||||
$after_sale->update_time = time();
|
||||
$after_sale->status = AfterSale::STATUS_REFUSE_RECEIVE_GOODS;//更新为拒绝收货状态
|
||||
$after_sale->admin_remark = isset($post['remark']) ? $post['remark'] : '';
|
||||
$after_sale->save();
|
||||
//记录日志
|
||||
AfterSaleLogLogic::record(
|
||||
AfterSaleLog::TYPE_SHOP,
|
||||
AfterSaleLog::SHOP_REFUSE_TAKE_GOODS,
|
||||
$after_sale['order_id'],
|
||||
$after_sale['id'],
|
||||
$admin_id,
|
||||
AfterSaleLog::SHOP_REFUSE_TAKE_GOODS
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 确认退款 ===> 退款
|
||||
* @param $id
|
||||
* @param $admin_id
|
||||
* @author 段誉(2021/1/30 16:57)
|
||||
* @return bool|string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function confirm($id, $admin_id)
|
||||
{
|
||||
//售后记录状态
|
||||
$after_sale = AfterSale::get($id);
|
||||
$order = Order::get(['id' => $after_sale['order_id']]);
|
||||
$order_goods = OrderGoods::get(['id' => $after_sale['order_goods_id']]);
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
//更新售后为退款成功状态
|
||||
$after_sale->update_time = time();
|
||||
$after_sale->status = AfterSale::STATUS_SUCCESS_REFUND;
|
||||
$after_sale->save();
|
||||
//售后日志
|
||||
AfterSaleLogLogic::record(
|
||||
AfterSaleLog::TYPE_SHOP,
|
||||
AfterSaleLog::REFUND_SUCCESS,
|
||||
$after_sale['order_id'],
|
||||
$after_sale['id'],
|
||||
$admin_id,
|
||||
AfterSaleLog::REFUND_SUCCESS
|
||||
);
|
||||
//更新订单和订单商品状态
|
||||
OrderRefundLogic::afterSaleRefundUpdate($order, $order_goods['id'], $admin_id);
|
||||
//订单退款
|
||||
OrderRefundLogic::refund($order, $order['order_amount'], $after_sale['refund_price']);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
//增加退款失败记录
|
||||
OrderRefundLogic::addErrorRefund($order, $e->getMessage());
|
||||
//记录日志
|
||||
AfterSaleLogLogic::record(
|
||||
AfterSaleLog::TYPE_SHOP,
|
||||
AfterSaleLog::REFUND_ERROR,//退款失败
|
||||
$after_sale['order_id'],
|
||||
$after_sale['id'],
|
||||
$admin_id,
|
||||
AfterSaleLog::REFUND_ERROR,//退款失败
|
||||
$e->getMessage()
|
||||
);
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 获取商家地址
|
||||
* @author 段誉(2021/1/30 16:57)
|
||||
* @return string
|
||||
*/
|
||||
public static function getShopAddress()
|
||||
{
|
||||
$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', '');
|
||||
$shop_contact = ConfigServer::get('shop', 'contact', '');
|
||||
$shop_mobile = ConfigServer::get('shop', 'mobile', '');
|
||||
$shop_address = AreaServer::getAddress([$shop_province, $shop_city, $shop_district], $shop_address);
|
||||
return $shop_address.'('.$shop_contact.','.$shop_mobile.')';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\admin\model\ArticleCategory;
|
||||
use think\Db;
|
||||
|
||||
class ArticleCategoryLogic
|
||||
{
|
||||
public static function lists($get)
|
||||
{
|
||||
$where = [];
|
||||
$where[] = ['del', '=', '0'];
|
||||
|
||||
$article_category = new ArticleCategory();
|
||||
$count = $article_category->where($where)->count();
|
||||
$list = $article_category->where($where)->page($get['page'], $get['limit'])->select();
|
||||
|
||||
foreach ($list as &$item) {
|
||||
$item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
|
||||
if ($item['is_show'] == 1) {
|
||||
$item['is_show_text'] = '启用';
|
||||
} else {
|
||||
$item['is_show_text'] = '停用';
|
||||
}
|
||||
}
|
||||
return ['count' => $count, 'lists' => $list];
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc: 添加文章分类
|
||||
* @param $post array 文章分类数据
|
||||
* @return boolean
|
||||
*/
|
||||
public static function addArticleCategory($post)
|
||||
{
|
||||
$article_category = new ArticleCategory();
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'is_show' => $post['is_show'],
|
||||
'create_time' => time(),
|
||||
];
|
||||
return $article_category->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc: 编辑文章分类
|
||||
* @param $post array 文章分类数据
|
||||
* @return boolean
|
||||
*/
|
||||
public static function editArticleCategory($post)
|
||||
{
|
||||
$article_category = new ArticleCategory();
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'is_show' => $post['is_show'],
|
||||
'update_time' => time(),
|
||||
];
|
||||
return $article_category->save($data, ['id' => $post['id'], 'del' => 0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc: 删除文章分类
|
||||
* @param $id int 文章分类id
|
||||
* @return boolean
|
||||
*/
|
||||
public static function delArticleCategory($id)
|
||||
{
|
||||
$article_category = new ArticleCategory();
|
||||
$data = [
|
||||
'update_time' => time(),
|
||||
'del' => 1,
|
||||
];
|
||||
return $article_category->save($data, ['id' => $id, 'del' => 0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc: 获取单条文章分类
|
||||
* @param $id int 文章分类id
|
||||
* @return boolean
|
||||
*/
|
||||
public static function getArticleCategory($id = 0)
|
||||
{
|
||||
$where[] = ['del', '=', 0];
|
||||
if ($id) {
|
||||
$where[] = ['id', '=', $id];
|
||||
}
|
||||
$article_category = new ArticleCategory();
|
||||
return $article_category->where($where)->column('*', 'id');
|
||||
}
|
||||
|
||||
public static function switchStatus($post)
|
||||
{
|
||||
$data = [
|
||||
'is_show' => $post['is_show'],
|
||||
'update_time' => time(),
|
||||
];
|
||||
return Db::name('article_category')->where(['del' => 0, 'id' => $post['id']])->update($data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\admin\model\Article;
|
||||
use app\common\server\UrlServer;
|
||||
use think\Db;
|
||||
|
||||
class ArticleLogic
|
||||
{
|
||||
|
||||
public static function lists($get, $category)
|
||||
{
|
||||
$article = Db::name('article');
|
||||
|
||||
$where = [];
|
||||
$where[] = ['del', '=', '0'];
|
||||
if (isset($get['is_notice']) && $get['is_notice'] != '') {
|
||||
$where[] = ['is_notice', '=', $get['is_notice']];
|
||||
}
|
||||
|
||||
if (isset($get['title']) && $get['title']) {
|
||||
$where[] = ['title', 'like', '%' . $get['title'] . '%'];
|
||||
}
|
||||
|
||||
if (isset($get['cid']) && $get['cid']) {
|
||||
$where[] = ['cid', '=', $get['cid']];
|
||||
}
|
||||
|
||||
|
||||
$count = $article->where($where)->count();
|
||||
$list = $article->where($where)->page($get['page'], $get['limit'])->order('id desc')->select();
|
||||
foreach ($list as &$item) {
|
||||
$item['image'] = UrlServer::getFileUrl($item['image']);
|
||||
$item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
|
||||
if (isset($category[$item['cid']])) {
|
||||
$item['cat_name'] = $category[$item['cid']]['name'];
|
||||
}
|
||||
if ($item['is_show'] == 1) {
|
||||
$item['is_show_text'] = '显示';
|
||||
} else {
|
||||
$item['is_show_text'] = '隐藏';
|
||||
}
|
||||
|
||||
if ($item['is_notice'] == 1) {
|
||||
$item['is_notice'] = '是';
|
||||
|
||||
} else if ($item['is_notice'] == 0) {
|
||||
$item['is_notice'] = '否';
|
||||
}
|
||||
}
|
||||
return ['count' => $count, 'lists' => $list];
|
||||
}
|
||||
|
||||
|
||||
public static function addArticle($post)
|
||||
{
|
||||
$article = new Article();
|
||||
|
||||
$data = [
|
||||
'title' => $post['title'],
|
||||
'cid' => $post['cid'],
|
||||
'image' => $post['image'],
|
||||
'content' => $post['content'],
|
||||
'is_show' => $post['is_show'],
|
||||
'is_notice' => $post['is_notice'],
|
||||
'create_time' => time(),
|
||||
'sort' => $post['sort'],
|
||||
'synopsis' => $post['synopsis']
|
||||
];
|
||||
return $article->save($data);
|
||||
}
|
||||
|
||||
public static function editArticle($post)
|
||||
{
|
||||
$article = new Article();
|
||||
$data = [
|
||||
'title' => $post['title'],
|
||||
'cid' => $post['cid'],
|
||||
'image' => $post['image'],
|
||||
'content' => $post['content'],
|
||||
'is_show' => $post['is_show'],
|
||||
'is_notice' => $post['is_notice'],
|
||||
'update_time' => time(),
|
||||
'sort' => $post['sort'],
|
||||
'synopsis' => $post['synopsis']
|
||||
|
||||
];
|
||||
return $article->save($data, ['id' => $post['id'], 'del' => 0]);
|
||||
}
|
||||
|
||||
public static function getArticle($id)
|
||||
{
|
||||
$article = new Article();
|
||||
$detail = $article::get(['id' => $id, 'del' => 0]);
|
||||
$detail['abs_image'] = UrlServer::getFileUrl($detail['image']);
|
||||
return $detail;
|
||||
}
|
||||
|
||||
public static function delArticle($id)
|
||||
{
|
||||
$article = new Article();
|
||||
|
||||
$data = [
|
||||
'del' => 1,
|
||||
'update_time' => time()
|
||||
];
|
||||
return $article->save($data, ['id' => $id, 'del' => 0]);
|
||||
}
|
||||
|
||||
public static function switchStatus($post)
|
||||
{
|
||||
$data = [
|
||||
'is_show' => $post['is_show'],
|
||||
'update_time' => time(),
|
||||
];
|
||||
return Db::name('article')->where(['del' => 0, 'id' => $post['id']])->update($data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
use think\Db;
|
||||
|
||||
class AuthLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取菜单列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function lists()
|
||||
{
|
||||
$lists = Db::name('dev_auth')
|
||||
->where(['del' => 0])
|
||||
->field(['id', 'type', 'system', 'pid', 'name', 'sort', 'icon', 'uri', 'disable'])
|
||||
->order(['sort' => 'desc', 'type' => 'asc'])
|
||||
->select();
|
||||
$pids = Db::name('dev_auth')
|
||||
->where(['del'=>0,'type'=>1])
|
||||
->column('pid');
|
||||
foreach ($lists as $k => $v) {
|
||||
$lists[$k]['type_str'] = $v['type'] == 1 ? '菜单' : '权限';
|
||||
$lists[$k]['open'] = in_array($v['id'],$pids) ? true : false;
|
||||
}
|
||||
return linear_to_tree($lists);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单信息
|
||||
* @param $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 info($id)
|
||||
{
|
||||
return Db::name('dev_auth')
|
||||
->where(['del' => 0, 'id' => $id])
|
||||
->field(['id', 'pid', 'type', 'name', 'sort', 'icon', 'uri', 'disable'])
|
||||
->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单选项
|
||||
* @param string $id 当前编辑菜单id(选项不包含该菜单的子菜单)
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function chooseMenu($id = '')
|
||||
{
|
||||
$lists = Db::name('dev_auth')
|
||||
->field(['id', 'pid', 'name'])
|
||||
->where(['del' => 0, 'type' => 1])
|
||||
->select();
|
||||
if ($id) {
|
||||
$remove_ids = self::getChildIds($lists, $id);
|
||||
$remove_ids[] = $id;
|
||||
foreach ($lists as $key => $row) {
|
||||
if (in_array($row['id'], $remove_ids)) {
|
||||
unset($lists[$key]);
|
||||
}
|
||||
}
|
||||
$lists = array_values($lists);
|
||||
}
|
||||
return multilevel_linear_sort($lists, '|-');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取子类id
|
||||
* @param $lists
|
||||
* @param $id
|
||||
* @return array
|
||||
*/
|
||||
private static function getChildIds($lists, $id)
|
||||
{
|
||||
$ids = [];
|
||||
foreach ($lists as $key => $row) {
|
||||
if ($row['pid'] == $id) {
|
||||
$ids[] = $row['id'];
|
||||
$child_ids = self::getChildIds($lists, $row['id']);
|
||||
foreach ($child_ids as $child_id) {
|
||||
$ids[] = $child_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加菜单
|
||||
* @param $post
|
||||
* @return int|string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function addMenu($post)
|
||||
{
|
||||
if ($post['type'] == 1) {
|
||||
$level = self::getParent($post['pid']);
|
||||
if ($level >= 3) {
|
||||
return '菜单不允许超出三级';
|
||||
}
|
||||
}
|
||||
|
||||
$data = [
|
||||
'pid' => $post['pid'],
|
||||
'type' => $post['type'],
|
||||
'name' => $post['name'],
|
||||
'icon' => $post['icon'],
|
||||
'sort' => $post['sort'],
|
||||
'uri' => $post['uri'],
|
||||
'disable' => $post['disable'],
|
||||
'create_time' => time(),
|
||||
];
|
||||
return Db::name('dev_auth')->insert($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 查找层级
|
||||
* @param $pid
|
||||
* @author 张无忌(2021/2/6 11:08)
|
||||
* @return int
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function getParent($pid)
|
||||
{
|
||||
static $count = 0;
|
||||
$auth = Db::name('dev_auth')->where(['id' => $pid])->find();
|
||||
if ($auth) {
|
||||
$count += 1;
|
||||
if ($count < 3) {
|
||||
self::getParent($auth['pid']);
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新菜单
|
||||
* @param $post
|
||||
* @return int|string
|
||||
* @throws \think\Exception
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function updateMenu($post)
|
||||
{
|
||||
if ($post['type'] == 1) {
|
||||
$level = self::getParent($post['pid']);
|
||||
if ($level >= 3) {
|
||||
return '菜单不允许超出三级';
|
||||
}
|
||||
}
|
||||
|
||||
$data = [
|
||||
'pid' => $post['pid'],
|
||||
'type' => $post['type'],
|
||||
'name' => $post['name'],
|
||||
'icon' => $post['icon'],
|
||||
'sort' => $post['sort'],
|
||||
'uri' => $post['uri'],
|
||||
'disable' => $post['disable'],
|
||||
'update_time' => time(),
|
||||
];
|
||||
return Db::name('dev_auth')
|
||||
->where(['id' => $post['id'], 'system' => 0])
|
||||
->update($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置菜单状态
|
||||
* @param $post
|
||||
* @return int|string
|
||||
* @throws \think\Exception
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function setStatus($post)
|
||||
{
|
||||
$data = [
|
||||
'disable' => $post['disable'],
|
||||
'update_time' => time(),
|
||||
];
|
||||
return Db::name('dev_auth')
|
||||
->where(['id' => $post['id'], 'system' => 0])
|
||||
->update($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
* @param $ids
|
||||
* @return int|string
|
||||
* @throws \think\Exception
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function delMenu($ids)
|
||||
{
|
||||
$lists = Db::name('dev_auth')
|
||||
->where(['del' => 0])
|
||||
->field(['id', 'pid', 'name', 'sort', 'icon', 'disable'])
|
||||
->select();
|
||||
$del_ids = $ids;
|
||||
foreach ($ids as $id) {
|
||||
$temp = self::getChildIds($lists, $id);
|
||||
$del_ids = array_merge($del_ids, $temp);
|
||||
}
|
||||
return Db::name('dev_auth')
|
||||
->where('id', 'in', $del_ids)
|
||||
->where(['del' => 0, 'system' => 0])
|
||||
->update(['del' => 1]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,538 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
use app\common\model\Bargain;
|
||||
use app\common\model\BargainItem;
|
||||
use app\common\model\BargainKnife;
|
||||
use app\common\model\BargainLaunch;
|
||||
use app\common\model\Goods as GoodsModel;
|
||||
use app\common\model\Order;
|
||||
use app\common\model\TeamActivity as TeamActivityModel;
|
||||
use app\common\model\User;
|
||||
use app\common\server\UrlServer;
|
||||
use think\Db;
|
||||
|
||||
class BargainLogic
|
||||
{
|
||||
protected static $error; //错误信息
|
||||
|
||||
/**
|
||||
* Notes: 错误错误信息
|
||||
* @author 张无忌(2021/1/12 16:01)
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getError()
|
||||
{
|
||||
return self::$error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 砍价活动列表
|
||||
* @param $get
|
||||
* @author 张无忌(2021/2/24 11:11)
|
||||
* @return array
|
||||
*/
|
||||
public static function activity($get) {
|
||||
|
||||
$where = [
|
||||
['del', '=', 0]
|
||||
];
|
||||
|
||||
// 查询条件
|
||||
if ( !empty($get['goods_name']) and $get['goods_name'] !== '') {
|
||||
$goodsModel = new GoodsModel();
|
||||
$ids = $goodsModel->field('id,name')->where([
|
||||
['name', 'like', '%' . $get['goods_name'] . '%']
|
||||
])->column('id');
|
||||
|
||||
$where[] = ['goods_id', 'in', $ids];
|
||||
}
|
||||
|
||||
if (isset($get['status']) and is_numeric($get['status'])) {
|
||||
$where[] = ['status', '=', (int)$get['status']];
|
||||
}
|
||||
|
||||
$bargainModel = new Bargain();
|
||||
$count = $bargainModel->where($where)->count('id');
|
||||
$lists = $bargainModel->field(true)
|
||||
->where($where)
|
||||
->with(['goods'])
|
||||
->withCount(['launchPeopleNumber', 'successKnifePeopleNumber'])
|
||||
->order(['id' => 'desc'])
|
||||
->page($get['page'], $get['limit'])
|
||||
->select();
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['goods']['image'] = UrlServer::getFileUrl($item['goods']['image']);
|
||||
$item['activity_start_time'] = date('Y-m-d H:i:s', $item['activity_start_time']);
|
||||
$item['activity_end_time'] = date('Y-m-d H:i:s', $item['activity_end_time']);
|
||||
}
|
||||
|
||||
return ['count'=>$count, 'lists'=>$lists];
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 获取砍价活动详细
|
||||
* @param $id
|
||||
* @author 张无忌(2021/2/24 11:11)
|
||||
* @return Bargain
|
||||
*/
|
||||
public static function getDetail($id)
|
||||
{
|
||||
$bargainModel = new Bargain();
|
||||
$bargainItemModel = new BargainItem();
|
||||
|
||||
$detail = $bargainModel->field(true)
|
||||
->where(['id'=>(int)$id])
|
||||
->with(['goods'])
|
||||
->find();
|
||||
|
||||
$goodItem = $bargainItemModel->field('t.*,gi.id as spec_item_id,
|
||||
gi.spec_value_str, gi.price as spec_item_price, gi.stock')
|
||||
->where(['bargain_id'=>(int)$id])
|
||||
->alias('t')
|
||||
->rightJoin('goods_item gi', 'gi.id = t.item_id')
|
||||
->select();
|
||||
|
||||
$detail['min_knife_price'] = 0;
|
||||
$detail['max_knife_price'] = 0;
|
||||
$detail['fixed_knife_price'] = 0;
|
||||
if ($detail['knife_type'] == 1) {
|
||||
$knife_price_arr = explode(',', $detail['knife_price']);
|
||||
$detail['min_knife_price'] = empty($knife_price_arr[0]) ? 0 : $knife_price_arr[0];
|
||||
$detail['max_knife_price'] = empty($knife_price_arr[1]) ? 0 : $knife_price_arr[1];
|
||||
} else {
|
||||
$detail['fixed_knife_price'] = $detail['knife_price'];
|
||||
}
|
||||
|
||||
// 处理判断商品规格是否已发生变化, 没变化是true, 否则false
|
||||
$detail['is_goods_item'] = true;
|
||||
foreach ($goodItem as $item) {
|
||||
if (!$item['spec_value_str'] || $item['spec_value_str'] == ''
|
||||
|| $item['spec_item_price'] == '') {
|
||||
$detail['is_goods_item'] = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$detail['item'] = $goodItem;
|
||||
$detail['goods']['image'] = UrlServer::getFileUrl($detail['goods']['image']);
|
||||
$detail['activity_start_time'] = date('Y-m-d H:i:s', $detail['activity_start_time']);
|
||||
$detail['activity_end_time'] = date('Y-m-d H:i:s', $detail['activity_end_time']);
|
||||
|
||||
return $detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 新增砍价活动
|
||||
* @param $post
|
||||
* @author 张无忌(2021/2/23 15:46)
|
||||
* @return bool
|
||||
*/
|
||||
public static function add($post)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 校验拼团活动是否存在
|
||||
$teamActivityModel = new TeamActivityModel();
|
||||
$team = $teamActivityModel->where([
|
||||
'goods_id' => intval($post['goods_id']),
|
||||
'del' => 0
|
||||
])->find();
|
||||
|
||||
if ($team) {
|
||||
static::$error = '商品正在参与拼团活动, 请先移除活动再添加';
|
||||
return false;
|
||||
}
|
||||
|
||||
//秒杀验证
|
||||
$seckill_goods = Db::name('seckill_goods')
|
||||
->where(['goods_id'=>intval($post['goods_id']),'del'=>0])
|
||||
->find();
|
||||
if($seckill_goods){
|
||||
static::$error = '商品正在参与秒杀活动,无法修改';
|
||||
return false;
|
||||
}
|
||||
|
||||
// 每刀金额(随机 / 固定)
|
||||
$knife_price = 0;
|
||||
if ($post['knife_type'] == 1) {
|
||||
$knife_price = [$post['min_knife_price'], $post['max_knife_price']];
|
||||
$knife_price = implode(',', $knife_price);
|
||||
} else {
|
||||
$knife_price = $post['fixed_knife_price'];
|
||||
}
|
||||
|
||||
// 查出最大低价和最少价格
|
||||
$bargain_price = [];
|
||||
foreach ($post['floor_price'] as $key => $value) {
|
||||
foreach ($value as $K => $item) {
|
||||
array_push($bargain_price, $item);
|
||||
}
|
||||
}
|
||||
$bargain_max_price = !empty($bargain_price) ? max($bargain_price) : 0;
|
||||
$bargain_min_price = !empty($bargain_price) ? min($bargain_price) : 0;
|
||||
|
||||
// 新增砍价活动
|
||||
$bargainModel = new Bargain();
|
||||
$bargain_id = $bargainModel->insertGetId([
|
||||
'goods_id' => $post['goods_id'],
|
||||
'time_limit' => $post['time_limit'],
|
||||
'activity_start_time' => strtotime($post['activity_start_time']),
|
||||
'activity_end_time' => strtotime($post['activity_end_time']),
|
||||
'bargain_min_price' => $bargain_min_price,
|
||||
'bargain_max_price' => $bargain_max_price,
|
||||
'share_title' => empty($post['share_title']) ? '' : $post['share_title'],
|
||||
'share_intro' => empty($post['share_intro']) ? '' : $post['share_intro'],
|
||||
'payment_where' => $post['payment_where'],
|
||||
'knife_type' => $post['knife_type'],
|
||||
'knife_price' => $knife_price,
|
||||
'status' => $post['status'],
|
||||
'del' => 0,
|
||||
]);
|
||||
|
||||
// 新增砍价商品SKU
|
||||
$lists = [];
|
||||
foreach ($post['floor_price'] as $key => $value) {
|
||||
foreach ($value as $K => $item) {
|
||||
$lists[] = [
|
||||
'bargain_id' => $bargain_id,
|
||||
'goods_id' => $key,
|
||||
'item_id' => $K,
|
||||
'floor_price' => $item,
|
||||
'first_knife_price' => $post['first_knife_price'][$key][$K]
|
||||
];
|
||||
}
|
||||
}
|
||||
if ( !empty($lists)) {
|
||||
$bargainItemModel = new BargainItem();
|
||||
$bargainItemModel->saveAll($lists);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
Db::rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 编辑砍价活动
|
||||
* @param $post
|
||||
* @author 张无忌(2021/2/24 11:10)
|
||||
* @return bool
|
||||
*/
|
||||
public static function edit($post)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 查询商品信息
|
||||
$goodsModel = new GoodsModel();
|
||||
$goods = $goodsModel->field('id,name,image')
|
||||
->where(['id' => (int)$post['goods_id']])->find();
|
||||
|
||||
if (!$goods) {
|
||||
static::$error = '选择的商品已不存在,可能已被删除';
|
||||
return false;
|
||||
}
|
||||
|
||||
// 每刀金额(随机 / 固定)
|
||||
$knife_price = 0;
|
||||
if ($post['knife_type'] == 1) {
|
||||
$knife_price = [$post['min_knife_price'], $post['max_knife_price']];
|
||||
$knife_price = implode(',', $knife_price);
|
||||
} else {
|
||||
$knife_price = $post['fixed_knife_price'];
|
||||
}
|
||||
|
||||
// 查出最大低价和最少价格
|
||||
$bargain_price = [];
|
||||
foreach ($post['floor_price'] as $key => $value) {
|
||||
foreach ($value as $K => $item) {
|
||||
array_push($bargain_price, $item);
|
||||
}
|
||||
}
|
||||
$bargain_max_price = !empty($bargain_price) ? max($bargain_price) : 0;
|
||||
$bargain_min_price = !empty($bargain_price) ? min($bargain_price) : 0;
|
||||
|
||||
// 新增砍价活动
|
||||
$bargainModel = new Bargain();
|
||||
$bargainModel->where(['id' => (int)$post['id']])->update([
|
||||
'goods_id' => $post['goods_id'],
|
||||
'time_limit' => $post['time_limit'],
|
||||
'activity_start_time' => strtotime($post['activity_start_time']),
|
||||
'activity_end_time' => strtotime($post['activity_end_time']),
|
||||
'bargain_min_price' => $bargain_min_price,
|
||||
'bargain_max_price' => $bargain_max_price,
|
||||
'share_title' => empty($post['share_title']) ? '' : $post['share_title'],
|
||||
'share_intro' => empty($post['share_intro']) ? '' : $post['share_intro'],
|
||||
'payment_where' => $post['payment_where'],
|
||||
'knife_type' => $post['knife_type'],
|
||||
'knife_price' => $knife_price,
|
||||
'status' => $post['status']
|
||||
]);
|
||||
|
||||
// 删除旧的SKU
|
||||
$bargainItemModel = new BargainItem();
|
||||
$bargainItemModel->where(['bargain_id' => (int)$post['id']])->delete();
|
||||
|
||||
// 新增砍价商品SKU
|
||||
$lists = [];
|
||||
foreach ($post['floor_price'] as $key => $value) {
|
||||
foreach ($value as $K => $item) {
|
||||
$lists[] = [
|
||||
'bargain_id' => $post['id'],
|
||||
'goods_id' => $key,
|
||||
'item_id' => $K,
|
||||
'floor_price' => $item,
|
||||
'first_knife_price' => $post['first_knife_price'][$key][$K]
|
||||
];
|
||||
}
|
||||
}
|
||||
if (!empty($lists)) {
|
||||
$bargainItemModel->saveAll($lists);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
Db::rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 软删除
|
||||
* @param int $id
|
||||
* @author 张无忌(2021/1/13 18:02)
|
||||
* @return bool
|
||||
*/
|
||||
public static function softDelete(int $id)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$bargainModel = new Bargain();
|
||||
$bargainModel->where(['id'=>(int)$id])->update(['del'=>1]);
|
||||
|
||||
// 关闭活动未完成的
|
||||
$bargainLaunchModel = new BargainLaunch();
|
||||
$bargainLaunchModel->where(['bargain_id'=>$id, 'status'=>0])
|
||||
->update(['status'=>2]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
static::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 切换状态
|
||||
* @param $post
|
||||
* @author 张无忌(2021/1/13 17:53)
|
||||
* @return bool
|
||||
*/
|
||||
public static function switchStatus($post)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$bargainModel = new Bargain();
|
||||
// 切换状态
|
||||
$bargainModel->where(['id' => (int)$post['id']])
|
||||
->update([ $post['field'] => $post['status'] ]);
|
||||
// 关闭活动未完成的
|
||||
// if ($post['status']) {
|
||||
$bargainLaunchModel = new BargainLaunch();
|
||||
// $bargainLaunchModel->where(['bargain_id'=>$post['id'], 'status'=>0])
|
||||
// ->update(['status'=>2]);
|
||||
// }
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
Db::rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 砍价列表
|
||||
* @param $get
|
||||
* @author 张无忌(2021/2/24 17:43)
|
||||
* @return array
|
||||
*/
|
||||
public static function getLaunch($get)
|
||||
{
|
||||
// 查询条件
|
||||
$where = [];
|
||||
|
||||
if (isset($get['bargain_id']) and $get['bargain_id']) {
|
||||
$where[] = ['bargain_id', '=', (int)$get['bargain_id']];
|
||||
}
|
||||
|
||||
if (isset($get['goods_name']) and $get['goods_name'] !== '') {
|
||||
$goodsModel = new GoodsModel();
|
||||
$ids = $goodsModel->field('id,name')->where([
|
||||
['name', 'like', '%' . $get['goods_name'] . '%']
|
||||
])->column('id');
|
||||
|
||||
$where[] = ['goods_id', 'in', $ids];
|
||||
}
|
||||
|
||||
if (isset($get['status']) and is_numeric($get['status'])) {
|
||||
$where[] = ['status', '=', (int)$get['status']];
|
||||
}
|
||||
|
||||
if (isset($get['launch_start_time']) and $get['launch_start_time'] !== '') {
|
||||
$where[] = ['launch_start_time', '>=', strtotime($get['launch_start_time'])];
|
||||
}
|
||||
|
||||
if (isset($get['launch_end_time']) and $get['launch_end_time'] !== '') {
|
||||
$where[] = ['launch_end_time', '<=', strtotime($get['launch_end_time'])];
|
||||
}
|
||||
|
||||
if (isset($get['type']) and $get['type'] !== '') {
|
||||
if (isset($get['keyword']) and $get['keyword'] !== '') {
|
||||
switch ($get['type']) {
|
||||
case 'sn':
|
||||
$uid = User::where('sn', '=', $get['keyword'])->column('id');
|
||||
$where[] = ['user_id', 'in', $uid];
|
||||
break;
|
||||
case 'nickname':
|
||||
$uid = User::where('nickname', 'like', '%' . $get['keyword'] . '%')->column('id');
|
||||
$where[] = ['user_id', 'in', $uid];
|
||||
break;
|
||||
case 'mobile':
|
||||
$uid = User::where('mobile', '=', $get['keyword'])->column('id');
|
||||
$where[] = ['user_id', 'in', $uid];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$model = new BargainLaunch();
|
||||
$count = $model->where($where)->count('id');
|
||||
$lists = $model->field(true)
|
||||
->where($where)
|
||||
->with(['user.level'])
|
||||
->order('id', 'desc')
|
||||
->page($get['page'], $get['limit'])
|
||||
->select();
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['launch_start_time'] = date('Y-m-d H:i:s', $item['launch_start_time']);
|
||||
$item['launch_end_time'] = date('Y-m-d H:i:s', $item['launch_end_time']);
|
||||
$item['domain'] = UrlServer::getFileUrl('/');
|
||||
$item['status'] = BargainLaunch::getStatusDesc($item['status']);
|
||||
$item['goods_image'] = $item['goods_snap']['image'] == "" ? $item['goods_snap']['goods_iamge'] : $item['goods_snap']['image'] ;
|
||||
}
|
||||
|
||||
return ['count'=>$count, 'lists'=>$lists];
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 砍价详细
|
||||
* @param $id
|
||||
* @author 张无忌(2021/2/24 17:43)
|
||||
* @return array
|
||||
*/
|
||||
public static function getLaunchDetail($id)
|
||||
{
|
||||
$model = new BargainLaunch();
|
||||
$detail = $model->field(true)
|
||||
->where(['id'=>(int)$id])
|
||||
->with(['user.level'])
|
||||
->find()->toArray();
|
||||
|
||||
$detail['domain'] = UrlServer::getFileUrl('/');
|
||||
$detail['goods_snap']['goods_iamge'] = UrlServer::getFileUrl($detail['goods_snap']['goods_iamge']);
|
||||
$detail['launch_start_time'] = date('Y-m-d H:i:s', $detail['launch_start_time']);
|
||||
$detail['launch_end_time'] = date('Y-m-d H:i:s', $detail['launch_end_time']);
|
||||
$detail['payment_where'] = $detail['bargain_snap']['payment_where'] == 1 ? '砍到指定底价' : '任意金额';
|
||||
$detail['status'] = BargainLaunch::getStatusDesc($detail['status']);
|
||||
return $detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 砍价订单
|
||||
* @param $launch_id
|
||||
* @param $get
|
||||
* @author 张无忌(2021/2/24 17:43)
|
||||
* @return array
|
||||
*/
|
||||
public static function getKnifeOrderRecord($launch_id, $get)
|
||||
{
|
||||
$model = new BargainLaunch();
|
||||
$count = $model->where(['id'=>(int)$launch_id])
|
||||
->where('order_id', '>', 0)->count('id');
|
||||
$lists = $model->field(true)
|
||||
->where(['id'=>(int)$launch_id])
|
||||
->where('order_id', '>', 0)
|
||||
->with(['user.level', 'order'])
|
||||
->page($get['page'], $get['limit'])
|
||||
->select()->toArray();
|
||||
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['order_status'] = Order::getOrderStatus($item['order']['order_status']);
|
||||
if (!empty($item['goods_snap']['goods_iamge'])) {
|
||||
$item['goods_snap']['goods_iamge'] = UrlServer::getFileUrl($item['goods_snap']['goods_iamge']);
|
||||
}
|
||||
}
|
||||
|
||||
return ['count'=>$count, 'lists'=>$lists];
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 砍价记录
|
||||
* @param $launch_id
|
||||
* @param $get
|
||||
* @author 张无忌(2021/2/24 15:48)
|
||||
* @return array
|
||||
*/
|
||||
public static function getKnifeRecord($launch_id, $get)
|
||||
{
|
||||
$model = new BargainKnife();
|
||||
|
||||
$count = $model->where(['launch_id'=>(int)$launch_id])->count();
|
||||
$lists = $model->field(true)
|
||||
->where(['launch_id'=>(int)$launch_id])
|
||||
->with(['user.level'])
|
||||
->page($get['page'], $get['limit'])
|
||||
->select();
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['help_time'] = date('Y-m-d H:i:s', $item['help_time']);
|
||||
$item['help_price'] = '¥'.$item['help_price'];
|
||||
$item['surplus_price'] = '¥'.$item['surplus_price'];
|
||||
}
|
||||
|
||||
return ['count'=>$count, 'lists'=>$lists];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
use app\common\model\Goods;
|
||||
use app\common\server\UrlServer;
|
||||
use think\Db;
|
||||
|
||||
class CommentHelperLogic
|
||||
{
|
||||
/**
|
||||
* @notes 商品列表
|
||||
* @param $get
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
* @author 段誉
|
||||
* @date 2022/1/12 11:00
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
$where = [];
|
||||
$where[] = ['del', '=', '0'];
|
||||
|
||||
if (isset($get['status']) && $get['status'] != '') {
|
||||
$where[] = ['status', '=', $get['status']];
|
||||
}
|
||||
if (isset($get['keyword']) && $get['keyword'] != '') {
|
||||
$where[] = ['name', 'like', '%' . $get['keyword'] . '%'];
|
||||
}
|
||||
if (isset($get['category_id']) && $get['category_id'] != '') {
|
||||
$where[] = ['first_category_id|second_category_id|third_category_id', '=', $get['category_id']];
|
||||
}
|
||||
|
||||
$count = Db::name('goods')->where($where)->count();
|
||||
|
||||
$lists = Db::name('goods')
|
||||
->field('*,virtual_sales_sum+sales_sum as total_sales_sum')
|
||||
->where($where)
|
||||
->withAttr('comment_count', function ($value,$data){
|
||||
return Db::name('goods_comment')->where(['goods_id' => $data['id']])->count();
|
||||
})
|
||||
->page($get['page'], $get['limit'])
|
||||
->order('id desc')
|
||||
->select();
|
||||
|
||||
$goods_category = Db::name('goods_category')->where(['del' => 0])->column('name', 'id');
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['cate_name'] = GoodsLogic::getCateName($goods_category, $item);
|
||||
$item['price'] = '¥' . $item['min_price'];
|
||||
if ($item['spec_type'] == 2 && $item['max_price'] !== $item['min_price']) {
|
||||
$item['price'] = '¥' . $item['min_price'] . '~' . '¥' . $item['max_price'];
|
||||
}
|
||||
$item['create_time_desc'] = date('Y-m-d H:i:s', $item['create_time']);
|
||||
$item['image'] = UrlServer::getFileUrl($item['image']);
|
||||
$item['status_desc'] = Goods::getStatusDesc($item['status']);
|
||||
}
|
||||
|
||||
return ['count' => $count, 'list' => $lists];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加虚拟评论
|
||||
* @param $post
|
||||
* @return bool|string
|
||||
* @author 段誉
|
||||
* @date 2022/1/12 11:00
|
||||
*/
|
||||
public static function addComment($post)
|
||||
{
|
||||
try {
|
||||
$goods_item = Db::name('goods_item')->where(['goods_id'=> $post['goods_id']])->find();
|
||||
|
||||
if (empty($goods_item)) {
|
||||
throw new \Exception('当前商品规格参数错误');
|
||||
}
|
||||
|
||||
$virtual_data = [
|
||||
'sn' => create_user_sn(),
|
||||
'nickname' => $post['nickname'],
|
||||
'avatar' => $post['avatar'],
|
||||
'comment_time' => strtotime($post['comment_time']),
|
||||
'level' => $post['level'],
|
||||
];
|
||||
|
||||
$data = [
|
||||
'goods_id' => $post['goods_id'],
|
||||
'item_id' => $goods_item['id'],
|
||||
'user_id' => 0,
|
||||
'order_goods_id' => 0,
|
||||
'goods_comment' => $post['score'],
|
||||
'service_comment' => $post['score'],
|
||||
'express_comment' => $post['score'],
|
||||
'description_comment' => $post['score'],
|
||||
'comment' => $post['comment'],
|
||||
'create_time' => time(),
|
||||
'virtual_data' => json_encode($virtual_data, JSON_UNESCAPED_UNICODE)
|
||||
];
|
||||
$comment_id = Db::name('goods_comment')->insertGetId($data);
|
||||
|
||||
if (!empty($post['comment_image'])) {
|
||||
foreach ($post['comment_image'] as $image_val) {
|
||||
$image[] = ['uri' => $image_val, 'goods_comment_id' => $comment_id];
|
||||
}
|
||||
Db::name('goods_comment_image')->insertAll($image);
|
||||
}
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\logic;
|
||||
use app\common\server\UrlServer;
|
||||
use think\Db;
|
||||
class CommonLogic{
|
||||
/**
|
||||
* note 修改制定表的某个字段
|
||||
* author cjh 2020/10/14 14:51
|
||||
* @param $table 表名
|
||||
* @param $pk_name id
|
||||
* @param $pk_value id的值
|
||||
* @param $field 需要修改的字段
|
||||
* @param $field_value 需要修改的值
|
||||
* @return bool
|
||||
* @throws \think\Exception
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function changeTableValue($table,$pk_name,$pk_value,$field,$field_value){
|
||||
//允许修改的字段
|
||||
$allow_field = [
|
||||
'is_show','sort','status','is_new','is_best','is_like','is_recommend'
|
||||
];
|
||||
if(!in_array($field,$allow_field)){
|
||||
return false;
|
||||
}
|
||||
if(is_array($pk_value)){
|
||||
$where[] = [$pk_name,'in',$pk_value];
|
||||
}else{
|
||||
$where[] = [$pk_name,'=',$pk_value];
|
||||
}
|
||||
|
||||
$data= [
|
||||
$field => $field_value,
|
||||
'update_time' => time(),
|
||||
];
|
||||
|
||||
if ($field == 'status' and $field_value == 0) {
|
||||
$activity_goods = GoodsLogic::activityGoods()['activity_goods'];
|
||||
if(in_array($pk_value,$activity_goods)){
|
||||
return '该商品正在参与活动,请先关闭后才允许下架';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$result = Db::name($table)->where($where)->update($data);
|
||||
return $result ? true : '修改失败';
|
||||
}
|
||||
|
||||
//获取商品列表
|
||||
public static function getGoodsList($get,$is_item = false){
|
||||
$where = [];
|
||||
$where[] = ['del', '=', '0'];
|
||||
$where[] = ['status','=',1];
|
||||
|
||||
if (isset($get['keyword']) && $get['keyword']) {
|
||||
$where[] = ['name', 'like', '%' . $get['keyword'] . '%'];
|
||||
}
|
||||
if(isset($get['cid']) && $get['cid']){
|
||||
$where[] = ['first_category_id|second_category_id|third_category_id','=',$get['cid']];
|
||||
}
|
||||
|
||||
$goods_count = Db::name('goods')
|
||||
->where($where)
|
||||
->count();
|
||||
|
||||
$goods_list = Db::name('goods')
|
||||
->where($where)
|
||||
->page($get['page'], $get['limit'])
|
||||
->column('*','id');
|
||||
$activity_goods = GoodsLogic::activityGoods();
|
||||
$seckill_goods = $activity_goods['seckill_goods'];
|
||||
$team_goods = $activity_goods['team_goods'];
|
||||
$bargain_goods = $activity_goods['bargain_goods'];
|
||||
|
||||
foreach ($goods_list as &$item) {
|
||||
$item['goods_item'] = [];
|
||||
$item['price'] = '¥'.$item['min_price'];
|
||||
if($item['max_price'] != $item['min_price']){
|
||||
$item['price'] = '¥'.$item['max_price'].'~'.'¥'.$item['min_price'];
|
||||
}
|
||||
$item['create_time_desc'] = date('Y-m-d H:i:s',$item['create_time']);
|
||||
$item['image'] = UrlServer::getFileUrl($item['image']);
|
||||
$item['attribute'] = '普通商品';
|
||||
if(in_array($item['id'],$seckill_goods)){
|
||||
$item['attribute'] = '秒杀商品';
|
||||
}elseif (in_array($item['id'],$team_goods)){
|
||||
$item['attribute'] = '拼团商品';
|
||||
}elseif (in_array($item['id'],$bargain_goods)){
|
||||
$item['attribute'] = '砍价商品';
|
||||
}
|
||||
}
|
||||
|
||||
if($is_item){
|
||||
$goods_ids = array_keys($goods_list);
|
||||
$goods_item = Db::name('goods_item')->where(['goods_id'=>$goods_ids])->select();
|
||||
foreach ($goods_item as $items){
|
||||
if(isset($goods_list[$items['goods_id']])){
|
||||
if($items['image']){
|
||||
$items['image'] = UrlServer::getFileUrl($items['image']);
|
||||
}else{
|
||||
$items['image'] = $goods_list[$items['goods_id']]['image'];
|
||||
}
|
||||
$goods_list[$items['goods_id']]['goods_item'][] = $items;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ['count' => $goods_count, 'list' =>array_values($goods_list)];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,325 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\Logic;
|
||||
use app\admin\model\Coupon;
|
||||
use app\common\server\UrlServer;
|
||||
use think\Db;
|
||||
|
||||
|
||||
class CouponLogic{
|
||||
public static function lists($get){
|
||||
//更新过期优惠券
|
||||
$now = time();
|
||||
Db::name('coupon')
|
||||
->where([['send_time_start','<',$now], ['send_time_end','<',$now],['status','=',1]])
|
||||
->update(['status'=>0,'update_time'=>$now]);
|
||||
|
||||
$where[] = ['del','=',0];
|
||||
//优惠券名称搜索
|
||||
if(isset($get['name']) && $get['name']){
|
||||
$where[] = ['name','like','%'.$get['name'].'%'];
|
||||
}
|
||||
//发放优惠券
|
||||
if(isset($get['type']) && $get['type'] === 'send'){
|
||||
$where[] = ['status','=',1];
|
||||
$where[] = ['get_type','=',2];
|
||||
|
||||
}
|
||||
if(isset($get['type']) && $get['type'] !== 'send' && $get['type'] !== ''){
|
||||
$where[] = ['status','=',$get['type']];
|
||||
}
|
||||
$coupon = new Coupon();
|
||||
|
||||
$coupon_count = $coupon
|
||||
->where($where)
|
||||
->count();
|
||||
|
||||
$coupon_list = $coupon
|
||||
->where($where)
|
||||
->page($get['page'], $get['limit'])
|
||||
->order('id desc')
|
||||
->select();
|
||||
$coupon_list->append(['status_desc','sent_total','send_time']);
|
||||
return ['count' => $coupon_count, 'list' => $coupon_list];
|
||||
|
||||
}
|
||||
|
||||
//添加优惠券
|
||||
public static function add($post){
|
||||
//拼接数据
|
||||
$add_data = [
|
||||
'name' => $post['name'],
|
||||
'money' => $post['money'],
|
||||
'send_time_start' => $post['send_time_start'],
|
||||
'send_time_end' => $post['send_time_end'],
|
||||
'send_total_type' => $post['send_total_type'],
|
||||
'send_total' => $post['send_total_type'] == 2 ? $post['send_total'] : '',
|
||||
'condition_type' => $post['condition_type'],
|
||||
'condition_money' => $post['condition_type'] == 2 ? $post['condition_money'] : '',
|
||||
'use_time_type' => $post['use_time_type'],
|
||||
'use_time_start' => $post['use_time_type'] == 1 ? $post['use_time_start'] : '',
|
||||
'use_time_end' => $post['use_time_type'] == 1 ? $post['use_time_end'] : '',
|
||||
'use_time' => $post['use_time_type'] == 2 ? $post['use_time'] : '',
|
||||
'get_type' => $post['get_type'],
|
||||
'get_num_type' => $post['get_num_type'],
|
||||
'get_num' => $post['get_num'],
|
||||
'use_goods_type' => $post['use_goods_type'],
|
||||
'status' => 1,
|
||||
];
|
||||
//用券时间
|
||||
if($post['use_time_type'] == 3){
|
||||
$add_data['use_time'] = $post['tomorrow_use_time'];
|
||||
}
|
||||
//领取次数
|
||||
if($post['get_num_type'] == 3){
|
||||
$add_data['get_num'] = $post['day_get_num'];
|
||||
}
|
||||
//提交订单
|
||||
Db::startTrans();
|
||||
try {
|
||||
$coupon = Coupon::create($add_data);
|
||||
if($coupon && $coupon['use_goods_type'] != 1){
|
||||
$goods_coupon = [];
|
||||
$now = time();
|
||||
foreach ($post['goods_ids'] as $item){
|
||||
$goods_coupon[] = [
|
||||
'coupon_id' => $coupon->id,
|
||||
'goods_id' => $item,
|
||||
'create_time' => $now,
|
||||
];
|
||||
}
|
||||
Db::name('coupon_goods')->insertAll($goods_coupon);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
public static function edit($post){
|
||||
|
||||
$coupon = new Coupon();
|
||||
//拼接数据
|
||||
$update_data = [
|
||||
'name' => $post['name'],
|
||||
'money' => $post['money'],
|
||||
'send_time_start' => $post['send_time_start'],
|
||||
'send_time_end' => $post['send_time_end'],
|
||||
'send_total_type' => $post['send_total_type'],
|
||||
'send_total' => $post['send_total_type'] == 2 ? $post['send_total'] : '',
|
||||
'condition_type' => $post['condition_type'],
|
||||
'condition_money' => $post['condition_type'] == 2 ? $post['condition_money'] : '',
|
||||
'use_time_type' => $post['use_time_type'],
|
||||
'use_time_start' => $post['use_time_type'] == 1 ? $post['use_time_start'] : '',
|
||||
'use_time_end' => $post['use_time_type'] == 1 ? $post['use_time_end'] : '',
|
||||
'use_time' => $post['use_time_type'] == 2 ? $post['use_time'] : '',
|
||||
'get_type' => $post['get_type'],
|
||||
'get_num_type' => $post['get_num_type'],
|
||||
'get_num' => $post['get_num_type'] == 2 ? $post['get_num'] : '',
|
||||
'use_goods_type' => $post['use_goods_type'],
|
||||
];
|
||||
//用券时间
|
||||
if($post['use_time_type'] == 3){
|
||||
$update_data['use_time'] = $post['tomorrow_use_time'];
|
||||
}
|
||||
//领取次数
|
||||
if($post['get_num_type'] == 3){
|
||||
$update_data['get_num'] = $post['day_get_num'];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$coupon->save($update_data,['id'=>$post['id']]);
|
||||
Db::name('coupon_goods')->where(['coupon_id'=>$post['id']])->delete();
|
||||
|
||||
if($coupon && $coupon['use_goods_type'] != 1){
|
||||
$goods_coupon = [];
|
||||
$now = time();
|
||||
foreach ($post['goods_ids'] as $item){
|
||||
$goods_coupon[] = [
|
||||
'coupon_id' => $post['id'],
|
||||
'goods_id' => $item,
|
||||
'create_time' => $now,
|
||||
];
|
||||
}
|
||||
Db::name('coupon_goods')->insertAll($goods_coupon);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static function getCoupon($id,$get_data = false){
|
||||
$coupon = Coupon::get($id);
|
||||
$coupon['goods_coupon'] = [];
|
||||
if($get_data) {
|
||||
$coupon = $coupon->getData();
|
||||
$coupon['send_time_start'] = date('Y-m-d H:i:s',$coupon['send_time_start']);
|
||||
$coupon['send_time_end'] = date('Y-m-d H:i:s',$coupon['send_time_end']);
|
||||
if($coupon['use_goods_type'] != 1){
|
||||
$goods_coupon= Db::name('coupon_goods cg')
|
||||
->join('goods g','cg.goods_id = g.id')
|
||||
->where(['coupon_id'=>$id])
|
||||
->field('g.id,name,max_price,min_price,stock')
|
||||
->select();
|
||||
foreach ($goods_coupon as &$item){
|
||||
$item['price'] = '¥'.$item['min_price'].'~'.'¥'.$item['max_price'];
|
||||
if($item['max_price'] == $item['min_price']){
|
||||
$item['price'] = '¥'.$item['min_price'];
|
||||
}
|
||||
}
|
||||
$coupon['goods_coupon'] = $goods_coupon;
|
||||
}
|
||||
if($coupon['use_time_start']){
|
||||
$coupon['use_time_start'] = date('Y-m-d H:i:s',$coupon['use_time_start']);
|
||||
$coupon['use_time_end'] = date('Y-m-d H:i:s',$coupon['use_time_end']);
|
||||
}
|
||||
}
|
||||
|
||||
return $coupon;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* 删除优惠券
|
||||
*/
|
||||
public static function del($id){
|
||||
Db::startTrans();
|
||||
try{
|
||||
$coupon = new Coupon();
|
||||
$coupon->save(['del'=>1,'update_time'=>time()],['id'=>$id]);
|
||||
|
||||
// 同步删除已领取未使用的用户的优惠券
|
||||
Db::name('coupon_list')->where([
|
||||
'status' => 0,
|
||||
'coupon_id' => $id,
|
||||
'del' => 0
|
||||
])->update([
|
||||
'del' => 1,
|
||||
'update_time' => time()
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
}catch(\Exception $e) {
|
||||
Db::rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 发放记录
|
||||
*/
|
||||
public static function log($get){
|
||||
$where[] = ['cl.del','=',0];
|
||||
$where[] = ['coupon_id','=',$get['id']];
|
||||
if(isset($get['keyword']) && $get['keyword']){
|
||||
$where[] = ['nickname|mobile','like','%'.$get['keyword'].'%'];
|
||||
}
|
||||
|
||||
$log_count = Db::name('coupon_list cl')
|
||||
->join('user u','cl.user_id = u.id')
|
||||
->where($where)
|
||||
->count();
|
||||
|
||||
$log_list = Db::name('coupon_list cl')
|
||||
->join('user u','cl.user_id = u.id')
|
||||
->where($where)
|
||||
->field('coupon_id,status,coupon_code,cl.create_time as create_time,cl.use_time,u.nickname,u.avatar,u.mobile,u.sex,u.sn,u.level,u.create_time as u_create_time')
|
||||
->page($get['page'], $get['limit'])
|
||||
->select();
|
||||
$coupon_list = Db::name('coupon')->where(['del'=>0])->column('name','id');
|
||||
$level_name = Db::name('user_level')->where(['del'=>0])->column('name','id');
|
||||
foreach ($log_list as &$item)
|
||||
{
|
||||
$item['use_time_desc'] = '-';
|
||||
$item['status_desc'] = '未使用';
|
||||
$item['create_time_desc'] = '';
|
||||
$item['sex_desc'] = '未知';
|
||||
if($item['use_time']){
|
||||
$item['use_time_desc'] = date('Y-m-d H:i:s',$item['use_time']);
|
||||
}
|
||||
$item['u_create_time'] = date('Y-m-d H:i:s',$item['u_create_time']);
|
||||
|
||||
if ($item['status'] == 1) {
|
||||
$item['status_desc'] = '已使用';
|
||||
} else if($item['status'] == 2) {
|
||||
$item['status_desc'] = '已过期';
|
||||
}
|
||||
|
||||
$item['avatar'] = UrlServer::getFileUrl($item['avatar']);
|
||||
$item['coupon_name'] = $coupon_list[$item['coupon_id']] ?? '';
|
||||
$item['create_time_desc'] = date('Y-m-d H:i:s',$item['create_time']);
|
||||
|
||||
$item['level_name'] = $level_name[$item['level']] ?? '';
|
||||
switch ($item['sex']){
|
||||
case 1:
|
||||
$item['sex_desc'] = '男';
|
||||
case 2:
|
||||
$item['sex_desc'] = '女';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return ['count'=>$log_count , 'lists'=>$log_list];
|
||||
}
|
||||
|
||||
/*
|
||||
* 关闭优惠券
|
||||
*/
|
||||
public static function close($id){
|
||||
$coupon = new Coupon();
|
||||
return $coupon->save(['status'=>0,'update_time'=>time()],['id'=>$id]);
|
||||
}
|
||||
|
||||
|
||||
public static function sendCoupon($post){
|
||||
$user_ids = $post['user_ids'];
|
||||
$coupon_ids = $post['coupon_ids'];
|
||||
$now = time();
|
||||
foreach ($coupon_ids as $coupon_id){
|
||||
foreach ($user_ids as $user_id){
|
||||
$add_data = [
|
||||
'user_id' => $user_id,
|
||||
'coupon_id' => $coupon_id,
|
||||
'status' => 0,
|
||||
'coupon_code' => create_coupon_code(),
|
||||
'create_time' => $now,
|
||||
];
|
||||
Db::name('coupon_list')->insert($add_data);
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
use app\common\model\Crontab_;
|
||||
use Cron\CronExpression;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
|
||||
class CrontabLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取定时任务列表
|
||||
* @return array|\PDOStatement|string|\think\Collection|\think\model\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function lists()
|
||||
{
|
||||
|
||||
$lists = Db::name('dev_crontab')
|
||||
->order(['system' => 'desc'])
|
||||
->select();
|
||||
foreach ($lists as $k => $v) {
|
||||
$lists[$k]['type_str'] = Crontab_::$type[$v['type']];
|
||||
$lists[$k]['last_time_str'] = empty($v['last_time']) ? '-' : date('m-d H:i:s', $v['last_time']);
|
||||
if ($v['type'] == 2) {
|
||||
$lists[$k]['expression'] = '-';
|
||||
}
|
||||
}
|
||||
return ['count' => count($lists), 'lists' => $lists];
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时任务信息
|
||||
* @param $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 info($id)
|
||||
{
|
||||
return Db::name('dev_crontab')
|
||||
->where(['id' => $id])
|
||||
->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取接下来几次执行时间
|
||||
* @param $get
|
||||
* @return array
|
||||
*/
|
||||
public static function expression($get)
|
||||
{
|
||||
if (CronExpression::isValidExpression($get['expression']) === false) {
|
||||
return [['time' => 0, 'date' => '规则设置错误']];
|
||||
}
|
||||
$cron_expression = CronExpression::factory($get['expression']);
|
||||
try {
|
||||
$res = $cron_expression->getMultipleRunDates(5);
|
||||
} catch (Exception $e) {
|
||||
return [['time' => 0, 'date' => '规则设置错误']];
|
||||
}
|
||||
$res = json_decode(json_encode($res), true);
|
||||
$lists = [];
|
||||
foreach ($res as $k => $v) {
|
||||
$lists[$k]['time'] = $k + 1;
|
||||
$lists[$k]['date'] = str_replace('.000000', '', $v['date']);
|
||||
}
|
||||
$lists[] = ['time' => 'x', 'date' => '……'];
|
||||
return $lists;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加系统任务
|
||||
* @param $post
|
||||
* @return int|string
|
||||
*/
|
||||
public static function add($post)
|
||||
{
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'type' => $post['type'],
|
||||
'remark' => $post['remark'],
|
||||
'command' => $post['command'],
|
||||
'parameter' => $post['parameter'],
|
||||
'status' => $post['status'],
|
||||
'expression' => $post['expression'],
|
||||
'create_time' => time()
|
||||
];
|
||||
$result = Db::name('dev_crontab')
|
||||
->insert($data);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑系统任务
|
||||
* @param $post
|
||||
* @return int|string
|
||||
*/
|
||||
public static function edit($post)
|
||||
{
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'type' => $post['type'],
|
||||
'remark' => $post['remark'],
|
||||
'command' => $post['command'],
|
||||
'parameter' => $post['parameter'],
|
||||
'status' => $post['status'],
|
||||
'expression' => $post['expression'],
|
||||
'update_time' => time()
|
||||
];
|
||||
$result = Db::name('dev_crontab')
|
||||
->where(['id' => $post['id']])
|
||||
->update($data);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除定时任务
|
||||
* @param $id
|
||||
* @return int
|
||||
* @throws Exception
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
$system = Db::name('dev_crontab')
|
||||
->where(['id' => $id])
|
||||
->value('system');
|
||||
if ($system === 1) {
|
||||
return false;
|
||||
}
|
||||
$flag = Db::name('dev_crontab')
|
||||
->where(['id' => $id])
|
||||
->delete();
|
||||
return $flag;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\admin\model\DistributionMemberApply;
|
||||
use app\common\logic\DistributionLogic;
|
||||
use app\common\logic\LogicBase;
|
||||
use app\common\model\Distribution;
|
||||
use app\common\server\AreaServer;
|
||||
use app\common\server\UrlServer;
|
||||
use think\Db;
|
||||
|
||||
class DistributionApplyLogic extends LogicBase
|
||||
{
|
||||
public static function lists($get)
|
||||
{
|
||||
try {
|
||||
$where[] = ['DMA.status', '=', $get['type'] ?? 0];
|
||||
if (!empty($get['keyword']) and $get['keyword']) {
|
||||
switch ($get['keyword_type']) {
|
||||
case 'sn':
|
||||
$where[] = ['U.sn', 'like', '%'.$get['keyword'].'%'];
|
||||
break;
|
||||
case 'nickname':
|
||||
$where[] = ['U.nickname', 'like', '%'.$get['keyword'].'%'];
|
||||
break;
|
||||
case 'mobile':
|
||||
$where[] = ['U.mobile', '=', $get['keyword']];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$model = new DistributionMemberApply();
|
||||
$lists = $model->field(['DMA.*'])->alias('DMA')
|
||||
->where($where)
|
||||
->with(['user.level'])
|
||||
->join('user U', 'U.id = DMA.user_id')
|
||||
->paginate([
|
||||
'page' => $get['page'],
|
||||
'list_rows' => $get['limit'],
|
||||
'var_page' => 'page'
|
||||
])->toArray();
|
||||
|
||||
foreach ($lists['data'] as &$item) {
|
||||
if ($item['user']) {
|
||||
$item['user']['avatar'] = UrlServer::getFileUrl($item['user']['avatar']);
|
||||
}
|
||||
$item['region'] = AreaServer::getAddress([
|
||||
$item['province'],
|
||||
$item['city'],
|
||||
$item['district']]
|
||||
);
|
||||
}
|
||||
|
||||
return ['count'=>$lists['total'], 'lists'=>$lists['data']];
|
||||
} catch (\Exception $e) {
|
||||
return ['error'=>$e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
public static function detail($id)
|
||||
{
|
||||
$model = new DistributionMemberApply();
|
||||
$detail = $model->field(true)
|
||||
->with(['user.level'])
|
||||
->findOrEmpty($id)
|
||||
->toArray();
|
||||
|
||||
$detail['status_text'] = DistributionMemberApply::getApplyStatus($detail['status']);
|
||||
$detail['region'] = AreaServer::getAddress([
|
||||
$detail['province'],
|
||||
$detail['city'],
|
||||
$detail['district']]
|
||||
);
|
||||
return $detail;
|
||||
}
|
||||
|
||||
public static function audit($post)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
if ($post['audit_status'] == 1) {
|
||||
// 审核通过
|
||||
$model = new DistributionMemberApply();
|
||||
$apply = $model->field(true)->findOrEmpty((int)$post['id'])->toArray();
|
||||
|
||||
DistributionMemberApply::update([
|
||||
'status' => $post['audit_status'],
|
||||
'denial_reason' => $post['denial_reason'] ?? '',
|
||||
'update_time' => time()
|
||||
], ['id'=>(int)$post['id']]);
|
||||
|
||||
$distribution = Distribution::where('user_id', $apply['user_id'])->findOrEmpty()->toArray();
|
||||
if (empty($distribution)) {
|
||||
// 生成分销基础信息表
|
||||
DistributionLogic::add($apply['user_id']);
|
||||
}
|
||||
// 更新分销基础信息表
|
||||
Distribution::where('user_id', $apply['user_id'])->update([
|
||||
'is_distribution' => 1,
|
||||
'distribution_time' => time()
|
||||
]);
|
||||
} else {
|
||||
// 审核拒绝
|
||||
DistributionMemberApply::update([
|
||||
'status' => $post['audit_status'],
|
||||
'denial_reason' => $post['denial_reason'] ?? '',
|
||||
'update_time' => time()
|
||||
], ['id'=>(int)$post['id']]);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
static::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\common\logic\LogicBase;
|
||||
use app\common\model\Distribution;
|
||||
use app\common\model\DistributionOrder;
|
||||
use app\common\model\DistributionOrderGoods;
|
||||
use app\common\server\UrlServer;
|
||||
|
||||
class DistributionCenterLogic extends LogicBase
|
||||
{
|
||||
/**
|
||||
* @notes 数据概览
|
||||
* @return array
|
||||
* @author Tab
|
||||
*/
|
||||
public static function center()
|
||||
{
|
||||
$data = [
|
||||
'earnings' => self::earnings(),
|
||||
'members' => self::members(),
|
||||
'topGoods' => self::topGoods(),
|
||||
'topMembers' => self::topMembers(),
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 佣金数据
|
||||
* @return array
|
||||
* @author Tab
|
||||
*/
|
||||
public static function earnings()
|
||||
{
|
||||
// 累计已入账佣金
|
||||
$totalSuccess = DistributionOrderGoods::where([
|
||||
'status' => 2,
|
||||
])->sum('money');
|
||||
// 今日已入账佣金
|
||||
$totalTodaySuccess = DistributionOrderGoods::where([
|
||||
'status' => 2,
|
||||
])->whereTime('settlement_time', 'd')->sum('money');
|
||||
// 累计待结算佣金
|
||||
$totalWait = DistributionOrderGoods::where([
|
||||
'status' => 1,
|
||||
])->sum('money');
|
||||
// 今日待结算佣金
|
||||
$totalTodayWait = DistributionOrderGoods::where([
|
||||
'status' => 1,
|
||||
])->whereTime('create_time', 'd')->sum('money');
|
||||
|
||||
return [
|
||||
'total_success' => $totalSuccess,
|
||||
'total_today_success' => $totalTodaySuccess,
|
||||
'total_wait' => $totalWait,
|
||||
'total_today_wait' => $totalTodayWait,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 分销会员数据
|
||||
* @author Tab
|
||||
*/
|
||||
public static function members()
|
||||
{
|
||||
$members = Distribution::where('is_distribution', 1)->count();
|
||||
$users = Distribution::count();
|
||||
$proportion = 0;
|
||||
if ($users) {
|
||||
$proportion = round(($members / $users), 2) * 100;
|
||||
}
|
||||
|
||||
|
||||
return [
|
||||
'members' => $members,
|
||||
'proportion' => $proportion,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 分销商品排行榜
|
||||
* @author Tab
|
||||
*/
|
||||
public static function topGoods()
|
||||
{
|
||||
$field = [
|
||||
'sum(dog.money)' => 'total_money',
|
||||
'g.image' => 'goods_image',
|
||||
'og.goods_name',
|
||||
];
|
||||
$where = [
|
||||
'dog.status' => 2, // 已入账
|
||||
];
|
||||
$topGoods = DistributionOrderGoods::alias('dog')
|
||||
->leftJoin('order_goods og', 'og.id = dog.order_goods_id')
|
||||
->leftJoin('goods g', 'g.id = og.goods_id')
|
||||
->field($field)
|
||||
->where($where)
|
||||
->group('g.image,og.goods_name')
|
||||
->order('total_money', 'desc')
|
||||
->limit(10)
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($topGoods as &$item) {
|
||||
$item['goods_image'] = empty($item['goods_image']) ? '' : UrlServer::getFileUrl($item['goods_image']);
|
||||
}
|
||||
|
||||
return $topGoods;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 分销会员排行榜
|
||||
* @return mixed
|
||||
* @author Tab
|
||||
*/
|
||||
public static function topMembers()
|
||||
{
|
||||
$field = [
|
||||
'sum(dog.money)' => 'total_money',
|
||||
'u.avatar',
|
||||
'u.nickname',
|
||||
];
|
||||
$where = [
|
||||
'dog.status' => 2, // 已入账
|
||||
];
|
||||
$topMembers = DistributionOrderGoods::alias('dog')
|
||||
->leftJoin('user u', 'u.id = dog.user_id')
|
||||
->field($field)
|
||||
->where($where)
|
||||
->group('dog.money,u.avatar,u.nickname')
|
||||
->order('total_money', 'desc')
|
||||
->limit(10)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
foreach($topMembers as &$item) {
|
||||
$item['avatar'] = empty($item['avatar']) ? '' : UrlServer::getFileUrl($item['avatar']);
|
||||
}
|
||||
|
||||
return $topMembers;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,295 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +------------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\api\model\Goods;
|
||||
use app\common\logic\LogicBase;
|
||||
use app\common\model\DistributionGoods;
|
||||
use app\common\model\DistributionLevel;
|
||||
use think\Db;
|
||||
|
||||
class DistributionGoodsLogic extends LogicBase
|
||||
{
|
||||
/**
|
||||
* @notes 分销商品列表
|
||||
* @param $params
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author Tab
|
||||
*/
|
||||
public static function lists($params)
|
||||
{
|
||||
$where = [
|
||||
['del', '<>', '1'],
|
||||
];
|
||||
// 商品信息
|
||||
if (isset($params['keyword']) && !empty($params['keyword'])) {
|
||||
$where[] = ['name|code', 'like', '%'. $params['keyword']. '%'];
|
||||
}
|
||||
|
||||
$field = [
|
||||
'id',
|
||||
'code',
|
||||
'name',
|
||||
'image',
|
||||
'max_price',
|
||||
'min_price',
|
||||
'id' => 'distribution_flag',
|
||||
];
|
||||
$lists = Goods::field($field)
|
||||
->where($where)
|
||||
->withSearch(['is_distribution'], $params)
|
||||
->page($params['page'], $params['limit'])
|
||||
->order('id', 'desc')
|
||||
->select()
|
||||
->toArray();
|
||||
$count = Goods::field($field)
|
||||
->where($where)
|
||||
->withSearch(['is_distribution'], $params)
|
||||
->count();
|
||||
|
||||
return [
|
||||
'count' => $count,
|
||||
'lists' => $lists
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 商品详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author Tab
|
||||
*/
|
||||
public static function detail($params)
|
||||
{
|
||||
// 商品信息
|
||||
$goods = Goods::field('id,code,name')->with('goods_item')->findOrEmpty($params['id'])->toArray();
|
||||
// 分销等级信息
|
||||
$distributionLevelLists = DistributionLevel::order('weights', 'asc')->select()->toArray();
|
||||
// 商品分销信息
|
||||
$distributionGoods = DistributionGoods::where('goods_id', $params['id'])->select()->toArray();
|
||||
if(empty($distributionGoods)) {
|
||||
// 未参与分销
|
||||
$goods['is_distribution'] = 0;
|
||||
$goods['rule'] = 1;
|
||||
$ratio = self::formatLevel($distributionLevelLists, $goods);
|
||||
} else {
|
||||
$goods['is_distribution'] = $distributionGoods[0]['is_distribution'];
|
||||
$goods['rule'] = $distributionGoods[0]['rule'];
|
||||
if($distributionGoods[0]['rule'] == 1) {
|
||||
$ratio = self::formatLevel($distributionLevelLists, $goods);
|
||||
} else {
|
||||
$ratio = self::formatGoods($distributionLevelLists, $goods);
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'goods' => $goods,
|
||||
'ratio' => $ratio
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 拼装分销等级佣金比例
|
||||
* @param $distributionLevelLists
|
||||
* @param $goods
|
||||
* @return array
|
||||
* @author Tab
|
||||
*/
|
||||
public static function formatLevel($distributionLevelLists, $goods)
|
||||
{
|
||||
$ratio = [];
|
||||
foreach($distributionLevelLists as $level) {
|
||||
foreach($goods['goods_item'] as $item) {
|
||||
$temp = [
|
||||
'level_id' => $level['id'],
|
||||
'level_name' => $level['name'],
|
||||
'first_ratio' => $level['first_ratio'],
|
||||
'second_ratio' => $level['second_ratio'],
|
||||
'goods_id' => $item['goods_id'],
|
||||
'item_id' => $item['id'],
|
||||
'spec_value_str' => $item['spec_value_str'],
|
||||
'price' => $item['price']
|
||||
];
|
||||
$ratio[] = $temp;
|
||||
}
|
||||
}
|
||||
return $ratio;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 拼装单独设置的佣金比例
|
||||
* @param $distributionLevelLists
|
||||
* @param $goods
|
||||
* @param $distributionGoods
|
||||
* @return array
|
||||
* @author Tab
|
||||
*/
|
||||
public static function formatGoods($distributionLevelLists, $goods)
|
||||
{
|
||||
$ratio = [];
|
||||
foreach($distributionLevelLists as $level) {
|
||||
foreach($goods['goods_item'] as $item) {
|
||||
$record = DistributionGoods::where([
|
||||
'level_id' => $level['id'],
|
||||
'item_id' => $item['id'],
|
||||
])->findOrEmpty()->toArray();
|
||||
$temp = [
|
||||
'level_id' => $level['id'],
|
||||
'level_name' => $level['name'],
|
||||
'first_ratio' => $record['first_ratio'] ?? 0,
|
||||
'second_ratio' => $record['second_ratio'] ?? 0,
|
||||
'goods_id' => $item['goods_id'],
|
||||
'item_id' => $item['id'],
|
||||
'spec_value_str' => $item['spec_value_str'],
|
||||
'price' => $item['price']
|
||||
];
|
||||
$ratio[] = $temp;
|
||||
}
|
||||
}
|
||||
return $ratio;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 设置佣金
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author Tab
|
||||
*/
|
||||
public static function set($params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
switch($params['rule']) {
|
||||
// 根据分销会员等级比例分佣
|
||||
case 1:
|
||||
self::setRuleOne($params);
|
||||
break;
|
||||
|
||||
// 单独设置
|
||||
case 2:
|
||||
self::setRuleTwo($params);
|
||||
break;
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
}catch(\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 设置佣金 - 根据分销会员等级比例分佣
|
||||
* @param $params
|
||||
* @author Tab
|
||||
*/
|
||||
public static function setRuleOne($params)
|
||||
{
|
||||
// 删除旧数据
|
||||
$deleteIds = DistributionGoods::where('goods_id', $params['id'])->column('id');
|
||||
DistributionGoods::destroy($deleteIds);
|
||||
|
||||
// 生成新数据
|
||||
$data = [
|
||||
'goods_id' => $params['id'],
|
||||
'is_distribution' => $params['is_distribution'],
|
||||
'rule' => $params['rule'],
|
||||
];
|
||||
DistributionGoods::create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 设置佣金 - 单独自定义
|
||||
* @param $params
|
||||
* @throws \Exception
|
||||
* @author Tab
|
||||
*/
|
||||
public static function setRuleTwo($params)
|
||||
{
|
||||
// 删除旧数据
|
||||
$deleteIds = DistributionGoods::where('goods_id', $params['id'])->column('id');
|
||||
DistributionGoods::destroy($deleteIds);
|
||||
|
||||
// 生成新数据
|
||||
$data= [];
|
||||
foreach($params['first_ratio'] as $k => $v) {
|
||||
if ($params['first_ratio'][$k] < 0 || $params['second_ratio'][$k] < 0) {
|
||||
throw new \Exception('分销比例不能小于0');
|
||||
}
|
||||
$temp = [
|
||||
'goods_id' => $params['id'],
|
||||
'item_id' => $params['items'][$k],
|
||||
'level_id' => $params['levels'][$k],
|
||||
'first_ratio' => !empty($params['first_ratio'][$k]) ? round($params['first_ratio'][$k], 2) : 0,
|
||||
'second_ratio' => !empty($params['second_ratio'][$k]) ? round($params['second_ratio'][$k], 2) : 0,
|
||||
'is_distribution' => $params['is_distribution'],
|
||||
'rule' => $params['rule'],
|
||||
];
|
||||
$data[] = $temp;
|
||||
}
|
||||
(new DistributionGoods())->saveAll($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 参与分销/取消分销
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author Tab
|
||||
*/
|
||||
public static function isDistribution($params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try{
|
||||
$existedIds = DistributionGoods::distinct(true)->column('goods_id');
|
||||
$updateIds = array_intersect($params['ids'], $existedIds);
|
||||
$insertIds = array_diff($params['ids'], $existedIds);
|
||||
if (!empty($updateIds)) {
|
||||
// 有分销数据,直接修改
|
||||
DistributionGoods::where('goods_id', 'in', $updateIds)->update(['is_distribution' => $params['is_distribution']]);
|
||||
}
|
||||
|
||||
// 无分销数据,新增
|
||||
$insertData = [];
|
||||
foreach($insertIds as $id) {
|
||||
$item['goods_id'] = $id;
|
||||
$item['is_distribution'] = $params['is_distribution'];
|
||||
$item['rule'] = 1;
|
||||
$insertData[] = $item;
|
||||
}
|
||||
|
||||
(new DistributionGoods())->saveAll($insertData);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
}catch(\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,493 @@
|
||||
<?php
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\common\logic\LogicBase;
|
||||
use app\common\model\Distribution;
|
||||
use app\common\model\DistributionGoods;
|
||||
use app\common\model\DistributionLevel;
|
||||
use app\common\model\DistributionLevelUpdate;
|
||||
use app\common\model\DistributionOrderGoods;
|
||||
use app\common\model\Order;
|
||||
use think\Db;
|
||||
|
||||
class DistributionLevelLogic extends LogicBase
|
||||
{
|
||||
/**
|
||||
* @notes 分销等级列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author Tab
|
||||
*/
|
||||
public static function index()
|
||||
{
|
||||
$field = [
|
||||
'id',
|
||||
'name',
|
||||
'weights' => 'weights_desc',
|
||||
'first_ratio',
|
||||
'second_ratio',
|
||||
'is_default',
|
||||
'id' => 'members_num'
|
||||
];
|
||||
$lists = DistributionLevel::field($field)
|
||||
->order('weights', 'asc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$count = DistributionLevel::count();
|
||||
|
||||
return [
|
||||
'count' => $count,
|
||||
'lists' => $lists,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 添加分销会员等级
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author Tab
|
||||
*/
|
||||
public static function add($params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try{
|
||||
// 写入等级主表
|
||||
$params['remark'] = $params['remark'] ?? '';
|
||||
$newLevel = DistributionLevel::create($params);
|
||||
|
||||
// 写入升级条件表
|
||||
self::addUpdateCondition($params, $newLevel->id);
|
||||
|
||||
// 处理分销商品比例
|
||||
self::updateDistributionGoods($newLevel->id);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
}catch(\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 添加更新升级条件
|
||||
* @param $params
|
||||
* @param $level_id
|
||||
* @throws \Exception
|
||||
* @author Tab
|
||||
*/
|
||||
public static function addUpdateCondition($params, $level_id)
|
||||
{
|
||||
$updateConditionData = [];
|
||||
foreach($params['update_condition'] as $key) {
|
||||
// 判断是否在规定的条件字段
|
||||
if(!in_array($key, DistributionLevel::UPDATE_CONDITION_FIELDS, true)) {
|
||||
continue;
|
||||
}
|
||||
if ($params[$key] < 0) {
|
||||
throw new \Exception('升级条件不允许小于0');
|
||||
}
|
||||
// 获取键对应值的字段名
|
||||
$valueField = DistributionLevel::getValueFiled($key);
|
||||
$updateConditionData[] = [
|
||||
'level_id' => $level_id,
|
||||
'key' => $key,
|
||||
$valueField => $params[$key]
|
||||
];
|
||||
}
|
||||
(new DistributionLevelUpdate())->saveAll($updateConditionData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取分销等级详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author Tab
|
||||
*/
|
||||
public static function detail($params)
|
||||
{
|
||||
$level = DistributionLevel::findOrEmpty($params['id']);
|
||||
if($level->isEmpty()) {
|
||||
return [];
|
||||
}
|
||||
$level = $level->toArray();
|
||||
// 默认等级
|
||||
if($level['is_default']) {
|
||||
unset($level['self_ratio']);
|
||||
unset($level['third_ratio']);
|
||||
unset($level['update_relation']);
|
||||
return $level;
|
||||
}
|
||||
// 自定义等级
|
||||
$level['update_condition'] = self::getUpdateCondition($level);
|
||||
unset($level['self_ratio']);
|
||||
unset($level['third_ratio']);
|
||||
|
||||
return $level;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取升级条件
|
||||
* @param $level
|
||||
* @return array
|
||||
* @author Tab
|
||||
*/
|
||||
public static function getUpdateCondition($level)
|
||||
{
|
||||
$updateCondition = DistributionLevelUpdate::where('level_id', $level['id'])->column('key,value_int,value_decimal,value_text');
|
||||
$updateConditionData = [];
|
||||
foreach($updateCondition as $item) {
|
||||
if($item['value_int']) {
|
||||
$updateConditionData[$item['key']] = $item['value_int'];
|
||||
continue;
|
||||
}
|
||||
if($item['value_decimal']) {
|
||||
$updateConditionData[$item['key']] = $item['value_decimal'];
|
||||
continue;
|
||||
}
|
||||
if($item['value_text']) {
|
||||
$updateConditionData[$item['key']] = $item['value_text'];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$data = [
|
||||
'keys' => array_keys($updateConditionData),
|
||||
'data' => $updateConditionData
|
||||
];
|
||||
// 补全条件
|
||||
foreach(DistributionLevel::UPDATE_CONDITION_FIELDS as $field) {
|
||||
if(!isset($data['data'][$field])) {
|
||||
$data['data'][$field] = '';
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 编辑分销等级
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author Tab
|
||||
*/
|
||||
public static function edit($params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try{
|
||||
$params['remark'] = $params['remark'] ?? '';
|
||||
$level = DistributionLevel::findOrEmpty($params['id']);
|
||||
if($level->isEmpty()) {
|
||||
throw new \Exception('等级不存在');
|
||||
}
|
||||
|
||||
// 佣金比例保留两位小数
|
||||
$params['first_ratio'] = !empty($params['first_ratio']) ? round($params['first_ratio'], 2) : 0;
|
||||
$params['second_ratio'] = !empty($params['second_ratio']) ? round($params['second_ratio'], 2) : 0;
|
||||
|
||||
// 默认等级
|
||||
if($level->is_default) {
|
||||
$level->allowField(['name', 'first_ratio', 'second_ratio','remark'])->save($params);
|
||||
Db::commit();
|
||||
return true;
|
||||
}
|
||||
// 自定义等级 - 更新主表信息
|
||||
if(!$params['weights'] > 1) {
|
||||
throw new \Exception('级别须大于1');
|
||||
}
|
||||
if(!isset($params['update_relation'])) {
|
||||
throw new \Exception('请选择升级关系');
|
||||
}
|
||||
if(!isset($params['update_condition']) || !count($params['update_condition'])) {
|
||||
throw new \Exception('请选择升级条件');
|
||||
}
|
||||
$level->allowField(['name', 'weights', 'first_ratio', 'second_ratio','remark', 'update_relation'])->save($params);
|
||||
|
||||
// 自定义等级 - 删除旧升级条件
|
||||
$deleteIds = DistributionLevelUpdate::where('level_id', $level->id)->column('id');
|
||||
DistributionLevelUpdate::destroy($deleteIds);
|
||||
|
||||
// 自定义等级 - 添加新的升级条件
|
||||
self::addUpdateCondition($params, $level->id);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
}catch(\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 删除分销等级
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author Tab
|
||||
*/
|
||||
public static function delete($params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try{
|
||||
$level = DistributionLevel::findOrEmpty($params['id']);
|
||||
if($level->isEmpty()) {
|
||||
throw new \Exception('等级不存在');
|
||||
}
|
||||
if($level->is_default) {
|
||||
throw new \Exception('系统默认等级不允许删除');
|
||||
}
|
||||
|
||||
// 重置该等级下的分销会员为系统默认等级
|
||||
$defaultId = DistributionLevel::where('is_default', 1)->value('id');
|
||||
Distribution::where('level_id', $level->id)->update(['level_id' => $defaultId]);
|
||||
|
||||
// 删除升级条件
|
||||
$deleteIds = DistributionLevelUpdate::where('level_id', $level->id)->column('id');
|
||||
DistributionLevelUpdate::destroy($deleteIds);
|
||||
|
||||
// 删除该等级下的分销商品比例
|
||||
$deleteIds = DistributionGoods::where('level_id', $level->id)->column('id');
|
||||
DistributionGoods::destroy($deleteIds);
|
||||
|
||||
// 删除等级
|
||||
$level->delete();
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
}catch(\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 更新分销会员等级
|
||||
* @param $userId
|
||||
* @return false
|
||||
* @author Tab
|
||||
*/
|
||||
public static function updateDistributionLevel($userId)
|
||||
{
|
||||
// 非默认等级
|
||||
$levels = DistributionLevel::where('is_default', 0)
|
||||
->order('weights', 'desc')
|
||||
->column('id,name,weights,update_relation', 'id');
|
||||
|
||||
$userInfo = Distribution::alias('d')
|
||||
->leftJoin('distribution_level dl', 'dl.id = d.level_id')
|
||||
->field('d.is_distribution,d.level_id,dl.weights')
|
||||
->where('d.user_id', $userId)
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
|
||||
// 非分销会员直接返回false
|
||||
if(empty($userInfo) || !$userInfo['is_distribution']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach($levels as $level) {
|
||||
if(self::isMeetConditions($userId, $level) && $level['weights'] > $userInfo['weights']) {
|
||||
// 满足升级条件且是升更高的等级
|
||||
Distribution::where(['user_id' => $userId])->update(['level_id' => $level['id']]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 判断是否满足当前等级的升级条件
|
||||
* @param $userId
|
||||
* @param $level
|
||||
* @return bool
|
||||
* @author Tab
|
||||
*/
|
||||
public static function isMeetConditions($userId, $level)
|
||||
{
|
||||
$updateRelation = $level['update_relation'];
|
||||
// 任一条件满足升级
|
||||
if($updateRelation == 1) {
|
||||
$flagOr = self::singleConsumptionAmountFlag($userId, $level, $updateRelation)
|
||||
|| self::cumulativeConsumptionAmountFlag($userId, $level, $updateRelation)
|
||||
|| self::cumulativeConsumptionTimesFlag($userId, $level, $updateRelation)
|
||||
|| self::returnedCommissionFlag($userId, $level, $updateRelation);
|
||||
return $flagOr;
|
||||
}
|
||||
|
||||
// 全部条件满足升级
|
||||
if($updateRelation == 2) {
|
||||
$flagAnd = self::singleConsumptionAmountFlag($userId, $level, $updateRelation)
|
||||
&& self::cumulativeConsumptionAmountFlag($userId, $level, $updateRelation)
|
||||
&& self::cumulativeConsumptionTimesFlag($userId, $level, $updateRelation)
|
||||
&& self::returnedCommissionFlag($userId, $level, $updateRelation);
|
||||
return $flagAnd;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 判断是否满足单笔消费金额条件
|
||||
* @param $userId
|
||||
* @param $level
|
||||
* @return bool
|
||||
* @author Tab
|
||||
*/
|
||||
public static function singleConsumptionAmountFlag($userId, $level, $updateRelation)
|
||||
{
|
||||
$condition = DistributionLevelUpdate::field('value_int,value_decimal,value_text')
|
||||
->where([
|
||||
'level_id' => $level['id'],
|
||||
'key' => 'singleConsumptionAmount'
|
||||
])
|
||||
->findOrEmpty();
|
||||
if($condition->isEmpty()) {
|
||||
// 等级条件为满足任一条件(updateRelation=1) 返回false (满足已设置的任一条件时才升级,未设置的条件归为未满足,返回false)
|
||||
// 等级条件为满足全部条件(updateRelation=2) 返回true (满足已设置的所有条件时才升级,未设置的条件归为已满足,返回true)
|
||||
return $updateRelation == 2;
|
||||
}
|
||||
$recentOrder = Order::where([
|
||||
'user_id' => $userId,
|
||||
'pay_status' => 1
|
||||
])
|
||||
->order('id', 'desc')
|
||||
->findOrEmpty();
|
||||
if($recentOrder->isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if($recentOrder->order_amount >= $condition['value_decimal']) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 判断是否满足累计消费金额条件
|
||||
* @param $userId
|
||||
* @param $level
|
||||
* @return bool
|
||||
* @author Tab
|
||||
*/
|
||||
public static function cumulativeConsumptionAmountFlag($userId, $level, $updateRelation)
|
||||
{
|
||||
$condition = DistributionLevelUpdate::field('value_int,value_decimal,value_text')
|
||||
->where([
|
||||
'level_id' => $level['id'],
|
||||
'key' => 'cumulativeConsumptionAmount'
|
||||
])
|
||||
->findOrEmpty();
|
||||
if($condition->isEmpty()) {
|
||||
// 等级条件为满足任一条件(updateRelation=1) 返回false (满足已设置的任一条件时才升级,未设置的条件归为未满足,返回false)
|
||||
// 等级条件为满足全部条件(updateRelation=2) 返回true (满足已设置的所有条件时才升级,未设置的条件归为已满足,返回true)
|
||||
return $updateRelation == 2;
|
||||
}
|
||||
$cumulativeConsumptionAmount = Order::where([
|
||||
'user_id' => $userId,
|
||||
'pay_status' => 1
|
||||
])->sum('order_amount');
|
||||
if($cumulativeConsumptionAmount >= $condition['value_decimal']) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 判断是否满足累计消费次数条件
|
||||
* @param $userId
|
||||
* @param $level
|
||||
* @return bool
|
||||
* @author Tab
|
||||
*/
|
||||
public static function cumulativeConsumptionTimesFlag($userId, $level, $updateRelation)
|
||||
{
|
||||
$condition = DistributionLevelUpdate::field('value_int,value_decimal,value_text')
|
||||
->where([
|
||||
'level_id' => $level['id'],
|
||||
'key' => 'cumulativeConsumptionTimes'
|
||||
])
|
||||
->findOrEmpty();
|
||||
if($condition->isEmpty()) {
|
||||
// 等级条件为满足任一条件(updateRelation=1) 返回false (满足已设置的任一条件时才升级,未设置的条件归为未满足,返回false)
|
||||
// 等级条件为满足全部条件(updateRelation=2) 返回true (满足已设置的所有条件时才升级,未设置的条件归为已满足,返回true)
|
||||
return $updateRelation == 2;
|
||||
}
|
||||
$cumulativeConsumptionTimes = Order::where([
|
||||
'user_id' => $userId,
|
||||
'pay_status' => 1
|
||||
])->count();
|
||||
|
||||
if($cumulativeConsumptionTimes >= $condition['value_int']) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 判断是否消费已返佣金条件
|
||||
* @param $userId
|
||||
* @param $level
|
||||
* @return bool
|
||||
* @author Tab
|
||||
*/
|
||||
public static function returnedCommissionFlag($userId, $level, $updateRelation)
|
||||
{
|
||||
$condition = DistributionLevelUpdate::field('value_int,value_decimal,value_text')
|
||||
->where([
|
||||
'level_id' => $level['id'],
|
||||
'key' => 'returnedCommission'
|
||||
])
|
||||
->findOrEmpty();
|
||||
if($condition->isEmpty()) {
|
||||
// 等级条件为满足任一条件(updateRelation=1) 返回false (满足已设置的任一条件时才升级,未设置的条件归为未满足,返回false)
|
||||
// 等级条件为满足全部条件(updateRelation=2) 返回true (满足已设置的所有条件时才升级,未设置的条件归为已满足,返回true)
|
||||
return $updateRelation == 2;
|
||||
}
|
||||
$returnedCommission = DistributionOrderGoods::where([
|
||||
'user_id' => $userId,
|
||||
'status' => 2
|
||||
])->sum('money');
|
||||
if($returnedCommission >= $condition['value_decimal']) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取所有分销会员等级
|
||||
* @return array
|
||||
* @author Tab
|
||||
*/
|
||||
public static function getLevels()
|
||||
{
|
||||
return DistributionLevel::order('weights', 'asc')->column('id, name,weights');
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 更新分销商品比例
|
||||
* @param $levelId
|
||||
* @author Tab
|
||||
*/
|
||||
public static function updateDistributionGoods($levelId)
|
||||
{
|
||||
// 处理单独设置比例的商品,新增分销会等级佣金比例初始化为0
|
||||
$field = [
|
||||
'goods_id',
|
||||
'item_id',
|
||||
];
|
||||
$distribution = DistributionGoods::distinct(true)->field($field)->where('rule', 2)->select()->toArray();
|
||||
$addData = [];
|
||||
foreach($distribution as $item) {
|
||||
$temp = [
|
||||
'goods_id' => $item['goods_id'],
|
||||
'item_id' => $item['item_id'],
|
||||
'level_id' => $levelId,
|
||||
'first_ratio' => 0,
|
||||
'second_ratio' => 0,
|
||||
'rule' => 2,
|
||||
];
|
||||
$addData[] = $temp;
|
||||
}
|
||||
(new DistributionGoods())->saveAll($addData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
<?php
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\admin\model\User;
|
||||
use app\common\logic\LogicBase;
|
||||
use app\common\model\Distribution;
|
||||
use app\common\model\DistributionOrderGoods;
|
||||
use app\common\server\UrlServer;
|
||||
|
||||
/**
|
||||
* 分销会员逻辑层
|
||||
* Class DistributionMemberLogic
|
||||
* @package app\admin\logic\distribution
|
||||
*/
|
||||
class DistributionMemberLogic extends LogicBase
|
||||
{
|
||||
/**
|
||||
* @notes 分销会员列表
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author Tab
|
||||
*/
|
||||
public static function lists($params)
|
||||
{
|
||||
$where = [
|
||||
['d.is_distribution', '=', 1]
|
||||
];
|
||||
// 用户信息
|
||||
if (isset($params['keyword']) && !empty($params['keyword'])) {
|
||||
$where[] = ['u.sn|u.nickname', 'like', '%'. $params['keyword'] .'%'];
|
||||
}
|
||||
// 分销等级
|
||||
if (isset($params['level_id']) && $params['level_id'] != 'all') {
|
||||
$where[] = ['d.level_id', '=', $params['level_id']];
|
||||
}
|
||||
// 分销状态
|
||||
if (isset($params['is_freeze']) && $params['is_freeze'] != 'all') {
|
||||
$where[] = ['d.is_freeze', '=', $params['is_freeze']];
|
||||
}
|
||||
|
||||
$field = [
|
||||
'u.id' => 'user_id',
|
||||
'u.sn' => 'user_sn',
|
||||
'u.avatar',
|
||||
'u.nickname',
|
||||
'dl.id' => 'level_id',
|
||||
'dl.weights',
|
||||
'dl.name' => 'level_name',
|
||||
'd.is_freeze',
|
||||
'd.distribution_time',
|
||||
];
|
||||
$lists = Distribution::alias('d')
|
||||
->leftJoin('user u', 'u.id = d.user_id')
|
||||
->leftJoin('distribution_level dl', 'dl.id = d.level_id')
|
||||
->field($field)
|
||||
->where($where)
|
||||
->order('u.id', 'desc')
|
||||
->page($params['page'], $params['limit'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$count = Distribution::alias('d')
|
||||
->leftJoin('user u', 'u.id = d.user_id')
|
||||
->leftJoin('distribution_level dl', 'dl.id = d.level_id')
|
||||
->field($field)
|
||||
->where($where)
|
||||
->count();
|
||||
|
||||
foreach($lists as &$item) {
|
||||
$item['avatar'] = empty($item['avatar']) ? '' : UrlServer::getFileUrl($item['avatar']);
|
||||
$item['earnings'] = DistributionOrderGoods::getEarnings($item['user_id']);
|
||||
}
|
||||
|
||||
return [
|
||||
'count' => $count,
|
||||
'lists' => $lists
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 用户列表
|
||||
* @param $params
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author Tab
|
||||
*/
|
||||
public static function getUserLists($params)
|
||||
{
|
||||
$where[] = ['del', '=', 0];
|
||||
// 用户信息
|
||||
if (isset($params['keyword']) && !empty($params['keyword'])) {
|
||||
$where[] = ['sn|nickname', 'like', '%'. $params['keyword'] .'%'];
|
||||
}
|
||||
|
||||
$lists = \app\common\model\User::field('id,sn,nickname,id as distribution')
|
||||
->where($where)
|
||||
->withSearch(['distribution'], $params)
|
||||
->page($params['page'], $params['limit'])
|
||||
->select()
|
||||
->toArray();
|
||||
$count = \app\common\model\User::where($where)->withSearch(['distribution'], $params)->count();
|
||||
|
||||
return [
|
||||
'count' => $count,
|
||||
'lists' => $lists,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 开通分销会员
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author Tab
|
||||
*/
|
||||
public static function open($params)
|
||||
{
|
||||
try {
|
||||
$user = User::where('id', $params['user_id'])->findOrEmpty()->toArray();
|
||||
if(empty($user)) {
|
||||
throw new \Exception('用户不存在');
|
||||
}
|
||||
$distribution = Distribution::where('user_id', $params['user_id'])->findOrEmpty()->toArray();
|
||||
if(!empty($distribution) && $distribution['is_distribution'] == 1) {
|
||||
throw new \Exception('用户已是分销会员');
|
||||
}
|
||||
if(!empty($distribution) && $distribution['is_distribution'] == 0) {
|
||||
Distribution::where('user_id', $params['user_id'])->update([
|
||||
'is_distribution' => 1,
|
||||
'distribution_time' => time()
|
||||
]);
|
||||
}
|
||||
if(empty($distribution)) {
|
||||
$data = [
|
||||
'user_id' => $params['user_id'],
|
||||
'level_id' => $params['level_id'],
|
||||
'is_distribution' => 1,
|
||||
'is_freeze' => 0,
|
||||
'remark' => '后台开通分销',
|
||||
'distribution_time' => time()
|
||||
];
|
||||
|
||||
Distribution::create($data);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getUser($params)
|
||||
{
|
||||
$field = [
|
||||
'u.id' => 'user_id',
|
||||
'u.sn' => 'user_sn',
|
||||
'u.nickname' => 'user_nickname',
|
||||
'dl.name' => 'level_name',
|
||||
'dl.weights',
|
||||
];
|
||||
$info = Distribution::alias('d')
|
||||
->leftJoin('user u', 'u.id = d.user_id')
|
||||
->leftJoin('distribution_level dl', 'dl.id = d.level_id')
|
||||
->field($field)
|
||||
->where('d.user_id', $params['id'])
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 分销会员等级调整
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author Tab
|
||||
*/
|
||||
public static function adjust($params)
|
||||
{
|
||||
try {
|
||||
Distribution::where(['user_id' => $params['user_id']])->update([
|
||||
'level_id' => $params['level_id']
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 冻结资格/恢复资格
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author Tab
|
||||
*/
|
||||
public static function isFreeze($params)
|
||||
{
|
||||
try {
|
||||
Distribution::where(['user_id' => $params['user_id']])->update([
|
||||
'is_freeze' => $params['is_freeze']
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch(\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +------------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\common\logic\LogicBase;
|
||||
use app\common\model\DistributionLevel;
|
||||
use app\common\model\DistributionOrderGoods;
|
||||
use app\common\model\User;
|
||||
use app\common\server\UrlServer;
|
||||
|
||||
class DistributionOrderGoodsLogic extends LogicBase
|
||||
{
|
||||
/**
|
||||
* @notes 分销订单列表
|
||||
* @param $params
|
||||
* @return int[]
|
||||
* @author Tab
|
||||
*/
|
||||
public static function lists($params)
|
||||
{
|
||||
$where = [];
|
||||
// 订单信息
|
||||
if (isset($params['order_keyword']) && !empty($params['order_keyword'])) {
|
||||
$where[] = ['o.order_sn', '=', $params['order_keyword']];
|
||||
}
|
||||
// 商品名称
|
||||
if (isset($params['goods_keyword']) && !empty($params['goods_keyword'])) {
|
||||
$where[] = ['og.goods_name', 'like', '%'.$params['goods_keyword'].'%'];
|
||||
}
|
||||
// 分销会员
|
||||
if (isset($params['distribution_keyword']) && !empty($params['distribution_keyword'])) {
|
||||
$where[] = ['u.sn|u.nickname', 'like', '%'.$params['distribution_keyword'].'%'];
|
||||
}
|
||||
// 佣金状态
|
||||
if (isset($params['status']) && !empty($params['status'])) {
|
||||
$where[] = ['dog.status', '=', $params['status']];
|
||||
}
|
||||
|
||||
$field = [
|
||||
'o.id' => 'order_id',
|
||||
'o.order_sn',
|
||||
'o.create_time' => 'order_create_time',
|
||||
'o.user_id' => 'order_user_id',
|
||||
'u.id' => 'distribution_user_id',
|
||||
'u.avatar' => 'distribution_avatar',
|
||||
'u.sn' => 'distribution_sn',
|
||||
'u.nickname' => 'distribution_nickname',
|
||||
'g.image' => 'goods_image',
|
||||
'g.name' => 'goods_name',
|
||||
'gi.spec_value_str',
|
||||
'og.goods_num' => 'goods_num',
|
||||
'og.total_pay_price' => 'total_pay_price',
|
||||
'dog.level_id',
|
||||
'dog.level',
|
||||
'dog.ratio',
|
||||
'dog.money',
|
||||
'dog.status' => 'status_desc',
|
||||
'dog.settlement_time'
|
||||
];
|
||||
|
||||
$lists = DistributionOrderGoods::alias('dog')
|
||||
->leftJoin('order o', 'o.id = dog.order_id')
|
||||
->leftJoin('user u', 'u.id = dog.user_id')
|
||||
->leftJoin('order_goods og', 'og.id = dog.order_goods_id')
|
||||
->leftJoin('goods g', 'g.id = og.goods_id')
|
||||
->leftJoin('goods_item gi', 'gi.id = og.item_id')
|
||||
->leftJoin('distribution_level dl', 'dl.id = dog.level_id')
|
||||
->field($field)
|
||||
->where($where)
|
||||
->order('dog.id', 'desc')
|
||||
->page($params['page'], $params['limit'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$count = DistributionOrderGoods::alias('dog')
|
||||
->leftJoin('order o', 'o.id = dog.order_id')
|
||||
->leftJoin('user u', 'u.id = dog.user_id')
|
||||
->leftJoin('order_goods og', 'og.id = dog.order_goods_id')
|
||||
->leftJoin('goods g', 'g.id = og.goods_id')
|
||||
->leftJoin('goods_item gi', 'gi.id = og.item_id')
|
||||
->leftJoin('distribution_level dl', 'dl.id = dog.level_id')
|
||||
->field($field)
|
||||
->where($where)
|
||||
->count();
|
||||
|
||||
foreach($lists as &$item) {
|
||||
$item['order_create_time'] = date('Y-m-d H:i:s', $item['order_create_time']);
|
||||
$item['user_info'] = User::getUserInfo($item['order_user_id']);
|
||||
$item['distribution_avatar'] = empty($item['distribution_avatar']) ? '' : UrlServer::getFileUrl($item['distribution_avatar']);
|
||||
$item['user_info']['avatar'] = empty($item['user_info']['avatar']) ? '' : UrlServer::getFileUrl($item['user_info']['avatar']);
|
||||
$item['level_name'] = DistributionLevel::getLevelName($item['level_id']);
|
||||
$item['goods_image'] = empty($item['goods_image']) ? '' : UrlServer::getFileUrl($item['goods_image']);
|
||||
}
|
||||
|
||||
return [
|
||||
'count' => $count,
|
||||
'lists' => $lists
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
use app\admin\model\User;
|
||||
use app\common\logic\DistributionLogic;
|
||||
use app\common\logic\LogicBase;
|
||||
use app\common\model\Distribution;
|
||||
use app\common\server\ConfigServer;
|
||||
use think\Db;
|
||||
|
||||
class DistributionSettingLogic extends LogicBase
|
||||
{
|
||||
public static function getConfig()
|
||||
{
|
||||
$config = [
|
||||
// 分销功能 0-关闭(默认) 1-开启
|
||||
'is_open' => ConfigServer::get('distribution', 'is_open', 0),
|
||||
// 分销层级 1-一级分销 2-二级分销(默认)
|
||||
'level' => ConfigServer::get('distribution', 'level', 2),
|
||||
// 商品详情是否显示佣金 0-不显示(默认) 1-默认
|
||||
'is_show_earnings' => ConfigServer::get('distribution', 'is_show_earnings', 0),
|
||||
// 详情页佣金可见用户 0-全部用户 1-分销商
|
||||
'show_earnings_scope' => ConfigServer::get('distribution', 'show_earnings_scope', 0),
|
||||
// 开通分销会员条件 1-无条件 2-申请分销(默认) 3-指定分销
|
||||
'apply_condition' => ConfigServer::get('distribution', 'apply_condition', 2),
|
||||
// 佣金计算方式 1-商品实际支付金额(默认)
|
||||
'cale_method' => ConfigServer::get('distribution', 'cale_method', 1),
|
||||
// 结算时机 1-订单完成后(默认)
|
||||
'settlement' => ConfigServer::get('distribution', 'settlement', 1),
|
||||
// 结算时机 订单完成后多少天内(默认7天)
|
||||
'settlement_days' => ConfigServer::get('distribution', 'settlement_days', 7),
|
||||
];
|
||||
return $config;
|
||||
}
|
||||
|
||||
public static function set($params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$allowFields = ['is_open', 'level', 'is_show_earnings', 'apply_condition', 'cale_method', 'settlement_days', 'show_earnings_scope'];
|
||||
foreach ($allowFields as $field) {
|
||||
if ($field == 'settlement_days' && isset($params[$field]) && $params[$field] < 0) {
|
||||
throw new \Exception('不允许填写负数');
|
||||
}
|
||||
if(isset($params[$field])) {
|
||||
ConfigServer::set('distribution', $field, $params[$field]);
|
||||
}
|
||||
if($field == 'apply_condition' && isset($params[$field]) && $params[$field] == 1) {
|
||||
// 开通分销会员无条件时,所有会员均成为分销会员
|
||||
self::distribution();
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function distribution()
|
||||
{
|
||||
// 将非分销会员变为分销会员
|
||||
Distribution::where('is_distribution', 0)->update([
|
||||
'is_distribution' => 1
|
||||
]);
|
||||
// 获取所有分销会员id
|
||||
$distributionIds = Distribution::distinct(true)->column('user_id');
|
||||
// 查找未生成分销会员基础信息表的会员
|
||||
$notDistributionIds = \app\common\model\User::where([
|
||||
['id', 'not in', $distributionIds],
|
||||
['del', '=', 0],
|
||||
])->column('id');
|
||||
foreach($notDistributionIds as $userId) {
|
||||
// 生成分销会员基础信息表
|
||||
DistributionLogic::add($userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\common\server\ConfigServer;
|
||||
|
||||
use app\common\server\UrlServer;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
|
||||
class ExpressLogic
|
||||
{
|
||||
/**
|
||||
* 列表
|
||||
* @param $get
|
||||
* @return array
|
||||
* @throws @\think\db\exception\DataNotFoundException
|
||||
* @throws @\think\db\exception\ModelNotFoundException
|
||||
* @throws @\think\exception\DbException
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
$where = [];
|
||||
$where[] = ['del', '=', '0'];
|
||||
|
||||
if (isset($get['express_name']) && $get['express_name'] != '') {
|
||||
$where[] = ['name', 'like', '%' . $get['express_name'] . '%'];
|
||||
}
|
||||
|
||||
$count = Db::name('express')
|
||||
->where($where)
|
||||
->count();
|
||||
|
||||
$lists = Db::name('express')
|
||||
->where($where)
|
||||
->page($get['page'], $get['limit'])
|
||||
->select();
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['icon'] = UrlServer::getFileUrl($item['icon']);
|
||||
}
|
||||
|
||||
return ['lists' => $lists, 'count' => $count];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取所有快递公司
|
||||
* @date 2021/9/26 10:40
|
||||
*/
|
||||
public static function all()
|
||||
{
|
||||
return Db::name('express')
|
||||
->where(['del'=>0])
|
||||
->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param $post
|
||||
* @return array|string|null
|
||||
*/
|
||||
public static function addExpress($post)
|
||||
{
|
||||
$time = time();
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'icon' => $post['icon'],
|
||||
'website' => $post['website'],
|
||||
'code' => $post['code'],
|
||||
'code100' => $post['code100'],
|
||||
'codebird' => $post['codebird'],
|
||||
'sort' => $post['sort'],
|
||||
'create_time' => $time
|
||||
];
|
||||
$result = Db::name('express')->insert($data);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取信息
|
||||
* @param $id
|
||||
* @return array|string|null
|
||||
* @throws @\think\db\exception\DataNotFoundException
|
||||
* @throws @\think\db\exception\ModelNotFoundException
|
||||
* @throws @\think\exception\DbException
|
||||
*/
|
||||
public static function info($id)
|
||||
{
|
||||
$detail = Db::name('express')->where(['id' => $id, 'del' => 0])->find();
|
||||
$detail['abs_icon'] = UrlServer::getFileUrl($detail['icon']);
|
||||
return $detail;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param $post
|
||||
* @return int|string
|
||||
* @throws Exception
|
||||
* @throws @\think\exception\PDOException
|
||||
*/
|
||||
public static function editExpress($post)
|
||||
{
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'icon' => $post['icon'],
|
||||
'website' => $post['website'],
|
||||
'code' => $post['code'],
|
||||
'code100' => $post['code100'],
|
||||
'codebird' => $post['codebird'],
|
||||
'sort' => $post['sort'],
|
||||
'update_time' => time()
|
||||
];
|
||||
Db::name('express')->where(['id' => $post['id']])->update(['name' => $post['name'],]);
|
||||
$result = Db::name('express')->where(['id' => $post['id']])->update($data);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param $delData
|
||||
* @return int|string
|
||||
* @throws Exception
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function delExpress($delData)
|
||||
{
|
||||
$data = [
|
||||
'del' => 1,
|
||||
'update_time' => time(),
|
||||
];
|
||||
return Db::name('express')->where(['del' => 0, 'id' => $delData])->update($data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static function getExpress()
|
||||
{
|
||||
$config = [
|
||||
'way' => ConfigServer::get('express', 'way', 'kd100'),
|
||||
'kd100_appkey' => ConfigServer::get('kd100', 'appkey', ''),
|
||||
'kd100_customer' => ConfigServer::get('kd100', 'appsecret', ''),
|
||||
'kdniao_appkey' => ConfigServer::get('kdniao', 'appkey', ''),
|
||||
'kdniao_ebussinessid' => ConfigServer::get('kdniao', 'appsecret', ''),
|
||||
'kdniao_type' => ConfigServer::get('kdniao', 'type', 'free'),
|
||||
];
|
||||
return $config;
|
||||
}
|
||||
|
||||
//快递100
|
||||
public static function kd100(){
|
||||
$config = [
|
||||
'appkey' => ConfigServer::get('kd100', 'appkey', ''),
|
||||
'appsecret' => ConfigServer::get('kd100', 'appsecret', ''),
|
||||
|
||||
];
|
||||
return $config;
|
||||
}
|
||||
//快递鸟
|
||||
public static function kdniao(){
|
||||
$res=[
|
||||
'appkey2' => ConfigServer::get('kdniao', 'appkey', ''),
|
||||
'appsecret2' => ConfigServer::get('kdniao', 'appsecret', ''),
|
||||
];
|
||||
return $res;
|
||||
}
|
||||
//快递方式
|
||||
public static function way(){
|
||||
$way = ConfigServer::get('express', 'way', '');
|
||||
return $way;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,保留版权即可
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | 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\admin\logic;
|
||||
|
||||
|
||||
use app\common\model\FaceSheetTemplate;
|
||||
use Exception;
|
||||
use think\Db;
|
||||
|
||||
class FaceSheetLogic
|
||||
{
|
||||
/**
|
||||
* @notes 获取电子面单模板列表
|
||||
* @param $get
|
||||
* @return array
|
||||
* @author 张无忌
|
||||
* @date 2021/9/26 11:46
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
$model = new FaceSheetTemplate();
|
||||
$count = $model->count('id');
|
||||
$lists = $model->order('id', 'desc')
|
||||
->page($get['page'], $get['limit'])
|
||||
->select();
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
|
||||
$item['express'] = Db::name('express')->where(['id'=>$item['express_id']])->value('name') ?? '未知';
|
||||
}
|
||||
|
||||
return ['count' => $count, 'lists' => $lists];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 所有电子面单模板
|
||||
* @author 张无忌
|
||||
* @date 2021/9/27 15:40
|
||||
*/
|
||||
public static function all()
|
||||
{
|
||||
$model = new FaceSheetTemplate();
|
||||
return $model->order('id', 'desc')->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取电子面单模板详细
|
||||
* @param $id
|
||||
* @return FaceSheetTemplate
|
||||
* @author 张无忌
|
||||
* @date 2021/9/26 11:51
|
||||
*/
|
||||
public static function detail($id)
|
||||
{
|
||||
return FaceSheetTemplate::where(['id'=>intval($id)])->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 新增电子面单模板
|
||||
* @param $post
|
||||
* @return bool|string
|
||||
* @author 张无忌
|
||||
* @date 2021/9/26 11:12
|
||||
*/
|
||||
public static function add($post)
|
||||
{
|
||||
try {
|
||||
FaceSheetTemplate::create([
|
||||
'express_id' => $post['express_id'],
|
||||
'name' => $post['name'],
|
||||
'tempid' => $post['tempid'],
|
||||
'partner_id' => $post['partner_id'],
|
||||
'partner_key' => $post['partner_key'],
|
||||
'net' => $post['net'],
|
||||
'pay_type' => $post['pay_type'],
|
||||
'create_time' => time(),
|
||||
'update_time' => time()
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 编辑电子面单模板
|
||||
* @param $post
|
||||
* @return bool|string
|
||||
* @author 张无忌
|
||||
* @date 2021/9/26 11:49
|
||||
*/
|
||||
public static function edit($post)
|
||||
{
|
||||
try {
|
||||
FaceSheetTemplate::update([
|
||||
'express_id' => $post['express_id'],
|
||||
'name' => $post['name'],
|
||||
'tempid' => $post['tempid'],
|
||||
'partner_id' => $post['partner_id'],
|
||||
'partner_key' => $post['partner_key'],
|
||||
'net' => $post['net'],
|
||||
'pay_type' => $post['pay_type'],
|
||||
'create_time' => time(),
|
||||
'update_time' => time()
|
||||
], ['id'=>$post['id']]);
|
||||
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 删除电子面单模板
|
||||
* @param $id
|
||||
* @return string
|
||||
* @author 张无忌
|
||||
* @date 2021/9/28 15:38
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
try {
|
||||
FaceSheetTemplate::destroy(intval($id));
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,308 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,保留版权即可
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | 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\admin\logic;
|
||||
|
||||
|
||||
use app\common\logic\OrderLogLogic;
|
||||
use app\common\model\NoticeSetting;
|
||||
use app\common\model\Order;
|
||||
use app\common\model\OrderGoods;
|
||||
use app\common\model\OrderLog;
|
||||
use app\common\model\TeamFound;
|
||||
use app\common\model\User;
|
||||
use app\common\model\FaceSheetSender;
|
||||
use app\common\model\FaceSheetTemplate;
|
||||
use app\common\model\Express;
|
||||
use app\common\server\AreaServer;
|
||||
use app\common\server\printing\Kuaidi100;
|
||||
use app\common\server\UrlServer;
|
||||
use Exception;
|
||||
use think\Db;
|
||||
use think\facade\Hook;
|
||||
|
||||
class FaceSheetOrderLogic
|
||||
{
|
||||
/**
|
||||
* @notes 获取待发货订单列表
|
||||
* @param $get
|
||||
* @return array
|
||||
* @author 张无忌
|
||||
* @date 2021/9/27 11:53
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
$where = [
|
||||
['O.order_status', '=', 1],
|
||||
['O.pay_status', '=', 1],
|
||||
['O.delivery_type', '=', 1],
|
||||
// ['TF.status', '=', 0]
|
||||
];
|
||||
|
||||
if (!empty($get['keyword_type']) and !empty($get['keyword'])) {
|
||||
switch ($get['keyword_type']) {
|
||||
case 'order_sn':
|
||||
$where[] = ['O.order_sn', '=', $get['keyword']];
|
||||
break;
|
||||
case 'user_sn':
|
||||
$where[] = ['U.sn', 'like', '%'.$get['keyword'].'%'];
|
||||
break;
|
||||
case 'nickname':
|
||||
$where[] = ['U.nickname', 'like', '%'.$get['keyword'].'%'];
|
||||
break;
|
||||
case 'consignee':
|
||||
$where[] = ['O.consignee', 'like', '%'.$get['keyword'].'%'];
|
||||
break;
|
||||
case 'consignee_mobile':
|
||||
$where[] = ['O.consignee_mobile', '=', $get['keyword']];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($get['goods_name']) and $get['goods_name']) {
|
||||
$where[] = ['OG.goods_name', 'like', '%'.$get['goods_name'].'%'];
|
||||
}
|
||||
|
||||
if (!empty($get['start_time']) and $get['start_time']) {
|
||||
$where[] = ['O.create_time', '>=', strtotime($get['start_time'])];
|
||||
}
|
||||
|
||||
if (!empty($get['end_time']) and $get['end_time']) {
|
||||
$where[] = ['O.create_time', '<=', strtotime($get['end_time'])];
|
||||
}
|
||||
|
||||
$count = Order::where($where)->alias('O')
|
||||
->join('user U', 'U.id = O.user_id')
|
||||
->join('orderGoods OG', 'OG.order_id = O.id')
|
||||
->leftJoin('team_found TF', 'TF.id = O.team_found_id')
|
||||
->group('O.id')
|
||||
->count('O.id');
|
||||
|
||||
$lists = Order::field(
|
||||
'O.id,O.user_id,O.order_type,O.order_sn,O.order_status,O.total_num,O.order_amount,O.delivery_type,
|
||||
O.consignee,O.mobile,O.province,O.city,O.district,O.address,O.create_time,TF.status as team_found_status'
|
||||
)->alias('O')
|
||||
->where($where)
|
||||
->join('user U', 'U.id = O.user_id')
|
||||
->join('orderGoods OG', 'OG.order_id = O.id')
|
||||
->leftJoin('team_found TF', 'TF.id = O.team_found_id')
|
||||
->group('O.id')
|
||||
->order('O.id desc')
|
||||
->page($get['page'], $get['limit'])
|
||||
->select();
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$user = User::field('nickname,sn')->where(['id'=>$item['user_id']])->find();
|
||||
$item['user'] = $user['nickname'];
|
||||
|
||||
// $item['team_found_status'] = $item['team_found_status'] ? 1 : 0;
|
||||
|
||||
$item['order_type'] = Order::getOrderType($item['order_type']);
|
||||
$item['order_status'] = Order::getOrderStatus($item['order_status']);
|
||||
$item['delivery_type'] = Order::getDeliveryType($item['delivery_type']);
|
||||
$item['address'] = AreaServer::getAddress([$item['province'], $item['city'], $item['district']], $item['address']);
|
||||
|
||||
$orderGoods = OrderGoods::field('id,goods_price,goods_num,goods_info')->where(['order_id'=>$item['id']])->select();
|
||||
$orderGoodsData = [];
|
||||
foreach ($orderGoods as $og) {
|
||||
$info = json_decode($og['goods_info'], true);
|
||||
$orderGoodsData[] = [
|
||||
'id' => $og['id'],
|
||||
'goods_price' => $og['goods_price'],
|
||||
'goods_num' => $og['goods_num'],
|
||||
'goods_name' => $info['goods_name'],
|
||||
'spec_value_str' => $info['spec_value_str'],
|
||||
'image' => $info['spec_image'] ? UrlServer::getFileUrl($info['spec_image']) : UrlServer::getFileUrl($info['image']),
|
||||
];
|
||||
}
|
||||
$item['orderGoods'] = $orderGoodsData;
|
||||
}
|
||||
|
||||
return ['count'=>$count, 'lists'=>$lists];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 打印电子面单
|
||||
* @param $order_id
|
||||
* @param $tempid
|
||||
* @param $sender_id
|
||||
* @param $admin_id
|
||||
* @return string
|
||||
* @author 张无忌
|
||||
* @date 2021/9/27 11:54
|
||||
*/
|
||||
public static function print($order_id, $tempid, $sender_id, $admin_id)
|
||||
{
|
||||
try {
|
||||
// 查询出订单信息
|
||||
$order = Order::field(true)->with(['orderGoods'])->where(['id' => intval($order_id)])->find();
|
||||
|
||||
if (!$order) {
|
||||
throw new Exception('订单不存在');
|
||||
}
|
||||
|
||||
if ($order['order_status'] != 1) {
|
||||
throw new Exception('该订单不是待发货状态的订单');
|
||||
}
|
||||
|
||||
if ($order['pay_status'] == 0) {
|
||||
throw new Exception('该订单未支付');
|
||||
}
|
||||
|
||||
if ($order['pay_status'] == 2) {
|
||||
throw new Exception('该订单已退款');
|
||||
}
|
||||
|
||||
// 拼团订单(未成功的订单)
|
||||
if ($order['order_type'] == 2) {
|
||||
$found = TeamFound::where(['id'=>$order['team_found_id']])->find();
|
||||
if ($found['status'] != 1) {
|
||||
throw new Exception('拼团未成功禁止打印:'.$order['order_sn']);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取发件人模板
|
||||
$sender = FaceSheetSender::where(['id'=>intval($sender_id)])->find();
|
||||
if (!$sender) {
|
||||
throw new Exception('未找到发件人模板信息');
|
||||
}
|
||||
|
||||
// 获取电子面单模板
|
||||
$template = FaceSheetTemplate::where(['id'=>intval($tempid)])->find();
|
||||
if (!$template) {
|
||||
throw new Exception('未找到电子面单模板信息');
|
||||
}
|
||||
|
||||
// 获取快递公司
|
||||
$express = Express::field('id,name,code100')->where(['id'=>$template['express_id']])->find();
|
||||
if (!$template) {
|
||||
throw new Exception('未找到快递公司信息');
|
||||
}
|
||||
|
||||
$goodsName = '';
|
||||
$totalWeight = 0;
|
||||
foreach ($order['order_goods'] as $item) {
|
||||
|
||||
$goodsInfo = json_decode($item['goods_info'], true);
|
||||
$goodsName .= $goodsInfo['goods_name'].' ('.$goodsInfo['spec_value_str'].$item['goods_num'].'件)\n';
|
||||
$totalWeight = round($goodsInfo['weight']+$totalWeight,2);
|
||||
}
|
||||
// 打印电子面单
|
||||
$result = (new Kuaidi100())->print([
|
||||
'remark' => $goodsName ?? '',
|
||||
'template' => [
|
||||
'partnerId' => $template['partner_id'],
|
||||
'partnerKey' => $template['partner_key'],
|
||||
'payType' => $template['pay_type'],
|
||||
'net' => $template['net'],
|
||||
'tempid' => $template['tempid'],
|
||||
'expressName' => $express['name'],
|
||||
'expressCode' => $express['code100'],
|
||||
],
|
||||
'total_weight' => $totalWeight,
|
||||
'recMan' => [
|
||||
'name' => trim($order['consignee']),
|
||||
'mobile' => trim($order['mobile']),
|
||||
'printAddr' => AreaServer::getAddress([$order['province'], $order['city'], $order['district']], $order['address'])
|
||||
],
|
||||
'sendMan' => array(
|
||||
'name' => $sender['name'],
|
||||
'mobile' => $sender['mobile'],
|
||||
'printAddr' => AreaServer::getAddress([$sender['province_id'], $sender['city_id'], $sender['district_id']], $sender['address']),
|
||||
)
|
||||
]);
|
||||
|
||||
// 更新信息状态为已发货
|
||||
$delivery_id = Db::name('delivery')->insertGetId([
|
||||
'order_id' => $order['id'],
|
||||
'order_sn' => $order['order_sn'],
|
||||
'user_id' => $order['user_id'],
|
||||
'admin_id' => $admin_id,
|
||||
'consignee' => $order['consignee'],
|
||||
'mobile' => $order['mobile'],
|
||||
'province' => $order['province'],
|
||||
'city' => $order['city'],
|
||||
'district' => $order['district'],
|
||||
'address' => $order['address'],
|
||||
'shipping_status' => 1,
|
||||
'shipping_id' => $express['id'],
|
||||
'shipping_name' => $express['name'],
|
||||
'send_type' => 1,
|
||||
'invoice_no' => $result['data']['kuaidinum'],
|
||||
'create_time' => time()
|
||||
]);
|
||||
|
||||
Order::update([
|
||||
'order_status' => 2,
|
||||
'shipping_status' => 1,
|
||||
'delivery_id' => $delivery_id,
|
||||
'shipping_time' => time(),
|
||||
'update_time' => time(),
|
||||
], ['id'=>$order['id']]);
|
||||
|
||||
//订单日志
|
||||
OrderLogLogic::record(
|
||||
OrderLog::TYPE_SHOP,
|
||||
OrderLog::SHOP_DELIVERY_ORDER,
|
||||
$order_id,
|
||||
$admin_id,
|
||||
OrderLog::SHOP_DELIVERY_ORDER
|
||||
);
|
||||
|
||||
//发货短信通知
|
||||
if($order['mobile']){
|
||||
$nickname = Db::name('user')->where(['id' => $order['user_id']])->value('nickname');
|
||||
$send_data = [
|
||||
'key' => NoticeSetting::ORDER_DELIVERY_NOTICE,
|
||||
'user_id' => $order['user_id'],
|
||||
'mobile' => $order['mobile'],
|
||||
'params' => [
|
||||
'order_sn' => $order['order_sn'],
|
||||
'nickname' => $nickname,
|
||||
'time' => date('Y-m-d H:i:s'),
|
||||
'invoice_no' => $result['data']['kuaidinum'],
|
||||
'shipping_name' => $express['name'],
|
||||
'goods_name' => omit_str($order['order_goods'][0]['goods_name'] ?? '商品', 8)
|
||||
],
|
||||
];
|
||||
Hook::listen('sms_send', $send_data);
|
||||
}
|
||||
|
||||
// 赠送成长值和积分
|
||||
Hook::listen('give_reward', [
|
||||
'order_id' => $order['id'],
|
||||
'scene' => 2, //2=发货场景
|
||||
]);
|
||||
|
||||
// 发货模板消息
|
||||
Hook::listen('notice', [
|
||||
'user_id' => $order['user_id'],
|
||||
'order_id' => $order['id'],
|
||||
'scene' => NoticeSetting::ORDER_DELIVERY_NOTICE,
|
||||
'shipping_name' => $express['name'],
|
||||
'invoice_no' => $result['data']['kuaidinum'],
|
||||
'time' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,保留版权即可
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | 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\admin\logic;
|
||||
|
||||
|
||||
use app\common\model\FaceSheetSender;
|
||||
use app\common\server\AreaServer;
|
||||
use Exception;
|
||||
|
||||
class FaceSheetSenderLogic
|
||||
{
|
||||
/**
|
||||
* @notes 获取发件人列表
|
||||
* @param $get
|
||||
* @return array
|
||||
* @author 张无忌
|
||||
* @date 2021/9/26 15:49
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
$model = new FaceSheetSender();
|
||||
$count = $model->count('id');
|
||||
$lists = $model->order('id', 'desc')
|
||||
->page($get['page'], $get['limit'])
|
||||
->select();
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
|
||||
$item['region'] = AreaServer::getAddress([
|
||||
$item['province_id'],
|
||||
$item['city_id'],
|
||||
$item['district_id'],
|
||||
]);
|
||||
}
|
||||
|
||||
return ['count' => $count, 'lists' => $lists];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 所有发件人模板
|
||||
* @author 张无忌
|
||||
* @date 2021/9/27 15:40
|
||||
*/
|
||||
public static function all()
|
||||
{
|
||||
$model = new FaceSheetSender();
|
||||
return $model->order('id', 'desc')->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取发件人模板详细
|
||||
* @param $id
|
||||
* @return FaceSheetSender
|
||||
* @author 张无忌
|
||||
* @date 2021/9/26 15:51
|
||||
*/
|
||||
public static function detail($id)
|
||||
{
|
||||
return FaceSheetSender::where(['id'=>$id])->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 新增发件人模板
|
||||
* @param $post
|
||||
* @return bool|string
|
||||
* @author 张无忌
|
||||
* @date 2021/9/26 15:18
|
||||
*/
|
||||
public static function add($post)
|
||||
{
|
||||
try {
|
||||
FaceSheetSender::create([
|
||||
'name' => $post['name'],
|
||||
'mobile' => $post['mobile'],
|
||||
'province_id' => $post['province_id'],
|
||||
'city_id' => $post['city_id'],
|
||||
'district_id' => $post['district_id'],
|
||||
'address' => $post['address'],
|
||||
'create_time' => time(),
|
||||
'update_time' => time(),
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 编辑发件人模板
|
||||
* @param $post
|
||||
* @return bool|string
|
||||
* @author 张无忌
|
||||
* @date 2021/9/26 15:23
|
||||
*/
|
||||
public static function edit($post)
|
||||
{
|
||||
try {
|
||||
FaceSheetSender::update([
|
||||
'name' => $post['name'],
|
||||
'mobile' => $post['mobile'],
|
||||
'province_id' => $post['province_id'],
|
||||
'city_id' => $post['city_id'],
|
||||
'district_id' => $post['district_id'],
|
||||
'address' => $post['address'],
|
||||
'update_time' => time(),
|
||||
], ['id'=>$post['id']]);
|
||||
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 删除发件人模板
|
||||
* @param $id
|
||||
* @return bool|string
|
||||
* @author 张无忌
|
||||
* @date 2021/9/26 15:45
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
try {
|
||||
FaceSheetSender::destroy($id);
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\common\model\FileCate;
|
||||
use app\common\server\UrlServer;
|
||||
use think\Db;
|
||||
|
||||
class FileNewLogic
|
||||
{
|
||||
public static function lists($get)
|
||||
{
|
||||
$field = 'id,name,uri';
|
||||
$where = [
|
||||
'del' => 0,
|
||||
'partner_id' => $get['partner_id'],
|
||||
'type' => FileCate::getTypeNumber($get['type']),
|
||||
'cate_id' => $get['cate_id']
|
||||
];
|
||||
$lists = Db::name('file')->field($field)->where($where)->page($get['page_no'], $get['page_size'])->select();
|
||||
$count = Db::name('file')->where($where)->count();
|
||||
foreach($lists as &$item) {
|
||||
$item['uri'] = UrlServer::getFileUrl($item['uri']);
|
||||
}
|
||||
return ['lists'=>$lists, 'count'=>$count];
|
||||
}
|
||||
|
||||
public static function pagelists($get)
|
||||
{
|
||||
$field = 'id,name,uri';
|
||||
$where = [
|
||||
['del', '=', 0],
|
||||
['partner_id', '=', $get['partner_id']],
|
||||
['type', '=', FileCate::getTypeNumber($get['type'])]
|
||||
];
|
||||
if($get['cate_id']) {
|
||||
// 查找子分类,属于当前分类或当前分类下的子分类的文件都显示出来
|
||||
$child = self::getChildren($get['cate_id']);
|
||||
$child[] = intval($get['cate_id']);
|
||||
$where[] = ['cate_id', 'in', $child];
|
||||
}
|
||||
$lists = Db::name('file')->field($field)->where($where)->page($get['page_no'], $get['page_size'])->select();
|
||||
$count = Db::name('file')->where($where)->count();
|
||||
foreach($lists as &$item) {
|
||||
$item['uri'] = UrlServer::getFileUrl($item['uri']);
|
||||
}
|
||||
return ['lists'=>$lists, 'count'=>$count, 'page_no'=>$get['page_no'], 'page_size'=>$get['page_size']];
|
||||
}
|
||||
|
||||
public static function addCate($post)
|
||||
{
|
||||
// 同级别不允许有同名分类
|
||||
$fileCate = FileCate::where([
|
||||
'del' => 0,
|
||||
'name' => $post['name'],
|
||||
'pid' => $post['pid']
|
||||
])->select()->toArray();
|
||||
if($fileCate) {
|
||||
return ['flag'=>false, 'msg'=>'同级别下已存在同名分类'];
|
||||
}
|
||||
// 分类不允许超过3级
|
||||
if(!empty($post['pid'])) {
|
||||
$level = FileCate::where(['id'=>$post['pid']])->value('level');
|
||||
if($level > 2) {
|
||||
return ['flag'=>false, 'msg'=>'分类不允许超过3级'];
|
||||
}
|
||||
$level = $level + 1;
|
||||
}else{
|
||||
$post['pid'] = 0;
|
||||
$level = 1;
|
||||
}
|
||||
switch($post['type']) {
|
||||
case 'video':
|
||||
$post['type'] = 2;
|
||||
break;
|
||||
}
|
||||
$post['level'] = $level;
|
||||
$post['create_time'] = time();
|
||||
$result = FileCate::create($post);
|
||||
if($result) {
|
||||
return ['flag'=>true, 'msg'=>'添加成功'];
|
||||
}else{
|
||||
return ['flag'=>false, 'msg'=>'添加失败'];
|
||||
}
|
||||
}
|
||||
|
||||
public static function editCate($post)
|
||||
{
|
||||
if(empty($post['pid'])) {
|
||||
$post['pid'] = 0;
|
||||
$pidLevel = 1;
|
||||
}
|
||||
// 同级分类下不允许重名
|
||||
$pidChildren = FileCate::where([
|
||||
['pid', '=', $post['pid']],
|
||||
['del', '=', 0],
|
||||
['id', '<>', $post['id']],
|
||||
['name', '=', $post['name']]
|
||||
])->select()->toArray();
|
||||
if($pidChildren) {
|
||||
return ['flag'=>false, 'msg'=>'同级下已存在该名称的分类'];
|
||||
}
|
||||
// 上级不能是自身或自己的子分类
|
||||
$children = self::getChildren($post['id']);
|
||||
if($post['pid'] == $post['id'] || in_array($post['pid'], $children)) {
|
||||
return ['flag'=>false, 'msg'=>'上级分类不能为自身或自己的子分类'];
|
||||
}
|
||||
// 分类层级不能超过3级
|
||||
$level = self::calcLevel($post['id']);
|
||||
$pidLevel = FileCate::where('id', $post['pid'])->value('level');
|
||||
if($level + $pidLevel > 3) {
|
||||
return ['flag'=>false, 'msg'=>'分类层级不允许超过3级'];
|
||||
}
|
||||
FileCate::where('id', $post['id'])->update([
|
||||
'name'=>trim($post['name']),
|
||||
'sort' => $post['sort'],
|
||||
'pid' => $post['pid'],
|
||||
'update_time' => time()
|
||||
]);
|
||||
self::updateLevel($post['id']);
|
||||
|
||||
return ['flag'=>true, 'msg'=>'编辑成功'];
|
||||
}
|
||||
|
||||
public static function delCate($post)
|
||||
{
|
||||
// 分类下还有子分类不允许删除
|
||||
$children = FileCate::where([
|
||||
'del' => 0,
|
||||
'pid' => $post['id']
|
||||
])->select()->toArray();
|
||||
if($children) {
|
||||
return ['flag'=>false, 'msg'=>'该分类下还有子分类不允许删除'];
|
||||
}
|
||||
// 有文件正在使用该分类不允许删除
|
||||
$files = Db::name('file')->where(['del'=>0, 'cate_id'=>$post['id']])->select();
|
||||
if($files) {
|
||||
return ['flag'=>false, 'msg'=>'有文件正在使用该分类不允许删除'];
|
||||
}
|
||||
FileCate::where(['id'=>$post['id']])->update(['del'=>1, 'update_time'=>time()]);
|
||||
return ['flag'=>true, 'msg'=>'删除成功'];
|
||||
}
|
||||
|
||||
public static function getChildren($id)
|
||||
{
|
||||
$child = [];
|
||||
$firstChild = FileCate::where(['del'=>0, 'pid'=>$id])->column('id');
|
||||
$child = $firstChild;
|
||||
foreach($firstChild as $firstId) {
|
||||
$secordChild = FileCate::where(['del'=>0, 'pid'=>$firstId])->column('id');
|
||||
$child = array_merge($child, $secordChild);
|
||||
}
|
||||
return $child;
|
||||
}
|
||||
|
||||
public static function calcLevel($id)
|
||||
{
|
||||
$level = 1;
|
||||
$two_ids = FileCate::where(['pid' => $id, 'del' => 0])->column('id');
|
||||
if ($two_ids) {
|
||||
$level = 2;
|
||||
$three_ids = FileCate::where([
|
||||
['del', '=', 0],
|
||||
['pid', 'in', $two_ids]
|
||||
])->column('id');
|
||||
if ($three_ids) $level = 3;
|
||||
}
|
||||
return $level;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新自己及后代分类的level
|
||||
*/
|
||||
public static function updateLevel($id)
|
||||
{
|
||||
$me = FileCate::find($id);
|
||||
if($me['pid'] == 0) { // 上级为顶级分类
|
||||
FileCate::update([
|
||||
'id' => $id,
|
||||
'level' => 1,
|
||||
'update_time' => time()
|
||||
]);
|
||||
$two_ids = FileCate::where([
|
||||
'pid' => $id,
|
||||
'del' => 0
|
||||
])->column('id');
|
||||
if($two_ids) {
|
||||
FileCate::where('id', 'in', $two_ids)->update([
|
||||
'level' => 2,
|
||||
'update_time' => time()
|
||||
]);
|
||||
$three_ids = FileCate::where([
|
||||
['pid', 'in', $two_ids],
|
||||
['del', '=', 0]
|
||||
])->column('id');
|
||||
if($three_ids) {
|
||||
FileCate::where('id', 'in', $three_ids)->update([
|
||||
'level' => 3,
|
||||
'update_time' => time()
|
||||
]);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$parent = FileCate::find($me['pid']);
|
||||
if($parent['level'] == 1) {
|
||||
FileCate::update([
|
||||
'id' => $id,
|
||||
'level' => 2,
|
||||
'update_time' => time()
|
||||
]);
|
||||
$three_ids = FileCate::where([
|
||||
'pid' => $id,
|
||||
'del' => 0
|
||||
])->column('id');
|
||||
if($three_ids) {
|
||||
FileCate::where('id', 'in', $three_ids)->update([
|
||||
'level' => 3,
|
||||
'update_time' => time()
|
||||
]);
|
||||
}
|
||||
}else if($parent['level'] == 2){
|
||||
FileCate::update([
|
||||
'id' => $id,
|
||||
'level' => 3,
|
||||
'update_time' => time()
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static function delFile($post)
|
||||
{
|
||||
try{
|
||||
$result = Db::name('file')->where('id', 'in', $post['ids'])->update([
|
||||
'del' => 1
|
||||
]);
|
||||
return true;
|
||||
}catch(\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\common\model\DistributionOrder;
|
||||
use app\common\model\OrderGoods;
|
||||
use app\common\model\Pay;
|
||||
use app\common\model\Withdraw;
|
||||
use think\Db;
|
||||
|
||||
class FinanceLogic
|
||||
{
|
||||
public static function lists()
|
||||
{
|
||||
//本月订单金额
|
||||
$month_order_amount = Db::name('order')
|
||||
->where(['pay_status' => Pay::ISPAID, 'refund_status' => OrderGoods::REFUND_STATUS_NO])
|
||||
->whereTime('create_time', 'month')
|
||||
->sum('order_amount');
|
||||
|
||||
//订单总金额
|
||||
$order = Db::name('order')
|
||||
->field('sum(order_amount) as amount, count(id) as num')
|
||||
->where('pay_status' , 'in', [Pay::ISPAID, Pay::REFUNDED])
|
||||
->find();
|
||||
|
||||
//退款订单
|
||||
$refund_order = Db::name('order_refund')
|
||||
->field('sum(refund_amount) as amount, count(id) as num')
|
||||
->where(['refund_status' => 1])
|
||||
->find();
|
||||
|
||||
//会员相关
|
||||
$user = Db::name('user')
|
||||
->field('sum(user_money) as money, sum(user_integral) as integral, sum(earnings) as earnings')
|
||||
->where(['del' => 0])
|
||||
->find();
|
||||
|
||||
//已提现佣金
|
||||
$have_withdraw_earnings = Db::name('withdraw_apply')
|
||||
->where(['status' => Withdraw::STATUS_SUCCESS])
|
||||
->sum('money');
|
||||
|
||||
//提现中
|
||||
$wait_withdraw_earnings = Db::name('withdraw_apply')
|
||||
->where(['status' => Withdraw::STATUS_ING])
|
||||
->sum('money');
|
||||
|
||||
|
||||
//本月分销佣金金额
|
||||
$month_earnings = Db::name('distribution_order_goods')
|
||||
->where('status', '<>', DistributionOrder::STATUS_ERROR)
|
||||
->whereTime('create_time', 'month')
|
||||
->sum('money');
|
||||
|
||||
//分销佣金总佣金
|
||||
$distribution_earnings = Db::name('distribution_order_goods')
|
||||
->where('status', '<>', DistributionOrder::STATUS_ERROR)
|
||||
->sum('money');
|
||||
|
||||
return [
|
||||
'month_order_amount' => round($month_order_amount, 2),
|
||||
'total_amount' => round($order['amount'], 2),
|
||||
'order_num' => $order['num'] ?? 0,
|
||||
'refund_amount' => round($refund_order['amount'], 2),
|
||||
'refund_num' => $refund_order['num'] ?? 0,
|
||||
|
||||
'total_user_money' => round($user['money'], 2),
|
||||
'total_user_integral' => $user['integral'] ?? 0,
|
||||
'able_earnings' => round($user['earnings'], 2),
|
||||
'have_withdraw_earnings' => round($have_withdraw_earnings, 2),
|
||||
|
||||
'month_earnings' => round($month_earnings, 2),
|
||||
'distribution_earnings' => round($distribution_earnings, 2),
|
||||
'wait_earnings' => round($wait_withdraw_earnings, 2),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
use app\common\model\Footprint;
|
||||
use app\common\server\ConfigServer;
|
||||
|
||||
class FootprintLogic
|
||||
{
|
||||
// 列表
|
||||
public static function lists()
|
||||
{
|
||||
$footprintModel = new Footprint();
|
||||
return $footprintModel->select();
|
||||
}
|
||||
|
||||
// 获取详情
|
||||
public static function info($id)
|
||||
{
|
||||
$footprintModel = new Footprint();
|
||||
return $footprintModel->where(['id'=>(int)$id])->find();
|
||||
}
|
||||
|
||||
public static function edit($post)
|
||||
{
|
||||
try {
|
||||
$footprintModel = new Footprint();
|
||||
$footprintModel->where(['id' => (int)$post['id']])
|
||||
->update(['status' => $post['status']]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function set($post)
|
||||
{
|
||||
try {
|
||||
ConfigServer::set('footprint', 'footprint_duration', $post['duration']);
|
||||
ConfigServer::set('footprint', 'footprint_status', $post['status']);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\common\model\Freight;
|
||||
use app\common\model\FreightConfig;
|
||||
use app\common\server\UrlServer;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
|
||||
class FreightLogic
|
||||
{
|
||||
|
||||
public static function lists($get)
|
||||
{
|
||||
$freight = new Freight();
|
||||
$where = [];
|
||||
|
||||
if (isset($get['name']) && $get['name'] != '') {
|
||||
$where[] = ['name', 'like', '%' . $get['name'] . '%'];
|
||||
}
|
||||
|
||||
if (isset($get['charge_way']) && $get['charge_way'] != '') {
|
||||
$where[] = ['charge_way', '=', $get['charge_way']];
|
||||
}
|
||||
|
||||
$count = $freight->where($where)->count();
|
||||
$list = $freight
|
||||
->where($where)
|
||||
->page($get['page'], $get['limit'])
|
||||
->append(['charge_way_text'])
|
||||
->order('id desc')
|
||||
->select();
|
||||
|
||||
if (!$list) {
|
||||
return ['count' => '', 'lists' => []];
|
||||
}
|
||||
|
||||
return ['count' => $count, 'lists' => $list];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static function add($post)
|
||||
{
|
||||
$freight = new Freight();
|
||||
$freight->name = $post['name'];
|
||||
$freight->charge_way = $post['charge_way'];
|
||||
$freight->remark = $post['remark'];
|
||||
$freight->allowField(true)->save();
|
||||
|
||||
$freight_config = new FreightConfig();
|
||||
|
||||
$config_data = [];
|
||||
foreach ($post as &$item) {
|
||||
if (is_array($item)) {
|
||||
$item = array_values($item);
|
||||
}
|
||||
}
|
||||
|
||||
$post = form_to_linear($post);
|
||||
foreach ($post as $v) {
|
||||
$v['freight_id'] = $freight->id;
|
||||
$v['create_time'] = time();
|
||||
$config_data[] = $v;
|
||||
}
|
||||
$freight_config->allowField(true)->insertAll($config_data);
|
||||
}
|
||||
|
||||
|
||||
public static function edit($post)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$freight = Freight::where(['id' => $post['id']])
|
||||
->with('configs')
|
||||
->find();
|
||||
|
||||
//删除之前保存的配置,再增加
|
||||
FreightConfig::where(['freight_id' => $freight['id']])->delete();
|
||||
|
||||
$freight->save([
|
||||
'name' => $post['name'],
|
||||
'charge_way' => $post['charge_way'],
|
||||
'remark' => $post['remark'],
|
||||
], ['id' => $freight['id']]);
|
||||
|
||||
|
||||
$config_data = [];
|
||||
foreach ($post as &$item) {
|
||||
if (is_array($item)) {
|
||||
$item = array_values($item);
|
||||
}
|
||||
}
|
||||
|
||||
$post = form_to_linear($post);
|
||||
|
||||
foreach ($post as $v) {
|
||||
$v['freight_id'] = $freight->id;
|
||||
$config_data[] = $v;
|
||||
}
|
||||
|
||||
$freight_config = new FreightConfig();
|
||||
$freight_config->allowField(true)->insertAll($config_data);
|
||||
Db::commit();
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function del($post)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
Freight::where(['id' => $post['id']])->delete();
|
||||
FreightConfig::where(['freight_id' => $post['id']])->delete();
|
||||
Db::commit();
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function detail($id)
|
||||
{
|
||||
$freight = Freight::where(['id' => $id])
|
||||
->with('configs')
|
||||
->append(['charge_way_text'])
|
||||
->find()->toArray();
|
||||
|
||||
$regions = Db::name('dev_region')->column('name', 'id');
|
||||
|
||||
foreach ($freight['configs'] as &$item) {
|
||||
$item['region_name'] = '';
|
||||
|
||||
if ($item['region'] == 'all'){
|
||||
$item['region_name'] = '全国';
|
||||
continue;
|
||||
}
|
||||
|
||||
$region = explode(',', $item['region']);
|
||||
|
||||
foreach ($region as $v) {
|
||||
if (isset($regions[$v])) {
|
||||
$item['region_name'] .= $regions[$v] . ',';
|
||||
}
|
||||
}
|
||||
$item['region_name'] = rtrim($item['region_name'], ',');
|
||||
}
|
||||
return $freight;
|
||||
}
|
||||
|
||||
public static function areaTree()
|
||||
{
|
||||
$lists = Db::name('dev_region')
|
||||
->field('id,parent_id,level,name as title')
|
||||
->order('parent_id', 'desc')
|
||||
->select();
|
||||
|
||||
$result = self::areaSort($lists);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function areaSort(&$lists)
|
||||
{
|
||||
$tree = [];
|
||||
foreach ($lists as $k1 => $province) {
|
||||
if ($province['level'] == 1) {
|
||||
|
||||
//树形结构参数
|
||||
$province['checkArr']['type'] = 0;
|
||||
$province['checkArr']['checked'] = 0;
|
||||
$province['last'] = false;
|
||||
$province['parentId'] = -1;
|
||||
|
||||
//钓鱼岛这个没有下级
|
||||
if ($province['id'] == 900000) {
|
||||
$province['children'] = [];
|
||||
$province['last'] = true;
|
||||
}
|
||||
|
||||
$tree[$k1] = $province;
|
||||
unset($lists[$k1]);
|
||||
foreach ($lists as $k2 => $city) {
|
||||
$city['parentId'] = $city['parent_id'];
|
||||
if ($city['parentId'] == $province['id']) {
|
||||
foreach ($lists as $k3 => $district) {
|
||||
$district['parentId'] = $district['parent_id'];
|
||||
if ($district['parentId'] == $city['id']) {
|
||||
|
||||
//树形结构参数
|
||||
$district['checkArr']['type'] = 0;
|
||||
$district['checkArr']['checked'] = 0;
|
||||
$district['last'] = true;
|
||||
|
||||
$city['children'][] = $district;
|
||||
unset($lists[$k3]);
|
||||
}
|
||||
}
|
||||
|
||||
//树形结构参数
|
||||
$city['checkArr']['type'] = 0;
|
||||
$city['checkArr']['checked'] = 0;
|
||||
$city['last'] = false;
|
||||
|
||||
$tree[$k1]['children'][] = $city;
|
||||
unset($lists[$k2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return array_values($tree);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* note 获取全部运费模板
|
||||
*/
|
||||
public static function getFreightList()
|
||||
{
|
||||
return Db::name('freight')->field('id,name')->select();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
use app\common\server\UrlServer;
|
||||
use think\Db;
|
||||
use think\facade\Cache;
|
||||
|
||||
class GoodsBrandLogic
|
||||
{
|
||||
//列表
|
||||
public static function lists($get)
|
||||
{
|
||||
$where[] = ['del','=',0];
|
||||
|
||||
if(isset($get['name']) && $get['name']){
|
||||
$where[] = ['name','like','%'.$get['name'].'%'];
|
||||
}
|
||||
|
||||
$count = Db::name('goods_brand')
|
||||
->where($where)
|
||||
->count();
|
||||
$lists = Db::name('goods_brand')
|
||||
->where($where)
|
||||
->page($get['page'],$get['limit'])
|
||||
->order(['sort' => 'desc', 'id'=>'desc'])
|
||||
->select();
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['image'] = UrlServer::getFileUrl($item['image']);
|
||||
}
|
||||
|
||||
return ['count' => $count,'list' => $lists];
|
||||
}
|
||||
//添加
|
||||
public static function add($post)
|
||||
{
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'initial' => $post['initial'],
|
||||
'image' => $post['image'],
|
||||
'sort' => $post['sort'],
|
||||
'is_show' => $post['is_show'],
|
||||
'remark' => $post['remark'],
|
||||
'del' => 0,
|
||||
'create_time' => time()
|
||||
];
|
||||
Cache::rm('goods_category_1');
|
||||
Cache::rm('goods_category_2');
|
||||
return Db::name('goods_brand')->insert($data);
|
||||
}
|
||||
|
||||
//获取单个品牌
|
||||
public static function getGoodsBrand($id)
|
||||
{
|
||||
$detail = Db::name('goods_brand')->where(['id' => $id])->find();
|
||||
$detail['abs_image'] = UrlServer::getFileUrl($detail['image']);
|
||||
return $detail;
|
||||
|
||||
}
|
||||
|
||||
//编辑品牌
|
||||
public static function edit($post,$id)
|
||||
{
|
||||
$update_data = [
|
||||
'name' => $post['name'],
|
||||
'initial' => $post['initial'],
|
||||
'image' => $post['image'],
|
||||
'sort' => $post['sort'],
|
||||
'is_show' => $post['is_show'],
|
||||
'remark' => $post['remark'],
|
||||
'del' => 0,
|
||||
'update_time' => time()
|
||||
];
|
||||
Cache::rm('goods_category_1');
|
||||
Cache::rm('goods_category_2');
|
||||
return Db::name('goods_brand')->where(['id' => $id])->update($update_data);
|
||||
}
|
||||
|
||||
//删除品牌
|
||||
public static function del($id)
|
||||
{
|
||||
$update_data = [
|
||||
'del' => 1,
|
||||
'update_time' => time(),
|
||||
];
|
||||
Cache::rm('goods_category_1');
|
||||
Cache::rm('goods_category_2');
|
||||
return Db::name('goods_brand')->where(['del' => 0, 'id' => $id])->update($update_data);
|
||||
}
|
||||
//更新品牌状态
|
||||
public static function switchStatus($data)
|
||||
{
|
||||
$update_data = [
|
||||
'is_show' => $data['status'],
|
||||
'update_time' => time(),
|
||||
];
|
||||
Cache::rm('goods_category_1');
|
||||
Cache::rm('goods_category_2');
|
||||
return Db::name('goods_brand')->where(['del' =>0,'id' =>$data['id']])->update($update_data);
|
||||
}
|
||||
//获取品牌列表
|
||||
public static function getGoodsBrandList(){
|
||||
return Db::name('goods_brand')->where(['del'=>0])->field('id,name')->select();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,318 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\admin\logic;
|
||||
use app\common\server\UrlServer;
|
||||
use think\Db;
|
||||
use app\admin\model\GoodsCategory;
|
||||
use think\facade\Cache;
|
||||
|
||||
class GoodsCategoryLogic
|
||||
{
|
||||
/**
|
||||
* Desc: 添加商品分类
|
||||
* @param $post array 分类数据
|
||||
* @return boolean
|
||||
*/
|
||||
public static function add($post)
|
||||
{
|
||||
$level = 0;
|
||||
if ($post['pid']) {
|
||||
$level = Db::name('goods_category')->where(['id' => $post['pid']], ['del' => 0])->value('level');
|
||||
}
|
||||
$is_recommend = $post['is_recommend'] ?? 0;
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'pid' => $post['pid'],
|
||||
'sort' => $post['sort'],
|
||||
'is_show' => $post['is_show'],
|
||||
'image' => $post['image'],
|
||||
'level' => $level + 1,
|
||||
'is_recommend' => $post['pid'] == 0 ? $is_recommend : 0,
|
||||
'remark' => $post['remark'],
|
||||
'create_time' => time(),
|
||||
'update_time' => time(),
|
||||
];
|
||||
|
||||
Cache::rm('goods_category_1');
|
||||
Cache::rm('goods_category_2');
|
||||
return Db::name('goods_category')->insert($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc: 编辑商品分类
|
||||
* @param $post array 分类数据
|
||||
* @return boolean
|
||||
*/
|
||||
public static function edit($post)
|
||||
{
|
||||
$level = 0;
|
||||
if ($post['pid']) {
|
||||
$level = Db::name('goods_category')->where(['id' => $post['pid']], ['del' => 0])->value('level');
|
||||
}
|
||||
$is_recommend = $post['is_recommend'] ?? 0;
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'sort' => $post['sort'],
|
||||
'is_show' => $post['is_show'],
|
||||
'image' => $post['image'],
|
||||
'level' => $level+1,
|
||||
'pid' => $post['pid'],
|
||||
'is_recommend' => $post['pid'] == 0 ? $is_recommend : 0,
|
||||
'remark' => $post['remark'],
|
||||
'update_time' => time(),
|
||||
];
|
||||
|
||||
Cache::rm('goods_category_1');
|
||||
Cache::rm('goods_category_2');
|
||||
return Db::name('goods_category')->where(['id'=>$post['id']])->update($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc: 删除商品分类
|
||||
* @param $id array 分类id
|
||||
* @return boolean
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
$data = [
|
||||
'del' => 1,
|
||||
'update_time' => time(),
|
||||
];
|
||||
|
||||
Cache::rm('goods_category_1');
|
||||
Cache::rm('goods_category_2');
|
||||
return Db::name('goods_category')->where(['del' => 0, 'id' => $id])->update($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc: 获取商品完整二级分类
|
||||
* @return array
|
||||
*/
|
||||
public static function categoryTwoTree()
|
||||
{
|
||||
$goods_category = new GoodsCategory();
|
||||
|
||||
$cateogry_list = $goods_category::with('sons')
|
||||
->where(['del' => 0, 'level' => 1])
|
||||
->field('id,name,pid,level')
|
||||
->select();
|
||||
|
||||
return self::categoryToSelect($cateogry_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc: 获取完整的商品分类
|
||||
* @return array
|
||||
*/
|
||||
public static function categoryThirdTree()
|
||||
{
|
||||
|
||||
$lists = Db::name('goods_category')
|
||||
->where(['del' => 0])
|
||||
->order('id asc')
|
||||
->column('id,name,pid,is_recommend,is_show,level,image,sort');
|
||||
foreach ($lists as $k => $item){
|
||||
$lists[$k]['image'] = UrlServer::getFileUrl($item['image']);
|
||||
}
|
||||
|
||||
$lists = linear_to_tree($lists);
|
||||
|
||||
foreach ($lists as $key => $list){
|
||||
|
||||
if(1 == $list['is_recommend']){
|
||||
$sub = [];
|
||||
foreach ($list['sub'] as $key1 => $sub1){
|
||||
$sub1['is_recommend'] = 1;
|
||||
|
||||
|
||||
foreach ($sub1['sub'] as $key2 => $sub2){
|
||||
$sub1['sub'][$key2]['is_recommend'] = 1;
|
||||
|
||||
}
|
||||
$sub[] = $sub1;
|
||||
|
||||
}
|
||||
|
||||
$lists[$key]['sub'] = $sub;
|
||||
}
|
||||
}
|
||||
|
||||
return $lists;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc: 列表结构转换成树形结构
|
||||
* @param $lists array 分类数据
|
||||
* @return array
|
||||
*/
|
||||
public static function categoryToTree($lists)
|
||||
{
|
||||
$tree = [];
|
||||
foreach ($lists as $val) {
|
||||
$temp = [
|
||||
'id' => $val['id'],
|
||||
'title' => $val['name'],
|
||||
'children' => [],
|
||||
'spread' => false
|
||||
];
|
||||
|
||||
if ($val['child']) {
|
||||
|
||||
foreach ($val['child'] as $child_val) {
|
||||
$children = [
|
||||
'id' => $child_val['id'],
|
||||
'title' => $child_val['name'],
|
||||
];
|
||||
$temp['spread'] = true;
|
||||
$temp['children'][] = $children;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$tree[] = $temp;
|
||||
}
|
||||
|
||||
return $tree;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc:将树形结构数组输出
|
||||
* @param $items array 要输出的数组
|
||||
* @param $select_id int 已选中项
|
||||
* @return string
|
||||
*/
|
||||
public static function categoryToSelect($lists, $select_id = 0)
|
||||
{
|
||||
$tree = [];
|
||||
foreach ($lists as $val) {
|
||||
$tree[$val['id']]['level'] = $val['level'];
|
||||
$tree[$val['id']]['name'] = '|----' . $val['name'];
|
||||
if ($val['sons']) {
|
||||
foreach ($val['sons'] as $val_sons) {
|
||||
$tree[$val_sons['id']]['level'] = $val_sons['level'];
|
||||
$tree[$val_sons['id']]['name'] = '|--------' . $val_sons['name'];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return $tree;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Desc: 获取某个商品分类
|
||||
* @param $id int 分类id
|
||||
* @return string
|
||||
*/
|
||||
public static function getCategory($id)
|
||||
{
|
||||
$detail = GoodsCategory::get(['id' => $id, 'del' => 0]);
|
||||
$detail['abs_image'] = UrlServer::getFileUrl($detail['image']);
|
||||
return $detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc: 返回该分类下有多少级子类
|
||||
* @param array $category 分类信息
|
||||
* @return string
|
||||
*/
|
||||
public static function getCategoryLevel($category)
|
||||
{
|
||||
$level = 1;
|
||||
$two_id = Db::name('goods_category')->where(['pid' => $category['id'], 'del' => 0])->value('id');
|
||||
if ($two_id) {
|
||||
$level = 2;
|
||||
$three_id = Db::name('goods_category')->where(['pid' => $two_id, 'del' => 0])->value('id');
|
||||
if ($three_id) $level = 3;
|
||||
|
||||
}
|
||||
return $level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc: 根据分类等级返回该级别的所有分类
|
||||
* @param $level int 需要获取的分类等级
|
||||
* @return string
|
||||
*/
|
||||
public static function getGoodsCategoryLevel($level = 3)
|
||||
{
|
||||
$where['level'] = $level;
|
||||
$where['del'] = 0;
|
||||
return Db::name('goods_category')->where($where)->column('name', 'id');
|
||||
}
|
||||
|
||||
|
||||
public static function categoryTreeeTree()
|
||||
{
|
||||
$goods_category = new GoodsCategory();
|
||||
$lists = $goods_category->where(['del' => 0])->column('id,name,pid,level', 'id');
|
||||
return self::cateToTree($lists, 0, '|-----', 1);
|
||||
}
|
||||
|
||||
public static function cateToTree($lists, $pid = 0, $html = '|-----', $level = 1, $clear = true)
|
||||
{
|
||||
static $tree = [];
|
||||
if ($clear) $tree = [];
|
||||
foreach ($lists as $k => $v) {
|
||||
if ($v['pid'] == $pid) {
|
||||
$v['html'] = str_repeat($html, $level);
|
||||
$tree[] = $v;
|
||||
unset($lists[$k]);
|
||||
self::cateToTree($lists, $v['id'], $html, $level + 1, false);
|
||||
}
|
||||
}
|
||||
return $tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有分类树形结构
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function getAllTree()
|
||||
{
|
||||
$lists = Db::name('goods_category')
|
||||
->field(['name', 'id', 'pid', 'level'])
|
||||
->where(['del' => 0])
|
||||
->order(['sort' => 'desc'])
|
||||
->select();
|
||||
return $lists;
|
||||
}
|
||||
|
||||
//更新分类状态
|
||||
public static function switchStatus($data)
|
||||
{
|
||||
$update_data = [
|
||||
'is_show' => $data['status'],
|
||||
'update_time' => time(),
|
||||
];
|
||||
|
||||
Cache::rm('goods_category_1');
|
||||
Cache::rm('goods_category_2');
|
||||
return Db::name('goods_category')->where(['del' =>0,'id' =>$data['id']])->update($update_data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\logic;
|
||||
use think\db;
|
||||
use app\common\server\UrlServer;
|
||||
class GoodsCommentLogic{
|
||||
//评价
|
||||
public static function lists($get){
|
||||
|
||||
$where = [];
|
||||
if(isset($get['type'])&&$get['type'] == 1){
|
||||
$where = [];
|
||||
}elseif (isset($get['type'])&&$get['type'] == 2){
|
||||
$where[] = ['reply','=',null];
|
||||
}
|
||||
//搜索条件
|
||||
if (isset($get['choice'])&& $get['choice']==1){
|
||||
if (isset($get['keyword']) && $get['keyword']) {
|
||||
$where[] = ['g.name', 'like', "%{$get['keyword']}%"];
|
||||
}
|
||||
}elseif (isset($get['choice'])&& $get['choice']==2){
|
||||
if (isset($get['keyword']) && $get['keyword']) {
|
||||
$where[] = ['user_id', 'like', "%{$get['keyword']}%"];
|
||||
}
|
||||
}elseif (isset($get['choice'])&& $get['choice']==3){
|
||||
if (isset($get['keyword']) && $get['keyword']) {
|
||||
$where[] = ['nickname', 'like', "%{$get['keyword']}%"];
|
||||
}
|
||||
}elseif (isset($get['choice'])&& $get['choice']==4){
|
||||
if (isset($get['keyword']) && $get['keyword']) {
|
||||
$where[] = ['mobile', 'like', "%{$get['keyword']}%"];
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($get['goods_comment'])&& $get['goods_comment']==1){
|
||||
$where[] = ['goods_comment', '>', 3];
|
||||
}elseif (isset($get['goods_comment'])&& $get['goods_comment']==2){
|
||||
$where[] = ['goods_comment', '=', 3];
|
||||
}elseif (isset($get['goods_comment'])&& $get['goods_comment']==3){
|
||||
$where[] = ['goods_comment', '<', 3];
|
||||
}
|
||||
|
||||
if(isset($get['start_time']) && $get['start_time']){
|
||||
$where[] = ['gc.create_time','>=',strtotime($get['start_time'])];
|
||||
}
|
||||
if(isset($get['end_time']) && $get['end_time']){
|
||||
$where[] = ['gc.create_time','<=',strtotime($get['end_time'])];
|
||||
}
|
||||
|
||||
// 评价类型-虚拟评价/真实评价
|
||||
if (isset($get['comment_type']) && $get['comment_type'] != '') {
|
||||
if ($get['comment_type'] == 1) {
|
||||
$where[] = ['virtual_data', 'null', ''];
|
||||
} else {
|
||||
$where[] = ['virtual_data', 'not null', ''];
|
||||
}
|
||||
}
|
||||
|
||||
$res = Db::name('goods_comment gc')
|
||||
->join('goods g','g.id = gc.goods_id')
|
||||
->leftjoin('goods_item gi','gi.id = gc.item_id')
|
||||
->leftjoin('user u','u.id = gc.user_id')
|
||||
->where('gc.del',0)
|
||||
->where($where)
|
||||
->withAttr('comment_image', function ($value, $data){
|
||||
$imgs = Db::name('goods_comment_image')->where([
|
||||
'goods_comment_id' => $data['id']
|
||||
])->column('uri');
|
||||
foreach ($imgs as $k => $img) {
|
||||
$imgs[$k] = UrlServer::getFileUrl($img);
|
||||
}
|
||||
return $imgs;
|
||||
})
|
||||
->field('u.id as user_id,u.nickname,u.mobile,u.sex,u.create_time,g.name,gi.spec_value_str
|
||||
,gc.goods_comment,gc.comment,gc.create_time as comment_time,gc.status,u.avatar,g.image,gc.reply,u.sn,u.level
|
||||
,gc.id,gc.virtual_data')
|
||||
->order('gc.create_time','desc')
|
||||
->append(['comment_image']);
|
||||
$count = $res->count();
|
||||
$lists = $res->page($get['page'],$get['limit'])->select();
|
||||
|
||||
$user_level = Db::name('user_level')
|
||||
->where(['del'=>0])
|
||||
->column('name','id');
|
||||
|
||||
|
||||
foreach ($lists as &$item){
|
||||
|
||||
$item['comment_type'] = '真实评价';
|
||||
// 虚拟评论
|
||||
if (empty($item['user_id']) && !empty($item['virtual_data'])) {
|
||||
$virtual_data = json_decode($item['virtual_data'], JSON_UNESCAPED_UNICODE);
|
||||
$item['sn'] = $virtual_data['sn'] ?? '';
|
||||
$item['nickname'] = $virtual_data['nickname'] ?? '';
|
||||
$item['level'] = $virtual_data['level'] ?? '';
|
||||
$item['avatar'] = $virtual_data['avatar'] ?? '';
|
||||
$item['create_time'] = $virtual_data['comment_time'] ?? time();
|
||||
$item['comment_type'] = '虚拟评价';
|
||||
}
|
||||
|
||||
$item['level_name'] = $user_level[$item['level']] ?? '无等级';
|
||||
switch($item['sex']){
|
||||
case 0:
|
||||
$item['sex'] ='未知';
|
||||
break;
|
||||
case 1:
|
||||
$item['sex'] ='男';
|
||||
break;
|
||||
case 2:
|
||||
$item['sex'] ='女';
|
||||
break;
|
||||
}
|
||||
|
||||
if($item['goods_comment'] > 3){
|
||||
$item['goods_comment'] = '好评';
|
||||
}elseif ($item['goods_comment'] == 3){
|
||||
$item['goods_comment'] = '中评';
|
||||
}elseif ($item['goods_comment'] < 3){
|
||||
$item['goods_comment'] = '差评';
|
||||
}
|
||||
if($item['status'] == 1){
|
||||
$item['status'] = '显示';
|
||||
$item['info_state_switch'] = '隐藏';
|
||||
}elseif ($item['status'] == 0){
|
||||
$item['status'] = '隐藏';
|
||||
$item['info_state_switch'] = '显示';
|
||||
}
|
||||
|
||||
$item['create_time'] = date('Y-m-d H:i:s',$item['create_time']);
|
||||
$item['comment_time'] = date('Y-m-d H:i:s',$item['comment_time']);
|
||||
$item['avatar'] = UrlServer::getFileUrl($item['avatar']);
|
||||
$item['image'] = UrlServer::getFileUrl($item['image']);
|
||||
}
|
||||
|
||||
return [
|
||||
'lists' => $lists,
|
||||
'count'=> $count
|
||||
];
|
||||
}
|
||||
|
||||
//删除
|
||||
public static function del($delData)
|
||||
{
|
||||
$data = [
|
||||
'del' => 1,
|
||||
'update_time' => time(),];
|
||||
return Db::name('goods_comment')
|
||||
->where(['del' => 0, 'id' =>$delData])
|
||||
->update($data); //逻辑删除
|
||||
}
|
||||
|
||||
|
||||
//切换状态
|
||||
public static function switchStatus($get)
|
||||
{
|
||||
$data = [
|
||||
'status' => $get['status'],
|
||||
'update_time' => time(),
|
||||
];
|
||||
return Db::name('goods_comment')->where(['del' => 0, 'id' => $get['id']])->update($data);
|
||||
}
|
||||
|
||||
//回复
|
||||
public static function reply($post){
|
||||
|
||||
$reply = db::name('goods_comment')
|
||||
->where([
|
||||
'id'=>$post['id'],
|
||||
'del'=>0
|
||||
])
|
||||
->update(['reply'=>$post['reply']]);
|
||||
return $reply;
|
||||
}
|
||||
|
||||
//评论信息
|
||||
public static function info($id){
|
||||
$info = db::name('goods_comment')
|
||||
->where('del',0)
|
||||
->where('id',$id)
|
||||
->find();
|
||||
return $info;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,908 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
use app\common\model\DistributionGoods;
|
||||
use app\common\model\GoodsItem;
|
||||
use app\common\server\UrlServer;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use think\facade\Hook;
|
||||
|
||||
class GoodsLogic
|
||||
{
|
||||
|
||||
public static $error = '';
|
||||
|
||||
/*
|
||||
* 商品统计
|
||||
*/
|
||||
public static function statistics(){
|
||||
// 回收站商品数量
|
||||
$goods['recycle'] = Db::name('goods')->where(['del'=>0, 'status'=>-1])->count('id');
|
||||
// 仓库中商品数量(含库存预警)
|
||||
$goods['warehouse'] = Db::name('goods')->where(['del'=>0, 'status'=>0])->count('id');
|
||||
|
||||
// 销售中商品数量(含库存预警)
|
||||
$goods['sell'] = Db::name('goods')->where(['del'=>0, 'status'=>1])->count('id');
|
||||
|
||||
// 仓库中、销售中的库存预警商品数量
|
||||
$goods['warn'] = Db::name('goods')
|
||||
->where([
|
||||
['del', '=', 0],
|
||||
['stock_warn', '>', 0],
|
||||
['stock','exp', Db::raw('<stock_warn')]
|
||||
])->count();
|
||||
return $goods;
|
||||
}
|
||||
|
||||
/*
|
||||
* 商品列表
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
$where = [];
|
||||
$where[] = ['del', '=', '0'];
|
||||
if($get['type']){
|
||||
switch ($get['type']){
|
||||
case 1: //销售中
|
||||
$where[] = ['status','=',1];
|
||||
break;
|
||||
case 2: //仓库中
|
||||
$where[] = ['status','=',0];
|
||||
break;
|
||||
case 3: //库存预警
|
||||
$where[] = ['stock_warn','>',0];
|
||||
$where[] = ['stock','exp', Db::raw('<stock_warn')];
|
||||
break;
|
||||
case 4: //回收站
|
||||
$where[] = ['status','=',-1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
$activity_goods = self::activityGoods();
|
||||
$seckill_goods = $activity_goods['seckill_goods'];
|
||||
$team_goods = $activity_goods['team_goods'];
|
||||
$bargain_goods = $activity_goods['bargain_goods'];
|
||||
if(isset($get['goods_type']) && $get['goods_type']){
|
||||
switch ($get['goods_type']){
|
||||
case 1:
|
||||
$where[] = ['id','not in',$activity_goods['activity_goods']];
|
||||
break;
|
||||
case 2:
|
||||
$where[] = ['id','in',$seckill_goods];
|
||||
break;
|
||||
case 3:
|
||||
$where[] = ['id','in',$team_goods];
|
||||
break;
|
||||
case 4:
|
||||
$where[] = ['id','in',$bargain_goods];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($get['keyword']) && $get['keyword']) {
|
||||
$where[] = ['name', 'like', '%' . $get['keyword'] . '%'];
|
||||
}
|
||||
if(isset($get['code']) && $get['code']){
|
||||
$where[] = ['code','like','%'.$get['code'].'%'];
|
||||
}
|
||||
if(isset($get['supplier_id']) && $get['supplier_id']){
|
||||
$where[] = ['supplier_id','=',$get['supplier_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['delivery_type']) && $get['delivery_type'] == 1){
|
||||
$where[] = ['is_express','=',1];
|
||||
}elseif (isset($get['delivery_type']) && $get['delivery_type'] == 2) {
|
||||
$where[] = ['is_selffetch','=',1];
|
||||
}
|
||||
|
||||
$goods_count = Db::name('goods')
|
||||
->where($where)
|
||||
->count();
|
||||
|
||||
$goods_list = Db::name('goods')
|
||||
->where($where)
|
||||
->page($get['page'], $get['limit'])
|
||||
->field('*,virtual_sales_sum+sales_sum as total_sales_sum')
|
||||
->order('id desc')
|
||||
->select();
|
||||
|
||||
|
||||
$goods_category_list = Db::name('goods_category')->where(['del'=>0])->column('name','id');
|
||||
|
||||
foreach ($goods_list as &$item) {
|
||||
$item['type'] = $get['type'];
|
||||
$item['cat_name'] = self::getCateName($goods_category_list, $item);
|
||||
$item['commission_status'] = '关闭';
|
||||
if($item['is_commission']){
|
||||
$item['commission_status'] = '开启';
|
||||
}
|
||||
$item['price'] = '¥'.$item['min_price'];
|
||||
if($item['spec_type'] == 2 && $item['max_price'] !== $item['min_price']){
|
||||
$item['price'] = '¥'.$item['min_price'].'~'.'¥'.$item['max_price'];
|
||||
}
|
||||
$item['create_time_desc'] = date('Y-m-d H:i:s',$item['create_time']);
|
||||
$item['first_ratio_desc'] = 0;
|
||||
$item['second_ratio_desc'] = 0;
|
||||
$item['three_ratio_desc'] = 0;
|
||||
$item['region_ratio_desc'] = 0;
|
||||
$item['shareholder_ratio_desc'] = 0;
|
||||
|
||||
if($item['first_ratio'] > 0) $item['first_ratio_desc'] = $item['first_ratio'] .'%';
|
||||
if($item['second_ratio'] > 0) $item['second_ratio_desc'] = $item['second_ratio'] .'%';
|
||||
if($item['three_ratio'] > 0) $item['three_ratio_desc'] = $item['three_ratio'] .'%';
|
||||
if($item['region_ratio'] > 0) $item['region_ratio_desc'] = $item['region_ratio'] .'%';
|
||||
if($item['shareholder_ratio'] > 0) $item['shareholder_ratio_desc'] = $item['shareholder_ratio'] /100 .'%';
|
||||
|
||||
$item['image'] = UrlServer::getFileUrl($item['image']);
|
||||
|
||||
$item['attribute'] = '普通商品';
|
||||
if(in_array($item['id'],$seckill_goods)){
|
||||
$item['attribute'] = '秒杀商品';
|
||||
}elseif (in_array($item['id'],$team_goods)){
|
||||
$item['attribute'] = '拼团商品';
|
||||
}elseif (in_array($item['id'],$bargain_goods)){
|
||||
$item['attribute'] = '砍价商品';
|
||||
}
|
||||
}
|
||||
|
||||
return ['count' => $goods_count, 'list' => $goods_list];
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表导出
|
||||
* @param $get
|
||||
*/
|
||||
public static function exportFile($get)
|
||||
{
|
||||
$where = [];
|
||||
$where[] = ['del', '=', '0'];
|
||||
if($get['type']){
|
||||
switch ($get['type']){
|
||||
case 1: //销售中
|
||||
$where[] = ['status','=',1];
|
||||
break;
|
||||
case 2: //仓库中
|
||||
$where[] = ['status','=',0];
|
||||
break;
|
||||
case 3: //库存预警
|
||||
$where[] = ['stock_warn','>',0];
|
||||
$where[] = ['stock','exp', Db::raw('<stock_warn')];
|
||||
break;
|
||||
case 4: //回收站
|
||||
$where[] = ['status','=',-1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($get['keyword']) && $get['keyword']) {
|
||||
$where[] = ['name', 'like', '%' . $get['keyword'] . '%'];
|
||||
}
|
||||
if(isset($get['code']) && $get['code']){
|
||||
$where[] = ['code','like','%'.$get['code'].'%'];
|
||||
}
|
||||
if(isset($get['supplier_id']) && $get['supplier_id']){
|
||||
$where[] = ['supplier_id','=',$get['supplier_id']];
|
||||
}
|
||||
if(isset($get['category_id']) && $get['category_id']){
|
||||
$where[] = ['first_category_id|second_category_id|third_category_id','=',$get['category_id']];
|
||||
}
|
||||
|
||||
$goods_list_export = Db::name('goods')
|
||||
->where($where)
|
||||
->field('*,virtual_sales_sum+sales_sum as total_sales_sum')
|
||||
->order('id desc')
|
||||
->select();
|
||||
|
||||
$goods_category_list = Db::name('goods_category')->where(['del'=>0])->column('name','id');
|
||||
|
||||
$exportTitle = ['商品名称', '商品分类', '是否开启分销', 'SKU最低价', 'SKU最高价', '总库存', '总销量', '新品推荐', '好物优选', '猜你喜欢', '排序', '发布时间'];
|
||||
$exportExt = 'xls';
|
||||
$exportData = [];
|
||||
foreach($goods_list_export as $item) {
|
||||
$cateName = self::getCateName($goods_category_list, $item); // 商品分类
|
||||
$isCommission = $item['is_commission'] ? '开启' : '关闭';
|
||||
$isNew = $item['is_new'] ? '是' : '否';
|
||||
$isBest = $item['is_best'] ? '是' : '否';
|
||||
$isLike = $item['is_like'] ? '是' : '否';
|
||||
$createTime = date('Y-m-d H:i:s',$item['create_time']);
|
||||
$exportData[] = [$item['name'], $cateName, $isCommission, $item['min_price'], $item['max_price'], $item['stock'], $item['total_sales_sum'], $isNew, $isBest, $isLike, $item['sort'], $createTime];
|
||||
}
|
||||
|
||||
return ['exportTitle'=> $exportTitle, 'exportData' => $exportData, 'exportExt'=>$exportExt, 'exportName'=>'商品列表'.date('Y-m-d H:i:s')];
|
||||
}
|
||||
|
||||
/*
|
||||
* 删除商品
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
try {
|
||||
$data = [
|
||||
'del' => 1,
|
||||
'update_time' => time()
|
||||
];
|
||||
Db::name('goods')->where(['del' => 0, 'id' => $id])->update($data);
|
||||
|
||||
// 下架或删除商品,更新商品收藏
|
||||
Hook::listen('update_collect', ['goods_id' => $id]);
|
||||
|
||||
return true;
|
||||
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 添加商品
|
||||
* @param $post
|
||||
* @param $spec_lists
|
||||
* @return bool
|
||||
*/
|
||||
public static function add($post, $spec_lists)
|
||||
{
|
||||
|
||||
try {
|
||||
Db::startTrans();
|
||||
$time = time();
|
||||
|
||||
//算出最大最小价格
|
||||
if ($post['spec_type'] == 1) {
|
||||
$max_price = $post['one_price'];
|
||||
$min_price = $post['one_price'];
|
||||
$market_price = $post['one_market_price'];
|
||||
$total_stock = $post['one_stock'];
|
||||
} else {
|
||||
$max_price = max($post['price']);
|
||||
$min_price = min($post['price']);
|
||||
$min_price_key = array_search($min_price,$post['price']);
|
||||
$market_price = $post['market_price'][$min_price_key];
|
||||
$total_stock = array_sum($post['stock']);
|
||||
}
|
||||
$free_shipping = $post['free_shipping_type'] == 2 ? $post['free_shipping']: '';
|
||||
$free_shipping_template_id = $post['free_shipping_type'] == 3 ? $post['free_shipping_template_id']: '';
|
||||
|
||||
// 替换内容中图片地址
|
||||
$domain = UrlServer::getFileUrl('/');
|
||||
$post['content'] = str_replace($domain, '/', $post['content']);
|
||||
|
||||
//赠送积分类型
|
||||
$give_integral_type = $post['give_integral_type'] ?? 0;
|
||||
switch ($give_integral_type){
|
||||
case 1:
|
||||
$give_integral = empty($post['give_integral_num']) ? 0 : $post['give_integral_num'];
|
||||
break;
|
||||
case 2:
|
||||
$give_integral = empty($post['give_integral_ratio']) ? 0 : $post['give_integral_ratio'];
|
||||
break;
|
||||
default:
|
||||
$give_integral = 0;
|
||||
}
|
||||
|
||||
$video = isset($post['video']) ? UrlServer::setFileUrl($post['video']) : '';
|
||||
|
||||
//写入主表
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'code' => $post['code'],
|
||||
'first_category_id' => $post['first_category_id'],
|
||||
'second_category_id' => $post['second_category_id'],
|
||||
'third_category_id' => $post['third_category_id'],
|
||||
'brand_id' => $post['brand_id'],
|
||||
'supplier_id' => $post['supplier_id'],
|
||||
'image' => $post['image'],
|
||||
'video' => $video,
|
||||
'poster' => $post['poster'] ?? '',
|
||||
'remark' => $post['remark'],
|
||||
'content' => $post['content'],
|
||||
'max_price' => $max_price,
|
||||
'min_price' => $min_price,
|
||||
'market_price' => $market_price,
|
||||
'stock' => $total_stock,
|
||||
'status' => $post['status'],
|
||||
'virtual_sales_sum' => $post['virtual_sales_sum'],
|
||||
'virtual_click' => $post['virtual_click'] ?? 0,
|
||||
'stock_warn' => $post['stock_warn'],
|
||||
'is_show_stock' => $post['is_show_stock'],
|
||||
'free_shipping_type' => $post['free_shipping_type'],
|
||||
'free_shipping' => $free_shipping,
|
||||
'free_shipping_template_id' => $free_shipping_template_id,
|
||||
'is_new' => isset($post['is_new']) && $post['is_new'] == 'on' ? 1 : 0,
|
||||
'is_best' => isset($post['is_best']) && $post['is_best'] == 'on' ? 1 : 0,
|
||||
'is_like' => isset($post['is_like']) && $post['is_like'] == 'on' ? 1 : 0,
|
||||
'is_integral' => $post['is_integral'],
|
||||
'is_member' => $post['is_member'],
|
||||
'give_integral_type' => $give_integral_type,
|
||||
'give_integral' => $give_integral,
|
||||
'spec_type' => $post['spec_type'],
|
||||
'create_time' => $time,
|
||||
'is_express' => isset($post['is_express']) && $post['is_express'] == 'on' ? 1 : 0,
|
||||
'is_selffetch' => isset($post['is_selffetch']) && $post['is_selffetch'] == 'on' ? 1 : 0,
|
||||
];
|
||||
$goods_id = Db::name('goods')->insertGetId($data);
|
||||
|
||||
//写入图片表
|
||||
$data = [];
|
||||
foreach ($post['goods_image'] as $k => $v) {
|
||||
$data[] = [
|
||||
'goods_id' => $goods_id,
|
||||
'uri' => $v,
|
||||
];
|
||||
}
|
||||
Db::name('goods_image')->insertAll($data);
|
||||
|
||||
|
||||
//写入规格表
|
||||
if ($post['spec_type'] == 1) {
|
||||
//单规格写入
|
||||
$goods_spec_id = Db::name('goods_spec')
|
||||
->insertGetId(['goods_id' => $goods_id, 'name' => '默认']);
|
||||
$goods_spec_value_id = Db::name('goods_spec_value')
|
||||
->insertGetId(['spec_id' => $goods_spec_id, 'goods_id' => $goods_id, 'value' => '默认']);
|
||||
|
||||
$data = [
|
||||
'image' => $post['one_spec_image'],
|
||||
'goods_id' => $goods_id,
|
||||
'spec_value_ids' => $goods_spec_value_id,
|
||||
'spec_value_str' => '默认',
|
||||
'market_price' => $post['one_market_price'],
|
||||
'price' => $post['one_price'],
|
||||
'cost_price' => $post['one_cost_price'],
|
||||
'stock' => $post['one_stock'],
|
||||
'volume' => $post['one_volume'],
|
||||
'weight' => $post['one_weight'],
|
||||
'bar_code' => $post['one_bar_code'],
|
||||
];
|
||||
Db::name('goods_item')
|
||||
->insert($data);
|
||||
} else {
|
||||
//多规格写入
|
||||
$goods_specs = [];
|
||||
foreach ($post['spec_name'] as $k => $v) {
|
||||
$temp = ['goods_id' => $goods_id, 'name' => $v];
|
||||
$goods_specs[] = $temp;
|
||||
}
|
||||
Db::name('goods_spec')->insertAll($goods_specs);
|
||||
$goods_spec_name_key_id = Db::name('goods_spec')
|
||||
->where(['goods_id' => $goods_id])
|
||||
->where('name', 'in', $post['spec_name'])
|
||||
->column('id', 'name');
|
||||
|
||||
$data = [];
|
||||
$check_values = []; //检查规格项是否存在相同值,相同值会出现错误
|
||||
|
||||
foreach ($post['spec_values'] as $k => $v) {
|
||||
$row = explode(',', $v);
|
||||
foreach ($row as $k2 => $v2) {
|
||||
if (in_array($v2, $check_values)) {
|
||||
throw new Exception('请勿添加相同规格值');
|
||||
}
|
||||
$temp = [
|
||||
'goods_id' => $goods_id,
|
||||
'spec_id' => $goods_spec_name_key_id[$post['spec_name'][$k]],
|
||||
'value' => $v2,
|
||||
];
|
||||
$data[] = $temp;
|
||||
$check_values[] = $v2;
|
||||
}
|
||||
}
|
||||
|
||||
Db::name('goods_spec_value')->insertAll($data);
|
||||
$goods_spec_name_value_id = Db::name('goods_spec_value')
|
||||
->where(['goods_id' => $goods_id])
|
||||
->column('id', 'value');
|
||||
|
||||
foreach ($spec_lists as $k => $v) {
|
||||
$spec_lists[$k]['spec_value_ids'] = '';
|
||||
$temp = explode(',', $v['spec_value_str']);
|
||||
|
||||
foreach ($temp as $k2 => $v2) {
|
||||
$spec_lists[$k]['spec_value_ids'] .= $goods_spec_name_value_id[$v2] . ',';
|
||||
}
|
||||
$spec_lists[$k]['spec_value_ids'] = trim($spec_lists[$k]['spec_value_ids'], ',');
|
||||
$spec_lists[$k]['image'] = $spec_lists[$k]['spec_image'];
|
||||
$spec_lists[$k]['goods_id'] = $goods_id;
|
||||
unset($spec_lists[$k]['spec_image']);
|
||||
unset($spec_lists[$k]['spec_id']);
|
||||
unset($spec_lists[$k]['item_id']);
|
||||
}
|
||||
Db::name('goods_item')->insertAll($spec_lists);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 编辑商品
|
||||
* @param $post
|
||||
* @param $spec_lists
|
||||
* @return bool
|
||||
*/
|
||||
public static function edit($post, $spec_lists)
|
||||
{
|
||||
|
||||
try {
|
||||
Db::startTrans();
|
||||
|
||||
$oldItemIds = GoodsItem::where('goods_id', $post['id'])->column('id');
|
||||
|
||||
$time = time();
|
||||
|
||||
//算出最大最小价格
|
||||
if ($post['spec_type'] == 1) {
|
||||
$max_price = $post['one_price'];
|
||||
$min_price = $post['one_price'];
|
||||
$market_price = $post['one_market_price'];
|
||||
$total_stock = $post['one_stock'];
|
||||
} else {
|
||||
|
||||
$max_price = max($post['price']);
|
||||
$min_price = min($post['price']);
|
||||
$min_price_key = array_search($min_price,$post['price']);
|
||||
$market_price = $post['market_price'][$min_price_key];
|
||||
$total_stock = array_sum($post['stock']);
|
||||
}
|
||||
|
||||
$free_shipping = $post['free_shipping_type'] == 2 ? $post['free_shipping']: '';
|
||||
$free_shipping_template_id = $post['free_shipping_type'] == 3 ? $post['free_shipping_template_id']: '';
|
||||
|
||||
$old_spec_type = Db::name('goods')
|
||||
->where('id', $post['goods_id'])
|
||||
->value('spec_type');
|
||||
|
||||
// 替换内容中图片地址
|
||||
$domain = UrlServer::getFileUrl('/');
|
||||
$post['content'] = str_replace($domain, '/', $post['content']);
|
||||
|
||||
//赠送积分
|
||||
$give_integral_type = $post['give_integral_type'] ?? 0;
|
||||
switch ($give_integral_type){
|
||||
case 1:
|
||||
$give_integral = empty($post['give_integral_num']) ? 0 : $post['give_integral_num'];
|
||||
break;
|
||||
case 2:
|
||||
$give_integral = empty($post['give_integral_ratio']) ? 0 : $post['give_integral_ratio'];
|
||||
break;
|
||||
default:
|
||||
$give_integral = 0;
|
||||
}
|
||||
|
||||
$video = isset($post['video']) ? UrlServer::setFileUrl($post['video']) : '';
|
||||
|
||||
//写入主表
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'code' => $post['code'],
|
||||
'first_category_id' => $post['first_category_id'],
|
||||
'second_category_id' => $post['second_category_id'],
|
||||
'third_category_id' => $post['third_category_id'],
|
||||
'brand_id' => $post['brand_id'],
|
||||
'supplier_id' => $post['supplier_id'],
|
||||
'image' => $post['image'],
|
||||
'video' => $video,
|
||||
'poster' => $post['poster'] ?? '',
|
||||
'remark' => $post['remark'],
|
||||
'content' => $post['content'],
|
||||
'max_price' => $max_price,
|
||||
'min_price' => $min_price,
|
||||
'market_price' => $market_price,
|
||||
'stock' => $total_stock,
|
||||
'status' => $post['status'],
|
||||
'virtual_sales_sum' => $post['virtual_sales_sum'],
|
||||
'virtual_click' => $post['virtual_click'] ?? 0,
|
||||
'stock_warn' => $post['stock_warn'],
|
||||
'is_show_stock' => $post['is_show_stock'],
|
||||
'free_shipping_type' => $post['free_shipping_type'],
|
||||
'free_shipping' => $free_shipping,
|
||||
'free_shipping_template_id' => $free_shipping_template_id,
|
||||
'is_new' => isset($post['is_new']) && $post['is_new'] == 'on' ? 1 : 0,
|
||||
'is_best' => isset($post['is_best']) && $post['is_best'] == 'on' ? 1 : 0,
|
||||
'is_like' => isset($post['is_like']) && $post['is_like'] == 'on' ? 1 : 0,
|
||||
'is_integral' => $post['is_integral'],
|
||||
'is_member' => $post['is_member'],
|
||||
'give_integral_type' => $give_integral_type,
|
||||
'give_integral' => $give_integral,
|
||||
'spec_type' => $post['spec_type'],
|
||||
'update_time' => $time,
|
||||
'is_express' => isset($post['is_express']) && $post['is_express'] == 'on' ? 1 : 0,
|
||||
'is_selffetch' => isset($post['is_selffetch']) && $post['is_selffetch'] == 'on' ? 1 : 0,
|
||||
];
|
||||
|
||||
Db::name('goods')
|
||||
->where(['id' => $post['goods_id']])
|
||||
->update($data);
|
||||
|
||||
// 下架或删除商品,更新商品收藏
|
||||
if ($data['status'] != 1) {
|
||||
Hook::listen('update_collect', ['goods_id' => $post['goods_id']]);
|
||||
}
|
||||
|
||||
//重新更新图片表
|
||||
Db::name('goods_image')
|
||||
->where(['goods_id' => $post['goods_id']])
|
||||
->delete();
|
||||
$data = [];
|
||||
foreach ($post['goods_image'] as $k => $v) {
|
||||
$data[] = [
|
||||
'goods_id' => $post['goods_id'],
|
||||
'uri' => $v,
|
||||
];
|
||||
}
|
||||
Db::name('goods_image')->insertAll($data);
|
||||
|
||||
|
||||
//写入规格表
|
||||
if ($post['spec_type'] == 1) {
|
||||
|
||||
//单规格写入
|
||||
if ($old_spec_type == 1) {
|
||||
//原来是单规格
|
||||
$data = [
|
||||
'image' => $post['one_spec_image'],
|
||||
'price' => $post['one_price'],
|
||||
'market_price' => $post['one_market_price'],
|
||||
'price' => $post['one_price'],
|
||||
'cost_price' => $post['one_cost_price'],
|
||||
'stock' => $post['one_stock'],
|
||||
'volume' => $post['one_volume'],
|
||||
'weight' => $post['one_weight'],
|
||||
'bar_code' => $post['one_bar_code'],
|
||||
];
|
||||
Db::name('goods_item')
|
||||
->where(['goods_id' => $post['goods_id']])
|
||||
->update($data);
|
||||
} else {
|
||||
//原来非单规格
|
||||
//删除多规格
|
||||
Db::name('goods_spec')
|
||||
->where('goods_id', $post['goods_id'])
|
||||
->delete();
|
||||
Db::name('goods_spec_value')
|
||||
->where('goods_id', $post['goods_id'])
|
||||
->delete();
|
||||
Db::name('goods_item')
|
||||
->where('goods_id', $post['goods_id'])
|
||||
->delete();
|
||||
$goods_spec_id = Db::name('goods_spec')
|
||||
->insertGetId(['goods_id' => $post['goods_id'], 'name' => '默认']);
|
||||
$goods_spec_value_id = Db::name('goods_spec_value')
|
||||
->insertGetId(['spec_id' => $goods_spec_id, 'goods_id' => $post['goods_id'], 'value' => '默认']);
|
||||
$data = [
|
||||
'image' => $post['one_spec_image'],
|
||||
'goods_id' => $post['goods_id'],
|
||||
'spec_value_ids' => $goods_spec_value_id,
|
||||
'spec_value_str' => '默认',
|
||||
'market_price' => $post['one_market_price'],
|
||||
'cost_price' => $post['one_cost_price'],
|
||||
'price' => $post['one_price'],
|
||||
'stock' => $post['one_stock'],
|
||||
'volume' => $post['one_volume'],
|
||||
'weight' => $post['one_weight'],
|
||||
'bar_code' => $post['one_bar_code'],
|
||||
];
|
||||
Db::name('goods_item')
|
||||
->insert($data);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$goods_specs = [];
|
||||
foreach ($post['spec_name'] as $k => $v) {
|
||||
$temp = ['goods_id' => $post['goods_id'], 'name' => $v, 'spec_id' => $post['spec_id'][$k]];
|
||||
$goods_specs[] = $temp;
|
||||
}
|
||||
$new_spec_name_ids = [];
|
||||
foreach ($goods_specs as $k => $v) {
|
||||
if ($v['spec_id']) {
|
||||
//更新规格名
|
||||
Db::name('goods_spec')
|
||||
->where(['goods_id' => $post['goods_id'], 'id' => $v['spec_id']])
|
||||
->update(['name' => $v['name']]);
|
||||
$new_spec_name_ids[] = $v['spec_id'];
|
||||
} else {
|
||||
//添加规格名
|
||||
$new_spec_name_ids[] = Db::name('goods_spec')
|
||||
->insertGetId(['goods_id' => $post['goods_id'], 'name' => $v['name']]);
|
||||
}
|
||||
}
|
||||
//删除规格名
|
||||
$all_spec_ids = Db::name('goods_spec')
|
||||
->where('goods_id', $post['goods_id'])
|
||||
->column('id');
|
||||
$del_spec_name_ids = array_diff($all_spec_ids, $new_spec_name_ids);
|
||||
if (!empty($del_spec_name_ids)) {
|
||||
Db::name('goods_spec')
|
||||
->where('goods_id', $post['goods_id'])
|
||||
->where('id', 'in', $del_spec_name_ids)
|
||||
->delete();
|
||||
}
|
||||
|
||||
|
||||
$new_spec_value_ids = [];
|
||||
$goods_spec_name_key_id = Db::name('goods_spec')
|
||||
->where(['goods_id' => $post['goods_id']])
|
||||
->where('name', 'in', $post['spec_name'])
|
||||
->column('id', 'name');
|
||||
|
||||
$check_values = [];//检查规格值是否存在相同
|
||||
|
||||
foreach ($post['spec_values'] as $k => $v) {
|
||||
$value_id_row = explode(',', $post['spec_value_ids'][$k]);
|
||||
$value_row = explode(',', $v);
|
||||
foreach ($value_row as $k2 => $v2) {
|
||||
if (in_array($v2, $check_values)) {
|
||||
throw new Exception('请勿添加相同规格值');
|
||||
}
|
||||
$temp = [
|
||||
'goods_id' => $post['goods_id'],
|
||||
'spec_id' => $goods_spec_name_key_id[$post['spec_name'][$k]],
|
||||
'value' => $v2,
|
||||
];
|
||||
$check_values[] = $v2;
|
||||
if ($value_id_row[$k2]) {
|
||||
//更新规格值
|
||||
Db::name('goods_spec_value')
|
||||
->where(['id' => $value_id_row[$k2]])
|
||||
->update($temp);
|
||||
$new_spec_value_ids[] = $value_id_row[$k2];
|
||||
} else {
|
||||
//添加规格值
|
||||
$new_spec_value_ids[] = Db::name('goods_spec_value')
|
||||
->insertGetId($temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
$all_spec_value_ids = Db::name('goods_spec_value')
|
||||
->where('goods_id', $post['goods_id'])
|
||||
->column('id');
|
||||
$del_spec_value_ids = array_diff($all_spec_value_ids, $new_spec_value_ids);
|
||||
if (!empty($del_spec_value_ids)) {
|
||||
//删除规格值
|
||||
Db::name('goods_spec_value')
|
||||
->where('goods_id', $post['goods_id'])
|
||||
->where('id', 'in', $del_spec_value_ids)
|
||||
->delete();
|
||||
}
|
||||
|
||||
$new_item_id = [];
|
||||
$goods_spec_name_value_id = Db::name('goods_spec_value')
|
||||
->where(['goods_id' => $post['goods_id']])
|
||||
->column('id', 'value');
|
||||
foreach ($spec_lists as $k => $v) {
|
||||
$spec_lists[$k]['spec_value_ids'] = '';
|
||||
$temp = explode(',', $v['spec_value_str']);
|
||||
foreach ($temp as $k2 => $v2) {
|
||||
$spec_lists[$k]['spec_value_ids'] .= $goods_spec_name_value_id[$v2] . ',';
|
||||
}
|
||||
$spec_lists[$k]['spec_value_ids'] = trim($spec_lists[$k]['spec_value_ids'], ',');
|
||||
$spec_lists[$k]['image'] = str_replace(UrlServer::getFileUrl('/'), '', $spec_lists[$k]['spec_image']);
|
||||
unset($spec_lists[$k]['spec_image']);
|
||||
$spec_lists[$k]['goods_id'] = $post['goods_id'];
|
||||
unset($spec_lists[$k]['spec_id']);
|
||||
$item_id = $spec_lists[$k]['item_id'];
|
||||
unset($spec_lists[$k]['item_id']);
|
||||
if ($item_id) {
|
||||
Db::name('goods_item')
|
||||
->where(['id' => $item_id])
|
||||
->update($spec_lists[$k]);
|
||||
$new_item_id[] = $item_id;
|
||||
} else {
|
||||
$new_item_id[] = Db::name('goods_item')
|
||||
->insertGetId($spec_lists[$k]);
|
||||
}
|
||||
}
|
||||
$all_item_id = Db::name('goods_item')
|
||||
->where('goods_id', $post['goods_id'])
|
||||
->column('id');
|
||||
$del_item_ids = array_diff($all_item_id, $new_item_id);
|
||||
if (!empty($del_item_ids)) {
|
||||
//删除规格值
|
||||
Db::name('goods_item')
|
||||
->where('goods_id', $post['goods_id'])
|
||||
->where('id', 'in', $del_item_ids)
|
||||
->delete();
|
||||
}
|
||||
}
|
||||
|
||||
$newItemIds = GoodsItem::where('goods_id', $post['id'])->column('id');
|
||||
$destroyIds = DistributionGoods::where('goods_id', $post['goods_id'])->column('id');
|
||||
|
||||
// 删除原来的分销设置
|
||||
if ($oldItemIds != $newItemIds && $destroyIds) {
|
||||
DistributionGoods::destroy($destroyIds);
|
||||
self::$error = '商品信息修改成功,该商品属于分销商品,请重新设置分销信息';
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 商品信息
|
||||
*/
|
||||
/**
|
||||
* 获取商品信息
|
||||
* @param $goods_id
|
||||
* @return array
|
||||
*/
|
||||
public static function info($goods_id)
|
||||
{
|
||||
|
||||
$info['base'] = Db::name('goods')
|
||||
->where(['id' => $goods_id])
|
||||
->withAttr('abs_image', function ($value, $data) {
|
||||
return UrlServer::getFileUrl($data['image']);
|
||||
})
|
||||
->withAttr('content', function ($value){
|
||||
$preg = '/(<img .*?src=")[^https|^http](.*?)(".*?>)/is';
|
||||
$local_url = UrlServer::getFileUrl('/');
|
||||
return preg_replace($preg, "\${1}$local_url\${2}\${3}",$value);
|
||||
})
|
||||
->withAttr('abs_video',function ($value,$data){
|
||||
if($data['video']){
|
||||
return UrlServer::getFileUrl($data['video']);
|
||||
}
|
||||
return '';
|
||||
})
|
||||
->withAttr('abs_poster',function ($value,$data){
|
||||
if($data['poster']){
|
||||
return UrlServer::getFileUrl($data['poster']);
|
||||
}
|
||||
return '';
|
||||
})
|
||||
->append(['abs_image','abs_video'])->find();
|
||||
$info['base']['goods_image'] = Db::name('goods_image')
|
||||
->where(['goods_id' => $goods_id])
|
||||
->withAttr('abs_image', function ($value, $data) {
|
||||
return UrlServer::getFileUrl($data['uri']);})
|
||||
->append(['abs_image'])
|
||||
->select();
|
||||
|
||||
$info['item'] = Db::name('goods_item')
|
||||
->where(['goods_id' => $goods_id])
|
||||
->withAttr('abs_image', function ($value, $data) {
|
||||
return UrlServer::getFileUrl($data['image']);
|
||||
})->append(['abs_image'])
|
||||
->select();
|
||||
|
||||
$info['spec'] = Db::name('goods_spec')
|
||||
->where(['goods_id' => $goods_id])
|
||||
->select();
|
||||
|
||||
$spec_value = Db::name('goods_spec_value')
|
||||
->where(['goods_id' => $goods_id])
|
||||
->select();
|
||||
|
||||
$data = [];
|
||||
foreach ($spec_value as $k => $v) {
|
||||
$data[$v['spec_id']][] = $v;
|
||||
}
|
||||
foreach ($info['spec'] as $k => $v) {
|
||||
$info['spec'][$k]['values'] = isset($data[$v['id']]) ? $data[$v['id']] : [];
|
||||
}
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 上架 / 下架 商品
|
||||
* @author 张无忌(2021/1/11 14:35)
|
||||
* @param array $ids (要更新的数据ID)
|
||||
* @param int $type (类型[0=下架, 1=上架])
|
||||
* @return bool
|
||||
*/
|
||||
public static function upperOrLower(array $ids, int $type=0)
|
||||
{
|
||||
if (empty($ids)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
if ($type == 0) {
|
||||
$activity_goods = GoodsLogic::activityGoods()['activity_goods'];
|
||||
$diff_goods = array_diff($activity_goods,$ids);
|
||||
if($activity_goods != $diff_goods){
|
||||
return '该商品正在参与活动,请先关闭后才允许下架';
|
||||
}
|
||||
}
|
||||
|
||||
$result = Db::name('goods')->whereIn('id', $ids)->update([
|
||||
'status' => $type,
|
||||
'update_time' => time()
|
||||
]);
|
||||
|
||||
// 下架或删除商品,更新商品收藏
|
||||
Hook::listen('update_collect', ['goods_id' => $ids]);
|
||||
|
||||
return $result ? true : '上架失败';
|
||||
} catch (\Exception $e) {
|
||||
return '上架失败';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 分类名称
|
||||
* @param $cates
|
||||
* @param $item
|
||||
* @author 段誉(2021/6/3 19:45)
|
||||
* @return mixed|string
|
||||
*/
|
||||
public static function getCateName($cates, $item)
|
||||
{
|
||||
if(isset($cates[$item['third_category_id']])) {
|
||||
return $cates[$item['third_category_id']];
|
||||
}
|
||||
|
||||
if(isset($cates[$item['second_category_id']])) {
|
||||
return $cates[$item['second_category_id']];
|
||||
}
|
||||
|
||||
if(isset($cates[$item['first_category_id']])) {
|
||||
return $cates[$item['first_category_id']];
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取有活动中商品
|
||||
* @return array
|
||||
* @author cjhao
|
||||
* @date 2022/1/19 9:52
|
||||
*/
|
||||
public static function activityGoods(){
|
||||
//秒杀验证
|
||||
$seckill_goods = Db::name('seckill_goods')
|
||||
->where(['del'=>0])
|
||||
->column('goods_id');
|
||||
|
||||
//拼团活动验证
|
||||
$team_goods = Db::name('team_activity')
|
||||
->where(['del'=>0])
|
||||
->column('goods_id');
|
||||
|
||||
// 砍价活动验证
|
||||
$bargain_goods = Db::name('bargain')
|
||||
->where(['del'=>0])
|
||||
->column('goods_id');
|
||||
|
||||
$activity_goods = array_merge($seckill_goods,$team_goods,$bargain_goods);
|
||||
|
||||
return [
|
||||
'activity_goods' => $activity_goods,
|
||||
'seckill_goods' => $seckill_goods,
|
||||
'team_goods' => $team_goods,
|
||||
'bargain_goods' => $bargain_goods,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\admin\model\HelpCategory;
|
||||
use think\Db;
|
||||
|
||||
class HelpCategoryLogic
|
||||
{
|
||||
|
||||
public static function lists($get)
|
||||
{
|
||||
$where = [];
|
||||
$where[] = ['del', '=', '0'];
|
||||
|
||||
$cate = new HelpCategory();
|
||||
$count = $cate->where($where)->count();
|
||||
$list = $cate->where($where)
|
||||
->page($get['page'], $get['limit'])
|
||||
->append(['is_show_text'])
|
||||
->order('id desc')
|
||||
->select();
|
||||
|
||||
return ['count' => $count, 'lists' => $list];
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc: 添加文章分类
|
||||
* @param $post array 文章分类数据
|
||||
* @return boolean
|
||||
*/
|
||||
public static function addHelpCategory($post)
|
||||
{
|
||||
$help_category = new HelpCategory();
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'is_show' => $post['is_show'],
|
||||
'create_time' => time(),
|
||||
];
|
||||
return $help_category->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc: 编辑文章分类
|
||||
* @param $post array 文章分类数据
|
||||
* @return boolean
|
||||
*/
|
||||
public static function editHelpCategory($post)
|
||||
{
|
||||
$help_category = new HelpCategory();
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'is_show' => $post['is_show'],
|
||||
'update_time' => time(),
|
||||
];
|
||||
return $help_category->save($data, ['id' => $post['id'], 'del' => 0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc: 删除文章分类
|
||||
* @param $id int 文章分类id
|
||||
* @return boolean
|
||||
*/
|
||||
public static function delHelpCategory($id)
|
||||
{
|
||||
$help_category = new HelpCategory();
|
||||
$data = [
|
||||
'update_time' => time(),
|
||||
'del' => 1,
|
||||
];
|
||||
return $help_category->save($data, ['id' => $id, 'del' => 0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc: 获取单条文章分类
|
||||
* @param $id int 文章分类id
|
||||
* @return boolean
|
||||
*/
|
||||
public static function getHelpCategory($id = 0)
|
||||
{
|
||||
$where[] = ['del', '=', 0];
|
||||
if ($id) {
|
||||
$where[] = ['id', '=', $id];
|
||||
}
|
||||
$help_category = new HelpCategory();
|
||||
return $help_category->where($where)->column('*', 'id');
|
||||
}
|
||||
|
||||
public static function switchStatus($post)
|
||||
{
|
||||
$data = [
|
||||
'is_show' => $post['is_show'],
|
||||
'update_time' => time(),
|
||||
];
|
||||
return Db::name('help_category')->where(['del' => 0, 'id' => $post['id']])->update($data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\admin\model\Help;
|
||||
use app\common\server\UrlServer;
|
||||
use think\Db;
|
||||
|
||||
class HelpLogic
|
||||
{
|
||||
|
||||
public static function lists($get, $category)
|
||||
{
|
||||
$where = [];
|
||||
$where[] = ['del', '=', '0'];
|
||||
if (isset($get['is_show']) && $get['is_show'] != '') {
|
||||
$where[] = ['is_show', '=', $get['is_show']];
|
||||
}
|
||||
|
||||
if (isset($get['title']) && $get['title']) {
|
||||
$where[] = ['title', 'like', '%' . $get['title'] . '%'];
|
||||
}
|
||||
|
||||
if (isset($get['cid']) && $get['cid']) {
|
||||
$where[] = ['cid', '=', $get['cid']];
|
||||
}
|
||||
|
||||
$help_count = Db::name('help')->where($where)->count();
|
||||
$help_list = Db::name('help')->where($where)->page($get['page'], $get['limit'])->order('id desc')->select();
|
||||
|
||||
foreach ($help_list as &$item) {
|
||||
$item['image'] = UrlServer::getFileUrl($item['image']);
|
||||
$item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
|
||||
if (isset($category[$item['cid']])) {
|
||||
$item['cat_name'] = $category[$item['cid']]['name'];
|
||||
}
|
||||
if ($item['is_show'] == 1) {
|
||||
$item['is_show_text'] = '显示';
|
||||
} else {
|
||||
$item['is_show_text'] = '隐藏';
|
||||
}
|
||||
}
|
||||
return ['count' => $help_count, 'lists' => $help_list];
|
||||
}
|
||||
|
||||
|
||||
public static function addHelp($post)
|
||||
{
|
||||
$help = new Help();
|
||||
$data = [
|
||||
'title' => $post['title'],
|
||||
'cid' => $post['cid'],
|
||||
'image' => $post['image'],
|
||||
'content' => $post['content'],
|
||||
'is_show' => $post['is_show'],
|
||||
'create_time' => time(),
|
||||
'sort' => $post['sort'],
|
||||
'synopsis' => $post['synopsis'],
|
||||
'del' => 0
|
||||
];
|
||||
return $help->save($data);
|
||||
}
|
||||
|
||||
public static function editHelp($post)
|
||||
{
|
||||
$help = new Help();
|
||||
$data = [
|
||||
'title' => $post['title'],
|
||||
'cid' => $post['cid'],
|
||||
'image' => $post['image'],
|
||||
'content' => $post['content'],
|
||||
'is_show' => $post['is_show'],
|
||||
'update_time' => time(),
|
||||
'sort' => $post['sort'],
|
||||
'synopsis' => $post['synopsis']
|
||||
];
|
||||
return $help->save($data, ['id' => $post['id'], 'del' => 0]);
|
||||
}
|
||||
|
||||
public static function getHelp($id)
|
||||
{
|
||||
$help = new Help();
|
||||
$detail = $help::get(['id' => $id, 'del' => 0]);
|
||||
$detail['abs_image'] = UrlServer::getFileUrl($detail['image']);
|
||||
return $detail;
|
||||
}
|
||||
|
||||
public static function delHelp($id)
|
||||
{
|
||||
$help = new Help();
|
||||
|
||||
$data = [
|
||||
'del' => time(),
|
||||
'update_time' => 1
|
||||
];
|
||||
return $help->save($data, ['id' => $id, 'del' => 0]);
|
||||
}
|
||||
|
||||
public static function switchStatus($post)
|
||||
{
|
||||
$data = [
|
||||
'is_show' => $post['is_show'],
|
||||
'update_time' => time(),
|
||||
];
|
||||
return Db::name('help')->where(['del' => 0, 'id' => $post['id']])->update($data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\common\server\ConfigServer;
|
||||
use think\facade\Env;
|
||||
|
||||
/**
|
||||
* H5商城逻辑层
|
||||
* Class Hfive
|
||||
* @package app\admin\logic
|
||||
*/
|
||||
class Hfive
|
||||
{
|
||||
/**
|
||||
* @notes 获取H5商城设置
|
||||
* @return array
|
||||
* @author Tab
|
||||
* @date 2021/8/14 14:56
|
||||
*/
|
||||
public static function getConfig()
|
||||
{
|
||||
$config = [
|
||||
'is_open' => ConfigServer::get('h5', 'is_open', 1),
|
||||
'page' => ConfigServer::get('h5', 'page', 1),
|
||||
'page_url' => ConfigServer::get('h5', 'page_url', ''),
|
||||
'h5_url' => request()->domain() . '/mobile'
|
||||
];
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes H5商城设置
|
||||
* @param $params
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
* @throws \think\exception\PDOException
|
||||
* @author Tab
|
||||
* @date 2021/8/14 14:57
|
||||
*/
|
||||
public static function set($params)
|
||||
{
|
||||
ConfigServer::set('h5', 'is_open', $params['is_open']);
|
||||
ConfigServer::set('h5', 'page', $params['page']);
|
||||
ConfigServer::set('h5', 'page_url', $params['page_url']);
|
||||
|
||||
// 恢复原入口
|
||||
if(file_exists('./mobile/index_lock.html')) {
|
||||
// 存在则原商城入口被修改过,先清除修改后的入口
|
||||
unlink('./mobile/index.html');
|
||||
// 恢复原入口
|
||||
rename('./mobile/index_lock.html', './mobile/index.html');
|
||||
}
|
||||
|
||||
// H5商城关闭 且 显示空白页
|
||||
if($params['is_open'] == 0 && $params['page'] == 1) {
|
||||
// 变更文件名
|
||||
rename('./mobile/index.html', './mobile/index_lock.html');
|
||||
// 创建新空白文件
|
||||
$newfile = fopen('./mobile/index.html', 'w');
|
||||
fclose($newfile);
|
||||
}
|
||||
|
||||
// H5商城关闭 且 跳转指定页
|
||||
if($params['is_open'] == 0 && $params['page'] == 2 && !empty($params['page_url'])) {
|
||||
// 变更文件名
|
||||
rename('./mobile/index.html', './mobile/index_lock.html');
|
||||
// 创建重定向文件
|
||||
$newfile = fopen('./mobile/index.html', 'w');
|
||||
$content = '<script>window.location.href = "' . $params['page_url'] . '";</script>';
|
||||
fwrite($newfile, $content);
|
||||
fclose($newfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
use app\common\server\ConfigServer;
|
||||
|
||||
class HotSearchLogic
|
||||
{
|
||||
|
||||
public static function info(){
|
||||
|
||||
$info = ConfigServer::get('hot_search','hot_keyword',[]);
|
||||
if (empty($info)){
|
||||
return [''];
|
||||
}
|
||||
return $info;
|
||||
}
|
||||
|
||||
public static function set($post){
|
||||
|
||||
if ($post['hot_keyword'] == ['']){
|
||||
return ConfigServer::set('hot_search','hot_keyword',[]);
|
||||
}
|
||||
$hot_keyword = array_values(array_filter($post['hot_keyword']));
|
||||
|
||||
return ConfigServer::set('hot_search','hot_keyword',$hot_keyword);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,保留版权即可
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | 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\admin\logic;
|
||||
|
||||
|
||||
use app\common\model\LiveGoods;
|
||||
use app\common\server\UrlServer;
|
||||
use app\common\server\WeChatServer;
|
||||
use EasyWeChat\Factory;
|
||||
use Exception;
|
||||
use think\facade\Cache;
|
||||
|
||||
/**
|
||||
* 直播商品逻辑层
|
||||
* Class LiveGoodsLogic
|
||||
* @package app\admin\logic
|
||||
*/
|
||||
class LiveGoodsLogic
|
||||
{
|
||||
/**
|
||||
* @notes 获取直播商品列表
|
||||
* @param $get
|
||||
* @return array|string
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\HttpException
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
||||
* @author heshihu
|
||||
* @date 2021/9/17 11:43
|
||||
*/
|
||||
public static function Lists($get)
|
||||
{
|
||||
try {
|
||||
$config = WeChatServer::getMnpConfig();
|
||||
$app = Factory::miniProgram($config);
|
||||
$access_token = $app->access_token->getToken()['access_token'];
|
||||
$goods_url = '&status=' . $get['type'] . '&limit=' . $get['limit'] . '&offset=' . ($get['page'] - 1);
|
||||
$url = 'https://api.weixin.qq.com/wxaapi/broadcast/goods/getapproved?access_token=' . $access_token . $goods_url;
|
||||
$result = curl_get($url);
|
||||
$result = json_decode($result, true);
|
||||
if ($result['errcode'] != 0) {
|
||||
return ['count' => 0, 'lists' => []];
|
||||
}
|
||||
$goodsStatus = [0 => '未审核', 1 => '审核中', 2 => '审核通过', 3 => '审核驳回'];
|
||||
|
||||
|
||||
foreach ($result['goods'] as &$goods) {
|
||||
// 获取商品信息
|
||||
$goods['goods_status_desc'] = $goodsStatus[$get['type']];
|
||||
}
|
||||
|
||||
return ['count' => $result['total'], 'lists' => $result['goods']];
|
||||
}catch (Exception $e){
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 添加直播商品
|
||||
* @param $post
|
||||
* @return bool|string
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\HttpException
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
||||
* @author heshihu
|
||||
* @date 2021/9/17 15:28
|
||||
*/
|
||||
public static function add($post)
|
||||
{
|
||||
$config = WeChatServer::getMnpConfig();
|
||||
$app = Factory::miniProgram($config);
|
||||
$access_token = $app->access_token->getToken()['access_token'];
|
||||
|
||||
$price = 0;
|
||||
$price2 = 0;
|
||||
switch ($post['use_price_type']) {
|
||||
case 1:
|
||||
$price = $post['price'];
|
||||
break;
|
||||
case 2:
|
||||
$price = $post['section_price_start'];
|
||||
$price2 = $post['section_price_end'];
|
||||
break;
|
||||
case 3:
|
||||
$price = $post['discount_price_start'];
|
||||
$price2 = $post['discount_price_end'];
|
||||
break;
|
||||
}
|
||||
|
||||
$data['goodsInfo'] = [
|
||||
'coverImgUrl' => $post['feedsImg'],
|
||||
'name' => $post['goods_name'],
|
||||
'priceType' => $post['use_price_type'],
|
||||
'price' => $price,
|
||||
'price2' => $price2,
|
||||
'url' => $post['url'],
|
||||
];
|
||||
|
||||
$url = 'https://api.weixin.qq.com/wxaapi/broadcast/goods/add?access_token=' . $access_token;
|
||||
$result = curl_post($url, $data);
|
||||
$result = json_decode($result, true);
|
||||
if ($result['errcode'] != 0) {
|
||||
return self::getLiveGoodsError($result['errcode'], $result['errmsg']);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 删除商品
|
||||
* @param $id
|
||||
* @return bool|string
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\HttpException
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
||||
* @author heshihu
|
||||
* @date 2021/9/17 18:39
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
$config = WeChatServer::getMnpConfig();
|
||||
$app = Factory::miniProgram($config);
|
||||
$access_token = $app->access_token->getToken()['access_token'];
|
||||
|
||||
$url = 'https://api.weixin.qq.com/wxaapi/broadcast/goods/delete?access_token=' . $access_token;
|
||||
$result = curl_post($url, ['goodsId' => intval($id)]);
|
||||
$result = json_decode($result, true);
|
||||
if ($result['errcode'] != 0) {
|
||||
return self::getLiveGoodsError($result['errcode'], $result['errmsg']);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品的信息与审核状态
|
||||
* @param $goods_ids
|
||||
* @return mixed|string
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\HttpException
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
||||
* @author heshihu
|
||||
* @date 2021/9/17 17:42
|
||||
*/
|
||||
// public static function goodsInfo($goods_ids)
|
||||
// {
|
||||
// $config = WeChatServer::getMnpConfig();
|
||||
// $app = Factory::miniProgram($config);
|
||||
// $access_token = $app->access_token->getToken(true)['access_token'];
|
||||
//
|
||||
// $url = 'https://api.weixin.qq.com/wxa/business/getgoodswarehouse?access_token=' . $access_token;
|
||||
// $result = curl_post($url, ['goods_ids' => $goods_ids]);
|
||||
// $result = json_decode($result, true);
|
||||
// if ($result['errcode'] != 0) {
|
||||
// return '';
|
||||
// }
|
||||
// return $result;
|
||||
// }
|
||||
|
||||
public static function addUploadImage($goods_image)
|
||||
{
|
||||
try {
|
||||
$config = WeChatServer::getMnpConfig();
|
||||
$app = Factory::miniProgram($config);
|
||||
$path = env('root_path') . 'public/' . strrchr($goods_image, 'uploads');
|
||||
if (!file_exists($path)) {
|
||||
return '商品封面不存在,请上传商品封面';
|
||||
}
|
||||
|
||||
// 裁剪图片尺寸,避免图片太大导致上传失败
|
||||
// 打开图片文件
|
||||
$image = \think\Image::open($path);
|
||||
// 定义上传文件目录
|
||||
$dir = './uploads/goods/';
|
||||
// 判断文件目录是否存在
|
||||
if (!is_dir($dir)) {
|
||||
// 创建文件目录
|
||||
if (!mkdir($dir, 0777, true)) {
|
||||
return '请给uploads目录开启777权限';
|
||||
}
|
||||
}
|
||||
// 定义新图片名称
|
||||
$new_image = 'livegoods' . time() . '.png';
|
||||
$image->thumb(300, 300)->save('./uploads/goods/' . $new_image);
|
||||
// 获取完整的新文件路径
|
||||
$new_path = env('root_path') . 'public/uploads/goods/' . $new_image;
|
||||
$result = $app->media->uploadImage($new_path);
|
||||
|
||||
return ['media_id' => $result['media_id'], 'url' => UrlServer::getFileUrl('uploads/goods/' . $new_image)];
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public static function getLiveGoodsError($code, $errmsg){
|
||||
$error_msg = [
|
||||
-1 => '系统错误',
|
||||
1003 => '商品id不存在',
|
||||
47001 => '参格式不符合规范',
|
||||
200002 => '入参错误',
|
||||
300001 => '禁止创建/更新商品',
|
||||
300002 => '名称长度不符合规则',
|
||||
300003 => '价格输入不合规',
|
||||
300004 => '商品名称存在违规违法内容',
|
||||
300005 => '商品封面图片存在违规违法内容',
|
||||
300006 => '图片上传失败',
|
||||
300007 => '线上小程序版本不存在该链接',
|
||||
300008 => '添加商品失败',
|
||||
300009 => '商品审核撤回失败',
|
||||
300010 => '商品审核状态不对',
|
||||
300011 => '操作非法',
|
||||
300012 => '没有提审额度(每天500次提审额度)',
|
||||
300013 => '提审失败',
|
||||
300014 => '审核中,无法删除',
|
||||
300017 => '商品未提审',
|
||||
300018 => '商品封面图片尺寸过大',
|
||||
300021 => '商品添加成功,审核失败'
|
||||
];
|
||||
if(!isset($error_msg[$code])){
|
||||
return $errmsg;
|
||||
}
|
||||
return $error_msg[$code];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,保留版权即可
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | 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\admin\logic;
|
||||
|
||||
|
||||
use app\common\server\UrlServer;
|
||||
use app\common\server\WeChatServer;
|
||||
use EasyWeChat\Factory;
|
||||
use Exception;
|
||||
|
||||
class LiveRoomLogic
|
||||
{
|
||||
/**
|
||||
* @notes 获取assessToken
|
||||
* @return mixed
|
||||
* @throws @\EasyWeChat\Kernel\Exceptions\HttpException
|
||||
* @throws @\EasyWeChat\Kernel\Exceptions\InvalidArgumentException
|
||||
* @throws @\EasyWeChat\Kernel\Exceptions\RuntimeException
|
||||
* @throws @\Psr\SimpleCache\InvalidArgumentException
|
||||
* @author 张无忌
|
||||
* @date 2021/10/13 11:36
|
||||
*/
|
||||
public static function getAccessToken()
|
||||
{
|
||||
$config = WeChatServer::getMnpConfig();
|
||||
$app = Factory::miniProgram($config);
|
||||
return $app->access_token->getToken()['access_token'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取直播间列表
|
||||
* @param $get
|
||||
* @return array|string
|
||||
* @author 张无忌
|
||||
* @date 2021/9/13 15:54
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
try {
|
||||
$config = WeChatServer::getMnpConfig();
|
||||
$app = Factory::miniProgram($config);
|
||||
$result = $app->live->getRooms($get['page'] - 1, $get['limit']);
|
||||
|
||||
if ($result['errcode'] != 0) {
|
||||
return $result['errcode'] . ':' . $result['errmsg'];
|
||||
}
|
||||
|
||||
$liveStatus = [101 => '直播中', 102 => '未开始', 103 => '已结束', 104 => '禁播', 105 => '暂停', 106 => '异常', 107 => '已过期'];
|
||||
|
||||
$data = [];
|
||||
foreach ($result['room_info'] as $item) {
|
||||
$data[] = [
|
||||
'name' => $item['name'],
|
||||
'roomid' => $item['roomid'],
|
||||
'cover_img' => $item['cover_img'],
|
||||
'anchor_name' => $item['anchor_name'],
|
||||
'live_status' => $liveStatus[$item['live_status']],
|
||||
'goods' => count($item['goods']),
|
||||
'start_time' => date('Y-m-d H:i:s', $item['start_time']),
|
||||
'end_time' => date('Y-m-d H:i:s', $item['end_time'])
|
||||
];
|
||||
}
|
||||
|
||||
return ['count' => $result['total'], 'lists' => $data];
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 创建直播间
|
||||
* @param $post
|
||||
* @return bool|string
|
||||
* @throws @\EasyWeChat\Kernel\Exceptions\HttpException
|
||||
* @throws @\EasyWeChat\Kernel\Exceptions\InvalidArgumentException
|
||||
* @throws @\EasyWeChat\Kernel\Exceptions\InvalidConfigException
|
||||
* @throws @\EasyWeChat\Kernel\Exceptions\RuntimeException
|
||||
* @throws @\Psr\SimpleCache\InvalidArgumentException
|
||||
* @author 张无忌
|
||||
* @date 2021/9/14 15:49
|
||||
*/
|
||||
public static function add($post)
|
||||
{
|
||||
$config = WeChatServer::getMnpConfig();
|
||||
$app = Factory::miniProgram($config);
|
||||
$access_token = $app->access_token->getToken()['access_token'];
|
||||
|
||||
$startTime = strtotime($post['startTime']);
|
||||
$endTime = strtotime($post['endTime']);
|
||||
|
||||
if (($startTime - time()) <= 610) {
|
||||
return '开播时间需要在当前时间的10分钟后';
|
||||
}
|
||||
|
||||
if (($endTime - $startTime) <= (30 * 60)) {
|
||||
return '播时间和结束时间间隔不得短于30分钟';
|
||||
}
|
||||
|
||||
if (empty($post['coverImg'])) {
|
||||
return '请上传封面图';
|
||||
}
|
||||
|
||||
if (empty($post['shareImg'])) {
|
||||
return '请上传分享图';
|
||||
}
|
||||
|
||||
if (empty($post['feedsImg'])) {
|
||||
return '请上传背景图';
|
||||
}
|
||||
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'coverImg' => $post['coverImg'],
|
||||
'startTime' => strtotime($post['startTime']),
|
||||
'endTime' => strtotime($post['endTime']),
|
||||
'anchorName' => $post['anchorName'],
|
||||
'anchorWechat' => $post['anchorWechat'],
|
||||
'subAnchorWechat' => $post['subAnchorWechat'] ?? '',
|
||||
'createrWechat' => $post['anchorWechat'],
|
||||
'shareImg' => $post['shareImg'],
|
||||
'feedsImg' => $post['feedsImg'],
|
||||
'type' => intval($post['type']),
|
||||
'isFeedsPublic' => empty($post['isFeedsPublic']) ? 0 : 1,
|
||||
'closeLike' => empty($post['closeLike']) ? 1 : 0,
|
||||
'closeGoods' => empty($post['closeGoods']) ? 1 : 0,
|
||||
'closeComment' => empty($post['closeComment']) ? 1 : 0,
|
||||
'closeReplay' => empty($post['closeReplay']) ? 1 : 0,
|
||||
'closeShare' => empty($post['closeShare']) ? 1 : 0,
|
||||
'closeKf' => empty($post['closeKf']) ? 1 : 0,
|
||||
];
|
||||
|
||||
$url = 'https://api.weixin.qq.com/wxaapi/broadcast/room/create?access_token='.$access_token;
|
||||
$result = curl_post($url, $data);
|
||||
$result = json_decode($result, true);
|
||||
if ($result['errcode'] != 0) {
|
||||
return $result['errcode'] . ':' . $result['errmsg'];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 删除直播间
|
||||
* @param $id
|
||||
* @return bool|string
|
||||
* @throws @\EasyWeChat\Kernel\Exceptions\HttpException
|
||||
* @throws @\EasyWeChat\Kernel\Exceptions\InvalidArgumentException
|
||||
* @throws @\EasyWeChat\Kernel\Exceptions\InvalidConfigException
|
||||
* @throws @\EasyWeChat\Kernel\Exceptions\RuntimeException
|
||||
* @throws @\Psr\SimpleCache\InvalidArgumentException
|
||||
* @author 张无忌
|
||||
* @date 2021/9/14 16:00
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
$config = WeChatServer::getMnpConfig();
|
||||
$app = Factory::miniProgram($config);
|
||||
$access_token = $app->access_token->getToken()['access_token'];
|
||||
|
||||
$url = 'https://api.weixin.qq.com/wxaapi/broadcast/room/deleteroom?access_token='.$access_token;
|
||||
$result = curl_post($url, ['id'=>intval($id)]);
|
||||
$result = json_decode($result, true);
|
||||
if ($result['errcode'] != 0) {
|
||||
return $result['errcode'] . ':' . $result['errmsg'];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 上传临时素材图片
|
||||
* @param $url
|
||||
* @return array|string
|
||||
* @throws @\GuzzleHttp\Exception\GuzzleException
|
||||
* @author 张无忌
|
||||
* @date 2021/9/13 17:34
|
||||
*/
|
||||
public static function upload($url)
|
||||
{
|
||||
try {
|
||||
$config = WeChatServer::getMnpConfig();
|
||||
$app = Factory::miniProgram($config);
|
||||
$path = env('root_path').'public/uploads/temp/'.$url;
|
||||
$result = $app->media->uploadImage($path);
|
||||
|
||||
return ['media_id'=>$result['media_id'], 'url'=>UrlServer::getFileUrl('uploads/temp/'.$url)];
|
||||
}catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
use think\Db;
|
||||
use think\helper\Time;
|
||||
|
||||
class LogLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取日志列表
|
||||
* @param $page_no
|
||||
* @param $size
|
||||
* @param $get
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function lists($page_no, $size, $get)
|
||||
{
|
||||
if (isset($get['start_time']) && $get['start_time'] && isset($get['end_time']) && $get['end_time']) {
|
||||
$where[] = ['create_time', 'between', [strtotime($get['start_time']), strtotime($get['end_time'])]];
|
||||
} else {
|
||||
$where[] = ['create_time', 'between', Time::today()];
|
||||
}
|
||||
|
||||
if (isset($get['account']) && $get['account']) {
|
||||
$where[] = ['account', 'like', "%{$get['account']}%"];
|
||||
}
|
||||
if (isset($get['type']) && $get['type']) {
|
||||
$where[] = ['type', 'eq', $get['type']];
|
||||
}
|
||||
if (isset($get['uri']) && $get['uri']) {
|
||||
$where[] = ['uri', 'like', "%{$get['uri']}%"];
|
||||
}
|
||||
if (isset($get['ip']) && $get['ip']) {
|
||||
$where[] = ['ip', 'like', "%{$get['ip']}%"];
|
||||
}
|
||||
|
||||
$lists = Db::name('system_log')
|
||||
->where($where)
|
||||
->page($page_no, $size)
|
||||
->order(['id' => 'desc'])
|
||||
->select();
|
||||
foreach ($lists as $k => $v) {
|
||||
$lists[$k]['create_time_str'] = date('Y-m-d H:i:s', $v['create_time']);
|
||||
$lists[$k]['param'] = str_replace([" ", " ", "\t", "\n", "\r"], '', $v['param']);
|
||||
}
|
||||
|
||||
$count = Db::name('system_log')
|
||||
->where($where)
|
||||
->count();
|
||||
|
||||
return ['lists' => $lists, 'count' => $count];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\admin\server\LoginServer;
|
||||
use app\common\server\ConfigServer;
|
||||
use think\Db;
|
||||
|
||||
class LoginLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* 登录
|
||||
* @param $post
|
||||
* @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)
|
||||
{
|
||||
//session激活
|
||||
$admin_info = Db::name('admin')
|
||||
->field(['id', 'account', 'name', 'role_id'])
|
||||
->where(['account' => $post['account'], 'del' => 0])
|
||||
->find();
|
||||
session('admin_info', $admin_info);
|
||||
LoginServer::setState($admin_info['id']);
|
||||
//登录信息更新
|
||||
$ip = request()->ip();
|
||||
$time = time();
|
||||
Db::name('admin')
|
||||
->where(['account' => $post['account'], 'del' => 0])
|
||||
->update(['login_ip' => $ip, 'login_time' => $time]);
|
||||
|
||||
//记住账号
|
||||
if (isset($post['remember_account']) && $post['remember_account'] == 'on') {
|
||||
\think\facade\Cookie::set('account', $post['account']);
|
||||
} else {
|
||||
\think\facade\Cookie::delete('account');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 登出
|
||||
* @param $admin_id
|
||||
*/
|
||||
public static function logout($admin_id)
|
||||
{
|
||||
if ($admin_id) {
|
||||
//清除登录标识
|
||||
LoginServer::setState($admin_id, false);
|
||||
}
|
||||
session(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录页面配置
|
||||
* @return array
|
||||
*/
|
||||
public static function config()
|
||||
{
|
||||
$config = [
|
||||
'company_name' => ConfigServer::get('copyright', 'company_name'),
|
||||
'number' => ConfigServer::get('copyright', 'number'),
|
||||
'link' => ConfigServer::get('copyright', 'link'),
|
||||
'admin_image' => ConfigServer::get('website', 'admin_image'),
|
||||
'admin_title' => ConfigServer::get('website', 'admin_title'),
|
||||
'name' => ConfigServer::get('website', 'name'),
|
||||
'login_logo' => ConfigServer::get('website', 'login_logo'),
|
||||
'slogan' => ConfigServer::get('website', 'slogan'),
|
||||
'slogan_status' => ConfigServer::get('website', 'slogan_status'),
|
||||
'web_favicon' => ConfigServer::get('website', 'web_favicon'),
|
||||
];
|
||||
return $config;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,300 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
use app\admin\model\Coupon;
|
||||
use app\common\model\Luckdraw;
|
||||
use app\common\model\LuckdrawRecord;
|
||||
use app\common\server\ConfigServer;
|
||||
|
||||
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/25 11:28)
|
||||
* @param $get
|
||||
* @return array
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
$where = [
|
||||
['is_delete', '=', 0]
|
||||
];
|
||||
|
||||
$model = new Luckdraw();
|
||||
$count = $model->where($where)->count();
|
||||
$lists = $model->field(true)->where($where)
|
||||
->append(['prize_name'])
|
||||
->order(['sort'=>'desc', 'id' => 'desc'])
|
||||
->page($get['page'], $get['limit'])
|
||||
->select();
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['number'] = $item['prize_type'] == 2 ? '-' : $item['number'];
|
||||
$item['probability'] = $item['probability'] . '%';
|
||||
}
|
||||
|
||||
return ['count'=>$count, 'list'=>$lists];
|
||||
}
|
||||
|
||||
public static function detail($id)
|
||||
{
|
||||
$model = new Luckdraw();
|
||||
return $model->field(true)
|
||||
->where('id', '=', (int)$id)
|
||||
->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 新增奖品
|
||||
* @param $post
|
||||
* @author 张无忌(2021/1/26 10:28)
|
||||
* @return bool
|
||||
*/
|
||||
public static function add($post)
|
||||
{
|
||||
try {
|
||||
$post['name'] = Luckdraw::getPrizeDesc($post['prize_type']);
|
||||
$post['image'] = !empty($post['image']) ? $post['image'] : '';
|
||||
|
||||
$model = new Luckdraw();
|
||||
return $model->save([
|
||||
'prize_type' => $post['prize_type'],
|
||||
'name' => $post['name'],
|
||||
'image' => $post['image'],
|
||||
'number' => self::getPrizeValue($post),
|
||||
'sort' => $post['sort'],
|
||||
'probability' => $post['probability'],
|
||||
'status' => $post['status'],
|
||||
'is_delete' => 0,
|
||||
'create_time' => time(),
|
||||
'update_time' => time()
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 编辑奖品
|
||||
* @param $post
|
||||
* @author 张无忌(2021/1/26 10:28)
|
||||
* @return bool
|
||||
*/
|
||||
public static function edit($post)
|
||||
{
|
||||
try {
|
||||
$post['name'] = Luckdraw::getPrizeDesc($post['prize_type']);
|
||||
$post['image'] = !empty($post['image']) ? $post['image'] : '';
|
||||
|
||||
$model = new Luckdraw();
|
||||
$result = $model->where(['id'=>(int)$post['id']])->update([
|
||||
'prize_type' => $post['prize_type'],
|
||||
'name' => $post['name'],
|
||||
'image' => $post['image'],
|
||||
'number' => self::getPrizeValue($post),
|
||||
'sort' => $post['sort'],
|
||||
'probability' => $post['probability'],
|
||||
'status' => $post['status'],
|
||||
'update_time' => time()
|
||||
]);
|
||||
return $result ? true : false;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 删除奖品
|
||||
* @param $id
|
||||
* @author 张无忌(2021/1/26 11:17)
|
||||
* @return bool
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
try {
|
||||
$model = new Luckdraw();
|
||||
$result = $model->where(['id'=>(int)$id])->update([
|
||||
'is_delete' => 1,
|
||||
'update_time' => time()
|
||||
]);
|
||||
return $result ? true : false;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 更新抽奖设置
|
||||
* @param $post
|
||||
* @author 张无忌(2021/1/26 11:40)
|
||||
* @return bool
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function set($post)
|
||||
{
|
||||
if ($post['status'] == 1) {
|
||||
$model = new Luckdraw();
|
||||
$prizes = $model->field(true)
|
||||
->where(['is_delete' => 0, 'status'=>1])
|
||||
->order(['id'=>'desc', 'sort'=>'desc'])
|
||||
->select();
|
||||
if (count($prizes) != 8) {
|
||||
static::$error = '抽奖限制8个抽奖奖品';
|
||||
return false;
|
||||
}
|
||||
$probability = array_column($prizes->toArray(), 'probability');
|
||||
if (array_sum($probability) > 100) {
|
||||
static::$error = '中奖概率合计不能大于100%';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
ConfigServer::set('luckdraw', 'limit', $post['limit']);
|
||||
ConfigServer::set('luckdraw', 'need', $post['need']);
|
||||
ConfigServer::set('luckdraw', 'rule', $post['rule']);
|
||||
ConfigServer::set('luckdraw', 'status', $post['status']);
|
||||
ConfigServer::set('luckdraw', 'show_win', $post['show_win']);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 抽奖记录
|
||||
* @param $get
|
||||
* @author 张无忌(2021/1/26 14:08)
|
||||
* @return array
|
||||
*/
|
||||
public static function record($get)
|
||||
{
|
||||
$model = new LuckdrawRecord();
|
||||
$count = $model->count();
|
||||
$lists = $model->field(true)
|
||||
->with('user')
|
||||
->order('id', 'desc')
|
||||
->page($get['page'], $get['limit'])
|
||||
->append(['send_desc'])
|
||||
->select();
|
||||
|
||||
return ['count'=>$count, 'list'=>$lists];
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 切换状态
|
||||
* @param $post
|
||||
* @author 张无忌(2021/1/13 17:53)
|
||||
* @return bool
|
||||
*/
|
||||
public static function switchStatus($post)
|
||||
{
|
||||
try {
|
||||
$model = new Luckdraw();
|
||||
$model->where(['id' => (int)$post['id']])->update([
|
||||
'status' => $post['status'],
|
||||
'update_time' => time()
|
||||
]);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 更新排序
|
||||
* @param $post
|
||||
* @author 张无忌(2021/1/13 17:53)
|
||||
* @return bool
|
||||
*/
|
||||
public static function updateSort($post)
|
||||
{
|
||||
try {
|
||||
$model = new Luckdraw();
|
||||
$model->where(['id' => (int)$post['id']])->update([
|
||||
$post['field'] => $post['data'],
|
||||
'update_time' => time()
|
||||
]);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 优惠券列表
|
||||
* @return Coupon[]
|
||||
* @author 段誉
|
||||
* @date 2022/2/15 10:18
|
||||
*/
|
||||
public static function coupon()
|
||||
{
|
||||
$where[] = ['del', '=', 0];
|
||||
$where[] = ['status', '=', 1];
|
||||
$where[] = ['get_type', '=', 2];
|
||||
return Coupon::where($where)->order('id desc')->select();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取奖品数值
|
||||
* @param $param
|
||||
* @return int|mixed
|
||||
* @author 段誉
|
||||
* @date 2022/2/15 14:14
|
||||
*/
|
||||
public static function getPrizeValue($param)
|
||||
{
|
||||
$number = 0;
|
||||
switch ($param['prize_type']) {
|
||||
case Luckdraw::PRIZE_INTEGRAL:
|
||||
$number = $param['integral'];
|
||||
break;
|
||||
case Luckdraw::PRIZE_COUPON:
|
||||
$number = $param['coupon'];
|
||||
break;
|
||||
case Luckdraw::PRIZE_BALANCE:
|
||||
$number = $param['balance'];
|
||||
break;
|
||||
}
|
||||
return $number;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\logic;
|
||||
use app\common\server\ConfigServer;
|
||||
use app\common\server\UrlServer;
|
||||
|
||||
class MapConfigLogic{
|
||||
/**
|
||||
* @notes 获取地图配置
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2021/8/20 8:34 下午
|
||||
*/
|
||||
public static function getConfig(){
|
||||
$config = [
|
||||
'tx_map_key' => ConfigServer::get('map','tx_map_key',''),
|
||||
];
|
||||
return $config;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 地图设置
|
||||
* @param $post
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
* @throws \think\exception\PDOException
|
||||
* @author ljj
|
||||
* @date 2021/8/20 8:34 下午
|
||||
*/
|
||||
public static function setConfig($post)
|
||||
{
|
||||
ConfigServer::set('map','tx_map_key',$post['tx_map_key']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\logic;
|
||||
use app\common\server\ConfigServer;
|
||||
use think\Db;
|
||||
|
||||
class MarketingConfigLogic{
|
||||
public static function getConfig($config_list){
|
||||
$config = [];
|
||||
foreach ($config_list as $config_name){
|
||||
$value = ConfigServer::get('marketing',$config_name,0);
|
||||
$config[$config_name] = $value;
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
public static function setConfig($post){
|
||||
foreach ($post as $config_name => $config_value){
|
||||
ConfigServer::set('marketing',$config_name,$config_value);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static function getCouponList(){
|
||||
return Db::name('coupon')->where(['status'=>1,'del'=>0,'get_type'=>2])->field('id,name')->select();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,299 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\logic;
|
||||
use app\common\model\Menu_;
|
||||
use app\common\server\UrlServer;
|
||||
use think\Db;
|
||||
|
||||
class MenuDecorateLogic{
|
||||
/*
|
||||
* 获取列表
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
$type = $get['type'] ?? 1;
|
||||
$where[] = ['del','=',0];
|
||||
$where[] = ['decorate_type', '=', $type];
|
||||
|
||||
$count = Db::name('menu_decorate')->where($where)->count();
|
||||
$lists = Db::name('menu_decorate')
|
||||
->where($where)
|
||||
->page($get['page'], $get['limit'])
|
||||
->order('id desc')
|
||||
->select();
|
||||
|
||||
foreach ($lists as &$item){
|
||||
$item['image'] = UrlServer::getFileUrl($item['image']);
|
||||
if($item['link_type'] == 1){
|
||||
$content = Menu_::getMenuContent($type,$item['link_address']);
|
||||
$item['link_address'] = $content['link'] ?? '';
|
||||
|
||||
}
|
||||
}
|
||||
return ['count' => $count, 'lists' => $lists];
|
||||
}
|
||||
|
||||
// 首页
|
||||
public static function indexList($get)
|
||||
{
|
||||
$where[] = ['del','=',0];
|
||||
$where[] = ['decorate_type', '=', 1];
|
||||
|
||||
$count = Db::name('menu_decorate')->where($where)->count();
|
||||
$lists = Db::name('menu_decorate')
|
||||
->where($where)
|
||||
->page($get['page'], $get['limit'])
|
||||
->order('id desc')
|
||||
->select();
|
||||
|
||||
foreach ($lists as &$item){
|
||||
$item['image'] = UrlServer::getFileUrl($item['image']);
|
||||
if($item['link_type'] == 1){
|
||||
$content = Menu_::getMenuContent(1,$item['link_address']);
|
||||
$item['link_address'] = $content['link'] ?? '';
|
||||
}
|
||||
}
|
||||
return ['count' => $count, 'lists' => $lists];
|
||||
}
|
||||
|
||||
// 首页
|
||||
public static function centerList($get)
|
||||
{
|
||||
$where[] = ['del','=',0];
|
||||
$where[] = ['decorate_type', '=', 2];
|
||||
|
||||
$count = Db::name('menu_decorate')->where($where)->count();
|
||||
$lists = Db::name('menu_decorate')
|
||||
->where($where)
|
||||
->page($get['page'], $get['limit'])
|
||||
->order('id desc')
|
||||
->select();
|
||||
|
||||
foreach ($lists as &$item){
|
||||
$item['image'] = UrlServer::getFileUrl($item['image']);
|
||||
if($item['link_type'] == 1){
|
||||
$content = Menu_::getMenuContent(1,$item['link_address']);
|
||||
$item['link_address'] = $content['link'] ?? '';
|
||||
}
|
||||
}
|
||||
return ['count' => $count, 'lists' => $lists];
|
||||
}
|
||||
|
||||
/*
|
||||
* 新增
|
||||
*/
|
||||
public static function add($post){
|
||||
$link_address = $post['menu'];
|
||||
if($post['link_type'] == 2){
|
||||
$link_address = $post['url'];
|
||||
}
|
||||
$time = time(); //当前时间截
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'image' => $post['image'],
|
||||
'decorate_type' => $post['decorate_type'],
|
||||
'link_type' => $post['link_type'],
|
||||
'link_address' => $link_address,
|
||||
'sort' => $post['sort']?:0,
|
||||
'update_time' => $time,
|
||||
'create_time' => $time,
|
||||
'is_show' => $post['is_show'],
|
||||
];
|
||||
return Db::name('menu_decorate')->insert($data);
|
||||
}
|
||||
|
||||
/*
|
||||
* 编辑菜单
|
||||
*/
|
||||
public static function edit($post){
|
||||
$link_address = $post['menu'];
|
||||
if($post['link_type'] == 2){
|
||||
$link_address = $post['url'];
|
||||
}
|
||||
$time = time(); //当前时间截
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'image' => $post['image'],
|
||||
'decorate_type' => $post['decorate_type'],
|
||||
'link_type' => $post['link_type'],
|
||||
'link_address' => $link_address,
|
||||
'sort' => $post['sort']?:0,
|
||||
'update_time' => $time,
|
||||
'is_show' => $post['is_show'],
|
||||
];
|
||||
return Db::name('menu_decorate')->where(['id'=>$post['id']])->update($data);
|
||||
}
|
||||
/*
|
||||
* 删除菜单
|
||||
*/
|
||||
public static function del($id){
|
||||
$data= [
|
||||
'del' =>1,
|
||||
'update_time' =>time()
|
||||
];
|
||||
return Db::name('menu_decorate')->where(['id'=>$id])->update($data);
|
||||
}
|
||||
/*
|
||||
* 批量删除菜单
|
||||
*/
|
||||
public static function batchDelMenuDecorate($ids){
|
||||
$data = [
|
||||
'del' => 1,
|
||||
'update_time' => time()
|
||||
];
|
||||
|
||||
return Db::name('menu_decorate')->where(['id'=>$ids])->update($data);
|
||||
}
|
||||
/*
|
||||
* 获取菜单
|
||||
*/
|
||||
public static function getMenuDecorate($id){
|
||||
$detail = Db::name('menu_decorate')->where(['id'=>$id])->find();
|
||||
$detail['abs_image'] = UrlServer::getFileUrl($detail['image']);
|
||||
return $detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加 - 底部导航
|
||||
*/
|
||||
public static function addNavigation($post)
|
||||
{
|
||||
if(empty($post['name'])) {
|
||||
return [
|
||||
'flag' => false,
|
||||
'msg' => '导航名称不能为空'
|
||||
];
|
||||
}
|
||||
$count = Db::name('dev_navigation')->where([
|
||||
['del', '=', 0],
|
||||
['name', '=', trim($post['name']) ]
|
||||
])->count();
|
||||
if($count) {
|
||||
return [
|
||||
'flag' => false,
|
||||
'msg' => '导航名称已存在'
|
||||
];
|
||||
}
|
||||
$data = [
|
||||
'name' => trim($post['name']),
|
||||
'selected_icon' => trim($post['selected_icon']),
|
||||
'un_selected_icon' => trim($post['un_selected_icon']),
|
||||
'create_time' => time(),
|
||||
'del' => 0
|
||||
];
|
||||
$result = Db::name('dev_navigation')->insert($data);
|
||||
if($result) {
|
||||
return [
|
||||
'flag' => true,
|
||||
'msg' => '添加成功'
|
||||
];
|
||||
}else{
|
||||
return [
|
||||
'flag' => false,
|
||||
'msg' => '添加失败'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 底部导航 - 列表
|
||||
*/
|
||||
public static function bottomNavigation($get)
|
||||
{
|
||||
$lists = Db::name('dev_navigation')
|
||||
->where('del', 0)
|
||||
->page($get['page'], $get['limit'])
|
||||
->order('id', 'desc')
|
||||
->select();
|
||||
$count = Db::name('dev_navigation')->count();
|
||||
foreach($lists as &$item) {
|
||||
$item['selected_icon'] = UrlServer::getFileUrl($item['selected_icon']);
|
||||
$item['un_selected_icon'] = UrlServer::getFileUrl($item['un_selected_icon']);
|
||||
}
|
||||
$data = [
|
||||
'count' => $count,
|
||||
'lists' => $lists
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 底部导航 - 详情
|
||||
*/
|
||||
public static function getNavigation($id)
|
||||
{
|
||||
$navigation = Db::name('dev_navigation')->where('id', $id)->find();
|
||||
$navigation['selected_icon'] = $navigation['selected_icon'] ? UrlServer::getFileUrl($navigation['selected_icon']) : '';
|
||||
$navigation['un_selected_icon'] = $navigation['un_selected_icon'] ? UrlServer::getFileUrl($navigation['un_selected_icon']) : '';
|
||||
return $navigation;
|
||||
}
|
||||
|
||||
/**
|
||||
* 底部导航 - 编辑
|
||||
*/
|
||||
public static function editNavigation($post)
|
||||
{
|
||||
if(empty($post['name'])) {
|
||||
return [
|
||||
'flag' => false,
|
||||
'msg' => '导航名称不能为空'
|
||||
];
|
||||
}
|
||||
$count = Db::name('dev_navigation')->where([
|
||||
['del', '=', 0],
|
||||
['name', '=', trim($post['name']) ],
|
||||
['id', '<>', $post['id']]
|
||||
])->count();
|
||||
if($count) {
|
||||
return [
|
||||
'flag' => false,
|
||||
'msg' => '导航名称已存在'
|
||||
];
|
||||
}
|
||||
$updateData = [
|
||||
'name' => trim($post['name']),
|
||||
'selected_icon' => trim($post['selected_icon']),
|
||||
'un_selected_icon' => trim($post['un_selected_icon']),
|
||||
'update_time' => time()
|
||||
];
|
||||
$result = Db::name('dev_navigation')->where('id', $post['id'])->update($updateData);
|
||||
if($result) {
|
||||
return [
|
||||
'flag' => true,
|
||||
'msg' => '编辑成功'
|
||||
];
|
||||
}else{
|
||||
return [
|
||||
'flag' => false,
|
||||
'msg' => '编辑失败'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除 - 底部导航
|
||||
*/
|
||||
public static function delNavigation($id)
|
||||
{
|
||||
return Db::name('dev_navigation')->where('id', $id)->update([
|
||||
'del' => 1,
|
||||
'update_time' => time()
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\logic;
|
||||
use think\Db;
|
||||
|
||||
class MessageLogic{
|
||||
|
||||
public static function config(){
|
||||
$list = Db::name('dev_message m')
|
||||
->join('dev_message_extend e','m.id = e.message_id')
|
||||
->where(['m.del'=>0])
|
||||
->field('m.*,e.status')
|
||||
->select();
|
||||
|
||||
$config = [
|
||||
'member' => [],
|
||||
'platform' => [],
|
||||
];
|
||||
|
||||
foreach ($list as $item){
|
||||
if($item['dev_type'] == 1){
|
||||
$config['member'][] = $item;
|
||||
}else{
|
||||
$config['platform'][] = $item;
|
||||
}
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
public static function set($id,$type){
|
||||
|
||||
}
|
||||
|
||||
public static function getMessage($id){
|
||||
$config = Db::name('dev_message_extend e')
|
||||
->join('dev_message d','e.message_id = d.id')
|
||||
->where(['e.id'=>$id])
|
||||
->field('d.name,e.*')
|
||||
->find();
|
||||
|
||||
if($config['variable']){
|
||||
$config['variable'] = json_decode($config['variable'],true);
|
||||
}else{
|
||||
$config['variable'] = [];
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
public static function setConfig($post){
|
||||
$post['status'] = isset($post['status']) && $post['status'] == 'on' ? 1 : 0;
|
||||
return Db::name('dev_message_extend')->where(['id'=>$post['id']])->update($post);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\logic;
|
||||
use app\common\server\ConfigServer;
|
||||
use app\common\server\UrlServer;
|
||||
|
||||
class MnpLogic{
|
||||
public static function getMnp(){
|
||||
$domain_name = $_SERVER['SERVER_NAME'];
|
||||
$qr_code = ConfigServer::get('mnp', 'qr_code', '');
|
||||
$config = [
|
||||
'name' => ConfigServer::get('mnp', 'name', ''),
|
||||
'original_id' => ConfigServer::get('mnp', 'original_id', ''),
|
||||
'qr_code' => $qr_code,
|
||||
'abs_qr_code' => UrlServer::getFileUrl($qr_code),
|
||||
'app_id' => ConfigServer::get('mnp', 'app_id', ''),
|
||||
'app_secret' => ConfigServer::get('mnp', 'secret', ''),
|
||||
'request_domain' => 'https://'.$domain_name,
|
||||
'socket_domain' => 'wss://'.$domain_name,
|
||||
'uploadfile_domain' => 'https://'.$domain_name,
|
||||
'downloadfile_domain' => 'https://'.$domain_name,
|
||||
'udp_domain' => 'udp://'.$domain_name,
|
||||
'tcp_domain' => 'tcp://'.$domain_name,
|
||||
'business_domain' => $domain_name,
|
||||
'url' => url('api/weChat/index','','',true),
|
||||
'token' => ConfigServer::get('mnp', 'token', 'LikeShop'),
|
||||
'encoding_ses_key' => ConfigServer::get('mnp', 'encoding_ses_key', ''),
|
||||
'encryption_type' => ConfigServer::get('mnp', 'encryption_type', ''),
|
||||
'data_type' => ConfigServer::get('mnp', 'data_type', ''),
|
||||
];
|
||||
return $config;
|
||||
}
|
||||
public static function setMnp($post){
|
||||
if($post){
|
||||
if(!isset($post['encryption_type'])){
|
||||
$post['encryption_type'] = '';
|
||||
}
|
||||
if(!isset($post['data_type'])){
|
||||
$post['data_type'] = '';
|
||||
}
|
||||
ConfigServer::set('mnp','name',$post['name']);
|
||||
ConfigServer::set('mnp','original_id',$post['original_id']);
|
||||
ConfigServer::set('mnp','qr_code',$post['qr_code']);
|
||||
ConfigServer::set('mnp','app_id',$post['app_id']);
|
||||
ConfigServer::set('mnp','secret',$post['app_secret']);
|
||||
// ConfigServer::set('mnp','token',$post['token']);
|
||||
// ConfigServer::set('mnp','encoding_ses_key',$post['encoding_ses_key']);
|
||||
// ConfigServer::set('mnp','encryption_type',$post['encryption_type']);
|
||||
// ConfigServer::set('mnp','data_type',$post['data_type']);
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
use app\common\logic\LogicBase;
|
||||
use app\common\model\MessageScene_;
|
||||
use app\common\server\WeChatServer;
|
||||
use EasyWeChat\Factory;
|
||||
use think\Db;
|
||||
|
||||
class MnpMessageLogic extends LogicBase
|
||||
{
|
||||
// 获取表
|
||||
public static function lists($get)
|
||||
{
|
||||
$where[] = ['type', '=', 1];
|
||||
|
||||
if(isset($get['disable']) && is_numeric($get['disable'])){
|
||||
$where[] = ['disable', '=', (int)$get['disable']];
|
||||
}
|
||||
|
||||
$count = Db::name('dev_message_template')
|
||||
->where($where)
|
||||
->count();
|
||||
$lists = Db::name('dev_message_template')
|
||||
->where($where)
|
||||
->page($get['page'],$get['limit'])
|
||||
->select();
|
||||
|
||||
$scene = (new MessageScene_());
|
||||
foreach ($lists as &$item) {
|
||||
$item['scene'] = $scene->getName($item['scene']);
|
||||
}
|
||||
|
||||
return ['count' => $count,'list' => $lists];
|
||||
}
|
||||
|
||||
// 获取单个消息模板
|
||||
public static function getTemplateMessage($id)
|
||||
{
|
||||
return Db::name('dev_message_template')->where(['id' => (int)$id])->find();
|
||||
}
|
||||
|
||||
// 更新消息模板状态
|
||||
public static function switchStatus($data)
|
||||
{
|
||||
$update_data = [
|
||||
'disable' => $data['disable']
|
||||
];
|
||||
return Db::name('dev_message_template')->where(['id' => (int)$data['id']])->update($update_data);
|
||||
}
|
||||
|
||||
// 同步消息模板到公众号
|
||||
public static function synchro($data)
|
||||
{
|
||||
try {
|
||||
$model = Db::name('dev_message_template')->where(['id' => (int)$data['id']])->find();
|
||||
|
||||
// 发起同步到公众号
|
||||
$config = WeChatServer::getMnpConfig();
|
||||
$app = Factory::miniProgram($config);
|
||||
$result = $app->subscribe_message->addTemplate($model['template_id_short'], explode(',', $model['keywords']), $model['name']);
|
||||
|
||||
// 获取关键词库(调试用)
|
||||
// $result = $app->subscribe_message->getTemplateKeywords('492');
|
||||
|
||||
// 保存返回的template_id
|
||||
if ($result['errcode'] === 0 && isset($result['priTmplId'])) {
|
||||
$update_data = ['template_id' => $result['priTmplId']];
|
||||
Db::name('dev_message_template')->where(['id' => (int)$data['id']])->update($update_data);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use think\Db;
|
||||
|
||||
class MyLogic
|
||||
{
|
||||
/**
|
||||
* 修改密码
|
||||
* @param $password
|
||||
* @param $admin_id
|
||||
* @throws \think\Exception
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function updatePassword($password, $admin_id)
|
||||
{
|
||||
$salt = Db::name('admin')
|
||||
->where(['id' => $admin_id])
|
||||
->value('salt');
|
||||
$password = create_password($password, $salt);
|
||||
|
||||
Db::name('admin')
|
||||
->where(['id' => $admin_id])
|
||||
->update(['update_time' => time(), 'password' => $password]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
use app\common\model\NoticeSetting;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 逻辑
|
||||
* Class NoticeSettingLogic
|
||||
* @package app\admin\logic
|
||||
*/
|
||||
class NoticeSettingLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 列表
|
||||
* @param $type
|
||||
* @author 段誉(2021/4/26 16:18)
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function lists($type)
|
||||
{
|
||||
$count = NoticeSetting::where('type', $type)->count();
|
||||
$lists = NoticeSetting::where('type', $type)->select();
|
||||
return ['lists' => $lists, 'count' => $count];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 设置通知消息
|
||||
* @param $post
|
||||
* @author 段誉(2021/4/26 16:18)
|
||||
* @return bool
|
||||
* @throws \think\Exception
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function set($post)
|
||||
{
|
||||
switch ($post['type']) {
|
||||
case 'system':
|
||||
$setting = [
|
||||
'title' => $post['title'],
|
||||
'content' => $post['content'],
|
||||
'is_push' => $post['is_push'],
|
||||
'status' => $post['status'],
|
||||
];
|
||||
break;
|
||||
case 'sms':
|
||||
$setting = [
|
||||
'template_code' => $post['template_code'],
|
||||
'content' => $post['content'],
|
||||
'status' => $post['status'],
|
||||
];
|
||||
break;
|
||||
case 'oa':
|
||||
$setting = [
|
||||
'name' => $post['name'],
|
||||
'first' => $post['first'],
|
||||
'template_sn' => $post['template_sn'],
|
||||
'template_id' => $post['template_id'],
|
||||
'remark' => $post['remark'],
|
||||
'status' => $post['status'],
|
||||
'tpl' => self::formatTplData($post)
|
||||
];
|
||||
break;
|
||||
case 'mnp':
|
||||
$setting = [
|
||||
'name' => $post['name'],
|
||||
'template_sn' => $post['template_sn'],
|
||||
'template_id' => $post['template_id'],
|
||||
'status' => $post['status'],
|
||||
'tpl' => self::formatTplData($post),
|
||||
];
|
||||
break;
|
||||
default:
|
||||
$setting = [];
|
||||
}
|
||||
|
||||
NoticeSetting::where('id', $post['id'])
|
||||
->update([
|
||||
$post['type'].'_notice' => json_encode($setting, JSON_UNESCAPED_UNICODE)
|
||||
]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 详情
|
||||
* @param $id
|
||||
* @param $type
|
||||
* @author 段誉(2021/4/26 17:34)
|
||||
* @return NoticeSetting
|
||||
*/
|
||||
public static function info($id, $type)
|
||||
{
|
||||
return NoticeSetting::where('id', $id)->find();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 格式化模板数据
|
||||
* @param $post
|
||||
* @author 段誉(2021/4/26 14:55)
|
||||
* @return array
|
||||
*/
|
||||
public static function formatTplData($post)
|
||||
{
|
||||
foreach ($post as &$value) {
|
||||
if (is_array($value)) {
|
||||
$value = array_values($value);
|
||||
}
|
||||
}
|
||||
return form_to_linear($post);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通知记录
|
||||
*/
|
||||
public static function record($get)
|
||||
{
|
||||
$where = [
|
||||
['send_type', '=', $get['send_type']]
|
||||
];
|
||||
|
||||
if(isset($get['content']) && !empty(trim($get['content']))) {
|
||||
$where[] = ['content', 'like', '%' . trim($get['content']) . '%'];
|
||||
}
|
||||
if(isset($get['create_time']) && !empty(trim($get['create_time']))) {
|
||||
$createTimeArr = explode('#', $get['create_time']);
|
||||
$start_time = strtotime(trim($createTimeArr[0]));
|
||||
$end_time = strtotime(trim($createTimeArr[1]));
|
||||
$where[] = ['create_time', '>=', $start_time];
|
||||
$where[] = ['create_time', '<=', $end_time];
|
||||
}
|
||||
|
||||
$scene = Db::name('dev_notice_setting')->where(['id'=>$get['id']])->value('scene');
|
||||
$where[] = ['scene', '=', $scene];
|
||||
|
||||
$lists = Db::name('notice')
|
||||
->where($where)
|
||||
->page($get['page'], $get['limit'])
|
||||
->order('create_time', 'desc')
|
||||
->select();
|
||||
$count = Db::name('notice')->where($where)->count();
|
||||
foreach($lists as &$item) {
|
||||
$item['sceneDesc'] = NoticeSetting::getSceneDesc($item['scene']);
|
||||
$item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
|
||||
switch ($item['receive_type']) {
|
||||
case 1: // 平台
|
||||
$item['userInfo'] = '平台';
|
||||
break;
|
||||
case 2:
|
||||
$user = Db::name('user')->field('sn,nickname')->where('id',$item['user_id'])->find();
|
||||
$item['userInfo'] = $user;
|
||||
break;
|
||||
case 3:
|
||||
$item['userInfo'] = '游客';
|
||||
break;
|
||||
}
|
||||
}
|
||||
return [
|
||||
'count' => $count,
|
||||
'lists' => $lists
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\logic;
|
||||
use app\common\logic\LogicBase;
|
||||
use app\common\server\ConfigServer;
|
||||
use app\common\server\UrlServer;
|
||||
use app\common\server\WeChatServer;
|
||||
use EasyWeChat\Factory;
|
||||
use EasyWeChat\Kernel\Exceptions\Exception;
|
||||
|
||||
class OaLogic extends LogicBase{
|
||||
public static function getOa(){
|
||||
$domain_name = $_SERVER['SERVER_NAME'];
|
||||
$qr_code = ConfigServer::get('oa', 'qr_code', '');
|
||||
$config = [
|
||||
'name' => ConfigServer::get('oa', 'name', ''),
|
||||
'original_id' => ConfigServer::get('oa', 'original_id', ''),
|
||||
'qr_code' => $qr_code,
|
||||
'abs_qr_code' => UrlServer::getFileUrl($qr_code),
|
||||
'app_id' => ConfigServer::get('oa', 'app_id', ''),
|
||||
'app_secret' => ConfigServer::get('oa', 'secret', ''),
|
||||
'url' => url('api/weChat/index','','',true),
|
||||
'token' => ConfigServer::get('oa', 'token', 'LikeShop'),
|
||||
'encoding_ses_key' => ConfigServer::get('oa', 'encoding_ses_key', ''),
|
||||
'encryption_type' => ConfigServer::get('oa', 'encryption_type', 1),
|
||||
'business_domain' => $domain_name,
|
||||
'safety_domain' => $domain_name,
|
||||
'auth_domain' => $domain_name,
|
||||
];
|
||||
return $config;
|
||||
}
|
||||
public static function setOa($post){
|
||||
if($post){
|
||||
if(!isset($post['encryption_type'])){
|
||||
$post['encryption_type'] = '';
|
||||
}
|
||||
ConfigServer::set('oa','name',$post['name']);
|
||||
ConfigServer::set('oa','original_id',$post['original_id']);
|
||||
ConfigServer::set('oa','qr_code',$post['qr_code']);
|
||||
ConfigServer::set('oa','app_id',$post['app_id']);
|
||||
ConfigServer::set('oa','secret',$post['app_secret']);
|
||||
ConfigServer::set('oa','token',$post['token']);
|
||||
ConfigServer::set('oa','encoding_ses_key',$post['encoding_ses_key']);
|
||||
ConfigServer::set('oa','encryption_type',$post['encryption_type']);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static function pulishMenu($buttons){
|
||||
try {
|
||||
$config = WeChatServer::getOaConfig();
|
||||
|
||||
if(empty($config['app_id']) || empty($config['secret'])){
|
||||
return self::dataError('请先配置微信公众号参数');
|
||||
}
|
||||
|
||||
$app = Factory::officialAccount($config);
|
||||
|
||||
$result = $app->menu->create($buttons);
|
||||
|
||||
if($result['errcode'] == 0){
|
||||
|
||||
ConfigServer::set('menu','wechat_menu',$buttons);
|
||||
return self::dataSuccess('菜单发布成功');
|
||||
}
|
||||
return self::dataError('菜单发布失败:'.json_encode($result));
|
||||
|
||||
} catch (Exception $e){
|
||||
return self::dataError($e->getMessage());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
use app\common\logic\LogicBase;
|
||||
use app\common\model\MessageScene_;
|
||||
use app\common\server\WeChatServer;
|
||||
use EasyWeChat\Factory;
|
||||
use think\Db;
|
||||
|
||||
class OaMessageLogic extends LogicBase
|
||||
{
|
||||
|
||||
// 获取表
|
||||
public static function lists($get)
|
||||
{
|
||||
$where[] = ['type', '=', 2];
|
||||
|
||||
if(isset($get['disable']) && is_numeric($get['disable'])){
|
||||
$where[] = ['disable', '=', (int)$get['disable']];
|
||||
}
|
||||
|
||||
$count = Db::name('dev_message_template')
|
||||
->where($where)
|
||||
->count();
|
||||
$lists = Db::name('dev_message_template')
|
||||
->where($where)
|
||||
->page($get['page'],$get['limit'])
|
||||
->select();
|
||||
|
||||
$scene = (new MessageScene_());
|
||||
foreach ($lists as &$item) {
|
||||
$item['scene'] = $scene->getName($item['scene']);
|
||||
}
|
||||
|
||||
return ['count' => $count,'list' => $lists];
|
||||
}
|
||||
|
||||
// 获取单个消息模板
|
||||
public static function getTemplateMessage($id)
|
||||
{
|
||||
return Db::name('dev_message_template')->where(['id' => (int)$id])->find();
|
||||
}
|
||||
|
||||
// 更新消息模板状态
|
||||
public static function switchStatus($data)
|
||||
{
|
||||
$update_data = [
|
||||
'disable' => $data['disable']
|
||||
];
|
||||
return Db::name('dev_message_template')->where(['id' => (int)$data['id']])->update($update_data);
|
||||
}
|
||||
|
||||
// 同步消息模板到公众号
|
||||
public static function synchro($data)
|
||||
{
|
||||
try {
|
||||
$model = Db::name('dev_message_template')->where(['id' => (int)$data['id']])->find();
|
||||
// 发起同步到公众号
|
||||
$config = WeChatServer::getOaConfig();
|
||||
$app = Factory::officialAccount($config);
|
||||
$result = $app->template_message->addTemplate($model['template_id_short']);
|
||||
|
||||
// 保存返回的template_id
|
||||
if ($result['errcode'] === 0 && isset($result['template_id'])) {
|
||||
$update_data = ['template_id' => $result['template_id']];
|
||||
Db::name('dev_message_template')->where(['id' => (int)$data['id']])->update($update_data);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\logic;
|
||||
use app\common\server\ConfigServer;
|
||||
|
||||
class OpLogic{
|
||||
public static function getConfig($config_list){
|
||||
$config = [];
|
||||
foreach ($config_list as $config_name){
|
||||
$value = ConfigServer::get('op', $config_name, '');
|
||||
$config[$config_name] = $value;
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
public static function setConfig($config_list){
|
||||
foreach ($config_list as $config_name => $config_value){
|
||||
ConfigServer::set('op',$config_name,$config_value);
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,739 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\common\logic\OrderRefundLogic;
|
||||
use app\common\model\MessageScene_;
|
||||
use app\common\model\NoticeSetting;
|
||||
use app\common\model\Order;
|
||||
use app\common\model\OrderGoods;
|
||||
use app\common\model\OrderLog;
|
||||
use app\common\logic\OrderLogLogic;
|
||||
use app\common\model\Pay;
|
||||
use app\common\model\SelffetchShop;
|
||||
use app\common\model\UserLevel;
|
||||
use app\common\server\ConfigServer;
|
||||
use app\common\server\UrlServer;
|
||||
use app\common\server\YlyPrinter;
|
||||
use expressage\Kd100;
|
||||
use expressage\Kdniao;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Env;
|
||||
use think\facade\Hook;
|
||||
|
||||
class OrderLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* Notes: 列表查询条件
|
||||
* @param $get
|
||||
* @author 段誉(2021/2/1 10:12)
|
||||
* @return array
|
||||
*/
|
||||
public static function getListsCondition($get)
|
||||
{
|
||||
$where = [];
|
||||
$where[] = ['o.del', '=', 0];
|
||||
|
||||
//订单状态
|
||||
if ($get['type'] != '') {
|
||||
$where[] = ['order_status', '=', $get['type']];
|
||||
}
|
||||
|
||||
//订单搜素
|
||||
if (!empty($get['search_key']) && !empty($get['keyword'])) {
|
||||
$keyword = $get['keyword'];
|
||||
switch ($get['search_key']) {
|
||||
case 'order_sn':
|
||||
$where[] = ['o.order_sn', 'like', '%' . $keyword . '%'];
|
||||
break;
|
||||
case 'user_sn':
|
||||
$where[] = ['u.sn', 'like', '%' . $keyword . '%'];
|
||||
break;
|
||||
case 'nickname':
|
||||
$where[] = ['nickname', 'like', '%' . $keyword . '%'];
|
||||
break;
|
||||
case 'user_mobile':
|
||||
$where[] = ['u.mobile', 'like', '%' . $keyword . '%'];
|
||||
break;
|
||||
case 'consignee':
|
||||
$where[] = ['consignee', 'like', '%' . $keyword . '%'];
|
||||
break;
|
||||
case 'consignee_mobile':
|
||||
$where[] = ['o.mobile', 'like', '%' . $keyword . '%'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//商品名称
|
||||
if (isset($get['goods_name']) && $get['goods_name'] != '') {
|
||||
$where[] = ['g.goods_name', 'like', '%' . $get['goods_name'] . '%'];
|
||||
}
|
||||
|
||||
//付款方式
|
||||
if (isset($get['pay_way']) && $get['pay_way'] != '') {
|
||||
$where[] = ['o.pay_way', '=', $get['pay_way']];
|
||||
}
|
||||
|
||||
//配送方式
|
||||
if (isset($get['delivery_type']) && $get['delivery_type'] != '') {
|
||||
$where[] = ['o.delivery_type', '=', $get['delivery_type']];
|
||||
}
|
||||
|
||||
//订单类型
|
||||
if (isset($get['order_type']) && $get['order_type'] != '') {
|
||||
$where[] = ['o.order_type', '=', $get['order_type']];
|
||||
}
|
||||
|
||||
//订单来源
|
||||
if (isset($get['order_source']) && $get['order_source'] != '') {
|
||||
$where[] = ['o.order_source', '=', $get['order_source']];
|
||||
}
|
||||
|
||||
//下单时间
|
||||
if (isset($get['start_time']) && $get['start_time'] != '') {
|
||||
$where[] = ['o.create_time', '>=', strtotime($get['start_time'])];
|
||||
}
|
||||
if (isset($get['end_time']) && $get['end_time'] != '') {
|
||||
$where[] = ['o.create_time', '<=', strtotime($get['end_time'])];
|
||||
}
|
||||
|
||||
return $where;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 列表
|
||||
* @param $get
|
||||
* @author 段誉(2021/2/1 10:12)
|
||||
* @return array
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
$order = new Order();
|
||||
$where = self::getListsCondition($get);
|
||||
|
||||
$field = 'o.*,order_status as order_status_text,pay_way as pay_way_text';
|
||||
|
||||
$count = $order
|
||||
->alias('o')
|
||||
->field($field)
|
||||
->join('user u', 'u.id = o.user_id')
|
||||
->join('order_goods g', 'g.order_id = o.id')
|
||||
->with(['order_goods', 'user.level'])
|
||||
->where($where)
|
||||
->group('o.id')
|
||||
->count();
|
||||
|
||||
$lists = $order
|
||||
->alias('o')
|
||||
->field($field)
|
||||
->join('user u', 'u.id = o.user_id')
|
||||
->join('order_goods g', 'g.order_id = o.id')
|
||||
->with(['order_goods', 'user.level'])
|
||||
->where($where)
|
||||
->append(['delivery_address', 'pay_status_text', 'order_type_text', 'user.base_avatar', 'order_source_text'])
|
||||
->page($get['page'], $get['limit'])
|
||||
->order('o.id desc')
|
||||
->group('o.id')
|
||||
->select()->toArray();
|
||||
|
||||
foreach ($lists as &$list){
|
||||
foreach ($list['order_goods'] as &$order_goods){
|
||||
$order_good_info = json_decode($order_goods['goods_info'], true);
|
||||
$order_goods['goods_name'] = $order_good_info['goods_name'];
|
||||
$order_goods['spec_value'] = $order_good_info['spec_value_str'];
|
||||
$order_goods['image'] = empty($order_good_info['spec_image']) ?
|
||||
UrlServer::getFileUrl($order_good_info['image']) : UrlServer::getFileUrl($order_good_info['spec_image']);
|
||||
}
|
||||
$list['delivery_type_desc'] = Order::getDeliveryType($list['delivery_type']);
|
||||
$list['user_level'] = $list['user']['level']['name'] ?? '无等级';
|
||||
|
||||
if ($list['delivery_type'] == 2) {
|
||||
$list['shop_name'] = SelffetchShop::where('id',$list['selffetch_shop_id'])->value('name');
|
||||
}
|
||||
}
|
||||
return ['count' => $count, 'lists' => $lists];
|
||||
}
|
||||
|
||||
public static function exportFile($get)
|
||||
{
|
||||
$where[] = ['o.del', '=', 0];
|
||||
|
||||
//订单状态
|
||||
if ($get['type'] != '') {
|
||||
$where[] = ['order_status', '=', $get['type']];
|
||||
}
|
||||
|
||||
//订单搜素
|
||||
if (!empty($get['search_key']) && !empty($get['keyword'])) {
|
||||
$keyword = $get['keyword'];
|
||||
switch ($get['search_key']) {
|
||||
case 'order_sn':
|
||||
$where[] = ['o.order_sn', 'like', '%' . $keyword . '%'];
|
||||
break;
|
||||
case 'user_sn':
|
||||
$where[] = ['u.sn', 'like', '%' . $keyword . '%'];
|
||||
break;
|
||||
case 'nickname':
|
||||
$where[] = ['nickname', 'like', '%' . $keyword . '%'];
|
||||
break;
|
||||
case 'user_mobile':
|
||||
$where[] = ['u.mobile', 'like', '%' . $keyword . '%'];
|
||||
break;
|
||||
case 'consignee':
|
||||
$where[] = ['consignee', 'like', '%' . $keyword . '%'];
|
||||
break;
|
||||
case 'consignee_mobile':
|
||||
$where[] = ['o.mobile', 'like', '%' . $keyword . '%'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//商品名称
|
||||
if (isset($get['goods_name']) && $get['goods_name'] != '') {
|
||||
$where[] = ['g.name', 'like', '%' . $get['goods_name'] . '%'];
|
||||
}
|
||||
|
||||
//付款方式
|
||||
if (isset($get['pay_way']) && $get['pay_way'] != '') {
|
||||
$where[] = ['o.pay_way', '=', $get['pay_way']];
|
||||
}
|
||||
|
||||
//配送方式
|
||||
if (isset($get['delivery_type']) && $get['delivery_type'] != '') {
|
||||
$where[] = ['o.delivery_type', '=', $get['delivery_type']];
|
||||
}
|
||||
|
||||
//订单类型
|
||||
if (isset($get['order_type']) && $get['order_type'] != '') {
|
||||
$where[] = ['o.order_type', '=', $get['order_type']];
|
||||
}
|
||||
|
||||
//订单来源
|
||||
if (isset($get['order_source']) && $get['order_source'] != '') {
|
||||
$where[] = ['o.order_source', '=', $get['order_source']];
|
||||
}
|
||||
|
||||
//下单时间
|
||||
if (isset($get['start_time']) && $get['start_time'] != '') {
|
||||
$where[] = ['o.create_time', '>=', strtotime($get['start_time'])];
|
||||
}
|
||||
if (isset($get['end_time']) && $get['end_time'] != '') {
|
||||
$where[] = ['o.create_time', '<=', strtotime($get['end_time'])];
|
||||
}
|
||||
|
||||
$field = 'o.*,o.order_type as order_type_text, o.order_source as order_source_text,o.pay_way as pay_way_text,address as delivery_address,o.pay_status as pay_status_text,o.order_status as order_status_text,u.sn as user_sn,u.nickname as user_nickname,u.level as user_level';
|
||||
|
||||
$lists = Order::alias('o')
|
||||
->join('user u','u.id=o.user_id')
|
||||
->join('order_goods og', 'og.order_id=o.id')
|
||||
->join('goods g', 'g.id=og.goods_id')
|
||||
->with('order_goods')
|
||||
->field($field)
|
||||
->where($where)
|
||||
->order('o.id', 'desc')
|
||||
->group('og.order_id')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$userLevel = UserLevel::where('del', 0)->column(['id','name'], 'id');
|
||||
|
||||
$exportTitle = ['订单编号', '订单类型', '下单时间', '支付时间', '订单来源', '会员编号', '会员昵称', '会员等级', '商品信息', '商品数量', '运费金额', '商品总金额', '优惠金额', '应付金额', '支付方式', '收货人', '手机号码', '收货地址', '配送方式', '支付状态', '订单状态'];
|
||||
$exportExt = 'xls';
|
||||
$exportData = [];
|
||||
foreach ($lists as $item){
|
||||
// halt($item);
|
||||
$orderSn = 'SN'.$item['order_sn']; // 转字符串
|
||||
$level = isset($userLevel[$item['user_level']]) ? $userLevel[$item['user_level']] : '无等级';
|
||||
$deliveryType = Order::getDeliveryType($item['delivery_type']);
|
||||
$goodsStr = '';
|
||||
foreach($item['order_goods'] as $subItem) {
|
||||
$goodsInfo = json_decode($subItem['goods_info'], true);
|
||||
$goodsStr.= '【'.$goodsInfo['goods_name'].' 规格:'.$goodsInfo['spec_value_str']. ' 数量:'.$subItem['goods_num']. '】';
|
||||
}
|
||||
$exportData[] = [$orderSn, $item['order_type_text'], $item['create_time'], $item['pay_time'], $item['order_source_text'], $item['user_sn'], $item['user_nickname'], $level, $goodsStr,$item['total_num'], $item['shipping_price'], $item['goods_price'], $item['discount_amount'], $item['order_amount'], $item['pay_way_text'], $item['consignee'], $item['mobile'], $item['delivery_address'],$deliveryType, $item['pay_status_text'], $item['order_status_text']];
|
||||
}
|
||||
return ['exportTitle'=> $exportTitle, 'exportData' => $exportData, 'exportExt'=>$exportExt, 'exportName'=>'订单列表'.date('Y-m-d H:i:s')];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 详情
|
||||
* @param $id
|
||||
* @author 段誉(2021/2/1 10:12)
|
||||
* @return Order
|
||||
*/
|
||||
public static function getDetail($id)
|
||||
{
|
||||
$order = new Order();
|
||||
$result = $order
|
||||
->with(['user', 'order_goods'])
|
||||
->where('id', $id)
|
||||
->append(['delivery_address', 'pay_status_text', 'order_status_text', 'pay_way_text', 'order_type_text'])
|
||||
->find();
|
||||
|
||||
$result['user']['avatar'] = UrlServer::getFileUrl($result['user']['avatar']);
|
||||
foreach ($result['order_goods'] as &$order_goods) {
|
||||
$info = json_decode($order_goods['goods_info'], true);
|
||||
$order_goods['goods_name'] = $info['goods_name'];
|
||||
$order_goods['spec_value'] = $info['spec_value_str'];
|
||||
$order_goods['goods_image'] = empty($info['spec_image']) ?
|
||||
UrlServer::getFileUrl($info['image']) : UrlServer::getFileUrl($info['spec_image']);
|
||||
|
||||
$order_goods['refund_status_desc'] = OrderGoods::getRefundStatus($order_goods['refund_status']);
|
||||
}
|
||||
|
||||
$result['shop_name'] = SelffetchShop::where('id',$result['selffetch_shop_id'])->value('name');
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 取消订单(返回商品规格表库存)
|
||||
* @param $order_id
|
||||
* @param $admin_id
|
||||
* @author 段誉(2021/2/1 10:12)
|
||||
*/
|
||||
public static function cancel($order_id, $admin_id)
|
||||
{
|
||||
Db::startTrans();
|
||||
try{
|
||||
$order = Order::get(['id' => $order_id], ['orderGoods']);
|
||||
//取消订单
|
||||
OrderRefundLogic::cancelOrder($order_id, OrderLog::TYPE_SHOP, $admin_id);
|
||||
//已支付的订单,取消,退款
|
||||
if ($order['pay_status'] == Pay::ISPAID) {
|
||||
//更新订单状态
|
||||
OrderRefundLogic::cancelOrderRefundUpdate($order);
|
||||
//订单退款
|
||||
OrderRefundLogic::refund($order, $order['order_amount'], $order['order_amount']);
|
||||
}
|
||||
Db::commit();
|
||||
|
||||
return true;
|
||||
|
||||
} catch(\Exception $e) {
|
||||
Db::rollback();
|
||||
//增加退款失败记录
|
||||
OrderRefundLogic::addErrorRefund($order, $e->getMessage());
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 删除已取消的订单
|
||||
* @param $order_id
|
||||
* @param $admin_id
|
||||
* @author 段誉(2021/2/1 10:14)
|
||||
*/
|
||||
public static function del($order_id, $admin_id)
|
||||
{
|
||||
$order = Order::get(['del' => 0, 'id' => $order_id]);
|
||||
$order->save(['del' => 1, 'update_time' => time()]);
|
||||
|
||||
//订单日志
|
||||
OrderLogLogic::record(
|
||||
OrderLog::TYPE_SHOP,
|
||||
OrderLog::SHOP_DEL_ORDER,
|
||||
$order_id,
|
||||
$admin_id,
|
||||
OrderLog::SHOP_DEL_ORDER
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 物流公司
|
||||
* @author 段誉(2021/2/1 10:15)
|
||||
* @return array|\PDOStatement|string|\think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function express()
|
||||
{
|
||||
return Db::name('express')->where('del', 0)->select();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 发货操作
|
||||
* @param $data
|
||||
* @param $admin_id
|
||||
* @author 段誉(2021/2/1 10:15)
|
||||
* @return bool
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function deliveryHandle($data, $admin_id)
|
||||
{
|
||||
$order_id = $data['order_id'];
|
||||
$order = Order::get(['del' => 0, 'id' => $order_id], ['order_goods']);
|
||||
|
||||
if ($order['shipping_status'] == 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$shipping = Db::name('express')->where('id', $data['shipping_id'])->find();
|
||||
|
||||
//添加发货单
|
||||
$delivery_data = [
|
||||
'order_id' => $order_id,
|
||||
'order_sn' => $order['order_sn'],
|
||||
'user_id' => $order['user_id'],
|
||||
'admin_id' => $admin_id,
|
||||
'consignee' => $order['consignee'],
|
||||
'mobile' => $order['mobile'],
|
||||
'province' => $order['province'],
|
||||
'city' => $order['city'],
|
||||
'district' => $order['district'],
|
||||
'address' => $order['address'],
|
||||
'invoice_no' => $data['invoice_no'],
|
||||
'send_type' => $data['send_type'],
|
||||
'create_time' => time(),
|
||||
];
|
||||
//配送方式->快递配送
|
||||
if ($data['send_type'] == 1) {
|
||||
$delivery_data['shipping_id'] = $data['shipping_id'];
|
||||
$delivery_data['shipping_name'] = $shipping['name'];
|
||||
$delivery_data['shipping_status'] = 1;
|
||||
}
|
||||
$delivery_id = Db::name('delivery')->insertGetId($delivery_data);
|
||||
|
||||
//更新订单下商品的发货状态
|
||||
$order->update_time = time();
|
||||
$order->shipping_time = time();
|
||||
$order->shipping_status = 1;
|
||||
$order->order_status = Order::STATUS_WAIT_RECEIVE;
|
||||
$order->delivery_id = $delivery_id;
|
||||
$order->save();
|
||||
|
||||
//订单日志
|
||||
OrderLogLogic::record(
|
||||
OrderLog::TYPE_SHOP,
|
||||
OrderLog::SHOP_DELIVERY_ORDER,
|
||||
$order_id,
|
||||
$admin_id,
|
||||
OrderLog::SHOP_DELIVERY_ORDER
|
||||
);
|
||||
|
||||
//发货短信通知
|
||||
if($order->mobile){
|
||||
$nickname = Db::name('user')->where(['id' => $order['user_id']])->value('nickname');
|
||||
$send_data = [
|
||||
'key' => NoticeSetting::ORDER_DELIVERY_NOTICE,
|
||||
'user_id' => $order['user_id'],
|
||||
'mobile' => $order->mobile,
|
||||
'params' => [
|
||||
'order_sn' => $order->order_sn,
|
||||
'nickname' => $nickname,
|
||||
'time' => date('Y-m-d H:i'),
|
||||
'invoice_no' => $data['invoice_no'] ?? '',
|
||||
'shipping_name' => $delivery_data['shipping_name'] ?? '无需快递',
|
||||
'goods_name' => omit_str($order['order_goods'][0]['goods_name'] ?? '商品', 8)
|
||||
],
|
||||
];
|
||||
}
|
||||
Hook::listen('sms_send', $send_data);
|
||||
|
||||
// 赠送成长值和积分
|
||||
Hook::listen('give_reward', [
|
||||
'order_id' => $order['id'],
|
||||
'scene' => 2, //2=发货场景
|
||||
]);
|
||||
|
||||
// 发货模板消息
|
||||
Hook::listen('notice', [
|
||||
'user_id' => $order['user_id'],
|
||||
'order_id' => $order['id'],
|
||||
'scene' => NoticeSetting::ORDER_DELIVERY_NOTICE,
|
||||
'shipping_name' => $delivery_data['shipping_name'] ?? '无需快递',
|
||||
'invoice_no' => $data['invoice_no'] ?? '',
|
||||
'time' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 确认收货
|
||||
* @param $order_id
|
||||
* @param $admin_id
|
||||
* @author 段誉(2021/2/1 10:16)
|
||||
*/
|
||||
public static function confirm($order_id, $admin_id)
|
||||
{
|
||||
$order = Order::get(['del' => 0, 'id' => $order_id]);
|
||||
$order->order_status = Order::STATUS_FINISH;
|
||||
$order->update_time = time();
|
||||
$order->confirm_take_time = time();
|
||||
$order->save();
|
||||
|
||||
// 赠送成长值和积分
|
||||
Hook::listen('give_reward', [
|
||||
'order_id' => $order_id,
|
||||
'scene' => 3, //3=订单完成
|
||||
]);
|
||||
|
||||
//订单日志
|
||||
OrderLogLogic::record(
|
||||
OrderLog::TYPE_SHOP,
|
||||
OrderLog::SHOP_CONFIRM_ORDER,
|
||||
$order_id,
|
||||
$admin_id,
|
||||
OrderLog::SHOP_CONFIRM_ORDER
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 物流信息
|
||||
* @param $order_id
|
||||
* @author 段誉(2021/2/1 10:16)
|
||||
* @return array|\PDOStatement|string|\think\Model|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function shippingInfo($order_id)
|
||||
{
|
||||
$shipping = Db::name('delivery')->where('order_id', $order_id)->find();
|
||||
if ($shipping) {
|
||||
$shipping['create_time_text'] = date('Y-m-d H:i:s', $shipping['create_time']);
|
||||
}
|
||||
$shipping['traces'] = self::getShipping($order_id);
|
||||
return $shipping;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 物流轨迹
|
||||
* @param $order_id
|
||||
* @author 段誉(2021/2/1 10:16)
|
||||
* @return array|bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function getShipping($order_id)
|
||||
{
|
||||
$orderModel = new Order();
|
||||
$order = $orderModel->alias('o')
|
||||
->field('invoice_no,shipping_name,shipping_id,o.shipping_status,o.mobile')
|
||||
->join('delivery d', 'd.order_id = o.id')
|
||||
->where(['o.id' => $order_id])
|
||||
->find();
|
||||
|
||||
$express = ConfigServer::get('express', 'way', '', '');
|
||||
$app = ConfigServer::get($express, 'appkey', '', '');
|
||||
$key = ConfigServer::get($express, 'appsecret', '', '');
|
||||
|
||||
if (empty($express) || $order['shipping_status'] != 1 || empty($app) || empty($key)) {
|
||||
return $traces[] = ['暂无物流信息'];
|
||||
}
|
||||
|
||||
//快递配置设置为快递鸟时
|
||||
if($express === 'kdniao') {
|
||||
$expressage = (new Kdniao($key, $app, Env::get('app.app_debug', 'true')));
|
||||
$shipping_field = 'codebird';
|
||||
} else {
|
||||
$expressage = (new Kd100($key, $app, Env::get('app.app_debug', 'true')));
|
||||
$shipping_field = 'code100';
|
||||
}
|
||||
|
||||
//快递编码
|
||||
$shipping_code = Db::name('express')
|
||||
->where(['id' => $order['shipping_id']])
|
||||
->value($shipping_field);
|
||||
|
||||
//获取物流轨迹
|
||||
if (in_array(strtolower($shipping_code ), [ 'sf', 'shunfeng' ])) {
|
||||
if ($express === 'kdniao') {
|
||||
$expressage->logistics($shipping_code, $order['invoice_no'], substr($order['mobile'],-4));
|
||||
} else {
|
||||
$expressage->logistics($shipping_code, $order['invoice_no'], $order['mobile']);
|
||||
}
|
||||
}else {
|
||||
$expressage->logistics($shipping_code, $order['invoice_no']);
|
||||
}
|
||||
|
||||
$traces = $expressage->logisticsFormat();
|
||||
if ($traces == false) {
|
||||
$traces[] = [$expressage->getError()];
|
||||
} else {
|
||||
foreach ($traces as &$item) {
|
||||
$item = array_values(array_unique($item));
|
||||
}
|
||||
}
|
||||
return $traces;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 订单备注
|
||||
* @param $post
|
||||
* @param string $type
|
||||
* @return int|string
|
||||
* @throws \think\Exception
|
||||
* @throws \think\exception\PDOException
|
||||
* @author 张无忌(2021/2/1 18:50)
|
||||
*/
|
||||
public static function remarks($post, $type="get")
|
||||
{
|
||||
if ($type==='get') {
|
||||
|
||||
return Db::name('order')->field('id,order_remarks')
|
||||
->where(['id'=>$post['id']])
|
||||
->findOrEmpty();
|
||||
} else {
|
||||
return Db::name('order')
|
||||
->where(['id'=>$post['id']])
|
||||
->update(['order_remarks'=>$post['order_remarks']]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:打印接口
|
||||
* @param $id int 订单id
|
||||
* @return string
|
||||
*/
|
||||
public static function orderPrint($id){
|
||||
try {
|
||||
|
||||
//打印机配置
|
||||
$printer_config = Db::name('printer_config')->where(['status'=>1])->find();
|
||||
//打印机列表
|
||||
$printer_list = Db::name('printer')->where(['type'=>$printer_config['id'],'status'=>1,'del'=>0])->select();
|
||||
|
||||
if(empty($printer_config) || empty($printer_list)){
|
||||
throw new Exception('请先配置打印机');
|
||||
}
|
||||
$yly_print = new YlyPrinter($printer_config['client_id'],$printer_config['client_secret']);
|
||||
$order = self::getPrintOrder($id);
|
||||
$template_config = ConfigServer::get('printer', 'yly_template', []);
|
||||
$yly_print->ylyPrint($printer_list,$order,$template_config);
|
||||
|
||||
}catch (\Exception $e){
|
||||
|
||||
$msg = json_decode($e->getMessage(),true);
|
||||
if($msg && isset($msg['error'])){
|
||||
return '易联云:'.$msg['error_description'];
|
||||
}
|
||||
if(18 === $e->getCode()){
|
||||
//todo token过期重新拿
|
||||
Cache::rm('yly_access_token');
|
||||
Cache::rm('yly_refresh_token');
|
||||
};
|
||||
return '易联云:'.$e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取订单信息
|
||||
* @param $id
|
||||
* @return array
|
||||
* @author cjhao
|
||||
* @date 2021/9/26 11:43
|
||||
*/
|
||||
public static function getPrintOrder($id){
|
||||
$order = new Order();
|
||||
$result = $order
|
||||
->with(['user', 'order_goods'])
|
||||
->where('id', $id)
|
||||
->append(['delivery_address'])
|
||||
->find();
|
||||
$selffetch_shop = [];
|
||||
if(Order::DELIVERY_STATUS_SELF == $result->delivery_type){
|
||||
$selffetch_shop = SelffetchShop::where(['id'=>$result->selffetch_shop_id])
|
||||
->field('id,name,province,city,district,address')
|
||||
->append(['shop_address'])
|
||||
->find();
|
||||
}
|
||||
$result->selffetch_shop = $selffetch_shop;
|
||||
foreach ($result['order_goods'] as &$order_goods) {
|
||||
$info = json_decode($order_goods['goods_info'], true);
|
||||
$order_goods['name'] = $info['goods_name'];
|
||||
$order_goods['spec_value_str'] = $info['spec_value_str'];
|
||||
$order_goods['goods_image'] = empty($info['spec_image']) ? $info['image'] : $info['spec_image'];
|
||||
}
|
||||
return $result->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取发货单
|
||||
* @param $get
|
||||
* @return array|\PDOStatement|string|\think\Model|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
* @author suny
|
||||
* @date 2021/11/08 16:06 下午
|
||||
*/
|
||||
public static function getDelivery($get)
|
||||
{
|
||||
return Db::name('delivery')
|
||||
->where(['order_id' => $get['id']])
|
||||
->find();
|
||||
}
|
||||
/**
|
||||
* @notes 修改物流信息
|
||||
* @param $get
|
||||
* @return array|string|\think\Model|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
* @author suny
|
||||
* @date 2021/11/08 16:07 下午
|
||||
*/
|
||||
public static function changeDelivery($post)
|
||||
{
|
||||
$delivery = Db::name('delivery')
|
||||
->where(['id' => $post['id']])
|
||||
->find();
|
||||
if(!$delivery){
|
||||
return false;
|
||||
}
|
||||
$express = Db::name('express')
|
||||
->where(['id' => $post['shipping_id']])
|
||||
->find();
|
||||
|
||||
$data = [
|
||||
'shipping_id' => $post['shipping_id'],
|
||||
'shipping_name' => $express['name'],
|
||||
'invoice_no' => $post['invoice_no'],
|
||||
];
|
||||
Db::name('delivery')
|
||||
->where(['id' => $post['id']])
|
||||
->update($data);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\common\model\Pay;
|
||||
use think\Db;
|
||||
|
||||
class PayConfigLogic
|
||||
{
|
||||
|
||||
public static function lists()
|
||||
{
|
||||
$payModel = new Pay();
|
||||
$count = $payModel->count();
|
||||
$lists = $payModel->order('sort')->select();
|
||||
$lists->append(['status_text']);
|
||||
return ['list' => $lists, 'count' => $count];
|
||||
}
|
||||
|
||||
|
||||
public static function info($pay_code)
|
||||
{
|
||||
$payModel = new Pay();
|
||||
$result = $payModel->where(['code' => $pay_code])->append(['status_text'])->find();
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 余额支付
|
||||
* @param $post
|
||||
* @author 段誉(2021/3/10 11:42)
|
||||
* @return bool
|
||||
*/
|
||||
public static function editBalance($post)
|
||||
{
|
||||
$payModel = new Pay();
|
||||
return $payModel->allowField(true)->save($post, ['code' => 'balance']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 微信支付
|
||||
* @param $post
|
||||
* @author 段誉(2021/3/10 10:30)
|
||||
* @return bool
|
||||
*/
|
||||
public static function editWechat($post)
|
||||
{
|
||||
$config = [
|
||||
'pay_sign_key' => $post['pay_sign_key'],
|
||||
'mch_id' => $post['mch_id'],
|
||||
'apiclient_cert' => $post['apiclient_cert'],
|
||||
'apiclient_key' => $post['apiclient_key']
|
||||
];
|
||||
$post['config'] = json_encode($config, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
$payModel = new Pay();
|
||||
return $payModel->allowField(true)->save($post, ['code' => 'wechat']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 支付宝
|
||||
* @param $post
|
||||
* @author 段誉(2021/3/10 11:43)
|
||||
* @return int|string
|
||||
* @throws \think\Exception
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function editAlipay($post)
|
||||
{
|
||||
$config = [
|
||||
'app_id' => $post['app_id'],
|
||||
'private_key' => $post['private_key'],//应用私钥
|
||||
'ali_public_key' => $post['ali_public_key']//支付宝公钥
|
||||
];
|
||||
$post['config'] = json_encode($config, JSON_UNESCAPED_UNICODE);
|
||||
$payModel = new Pay();
|
||||
return $payModel->allowField(true)->save($post, ['code' => 'alipay']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\common\server\ConfigServer;
|
||||
use think\facade\Env;
|
||||
|
||||
/**
|
||||
* PC商城逻辑层
|
||||
* Class Pc
|
||||
* @package app\admin\logic
|
||||
*/
|
||||
class Pc
|
||||
{
|
||||
/**
|
||||
* @notes 获取PC商城设置
|
||||
* @return array
|
||||
* @author Tab
|
||||
* @date 2021/8/14 14:56
|
||||
*/
|
||||
public static function getConfig()
|
||||
{
|
||||
$config = [
|
||||
'is_open' => ConfigServer::get('pc', 'is_open', 1),
|
||||
'page' => ConfigServer::get('pc', 'page', 1),
|
||||
'page_url' => ConfigServer::get('pc', 'page_url', ''),
|
||||
'pc_url' => request()->domain() . '/pc'
|
||||
];
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes PC商城设置
|
||||
* @param $params
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
* @throws \think\exception\PDOException
|
||||
* @author Tab
|
||||
* @date 2021/8/14 14:57
|
||||
*/
|
||||
public static function set($params)
|
||||
{
|
||||
ConfigServer::set('pc', 'is_open', $params['is_open']);
|
||||
ConfigServer::set('pc', 'page', $params['page']);
|
||||
ConfigServer::set('pc', 'page_url', $params['page_url']);
|
||||
|
||||
// 恢复原入口
|
||||
if(file_exists('./pc/index_lock.html')) {
|
||||
// 存在则原商城入口被修改过,先清除修改后的入口
|
||||
unlink('./pc/index.html');
|
||||
// 恢复原入口
|
||||
rename('./pc/index_lock.html', './pc/index.html');
|
||||
}
|
||||
|
||||
// PC商城关闭 且 显示空白页
|
||||
if($params['is_open'] == 0 && $params['page'] == 1) {
|
||||
// 变更文件名
|
||||
rename('./pc/index.html', './pc/index_lock.html');
|
||||
// 创建新空白文件
|
||||
$newfile = fopen('./pc/index.html', 'w');
|
||||
fclose($newfile);
|
||||
}
|
||||
|
||||
// PC商城关闭 且 跳转指定页
|
||||
if($params['is_open'] == 0 && $params['page'] == 2 && !empty($params['page_url'])) {
|
||||
// 变更文件名
|
||||
rename('./pc/index.html', './pc/index_lock.html');
|
||||
// 创建重定向文件
|
||||
$newfile = fopen('./pc/index.html', 'w');
|
||||
$content = '<script>window.location.href = "' . $params['page_url'] . '";</script>';
|
||||
fwrite($newfile, $content);
|
||||
fclose($newfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,416 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\logic;
|
||||
use app\common\server\ConfigServer;
|
||||
use app\common\server\UrlServer;
|
||||
use app\common\server\YlyPrinter;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Hook;
|
||||
|
||||
class PrinterLogic{
|
||||
|
||||
/**
|
||||
* Notes:打印机列表
|
||||
* @param $get
|
||||
* @return array
|
||||
* @author: cjhao 2021/4/24 14:45
|
||||
*/
|
||||
public static function lists($get){
|
||||
|
||||
switch ($get['type']){
|
||||
case 1:
|
||||
$list = Db::name('printer')
|
||||
->where(['del'=>0])
|
||||
->order('id desc')
|
||||
->select();
|
||||
foreach ($list as $key => $value){
|
||||
$list[$key]['type_name'] = Db::name('printer_config')->where(['id'=>$value['type']])->value('name');
|
||||
$list[$key]['status'] = $value['status'] ? '开启' : '关闭';
|
||||
$list[$key]['auto_print'] = $value['auto_print'] ? '开启' : '关闭';
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
$list = Db::name('printer_config')
|
||||
->where(['del'=>0])
|
||||
->select();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$list = ConfigServer::get('printer', 'yly_template', []);
|
||||
$list['file_url'] = UrlServer::getFileUrl('/');
|
||||
break;
|
||||
}
|
||||
|
||||
return['lists' => $list];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Notes:设置添加打印机
|
||||
* @param $post
|
||||
* @return bool|string
|
||||
* @author: cjhao 2021/4/24 14:45
|
||||
*/
|
||||
public static function add($post){
|
||||
Db::startTrans();
|
||||
try {
|
||||
|
||||
$now = time();
|
||||
$data = [
|
||||
'type' => $post['type'],
|
||||
'name' => $post['name'],
|
||||
'machine_code' => $post['machine_code'],
|
||||
'private_key' => $post['private_key'],
|
||||
'print_number' => $post['print_number'],
|
||||
'auto_print' => $post['auto_print'],
|
||||
'status' => $post['status'],
|
||||
'create_time' => $now,
|
||||
'update_time' => $now,
|
||||
'del' => 0,
|
||||
];
|
||||
Db::name('printer')->insert($data);
|
||||
|
||||
$printer_config = Db::name('printer_config')->where(['id'=>$post['type']])->field('client_id,client_secret')->find();
|
||||
$yly_print = new YlyPrinter($printer_config['client_id'],$printer_config['client_secret']);
|
||||
|
||||
//调用易联云添加打印机
|
||||
$yly_print->addPrinter($post['machine_code'],$post['private_key'],$post['name']);
|
||||
|
||||
//获取打印机状态,设置logo
|
||||
$response = $yly_print->getPrintStatus($post['machine_code']);
|
||||
//打印机在线时,设置logo
|
||||
$yly_template = ConfigServer::get('printer', 'yly_template', []);
|
||||
if(1 == $response->body->state && isset($yly_template['logo'])){
|
||||
|
||||
$yly_print->setIcon($post['machine_code'],UrlServer::getFileUrl($yly_template['logo']));
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
|
||||
|
||||
}catch (\Exception $e){
|
||||
|
||||
|
||||
$msg = json_decode($e->getMessage(),true);
|
||||
if($msg && isset($msg['error'])){
|
||||
return '易联云:'.$msg['error_description'];
|
||||
}
|
||||
if(18 === $e->getCode()){
|
||||
//todo token过期重新拿
|
||||
Cache::rm('yly_access_token');
|
||||
Cache::rm('yly_refresh_token');
|
||||
};
|
||||
Db::rollback();
|
||||
return '易联云:'.$e->getMessage();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Notes:编辑打印机
|
||||
* @param $post
|
||||
* @return bool|string
|
||||
* @author: cjhao 2021/4/24 14:44
|
||||
*/
|
||||
public static function edit($post){
|
||||
Db::startTrans();
|
||||
try {
|
||||
|
||||
$now = time();
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'print_number' => $post['print_number'],
|
||||
'status' => $post['status'],
|
||||
'auto_print' => $post['auto_print'],
|
||||
'update_time' => $now,
|
||||
];
|
||||
Db::name('printer')->where(['id'=>$post['id']])->update($data);
|
||||
|
||||
//调用易联云,更新打印机
|
||||
$printer_config = Db::name('printer_config')->where(['id'=>$post['type']])->field('client_id,client_secret')->find();
|
||||
$yly_print = new YlyPrinter($printer_config['client_id'],$printer_config['client_secret']);
|
||||
|
||||
$yly_print->addPrinter($post['machine_code'],$post['private_key'],$post['name']);
|
||||
|
||||
//获取打印机状态,设置logo
|
||||
$response = $yly_print->getPrintStatus($post['machine_code']);
|
||||
//打印机在线时,设置logo
|
||||
$yly_template = ConfigServer::get('printer', 'yly_template', []);
|
||||
|
||||
if(1 == $response->body->state && isset($yly_template['logo'])){
|
||||
$yly_print->setIcon($post['machine_code'],UrlServer::getFileUrl($yly_template['logo']));
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
|
||||
}catch (\Exception $e){
|
||||
|
||||
|
||||
$msg = json_decode($e->getMessage(),true);
|
||||
|
||||
if($msg && isset($msg['error'])){
|
||||
return '易联云:'.$msg['error_description'];
|
||||
}
|
||||
if(18 === $e->getCode()){
|
||||
//todo token过期重新拿
|
||||
Cache::rm('yly_access_token');
|
||||
Cache::rm('yly_refresh_token');
|
||||
};
|
||||
Db::rollback();
|
||||
return '易联云:'.$e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes:获取打印机配置
|
||||
* @param $id
|
||||
* @return array|\PDOStatement|string|\think\Model|null
|
||||
* @author: cjhao 2021/4/24 14:44
|
||||
*/
|
||||
public static function getPrinter($id){
|
||||
return Db::name('printer')->where(['del'=>0,'id'=>$id])->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:设置配置
|
||||
* @param $post
|
||||
* @return int|string
|
||||
* @author: cjhao 2021/4/24 14:44
|
||||
*/
|
||||
public static function setConfig($post){
|
||||
$post['status'] = isset($post['status']) && $post['status'] == 'on' ? 1 : 0;
|
||||
if($post['status']){
|
||||
Db::name('printer_config')->where(['status'=>1])->update(['status'=>0]);
|
||||
}
|
||||
$update_data = [
|
||||
'client_id' => $post['client_id'],
|
||||
'client_secret' => $post['client_secret'],
|
||||
'update_time' => time(),
|
||||
'status' => $post['status'],
|
||||
];
|
||||
return Db::name('printer_config')->where(['id'=>$post['id']])->update($update_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:获取配置
|
||||
* @param $id
|
||||
* @return array|\PDOStatement|string|\think\Model|null
|
||||
* @author: cjhao 2021/4/24 14:45
|
||||
*/
|
||||
public static function getConfig($id){
|
||||
return Db::name('printer_config')->where(['id'=>$id])->find();
|
||||
}
|
||||
|
||||
/***
|
||||
* Notes:获取打印配置类型
|
||||
* @return array|\PDOStatement|string|\think\Collection
|
||||
* @author: cjhao 2021/4/24 14:44
|
||||
*/
|
||||
public static function getTypeList(){
|
||||
return Db::name('printer_config')->where(['del'=>0])->field('id,name')->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:设置打印模板
|
||||
* @param $post
|
||||
* @return bool|string
|
||||
* @author: cjhao 2021/4/24 14:44
|
||||
*/
|
||||
public static function setTemplate($post){
|
||||
try{
|
||||
|
||||
$printer_config = Db::name('printer_config')->where(['id'=>$post['type']])->field('client_id,client_secret')->find();
|
||||
|
||||
if($post['logo'] && $printer_config){
|
||||
$yly_print = new YlyPrinter($printer_config['client_id'],$printer_config['client_secret']);
|
||||
$printer_list = self::getPrinterList(0);
|
||||
//调用易联云,更新打印机
|
||||
$logo = UrlServer::getFileUrl($post['logo']);
|
||||
|
||||
foreach ($printer_list as $printer){
|
||||
|
||||
//获取打印机状态,设置logo
|
||||
$response = $yly_print->getPrintStatus($printer['machine_code']);
|
||||
|
||||
if(1 == $response->body->state){
|
||||
$yly_print->setIcon($printer['machine_code'],$logo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
ConfigServer::set('printer', 'yly_template', $post);
|
||||
return true;
|
||||
}catch (\Exception $e){
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:获取打印机列表
|
||||
* @param bool $status
|
||||
* @return array
|
||||
* @author: cjhao 2021/4/24 14:43
|
||||
*/
|
||||
public static function getPrinterList($status = false){
|
||||
$where[] = ['del','=',0];
|
||||
$where[] = ['type','=',1];
|
||||
$status && $where[] = ['status','=',1];
|
||||
return Db::name('printer')
|
||||
->where($where)
|
||||
->column('machine_code,private_key,print_number','machine_code');
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:测试打印
|
||||
* @param $post
|
||||
* @return bool|string
|
||||
* @author: cjhao 2021/4/24 14:43
|
||||
*/
|
||||
public static function testPrint($post){
|
||||
try {
|
||||
|
||||
$printer = Db::name('printer')->where(['id'=>$post['id'],'del'=>0])->find();
|
||||
|
||||
$printer_config = Db::name('printer_config')->where(['id'=>$post['type']])->field('client_id,client_secret')->find();
|
||||
$yly_print = new YlyPrinter($printer_config['client_id'],$printer_config['client_secret']);
|
||||
|
||||
//获取打印机状态
|
||||
$response = $yly_print->getPrintStatus($printer['machine_code']);
|
||||
|
||||
if(1 == $response->body->state){
|
||||
$data = static::testData();
|
||||
$template_config = ConfigServer::get('printer', 'yly_template', []);
|
||||
$yly_print->ylyPrint([['machine_code'=>$printer['machine_code'],'print_number'=>$printer['print_number']]],$data,$template_config);
|
||||
return true;
|
||||
}
|
||||
$msg = '打印机离线';
|
||||
|
||||
if(2 == $response->body->state){
|
||||
$msg = '打印机缺纸';
|
||||
}
|
||||
throw new Exception($msg);
|
||||
}catch (\Exception $e){
|
||||
|
||||
|
||||
$msg = json_decode($e->getMessage(),true);
|
||||
if($msg && isset($msg['error'])){
|
||||
return '易联云:'.$msg['error_description'];
|
||||
}
|
||||
if(18 === $e->getCode()){
|
||||
//todo token过期重新拿
|
||||
Cache::rm('yly_access_token');
|
||||
Cache::rm('yly_refresh_token');
|
||||
};
|
||||
return '易联云:'.$e->getMessage();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:测试打印数据
|
||||
* @return array
|
||||
* @author: cjhao 2021/4/24 14:45
|
||||
*/
|
||||
public static function testData(){
|
||||
$order = [
|
||||
'order_sn' => date("Ymd").'88888888888',
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
'delivery_type' => 1,
|
||||
'consignee' => '张先生',
|
||||
'mobile' => '138888888888',
|
||||
'delivery_address' => '广东省广州市天河区XXXX科技园',
|
||||
'user_remark' => '这是用户备注',
|
||||
'order_goods' => [
|
||||
[
|
||||
'name' => 'iPhone 11',
|
||||
'spec_value_str'=> '全网通256G,银色',
|
||||
'goods_num' => '88',
|
||||
'goods_price' => '3689',
|
||||
'total_price' => '88888',
|
||||
],
|
||||
[
|
||||
'name' => '小米手机Plus',
|
||||
'spec_value_str'=> '全网通256G,黑色',
|
||||
'goods_num' => '88',
|
||||
'goods_price' => '3689',
|
||||
'total_price' => '88888',
|
||||
],
|
||||
[
|
||||
'name' => '华为 P40',
|
||||
'spec_value_str'=> '全网通256G,黑色',
|
||||
'goods_num' => '88',
|
||||
'goods_price' => '3689',
|
||||
'total_price' => '88888',
|
||||
],
|
||||
],
|
||||
'selffetch_shop' => [],
|
||||
'total_amount' => '888888', //商品总价
|
||||
'discount_amount' => '80', //优惠金额
|
||||
'shipping_price' => '12', //应付
|
||||
'order_amount' => '222' //应付金额
|
||||
];
|
||||
return $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:删除打印机
|
||||
* @param $id
|
||||
* @return bool|string
|
||||
* @author: cjhao 2021/4/24 14:45
|
||||
*/
|
||||
public static function del($id){
|
||||
Db::startTrans();
|
||||
try {
|
||||
|
||||
Db::name('printer')->where(['id'=>$id])->update(['del'=>1,'update_time'=>time()]);
|
||||
$printer = Db::name('printer')->where(['id'=>$id])->find();
|
||||
$printer_config = Db::name('printer_config')->where(['id'=>$printer['type']])->field('client_id,client_secret')->find();
|
||||
//调用易联云接口,删除打印机
|
||||
$yly_print = new YlyPrinter($printer_config['client_id'],$printer_config['client_secret']);
|
||||
$yly_print->deletePrinter($printer['machine_code']);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
|
||||
}catch (\Exception $e){
|
||||
|
||||
$msg = json_decode($e->getMessage(),true);
|
||||
if($msg && isset($msg['error'])){
|
||||
return '易联云:'.$msg['error_description'];
|
||||
}
|
||||
if(18 === $e->getCode()){
|
||||
//todo token过期重新拿
|
||||
Cache::rm('yly_access_token');
|
||||
Cache::rm('yly_refresh_token');
|
||||
};
|
||||
Db::rollback();
|
||||
return '易联云:'.$e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\logic;
|
||||
use app\common\model\Pay;
|
||||
use think\Db;
|
||||
use think\helper\Time;
|
||||
|
||||
class RechargeLogLogic{
|
||||
public static function lists($get){
|
||||
$where = [];
|
||||
if(isset($get['keyword']) && $get['keyword']){
|
||||
$where[] = [$get['type'],'like','%'.$get['keyword'].'%'];
|
||||
}
|
||||
if(isset($get['order_source']) && $get['order_source']){
|
||||
$where[] = ['order_source','=',$get['order_source']];
|
||||
}
|
||||
if(isset($get['pay_status']) && ($get['pay_status'] == 0 || $get['pay_status'] == 1)){
|
||||
$where[] = ['pay_status','=',$get['pay_status']];
|
||||
}
|
||||
if(isset($get['pay_way']) && $get['pay_way']){
|
||||
$where[] = ['pay_way','=',$get['pay_way']];
|
||||
}
|
||||
if (isset($get['start_time']) && $get['start_time'] && isset($get['end_time']) && $get['end_time']) {
|
||||
$where[] = ['ro.create_time', 'between', [strtotime($get['start_time']), strtotime($get['end_time'])]];
|
||||
}
|
||||
if(isset($get['create_end']) && $get['create_end']!=''){
|
||||
$where[] = ['ro.create_time','<=',strtotime($get['create_end'])];
|
||||
}
|
||||
|
||||
$count = Db::name('recharge_order')->alias('ro')
|
||||
->join('user u','ro.user_id = u.id')
|
||||
->where($where)
|
||||
->count();
|
||||
$list = Db::name('recharge_order')->alias('ro')
|
||||
->join('user u','ro.user_id = u.id')
|
||||
->where($where)
|
||||
->field('ro.id,order_sn,order_amount,give_money,give_integral,give_growth,pay_time,pay_way,pay_status,ro.create_time')
|
||||
->page($get['page'],$get['limit'])
|
||||
->order('ro.id desc')
|
||||
->select();
|
||||
foreach ($list as &$order){
|
||||
$order['order_amount'] = '¥'.$order['order_amount'];
|
||||
$order['pay_way'] = Pay::getPayWay($order['pay_way']);
|
||||
$order['pay_status'] = Pay::getPayStatus($order['pay_status']);
|
||||
if($order['pay_time']){
|
||||
$order['pay_time'] = date('Y-m-d H:i:s',$order['pay_time']);
|
||||
}
|
||||
$order['create_time'] = date('Y-m-d H:i:s',$order['create_time']);
|
||||
}
|
||||
return ['count'=>$count , 'lists'=>$list];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\logic;
|
||||
use app\common\server\ConfigServer;
|
||||
use think\Db;
|
||||
|
||||
class RechargeLogic{
|
||||
public static function templatelists(){
|
||||
$list = Db::name('recharge_template')->where(['del'=>0])->order('id desc')->select();
|
||||
foreach ($list as &$item){
|
||||
$item['money'] && $item['money'] = '¥'.$item['money'];
|
||||
$item['give_money'] && $item['give_money'] = '¥'.$item['give_money'];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
public static function getRechargeConfig(){
|
||||
$config = [
|
||||
'open_racharge' => ConfigServer::get('recharge','open_racharge',0),
|
||||
'give_integral' => ConfigServer::get('recharge', 'give_integral', ''),
|
||||
'give_growth' => ConfigServer::get('recharge', 'give_growth', ''),
|
||||
'min_money' => ConfigServer::get('recharge', 'min_money', ''),
|
||||
];
|
||||
return [$config];
|
||||
}
|
||||
public static function setRecharge($post){
|
||||
ConfigServer::set('recharge','open_racharge',$post['open_racharge']);
|
||||
ConfigServer::set('recharge','give_integral',$post['give_integral']);
|
||||
ConfigServer::set('recharge','give_growth',$post['give_growth']);
|
||||
ConfigServer::set('recharge','min_money', round($post['min_money'], 2));
|
||||
}
|
||||
|
||||
public static function add($post){
|
||||
$new = time();
|
||||
$add_data = [
|
||||
'money' => $post['money'],
|
||||
'give_money' => $post['give_money'],
|
||||
'sort' => $post['sort'],
|
||||
'is_recommend' => $post['is_recommend'],
|
||||
'create_time' => $new,
|
||||
'update_time' => $new,
|
||||
];
|
||||
return Db::name('recharge_template')->insert($add_data);
|
||||
}
|
||||
|
||||
public static function edit($post){
|
||||
$new = time();
|
||||
$update_data = [
|
||||
'money' => $post['money'],
|
||||
'give_money' => $post['give_money'],
|
||||
'sort' => $post['sort'],
|
||||
'is_recommend' => $post['is_recommend'],
|
||||
'update_time' => $new,
|
||||
];
|
||||
return Db::name('recharge_template')->where(['id'=>$post['id']])->update($update_data);
|
||||
}
|
||||
|
||||
public static function getRechargeTemplate($id){
|
||||
return Db::name('recharge_template')->where(['id'=>$id])->find();
|
||||
}
|
||||
|
||||
|
||||
public static function del($id){
|
||||
return Db::name('recharge_template')->where(['id'=>$id])->update(['update_time'=>time(),'del'=>1]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
|
||||
class RoleLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* 角色列表
|
||||
* @return array|\PDOStatement|string|\think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function lists()
|
||||
{
|
||||
$result = Db::name('role_dev_auth_index r')
|
||||
->join('dev_auth m', 'r.menu_auth_id=m.id')
|
||||
->where(['m.del' => 0])
|
||||
->order(['sort' => 'desc'])
|
||||
->field(['m.name' => 'name', 'r.role_id' => 'role_id'])
|
||||
->select();
|
||||
$role_id_menu_auth_names = [];
|
||||
|
||||
foreach ($result as $k => $v) {
|
||||
if (isset($role_id_menu_auth_names[$v['role_id']])) {
|
||||
$role_id_menu_auth_names[$v['role_id']] .= $v['name'] . ',';
|
||||
} else {
|
||||
$role_id_menu_auth_names[$v['role_id']] = $v['name'] . ',';
|
||||
}
|
||||
}
|
||||
|
||||
$lists = Db::name('role')
|
||||
->where(['del' => 0])
|
||||
->select();
|
||||
|
||||
foreach ($lists as $k => $v) {
|
||||
$lists[$k]['auth_str'] = isset($role_id_menu_auth_names[$v['id']]) ? $role_id_menu_auth_names[$v['id']] : '';
|
||||
$lists[$k]['auth_str'] = rtrim($lists[$k]['auth_str'], ',');
|
||||
$lists[$k]['create_time_str'] = date('Y-m-d H:i:s', $v['create_time']);
|
||||
}
|
||||
return $lists;
|
||||
}
|
||||
|
||||
public static function roleInfo($role_id)
|
||||
{
|
||||
return Db::name('role')->where(['id' => $role_id])->field(['id', 'name', 'desc'])->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加角色
|
||||
* @param $post
|
||||
* @return int|string
|
||||
*/
|
||||
public static function addRole($post)
|
||||
{
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'desc' => $post['desc'],
|
||||
'create_time' => time(),
|
||||
];
|
||||
|
||||
try {
|
||||
Db::startTrans();
|
||||
$role_id = Db::name('role')->insertGetId($data);
|
||||
$data = [];
|
||||
$post['auth_ids'] = empty($post['auth_ids'])?[]:$post['auth_ids'];
|
||||
foreach ($post['auth_ids'] as $k => $v) {
|
||||
$data[] = [
|
||||
'role_id' => $role_id,
|
||||
'menu_auth_id' => $v,
|
||||
];
|
||||
}
|
||||
Db::name('role_dev_auth_index')
|
||||
->insertAll($data);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加角色
|
||||
* @param $post
|
||||
* @return int|string
|
||||
* @throws \think\Exception
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function editRole($post)
|
||||
{
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'desc' => $post['desc'],
|
||||
'update_time' => time(),
|
||||
];
|
||||
try {
|
||||
Db::startTrans();
|
||||
Db::name('role')
|
||||
->where(['del' => 0, 'id' => $post['id']])
|
||||
->update($data);
|
||||
$data = [];
|
||||
Db::name('role_dev_auth_index')
|
||||
->where(['role_id' => $post['id']])
|
||||
->delete();
|
||||
$post['auth_ids'] = empty($post['auth_ids'])?[]:$post['auth_ids'];
|
||||
foreach ($post['auth_ids'] as $k => $v) {
|
||||
$data[] = [
|
||||
'role_id' => $post['id'],
|
||||
'menu_auth_id' => $v,
|
||||
];
|
||||
}
|
||||
Db::name('role_dev_auth_index')
|
||||
->insertAll($data);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除成功
|
||||
* @param $role_id
|
||||
* @return int|string
|
||||
* @throws \think\Exception
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function delRole($role_id)
|
||||
{
|
||||
$data = [
|
||||
'del' => 1,
|
||||
'update_time' => time(),
|
||||
];
|
||||
return Db::name('role')->where(['del' => 0, 'id' => $role_id])->update($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取菜单权限树
|
||||
* @param string $role_id
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function authTree($role_id = '')
|
||||
{
|
||||
|
||||
$lists = Db::name('dev_auth')
|
||||
->where(['disable' => 0, 'del' => 0])
|
||||
->select();
|
||||
$pids = Db::name('dev_auth')
|
||||
->where(['disable' => 0, 'type' => 1, 'del' => 0])
|
||||
->column('pid');
|
||||
foreach ($lists as $k => $v) {
|
||||
$lists[$k]['spread'] = in_array($v['id'], $pids) ? true : false;
|
||||
}
|
||||
$menu_auth_ids = [];
|
||||
if ($role_id) {
|
||||
$menu_auth_ids = Db::name('role_dev_auth_index')
|
||||
->where(['role_id' => $role_id])
|
||||
->column('menu_auth_id');
|
||||
}
|
||||
return self::authListToTree($lists, 0, $menu_auth_ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表结构转换成树形结构
|
||||
* @param $lists
|
||||
* @param int $pid
|
||||
* @param array $menu_auth_ids
|
||||
* @return array
|
||||
*/
|
||||
public static function authListToTree($lists, $pid = 0, $menu_auth_ids = [])
|
||||
{
|
||||
$tree = [];
|
||||
foreach ($lists as $k => $v) {
|
||||
if ($v['pid'] == $pid) {
|
||||
$temp['id'] = $v['id'];
|
||||
$temp['field'] = 'auth_ids[' . $v['id'] . ']';
|
||||
$temp['title'] = $v['name'];
|
||||
$temp['children'] = self::authListToTree($lists, $v['id'], $menu_auth_ids);
|
||||
$temp['checked'] = in_array($v['id'], $menu_auth_ids) && empty($temp['children']) ? true : false;
|
||||
$temp['spread'] = $v['spread'];
|
||||
$tree[] = $temp;
|
||||
}
|
||||
}
|
||||
return $tree;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\logic;
|
||||
use app\common\server\UrlServer;
|
||||
use think\Db;
|
||||
|
||||
class SeckillLogic{
|
||||
|
||||
public static function goodsList($get){
|
||||
$where = [];
|
||||
$where[] = ['sg.del','=',0];
|
||||
$where[] = ['g.del','=',0];
|
||||
if(isset($get['name']) && $get['name']) {
|
||||
$where[] = ['name','like','%'.$get['name'].'%'];
|
||||
}
|
||||
|
||||
if(isset($get['seckill_id']) && $get['seckill_id']){
|
||||
$where[] = ['seckill_id','=',$get['seckill_id']];
|
||||
}
|
||||
|
||||
$count = Db::name('seckill_goods sg')
|
||||
->join('goods g','sg.goods_id = g.id')
|
||||
->where($where)
|
||||
->group('goods_id,seckill_id')
|
||||
->count();
|
||||
|
||||
|
||||
$list = Db::name('seckill_goods sg')
|
||||
->join('goods g','sg.goods_id = g.id')
|
||||
->where($where)
|
||||
->group('goods_id,seckill_id')
|
||||
->field('sg.id,seckill_id,goods_id,g.name,g.image,g.max_price,g.min_price,sg.sales_sum')
|
||||
->page($get['page'], $get['limit'])
|
||||
->order('sg.id desc')
|
||||
->select();
|
||||
$goods_ids = array_column($list,'goods_id');
|
||||
$seckill_goods_list = Db::name('seckill_goods')->where(['goods_id'=>$goods_ids])->column('*','id');
|
||||
|
||||
$seckill = Db::name('seckill_time')->where(['del'=>0])->column('*','id');
|
||||
foreach ($list as &$item){
|
||||
$price_array = [];
|
||||
$item['image'] = UrlServer::getFileUrl($item['image']);
|
||||
$item['goods_price'] = '¥'.$item['min_price'];
|
||||
if($item['max_price'] != $item['min_price']){
|
||||
$item['goods_price'] = '¥'.$item['min_price'].' ~ '.'¥'.$item['max_price'];
|
||||
}
|
||||
if(isset($seckill[$item['seckill_id']])){
|
||||
$item['start_time'] = $seckill[$item['seckill_id']]['start_time'];
|
||||
$item['end_time'] = $seckill[$item['seckill_id']]['end_time'];
|
||||
}
|
||||
//该秒杀商品的全部规格
|
||||
$seckill_goods_item = Db::name('seckill_goods')
|
||||
->where(['seckill_id'=>$item['seckill_id'],'goods_id'=>$item['goods_id'],'del'=>0])
|
||||
->column('*','id');
|
||||
|
||||
// 秒杀商品销量
|
||||
$item['sales_sum'] = 0;
|
||||
foreach ($seckill_goods_item as $seckill_id => $seckill_item){
|
||||
if(isset($seckill_goods_list[$seckill_id])){
|
||||
$price_array[] = $seckill_goods_list[$seckill_id]['price'];
|
||||
// 秒杀商品销量
|
||||
$item['sales_sum'] += $seckill_goods_list[$seckill_id]['sales_sum'];
|
||||
}
|
||||
}
|
||||
|
||||
$max_price = max($price_array);
|
||||
$min_price = min($price_array);
|
||||
|
||||
$item['seckill_price'] = '¥'.$max_price;
|
||||
if($max_price != $min_price){
|
||||
$item['seckill_price'] = '¥'.$min_price.' ~ '.'¥'.$max_price;
|
||||
}
|
||||
}
|
||||
|
||||
return ['count' => $count, 'list' => $list];
|
||||
}
|
||||
|
||||
public static function timeList($get){
|
||||
$where = [];
|
||||
$where[] = ['del','=',0];
|
||||
$count = Db::name('seckill_time')->where($where)->count();
|
||||
$list = Db::name('seckill_time')
|
||||
->where($where)
|
||||
->order('start_time asc')
|
||||
->page($get['page'], $get['limit'])
|
||||
->select();
|
||||
foreach ($list as &$item){
|
||||
$item['time'] = $item['start_time'].' ~ '.$item['end_time'];
|
||||
}
|
||||
return ['count' => $count, 'list' => $list];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function addTime($post){
|
||||
$post['create_time'] = time();
|
||||
$post['update_time'] = time();
|
||||
return Db::name('seckill_time')->insert($post);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function editTime($post){
|
||||
$post['update_time'] = time();
|
||||
return Db::name('seckill_time')->where(['id'=>$post['id']])->update($post);
|
||||
}
|
||||
|
||||
public static function addGoods($post){
|
||||
$now = time();
|
||||
$add_data = [];
|
||||
|
||||
foreach ($post['item'] as $item){
|
||||
$add_data[] =[
|
||||
'seckill_id' => $post['seckill_id'],
|
||||
'goods_id' => $item['goods_id'],
|
||||
'item_id' => $item['item_id'],
|
||||
'price' => $item['price'],
|
||||
'create_time' => $now,
|
||||
'sales_sum' => 0,
|
||||
'update_time' => $now,
|
||||
'del' => 0,
|
||||
];
|
||||
}
|
||||
return Db::name('seckill_goods')->insertAll($add_data);
|
||||
}
|
||||
|
||||
public static function editGoods($post){
|
||||
$now = time();
|
||||
|
||||
foreach ($post['item'] as $goods){
|
||||
|
||||
$update_data = [
|
||||
'seckill_id' => $post['seckill_id'],
|
||||
'price' => $goods['price'],
|
||||
'update_time' => $now,
|
||||
];
|
||||
Db::name('seckill_goods')->where(['id'=>$goods['id']])->update($update_data);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function delGoods($id,$seckill_id){
|
||||
$update_data = [
|
||||
'update_time' => time(),
|
||||
'del' => 1,
|
||||
];
|
||||
return Db::name('seckill_goods')->where(['del'=>0,'goods_id'=>$id,'seckill_id'=>$seckill_id])->update($update_data);
|
||||
}
|
||||
|
||||
|
||||
public static function delTime($id){
|
||||
$update_data = [
|
||||
'update_time' => time(),
|
||||
'del' => 1,
|
||||
];
|
||||
Db::name('seckill_time')->where(['id'=>$id])->update($update_data);
|
||||
Db::name('seckill_goods')->where(['del'=>0,'seckill_id'=>$id])->update($update_data);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getTime($id){
|
||||
return Db::name('seckill_time')->where(['del'=>0,'id'=>$id])->find();
|
||||
}
|
||||
|
||||
public static function getTimeAll(){
|
||||
|
||||
$time_list = Db::name('seckill_time')->where(['del'=>0])->order('start_time asc')->select();
|
||||
foreach ($time_list as &$item){
|
||||
$item['time'] = $item['start_time'].' ~ '.$item['end_time'];
|
||||
}
|
||||
return $time_list;
|
||||
}
|
||||
|
||||
public static function getSeckillGoods($id,$seckill_id){
|
||||
$skill_goods = Db::name('seckill_goods sg')
|
||||
->join('goods_item gi','sg.item_id = gi.id')
|
||||
->where(['del'=>0,'sg.goods_id'=>$id,'sg.seckill_id'=>$seckill_id ])
|
||||
->field('sg.*,gi.image,gi.spec_value_str,gi.price as goods_price')
|
||||
->select();
|
||||
|
||||
$goods_id = $skill_goods[0]['goods_id'];
|
||||
$goods = Db::name('goods')->where(['del'=>0,'id'=>$goods_id])->field('image,name')->find();
|
||||
|
||||
foreach ($skill_goods as &$item){
|
||||
$item['name'] = $goods['name'];
|
||||
if(!$item['image']){
|
||||
$item['image'] = $goods['image'];
|
||||
}
|
||||
}
|
||||
|
||||
return $skill_goods;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
use app\common\model\DevRegion;
|
||||
use app\common\model\SelffetchShop;
|
||||
|
||||
class SelffetchShopLogic
|
||||
{
|
||||
/**
|
||||
* @notes 查看自提门店列表
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2021/8/14 6:01 下午
|
||||
*/
|
||||
public static function lists($params)
|
||||
{
|
||||
$where = [];
|
||||
$where[] = ['del', '=', 0];
|
||||
if (isset($params['name']) && !empty($params['name'])) {
|
||||
$where[] = ['name', 'like', '%'.$params['name'].'%'];
|
||||
}
|
||||
if (isset($params['status']) && $params['status'] != '') {
|
||||
$where[] = ['status', '=', $params['status']];
|
||||
}
|
||||
|
||||
$count = SelffetchShop::where($where)->count();
|
||||
|
||||
$lists = SelffetchShop::field('*')
|
||||
->append(['status_desc','shop_address'])
|
||||
->page($params['page'], $params['limit'])
|
||||
->order('id','desc')
|
||||
->where($where)
|
||||
->select();
|
||||
|
||||
if (empty($lists)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
foreach ($lists as &$list) {
|
||||
$list['business_time'] = $list['business_start_time'].'-'.$list['business_end_time'];
|
||||
}
|
||||
|
||||
return ['count' => $count, 'lists' => $lists];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 添加自提门店
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author ljj
|
||||
* @date 2021/8/14 4:28 下午
|
||||
*/
|
||||
public static function add($params)
|
||||
{
|
||||
$selffetch_shop = new SelffetchShop;
|
||||
$selffetch_shop->name = $params['name'];
|
||||
$selffetch_shop->image = $params['image'];
|
||||
$selffetch_shop->contact = $params['contact'];
|
||||
$selffetch_shop->mobile = $params['mobile'];
|
||||
$selffetch_shop->province = $params['province'];
|
||||
$selffetch_shop->city = $params['city'] ?? '';
|
||||
$selffetch_shop->district = $params['district'] ?? '';
|
||||
$selffetch_shop->address = $params['address'];
|
||||
$selffetch_shop->longitude = $params['longitude'];
|
||||
$selffetch_shop->latitude = $params['latitude'];
|
||||
$selffetch_shop->business_start_time = $params['business_start_time'];
|
||||
$selffetch_shop->business_end_time = $params['business_end_time'];
|
||||
$selffetch_shop->weekdays = implode(',',$params['weekdays']);
|
||||
$selffetch_shop->status = $params['status'];
|
||||
$selffetch_shop->remark = $params['remark'] ?? '';
|
||||
$selffetch_shop->create_time = time();
|
||||
return $selffetch_shop->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取地区列表
|
||||
* @return DevRegion[]
|
||||
* @author ljj
|
||||
* @date 2021/8/14 4:27 下午
|
||||
*/
|
||||
public static function getAreaLists()
|
||||
{
|
||||
return DevRegion::field(['name', 'id', 'parent_id as pid', 'level'])->where('level', '>', 0)->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 查看自提门店详情
|
||||
* @param $id
|
||||
* @return SelffetchShop
|
||||
* @author ljj
|
||||
* @date 2021/8/16 11:29 上午
|
||||
*/
|
||||
public static function detail($id)
|
||||
{
|
||||
$detail = SelffetchShop::find($id);
|
||||
$detail['weekdays'] = explode(',',$detail['weekdays']);
|
||||
return $detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 编辑自提门店
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author ljj
|
||||
* @date 2021/8/16 2:16 下午
|
||||
*/
|
||||
public static function edit($params)
|
||||
{
|
||||
$selffetch_shop = SelffetchShop::find($params['id']);
|
||||
$selffetch_shop->name = $params['name'];
|
||||
$selffetch_shop->image = $params['image'];
|
||||
$selffetch_shop->contact = $params['contact'];
|
||||
$selffetch_shop->mobile = $params['mobile'];
|
||||
$selffetch_shop->province = $params['province'];
|
||||
$selffetch_shop->city = $params['city'] ?? '';
|
||||
$selffetch_shop->district = $params['district'] ?? '';
|
||||
$selffetch_shop->address = $params['address'];
|
||||
$selffetch_shop->longitude = $params['longitude'];
|
||||
$selffetch_shop->latitude = $params['latitude'];
|
||||
$selffetch_shop->business_start_time = $params['business_start_time'];
|
||||
$selffetch_shop->business_end_time = $params['business_end_time'];
|
||||
$selffetch_shop->weekdays = implode(',',$params['weekdays']);
|
||||
$selffetch_shop->status = $params['status'];
|
||||
$selffetch_shop->remark = $params['remark'];
|
||||
$selffetch_shop->update_time = time();
|
||||
return $selffetch_shop->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 修改自提门店状态
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author ljj
|
||||
* @date 2021/8/16 2:35 下午
|
||||
*/
|
||||
public static function status($params)
|
||||
{
|
||||
$selffetch_shop = SelffetchShop::find($params['id']);
|
||||
$selffetch_shop->status = $params['status'];
|
||||
$selffetch_shop->update_time = time();
|
||||
return $selffetch_shop->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 删除自提门店
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author ljj
|
||||
* @date 2021/8/16 2:42 下午
|
||||
*/
|
||||
public static function del($params)
|
||||
{
|
||||
$selffetch_shop = SelffetchShop::find($params['id']);
|
||||
$selffetch_shop->del = 1;
|
||||
$selffetch_shop->update_time = time();
|
||||
return $selffetch_shop->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 导出列表
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2021/8/16 2:50 下午
|
||||
*/
|
||||
public static function exportFile($params)
|
||||
{
|
||||
$where = [];
|
||||
$where[] = ['del', '=', 0];
|
||||
if (isset($params['name']) && !empty($params['name'])) {
|
||||
$where[] = ['name', 'like', '%'.$params['name'].'%'];
|
||||
}
|
||||
if (isset($params['status']) && $params['status'] != '') {
|
||||
$where[] = ['status', '=', $params['status']];
|
||||
}
|
||||
|
||||
$lists = SelffetchShop::field('*')
|
||||
->append(['status_desc','shop_address'])
|
||||
->order('id','desc')
|
||||
->where($where)
|
||||
->select();
|
||||
|
||||
$exportTitle = ['门店名称', '联系人', '联系电话', '门店地址', '营业时段', '门店状态', '创建时间'];
|
||||
$exportExt = 'xls';
|
||||
$exportData = [];
|
||||
foreach ($lists as $item){
|
||||
$exportData[] = [$item['name'], $item['contact'], $item['mobile'], $item['shop_address'], $item['business_start_time'].'-'.$item['business_end_time'], $item['status_desc'], $item['create_time']];
|
||||
}
|
||||
return ['exportTitle'=> $exportTitle, 'exportData' => $exportData, 'exportExt'=>$exportExt, 'exportName'=>'自提门店'.date('Y-m-d H:i:s')];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
use app\common\model\SelffetchShop;
|
||||
use app\common\model\SelffetchVerifier;
|
||||
use app\common\model\User;
|
||||
use app\common\server\UrlServer;
|
||||
|
||||
class SelffetchVerifierLogic
|
||||
{
|
||||
/**
|
||||
* @notes 核销员列表
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2021/8/16 3:30 下午
|
||||
*/
|
||||
public static function lists($params)
|
||||
{
|
||||
$where = [];
|
||||
$where[] = ['sv.del', '=', 0];
|
||||
if (isset($params['verifier_info']) && !empty($params['verifier_info'])) {
|
||||
$where[] = ['sv.name|sv.sn', 'like', '%'.$params['verifier_info'].'%'];
|
||||
}
|
||||
if (isset($params['shop_name']) && !empty($params['shop_name'])) {
|
||||
$where[] = ['ss.name', 'like', '%'.$params['shop_name'].'%'];
|
||||
}
|
||||
if (isset($params['status']) && $params['status'] != '') {
|
||||
$where[] = ['sv.status', '=', $params['status']];
|
||||
}
|
||||
|
||||
$count = SelffetchVerifier::alias('sv')
|
||||
->join('selffetch_shop ss', 'sv.selffetch_shop_id = ss.id')
|
||||
->join('user u', 'sv.user_id = u.id')
|
||||
->where($where)
|
||||
->count();
|
||||
|
||||
$lists = SelffetchVerifier::alias('sv')
|
||||
->join('selffetch_shop ss', 'sv.selffetch_shop_id = ss.id')
|
||||
->join('user u', 'sv.user_id = u.id')
|
||||
->field('sv.*,ss.name as shop_name,u.avatar,u.nickname')
|
||||
->append(['status_desc'])
|
||||
->page($params['page'], $params['limit'])
|
||||
->order('sv.id','desc')
|
||||
->where($where)
|
||||
->select();
|
||||
|
||||
if (empty($lists)) {
|
||||
return ['count' => $count, 'lists' => $lists];
|
||||
}
|
||||
|
||||
foreach ($lists as &$list) {
|
||||
$list['avatar'] = empty($list['avatar']) ? '' : UrlServer::getFileUrl($list['avatar']);
|
||||
}
|
||||
|
||||
return ['count' => $count, 'lists' => $lists];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取用户列表
|
||||
* @return User[]
|
||||
* @author ljj
|
||||
* @date 2021/8/16 4:17 下午
|
||||
*/
|
||||
public static function getUserLists($params)
|
||||
{
|
||||
$where = [];
|
||||
$where[] = ['disable', '=', 0];
|
||||
$where[] = ['del', '=', 0];
|
||||
if (isset($params['nickname']) && !empty($params['nickname'])) {
|
||||
$where[] = ['nickname|sn', 'like', '%'.$params['nickname'].'%'];
|
||||
}
|
||||
|
||||
$count = User::where($where)->count();
|
||||
|
||||
$lists = User::where($where)
|
||||
->field('id,sn,nickname,avatar,mobile')
|
||||
->page($params['page'], $params['limit'])
|
||||
->order('id','desc')
|
||||
->select();
|
||||
|
||||
return ['count' => $count, 'lists' => $lists];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取自提门店列表
|
||||
* @return SelffetchShop[]
|
||||
* @author ljj
|
||||
* @date 2021/8/16 4:18 下午
|
||||
*/
|
||||
public static function getShopLists()
|
||||
{
|
||||
return SelffetchShop::where(['del'=>0,'status'=>1])->field('id,name')->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 添加核销员
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
* @author ljj
|
||||
* @date 2021/8/16 4:45 下午
|
||||
*/
|
||||
public static function add($params)
|
||||
{
|
||||
$selffetch_shop = new SelffetchVerifier;
|
||||
$selffetch_shop->name = $params['name'];
|
||||
$selffetch_shop->selffetch_shop_id = $params['selffetch_shop_id'];
|
||||
$selffetch_shop->user_id = $params['user_id'];
|
||||
$selffetch_shop->sn = create_verifier_sn('selffetch_verifier', 'sn', 8, '');
|
||||
$selffetch_shop->name = $params['name'];
|
||||
$selffetch_shop->mobile = $params['mobile'];
|
||||
$selffetch_shop->status = $params['status'];
|
||||
$selffetch_shop->create_time = time();
|
||||
return $selffetch_shop->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取核销员详情
|
||||
* @param $id
|
||||
* @return SelffetchVerifier
|
||||
* @author ljj
|
||||
* @date 2021/8/16 4:47 下午
|
||||
*/
|
||||
public static function detail($id)
|
||||
{
|
||||
$detail = SelffetchVerifier::alias('sv')
|
||||
->join('user u', 'sv.user_id = u.id')
|
||||
->field('sv.*,u.nickname,u.avatar,u.sn as user_sn')
|
||||
->find($id);
|
||||
$detail['avatar'] = (!empty($detail['avatar'])) ? UrlServer::getFileUrl($detail['avatar']) : '';
|
||||
return $detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 编辑核销员
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author ljj
|
||||
* @date 2021/8/16 4:48 下午
|
||||
*/
|
||||
public static function edit($params)
|
||||
{
|
||||
$selffetch_shop = SelffetchVerifier::find($params['id']);
|
||||
$selffetch_shop->name = $params['name'];
|
||||
$selffetch_shop->selffetch_shop_id = $params['selffetch_shop_id'];
|
||||
//$selffetch_shop->user_id = $params['user_id'];
|
||||
$selffetch_shop->name = $params['name'];
|
||||
$selffetch_shop->mobile = $params['mobile'];
|
||||
$selffetch_shop->status = $params['status'];
|
||||
$selffetch_shop->update_time = time();
|
||||
return $selffetch_shop->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 修改核销员状态
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author ljj
|
||||
* @date 2021/8/16 4:55 下午
|
||||
*/
|
||||
public static function status($params)
|
||||
{
|
||||
$selffetch_shop = SelffetchVerifier::find($params['id']);
|
||||
$selffetch_shop->status = $params['status'];
|
||||
$selffetch_shop->update_time = time();
|
||||
return $selffetch_shop->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 删除核销员
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author ljj
|
||||
* @date 2021/8/16 4:58 下午
|
||||
*/
|
||||
public static function del($params)
|
||||
{
|
||||
$selffetch_shop = SelffetchVerifier::find($params['id']);
|
||||
$selffetch_shop->del = 1;
|
||||
$selffetch_shop->update_time = time();
|
||||
return $selffetch_shop->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 导出核销员列表
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2021/8/16 4:59 下午
|
||||
*/
|
||||
public static function exportFile($params)
|
||||
{
|
||||
$where = [];
|
||||
$where[] = ['sv.del', '=', 0];
|
||||
if (isset($params['verifier_info']) && !empty($params['verifier_info'])) {
|
||||
$where[] = ['sv.name|sv.sn', 'like', '%'.$params['verifier_info'].'%'];
|
||||
}
|
||||
if (isset($params['shop_name']) && !empty($params['shop_name'])) {
|
||||
$where[] = ['ss.name', 'like', '%'.$params['shop_name'].'%'];
|
||||
}
|
||||
if (isset($params['status']) && $params['status'] != '') {
|
||||
$where[] = ['sv.status', '=', $params['status']];
|
||||
}
|
||||
|
||||
$lists = SelffetchVerifier::alias('sv')
|
||||
->join('selffetch_shop ss', 'sv.selffetch_shop_id = ss.id')
|
||||
->join('user u', 'sv.user_id = u.id')
|
||||
->field('sv.*,ss.name as shop_name,u.avatar,u.nickname')
|
||||
->append(['status_desc'])
|
||||
->order('sv.id','desc')
|
||||
->where($where)
|
||||
->select();
|
||||
|
||||
$exportTitle = ['核销员编号', '核销员名称', '用户名称', '联系电话', '核销员状态', '创建时间'];
|
||||
$exportExt = 'xls';
|
||||
$exportData = [];
|
||||
foreach ($lists as $item){
|
||||
$exportData[] = [$item['sn'],$item['name'], $item['nickname'], $item['mobile'], $item['status_desc'], $item['create_time']];
|
||||
}
|
||||
return ['exportTitle'=> $exportTitle, 'exportData' => $exportData, 'exportExt'=>$exportExt, 'exportName'=>'核销员列表'.date('Y-m-d H:i:s')];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\logic;
|
||||
use app\common\server\ConfigServer;
|
||||
use app\common\server\UrlServer;
|
||||
|
||||
class ServiceConfigLogic{
|
||||
public static function getConfig(){
|
||||
$config = [
|
||||
'file_url' => UrlServer::getFileUrl('/'),
|
||||
'wechat' => ConfigServer::get('service','wechat',''),
|
||||
'phone' => ConfigServer::get('service','phone',''),
|
||||
'time' => ConfigServer::get('service','time',''),
|
||||
'image' => ConfigServer::get('service','image',''),
|
||||
];
|
||||
return $config;
|
||||
|
||||
}
|
||||
public static function setConfig($post){
|
||||
|
||||
foreach ($post as $config_name => $config_value){
|
||||
ConfigServer::set('service',$config_name,$config_value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
use app\common\server\UrlServer;
|
||||
|
||||
use app\common\server\ConfigServer;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
|
||||
class SignDailyLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* 签到设置列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function lists()
|
||||
{
|
||||
$where[] = ['type', '=',2];
|
||||
$where[] = ['del','=',0];
|
||||
$count = Db::name('sign_daily')->where($where)->count();
|
||||
$lists = Db::name('sign_daily')->where($where)->select();
|
||||
foreach ($lists as $key => $sign){
|
||||
$tips = '';
|
||||
if(1 == $sign['integral_status'] && $sign['integral'] > 0){
|
||||
$tips.= '赠送'.$sign['integral'].'积分;';
|
||||
}
|
||||
if(1 == $sign['growth_status'] && $sign['growth'] > 0){
|
||||
$tips.= '赠送'.$sign['growth'].'成长值';
|
||||
}
|
||||
$lists[$key]['award_tips'] = $tips;
|
||||
|
||||
}
|
||||
return ['count' => $count,'list' => $lists];
|
||||
|
||||
}
|
||||
/**
|
||||
* 签到记录列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function record($get){
|
||||
$where = [];
|
||||
|
||||
if (isset($get['keyword']) && $get['keyword']){
|
||||
$where[] = [$get['type'],'like','%'.$get['keyword'].'%'];
|
||||
}
|
||||
|
||||
|
||||
$count = Db::name('user_sign us')
|
||||
->where(['us.del'=>0,'u.del'=>0])
|
||||
->where($where )
|
||||
->join('user u','u.id = us.user_id')
|
||||
->count();
|
||||
$lists = Db::name('user_sign us')
|
||||
->where(['us.del'=>0,'u.del'=>0])
|
||||
->where($where )
|
||||
->join('user u','u.id = us.user_id')
|
||||
->field('us.user_id,sn,nickname,avatar,mobile,sex,u.create_time ,days,integral,growth,
|
||||
continuous_integral, continuous_growth,sign_time,mobile,us.sign_time')
|
||||
->order('us.id desc')
|
||||
->page($get['page'], $get['limit'])
|
||||
->select();
|
||||
foreach ( $lists as &$item){
|
||||
switch ($item['sex']){
|
||||
case 1:
|
||||
$item['sex'] = '男';
|
||||
break;
|
||||
case 2:
|
||||
$item['sex'] = '女';
|
||||
break;
|
||||
default:
|
||||
$item['sex'] = '未知';
|
||||
}
|
||||
$item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
|
||||
$item['sign_time'] = date('Y-m-d H:i:s', $item['sign_time']);
|
||||
$item['avatar'] = UrlServer::getFileUrl($item['avatar']);
|
||||
}
|
||||
return ['count' => $count,'list' => $lists];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加连续签到奖励
|
||||
* @param $post
|
||||
*/
|
||||
public static function add($post)
|
||||
{
|
||||
$data = [
|
||||
'type' =>'2',
|
||||
'days' => $post['days'],
|
||||
'integral' => $post['integral'],
|
||||
'integral_status' => $post['integral_status'],
|
||||
'growth' => $post['growth'],
|
||||
'growth_status' => $post['growth_status'],
|
||||
'del' =>0,
|
||||
'create_time' =>time()
|
||||
|
||||
|
||||
];
|
||||
return Db::name('sign_daily')->insert($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取连续签到奖励
|
||||
* @param $id
|
||||
* @return array|null|\PDOStatement|string|\think\Model
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function getSignDaily($id)
|
||||
{
|
||||
return Db::name('sign_daily')->where(['id' =>$id])->find();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 编辑连续签到奖励
|
||||
* @param $post
|
||||
* @param $id
|
||||
* @return bool
|
||||
*/
|
||||
public static function edit($post,$id)
|
||||
{
|
||||
$data = [
|
||||
'type' =>'2',
|
||||
'days' => $post['days'],
|
||||
'integral' => $post['integral'],
|
||||
'integral_status' => $post['integral_status'],
|
||||
'growth' => $post['growth'],
|
||||
'growth_status' => $post['growth_status'],
|
||||
'del' =>0,
|
||||
'update_time' =>time()
|
||||
];
|
||||
return Db::name('sign_daily')->where(['id' =>$id])->update($data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除连续签到奖励列表
|
||||
* @param $id
|
||||
* @return int|string
|
||||
* @throws Exception
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
$data = [
|
||||
'id' =>$id,
|
||||
'del' =>1,
|
||||
'update_time' =>time()
|
||||
];
|
||||
$result = Db::name('sign_daily')->where(['id' =>$id])->update($data);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置签到
|
||||
* @param $post
|
||||
* @throws Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function setSignRule($post)
|
||||
{
|
||||
|
||||
$data = [
|
||||
'type' =>1,
|
||||
'days' => 0,
|
||||
'integral' =>$post['integral'],
|
||||
'growth' =>$post['growth'],
|
||||
'integral_status' =>$post['integral_status'],
|
||||
'growth_status' =>$post['growth_status'],
|
||||
'create_time' =>time(),
|
||||
'del' =>0,
|
||||
|
||||
];
|
||||
|
||||
$info = [
|
||||
'type' =>1,
|
||||
'days' => 0,
|
||||
'integral' =>$post['integral'],
|
||||
'growth' =>$post['growth'],
|
||||
'integral_status' =>$post['integral_status'],
|
||||
'growth_status' =>$post['growth_status'],
|
||||
'update_time' =>time(),
|
||||
'del' =>0,
|
||||
|
||||
];
|
||||
|
||||
|
||||
|
||||
$name = Db::name('sign_daily')->where(['type' =>1])->find();
|
||||
if (empty($name)){
|
||||
Db::name('sign_daily')->insert($data);
|
||||
}else{
|
||||
Db::name('sign_daily')->where(['type' =>1])->update($info);
|
||||
}
|
||||
|
||||
|
||||
ConfigServer::set('sign_rule','instructions',$post['instructions']);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取签到规则说明
|
||||
* @return array
|
||||
*/
|
||||
public static function getSignRule()
|
||||
{
|
||||
|
||||
|
||||
$data = Db::name('sign_daily')->where(['type' =>1])->find();
|
||||
$config = [
|
||||
'instructions' => ConfigServer::get('sign_rule','instructions'),
|
||||
'dailySign' => $data
|
||||
|
||||
];
|
||||
|
||||
|
||||
|
||||
return $config;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\logic;
|
||||
use app\common\model\NoticeSetting;
|
||||
use app\common\model\SmsLog;
|
||||
use think\Db;
|
||||
class SmsLogic{
|
||||
|
||||
public static function configLists(){
|
||||
$list = Db::name('sms_config')->where(['del'=>0])
|
||||
->field('id,name,status,describe')
|
||||
->select();
|
||||
foreach ($list as &$item){
|
||||
$item['status_desc'] = '关闭';
|
||||
if($item['status']){
|
||||
$item['status_desc'] = '开启';
|
||||
}
|
||||
}
|
||||
return ['count'=>count($list),'list'=>$list];
|
||||
}
|
||||
|
||||
public static function logLists($get){
|
||||
$where = [];
|
||||
if(isset($get['name']) && $get['name']){
|
||||
$where[] = ['d.name','like','%'.$get['name'].'%'];
|
||||
}
|
||||
if(isset($get['mobile']) && $get['mobile']){
|
||||
$where[] = ['mobile','like','%'.$get['mobile'].'%'];
|
||||
}
|
||||
if(isset($get['send_status']) && $get['send_status']){
|
||||
$where[] = ['send_status','=',$get['send_status']];
|
||||
}
|
||||
if(isset($get['start_time']) && $get['start_time']){
|
||||
$where[] = ['create_time', '>=', strtotime($get['start_time'])];
|
||||
}
|
||||
if(isset($get['end_time']) && $get['end_time']){
|
||||
$where[] = ['create_time', '<=', strtotime($get['end_time'])];
|
||||
}
|
||||
$sms_log = new SmsLog();
|
||||
|
||||
$count = $sms_log->alias('s')
|
||||
->where($where)
|
||||
->where('message_key', 'in', NoticeSetting::SMS_SCENE)
|
||||
->count();
|
||||
|
||||
|
||||
$list = $sms_log->alias('s')
|
||||
->field('s.*')
|
||||
->where('message_key', 'in', NoticeSetting::SMS_SCENE)
|
||||
->where($where)
|
||||
->order('s.id desc')
|
||||
->page($get['page'],$get['limit'])
|
||||
->select();
|
||||
|
||||
foreach ($list as $item) {
|
||||
$item['name'] = NoticeSetting::getSceneDesc($item['message_key']) ?? '短信通知';
|
||||
}
|
||||
|
||||
return ['count'=>$count,'list'=>$list];
|
||||
|
||||
}
|
||||
|
||||
public static function setConfig($post){
|
||||
$post['status'] = isset($post['status']) && $post['status'] == 'on' ? 1 : 0;
|
||||
|
||||
if ($post['status'] == 1) {
|
||||
Db::name('sms_config')->whereIn('id', [1, 2])
|
||||
->update(['status' => 0]);
|
||||
}
|
||||
|
||||
Db::name('sms_config')->where(['id'=>$post['id']])->update($post);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public static function getConfig($id){
|
||||
return Db::name('sms_config')->where(['id'=>$id,'del'=>0])->find();
|
||||
}
|
||||
|
||||
public static function detail($id){
|
||||
$sms_log = new SmsLog();
|
||||
$log = $sms_log->alias('s')
|
||||
->where('s.message_key', 'in', NoticeSetting::SMS_SCENE)
|
||||
->field('s.*')->where(['s.id'=>$id])
|
||||
->find();
|
||||
|
||||
$log['name'] = NoticeSetting::getSceneDesc($log['message_key']);
|
||||
return $log;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\common\model\Pay;
|
||||
use think\helper\Time;
|
||||
use think\Db;
|
||||
|
||||
class StatLogic
|
||||
{
|
||||
//工作台基本数据
|
||||
public static function stat()
|
||||
{
|
||||
//更新时间
|
||||
$time = date('Y-m-d H:i:s', time());
|
||||
//今日成交订单
|
||||
$order_num_today = Db::name('order')
|
||||
->where(['del' => 0, 'pay_status' => Pay::ISPAID])
|
||||
->whereTime('create_time', 'today')
|
||||
->count();
|
||||
//昨日
|
||||
$order_num_yesterday = Db::name('order')
|
||||
->where(['del' => 0, 'pay_status' => Pay::ISPAID])
|
||||
->whereTime('create_time', 'yesterday')
|
||||
->count();
|
||||
//变化
|
||||
$order_num_change = $order_num_today - $order_num_yesterday;
|
||||
if ($order_num_change >= 0) {
|
||||
$order_num_change = '+' . $order_num_change;
|
||||
}
|
||||
//总
|
||||
$order_num_all = Db::name('order')
|
||||
->where(['del' => 0, 'pay_status' => Pay::ISPAID])
|
||||
->count();
|
||||
//今日销售金额(元)
|
||||
$order_amount_today = Db::name('order')
|
||||
->where(['del' => 0, 'pay_status' => Pay::ISPAID])
|
||||
->whereTime('create_time', 'today')
|
||||
->sum('order_amount');
|
||||
//昨日
|
||||
$order_amount_yesterday = Db::name('order')
|
||||
->where(['del' => 0, 'pay_status' => Pay::ISPAID])
|
||||
->whereTime('create_time', 'yesterday')
|
||||
->sum('order_amount');
|
||||
//总
|
||||
$order_amount_all = Db::name('order')
|
||||
->where(['del' => 0, 'pay_status' => Pay::ISPAID])
|
||||
->sum('order_amount');
|
||||
//变化
|
||||
$order_amount_change = $order_amount_today - $order_amount_yesterday;
|
||||
if ($order_amount_change >= 0) {
|
||||
$order_amount_change = '+' . $order_amount_change;
|
||||
}
|
||||
|
||||
|
||||
// 今天新增会员数量
|
||||
$add_user_today = Db::name('user')
|
||||
->where('del', 0)
|
||||
->whereTime('create_time', 'today')
|
||||
->count();
|
||||
//昨天
|
||||
$add_user_yesterday = Db::name('user')
|
||||
->where('del', 0)
|
||||
->whereTime('create_time', 'yesterday')
|
||||
->count();
|
||||
//总
|
||||
$user_all = Db::name('user')
|
||||
->where('del', 0)
|
||||
->count();
|
||||
//变化
|
||||
$add_change = $add_user_today - $add_user_yesterday;
|
||||
if ($add_change >= 0) {
|
||||
$add_change = '+' . $add_change;
|
||||
}
|
||||
|
||||
$today_ip = Db::name('stat')
|
||||
->whereTime('create_time', 'today')
|
||||
->count();
|
||||
$yesterday_ip = Db::name('stat')
|
||||
->whereTime('create_time', 'yesterday')
|
||||
->count();
|
||||
$ip_change = $today_ip - $yesterday_ip;
|
||||
if ($ip_change >= 0) {
|
||||
$ip_change = '+' . $ip_change;
|
||||
}
|
||||
$total_ip = Db::name('stat')->count();
|
||||
|
||||
|
||||
return [
|
||||
'time' => $time,
|
||||
'order_num_today' => $order_num_today,
|
||||
'order_num_yesterday' => $order_num_yesterday,
|
||||
'order_num_change' => $order_num_change,
|
||||
'order_amount_today' => $order_amount_today,
|
||||
'order_amount_yesterday' => $order_amount_yesterday,
|
||||
'order_amount_change' => $order_amount_change,
|
||||
|
||||
'add_user_today' => $add_user_today,
|
||||
'add_user_yesterday' => $add_user_yesterday,
|
||||
'add_user_change' => $add_change,
|
||||
|
||||
'order_num_all' => $order_num_all,
|
||||
'order_amount_all' => $order_amount_all,
|
||||
'user_all' => $user_all,
|
||||
|
||||
'today_user_ip' => $today_ip ?? 0,
|
||||
'yesterday_user_ip' => $yesterday_ip ?? 0,
|
||||
'ip_change' => $ip_change,
|
||||
'total_user_ip' => $total_ip ?? 0,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
//图标数据
|
||||
public static function graphData()
|
||||
{
|
||||
//今天时间戳
|
||||
list($start_t, $end_t) = Time::dayToNow(15);
|
||||
//echarts图表数据
|
||||
|
||||
$echarts_order_amount = [];
|
||||
$echarts_user_pv = [];
|
||||
$dates = [];
|
||||
for ($i = 1; $i <= 15; $i++) {
|
||||
$where_start = strtotime("+ ".$i."day", $start_t);
|
||||
$where_end = strtotime("+ ".$i."day", $start_t) + 86399;
|
||||
$dates[] = date('m-d',$where_end);
|
||||
|
||||
//每天订单金额
|
||||
$order_amount = Db::name('order')
|
||||
->where('create_time', '<=', $where_end)
|
||||
->where('create_time', '>=', $where_start)
|
||||
->where(['del' => 0, 'pay_status' => Pay::ISPAID])
|
||||
->sum('order_amount');
|
||||
|
||||
//每天用户访问量
|
||||
$user_pv = Db::name('stat')
|
||||
->where('create_time', '<=', $where_end)
|
||||
->where('create_time', '>=', $where_start)
|
||||
->sum('count');
|
||||
|
||||
$echarts_order_amount[] = $order_amount ?:0;
|
||||
$echarts_user_pv[] = $user_pv ?:0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
return [
|
||||
'echarts_order_amount' => $echarts_order_amount,
|
||||
'echarts_user_visit' => $echarts_user_pv,
|
||||
'dates' => $dates,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,377 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\admin\model\User;
|
||||
use app\common\model\OrderGoods;
|
||||
use app\common\model\Pay;
|
||||
use think\helper\Time;
|
||||
use think\Db;
|
||||
|
||||
class StatisticsLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 获取两个日期区间
|
||||
* @param $start
|
||||
* @param $end
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/4/27 12:09
|
||||
*/
|
||||
public static function getDateRange($start, $end)
|
||||
{
|
||||
$start = strtotime($start);
|
||||
$end = strtotime($end);
|
||||
$range = get_date_range($start, $end);
|
||||
return [
|
||||
'start' => $start,
|
||||
'end' => $end,
|
||||
'range' => $range,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取会员数据
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/4/27 10:50
|
||||
*/
|
||||
public static function getMemberData($params)
|
||||
{
|
||||
// 获取两个日期区间
|
||||
$range = self::getDateRange($params['start_time'], $params['end_time']);
|
||||
|
||||
$start_time = $range['start'];
|
||||
$end_time = $range['end'];
|
||||
$range_data = $range['range'];
|
||||
|
||||
// 会员数量
|
||||
$count = User::getUserCount();
|
||||
|
||||
// 新增会员数量
|
||||
$new = User::getUserCount(['create_time', 'between', [$start_time, $end_time]]);
|
||||
|
||||
$echarts_count = [];
|
||||
$echarts_new = [];
|
||||
for ($i = 0; $i < count($range_data['data']); $i++) {
|
||||
// 每次的开始和结束时间
|
||||
$item_time = self::getItemTime($i, $range_data, $start_time, $end_time);
|
||||
$time_start = $item_time['time_start'];
|
||||
$time_end = $item_time['time_end'];
|
||||
// 查询对应时间数据
|
||||
$echarts_count[] = User::getUserCount(['create_time', '<=', $time_end]);
|
||||
$echarts_new[] = User::getUserCount(['create_time', 'between', [$time_start, $time_end]]);
|
||||
}
|
||||
|
||||
if ($range_data['type'] == 'day') {
|
||||
$range_data['data'] = $range_data['day_extend'];
|
||||
}
|
||||
|
||||
return [
|
||||
'count' => $count,
|
||||
'new' => $new,
|
||||
'days' => $range_data['data'],
|
||||
'echarts_count' => $echarts_count,
|
||||
'echarts_new' => $echarts_new,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品数据
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/4/27 15:03
|
||||
*/
|
||||
public static function getGoodsData($params)
|
||||
{
|
||||
$range = self::getDateRange($params['start_time'], $params['end_time']);
|
||||
|
||||
$start_time = $range['start'];
|
||||
$end_time = $range['end'];
|
||||
$range_data = $range['range'];
|
||||
|
||||
$goods_click = Db::name('goods_click')
|
||||
->where('create_time', 'between', [$start_time, $end_time])
|
||||
->count();
|
||||
|
||||
$goods_sale = Db::name('order')
|
||||
->where(['pay_status' => Pay::ISPAID, 'refund_status' => OrderGoods::REFUND_STATUS_NO])
|
||||
->where('create_time', 'between', [$start_time, $end_time])
|
||||
->sum('total_num');
|
||||
|
||||
$goods_collect = Db::name('goods_collect')
|
||||
->where('create_time', 'between', [$start_time, $end_time])
|
||||
->count();
|
||||
|
||||
$echarts_click = [];
|
||||
$echarts_collect = [];
|
||||
$echarts_sale = [];
|
||||
|
||||
for ($i = 0; $i < count($range_data['data']); $i++) {
|
||||
// 每次的开始和结束时间
|
||||
$item_time = self::getItemTime($i, $range_data, $start_time, $end_time);
|
||||
$time_start = $item_time['time_start'];
|
||||
$time_end = $item_time['time_end'];
|
||||
|
||||
$echarts_click[] = Db::name('goods_click')
|
||||
->where('create_time', 'between', [$time_start, $time_end])
|
||||
->count();
|
||||
|
||||
$echarts_collect[] = Db::name('order')
|
||||
->where(['pay_status' => Pay::ISPAID, 'refund_status' => OrderGoods::REFUND_STATUS_NO])
|
||||
->where('create_time', 'between', [$time_start, $time_end])
|
||||
->sum('total_num');
|
||||
|
||||
$echarts_sale[] = Db::name('goods_collect')
|
||||
->where('create_time', 'between', [$time_start, $time_end])
|
||||
->count();
|
||||
}
|
||||
|
||||
if ($range_data['type'] == 'day') {
|
||||
$range_data['data'] = $range_data['day_extend'];
|
||||
}
|
||||
|
||||
return [
|
||||
'days' => $range_data['data'],
|
||||
'click' => $goods_click,
|
||||
'collect' => $goods_collect,
|
||||
'sale' => $goods_sale,
|
||||
'echarts_click' => $echarts_click,
|
||||
'echarts_collect' => $echarts_collect,
|
||||
'echarts_sale' => $echarts_sale,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取每项开始结束时间
|
||||
* @param $i
|
||||
* @param $data
|
||||
* @param $start_time
|
||||
* @param $end_time
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/4/27 14:47
|
||||
*/
|
||||
public static function getItemTime($i, $data, $start_time, $end_time)
|
||||
{
|
||||
// 处理开始时间
|
||||
if ($i == 0) {
|
||||
$time_start = $start_time;
|
||||
} else {
|
||||
if ($data['type'] == 'year') {
|
||||
$time_start = strtotime($data['data'][$i] . "-1-1");
|
||||
} else {
|
||||
$time_start = strtotime($data['data'][$i]);
|
||||
}
|
||||
}
|
||||
|
||||
// 处理结束时间
|
||||
if ($data['type'] == 'day') {
|
||||
$time_end = strtotime($data['data'][$i] . "+ 1days") - 1;
|
||||
} else {
|
||||
if ($i == (count($data['data']) - 1)) {
|
||||
$time_end = $end_time + 86400 -1;
|
||||
} else {
|
||||
if ($data['type'] == 'year') {
|
||||
$time_end = strtotime($data['data'][$i] . "-12-31 23:59:59");
|
||||
} else {
|
||||
$time_end = strtotime($data['data'][$i + 1]) - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'time_start' => $time_start,
|
||||
'time_end' => $time_end,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取交易数据
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/4/27 15:32
|
||||
*/
|
||||
public static function getDealData($params)
|
||||
{
|
||||
$range = self::getDateRange($params['start_time'], $params['end_time']);
|
||||
|
||||
$start_time = $range['start'];
|
||||
$end_time = $range['end'];
|
||||
$range_data = $range['range'];
|
||||
|
||||
//订单金额
|
||||
$order_amount = Db::name('order')
|
||||
->where('del', 0)
|
||||
->where('create_time', 'between', [$start_time, $end_time])
|
||||
->sum('order_amount');
|
||||
//订单数量
|
||||
$order_num = Db::name('order')
|
||||
->where('del', 0)
|
||||
->where('create_time', 'between', [$start_time, $end_time])
|
||||
->count();
|
||||
//商家售后单数量
|
||||
$after_num = Db::name('after_sale')
|
||||
->where('del', 0)
|
||||
->where('create_time', 'between', [$start_time, $end_time])
|
||||
->count();
|
||||
|
||||
$echarts_order_amount = [];
|
||||
$echarts_order_num = [];
|
||||
$echarts_after_num = [];
|
||||
|
||||
for ($i = 0; $i < count($range_data['data']); $i++) {
|
||||
// 每次的开始和结束时间
|
||||
$item_time = self::getItemTime($i, $range_data, $start_time, $end_time);
|
||||
$time_start = $item_time['time_start'];
|
||||
$time_end = $item_time['time_end'];
|
||||
|
||||
$echarts_order_amount[] = Db::name('order')
|
||||
->where('del', 0)
|
||||
->where('create_time', 'between', [$time_start, $time_end])
|
||||
->sum('order_amount');
|
||||
|
||||
$echarts_order_num[] = Db::name('order')
|
||||
->where('del', 0)
|
||||
->where('create_time', 'between', [$time_start, $time_end])
|
||||
->count();
|
||||
|
||||
$echarts_after_num[] = Db::name('after_sale')
|
||||
->where('del', 0)
|
||||
->where('create_time', 'between', [$time_start, $time_end])
|
||||
->count();
|
||||
}
|
||||
|
||||
if ($range_data['type'] == 'day') {
|
||||
$range_data['data'] = $range_data['day_extend'];
|
||||
}
|
||||
|
||||
return [
|
||||
'days' => $range_data['data'],
|
||||
'order_amount' => $order_amount,
|
||||
'order_num' => $order_num,
|
||||
'after_num' => $after_num,
|
||||
'echarts_order_amount' => $echarts_order_amount,
|
||||
'echarts_order_num' => $echarts_order_num,
|
||||
'echarts_after_num' => $echarts_after_num,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* @notes 获取访问数据
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/4/27 15:47
|
||||
*/
|
||||
public static function getVisitData($params)
|
||||
{
|
||||
$range = self::getDateRange($params['start_time'], $params['end_time']);
|
||||
|
||||
$start_time = $range['start'];
|
||||
$end_time = $range['end'];
|
||||
$range_data = $range['range'];
|
||||
|
||||
//每天商品浏览量
|
||||
$goods_click = Db::name('goods_click')
|
||||
->where('create_time', 'between', [$start_time, $end_time])
|
||||
->count();
|
||||
//每天用户浏览量
|
||||
$user_click = Db::name('stat')
|
||||
->where('create_time', 'between', [$start_time, $end_time])
|
||||
->count();
|
||||
|
||||
$echarts_goods_click = [];
|
||||
$echarts_user_click = [];
|
||||
|
||||
for ($i = 0; $i < count($range_data['data']); $i++) {
|
||||
// 每次的开始和结束时间
|
||||
$item_time = self::getItemTime($i, $range_data, $start_time, $end_time);
|
||||
$time_start = $item_time['time_start'];
|
||||
$time_end = $item_time['time_end'];
|
||||
|
||||
//每天商品浏览量
|
||||
$echarts_goods_click[] = Db::name('goods_click')
|
||||
->where('create_time', 'between', [$time_start, $time_end])
|
||||
->count();
|
||||
//每天用户浏览量
|
||||
$echarts_user_click[] = Db::name('stat')
|
||||
->where('create_time', 'between', [$time_start, $time_end])
|
||||
->count();
|
||||
}
|
||||
|
||||
if ($range_data['type'] == 'day') {
|
||||
$range_data['data'] = $range_data['day_extend'];
|
||||
}
|
||||
|
||||
return [
|
||||
'days' => $range_data['data'],
|
||||
'goods_click' => $goods_click,
|
||||
'user_click' => $user_click,
|
||||
'echarts_goods_click' => $echarts_goods_click,
|
||||
'echarts_user_click' => $echarts_user_click,
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取日期
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/4/27 10:50
|
||||
*/
|
||||
public static function getDateData()
|
||||
{
|
||||
$today = array_map(function ($time) {
|
||||
return date('Y-m-d', $time);
|
||||
}, Time::today());
|
||||
|
||||
$days_ago7 = array_map(function ($time) {
|
||||
return date('Y-m-d', $time);
|
||||
}, Time::dayToNow(7));
|
||||
|
||||
$days_ago15 = array_map(function ($time) {
|
||||
return date('Y-m-d', $time);
|
||||
}, Time::dayToNow(15, true));
|
||||
|
||||
$time = [
|
||||
'today' => $today,
|
||||
'days_ago7' => $days_ago7,
|
||||
'days_ago15' => $days_ago15,
|
||||
];
|
||||
return $time;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\logic;
|
||||
use think\db;
|
||||
|
||||
class SupplierLogic{
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
public static function lists($get){
|
||||
$where =[];
|
||||
if(isset($get['keyword']) && $get['keyword']){
|
||||
$where[] = ['name','like','%'.$get['keyword'].'%'];
|
||||
}
|
||||
$res = db::name('supplier')
|
||||
->where('del',0)
|
||||
->where($where);
|
||||
$count = $res->count();
|
||||
$lists = $res->page($get['page'],$get['limit'])->select();
|
||||
return[
|
||||
'count' =>$count,
|
||||
'lists' =>$lists,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public static function add($post){
|
||||
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'contact' => $post['contact'],
|
||||
'tel' => $post['tel'],
|
||||
'remark' => $post['remark'],
|
||||
'address' => $post['address'],
|
||||
'create_time' => time(),
|
||||
];
|
||||
|
||||
db::name('supplier')
|
||||
->insert($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public static function edit($post){
|
||||
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'contact' => $post['contact'],
|
||||
'tel' => $post['tel'],
|
||||
'remark' => $post['remark'],
|
||||
'address' => $post['address'],
|
||||
'update_time' => time(),
|
||||
];
|
||||
|
||||
db::name('supplier')
|
||||
->where(['id'=>$post['id']])
|
||||
->update($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*/
|
||||
public static function info($id){
|
||||
$info = db::name('supplier')
|
||||
->where(['id'=>$id])
|
||||
->find();
|
||||
return $info;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
|
||||
$data = [
|
||||
'del' => 1,
|
||||
'update_time' => time()];
|
||||
return Db::name('supplier')->where(['del' => 0, 'id' =>$id])->update($data); //逻辑删除
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* note 获取所有供应商
|
||||
*/
|
||||
public static function getSupplierList(){
|
||||
$list = Db::name('supplier')
|
||||
->field('id,name')
|
||||
->where(['del' => 0])
|
||||
->select();
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,464 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
use app\common\model\Goods as GoodsModel;
|
||||
use app\common\model\Team;
|
||||
use app\common\model\TeamActivity as TeamActivityModel;
|
||||
use app\common\model\TeamFollow as TeamFollowModel;
|
||||
use app\common\model\TeamFound as TeamFoundModel;
|
||||
use app\common\model\TeamGoodsItem as TeamGoodsItemModel;
|
||||
use app\common\server\UrlServer;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 拼团商品逻辑层
|
||||
* Class TeamActivityLogic
|
||||
* @package app\admin\logic
|
||||
*/
|
||||
class TeamActivityLogic
|
||||
{
|
||||
protected static $error; //错误信息
|
||||
|
||||
/**
|
||||
* Notes: 错误错误信息
|
||||
* @author 张无忌(2021/1/12 16:01)
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getError()
|
||||
{
|
||||
return self::$error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 列表数据
|
||||
* @author 张无忌(2021/1/13 15:03)
|
||||
* @param array $get
|
||||
* @return array
|
||||
*/
|
||||
public static function lists(array $get)
|
||||
{
|
||||
$teamActivityModel = new TeamActivityModel();
|
||||
|
||||
// 查询条件
|
||||
$where = [];
|
||||
if ( !empty($get['goods_name']) and $get['goods_name'] !== '') {
|
||||
$goodsModel = new GoodsModel();
|
||||
$ids = $goodsModel->field('id,name')->where([
|
||||
['name', 'like', '%' . $get['goods_name'] . '%']
|
||||
])->column('id');
|
||||
|
||||
$where[] = ['goods_id', 'in', $ids];
|
||||
}
|
||||
|
||||
if (isset($get['status']) and is_numeric($get['status'])) {
|
||||
$where[] = ['t.status', '=', (int)$get['status']];
|
||||
}
|
||||
|
||||
if ( !empty($get['start_time']) and $get['start_time'] !== '') {
|
||||
$where[] = ['start_time', '>=', strtotime($get['start_time'])];
|
||||
}
|
||||
|
||||
if ( !empty($get['end_time']) and $get['end_time'] !== '') {
|
||||
$where[] = ['end_time', '<=', strtotime($get['end_time'])];
|
||||
}
|
||||
|
||||
$count = $teamActivityModel->alias('t')->where(['del' => 0])->where($where)->count();
|
||||
$lists = $teamActivityModel->alias('t')
|
||||
->where(['t.del' => 0])
|
||||
->where($where)->field('t.*,g.name,g.image,g.max_price,g.min_price')
|
||||
->withAttr('team_count', function ($value, $data) {
|
||||
return TeamFoundModel::where(['team_id'=>$data['team_id']])->count();
|
||||
})
|
||||
->withAttr('follow_count', function ($value, $data) {
|
||||
return TeamFollowModel::where(['team_id'=>$data['team_id']])->count();
|
||||
})
|
||||
->join('Goods g', 't.goods_id=g.id')
|
||||
->order('team_id', 'desc')
|
||||
->page($get['page'], $get['limit'])
|
||||
->select()->append(['team_count', 'follow_count']);
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['image'] = UrlServer::getFileUrl($item['image']);
|
||||
$item['status'] = $item['end_time'] <= time() ? 0 : $item['status'];
|
||||
$item['start_time'] = date('Y-m-d H:i:s', $item['start_time']);
|
||||
$item['end_time'] = date('Y-m-d H:i:s', $item['end_time']);
|
||||
}
|
||||
|
||||
return ['count' => $count, 'lists' => $lists];
|
||||
}
|
||||
|
||||
public static function getDetail(int $id)
|
||||
{
|
||||
$teamActivityModel = new TeamActivityModel();
|
||||
$teamGoodsItemModel = new TeamGoodsItemModel();
|
||||
|
||||
$detail = $teamActivityModel->field('t.*,g.name,g.image')
|
||||
->alias('t')
|
||||
->join('Goods g', 't.goods_id=g.id')
|
||||
->where(['team_id' => $id])->find();
|
||||
|
||||
$goods_item = $teamGoodsItemModel->field('t.*,gi.id as spec_item_id, gi.spec_value_str, gi.price as spec_item_price')
|
||||
->alias('t')->where(['team_id' => $id])
|
||||
->rightJoin('goods_item gi', 'gi.id = t.item_id')
|
||||
->select();
|
||||
|
||||
$detail['item'] = $goods_item;
|
||||
$detail['image'] = UrlServer::getFileUrl($detail['image']);
|
||||
$detail['start_time'] = date('Y-m-d H:i:s', $detail['start_time']);
|
||||
$detail['end_time'] = date('Y-m-d H:i:s', $detail['end_time']);
|
||||
return $detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 新增拼团商品
|
||||
* @author 张无忌(2021/1/13 11:46)
|
||||
* @param array $post
|
||||
* @return bool
|
||||
*/
|
||||
public static function add(array $post)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$goodsModel = new GoodsModel();
|
||||
$teamActivityModel = new TeamActivityModel();
|
||||
|
||||
// 查询商品信息
|
||||
$goods = $goodsModel->field('id,name,image')
|
||||
->where(['id' => (int)$post['goods_id']])->find();
|
||||
|
||||
if (!$goods) {
|
||||
static::$error = '选择的商品不存在';
|
||||
return false;
|
||||
}
|
||||
|
||||
// 拼团商品已存在
|
||||
$teamGoods = $teamActivityModel->field('goods_id')
|
||||
->where(['goods_id'=>(int)$goods['id'], 'del'=>0])->find();
|
||||
|
||||
if ($teamGoods) {
|
||||
static::$error = '该商品已是拼团商品,无需重复添加';
|
||||
return false;
|
||||
}
|
||||
|
||||
// 查询该商品是否开启了秒杀活动
|
||||
$seckillGoods = Db::name('seckill_goods')->field(true)
|
||||
->where(['goods_id'=>(int)$goods['id'], 'del'=>0])->find();
|
||||
|
||||
if ($seckillGoods) {
|
||||
static::$error = '该商品开启了秒杀活动,请先移除';
|
||||
return false;
|
||||
}
|
||||
|
||||
// 查出最大和最少价格
|
||||
$team_price = [];
|
||||
foreach ($post['item'] as $key => $value) {
|
||||
foreach ($value as $K => $item) {
|
||||
array_push($team_price, $item);
|
||||
}
|
||||
}
|
||||
$team_max_price = !empty($team_price) ? max($team_price) : 0;
|
||||
$team_min_price = !empty($team_price) ? min($team_price) : 0;
|
||||
|
||||
// 新增拼团商品信息
|
||||
$activity = $teamActivityModel->insertGetId([
|
||||
'goods_id' => $post['goods_id'],
|
||||
'sales_sum' => 0,
|
||||
'people_num' => $post['people_num'],
|
||||
'time_limit' => $post['time_limit'],
|
||||
'start_time' => strtotime($post['start_time']),
|
||||
'end_time' => strtotime($post['end_time']),
|
||||
'share_title' => empty($post['share_title']) ? '' : $post['share_title'],
|
||||
'share_intro' => empty($post['share_intro']) ? '' : $post['share_intro'],
|
||||
'team_max_price' => $team_max_price,
|
||||
'team_min_price' => $team_min_price,
|
||||
'status' => $post['status'],
|
||||
'create_time' => time()
|
||||
]);
|
||||
|
||||
// 新增拼团商品规格
|
||||
$lists = [];
|
||||
foreach ($post['item'] as $key => $value) {
|
||||
foreach ($value as $K => $item) {
|
||||
$lists[] = [
|
||||
'team_id' => $activity,
|
||||
'goods_id' => $key,
|
||||
'item_id' => $K,
|
||||
'team_price' => $item
|
||||
];
|
||||
}
|
||||
}
|
||||
if ( !empty($lists)) {
|
||||
$teamGoodsItemModel = new TeamGoodsItemModel();
|
||||
$teamGoodsItemModel->saveAll($lists);
|
||||
}
|
||||
|
||||
// 回调更新商品表拼团字段
|
||||
if ($post['status'] == 1) {
|
||||
$goodsModel->where(['id' => (int)$post['goods_id']])->update([
|
||||
'is_team' => 1,
|
||||
'update_time' => time()
|
||||
]);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
Db::rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 编辑
|
||||
* @param $post
|
||||
* @author 张无忌(2021/1/13 17:41)
|
||||
* @return bool
|
||||
*/
|
||||
public static function edit($post)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$goodsModel = new GoodsModel();
|
||||
$teamActivityModel = new TeamActivityModel();
|
||||
|
||||
// 查询商品信息
|
||||
$goods = $goodsModel->field('id,name,image')
|
||||
->where(['id' => (int)$post['goods_id']])->find();
|
||||
|
||||
if ( !$goods) {
|
||||
static::$error = '选择的商品不存在';
|
||||
return false;
|
||||
}
|
||||
|
||||
// 拼团商品已存在
|
||||
$teamGoods = $teamActivityModel->field('goods_id')
|
||||
->where(['goods_id'=>(int)$goods['id'], 'del'=>0])
|
||||
->where('team_id', '<>', (int)$post['team_id'])
|
||||
->find();
|
||||
|
||||
if ($teamGoods) {
|
||||
static::$error = '该商品已是拼团商品,换一个吧';
|
||||
return false;
|
||||
}
|
||||
|
||||
// 查询该商品是否开启了秒杀活动
|
||||
$seckillGoods = Db::name('seckill_goods')->field(true)
|
||||
->where(['goods_id'=>(int)$goods['id'], 'del'=>0])->find();
|
||||
|
||||
if ($seckillGoods) {
|
||||
static::$error = '该商品开启了秒杀活动,请先移除';
|
||||
return false;
|
||||
}
|
||||
|
||||
// 查出最大和最少价格
|
||||
$team_price = [];
|
||||
foreach ($post['item'] as $key => $value) {
|
||||
foreach ($value as $K => $item) {
|
||||
array_push($team_price, $item);
|
||||
}
|
||||
}
|
||||
$team_max_price = !empty($team_price) ? max($team_price) : 0;
|
||||
$team_min_price = !empty($team_price) ? min($team_price) : 0;
|
||||
|
||||
// 新增拼团商品信息
|
||||
$teamActivityModel->where(['team_id' => (int)$post['team_id']])->update([
|
||||
'goods_id' => $post['goods_id'],
|
||||
'people_num' => $post['people_num'],
|
||||
'time_limit' => $post['time_limit'],
|
||||
'start_time' => strtotime($post['start_time']),
|
||||
'end_time' => strtotime($post['end_time']),
|
||||
'share_title' => empty($post['share_title']) ? '' : $post['share_title'],
|
||||
'share_intro' => empty($post['share_intro']) ? '' : $post['share_intro'],
|
||||
'team_max_price' => $team_max_price,
|
||||
'team_min_price' => $team_min_price,
|
||||
'status' => $post['status']
|
||||
]);
|
||||
|
||||
// 删除旧的规格
|
||||
$teamGoodsItemModel = new TeamGoodsItemModel();
|
||||
$teamGoodsItemModel->where(['team_id' => (int)$post['team_id']])->delete();
|
||||
|
||||
// 新增拼团商品规格
|
||||
$lists = [];
|
||||
foreach ($post['item'] as $key => $value) {
|
||||
foreach ($value as $K => $item) {
|
||||
$lists[] = [
|
||||
'team_id' => (int)$post['team_id'],
|
||||
'goods_id' => $key,
|
||||
'item_id' => $K,
|
||||
'team_price' => $item
|
||||
];
|
||||
}
|
||||
}
|
||||
if ( !empty($lists)) {
|
||||
$teamGoodsItemModel->saveAll($lists);
|
||||
}
|
||||
|
||||
// 回调更新商品表拼团字段
|
||||
if ($post['status'] == 1) {
|
||||
$goodsModel->where(['id' => (int)$post['goods_id']])->update([
|
||||
'is_team' => 1,
|
||||
'update_time' => time()
|
||||
]);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
Db::rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 软删除
|
||||
* @param int $id
|
||||
* @author 张无忌(2021/1/13 18:02)
|
||||
* @return bool
|
||||
*/
|
||||
public static function softDelete(int $id)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$teamActivityModel = new TeamActivityModel();
|
||||
|
||||
$team = $teamActivityModel->field(true)->where(['team_id' => (int)$id])->find();
|
||||
if (!$team) {
|
||||
static::$error = '该拼团活动不存在';
|
||||
return false;
|
||||
}
|
||||
|
||||
$teamActivityModel->where(['team_id' => (int)$id])->update([
|
||||
'del' => 1
|
||||
]);
|
||||
|
||||
$goodsModel = new GoodsModel();
|
||||
$goodsModel->where(['id' => (int)$team['goods_id']])->update([
|
||||
'is_team' => 0,
|
||||
'update_time' => time()
|
||||
]);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
Db::rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 切换状态
|
||||
* @param $post
|
||||
* @author 张无忌(2021/1/13 17:53)
|
||||
* @return bool
|
||||
*/
|
||||
public static function switchStatus($post)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$teamActivityModel = new TeamActivityModel();
|
||||
$teamActivityModel->where(['team_id' => (int)$post['id']])->update([
|
||||
$post['field'] => $post['status']
|
||||
]);
|
||||
|
||||
$activity = $teamActivityModel->field('goods_id')->where(['team_id' => (int)$post['id']])->find();
|
||||
|
||||
$goodsModel = new GoodsModel();
|
||||
$goodsModel->where(['id' => (int)$activity['goods_id']])->update([
|
||||
'is_team' => $post['status'],
|
||||
'update_time' => time()
|
||||
]);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
Db::rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 拼团列表
|
||||
* @author 张无忌(2021/1/14 14:25)
|
||||
* @param $get
|
||||
* @return array
|
||||
*/
|
||||
public static function teamOrder($get)
|
||||
{
|
||||
$where = [
|
||||
['f.team_id', '=', (int)$get['team_id']]
|
||||
];
|
||||
|
||||
if ( !empty($get['goods_name']) and $get['goods_name'] !== '') {
|
||||
$goodsModel = new GoodsModel();
|
||||
$goods_ids = $goodsModel->where('name', 'like', '%' . $get['goods_name'] . '%')->column('id');
|
||||
if ( !empty($goods_ids)) {
|
||||
$teamActivityModel = new TeamActivityModel();
|
||||
$team_ids = $teamActivityModel->whereIn('goods_id', $goods_ids)->column('team_id');
|
||||
if ( !empty($team_ids)) {
|
||||
$where[] = ['f.team_id', 'in', $team_ids];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( !empty($get['nickname']) and $get['nickname'] !== '') {
|
||||
$where[] = ['nickname', 'like', '%' . $get['nickname'] . '%'];
|
||||
}
|
||||
|
||||
if ( !empty($get['found_time']) and $get['found_time'] !== '') {
|
||||
$where[] = ['found_time', '>=', strtotime($get['found_time'])];
|
||||
}
|
||||
|
||||
if ( !empty($get['found_end_time']) and $get['found_end_time'] !== '') {
|
||||
$where[] = ['found_end_time', '<=', strtotime($get['found_end_time'])];
|
||||
}
|
||||
|
||||
if (isset($get['status']) and is_numeric($get['status'])) {
|
||||
$where[] = ['f.status', '=', (int)$get['status']];
|
||||
}
|
||||
|
||||
$teamFoundModel = new TeamFoundModel();
|
||||
$count = $teamFoundModel->where($where)->alias('f')->count();
|
||||
|
||||
$lists = $teamFoundModel->field('f.*,t.goods_id,g.name,g.image')
|
||||
->alias('f')->where($where)
|
||||
->with('user.level')
|
||||
->join('team_activity t', 't.team_id = f.team_id')
|
||||
->join('goods g', 't.goods_id = g.id')
|
||||
->page($get['page'], $get['limit'])
|
||||
->order('f.id desc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['found_time'] = date('Y-m-d H:i:s', $item['found_time']);
|
||||
$item['found_end_time'] = date('Y-m-d H:i:s', $item['found_end_time']);
|
||||
$item['status'] = Team::getStatusDesc($item['status']);
|
||||
$item['user_level'] = $item['user']['level']['name'] ?? '无等级';
|
||||
}
|
||||
|
||||
return ['count' => $count, 'lists' => $lists];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,272 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
use app\admin\model\User;
|
||||
use app\common\logic\OrderRefundLogic;
|
||||
use app\common\model\Goods as GoodsModel;
|
||||
use app\common\model\Order;
|
||||
use app\common\model\OrderLog;
|
||||
use app\common\model\Pay;
|
||||
use app\common\model\Team;
|
||||
use app\common\model\TeamActivity as TeamActivityModel;
|
||||
use app\common\model\TeamFollow as TeamFollowModel;
|
||||
use app\common\model\TeamFound as TeamFoundModel;
|
||||
use app\common\server\UrlServer;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
|
||||
class TeamFoundLogic
|
||||
{
|
||||
protected static $error; //错误信息
|
||||
|
||||
/**
|
||||
* Notes: 错误错误信息
|
||||
* @author 张无忌(2021/1/12 16:01)
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getError()
|
||||
{
|
||||
return self::$error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 拼团列表
|
||||
* @param $get
|
||||
* @author 张无忌(2021/1/15 18:24)
|
||||
* @return array
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
// 查询条件
|
||||
$where = [];
|
||||
|
||||
if (isset($get['goods_name']) and $get['goods_name'] !== '') {
|
||||
$goodsModel = new GoodsModel();
|
||||
$ids = $goodsModel->field('id,name')->where([
|
||||
['name', 'like', '%' . $get['goods_name'] . '%']
|
||||
])->column('id');
|
||||
|
||||
$team_ids = TeamActivityModel::where('goods_id', 'in', $ids)->column('team_id');
|
||||
|
||||
$where[] = ['f.team_id', 'in', $team_ids];
|
||||
}
|
||||
|
||||
if (isset($get['status']) and is_numeric($get['status'])) {
|
||||
$where[] = ['f.status', '=', (int)$get['status']];
|
||||
}
|
||||
|
||||
if (isset($get['found_time']) and $get['found_time'] !== '') {
|
||||
$where[] = ['found_time', '>=', strtotime($get['found_time'])];
|
||||
}
|
||||
|
||||
if (isset($get['found_end_time']) and $get['found_end_time'] !== '') {
|
||||
$where[] = ['found_end_time', '<=', strtotime($get['found_end_time'])];
|
||||
}
|
||||
|
||||
if (isset($get['type']) and $get['type'] !== '') {
|
||||
if (isset($get['keyword']) and $get['keyword'] !== '') {
|
||||
switch ($get['type']) {
|
||||
case 'sn':
|
||||
$uid = User::where('sn', '=', $get['keyword'])->column('id');
|
||||
$where[] = ['user_id', 'in', $uid];
|
||||
break;
|
||||
case 'nickname':
|
||||
$uid = User::where('nickname', 'like', '%' . $get['keyword'] . '%')->column('id');
|
||||
$where[] = ['user_id', 'in', $uid];
|
||||
break;
|
||||
case 'mobile':
|
||||
$uid = User::where('mobile', '=', $get['keyword'])->column('id');
|
||||
$where[] = ['user_id', 'in', $uid];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//执行查询
|
||||
$teamFollowModel = new TeamFoundModel();
|
||||
$count = $teamFollowModel->where($where)->alias('f')->count();
|
||||
$lists = $teamFollowModel->alias('f')
|
||||
->field('f.*,g.name,g.image')
|
||||
->where($where)
|
||||
->with('user.level')
|
||||
->order('id', 'desc')
|
||||
->join('team_activity a', 'a.team_id = f.team_id')
|
||||
->join('goods g', 'g.id = a.goods_id')
|
||||
->append(['user.base_avatar'])
|
||||
->page($get['page'], $get['limit'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['image'] = UrlServer::getFileUrl($item['image']);
|
||||
$item['found_time'] = date('Y-m-d H:i:s', $item['found_time']);
|
||||
$item['found_end_time'] = date('Y-m-d H:i:s', $item['found_end_time']);
|
||||
$item['status_text'] = Team::getStatusDesc($item['status']);
|
||||
$item['user_level'] = $item['user']['level']['name'] ?? '无等级';
|
||||
}
|
||||
|
||||
return ['count'=>$count, 'lists'=>$lists];
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 拼团详细信息
|
||||
* @param $fount_id (团ID)
|
||||
* @author 张无忌(2021/1/18 15:09)
|
||||
* @return array
|
||||
*/
|
||||
public static function getDetail($fount_id)
|
||||
{
|
||||
$teamFoundModel = new TeamFoundModel();
|
||||
$detail = $teamFoundModel->field(true)
|
||||
->with('user.level')
|
||||
->where(['id'=>(int)$fount_id])
|
||||
->find()->toArray();
|
||||
|
||||
$detail['found_time'] = date('Y-m-d H:i:s', $detail['found_time']);
|
||||
$detail['found_end_time'] = date('Y-m-d H:i:s', $detail['found_end_time']);
|
||||
$detail['status'] = Team::getStatusDesc($detail['status']);
|
||||
$detail['user_level'] = $detail['user']['level']['name'] ?? '无等级';
|
||||
|
||||
return $detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 根据团ID, 获取团下面的订单
|
||||
* @param $get
|
||||
* @author 张无忌(2021/1/18 15:10)
|
||||
* @return array
|
||||
*/
|
||||
public static function teamOrderListById($get)
|
||||
{
|
||||
$where = [
|
||||
['found_id', '=', (int)$get['found_id']]
|
||||
];
|
||||
|
||||
$teamFollowModel = new TeamFollowModel();
|
||||
$count = $teamFollowModel->where($where)->count();
|
||||
$lists = $teamFollowModel->alias('f')
|
||||
->field('f.*,o.order_sn,o.order_status,o.create_time,o.total_amount,t.goods_id,g.name,g.image')
|
||||
->where($where)
|
||||
->with('user.level')
|
||||
->join('order o', 'o.id = f.order_id')
|
||||
->join('team_activity t', 't.team_id = f.team_id')
|
||||
->join('goods g', 't.goods_id = g.id')
|
||||
->page($get['page'], $get['limit'])
|
||||
->select()->toArray();
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['image'] = UrlServer::getFileUrl($item['image']);
|
||||
$item['relation'] = $item['type'] ? '团长' : '团员';
|
||||
$item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
|
||||
$item['order_status'] = Order::getOrderStatus($item['order_status']);
|
||||
$item['user_level'] = $item['user']['level']['name'] ?? '无等级';
|
||||
}
|
||||
|
||||
return ['count'=>$count, 'lists'=>$lists];
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 获取团退款详细信息
|
||||
* @author 张无忌(2021/1/18 18:43)
|
||||
* @param $get
|
||||
* @return array
|
||||
*/
|
||||
public static function getRefundDetail($get)
|
||||
{
|
||||
$where = [
|
||||
['found_id', '=', (int)$get['found_id']]
|
||||
];
|
||||
|
||||
$teamFollowModel = new TeamFollowModel();
|
||||
$count = $teamFollowModel->where($where)->count();
|
||||
$lists = $teamFollowModel->field(true)
|
||||
->with('user.level')
|
||||
->withAttr('order', function ($value, $data) {
|
||||
$orderModel = new Order();
|
||||
return $orderModel->field('id,order_sn,order_source,order_status,
|
||||
pay_status,pay_way,order_amount')
|
||||
->where('user_id', $data['follow_user_id'])
|
||||
->where('id', $data['order_id'])
|
||||
->where('team_found_id', (int)$data['found_id'])
|
||||
->append(['pay_way_text', 'pay_status_text', 'order_status_text', 'order_source_text'])
|
||||
->find();
|
||||
})
|
||||
->where('found_id', '=', $get['found_id'])
|
||||
->page($get['page'], $get['limit'])
|
||||
->append(['order'])
|
||||
->select()->toArray();
|
||||
|
||||
foreach ($lists as &$item){
|
||||
$item['user_level'] = $item['user']['level']['name'] ?? '无等级';
|
||||
}
|
||||
|
||||
return ['count'=>$count, 'lists'=>$lists];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 取消订单并退款
|
||||
* @param $post
|
||||
* @param $admin_id
|
||||
* @author 段誉(2021/1/29 18:28)
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function handleRefund($post, $admin_id)
|
||||
{
|
||||
Db::startTrans();
|
||||
try{
|
||||
$orderModel = new Order();
|
||||
$order = $orderModel->field(true)
|
||||
->where('id', '=', (int)$post['order_id'])
|
||||
->where(['order_status' => 1, 'pay_status' => 1])
|
||||
->find();
|
||||
|
||||
if (!$order){
|
||||
throw new Exception('订单信息错误');
|
||||
}
|
||||
|
||||
//取消订单
|
||||
OrderRefundLogic::cancelOrder($order['id'], OrderLog::TYPE_SHOP, $admin_id);
|
||||
//退款
|
||||
if ($order['pay_status'] == Pay::ISPAID){
|
||||
//更新订单状态
|
||||
OrderRefundLogic::cancelOrderRefundUpdate($order);
|
||||
//订单退款
|
||||
OrderRefundLogic::refund($order, $order['order_amount'], $order['order_amount']);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
|
||||
Db::rollback();
|
||||
static::$error = $e->getMessage();
|
||||
OrderRefundLogic::addErrorRefund($order, $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\admin\logic;
|
||||
use think\Db;
|
||||
|
||||
class UserGroupLogic
|
||||
{
|
||||
|
||||
/*
|
||||
* 分组列表
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
$where = [];
|
||||
$where[] = ['del','=', '0'];
|
||||
|
||||
//查询条数
|
||||
$user_group_count = Db::name('user_group')
|
||||
->where($where)
|
||||
->count();
|
||||
//数据查询
|
||||
$user_group_list = Db::name('user_group')
|
||||
->where($where)
|
||||
->field(['id','name', 'remark'])
|
||||
->order('id desc')
|
||||
->page($get['page'],$get['limit'])
|
||||
->select();
|
||||
|
||||
//返回数据及页面条数
|
||||
return ['list'=>$user_group_list,'count' =>$user_group_count];
|
||||
}
|
||||
|
||||
/**
|
||||
* 分组信息
|
||||
*/
|
||||
public static function info($id)
|
||||
{
|
||||
return Db::name('user_group')->where(['id' => $id])->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public static function addUserGroup($post)
|
||||
{
|
||||
$time = time(); //当前时间截
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'remark' => $post['remark'],
|
||||
'create_time' => $time
|
||||
];
|
||||
return Db::name('user_group')->insert($data); //插入数据
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public static function editUserGroup($post)
|
||||
{
|
||||
$time = time(); //当前时间截
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'remark' => $post['remark'],
|
||||
'update_time' => $time
|
||||
];
|
||||
return Db::name('user_group')->where(['del' => 0, 'id' => $post['id']])->update($data); //逻辑删除
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public static function delUserGroup($id)
|
||||
{
|
||||
$data = [
|
||||
'del' => 1,
|
||||
'update_time' => time(),
|
||||
];
|
||||
return Db::name('user_group')->where(['del' => 0, 'id' => $id])->update($data); //逻辑删除
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\logic;
|
||||
use app\common\logic\UserLevelLogic as CommonUserLevelLogic;
|
||||
use app\common\server\UrlServer;
|
||||
use think\Db;
|
||||
|
||||
class UserLevelLogic{
|
||||
|
||||
public static function lists($get){
|
||||
|
||||
$count = Db::name('user_level')->where(['del'=>0])->count();
|
||||
$list = Db::name('user_level')
|
||||
->where(['del'=>0])
|
||||
->page($get['page'], $get['limit'])
|
||||
->order('id desc')
|
||||
->select();
|
||||
|
||||
foreach ($list as &$item){
|
||||
$item['privilege_list'] = '';
|
||||
|
||||
$item['image'] = UrlServer::getFileUrl($item['image']);
|
||||
$item['background_image'] = UrlServer::getFileUrl($item['background_image']);
|
||||
if($item['privilege']){
|
||||
$privileges = explode(',',$item['privilege']);
|
||||
$privilege_list = Db::name('user_privilege')
|
||||
->where(['del'=>0,'id'=>$privileges])
|
||||
->column('name');
|
||||
$item['privilege_list'] = $privilege_list ? implode('、',$privilege_list) : '';
|
||||
}
|
||||
|
||||
}
|
||||
return ['count' => $count, 'list' => $list];
|
||||
}
|
||||
|
||||
public static function add($post){
|
||||
$now = time();
|
||||
$post['create_time'] = $now;
|
||||
$post['update_time'] = $now;
|
||||
$id = Db::name('user_level')->insertGetId($post);
|
||||
if($id){
|
||||
CommonUserLevelLogic::updateAllUserLevel($id);
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
|
||||
public static function edit($post){
|
||||
$now = time();
|
||||
$post['update_time'] = $now;
|
||||
Db::name('user_level')->where(['id'=>$post['id']])->update($post);
|
||||
CommonUserLevelLogic::updateAllUserLevel($post['id']);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function del($id){
|
||||
$now = time();
|
||||
$post['update_time'] = $now;
|
||||
$post['del'] = 1;
|
||||
return Db::name('user_level')->where(['id'=>$id])->update($post);
|
||||
}
|
||||
|
||||
public static function getUserLevel($id){
|
||||
$detail = Db::name('user_level')->where(['id'=>$id,'del'=>0])->find();
|
||||
$detail['abs_image'] = UrlServer::getFileUrl($detail['image']);
|
||||
$detail['abs_background_image'] = UrlServer::getFileUrl($detail['background_image']);
|
||||
return $detail;
|
||||
}
|
||||
|
||||
public static function getPrivilegeList(){
|
||||
return Db::name('user_privilege')->where(['del'=>0])->field('id,name')->select();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,802 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\api\cache\TokenCache;
|
||||
use app\common\logic\AccountLogLogic;
|
||||
use app\common\logic\LogicBase;
|
||||
use app\common\logic\UserLevelLogic;
|
||||
use app\common\model\AccountLog;
|
||||
use app\common\model\Order;
|
||||
use app\common\model\Pay;
|
||||
use app\common\model\User;
|
||||
use app\common\model\UserLevel;
|
||||
use app\common\server\UrlServer;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
|
||||
class UserLogic extends LogicBase
|
||||
{
|
||||
/**
|
||||
* 列表
|
||||
* @param $get
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function lists($get){
|
||||
$user = new User();
|
||||
|
||||
$where = [];
|
||||
$where[] = ['del','=', '0'];
|
||||
|
||||
//查询
|
||||
if(isset($get['keyword']) && $get['keyword']){
|
||||
$where[] = [$get['keyword_type'],'like','%'.$get['keyword'].'%'];
|
||||
}
|
||||
//等级查询
|
||||
if(isset($get['level']) && $get['level'] != ''){
|
||||
$where[] = ['level','=',$get['level']];
|
||||
}
|
||||
|
||||
//分组查询
|
||||
if(isset($get['group_id']) && $get['group_id']){
|
||||
$where[] = ['group_id','=',$get['group_id']];
|
||||
}
|
||||
//消费金额
|
||||
if(isset($get['total_amount_start']) && $get['total_amount_start']){
|
||||
$where[] = ['total_order_amount','>=',$get['total_amount_start']];
|
||||
}
|
||||
if(isset($get['total_amount_end']) && $get['total_amount_end']){
|
||||
$where[] = ['total_order_amount','<=',$get['total_amount_end']];
|
||||
}
|
||||
|
||||
//注册时间
|
||||
if(isset($get['start_time']) && $get['start_time']!=''){
|
||||
$where[] = ['create_time','>=',strtotime($get['start_time'])];
|
||||
}
|
||||
if(isset($get['end_time']) && $get['end_time']!=''){
|
||||
$where[] = ['create_time','<=',strtotime($get['end_time'])];
|
||||
}
|
||||
|
||||
$user_count = $user
|
||||
->where($where)
|
||||
->count();
|
||||
|
||||
$user_list = $user
|
||||
->where($where)
|
||||
->field('password,pay_password,salt',true)
|
||||
->page($get['page'],$get['limit'])
|
||||
->order('id desc')
|
||||
->select()->toArray();
|
||||
//会员分组
|
||||
$user_group = Db::name('user_group')->where(['del'=>0])->column('name','id');
|
||||
//会员等级
|
||||
$user_level = Db::name('user_level')->where(['del'=>0])->column('name','id');
|
||||
|
||||
$all_user_list = $user->where(['del'=>0])->column('sn,nickname,avatar,mobile,level','id');
|
||||
$group_list = db::name('user_group')->where(['del'=>0])->column('name','id');
|
||||
|
||||
foreach ($user_list as &$item){
|
||||
$item['total_amount'] = round($item['user_money'] + $item['earnings'], 2);
|
||||
$item['group_name'] = '-';
|
||||
$item['level_name'] = '无等级';
|
||||
//会员所属分组
|
||||
if(isset($user_group[$item['group_id']])){
|
||||
$item['group_name'] = $user_group[$item['group_id']];
|
||||
}
|
||||
|
||||
if(isset($user_level[$item['level']])){
|
||||
$item['level_name'] = $user_level[$item['level']];
|
||||
}
|
||||
|
||||
|
||||
if ($item['avatar'] != '/static/common/image/default/user.png') {
|
||||
$item['abs_avatar'] = $item['avatar'] ? UrlServer::getFileUrl($item['avatar']) : '';
|
||||
} else {
|
||||
$item['abs_avatar'] = '/static/common/image/default/user.png';
|
||||
}
|
||||
|
||||
// 上级推荐人
|
||||
$item['first_leader_info'] = User::getUserInfo($item['first_leader']);
|
||||
|
||||
//推荐下级人数
|
||||
$item['fans'] = User::where([
|
||||
['first_leader|second_leader', '=', $item['id']],
|
||||
['del', '=', 0]
|
||||
])->count();
|
||||
|
||||
|
||||
if(isset($group_list[$item['group_id']])){
|
||||
$item['group_name'] = $group_list[$item['group_id']];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ['count'=>$user_count , 'lists'=>$user_list];
|
||||
}
|
||||
|
||||
public static function exportFile($get)
|
||||
{
|
||||
$where[] = ['del','=', '0'];
|
||||
|
||||
//查询
|
||||
if(isset($get['keyword']) && $get['keyword']){
|
||||
$where[] = [$get['keyword_type'],'like','%'.$get['keyword'].'%'];
|
||||
}
|
||||
//等级查询
|
||||
if(isset($get['level']) && $get['level'] != ''){
|
||||
$where[] = ['level','=',$get['level']];
|
||||
}
|
||||
//分组查询
|
||||
if(isset($get['group_id']) && $get['group_id']){
|
||||
$where[] = ['group_id','=',$get['group_id']];
|
||||
}
|
||||
//消费金额
|
||||
if(isset($get['total_amount_start']) && $get['total_amount_start']){
|
||||
$where[] = ['total_order_amount','>=',$get['total_amount_start']];
|
||||
}
|
||||
if(isset($get['total_amount_end']) && $get['total_amount_end']){
|
||||
$where[] = ['total_order_amount','<=',$get['total_amount_end']];
|
||||
}
|
||||
|
||||
//注册时间
|
||||
if(isset($get['start_time']) && $get['start_time']!=''){
|
||||
$where[] = ['create_time','>=',strtotime($get['start_time'])];
|
||||
}
|
||||
if(isset($get['end_time']) && $get['end_time']!=''){
|
||||
$where[] = ['create_time','<=',strtotime($get['end_time'])];
|
||||
}
|
||||
|
||||
$user_list = Db::name('user')->where($where)
|
||||
->order('id desc')
|
||||
->select();
|
||||
|
||||
//会员分组
|
||||
$user_group = Db::name('user_group')->where(['del'=>0])->column('name','id');
|
||||
//会员等级
|
||||
$user_level = Db::name('user_level')->where(['del'=>0])->column('name','id');
|
||||
// 所有会员信息
|
||||
$all_user_list = User::where(['del'=>0])->column('sn,nickname,mobile,level','id');
|
||||
|
||||
$exportData = [];
|
||||
foreach ($user_list as $item){
|
||||
$groupName = '-';
|
||||
$levelName = '无等级';
|
||||
//会员所属分组
|
||||
if(isset($user_group[$item['group_id']])){
|
||||
$groupName = $user_group[$item['group_id']];
|
||||
}
|
||||
|
||||
if(isset($user_level[$item['level']])){
|
||||
$levelName = $user_level[$item['level']];
|
||||
}
|
||||
|
||||
$referrer_user_info = '';
|
||||
$referrer_nickname = '';
|
||||
$referrer_sn = '';
|
||||
$referrer_mobile = '';
|
||||
$referrer_level_name = '-';
|
||||
if(isset($all_user_list[$item['first_leader']])){
|
||||
$referrer_user = $all_user_list[$item['first_leader']];
|
||||
$referrer_nickname = $referrer_user['nickname'];
|
||||
$referrer_sn = $referrer_user['sn'];
|
||||
$referrer_mobile = $referrer_user['mobile'];
|
||||
if(isset($user_level[$referrer_user['level']])){
|
||||
$referrer_level_name =$user_level[$referrer_user['level']];
|
||||
}
|
||||
$referrer_user_info.= '【昵称:'.$referrer_nickname.' 编号:'.$referrer_sn. ' 手机:'. $referrer_mobile . ' 等级:'. $referrer_level_name.'】';
|
||||
}
|
||||
$loginTime = date('Y-m-d H:i:s', $item['login_time']);
|
||||
|
||||
$exportData[] = [$item['sn'], $item['nickname'], $levelName, $groupName, $referrer_user_info, $item['total_order_amount'], $item['user_money'], $item['user_integral'], $loginTime];
|
||||
}
|
||||
|
||||
$exportTitle = ['会员编号', '会员昵称', '会员等级', '会员分组', '推荐人信息', '消费金额', '账户余额', '积分', '最后登录时间'];
|
||||
$exportExt = 'xls';
|
||||
return ['exportTitle'=> $exportTitle, 'exportData' => $exportData, 'exportExt'=>$exportExt, 'exportName'=>'会员列表'.date('Y-m-d H:i:s')];
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 获取会员信息
|
||||
* @param $id
|
||||
* @param bool $getdata 是否获取原始数据
|
||||
* @param bool $expenditure 是否显示会员消费
|
||||
* @return User|mixed
|
||||
*/
|
||||
public static function getUser($id,$getdata = false,$expenditure = false){
|
||||
$user = User::get($id);
|
||||
$user->append(['level_name','group_name']);
|
||||
if($getdata){
|
||||
$user = $user->getData();
|
||||
if($user['birthday']) $user['birthday'] = date('Y-m-d',$user['birthday']);
|
||||
}
|
||||
$user['abs_avatar'] = UrlServer::getFileUrl($user['avatar']);
|
||||
if($expenditure){
|
||||
//本月的消费金额
|
||||
$month_amount = Db::name('order')
|
||||
->where('order_status','not in',[Order::STATUS_CLOSE,Order::STATUS_WAIT_PAY])
|
||||
->where(['user_id'=>$id,'pay_status'=>Pay::ISPAID])
|
||||
->whereTime('create_time', 'month')
|
||||
->sum('order_amount');
|
||||
//本月的订单笔数
|
||||
$month_num = Db::name('order')
|
||||
->where('order_status','not in',[Order::STATUS_CLOSE,Order::STATUS_WAIT_PAY])
|
||||
->where(['user_id'=>$id,'pay_status'=>Pay::ISPAID])
|
||||
->whereTime('create_time', 'month')
|
||||
->count();
|
||||
//累计消费笔数
|
||||
$total_num =Db::name('order')
|
||||
->where('order_status','not in',[Order::STATUS_CLOSE,Order::STATUS_WAIT_PAY])
|
||||
->where(['user_id'=>$id,'pay_status'=>Pay::ISPAID])
|
||||
->sum('order_amount');
|
||||
$avg_amount = Db::name('order')
|
||||
->where('order_status','not in',[Order::STATUS_CLOSE,Order::STATUS_WAIT_PAY])
|
||||
->where(['user_id'=>$id,'pay_status'=>Pay::ISPAID])
|
||||
->avg('order_amount');
|
||||
$user['month_amount'] = '¥'.round($month_amount,2);
|
||||
$user['month_num'] = round($month_num,2);
|
||||
$user['total_num'] = round($total_num,2);
|
||||
$user['avg_amount'] = '¥'.round($avg_amount,2);
|
||||
//分销会员
|
||||
$user['distribution_tips'] = '否';
|
||||
$user['superior_referrer'] = '-';
|
||||
$user['superior_referrer_sn'] = '-';
|
||||
if($user['is_distribution']){
|
||||
$user['distribution_tips'] = '是';
|
||||
$superior_referrer = Db::name('user')->where(['id'=>$user['first_leader']])->field('nickname,sn')->findOrEmpty();
|
||||
$user['superior_referrer'] = '-';
|
||||
$user['superior_referrer_sn'] = '-';
|
||||
if($superior_referrer) {
|
||||
$user['superior_referrer'] = $superior_referrer['nickname'];
|
||||
$user['superior_referrer_sn'] = $superior_referrer['sn'];
|
||||
}
|
||||
}
|
||||
// 头像
|
||||
$user['avatar'] = UrlServer::getFileUrl($user['avatar']);
|
||||
}
|
||||
return $user;
|
||||
}
|
||||
/*
|
||||
* 批量设置会员分组
|
||||
*/
|
||||
public static function setGroup($post){
|
||||
return Db::name('user')->where(['id'=>$post['user_ids']])->update(['group_id'=>$post['group_id']]);
|
||||
}
|
||||
|
||||
public static function fans($params)
|
||||
{
|
||||
$where = [];
|
||||
// 一级
|
||||
if ($params['type'] == 'one') {
|
||||
$where[] = ['first_leader', '=', $params['id']];
|
||||
}
|
||||
// 二级粉丝
|
||||
if ($params['type'] == 'two') {
|
||||
$where[] = ['second_leader', '=', $params['id']];
|
||||
}
|
||||
if(isset($params['keyword']) && !empty($params['keyword'])) {
|
||||
$where[] = [$params['field'], 'like', '%'. $params['keyword'] . '%'];
|
||||
}
|
||||
|
||||
$lists = User::field('id,sn,nickname,avatar,first_leader')
|
||||
->where($where)
|
||||
->page($params['page'], $params['limit'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$count = User::field('id,sn,nickname,avatar,first_leader')
|
||||
->where($where)
|
||||
->count();
|
||||
|
||||
foreach($lists as &$item) {
|
||||
$item['avatar'] = empty($item['avatar']) ? '' : UrlServer::getFileUrl($item['avatar']);
|
||||
$item['first_leader_info'] = User::getUserInfo($item['first_leader']);
|
||||
$item['fans'] = User::where([
|
||||
['first_leader|second_leader', '=', $item['id']],
|
||||
['del', '=', 0]
|
||||
])->count();
|
||||
}
|
||||
return [
|
||||
'lists' => $lists,
|
||||
'count' => $count,
|
||||
];
|
||||
}
|
||||
|
||||
/*
|
||||
* 用户账户调整
|
||||
*/
|
||||
public static function adjustAccount($post_data){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$update_data = [];
|
||||
$account_log = [];
|
||||
//余额调整
|
||||
if ($post_data['type'] == 'money') {
|
||||
$number = $post_data['money'];
|
||||
$change_type = 1;
|
||||
$source_type = AccountLog::admin_add_money;
|
||||
$money_sql = Db::raw('user_money + ' . $post_data['money']);
|
||||
if ($post_data['money_handle'] == 0) {
|
||||
$change_type = 2;
|
||||
$source_type = AccountLog::admin_reduce_money;
|
||||
$money_sql = Db::raw('user_money - ' . $post_data['money']);
|
||||
}
|
||||
$update_data['user_money'] = $money_sql;
|
||||
$account_log[] = [
|
||||
'number' => $number,
|
||||
'change_type' => $change_type,
|
||||
'source_type' => $source_type,
|
||||
'remark' => $post_data['money_remark'],
|
||||
];
|
||||
}
|
||||
//积分调整
|
||||
if ($post_data['type'] == 'integral') {
|
||||
$number = $post_data['integral'];
|
||||
$change_type = 1;
|
||||
$source_type = AccountLog::admin_add_integral;
|
||||
$integral_sql = Db::raw('user_integral + ' . $post_data['integral']);
|
||||
|
||||
if ($post_data['integral_handle'] == 0) {
|
||||
$change_type = 2;
|
||||
$source_type = AccountLog::admin_reduce_integral;
|
||||
$integral_sql = Db::raw('user_integral - ' . $post_data['integral']);
|
||||
}
|
||||
$update_data['user_integral'] = $integral_sql;
|
||||
$account_log[] = [
|
||||
'number' => $number,
|
||||
'change_type' => $change_type,
|
||||
'source_type' => $source_type,
|
||||
'remark' => $post_data['integral_remark'],
|
||||
];
|
||||
}
|
||||
//成长值调整
|
||||
if ($post_data['type'] == 'growth') {
|
||||
$number = $post_data['growth'];
|
||||
$change_type = 1;
|
||||
$source_type = AccountLog::admin_add_growth;
|
||||
$growth_sql = Db::raw('user_growth + ' . $post_data['growth']);
|
||||
|
||||
if ($post_data['growth_handle'] == 0) {
|
||||
$change_type = 2;
|
||||
$source_type = AccountLog::admin_reduce_growth;
|
||||
$growth_sql = Db::raw('user_growth - ' . $post_data['growth']);
|
||||
}
|
||||
$update_data['user_growth'] = $growth_sql;
|
||||
$account_log[] = [
|
||||
'number' => $number,
|
||||
'change_type' => $change_type,
|
||||
'source_type' => $source_type,
|
||||
'remark' => $post_data['growth_remark'],
|
||||
];
|
||||
}
|
||||
|
||||
//佣金调整
|
||||
if ($post_data['type'] == 'earnings') {
|
||||
$number = $post_data['earnings'];
|
||||
$change_type = 1;
|
||||
$source_type = AccountLog::admin_inc_earnings;
|
||||
$money_sql = Db::raw('earnings + ' . $post_data['earnings']);
|
||||
if ($post_data['earnings_handle'] == 0) {
|
||||
$change_type = 2;
|
||||
$source_type = AccountLog::admin_reduce_earnings;
|
||||
$money_sql = Db::raw('earnings - ' . $post_data['earnings']);
|
||||
}
|
||||
$update_data['earnings'] = $money_sql;
|
||||
$account_log[] = [
|
||||
'number' => $number,
|
||||
'change_type' => $change_type,
|
||||
'source_type' => $source_type,
|
||||
'remark' => $post_data['earnings_remark'],
|
||||
];
|
||||
}
|
||||
|
||||
Db::name('user')->where('id', $post_data['id'])->update($update_data);
|
||||
foreach ($account_log as $item => $value){
|
||||
AccountLogLogic::AccountRecord($post_data['id'],$value['number'],$value['change_type'],$value['source_type'],$value['remark']);
|
||||
}
|
||||
if (isset($post_data['growth_handle'])) {
|
||||
UserLevelLogic::updateUserLevel($post_data['id']);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function adjustLevel($post_data){
|
||||
|
||||
return Db::name('user')->where('id',$post_data['id'])->update(['level'=>$post_data['level']]);
|
||||
}
|
||||
/*
|
||||
* 获取分组
|
||||
*/
|
||||
public static function getGroupList(){
|
||||
return Db::name('user_group')->where(['del'=>0])->field('id,name')->select();
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取等级
|
||||
*/
|
||||
public static function getLevelList()
|
||||
{
|
||||
return UserLevel::getSelectList();
|
||||
}
|
||||
|
||||
/*
|
||||
* 编辑会员
|
||||
*/
|
||||
public static function edit($post){
|
||||
$user = User::get($post['id']);
|
||||
if (!empty($post['password'])) {
|
||||
//生成密码
|
||||
$post['password'] = create_password($post['password'], $user->salt);
|
||||
} else {
|
||||
unset($post['password']);
|
||||
}
|
||||
$post['update_time'] = time();
|
||||
$post['birthday'] = strtotime($post['birthday']);
|
||||
|
||||
//如果用户被禁用,设置当前用户token超时
|
||||
if ($post['disable'] == 1) {
|
||||
//设置token超时
|
||||
Db::name('session')
|
||||
->where(['user_id' => $user['id']])
|
||||
->update(['expire_time' => time()]);
|
||||
|
||||
//清除token缓存
|
||||
$tokens = Db::name('session')
|
||||
->where(['user_id' => $user['id']])
|
||||
->select();
|
||||
|
||||
if(count($tokens) > 0) {
|
||||
foreach ($tokens as $item) {
|
||||
$token_cache = new TokenCache($item['token']);
|
||||
$token_cache->del();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $user->allowField(true)->save($post);
|
||||
}
|
||||
|
||||
public static function getList($get){
|
||||
switch ($get['type']){
|
||||
case 0://下单明细
|
||||
$order = new Order();
|
||||
$count = $order->alias('o')
|
||||
->where(['user_id'=>$get['user_id']])
|
||||
->where('order_status','not in',[Order::STATUS_CLOSE,Order::STATUS_WAIT_PAY])
|
||||
->count();
|
||||
|
||||
$list = $order->alias('o')
|
||||
->where(['user_id'=>$get['user_id']])
|
||||
->where('order_status','not in',[Order::STATUS_CLOSE,Order::STATUS_WAIT_PAY])
|
||||
->page($get['page'],$get['limit'])
|
||||
->order('id desc')
|
||||
->field('o.id,order_sn,total_num,pay_time,total_amount,order_amount,discount_amount,
|
||||
o.create_time,consignee,province,city,district,o.address,mobile')
|
||||
->select();
|
||||
|
||||
break;
|
||||
case 1://积分明细
|
||||
$account_log =new AccountLog();
|
||||
$count = $account_log
|
||||
->where(['user_id'=>$get['user_id'],'source_type'=>AccountLog::integral_change])
|
||||
->count();
|
||||
$list = $account_log
|
||||
->where(['user_id'=>$get['user_id'],'source_type'=>AccountLog::integral_change])
|
||||
->page($get['page'],$get['limit'])
|
||||
->order('id desc')
|
||||
->select();
|
||||
break;
|
||||
case 2://签到明细
|
||||
$account_log =new AccountLog();
|
||||
$count = $account_log
|
||||
->where(['user_id'=>$get['user_id'],'source_type'=>AccountLog::sign_in_integral])
|
||||
->count();
|
||||
$list = $account_log
|
||||
->where(['user_id'=>$get['user_id'],'source_type'=>AccountLog::sign_in_integral])
|
||||
->page($get['page'],$get['limit'])
|
||||
->order('id desc')
|
||||
->select();
|
||||
break;
|
||||
case 3://余额明细
|
||||
$account_log = new AccountLog();
|
||||
$count = $account_log
|
||||
->where(['user_id'=>$get['user_id'],'source_type'=>AccountLog::money_change])
|
||||
->count();
|
||||
$list = $account_log
|
||||
->where(['user_id'=>$get['user_id'],'source_type'=>AccountLog::money_change])
|
||||
->page($get['page'],$get['limit'])
|
||||
->order('id desc')
|
||||
->select();
|
||||
break;
|
||||
case 4://推广明细
|
||||
$count = 1;
|
||||
$first_leader = Db::name('user')->where(['id'=>$get['user_id']])->value('first_leader');
|
||||
$list = [];
|
||||
if($first_leader){
|
||||
$user = new User();
|
||||
$list = $user
|
||||
->where(['id'=>$first_leader])
|
||||
->field('id,sn,nickname,mobile,avatar,level,sex,create_time,total_order_amount,user_money,user_integral')
|
||||
->order('id desc')
|
||||
->select();
|
||||
$level_list = Db::name('user_level')->where(['del'=>0])->column('name','id');
|
||||
foreach ($list as &$item) {
|
||||
$item['avatar'] = UrlServer::getFileUrl($item['avatar']);
|
||||
$item['level_name'] = '-';
|
||||
if(isset($level_list[$item['level']])){
|
||||
$item['level_name'] = $level_list[$item['level']];
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 5://收货地址
|
||||
$count = Db::name('user_address')
|
||||
->where(['user_id'=>$get['user_id'],'del'=>0])
|
||||
->count();
|
||||
$list = Db::name('user_address')
|
||||
->where(['user_id'=>$get['user_id'],'del'=>0])
|
||||
->order('id desc')
|
||||
->select();
|
||||
foreach ($list as &$item){
|
||||
$item['default'] = '否';
|
||||
$region = Db::name('dev_region')
|
||||
->where('id', 'IN', [$item['province_id'], $item['city_id'], $item['district_id']])->order('level asc')->column('name');
|
||||
$region_desc = implode('', $region);
|
||||
$item['address'] = $region_desc.$item['address'];
|
||||
if($item['is_default']){
|
||||
$item['default'] = '是';
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return ['count'=>$count , 'lists'=>$list];
|
||||
}
|
||||
|
||||
/**
|
||||
* 转账记录
|
||||
*/
|
||||
public static function transferRecord($get)
|
||||
{
|
||||
$where = [];
|
||||
// 开始时间
|
||||
if(!empty($get['start_time'])) {
|
||||
$where[] = ['create_time', '>=', strtotime($get['start_time'])];
|
||||
}
|
||||
// 结束时间
|
||||
if(!empty($get['end_time'])) {
|
||||
$where[] = ['create_time', '<=', strtotime($get['end_time'])];
|
||||
}
|
||||
|
||||
$list = Db::name('user_transfer')
|
||||
->where($where)
|
||||
->page($get['page'], $get['limit'])
|
||||
->order('create_time', 'desc')
|
||||
->select();
|
||||
|
||||
$count = Db::name('user_transfer')->count();
|
||||
|
||||
// 获取转账人及收款人信息
|
||||
foreach($list as &$item) {
|
||||
$transferFromInfo = Db::name('user')->alias('u')
|
||||
->field('u.sn, u.nickname, u.avatar, ul.name as user_level_name')
|
||||
->leftJoin('user_level ul', 'u.level=ul.id')
|
||||
->where('u.id', $item['transfer_from_id'])->find();
|
||||
$transferToInfo = Db::name('user')->alias('u')
|
||||
->field('u.sn, u.nickname, u.avatar, ul.name as user_level_name')
|
||||
->leftJoin('user_level ul', 'u.level=ul.id')
|
||||
->where('u.id', $item['transfer_to_id'])->find();
|
||||
$item['from_nickname'] = $transferFromInfo['nickname'];
|
||||
$item['from_avatar'] = UrlServer::getFileUrl($transferFromInfo['avatar']);
|
||||
$item['from_sn'] = $transferFromInfo['sn'];
|
||||
$item['from_level_name'] = $transferFromInfo['user_level_name'] ?? '无等级';
|
||||
$item['to_nickname'] = $transferToInfo['nickname'];
|
||||
$item['to_avatar'] = UrlServer::getFileUrl($transferToInfo['avatar']);
|
||||
$item['to_sn'] = $transferToInfo['sn'];
|
||||
$item['to_level_name'] = $transferToInfo['user_level_name'] ?? '无等级';
|
||||
$item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'count' => $count,
|
||||
'list' => $list
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function userLists()
|
||||
{
|
||||
$where[] = ['del', '=', 0];
|
||||
// 用户信息
|
||||
if (isset($params['keyword']) && !empty($params['keyword'])) {
|
||||
$where[] = ['sn|nickname', 'like', '%'. $params['keyword'] .'%'];
|
||||
}
|
||||
|
||||
$lists = \app\common\model\User::field('id,sn,nickname,id as distribution')
|
||||
->where($where)
|
||||
->page($params['page'], $params['limit'])
|
||||
->select()
|
||||
->toArray();
|
||||
$count = User::where($where)->count();
|
||||
|
||||
return [
|
||||
'count' => $count,
|
||||
'lists' => $lists,
|
||||
];
|
||||
}
|
||||
|
||||
public static function adjustFirstLeader($params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
switch($params['type']) {
|
||||
// 指定推荐人
|
||||
case 'assign':
|
||||
$formatData = self::assignFirstLeader($params);
|
||||
break;
|
||||
// 设置推荐人为系统,即清空上级
|
||||
case 'system':
|
||||
$formatData = self::clearFirstLeader($params);
|
||||
break;
|
||||
}
|
||||
|
||||
$user = User::findOrEmpty($params['id']);
|
||||
// 旧关系链
|
||||
if (!empty($user->ancestor_relation)) {
|
||||
$old_ancestor_relation = $user->id . ',' .$user->ancestor_relation;
|
||||
} else {
|
||||
$old_ancestor_relation = $user->id;
|
||||
}
|
||||
|
||||
// 更新当前用户的分销关系
|
||||
User::where(['id' => $params['id']])->update($formatData);
|
||||
|
||||
//更新当前用户下级的分销关系
|
||||
$data = [
|
||||
'second_leader' => $formatData['first_leader'],
|
||||
'third_leader' => $formatData['second_leader'],
|
||||
'update_time' => time()
|
||||
];
|
||||
User::where(['first_leader' => $params['id']])->update($data);
|
||||
|
||||
//更新当前用户下下级的分销关系
|
||||
$data = [
|
||||
'third_leader' => $formatData['first_leader'],
|
||||
'update_time' => time()
|
||||
];
|
||||
User::where(['second_leader' => $params['id']])->update($data);
|
||||
|
||||
//更新当前用户所有后代的关系链
|
||||
Db::name('user')
|
||||
->where("find_in_set({$params['id']},ancestor_relation)")
|
||||
->exp('ancestor_relation', "replace(ancestor_relation,'{$old_ancestor_relation}','" . trim("{$params['id']},{$formatData['ancestor_relation']}", ',') . "')")
|
||||
->update();
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch(\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function assignFirstLeader($params)
|
||||
{
|
||||
if (empty($params['first_id'])) {
|
||||
throw new \think\Exception('请选择推荐人');
|
||||
}
|
||||
$firstLeader = User::field(['id', 'first_leader', 'second_leader', 'third_leader', 'ancestor_relation'])
|
||||
->where('id', $params['first_id'])
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
if(empty($firstLeader)) {
|
||||
throw new \think\Exception('推荐人不存在');
|
||||
}
|
||||
if ($params['first_id'] == $params['id']) {
|
||||
throw new \think\Exception('不能指定上级是自己');
|
||||
}
|
||||
$ancestorArr = explode(',', trim($firstLeader['ancestor_relation']));
|
||||
if(!empty($ancestorArr) && in_array($params['id'], $ancestorArr)) {
|
||||
throw new \think\Exception('不能指定推荐人为自己的下级');
|
||||
}
|
||||
|
||||
// 上级
|
||||
$first_leader_id = $firstLeader['id'];
|
||||
// 上上级
|
||||
$second_leader_id = $firstLeader['first_leader'];
|
||||
// 上上上级
|
||||
$third_leader_id = $firstLeader['second_leader'];
|
||||
// 拼接关系链
|
||||
$firstLeader['ancestor_relation'] = $firstLeader['ancestor_relation'] ?? ''; // 清空null值及0
|
||||
$my_ancestor_relation = $first_leader_id. ',' . $firstLeader['ancestor_relation'];
|
||||
// 去除两端逗号
|
||||
$my_ancestor_relation = trim($my_ancestor_relation, ',');
|
||||
$data = [
|
||||
'first_leader' => $first_leader_id,
|
||||
'second_leader' => $second_leader_id,
|
||||
'third_leader' => $third_leader_id,
|
||||
'ancestor_relation' => $my_ancestor_relation,
|
||||
'update_time' => time()
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function clearFirstLeader($params)
|
||||
{
|
||||
$data = [
|
||||
'first_leader' => 0,
|
||||
'second_leader' => 0,
|
||||
'third_leader' => 0,
|
||||
'ancestor_relation' => '',
|
||||
'update_time' => time()
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getInfo($id)
|
||||
{
|
||||
$user = User::field('id,sn,level,nickname,avatar,birthday,group_id,sex,mobile,create_time,login_time,user_money,user_growth,earnings,first_leader')
|
||||
->findOrEmpty($id);
|
||||
if($user->isEmpty()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$user =$user->toArray();
|
||||
$orderWhere = [
|
||||
'user_id' => $id,
|
||||
'del' => 0,
|
||||
'pay_status' => 1
|
||||
];
|
||||
// 上级推荐人
|
||||
$user['first_leader_info'] = User::getUserInfo($user['first_leader']);
|
||||
// 推荐下级人数
|
||||
$user['fans'] = User::where([
|
||||
['first_leader|second_leader', '=', $user['id']],
|
||||
['del', '=', 0],
|
||||
])->count();
|
||||
// 总资产
|
||||
$user['assets'] = $user['user_money'] + $user['earnings'];
|
||||
// 总订单数
|
||||
$user['order_num'] = Order::where($orderWhere)->count();
|
||||
// 总消费金额
|
||||
$user['total_amount'] = Order::where($orderWhere)->sum('order_amount');
|
||||
$user['total_amount'] = round($user['total_amount'] ,2);
|
||||
// 平均消费单价
|
||||
$user['avg_amount'] = Order::where($orderWhere)->avg('order_amount');
|
||||
$user['avg_amount'] = round($user['avg_amount'], 2);
|
||||
// 头像
|
||||
$user['avatar'] = UrlServer::getFileUrl($user['avatar']);
|
||||
// 用户等级
|
||||
$levelName = UserLevel::where('id', $user['level'])->value('name');
|
||||
$user['level_name'] = empty($levelName) ? '无等级' : $levelName;
|
||||
// 会员分组
|
||||
$user['user_group'] = Db::name('user_group')->where('id', $user['group_id'])->value('name');
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\logic;
|
||||
use app\common\server\UrlServer;
|
||||
use think\Db;
|
||||
|
||||
class UserPrivilegeLogic{
|
||||
|
||||
public static function lists($get){
|
||||
$count = Db::name('user_privilege')
|
||||
->where(['del'=>0])
|
||||
->count();
|
||||
|
||||
$list = Db::name('user_privilege')
|
||||
->where(['del'=>0])
|
||||
->page($get['page'], $get['limit'])
|
||||
->select();
|
||||
|
||||
foreach ($list as &$item) {
|
||||
$item['image'] = UrlServer::getFileUrl($item['image']);
|
||||
}
|
||||
|
||||
return ['count' => $count, 'list' => $list];
|
||||
|
||||
}
|
||||
|
||||
public static function add($post){
|
||||
$post['create_time'] = time();
|
||||
$post['del'] = 0;
|
||||
return Db::name('user_privilege')->insert($post);
|
||||
}
|
||||
|
||||
public static function edit($post){
|
||||
$post['update_time'] = time();
|
||||
return Db::name('user_privilege')->where(['id'=>$post['id']])->update($post);
|
||||
}
|
||||
|
||||
public static function del($id){
|
||||
$update_date = [
|
||||
'update_time' => time(),
|
||||
'del' => 1,
|
||||
];
|
||||
return Db::name('user_privilege')->where(['id'=>$id,'del'=>0])->update($update_date);
|
||||
}
|
||||
|
||||
public static function getPrivilege($id){
|
||||
$detail = Db::name('user_privilege')->where(['id'=>$id,'del'=>0])->find();
|
||||
$detail['abs_image'] = UrlServer::getFileUrl($detail['image']);
|
||||
return $detail;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\common\logic\LogicBase;
|
||||
use app\common\model\UserLevel;
|
||||
use app\common\server\ConfigServer;
|
||||
use app\common\server\UrlServer;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 用户设置逻辑层
|
||||
* Class UserLogic
|
||||
* @package app\admin\logic\setting
|
||||
*/
|
||||
class UserSettingLogic extends LogicBase
|
||||
{
|
||||
/**
|
||||
* @notes 获取用户配置
|
||||
* @return array
|
||||
* @author Tab
|
||||
*/
|
||||
public static function getConfig()
|
||||
{
|
||||
$config = [
|
||||
// 邀请下级 0-关闭 1-开启(默认)
|
||||
'is_open' => ConfigServer::get('invite', 'is_open', 1),
|
||||
// 邀请下级资格 1-全部用户(默认) 2-分销会员
|
||||
'qualifications' => ConfigServer::get('invite', 'qualifications', [1]),
|
||||
// 成为下级条件 1-邀请码(默认)
|
||||
'condition' => ConfigServer::get('invite', 'condition', 1),
|
||||
// 自定义邀请海报
|
||||
'poster' => ConfigServer::get('invite', 'poster', '/images/share/share_user_bg.png'),
|
||||
//指定会员
|
||||
'invite_appoint_user' => ConfigServer::get('invite', 'invite_appoint_user', []),
|
||||
];
|
||||
$config['poster'] = empty($config['poster']) ? UrlServer::getFileUrl('images/share/share_user_bg.png') : UrlServer::getFileUrl($config['poster']);
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 用户设置
|
||||
* @param $params
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author Tab
|
||||
*/
|
||||
public static function set($params)
|
||||
{
|
||||
try {
|
||||
if(!isset($params['poster']) || empty($params['poster'])) {
|
||||
throw new \Exception('请选择自定义海报');
|
||||
}
|
||||
if(!isset($params['qualifications'])) {
|
||||
throw new \Exception('请至少选择一种分销资格');
|
||||
}
|
||||
//兼容以前版本,保存数据格式
|
||||
$params['qualifications'] = [$params['qualifications']];
|
||||
if(count($params['qualifications']) >= 2){
|
||||
throw new \Exception('分销资格只能选择一种');
|
||||
}
|
||||
$allowFields = ['is_open', 'qualifications', 'condition', 'poster','invite_appoint_user'];
|
||||
if(in_array(2,$params['qualifications'])){
|
||||
if(!isset($params['invite_appoint_user']) || empty($params['invite_appoint_user'])){
|
||||
throw new \Exception('请选择指定会员等级');
|
||||
}
|
||||
$user_level = self::getUserLevel();
|
||||
$user_level = array_column($user_level,'id');
|
||||
$ids = [];
|
||||
foreach ($params['invite_appoint_user'] as $id =>$val) {
|
||||
if(!in_array($id,$user_level)){
|
||||
throw new \Exception('用户等级错误,请刷新页面');
|
||||
}
|
||||
$ids[] = $id;
|
||||
}
|
||||
$params['invite_appoint_user'] = $ids;
|
||||
}else{
|
||||
|
||||
$params['invite_appoint_user'] = [];
|
||||
|
||||
}
|
||||
|
||||
foreach ($allowFields as $field) {
|
||||
if(isset($params[$field])) {
|
||||
$params[$field] = is_array($params[$field]) ? json_encode($params[$field], JSON_UNESCAPED_UNICODE) : $params[$field];
|
||||
$params[$field] = $field == 'poster' ? UrlServer::setFileUrl($params[$field]) : $params[$field];
|
||||
ConfigServer::set('invite', $field, $params[$field]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取会员等级
|
||||
* @author cjhao
|
||||
* @date 2022/2/25 16:10
|
||||
*/
|
||||
public static function getUserLevel()
|
||||
{
|
||||
return UserLevel::getSelectList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,362 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
use app\common\logic\OrderLogLogic;
|
||||
use app\common\model\Order;
|
||||
use app\common\model\OrderLog;
|
||||
use app\common\model\UserLevel;
|
||||
use app\common\model\Verification;
|
||||
use app\common\server\UrlServer;
|
||||
use think\Db;
|
||||
use think\facade\Hook;
|
||||
|
||||
class VerificationLogic
|
||||
{
|
||||
/**
|
||||
* @notes 列表查询条件
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2021/8/16 5:59 下午
|
||||
*/
|
||||
public static function getWhere($params)
|
||||
{
|
||||
$where = [];
|
||||
$where[] = ['o.del', '=', 0];
|
||||
$where[] = ['o.delivery_type', '=', 2];
|
||||
|
||||
//提货码
|
||||
if (!empty($params['pickup_code'])) {
|
||||
$where[] = ['o.pickup_code', 'like', '%'.$params['pickup_code'].'%'];
|
||||
}
|
||||
|
||||
//核销状态
|
||||
if (isset($params['verification_status']) && $params['verification_status'] != '') {
|
||||
$where[] = ['o.verification_status', '=', $params['verification_status']];
|
||||
}
|
||||
|
||||
//订单搜素
|
||||
if (!empty($params['search_key']) && !empty($params['keyword'])) {
|
||||
$keyword = $params['keyword'];
|
||||
switch ($params['search_key']) {
|
||||
case 'order_sn':
|
||||
$where[] = ['o.order_sn', 'like', '%' . $keyword . '%'];
|
||||
break;
|
||||
case 'user_sn':
|
||||
$where[] = ['u.sn', 'like', '%' . $keyword . '%'];
|
||||
break;
|
||||
case 'nickname':
|
||||
$where[] = ['nickname', 'like', '%' . $keyword . '%'];
|
||||
break;
|
||||
case 'consignee':
|
||||
$where[] = ['consignee', 'like', '%' . $keyword . '%'];
|
||||
break;
|
||||
case 'consignee_mobile':
|
||||
$where[] = ['o.mobile', 'like', '%' . $keyword . '%'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//商品名称
|
||||
if (!empty($params['goods_name'])) {
|
||||
$where[] = ['g.goods_name', 'like', '%' . $params['goods_name'] . '%'];
|
||||
}
|
||||
|
||||
//订单类型
|
||||
if (!empty($params['order_type'])) {
|
||||
$where[] = ['o.order_type', '=', $params['order_type']];
|
||||
}
|
||||
|
||||
//订单来源
|
||||
if (!empty($params['order_source'])) {
|
||||
$where[] = ['o.order_source', '=', $params['order_source']];
|
||||
}
|
||||
|
||||
//付款方式
|
||||
if (!empty($params['pay_way'])) {
|
||||
$where[] = ['o.pay_way', '=', $params['pay_way']];
|
||||
}
|
||||
|
||||
//下单时间
|
||||
if (!empty($params['start_time'])) {
|
||||
$where[] = ['o.create_time', '>=', strtotime($params['start_time'])];
|
||||
}
|
||||
if (!empty($params['end_time'])) {
|
||||
$where[] = ['o.create_time', '<=', strtotime($params['end_time'])];
|
||||
}
|
||||
|
||||
return $where;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 自提订单列表
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2021/8/16 6:09 下午
|
||||
*/
|
||||
public static function lists($params)
|
||||
{
|
||||
$order = new Order();
|
||||
$where = self::getWhere($params);
|
||||
|
||||
$field = 'o.*,pay_way as pay_way_text,ss.name as shop_name';
|
||||
|
||||
$count = $order
|
||||
->alias('o')
|
||||
->field($field)
|
||||
->join('user u', 'u.id = o.user_id')
|
||||
->join('order_goods g', 'g.order_id = o.id')
|
||||
->join('selffetch_shop ss', 'ss.id = o.selffetch_shop_id')
|
||||
->with(['order_goods', 'user.level'])
|
||||
->where($where)
|
||||
->group('o.id')
|
||||
->count();
|
||||
|
||||
$lists = $order
|
||||
->alias('o')
|
||||
->field($field)
|
||||
->join('user u', 'u.id = o.user_id')
|
||||
->join('order_goods g', 'g.order_id = o.id')
|
||||
->join('selffetch_shop ss', 'ss.id = o.selffetch_shop_id')
|
||||
->with(['order_goods', 'user.level'])
|
||||
->where($where)
|
||||
->append(['delivery_address', 'order_type_text', 'user.base_avatar', 'order_source_text','verification_status_text'])
|
||||
->page($params['page'], $params['limit'])
|
||||
->order('o.id desc')
|
||||
->group('o.id')
|
||||
->select()->toArray();
|
||||
|
||||
foreach ($lists as &$list){
|
||||
foreach ($list['order_goods'] as &$order_goods){
|
||||
$order_good_info = json_decode($order_goods['goods_info'], true);
|
||||
$order_goods['goods_name'] = $order_good_info['goods_name'];
|
||||
$order_goods['spec_value'] = $order_good_info['spec_value_str'];
|
||||
$order_goods['image'] = empty($order_good_info['spec_image']) ?
|
||||
UrlServer::getFileUrl($order_good_info['image']) : UrlServer::getFileUrl($order_good_info['spec_image']);
|
||||
}
|
||||
$list['delivery_type'] = Order::getDeliveryType($list['delivery_type']);
|
||||
$list['user_level'] = $list['user']['level']['name'] ?? '无等级';
|
||||
|
||||
$list['verifier_name'] = '-';
|
||||
$list['verification_time'] = '-';
|
||||
if ($list['verification_status'] == Order::WRITTEN_OFF) {
|
||||
$verification = Verification::where('order_id',$list['id'])->json(['snapshot'],true)->find();
|
||||
$list['verification_time'] = date('Y-m-d H:i:s',$verification['create_time']);
|
||||
$list['verifier_name'] = $verification['snapshot']['name'];
|
||||
}
|
||||
}
|
||||
return ['count' => $count, 'lists' => $lists];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 导出自提订单列表
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2021/8/16 7:55 下午
|
||||
*/
|
||||
public static function exportFile($params)
|
||||
{
|
||||
$where = self::getWhere($params);
|
||||
|
||||
$field = 'o.*,o.order_type as order_type_text, o.order_source as order_source_text,o.pay_way as pay_way_text,o.pay_status as pay_status_text,o.order_status as order_status_text,u.sn as user_sn,u.nickname as user_nickname,u.level as user_level';
|
||||
|
||||
$lists = Order::alias('o')
|
||||
->join('user u','u.id=o.user_id')
|
||||
->join('order_goods og', 'og.order_id=o.id')
|
||||
->join('goods g', 'g.id=og.goods_id')
|
||||
->with([
|
||||
'order_goods',
|
||||
'selffetch_shop' => function ($query) {
|
||||
$query->field([ 'id', 'name', 'address', 'district', 'city', 'province' ])->append([ 'shop_address' ]);
|
||||
}
|
||||
])
|
||||
->field($field)
|
||||
->where($where)
|
||||
->append([ 'verification_status_text', 'order_status_text' ])
|
||||
->order('o.id', 'desc')
|
||||
->group('og.order_id')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$userLevel = UserLevel::where('del', 0)->column(['id','name'], 'id');
|
||||
|
||||
$exportTitle = [
|
||||
'订单编号', '订单类型', '下单时间', '支付时间', '订单来源',
|
||||
'会员编号', '会员昵称', '会员等级',
|
||||
'商品信息', '商品数量',
|
||||
'运费金额', '商品总金额', '优惠金额', '积分抵扣', '应付金额', '支付方式',
|
||||
'配送方式', '自提门店', '自提地址', '联系人', '联系手机', '提货码',
|
||||
'核销状态', '订单状态', '核销员', '核销时间',
|
||||
];
|
||||
$exportExt = 'xls';
|
||||
$exportData = [];
|
||||
foreach ($lists as $item){
|
||||
$item['delivery_type'] = Order::getDeliveryType($item['delivery_type']);
|
||||
$orderSn = 'SN'.$item['order_sn']; // 转字符串
|
||||
$level = $userLevel[$item['user_level']] ?? '无等级';
|
||||
// $deliveryType = Order::getDeliveryType($item['delivery_type']);
|
||||
$goodsStr = '';
|
||||
foreach($item['order_goods'] as $subItem) {
|
||||
$goodsInfo = json_decode($subItem['goods_info'], true);
|
||||
$goodsStr.= '【'.$goodsInfo['goods_name'].' 规格:'.$goodsInfo['spec_value_str']. ' 数量:'.$subItem['goods_num']. '】';
|
||||
}
|
||||
|
||||
$item['verifier_name'] = '-';
|
||||
$item['verification_time'] = '-';
|
||||
if ($item['verification_status'] == Order::WRITTEN_OFF) {
|
||||
$verification = Verification::where('order_id',$item['id'])->json(['snapshot'],true)->find();
|
||||
$item['verification_time'] = date('Y-m-d H:i:s',$verification['create_time']);
|
||||
$item['verifier_name'] = $verification['snapshot']['name'];
|
||||
}
|
||||
|
||||
$exportData[] = [
|
||||
$orderSn, $item['order_type_text'], $item['create_time'], $item['pay_time'], $item['order_source_text'],
|
||||
$item['user_sn'], $item['user_nickname'], $level,
|
||||
$goodsStr, $item['total_num'],
|
||||
$item['shipping_price'], $item['goods_price'], $item['discount_amount'], $item['integral_amount'], $item['order_amount'], $item['pay_way_text'],
|
||||
$item['delivery_type'], $item['selffetch_shop']['name'] ?? '', $item['selffetch_shop']['shop_address'] ?? '', $item['consignee'], $item['mobile'], $item['pickup_code'],
|
||||
$item['verification_status_text'], $item['order_status_text'], $item['verifier_name'], $item['verification_time'],
|
||||
];
|
||||
}
|
||||
return ['exportTitle'=> $exportTitle, 'exportData' => $exportData, 'exportExt'=>$exportExt, 'exportName'=>'自提订单列表'.date('Y-m-d H:i:s')];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 提货核销
|
||||
* @param $params
|
||||
* @return bool|string
|
||||
* @author ljj
|
||||
* @date 2021/8/17 10:09 上午
|
||||
*/
|
||||
public static function verification($params)
|
||||
{
|
||||
// 启动事务
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = Order::find($params['id']);
|
||||
|
||||
//添加核销记录
|
||||
$snapshot = [
|
||||
'sn' => $params['admin_info']['account'],
|
||||
'name' => $params['admin_info']['name']
|
||||
];
|
||||
$verification = new Verification;
|
||||
$verification->order_id = $params['id'];
|
||||
$verification->selffetch_shop_id = $order['selffetch_shop_id'];
|
||||
$verification->handle_id = $params['admin_info']['id'];
|
||||
$verification->verification_scene = Verification::TYPE_ADMIN;
|
||||
$verification->snapshot = json_encode($snapshot);
|
||||
$verification->create_time = time();
|
||||
$verification->save();
|
||||
|
||||
//更新订单状态
|
||||
$order->order_status = Order::STATUS_FINISH;
|
||||
$order->verification_status = Order::WRITTEN_OFF;
|
||||
$order->update_time = time();
|
||||
$order->confirm_take_time = time();
|
||||
$order->save();
|
||||
|
||||
//订单日志
|
||||
OrderLogLogic::record(
|
||||
OrderLog::TYPE_SHOP,
|
||||
OrderLog::SHOP_VERIFICATION,
|
||||
$params['id'],
|
||||
$params['admin_info']['id'],
|
||||
OrderLog::SHOP_VERIFICATION
|
||||
);
|
||||
|
||||
// 赠送成长值和积分
|
||||
Hook::listen('give_reward', [
|
||||
'order_id' => $params['id'],
|
||||
'scene' => 3, //3=订单完成
|
||||
]);
|
||||
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 提货核销详情
|
||||
* @param $id
|
||||
* @return Order
|
||||
* @author ljj
|
||||
* @date 2021/8/17 10:00 上午
|
||||
*/
|
||||
public static function verificationInfo($id)
|
||||
{
|
||||
$detail = Order::alias('o')
|
||||
->join('selffetch_shop ss', 'ss.id = o.selffetch_shop_id')
|
||||
->with('order_goods')
|
||||
->where('o.id',$id)
|
||||
->field('o.id,o.pickup_code,ss.name as shop_name,o.consignee,o.mobile')
|
||||
->find();
|
||||
|
||||
foreach ($detail['order_goods'] as &$order_goods) {
|
||||
$info = json_decode($order_goods['goods_info'], true);
|
||||
$order_goods['goods_name'] = $info['goods_name'];
|
||||
$order_goods['spec_value'] = $info['spec_value_str'];
|
||||
$order_goods['goods_image'] = empty($info['spec_image']) ?
|
||||
UrlServer::getFileUrl($info['image']) : UrlServer::getFileUrl($info['spec_image']);
|
||||
}
|
||||
|
||||
return $detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 核销查询
|
||||
* @param $id
|
||||
* @return Order
|
||||
* @author ljj
|
||||
* @date 2021/8/17 11:47 上午
|
||||
*/
|
||||
public static function verificationQuery($id)
|
||||
{
|
||||
$detail = Order::alias('o')
|
||||
->join('selffetch_shop ss', 'ss.id = o.selffetch_shop_id')
|
||||
->join('verification v', 'o.id = v.order_id')
|
||||
->with('order_goods')
|
||||
->where('o.id',$id)
|
||||
->field('o.id,ss.name as shop_name,o.consignee,o.mobile,v.snapshot,v.create_time as verification_time')
|
||||
->json(['snapshot'],true)
|
||||
->find();
|
||||
|
||||
foreach ($detail['order_goods'] as &$order_goods) {
|
||||
$info = json_decode($order_goods['goods_info'], true);
|
||||
$order_goods['goods_name'] = $info['goods_name'];
|
||||
$order_goods['spec_value'] = $info['spec_value_str'];
|
||||
$order_goods['goods_image'] = empty($info['spec_image']) ?
|
||||
UrlServer::getFileUrl($info['image']) : UrlServer::getFileUrl($info['spec_image']);
|
||||
}
|
||||
|
||||
$detail['verification_time'] = date('Y-m-d H:i:s',$detail['verification_time']);
|
||||
|
||||
return $detail;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,287 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
/**
|
||||
* 功能: 微信企业付款
|
||||
* 用途:企业向微信用户个人付款
|
||||
* 证书:需要
|
||||
* 失败后一定要用【原来的商户订单号】去重试,不然有可能存在重复支付的风险!!!
|
||||
* 商户订单号: 必须唯一且需要为33位以下的数字或字母
|
||||
*/
|
||||
|
||||
use EasyWeChat\Factory;
|
||||
use app\common\model\Pay;
|
||||
use app\common\server\ConfigServer;
|
||||
use app\common\server\WeChatServer;
|
||||
use think\Db;
|
||||
use app\common\model\User;
|
||||
|
||||
class WechatCorporatePaymentLogic
|
||||
{
|
||||
/**
|
||||
* 获取app
|
||||
*/
|
||||
public static function getApp($client)
|
||||
{
|
||||
$config = WeChatServer::getPayConfigBySource($client)['config'];
|
||||
$app = Factory::payment($config);
|
||||
return $app;
|
||||
}
|
||||
|
||||
/**
|
||||
* 企业付款
|
||||
*/
|
||||
public static function pay($withdraw)
|
||||
{
|
||||
// 微信零钱最小提现金额 1元
|
||||
if($withdraw['left_money'] < 1) {
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '扣除手续费后提现金额不能小于1元'
|
||||
];
|
||||
}
|
||||
// 每天最多可向同一用户付款10次
|
||||
$count = Db::name('withdraw_apply')
|
||||
->whereTime('update_time', 'd') // 今天
|
||||
->where('user_id', $withdraw['user_id'])
|
||||
->where('type', 2) // 微信零钱
|
||||
->where('status', '>=', 2) // 提现中、提现成功、提现失败
|
||||
->count();
|
||||
if($count > 10) {
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '同一个用户一天最多可付款10次'
|
||||
];
|
||||
}
|
||||
// 一天一个用户累计提现金额不能超过5000元
|
||||
$sum = Db::name('withdraw_apply')
|
||||
->whereTime('update_time', 'd') // 今天
|
||||
->where('user_id', $withdraw['user_id'])
|
||||
->where('type', 2) // 微信零钱
|
||||
->where('status', 'in', [2, 3]) // 提现中、提现成功
|
||||
->sum('left_money');
|
||||
$sum = $sum + $withdraw['left_money'];
|
||||
if($sum > 5000) {
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '一天一个用户累计提现金额(不算手续费)不能超过5000元'
|
||||
];
|
||||
}
|
||||
|
||||
// 用户授权信息(同一个用户可能有多条,取client最小的一条)
|
||||
$userAuth = Db::name('user_auth')->where('user_id', $withdraw['user_id'])->order('client', 'asc')->find();
|
||||
if(!$userAuth) {
|
||||
// 无授权记录
|
||||
return [
|
||||
'code'=> 0,
|
||||
'msg' => '查询不到该用户的openid'
|
||||
];
|
||||
}
|
||||
// 获取app
|
||||
$app = self::getApp($userAuth['client']);
|
||||
// 商户唯一订单号
|
||||
$partner_trade_no = $withdraw['sn'];
|
||||
// 发起企业付款
|
||||
$result = $app->transfer->toBalance([
|
||||
// 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号)
|
||||
'partner_trade_no' => $partner_trade_no,
|
||||
'openid' => $userAuth['openid'],
|
||||
// NO_CHECK:不校验真实姓名, FORCE_CHECK:强校验真实姓名
|
||||
'check_name' => 'NO_CHECK',
|
||||
// 如果 check_name 设置为FORCE_CHECK,则必填用户真实姓名
|
||||
're_user_name' => '',
|
||||
// 企业付款金额,单位为分 100分=1元
|
||||
'amount' => 100 * $withdraw['left_money'],
|
||||
// 企业付款操作说明信息。必填
|
||||
'desc' => '佣金提现'
|
||||
]);
|
||||
// 马上将提现申请单状态修改为提现中,并记录微信返回信息,避免同一提现单多次点击发起多次企业付款
|
||||
$fiterField = ['appid','mch_appid', 'mchid', 'mch_id', 'openid']; // 过滤敏感字段
|
||||
$filterResult = array_filter($result, function($key) use ($fiterField) {
|
||||
return !in_array($key, $fiterField);
|
||||
}, ARRAY_FILTER_USE_KEY);
|
||||
Db::name('withdraw_apply')
|
||||
->where('id', $withdraw['id'])
|
||||
->update([
|
||||
'status' => 2, // 提现中
|
||||
'update_time' => time(),
|
||||
'pay_desc' => json_encode($filterResult)
|
||||
]);
|
||||
// 通信标识 return_code
|
||||
if($result['return_code'] == 'SUCCESS') {
|
||||
// 业务结果 result_code
|
||||
if($result['result_code'] == 'SUCCESS') {
|
||||
// 企业付款成功, 更新提现申请单状态为提现成功并记录支付单号及支付时间
|
||||
Db::name('withdraw_apply')
|
||||
->where('id', $withdraw['id'])
|
||||
->update([
|
||||
'status' => 3, // 提现成功
|
||||
'payment_no' => $result['payment_no'],
|
||||
'payment_time' => strtotime($result['payment_time']),
|
||||
'update_time' => time()
|
||||
]);
|
||||
return [
|
||||
'code' => 1,
|
||||
'msg' => '成功提现至微信零钱'
|
||||
];
|
||||
}else{
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => $result['err_code_des']
|
||||
];
|
||||
}
|
||||
}else{
|
||||
// 提现至零钱失败,更新提现申请单为提现失败,并回退佣金
|
||||
Db::name('withdraw_apply')
|
||||
->where('id', $withdraw['id'])
|
||||
->update([
|
||||
'status' => 4, // 提现失败
|
||||
'update_time' => time()
|
||||
]);
|
||||
//回退佣金
|
||||
$user = User::get($withdraw['user_id']);
|
||||
$user->earnings = ['inc', $withdraw['money']];
|
||||
$user->save();
|
||||
|
||||
//增加佣金变动记录
|
||||
AccountLogLogic::AccountRecord(
|
||||
$withdraw['user_id'],
|
||||
$withdraw['money'],
|
||||
1,
|
||||
AccountLog::withdraw_back_earnings,
|
||||
'',
|
||||
$withdraw['id'],
|
||||
$withdraw['sn']
|
||||
);
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => $result['return_msg']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询企业付款
|
||||
*/
|
||||
public static function search($withdraw)
|
||||
{
|
||||
$userAuth = Db::name('user_auth')->where('user_id', $withdraw['user_id'])->order('client', 'asc')->find();
|
||||
if(!$userAuth) {
|
||||
// 无授权记录
|
||||
return [
|
||||
'code'=> 0,
|
||||
'msg' => '查询不到该用户的openid'
|
||||
];
|
||||
}
|
||||
$app = self::getApp($userAuth['client']);
|
||||
$partnerTradeNo = $withdraw['sn'];
|
||||
$result = $app->transfer->queryBalanceOrder($partnerTradeNo);
|
||||
$fiterField = ['appid','mch_appid', 'mchid', 'mch_id', 'openid']; // 过滤敏感字段
|
||||
$filterResult = array_filter($result, function($key) use ($fiterField) {
|
||||
return !in_array($key, $fiterField);
|
||||
}, ARRAY_FILTER_USE_KEY );
|
||||
// 记录查询结果
|
||||
Db::name('withdraw_apply')
|
||||
->where('id', $withdraw['id'])
|
||||
->update([
|
||||
'update_time' => time(),
|
||||
'pay_search_desc' => json_encode($filterResult)
|
||||
]);
|
||||
if($result['return_code'] == 'SUCCESS') { // 通信标识
|
||||
if($result['result_code'] == 'SUCCESS') { // 另一个标识
|
||||
if($result['status'] == 'SUCCESS') { // 业务结果
|
||||
// 转账成功,标记提现申请单为提现成功,记录支付信息
|
||||
Db::name('withdraw_apply')
|
||||
->where('id', $withdraw['id'])
|
||||
->update([
|
||||
'status' => 3, // 提现成功
|
||||
'payment_no' => $result['detail_id'],
|
||||
'payment_time' => strtotime($result['payment_time']),
|
||||
'update_time' => time()
|
||||
]);
|
||||
return [
|
||||
'code' => 1,
|
||||
'msg' => '已提现成功'
|
||||
];
|
||||
}else if($result['status'] == 'FAILED'){
|
||||
// 转账失败
|
||||
Db::name('withdraw_apply')
|
||||
->where('id', $withdraw['id'])
|
||||
->update([
|
||||
'status' => 4, // 提现失败
|
||||
'update_time' => time()
|
||||
]);
|
||||
//回退佣金
|
||||
$user = User::get($withdraw['user_id']);
|
||||
$user->earnings = ['inc', $withdraw['money']];
|
||||
$user->save();
|
||||
|
||||
//增加佣金变动记录
|
||||
AccountLogLogic::AccountRecord(
|
||||
$withdraw['user_id'],
|
||||
$withdraw['money'],
|
||||
1,
|
||||
AccountLog::withdraw_back_earnings,
|
||||
'',
|
||||
$withdraw['id'],
|
||||
$withdraw['sn']
|
||||
);
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '提现至微信零钱失败'
|
||||
];
|
||||
}else{
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => $result['reason']
|
||||
];
|
||||
}
|
||||
}else{
|
||||
// 查看这个提现单今天是否有重新发起过付款,如果没有则尝试使用【相同的商户订单号】再次发起付款
|
||||
// $count = Db::name('withdraw_apply')
|
||||
// ->whereTime('repay_time', 'd') // 今天
|
||||
// ->where('id', $withdraw['id']) // 提现申请单号
|
||||
// ->count();
|
||||
// if(!$count) {
|
||||
// // 记录重新发起支付的时间
|
||||
// Db::name('withdraw_apply')->where('id', $withdraw['id'])->update([
|
||||
// 'repay_time' => time(),
|
||||
// 'update_time' => time()
|
||||
// ]);
|
||||
// return self::pay($withdraw);
|
||||
// }else{
|
||||
// return [
|
||||
// 'code' => 0,
|
||||
// 'msg' => $result['err_code_des']
|
||||
// ];
|
||||
// }
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => $result['err_code_des']
|
||||
];
|
||||
}
|
||||
}else{
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => $result['return_msg']
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,281 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
use app\common\model\Pay;
|
||||
use app\common\server\WeChatServer;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 功能: 商家转账到零钱
|
||||
* 用途:商户可以通过该接口同时向多个用户微信零钱进行转账操作。
|
||||
* 证书:需要
|
||||
* 请求URL:https://api.mch.weixin.qq.com/v3/transfer/batches
|
||||
* 失败后一定要用【原来的商户订单号】去重试,不然有可能存在重复支付的风险!!!
|
||||
* 转账批次单中涉及金额的字段单位为“分”
|
||||
* 成功受理商家转账请求后,可调用《商家明细单号查询明细单》接口来判断转账明细列表状态
|
||||
*/
|
||||
class WechatMerchantTransferLogic
|
||||
{
|
||||
/**
|
||||
* @notes 商家转账到零钱
|
||||
* @param $withdrawApply
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
* @author ljj
|
||||
* @date 2022/9/27 4:40 下午
|
||||
*/
|
||||
public static function transfer($withdrawApply)
|
||||
{
|
||||
// 微信零钱最小提现金额 1元
|
||||
if($withdrawApply['left_money'] < 1) {
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '扣除手续费后提现金额不能小于1元'
|
||||
];
|
||||
}
|
||||
// 每天最多可向同一用户付款7次
|
||||
$count = Db::name('withdraw_apply')
|
||||
->whereTime('update_time', 'd') // 今天
|
||||
->where('user_id', $withdrawApply['user_id'])
|
||||
->where('type', 2) // 微信零钱
|
||||
->where('status', '>=', 2) // 提现中、提现成功、提现失败
|
||||
->count();
|
||||
if($count >= 7) {
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '同一个用户一天最多可付款7次'
|
||||
];
|
||||
}
|
||||
// 一个商户默认同一日付款总额限额10万元
|
||||
$sum = Db::name('withdraw_apply')
|
||||
->whereTime('update_time', 'd') // 今天
|
||||
->where('type', 2) // 微信零钱
|
||||
->where('status', 'in', [2, 3]) // 提现中、提现成功
|
||||
->sum('left_money');
|
||||
$sum = $sum + $withdrawApply['left_money'];
|
||||
if($sum > 100000) {
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '一个商户默认同一日付款总额限额10万元'
|
||||
];
|
||||
}
|
||||
|
||||
// 用户授权信息(同一个用户可能有多条,取client最小的一条)
|
||||
$userAuth = Db::name('user_auth')->where('user_id', $withdrawApply['user_id'])->order('client', 'asc')->find();
|
||||
if(!$userAuth) {
|
||||
// 无授权记录
|
||||
return [
|
||||
'code'=> 0,
|
||||
'msg' => '查询不到该用户的openid'
|
||||
];
|
||||
}
|
||||
|
||||
//获取配置信息
|
||||
$config = WeChatServer::getPayConfigBySource($userAuth['client'])['config'];
|
||||
|
||||
|
||||
//请求URL
|
||||
$url = 'https://api.mch.weixin.qq.com/v3/transfer/batches';
|
||||
//请求方式
|
||||
$http_method = 'POST';
|
||||
//请求参数
|
||||
$data = [
|
||||
'appid' => $config['app_id'],//申请商户号的appid或商户号绑定的appid(企业号corpid即为此appid)
|
||||
'out_batch_no' => $withdrawApply['batch_no'],//商户系统内部的商家批次单号,要求此参数只能由数字、大小写字母组成,在商户系统内部唯一
|
||||
'batch_name' => '提现至微信零钱',//该笔批量转账的名称
|
||||
'batch_remark' => '提现至微信零钱',//转账说明,UTF8编码,最多允许32个字符
|
||||
'total_amount' => $withdrawApply['left_money'] * 100,//转账金额单位为“分”。转账总金额必须与批次内所有明细转账金额之和保持一致,否则无法发起转账操作
|
||||
'total_num' => 1,//一个转账批次单最多发起三千笔转账。转账总笔数必须与批次内所有明细之和保持一致,否则无法发起转账操作
|
||||
'transfer_detail_list' => [
|
||||
[//发起批量转账的明细列表,最多三千笔
|
||||
'out_detail_no' => $withdrawApply['sn'],//商户系统内部区分转账批次单下不同转账明细单的唯一标识,要求此参数只能由数字、大小写字母组成
|
||||
'transfer_amount' => $withdrawApply['left_money'] * 100,//转账金额单位为分
|
||||
'transfer_remark' => '提现至微信零钱',//单条转账备注(微信用户会收到该备注),UTF8编码,最多允许32个字符
|
||||
'openid' => $userAuth['openid'],//openid是微信用户在公众号appid下的唯一用户标识(appid不同,则获取到的openid就不同),可用于永久标记一个用户
|
||||
]]
|
||||
];
|
||||
if ($withdrawApply['left_money'] >= 2000) {
|
||||
if (empty($withdrawApply['real_name'])) {
|
||||
throw new \Exception('转账金额 >= 2000元,收款用户真实姓名必填');
|
||||
}
|
||||
$data['transfer_detail_list'][0]['user_name'] = self::getEncrypt($withdrawApply['real_name'],$config);
|
||||
}
|
||||
|
||||
$token = self::token($url,$http_method,$data,$config);//获取token
|
||||
$result = self::https_request($url,json_encode($data),$token);//发送请求
|
||||
$result_arr = json_decode($result,true);
|
||||
|
||||
if(!isset($result_arr['create_time'])) {//批次受理失败
|
||||
throw new \Exception($result_arr['message']);
|
||||
}
|
||||
|
||||
//批次受理成功,更新提现申请单为提现中状态
|
||||
Db::name('withdraw_apply')
|
||||
->where('id', $withdrawApply['id'])
|
||||
->update([
|
||||
'status' => 2, // 提现中
|
||||
'update_time' => time(),
|
||||
'pay_desc' => $result
|
||||
]);
|
||||
|
||||
return [
|
||||
'code' => 1,
|
||||
'msg' => '零钱提现中'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 签名生成
|
||||
* @param $url
|
||||
* @param $http_method
|
||||
* @param $data
|
||||
* @param $config
|
||||
* @return string
|
||||
* @author ljj
|
||||
* @date 2022/9/27 4:14 下午
|
||||
*/
|
||||
public static function token($url,$http_method,$data,$config)
|
||||
{
|
||||
$timestamp = time();//请求时间戳
|
||||
$url_parts = parse_url($url);//获取请求的绝对URL
|
||||
$nonce = $timestamp.rand('10000','99999');//请求随机串
|
||||
$body = empty($data) ? '' : json_encode((object)$data);//请求报文主体
|
||||
$stream_opts = [
|
||||
"ssl" => [
|
||||
"verify_peer"=>false,
|
||||
"verify_peer_name"=>false,
|
||||
]
|
||||
];
|
||||
|
||||
$apiclient_cert_arr = openssl_x509_parse(file_get_contents($config['cert_path'],false, stream_context_create($stream_opts)));
|
||||
$serial_no = $apiclient_cert_arr['serialNumberHex'];//证书序列号
|
||||
$mch_private_key = file_get_contents($config['key_path'],false, stream_context_create($stream_opts));//密钥
|
||||
$merchant_id = $config['mch_id'];//商户id
|
||||
$canonical_url = ($url_parts['path'] . (!empty($url_parts['query']) ? "?${url_parts['query']}" : ""));
|
||||
$message = $http_method."\n".
|
||||
$canonical_url."\n".
|
||||
$timestamp."\n".
|
||||
$nonce."\n".
|
||||
$body."\n";
|
||||
openssl_sign($message, $raw_sign, $mch_private_key, 'sha256WithRSAEncryption');
|
||||
$sign = base64_encode($raw_sign);//签名
|
||||
$schema = 'WECHATPAY2-SHA256-RSA2048';
|
||||
$token = sprintf('mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"',
|
||||
$merchant_id, $nonce, $timestamp, $serial_no, $sign);//微信返回token
|
||||
return $schema.' '.$token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 发送请求
|
||||
* @param $url
|
||||
* @param $data
|
||||
* @param $token
|
||||
* @return bool|string
|
||||
* @author ljj
|
||||
* @date 2022/9/27 4:15 下午
|
||||
*/
|
||||
public static function https_request($url,$data,$token)
|
||||
{
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_URL, (string)$url);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||||
if (!empty($data)){
|
||||
curl_setopt($curl, CURLOPT_POST, 1);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
}
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
//添加请求头
|
||||
$headers = [
|
||||
'Authorization:'.$token,
|
||||
'Accept: application/json',
|
||||
'Content-Type: application/json; charset=utf-8',
|
||||
'User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
|
||||
];
|
||||
if(!empty($headers)){
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
}
|
||||
$output = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 敏感信息加解密
|
||||
* @param $str
|
||||
* @param $config
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
* @author ljj
|
||||
* @date 2022/9/27 3:53 下午
|
||||
*/
|
||||
public static function getEncrypt($str,$config)
|
||||
{
|
||||
//$str是待加密字符串
|
||||
$public_key = file_get_contents($config['cert_path']);
|
||||
$encrypted = '';
|
||||
if (openssl_public_encrypt($str, $encrypted, $public_key, OPENSSL_PKCS1_OAEP_PADDING)) {
|
||||
//base64编码
|
||||
$sign = base64_encode($encrypted);
|
||||
} else {
|
||||
throw new \Exception('encrypt failed');
|
||||
}
|
||||
return $sign;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 商家明细单号查询明细单API
|
||||
* @param $withdrawApply
|
||||
* @return mixed
|
||||
* @author ljj
|
||||
* @date 2022/9/27 5:54 下午
|
||||
*/
|
||||
public static function details($withdrawApply)
|
||||
{
|
||||
$userAuth = Db::name('user_auth')->where('user_id', $withdrawApply['user_id'])->order('client', 'asc')->find();
|
||||
if(!$userAuth) {
|
||||
// 无授权记录
|
||||
return [
|
||||
'code'=> 0,
|
||||
'msg' => '查询不到该用户的openid'
|
||||
];
|
||||
}
|
||||
//获取配置信息
|
||||
$pay = Pay::where(['code' => 'wechat'])->find()->toArray();
|
||||
$config = [
|
||||
'mch_id' => $pay['config']['mch_id'] ?? '',
|
||||
'cert_path' => dirname(__FILE__, 2).'/../../public/'.$pay['config']['apiclient_cert'] ?? '',
|
||||
'key_path' => dirname(__FILE__, 2).'/../../public/'.$pay['config']['apiclient_key'] ?? '',
|
||||
];
|
||||
|
||||
//请求URL
|
||||
$url = 'https://api.mch.weixin.qq.com/v3/transfer/batches/out-batch-no/'.$withdrawApply['batch_no'].'/details/out-detail-no/'.$withdrawApply['sn'];
|
||||
//请求方式
|
||||
$http_method = 'GET';
|
||||
//请求参数
|
||||
$data = [];
|
||||
$token = self::token($url,$http_method,$data,$config);//获取token
|
||||
$result = self::https_request($url,$data,$token);//发送请求
|
||||
$result_arr = json_decode($result,true);
|
||||
return $result_arr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\logic;
|
||||
use app\common\model\WeChat;
|
||||
use think\Db;
|
||||
|
||||
class WechatReplyLogic{
|
||||
public static function lists($get){
|
||||
$where[] = ['del','=',0];
|
||||
if(isset($get['type'])){
|
||||
$where[] = ['reply_type','=',$get['type']];
|
||||
}
|
||||
$count = Db::name('wechat_reply')
|
||||
->where($where)
|
||||
->count();
|
||||
$list = Db::name('wechat_reply')
|
||||
->where($where)
|
||||
->page($get['page'],$get['limit'])
|
||||
->select();
|
||||
foreach ($list as $key => $reply) {
|
||||
$reply['content_type'] && $list[$key]['content_type'] = '文本';
|
||||
switch ($reply['matching_type']){
|
||||
case 1:
|
||||
$list[$key]['matching_type'] = '全匹配';
|
||||
break;
|
||||
case 2:
|
||||
$list[$key]['matching_type'] = '模糊匹配';
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ['count'=>$count,'list'=>$list];
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* note 添加微信回复
|
||||
* create_time 2020/12/5 15:24
|
||||
*/
|
||||
public static function add($post){
|
||||
$post['create_time'] = time();
|
||||
$post['del'] = 0;
|
||||
if($post['reply_type'] !== WeChat::msg_type_text && $post['status']){
|
||||
Db::name('wechat_reply')->where(['reply_type'=>$post['reply_type']])->update(['update_time'=>time(),'status'=>0]);
|
||||
}
|
||||
return Db::name('wechat_reply')->insert($post);
|
||||
}
|
||||
|
||||
/**
|
||||
* note 编辑微信回复
|
||||
* create_time 2020/12/5 15:24
|
||||
*/
|
||||
public static function edit($post){
|
||||
$post['update_time'] = time();
|
||||
if($post['reply_type'] !== WeChat::msg_type_text && $post['status']){
|
||||
Db::name('wechat_reply')->where(['reply_type'=>$post['reply_type']])->update(['update_time'=>time(),'status'=>0]);
|
||||
}
|
||||
return Db::name('wechat_reply')->where(['id'=>$post['id']])->update($post);
|
||||
}
|
||||
|
||||
/**
|
||||
* note 删除微信回复
|
||||
* create_time 2020/12/5 15:25
|
||||
*/
|
||||
public static function del($id){
|
||||
|
||||
return Db::name('wechat_reply')->where(['id'=>$id])->update(['update_time'=>time(),'del'=>1]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* note 获取微信回复
|
||||
* create_time 2020/12/5 15:25
|
||||
*/
|
||||
public static function getReply($id){
|
||||
return Db::name('wechat_reply')->where(['id'=>$id])->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* note
|
||||
* create_time 2020/12/5 18:56
|
||||
*/
|
||||
public static function changeFields($id,$field,$field_value,$reply_type){
|
||||
if( 'status' === $field && $field_value && $reply_type !== WeChat::msg_type_text){
|
||||
Db::name('wechat_reply')->where(['reply_type'=>$reply_type])->update(['update_time'=>time(),'status'=>0]);
|
||||
}
|
||||
return Db::name('wechat_reply')->where(['id'=>$id])->update(['update_time'=>time(),$field=>$field_value]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,391 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\admin\model\WithdrawApply;
|
||||
use app\common\logic\AccountLogLogic;
|
||||
use app\admin\logic\WechatCorporatePaymentLogic;
|
||||
use app\common\server\ConfigServer;
|
||||
use app\common\server\UrlServer;
|
||||
use app\common\model\AccountLog;
|
||||
use app\common\model\User;
|
||||
use app\common\model\Withdraw;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use think\helper\Time;
|
||||
|
||||
class WithdrawLogic
|
||||
{
|
||||
/**
|
||||
* 佣金提现列表
|
||||
* @param $get
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
$where = [];
|
||||
// 会员信息
|
||||
if (!empty($get['search_key']) && !empty($get['keyword'])) {
|
||||
$keyword = $get['keyword'];
|
||||
if ($get['search_key'] == 'user_sn') {
|
||||
$where[] = ['u.sn', '=', $keyword];
|
||||
} elseif ($get['search_key'] == 'nickname'){
|
||||
$where[] = ['u.nickname', 'like', '%' . $keyword . '%'];
|
||||
}
|
||||
}
|
||||
|
||||
//提现单号
|
||||
if (isset($get['withdraw_sn']) && $get['withdraw_sn'] != '') {
|
||||
$where[] = ['w.sn', '=', $get['withdraw_sn']];
|
||||
}
|
||||
|
||||
//提现方式
|
||||
if (isset($get['type']) && $get['type'] != '') {
|
||||
$where[] = ['type', '=', $get['type']];
|
||||
}
|
||||
|
||||
//提现状态
|
||||
if (isset($get['status']) && $get['status'] != '') {
|
||||
$where[] = ['status', '=', $get['status']];
|
||||
}
|
||||
|
||||
// 提现时间
|
||||
if (isset($get['start_time']) && $get['start_time'] && isset($get['end_time']) && $get['end_time']) {
|
||||
$where[] = ['w.create_time', 'between', [strtotime($get['start_time']), strtotime($get['end_time'])]];
|
||||
}else{
|
||||
// $where[] = ['w.create_time', 'between', Time::today()];
|
||||
}
|
||||
|
||||
$lists = Db::name('withdraw_apply w')
|
||||
->field('w.*, u.nickname,u.avatar, u.sn as user_sn, u.mobile, ul.name as user_level_name')
|
||||
->leftJoin('user u', 'u.id = w.user_id')
|
||||
->leftJoin('user_level ul', 'ul.id = u.level')
|
||||
->where($where)
|
||||
->page($get['page'], $get['limit'])
|
||||
->order('w.id desc')
|
||||
->select();
|
||||
|
||||
$count = Db::name('withdraw_apply w')
|
||||
->field('w.*, u.nickname,u.avatar, u.sn as user_sn, u.mobile, ul.name as user_level_name')
|
||||
->leftJoin('user u', 'u.id = w.user_id')
|
||||
->leftJoin('user_level ul', 'ul.id = u.level')
|
||||
->where($where)
|
||||
->order('w.id desc')
|
||||
->count();
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['type_text'] = Withdraw::getTypeDesc($item['type']);
|
||||
$item['status_text'] = Withdraw::getStatusDesc($item['status']);
|
||||
$item['avatar'] = UrlServer::getFileUrl($item['avatar']);
|
||||
$item['user_level_name'] = $item['user_level_name'] ? $item['user_level_name'] : '无等级';
|
||||
$item['create_time'] = date('Y-m-d h:i:s', $item['create_time']);
|
||||
$item['payment_time'] = date('Y-m-d h:i:s', $item['payment_time']);
|
||||
}
|
||||
|
||||
return ['count' => $count, 'lists' => $lists];
|
||||
}
|
||||
|
||||
|
||||
//审核通过
|
||||
public static function confirm($post)
|
||||
{
|
||||
$id = $post['id'];
|
||||
$withdraw = Db::name('withdraw_apply')
|
||||
->where('id', $id)
|
||||
->find();
|
||||
|
||||
// 判断提现单是否为待提现状态 1
|
||||
if($withdraw['status'] != 1) {
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '不是待提现申请单'
|
||||
];
|
||||
}
|
||||
|
||||
//提现到钱包余额
|
||||
if ($withdraw['type'] == Withdraw::TYPE_BALANCE){
|
||||
$user = User::get($withdraw['user_id']);
|
||||
$user->user_money = ['inc', $withdraw['left_money']];
|
||||
$user->save();
|
||||
AccountLogLogic::AccountRecord(
|
||||
$withdraw['user_id'],
|
||||
$withdraw['left_money'],
|
||||
1,
|
||||
AccountLog::withdraw_to_balance,
|
||||
'',
|
||||
$withdraw['id'],
|
||||
$withdraw['sn']
|
||||
);
|
||||
//更新提现申请单状态为提现成功
|
||||
Db::name('withdraw_apply')
|
||||
->where('id', $id)
|
||||
->update(['status' => Withdraw::STATUS_SUCCESS, 'update_time' => time(), 'description'=>$post['description']]);
|
||||
|
||||
return [
|
||||
'code' => 1,
|
||||
'msg' => '提现至钱包余额成功'
|
||||
];
|
||||
}
|
||||
//提现到微信零钱
|
||||
if($withdraw['type'] == Withdraw::TYPE_WECHAT_CHANGE) {
|
||||
// 先更新审核备注
|
||||
Db::name('withdraw_apply')
|
||||
->where('id', $id)
|
||||
->update(['update_time' => time(),'description'=>$post['description']]);
|
||||
//微信零钱接口:1-企业付款到零钱;2-商家转账到零钱
|
||||
$transfer_way = ConfigServer::get('withdraw', 'transfer_way',1);
|
||||
if ($transfer_way == 1) {
|
||||
return WechatCorporatePaymentLogic::pay($withdraw);
|
||||
}
|
||||
if ($transfer_way == 2) {
|
||||
return WechatMerchantTransferLogic::transfer($withdraw);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//提现到微信收款码、支付收款码
|
||||
if($withdraw['type'] == Withdraw::TYPE_WECHAT_CODE || $withdraw['type'] == Withdraw::TYPE_ALI_CODE || Withdraw::TYPE_BANK) {
|
||||
// 直接标识为提现中状态
|
||||
Db::name('withdraw_apply')
|
||||
->where('id', $id)
|
||||
->update(['status' => Withdraw::STATUS_ING, 'update_time' => time(),'description'=>$post['description']]);
|
||||
return [
|
||||
'code' => 1,
|
||||
'msg' => '审核通过,提现中'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
//审核拒绝
|
||||
public static function refuse($post)
|
||||
{
|
||||
Db::startTrans();
|
||||
try{
|
||||
$withdraw_apply = WithdrawApply::where('id', $post['id'])->find();
|
||||
$withdraw_apply->status = Withdraw::STATUS_FAIL; // 提现失败
|
||||
$withdraw_apply->description = $post['description'];
|
||||
$withdraw_apply->update_time = time();
|
||||
$withdraw_apply->save();
|
||||
|
||||
//拒绝提现,回退佣金
|
||||
$user = User::get($withdraw_apply['user_id']);
|
||||
$user->earnings = ['inc', $withdraw_apply['money']];
|
||||
$user->save();
|
||||
|
||||
//增加佣金变动记录
|
||||
AccountLogLogic::AccountRecord(
|
||||
$withdraw_apply['user_id'],
|
||||
$withdraw_apply['money'],
|
||||
1,
|
||||
AccountLog::withdraw_back_earnings,
|
||||
'',
|
||||
$withdraw_apply['id'],
|
||||
$withdraw_apply['sn']
|
||||
);
|
||||
Db::commit();
|
||||
} catch (Exception $e){
|
||||
Db::rollback();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现失败
|
||||
*/
|
||||
public static function withdrawFailed($id)
|
||||
{
|
||||
$withdraw_apply = WithdrawApply::where('id', $id)->find();
|
||||
$withdraw_apply->status = Withdraw::STATUS_FAIL; // 提现失败
|
||||
$withdraw_apply->update_time = time();
|
||||
$withdraw_apply->save();
|
||||
|
||||
//拒绝提现,回退佣金
|
||||
$user = User::get($withdraw_apply['user_id']);
|
||||
$user->earnings = ['inc', $withdraw_apply['money']];
|
||||
$user->save();
|
||||
|
||||
//增加佣金变动记录
|
||||
AccountLogLogic::AccountRecord(
|
||||
$withdraw_apply['user_id'],
|
||||
$withdraw_apply['money'],
|
||||
1,
|
||||
AccountLog::withdraw_back_earnings,
|
||||
'',
|
||||
$withdraw_apply['id'],
|
||||
$withdraw_apply['sn']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现详情
|
||||
*/
|
||||
public static function detail($id)
|
||||
{
|
||||
$detail = Db::name('withdraw_apply w')
|
||||
->field('w.*,u.sn as user_sn, u.nickname, u.mobile')
|
||||
->leftJoin('user u', 'u.id=w.user_id')
|
||||
->where('w.id', $id)
|
||||
->find();
|
||||
$detail['typeDesc'] = Withdraw::getTypeDesc($detail['type']);
|
||||
$detail['statusDesc'] = Withdraw::getStatusDesc($detail['status']);
|
||||
$detail['create_time'] = Date('Y-m-d H:i:s', $detail['create_time']);
|
||||
$detail['payment_time'] = Date('Y-m-d H:i:s', $detail['payment_time']);
|
||||
$detail['transfer_time'] = $detail['transfer_time'] ? Date('Y-m-d H:i:s', $detail['transfer_time']) : '';
|
||||
return $detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现结果查询
|
||||
*/
|
||||
public static function search($id)
|
||||
{
|
||||
$withdraw = Db::name('withdraw_apply')
|
||||
->where('id', $id)
|
||||
->find();
|
||||
|
||||
// 判断提现单是否为提现中状态 2 且 提现方式为 微信零钱 2
|
||||
if($withdraw['status'] == 2 && $withdraw['type'] == 2) {
|
||||
//微信零钱接口:1-企业付款到零钱;2-商家转账到零钱
|
||||
$transfer_way = ConfigServer::get('withdraw', 'transfer_way',1);
|
||||
if ($transfer_way == 1) {
|
||||
return WechatCorporatePaymentLogic::search($withdraw);
|
||||
}
|
||||
if ($transfer_way == 2) {
|
||||
$result = WechatMerchantTransferLogic::details($withdraw);
|
||||
// 记录查询结果
|
||||
WithdrawApply::update(['update_time'=>time(),'pay_search_desc'=>json_encode($result, JSON_UNESCAPED_UNICODE)],['id'=>$withdraw['id']]);
|
||||
if(isset($result['detail_status'])) {
|
||||
if ($result['detail_status'] == 'SUCCESS') {
|
||||
// 转账成功,标记提现申请单为提现成功,记录支付信息
|
||||
WithdrawApply::update(['status'=>3,'payment_no'=>$result['detail_id'],'payment_time'=>strtotime($result['update_time'])],['id'=>$withdraw['id']]);
|
||||
return ['code' => 1, 'msg' => '提现成功'];
|
||||
}
|
||||
if ($result['detail_status'] == 'FAIL') {
|
||||
// 转账失败
|
||||
WithdrawApply::update(['status'=>4],['id'=>$withdraw['id']]);
|
||||
//回退佣金
|
||||
$user = User::find($withdraw['user_id']);
|
||||
$user->earnings = ['inc', $withdraw['money']];
|
||||
$user->save();
|
||||
|
||||
//增加佣金变动记录
|
||||
AccountLogLogic::AccountRecord(
|
||||
$withdraw['user_id'],
|
||||
$withdraw['money'],
|
||||
1,
|
||||
AccountLog::withdraw_back_earnings,
|
||||
'',
|
||||
$withdraw['id'],
|
||||
$withdraw['sn']
|
||||
);
|
||||
return ['code' => 1, 'msg' => '提现至微信零钱失败'];
|
||||
}
|
||||
if ($result['detail_status'] == 'PROCESSING') {
|
||||
return ['code' => 0, 'msg' => '正在处理中'];
|
||||
}
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => $result['message'] ?? '商家转账到零钱查询失败'];
|
||||
}
|
||||
}
|
||||
}else{
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '不是提现中的微信零钱申请单,无法查询'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转账失败
|
||||
*/
|
||||
public static function transferFail($post)
|
||||
{
|
||||
if(empty($post['transfer_description'])) {
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '请填写转账说明'
|
||||
];
|
||||
}
|
||||
// 标识提现失败
|
||||
Db::name('withdraw_apply')->where('id', $post['id'])->update([
|
||||
'status' => 4, // 提现失败
|
||||
'transfer_description' => $post['transfer_description'],
|
||||
'update_time' => time()
|
||||
]);
|
||||
|
||||
$withdraw_apply = Db::name('withdraw_apply')->where('id', $post['id'])->find();
|
||||
// 退回佣金
|
||||
$user = User::get($withdraw_apply['user_id']);
|
||||
$user->earnings = ['inc', $withdraw_apply['money']];
|
||||
$user->save();
|
||||
|
||||
//增加佣金变动记录
|
||||
AccountLogLogic::AccountRecord(
|
||||
$withdraw_apply['user_id'],
|
||||
$withdraw_apply['money'],
|
||||
1,
|
||||
AccountLog::withdraw_back_earnings,
|
||||
'',
|
||||
$withdraw_apply['id'],
|
||||
$withdraw_apply['sn']
|
||||
);
|
||||
return [
|
||||
'code' => 1,
|
||||
'msg' => '转账失败,提现金额已退回佣金账户'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 转账成功
|
||||
*/
|
||||
public static function transferSuccess($post)
|
||||
{
|
||||
if(empty($post['transfer_voucher'])) {
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '请上传转账凭证'
|
||||
];
|
||||
}
|
||||
|
||||
$post['transfer_voucher'] = UrlServer::getFileUrl($post['transfer_voucher']);
|
||||
|
||||
if(empty($post['transfer_description'])) {
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '请填写转账说明'
|
||||
];
|
||||
}
|
||||
// 标识提现成功
|
||||
Db::name('withdraw_apply')->where('id', $post['id'])->update([
|
||||
'status' => 3, // 提现成功
|
||||
'transfer_voucher' => $post['transfer_voucher'],
|
||||
'transfer_description' => $post['transfer_description'],
|
||||
'update_time' => time(),
|
||||
'transfer_time' => time()
|
||||
]);
|
||||
|
||||
return [
|
||||
'code' => 1,
|
||||
'msg' => '转账成功'
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user