|
@@ -21,9 +21,7 @@ use crmeb\repositories\ShortLetterRepositories;
|
|
|
use crmeb\services\{
|
|
|
MiniProgramService, UtilService, WechatService
|
|
|
};
|
|
|
-use app\models\store\{
|
|
|
- StoreCart, StoreOrder, StoreOrderStatus, StorePink, StoreService
|
|
|
-};
|
|
|
+use app\models\store\{StoreCart, StoreExchangeOrder, StoreOrder, StoreOrderStatus, StorePink, StoreService};
|
|
|
use app\models\system\SystemStoreStaff;
|
|
|
|
|
|
/**
|
|
@@ -318,6 +316,34 @@ class StoreOrderController
|
|
|
return app('json')->successful(StoreOrder::orderList($where));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 订单列表
|
|
|
+ * @param Request $request
|
|
|
+ * @return mixed
|
|
|
+ * @throws DataNotFoundException
|
|
|
+ * @throws DbException
|
|
|
+ * @throws ModelNotFoundException
|
|
|
+ */
|
|
|
+ public function exchange_order_lst(Request $request)
|
|
|
+ {
|
|
|
+ $uid = $request->uid();
|
|
|
+ $where = UtilService::getMore([
|
|
|
+ ['status', ''],
|
|
|
+ ['user_phone', ''],
|
|
|
+ ['is_del', 0],
|
|
|
+ ['data', ''],
|
|
|
+ ['order', ''],
|
|
|
+ ['page', 0],
|
|
|
+ ['limit', 0]
|
|
|
+ ], $request);
|
|
|
+ $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
|
|
|
+ if ($info) {
|
|
|
+ $where['store_id'] = $info['store_id'];
|
|
|
+ }
|
|
|
+ if (!$where['limit']) return app('json')->successful([]);
|
|
|
+ return app('json')->successful(StoreExchangeOrder::orderList($where));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 订单详情
|
|
|
* @param Request $request
|
|
@@ -805,6 +831,55 @@ class StoreOrderController
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 门店核销
|
|
|
+ * @param Request $request
|
|
|
+ * @return
|
|
|
+ * @throws DataNotFoundException
|
|
|
+ * @throws DbException
|
|
|
+ * @throws ModelNotFoundException
|
|
|
+ */
|
|
|
+ public function exchange_order_verific(Request $request)
|
|
|
+ {
|
|
|
+ $uid = $request->uid();
|
|
|
+ list($verify_code, $is_confirm) = UtilService::postMore([
|
|
|
+ ['verify_code', ''],
|
|
|
+ ['is_confirm', 0]
|
|
|
+ ], $request, true);
|
|
|
+ if (!$verify_code) return app('json')->fail('缺少核销码');
|
|
|
+ $orderInfo = StoreExchangeOrder::where('verify_code', $verify_code)->where('store_id', 'in', [SystemStoreStaff::where('uid', $uid)->value('store_id'), 0])->where('refund_status', 0)->find();
|
|
|
+ if (!$orderInfo) return app('json')->fail('核销的兑换券不存在于该门店或未支付或已退款');
|
|
|
+ if ($orderInfo->status > 0) return app('json')->fail('兑换券已经核销');
|
|
|
+ if (!$is_confirm) {
|
|
|
+ $orderInfo['image'] = StoreCart::getProductImage($orderInfo->cart_id);
|
|
|
+ return app('json')->success($orderInfo->toArray());
|
|
|
+ }
|
|
|
+ StoreExchangeOrder::beginTrans();
|
|
|
+ try {
|
|
|
+ if (SystemStoreStaff::verifyStatus($uid) && ($storeStaff = SystemStoreStaff::where('uid', $uid)->field(['store_id', 'id'])->find())) {
|
|
|
+ $orderInfo->clerk_id = $storeStaff['id'];
|
|
|
+ }
|
|
|
+ $orderInfo->status = 1;
|
|
|
+ if ($orderInfo->store_id == 0) {
|
|
|
+ $orderInfo->store_id = SystemStoreStaff::where('uid', $uid)->value('store_id');
|
|
|
+ SystemStore::decStock($orderInfo);
|
|
|
+ }
|
|
|
+ if ($orderInfo->save()) {
|
|
|
+ StoreExchangeOrder::commitTrans();
|
|
|
+ return app('json')->success('核销成功');
|
|
|
+ } else {
|
|
|
+ StoreExchangeOrder::rollbackTrans();
|
|
|
+ return app('json')->fail('核销失败');
|
|
|
+ }
|
|
|
+ } catch (\PDOException $e) {
|
|
|
+ StoreExchangeOrder::rollbackTrans();
|
|
|
+ return app('json')->fail($e->getMessage());
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ StoreExchangeOrder::rollbackTrans();
|
|
|
+ return app('json')->fail($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public function rechargeList(Request $request)
|
|
|
{
|
|
|
$uid = $request->uid();
|
|
@@ -882,4 +957,66 @@ class StoreOrderController
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public function exchange_order_back_deposit(Request $request)
|
|
|
+ {
|
|
|
+ $uid = $request->uid();
|
|
|
+ $data = UtilService::postMore([
|
|
|
+ ['id', ''],
|
|
|
+ ['refund_price', 0],
|
|
|
+ ['type', 1],
|
|
|
+ ]);
|
|
|
+ if (!$data['id']) return app('json')->fail('数据不存在');
|
|
|
+ $orderInfo = StoreExchangeOrder::where('id', $data['id'])->where('store_id', SystemStoreStaff::where('uid', $uid)->value('store_id'))->where('refund_status', 0)->find();
|
|
|
+ if (!$orderInfo) return app('json')->fail('订单不存在于该门店或未支付或已退款');
|
|
|
+ if ($orderInfo['deposit'] == $orderInfo['deposit_back']) return app('json')->fail('已退完押金!不能再退款了');
|
|
|
+ if (!$data['refund_price']) return app('json')->fail('请输入退款金额');
|
|
|
+ $refund_price = $data['refund_price'];
|
|
|
+ $data['deposit_back'] = bcadd($data['refund_price'], $orderInfo['deposit_back'], 2);
|
|
|
+ $bj = bccomp((float)$orderInfo['deposit'], (float)$data['deposit_back'], 2);
|
|
|
+ if ($bj < 0) return app('json')->fail('退押金额大于支付押金,请修改退押金额');
|
|
|
+ if ($data['type'] == 1) {
|
|
|
+ $data['deposit_status'] = 1;
|
|
|
+ } else if ($data['type'] == 2) {
|
|
|
+ $data['deposit_status'] = 0;
|
|
|
+ }
|
|
|
+// $type = $data['type'];
|
|
|
+ unset($data['type']);
|
|
|
+ unset($data['refund_price']);
|
|
|
+ $refund_data['pay_price'] = bcadd($orderInfo['pay_price'], $orderInfo['deposit'], 2);
|
|
|
+ $refund_data['refund_price'] = $refund_price;
|
|
|
+ $refund_data['refund_id'] = 'refund_deposit' . $orderInfo['order_id'] . time();
|
|
|
+
|
|
|
+ if ($orderInfo['pay_type'] == 'weixin') {
|
|
|
+ if ($orderInfo['is_channel'] == 1) {//小程序
|
|
|
+ try {
|
|
|
+ MiniProgramService::payOrderRefund($orderInfo['order_id'], $refund_data);//2.5.36
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return app('json')->fail($e->getMessage());
|
|
|
+ }
|
|
|
+ } else {//TODO 公众号
|
|
|
+ try {
|
|
|
+ WechatService::payOrderRefund($orderInfo['order_id'], $refund_data);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return app('json')->fail($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if ($orderInfo['pay_type'] == 'yue') {
|
|
|
+ BaseModel::beginTrans();
|
|
|
+ $usermoney = User::where('uid', $orderInfo['uid'])->value('now_money');
|
|
|
+ $res1 = User::bcInc($orderInfo['uid'], 'now_money', $refund_price, 'uid');
|
|
|
+ $res2 = UserBill::income('商品退押金', $orderInfo['uid'], 'now_money', 'pay_deposit_refund', $refund_price, $orderInfo['id'], bcadd($usermoney, $refund_price, 2), '订单退押金到余额' . floatval($refund_price) . '元');
|
|
|
+ $res = $res1 && $res2;
|
|
|
+ BaseModel::checkTrans($res);
|
|
|
+ if (!$res) return app('json')->fail('余额退押金失败!');
|
|
|
+ }
|
|
|
+ $resEdit = StoreExchangeOrder::edit($data, $orderInfo['id']);
|
|
|
+ if ($resEdit) {
|
|
|
+ \app\admin\model\order\StoreOrderStatus::setStatus($orderInfo['oid'], 'refund_deposit', '退押金给用户' . $refund_price . '元');
|
|
|
+ return app('json')->success('成功!');
|
|
|
+ } else {
|
|
|
+ \app\admin\model\order\StoreOrderStatus::setStatus($orderInfo['oid'], 'refund_deposit', '退押金给用户' . $refund_price . '元失败');
|
|
|
+ return app('json')->fail('失败!');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|