|
|
@@ -2,7 +2,15 @@
|
|
|
|
|
|
namespace app\api\controller\admin;
|
|
|
|
|
|
+use app\admin\model\system\SystemStoreBill;
|
|
|
+use app\admin\model\system\SystemStoreExtract;
|
|
|
+use app\admin\model\system\SystemStorePoint;
|
|
|
+use app\admin\model\system\SystemStoreProductStock;
|
|
|
+use app\models\system\SystemStore;
|
|
|
use app\Request;
|
|
|
+use think\db\exception\DataNotFoundException;
|
|
|
+use think\db\exception\DbException;
|
|
|
+use think\db\exception\ModelNotFoundException;
|
|
|
use app\models\user\{
|
|
|
User, UserBill
|
|
|
};
|
|
|
@@ -23,18 +31,225 @@ use app\models\system\SystemStoreStaff;
|
|
|
*/
|
|
|
class StoreOrderController
|
|
|
{
|
|
|
+
|
|
|
+ public function pointList(Request $request)
|
|
|
+ {
|
|
|
+ $uid = $request->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 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 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],
|
|
|
+ ], $request);
|
|
|
+ $extractInfo['extract_type'] = 'bank';
|
|
|
+ $extractInfo['name'] = $store['leader'];
|
|
|
+ $extractInfo['bankname'] = $store['bank_name'];
|
|
|
+ $extractInfo['cardnum'] = $store['bank_card'];
|
|
|
+ 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('权限不足');
|
|
|
- $dataCount = StoreOrder::getOrderDataAdmin();
|
|
|
- $dataPrice = StoreOrder::getOrderTimeData();
|
|
|
+// 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);
|
|
|
}
|
|
|
@@ -43,20 +258,28 @@ class StoreOrderController
|
|
|
* 订单每月统计数据
|
|
|
* @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('权限不足');
|
|
|
+// 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);
|
|
|
+ $data = StoreOrder::getOrderDataPriceCount($page, $limit, $start, $stop, $where);
|
|
|
if ($data) return app('json')->successful($data->toArray());
|
|
|
return app('json')->successful([]);
|
|
|
}
|
|
|
@@ -65,21 +288,29 @@ class StoreOrderController
|
|
|
* 订单列表
|
|
|
* @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('权限不足');
|
|
|
+// if (!StoreService::orderServiceStatus($uid))
|
|
|
+// return app('json')->fail('权限不足');
|
|
|
$where = UtilService::getMore([
|
|
|
['status', ''],
|
|
|
['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));
|
|
|
}
|
|
|
@@ -89,17 +320,21 @@ class StoreOrderController
|
|
|
* @param Request $request
|
|
|
* @param $orderId
|
|
|
* @return mixed
|
|
|
- * @throws \think\Exception
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
+ * @throws DataNotFoundException
|
|
|
+ * @throws ModelNotFoundException
|
|
|
+ * @throws DbException
|
|
|
*/
|
|
|
public function detail(Request $request, $orderId)
|
|
|
{
|
|
|
$uid = $request->uid();
|
|
|
- if (!StoreService::orderServiceStatus($uid))
|
|
|
- return app('json')->fail('权限不足');
|
|
|
- $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');
|
|
|
+// 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', $where);
|
|
|
if (!$order) return app('json')->fail('订单不存在');
|
|
|
$order = $order->toArray();
|
|
|
$nickname = User::getUserInfo($order['uid'], 'nickname')['nickname'];
|
|
|
@@ -114,17 +349,21 @@ class StoreOrderController
|
|
|
* @param Request $request
|
|
|
* @param $orderId
|
|
|
* @return mixed
|
|
|
- * @throws \think\Exception
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
+ * @throws DataNotFoundException
|
|
|
+ * @throws ModelNotFoundException
|
|
|
+ * @throws DbException
|
|
|
*/
|
|
|
public function delivery_gain(Request $request, $orderId)
|
|
|
{
|
|
|
$uid = $request->uid();
|
|
|
- if (!StoreService::orderServiceStatus($uid))
|
|
|
- return app('json')->fail('权限不足');
|
|
|
- $order = StoreOrder::getAdminOrderDetail($orderId, 'real_name,user_phone,user_address,order_id,uid,status,paid');
|
|
|
+// 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'];
|
|
|
@@ -138,25 +377,31 @@ class StoreOrderController
|
|
|
* 订单发货
|
|
|
* @param Request $request
|
|
|
* @return mixed
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @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('权限不足');
|
|
|
+// 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);
|
|
|
- $order = StoreOrder::getAdminOrderDetail($order_id, 'id,status,paid');
|
|
|
+ $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 = ['send', 'express', 'fictitious'];
|
|
|
+ $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') {
|
|
|
@@ -191,20 +436,25 @@ class StoreOrderController
|
|
|
* 订单改价
|
|
|
* @param Request $request
|
|
|
* @return mixed
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
+ * @throws DataNotFoundException
|
|
|
+ * @throws ModelNotFoundException
|
|
|
+ * @throws DbException
|
|
|
*/
|
|
|
public function price(Request $request)
|
|
|
{
|
|
|
$uid = $request->uid();
|
|
|
- if (!StoreService::orderServiceStatus($uid))
|
|
|
- return app('json')->fail('权限不足');
|
|
|
+// if (!StoreService::orderServiceStatus($uid))
|
|
|
+// return app('json')->fail('权限不足');
|
|
|
list($order_id, $price) = UtilService::postMore([
|
|
|
['order_id', ''],
|
|
|
['price', '']
|
|
|
], $request, true);
|
|
|
- $order = StoreOrder::getAdminOrderDetail($order_id, 'id,paid,user_phone,pay_price,order_id,total_price,total_postage,pay_postage,gain_integral');
|
|
|
+ $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']) {
|
|
|
@@ -231,20 +481,25 @@ class StoreOrderController
|
|
|
* 订单备注
|
|
|
* @param Request $request
|
|
|
* @return mixed
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
+ * @throws DataNotFoundException
|
|
|
+ * @throws ModelNotFoundException
|
|
|
+ * @throws DbException
|
|
|
*/
|
|
|
public function remark(Request $request)
|
|
|
{
|
|
|
$uid = $request->uid();
|
|
|
- if (!StoreService::orderServiceStatus($uid))
|
|
|
- return app('json')->fail('权限不足');
|
|
|
+// if (!StoreService::orderServiceStatus($uid))
|
|
|
+// return app('json')->fail('权限不足');
|
|
|
list($order_id, $remark) = UtilService::postMore([
|
|
|
['order_id', ''],
|
|
|
['remark', '']
|
|
|
], $request, true);
|
|
|
- $order = StoreOrder::getAdminOrderDetail($order_id, 'id');
|
|
|
+ $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('请填写备注内容');
|
|
|
@@ -261,13 +516,18 @@ class StoreOrderController
|
|
|
public function time(Request $request)
|
|
|
{
|
|
|
$uid = $request->uid();
|
|
|
- if (!StoreService::orderServiceStatus($uid))
|
|
|
- return app('json')->fail('权限不足');
|
|
|
+// 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('开始时间不能等于结束时间');
|
|
|
}
|
|
|
@@ -279,9 +539,9 @@ class StoreOrderController
|
|
|
$space = bcsub($stop, $start, 0);//间隔时间段
|
|
|
$front = bcsub($start, $space, 0);//第一个时间段
|
|
|
if ($type == 1) {//销售额
|
|
|
- $frontPrice = StoreOrder:: getOrderTimeBusinessVolumePrice($front, $start);
|
|
|
- $afterPrice = StoreOrder:: getOrderTimeBusinessVolumePrice($start, $stop);
|
|
|
- $chartInfo = StoreOrder::chartTimePrice($start, $stop);
|
|
|
+ $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); //同比上个时间区间增长营业额
|
|
|
@@ -292,9 +552,9 @@ class StoreOrderController
|
|
|
$data['increase_time'] = abs($increase); //同比上个时间区间增长营业额
|
|
|
$data['increase_time_status'] = $increase >= 0 ? 1 : 2; //同比上个时间区间增长营业额增长 1 减少 2
|
|
|
} else {//订单数
|
|
|
- $frontNumber = StoreOrder:: getOrderTimeBusinessVolumeNumber($front, $start);
|
|
|
- $afterNumber = StoreOrder:: getOrderTimeBusinessVolumeNumber($start, $stop);
|
|
|
- $chartInfo = StoreOrder::chartTimeNumber($start, $stop);
|
|
|
+ $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); //同比上个时间区间增长订单数
|
|
|
@@ -312,14 +572,20 @@ class StoreOrderController
|
|
|
* 订单支付
|
|
|
* @param Request $request
|
|
|
* @return mixed
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
+ * @throws DataNotFoundException
|
|
|
+ * @throws ModelNotFoundException
|
|
|
+ * @throws DbException
|
|
|
*/
|
|
|
public function offline(Request $request)
|
|
|
{
|
|
|
+ $uid = $request->uid();
|
|
|
list($orderId) = UtilService::postMore([['order_id', '']], $request, true);
|
|
|
- $orderInfo = StoreOrder::getAdminOrderDetail($orderId, 'id');
|
|
|
+ $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);
|
|
|
@@ -336,19 +602,25 @@ class StoreOrderController
|
|
|
* @param Request $request
|
|
|
* @return mixed
|
|
|
* @throws \think\Exception
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
+ * @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);
|
|
|
+ $orderInfo = StoreOrder::getAdminOrderDetail($orderId, '*', $where);
|
|
|
if (!$orderInfo) return app('json')->fail('数据不存在!');
|
|
|
$orderInfo = $orderInfo->toArray();
|
|
|
if ($type == 1)
|
|
|
@@ -411,12 +683,26 @@ class StoreOrderController
|
|
|
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) {
|
|
|
@@ -433,94 +719,24 @@ class StoreOrderController
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * 订单退押金
|
|
|
- * @param Request $request
|
|
|
- * @return mixed
|
|
|
- * @throws \think\Exception
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
- */
|
|
|
- public function back_deposit(Request $request)
|
|
|
- {
|
|
|
- list($orderId, $price, $type) = UtilService::postMore([
|
|
|
- ['order_id', ''],
|
|
|
- ['price', 0],
|
|
|
- ['type', 1],
|
|
|
- ], $request, true);
|
|
|
- if (!strlen(trim($orderId))) return app('json')->fail('参数错误');
|
|
|
- $orderInfo = StoreOrder::getAdminOrderDetail($orderId);
|
|
|
- if (!$orderInfo) return app('json')->fail('数据不存在!');
|
|
|
- $orderInfo = $orderInfo->toArray();
|
|
|
- if ($type == 1)
|
|
|
- $data['deposit_status'] = 1;
|
|
|
- else if ($type == 2) {
|
|
|
- $data['deposit_status'] = 0;
|
|
|
- } else
|
|
|
- return app('json')->fail('退款修改状态错误');
|
|
|
- if ($orderInfo['deposit'] == 0 || $type == 2) {
|
|
|
- StoreOrder::update($data, ['order_id' => $orderId]);
|
|
|
- return app('json')->successful('修改退款状态成功!');
|
|
|
- }
|
|
|
- if ($orderInfo['deposit'] == $orderInfo['deposit_back']) return app('json')->fail('已退完押金!不能再退了');
|
|
|
- if (!$price) return app('json')->fail('请输入退押金额');
|
|
|
- $data['deposit_back'] = bcadd($price, $orderInfo['deposit_back'], 2);
|
|
|
- $bj = bccomp((float)$orderInfo['deposit'], (float)$data['deposit_back'], 2);
|
|
|
- if ($bj < 0) return app('json')->fail('退款押金大于支付押金,请修改退款押金');
|
|
|
- $refundData['pay_price'] = bcadd($orderInfo['pay_price'], $orderInfo['deposit'], 2);
|
|
|
- $refundData['refund_price'] = $price;
|
|
|
- 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 = UserBill::income('商品退押金', $orderInfo['uid'], 'now_money', 'pay_deposit_refund', $price, $orderInfo['id'], bcadd($userInfo['now_money'], $price, 2), '订单退押金到余额' . floatval($price) . '元');
|
|
|
- $res = $res1 && $res2;
|
|
|
- StoreOrder::checkTrans($res);
|
|
|
- if (!$res) return app('json')->fail('余额退押金失败!');
|
|
|
- }
|
|
|
- $resEdit = StoreOrder::edit($data, $orderInfo['id'], 'id');
|
|
|
- if ($resEdit) {
|
|
|
- StoreOrderStatus::status($orderInfo['id'], 'refund_deposit', '退押金给用户' . $price . '元');
|
|
|
- return app('json')->successful('修改成功!');
|
|
|
- } else {
|
|
|
- StoreOrderStatus::status($orderInfo['id'], 'refund_deposit', '退押金给用户' . $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('paid', 1)->where('refund_status', 0)->find();
|
|
|
- if (!$orderInfo) return app('json')->fail('核销的订单不存在或未支付或已退款');
|
|
|
+ $orderInfo = StoreOrder::where('verify_code', $verify_code)->where('store_id', $storeStaff = SystemStoreStaff::where('uid', $uid)->value('store_id'))->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();
|
|
|
@@ -532,9 +748,8 @@ class StoreOrderController
|
|
|
}
|
|
|
StoreOrder::beginTrans();
|
|
|
try {
|
|
|
- $uid = $request->uid();
|
|
|
if (SystemStoreStaff::verifyStatus($uid) && ($storeStaff = SystemStoreStaff::where('uid', $uid)->field(['store_id', 'id'])->find())) {
|
|
|
- $orderInfo->store_id = $storeStaff['store_id'];
|
|
|
+// $orderInfo->store_id = $storeStaff['store_id'];
|
|
|
$orderInfo->clerk_id = $storeStaff['id'];
|
|
|
}
|
|
|
$orderInfo->status = 2;
|
|
|
@@ -551,8 +766,10 @@ class StoreOrderController
|
|
|
} catch (\PDOException $e) {
|
|
|
StoreOrder::rollbackTrans();
|
|
|
return app('json')->fail($e->getMessage());
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ StoreOrder::rollbackTrans();
|
|
|
+ return app('json')->fail($e->getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
}
|