SalesroomOrderController.class.php 9.6 KB

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