uid(); $where = UtilService::getMore([ ['page', 1], ['limit', 20], ['type', 1] ]); $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find(); if (!$info) { return app('json')->fail('权限不足'); } // var_dump($info->toArray()); $where['store_id'] = $info['store_id']; $where['excel'] = 0; // $where['type'] = $info['store_id']; return app('json')->successful('ok', SystemStorePoint::getStoreList($where)); } public function senderList(Request $request) { $uid = $request->uid(); $where = UtilService::getMore([ ['page', 1], ['limit', 20], ]); $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find(); if (!$info) { return app('json')->fail('权限不足'); } // var_dump($info->toArray()); $where['store_id'] = $info['store_id']; $where['excel'] = 0; // $where['type'] = $info['store_id']; return app('json')->successful('ok', SystemStoreSender::getStoreList($where)); } public function pointDetail($id, Request $request) { $uid = $request->uid(); $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find(); if (!$info) { return app('json')->fail('权限不足'); } return app('json')->successful('ok', ['data' => SystemStorePoint::getStoreDispose($id)]); } public function sendCard(Request $request) { $uid = $request->uid(); $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find(); if (!$info) { return app('json')->fail('权限不足'); } $code = UtilService::postMore(['code']); $res = Card::sendCard($info['store_id'], $code['code']); if ($res) return app('json')->successful('赠送成功'); else return app('json')->fail(Card::getErrorInfo('赠送失败')); } public function sendCardList(Request $request) { $uid = $request->uid(); $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find(); if (!$info) { return app('json')->fail('权限不足'); } $where = UtilService::getMore([['page', 1], ['limit', 10], ['status', '']]); $where['store_id'] = $info['store_id']; $list = Card::systemPage($where); unset($where['page']); unset($where['limit']); $count = Card::where($where)->count(); return app('json')->success('ok', compact('list', 'count')); } public function checkCard(Request $request) { $uid = $request->uid(); $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find(); if (!$info) { return app('json')->fail('权限不足'); } $code = UtilService::postMore(['code', 'password']); $res = Card::checkCard($info['store_id'], $code['code'], $code['password']); if ($res) return app('json')->successful('核销成功'); else return app('json')->fail(Card::getErrorInfo('核销失败')); } public function addDetail(Request $request, $id = 0) { $uid = $request->uid(); $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find(); if (!$info) { return app('json')->fail('权限不足'); } $data = UtilService::postMore([ ['name', ''], ['phone', ''], ['address', ''], ['detailed_address', ''], ['latlng', ''], ['valid_time', []], ['day_time', []], ['is_show', 0], ]); $data['store_id'] = $info['store_id']; $data['address'] = implode(',', $data['address']); $data['latlng'] = is_string($data['latlng']) ? explode(',', $data['latlng']) : $data['latlng']; if (!isset($data['latlng'][0]) || !isset($data['latlng'][1])) return app('json')->fail('请选择门店位置'); $data['latitude'] = $data['latlng'][0]; $data['longitude'] = $data['latlng'][1]; $data['valid_time'] = implode(' - ', $data['valid_time']); $data['day_time'] = implode(' - ', $data['day_time']); unset($data['latlng']); if ($id) { $store_info = SystemStorePoint::get($id); if ($store_info['store_id'] != $info['store_id']) { return app('json')->fail('权限不足'); } if (SystemStorePoint::where('id', $id)->update($data)) { SystemStorePoint::commitTrans(); return app('json')->successful('修改成功'); } else { SystemStorePoint::rollbackTrans(); return app('json')->fail('修改失败或者您没有修改什么!'); } } else { $data['add_time'] = time(); $data['is_show'] = 1; if ($res = SystemStorePoint::create($data)) { SystemStorePoint::commitTrans(); return app('json')->successful('保存成功', ['id' => $res->id]); } else { SystemStorePoint::rollbackTrans(); return app('json')->fail('保存失败!'); } } } /** * 删除恢复门店 * @param $id */ public function point_delete($id, Request $request) { if (!$id) return app('json')->fail('数据不存在'); if (!SystemStorePoint::be(['id' => $id])) return app('json')->fail('数据不存在'); $uid = $request->uid(); $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find(); if (!$info) { return app('json')->fail('权限不足'); } $store_info = SystemStorePoint::get($id); if ($store_info['store_id'] != $info['store_id']) { return app('json')->fail('权限不足'); } if (SystemStorePoint::be(['id' => $id, 'is_del' => 1])) { $data['is_del'] = 0; if (!SystemStorePoint::edit($data, $id)) return app('json')->fail(SystemStorePoint::getErrorInfo('恢复失败,请稍候再试!')); else return app('json')->success('恢复门店成功!'); } else { $data['is_del'] = 1; if (!SystemStorePoint::edit($data, $id)) return app('json')->fail(SystemStorePoint::getErrorInfo('删除失败,请稍候再试!')); else return app('json')->success('删除门店成功!'); } } public function stockList(Request $request) { $uid = $request->uid(); $where = UtilService::getMore([ ['type', ''], ['page', 1], ['limit', 20], ['start_time', ''], ['end_time', ''], ]); $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find(); if (!$info) { return app('json')->fail('权限不足'); } return app('json')->successful('ok', ['warning' => SystemStoreProductStock::getWarning($info['store_id']), 'data' => SystemStoreProductStock::getStockList($where, $info['store_id'])]); } public function billList(Request $request) { $uid = $request->uid(); $where = UtilService::getMore([ ['page', 1], ['limit', 20], ['type', ''], ['time', ''], ]); $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find(); if (!$info) { return app('json')->fail('权限不足'); } return app('json')->successful('ok', ['switch' => sys_config('withdraw_switch', 0), 'all' => SystemStore::get($info['store_id'])['brokerage_price'], 'data' => SystemStoreBill::getList($where, $info['store_id'])]); } public function cash(Request $request) { $uid = $request->uid(); $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find(); if (!$info) { return app('json')->fail('权限不足'); } if (!in_array(sys_config('default_store_admin', 7), explode(',', $request->admin_info()['roles']))) { return app('json')->fail('权限不足'); } $store = SystemStore::get($info['store_id']); $extractInfo = UtilService::postMore([ ['money', 0], ['bankname', ''], ['name', ''], ['cardnum', ''], ], $request); $extractInfo['extract_type'] = 'bank'; $extractInfo['name'] = $extractInfo['name'] ?? $store['leader']; if (!preg_match('/^(([1-9]\d*)|0)(\.\d{1-2})?$/', $extractInfo['money'])) app('json')->fail('提现金额输入有误'); $store = SystemStore::get($info['store_id']); if ($extractInfo['money'] > $store['brokerage_price']) return app('json')->fail('可提现佣金不足'); if (!$extractInfo['cardnum'] == '') if (!preg_match('/^([1-9]{1})(\d{14}|\d{18})$/', $extractInfo['cardnum'])) return app('json')->fail('银行卡号有误'); if (SystemStoreExtract::userExtract($store, $extractInfo)) return app('json')->successful('申请提现成功!'); else return app('json')->fail(SystemStoreExtract::getErrorInfo('提现失败')); } public function childrenList(Request $request) { $uid = $request->uid(); $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find(); if (!$info) { return app('json')->fail('权限不足'); } $where = UtilService::getMore([ ['page', 1], ['limit', 20], ['name', ''], ['level', ''], ['excel', 0], ['type', ''], ['parent_id', 0], ]); $where['self_store'] = $info['store_id']; return app('json')->successful('ok', \app\admin\model\system\SystemStore::getStoreList($where)); } /** * 订单数据统计 * @param Request $request * @return mixed * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ public function statistics(Request $request) { $uid = $request->uid(); // if (!StoreService::orderServiceStatus($uid)) // return app('json')->fail('权限不足'); $where = []; $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find(); if ($info) { $where['store_id'] = $info['store_id']; } $dataCount = StoreOrder::getOrderDataAdmin($where); $dataPrice = StoreOrder::getOrderTimeData($where); $data = array_merge($dataCount, $dataPrice); return app('json')->successful($data); } /** * 订单每月统计数据 * @param Request $request * @return mixed * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ public function data(Request $request) { $uid = $request->uid(); // if (!StoreService::orderServiceStatus($uid)) // return app('json')->fail('权限不足'); list($page, $limit, $start, $stop) = UtilService::getMore([ ['page', 1], ['limit', 7], ['start', ''], ['stop', ''] ], $request, true); $where = []; $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find(); if ($info) { $where['store_id'] = $info['store_id']; } if (!$limit) return app('json')->successful([]); $data = StoreOrder::getOrderDataPriceCount($page, $limit, $start, $stop, $where); if ($data) return app('json')->successful($data->toArray()); return app('json')->successful([]); } /** * 订单列表 * @param Request $request * @return mixed * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ public function lst(Request $request) { $uid = $request->uid(); // if (!StoreService::orderServiceStatus($uid)) // return app('json')->fail('权限不足'); $where = UtilService::getMore([ ['status', ''], ['user_phone', ''], ['is_del', 0], ['data', ''], ['type', ''], ['shipping_type', ''], ['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(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 * @param $orderId * @return mixed * @throws DataNotFoundException * @throws ModelNotFoundException * @throws DbException */ public function detail(Request $request, $orderId) { $uid = $request->uid(); // if (!StoreService::orderServiceStatus($uid)) // return app('json')->fail('权限不足'); $where = []; $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find(); if ($info) { $where['store_id'] = $info['store_id']; } $order = StoreOrder::getAdminOrderDetail($orderId, 'id,uid,order_id,add_time,status,total_num,total_price,total_postage,pay_price,pay_postage,paid,refund_status,remark,pink_id,combination_id,mark,seckill_id,bargain_id,delivery_type,pay_type,real_name,user_phone,user_address,coupon_price,freight_price,delivery_name,delivery_type,delivery_id,store_id,point_id', $where); if (!$order) return app('json')->fail('订单不存在'); $order = $order->toArray(); $nickname = User::getUserInfo($order['uid'], 'nickname')['nickname']; $orderInfo = StoreOrder::tidyAdminOrder([$order], true)[0]; unset($orderInfo['uid'], $orderInfo['seckill_id'], $orderInfo['pink_id'], $orderInfo['combination_id'], $orderInfo['bargain_id'], $orderInfo['status'], $orderInfo['total_postage']); $orderInfo['nickname'] = $nickname; return app('json')->successful('ok', $orderInfo); } /** * 订单发货获取订单信息 * @param Request $request * @param $orderId * @return mixed * @throws DataNotFoundException * @throws ModelNotFoundException * @throws DbException */ public function delivery_gain(Request $request, $orderId) { $uid = $request->uid(); // if (!StoreService::orderServiceStatus($uid)) // return app('json')->fail('权限不足'); $where = []; $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find(); if ($info) { $where['store_id'] = $info['store_id']; } $order = StoreOrder::getAdminOrderDetail($orderId, 'real_name,user_phone,user_address,order_id,uid,status,paid', $where); if (!$order) return app('json')->fail('订单不存在'); if ($order['paid']) { $order['nickname'] = User::getUserInfo($order['uid'], 'nickname')['nickname']; $order = $order->hidden(['uid', 'status', 'paid'])->toArray(); return app('json')->successful('ok', $order); } return app('json')->fail('状态错误'); } /** * 订单发货 * @param Request $request * @return mixed * @throws DataNotFoundException * @throws ModelNotFoundException * @throws \think\exception\DbException * @throws DbException */ public function delivery_keep(Request $request) { $uid = $request->uid(); // if (!StoreService::orderServiceStatus($uid)) // return app('json')->fail('权限不足'); list($order_id, $delivery_type, $delivery_name, $delivery_id) = UtilService::postMore([ ['order_id', ''], ['delivery_type', 0], ['delivery_name', ''], ['delivery_id', ''], ], $request, true); $where = []; $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find(); if ($info) { $where['store_id'] = $info['store_id']; } $order = StoreOrder::getAdminOrderDetail($order_id, 'id,status,paid', $where); if (!$order) return app('json')->fail('订单不存在'); if (!$order['status'] && $order['paid']) { $deliveryTypeArr = isset($where['store_id']) ? ['send'] : ['send', 'express', 'fictitious']; if (!strlen(trim($delivery_type))) return app('json')->fail('请填写发货方式'); if (!in_array($delivery_type, $deliveryTypeArr)) return app('json')->fail('发货方式错误'); if ($delivery_type == 'express') { if (!strlen(trim($delivery_name))) return app('json')->fail('请选择快递公司'); if (!strlen(trim($delivery_id))) return app('json')->fail('请填写快递单号'); } if ($delivery_type == 'send') { if (!strlen(trim($delivery_name))) return app('json')->fail('请填写发货人'); if (!strlen(trim($delivery_id))) return app('json')->fail('请填写发货手机号'); } $data['status'] = 1; $data['delivery_type'] = $delivery_type; $data['delivery_name'] = $delivery_name; $data['delivery_id'] = $delivery_id; $res = StoreOrder::edit($data, $order['id'], 'id'); if ($res) { if ($delivery_type == 'express') { StoreOrderStatus::status($order['id'], 'delivery_goods', '已发货 快递公司:' . $data['delivery_name'] . ' 快递单号:' . $data['delivery_id']); } else if ($delivery_type == 'send') { StoreOrderStatus::status($order['id'], 'delivery', '已配送 发货人:' . $delivery_name . ' 发货人电话:' . $delivery_id); } else if ($delivery_type == 'fictitious') { StoreOrderStatus::status($order['id'], 'delivery_fictitious', '虚拟产品已发货'); } } event('StoreProductOrderDeliveryGoodsAfter', [$data, $order['id']]); return app('json')->successful('发货成功!'); } return app('json')->fail('状态错误'); } /** * 订单改价 * @param Request $request * @return mixed * @throws DataNotFoundException * @throws ModelNotFoundException * @throws DbException */ public function price(Request $request) { $uid = $request->uid(); // if (!StoreService::orderServiceStatus($uid)) // return app('json')->fail('权限不足'); list($order_id, $price) = UtilService::postMore([ ['order_id', ''], ['price', ''] ], $request, true); $where = []; $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find(); if ($info) { $where['store_id'] = $info['store_id']; } $order = StoreOrder::getAdminOrderDetail($order_id, 'id,paid,user_phone,pay_price,order_id,total_price,total_postage,pay_postage,gain_integral', $where); if (!$order) return app('json')->fail('订单不存在'); $order = $order->toArray(); if (!$order['paid']) { if ($price === '') return app('json')->fail('请填写实际支付金额'); if ($price < 0) return app('json')->fail('实际支付金额不能小于0元'); if ($order['pay_price'] == $price) return app('json')->successful('修改成功'); $order['order_id'] = StoreOrder::changeOrderId($order['order_id']); if (!StoreOrder::edit(['pay_price' => $price, 'order_id' => $order['order_id']], $order['id'], 'id')) return app('json')->fail('状态错误'); $order['pay_price'] = $price; event('StoreProductOrderEditAfter', [$order, $order['id']]); StoreOrderStatus::status($order['id'], 'order_edit', '修改实际支付金额' . $price); //改价短信提醒 if ($price != $order['pay_price']) { $switch = sys_config('price_revision_switch') ? true : false; ShortLetterRepositories::send($switch, $order['user_phone'], ['order_id' => $order_id, 'pay_price' => $order['pay_price']], 'PRICE_REVISION_CODE'); } return app('json')->successful('修改成功'); } return app('json')->fail('状态错误'); } /** * 订单备注 * @param Request $request * @return mixed * @throws DataNotFoundException * @throws ModelNotFoundException * @throws DbException */ public function remark(Request $request) { $uid = $request->uid(); // if (!StoreService::orderServiceStatus($uid)) // return app('json')->fail('权限不足'); list($order_id, $remark) = UtilService::postMore([ ['order_id', ''], ['remark', ''] ], $request, true); $where = []; $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find(); if ($info) { $where['store_id'] = $info['store_id']; } $order = StoreOrder::getAdminOrderDetail($order_id, 'id', $where); if (!$order) return app('json')->fail('订单不存在'); $order = $order->toArray(); if (!strlen(trim($remark))) return app('json')->fail('请填写备注内容'); if (!StoreOrder::edit(['remark' => $remark], $order['id'])) return app('json')->fail('备注失败'); return app('json')->successful('备注成功'); } /** * 订单交易额/订单数量时间统计 * @param Request $request * @return bool */ public function time(Request $request) { $uid = $request->uid(); // if (!StoreService::orderServiceStatus($uid)) // return app('json')->fail('权限不足'); list($start, $stop, $type) = UtilService::getMore([ ['start', strtotime(date('Y-m'))], ['stop', time()], ['type', 1] ], $request, true); $where = []; $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find(); if ($info) { $where['store_id'] = $info['store_id']; } if ($start == $stop) { return app('json')->fail('开始时间不能等于结束时间'); } if ($start > $stop) { $middle = $stop; $stop = $start; $start = $middle; } $space = bcsub($stop, $start, 0);//间隔时间段 $front = bcsub($start, $space, 0);//第一个时间段 if ($type == 1) {//销售额 $frontPrice = StoreOrder:: getOrderTimeBusinessVolumePrice($front, $start, $where); $afterPrice = StoreOrder:: getOrderTimeBusinessVolumePrice($start, $stop, $where); $chartInfo = StoreOrder::chartTimePrice($start, $stop, $where); $data['chart'] = $chartInfo;//营业额图表数据 $data['time'] = $afterPrice;//时间区间营业额 $increase = (float)bcsub($afterPrice, $frontPrice, 2); //同比上个时间区间增长营业额 $growthRate = abs($increase); if ($growthRate == 0) $data['growth_rate'] = 0; else if ($frontPrice == 0) $data['growth_rate'] = $growthRate; else $data['growth_rate'] = (int)bcmul(bcdiv($growthRate, $frontPrice, 2), 100, 0);//时间区间增长率 $data['increase_time'] = abs($increase); //同比上个时间区间增长营业额 $data['increase_time_status'] = $increase >= 0 ? 1 : 2; //同比上个时间区间增长营业额增长 1 减少 2 } else {//订单数 $frontNumber = StoreOrder:: getOrderTimeBusinessVolumeNumber($front, $start, $where); $afterNumber = StoreOrder:: getOrderTimeBusinessVolumeNumber($start, $stop, $where); $chartInfo = StoreOrder::chartTimeNumber($start, $stop, $where); $data['chart'] = $chartInfo;//订单数图表数据 $data['time'] = $afterNumber;//时间区间订单数 $increase = (int)bcsub($afterNumber, $frontNumber, 0); //同比上个时间区间增长订单数 $growthRate = abs($increase); if ($growthRate == 0) $data['growth_rate'] = 0; else if ($frontNumber == 0) $data['growth_rate'] = $growthRate; else $data['growth_rate'] = (int)bcmul(bcdiv($growthRate, $frontNumber, 2), 100, 0);//时间区间增长率 $data['increase_time'] = abs($increase); //同比上个时间区间增长营业额 $data['increase_time_status'] = $increase >= 0 ? 1 : 2; //同比上个时间区间增长营业额增长 1 减少 2 } return app('json')->successful($data); } public function month(Request $request) { $uid = $request->uid(); $where = []; $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find(); if ($info) { $where['store_id'] = $info['store_id']; } $start = StoreOrder::min('add_time'); $data = []; while ($start < time()) { $start_month = date('Y-m', $start); $end = strtotime('+1month', strtotime($start_month)) - 1; $frontPrice = StoreOrder:: getOrderTimeBusinessVolumePrice($start, $end, $where); $frontNumber = StoreOrder:: getOrderTimeBusinessVolumeNumber($start, $end, $where); $start = $end + 1; $data[$start_month] = compact('frontPrice', 'frontNumber'); } return app('json')->successful($data); } /** * 订单支付 * @param Request $request * @return mixed * @throws DataNotFoundException * @throws ModelNotFoundException * @throws DbException */ public function offline(Request $request) { $uid = $request->uid(); list($orderId) = UtilService::postMore([['order_id', '']], $request, true); $where = []; $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find(); if ($info) { $where['store_id'] = $info['store_id']; } $orderInfo = StoreOrder::getAdminOrderDetail($orderId, 'id', $where); if (!$orderInfo) return app('json')->fail('参数错误'); $id = $orderInfo->id; $res = StoreOrder::updateOffline($id); if ($res) { event('StoreProductOrderOffline', [$id]); StoreOrderStatus::status($id, 'offline', '线下付款'); return app('json')->successful('修改成功!'); } return app('json')->fail(StoreOrder::getErrorInfo('修改失败!')); } /** * 订单退款 * @param Request $request * @return mixed * @throws \think\Exception * @throws DataNotFoundException * @throws ModelNotFoundException * @throws DbException */ public function refund(Request $request) { $uid = $request->uid(); list($orderId, $price, $type) = UtilService::postMore([ ['order_id', ''], ['price', 0], ['type', 1], ], $request, true); $where = []; $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find(); if ($info) { $where['store_id'] = $info['store_id']; } if (!strlen(trim($orderId))) return app('json')->fail('参数错误'); $orderInfo = StoreOrder::getAdminOrderDetail($orderId, '*', $where); if (!$orderInfo) return app('json')->fail('数据不存在!'); $orderInfo = $orderInfo->toArray(); if ($type == 1) $data['refund_status'] = 2; else if ($type == 2) $data['refund_status'] = 0; else return app('json')->fail('退款修改状态错误'); if ($orderInfo['pay_price'] == 0 || $type == 2) { StoreOrder::update($data, ['order_id' => $orderId]); return app('json')->successful('修改退款状态成功!'); } if ($orderInfo['pay_price'] == $orderInfo['refund_price']) return app('json')->fail('已退完支付金额!不能再退款了'); if (!$price) return app('json')->fail('请输入退款金额'); $data['refund_price'] = bcadd($price, $orderInfo['refund_price'], 2); $bj = bccomp((float)$orderInfo['pay_price'], (float)$data['refund_price'], 2); if ($bj < 0) return app('json')->fail('退款金额大于支付金额,请修改退款金额'); $refundData['pay_price'] = bcadd($orderInfo['pay_price'], $orderInfo['deposit'], 2); $refundData['refund_price'] = $price; $refundData['refund_id'] = $orderInfo['order_id'] . time(); if ($orderInfo['pay_type'] == 'weixin') { if ($orderInfo['is_channel'] == 1) {// 小程序 try { MiniProgramService::payOrderRefund($orderInfo['order_id'], $refundData); } catch (\Exception $e) { return app('json')->fail($e->getMessage()); } } else {// 公众号 try { WechatService::payOrderRefund($orderInfo['order_id'], $refundData); } catch (\Exception $e) { return app('json')->fail($e->getMessage()); } } } else if ($orderInfo['pay_type'] == 'yue') {//余额 StoreOrder::beginTrans(); $userInfo = User::getUserInfo($orderInfo['uid'], 'now_money'); if (!$userInfo) { StoreOrder::rollbackTrans(); return app('json')->fail('订单用户不存在'); } $res1 = User::bcInc($orderInfo['uid'], 'now_money', $price, 'uid'); $res2 = $res2 = UserBill::income('商品退款', $orderInfo['uid'], 'now_money', 'pay_product_refund', $price, $orderInfo['id'], bcadd($userInfo['now_money'], $price, 2), '订单退款到余额' . floatval($price) . '元'); try { OrderRepository::storeOrderYueRefund($orderInfo, $refundData); } catch (\Exception $e) { StoreOrder::rollbackTrans(); return app('json')->fail($e->getMessage()); } $res = $res1 && $res2; StoreOrder::checkTrans($res); if (!$res) return app('json')->fail('余额退款失败!'); } $resEdit = StoreOrder::edit($data, $orderInfo['id'], 'id'); if ($resEdit) { $data['type'] = $type; if ($data['type'] == 1) StorePink::setRefundPink($orderInfo['id']); try { OrderRepository::storeProductOrderRefundY($data, $orderInfo['id']); } catch (\Exception $e) { return app('json')->fail($e->getMessage()); } StoreOrderStatus::status($orderInfo['id'], 'refund_price', '退款给用户' . $price . '元'); SystemStoreBill::where('category', 'brokerage_price') //->where('type', 'brokerage') ->where('link_id', $orderId) ->where('pm', 1) ->where('status', 0) ->update(['status' => -1]); \app\admin\model\user\UserBill::where('category', 'now_money') ->where('type', 'brokerage') ->where('link_id', $orderId) ->where('pm', 1) ->where('status', 0) ->update(['status' => -1]); //退佣金 $brokerage_list = UserBill::where('category', 'now_money') ->where('type', 'brokerage') ->where('link_id', $orderId) ->where('pm', 1) ->where('status', 1) ->select()->toArray(); if ($brokerage_list) 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'], $orderId, bcsub($usermoney, $item['number'], 2), '订单退款扣除佣金' . floatval($item['number']) . '元'); } return app('json')->successful('修改成功!'); } else { StoreOrderStatus::status($orderInfo['id'], 'refund_price', '退款给用户' . $price . '元失败'); return app('json')->successful('修改失败!'); } } /** * 门店核销 * @param Request $request * @return * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ public function 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 = StoreOrder::where('verify_code', $verify_code)->where('store_id', 'in', [SystemStoreStaff::where('uid', $uid)->value('store_id'), 0])->where('paid', 1)->where('refund_status', 0)->find(); if (!$orderInfo) return app('json')->fail('核销的订单不存在于该门店或未支付或已退款'); if ($orderInfo->status > 0) return app('json')->fail('订单已经核销'); if ($orderInfo->combination_id && $orderInfo->pink_id) { $res = StorePink::where('id', $orderInfo->pink_id)->where('status', '<>', 2)->count(); if ($res) return app('json')->fail('拼团订单暂未成功无法核销!'); } if (!$is_confirm) { $orderInfo['image'] = StoreCart::getProductImage($orderInfo->cart_id); return app('json')->success($orderInfo->toArray()); } StoreOrder::beginTrans(); try { if (SystemStoreStaff::verifyStatus($uid) && ($storeStaff = SystemStoreStaff::where('uid', $uid)->field(['store_id', 'id'])->find())) { // $orderInfo->store_id = $storeStaff['store_id']; $orderInfo->clerk_id = $storeStaff['id']; } $orderInfo->status = 2; $orderInfo->verify_time = time(); if ($orderInfo->store_id == 0) { $orderInfo->store_id = SystemStoreStaff::where('uid', $uid)->value('store_id'); $store = SystemStore::get($orderInfo->store_id); $orderInfo->province = explode(',', $store['address'])[0] ?? ''; $orderInfo->city = explode(',', $store['address'])[1] ?? ''; $orderInfo->district = explode(',', $store['address'])[2] ?? ''; SystemStore::decStock($orderInfo); } if ($orderInfo->save()) { OrderRepository::storeProductOrderTakeDeliveryAdmin($orderInfo); StoreOrderStatus::status($orderInfo->id, 'take_delivery', '已核销'); event('ShortMssageSend', [$orderInfo['order_id'], 'Receiving']); StoreOrder::commitTrans(); return app('json')->success('核销成功'); } else { StoreOrder::rollbackTrans(); return app('json')->fail('核销失败'); } } catch (\PDOException $e) { StoreOrder::rollbackTrans(); return app('json')->fail($e->getMessage()); } catch (\Exception $e) { StoreOrder::rollbackTrans(); return app('json')->fail($e->getMessage()); } } /** * 门店核销 * @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 == 2) 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; $orderInfo->verify_time = time(); 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(); $where = UtilService::getMore([ ['page', 1], ['limit', 20], ]); $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find(); if (!$info) { return app('json')->fail('权限不足'); } $where['store_id'] = $info['store_id']; return app('json')->successful('ok', UserRecharge::getStoreRechargeList($where)); } public function back_deposit(Request $request) { $uid = $request->uid(); $data = UtilService::postMore([ ['order_id', ''], ['refund_price', 0], ['type', 1], ]); if (!$data['order_id']) return app('json')->fail('数据不存在'); $orderInfo = StoreOrder::where('order_id', $data['order_id'])->where('store_id', SystemStoreStaff::where('uid', $uid)->value('store_id'))->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 = StoreOrder::edit($data, $orderInfo['id']); if ($resEdit) { \app\admin\model\order\StoreOrderStatus::setStatus($orderInfo['id'], 'refund_deposit', '退押金给用户' . $refund_price . '元'); return app('json')->success('成功!'); } else { \app\admin\model\order\StoreOrderStatus::setStatus($orderInfo['id'], 'refund_deposit', '退押金给用户' . $refund_price . '元失败'); return app('json')->fail('失败!'); } } public function exchange_order_back_deposit(Request $request) { $uid = $request->uid(); $data = UtilService::postMore([ ['id', ''], ['refund_price', 0], ['type', 1], ], $request); // var_dump($data); 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(); $order = StoreOrderModel::where('order_id', $orderInfo['order_id'])->find(); if ($order['pay_type'] == 'weixin') { if ($order['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('失败!'); } } }