1.提交缺失的东西

This commit is contained in:
2025-05-16 16:15:42 +08:00
parent 40e2dff66a
commit e975b4da98
7 changed files with 2676 additions and 0 deletions

View File

@ -0,0 +1,221 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\api\controller;
use app\api\logic\OrderLogic;
use app\common\model\Client_;
use app\common\service\ConfigServer;
use app\common\server\WechatMiniExpressSendSyncServer;
use think\Db;
/**
* 订单
* Class OrderValidate
* @package app\api\controller
*/
class OrderController extends BaseApiController
{
//订单列表
public function lists()
{
$type = $this->request->get('type', 'all');
$order_list = OrderLogic::getOrderList($this->userId, $type, $this->page_no, $this->page_size);
return $this->success('获取成功', $order_list);
}
//下单接口
public function buy()
{
$post = $this->request->post();
$post['user_id'] = $this->userId;
$post['client'] = $this->client;
$check = $this->validate($post, 'app\api\validate\OrderValidate.buy');
if (true !== $check) {
return $this->fail($check);
}
$action = $post['action'];
$info = OrderLogic::info($post, $this->userId);
if ($info['code'] == 0) {
return $this->fail($info['msg']);
}
if ($action == 'info') {
return $this->success('', $info['data']);
}
$order = OrderLogic::add($this->userId, $info['data'], $post);
return $order;
}
//订单详情
public function detail()
{
$order_id = $this->request->get('id');
if (!$order_id){
$this->_error('请选择订单');
}
$order_detail = OrderLogic::getOrderDetail($order_id, $this->user_id);
if (!$order_detail) {
$this->_error('订单不存在了!', '');
}
$this->_success('获取成功', $order_detail);
}
/**
* @notes 微信确认收货 获取详情
* @return \think\response\Json
* @author lbzy
* @datetime 2023-09-05 09:51:41
*/
function wxReceiveDetail()
{
return $this->_success('获取成功', OrderLogic::wxReceiveDetail(input('order_id/d'), $this->user_id));
}
//取消订单
public function cancel()
{
$order_id = $this->request->post('id');
if (empty($order_id)) {
$this->_error('参数错误');
}
return OrderLogic::cancel($order_id, $this->user_id);
}
//删除订单
public function del()
{
$order_id = $this->request->post('id');
if (empty($order_id)) {
$this->_error('参数错误');
}
return OrderLogic::del($order_id, $this->user_id);
}
//确认订单
public function confirm()
{
$order_id = $this->request->post('id');
if (empty($order_id)) {
$this->_error('参数错误');
}
return OrderLogic::confirm($order_id, $this->user_id);
}
public function orderTraces()
{
$order_id = $this->request->get('id');
$tips = '参数错误';
if ($order_id) {
$traces = OrderLogic::orderTraces($order_id, $this->user_id);
if ($traces) {
$this->_success('获取成功', $traces);
}
$tips = '暂无物流信息';
}
$this->_error($tips);
}
/**
* @notes 核销订单列表
* @author ljj
* @date 2021/8/18 3:58 下午
*/
public function verificationLists()
{
$type = $this->request->get('type',\app\common\model\Order::NOT_WRITTEN_OFF);
$lists = OrderLogic::verificationLists($type, $this->user_id, $this->page_no, $this->page_size);
$this->_success('获取成功', $lists);
}
/**
* @notes 提货核销
* @author ljj
* @date 2021/8/18 4:36 下午
*/
public function verification()
{
$post = $this->request->post();
$post['user_id'] = $this->user_id;
$check = $this->validate($post, 'app\api\validate\Order.verification');
if (true !== $check) {
$this->_error($check);
}
$result = OrderLogic::verification($post);
$this->_success('获取成功',$result);
}
/**
* @notes 确认提货
* @author ljj
* @date 2021/8/18 7:02 下午
*/
public function verificationConfirm()
{
$post = $this->request->post();
$post['user_id'] = $this->user_id;
$result = OrderLogic::verificationConfirm($post);
if (true !== $result) {
$this->_error($result);
}
$this->_success('提货成功');
}
/**
* @notes 获取配送方式
* @author ljj
* @date 2021/8/19 7:17 下午
*/
public function getDeliveryType()
{
$data = OrderLogic::getDeliveryType();
return $this->success('获取成功',$data);
}
/**
* @notes 微信同步发货 查询
* @return \think\response\Json
* @author lbzy
* @datetime 2023-09-07 15:27:17
*/
function wechatSyncCheck()
{
$id = $this->request->get('id');
$order = \app\common\model\Order::where('id', $id)->where('user_id', $this->user_id)->findOrEmpty();
$result = WechatMiniExpressSendSyncServer::wechatSyncCheck($order);
if (! $result) {
$this->_error('获取失败');
}
$this->_success('成功', $result);
}
}

1528
app/api/logic/OrderLogic.php Normal file

File diff suppressed because it is too large Load Diff

66
app/api/model/User.php Normal file
View File

@ -0,0 +1,66 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\api\model;
use app\common\model\distribution\DistributionOrder;
use app\common\service\UrlServer;
use think\Db;
use think\Model;
class User extends Model{
public function getAvatarAttr($value,$data){
if($value){
return UrlServer::getFileUrl($value);
}
return $value;
}
public function getLevelAttr($value,$data){
$level_name = '普通买家';
if($value){
$level_name = Db::name('user_level')->where(['del'=>0,'id'=>$value])->value('name');
}
return $level_name;
}
public function getFansDistributionAttr($value,$data)
{
$distribution_order = Db::name('distribution_order_goods')
->field('count(id) as order_num, sum(money) as money')
->where(['user_id' => $data['id'], 'status' => DistributionOrder::STATUS_SUCCESS])
->find();
$where1 = [
['first_leader', '=', $data['id']],
];
$where2 = [
['second_leader', '=', $data['id']],
];
$fans = Db::name('user')
->whereOr([$where1,$where2])
->count();
return [
'fans' => $fans,
'order_num' => $distribution_order['order_num'] ?? 0,
'money' => $distribution_order['money'] ?? 0,
];
}
}

View File

@ -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\api\validate;
use app\api\logic\SeckillLogic;
use app\common\model\Goods;
use app\common\model\GoodsItem;
use app\common\model\Order as CommonOrder;
use app\common\model\OrderGoods;
use app\common\model\SelffetchShop;
use app\common\model\SelffetchVerifier;
use app\common\model\Team;
use app\common\service\ConfigServer;
use think\Db;
use think\Validate;
use app\common\model\AfterSale as CommonAfterSale;
class OrderValidate extends Validate
{
protected $rule = [
'goods' => 'require|array|checkGoods',
'action' => 'require',
'coupon_id' =>'checkCoupon',
'delivery_type' => 'require|in:'.CommonOrder::DELIVERY_STATUS_EXPRESS.','.CommonOrder::DELIVERY_STATUS_SELF,
// 'selffetch_shop_id' => 'requireIf:delivery_type,'.CommonOrder::DELIVERY_STATUS_SELF,
// 'consignee' => 'requireIf:delivery_type,'.CommonOrder::DELIVERY_STATUS_SELF,
// 'mobile' => 'requireCallback:check_require|mobile',
'pickup_code' => 'require|checkPickupCode',
];
protected $message = [
'goods.require' => '参数错误',
'action.require' => '参数缺失',
'delivery_type.require' => '配送方式不能为空',
// 'selffetch_shop_id.requireIf' => '自提门店不能为空',
// 'consignee.requireIf' => '取货人不能为空',
// 'mobile.requireCallback' => '联系电话不能为空',
// 'mobile.mobile' => '联系电话格式不正确',
'pickup_code.require' => '提货码不能为空',
];
protected function sceneBuy()
{
$this->only(['action', 'goods', 'coupon_id', 'delivery_type']);
}
protected function sceneVerification()
{
$this->only(['pickup_code']);
}
protected function checkGoods($value, $rule, $data)
{
foreach ($value as $item){
if (!$item['item_id'] || !$item['num']){
return '参数缺失';
}
}
return true;
}
//验证优惠券
protected function checkCoupon($value,$rule,$data){
if($value){
$coupon = Db::name('coupon c')
->join('coupon_list cl','c.id = cl.coupon_id')
->where(['cl.id '=>$value, 'c.del'=>0,'cl.del'=>0,'cl.status'=>0])
->field('c.*,cl.create_time as get_coupon_time')
->find();
if(empty($coupon)){
return '优惠券不存在';
}
$tips = true;
$now = time();
if($coupon['use_time_type'] == 1){
if($coupon['use_time_start'] > $now || $coupon['use_time_end'] < $now){
$tips = '优惠券不在使用时间范围内';
}
}else{//领券当天X天可用
$coupon['use_time'] = $coupon['get_coupon_time']+86400*$coupon['use_time'];
if($coupon['use_time_type'] == 3){ //领券次日起X天可用
$coupon['use_time'] = $coupon['create_time'] + 86400*$coupon['use_time']+86400;
}
if($coupon['use_time'] - $now < 0){
$tips = '优惠券不在使用时间范围内';
}
}
$item_ids = array_column($data['goods'], 'item_id');
$item_num = array_column($data['goods'], 'num', 'item_id');
$goods_price_array = Db::name('goods_item')->alias('gi')
->join('goods g', 'gi.goods_id = g.id')
->where(['gi.id' => $item_ids])
->column('gi.*,g.is_member', 'gi.id');
//会员折扣价格
$user_id = $data['user_id'] ?? 0;
$level_discount = Db::name('user u')
->join('user_level l', 'u.level = l.id')
->where('u.id', $user_id)
->value('discount');
$seckill_list = SeckillLogic::getSeckillGoods();
$seckill_goods = $seckill_list['seckill_goods'];
//会员折扣价(优先级最高且不和其他活动重叠) > 活动价格
foreach ($goods_price_array as $key => $item){
if ($item['is_member'] == 1 && $level_discount > 0) {
$goods_price_array[$key]['price'] = round($item['price'] * $level_discount / 10, 2);
continue;
}
if(isset($seckill_goods[$item['id']])){
$goods_price_array[$key]['price'] = $seckill_goods[$item['id']]['price'];
continue;
}
}
//所有的商品id
$goods_ids = array_column($goods_price_array, 'goods_id');
//优惠券商品
$coupon_goods = Db::name('coupon_goods')->where(['coupon_id' => $coupon['id']])->column('goods_id');
//与当前优惠券关联的商品id
$intersect_goods = array_intersect($goods_ids, $coupon_goods);
//全部商品可用、满足金额可用
if($coupon['use_goods_type'] == 1 && $coupon['condition_type'] == 2){
$total_price = 0;
foreach ($data['goods'] as $goods_item){
$price = isset($goods_price_array[$goods_item['item_id']]) ? $goods_price_array[$goods_item['item_id']]['price'] : 0;
$total_price += $price * $goods_item['num'];
}
//结算商品未满足金额
if($total_price < $coupon['condition_money']){
$tips = '所结算的商品中未满足使用的金额';
}
}
//指定商品可用
if($coupon['use_goods_type'] == 2) {
//未包含指定商品
if(empty($intersect_goods)){
$tips = '所结算的商品中未包含指定商品';
}
if($intersect_goods && $coupon['condition_type'] == 2){
$total_price = 0;
foreach ($intersect_goods as $goods_item){
foreach ($goods_price_array as $price_item){
if($price_item['goods_id'] == $goods_item){
$num = $item_num[$price_item['id']] ?? 0;
$total_price += $price_item['price'] * $num;
}
}
}
//结算商品未满足金额
if($total_price < $coupon['condition_money']){
$tips = '所结算的商品中未满足使用的金额';
}
}
}
//指定商品不可用
if($coupon['use_goods_type'] == 3) {
//包含不可用商品
if($intersect_goods){
$tips = '所结算的商品中包含指定不可用商品';
}
//满足金额可用
if(empty($intersect_goods) && $coupon['condition_type'] == 2){
$diff_goods = array_diff($goods_ids,$coupon_goods);
$total_price = 0;
foreach ($diff_goods as $goods_item){
foreach ($goods_price_array as $price_item){
if($price_item['goods_id'] == $goods_item){
$num = $item_num[$price_item['id']] ?? 0;
$total_price += $price_item['price'] * $num;
}
}
}
//结算商品未满足金额
if($total_price < $coupon['condition_money']){
$tips = '所结算的商品中未满足使用的金额';
}
}
}
return $tips;
}
}
function check_require($value, $data){
if($data['delivery_type'] == CommonOrder::DELIVERY_STATUS_SELF){
return true;
}
}
public function checkPickupCode($value,$rule,$data)
{
$result = CommonOrder::where(['pickup_code'=>$value])->find();
if (empty($result)) {
return '提货码不正确或订单不存在';
}
if ($result['order_status'] != CommonOrder::STATUS_WAIT_DELIVERY) {
return '订单不允许核销';
}
if ($result['delivery_type'] != CommonOrder::DELIVERY_STATUS_SELF) {
return '不是自提订单,不允许核销';
}
if ($result['verification_status'] == CommonOrder::WRITTEN_OFF) {
return '订单已核销';
}
$verifier = SelffetchVerifier::where(['selffetch_shop_id'=>$result['selffetch_shop_id'],'user_id'=>$data['user_id'],'status'=>1,'del'=>0])->find();
if (empty($verifier)) {
return '非门店核销员,无法核销订单';
}
if ($result['order_type'] == CommonOrder::TEAM_ORDER){
$found = Db::name('team_found')->where(['id' => $result['team_found_id']])->find();
if ($found['status'] != Team::STATUS_SUCCESS){
return '拼团成功后才能核销';
}
}
return true;
}
//验证订单商品是否支持对应的配送方式
public function checkDeliveryType($value,$rule,$data)
{
$is_express = ConfigServer::get('delivery_type', 'is_express');
$is_express = ($is_express === null) ? 1 : $is_express;
$is_selffetch = ConfigServer::get('delivery_type', 'is_selffetch');
$is_selffetch = ($is_selffetch === null) ? 0 : $is_selffetch;
$tips = true;
//门店自提
if ($value == CommonOrder::DELIVERY_STATUS_SELF) {
if ($is_selffetch == 0) {
$tips = '暂未开启门店自提配送方式';
}else {
$item_ids = implode(',',array_column($data['goods'],'item_id'));
$goods_ids = implode(',',GoodsItem::where('id','in', $item_ids)->column('goods_id'));
$goods = Goods::where('id','in', $goods_ids)->select();
$goods_name = [];
foreach ($goods as $val) {
if ($val['is_selffetch'] == 0) {
$goods_name[] = $val['name'];
}
}
if (!empty($goods_name)) {
// $tips = '商品:'.implode('、',$goods_name).'不支持门店自提!';
$tips = '订单存在不支持门店自提的商品!';
}
}
}elseif ($value == CommonOrder::DELIVERY_STATUS_EXPRESS) { //快递配送
if ($is_express == 0) {
$tips = '暂未开启快递配送方式';
}else {
$item_ids = implode(',',array_column($data['goods'],'item_id'));
$goods_ids = implode(',',GoodsItem::where('id','in', $item_ids)->column('goods_id'));
$goods = Goods::where('id','in', $goods_ids)->select();
$goods_name = [];
foreach ($goods as $val) {
if ($val['is_express'] == 0) {
$goods_name[] = $val['name'];
}
}
if (!empty($goods_name)) {
// $tips = '商品:'.implode('、',$goods_name).'不支持快递配送!';
$tips = '订单存在不支持快递配送的商品!';
}
}
}
return $tips;
}
}

View File

@ -0,0 +1,236 @@
<?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\common\logic;
use app\api\model\User;
use app\common\model\account\AccountLog;
use app\common\model\OrderGoods;
use app\common\service\ConfigServer;
use think\Db;
class IntegralLogic
{
/**
* Notes: 订单是否开启积分抵扣
* @param $order_goods
* @author 段誉(2021/4/1 11:05)
* @return bool
*/
public static function isIntegralInOrder($order_goods)
{
$integral_switch = ConfigServer::get('marketing', 'integral_deduction_status', 0);
if ($integral_switch == 0) {
return false;
}
foreach ($order_goods as $good) {
if ($good['is_integral'] != 1) {
return false;
}
}
return true;
}
/**
* Desc: 处理积分
* @param $user_id
* @param $use_integral
* @param $channel
* @param $source_id
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public static function handleIntegral($user_id, $use_integral, $channel, $source_id)
{
$user = User::get($user_id);
switch ($channel) {
//下单积分抵扣
case AccountLog::order_deduction_integral:
$user->user_integral = ['dec', $use_integral];
$change_type = 2;
break;
//取消订单退回积分
case AccountLog::cancel_order_refund_integral:
$user->user_integral = ['inc', $use_integral];
$change_type = 1;
break;
//下单奖励积分(每天一单)
case AccountLog::order_add_integral:
$user->user_integral = ['inc', $use_integral];
$change_type = 1;
break;
//扣除首单积分奖励(用户取消订单)
case AccountLog::deduct_order_first_integral:
$diff = $user->user_integral - $use_integral;
if ($diff < 0) {
$user->user_integral = 0;
} else {
$user->user_integral = ['dec', $use_integral];
}
$change_type = 2;
break;
//购买商品赠送积分
case AccountLog::order_goods_give_integral:
$user->user_integral = ['inc', $use_integral];
$change_type = 1;
break;
default:
return;
}
$user->save();
//更新积分记录
AccountLogLogic::AccountRecord($user_id, $use_integral, $change_type, $channel, '', $source_id);
}
/**
* Desc: 下单奖励积分(每天第一单)
* @param $user_id
* @param $order_id
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public static function rewardIntegral($user_id, $order_id)
{
//是否为当天第一个订单(是->奖励积分)
$check = Db::name('account_log')
->where(['user_id' => $user_id, 'source_type' => AccountLog::order_add_integral])
->whereTime('create_time', 'today')
->find();
//下单奖励开关;0-关闭;1-开启;
$order_award_integral = ConfigServer::get('marketing', 'order_award_integral', 0);
if ($order_award_integral == 0 || $check) {
return;
}
self::handleIntegral($user_id, $order_award_integral, AccountLog::order_add_integral, $order_id);
}
/**
* Notes: 扣除首单积分
* @param $user_id
* @param $order_id
* @author 段誉(2021/2/25 10:23)
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public static function backIntegral($user_id, $order_id)
{
$log = Db::name('account_log')
->where([
'user_id' => $user_id,
'source_type' => AccountLog::order_add_integral,
'source_id' => $order_id
])
->find();
if (!$log){
return false;
}
self::handleIntegral($user_id, $log['change_amount'], AccountLog::deduct_order_first_integral, $order_id);
return true;
}
/**
* Notes: 购买商品奖励积分
* @param $user_id
* @param $order_id
* @author 段誉(2021/4/1 11:06)
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public static function rewardIntegralByGoods($user_id, $order_id)
{
$goods_model = new OrderGoods();
$goods = $goods_model->alias('og')
->field('g.*,og.total_pay_price')
->join('goods g', 'g.id = og.goods_id')
->where(['order_id' => $order_id])
->select();
$get_integral = 0;//可得积分
foreach ($goods as $good) {
//赠送积分类型0-不赠送1-赠送固定积分2-按比例赠送积分'
if ($good['give_integral_type'] == 0) {
continue;
}
$good['give_integral'] = empty($good['give_integral']) ? 0 : intval($good['give_integral']);
if ($good['give_integral_type'] == 1) {
$get_integral += $good['give_integral'];
}
if ($good['give_integral_type'] == 2) {
$get_integral += $good['give_integral'] * $good['total_pay_price'] / 100;
}
}
if ($get_integral <= 0) {
return;
}
//用户赠送积分
self::handleIntegral($user_id, $get_integral, AccountLog::order_goods_give_integral, $order_id);
}
/**
* Notes: 积分抵扣描述
* @param $integral_config
* @param $integral_limit
* @author 段誉(2021/5/19 18:32)
* @return string
*/
public static function getIntegralDesc($integral_config, $integral_limit)
{
if ($integral_config <= 0) {
return '积分不可抵扣';
}
$integral_desc = $integral_config.'积分可抵扣1元';
if ($integral_limit > 0) {
$integral_desc .= ',单次抵扣积分不能低于'.$integral_limit;
}
return $integral_desc;
}
}

246
app/common/model/Order.php Normal file
View File

@ -0,0 +1,246 @@
<?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\common\model;
use think\facade\Db;
use think\Model;
class Order extends Model
{
protected $name = 'order';
//订单类型
const NORMAL_ORDER = 0;//普通订单
const SECKILL_ORDER = 1;//秒杀订单
const TEAM_ORDER = 2;//拼团订单
const BARGAIN_ORDER = 3;//砍价订单
//订单状态
const STATUS_WAIT_PAY = 0; //待付款
const STATUS_WAIT_DELIVERY = 1; //待发货
const STATUS_WAIT_RECEIVE = 2; //待收货
const STATUS_FINISH = 3; //已完成
const STATUS_CLOSE = 4; //已关闭
//配送方式
const DELIVERY_STATUS_EXPRESS = 1;//快递配送
const DELIVERY_STATUS_SELF = 2;//上门自提
//核销状态
const NOT_WRITTEN_OFF = 0;//待核销
const WRITTEN_OFF = 1;//已核销
//订单状态
public static function getOrderStatus($status = true)
{
$desc = [
self::STATUS_WAIT_PAY => '待付款',
self::STATUS_WAIT_DELIVERY => '待发货',
self::STATUS_WAIT_RECEIVE => '待收货',
self::STATUS_FINISH => '已完成',
self::STATUS_CLOSE => '已关闭',
];
if ($status === true) {
return $desc;
}
return $desc[$status] ?? '未知';
}
//订单类型
public static function getOrderType($type)
{
$desc = [
self::NORMAL_ORDER => '普通订单',
self::SECKILL_ORDER => '秒杀订单',
self::TEAM_ORDER => '拼团订单',
self::BARGAIN_ORDER => '砍价订单',
];
if ($type === true){
return $desc;
}
return $desc[$type] ?? '未知';
}
//配送方式
public static function getDeliveryType($type)
{
$desc = [
self::DELIVERY_STATUS_EXPRESS => '快递发货',
self::DELIVERY_STATUS_SELF => '上门自提'
];
if ($type === true){
return $desc;
}
return $desc[$type] ?? '未知';
}
/**
* @notes 核销状态
* @param $type
* @return string|string[]
* @author ljj
* @date 2021/8/16 7:31 下午
*/
public static function getVerificationStatus($type)
{
$desc = [
self::NOT_WRITTEN_OFF => '待核销',
self::WRITTEN_OFF => '已核销',
];
if ($type === true){
return $desc;
}
return $desc[$type] ?? '未知';
}
//下单时间
public function getCreateTimeAttr($value, $data)
{
return date('Y-m-d H:i:s', $value);
}
//付款时间
public function getPayTimeAttr($value, $data)
{
if ($value) {
return date('Y-m-d H:i:s', $value);
}
$value = '未支付';
return $value;
}
// 发货时间
public function getShippingTimeAttr($value, $data)
{
if ($value) {
return date('Y-m-d H:i:s', $value);
}
return $value;
}
//收货时间
public function getTakeTimeAttr($value, $data)
{
if ($value) {
return date('Y-m-d H:i:s', $value);
}
return $value;
}
//取消时间
public function getCancelTimeAttr($value, $data)
{
if ($value) {
return date('Y-m-d H:i:s', $value);
}
return $value;
}
//订单类型
public function getOrderTypeTextAttr($value, $data)
{
return self::getOrderType($data['order_type']);
}
//订单状态
public function getOrderStatusTextAttr($value, $data)
{
return self::getOrderStatus($data['order_status']);
}
//订单支付方式
public function getPayWayTextAttr($value, $data)
{
return Pay::getPayWay($data['pay_way']);
}
//订单支付状态
public function getPayStatusTextAttr($value, $data)
{
return Pay::getPayStatus($data['pay_status']);
}
//订单来源
public function getOrderSourceTextAttr($value, $data)
{
return Client_::getClient($data['order_source']);
}
//订单商品数量
public function getGoodsCountAttr($value, $data)
{
return count($this->order_goods);
}
//订单关联商品
public function orderGoods()
{
return $this->hasMany('order_goods', 'order_id', 'id');
}
//订单用户
public function user()
{
return $this->hasOne('user', 'id', 'user_id')
->field('id,sn,nickname,avatar,level,mobile,sex,create_time');
}
/**
* @notes 自提门店
* @return \think\model\relation\HasOne
* @author lbzy
* @datetime 2023-10-08 16:48:44
*/
function selffetchShop()
{
return $this->hasOne(SelffetchShop::class, 'id', 'selffetch_shop_id');
}
//收货地址
public function getDeliveryAddressAttr($value, $data)
{
$region = Db::name('dev_region')
->where('id', 'IN', [$data['province'], $data['city'], $data['district']])
->order('level asc')
->column('name');
$region_desc = implode('', $region);
return $region_desc . $data['address'];
}
/**
* @notes 核销状态
* @param $value
* @param $data
* @return string|string[]
* @author ljj
* @date 2021/8/16 7:32 下午
*/
public function getVerificationStatusTextAttr($value, $data)
{
return self::getVerificationStatus($data['verification_status']);
}
}

View File

@ -0,0 +1,80 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\model\distribution;
use think\Model;
/**
* 分销订单
* Class DistributionOrder
* @package app\common\model
*/
class DistributionOrder extends Model
{
protected $name = 'distribution_order_goods';
//分销订单状态
const STATUS_WAIT_HANDLE = 1;//待返佣
const STATUS_SUCCESS = 2;//已结算
const STATUS_ERROR = 3;//已失效
//分销订单状态
public static function getOrderStatus($status = true)
{
$desc = [
self::STATUS_WAIT_HANDLE => '待返佣',
self::STATUS_SUCCESS => '已结算',
self::STATUS_ERROR => '已失效',
];
if ($status === true) {
return $desc;
}
return $desc[$status] ?? '未知';
}
/**
* Notes: 更新指定分佣订单状态
* @param $distribution_id
* @param $status
* @author 段誉(2021/4/23 10:10)
* @return DistributionOrder
*/
public static function updateOrderStatus($distribution_id, $status)
{
$time = time();
return self::where('id', $distribution_id)
->update([
'status' => $status,
'settlement_time' => $time,
'update_time' => $time
]);
}
//用户
public function user()
{
return $this->hasOne('user', 'id', 'user_id')
->field('id,sn,nickname,avatar,level,mobile,sex,create_time');
}
}