|
|
@@ -23,7 +23,8 @@ use crmeb\services\{ExpressService,
|
|
|
WechatService,
|
|
|
FormBuilder as Form,
|
|
|
CacheService,
|
|
|
- UtilService as Util};
|
|
|
+ UtilService as Util
|
|
|
+};
|
|
|
use app\admin\model\order\StoreOrderStatus;
|
|
|
use app\admin\model\ump\StorePink;
|
|
|
use think\Exception;
|
|
|
@@ -97,7 +98,7 @@ class StoreOrder extends AuthController
|
|
|
['page', 1],
|
|
|
['limit', 20],
|
|
|
['excel', 0],
|
|
|
- ['store_id',$this->adminInfo['store_id']],
|
|
|
+ ['store_id', $this->adminInfo['store_id']],
|
|
|
]);
|
|
|
|
|
|
return Json::successlayui(StoreOrderModel::OrderList($where));
|
|
|
@@ -113,8 +114,8 @@ class StoreOrder extends AuthController
|
|
|
return JsonService::fail('订单没有查到,无法打印!');
|
|
|
}
|
|
|
try {
|
|
|
- $order['cart_id'] = is_array($order['cart_id']) ? $order['cart_id']: json_decode($order['cart_id'], true) ;
|
|
|
- $cartInfo = StoreOrderCartInfo::whereIn('cart_id', join(",",$order['cart_id'] ))->field('cart_info')->select();
|
|
|
+ $order['cart_id'] = is_array($order['cart_id']) ? $order['cart_id'] : json_decode($order['cart_id'], true);
|
|
|
+ $cartInfo = StoreOrderCartInfo::whereIn('cart_id', join(",", $order['cart_id']))->field('cart_info')->select();
|
|
|
$cartInfo = count($cartInfo) ? $cartInfo->toArray() : [];
|
|
|
$product = [];
|
|
|
foreach ($cartInfo as $item) {
|
|
|
@@ -123,7 +124,7 @@ class StoreOrder extends AuthController
|
|
|
$value['productInfo']['store_name'] = StoreOrderCartInfo::getSubstrUTf8($value['productInfo']['store_name'], 10, 'UTF-8', '');
|
|
|
$product[] = $value;
|
|
|
}
|
|
|
- if(!$product){
|
|
|
+ if (!$product) {
|
|
|
return JsonService::fail('订单商品获取失败,无法打印!');
|
|
|
}
|
|
|
$res = YLYService::instance()->selectStore($order['store_id'])->setContent(sys_config('site_name'), is_object($order) ? $order->toArray() : $order, $product)->orderPrinting();
|
|
|
@@ -134,9 +135,10 @@ class StoreOrder extends AuthController
|
|
|
}
|
|
|
} catch (\Exception $e) {
|
|
|
Log::error('小票打印出现错误,错误原因:' . $e->getMessage());
|
|
|
- return JsonService::fail($e->getFile().'--'.$e->getLine().'--'.$e->getMessage());
|
|
|
+ return JsonService::fail($e->getFile() . '--' . $e->getLine() . '--' . $e->getMessage());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
public function info($id)
|
|
|
{
|
|
|
if (!$id) {
|
|
|
@@ -147,36 +149,39 @@ class StoreOrder extends AuthController
|
|
|
return JsonService::fail('订单没有查到,无法打印!');
|
|
|
}
|
|
|
$info = $order->toArray();
|
|
|
- $order['cart_id'] = is_array($order['cart_id']) ? $order['cart_id']: json_decode($order['cart_id'], true) ;
|
|
|
- $cartInfo = StoreOrderCartInfo::whereIn('cart_id', join(",",$order['cart_id'] ))->field('cart_info')->select()->toArray();
|
|
|
+ $order['cart_id'] = is_array($order['cart_id']) ? $order['cart_id'] : json_decode($order['cart_id'], true);
|
|
|
+ $cartInfo = StoreOrderCartInfo::whereIn('cart_id', join(",", $order['cart_id']))->field('cart_info')->select()->toArray();
|
|
|
|
|
|
- return Json::successful(compact('info','cartInfo'));
|
|
|
+ return Json::successful(compact('info', 'cartInfo'));
|
|
|
}
|
|
|
- public function out_goods($id)
|
|
|
+
|
|
|
+ public function out_goods($id)
|
|
|
{
|
|
|
- $this->assign('id',$id);
|
|
|
+ $this->assign('id', $id);
|
|
|
return $this->fetch();
|
|
|
}
|
|
|
+
|
|
|
public function cart_refund()
|
|
|
{
|
|
|
$order = UtilService::getMore([
|
|
|
- ['order_id',0],
|
|
|
- ['cart_id',0],
|
|
|
- ['product_id',0],
|
|
|
- ['refund_num',0],
|
|
|
- ['cart_num',0],
|
|
|
- ['refund_price',0],
|
|
|
+ ['order_id', 0],
|
|
|
+ ['cart_id', 0],
|
|
|
+ ['product_id', 0],
|
|
|
+ ['refund_num', 0],
|
|
|
+ ['cart_num', 0],
|
|
|
+ ['refund_price', 0],
|
|
|
]);
|
|
|
- if($order['order_id']==0) return JsonService::fail('订单不能为空');
|
|
|
- if($order['cart_id']==0) return JsonService::fail('订单购物车不能为空');
|
|
|
- if($order['product_id']==0) return JsonService::fail('商品编号不能为空');
|
|
|
- if($order['refund_num']==0) return JsonService::fail('退货数量');
|
|
|
- if($order['refund_price']==0) return JsonService::fail('商品价格');
|
|
|
+ if ($order['order_id'] == 0) return JsonService::fail('订单不能为空');
|
|
|
+ if ($order['cart_id'] == 0) return JsonService::fail('订单购物车不能为空');
|
|
|
+ if ($order['product_id'] == 0) return JsonService::fail('商品编号不能为空');
|
|
|
+ if ($order['refund_num'] == 0) return JsonService::fail('退货数量');
|
|
|
+ if ($order['refund_price'] == 0) return JsonService::fail('商品价格');
|
|
|
$order['admin_id'] = $this->adminId;
|
|
|
$order['refund_time'] = time();
|
|
|
StoreOrderRefund::refund($order);
|
|
|
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 核销码核销
|
|
|
* @param string $verify_code
|
|
|
@@ -464,7 +469,7 @@ class StoreOrder extends AuthController
|
|
|
if (!(int)$data['delivery_id']) return Json::fail('请输入送货人电话号码');
|
|
|
else if (!preg_match("/^1[3456789]{1}\d{9}$/", $data['delivery_id'])) return Json::fail('请输入正确的送货人电话号码');
|
|
|
$data['status'] = 1;
|
|
|
- StoreOrderModel::where('id',$id)->update($data);
|
|
|
+ StoreOrderModel::where('id', $id)->update($data);
|
|
|
event('StoreProductOrderDeliveryAfter', [$data, $id]);
|
|
|
StoreOrderStatus::setStatus($id, 'delivery', '已配送 发货人:' . $data['delivery_name'] . ' 发货人电话:' . $data['delivery_id']);
|
|
|
return Json::successful('修改成功!');
|
|
|
@@ -512,7 +517,7 @@ class StoreOrder extends AuthController
|
|
|
if (!$data['delivery_name']) return Json::fail('请选择快递公司');
|
|
|
if (!$data['delivery_id']) return Json::fail('请输入快递单号');
|
|
|
$data['status'] = 1;
|
|
|
- StoreOrderModel::where('id',$id)->update($data);
|
|
|
+ StoreOrderModel::where('id', $id)->update($data);
|
|
|
event('StoreProductOrderDeliveryGoodsAfter', [$data, $id]);
|
|
|
StoreOrderStatus::setStatus($id, 'delivery_goods', '已发货 快递公司:' . $data['delivery_name'] . ' 快递单号:' . $data['delivery_id']);
|
|
|
return Json::successful('修改成功!');
|
|
|
@@ -644,14 +649,11 @@ class StoreOrder extends AuthController
|
|
|
if (!$res) return Json::fail('余额退款失败!');
|
|
|
} elseif ($product['pay_type'] == 'jialie') {
|
|
|
try {
|
|
|
- $rs = JiaLieService::initialize()->payOrderRefund(!empty($product['re_order_id'])?$product['re_order_id']:$product['order_id'], $refund_data);//2.5.36
|
|
|
- if($rs['ret_code']=='00' && $rs['status']=='2')
|
|
|
- {
|
|
|
+ $rs = JiaLieService::initialize()->payOrderRefund(!empty($product['re_order_id']) ? $product['re_order_id'] : $product['order_id'], $refund_data);//2.5.36
|
|
|
+ if ($rs['ret_code'] == '00' && $rs['status'] == '2') {
|
|
|
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (!$res) return Json::fail('嘉联退款失败!');
|
|
|
+ } else {
|
|
|
+ if (!$rs) return Json::fail('嘉联退款失败!');
|
|
|
}
|
|
|
} catch (\Exception $e) {
|
|
|
return Json::fail($e->getMessage());
|
|
|
@@ -661,60 +663,60 @@ class StoreOrder extends AuthController
|
|
|
$res = true;
|
|
|
BaseModel::beginTrans();
|
|
|
|
|
|
- if ($resEdit) {
|
|
|
- $data['type'] = $type;
|
|
|
- if ($data['type'] == 1) $res = StorePink::setRefundPink($id);
|
|
|
- if (!$res) return Json::fail('修改失败');
|
|
|
- try {
|
|
|
- OrderRepository::storeProductOrderRefundY($data, $id);
|
|
|
- } catch (\Exception $e) {
|
|
|
- BaseModel::rollbackTrans();
|
|
|
- return Json::fail($e->getFile().'--'.$e->getLine().'--'.$e->getMessage());
|
|
|
- }
|
|
|
- StoreOrderStatus::setStatus($id, 'refund_price', '退款给用户' . $refund_price . '元');
|
|
|
+ if ($resEdit) {
|
|
|
+ $data['type'] = $type;
|
|
|
+ if ($data['type'] == 1) $res = StorePink::setRefundPink($id);
|
|
|
+ if (!$res) return Json::fail('修改失败');
|
|
|
+ try {
|
|
|
+ OrderRepository::storeProductOrderRefundY($data, $id);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ BaseModel::rollbackTrans();
|
|
|
+ return Json::fail($e->getFile() . '--' . $e->getLine() . '--' . $e->getMessage());
|
|
|
+ }
|
|
|
+ StoreOrderStatus::setStatus($id, 'refund_price', '退款给用户' . $refund_price . '元');
|
|
|
|
|
|
- //退佣金
|
|
|
- $brokerage_list = UserBill::where('category', 'now_money')
|
|
|
- ->where('type', 'brokerage')
|
|
|
- ->where('link_id', $id)
|
|
|
- ->where('pm', 1)
|
|
|
- ->select();
|
|
|
+ //退佣金
|
|
|
+ $brokerage_list = UserBill::where('category', 'now_money')
|
|
|
+ ->where('type', 'brokerage')
|
|
|
+ ->where('link_id', $id)
|
|
|
+ ->where('pm', 1)
|
|
|
+ ->select();
|
|
|
|
|
|
- if ($brokerage_list) {
|
|
|
- $brokerage_list = $brokerage_list->toArray();
|
|
|
- foreach ($brokerage_list as $item) {
|
|
|
- $usermoney = User::where('uid', $item['uid'])->value('brokerage_price');
|
|
|
- if ($item['number'] > $usermoney)
|
|
|
- $item['number'] = $usermoney;
|
|
|
- User::bcDec($item['uid'], 'brokerage_price', $item['number'], 'uid');
|
|
|
- UserBill::expend('退款退佣金', $item['uid'], 'now_money', 'brokerage', $item['number'], $id, bcsub($usermoney, $item['number'], 2), '订单退款扣除佣金' . floatval($item['number']) . '元');
|
|
|
- }
|
|
|
+ if ($brokerage_list) {
|
|
|
+ $brokerage_list = $brokerage_list->toArray();
|
|
|
+ foreach ($brokerage_list as $item) {
|
|
|
+ $usermoney = User::where('uid', $item['uid'])->value('brokerage_price');
|
|
|
+ if ($item['number'] > $usermoney)
|
|
|
+ $item['number'] = $usermoney;
|
|
|
+ User::bcDec($item['uid'], 'brokerage_price', $item['number'], 'uid');
|
|
|
+ UserBill::expend('退款退佣金', $item['uid'], 'now_money', 'brokerage', $item['number'], $id, bcsub($usermoney, $item['number'], 2), '订单退款扣除佣金' . floatval($item['number']) . '元');
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- //退款扣除用户积分
|
|
|
- //购买赠送的积分
|
|
|
- $bill_integral = UserBill::where('category', 'integral')
|
|
|
- ->where('type', 'gain')
|
|
|
- ->where('link_id', $id)
|
|
|
- ->where('pm', 1)
|
|
|
- ->find();
|
|
|
- if ($bill_integral) {
|
|
|
- $bill_integral = $bill_integral->toArray();
|
|
|
- //用户积分
|
|
|
- $user_integral = User::where('uid', $bill_integral['uid'])->value('integral');
|
|
|
- if ($bill_integral['number'] > $user_integral)
|
|
|
- $bill_integral['number'] = $user_integral;
|
|
|
- User::bcDec($bill_integral['uid'], 'integral', $bill_integral['number'], 'uid');
|
|
|
- UserBill::expend('退款扣除积分', $bill_integral['uid'], 'integral', 'gain', $bill_integral['number'], $id, bcsub($user_integral, $bill_integral['number'], 2), '订单退款扣除积分' . floatval($bill_integral['number']) . '积分');
|
|
|
- }
|
|
|
- //回退库存
|
|
|
- StoreOrderModels::RegressionStock($product);
|
|
|
- BaseModel::commitTrans();
|
|
|
- return Json::successful('修改成功!');
|
|
|
- } else {
|
|
|
- StoreOrderStatus::setStatus($id, 'refund_price', '退款给用户' . $refund_price . '元失败');
|
|
|
- return Json::fail('修改失败!');
|
|
|
+ //退款扣除用户积分
|
|
|
+ //购买赠送的积分
|
|
|
+ $bill_integral = UserBill::where('category', 'integral')
|
|
|
+ ->where('type', 'gain')
|
|
|
+ ->where('link_id', $id)
|
|
|
+ ->where('pm', 1)
|
|
|
+ ->find();
|
|
|
+ if ($bill_integral) {
|
|
|
+ $bill_integral = $bill_integral->toArray();
|
|
|
+ //用户积分
|
|
|
+ $user_integral = User::where('uid', $bill_integral['uid'])->value('integral');
|
|
|
+ if ($bill_integral['number'] > $user_integral)
|
|
|
+ $bill_integral['number'] = $user_integral;
|
|
|
+ User::bcDec($bill_integral['uid'], 'integral', $bill_integral['number'], 'uid');
|
|
|
+ UserBill::expend('退款扣除积分', $bill_integral['uid'], 'integral', 'gain', $bill_integral['number'], $id, bcsub($user_integral, $bill_integral['number'], 2), '订单退款扣除积分' . floatval($bill_integral['number']) . '积分');
|
|
|
}
|
|
|
+ //回退库存
|
|
|
+ StoreOrderModels::RegressionStock($product);
|
|
|
+ BaseModel::commitTrans();
|
|
|
+ return Json::successful('修改成功!');
|
|
|
+ } else {
|
|
|
+ StoreOrderStatus::setStatus($id, 'refund_price', '退款给用户' . $refund_price . '元失败');
|
|
|
+ return Json::fail('修改失败!');
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -809,7 +811,7 @@ class StoreOrder extends AuthController
|
|
|
if (!$data['delivery_name']) return Json::fail('请选择快递公司');
|
|
|
if (!$data['delivery_id']) return Json::fail('请输入快递单号');
|
|
|
}
|
|
|
- StoreOrderModel::where('id',$id)->update($data);
|
|
|
+ StoreOrderModel::where('id', $id)->update($data);
|
|
|
event('StoreProductOrderDistributionAfter', [$data, $id]);
|
|
|
StoreOrderStatus::setStatus($id, 'distribution', '修改发货信息为' . $data['delivery_name'] . '号' . $data['delivery_id']);
|
|
|
return Json::successful('修改成功!');
|
|
|
@@ -846,7 +848,7 @@ class StoreOrder extends AuthController
|
|
|
if (!$product) return Json::fail('数据不存在!');
|
|
|
if (!$data['refund_reason']) return Json::fail('请输入退款原因');
|
|
|
$data['refund_status'] = 0;
|
|
|
- StoreOrderModel::where('id',$id)->update($data);
|
|
|
+ StoreOrderModel::where('id', $id)->update($data);
|
|
|
event('StoreProductOrderRefundNAfter', [$data['refund_reason'], $id]);
|
|
|
StoreOrderStatus::setStatus($id, 'refund_n', '不退款原因:' . $data['refund_reason']);
|
|
|
return Json::successful('修改成功!');
|
|
|
@@ -927,7 +929,7 @@ class StoreOrder extends AuthController
|
|
|
if ($product['pay_price'] == 0 && $bj == 0) {
|
|
|
$data['refund_status'] = 2;
|
|
|
}
|
|
|
- StoreOrderModel::where('id',$id)->update($data);
|
|
|
+ StoreOrderModel::where('id', $id)->update($data);
|
|
|
StoreOrderStatus::setStatus($id, 'integral_back', '商品退积分:' . $data['back_integral']);
|
|
|
return Json::successful('退积分成功!');
|
|
|
}
|
|
|
@@ -939,7 +941,7 @@ class StoreOrder extends AuthController
|
|
|
if ($data['remark'] == '') return Json::fail('请输入要备注的内容!');
|
|
|
$id = $data['id'];
|
|
|
unset($data['id']);
|
|
|
- StoreOrderModel::where('id',$id)->update($data);
|
|
|
+ StoreOrderModel::where('id', $id)->update($data);
|
|
|
return Json::successful('备注成功!');
|
|
|
}
|
|
|
|
|
|
@@ -988,45 +990,41 @@ class StoreOrder extends AuthController
|
|
|
return Json::fail('核销失败');
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
public function re_pay($id)
|
|
|
{
|
|
|
if (!$id) return $this->failed('数据不存在');
|
|
|
- $product = StoreOrderModel::where('id',$id)->find();
|
|
|
+ $product = StoreOrderModel::where('id', $id)->find();
|
|
|
|
|
|
if (!$product) return Json::fail('数据不存在!');
|
|
|
$f = [];
|
|
|
$f[] = Form::input('order_id', '订单编号', $product->getData('order_id'))->disabled(1);
|
|
|
$f[] = Form::number('total_price', '商品总价', $product->getData('total_price'))->min(0);
|
|
|
|
|
|
- $f[] = Form::input('auth_code', '支付码','');
|
|
|
+ $f[] = Form::input('auth_code', '支付码', '');
|
|
|
$form = Form::make_post_form('修改订单', $f, Url::buildUrl('paysave', array('id' => $id)));
|
|
|
$this->assign(compact('form'));
|
|
|
return $this->fetch('public/form-builder');
|
|
|
}
|
|
|
- public function paysave($id)
|
|
|
+
|
|
|
+ public function paysave($id)
|
|
|
{
|
|
|
$orderInfo = StoreOrderModel::where('id', $id)->find();
|
|
|
$orderInfo = $orderInfo->toArray();
|
|
|
if ($orderInfo['paid']) return app('json')->fail('支付已支付!');
|
|
|
- $order_id = mt_rand(100,999).'-'.$orderInfo['order_id'];
|
|
|
- StoreOrderModel::where('id', $id)->update(['re_order_id'=>$order_id]);
|
|
|
- $rs = OrderRepository::jialiePay($order_id,input('auth_code')); //支付结果
|
|
|
- if($rs['ret_code']=="00" && $rs['status']=="2")
|
|
|
- {
|
|
|
+ $order_id = mt_rand(100, 999) . '-' . $orderInfo['order_id'];
|
|
|
+ StoreOrderModel::where('id', $id)->update(['re_order_id' => $order_id]);
|
|
|
+ $rs = OrderRepository::jialiePay($order_id, input('auth_code')); //支付结果
|
|
|
+ if ($rs['ret_code'] == "00" && $rs['status'] == "2") {
|
|
|
$this->verify($orderInfo['id']);
|
|
|
- StoreOrderModel1::paySuccess($orderInfo['order_id'],'jialie');
|
|
|
- }
|
|
|
- elseif($rs['ret_code']=="00" && $rs['status']=="1")
|
|
|
- {
|
|
|
- StoreOrderModel1::edit(['jialie_do'=>1],$orderInfo['id']);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ StoreOrderModel1::paySuccess($orderInfo['order_id'], 'jialie');
|
|
|
+ } elseif ($rs['ret_code'] == "00" && $rs['status'] == "1") {
|
|
|
+ StoreOrderModel1::edit(['jialie_do' => 1], $orderInfo['id']);
|
|
|
+ } else {
|
|
|
return app('json')->fail($rs['ret_msg']);
|
|
|
}
|
|
|
return app('json')->status('success', '订单支付成功', $rs);
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
}
|