Commit 97542556 by lizhilin

更新

parent 06f2dc65
......@@ -73,11 +73,19 @@ public function render()
//获取商品规格信息
if ($this->type == 1) {
$dataList = GoodSku::where("goods_id", $this->goods_id)->get();
$gid = $this->goods_id;
$dataList = GoodSku::where("goods_id", $gid)->get();
foreach ($dataList as $kk => $vv) {
$dataList[$kk]['attr_id'] = $vv->id;
//获取商户库存信息
$merStock = MerchantGoodSku::where(['goods_id' => $gid, 'attr_id' => $vv->id])->sum('stock');
$dataList[$kk]['stock'] = $vv->stock - $merStock;
}
} else {
$dataList = MerchantGoodSku::where("mgs_id", $mgs_id)->get();
foreach ($dataList as $kk => $vv) {
$skuObj = GoodSku::find($vv['attr_id']);
$dataList[$kk]['attr_id'] = $vv['attr_id'];
$dataList[$kk]['attr_val'] = $skuObj->attr_val;
}
}
......@@ -93,7 +101,7 @@ public function render()
$html .= '<input type="hidden" name="goods_id" value="' . $this->goods_id . '">';
$html .= '<input type="hidden" name="mgs_id" value="' . $mgs_id . '">';
$html .= '<input type="hidden" name="typeid" value="' . $this->type . '">';
$html .= '<td style="text-align:center;vertical-align: middle;">' . $goodObj->goods_name . '<input type="hidden" name="attr_id[]" value="' . $vv['id'] . '"></td>';
$html .= '<td style="text-align:center;vertical-align: middle;">' . $goodObj->goods_name . '<input type="hidden" name="attr_id[]" value="' . $vv['attr_id'] . '"></td>';
$html .= '<td style="text-align:center;vertical-align: middle;">' . $vv['attr_val'] . '</td>';
$html .= '<td ><input type="text" name="stock[]" value="" class="form-control field_remark _normal_" placeholder=""></td>';
$html .= '<td style="text-align:center;vertical-align: middle;">' . $vv['stock'] . '</td>';
......@@ -136,9 +144,12 @@ public function render()
->body(MerchantStoreForms::make(['id' => $this->type]))
->onShown(
<<<js
$("#storeTitle").html('{$this->title}');
$("#tabletr").html('"+ $html +"');
js
$(document).ready(function () {
console.log('{$html}');
$("#storeTitle").html('{$this->title}');
$("#tabletr").html('"+ $html +"');
});
js
);
//->button("<button class='btn btn-sm btn-primary'>$this->title</button>"); // 这个button就是对应上面的按钮
}
......
......@@ -19,8 +19,8 @@ public function index(Content $content)
->body(function (Row $row) {
$row->column(12, function (Column $column) {
$column->row(function (Row $row) {
$row->column(6, new Examples\NewUsers());
$row->column(6, new Examples\GoodsTotal());
$row->column(6, new Examples\OrderWaitCount());
$row->column(6, new Examples\OrderPickCount());
$row->column(12, new Examples\Product());
});
});
......
......@@ -3,7 +3,7 @@
namespace App\Admin\Forms;
use App\Models\GoodSku;
use App\Models\MerchantStore;
use App\Models\MerchantGoodsStore;
use App\Models\MerchantGoodSku;
use Dcat\Admin\Widgets\Form;
use Dcat\Admin\Layout\Row;
......@@ -37,6 +37,9 @@ public function handle(array $input)
if (!$goods_id || !$mgs_id || !$attr_ids || !$stocks) {
return $this->response()->error('参数错误')->refresh();
}
//商品库存信息
$msgObj = MerchantGoodsStore::find($mgs_id);
$merchant_id = $msgObj->merchant_id;
$logData = [];
if ($typeid == 1) {
foreach ($attr_ids as $kk => $vv) {
......@@ -51,6 +54,7 @@ public function handle(array $input)
} else {
$skuObj = new MerchantGoodSku();
$skuObj->mgs_id = $mgs_id;
$skuObj->merchant_id = $merchant_id;
$skuObj->goods_id = $goods_id;
$skuObj->attr_id = $vv;
$skuObj->stock = $stockNum;
......
......@@ -24,6 +24,17 @@ protected function init()
'30' => '最近30天',
'365' => '最近一年',
]);
#日期选择开始
$id = $this->id();
$this->datepicker($id)
->click("#{$id} .datepicker .btn-primary")
->addVariables([
'datepicker' => [
'start' => date('Y-m-d', strtotime('-7 days')),
'end' => date('Y-m-d', time()),
]
]);
}
/**
......
<?php
namespace App\Admin\Metrics\Examples;
use Dcat\Admin\Widgets\Metrics\Line;
use App\Models\OrderInfo;
use Illuminate\Http\Request;
use Dcat\Admin\widgets\Metrics\RadialBar;
use App\Traits\DatepickerTrait;
class OrderPickCount extends Line
{
use DatepickerTrait;
protected $view = "widgets.metrics.card";
/**
* 初始化卡片内容
*
* @return void
*/
protected function init()
{
parent::init();
$this->title('已取货总数');
#日期选择开始
$id = $this->id();
$this->datepicker($id)
->click("#{$id} .datepicker .btn-primary")
->addVariables([
'datepicker' => [
'start' => '', //date('Y-m-d', strtotime('-7 days')),
'end' => '', //date('Y-m-d', time()),
]
]);
}
/**
* 处理请求
*
* @param Request $request
*
* @return mixed|void
*/
public function handle(Request $request)
{
//dd($request->input());
$started = $request->get('started') ?? '';
$ended = $request->get('ended') ?? '';
switch ($request->get('option')) {
case '365':
case '30':
case '7':
default:
$count = OrderInfo::getNumDayData($started, $ended, [3, 4]);
// 卡片内容
$this->withContent($count);
// 图表数据
//$this->withChart($data['list']);
}
}
/**
* 设置图表数据.
*
* @param array $data
*
* @return $this
*/
public function withChart(array $data)
{
$series_data = [];
foreach ($data as $v) {
$series_data[] = $v;
}
return $this->chart([
'series' => [
[
'name' => $this->title,
'data' => $series_data,
],
],
'stroke' => [
'curve' => 'smooth'
],
]);
}
// public function withChart(array $data)
// {
// return $this->chart([
// 'series' => [
// [
// 'name' => $this->title,
// 'data' => $data,
// ],
// ],
// ]);
// }
/**
* 设置卡片内容.
*
* @param string $content
*
* @return $this
*/
public function withContent($content)
{
return $this->content(
<<<HTML
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
<h2 class="ml-1 font-lg-1">{$content}</h2>
</div>
HTML
);
}
}
<?php
namespace App\Admin\Metrics\Examples;
use Dcat\Admin\Widgets\Metrics\Line;
use App\Models\OrderInfo;
use Illuminate\Http\Request;
use Dcat\Admin\widgets\Metrics\RadialBar;
use App\Traits\DatepickerTrait;
class OrderWaitCount extends Line
{
use DatepickerTrait;
protected $view = "widgets.metrics.card";
/**
* 初始化卡片内容
*
* @return void
*/
protected function init()
{
parent::init();
$this->title('待取货总数');
#日期选择开始
$id = $this->id();
$this->datepicker($id)
->click("#{$id} .datepicker .btn-primary")
->addVariables([
'datepicker' => [
'start' => '', //date('Y-m-d', strtotime('-7 days')),
'end' => '', //date('Y-m-d', time()),
]
]);
}
/**
* 处理请求
*
* @param Request $request
*
* @return mixed|void
*/
public function handle(Request $request)
{
//dd($request->input());
$started = $request->get('started') ?? '';
$ended = $request->get('ended') ?? '';
switch ($request->get('option')) {
case '365':
case '30':
case '7':
default:
$count = OrderInfo::getNumDayData($started, $ended, [2]);
// 卡片内容
$this->withContent($count);
// 图表数据
//$this->withChart($data['list']);
}
}
/**
* 设置图表数据.
*
* @param array $data
*
* @return $this
*/
public function withChart(array $data)
{
$series_data = [];
foreach ($data as $v) {
$series_data[] = $v;
}
return $this->chart([
'series' => [
[
'name' => $this->title,
'data' => $series_data,
],
],
'stroke' => [
'curve' => 'smooth'
],
]);
}
// public function withChart(array $data)
// {
// return $this->chart([
// 'series' => [
// [
// 'name' => $this->title,
// 'data' => $data,
// ],
// ],
// ]);
// }
/**
* 设置卡片内容.
*
* @param string $content
*
* @return $this
*/
public function withContent($content)
{
return $this->content(
<<<HTML
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
<h2 class="ml-1 font-lg-1">{$content}</h2>
</div>
HTML
);
}
}
......@@ -6,6 +6,9 @@
use App\Handlers\FileUploadHandler;
use App\Models\Comment;
use App\Models\CommentTpl;
use App\Jobs\AutoCompleteOrder;
use App\Models\OrderGoods;
use App\Models\OrderInfo;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
......@@ -14,22 +17,40 @@ class CommentController extends BaseController
public function add(Request $request)
{
$useObj = $request->user();
$gid = $request->gid ?? 0;
$og_id = $request->og_id ?? 0;
$star = $request->star ?? 0;
$content = $request->content ?? '';
$ogObj = OrderGoods::find($og_id);
if (!$ogObj) {
return $this->JsonResponse('', '参数错误', 201);
}
$oid = $ogObj->order_id;
$orderObj = OrderInfo::find($oid);
DB::beginTransaction();
try {
$comObj = new Comment();
$comObj->goods_id = $gid;
$comObj->og_id = $og_id;
$comObj->goods_id = $ogObj->goods_id;
$comObj->star = $star;
$comObj->content = $content;
$comObj->nickname = $useObj->name;
$comObj->avatar = $useObj->avatar ?? '';
$comObj->phone = $useObj->phone;
$comObj->save();
if ($comObj->save()) {
//更新评论状态
$ogObj->is_comment = 1;
$ogObj->save();
}
DB::commit();
//2分钟执行订单分佣
$count = OrderGoods::where('order_id', $oid)->where('is_comment', 0)->count();
//Log::add('订单商品评论' . $og_id, ['num' => $count]);
if ($count == 0) {
$this->dispatch(new AutoCompleteOrder($orderObj, 120));
}
return $this->JsonResponse('');
} catch (\Exception $exception) {
Log::add('添加评论失败', $exception->getMessage());
......
......@@ -107,7 +107,7 @@ public function login(Request $request)
public function logout(Request $request)
{
$request->user()->tokens()->delete();
PersonalAccessToken::where(['tokenable_id' => $request->user()->id])->delete();
//PersonalAccessToken::where(['tokenable_id' => $request->user()->id])->delete();
return $this->JsonResponse('');
}
......
......@@ -2,9 +2,7 @@
namespace App\Http\Controllers\Api;
use App\Admin\Repositories\OrderInfo;
use App\Command\Log;
use App\Models\UserRefund;
use App\Models\Pay;
use App\Models\UserAddress;
use App\Models\Store;
......@@ -12,9 +10,8 @@
use App\Models\GoodSku;
use App\Models\OrderGoods;
use App\Models\OrderInfo as OrderInfoModel;
use App\Models\GoodsAttr as GoodsAttrModel;
use App\Models\UserApplyService as UserApplyServiceModel;
use App\Jobs\CancelOrder;
use App\Models\MerchantGoodSku;
use Dcat\Admin\Grid\Displayers\Orderable;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use League\CommonMark\Node\Query\OrExpr;
......@@ -111,6 +108,8 @@ public function CreateBuyOrder(Request $request)
$tmp['attr_id'] = $attr_id;
$tmp['goods_name'] = $goodObj->goods_name;
$tmp['goods_img'] = $goodObj->cover_img;
$tmp['merchant_id'] = $merchant_id;
$tmp['created_at'] = date("Y-m-d H:i:s");
array_push($orderGoods, $tmp);
//订单信息
$orderObj->order_sn = $order_sn;
......@@ -196,6 +195,8 @@ public function CreateOrder(Request $request)
$tmp['attr_id'] = $cartRow['attr_id'];
$tmp['goods_name'] = $goodsObj->goods_name;
$tmp['goods_img'] = $goods_img;
$tmp['merchant_id'] = $merchant_id;
$tmp['created_at'] = date("Y-m-d H:i:s");
array_push($orderGoods, $tmp);
//总价
$total_price += ((float)$cartRow['goods_price'] * (int)$cartRow['num']);
......@@ -282,12 +283,14 @@ public function orderList(Request $request)
$ogoods = OrderGoods::where(["order_id" => $item->id])->limit(1)->get();
foreach ($ogoods as $key => $valObj) {
$tmp = [];
$tmp['og_id'] = $valObj->id;
$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 : '';
$tmp['is_comment'] = $valObj->is_comment;
array_push($order_goods, $tmp);
}
$data['list'][] = [
......@@ -468,9 +471,34 @@ public function CheckoutCartOrder(Request $request)
}
//商户端首页统计
public function orderCollect()
public function orderCollect(Request $request)
{
return $this->JsonResponse($data = []);
$muser = $request->user();
$merchant_id = $muser->merchant_id;
//订单状态 0:待付款 1:待到货 2:待领取 3: 待评价 4:已完成 7:已取消 8:已退款
$where = ['merchant_id' => $merchant_id];
$firstDayOfMonth = date('Y-m-01 00:00:00'); // 00:00:00
$lastDayOfMonth = date("Y-m-t 23:59:59", time());
//本月数据统计
$currentMonth = [];
$currentMonth['buyCount'] = OrderInfoModel::where($where)->whereBetween('created_at', [$firstDayOfMonth, $lastDayOfMonth])->count();
$currentMonth['pickedCount'] = OrderInfoModel::where($where)->whereIn('order_status', [3, 4])->whereBetween('created_at', [$firstDayOfMonth, $lastDayOfMonth])->count();
$currentMonth['waitCount'] = OrderInfoModel::where($where)->where("order_status", 2)->whereBetween('created_at', [$firstDayOfMonth, $lastDayOfMonth])->count();
$currentStock = MerchantGoodSku::where($where)->sum('stock');
$currentMonth['stockCount'] = $currentStock;
//上月数据统计
$lastMonth = [];
if (date('d') < 10) {
$firstDayOfLastMonth = date('Y-m-01 00:00:00', strtotime('-1 month', time()));
$ninthDayOfLastMonth = date('Y-m-t 23:59:59', strtotime('-1 month', time()));
$lastMonth['buyCount'] = OrderInfoModel::where($where)->whereBetween('created_at', [$firstDayOfLastMonth, $ninthDayOfLastMonth])->count();
$lastMonth['pickedCount'] = OrderInfoModel::where($where)->whereIn('order_status', [3, 4])->whereBetween('created_at', [$firstDayOfLastMonth, $ninthDayOfLastMonth])->count();
$lastMonth['waitCount'] = OrderInfoModel::where($where)->where("order_status", 2)->whereBetween('created_at', [$firstDayOfLastMonth, $ninthDayOfLastMonth])->count();
//本月订单商品销量
$goods_number = OrderGoods::where('merchant_id', $merchant_id)->whereBetween('created_at', [$firstDayOfMonth, $lastDayOfMonth])->sum('goods_number');
$lastMonth['stockCount'] = $goods_number + $currentStock;
}
return $this->JsonResponse(['current' => $currentMonth, 'last' => $lastMonth]);
}
}
......@@ -5,6 +5,7 @@
use App\Command\Log;
use App\Handlers\FileUploadHandler;
use App\Models\Merchant;
use App\Models\Store;
use App\Models\StoreAdminUsers;
use App\Models\UserPermission;
use App\Models\PersonalAccessToken;
......@@ -61,7 +62,9 @@ public function info(Request $request)
$muser = $request->user();
$buycode = '';
$merchant_id = $muser->merchant_id;
$store_id = $muser->store_id;
$total_revenue = $balance = $cashout = 0;
$store_name = '';
if ($merchant_id) {
$merObj = Merchant::where('id', $merchant_id)->first();
$buycode = $merObj->buycode;
......@@ -69,9 +72,14 @@ public function info(Request $request)
$balance = $merObj->balance ?? 0;
$cashout = $total_revenue - $balance;
}
if ($store_id) {
$storeObj = Store::where('id', $store_id)->first();
$store_name = $storeObj->title;
}
return $this->JsonResponse([
'user_id' => $muser->id,
'username' => $muser->username,
'merchant_name' => $muser->name,
'avatar' => $muser->avatar ? env('IMAGE_URL') . $muser->avatar : '',
'merchant_id' => $muser->merchant_id,
'buycode' => $buycode,
......@@ -79,6 +87,7 @@ public function info(Request $request)
'balance' => $balance,
'cashout' => $cashout,
'role_id' => $muser->role_id,
'store_name' => $store_name
]);
}
}
......@@ -337,8 +337,8 @@ public function delUserAddress(Request $request)
public function share(Request $request)
{
$shuid = $request->spuid ?? 0;
$exist = User::find($shuid);
if (!$exist) {
$spObj = User::find($shuid);
if (!$spObj) {
return $this->JsonResponse('', '参数错误', 201);
}
......@@ -346,7 +346,8 @@ public function share(Request $request)
$user_id = $userObj->id;
$spuid = $userObj->spuid; //是否已有推荐人
if (!$spuid && $user_id != $shuid) {
$userObj->spuid = $shuid;
$userObj->spuid = $shuid; //直推
$userObj->second_spuid = $spObj->spuid; //间推
$userObj->save();
}
return $this->JsonResponse('');
......
<?php
namespace App\Jobs;
use App\Command\Log;
use App\Models\OrderDivideRecord;
use App\Models\Service;
use App\Models\StoreInfo;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\DB;
class AutoCompleteOrder implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $order;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($order, $delay)
{
$this->order = $order;
// 设置延迟的时间,delay() 方法的参数代表多少秒之后执行
$this->delay($delay);
}
/**
* * 定义这个任务类具体的执行逻辑
* 当队列处理器从队列中取出任务时,会调用 handle() 方法
* Execute the job.
*
* @return void
*/
public function handle()
{
if ($this->order->order_status != 3) { //待评价
return;
}
// 通过事务执行 sql
DB::beginTransaction();
try {
$this->order->order_status = 4; //已完成
$this->order->save();
//佣金分配
OrderDivideRecord::divide($this->order->id);
// switch ($this->order->business_id) {
// case 0:
// $this->order->store_order->status = 2;
// $this->order->store_order->over_time = date('Y-m-d H:i:s');
// $this->order->store_order->save();
// $store = StoreInfo::where(['store_id' => $this->order->store_order->store_id])->first();
// $store->total_revenue += $this->order->pay_money;
// $store->balance += $this->order->pay_money;
// $store->save();
// dispatch(new AutoCommentOrder($this->order, (3 * 24 * 3600)));
// break;
// case 1:
// case 2:
// case 3:
// case 4:
// case 5:
// $fcbl = Service::find($this->order->service_id)->fenmo ?? 0;
// //订单佣金分配
// Employee::divide($this->order->id, $this->order->em_id, $this->order->pay_money, $fcbl);
// dispatch(new AutoCommentOrder($this->order, (3 * 24 * 3600)));
// break;
// default:
// break;
// }
DB::commit();
//dispatch(new AutoCommentOrder($this->order, (3 * 24 * 3600)));
Log::add('订单自动完成', $this->order->toArray());
} catch (\Exception $exception) {
DB::rollBack();
Log::add('自动完成订单失败', $exception);
}
}
}
<?php
namespace App\Models;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model;
use App\Models\Store;
use App\Models\Merchant;
use App\Models\Good;
class MerchantGoodsStore extends Model
{
use HasDateTimeFormatter;
use SoftDeletes;
protected $table = 'merchat_goods_store';
public function store_desc()
{
return $this->hasMany(Store::class, 'merchant_id');
}
public function goods()
{
return $this->belongsTo(Good::class, 'goods_id');
}
public function merchant()
{
return $this->belongsTo(Merchant::class, 'merchant_id');
}
}
......@@ -2,6 +2,7 @@
namespace App\Models;
use App\Command\Log;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model;
......@@ -11,4 +12,70 @@ class OrderDivideRecord extends Model
use HasDateTimeFormatter;
use SoftDeletes;
protected $table = 'order_divide_record';
//收益分配
public static function divide($order_id)
{
$orderObj = OrderInfo::find($order_id);
$merchant_id = $orderObj->merchant_id; //绑定的商户
$user_id = $orderObj->user_id; //下单用户ID
$userObj = User::find($user_id);
$spuid = $userObj->spuid; //直推分享人
$second_spuid = $userObj->second_spuid; //间推分享人
$ogList = OrderGoods::where("order_id", $order_id)->get(); //订单商品
foreach ($ogList as $kk => $item) {
$goods_amount = $item->goods_price * $item->goods_number;
//商品信息
$goodObj = Good::find($item->goods_id);
$merchant_commission = $goodObj->merchant_commission;
$first_commission = $goodObj->first_commission;
$second_commission = $goodObj->second_commission;
//直推佣金
if ($spuid && $first_commission >= 1 && $first_commission < 100) {
$divide_price = number_format($goods_amount * ($first_commission / 100), 2);
//收益直接到直推账户
$spObj = User::find($spuid);
$spObj->total_revenue += $divide_price;
$spObj->balance += $divide_price;
$spObj->save();
self::addRecord($item->id, $order_id, $goods_amount, $divide_price, $first_commission, $spuid, 1);
}
//间推佣金
if ($second_spuid && $second_commission >= 1 && $second_commission < 100) {
$divide_price = number_format($goods_amount * ($second_commission / 100), 2);
//收益直接到直推账户
$spObj = User::find($second_spuid);
$spObj->total_revenue += $divide_price;
$spObj->balance += $divide_price;
$spObj->save();
self::addRecord($item->id, $order_id, $goods_amount, $divide_price, $second_commission, $second_spuid, 2);
}
//商户分佣记录
if ($merchant_id && $merchant_commission >= 1 && $merchant_commission < 100) {
$divide_price = number_format($goods_amount * ($merchant_commission / 100), 2);
//收益直接到商户账户
$merObj = Merchant::find($merchant_id);
$merObj->total_revenue += $divide_price;
$merObj->balance += $divide_price;
$merObj->save();
//记录
self::addRecord($item->id, $order_id, $goods_amount, $divide_price, $merchant_commission, $merchant_id, 3);
}
}
}
public function addRecord($og_id, $order_id, $goods_amount, $divide_price, $commission, $um_id, $sh_type)
{
$recordObj = new self();
$recordObj->order_id = $order_id;
$recordObj->og_id = $og_id;
$recordObj->order_price = $goods_amount;
$recordObj->divide_price = $divide_price;
$recordObj->proportion = $commission;
$recordObj->um_id = $um_id;
$recordObj->sh_type = $sh_type;
$recordObj->save();
Log::add('订单分佣记录', $recordObj->toArray());
}
}
......@@ -35,27 +35,31 @@ public function merchant()
return $this->belongsTo(Merchant::class, 'merchant_id');
}
//获取指定天数订单量
public static function getNumDayData($dayNum)
/**
* 获取指定天数订单量
* started 开始时间
* ended 截至时间
* status 订单状态
* merchant_id 商户ID
*/
public static function getNumDayData($started = '', $ended = '', $status = [], $merchant_id = 0)
{
$days = [date('Y-m-d')];
for ($i = 1; $i < $dayNum; $i++) {
$days[] = date("Y-m-d", strtotime("-$i day"));
}
$days = array_reverse($days);
$data = [
'total' => 0,
'list' => []
];
$where = [];
foreach ($days as $day) {
$startTime = $day . ' 00:00:00';
$endTime = $day . ' 23:59:59';
$count = self::whereBetween('created_at', [$startTime, $endTime])->where($where)->count();
$data['list'][$day] = $count;
$data['total'] += $count;
$sqlObj = new self();
if ($merchant_id) {
$where['merchant_id'] = $merchant_id;
}
return $data;
if ($status) {
$sqlObj = $sqlObj->whereIn('order_status', $status);
}
if ($started && $ended) {
$startTime = $started . ' 00:00:00';
$endTime = $ended . ' 23:59:59';
$sqlObj = $sqlObj->whereBetween('created_at', [$startTime, $endTime]);
}
$count = $sqlObj->where($where)->count();
return $count;
}
......
......@@ -2,7 +2,7 @@
namespace App\Store\Controllers;
use App\Models\StoreInfo;
use App\Models\Merchant;
use App\Store\Metrics\Examples;
use App\Http\Controllers\Controller;
use Dcat\Admin\Admin;
......@@ -25,6 +25,30 @@ public function index(Content $content)
// // $row->column(6, new Examples\GoodsTotal());
// $column->row(new Examples\Revenue());
// });
$day = date("d");
if ($day < 18) {
$row->column(12, function (Column $column) {
$content = "上月数据统计";
$column->row(new Card('', $content));
});
$row->column(6, function (Column $column) {
$column->row(function (Row $row) {
$row->column(6, new Examples\LastProductOrders());
$row->column(6, new Examples\LastStockTotal());
});
});
$row->column(6, function (Column $column) {
$column->row(function (Row $row) {
$row->column(6, new Examples\LastPickupTotal());
$row->column(6, new Examples\LastWaitPickTotal());
});
});
}
$row->column(12, function (Column $column) {
$content = "本月数据统计";
$column->row(new Card('', $content));
});
$row->column(6, function (Column $column) {
$column->row(function (Row $row) {
......@@ -35,28 +59,28 @@ public function index(Content $content)
$row->column(6, function (Column $column) {
$column->row(function (Row $row) {
$row->column(6, new Examples\PickupTotal('已取货状态'));
$row->column(6, new Examples\PickupTotal('待取货状态'));
$row->column(6, new Examples\WaitPickTotal('待取货状态'));
});
});
$row->column(6, function (Column $column) {
// $store = StoreInfo::where(['store_id'=>Admin::user()->id])->first();
// $total_revenue = $store->total_revenue > 1000 ? round(2,($store->total_revenue/1000)).' 千' : $store->total_revenue;
// $balance = $store->balance > 1000 ? round(2,($store->balance/1000)).' 千' : $store->balance;
// $freeze_balance = $store->freeze_balance > 1000 ? round(2,($store->freeze_balance/1000)).' 千' : $store->freeze_balance;
// $row->column(12, function (Column $column) {
// $store = Merchant::where(['id' => Admin::user()->id])->first();
// $total_revenue = $store->total_revenue > 1000 ? round(2, ($store->total_revenue / 1000)) . ' 千' : $store->total_revenue;
// $balance = $store->balance > 1000 ? round(2, ($store->balance / 1000)) . ' 千' : $store->balance;
// $freeze_balance = $store->freeze_balance > 1000 ? round(2, ($store->freeze_balance / 1000)) . ' 千' : $store->freeze_balance;
// $content = '<div style="height: 135px;display: flex;align-items: center;text-align: center;">
// <div style="flex: 1;display: flex;flex-direction: column;border-right: 1px solid #b9c3cd;">
// <h2 style="font-size: 25px;margin-top: 25px;">总收益</h2>
// <p style="color: orange;font-size: 45px;font-weight: bold;">'.$total_revenue.'</p>
// <p style="color: orange;font-size: 45px;font-weight: bold;">100</p>
// </div>
// <div style="flex: 1;display: flex;flex-direction: column;border-right: 1px solid #b9c3cd;">
// <h2 style="font-size: 25px;margin-top: 25px;">余额(可提现)</h2><p style="color:#21b978;font-size: 45px;font-weight: bold;">'.$balance.'</p>
// <h2 style="font-size: 25px;margin-top: 25px;">余额(可提现)</h2><p style="color:#21b978;font-size: 45px;font-weight: bold;">80</p>
// </div>
// <div style="flex: 1;display: flex;flex-direction: column;">
// <h2 style="font-size: 25px;margin-top: 25px;">冻结金额(提现中)</h2><p style="color: red;font-size: 45px;font-weight: bold;">'.$freeze_balance.'</p>
// <h2 style="font-size: 25px;margin-top: 25px;">冻结金额(提现中)</h2><p style="color: red;font-size: 45px;font-weight: bold;">' . $freeze_balance . '</p>
// </div></div>';
// $column->row(new Card('',$content));
});
// $column->row(new Card('', $content));
// });
$row->column(12, function (Column $column) {
......
<?php
namespace App\Store\Metrics\Examples;
use App\Models\OrderInfo as OrderInfoModel;
use Dcat\Admin\Widgets\Metrics\Card;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Dcat\Admin\Admin;
class LastPickupTotal extends Card
{
/**
* 卡片底部内容.
*
* @var string|Renderable|\Closure
*/
protected $footer;
/**
* 初始化卡片.
*/
protected function init()
{
parent::init();
$this->title('已取货状态');
}
/**
* 处理请求.
*
* @param Request $request
*
* @return void
*/
public function handle(Request $request)
{
switch ($request->get('option')) {
case '365':
case '1':
case '7':
case '60':
default:
$started = date('Y-m-01', strtotime('last month'));
$ended = date('Y-m-t', strtotime('last month'));
$order_status = [3, 4];
$count = OrderInfoModel::getNumDayData($started, $ended, $order_status, Admin::user()->id);
// 卡片内容
$this->withContent($count);
// 图表数据
//$this->withChart($data['list']);
}
}
/**
* 设置卡片底部内容.
*
* @param string|Renderable|\Closure $footer
*
* @return $this
*/
public function footer($footer)
{
$this->footer = $footer;
return $this;
}
/**
* 设置卡片内容.
*
* @param string $content
*
* @return $this
*/
public function withContent($content)
{
return $this->content(
<<<HTML
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
<h2 class="ml-1 font-lg-1">{$content}</h2>
</div>
HTML
);
}
}
<?php
namespace App\Store\Metrics\Examples;
use App\Models\OrderInfo as OrderInfoModel;
use Dcat\Admin\Widgets\Metrics\Card;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Dcat\Admin\Admin;
class LastProductOrders extends Card
{
/**
* 卡片底部内容.
*
* @var string|Renderable|\Closure
*/
protected $footer;
/**
* 初始化卡片.
*/
protected function init()
{
parent::init();
$this->title('用户已购买总数');
// $this->dropdown([
// '1' => '今天',
// '7' => '最近7天',
// '30' => '最近30天',
// '365' => '最近一年',
// ]);
}
/**
* 处理请求.
*
* @param Request $request
*
* @return void
*/
public function handle(Request $request)
{
switch ($request->get('option')) {
case '365':
case '30':
case '7':
default:
//上月
$started = date('Y-m-01', strtotime('last month'));
$ended = date('Y-m-t', strtotime('last month'));
$count = OrderInfoModel::getNumDayData($started, $ended, [2], Admin::user()->id);
// 卡片内容
$this->withContent($count);
// 图表数据
//$this->withChart($data['list']);
}
}
/**
* 设置卡片底部内容.
*
* @param string|Renderable|\Closure $footer
*
* @return $this
*/
public function footer($footer)
{
$this->footer = $footer;
return $this;
}
/**
* 设置卡片内容.
*
* @param string $content
*
* @return $this
*/
public function withContent($content)
{
return $this->content(
<<<HTML
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
<h2 class="ml-1 font-lg-1">{$content}</h2>
</div>
HTML
);
}
}
<?php
namespace App\Store\Metrics\Examples;
use App\Models\OrderInfo as OrderInfoModel;
use App\Models\MerchantGoodSku;
use App\Models\OrderGoods;
use Dcat\Admin\Widgets\Metrics\Card;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Dcat\Admin\Admin;
class LastStockTotal extends Card
{
/**
* 卡片底部内容.
*
* @var string|Renderable|\Closure
*/
protected $footer;
/**
* 初始化卡片.
*/
protected function init()
{
parent::init();
$this->title('库存剩余总数');
}
/**
* 处理请求.
*
* @param Request $request
*
* @return void
*/
public function handle(Request $request)
{
switch ($request->get('option')) {
case '365':
case '30':
case '7':
default:
$mer_id = Admin::user()->id;
$firstDayOfMonth = date('Y-m-01 00:00:00', strtotime('-1 month', time()));
$lastDayOfMonth = date('Y-m-t 23:59:59', strtotime('-1 month', time()));
$currentStock = MerchantGoodSku::where("merchant_id", $mer_id)->sum('stock');
//本月订单商品销量
$goods_number = OrderGoods::where('merchant_id', $mer_id)->whereBetween('created_at', [$firstDayOfMonth, $lastDayOfMonth])->sum('goods_number');
$total = $goods_number + $currentStock;
// 卡片内容
$this->withContent($total);
// 图表数据
//$this->withChart($data['list']);
}
}
/**
* 设置卡片内容.
*
* @param string $content
*
* @return $this
*/
public function withContent($content)
{
return $this->content(
<<<HTML
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
<h2 class="ml-1 font-lg-1">{$content}</h2>
</div>
HTML
);
}
}
<?php
namespace App\Store\Metrics\Examples;
use App\Models\OrderInfo as OrderInfoModel;
use Dcat\Admin\Widgets\Metrics\Card;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Dcat\Admin\Admin;
class LastWaitPickTotal extends Card
{
/**
* 卡片底部内容.
*
* @var string|Renderable|\Closure
*/
protected $footer;
/**
* 初始化卡片.
*/
protected function init()
{
parent::init();
$this->title('待取货状态');
}
/**
* 处理请求.
*
* @param Request $request
*
* @return void
*/
public function handle(Request $request)
{
switch ($request->get('option')) {
case '365':
case '1':
case '7':
default:
$started = date('Y-m-01', strtotime('last month'));
$ended = date('Y-m-t', strtotime('last month'));
$order_status = [2];
$count = OrderInfoModel::getNumDayData($started, $ended, $order_status, Admin::user()->id);
// 卡片内容
$this->withContent($count);
// 图表数据
//$this->withChart($data['list']);
}
}
/**
* 设置卡片底部内容.
*
* @param string|Renderable|\Closure $footer
*
* @return $this
*/
public function footer($footer)
{
$this->footer = $footer;
return $this;
}
/**
* 设置卡片内容.
*
* @param string $content
*
* @return $this
*/
public function withContent($content)
{
return $this->content(
<<<HTML
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
<h2 class="ml-1 font-lg-1">{$content}</h2>
</div>
HTML
);
}
}
......@@ -6,6 +6,7 @@
use Dcat\Admin\Widgets\Metrics\Card;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Dcat\Admin\Admin;
class PickupTotal extends Card
{
......@@ -18,6 +19,8 @@ class PickupTotal extends Card
protected $title;
protected $type;
public function __construct($title = null, $icon = null)
{
parent::__construct();
......@@ -32,13 +35,6 @@ protected function init()
parent::init();
$this->title($this->title);
$this->dropdown([
'30' => '最近30天',
'60' => '最近60天',
'1' => '今天',
'7' => '最近7天',
'365' => '最近一年',
]);
}
/**
......@@ -52,37 +48,17 @@ public function handle(Request $request)
{
switch ($request->get('option')) {
case '365':
$data = OrderInfoModel::getYearData();
// 卡片内容
$this->withContent($data['total']);
// 图表数据
//$this->withChart($data['list']);
break;
case '1':
$data = OrderInfoModel::getNumDayData(1);
// 卡片内容
$this->withContent($data['total']);
// 图表数据
//$this->withChart($data['list']);
break;
case '7':
$data = OrderInfoModel::getNumDayData(7);
// 卡片内容
$this->withContent($data['total']);
// 图表数据
//$this->withChart($data['list']);
break;
case '60':
$data = OrderInfoModel::getNumDayData(7);
// 卡片内容
$this->withContent($data['total']);
// 图表数据
//$this->withChart($data['list']);
break;
default:
$data = OrderInfoModel::getNumDayData(30);
$started = date("Y-m-01");
$ended = date("Y-m-t");
$order_status = [3, 4];
$count = OrderInfoModel::getNumDayData($started, $ended, $order_status, Admin::user()->id);
// 卡片内容
$this->withContent($data['total']);
$this->withContent($count);
// 图表数据
//$this->withChart($data['list']);
}
......
......@@ -6,6 +6,7 @@
use Dcat\Admin\Widgets\Metrics\Card;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Dcat\Admin\Admin;
class ProductOrders extends Card
{
......@@ -24,12 +25,12 @@ protected function init()
parent::init();
$this->title('用户已购买总数');
$this->dropdown([
'1' => '今天',
'7' => '最近7天',
'30' => '最近30天',
'365' => '最近一年',
]);
// $this->dropdown([
// '1' => '今天',
// '7' => '最近7天',
// '30' => '最近30天',
// '365' => '最近一年',
// ]);
}
/**
......@@ -43,30 +44,15 @@ public function handle(Request $request)
{
switch ($request->get('option')) {
case '365':
$data = OrderInfoModel::getYearData();
// 卡片内容
$this->withContent($data['total']);
// 图表数据
//$this->withChart($data['list']);
break;
case '30':
$data = OrderInfoModel::getNumDayData(30);
// 卡片内容
$this->withContent($data['total']);
// 图表数据
//$this->withChart($data['list']);
break;
case '7':
$data = OrderInfoModel::getNumDayData(7);
// 卡片内容
$this->withContent($data['total']);
// 图表数据
//$this->withChart($data['list']);
break;
default:
$data = OrderInfoModel::getNumDayData(1);
//本月
$started = date("Y-m-01");
$ended = date("Y-m-t");
$count = OrderInfoModel::getNumDayData($started, $ended, [2], Admin::user()->id);
// 卡片内容
$this->withContent($data['total']);
$this->withContent($count);
// 图表数据
//$this->withChart($data['list']);
}
......
......@@ -3,9 +3,11 @@
namespace App\Store\Metrics\Examples;
use App\Models\OrderInfo as OrderInfoModel;
use App\Models\MerchantGoodSku;
use Dcat\Admin\Widgets\Metrics\Card;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Dcat\Admin\Admin;
class StockTotal extends Card
{
......@@ -24,12 +26,6 @@ protected function init()
parent::init();
$this->title('库存剩余总数');
$this->dropdown([
'1' => '今天',
'7' => '最近7天',
'30' => '最近30天',
'365' => '最近一年',
]);
}
/**
......@@ -43,30 +39,13 @@ public function handle(Request $request)
{
switch ($request->get('option')) {
case '365':
$data = OrderInfoModel::getYearData();
// 卡片内容
$this->withContent($data['total']);
// 图表数据
//$this->withChart($data['list']);
break;
case '30':
$data = OrderInfoModel::getNumDayData(30);
// 卡片内容
$this->withContent($data['total']);
// 图表数据
//$this->withChart($data['list']);
break;
case '7':
$data = OrderInfoModel::getNumDayData(7);
// 卡片内容
$this->withContent($data['total']);
// 图表数据
//$this->withChart($data['list']);
break;
default:
$data = OrderInfoModel::getNumDayData(1);
$mer_id = Admin::user()->id;
$currentStock = MerchantGoodSku::where("merchant_id", $mer_id)->sum('stock');
// 卡片内容
$this->withContent($data['total']);
$this->withContent($currentStock);
// 图表数据
//$this->withChart($data['list']);
}
......
<?php
namespace App\Store\Metrics\Examples;
use App\Models\OrderInfo as OrderInfoModel;
use Dcat\Admin\Widgets\Metrics\Card;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Dcat\Admin\Admin;
class WaitPickTotal extends Card
{
/**
* 卡片底部内容.
*
* @var string|Renderable|\Closure
*/
protected $footer;
protected $title;
protected $type;
public function __construct($title = null, $icon = null)
{
parent::__construct();
$this->title = $title;
}
/**
* 初始化卡片.
*/
protected function init()
{
parent::init();
$this->title($this->title);
}
/**
* 处理请求.
*
* @param Request $request
*
* @return void
*/
public function handle(Request $request)
{
switch ($request->get('option')) {
case '365':
case '1':
case '7':
default:
$started = date("Y-m-01");
$ended = date("Y-m-t");
$order_status = [2];
$count = OrderInfoModel::getNumDayData($started, $ended, $order_status, Admin::user()->id);
// 卡片内容
$this->withContent($count);
// 图表数据
//$this->withChart($data['list']);
}
}
/**
* 设置卡片底部内容.
*
* @param string|Renderable|\Closure $footer
*
* @return $this
*/
public function footer($footer)
{
$this->footer = $footer;
return $this;
}
/**
* 设置卡片内容.
*
* @param string $content
*
* @return $this
*/
public function withContent($content)
{
return $this->content(
<<<HTML
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
<h2 class="ml-1 font-lg-1">{$content}</h2>
</div>
HTML
);
}
}
<?php
namespace App\Traits;
trait DatepickerTrait
{
protected $id = '';
/**
* 引入
* @param $formID
* @return $this
*/
public function datepicker($formID)
{
$this->id = $formID;
$this->file();
$this->script();
return $this;
}
/**
* 所需要的css js
*/
protected function file()
{
admin_css('/vendor/dcat-admin/dcat/plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.css');
admin_js('/vendor/dcat-admin/dcat/plugins/moment/moment-with-locales.min.js');
admin_js('/vendor/dcat-admin/dcat/plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js');
}
/**
* 绑定时间选择器点击事件
*/
protected function script()
{
admin_script(<<<JS
Dcat.init('#{$this->id} .datepicker .field_started', function (self, id) { var options = {"format":"YYYY-MM-DD","locale":"zh_CN"};
var last = $('#{$this->id} .datepicker .field_ended');
self.datetimepicker(options);
last.datetimepicker($.extend(options, {useCurrent: false}));
self.on("dp.change", function (e) {
last.data("DateTimePicker").minDate(e.date);
$("#{$this->id} .datepicker .btn-primary").data('started', $(this).val())
});
last.on("dp.change", function (e) {
self.data("DateTimePicker").maxDate(e.date);
$("#{$this->id} .datepicker .btn-primary").data('ended', $(this).val())
});
});
JS);
}
}
<div {!! $attributes !!}>
<div class="card-header d-flex justify-content-between align-items-start pb-0">
<div>
@if($icon)
<div class="avatar bg-rgba-{{ $style }} p-50 m-0">
<div class="avatar-content">
<i class="{{ $icon }} text-{{ $style }} font-medium-5"></i>
</div>
</div>
@endif
@if($title)
<h4 class="card-title mb-1">{!! $title !!}</h4>
@endif
<div class="metric-header">{!! $header !!}</div>
</div>
@if (! empty($subTitle))
<span class="btn btn-sm bg-light shadow-0 p-0">
{{ $subTitle }}
</span>
@endif
@if(! empty($dropdown))
<div class="dropdown chart-dropdown">
<button class="btn btn-sm btn-light shadow-0 dropdown-toggle p-0 waves-effect" data-toggle="dropdown">
{{ current($dropdown) }}
</button>
<div class="dropdown-menu dropdown-menu-right">
@foreach($dropdown as $key => $value)
<li class="dropdown-item"><a href="javascript:void(0)" class="select-option" data-option="{{ $key }}">{{ $value }}</a></li>
@endforeach
</div>
</div>
@endif
@if(! empty($datepicker))
<div class="col-md-9 datepicker">
<div class="row">
<div class="col-lg-5 pl-0">
<div class="input-group">
<span class="input-group-prepend">
<span class="input-group-text bg-white"><i class="feather icon-calendar"></i></span>
</span>
<input autocomplete="off" type="text" name="started" value="{{ $datepicker['start'] }}" class="form-control field_started" required="1" id="asdsss">
</div>
</div>
<div class="col-lg-5 pl-0">
<div class="input-group">
<span class="input-group-prepend">
<span class="input-group-text bg-white"><i class="feather icon-calendar"></i></span>
</span>
<input autocomplete="off" type="text" name="ended" value="{{ $datepicker['end'] }}" class="form-control field_ended" required="1" id="_35455a066a22a942">
</div>
</div>
<div class="col-lg-2 pl-0 pr-0">
<button class="btn btn-primary btn-outline-info" data-started="{{ $datepicker['start'] }}" data-ended="{{ $datepicker['end'] }}">
<span class="d-none d-sm-inline">查询</span>
</button>
</div>
</div>
</div>
@endif
</div>
<div class="metric-content">{!! $content !!}</div>
</div>
\ No newline at end of file
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