Index.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\water\WaterQuery;
  4. use FormBuilder\Json;
  5. use think\facade\Config;
  6. use app\admin\model\order\StoreOrder as StoreOrderModel;//订单
  7. use app\admin\model\system\{SystemConfig, SystemMenus, SystemRole};
  8. use app\admin\model\user\{User, UserExtract as UserExtractModel, User as UserModel};
  9. use app\admin\model\store\{StoreProduct, StoreProductReply as StoreProductReplyModel, StoreProduct as ProductModel};
  10. /**
  11. * 首页控制器
  12. * Class Index
  13. * @package app\admin\controller
  14. *
  15. */
  16. class Index extends AuthController
  17. {
  18. public function index()
  19. {
  20. //获取当前登录后台的管理员信息
  21. $adminInfo = $this->adminInfo->toArray();
  22. $roles = explode(',', $adminInfo['roles']);
  23. $site_logo = SystemConfig::getOneConfig('menu_name', 'site_logo')->toArray();
  24. $this->assign([
  25. 'menuList' => SystemMenus::menuList(),
  26. 'site_logo' => json_decode($site_logo['value'], true),
  27. 'new_order_audio_link' => sys_config('new_order_audio_link'),
  28. 'role_name' => SystemRole::where('id', $roles[0])->field('role_name')->find(),
  29. 'workermanPort' => Config::get('workerman.admin.port')
  30. ]);
  31. return $this->fetch();
  32. }
  33. //后台首页内容
  34. public function main()
  35. {
  36. /*首页第一行统计*/
  37. $now_month = strtotime(date('Y-m'));//本月
  38. $pre_month = strtotime(date('Y-m', strtotime('-1 month')));//上月
  39. $now_day = strtotime(date('Y-m-d'));//今日
  40. $pre_day = strtotime(date('Y-m-d', strtotime('-1 day')));//昨天时间戳
  41. $beforyester_day = strtotime(date('Y-m-d', strtotime('-2 day')));//前天时间戳
  42. //待发货数量
  43. $topData['orderDeliveryNum'] = StoreOrderModel::where('status', 0)
  44. ->where('paid', 1)
  45. ->where('refund_status', 0)
  46. ->where('shipping_type', 1)
  47. ->where('is_del', 0)
  48. ->count();
  49. //退换货订单数
  50. $topData['orderRefundNum'] = StoreOrderModel::where('paid', 1)
  51. ->where('refund_status', 'IN', '1')
  52. ->count();
  53. //库存预警
  54. $replenishment_num = sys_config('store_stock') > 0 ? sys_config('store_stock') : 20;//库存预警界限
  55. $topData['stockProduct'] = StoreProduct::where('stock', '<=', $replenishment_num)->where('is_show', 1)->where('is_del', 0)->count();
  56. //待处理提现
  57. $topData['treatedExtract'] = UserExtractModel::where('status', 0)->count();
  58. //订单数->昨日
  59. $now_day_order_p = StoreOrderModel::where('paid', 1)->whereTime('pay_time', 'yesterday')->count();
  60. $pre_day_order_p = StoreOrderModel::where('paid', 1)->where('pay_time', '>', $pre_day)->where('pay_time', '<', $now_day)->count();
  61. $first_line['d_num'] = [
  62. 'data' => $now_day_order_p ? $now_day_order_p : 0,
  63. 'percent' => abs($now_day_order_p - $pre_day_order_p),
  64. 'is_plus' => $now_day_order_p - $pre_day_order_p > 0 ? 1 : ($now_day_order_p - $pre_day_order_p == 0 ? -1 : 0)
  65. ];
  66. //交易额->昨天
  67. $now_month_order_p = StoreOrderModel::where('paid', 1)->whereTime('pay_time', 'yesterday')->sum('pay_price');
  68. $pre_month_order_p = StoreOrderModel::where('paid', 1)->where('pay_time', '>', $beforyester_day)->where('pay_time', '<', $pre_day)->sum('pay_price');
  69. $first_line['d_price'] = [
  70. 'data' => $now_month_order_p > 0 ? $now_month_order_p : 0,
  71. 'percent' => abs($now_month_order_p - $pre_month_order_p),
  72. 'is_plus' => $now_month_order_p - $pre_month_order_p > 0 ? 1 : ($now_month_order_p - $pre_month_order_p == 0 ? -1 : 0)
  73. ];
  74. //交易额->月
  75. $now_month_order_p = StoreOrderModel::where('paid', 1)->whereTime('pay_time', 'month')->sum('pay_price');
  76. $pre_month_order_p = StoreOrderModel::where('paid', 1)->where('pay_time', '>', $pre_month)->where('pay_time', '<', $now_month)->value('sum(pay_price)');
  77. $first_line['m_price'] = [
  78. 'data' => $now_month_order_p > 0 ? $now_month_order_p : 0,
  79. 'percent' => abs($now_month_order_p - $pre_month_order_p),
  80. 'is_plus' => $now_month_order_p - $pre_month_order_p > 0 ? 1 : ($now_month_order_p - $pre_month_order_p == 0 ? -1 : 0)
  81. ];
  82. //新粉丝->日
  83. $now_day_user = User::where('add_time', '>', $now_day)->count();
  84. $pre_day_user = User::where('add_time', '>', $pre_day)->where('add_time', '<', $now_day)->count();
  85. $pre_day_user = $pre_day_user ? $pre_day_user : 0;
  86. $first_line['day'] = [
  87. 'data' => $now_day_user ? $now_day_user : 0,
  88. 'percent' => abs($now_day_user - $pre_day_user),
  89. 'is_plus' => $now_day_user - $pre_day_user > 0 ? 1 : ($now_day_user - $pre_day_user == 0 ? -1 : 0)
  90. ];
  91. //新粉丝->月
  92. $now_month_user = User::where('add_time', '>', $now_month)->count();
  93. $pre_month_user = User::where('add_time', '>', $pre_month)->where('add_time', '<', $now_month)->count();
  94. $first_line['month'] = [
  95. 'data' => $now_month_user ? $now_month_user : 0,
  96. 'percent' => abs($now_month_user - $pre_month_user),
  97. 'is_plus' => $now_month_user - $pre_month_user > 0 ? 1 : ($now_month_user - $pre_month_user == 0 ? -1 : 0)
  98. ];
  99. //本月订单总数
  100. $now_order_info_c = StoreOrderModel::where('add_time', '>', $now_month)->count();
  101. $pre_order_info_c = StoreOrderModel::where('add_time', '>', $pre_month)->where('add_time', '<', $now_month)->count();
  102. $order_info['first'] = [
  103. 'data' => $now_order_info_c ? $now_order_info_c : 0,
  104. 'percent' => abs($now_order_info_c - $pre_order_info_c),
  105. 'is_plus' => $now_order_info_c - $pre_order_info_c > 0 ? 1 : ($now_order_info_c - $pre_order_info_c == 0 ? -1 : 0)
  106. ];
  107. //上月订单总数
  108. $second_now_month = strtotime(date('Y-m', strtotime('-1 month')));
  109. $second_pre_month = strtotime(date('Y-m', strtotime('-2 month')));
  110. $now_order_info_c = StoreOrderModel::where('add_time', '>', $pre_month)->where('add_time', '<', $now_month)->count();
  111. $pre_order_info_c = StoreOrderModel::where('add_time', '>', $second_pre_month)->where('add_time', '<', $second_now_month)->count();
  112. $order_info["second"] = [
  113. 'data' => $now_order_info_c ? $now_order_info_c : 0,
  114. 'percent' => abs($now_order_info_c - $pre_order_info_c),
  115. 'is_plus' => $now_order_info_c - $pre_order_info_c > 0 ? 1 : ($now_order_info_c - $pre_order_info_c == 0 ? -1 : 0)
  116. ];
  117. $second_line['order_info'] = $order_info;
  118. $this->assign([
  119. 'first_line' => $first_line,
  120. 'second_line' => $second_line,
  121. 'topData' => $topData,
  122. ]);
  123. return $this->fetch();
  124. }
  125. /**
  126. * 订单图表
  127. */
  128. public function orderchart()
  129. {
  130. header('Content-type:text/json');
  131. $cycle = $this->request->param('cycle') ?: 'thirtyday';//默认30天
  132. $datalist = [];
  133. switch ($cycle) {
  134. case 'thirtyday':
  135. $datebefor = date('Y-m-d', strtotime('-30 day'));
  136. $dateafter = date('Y-m-d');
  137. //上期
  138. $pre_datebefor = date('Y-m-d', strtotime('-60 day'));
  139. $pre_dateafter = date('Y-m-d', strtotime('-30 day'));
  140. for ($i = -30; $i < 0; $i++) {
  141. $datalist[date('m-d', strtotime($i . ' day'))] = date('m-d', strtotime($i . ' day'));
  142. }
  143. $order_list = WaterQuery::where('create_time', 'between time', [$datebefor, $dateafter])
  144. ->field("FROM_UNIXTIME(create_time,'%m-%d') as day,count(*) as count")
  145. ->group("FROM_UNIXTIME(create_time, '%Y%m%d')")
  146. ->order('create_time asc')
  147. ->select()->toArray();
  148. // if (empty($order_list)) return Json::fail('无数据');
  149. foreach ($order_list as $k => &$v) {
  150. $order_list[$v['day']] = $v;
  151. }
  152. $cycle_list = [];
  153. foreach ($datalist as $dk => $dd) {
  154. if (!empty($order_list[$dd])) {
  155. $cycle_list[$dd] = $order_list[$dd];
  156. } else {
  157. $cycle_list[$dd] = ['count' => 0, 'day' => $dd];
  158. }
  159. }
  160. $chartdata = [];
  161. $data = [];//临时
  162. $chartdata['yAxis']['maxnum'] = 0;//最大值数量
  163. foreach ($cycle_list as $k => $v) {
  164. $data['day'][] = $v['day'];
  165. $data['count'][] = $v['count'];
  166. if ($chartdata['yAxis']['maxnum'] < $v['count'])
  167. $chartdata['yAxis']['maxnum'] = $v['count'];//日最大订单数
  168. }
  169. $chartdata['legend'] = ['计算数'];//分类
  170. $chartdata['xAxis'] = $data['day'];//X轴值
  171. //,'itemStyle'=>$series
  172. $series = ['normal' => ['label' => ['show' => true, 'position' => 'top']]];
  173. $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['count']];//分类1值
  174. // //统计总数上期
  175. // $pre_total = StoreOrderModel::where('add_time', 'between time', [$pre_datebefor, $pre_dateafter])
  176. // ->field("count(*) as count,sum(pay_price) as price")
  177. // ->find();
  178. // if ($pre_total) {
  179. // $chartdata['pre_cycle']['count'] = [
  180. // 'data' => $pre_total['count'] ?: 0
  181. // ];
  182. // $chartdata['pre_cycle']['price'] = [
  183. // 'data' => $pre_total['price'] ?: 0
  184. // ];
  185. // }
  186. //
  187. // //统计总数
  188. // $total = StoreOrderModel::where('add_time', 'between time', [$datebefor, $dateafter])
  189. // ->field("count(*) as count,sum(pay_price) as price")
  190. // ->find();
  191. // if ($total) {
  192. // $cha_count = intval($pre_total['count']) - intval($total['count']);
  193. // //$pre_total['count'] = $pre_total['count'] == 0 ? 1 : $pre_total['count'];
  194. // $chartdata['cycle']['count'] = [
  195. // 'data' => $total['count'] ?: 0,
  196. // 'percent' => intval($pre_total['count']) == 0 ? 100 : round((abs($cha_count) / intval($pre_total['count']) * 100), 2),
  197. // 'is_plus' => $cha_count > 0 ? -1 : ($cha_count == 0 ? 0 : 1)
  198. // ];
  199. // $cha_price = round($pre_total['price'], 2) - round($total['price'], 2);
  200. // //$pre_total['price'] = $pre_total['price'] == 0 ? 1 : $pre_total['price'];
  201. // $chartdata['cycle']['price'] = [
  202. // 'data' => $total['price'] ?: 0,
  203. // 'percent' => (intval($pre_total['price']) == 0 || !$pre_total['price'] || $pre_total['price'] == 0.00) ? 100 : round(abs($cha_price) / $pre_total['price'] * 100, 2),
  204. // 'is_plus' => $cha_price > 0 ? -1 : ($cha_price == 0 ? 0 : 1)
  205. // ];
  206. // }
  207. return app('json')->success('ok', $chartdata);
  208. break;
  209. case 'week':
  210. $weekarray = array(['周日'], ['周一'], ['周二'], ['周三'], ['周四'], ['周五'], ['周六']);
  211. $datebefor = date('Y-m-d', strtotime('-1 week Monday'));
  212. $dateafter = date('Y-m-d', strtotime('-1 week Sunday'));
  213. $order_list = WaterQuery::where('create_time', 'between time', [$datebefor, $dateafter])
  214. ->field("FROM_UNIXTIME(create_time,'%w') as day,count(*) as count")
  215. ->group("FROM_UNIXTIME(create_time, '%Y%m%d')")
  216. ->order('create_time asc')
  217. ->select()->toArray();
  218. //数据查询重新处理
  219. $new_order_list = [];
  220. foreach ($order_list as $k => $v) {
  221. $new_order_list[$v['day']] = $v;
  222. }
  223. $now_datebefor = date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600));
  224. $now_dateafter = date('Y-m-d', strtotime("+1 day"));
  225. $now_order_list = WaterQuery::where('create_time', 'between time', [$now_datebefor, $now_dateafter])
  226. ->field("FROM_UNIXTIME(create_time,'%w') as day,count(*) as count")
  227. ->group("FROM_UNIXTIME(create_time, '%Y%m%d')")
  228. ->order('create_time asc')
  229. ->select()->toArray();
  230. //数据查询重新处理 key 变为当前值
  231. $new_now_order_list = [];
  232. foreach ($now_order_list as $k => $v) {
  233. $new_now_order_list[$v['day']] = $v;
  234. }
  235. foreach ($weekarray as $dk => $dd) {
  236. if (!empty($new_order_list[$dk])) {
  237. $weekarray[$dk]['pre'] = $new_order_list[$dk];
  238. } else {
  239. $weekarray[$dk]['pre'] = ['count' => 0, 'day' => $weekarray[$dk][0]];
  240. }
  241. if (!empty($new_now_order_list[$dk])) {
  242. $weekarray[$dk]['now'] = $new_now_order_list[$dk];
  243. } else {
  244. $weekarray[$dk]['now'] = ['count' => 0, 'day' => $weekarray[$dk][0]];
  245. }
  246. }
  247. $chartdata = [];
  248. $data = [];//临时
  249. $chartdata['yAxis']['maxnum'] = 0;//最大值数量
  250. $chartdata['yAxis']['maxprice'] = 0;//最大值金额
  251. foreach ($weekarray as $k => $v) {
  252. $data['day'][] = $v[0];
  253. $data['pre']['count'][] = $v['pre']['count'];
  254. // $data['pre']['price'][] = round($v['pre']['price'], 2);
  255. $data['now']['count'][] = $v['now']['count'];
  256. // $data['now']['price'][] = round($v['now']['price'], 2);
  257. if ($chartdata['yAxis']['maxnum'] < $v['pre']['count'] || $chartdata['yAxis']['maxnum'] < $v['now']['count']) {
  258. $chartdata['yAxis']['maxnum'] = $v['pre']['count'] > $v['now']['count'] ? $v['pre']['count'] : $v['now']['count'];//日最大订单数
  259. }
  260. // if ($chartdata['yAxis']['maxprice'] < $v['pre']['price'] || $chartdata['yAxis']['maxprice'] < $v['now']['price']) {
  261. // $chartdata['yAxis']['maxprice'] = $v['pre']['price'] > $v['now']['price'] ? $v['pre']['price'] : $v['now']['price'];//日最大金额
  262. // }
  263. }
  264. $chartdata['legend'] = ['本周订单数'];//分类
  265. $chartdata['xAxis'] = $data['day'];//X轴值
  266. //,'itemStyle'=>$series
  267. $series = ['normal' => ['label' => ['show' => true, 'position' => 'top']]];
  268. // $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['pre']['price']];//分类1值
  269. // $chartdata['series'][] = ['name' => $chartdata['legend'][1], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['now']['price']];//分类1值
  270. // $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'line', 'itemStyle' => $series, 'data' => $data['pre']['count']];//分类2值
  271. $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'line', 'itemStyle' => $series, 'data' => $data['now']['count']];//分类2值
  272. // //统计总数上期
  273. // $pre_total = StoreOrderModel::where('add_time', 'between time', [$datebefor, $dateafter])
  274. // ->field("count(*) as count,sum(pay_price) as price")
  275. // ->find();
  276. // if ($pre_total) {
  277. // $chartdata['pre_cycle']['count'] = [
  278. // 'data' => $pre_total['count'] ?: 0
  279. // ];
  280. // $chartdata['pre_cycle']['price'] = [
  281. // 'data' => $pre_total['price'] ?: 0
  282. // ];
  283. // }
  284. // //统计总数
  285. // $total = StoreOrderModel::where('add_time', 'between time', [$now_datebefor, $now_dateafter])
  286. // ->field("count(*) as count,sum(pay_price) as price")
  287. // ->find();
  288. // if ($total) {
  289. // $cha_count = intval($pre_total['count']) - intval($total['count']);
  290. // //$pre_total['count'] = $pre_total['count'] == 0 ? 1 : $pre_total['count'];
  291. // $chartdata['cycle']['count'] = [
  292. // 'data' => $total['count'] ?: 0,
  293. // 'percent' => intval($pre_total['count']) == 0 ? 100 : round((abs($cha_count) / intval($pre_total['count']) * 100), 2),
  294. // 'is_plus' => $cha_count > 0 ? -1 : ($cha_count == 0 ? 0 : 1)
  295. // ];
  296. // $cha_price = round($pre_total['price'], 2) - round($total['price'], 2);
  297. // //$pre_total['price'] = $pre_total['price'] == 0 ? 1 : $pre_total['price'];
  298. // $chartdata['cycle']['price'] = [
  299. // 'data' => $total['price'] ?: 0,
  300. // 'percent' => (intval($pre_total['price']) == 0 || !$pre_total['price'] || $pre_total['price'] == 0.00) ? 100 : round(abs($cha_price) / $pre_total['price'] * 100, 2),
  301. // 'is_plus' => $cha_price > 0 ? -1 : ($cha_price == 0 ? 0 : 1)
  302. // ];
  303. // }
  304. return app('json')->success('ok', $chartdata);
  305. break;
  306. case 'month':
  307. $weekarray = array('01' => ['1'], '02' => ['2'], '03' => ['3'], '04' => ['4'], '05' => ['5'], '06' => ['6'], '07' => ['7'], '08' => ['8'], '09' => ['9'], '10' => ['10'], '11' => ['11'], '12' => ['12'], '13' => ['13'], '14' => ['14'], '15' => ['15'], '16' => ['16'], '17' => ['17'], '18' => ['18'], '19' => ['19'], '20' => ['20'], '21' => ['21'], '22' => ['22'], '23' => ['23'], '24' => ['24'], '25' => ['25'], '26' => ['26'], '27' => ['27'], '28' => ['28'], '29' => ['29'], '30' => ['30'], '31' => ['31']);
  308. $datebefor = date('Y-m-01', strtotime('-1 month'));
  309. $dateafter = date('Y-m-d', strtotime(date('Y-m-01')));
  310. $order_list = WaterQuery::where('create_time', 'between time', [$datebefor, $dateafter])
  311. ->field("FROM_UNIXTIME(create_time,'%d') as day,count(*) as count")
  312. ->group("FROM_UNIXTIME(create_time, '%Y%m%d')")
  313. ->order('create_time asc')
  314. ->select()->toArray();
  315. //数据查询重新处理
  316. $new_order_list = [];
  317. foreach ($order_list as $k => $v) {
  318. $new_order_list[$v['day']] = $v;
  319. }
  320. $now_datebefor = date('Y-m-01');
  321. $now_dateafter = date('Y-m-d', strtotime("+1 day"));
  322. $now_order_list = WaterQuery::where('create_time', 'between time', [$now_datebefor, $now_dateafter])
  323. ->field("FROM_UNIXTIME(create_time,'%d') as day,count(*) as count")
  324. ->group("FROM_UNIXTIME(create_time, '%Y%m%d')")
  325. ->order('create_time asc')
  326. ->select()->toArray();
  327. //数据查询重新处理 key 变为当前值
  328. $new_now_order_list = [];
  329. foreach ($now_order_list as $k => $v) {
  330. $new_now_order_list[$v['day']] = $v;
  331. }
  332. foreach ($weekarray as $dk => $dd) {
  333. if (!empty($new_order_list[$dk])) {
  334. $weekarray[$dk]['pre'] = $new_order_list[$dk];
  335. } else {
  336. $weekarray[$dk]['pre'] = ['count' => 0, 'day' => $weekarray[$dk][0]];
  337. }
  338. if (!empty($new_now_order_list[$dk])) {
  339. $weekarray[$dk]['now'] = $new_now_order_list[$dk];
  340. } else {
  341. $weekarray[$dk]['now'] = ['count' => 0, 'day' => $weekarray[$dk][0]];
  342. }
  343. }
  344. $chartdata = [];
  345. $data = [];//临时
  346. $chartdata['yAxis']['maxnum'] = 0;//最大值数量
  347. $chartdata['yAxis']['maxprice'] = 0;//最大值金额
  348. foreach ($weekarray as $k => $v) {
  349. $data['day'][] = $v[0];
  350. $data['pre']['count'][] = $v['pre']['count'];
  351. // $data['pre']['price'][] = round($v['pre']['price'], 2);
  352. $data['now']['count'][] = $v['now']['count'];
  353. // $data['now']['price'][] = round($v['now']['price'], 2);
  354. if ($chartdata['yAxis']['maxnum'] < $v['pre']['count'] || $chartdata['yAxis']['maxnum'] < $v['now']['count']) {
  355. $chartdata['yAxis']['maxnum'] = $v['pre']['count'] > $v['now']['count'] ? $v['pre']['count'] : $v['now']['count'];//日最大订单数
  356. }
  357. // if ($chartdata['yAxis']['maxprice'] < $v['pre']['price'] || $chartdata['yAxis']['maxprice'] < $v['now']['price']) {
  358. // $chartdata['yAxis']['maxprice'] = $v['pre']['price'] > $v['now']['price'] ? $v['pre']['price'] : $v['now']['price'];//日最大金额
  359. // }
  360. }
  361. $chartdata['legend'] = ['上月订单数', '本月订单数'];//分类
  362. $chartdata['xAxis'] = $data['day'];//X轴值
  363. //,'itemStyle'=>$series
  364. $series = ['normal' => ['label' => ['show' => true, 'position' => 'top']]];
  365. // $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['pre']['price']];//分类1值
  366. // $chartdata['series'][] = ['name' => $chartdata['legend'][1], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['now']['price']];//分类1值
  367. $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'line', 'itemStyle' => $series, 'data' => $data['pre']['count']];//分类2值
  368. $chartdata['series'][] = ['name' => $chartdata['legend'][1], 'type' => 'line', 'itemStyle' => $series, 'data' => $data['now']['count']];//分类2值
  369. // //统计总数上期
  370. // $pre_total = StoreOrderModel::where('add_time', 'between time', [$datebefor, $dateafter])
  371. // ->field("count(*) as count,sum(pay_price) as price")
  372. // ->find();
  373. // if ($pre_total) {
  374. // $chartdata['pre_cycle']['count'] = [
  375. // 'data' => $pre_total['count'] ?: 0
  376. // ];
  377. // $chartdata['pre_cycle']['price'] = [
  378. // 'data' => $pre_total['price'] ?: 0
  379. // ];
  380. // }
  381. // //统计总数
  382. // $total = StoreOrderModel::where('add_time', 'between time', [$now_datebefor, $now_dateafter])
  383. // ->field("count(*) as count,sum(pay_price) as price")
  384. // ->find();
  385. // if ($total) {
  386. // $cha_count = intval($pre_total['count']) - intval($total['count']);
  387. // //$pre_total['count'] = $pre_total['count'] == 0 ? 1 : $pre_total['count'];
  388. // $chartdata['cycle']['count'] = [
  389. // 'data' => $total['count'] ?: 0,
  390. // 'percent' => intval($pre_total['count']) == 0 ? 100 : round((abs($cha_count) / intval($pre_total['count']) * 100), 2),
  391. // 'is_plus' => $cha_count > 0 ? -1 : ($cha_count == 0 ? 0 : 1)
  392. // ];
  393. // $cha_price = round($pre_total['price'], 2) - round($total['price'], 2);
  394. // //$pre_total['price'] = $pre_total['price'] == 0 ? 1 : $pre_total['price'];
  395. // $chartdata['cycle']['price'] = [
  396. // 'data' => $total['price'] ?: 0,
  397. // 'percent' => (intval($pre_total['price']) == 0 || !$pre_total['price'] || $pre_total['price'] == 0.00) ? 100 : round(abs($cha_price) / $pre_total['price'] * 100, 2),
  398. // 'is_plus' => $cha_price > 0 ? -1 : ($cha_price == 0 ? 0 : 1)
  399. // ];
  400. // }
  401. return app('json')->success('ok', $chartdata);
  402. break;
  403. case 'year':
  404. $weekarray = array('01' => ['一月'], '02' => ['二月'], '03' => ['三月'], '04' => ['四月'], '05' => ['五月'], '06' => ['六月'], '07' => ['七月'], '08' => ['八月'], '09' => ['九月'], '10' => ['十月'], '11' => ['十一月'], '12' => ['十二月']);
  405. $datebefor = date('Y-01-01', strtotime('-1 year'));
  406. $dateafter = date('Y-12-31', strtotime('-1 year'));
  407. $order_list = WaterQuery::where('create_time', 'between time', [$datebefor, $dateafter])
  408. ->field("FROM_UNIXTIME(create_time,'%m') as day,count(*) as count")
  409. ->group("FROM_UNIXTIME(create_time, '%Y%m%d')")
  410. ->order('create_time asc')
  411. ->select()->toArray();
  412. //数据查询重新处理
  413. $new_order_list = [];
  414. foreach ($order_list as $k => $v) {
  415. $new_order_list[$v['day']] = $v;
  416. }
  417. $now_datebefor = date('Y-01-01');
  418. $now_dateafter = date('Y-m-d');
  419. $now_order_list = WaterQuery::where('create_time', 'between time', [$now_datebefor, $now_dateafter])
  420. ->field("FROM_UNIXTIME(create_time,'%m') as day,count(*) as count")
  421. ->group("FROM_UNIXTIME(create_time, '%Y%m%d')")
  422. ->order('create_time asc')
  423. ->select()->toArray();
  424. //数据查询重新处理 key 变为当前值
  425. $new_now_order_list = [];
  426. foreach ($now_order_list as $k => $v) {
  427. $new_now_order_list[$v['day']] = $v;
  428. }
  429. foreach ($weekarray as $dk => $dd) {
  430. if (!empty($new_order_list[$dk])) {
  431. $weekarray[$dk]['pre'] = $new_order_list[$dk];
  432. } else {
  433. $weekarray[$dk]['pre'] = ['count' => 0, 'day' => $weekarray[$dk][0]];
  434. }
  435. if (!empty($new_now_order_list[$dk])) {
  436. $weekarray[$dk]['now'] = $new_now_order_list[$dk];
  437. } else {
  438. $weekarray[$dk]['now'] = ['count' => 0, 'day' => $weekarray[$dk][0]];
  439. }
  440. }
  441. $chartdata = [];
  442. $data = [];//临时
  443. $chartdata['yAxis']['maxnum'] = 0;//最大值数量
  444. $chartdata['yAxis']['maxprice'] = 0;//最大值金额
  445. foreach ($weekarray as $k => $v) {
  446. $data['day'][] = $v[0];
  447. $data['pre']['count'][] = $v['pre']['count'];
  448. // $data['pre']['price'][] = round($v['pre']['price'], 2);
  449. $data['now']['count'][] = $v['now']['count'];
  450. // $data['now']['price'][] = round($v['now']['price'], 2);
  451. if ($chartdata['yAxis']['maxnum'] < $v['pre']['count'] || $chartdata['yAxis']['maxnum'] < $v['now']['count']) {
  452. $chartdata['yAxis']['maxnum'] = $v['pre']['count'] > $v['now']['count'] ? $v['pre']['count'] : $v['now']['count'];//日最大订单数
  453. }
  454. // if ($chartdata['yAxis']['maxprice'] < $v['pre']['price'] || $chartdata['yAxis']['maxprice'] < $v['now']['price']) {
  455. // $chartdata['yAxis']['maxprice'] = $v['pre']['price'] > $v['now']['price'] ? $v['pre']['price'] : $v['now']['price'];//日最大金额
  456. // }
  457. }
  458. $chartdata['legend'] = ['去年订单数', '今年订单数'];//分类
  459. $chartdata['xAxis'] = $data['day'];//X轴值
  460. //,'itemStyle'=>$series
  461. $series = ['normal' => ['label' => ['show' => true, 'position' => 'top']]];
  462. // $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['pre']['price']];//分类1值
  463. // $chartdata['series'][] = ['name' => $chartdata['legend'][1], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['now']['price']];//分类1值
  464. $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'line', 'itemStyle' => $series, 'data' => $data['pre']['count']];//分类2值
  465. $chartdata['series'][] = ['name' => $chartdata['legend'][1], 'type' => 'line', 'itemStyle' => $series, 'data' => $data['now']['count']];//分类2值
  466. //统计总数上期
  467. // $pre_total = StoreOrderModel::where('add_time', 'between time', [$datebefor, $dateafter])
  468. // ->field("count(*) as count,sum(pay_price) as price")
  469. // ->find();
  470. // if ($pre_total) {
  471. // $chartdata['pre_cycle']['count'] = [
  472. // 'data' => $pre_total['count'] ?: 0
  473. // ];
  474. // $chartdata['pre_cycle']['price'] = [
  475. // 'data' => $pre_total['price'] ?: 0
  476. // ];
  477. // }
  478. // //统计总数
  479. // $total = StoreOrderModel::where('add_time', 'between time', [$now_datebefor, $now_dateafter])
  480. // ->field("count(*) as count,sum(pay_price) as price")
  481. // ->find();
  482. // if ($total) {
  483. // $cha_count = intval($pre_total['count']) - intval($total['count']);
  484. // //$pre_total['count'] = $pre_total['count'] == 0 ? 1 : $pre_total['count'];
  485. // $chartdata['cycle']['count'] = [
  486. // 'data' => $total['count'] ?: 0,
  487. // 'percent' => intval($pre_total['count']) == 0 ? 100 : round((abs($cha_count) / intval($pre_total['count']) * 100), 2),
  488. // 'is_plus' => $cha_count > 0 ? -1 : ($cha_count == 0 ? 0 : 1)
  489. // ];
  490. // $cha_price = round($pre_total['price'], 2) - round($total['price'], 2);
  491. // //$pre_total['price'] = $pre_total['price'] == 0 ? 1 : $pre_total['price'];
  492. // $chartdata['cycle']['price'] = [
  493. // 'data' => $total['price'] ?: 0,
  494. // 'percent' => (intval($pre_total['price']) == 0 || !$pre_total['price'] || $pre_total['price'] == 0.00) ? 100 : round(abs($cha_price) / $pre_total['price'] * 100, 2),
  495. // 'is_plus' => $cha_price > 0 ? -1 : ($cha_price == 0 ? 0 : 1)
  496. // ];
  497. // }
  498. return app('json')->success('ok', $chartdata);
  499. break;
  500. default:
  501. break;
  502. }
  503. }
  504. /**
  505. * 用户图表
  506. */
  507. public function userchart()
  508. {
  509. header('Content-type:text/json');
  510. $starday = date('Y-m-d', strtotime('-30 day'));
  511. $yesterday = date('Y-m-d');
  512. $user_list = UserModel::where('add_time', 'between time', [$starday, $yesterday])
  513. ->field("FROM_UNIXTIME(add_time,'%m-%e') as day,count(*) as count")
  514. ->group("FROM_UNIXTIME(add_time, '%Y%m%e')")
  515. ->order('add_time asc')
  516. ->select()->toArray();
  517. $chartdata = [];
  518. $data = [];
  519. $chartdata['legend'] = ['用户数'];//分类
  520. $chartdata['yAxis']['maxnum'] = 0;//最大值数量
  521. $chartdata['xAxis'] = [date('m-d')];//X轴值
  522. $chartdata['series'] = [0];//分类1值
  523. if (!empty($user_list)) {
  524. foreach ($user_list as $k => $v) {
  525. $data['day'][] = $v['day'];
  526. $data['count'][] = $v['count'];
  527. if ($chartdata['yAxis']['maxnum'] < $v['count'])
  528. $chartdata['yAxis']['maxnum'] = $v['count'];
  529. }
  530. $chartdata['xAxis'] = $data['day'];//X轴值
  531. $chartdata['series'] = $data['count'];//分类1值
  532. }
  533. return app('json')->success('ok', $chartdata);
  534. }
  535. /**
  536. * 待办事统计
  537. * @param int $newTime
  538. * @return false|string
  539. */
  540. public function Jnotice($newTime = 30)
  541. {
  542. header('Content-type:text/json');
  543. $data = [];
  544. $data['ordernum'] = StoreOrderModel::statusByWhere(1)->count();//待发货
  545. $replenishment_num = sys_config('store_stock') > 0 ? sys_config('store_stock') : 2;//库存预警界限
  546. $data['inventory'] = ProductModel::where('stock', '<=', $replenishment_num)->where('is_show', 1)->where('is_del', 0)->count();//库存
  547. $data['commentnum'] = StoreProductReplyModel::where('is_reply', 0)->count();//评论
  548. $data['reflectnum'] = UserExtractModel::where('status', 0)->count();;//提现
  549. $data['msgcount'] = intval($data['ordernum']) + intval($data['inventory']) + intval($data['commentnum']) + intval($data['reflectnum']);
  550. //新订单提醒
  551. $data['newOrderId'] = StoreOrderModel::statusByWhere(1)->where('is_remind', 0)->column('order_id', 'id');
  552. if (count($data['newOrderId'])) StoreOrderModel::where('order_id', 'in', $data['newOrderId'])->update(['is_remind' => 1]);
  553. return app('json')->success('ok', $data);
  554. }
  555. }