Stat.php 23 KB

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