diff --git a/app/Admin/Controllers/HomeController.php b/app/Admin/Controllers/HomeController.php index 1eeef89..6922a72 100644 --- a/app/Admin/Controllers/HomeController.php +++ b/app/Admin/Controllers/HomeController.php @@ -68,8 +68,8 @@ class HomeController extends Controller $column->row(new Examples\Community\TotalAmount(Admin::user()->id,Type::BALANCE_USER_TYPE_MP)); }); - $row->column(3, function (Column $column) { - $column->row(new Examples\ServiceCard\TotalStore()); + $row->column(3, function (Column $column)use ($marketIds) { + $column->row(new Examples\ServiceCard\TotalStore($marketIds,'商户数')); }); $row->column(3, function (Column $column)use ($marketIds) { $column->row(new Examples\Order\OrderData('number',$marketIds,'订单数')); diff --git a/app/Admin/Metrics/Examples/ServiceCard/TotalStore.php b/app/Admin/Metrics/Examples/ServiceCard/TotalStore.php index 09f7225..d4eb5ab 100644 --- a/app/Admin/Metrics/Examples/ServiceCard/TotalStore.php +++ b/app/Admin/Metrics/Examples/ServiceCard/TotalStore.php @@ -9,29 +9,99 @@ use App\Models\LanzuMmInfo; use App\Models\LanzuStore; use Dcat\Admin\Admin; use Dcat\Admin\Widgets\Metrics\Card; +use Illuminate\Http\Request; class TotalStore extends Card { + protected $title; + protected $market_id; + public function __construct($market_id=null,$title = null, $icon = null) + { + $this->title = $title; + $this->market_id = $market_id; + parent::__construct($title, $icon); + } protected function init() { parent::init(); - $this->title = '商户数'; - $aud = Admin::user(); - $count = 0; - if ($aud->isRole('lanzu_mm')){ - $mm = LanzuMmInfo::where('admin_user_id',$aud->id)->first(); - if ($mm){ - $count = ImsCjdcStore::where('mm_user_id',$mm->user_id)->count(); + $this->dropdown([ + '0'=>'全部', + '1'=>'今日新增', + '-1'=>'昨日新增', + '7'=>'过去一周新增', + '30'=>'本月新增', + '-30'=>'上月新增' + ]); + } + + public function handle(Request $request) + { + $type = $request->get('option');//数据选项 + $market_id = $request->get('market_id');//市场id + $this->content($this->storeNum($type,$market_id)); + } + + public function storeBuild($type=null,$marketId=null) + { + $where = ['status'=>2]; + if ($marketId){ + if (is_array($marketId)){ + $where[] = ['in'=>['market_id'=>$marketId]]; + }else{ + $where['market_id'] = $marketId; } - }elseif($aud->isRole('lanzu_mp')){ - $count = ImsCjdcStore::count(); - }else{ - $count = ImsCjdcStore::count(); } - $this->content($count); + switch ($type){ + case '1': + $beginTime=mktime(0,0,0,date('m'),date('d'),date('Y')); + $endTime=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1; + break; + case '-1': + $beginTime=mktime(0,0,0,date('m'),date('d')-1,date('Y')); + $endTime=mktime(0,0,0,date('m'),date('d'),date('Y'))-1; + break; + case '7': + $beginTime=mktime(0,0,0,date('m'),date('d')-7,date('Y')); + $endTime=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1; + break; + case '30': + $beginTime=mktime(0,0,0,date('m'),1,date('Y')); + $endTime=mktime(23,59,59,date('m'),date('t'),date('Y')); + break; + case '-30': + $beginTime=mktime(0,0,0,date('m')-1,1,date('Y')); + $endTime=strtotime(date("Y-m-d H:i:s",mktime(23,59,59,date("m") ,0,date("Y")))); + break; + default: + $beginTime=0; + $endTime=999999999999999; + break; + } + + $build = LanzuStore + ::whereBetween('created_at',[$beginTime,$endTime]) + ->where($where); + return $build; + } + + + public function storeNum($type,$marketId) + { + $build = $this->storeBuild($type,$marketId); + $result = $build->count(); + return $result; } + // 传递自定义参数到 handle 方法 + public function parameters() : array + { + return [ + 'market_id'=>$this->market_id, + ]; + } + + public function renderContent() { $content = parent::renderContent();