You've already forked guangan
订单下单相关
This commit is contained in:
@ -39,14 +39,8 @@ class Goods extends Controller
|
|||||||
$query->equal('code')->like('name#keys')->like('marks,cates', ',');
|
$query->equal('code')->like('name#keys')->like('marks,cates', ',');
|
||||||
if (!empty($code = input('code'))) {
|
if (!empty($code = input('code'))) {
|
||||||
// 查询单个商品详情
|
// 查询单个商品详情
|
||||||
$query->with(['discount', 'items', 'comments' => function (Query $query) {
|
$query->with(['items']);
|
||||||
$query->limit(2)->where(['status' => 1, 'deleted' => 0]);
|
|
||||||
}])->withCount(['comments' => function (Query $query) {
|
|
||||||
$query->where(['status' => 1, 'deleted' => 0]);
|
|
||||||
}]);
|
|
||||||
PointsMallGoods::mk()->where(['code' => $code])->inc('num_read')->update([]);
|
PointsMallGoods::mk()->where(['code' => $code])->inc('num_read')->update([]);
|
||||||
} else {
|
|
||||||
$query->with('discount')->withoutField('content');
|
|
||||||
}
|
}
|
||||||
// 数据排序处理
|
// 数据排序处理
|
||||||
$sort = intval(input('sort', 0));
|
$sort = intval(input('sort', 0));
|
||||||
|
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace plugin\points_mall\controller\api\auth;
|
||||||
|
|
||||||
|
use plugin\points_mall\controller\api\Auth;
|
||||||
|
use plugin\points_mall\model\PointsMallAddress;
|
||||||
|
use think\admin\helper\QueryHelper;
|
||||||
|
|
||||||
|
class Address extends Auth
|
||||||
|
{
|
||||||
|
public function list()
|
||||||
|
{
|
||||||
|
PointsMallAddress::mQuery(null, function (QueryHelper $query) {
|
||||||
|
$query->where("unid", $this->usid);
|
||||||
|
$this->success('获取成功!', $query->select(), false, false, 10);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function info()
|
||||||
|
{
|
||||||
|
$data = $this->_vali([
|
||||||
|
"id.require" => "获取失败,请稍候再试!",
|
||||||
|
"unid.value" => $this->usid,
|
||||||
|
]);
|
||||||
|
$this->success('获取成功!', PointsMallAddress::query()->where($data)->find());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save()
|
||||||
|
{
|
||||||
|
$data = $this->request->post();
|
||||||
|
$data['unid'] = $this->usid;
|
||||||
|
if (empty($data['id']) || $data['id'] == 0) {
|
||||||
|
unset($data['id']);
|
||||||
|
$pointsMallAddress = PointsMallAddress::create($data);
|
||||||
|
} else {
|
||||||
|
$pointsMallAddress = PointsMallAddress::find($data['id']);
|
||||||
|
if ($pointsMallAddress->unid != $this->usid) {
|
||||||
|
$this->error('非法操作!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($pointsMallAddress->save($data)) {
|
||||||
|
$this->success('保存成功!');
|
||||||
|
} else {
|
||||||
|
$this->error('保存失败!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete()
|
||||||
|
{
|
||||||
|
$input = $this->_vali([
|
||||||
|
"id.require" => "删除失败,请稍候再试!",
|
||||||
|
"unid.value" => $this->usid,
|
||||||
|
]);
|
||||||
|
if (PointsMallAddress::query()->where($input)->delete()) {
|
||||||
|
$this->success('删除成功!');
|
||||||
|
} else {
|
||||||
|
$this->error('删除失败!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ namespace plugin\points_mall\controller\api\auth;
|
|||||||
|
|
||||||
use plugin\points_mall\controller\api\Auth;
|
use plugin\points_mall\controller\api\Auth;
|
||||||
use plugin\points_mall\model\PointsMallAddress;
|
use plugin\points_mall\model\PointsMallAddress;
|
||||||
|
use plugin\points_mall\model\PointsMallGoods;
|
||||||
use plugin\points_mall\model\PointsMallOrder;
|
use plugin\points_mall\model\PointsMallOrder;
|
||||||
use plugin\points_mall\model\PointsMallOrderCart;
|
use plugin\points_mall\model\PointsMallOrderCart;
|
||||||
use plugin\points_mall\model\PointsMallOrderItem;
|
use plugin\points_mall\model\PointsMallOrderItem;
|
||||||
@ -18,7 +19,7 @@ use think\exception\HttpResponseException;
|
|||||||
|
|
||||||
class Order extends Auth
|
class Order extends Auth
|
||||||
{
|
{
|
||||||
protected $checkBind = true;
|
protected $checkBind = false;
|
||||||
/**
|
/**
|
||||||
* 获取订单数据
|
* 获取订单数据
|
||||||
* @return void
|
* @return void
|
||||||
@ -29,19 +30,101 @@ class Order extends Auth
|
|||||||
if (empty(input('order_no'))) {
|
if (empty(input('order_no'))) {
|
||||||
$query->with('items')->where(['refund_status' => 0]);
|
$query->with('items')->where(['refund_status' => 0]);
|
||||||
} else {
|
} else {
|
||||||
$query->with(['items', 'address', 'sender', 'payments' => function (Query $query) {
|
$query->with(['items', 'address', 'sender']);
|
||||||
$query->where(static function (Query $query) {
|
|
||||||
// $query->whereOr(['channel_type' => Payment::VOUCHER, 'payment_status' => 1, 'audit_status' => 1]);
|
|
||||||
$query->whereOr(['payment_status' => 1, 'audit_status' => 1]);
|
|
||||||
});
|
|
||||||
}]);
|
|
||||||
}
|
}
|
||||||
$query->in('status')->equal('order_no');
|
$query->in('status')->equal('order_no');
|
||||||
$query->where(['unid' => $this->unid, 'deleted_status' => 0])->order('id desc');
|
$query->where(['unid' => $this->usid, 'deleted_status' => 0])->order('id desc');
|
||||||
$this->success('获取订单成功!', $query->page(intval(input('page')), false, false, 10));
|
$this->success('获取订单成功!', $query->page(intval(input('page')), false, false, 10));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
public function add_goods() {
|
||||||
|
$input = $this->_vali([
|
||||||
|
'code.require' => '请传入商品编号',
|
||||||
|
]);
|
||||||
|
$order = [
|
||||||
|
'unid' => $this->usid,
|
||||||
|
];
|
||||||
|
do $extra = ['order_no' => $order['order_no'] = CodeExtend::uniqidNumber(16, 'N')];
|
||||||
|
while (PointsMallOrder::mk()->master()->where($extra)->findOrEmpty()->isExists());
|
||||||
|
[$items, $deliveryType] = [[], 1];
|
||||||
|
$goods = PointsMallGoods::query()->with(['items'])->where(['code' => $input['code']])->findOrEmpty();
|
||||||
|
if ($goods->isEmpty()) $this->error('商品不存在!');
|
||||||
|
$gspec = $goods->items->first();
|
||||||
|
$count = 1;
|
||||||
|
// 商品库存检查
|
||||||
|
if ($gspec['stock_sales'] + $count > $gspec['stock_total']) $this->error('库存不足!');
|
||||||
|
// 订单详情处理
|
||||||
|
$items[] = [
|
||||||
|
'unid' => $order['unid'],
|
||||||
|
'order_no' => $order['order_no'],
|
||||||
|
// 商品字段
|
||||||
|
'gsku' => $gspec['gsku'],
|
||||||
|
'gname' => $goods['name'],
|
||||||
|
'gcode' => $gspec['gcode'],
|
||||||
|
'ghash' => $gspec['ghash'],
|
||||||
|
'gspec' => $gspec['gspec'],
|
||||||
|
'gunit' => $gspec['gunit'],
|
||||||
|
'gcover' => empty($gspec['gimage']) ? $goods['cover'] : $gspec['gimage'],
|
||||||
|
// 库存数量处理
|
||||||
|
'stock_sales' => $count,
|
||||||
|
// 快递发货数据
|
||||||
|
'delivery_code' => $goods['delivery_code'],
|
||||||
|
'delivery_count' => $goods['rebate_type'] > 0 ? $gspec['number_express'] * $count : 0,
|
||||||
|
// 商品费用字段
|
||||||
|
'price_cost' => $gspec['price_cost'],
|
||||||
|
'price_market' => $gspec['price_market'],
|
||||||
|
'price_selling' => $gspec['price_selling'],
|
||||||
|
// 商品费用统计
|
||||||
|
'total_price_cost' => $gspec['price_cost'] * $count,
|
||||||
|
'total_price_market' => $gspec['price_market'] * $count,
|
||||||
|
'total_price_selling' => $gspec['price_selling'] * $count,
|
||||||
|
'total_allow_balance' => $gspec['allow_balance'] * $count,
|
||||||
|
'total_allow_integral' => $gspec['allow_integral'] * $count,
|
||||||
|
'total_reward_balance' => $gspec['reward_balance'] * $count,
|
||||||
|
'total_reward_integral' => $gspec['reward_integral'] * $count,
|
||||||
|
];
|
||||||
|
|
||||||
|
// 默认使用销售销售
|
||||||
|
$order['rebate_amount'] = array_sum(array_column($items, 'rebate_amount'));
|
||||||
|
$order['allow_balance'] = array_sum(array_column($items, 'total_allow_balance'));
|
||||||
|
$order['allow_integral'] = array_sum(array_column($items, 'total_allow_integral'));
|
||||||
|
$order['reward_balance'] = array_sum(array_column($items, 'total_reward_balance'));
|
||||||
|
$order['reward_integral'] = array_sum(array_column($items, 'total_reward_integral'));
|
||||||
|
// 订单发货类型
|
||||||
|
$order['status'] = $deliveryType ? 1 : 2;
|
||||||
|
$order['delivery_type'] = $deliveryType;
|
||||||
|
$order['ratio_integral'] = 100;
|
||||||
|
// 统计商品数量
|
||||||
|
$order['number_goods'] = array_sum(array_column($items, 'stock_sales'));
|
||||||
|
$order['number_express'] = array_sum(array_column($items, 'delivery_count'));
|
||||||
|
// 统计商品金额
|
||||||
|
$order['amount_cost'] = array_sum(array_column($items, 'total_price_cost'));
|
||||||
|
$order['amount_goods'] = array_sum(array_column($items, 'total_price_selling'));
|
||||||
|
// 折扣后的金额
|
||||||
|
$order['amount_discount'] = array_sum(array_column($items, 'discount_amount'));
|
||||||
|
$order['amount_reduct'] = $order['amount_goods'];
|
||||||
|
// 统计订单金额
|
||||||
|
$order['amount_real'] = round($order['amount_discount'] - $order['amount_reduct'], 2);
|
||||||
|
$order['amount_total'] = $order['amount_goods'];
|
||||||
|
$order['amount_profit'] = round($order['amount_real'] - $order['amount_cost']);
|
||||||
|
// 写入商品数据
|
||||||
|
$model = PointsMallOrder::mk();
|
||||||
|
$this->app->db->transaction(function () use ($order, $items, &$model) {
|
||||||
|
$model->save($order) && PointsMallOrderItem::mk()->saveAll($items);
|
||||||
|
});
|
||||||
|
// 同步库存销量
|
||||||
|
foreach (array_unique(array_column($items, 'gcode')) as $gcode) {
|
||||||
|
GoodsService::stock($gcode);
|
||||||
|
}
|
||||||
|
// 触发订单创建事件
|
||||||
|
$this->app->event->trigger('PluginWemallOrderCreate', $order);
|
||||||
|
// 无需发货且无需支付,直接完成支付流程
|
||||||
|
if ($order['status'] === 2 && empty($order['amount_real'])) {
|
||||||
|
$this->success('下单成功!', $model->toArray());
|
||||||
|
}
|
||||||
|
// 返回处理成功数据
|
||||||
|
$this->success('下单成功!', array_merge($order, ['items' => $items]));
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 创建订单数据
|
* 创建订单数据
|
||||||
* @return void
|
* @return void
|
||||||
@ -208,18 +291,18 @@ class Order extends Auth
|
|||||||
public function perfect()
|
public function perfect()
|
||||||
{
|
{
|
||||||
$data = $this->_vali([
|
$data = $this->_vali([
|
||||||
'unid.value' => $this->unid,
|
'unid.value' => $this->usid,
|
||||||
'order_no.require' => '单号不能为空',
|
'order_no.require' => '单号不能为空',
|
||||||
'address_id.require' => '地址不能为空',
|
'address_id.require' => '地址不能为空',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// 用户收货地址
|
// 用户收货地址
|
||||||
$where = ['id' => $data['address_id'], 'unid' => $this->unid, 'deleted' => 0];
|
$where = ['id' => $data['address_id'], 'unid' => $this->usid, 'deleted' => 0];
|
||||||
$address = PointsMallAddress::mk()->where($where)->findOrEmpty();
|
$address = PointsMallAddress::mk()->where($where)->findOrEmpty();
|
||||||
if ($address->isEmpty()) $this->error('地址异常!');
|
if ($address->isEmpty()) $this->error('地址异常!');
|
||||||
|
|
||||||
// 订单状态检查
|
// 订单状态检查
|
||||||
$where = ['unid' => $this->unid, 'order_no' => $data['order_no'], 'delivery_type' => 1];
|
$where = ['unid' => $this->usid, 'order_no' => $data['order_no'], 'delivery_type' => 1];
|
||||||
$order = PointsMallOrder::mk()->where($where)->whereIn('status', [1, 2])->findOrEmpty();
|
$order = PointsMallOrder::mk()->where($where)->whereIn('status', [1, 2])->findOrEmpty();
|
||||||
if ($order->isEmpty()) $this->error('不能修改!');
|
if ($order->isEmpty()) $this->error('不能修改!');
|
||||||
|
|
||||||
@ -251,15 +334,15 @@ class Order extends Auth
|
|||||||
public function payment()
|
public function payment()
|
||||||
{
|
{
|
||||||
$data = $this->_vali([
|
$data = $this->_vali([
|
||||||
'unid.value' => $this->unid,
|
'unid.value' => $this->usid,
|
||||||
'balance.default' => '0.00',
|
// 'balance.default' => '0.00',
|
||||||
'integral.default' => '0',
|
// 'integral.default' => '0',
|
||||||
'order_no.require' => '单号不能为空',
|
'order_no.require' => '单号不能为空',
|
||||||
'order_ps.default' => '',
|
// 'order_ps.default' => '',
|
||||||
'coupon_code.default' => '', # 优惠券编号
|
// 'coupon_code.default' => '', # 优惠券编号
|
||||||
'channel_code.require' => '支付不能为空',
|
// 'channel_code.require' => '支付不能为空',
|
||||||
'payment_back.default' => '', # 支付回跳地址
|
// 'payment_back.default' => '', # 支付回跳地址
|
||||||
'payment_image.default' => '', # 支付凭证图片
|
// 'payment_image.default' => '', # 支付凭证图片
|
||||||
]);
|
]);
|
||||||
try {
|
try {
|
||||||
$order = $this->getOrderModel();
|
$order = $this->getOrderModel();
|
||||||
|
@ -31,15 +31,6 @@ class PointsMallGoods extends Model
|
|||||||
->where(['status' => 1]);
|
->where(['status' => 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 关联商品评论数据
|
|
||||||
* @return \think\model\relation\HasMany
|
|
||||||
*/
|
|
||||||
public function comments()
|
|
||||||
{
|
|
||||||
return $this->hasMany(PluginWemallUserActionComment::class, 'gcode', 'code')->with('bindUser');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 关联产品列表
|
* 关联产品列表
|
||||||
* @return array
|
* @return array
|
||||||
|
@ -44,54 +44,58 @@ class PointsMallOrder extends Model
|
|||||||
// {
|
// {
|
||||||
// return $this->hasMany(PluginPaymentRecord::class, 'order_no', 'order_no')->order('id desc')->withoutField('payment_notify');
|
// return $this->hasMany(PluginPaymentRecord::class, 'order_no', 'order_no')->order('id desc')->withoutField('payment_notify');
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关联收货地址
|
||||||
|
* @return \think\model\relation\HasOne
|
||||||
|
*/
|
||||||
|
public function address()
|
||||||
|
{
|
||||||
|
return $this->hasOne(PointsMallAddress::class, 'id', 'address_id');
|
||||||
|
}
|
||||||
|
public function sender()
|
||||||
|
{
|
||||||
|
return $this->hasOne(PointsMallOrderSender::class, 'order_no', 'order_no');
|
||||||
|
}
|
||||||
//
|
//
|
||||||
// /**
|
// /**
|
||||||
// * 关联收货地址
|
// * 格式化支付通道
|
||||||
// * @return \think\model\relation\HasOne
|
// * @param mixed $value
|
||||||
|
// * @return array
|
||||||
// */
|
// */
|
||||||
// public function address()
|
// public function getPaymentAllowsAttr($value): array
|
||||||
// {
|
// {
|
||||||
// return $this->hasOne(PluginWemallOrderSender::class, 'order_no', 'order_no');
|
// $payments = is_string($value) ? str2arr($value) : [];
|
||||||
|
// return in_array('all', $payments) ? ['all'] : $payments;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 时间格式处理
|
||||||
|
// * @param mixed $value
|
||||||
|
// * @return string
|
||||||
|
// */
|
||||||
|
// public function getPaymentTimeAttr($value): string
|
||||||
|
// {
|
||||||
|
// return $this->getCreateTimeAttr($value);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 时间格式处理
|
||||||
|
// * @param mixed $value
|
||||||
|
// * @return string
|
||||||
|
// */
|
||||||
|
// public function setPaymentTimeAttr($value): string
|
||||||
|
// {
|
||||||
|
// return $this->setCreateTimeAttr($value);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public function setConfirmTimeAttr($value): string
|
||||||
|
// {
|
||||||
|
// return $this->setCreateTimeAttr($value);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public function getConfirmTimeAttr($value): string
|
||||||
|
// {
|
||||||
|
// return $this->getCreateTimeAttr($value);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/**
|
|
||||||
* 格式化支付通道
|
|
||||||
* @param mixed $value
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getPaymentAllowsAttr($value): array
|
|
||||||
{
|
|
||||||
$payments = is_string($value) ? str2arr($value) : [];
|
|
||||||
return in_array('all', $payments) ? ['all'] : $payments;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 时间格式处理
|
|
||||||
* @param mixed $value
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getPaymentTimeAttr($value): string
|
|
||||||
{
|
|
||||||
return $this->getCreateTimeAttr($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 时间格式处理
|
|
||||||
* @param mixed $value
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function setPaymentTimeAttr($value): string
|
|
||||||
{
|
|
||||||
return $this->setCreateTimeAttr($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setConfirmTimeAttr($value): string
|
|
||||||
{
|
|
||||||
return $this->setCreateTimeAttr($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getConfirmTimeAttr($value): string
|
|
||||||
{
|
|
||||||
return $this->getCreateTimeAttr($value);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -16,23 +16,11 @@ class PointsMallOrderSender extends Model
|
|||||||
return $this->hasOne(PointsMallOrder::class, 'order_no', 'order_no')->with(['items']);
|
return $this->hasOne(PointsMallOrder::class, 'order_no', 'order_no')->with(['items']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function setExtraAttr($value) {
|
||||||
* 设置发货时间
|
return json_encode($value);
|
||||||
* @param mixed $value
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function setExpressTimeAttr($value): string
|
|
||||||
{
|
|
||||||
return $this->setCreateTimeAttr($value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getExtraAttr($value) {
|
||||||
* 获取发货时间
|
return json_decode($value, true);
|
||||||
* @param mixed $value
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getExpressTimeAttr($value): string
|
|
||||||
{
|
|
||||||
return $this->getCreateTimeAttr($value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,6 +9,7 @@ use plugin\points_mall\model\PointsMallGoodsItem;
|
|||||||
use plugin\points_mall\model\PointsMallOrder;
|
use plugin\points_mall\model\PointsMallOrder;
|
||||||
use plugin\points_mall\model\PointsMallOrderCart;
|
use plugin\points_mall\model\PointsMallOrderCart;
|
||||||
use plugin\points_mall\model\PointsMallOrderItem;
|
use plugin\points_mall\model\PointsMallOrderItem;
|
||||||
|
use think\admin\Model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品数据服务
|
* 商品数据服务
|
||||||
|
@ -167,8 +167,8 @@
|
|||||||
|
|
||||||
{block name='script'}
|
{block name='script'}
|
||||||
<label class="layui-hide">
|
<label class="layui-hide">
|
||||||
<textarea id="GoodsSpecs">{$vo.specs|raw|default=''}</textarea>
|
<textarea id="GoodsSpecs">{$vo.specs|raw|default='[]'}</textarea>
|
||||||
<textarea id="GoodsItems">{$vo.items|raw|default=''}</textarea>
|
<textarea id="GoodsItems">{$vo.items|raw|default='[]'}</textarea>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -204,10 +204,16 @@
|
|||||||
for (let i in v) setValue(k, i, v[i]);
|
for (let i in v) setValue(k, i, v[i]);
|
||||||
});
|
});
|
||||||
// 创建 Vue2 实例
|
// 创建 Vue2 实例
|
||||||
|
let parse = [];
|
||||||
|
try {
|
||||||
|
parse = JSON.parse(JSON.parse($('#GoodsSpecs').val() || '[]'));
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(e)
|
||||||
|
}
|
||||||
let app = new Vue({
|
let app = new Vue({
|
||||||
el: '#GoodsSpecsEditor', data: () => ({
|
el: '#GoodsSpecsEditor', data: () => ({
|
||||||
mode: '{$mode|default="add"}', items: {}, attrs: {},
|
mode: '{$mode|default="add"}', items: {}, attrs: {},
|
||||||
specs: JSON.parse(JSON.parse($('#GoodsSpecs').val() || '[]')) || []
|
specs: parse
|
||||||
}),
|
}),
|
||||||
created: function () {
|
created: function () {
|
||||||
this.specs.length < 1 && addSpecRow(this.specs);
|
this.specs.length < 1 && addSpecRow(this.specs);
|
||||||
|
Reference in New Issue
Block a user