store.table.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. class StoreTable extends We7Table {
  8. public function searchGoodsList($type = '', $pageindex, $pagesize) {
  9. $this->query->from('site_store_goods');
  10. if (!empty($type)) {
  11. $this->query->where('type', $type);
  12. }
  13. $goods_list = array(
  14. 'goods_list' => $this->searchWithPage($pageindex, $pagesize)->getall('id'),
  15. 'total' => $this->getLastQueryTotal()
  16. );
  17. return $goods_list;
  18. }
  19. public function searchAccountBuyGoods($uniacid, $type) {
  20. $this->query->from('site_store_goods', 'g')
  21. ->leftjoin('site_store_order', 'r')
  22. ->on(array('g.id' => 'r.goodsid'))
  23. ->where('g.type', $type)
  24. ->where('r.type', STORE_ORDER_FINISH);
  25. if ($type == STORE_TYPE_API) {
  26. $number_list = $this->query->where('r.uniacid', $uniacid)->select('(g.api_num * r.duration) as number')->getall('number');
  27. return array_sum(array_keys($number_list));
  28. } else{
  29. $this->query->where(function ($query) use ($uniacid) {
  30. $query->where('r.uniacid', $uniacid)->whereor('r.wxapp', $uniacid);
  31. });
  32. load()->model('store');
  33. $all_type = store_goods_type_info();
  34. if ($all_type[$type]['group'] == 'module') {
  35. $keyfield = 'module';
  36. } else {
  37. $type_name = array(
  38. STORE_TYPE_PACKAGE => 'module_group',
  39. );
  40. $keyfield = empty($type_name[$type]) ? '' : $type_name[$type];
  41. }
  42. return $this->query->getall($keyfield);
  43. }
  44. }
  45. public function searchWithEndtime() {
  46. $this->query->where('r.endtime >=', time());
  47. return $this;
  48. }
  49. public function searchWithKeyword($title) {
  50. if (!empty($title)) {
  51. $this->query->where('title LIKE', "%{$title}%");
  52. return $this;
  53. }
  54. }
  55. public function searchWithStatus($status) {
  56. $status = intval($status) > 0 ? 1 : 0;
  57. $this->query->where('status', $status);
  58. return $this;
  59. }
  60. public function searchWithLetter($letter) {
  61. if (!empty($letter)) {
  62. $this->query->where('title_initial LIKE', "%{$letter}%");
  63. return $this;
  64. }
  65. }
  66. public function searchWithIsWish($is_wish) {
  67. $this->query->where('is_wish', $is_wish);
  68. return $this;
  69. }
  70. public function searchWithOrderid($orderid) {
  71. if (!empty($orderid)) {
  72. $this->query->where('orderid', $orderid);
  73. return $this;
  74. }
  75. return true;
  76. }
  77. public function goodsInfo($id) {
  78. return $this->query->from('site_store_goods')->where('id', $id)->getall('id');
  79. }
  80. public function searchOrderList($pageindex = 0, $pagesize = 0) {
  81. $this->query->from('site_store_order')->where('type <>', STORE_GOODS_STATUS_DELETE);
  82. if (!empty($pageindex) && !empty($pagesize)) {
  83. $this->searchWithPage($pageindex, $pagesize);
  84. }
  85. $lists = $this->query->orderby('id', 'desc')->getall();
  86. return $lists;
  87. }
  88. public function searchOrderType($type, $ortype = 0) {
  89. $type = intval($type);
  90. if (!empty($ortype)) {
  91. $ortype = intval($ortype);
  92. }
  93. if (!empty($ortype)) {
  94. $this->query->where('type in', array($type, $ortype));
  95. } else {
  96. $this->query->where('type', $type);
  97. }
  98. return $this;
  99. }
  100. public function searchOrderInfo($id) {
  101. return $this->query->from('site_store_order')->where('id', $id)->getall('id');
  102. }
  103. public function searchOrderWithUid($uid) {
  104. $uid = intval($uid);
  105. $this->query->where('buyerid', $uid);
  106. return $this;
  107. }
  108. public function searchHaveModule($type = STORE_TYPE_MODULE) {
  109. $this->query->from('site_store_goods');
  110. $result = $this->query->where('type', $type)->where('status !=', STORE_GOODS_STATUS_DELETE)->getall();
  111. return $result;
  112. }
  113. public function apiOrderWithUniacid($uniacid)
  114. {
  115. $this->query->from ('site_store_order', 'r')->leftjoin ('site_store_goods', 'g')->select ('r.duration, g.api_num, g.price')
  116. ->on (array ('r.goodsid' => 'g.id'))->where ('g.type', STORE_TYPE_API)->where ('uniacid', $uniacid)->where ('type', STORE_ORDER_FINISH);
  117. $list = $this->query->getall ();
  118. return $list;
  119. }
  120. public function StoreCreateAccountInfo($uniacid) {
  121. return $this->query->from('site_store_create_account')->where('uniacid', $uniacid)->get();
  122. }
  123. public function searchUserBuyAccount($uid) {
  124. $sql = "SELECT SUM(b.account_num) FROM " . tablename('site_store_order') . " as a left join " . tablename('site_store_goods') . " as b on a.goodsid = b.id WHERE a.buyerid = :buyerid AND a.type = 3 AND b.type = 2" ;
  125. $count = pdo_fetchcolumn($sql, array(':buyerid' => $uid));
  126. $isdeleted_account_sql = "SELECT COUNT(*) FROM " . tablename('site_store_create_account') . " as a LEFT JOIN " . tablename('account') . " as b ON a.uniacid = b.uniacid WHERE a.uid = :uid AND a.type = 1 AND (b.isdeleted = 1 OR b.uniacid is NULL)";
  127. $deleted_account = pdo_fetchcolumn($isdeleted_account_sql, array(':uid' => $uid));
  128. return $count - $deleted_account;
  129. }
  130. public function searchUserBuyWxapp($uid) {
  131. $sql = "SELECT SUM(b.wxapp_num) FROM " . tablename('site_store_order') . " as a left join " . tablename('site_store_goods') . " as b on a.goodsid = b.id WHERE a.buyerid = :buyerid AND a.type = 3 AND b.type = 3" ;
  132. $count = pdo_fetchcolumn($sql, array(':buyerid' => $uid));
  133. $isdeleted_account_sql = "SELECT COUNT(*) FROM " . tablename('site_store_create_account') . " as a LEFT JOIN " . tablename('account') . " as b ON a.uniacid = b.uniacid WHERE a.uid = :uid AND a.type = 4 AND (b.isdeleted = 1 OR b.uniacid is NULL)";
  134. $deleted_account = pdo_fetchcolumn($isdeleted_account_sql, array(':uid' => $uid));
  135. return $count - $deleted_account;
  136. }
  137. public function searchUserBuyPackage($uniacid) {
  138. $sql = "SELECT * FROM " . tablename('site_store_order') . " as a left join " . tablename('site_store_goods') . " as b on a.goodsid = b.id WHERE (a.uniacid = :uniacid OR a.wxapp = :wxapp) AND a.type = 3 AND b.type = 5" ;
  139. return pdo_fetchall($sql, array(':uniacid' => $uniacid, ':wxapp' => $uniacid), 'module_group');
  140. }
  141. public function searchUserCreateAccountNum($uid) {
  142. $count = $this->query->from('site_store_create_account', 'a')->leftjoin('account', 'b')->on('a.uniacid', 'b.uniacid')->where('a.uid', $uid)->where('b.type', 1)->select('count(*) as count')->get('count');
  143. return $count['count'];
  144. }
  145. public function searchUserCreateWxappNum($uid) {
  146. $count = $this->query->from('site_store_create_account', 'a')->leftjoin('account', 'b')->on('a.uniacid', 'b.uniacid')->where('a.uid', $uid)->where('b.type', 4)->select('count(*) as count')->get('count');
  147. return $count['count'];
  148. }
  149. public function searchPaymentsOrder() {
  150. return $this->query->from('site_store_order', 'a')->leftjoin('site_store_goods', 'b')->on('a.goodsid', 'b.id')->where('a.type', 3)->orderby('a.createtime', 'desc')->select(array('a.id', 'a.createtime', 'b.title', 'a.orderid', 'b.type', 'a.amount'))->getall();
  151. }
  152. public function getStatisticsOrderInfoByDate($starttime, $endtime) {
  153. $sql = "SELECT COUNT(id) AS total_orders, SUM(amount) AS total_amounts FROM " . tablename('site_store_order') . " WHERE type=3 AND createtime >= :starttime AND createtime <= :endtime";
  154. return pdo_fetch($sql, array(':starttime' => $starttime, ':endtime' => $endtime));
  155. }
  156. }