人人商城

store.table.php 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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)->query->where('status !=', STORE_GOODS_STATUS_DELETE)->getall('id'),
  15. 'total' => $this->getLastQueryTotal()
  16. );
  17. return $goods_list;
  18. }
  19. public function searchAccountBuyGoods($uniacid, $type) {
  20. $type_name = array(
  21. STORE_TYPE_MODULE => 'module',
  22. STORE_TYPE_WXAPP_MODULE => 'module',
  23. STORE_TYPE_PACKAGE => 'module_group',
  24. STORE_TYPE_API => '(g.api_num * r.duration) as number',
  25. );
  26. if ($type == STORE_TYPE_API) {
  27. $number_list = $this->query->from('site_store_goods', 'g')->leftjoin('site_store_order', 'r')->on(array('g.id' => 'r.goodsid'))->where('r.uniacid', $uniacid)->where('g.type', $type)->where('r.type', STORE_ORDER_FINISH)->select($type_name[$type])->getall('number');
  28. return array_sum(array_keys($number_list));
  29. } else{
  30. $this->query->from('site_store_goods', 'g')
  31. ->leftjoin('site_store_order', 'r')
  32. ->on(array('g.id' => 'r.goodsid'))
  33. ->where('g.type', $type)
  34. ->where('r.type', STORE_ORDER_FINISH)
  35. ->where('r.type <>', STORE_ORDER_DEACTIVATE)
  36. ->where(function ($query) use ($uniacid) {
  37. $query->where('r.uniacid', $uniacid)->whereor('r.wxapp', $uniacid);
  38. });
  39. return $this->query->getall($type_name[$type]);
  40. }
  41. }
  42. public function searchWithEndtime() {
  43. $this->query->where('r.endtime >=', time());
  44. return $this;
  45. }
  46. public function searchWithKeyword($title) {
  47. if (!empty($title)) {
  48. $this->query->where('title LIKE', "%{$title}%");
  49. return $this;
  50. }
  51. }
  52. public function searchWithStatus($status) {
  53. $status = intval($status) > 0 ? 1 : 0;
  54. $this->query->where('status', $status);
  55. return $this;
  56. }
  57. public function searchWithLetter($letter) {
  58. if (!empty($letter)) {
  59. $this->query->where('title_initial LIKE', "%{$letter}%");
  60. return $this;
  61. }
  62. }
  63. public function searchWithOrderid($orderid) {
  64. if (!empty($orderid)) {
  65. $this->query->where('orderid', $orderid);
  66. return $this;
  67. }
  68. return true;
  69. }
  70. public function goodsInfo($id) {
  71. $id = intval($id);
  72. $this->query->from('site_store_goods')->where('id', $id);
  73. return $this->query->get();
  74. }
  75. public function searchOrderList($pageindex = 0, $pagesize = 0) {
  76. $this->query->from('site_store_order')->where('type <>', STORE_GOODS_STATUS_DELETE);
  77. if (!empty($pageindex) && !empty($pagesize)) {
  78. $this->searchWithPage($pageindex, $pagesize);
  79. }
  80. $lists = $this->query->orderby('id', 'desc')->getall();
  81. return $lists;
  82. }
  83. public function searchOrderType($type, $ortype = 0) {
  84. $type = intval($type);
  85. if (!empty($ortype)) {
  86. $ortype = intval($ortype);
  87. }
  88. if (!empty($ortype)) {
  89. $this->query->where('type in', array($type, $ortype));
  90. } else {
  91. $this->query->where('type', $type);
  92. }
  93. return $this;
  94. }
  95. public function searchOrderInfo($id) {
  96. $id = intval($id);
  97. $result = $this->query->from('site_store_order')->where('id', $id)->get();
  98. return $result;
  99. }
  100. public function searchOrderWithUid($uid) {
  101. $uid = intval($uid);
  102. $this->query->where('buyerid', $uid);
  103. return $this;
  104. }
  105. public function searchHaveModule($type = STORE_TYPE_MODULE) {
  106. $this->query->from('site_store_goods');
  107. $result = $this->query->where('type', $type)->where('status !=', STORE_GOODS_STATUS_DELETE)->getall('module');
  108. return $result;
  109. }
  110. public function apiOrderWithUniacid($uniacid)
  111. {
  112. $this->query->from ('site_store_order', 'r')->leftjoin ('site_store_goods', 'g')->select ('r.duration, g.api_num, g.price')
  113. ->on (array ('r.goodsid' => 'g.id'))->where ('g.type', STORE_TYPE_API)->where ('uniacid', $uniacid)->where ('type', STORE_ORDER_FINISH);
  114. $list = $this->query->getall ();
  115. return $list;
  116. }
  117. public function StoreCreateAccountInfo($uniacid) {
  118. return $this->query->from('site_store_create_account')->where('uniacid', $uniacid)->get();
  119. }
  120. public function searchUserBuyAccount($uid) {
  121. $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" ;
  122. $count = pdo_fetchcolumn($sql, array(':buyerid' => $uid));
  123. $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)";
  124. $deleted_account = pdo_fetchcolumn($isdeleted_account_sql, array(':uid' => $uid));
  125. return $count - $deleted_account;
  126. }
  127. public function searchUserBuyWxapp($uid) {
  128. $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" ;
  129. $count = pdo_fetchcolumn($sql, array(':buyerid' => $uid));
  130. $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)";
  131. $deleted_account = pdo_fetchcolumn($isdeleted_account_sql, array(':uid' => $uid));
  132. return $count - $deleted_account;
  133. }
  134. public function searchUserBuyPackage($uniacid) {
  135. $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" ;
  136. return pdo_fetchall($sql, array(':uniacid' => $uniacid, ':wxapp' => $uniacid), 'module_group');
  137. }
  138. public function searchUserCreateAccountNum($uid) {
  139. $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)->where('b.isdeleted', 0)->select('count(*) as count')->get('count');
  140. return $count['count'];
  141. }
  142. public function searchUserCreateWxappNum($uid) {
  143. $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)->where('b.isdeleted', 0)->select('count(*) as count')->get('count');
  144. return $count['count'];
  145. }
  146. public function searchPaymentsOrder() {
  147. 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();
  148. }
  149. }