Commit ee6aa6e1 by lizhilin

更新

parent 42755d97
...@@ -27,12 +27,13 @@ protected function grid() ...@@ -27,12 +27,13 @@ protected function grid()
return Grid::make(OrderInfo::with(['user', 'merchant']), function (Grid $grid) { return Grid::make(OrderInfo::with(['user', 'merchant']), function (Grid $grid) {
$grid->model()->orderBy('created_at', 'DESC'); $grid->model()->orderBy('created_at', 'DESC');
$grid->column('id')->sortable(); $grid->column('id')->sortable();
$grid->column('order_sn', '订单号'); $grid->column('order_sn', '订单号')->width(80);
$grid->column('mobile', '手机号'); $grid->column('mobile', '手机号');
$grid->column('goods', '商品信息')->expand(function (Grid\Displayers\Expand $expand) { $grid->column('goods', '商品信息')->expand(function (Grid\Displayers\Expand $expand) {
$expand->button('查看'); $expand->button('查看');
return OrderGoodsList::make(['order_id' => $this->id]); return OrderGoodsList::make(['order_id' => $this->id]);
})->width(100); });
$grid->column('goods_amount', '订单总金额'); $grid->column('goods_amount', '订单总金额');
$grid->column('merchant.name', '所属商家'); $grid->column('merchant.name', '所属商家');
$grid->column('merchant.province_id', '所在省市')->display(function ($val) { $grid->column('merchant.province_id', '所在省市')->display(function ($val) {
...@@ -42,6 +43,7 @@ protected function grid() ...@@ -42,6 +43,7 @@ protected function grid()
$cityname = $cityObj->name ?? ''; $cityname = $cityObj->name ?? '';
return $proname . " " . $cityname; return $proname . " " . $cityname;
}); });
$grid->column('store_id', '快递代收点')->display(function ($val) { $grid->column('store_id', '快递代收点')->display(function ($val) {
$res = null; $res = null;
if ($val) { if ($val) {
...@@ -59,7 +61,7 @@ protected function grid() ...@@ -59,7 +61,7 @@ protected function grid()
return $res; return $res;
}); });
$grid->column('created_at', '下单时间'); $grid->column('created_at', '下单时间');
$grid->column('order_status', '订单状态')->display(function ($val) { $grid->column('order_status', '状态')->display(function ($val) {
$options = OrderInfo::STATUS_OPTIONS; $options = OrderInfo::STATUS_OPTIONS;
return $options[$val]; return $options[$val];
})->if(function ($column) { })->if(function ($column) {
...@@ -83,8 +85,14 @@ protected function grid() ...@@ -83,8 +85,14 @@ protected function grid()
$grid->filter(function (Grid\Filter $filter) { $grid->filter(function (Grid\Filter $filter) {
// 更改为 panel 布局 // 更改为 panel 布局
$filter->panel(); $filter->panel();
$filter->equal('order_sn', '订单号')->width(4); $filter->equal('order_sn', '订单号')->width(3);
$filter->like('phone', '手机号')->width(4); $filter->like('phone', '手机号')->width(3);
$filter->like('merchant.name', '所属商家')->width(3);
//订单状态
$filter->equal('order_status', '订单状态')->select(OrderInfo::STATUS_OPTIONS)->width(3);
$filter->equal('merchant.province_id', '省份')->select(City::where('parent_id', 0)->get()->pluck('name', 'city_id'))->load('merchant.city_id', '/city')->width(3);
// 城市
$filter->equal('merchant.city_id', '城市')->select()->width(3);
$filter->between('created_at', '创建时间')->datetime()->width(4); $filter->between('created_at', '创建时间')->datetime()->width(4);
}); });
}); });
...@@ -135,9 +143,6 @@ protected function form() ...@@ -135,9 +143,6 @@ protected function form()
$form->select('order_status', '订单状态')->options($options); $form->select('order_status', '订单状态')->options($options);
// $form->switch('pay_status')->default(0); // $form->switch('pay_status')->default(0);
// $form->switch('shipping_status', '发货状态')->default(0); // $form->switch('shipping_status', '发货状态')->default(0);
// $form->datetime('shipping_time', '发货时间');
// $form->text('shipping_name', '物流公司');
// $form->text('shipping_code', '物流单号');
// $form->text('order_amount', '订单应付款'); // $form->text('order_amount', '订单应付款');
// $form->display('created_at'); // $form->display('created_at');
// $form->display('updated_at'); // $form->display('updated_at');
......
<?php
namespace App\Http\Controllers\Api;
use App\Command\Log;
use App\Models\Merchant;
use App\Models\User as UserModel;
use App\Models\OrderDivideRecord;
use Illuminate\Http\Request;
class MerchantController extends BaseController
{
//绑定直购码用户列表
public function getUserList(Request $request)
{
$mer_id = $request->user()->id;
$merObj = Merchant::where('id', $mer_id)->first();
$buycode = $merObj->buycode;
if (!$buycode) {
return $this->JsonResponse('', '参数错误', 201);
}
$page = $request->page ?? 1;
$limit = $request->limit ?? 10;
$sql = UserModel::where(['buycode' => $buycode, 'status' => 1, 'deleted_at' => null]);
$total = $sql->count();
$data = [
'divideAmount' => 0,
'total' => $total,
'total_page' => ceil($total / $limit),
'list' => []
];
//商户佣金总额
$divideAmount = OrderDivideRecord::where(['sh_type' => 3, 'um_id' => $mer_id])->sum('divide_price');
$data['divideAmount'] = (float)$divideAmount;
$listData = $sql->offset(($page - 1) * $limit)->limit($limit)->orderBy('created_at', 'DESC')->get();
if ($listData->toArray()) {
foreach ($listData as $item) {
//获取会员给商户产生的佣金
$uid = $item->id;
$divide_price = OrderDivideRecord::where(['sh_type' => 3, 'um_id' => $mer_id, 'user_id' => $uid])->sum('divide_price');
$data['list'][] = [
'uid' => $uid,
'name' => $item->name,
'divide_price' => (float)$divide_price,
'avatar' => (isset($item->avatar) ? env('IMAGE_URL') . $item->avatar : ''),
'created_at' => date('Y-m-d H:i:s', strtotime($item->created_at)),
];
}
}
return $this->JsonResponse($data);
}
}
...@@ -434,10 +434,59 @@ public function scanCodeVerifi(Request $request) ...@@ -434,10 +434,59 @@ public function scanCodeVerifi(Request $request)
$orderObj->order_status = 3; $orderObj->order_status = 3;
$orderObj->verification_at = date("Y-m-d H:i:s"); $orderObj->verification_at = date("Y-m-d H:i:s");
$orderObj->save(); $orderObj->save();
} else {
return $this->JsonResponse('', '该码已核销,无需多次重复扫码', 500);
} }
return $this->JsonResponse(''); return $this->JsonResponse('');
} }
//扫码核销展示详情
public function scanCodeDetail(Request $request)
{
$code = $request->code ?? '';
$orderObj = OrderInfoModel::where('verification_code', $code)->first();
if (!$orderObj) {
return $this->JsonResponse('', '参数错误', 201);
}
$order_id = $orderObj->id;
//商品信息
$order_goods = $this->getOrderGoods($order_id);
//快递待收点、收货地址
$delivery = [];
if ($orderObj->address_id) {
$addressObj = UserAddress::find($orderObj->address_id);
$delivery['contacts'] = $addressObj->consignee;
$delivery['phone'] = $addressObj->phone;
$delivery['area'] = $addressObj->area;
$delivery['lat'] = $addressObj->lat;
$delivery['lng'] = $addressObj->lng;
}
if ($orderObj->store_id) {
$sObj = Store::find($orderObj->store_id);
$lat_lng = $sObj->lat_lng; //121.47,31.23
$latlngArr = $lat_lng ? explode(",", $lat_lng) : [];
$delivery['contacts'] = $sObj->contacts;
$delivery['phone'] = $sObj->phone;
$delivery['address'] = $sObj->address;
$delivery['lat'] = isset($latlngArr[1]) ? $latlngArr[1] : '';
$delivery['lng'] = isset($latlngArr[0]) ? $latlngArr[0] : '';
}
$data = [
'id' => $order_id,
'order_sn' => $orderObj->order_sn,
'user_id' => $orderObj->user_id,
'order_amount' => $orderObj->order_amount,
//'mobile' => $orderObj->mobile,
'delivery' => $delivery,
'delivery_type' => $orderObj->delivery_type,
'delivery_typename' => ($orderObj->delivery_type == 1) ? '快递代收点' : '送货上门',
'created_at' => date("Y-m-d H:i:s", strtotime($orderObj->created_at)),
'order_goods' => $order_goods
];
return $this->JsonResponse($data);
}
//订单详情 //订单详情
public function OrderInfo(Request $request) public function OrderInfo(Request $request)
{ {
...@@ -452,18 +501,8 @@ public function OrderInfo(Request $request) ...@@ -452,18 +501,8 @@ public function OrderInfo(Request $request)
} }
//商品信息 //商品信息
$order_goods = []; $order_goods = $this->getOrderGoods($order_id);
$ogoods = OrderGoods::where(["order_id" => $order_id])->get(); //快递待收点、收货地址
foreach ($ogoods as $key => $valObj) {
$tmp = [];
$tmp['goods_id'] = $valObj->goods_id;
$tmp['goods_name'] = $valObj->goods_name;
$tmp['goods_number'] = $valObj->goods_number;
$tmp['goods_attr'] = $valObj->goods_attr;
$tmp['goods_price'] = $valObj->goods_price;
$tmp['goods_img'] = $valObj->goods_img ? env('IMAGE_URL') . $valObj->goods_img : '';
array_push($order_goods, $tmp);
}
$delivery = []; $delivery = [];
if ($orderObj->address_id) { if ($orderObj->address_id) {
$addressObj = UserAddress::find($orderObj->address_id); $addressObj = UserAddress::find($orderObj->address_id);
...@@ -489,7 +528,6 @@ public function OrderInfo(Request $request) ...@@ -489,7 +528,6 @@ public function OrderInfo(Request $request)
'order_sn' => $orderObj->order_sn, 'order_sn' => $orderObj->order_sn,
'user_id' => $orderObj->user_id, 'user_id' => $orderObj->user_id,
'order_amount' => $orderObj->order_amount, 'order_amount' => $orderObj->order_amount,
//'consignee' => $orderObj->consignee,
'mobile' => $orderObj->mobile, 'mobile' => $orderObj->mobile,
'delivery' => $delivery, 'delivery' => $delivery,
'delivery_type' => $orderObj->delivery_type, 'delivery_type' => $orderObj->delivery_type,
...@@ -500,6 +538,24 @@ public function OrderInfo(Request $request) ...@@ -500,6 +538,24 @@ public function OrderInfo(Request $request)
return $this->JsonResponse($data); return $this->JsonResponse($data);
} }
//订单商品信息
private function getOrderGoods($oid)
{
$order_goods = [];
$ogoods = OrderGoods::where(["order_id" => $oid])->get();
foreach ($ogoods as $key => $valObj) {
$tmp = [];
$tmp['goods_id'] = $valObj->goods_id;
$tmp['goods_name'] = $valObj->goods_name;
$tmp['goods_number'] = $valObj->goods_number;
$tmp['goods_attr'] = $valObj->goods_attr;
$tmp['goods_price'] = $valObj->goods_price;
$tmp['goods_img'] = $valObj->goods_img ? env('IMAGE_URL') . $valObj->goods_img : '';
array_push($order_goods, $tmp);
}
return $order_goods;
}
//购物车确认订单 //购物车确认订单
public function CheckoutCartOrder(Request $request) public function CheckoutCartOrder(Request $request)
{ {
...@@ -560,6 +616,6 @@ public function orderCollect(Request $request) ...@@ -560,6 +616,6 @@ public function orderCollect(Request $request)
$goods_number = OrderGoods::where('merchant_id', $merchant_id)->whereBetween('created_at', [$firstDayOfMonth, $lastDayOfMonth])->sum('goods_number'); $goods_number = OrderGoods::where('merchant_id', $merchant_id)->whereBetween('created_at', [$firstDayOfMonth, $lastDayOfMonth])->sum('goods_number');
$lastMonth['stockCount'] = $goods_number + $currentStock; $lastMonth['stockCount'] = $goods_number + $currentStock;
} }
return $this->JsonResponse(['current' => $currentMonth, 'last' => $lastMonth]); return $this->JsonResponse(['current' => $currentMonth ? $currentMonth : new \stdClass(), 'last' => $lastMonth ? $lastMonth : new \stdClass()]);
} }
} }
...@@ -45,7 +45,7 @@ public static function divide($order_id) ...@@ -45,7 +45,7 @@ public static function divide($order_id)
$spObj->total_revenue += $divide_price; $spObj->total_revenue += $divide_price;
$spObj->balance += $divide_price; $spObj->balance += $divide_price;
$spObj->save(); $spObj->save();
self::addRecord($item->id, $order_id, $goods_amount, $divide_price, $first_commission, $spuid, 1); self::addRecord($item->id, $order_id, $goods_amount, $divide_price, $first_commission, $spuid, $user_id, 1);
} }
//间推佣金 //间推佣金
if ($second_spuid && $second_commission >= 1 && $second_commission < 100) { if ($second_spuid && $second_commission >= 1 && $second_commission < 100) {
...@@ -55,7 +55,7 @@ public static function divide($order_id) ...@@ -55,7 +55,7 @@ public static function divide($order_id)
$spObj->total_revenue += $divide_price; $spObj->total_revenue += $divide_price;
$spObj->balance += $divide_price; $spObj->balance += $divide_price;
$spObj->save(); $spObj->save();
self::addRecord($item->id, $order_id, $goods_amount, $divide_price, $second_commission, $second_spuid, 2); self::addRecord($item->id, $order_id, $goods_amount, $divide_price, $second_commission, $second_spuid, $user_id, 2);
} }
//商户分佣记录 //商户分佣记录
if ($merchant_id && $merchant_commission >= 1 && $merchant_commission < 100) { if ($merchant_id && $merchant_commission >= 1 && $merchant_commission < 100) {
...@@ -66,15 +66,16 @@ public static function divide($order_id) ...@@ -66,15 +66,16 @@ public static function divide($order_id)
$merObj->balance += $divide_price; $merObj->balance += $divide_price;
$merObj->save(); $merObj->save();
//记录 //记录
self::addRecord($item->id, $order_id, $goods_amount, $divide_price, $merchant_commission, $merchant_id, 3); self::addRecord($item->id, $order_id, $goods_amount, $divide_price, $merchant_commission, $merchant_id, $user_id, 3);
} }
} }
} }
public function addRecord($og_id, $order_id, $goods_amount, $divide_price, $commission, $um_id, $sh_type) public function addRecord($og_id, $order_id, $goods_amount, $divide_price, $commission, $um_id, $user_id, $sh_type)
{ {
$recordObj = new self(); $recordObj = new self();
$recordObj->order_id = $order_id; $recordObj->order_id = $order_id;
$recordObj->user_id = $user_id; //下单userId
$recordObj->og_id = $og_id; $recordObj->og_id = $og_id;
$recordObj->order_price = $goods_amount; $recordObj->order_price = $goods_amount;
$recordObj->divide_price = $divide_price; $recordObj->divide_price = $divide_price;
......
...@@ -21,7 +21,7 @@ class OrderInfo extends Model ...@@ -21,7 +21,7 @@ class OrderInfo extends Model
3 => '待评价', 3 => '待评价',
4 => '已完成', 4 => '已完成',
7 => '已取消', 7 => '已取消',
8 => '已退款', //8 => '已退款',
]; ];
......
...@@ -150,7 +150,11 @@ ...@@ -150,7 +150,11 @@
Route::post('income-add', 'IncomeController@add'); //去提现 Route::post('income-add', 'IncomeController@add'); //去提现
Route::post('scan-code', 'OrderController@scanCodeVerifi'); //扫码核销 Route::get('my-member', 'MerchantController@getUserList'); //商户端-我的用户
Route::post('scan-code-detail', 'OrderController@scanCodeDetail'); //扫码核销展示详情
Route::post('scan-code-verifi', 'OrderController@scanCodeVerifi'); //扫码核销确认
Route::get('merchant-order-collect', 'OrderController@orderCollect'); //商户端首页统计 Route::get('merchant-order-collect', 'OrderController@orderCollect'); //商户端首页统计
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment