PresaleController.class.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. *
  6. * @author fish
  7. *
  8. */
  9. namespace Seller\Controller;
  10. class PresaleController extends CommonController{
  11. protected function _initialize(){
  12. parent::_initialize();
  13. }
  14. public function index()
  15. {
  16. $_GET['goods_type'] = 'presale';
  17. $Goods_controller = A('Goods');
  18. $Goods_controller->index();
  19. }
  20. /**
  21. * @author yj
  22. * @desc 预售配置
  23. */
  24. public function config()
  25. {
  26. $_GPC = I('request.');
  27. if (IS_POST) {
  28. $data = ((is_array($_GPC['parameter']) ? $_GPC['parameter'] : array()));
  29. $data['isopen_presale'] = isset($data['isopen_presale']) ? $data['isopen_presale']:0;
  30. $data['presale_layout'] = isset($data['presale_layout']) ? $data['presale_layout']:0;
  31. $data['is_open_presale_show'] = isset($data['is_open_presale_show']) ? $data['is_open_presale_show']:0;
  32. $data['iscan_presale_dingrefund'] = isset($data['iscan_presale_dingrefund']) ? $data['iscan_presale_dingrefund']:0;
  33. $data['presale_name_modify'] = isset($data['presale_name_modify']) ? $data['presale_name_modify']:'';
  34. $data['presale_share_title'] = isset($data['presale_share_title']) ? $data['presale_share_title']:'';
  35. $data['presale_share_img'] = isset($data['presale_share_img']) ? $data['presale_share_img']:'';
  36. $data['presale_publish'] = isset($data['presale_publish']) ? $data['presale_publish']:'';
  37. D('Seller/Config')->update($data);
  38. show_json(1, array('url' => $_SERVER['HTTP_REFERER']) );
  39. die();
  40. }
  41. $data = D('Seller/Config')->get_all_config();
  42. $this->data = $data;
  43. $this->display();
  44. }
  45. /**
  46. * @author yj
  47. * @desc 预售订阅消息
  48. */
  49. public function templatemsg()
  50. {
  51. $_GPC = I('request.');
  52. if (IS_POST) {
  53. $data = ((is_array($_GPC['parameter']) ? $_GPC['parameter'] : array()));
  54. $data['isopen_presale'] = isset($data['isopen_presale']) ? $data['isopen_presale']:0;
  55. $data['presale_layout'] = isset($data['presale_layout']) ? $data['presale_layout']:0;
  56. D('Seller/Config')->update($data);
  57. show_json(1, array('url' => $_SERVER['HTTP_REFERER']) );
  58. die();
  59. }
  60. $data = D('Seller/Config')->get_all_config();
  61. $this->data = $data;
  62. $this->display();
  63. }
  64. public function addgoods()
  65. {
  66. $_GET['goods_type'] = 'presale';
  67. $Goods_controller = A('Goods');
  68. $Goods_controller->addgoods();
  69. }
  70. public function edit()
  71. {
  72. $_GET['goods_type'] = 'presale';
  73. $Goods_controller = A('Goods');
  74. $Goods_controller->edit();
  75. }
  76. public function order()
  77. {
  78. $_GET['presale_order'] = '1';
  79. $Goods_controller = A('Order');
  80. $Goods_controller->index();
  81. }
  82. public function statistics()
  83. {
  84. $_GPC = I('request.');
  85. $pindex = I('request.page', 1);
  86. $psize = 20;
  87. //商品名称
  88. $keyword = I('get.keyword','','addslashes');
  89. $keyword2 = stripslashes($keyword);
  90. $this->keyword = $keyword2;
  91. $condition = " and og.cost_price is not NULL ";
  92. if (!empty($keyword)) {
  93. $condition .= " and og.name like '%".$keyword."%' ";
  94. }
  95. $starttime = strtotime( date('Y-m-d').' 00:00:00' );
  96. $endtime = $starttime + 86400;
  97. $searchtime = $_GPC['searchtime'];
  98. if( !empty($searchtime) )
  99. {
  100. $starttime = isset($_GPC['time']['start']) ? strtotime($_GPC['time']['start']) : strtotime(date('Y-m-d'.' 00:00:00'));
  101. $endtime = isset($_GPC['time']['end']) ? strtotime($_GPC['time']['end']) : strtotime(date('Y-m-d'.' 23:59:59'));
  102. $condition .= " and op.presale_sendorder_datetime >= {$starttime} and op.presale_sendorder_datetime <= {$endtime} ";
  103. }else{
  104. // $condition .= " and op.presale_sendorder_datetime >= {$starttime} and op.presale_sendorder_datetime <= {$endtime} ";
  105. }
  106. $this->starttime = $starttime;
  107. $this->endtime = $endtime;
  108. $this->searchtime = $searchtime;
  109. $sql = " SELECT og.goods_id,og.order_id,og.name,og.rela_goodsoption_valueid,og.price,og.cost_price,SUM( og.quantity ) as quantity, "
  110. . " SUM( og.quantity * og.price ) as total_price,SUM( og.quantity * og.cost_price ) as cost_total_price,sum(og.profit_total) as profit_total "
  111. . " FROM ". C('DB_PREFIX'). "lionfish_comshop_order_presale as op "
  112. . " , ". C('DB_PREFIX'). "lionfish_comshop_order_goods as og "
  113. . " , ". C('DB_PREFIX'). "lionfish_comshop_order as o "
  114. . " WHERE og.order_id = op.order_id and og.order_id=o.order_id and o.order_status_id in (1) "
  115. . $condition . " group by og.goods_id, og.name, og.rela_goodsoption_valueid,og.price ";
  116. if( isset($_GPC['export']) && $_GPC['export'] == 1 )
  117. {
  118. $t_sql = " select * from ( " .$sql. " ) t "
  119. . " order by profit_total desc ";
  120. $list = M()->query($t_sql);
  121. $i = 1;
  122. foreach ($list as $k=>$v) {
  123. $list[$k]['rank'] = $i;
  124. $list[$k]['profit_fee'] = round($v['profit_total']/$v['total_price']*100,2);
  125. $order_goods_info = M('lionfish_comshop_order_goods')->where(array('goods_id'=>$v['goods_id'],'rela_goodsoption_valueid'=>$v['rela_goodsoption_valueid']))->find();
  126. $list[$k]['option_sku'] = D('Seller/Order')->get_order_option_sku($order_goods_info['order_id'], $order_goods_info['order_goods_id']);
  127. //商品名称
  128. /*$goods_info = M('lionfish_comshop_goods')->where(array('id'=>$v['goods_id']))->field('goodsname')->find();
  129. if(!empty($goods_info)){
  130. $list[$k]['name'] = $goods_info['goodsname'];
  131. }*/
  132. $i++;
  133. }
  134. $columns = array(
  135. array('title' => '排名', 'field' => 'rank', 'width' => 32),
  136. array('title' => '商品名称', 'field' => 'name', 'width' => 32),
  137. array('title' => '规格', 'field' => 'option_sku', 'width' => 32),
  138. array('title' => '商城售价(元)', 'field' => 'price', 'width' => 32),
  139. //array('title' => '成本价(元)', 'field' => 'cost_price', 'width' => 32),
  140. array('title' => '商品销量', 'field' => 'quantity', 'width' => 32),
  141. //array('title' => '商品销量总价(元) ', 'field' => 'total_price', 'width' => 32),
  142. //array('title' => '商品销量成本总价(元)', 'field' => 'cost_total_price', 'width' => 32),
  143. //array('title' => '毛利额', 'field' => 'profit_total', 'width' => 32),
  144. //array('title' => '毛利率(%)', 'field' => 'profit_fee', 'width' => 32),
  145. );
  146. $data = array();
  147. foreach($list as $k=>$v){
  148. $tmp = array();
  149. $tmp['rank'] = $v['rank'];
  150. $tmp['name'] = $v['name'];
  151. $tmp['option_sku'] = $v['option_sku'];
  152. $tmp['price'] = $v['price'];
  153. //$tmp['cost_price'] = $v['cost_price'];
  154. $tmp['quantity'] = $v['quantity'];
  155. // $tmp['total_price'] = $v['total_price'];
  156. //$tmp['cost_total_price'] = $v['cost_total_price'];
  157. // $tmp['profit_total'] = $v['profit_total'];
  158. // $tmp['profit_fee'] = $v['profit_fee'];
  159. $data[] = $tmp;
  160. }
  161. $title = '预售统计';
  162. D('Seller/Excel')->export($data, array('title' => $title, 'columns' => $columns));
  163. }else{
  164. $t_sql = " select * from ( " .$sql. " ) t "
  165. . " order by profit_total desc limit " . (($pindex - 1) * $psize) . "," . $psize;
  166. $list = M()->query($t_sql);
  167. $total_list = M()->query("select count(1) as count from (".$sql.") as t");
  168. $total = $total_list[0]['count'];
  169. $pager = pagination2($total, $pindex, $psize);
  170. foreach($list as $k=>$v){
  171. $tmp = array();
  172. $tmp['rank'] = $v['rank'];
  173. $tmp['name'] = $v['name'];
  174. $tmp['option_sku'] = $v['option_sku'];
  175. $tmp['price'] = $v['price'];
  176. //$tmp['cost_price'] = $v['cost_price'];
  177. $tmp['quantity'] = $v['quantity'];
  178. // $tmp['total_price'] = $v['total_price'];
  179. //$tmp['cost_total_price'] = $v['cost_total_price'];
  180. // $tmp['profit_total'] = $v['profit_total'];
  181. // $tmp['profit_fee'] = $v['profit_fee'];
  182. $data[] = $tmp;
  183. }
  184. $this->list = $list;
  185. $this->all_quantity = !empty($all_list[0]['quantity']) ? $all_list[0]['quantity'] : 0;
  186. $this->all_total = !empty($all_list[0]['total_price']) ? $all_list[0]['total_price'] : 0;
  187. $this->pager = $pager;
  188. $this->gpc = $_GPC;
  189. $this->display();
  190. }
  191. }
  192. /**
  193. * @author yj
  194. * @desc 幻灯片
  195. */
  196. public function slider()
  197. {
  198. $_GPC = I('request.');
  199. $condition = ' and type="presale" ';
  200. $pindex = max(1, intval($_GPC['page']));
  201. $psize = 20;
  202. if (!empty($_GPC['keyword'])) {
  203. $_GPC['keyword'] = trim($_GPC['keyword']);
  204. $condition .= ' and advname like "%'.$_GPC['keyword'].'%"';
  205. }
  206. if (isset($_GPC['enabled']) && $_GPC['enabled'] >= 0) {
  207. $_GPC['enabled'] = trim($_GPC['enabled']);
  208. $condition .= ' and enabled = ' . $_GPC['enabled'];
  209. } else {
  210. $_GPC['enabled'] = -1;
  211. }
  212. $list = M()->query('SELECT id,advname,thumb,link,type,displayorder,enabled FROM ' . C('DB_PREFIX') . "lionfish_comshop_adv
  213. WHERE 1 " . $condition . ' order by displayorder desc, id desc limit ' . (($pindex - 1) * $psize) . ',' . $psize);
  214. $total_arr = M()->query('SELECT count(1) as count FROM ' . C('DB_PREFIX'). 'lionfish_comshop_adv WHERE 1 ' . $condition );
  215. $total = $total_arr[0]['count'];
  216. $pager = pagination2($total, $pindex, $psize);
  217. $this->list = $list;
  218. $this->pager = $pager;
  219. $this->_GPC = $_GPC;
  220. include $this->display();
  221. }
  222. public function addslider()
  223. {
  224. $id = I('request.id');
  225. if (!empty($id)) {
  226. $item = M('lionfish_comshop_adv')->where( array('id' => $id) )->find();
  227. $this->item = $item;
  228. }
  229. if (IS_POST) {
  230. $data = I('request.data');
  231. D('Seller/Adv')->update($data ,'presale');
  232. show_json(1, array('url' => U('presale.slider') ));
  233. }
  234. $this->display();
  235. }
  236. }
  237. ?>