ExpressController.class.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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. use Seller\Model\ExpressModel;
  16. class ExpressController extends CommonController{
  17. protected function _initialize(){
  18. parent::_initialize();
  19. $this->breadcrumb1='发货设置';
  20. $this->breadcrumb2='快递管理';
  21. }
  22. public function index(){
  23. $model=new ExpressModel();
  24. $search = array();
  25. $search['store_id'] = array('in','0,'.SELLERUID);
  26. $data=$model->show_express_page($search);
  27. $seller_express_relat = M('seller_express_relat')->where( array('store_id' => SELLERUID) )->select();
  28. $express_ids = array();
  29. foreach($seller_express_relat as $express)
  30. {
  31. $express_ids[] = $express['express_id'];
  32. }
  33. foreach($data['list'] as $key => $val)
  34. {
  35. $val['is_selected'] = 0;
  36. if(!empty($express_ids) && in_array($val['id'], $express_ids))
  37. {
  38. $val['is_selected'] = 1;
  39. }
  40. $data['list'][$key] = $val;
  41. }
  42. $this->assign('seller_id',SELLERUID);
  43. $this->assign('empty',$data['empty']);// 赋值数据集
  44. $this->assign('list',$data['list']);// 赋值数据集
  45. $this->assign('page',$data['page']);// 赋值分页输出
  46. $this->display();
  47. }
  48. function toggle_express_show()
  49. {
  50. $eid = intval(I('post.eid'));
  51. $rel_ex = M('seller_express_relat')->where( array('store_id' => SELLERUID, 'express_id' => $eid) )->find();
  52. if(empty($rel_ex))
  53. {
  54. $data = array();
  55. $data['express_id'] = $eid;
  56. $data['store_id'] = SELLERUID;
  57. M('seller_express_relat')->add($data);
  58. } else {
  59. M('seller_express_relat')->where( array('store_id' => SELLERUID, 'express_id' => $eid) )->delete();
  60. }
  61. echo json_encode( array('code' => 1) );
  62. die();
  63. }
  64. function add(){
  65. if(IS_POST){
  66. $data=I('post.');
  67. $data['store_id'] = SELLERUID;
  68. $data['addtime'] = time();
  69. if( empty($data['express_name']) )
  70. {
  71. $return = array(
  72. 'status'=>'fail',
  73. 'message'=>'请填写快递名称',
  74. 'jump'=>U('Express/index')
  75. );
  76. }else{
  77. $res = M('seller_express')->add($data);
  78. if($res) {
  79. $return = array(
  80. 'status'=>'success',
  81. 'message'=>'新增成功',
  82. 'jump'=>U('Express/index')
  83. );
  84. } else {
  85. $return = array(
  86. 'status'=>'fail',
  87. 'message'=>'新增失败',
  88. 'jump'=>U('Express/index')
  89. );
  90. }
  91. }
  92. $this->osc_alert($return);
  93. }
  94. $this->crumbs='新增';
  95. $this->action=U('Express/add');
  96. $this->display('edit');
  97. }
  98. function edit(){
  99. if(IS_POST){
  100. $data=I('post.');
  101. $data['addtime'] = time();
  102. $ck_info = M('seller_express')->where(array('id' =>$data['id'],'store_id' =>SELLERUID))->find();
  103. if(empty($ck_info)) {
  104. $return = array(
  105. 'status'=>'fail',
  106. 'message'=>'非法操作',
  107. 'jump'=>U('Express/index')
  108. );
  109. $this->osc_alert($return);
  110. }
  111. $res = M('seller_express')->save($data);
  112. if($res) {
  113. $return = array(
  114. 'status'=>'success',
  115. 'message'=>'编辑成功',
  116. 'jump'=>U('Express/index')
  117. );
  118. } else {
  119. $return = array(
  120. 'status'=>'fail',
  121. 'message'=>'编辑失败',
  122. 'jump'=>U('Express/index')
  123. );
  124. }
  125. $this->osc_alert($return);
  126. }
  127. $this->crumbs='编辑';
  128. $this->action=U('Express/edit');
  129. $this->d=M('seller_express')->find(I('id'));
  130. $this->display('edit');
  131. }
  132. public function del(){
  133. $id = I('get.id', 0);
  134. $res = M('seller_express')->where( array('id' => $id) )->delete();
  135. if($res) {
  136. $return = array(
  137. 'status'=>'success',
  138. 'message'=>'删除成功',
  139. 'jump'=>U('Express/index')
  140. );
  141. } else {
  142. $return = array(
  143. 'status'=>'fail',
  144. 'message'=>'删除失败',
  145. 'jump'=>U('Express/index')
  146. );
  147. }
  148. $this->osc_alert($return);
  149. }
  150. public function config()
  151. {
  152. $_GPC = I('request.');
  153. $this->gpc = $_GPC;
  154. $condition = '';
  155. $pindex = max(1, intval($_GPC['page']));
  156. $psize = 20;
  157. if (!empty($_GPC['keyword'])) {
  158. $condition .= ' and name like "%'.$_GPC['keyword'].'%" ';
  159. }
  160. $label = M()->query('SELECT id,name,simplecode FROM ' . C('DB_PREFIX') . "lionfish_comshop_express
  161. WHERE 1 " . $condition . ' order by id desc limit ' . (($pindex - 1) * $psize) . ',' . $psize);
  162. $total = M('lionfish_comshop_express')->where('1 ' . $condition)->count();
  163. $pager = pagination2($total, $pindex, $psize);
  164. $this->label = $label;
  165. $this->total = $total;
  166. $this->pager = $pager;
  167. $this->display();
  168. }
  169. public function addexpress()
  170. {
  171. $_GPC = I('request.');
  172. if (IS_POST) {
  173. $data = $_GPC['data'];
  174. D('Seller/Express')->update($data);
  175. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  176. }
  177. $this->display();
  178. }
  179. public function editexpress()
  180. {
  181. $_GPC = I('request.');
  182. $id = intval($_GPC['id']);
  183. if (!empty($id)) {
  184. $item = M('lionfish_comshop_express')->field('id,name,simplecode')->where( array('id' => $id) )->find();
  185. $this->item = $item;
  186. }
  187. if (IS_POST) {
  188. $data = $_GPC['data'];
  189. D('Seller/Express')->update($data);
  190. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  191. }
  192. $this->display('Express/addexpress');
  193. }
  194. public function delexpress()
  195. {
  196. $_GPC = I('request.');
  197. $id = intval($_GPC['id']);
  198. if (empty($id)) {
  199. $id = (is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0);
  200. }
  201. $items = M('lionfish_comshop_express')->field('id,name')->where('id in( ' . $id . ' ) ')->select();
  202. if (empty($item)) {
  203. $item = array();
  204. }
  205. foreach ($items as $item) {
  206. M('lionfish_comshop_express')->where( array('id' => $item['id']) )->delete();
  207. }
  208. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  209. }
  210. public function deconfig()
  211. {
  212. $_GPC = I('request.');
  213. if (IS_POST) {
  214. $data = ((is_array($_GPC['parameter']) ? $_GPC['parameter'] : array()));
  215. $data['delivery_type_ziti'] = trim($data['delivery_type_ziti']);
  216. $data['delivery_type_express'] = $data['delivery_type_express'];
  217. $data['delivery_type_tuanz'] = $data['delivery_type_tuanz'];
  218. $data['delivery_tuanz_money'] = $data['delivery_tuanz_money'];
  219. $data['delivery_express_name'] = $data['delivery_express_name'];
  220. $data['delivery_diy_sort'] = $data['delivery_diy_sort'];
  221. D('Seller/Config')->update($data);
  222. if(empty($data['delivery_diy_sort']) || !isset($data['delivery_diy_sort']))
  223. $data['delivery_diy_sort'] = '0,1,2';
  224. $data['delivery_diy_sort_arr'] = explode(",", $data['delivery_diy_sort']);
  225. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  226. }
  227. $data = D('Seller/Config')->get_all_config();
  228. if(empty($data['delivery_diy_sort']) || !isset($data['delivery_diy_sort'])) $data['delivery_diy_sort'] = '0,1,2';
  229. $data['delivery_diy_sort_arr'] = explode(",", $data['delivery_diy_sort']);
  230. $this->data = $data;
  231. $this->display();
  232. }
  233. public function config2()
  234. {
  235. $open_info = M('config')->where( array('name' => 'EXPRESS_OPEN') )->find();
  236. $ebuss_info = M('config')->where( array('name' => 'EXPRESS_EBUSS_ID') )->find();
  237. $exappkey = M('config')->where( array('name' => 'EXPRESS_APPKEY') )->find();
  238. $is_open = $open_info['value'];
  239. $ebuss_id = $ebuss_info['value'];
  240. $express_appkey = $exappkey['value'];
  241. $this->is_open = $is_open;
  242. $this->ebuss_id = $ebuss_id;
  243. $this->express_appkey = $express_appkey;
  244. $this->type = 1;
  245. $this->display();
  246. }
  247. function configadd()
  248. {
  249. $data = I('post.');
  250. /**
  251. array(4) { ["is_open"]=> string(1) "1" ["ebuss_id"]=> string(7) "1276098" ["express_appkey"]=> string(36) "9933541f-2d17-4312-8250-a9cecdbe633d" ["send"]=> string(6) "提交" }
  252. **/
  253. M('config')->where( array('name' => 'EXPRESS_OPEN') )->save( array('value' => $data['is_open']) );
  254. M('config')->where( array('name' => 'EXPRESS_EBUSS_ID') )->save( array('value' => $data['ebuss_id']) );
  255. M('config')->where( array('name' => 'EXPRESS_APPKEY') )->save( array('value' => $data['express_appkey']) );
  256. $return = array(
  257. 'status'=>'success',
  258. 'message'=>'保存成功',
  259. 'jump'=>U('Express/config')
  260. );
  261. $this->osc_alert($return);
  262. }
  263. }
  264. ?>