其余文件

This commit is contained in:
2026-04-14 17:46:22 +08:00
parent 294b68fe37
commit 3691f4db22
1343 changed files with 189847 additions and 0 deletions

View File

@ -0,0 +1,473 @@
<?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\shopapi\logic;
use app\common\basics\Logic;
use app\common\enum\GoodsEnum;
use app\common\enum\ShopEnum;
use app\common\model\goods\Goods;
use app\common\model\goods\GoodsItem;
use app\common\model\goods\GoodsSpec;
use app\common\server\ConfigServer;
use app\common\server\UrlServer;
use think\facade\Db;
class GoodsLogic extends Logic
{
/**
* @notes 商品列表
* @param $params
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author Tab
* @date 2021/11/10 11:16
*/
public function lists($params)
{
// 组装条件
$field = $this->assemblyField();
$where = $this->assemblyWhere($params);
$order = $this->assemblyOrder();
$lists = Goods::field($field)
->where($where)
->page($params['page_no'], $params['page_size'])
->order($order)
->select()
->toArray();
$count = Goods::where($where)->count();
$lists = $this->formatLists($lists);
$more = is_more($count, $params['page_no'], $params['page_size']);
$btns = $this->btns($params);
$data = [
'lists' => $lists,
'page_no' => $params['page_no'],
'page_size' => $params['page_size'],
'count' => $count,
'more' => $more,
'btns' => $btns,
];
return $data;
}
/**
* @notes 字段
* @return string[]
* @author Tab
* @date 2021/11/10 11:04
*/
public function assemblyField()
{
return [
"id",
"name",
"image",
"min_price",
"max_price",
"stock",
"sales_actual",
];
}
/**
* @notes 搜索条件
* @param $params
* @return array[]
* @author Tab
* @date 2021/11/10 10:47
*/
public function assemblyWhere($params)
{
// 商家
$where = [
['shop_id', '=', $params['shop_id']]
];
// 商品名称
if(isset($params['name']) && trim($params['name'])) {
$where[] = ['name','like','%'.trim($params['name']).'%'];
}
// 商品类型 - 默认销售中
$type = !empty($params['type']) ? (int)$params['type'] : GoodsEnum::SALES;
switch ($type) {
case GoodsEnum::SALES:
$where[] = ['status', '=', GoodsEnum::STATUS_SHELVES];//上架
$where[] = ['del', '=', GoodsEnum::DEL_NORMAL];
$where[] = ['audit_status', '=', GoodsEnum::AUDIT_STATUS_OK];//审核通过
$where[] = ['stock','exp', Db::raw('>stock_warn')];
break;
case GoodsEnum::WAREHOUSE:
$where[] = ['status', '=', GoodsEnum::STATUS_SOLD_OUT];//下架
$where[] = ['del', '=', GoodsEnum::DEL_NORMAL];
$where[] = ['audit_status', '=', GoodsEnum::AUDIT_STATUS_OK];//审核通过
break;
case GoodsEnum::WARNING:
$where[] = ['status', '=', GoodsEnum::STATUS_SHELVES];//上架
$where[] = ['del', '=', GoodsEnum::DEL_NORMAL];
$where[] = ['audit_status', '=', GoodsEnum::AUDIT_STATUS_OK];//审核通过
$where[] = ['stock','exp', Db::raw('<=stock_warn')];
break;
case GoodsEnum::RECYCLE_BIN:
$where[] = ['del', '=', GoodsEnum::DEL_RECYCLE];
$where[] = ['audit_status', '=', GoodsEnum::AUDIT_STATUS_OK];//审核通过
break;
case GoodsEnum::WAIT_AUDIT:
$where[] = ['del', '<>', GoodsEnum::DEL_TRUE];
$where[] = ['audit_status', '=', GoodsEnum::AUDIT_STATUS_STAY];
break;
case GoodsEnum::UNPASS_AUDIT:
$where[] = ['del', '<>', GoodsEnum::DEL_TRUE];
$where[] = ['audit_status', '=', GoodsEnum::AUDIT_STATUS_REFUSE];
break;
default:
$where[] = ['del', '=', GoodsEnum::DEL_NORMAL];
}
return $where;
}
/**
* @notes 排序
* @return string[]
* @author Tab
* @date 2021/11/10 10:47
*/
public function assemblyOrder()
{
return [
'sort' => 'asc',
'id' => 'desc'
];
}
/**
* @notes 格式化
* @param $lists
* @return mixed
* @author Tab
* @date 2021/11/10 11:06
*/
public function formatLists($lists)
{
if (empty($lists)) {
return $lists;
}
foreach ($lists as &$item) {
$minPrice = floor($item["min_price"] * 100);
$maxPrice = floor($item["max_price"] * 100);
$item['price'] = $minPrice == $maxPrice ? "¥" . clearZero($item["min_price"]) : "¥" . clearZero($item["min_price"]) . " ~ " . clearZero($item["max_price"]);
}
return $lists;
}
/**
* @notes 操作
* @param $shopId
* @param $params
* @return bool
* @author Tab
* @date 2021/11/10 14:08
*/
public function operation($shopId, $params)
{
try {
if (empty($params['action'])) {
throw new \Exception("请选择操作");
}
$goods = Goods::where([
'shop_id' => $shopId,
'id' => $params['id']
])->findOrEmpty();
if ($goods->isEmpty()) {
throw new \Exception("商品不存在");
}
switch ($params['action']) {
case "delete":
$this->delete($goods);
break;
case "recycle":
$this->recycle($goods);
break;
case "on_shelf":
$this->onShelf($goods);
break;
case "off_shelf":
$this->offShelf($goods);
break;
case "warehouse":
$this->warehouse($goods);
break;
default:
throw new \Exception("无效的操作");
}
return true;
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 删除商品
* @param $goods
* @author Tab
* @date 2021/11/10 11:58
*/
public function delete($goods)
{
$goods->del = GoodsEnum::DEL_TRUE;
$goods->save();
}
/**
* @notes 放入回收站
* @param $goods
* @author Tab
* @date 2021/11/10 11:58
*/
public function recycle($goods)
{
$goods->del = GoodsEnum::DEL_RECYCLE;
$goods->save();
}
/**
* @notes 上架
* @param $goods
* @throws \Exception
* @author Tab
* @date 2021/11/10 12:01
*/
public function onShelf($goods)
{
if ($goods->stock <= 0) {
throw new \Exception("库存不足不允许上架");
}
$goods->status = GoodsEnum::STATUS_SHELVES;
$goods->save();
}
/**
* @notes 下架
* @param $goods
* @author Tab
* @date 2021/11/10 14:04
*/
public function offShelf($goods)
{
$goods->status = GoodsEnum::STATUS_SOLD_OUT;
$goods->save();
}
/**
* @notes 放入仓库
* @param $goods
* @author Tab
* @date 2021/11/10 14:07
*/
public function warehouse($goods)
{
$goods->status = GoodsEnum::STATUS_SOLD_OUT;
$goods->del = GoodsEnum::DEL_NORMAL;
$goods->save();
}
/**
* @notes 商品详情
* @param $id
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author Tab
* @date 2021/11/10 15:14
*/
public function detail($id)
{
$goodsDetail = Goods::with(['goods_image', 'goods_item', 'shop'])
->field('id,type,code,name,spec_type,image,video,remark,content,market_price,min_price,max_price,stock,sales_actual,shop_id')
->where('id', $id)
->findOrEmpty();
if ($goodsDetail->isEmpty()) {
return [];
}
$goodsDetail = $goodsDetail->toArray();
// 轮播图添加域名
foreach($goodsDetail['goods_image'] as &$item) {
$item['uri'] = empty($item['uri']) ? '' : UrlServer::getFileUrl($item['uri']);
}
// 规格项及规格值信息
$goodsDetail['goods_spec'] = GoodsSpec::with('spec_value')
->where('goods_id', $goodsDetail['id'])->select()->toArray();
return $goodsDetail;
}
/**
* @notes 商品编辑
* @param $shopId
* @param $params
* @author Tab
* @date 2021/11/10 15:24
*/
public function edit($params)
{
try {
$updateData = $this->checkParams($params);
(new GoodsItem())->saveAll($updateData['itemData']);
Goods::update($updateData['goodsData']);
return true;
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 参数校验
* @param $params
* @throws \Exception
* @author Tab
* @date 2021/11/10 15:48
*/
public function checkParams($params)
{
$goodsStock = 0;
$itemId = 0;
$updateData = [];
$max_price = 0;
$min_price = 0;
$market_price = 0;
if (!isset($params['items']) || !is_array($params['items'])) {
throw new \Exception("参数缺失或格式有误");
}
foreach($params['items'] as $item) {
if (!is_array($item)) {
throw new \Exception("参数格式错误");
}
if (!isset($item['id']) || !isset($item['price']) || !isset($item['stock']) || !isset($item['market_price']) || !isset($item['chengben_price'])) {
throw new \Exception("参数缺失");
}
if ($item['price'] <= 0 || $item['market_price'] <= 0 || $item['chengben_price'] <= 0 || $item['stock'] <= 0) {
throw new \Exception("价格及库存均不能为负数和零");
}
if ($item['market_price'] < $item['price']) {
throw new \Exception("市场价不能低于售价");
}
// 重新赋值作用:避免$item字段过多时修改了不该修改的字段
$temp['id'] = $item['id'];
$temp['price'] = $item['price'];
$temp['market_price'] = $item['market_price'];
$temp['chengben_price'] = $item['chengben_price'];
$temp['stock'] = $item['stock'];
// 规格数据
$updateData[] = $temp;
// 主表库存
$goodsStock += $item['stock'];
$itemId = $item['id'];
// 最高价
if ($item['price'] > $max_price) {
$max_price = $item['price'];
}
if ($min_price == 0) {
$min_price = $item['price'];
$market_price = $item['market_price'];
}
//最低价
if ($item['price'] < $min_price) {
$min_price = $item['price'];
$market_price = $item['market_price'];
}
}
// 商品id
$goodsId = (new GoodsItem())->where(['id' => $itemId])->value('goods_id');
// 商品更新库存
$goodsData = [
'id' => $goodsId,
'stock' => $goodsStock,
'max_price' => $max_price,
'min_price' => $min_price,
'market_price' => $market_price,
];
return ['itemData' => $updateData, 'goodsData' => $goodsData];
}
/**
* @notes 按钮显示与隐藏
* @param $params
* @return array
* @author Tab
* @date 2021/11/12 17:59
*/
public function btns($params)
{
$recycleBtn = $editBtn = $offShelfBtn = $onShelfBtn = $deleteBtn = $warehouseBtn = false;
// 商品类型 - 默认销售中
$type = !empty($params['type']) ? (int)$params['type'] : GoodsEnum::SALES;
switch ($type) {
case GoodsEnum::SALES:
case GoodsEnum::WARNING:
$recycleBtn = $editBtn = $offShelfBtn = true;
break;
case GoodsEnum::WAREHOUSE:
$recycleBtn = $editBtn = $onShelfBtn = true;
break;
case GoodsEnum::RECYCLE_BIN:
$deleteBtn = $warehouseBtn = true;
break;
case GoodsEnum::WAIT_AUDIT:
case GoodsEnum::UNPASS_AUDIT:
$deleteBtn = $editBtn = true;
break;
}
return [
"recycle_btn" => $recycleBtn,
"edit_btn" => $editBtn,
"off_shelf_btn" => $offShelfBtn,
"on_shelf_btn" => $onShelfBtn,
"delete_btn" => $deleteBtn,
"warehouse_btn" => $warehouseBtn,
];
}
}

View File

@ -0,0 +1,70 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\shopapi\logic;
use app\common\basics\Logic;
use app\common\model\shop\Shop;
use app\common\server\ConfigServer;
use app\common\server\UrlServer;
/**
* 商家移动端管理员默认配置
* Class LoginLogic
* @package app\shopapi\logic
*/
class IndexLogic extends Logic
{
/**
* @notes 配置信息
* @return array
* @author 段誉
* @date 2021/11/13 17:13
*/
public static function config()
{
$config = [
'platform_name' => ConfigServer::get('website', 'name'),
];
return $config;
}
/**
* @notes 版权资质
* @param $shop_id
* @return mixed
* @author ljj
* @date 2022/2/22 11:10 上午
*/
public static function copyright($shop_id)
{
$result = Shop::where('id',$shop_id)->json(['other_qualifications'],true)->field('business_license,other_qualifications')->findOrEmpty()->toArray();
$business_license = $result['business_license'] ? UrlServer::getFileUrl($result['business_license']) : '';
foreach ($result['other_qualifications'] as &$val) {
$other_qualifications[] = UrlServer::getFileUrl($val);
}
if (!empty($business_license)) {
array_unshift($other_qualifications,$business_license);
}
return $other_qualifications;
}
}

View File

@ -0,0 +1,158 @@
<?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\shopapi\logic;
use app\common\basics\Logic;
use app\common\model\shop\ShopAdmin;
use app\common\model\ShopSession;
use app\common\model\ShopSession as SessionModel;
use app\common\server\UrlServer;
use think\facade\Config;
use think\facade\Cache;
/**
* 商家移动端管理员登录逻辑
* Class LoginLogic
* @package app\shopapi\logic
*/
class LoginLogic extends Logic
{
/**
* @notes 账号密码登录
* @param $params
* @return mixed
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2021/11/9 16:37
*/
public static function accountLogin($params)
{
$adminModel = new ShopAdmin();
$admin = $adminModel->alias('a')
->join('shop s', 's.id = a.shop_id')
->field(['a.id', 'a.account', 'a.name', 'role_id', 'shop_id', 's.name' => 'shop_name', 's.logo' => 'shop_logo'])
->where(['a.account' => $params['account'], 'a.del' => 0])
->findOrEmpty()->toArray();
$admin['shop_logo'] = UrlServer::getFileUrl($admin['shop_logo']);
$admin['token'] = self::createSession($admin['id'], $params['client']);
//登录信息更新
$adminModel->where(['account' => $params['account']])->update([
'login_ip' => request()->ip(),
'login_time' => time()
]);
return $admin;
}
/**
* @notes 退出登录
* @param $user_id
* @param $client
* @return SessionModel
* @author 段誉
* @date 2021/11/9 16:37
*/
public static function logout($user_id, $client)
{
$time = time();
$token = (new ShopSession())
->where(['admin_id' => $user_id, 'client' => $client])
->value('token');
Cache::delete($token);
return (new ShopSession())
->where(['admin_id' => $user_id, 'client' => $client])
->update(['update_time' => $time, 'expire_time' => $time]);
}
/**
* @notes 创建会话
* @param $admin_id
* @param $client
* @return string
* @author 段誉
* @date 2021/11/9 16:38
*/
public static function createSession($admin_id, $client)
{
//清除之前缓存
$token = SessionModel::where(['admin_id' => $admin_id, 'client' => $client])
->value('token');
if ($token) {
Cache::delete($token);
}
$result = SessionModel::where(['admin_id' => $admin_id, 'client' => $client])
->findOrEmpty();
$time = time();
$expire_time = $time + Config::get('project.token_expire_time');
// 新token
$token = md5($admin_id . $client . $time);
$shop_amdin = ShopAdmin::where(['id' => $admin_id])->findOrEmpty();
$data = [
'shop_id' => $shop_amdin['shop_id'],
'admin_id' => $admin_id,
'token' => $token,
'client' => $client,
'update_time' => $time,
'expire_time' => $expire_time,
];
if ($result->isEmpty()) {
SessionModel::create($data);
} else {
SessionModel::where(['admin_id' => $admin_id, 'client' => $client])
->update($data);
}
//更新登录信息
$login_ip = request()->ip();
ShopAdmin::where(['id' => $admin_id])
->update(['login_time' => $time, 'login_ip' => $login_ip]);
// 获取最新的用户信息
$admin_info = ShopAdmin::alias('a')
->join('shop_session s', 'a.id=s.admin_id')
->where(['s.token' => $token])
->field('a.*,s.token,s.client')
->find();
$admin_info = $admin_info ? $admin_info->toArray() : [];
//创建新的缓存
$ttl = 0 + Config::get('project.token_expire_time');
Cache::set($token, $admin_info, $ttl);
return $token;
}
}

View File

@ -0,0 +1,511 @@
<?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\shopapi\logic;
use app\common\basics\Logic;
use app\common\enum\NoticeEnum;
use app\common\enum\OrderEnum;
use app\common\enum\OrderLogEnum;
use app\common\enum\PayEnum;
use app\common\enum\TeamEnum;
use app\common\logic\GoodsVirtualLogic;
use app\common\logic\OrderLogLogic;
use app\common\logic\OrderRefundLogic;
use app\common\logic\PayNotifyLogic;
use app\common\model\Delivery;
use app\common\model\DevRegion;
use app\common\model\distribution\DistributionOrderGoods;
use app\common\model\Express;
use app\common\model\order\Order;
use app\common\model\team\TeamFound;
use app\common\model\team\TeamJoin;
use think\facade\Db;
/**
* 商家移动端订单管理逻辑层
* Class OrderLogic
* @package app\shopapi\logic
*/
class OrderLogic extends Logic
{
/**
* @notes 订单列表
* @param $get
* @param $page_no
* @param $page_size
* @param $shop_id
* @return array
* @author ljj
* @date 2021/11/10 3:13 下午
*/
public static function lists($get, $page_no, $page_size, $shop_id)
{
$get['type'] = $get['type'] ?? 'all';
$where[] = ['o.shop_id', '=', $shop_id];
$where[] = ['o.del', '=', 0];
$where[] = ['o.delete', '=', 0];
//订单状态
if (isset($get['type']) && !empty($get['type'])) {
switch ($get['type']) {
case 'pay':
$where[] = ['o.order_status', '=', 0];
break;
case 'delivery':
$where[] = ['o.order_status', '=', 1];
break;
case 'receiving':
$where[] = ['o.order_status', '=', 2];
break;
case 'finish':
$where[] = ['o.order_status', '=', 3];
break;
case 'close':
$where[] = ['o.order_status', '=', 4];
break;
}
}
//订单商品名称
if (isset($get['goods_name']) && !empty($get['goods_name'])) {
$where[] = ['og.goods_name', 'like', '%'.$get['goods_name'].'%'];
}
$count = Order::alias('o')
->join('order_goods og', 'og.order_id = o.id')
->where($where)
->group('o.id')
->count();
$lists = Order::alias('o')
->join('order_goods og', 'og.order_id = o.id')
->where($where)
->with(['order_goods'])
->field('o.id,o.order_type,o.order_sn,o.order_status,o.pay_status,o.shipping_status,o.order_amount,o.create_time,o.delivery_type, o.verification_status,o.pay_way')
->append(['is_team_success','shop_cancel_btn','edit_address_btn','to_ship_btn','take_btn','delivery_btn','del_btn','content_btn', 'to_verification_btn'])
->page($page_no, $page_size)
->order('o.id desc')
->group('o.id')
->select()
->toArray();
foreach ($lists as &$item) {
// 订单状态描述
if ($item['order_status'] == OrderEnum::ORDER_STATUS_DELIVERY
&& $item['delivery_type'] == OrderEnum::DELIVERY_TYPE_SELF
&& $item['pay_status'] == PayEnum::ISPAID) {
$item['order_status_text'] = '待取货';
} else {
$item['order_status_text'] = OrderEnum::getOrderStatus($item['order_status']);
}
}
return [
'list' => $lists,
'page' => $page_no,
'size' => $page_size,
'count' => $count,
'more' => is_more($count, $page_no, $page_size)
];
}
/**
* @notes 订单详情
* @param $id
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author ljj
* @date 2021/11/10 4:15 下午
*/
public static function detail($id)
{
$result = Order::where('id',$id)
->field('id,user_id,order_sn,order_type,order_source,order_status,pay_status,pay_time,shipping_status,pay_way,order_amount,goods_price,shipping_price,discount_amount,member_amount,create_time,consignee,mobile,province,city,district,address,user_remark,delivery_type,delivery_content,pay_way')
->with(['order_goods','user', 'invoice'])
->append(['is_team_success','shop_cancel_btn','edit_address_btn','to_ship_btn','take_btn','delivery_btn','del_btn','order_status_text','pay_way_text','delivery_address','order_type_text','order_source_text','pay_status_text'])
->find()
->toArray();
$result['pay_time'] = $result['pay_time'] ? date('Y-m-d H:i:s', $result['pay_time']) : '-';
// 虚拟商品 发货内容
if ($result['delivery_type'] != OrderEnum::DELIVERY_TYPE_VIRTUAL || $result['shipping_status'] != OrderEnum::SHIPPING_FINISH) {
$result['delivery_content'] = '';
}
return $result;
}
/**
* @notes 取消订单
* @param $id
* @param $admin_id
* @return bool|string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author ljj
* @date 2021/11/10 5:06 下午
*/
public static function cancel($id,$admin_id)
{
$order = Order::where(['id' => $id], ['orderGoods'])->find()->toArray();
Db::startTrans();
try {
// 如果是拼团订单
if ($order['order_type'] == OrderEnum::TEAM_ORDER) {
$time = time();
$team_id = (new TeamJoin())->where(['order_id' => $order['id']])->value('team_id');
$teamJoin = (new TeamJoin())->alias('TJ')
->field(['TJ.*,O.order_sn,O.order_status,O.pay_status,O.refund_status,O.order_amount'])
->where(['team_id' => $team_id])
->join('order O', 'O.id=TJ.order_id')
->select()->toArray();
TeamFound::update(['status' => TeamEnum::TEAM_STATUS_FAIL, 'team_end_time' => $time], ['id' => $team_id]);
foreach ($teamJoin as $item) {
TeamJoin::update(['status' => TeamEnum::TEAM_STATUS_FAIL, 'update_time' => $time], ['id' => $item['id']]);
OrderRefundLogic::cancelOrder($item['order_id'], OrderLogEnum::TYPE_USER); //取消订单
if ($item['pay_status'] == PayEnum::ISPAID) {
$order = (new Order())->findOrEmpty($item['order_id'])->toArray();
OrderRefundLogic::cancelOrderRefundUpdate($order); //更新订单状态
OrderRefundLogic::refund($order, $order['order_amount'], $order['order_amount']); //订单退款
}
}
} else {
//取消订单
OrderRefundLogic::cancelOrder($id, OrderLogEnum::TYPE_SHOP, $admin_id);
//已支付的订单,取消,退款
if ($order['pay_status'] == PayEnum::ISPAID) {
//更新订单状态
OrderRefundLogic::cancelOrderRefundUpdate($order);
//订单退款
OrderRefundLogic::refund($order, $order['order_amount'], $order['order_amount']);
}
}
// 查找对应的分销订单置为失效状态
if ($order['pay_status'] == PayEnum::ISPAID) {
DistributionOrderGoods::where('order_id', $id)->update(['status' => 3]);
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
//增加退款失败记录
if ($order['pay_status'] == PayEnum::ISPAID) {
OrderRefundLogic::addErrorRefund($order, $e->getMessage());
}
return $e->getMessage();
}
}
/**
* @notes 删除订单
* @param $id
* @param $admin_id
* @author ljj
* @date 2021/11/10 5:37 下午
*/
public static function del($id,$admin_id)
{
Order::update(['delete'=>1,'update_time'=>time()], ['id'=>$id]);
//订单日志
OrderLogLogic::record(
OrderLogEnum::TYPE_SHOP,
OrderLogEnum::SHOP_DEL_ORDER,
$id,
$admin_id,
OrderLogEnum::SHOP_DEL_ORDER
);
}
/**
* @notes 修改地址
* @param $post
* @return bool
* @author ljj
* @date 2021/11/10 6:35 下午
*/
public static function editAddress($post)
{
Order::update(
[
'consignee'=>$post['consignee'],
'province'=>$post['province'],
'city'=>$post['city'],
'district'=>$post['district'],
'address'=>$post['address'],
'mobile'=>$post['mobile'],
'update_time' => time(),
], ['id'=>$post['id']]);
return true;
}
/**
* @notes 获取地址详情
* @param $id
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author ljj
* @date 2021/11/13 11:41 上午
*/
public static function getAddress($id)
{
$result = Order::where('id',$id)
->field('consignee,province,city,district,address,mobile')
->find()
->toArray();
$result['region'] = DevRegion::where('id', 'in', $result['province'].','.$result['city'].','.$result['district'])->order('id','asc')->column('name');
return $result;
}
/**
* @notes 发货
* @param $post
* @param $admin_id
* @return bool|string
* @author ljj
* @date 2021/11/11 10:27 上午
*/
public static function delivery($post, $admin_id)
{
Db::startTrans();
try {
$order = Order::where(['id' => $post['id']], ['order_goods'])->find();
if ($order['shipping_status'] == 1) {
return true;
}
//添加发货单
$delivery_data = [
'order_id' => $post['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' => $post['invoice_no'] ?? '',
'send_type' => $post['send_type'],
'create_time' => time(),
];
//配送方式->快递配送
if ($post['send_type'] == 1) {
$shipping = Express::where('id', $post['shipping_id'])->find();
$delivery_data['shipping_id'] = $post['shipping_id'];
$delivery_data['shipping_name'] = $shipping['name'];
$delivery_data['shipping_status'] = 1;
}
$delivery = Delivery::create($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(
OrderLogEnum::TYPE_SHOP,
OrderLogEnum::SHOP_DELIVERY_ORDER,
$post['id'],
$admin_id,
OrderLogEnum::SHOP_DELIVERY_ORDER
);
//通知用户发货
if (!empty($order['mobile'])) {
event('Notice', [
'scene' => NoticeEnum::ORDER_DELIVERY_NOTICE,
'mobile' => $order['mobile'],
'params' => [
'order_id' => $order['id'],
'user_id' => $order['user_id'],
'shipping_name' => $delivery_data['shipping_name'] ?? '无需快递',
'invoice_no' => $post['invoice_no'] ?? '-',
]
]);
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
return $e->getMessage();
}
}
/**
* @notes 获取物流公司列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author ljj
* @date 2021/11/13 11:46 上午
*/
public static function getExpress()
{
return Express::where('del',0)->field('id,name')->select()->toArray();
}
/**
* @notes 确认收货
* @param $id
* @param $admin_id
* @author ljj
* @date 2021/11/11 10:55 上午
*/
public static function confirm($id, $admin_id)
{
Order::update(
[
'order_status' => Order::STATUS_FINISH,
'confirm_take_time' => time(),
'update_time' => time(),
], ['id'=>$id]);
//订单日志
OrderLogLogic::record(
OrderLogEnum::TYPE_SHOP,
OrderLogEnum::SHOP_CONFIRM_ORDER,
$id,
$admin_id,
OrderLogEnum::SHOP_CONFIRM_ORDER
);
}
/**
* @notes 查看物流
* @param $id
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author ljj
* @date 2021/11/11 11:34 上午
*/
public static function logistics($id)
{
return Delivery::where('order_id',$id)
->field('shipping_name,invoice_no')
->find()
->toArray();
}
/**
* @notes 虚拟发货
* @param $post
* @param $admin_id
* @return bool
* @author 段誉
* @date 2022/4/20 17:56
*/
public static function virtualDelivery($post, $admin_id)
{
try {
$order_id = $post['order_id'];
$order = Order::with(['order_goods'])->where(['del' => 0, 'id' => $order_id])->find();
// 更新发货订单信息
$result = GoodsVirtualLogic::shopSelfDelivery($order_id, $post['delivery_content']);
if (true !== $result) {
throw new \Exception($result);
}
//订单日志
OrderLogLogic::record(
OrderLogEnum::TYPE_SHOP,
OrderLogEnum::SHOP_DELIVERY_ORDER,
$order_id,
$admin_id,
OrderLogEnum::SHOP_DELIVERY_ORDER
);
//通知用户发货
if (!empty($order['mobile'])) {
event('Notice', [
'scene' => NoticeEnum::ORDER_DELIVERY_NOTICE,
'mobile' => $order['mobile'],
'params' => [
'order_id' => $order['id'],
'user_id' => $order['user_id'],
'shipping_name' => '无需快递',
'invoice_no' => '-',
]
]);
}
return true;
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 确认付款
* @param $order_id
* @param $adminInfo
* @return string|true
* @author ljj
* @date 2024/7/19 下午6:32
*/
public static function confirmPay($order_id, $adminInfo)
{
Db::startTrans();
try {
$order = Order::where(['id' => $order_id])->findOrEmpty()->toArray();
$result = PayNotifyLogic::handle('order', $order['order_sn']);
if (true !== $result) {
throw new \Exception($result);
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
return $e->getMessage();
}
}
}

View File

@ -0,0 +1,303 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\shopapi\logic;
use app\admin\controller\activity_area\Area;
use app\common\enum\NoticeEnum;
use app\common\enum\WithdrawalEnum;
use app\common\model\shop\Shop;
use app\common\model\shop\ShopAccountLog;
use app\common\model\shop\ShopAdmin;
use app\common\model\shop\ShopBank;
use app\common\model\shop\ShopCategory;
use app\common\model\shop\ShopWithdrawal;
use app\common\server\AreaServer;
use app\common\server\ConfigServer;
use think\facade\Db;
/**
* 商家逻辑层
* Class ShopLogic
* @package app\shopapi\logic
*/
class ShopLogic{
/**
* @notes 获取商家可提现余额
* @param $shop_id
* @return mixed
* @author cjhao
* @date 2021/11/10 16:15
*/
public function getShopInfo(int $shop_id){
$shop = Shop::where(['id'=>$shop_id])
->field("id,cid,name,logo,is_run,wallet,score,nickname,mobile,intro,
run_start_time,run_end_time,weekdays,province_id,city_id,district_id,address,refund_address,open_invoice,spec_invoice")
->find()->toArray();
$shop['run_start_time'] = date('H:i',$shop['run_start_time']);
$shop['run_end_time'] = date('H:i',$shop['run_end_time']);
$shop['province_name'] = '';
$shop['city_name'] = '';
$shop['district_name'] = '';
$shop['province_id'] && $shop['province_name'] = AreaServer::getAddress($shop['province_id']);
$shop['city_id'] && $shop['city_name'] = AreaServer::getAddress($shop['city_id']);
$shop['district_id'] && $shop['district_name'] = AreaServer::getAddress($shop['district_id']);
$shop['refund_address']['province_name'] = !empty($shop['refund_address']['province_id']) ? AreaServer::getAddress($shop['refund_address']['province_id']) : '';
$shop['refund_address']['city_name'] = !empty($shop['refund_address']['city_id']) ? AreaServer::getAddress($shop['refund_address']['city_id']) : '';
$shop['refund_address']['district_name'] = !empty($shop['refund_address']['district_id']) ? AreaServer::getAddress($shop['refund_address']['district_id']) : '';
$shop['cate_name'] = ShopCategory::where('id', $shop['cid'])->value('name');
return $shop;
}
/**
* @notes 获取提现信息
* @param int $shop_id
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author cjhao
* @date 2021/11/10 16:30
*/
public function getWithdrawInfo(int $shop_id){
$wallet = Shop::where(['id'=>$shop_id])
->value("wallet");
$min_withdrawal_money = ConfigServer::get('shop_withdrawal', 'min_withdrawal_money', 0);
$max_withdrawal_money = ConfigServer::get('shop_withdrawal', 'max_withdrawal_money', 0);
$withdrawal_service_charge = ConfigServer::get('shop_withdrawal', 'withdrawal_service_charge', 0);
$bank_list = ShopBank::where(['shop_id'=>$shop_id,'del'=>0])
->field('id,name,branch,nickname,account')
->select()->toArray();
return [
'wallet' => $wallet,
'min_withdrawal_money' => $min_withdrawal_money,
'max_withdrawal_money' => $max_withdrawal_money,
'withdrawal_service_charge' => $withdrawal_service_charge,
'bank_list' => $bank_list,
];
}
/**
* @notes 提现金额
* @param array $post
* @return bool|string
* @author cjhao
* @date 2021/11/10 16:56
*/
public function withdraw(array $post){
Db::startTrans();
try {
$shop_id = $post['shop_id'];
// 1、获取提现条件
$withdrawal_service_charge = ConfigServer::get('shop_withdrawal', 'withdrawal_service_charge', 0);
// 2、获取商家信息
$shop = (new Shop())->findOrEmpty($shop_id)->toArray();
// 4、获取商家提现手续费
$poundage_amount = 0;
if ($withdrawal_service_charge > 0) {
$proportion = $withdrawal_service_charge / 100;
$poundage_amount = $post['money'] * $proportion;
$poundage_amount = $poundage_amount <= 0 ? 0 : $poundage_amount;
}
// 5、创建申请记录
$withdrawal = ShopWithdrawal::create([
'sn' => createSn('shop_withdrawal', 'sn'),
'bank_id' => $post['bank_id'],
'shop_id' => $shop_id,
'apply_amount' => floatval($post['money']),
'left_amount' => $post['money'] - $poundage_amount,
'poundage_amount' => $poundage_amount,
'poundage_ratio' => $withdrawal_service_charge,
'status' => WithdrawalEnum::APPLY_STATUS
]);
// 6、扣除商家可提现金额
Shop::update([
'wallet' => ['dec', floatval($post['money'])],
'update_time' => time()
], ['id' => $shop_id]);
$left_amount = Shop::where(['id' => $shop_id])->value('wallet');
// 7、增加提现流水记录(待提现)
$logType = ShopAccountLog::withdrawal_stay_money;
ShopAccountLog::decData($shop_id, $logType, $post['money'], $left_amount, [
'source_id' => $withdrawal['id'],
'source_sn' => $withdrawal['sn'],
'remark' => '商家提现'
]);
$platform_contacts = ConfigServer::get('website_platform', 'platform_mobile');
if (!empty($platform_contacts)) {
event('Notice', [
'scene' => NoticeEnum::SHOP_WITHDRAWAL_NOTICE_PLATFORM,
'mobile' => $platform_contacts,
'params' => [
'shop_withdrawal_sn' => $withdrawal['sn'],
'shop_name' => $shop['name'],
]
]);
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
return $e->getMessage();
}
}
/**
* @notes 提现记录
* @param $shop_id
* @param $page_no
* @param $page_size
* @return array
* @throws \think\db\exception\DbException
* @author cjhao
* @date 2021/11/10 17:10
*/
public function withdrawLog(int $shop_id,int $page_no,int $page_size){
$lists = ShopWithdrawal::alias('SW')
->join('shop_account_log SCL','SW.sn = SCL.source_sn')
->where(['SW.shop_id'=>$shop_id,'source_type'=>[ShopAccountLog::withdrawal_stay_money,ShopAccountLog::withdrawal_dec_money,ShopAccountLog::withdrawal_fail_money]])
->field("SCL.id,SCL.change_amount,SCL.left_amount,status,SCL.create_time")
->paginate([
'page' => $page_no,
'list_rows' => $page_size,
'var_page' => 'page'
])->toArray();
return ['count' => $lists['total'], 'lists' => $lists['data']];
}
/**
* @notes 添加银行账户
* @param $post
* @return bool
* @author cjhao
* @date 2021/11/10 18:30
*/
public function addBank(array $post){
$shop_bank = new ShopBank();
$shop_bank->shop_id = $post['shop_id'];
$shop_bank->name = $post['name'];
$shop_bank->branch = $post['branch'];
$shop_bank->nickname = $post['nickname'];
$shop_bank->account = $post['account'];
$shop_bank->save();
return true;
}
/**
* @notes 获取银行卡
* @param int $id
* @param int $shop_id
* @return array
* @author cjhao
* @date 2021/11/11 15:46
*/
public function getBank(int $id,int $shop_id){
$shop_bank = ShopBank::where(['id'=>$id,'shop_id'=>$shop_id])
->field('id,name,branch,nickname,account')
->findOrEmpty()->toArray();
return $shop_bank;
}
/**
* @notes 编辑银行账户
* @param $post
* @return bool
* @author cjhao
* @date 2021/11/10 18:38
*/
public function editBank(array $post){
ShopBank::update([
'name' => $post['name'],
'branch' => $post['branch'],
'nickname' => $post['nickname'],
'account' => $post['account'],
'del' => 0
], ['id'=>$post['id']]);
return true;
}
/**
* @notes 删除银行卡
* @param $id
* @param $shop_id
* @return bool
* @author cjhao
* @date 2021/11/10 18:42
*/
public function delBank(int $id,int $shop_id){
ShopBank::where(['id'=>$id,'shop_id'=>$shop_id])->delete();
return true;
}
/**
* @notes 更新商家信息
* @param array $post
* @param int $shop_id
* @return Shop
* @author cjhao
* @date 2021/11/11 11:34
*/
public function shopSet(array $post,int $shop_id){
if(isset($post['refund_address'])){
$post['refund_address'] = json_encode($post['refund_address'],JSON_UNESCAPED_UNICODE);
}
return Shop::update($post,['id'=>$shop_id]);
}
/**
* @notes 修改密码
* @param $password
* @param $admin_id
* @param $shop_id
* @return bool
* @author cjhao
* @date 2021/11/11 16:03
*/
public function updatePassword(array $post,int $shop_id)
{
try {
$admin = ShopAdmin::where(['id' => $post['admin_id'], 'shop_id' => $shop_id])->find();
$admin->password = generatePassword($post['password'], $admin['salt']);
$admin->save();
return true;
} catch (\Exception $e) {
return $e->getMessage();
}
}
}

View File

@ -0,0 +1,263 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\shopapi\logic;
use app\common\enum\OrderEnum;
use app\common\enum\PayEnum;
use app\common\enum\VerificationEnum;
use app\common\model\order\Order;
use app\common\model\shop\Shop;
use app\common\server\UrlServer;
use think\facade\Db;
/**
* 数据逻辑层
* Class StatisticsLogic
* @package app\shopapi\logic
*/
class StatisticsLogic{
/**
* @notes 工作台
* @param int $shop_id
* @return array
* @author cjhao
* @date 2021/11/11 15:23
*/
public function workbench(int $shop_id){
//头部数据统计
$where = [];
$where[] = ['pay_status', '>', PayEnum::UNPAID];
$where[] = ['shop_id','=',$shop_id];
//成交笔数
$order_num = Db::name('order')
->where($where)
->whereDay('create_time')
->count('id');
//销售金额
$order_amount = Db::name('order')
->where($where)
->whereDay('create_time')
->sum('order_amount') ?? 0;
//进店人数
$shop_user = Db::name('shop_stat')
->where(['shop_id'=>$shop_id])
->whereDay('create_time')
->group(['ip'])
->count('id');
//当前时间戳
$start_t = time();
//echarts图表数据
$echarts_order_amount = [];
$echarts_user_pv = [];
$dates = [];
for ($i = 7; $i >= 1; $i--) {
$where_start = strtotime("- ".$i."day", $start_t);
$dates[] = date('m-d',$where_start);
$start_now = strtotime(date('Y-m-d',$where_start));
$end_now = strtotime(date('Y-m-d 23:59:59',$where_start));
$amount = Db::name('order')
->where([['shop_id','=',$shop_id],['create_time','between',[$start_now, $end_now]],['pay_status','>',PayEnum::UNPAID]])
->sum('order_amount');
$pv = Db::name('shop_stat')
->where([['shop_id','=',$shop_id],['create_time','between',[$start_now, $end_now]]])
->group('ip')
->count('id');
$echarts_order_amount[] = sprintf("%.2f",substr(sprintf("%.3f", $amount), 0, -2));
$echarts_user_pv[] = $pv;
}
$self_order_num = Order::where([
'delivery_type' => OrderEnum::DELIVERY_TYPE_SELF,
'pay_status' => PayEnum::ISPAID,
'shop_id' => $shop_id
])->count();
$is_verification = Order::where([
'delivery_type' => OrderEnum::DELIVERY_TYPE_SELF,
'pay_status' => PayEnum::ISPAID,
'verification_status' => OrderEnum::NOT_WRITTEN_OFF,
'shop_id' => $shop_id
])->count();
$no_verification = Order::where([
'delivery_type' => OrderEnum::DELIVERY_TYPE_SELF,
'pay_status' => PayEnum::ISPAID,
'verification_status' => OrderEnum::WRITTEN_OFF,
'shop_id' => $shop_id
])->count();
return [
'now' => date('Y-m-d H:i:s', time()),
'shop_name' => Shop::where(['id'=>$shop_id])->value('name'),
'order_num' => $order_num,
'order_amount' => $order_amount,
'shop_user' => $shop_user,
'self_order' => $self_order_num,
'is_verification' => $is_verification,
'no_verification' => $no_verification,
'echarts_order_amount' => $echarts_order_amount,
'echarts_user_visit' => $echarts_user_pv,
'dates' => $dates,
];
}
/**
* @notes 交易接口
* @param int $shop_id
* @return array
* @author cjhao
* @date 2021/11/11 14:39
*/
public function trading(int $shop_id){
//获取今天的时间戳
$today = strtotime('today');
//近七天的开始日期
$start_time = $today - 86400 * 7;
//近七天的结束日期
$end_time = $today - 1;
$order_num = Db::name('order')
->where([['pay_status', '>', PayEnum::UNPAID],['shop_id', '=', $shop_id]])
->whereDay('create_time')
->count('id');
$order_amount = Db::name('order')
->where([['pay_status', '>', PayEnum::UNPAID],['shop_id', '=', $shop_id]])
->whereDay('create_time')
->sum('order_amount') ?? 0;
//当前时间戳
$start_t = time();
//echarts图表数据
$echarts_order_num_add = [];
$echarts_order_amount_add = [];
$dates = [];
for ($i = 7; $i >= 1; $i--) {
$where_start = strtotime("- " . $i . "day", $start_t);
$dates[] = date('m-d', $where_start);
$start_now = strtotime(date('Y-m-d', $where_start));
$end_now = strtotime(date('Y-m-d 23:59:59', $where_start));
$order_num_add = Db::name('order')
->where([['create_time', 'between', [$start_now, $end_now]], ['pay_status', '>', PayEnum::UNPAID],['shop_id', '=', $shop_id]])
->count('id');
$order_amount_add = Db::name('order')
->where([['create_time', 'between', [$start_now, $end_now]], ['pay_status', '>', PayEnum::UNPAID],['shop_id', '=', $shop_id]])
->sum('order_amount') ?? 0;
$echarts_order_num_add[] = $order_num_add;
$echarts_order_amount_add[] = sprintf("%.2f",substr(sprintf("%.3f", $order_amount_add), 0, -2));
}
return [
'order_num' => $order_num,
'order_amount' => '¥'.number_format($order_amount,2),
'echarts_order_num_add' => $echarts_order_num_add,
'echarts_order_amount_add' => $echarts_order_amount_add,
'days' => $dates,
];
}
/**
* @notes 商品分析
* @param int $shop_id
* @return array
* @author cjhao
* @date 2021/11/11 15:09
*/
public function goodslist(int $shop_id){
// 商品列表
$goods_count = Db::name('order')->alias('o')
->join('order_goods og', 'og.order_id = o.id')
->join('shop s', 's.id = o.shop_id')
->where([['o.pay_status', '=', 1],['o.shop_id', '=', $shop_id]])
->group('og.goods_id')
->count();
$goods_list = Db::name('order')->alias('o')
->join('order_goods og', 'og.order_id = o.id')
->join('shop s', 's.id = o.shop_id')
->where([['o.pay_status', '=', 1],['o.shop_id', '=', $shop_id]])
->group('og.goods_id')
->limit(20)
->order('sales_volume desc')
->column('s.id,s.logo,s.type,s.name,o.shop_id,count(o.id) as sales_volume,sum(o.order_amount) as sales_price,og.image,og.goods_name');
foreach ($goods_list as $k => $item) {
$goods_list[$k]['number'] = $k + 1;
$goods_list[$k]['sales_price'] = '¥' . number_format($item['sales_price'], 2);
$goods_list[$k]['goods_image'] = UrlServer::getFileUrl($item['image']);
$goods_list[$k]['logo'] = UrlServer::getFileUrl($item['logo']);
if ($item['type'] == 1) {
$goods_list[$k]['type_desc'] = '官方自营';
} else {
$goods_list[$k]['type_desc'] = '入驻商家';
}
}
return ['count' => $goods_count, 'lists' => $goods_list];
}
/**
* @notes 访问分析
* @param int $shop_id
* @return array
* @author cjhao
* @date 2021/11/11 15:09
*/
public function visit(int $shop_id){
//获取今天的时间戳
$today = strtotime('today');
//近七天的开始日期
$start_time = $today - 86400 * 7;
//近七天的结束日期
$end_time = $today - 1;
$user_count = Db::name('shop_stat')
->where([['create_time', 'between', [$start_time, $end_time]],['shop_id', '=', $shop_id]])
->count('id');
//当前时间戳
$start_t = time();
//echarts图表数据
$echarts_add = [];
$dates = [];
for ($i = 7; $i >= 1; $i--) {
$where_start = strtotime("- " . $i . "day", $start_t);
$dates[] = date('m-d', $where_start);
$start_now = strtotime(date('Y-m-d', $where_start));
$end_now = strtotime(date('Y-m-d 23:59:59', $where_start));
$add = Db::name('shop_stat')
->where([['create_time', 'between', [$start_now, $end_now]],['shop_id', '=', $shop_id]])
->count('id');
$echarts_add[] = $add;
}
return [
'user_count' => $user_count,
'echarts_add' => $echarts_add,
'days' => $dates,
];
}
}

View File

@ -0,0 +1,174 @@
<?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\shopapi\logic;
use app\common\basics\Logic;
use app\common\enum\OrderEnum;
use app\common\enum\OrderLogEnum;
use app\common\enum\PayEnum;
use app\common\enum\VerificationEnum;
use app\common\logic\OrderLogLogic;
use app\common\model\order\Order;
use app\common\model\order\Verification;
use think\facade\Db;
/**
* 自提核销逻辑
* Class VerificationLogic
* @package app\shopapi\logic
*/
class VerificationLogic extends Logic
{
/**
* @notes 核销订单列表
* @param $params
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2022/11/2 17:40
*/
public static function lists($params, $pageNo, $pageSize, $shopId)
{
$where[] = ['delivery_type', '=', OrderEnum::DELIVERY_TYPE_SELF];
$where[] = ['pay_status', '=', PayEnum::ISPAID];
$where[] = ['shop_id', '=', $shopId];
$verificationStatus = 0;
if (isset($params['status'])) {
$verificationStatus = $params['status'];
}
$where[] = ['verification_status', '=', $verificationStatus];
$lists = Order::field('id,address,verification_status,consignee,verification_status')
->with(['order_goods' => function ($query) {
$query->field('order_id,image,goods_name,goods_num,spec_value');
}])
->where($where)
->append(['verification_status_text'])
->order(['id' => 'desc'])
->select()
->toArray();
$count = Order::where($where)->count();
return [
'list' => $lists,
'page' => $pageNo,
'size' => $pageSize,
'count' => $count,
'more' => is_more($count, $pageNo, $pageSize)
];
}
/**
* @notes 订单详情
* @param $params
* @param $shopId
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2022/11/2 18:08
*/
public static function detail($params, $shopId)
{
$detail = Order::where('pickup_code',$params['pickup_code'])
->where('shop_id', $shopId)
->with([
'user',
'order_goods' => function ($query) {
$query->field('order_id,image,goods_name,goods_num,spec_value');
}
])
->append(['verification_status_text'])
->field('id,address,verification_status,consignee,verification_status,consignee,mobile')
->find()
->toArray();
$detail['show_verification_nickname'] = $detail['consignee'] ? : ($detail['user']['nickname'] ?? '');
$detail['show_verification_mobile'] = $detail['mobile'] ? : ($detail['user']['mobile'] ?? '');
if ($detail['show_verification_mobile']) {
$detail['show_verification_mobile'] = substr_replace($detail['show_verification_mobile'], '****', 3, 4);
}
return $detail;
}
/**
* @notes 核销订单
* @param $params
* @param $adminInfo
* @return bool
* @author 段誉
* @date 2022/11/2 17:11
*/
public static function verification($params, $adminInfo)
{
Db::startTrans();
try {
$order = Order::find($params['id']);
//添加核销记录
Verification::create([
'order_id' => $order['id'],
'shop_id' => $order['shop_id'],
'handle_id' => $adminInfo['id'],
'verification_scene' => VerificationEnum::TYPE_SHOP,
'snapshot' => json_encode([
'sn' => $adminInfo['account'],
'name' => $adminInfo['name']
]),
]);
//更新订单状态
$order->order_status = OrderEnum::ORDER_STATUS_COMPLETE;
$order->verification_status = OrderEnum::WRITTEN_OFF;
$order->confirm_take_time = time();
$order->save();
//订单日志
OrderLogLogic::record(
OrderLogEnum::TYPE_SHOP,
OrderLogEnum::SHOP_VERIFICATION,
$order['id'],
$adminInfo['id'],
OrderLogEnum::SHOP_VERIFICATION
);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::$error = $e->getMessage();
return false;
}
}
}