SalesroomOrderController.class.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author zcy 2020-09-18
  12. *
  13. */
  14. namespace Seller\Controller;
  15. class SalesroomOrderController extends CommonController{
  16. protected function _initialize(){
  17. parent::_initialize();
  18. }
  19. public function index()
  20. {
  21. $pindex = I('request.page', 1);
  22. $psize = 20;
  23. $_GPC = I('request.');
  24. $keyword = I('request.keyword');
  25. $this->keyword = $keyword;
  26. $this->state = I('request.state','');
  27. $this->salesroom_id = $_GPC['salesroom_id'];
  28. $condition = "";
  29. //姓名/手机号/会员名
  30. if (!empty($keyword)) {
  31. $keyword = htmlspecialchars(addslashes(trim($keyword)));
  32. $condition .= " and (o.name like '%".$keyword."%' or o.telephone like '%".$keyword."%' or o.shipping_name like '%".$keyword."%' or o.order_num_alias like '%".$keyword."%') ";
  33. }
  34. if(!empty($this->state)){
  35. if($this->state == 2){//已核销
  36. $condition .= " and ogs.is_hexiao_over = 1 and o.order_status_id != 5 ";
  37. }else if($this->state == 1){//待核销
  38. $condition .= " and ogs.is_hexiao_over = 0 and o.order_status_id != 5 ";
  39. }else if($this->state == 3){
  40. $condition .= " and o.order_status_id = 5 ";
  41. }else if($this->state == 4){
  42. $condition .= " and ogs.is_hexiao_over = 2 ";
  43. }
  44. }
  45. $starttime = strtotime( date('Y-m-d')." 00:00:00" );
  46. $endtime = $starttime + 86400;
  47. if( isset($_GPC['searchtime']) && $_GPC['searchtime'] == 'create_time' )
  48. {
  49. if (!empty($_GPC['time']['start']) && !empty($_GPC['time']['end'])) {
  50. $starttime = strtotime($_GPC['time']['start']);
  51. $endtime = strtotime($_GPC['time']['end']);
  52. $condition .= ' AND o.date_added >= '.$starttime.' AND o.date_added <= '.$endtime.' ';
  53. }
  54. $this->searchtime = $_GPC['searchtime'];
  55. }
  56. if(!empty($this->salesroom_id)){
  57. $this->salesroom = M('lionfish_comshop_salesroom')->where( array('id' => $this->salesroom_id ) )->find();
  58. $condition .= ' AND EXISTS(SELECT order_id FROM '. C('DB_PREFIX').'lionfish_comshop_order_goods_saleshexiao_record as osr WHERE osr.order_goods_id=og.order_goods_id and osr.salesroom_id='.$this->salesroom_id.') ';
  59. }
  60. if (defined('ROLE') && ROLE == 'agenter' )
  61. {
  62. $supper_info = get_agent_logininfo();
  63. $supply_id = $supper_info['id'];
  64. $condition .= " and o.store_id= ".$supply_id;
  65. }
  66. $this->starttime = $starttime;
  67. $this->endtime = $endtime;
  68. $sql = 'SELECT ogs.*,o.order_num_alias,o.member_id,o.store_id,o.head_id,o.name as member_name,o.telephone,o.shipping_name,o.head_id,'
  69. . ' o.date_added,o.payment_code,o.order_status_id,og.goods_id,og.name as goods_name,og.goods_images,og.quantity,og.shipping_fare,'
  70. . ' og.price,og.total,ogs.refund_quantity,ogs.goods_quantity '
  71. . ' FROM '. C('DB_PREFIX').'lionfish_comshop_order_goods_saleshexiao as ogs '
  72. . ' left join '. C('DB_PREFIX').'lionfish_comshop_order as o on ogs.order_id=o.order_id '
  73. . ' left join '. C('DB_PREFIX').'lionfish_comshop_order_goods as og on og.order_goods_id=ogs.order_goods_id '
  74. . ' WHERE 1=1 '.$condition. ' order by o.date_added desc limit ' . (($pindex - 1) * $psize) . ',' . $psize;
  75. $list = M()->query($sql);
  76. foreach ($list as $k=>$v) {
  77. $list[$k]['date_added'] = date('Y-m-d H:i:s',$v['date_added']);
  78. //团长信息
  79. $community_info = D('Seller/Front')->get_community_byid($v['head_id']);
  80. $list[$k]['community_name'] = $community_info['communityName'];
  81. $list[$k]['head_name'] = $community_info['disUserName'];
  82. $list[$k]['head_mobile'] = $community_info['head_mobile'];
  83. $list[$k]['province'] = $community_info['province'];
  84. $list[$k]['city'] = $community_info['city'];
  85. //最后一次核销员信息
  86. if($v['is_hexiao_over'] == 1){
  87. $record = M('lionfish_comshop_order_goods_saleshexiao_record')->where( array('order_id' => $v['order_id'],'order_goods_id' => $v['order_goods_id'] ) )->order('id desc')->limit(1)->find();
  88. $list[$k]['smember_name'] = $record['smember_name'];
  89. if($record['is_admin'] == 0){//不是后台核销
  90. $salesroom_member = M('lionfish_comshop_salesroom_member')->field('mobile')->where( array('id' => $record['salesmember_id'] ) )->find();
  91. $list[$k]['smember_mobile'] = $salesroom_member['mobile'];
  92. $list[$k]['salesroom_name'] = $record['salesroom_name'];
  93. }
  94. }else{
  95. $record_count = M('lionfish_comshop_order_goods_saleshexiao_record')->where( array('order_id' => $v['order_id'],'order_goods_id' => $v['order_goods_id'] ) )->count();
  96. if($record_count > 0){
  97. $list[$k]['record_count'] = $record_count;
  98. }
  99. }
  100. }
  101. $total_count = M()->query('SELECT count(1) as count '
  102. . ' FROM '. C('DB_PREFIX').'lionfish_comshop_order_goods_saleshexiao as ogs '
  103. . ' left join '. C('DB_PREFIX').'lionfish_comshop_order as o on ogs.order_id=o.order_id '
  104. . ' left join '. C('DB_PREFIX').'lionfish_comshop_order_goods as og on og.order_goods_id=ogs.order_goods_id '
  105. . ' WHERE 1=1 '.$condition );
  106. $total = $total_count[0]['count'];
  107. $pager = pagination2($total, $pindex, $psize);
  108. $this->list = $list;
  109. $this->pager = $pager;
  110. $this->display('Salesroom_order/index');
  111. }
  112. public function member_orders()
  113. {
  114. $pindex = I('request.page', 1);
  115. $psize = 20;
  116. $_GPC = I('request.');
  117. $keyword = I('request.keyword');
  118. $this->keyword = $keyword;
  119. //核销员信息
  120. $smember_id = $_GPC['smember_id'];
  121. $smember_info = M('lionfish_comshop_salesroom_member')->where( array('id' => $smember_id ) )->find();
  122. $this->smember_info = $smember_info;
  123. $condition = "";
  124. //姓名/手机号/会员名
  125. if (!empty($keyword)) {
  126. $condition .= " and (o.order_num_alias like '%".$keyword."%' or og.name like '%".$keyword."%' or o.telephone like '%".$keyword."%' or o.shipping_name like '%".$keyword."%') ";
  127. }
  128. $starttime = strtotime( date('Y-m-d')." 00:00:00" );
  129. $endtime = $starttime + 86400;
  130. if( isset($_GPC['searchtime']) && $_GPC['searchtime'] == 'create_time' )
  131. {
  132. if (!empty($_GPC['time']['start']) && !empty($_GPC['time']['end'])) {
  133. $starttime = strtotime($_GPC['time']['start']);
  134. $endtime = strtotime($_GPC['time']['end']);
  135. $condition .= ' AND o.date_added >= '.$starttime.' AND o.date_added <= '.$endtime.' ';
  136. }
  137. $this->searchtime = $_GPC['searchtime'];
  138. }
  139. if(!empty($smember_id)){
  140. $condition .= ' AND EXISTS(SELECT order_id FROM '. C('DB_PREFIX').'lionfish_comshop_order_goods_saleshexiao_record as osr WHERE osr.order_id=o.order_id and osr.salesmember_id='.$smember_id.') ';
  141. }
  142. if(!empty($_GPC['payment_code'])){
  143. $condition .= " and o.payment_code = '".$_GPC['payment_code']."' ";
  144. $this->payment_code = $_GPC['payment_code'];
  145. }
  146. $this->starttime = $starttime;
  147. $this->endtime = $endtime;
  148. $list = M()->query('SELECT ogs.*,o.order_num_alias,o.member_id,o.store_id,o.head_id,o.name as member_name,o.telephone,o.shipping_name,o.head_id,'
  149. . ' o.date_added,o.payment_code,og.goods_id,og.name as goods_name,og.goods_images,og.quantity,og.shipping_fare,'
  150. . ' og.price,og.total '
  151. . ' FROM '. C('DB_PREFIX').'lionfish_comshop_order_goods_saleshexiao as ogs '
  152. . ' left join '. C('DB_PREFIX').'lionfish_comshop_order as o on ogs.order_id=o.order_id '
  153. . ' left join '. C('DB_PREFIX').'lionfish_comshop_order_goods as og on og.order_goods_id=ogs.order_goods_id '
  154. . ' WHERE 1=1 '.$condition. ' order by o.date_added desc limit ' . (($pindex - 1) * $psize) . ',' . $psize);
  155. foreach ($list as $k=>$v) {
  156. $list[$k]['date_added'] = date('Y-m-d H:i:s',$v['date_added']);
  157. //最后一次核销员信息
  158. $record = M('lionfish_comshop_order_goods_saleshexiao_record')->where( array('order_id' => $v['order_id'],'order_goods_id' => $v['order_goods_id'] ) )->order('id desc')->find();
  159. $list[$k]['smember_name'] = $record['smember_name'];
  160. if($record['is_admin'] == 0){//不是后台核销
  161. $salesroom_member = M('lionfish_comshop_salesroom_member')->field('mobile')->where( array('id' => $record['salesmember_id'] ) )->find();
  162. $list[$k]['smember_mobile'] = $salesroom_member['mobile'];
  163. $list[$k]['salesroom_name'] = $record['salesroom_name'];
  164. }
  165. if($v['is_hexiao_over'] == 1){
  166. $list[$k]['hexiao_time'] = $record['addtime'];
  167. }
  168. }
  169. $total_count = M()->query('SELECT count(1) as count '
  170. . ' FROM '. C('DB_PREFIX').'lionfish_comshop_order_goods_saleshexiao as ogs '
  171. . ' left join '. C('DB_PREFIX').'lionfish_comshop_order as o on ogs.order_id=o.order_id '
  172. . ' left join '. C('DB_PREFIX').'lionfish_comshop_order_goods as og on og.order_goods_id=ogs.order_goods_id '
  173. . ' WHERE 1=1 '.$condition );
  174. $total = $total_count[0]['count'];
  175. $pager = pagination2($total, $pindex, $psize);
  176. $this->list = $list;
  177. $this->pager = $pager;
  178. $this->display();
  179. }
  180. }
  181. ?>