ShippingController.class.php 8.6 KB

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