PresaleController.class.php 11 KB

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