ShippingController.class.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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 ShippingController extends CommonController{
  16. protected function _initialize(){
  17. parent::_initialize();
  18. }
  19. public function templates()
  20. {
  21. $_GPC = I('request.');
  22. $pindex = max(1, intval($_GPC['page']));
  23. $psize = 20;
  24. $condition = ' ';
  25. $this->gpc = $_GPC;
  26. if ($_GPC['enabled'] != '') {
  27. $condition .= ' and enabled=' . intval($_GPC['enabled']);
  28. }
  29. if (!empty($_GPC['keyword'])) {
  30. $condition .= ' and name like "%'.$_GPC['keyword'].'%" ';
  31. }
  32. $list = M()->query('SELECT * FROM ' . C('DB_PREFIX') . 'lionfish_comshop_shipping WHERE 1 ' .
  33. $condition . ' ORDER BY sort_order DESC limit ' . (($pindex - 1) * $psize) . ',' . $psize);
  34. $total = M('lionfish_comshop_shipping')->where( "1 ". $condition )->count();
  35. $pager = pagination2($total, $pindex, $psize);
  36. $this->list = $list;
  37. $this->pager = $pager;
  38. $this->display();
  39. }
  40. public function setdefault()
  41. {
  42. $_GPC = I('request.');
  43. $id = intval($_GPC['id']);
  44. if (empty($id)) {
  45. $id = (is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0);
  46. }
  47. if ($_GPC['isdefault'] == 1) {
  48. M('lionfish_comshop_shipping')->where( 1 )->save( array('isdefault' => 0) );
  49. }
  50. $items = M('lionfish_comshop_shipping')->field('id,name')->where( 'id in( ' . $id . ' )' )->select();
  51. foreach ($items as $item) {
  52. M('lionfish_comshop_shipping')->where( array('id' => $item['id']) )->save( array('isdefault' => intval($_GPC['isdefault'])) );
  53. }
  54. show_json(1, array('url' => $_SERVER['HTTP_REFERER'] ));
  55. }
  56. public function enabled()
  57. {
  58. $_GPC = I('request.');
  59. $id = intval($_GPC['id']);
  60. if (empty($id)) {
  61. $id = (is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0);
  62. }
  63. $items = M('lionfish_comshop_shipping')->where( ' id in( ' . $id . ' ) ' )->select();
  64. foreach ($items as $item) {
  65. M('lionfish_comshop_shipping')->where( array('id' => $item['id']) )->save( array('enabled' => intval($_GPC['enabled'])) );
  66. }
  67. show_json(1, array('url' => $_SERVER['HTTP_REFERER'] ));
  68. }
  69. public function deleteshipping()
  70. {
  71. $_GPC = I('request.');
  72. $id = intval($_GPC['id']);
  73. if (empty($id)) {
  74. $id = (is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0);
  75. }
  76. $items = M('lionfish_comshop_shipping')->field('id,name')->where( 'id in( ' . $id . ' )' )->select();
  77. foreach ($items as $item) {
  78. M('lionfish_comshop_shipping')->where( array('id' => $item['id']) )->delete();
  79. }
  80. show_json(1, array('url' => $_SERVER['HTTP_REFERER'] ));
  81. }
  82. public function editshipping()
  83. {
  84. $_GPC = I('request.');
  85. if (IS_POST) {
  86. $data = array();
  87. $data['id'] = $_GPC['data']['id'];
  88. $data['name'] = $_GPC['data']['name'];
  89. $data['sort_order'] = $_GPC['sort_order'];
  90. $data['isdefault'] = $_GPC['isdefault'];
  91. $data['isdefault'] = $_GPC['isdefault'];
  92. $data['type'] = $_GPC['type'];
  93. $data['default_firstweight'] = $_GPC['default_firstweight'];
  94. $data['default_firstprice'] = $_GPC['default_firstprice'];
  95. $data['default_secondweight'] = $_GPC['default_secondweight'];
  96. $data['default_secondprice'] = $_GPC['default_secondprice'];
  97. $data['default_firstnum'] = $_GPC['default_firstnum'];
  98. $data['default_firstnumprice'] = $_GPC['default_firstnumprice'];
  99. $data['default_secondnum'] = $_GPC['default_secondnum'];
  100. $data['default_secondnumprice'] = $_GPC['default_secondnumprice'];
  101. $data['default_freeprice'] = $_GPC['default_freeprice'];
  102. $areas = array();
  103. $randoms = $_GPC['random'];
  104. $areas = array();
  105. $randoms = $_GPC['random'];
  106. //detail[PU0fIwE9052ZqWAb][frist]
  107. if (is_array($randoms)) {
  108. foreach ($randoms as $random) {
  109. $citys = trim($_GPC['citys'][$random]);
  110. if (empty($citys)) {
  111. continue;
  112. }
  113. if ($_GPC['firstnum'][$random] < 1) {
  114. $_GPC['firstnum'][$random] = 1;
  115. }
  116. if ($_GPC['secondnum'][$random] < 1) {
  117. $_GPC['secondnum'][$random] = 1;
  118. }
  119. $areas[] = array('citys' => $_GPC['citys'][$random], 'citys_code' => $_GPC['citys_code'][$random], 'frist' => $_GPC['detail'][$random]['frist'], 'frist_price' => max(0, $_GPC['detail'][$random]['frist_price']), 'second' => $_GPC['detail'][$random]['second'],'second_price' => $_GPC['detail'][$random]['second_price'] );
  120. }
  121. }
  122. $data['areas'] = $areas;
  123. D('Seller/Shipping')->update($data);
  124. show_json(1, array('url' => U('shipping/templates')));
  125. }
  126. $id = intval($_GPC['id']);
  127. $this->id =$id;
  128. $item = M('lionfish_comshop_shipping')->where( array('id' => $id) )->find();
  129. $this->item = $item;
  130. if (!empty($item)) {
  131. $dispatch_areas = unserialize($item['areas']);
  132. $this->dispatch_areas = $dispatch_areas;
  133. }
  134. //getAreas
  135. $areas = D('Seller/Area')->getAreas();
  136. $this->areas = $areas;
  137. $this->display('Shipping/addshipping');
  138. }
  139. public function addshipping()
  140. {
  141. $_GPC = I('request.');
  142. //show_json(1, array('url' => $_SERVER['HTTP_REFERER'] ));
  143. if (IS_POST) {
  144. $data = array();
  145. $data['id'] = $_GPC['data']['id'];
  146. $data['name'] = $_GPC['data']['name'];
  147. $data['sort_order'] = $_GPC['sort_order'];
  148. $data['isdefault'] = $_GPC['isdefault'];
  149. $data['isdefault'] = $_GPC['isdefault'];
  150. $data['type'] = $_GPC['type'];
  151. $data['default_firstweight'] = $_GPC['default_firstweight'];
  152. $data['default_firstprice'] = $_GPC['default_firstprice'];
  153. $data['default_secondweight'] = $_GPC['default_secondweight'];
  154. $data['default_secondprice'] = $_GPC['default_secondprice'];
  155. $data['default_firstnum'] = $_GPC['default_firstnum'];
  156. $data['default_firstnumprice'] = $_GPC['default_firstnumprice'];
  157. $data['default_secondnum'] = $_GPC['default_secondnum'];
  158. $data['default_secondnumprice'] = $_GPC['default_secondnumprice'];
  159. $data['default_freeprice'] = $_GPC['default_freeprice'];
  160. $areas = array();
  161. $randoms = $_GPC['random'];
  162. $areas = array();
  163. $randoms = $_GPC['random'];
  164. if (is_array($randoms)) {
  165. foreach ($randoms as $random) {
  166. $citys = trim($_GPC['citys'][$random]);
  167. if (empty($citys)) {
  168. continue;
  169. }
  170. if ($_GPC['firstnum'][$random] < 1) {
  171. $_GPC['firstnum'][$random] = 1;
  172. }
  173. if ($_GPC['secondnum'][$random] < 1) {
  174. $_GPC['secondnum'][$random] = 1;
  175. }
  176. //$areas[] = array('citys' => $_GPC['citys'][$random], 'citys_code' => $_GPC['citys_code'][$random], 'firstprice' => $_GPC['firstprice'][$random], 'firstweight' => max(0, $_GPC['firstweight'][$random]), 'secondprice' => $_GPC['secondprice'][$random], 'secondweight' => $_GPC['secondweight'][$random] <= 0 ? 1000 : $_GPC['secondweight'][$random], 'firstnumprice' => $_GPC['firstnumprice'][$random], 'firstnum' => $_GPC['firstnum'][$random], 'secondnumprice' => $_GPC['secondnumprice'][$random], 'secondnum' => $_GPC['secondnum'][$random], 'freeprice' => $_GPC['freeprice'][$random]);
  177. $areas[] = array('citys' => $_GPC['citys'][$random], 'citys_code' => $_GPC['citys_code'][$random], 'frist' => $_GPC['detail'][$random]['frist'], 'frist_price' => max(0, $_GPC['detail'][$random]['frist_price']), 'second' => $_GPC['detail'][$random]['second'],'second_price' => $_GPC['detail'][$random]['second_price'] );
  178. }
  179. }
  180. $data['areas'] = $areas;
  181. D('Seller/Shipping')->update($data);
  182. show_json(1, array('url' => U('shipping/templates')));
  183. }
  184. $areas = D('Seller/Area')->getAreas();
  185. $this->areas = $areas;
  186. $this->display();
  187. }
  188. public function tpl()
  189. {
  190. global $_W;
  191. global $_GPC;
  192. $random = random(16);
  193. $this->random = $random;
  194. $contents = $this->fetch('Shipping:tpl');
  195. exit(json_encode(array('random' => $random, 'html' => $contents)));
  196. }
  197. public function editexpress()
  198. {
  199. $_GPC = I('request.');
  200. $id = intval($_GPC['id']);
  201. if (!empty($id)) {
  202. $item = M('lionfish_comshop_express')->field('id,name,simplecode')->where( array('id' => $id ) )->find();
  203. $this->item = $item;
  204. }
  205. if (IS_POST) {
  206. $data = $_GPC['data'];
  207. D('Seller/Express')->update($data);
  208. show_json(1, array('url' => $_SERVER['HTTP_REFERER'] ));
  209. }
  210. $this->display('Express/addexpress');
  211. }
  212. public function delexpress()
  213. {
  214. $_GPC = I('request.');
  215. $id = intval($_GPC['id']);
  216. if (empty($id)) {
  217. $id = (is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0);
  218. }
  219. $items = M('lionfish_comshop_express')->field('id,name')->where( 'id in( ' . $id . ' )' )->select();
  220. if (empty($item)) {
  221. $item = array();
  222. }
  223. foreach ($items as $item) {
  224. M('lionfish_comshop_express')->where( array('id' => $item['id']) )->delete();
  225. }
  226. show_json(1, array('url' => $_SERVER['HTTP_REFERER'] ));
  227. }
  228. }
  229. ?>