Stat.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 数据层模型
  10. */
  11. class Stat extends BaseModel
  12. {
  13. public $page_info;
  14. /**
  15. * 查询新增会员统计
  16. * @access public
  17. * @author csdeshang
  18. * @param array $condition 条件
  19. * @param string $field 字段
  20. * @return array
  21. */
  22. public function statByMember($where, $field = '*', $pagesize = 0, $order = '', $group = '')
  23. {
  24. if ($pagesize) {
  25. $res = Db::name('member')->field($field)->where($where)->group($group)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  26. $this->page_info = $res;
  27. return $res->items();
  28. } else {
  29. return Db::name('member')->field($field)->where($where)->page($pagesize)->order($order)->group($group)->select()->toArray();
  30. }
  31. }
  32. /**
  33. * 查询单条会员统计
  34. * @access public
  35. * @author csdeshang
  36. * @param array $where 条件
  37. * @param string $field 字段
  38. * @param string $order 排序
  39. * @param string $group 分组
  40. * @return array
  41. */
  42. public function getOneByMember($where, $field = '*', $order = '', $group = '')
  43. {
  44. return Db::name('member')->field($field)->where($where)->order($order)->group($group)->find();
  45. }
  46. /**
  47. * 查询单条店铺统计
  48. * @access public
  49. * @author csdeshang
  50. * @param type $where 条件
  51. * @param type $field 字段
  52. * @param type $order 排序
  53. * @param type $group 分组
  54. * @return type
  55. */
  56. public function getOneByStore($where, $field = '*', $order = '', $group = '')
  57. {
  58. return Db::name('store')->field($field)->where($where)->order($order)->group($group)->find();
  59. }
  60. /**
  61. * 查询店铺统计
  62. * @access public
  63. * @author csdeshang
  64. * @param type $where 条件
  65. * @param type $field 字段
  66. * @param type $order 排序
  67. * @param type $group 分组
  68. * @return type
  69. */
  70. public function statByStore($where, $field = '*', $order = '', $group = '')
  71. {
  72. return Db::name('store')->field($field)->where($where)->group($group)->order($order)->select()->toArray();
  73. }
  74. /**
  75. * 查询新增店铺统计
  76. * @access public
  77. * @author csdeshang
  78. * @param array $condition 条件
  79. * @param string $field 字段
  80. * @param int $pagesize 分页
  81. * @param string $order 排序
  82. * @param int $limit 限制
  83. * @param sting $group 分组
  84. * @return array
  85. */
  86. public function getNewStoreStatList($condition, $field = '*', $pagesize = 0, $order = 'store_id desc', $limit = 0, $group = '')
  87. {
  88. if ($pagesize) {
  89. $res = Db::name('store')->field($field)->where($condition)->group($group)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  90. $this->page_info = $res;
  91. return $res->items();
  92. } else {
  93. return Db::name('store')->field($field)->where($condition)->group($group)->order($order)->limit($limit)->select()->toArray();
  94. }
  95. }
  96. /**
  97. * 查询会员列表
  98. * @access public
  99. * @author csdeshang
  100. * @param type $where 条件
  101. * @param type $field 字段
  102. * @param type $pagesize 分页
  103. * @param type $order 排序
  104. * @return type
  105. */
  106. public function getMemberList($where, $field = '*', $pagesize = 0, $order = 'member_id desc')
  107. {
  108. if ($pagesize) {
  109. $res = Db::name('member')->field($field)->where($where)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  110. $this->page_info = $res;
  111. return $res->items();
  112. } else {
  113. return Db::name('member')->field($field)->where($where)->order($order)->select()->toArray();
  114. }
  115. }
  116. /**
  117. * 调取店铺等级信息
  118. * @access public
  119. * @author csdeshang
  120. * @return type
  121. */
  122. public function getStoreDegree()
  123. {
  124. $tmp = Db::name('storegrade')->field('storegrade_id,storegrade_name')->where(true)->select()->toArray();
  125. $sd_list = array();
  126. if (!empty($tmp)) {
  127. foreach ($tmp as $k => $v) {
  128. $sd_list[$v['storegrade_id']] = $v['storegrade_name'];
  129. }
  130. }
  131. return $sd_list;
  132. }
  133. /**
  134. * 查询会员统计数据记录
  135. * @access public
  136. * @author csdeshang
  137. * @param type $where 条件
  138. * @param type $field 字段
  139. * @param type $pagesize 分页
  140. * @param type $limit 限制
  141. * @param type $order 排序
  142. * @param type $group 分组
  143. * @return array
  144. */
  145. public function statByStatmember($where, $field = '*', $pagesize = 0, $limit = 0, $order = '', $group = '')
  146. {
  147. if ($pagesize) {
  148. $res = Db::name('statmember')->field($field)->where($where)->limit($limit)->order($order)->group($group)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  149. $this->page_info = $res;
  150. return $res->items();
  151. } else {
  152. return Db::name('statmember')->field($field)->where($where)->limit($limit)->order($order)->group($group)->select()->toArray();
  153. }
  154. }
  155. /**
  156. * 查询商品数量
  157. * @access public
  158. * @author csdeshang
  159. * @param type $where 条件
  160. * @return type
  161. */
  162. public function getGoodsNum($where)
  163. {
  164. $rs = Db::name('goodscommon')->field('count(*) as allnum')->where($where)->select()->toArray();
  165. return $rs[0]['allnum'];
  166. }
  167. /**
  168. * 获取预存款数据
  169. * @access public
  170. * @author csdeshang
  171. * @param type $condition 条件
  172. * @param type $field 字段
  173. * @param type $pagesize 分页
  174. * @param type $order 排序
  175. * @param type $limit 限制
  176. * @param type $group 分组
  177. * @return type
  178. */
  179. public function getPredepositInfo($condition, $field = '*', $pagesize = 0, $order = 'lg_addtime desc', $limit = 0, $group = '')
  180. {
  181. if ($pagesize) {
  182. $res = Db::name('pdlog')->field($field)->where($condition)->group($group)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  183. $this->page_info = $res;
  184. return $res->items();
  185. } else {
  186. return Db::name('pdlog')->field($field)->where($condition)->group($group)->order($order)->limit($limit)->select()->toArray();
  187. }
  188. }
  189. /**
  190. * 获取结算数据
  191. * @access public
  192. * @author csdeshang
  193. * @param type $condition 条件
  194. * @param type $type 类型
  195. * @param type $have_page 判断分页
  196. * @return type
  197. */
  198. public function getBillList($condition, $type, $have_page = true)
  199. {
  200. switch ($type) {
  201. case 'os': //平台
  202. return Db::name('orderstatis')->field('sum(os_order_totals) as oot,sum(os_order_returntotals) as oort,sum(os_commis_totals-os_commis_returntotals) as oct,sum(os_store_costtotals) as osct,sum(os_result_totals) as ort')->where($condition)->select()->toArray();
  203. break;
  204. case 'ob': //店铺
  205. $pagesize = $have_page ? 15 : '';
  206. $result = Db::name('orderbill')->alias('order_bill')->join('store store', 'order_bill.ob_store_id=store.store_id', 'left')->field('order_bill.*,store.member_name')->where($condition)->order('ob_no desc');
  207. if ($have_page) {
  208. $result = $result->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  209. $this->page_info = $result;
  210. return $result->items();
  211. } else {
  212. $result = $result->select()->toArray();
  213. return $result;
  214. }
  215. break;
  216. }
  217. }
  218. /**
  219. * 查询订单及订单商品的统计
  220. * @access public
  221. * @author csdeshang
  222. * @param type $where 条件
  223. * @param type $field 字段
  224. * @param type $pagesize 分页
  225. * @param type $limit 限制
  226. * @param type $order 排序
  227. * @param type $group 分组
  228. * @return type
  229. */
  230. public function statByOrderGoods($where, $field = '*', $pagesize = 0, $limit = 0, $order = '', $group = '')
  231. {
  232. if ($pagesize) {
  233. $res = Db::name('ordergoods')->alias('ordergoods')->field($field)->join('order order', 'ordergoods.order_id=order.order_id', 'left')->where($where)->group($group)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  234. $this->page_info = $res;
  235. return $res->items();
  236. } else {
  237. return Db::name('ordergoods')->alias('ordergoods')->field($field)->join('order order', 'ordergoods.order_id=order.order_id', 'left')->where($where)->group($group)->order($order)->select()->toArray();
  238. }
  239. }
  240. /**
  241. * 查询订单及订单商品的统计
  242. * @access public
  243. * @author csdeshang
  244. * @param type $where 条件
  245. * @param type $field 字段
  246. * @param type $pagesize 分页
  247. * @param type $limit 限制
  248. * @param type $order 排序
  249. * @param type $group 分组
  250. * @return type
  251. */
  252. public function statByOrderLog($where, $field = '*', $pagesize = 0, $limit = 0, $order = '', $group = '')
  253. {
  254. if ($pagesize) {
  255. $res = Db::name('orderlog')->alias('orderlog')->field($field)->join('order order', 'orderlog.order_id = order.order_id', 'left')->where($where)->group($group)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  256. $this->page_info = $res;
  257. return $res->items();
  258. } else {
  259. return Db::name('orderlog')->alias('orderlog')->field($field)->join('order order', 'orderlog.order_id = order.order_id', 'left')->where($where)->group($group)->order($order)->select()->toArray();
  260. }
  261. }
  262. /**
  263. * 查询退款退货统计
  264. * @access public
  265. * @author csdeshang
  266. * @param type $where 条件
  267. * @param type $field 字段
  268. * @param type $pagesize 分页
  269. * @param type $limit 限制
  270. * @param type $order 排序
  271. * @param type $group 分组
  272. * @return type
  273. */
  274. public function statByRefundreturn($where, $field = '*', $pagesize = 0, $limit = 0, $order = '', $group = '')
  275. {
  276. if ($pagesize) {
  277. $res = Db::name('refundreturn')->field($field)->where($where)->group($group)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  278. $this->page_info = $res;
  279. return $res->items();
  280. } else {
  281. return Db::name('refundreturn')->field($field)->where($where)->group($group)->order($order)->limit($limit)->select()->toArray();
  282. }
  283. }
  284. /**
  285. * 查询店铺动态评分统计
  286. * @access public
  287. * @author csdeshang
  288. * @param type $where 条件
  289. * @param type $field 字段
  290. * @param type $pagesize 分页
  291. * @param type $limit 限制
  292. * @param type $order 排序
  293. * @param type $group 分组
  294. * @return type
  295. */
  296. public function statByStoreAndEvaluatestore($where, $field = '*', $pagesize = 0, $limit = 0, $order = '', $group = '')
  297. {
  298. if ($pagesize) {
  299. $res = Db::name('evaluatestore')->alias('evaluatestore')->field($field)->join('store store', 'evaluatestore.seval_storeid=store.store_id', 'left')->where($where)->group($group)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  300. $this->page_info = $res;
  301. return $res->items();
  302. } else {
  303. return Db::name('evaluatestore')->alias('evaluatestore')->field($field)->join('store store', 'evaluatestore.seval_storeid=store.store_id', 'left')->where($where)->group($group)->order($order)->select()->toArray();
  304. }
  305. }
  306. /**
  307. * 处理搜索时间
  308. * @access public
  309. * @author csdeshang
  310. * @param type $search_arr 搜索数组
  311. * @return type
  312. */
  313. public function dealwithSearchTime($search_arr)
  314. {
  315. //初始化时间
  316. //天
  317. if (!isset($search_arr['search_time'])) {
  318. $search_arr['search_time'] = date('Y-m-d', TIMESTAMP - 86400);
  319. }
  320. $search_arr['day']['search_time'] = strtotime($search_arr['search_time']); //搜索的时间
  321. //周
  322. if (!isset($search_arr['searchweek_year'])) {
  323. $search_arr['searchweek_year'] = date('Y', TIMESTAMP);
  324. }
  325. if (!isset($search_arr['searchweek_month'])) {
  326. $search_arr['searchweek_month'] = date('m', TIMESTAMP);
  327. }
  328. if (!isset($search_arr['searchweek_week'])) {
  329. $search_arr['searchweek_week'] = implode('|', getWeek_SdateAndEdate(TIMESTAMP));
  330. }
  331. $weekcurrent_year = $search_arr['searchweek_year'];
  332. $weekcurrent_month = $search_arr['searchweek_month'];
  333. $weekcurrent_week = $search_arr['searchweek_week'];
  334. $search_arr['week']['current_year'] = $weekcurrent_year;
  335. $search_arr['week']['current_month'] = $weekcurrent_month;
  336. $search_arr['week']['current_week'] = $weekcurrent_week;
  337. //月
  338. if (!isset($search_arr['searchmonth_year'])) {
  339. $search_arr['searchmonth_year'] = date('Y', TIMESTAMP);
  340. }
  341. if (!isset($search_arr['searchmonth_month'])) {
  342. $search_arr['searchmonth_month'] = date('m', TIMESTAMP);
  343. }
  344. $monthcurrent_year = $search_arr['searchmonth_year'];
  345. $monthcurrent_month = $search_arr['searchmonth_month'];
  346. $search_arr['month']['current_year'] = $monthcurrent_year;
  347. $search_arr['month']['current_month'] = $monthcurrent_month;
  348. return $search_arr;
  349. }
  350. /**
  351. * 获得查询的开始和结束时间
  352. * @access public
  353. * @author csdeshang
  354. * @param type $search_arr 搜索数组
  355. * @return type
  356. */
  357. public function getStarttimeAndEndtime($search_arr)
  358. {
  359. $stime = array();
  360. $etime = array();
  361. if (isset($search_arr['search_type']) && $search_arr['search_type'] == 'day') {
  362. $stime = $search_arr['day']['search_time']; //今天0点
  363. $etime = $search_arr['day']['search_time'] + 86400 - 1; //今天24点
  364. }
  365. if (isset($search_arr['search_type']) && $search_arr['search_type'] == 'week') {
  366. $current_weekarr = explode('|', $search_arr['week']['current_week']);
  367. $stime = strtotime($current_weekarr[0]);
  368. $etime = strtotime($current_weekarr[1]) + 86400 - 1;
  369. }
  370. if (isset($search_arr['search_type']) && $search_arr['search_type'] == 'month') {
  371. $stime = strtotime($search_arr['month']['current_year'] . '-' . $search_arr['month']['current_month'] . "-01 0 month");
  372. $etime = getMonthLastDay($search_arr['month']['current_year'], $search_arr['month']['current_month']) + 86400 - 1;
  373. }
  374. return array($stime, $etime);
  375. }
  376. /**
  377. * 查询会员统计数据单条记录
  378. * @access public
  379. * @author csdeshang
  380. * @param type $where 条件
  381. * @param type $field 字段
  382. * @param type $order 排序
  383. * @param type $group 分组
  384. * @return type
  385. */
  386. public function getOneStatmember($where, $field = '*', $order = '', $group = '')
  387. {
  388. return Db::name('statmember')->field($field)->where($where)->group($group)->order($order)->find();
  389. }
  390. /**
  391. * 更新会员统计数据单条记录
  392. * @access public
  393. * @author csdeshang
  394. * @param type $where 条件
  395. * @param type $update_arr 更新数据
  396. * @return type
  397. */
  398. public function editStatmember($where, $update_arr)
  399. {
  400. return Db::name('statmember')->where($where)->update($update_arr);
  401. }
  402. /**
  403. * 查询订单的统计
  404. * @access public
  405. * @author csdeshang
  406. * @param array $where 条件
  407. * @param string $field 字段
  408. * @param int $pagesize 分页
  409. * @param int $limit 限制
  410. * @param string $order 排序
  411. * @return array
  412. */
  413. public function statByOrder($where, $field = '*', $pagesize = 0, $limit = 0, $order = '')
  414. {
  415. if ($pagesize) {
  416. $res = Db::name('order')->field($field)->where($where)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  417. $this->page_info = $res;
  418. return $res->items();
  419. } else {
  420. return Db::name('order')->field($field)->where($where)->order($order)->select()->toArray();
  421. }
  422. }
  423. /**
  424. * 查询积分的统计
  425. * @access public
  426. * @author csdeshang
  427. * @param array $where 条件
  428. * @param string $field 字段
  429. * @param int $pagesize 分页
  430. * @param int $limit 限制
  431. * @param string $order 排序
  432. * @param string $group 分组
  433. */
  434. public function statByPointslog($where, $field = '*', $pagesize = 0, $limit = 0, $order = '', $group = '')
  435. {
  436. if ($pagesize) {
  437. $res = Db::name('pointslog')->field($field)->where($where)->group($group)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  438. $this->page_info = $res;
  439. return $res->items();
  440. } else {
  441. return Db::name('pointslog')->field($field)->where($where)->group($group)->order($order)->select()->toArray();
  442. }
  443. }
  444. /**
  445. * 删除会员统计数据记录
  446. * @access public
  447. * @author csdeshang
  448. * @param type $where 条件数组
  449. */
  450. public function delByStatmember($where = array())
  451. {
  452. Db::name('statmember')->where($where)->delete();
  453. }
  454. /**
  455. * 查询订单商品缓存的统计
  456. * @access public
  457. * @author csdeshang
  458. * @param type $where 条件
  459. * @param type $field 字段
  460. * @param type $order 排序
  461. * @param type $group 分组
  462. * @return type
  463. */
  464. public function getoneByStatordergoods($where, $field = '*', $order = '', $group = '')
  465. {
  466. return Db::name('statordergoods')->field($field)->where($where)->group($group)->order($order)->find();
  467. }
  468. /**
  469. * 查询订单商品缓存的统计
  470. * @access public
  471. * @author csdeshang
  472. * @param type $where 条件
  473. * @param type $field 字段
  474. * @param type $pagesize 分页
  475. * @param type $limit 限制
  476. * @param type $order 排序
  477. * @param type $group 分组
  478. * @return type
  479. */
  480. public function statByStatordergoods($where, $field = '*', $pagesize = 0, $limit = 0, $order = '', $group = '')
  481. {
  482. if ($pagesize) {
  483. $res = Db::name('statordergoods')->field($field)->where($where)->group($group)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  484. $this->page_info = $res;
  485. return $res->items();
  486. } else {
  487. return Db::name('statordergoods')->field($field)->where($where)->group($group)->order($order)->limit($limit)->select()->toArray();
  488. }
  489. }
  490. /**
  491. * 查询订单缓存的统计
  492. * @access public
  493. * @author csdeshang
  494. * @param array $where 条件
  495. * @param string $field 字段
  496. * @param string $order 排序
  497. * @param string $group 分组
  498. * @return array
  499. */
  500. public function getoneByStatorder($where, $field = '*', $order = '', $group = '')
  501. {
  502. return Db::name('statorder')->field($field)->where($where)->group($group)->order($order)->find();
  503. }
  504. /**
  505. * 查询订单缓存的统计
  506. * @access public
  507. * @author csdeshang
  508. * @param type $where 条件
  509. * @param type $field 字段
  510. * @param type $pagesize 分页
  511. * @param type $limit 限制
  512. * @param type $order 排序
  513. * @param type $group 分组
  514. * @return type
  515. */
  516. public function statByStatorder($where, $field = '*', $pagesize = 0, $limit = 0, $order = '', $group = '')
  517. {
  518. if ($pagesize) {
  519. $res = Db::name('statorder')->field($field)->where($where)->group($group)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  520. $this->page_info = $res;
  521. return $res->items();
  522. } else {
  523. return Db::name('statorder')->field($field)->where($where)->group($group)->order($order)->limit($limit)->select()->toArray();
  524. }
  525. }
  526. /**
  527. * 查询商品列表
  528. * @access public
  529. * @author csdeshang
  530. * @param type $where 条件
  531. * @param type $field 字段
  532. * @param type $pagesize 分页
  533. * @param type $limit 限制
  534. * @param type $order 排序
  535. * @param type $group 分组
  536. * @return type
  537. */
  538. public function statByGoods($where, $field = '*', $pagesize = 0, $limit = 0, $order = '', $group = '')
  539. {
  540. if ($pagesize) {
  541. $res = Db::name('goods')->field($field)->where($where)->group($group)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  542. $this->page_info = $res;
  543. return $res->items();
  544. } else {
  545. return Db::name('goods')->field($field)->where($where)->group($group)->order($order)->select()->toArray();
  546. }
  547. }
  548. /**
  549. * 查询流量统计单条记录
  550. * @access public
  551. * @author csdeshang
  552. * @param type $tablename 表名
  553. * @param type $where 条件
  554. * @param type $field 字段
  555. * @param type $order 排序
  556. * @param type $group 分组
  557. * @return type
  558. */
  559. public function getoneByFlowstat($tablename = 'flowstat', $where, $field = '*', $order = '', $group = '')
  560. {
  561. return Db::name($tablename)->field($field)->where($where)->group($group)->order($order)->find();
  562. }
  563. /**
  564. * 查询流量统计记录
  565. * @access public
  566. * @author csdeshang
  567. * @param string $tablename 表名
  568. * @param array $where 条件
  569. * @param string $field 字段
  570. * @param int $pagesize 分页
  571. * @param int $limit 限制
  572. * @param string $order 排序
  573. * @param string $group 分组
  574. * @return array
  575. */
  576. public function statByFlowstat($tablename = 'flowstat', $where, $field = '*', $pagesize = 0, $limit = 0, $order = '', $group = '')
  577. {
  578. if ($pagesize) {
  579. $res = Db::name($tablename)->field($field)->where($where)->group($group)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  580. $this->page_info = $res;
  581. return $res->items();
  582. } else {
  583. return Db::name($tablename)->field($field)->where($where)->group($group)->order($order)->limit($limit)->select()->toArray();
  584. }
  585. }
  586. }