链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
3.2 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Admin\Metrics\Examples\ServiceCard;
  3. use App\Models\ImsCjdcStore;
  4. use App\Models\LanzuMmInfo;
  5. use App\Models\LanzuStore;
  6. use Dcat\Admin\Admin;
  7. use Dcat\Admin\Widgets\Metrics\Card;
  8. use Illuminate\Http\Request;
  9. class TotalStore extends Card
  10. {
  11. protected $title;
  12. protected $market_id;
  13. public function __construct($market_id=null,$title = null, $icon = null)
  14. {
  15. $this->title = $title;
  16. $this->market_id = $market_id;
  17. parent::__construct($title, $icon);
  18. }
  19. protected function init()
  20. {
  21. parent::init();
  22. $this->dropdown([
  23. '0'=>'全部',
  24. '1'=>'今日新增',
  25. '-1'=>'昨日新增',
  26. '7'=>'过去一周新增',
  27. '30'=>'本月新增',
  28. '-30'=>'上月新增'
  29. ]);
  30. }
  31. public function handle(Request $request)
  32. {
  33. $type = $request->get('option');//数据选项
  34. $market_id = $request->get('market_id');//市场id
  35. $this->content($this->storeNum($type,$market_id));
  36. }
  37. public function storeBuild($type=null,$marketId=null)
  38. {
  39. $where = ['status'=>2];
  40. if ($marketId){
  41. if (is_array($marketId)){
  42. $where[] = ['in'=>['market_id'=>$marketId]];
  43. }else{
  44. $where['market_id'] = $marketId;
  45. }
  46. }
  47. switch ($type){
  48. case '1':
  49. $beginTime=mktime(0,0,0,date('m'),date('d'),date('Y'));
  50. $endTime=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
  51. break;
  52. case '-1':
  53. $beginTime=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
  54. $endTime=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
  55. break;
  56. case '7':
  57. $beginTime=mktime(0,0,0,date('m'),date('d')-7,date('Y'));
  58. $endTime=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
  59. break;
  60. case '30':
  61. $beginTime=mktime(0,0,0,date('m'),1,date('Y'));
  62. $endTime=mktime(23,59,59,date('m'),date('t'),date('Y'));
  63. break;
  64. case '-30':
  65. $beginTime=mktime(0,0,0,date('m')-1,1,date('Y'));
  66. $endTime=strtotime(date("Y-m-d H:i:s",mktime(23,59,59,date("m") ,0,date("Y"))));
  67. break;
  68. default:
  69. $beginTime=0;
  70. $endTime=999999999999999;
  71. break;
  72. }
  73. $build = LanzuStore
  74. ::whereBetween('created_at',[$beginTime,$endTime])
  75. ->where($where);
  76. return $build;
  77. }
  78. public function storeNum($type,$marketId)
  79. {
  80. $build = $this->storeBuild($type,$marketId);
  81. $result = $build->count();
  82. return $result;
  83. }
  84. // 传递自定义参数到 handle 方法
  85. public function parameters() : array
  86. {
  87. return [
  88. 'market_id'=>$this->market_id,
  89. ];
  90. }
  91. public function renderContent()
  92. {
  93. $content = parent::renderContent();
  94. return <<<HTML
  95. <div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
  96. <h2 class="ml-1 font-large-1 text-primary">{$content}</h2>
  97. </div>
  98. HTML;
  99. }
  100. }