SellerManageController.class.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. <?php
  2. /**
  3. * 小梦科技资源nanodreamtech.com
  4. *
  5. * ==========================================================================
  6. * @link https://www.nanodreamtech.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license https://www.nanodreamtech.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Admin\Controller;
  15. use Admin\Model\SellerModel;
  16. use Seller\Model\ExpressModel;
  17. class SellerManageController extends CommonController{
  18. protected function _initialize(){
  19. parent::_initialize();
  20. $this->breadcrumb1='商家管理';
  21. $this->breadcrumb2='卖家管理';
  22. }
  23. public function index(){
  24. //name=ddd
  25. $name = I('get.name','','htmlspecialchars');
  26. $search = array();
  27. $search['s_true_name'] = $name;
  28. $model=new SellerModel();
  29. $data=$model->show_seller_user_page($search);
  30. $this->assign('empty',$data['empty']);// 赋值数据集
  31. $this->assign('list',$data['list']);// 赋值数据集
  32. $this->assign('page',$data['page']);// 赋值分页输出
  33. $this->display();
  34. }
  35. public function express()
  36. {
  37. $this->breadcrumb1='快递配置';
  38. $this->breadcrumb2='快递配置';
  39. $model=new ExpressModel();
  40. $search = array('store_id' => 0);
  41. $data=$model->show_express_page($search);
  42. $this->assign('empty',$data['empty']);// 赋值数据集
  43. $this->assign('list',$data['list']);// 赋值数据集
  44. $this->assign('page',$data['page']);// 赋值分页输出
  45. $this->type = 0;
  46. $this->display();
  47. }
  48. function config()
  49. {
  50. $this->breadcrumb1='快递配置';
  51. $this->breadcrumb2='快递配置';
  52. $open_info = M('config')->where( array('name' => 'EXPRESS_OPEN') )->find();
  53. $ebuss_info = M('config')->where( array('name' => 'EXPRESS_EBUSS_ID') )->find();
  54. $exappkey = M('config')->where( array('name' => 'EXPRESS_APPKEY') )->find();
  55. $is_open = $open_info['value'];
  56. $ebuss_id = $ebuss_info['value'];
  57. $express_appkey = $exappkey['value'];
  58. $this->is_open = $is_open;
  59. $this->ebuss_id = $ebuss_id;
  60. $this->express_appkey = $express_appkey;
  61. $this->type = 1;
  62. $this->display();
  63. }
  64. function configadd()
  65. {
  66. $data = I('post.');
  67. /**
  68. array(4) { ["is_open"]=> string(1) "1" ["ebuss_id"]=> string(7) "1276098" ["express_appkey"]=> string(36) "9933541f-2d17-4312-8250-a9cecdbe633d" ["send"]=> string(6) "提交" }
  69. **/
  70. M('config')->where( array('name' => 'EXPRESS_OPEN') )->save( array('value' => $data['is_open']) );
  71. M('config')->where( array('name' => 'EXPRESS_EBUSS_ID') )->save( array('value' => $data['ebuss_id']) );
  72. M('config')->where( array('name' => 'EXPRESS_APPKEY') )->save( array('value' => $data['express_appkey']) );
  73. $return = array(
  74. 'status'=>'success',
  75. 'message'=>'保存成功',
  76. 'jump'=>U('SellerManage/config')
  77. );
  78. $this->osc_alert($return);
  79. }
  80. function addexpress(){
  81. $this->breadcrumb2='快递配置';
  82. if(IS_POST){
  83. $data=I('post.');
  84. $data['store_id'] = 0;
  85. $data['addtime'] = time();
  86. $res = M('seller_express')->add($data);
  87. if($res) {
  88. $return = array(
  89. 'status'=>'success',
  90. 'message'=>'新增成功',
  91. 'jump'=>U('SellerManage/express')
  92. );
  93. } else {
  94. $return = array(
  95. 'status'=>'fail',
  96. 'message'=>'新增失败',
  97. 'jump'=>U('SellerManage/express')
  98. );
  99. }
  100. $this->osc_alert($return);
  101. }
  102. $this->crumbs='新增';
  103. $this->action=U('SellerManage/addexpress');
  104. $this->display('editexpress');
  105. }
  106. function editexpress(){
  107. $this->breadcrumb2='快递配置';
  108. if(IS_POST){
  109. $data=I('post.');
  110. $data['addtime'] = time();
  111. $res = M('seller_express')->save($data);
  112. if($res) {
  113. $return = array(
  114. 'status'=>'success',
  115. 'message'=>'编辑成功',
  116. 'jump'=>U('SellerManage/express')
  117. );
  118. } else {
  119. $return = array(
  120. 'status'=>'fail',
  121. 'message'=>'编辑失败',
  122. 'jump'=>U('SellerManage/express')
  123. );
  124. }
  125. $this->osc_alert($return);
  126. }
  127. $this->crumbs='编辑';
  128. $this->action=U('SellerManage/editexpress');
  129. $this->d=M('seller_express')->find(I('id'));
  130. $this->display('editexpress');
  131. }
  132. public function delexpress(){
  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('SellerManage/express')
  140. );
  141. } else {
  142. $return = array(
  143. 'status'=>'fail',
  144. 'message'=>'删除失败',
  145. 'jump'=>U('SellerManage/express')
  146. );
  147. }
  148. $this->osc_alert($return);
  149. }
  150. public function apply()
  151. {
  152. $this->breadcrumb1='入驻中心';
  153. $this->breadcrumb2='申请管理';
  154. $model=new SellerModel();
  155. $state = I('get.state',-1);
  156. $search = array();
  157. if($state >= 0)
  158. {
  159. $search['state'] = intval($state);
  160. }
  161. $data=$model->show_apply_user_page($search);
  162. $this->state = $state;
  163. $this->assign('empty',$data['empty']);// 赋值数据集
  164. $this->assign('list',$data['list']);// 赋值数据集
  165. $this->assign('page',$data['page']);// 赋值分页输出
  166. $this->display();
  167. }
  168. public function apply_detail()
  169. {
  170. $this->breadcrumb1='入驻中心';
  171. $this->breadcrumb2='申请管理';
  172. $aid = I('get.id',0);
  173. $apply_info = M('apply')->where( array('id' => $aid) )->find();
  174. $apply_relship = M('apply_relship')->where( array('aid' => $aid) )->find();
  175. if(!empty($apply_relship))
  176. {
  177. $apply_relship['rel_data'] = unserialize( $apply_relship['rel_data'] );
  178. }
  179. $this->apply_relship = $apply_relship;
  180. if($apply_info['type'] == 1)
  181. {
  182. $this->display('apply_detailbus');
  183. }else
  184. $this->display();
  185. }
  186. function certif_chang()
  187. {
  188. $data = I('post.');
  189. $s_id = $data['s_id'];
  190. $certif = $data['certif'];
  191. M('seller')->where( array('s_id' => $s_id) )->save( array('certification' => $certif) );
  192. $result = array();
  193. $result['code'] = 1;
  194. echo json_encode($result);
  195. die();
  196. }
  197. function shenhe()
  198. {
  199. $id = I('get.id');
  200. $state = I('get.state');
  201. if($state == 2)
  202. {
  203. M('apply')->where( array('id' => $id) )->save( array('state' => intval($state)) );
  204. $return = array('status' => 'success', 'message' => '操作成功,新增商家成功', 'jump' => U('SellerManage/apply'));
  205. $this->osc_alert($return);
  206. die();
  207. }
  208. $ckname = M('seller')->where( array('s_true_name' =>$apply_info['store_name']) )->find();
  209. if(!empty($ckname))
  210. {
  211. $return = array('status' => 'fail', 'message' => '该店铺名称已经存在', 'jump' => U('SellerManage/apply'));
  212. $this->osc_alert($return);
  213. die();
  214. }
  215. $ckmobile = M('seller')->where( array('s_mobile' =>$apply_info['mobile']) )->find();
  216. if(!empty($ckname))
  217. {
  218. $return = array('status' => 'fail', 'message' => '该手机号已经被店铺注册', 'jump' => U('SellerManage/apply'));
  219. $this->osc_alert($return);
  220. die();
  221. }
  222. $apply_info = M('apply')->where( array('id' => $id) )->find();
  223. //type =0 1 个人 企业
  224. //0普通,1个人认证,2企业认证,3平台自营'
  225. $certification = 0;
  226. if($apply_info['type'] == 0)
  227. {
  228. $certification = 1;
  229. } else {
  230. $certification = 2;
  231. }
  232. $data = array();
  233. $data['s_uname'] = $apply_info['mobile'];
  234. $data['s_true_name'] = $apply_info['store_name'];
  235. $data['s_logo'] = '';
  236. $data['s_qrcode'] = '';
  237. $data['certification'] = $certification;
  238. $data['s_telephone'] = $apply_info['mobile'];
  239. $data['s_mobile'] = $apply_info['mobile'];
  240. $data['s_qq'] = '';
  241. $data['s_weixin'] = '';
  242. $data['s_alipay'] = '';
  243. $data['s_cardname'] = '';
  244. $data['s_cardnumber'] = '';
  245. $data['s_email'] = $apply_info['email'];
  246. $data['s_passwd'] = $apply_info['mobile'];
  247. $data['s_is_super'] = 0;
  248. $data['s_role_id'] = 0;
  249. $data['s_login_count'] = 0;
  250. $data['s_last_login_ip'] = '';
  251. $data['s_last_ip_region'] = '';
  252. $data['s_create_time'] = time();
  253. $data['s_last_login_time'] = 0;
  254. $data['s_status'] = 1;
  255. $apply_relship = M('apply_relship')->where( array('aid' => $id) )->find();
  256. if(!empty($apply_relship))
  257. {
  258. $apply_relship['rel_data'] = unserialize( $apply_relship['rel_data'] );
  259. $data['s_logo'] = $apply_relship['rel_data']['store_logo'];
  260. }
  261. $model=new SellerModel();
  262. $res=$model->add_seller_user($data);
  263. if(!empty($apply_relship))
  264. {
  265. M('apply_relship')->where( array('aid' => $id) )->save( array('seller_id' => $res['s_id']) );
  266. }
  267. M('apply')->where( array('id' => $id) )->save( array('state' => intval($state)) );
  268. //检测是否开启短信,发送短信
  269. $open_sms_info = M('config')->where( array('name' => 'open_sms') )->find();
  270. $is_open = $open_sms_info['value'];
  271. if(!empty($is_open) && $is_open == 1)
  272. {
  273. //发送短信
  274. $this->send_sms_sh($apply_info['store_name'],$data['s_mobile']);
  275. }
  276. $return = array('status' => 'success', 'message' => '操作成功,新增商家成功', 'jump' => U('SellerManage/apply'));
  277. $this->osc_alert($return);
  278. }
  279. /**
  280. 发送短信
  281. **/
  282. private function send_sms_sh($store_name, $mobile)
  283. {
  284. $sms_userid_info = M('config')->where( array('name' => 'sms_userid') )->find();
  285. $sms_userid = $sms_userid_info['value'];
  286. $sms_username_info = M('config')->where( array('name' => 'sms_username') )->find();
  287. $sms_username = $sms_username_info['value'];
  288. $sms_password_info = M('config')->where( array('name' => 'sms_password') )->find();
  289. $sms_password = $sms_password_info['value'];
  290. $sms_template_info = M('config')->where( array('name' => 'sms_template') )->find();
  291. $sms_template = $sms_template_info['value'];
  292. $sms_template = str_replace("{uname}",$store_name,$sms_template);
  293. $post_data = array();
  294. $post_data['userid'] = $sms_userid;
  295. $post_data['account'] = $sms_username;
  296. $post_data['password'] = $sms_password;
  297. $post_data['content'] = $sms_template;
  298. $post_data['mobile'] = $mobile;
  299. $url='http://sms.kingtto.com:9999/sms.aspx?action=send';
  300. $o='';
  301. foreach ($post_data as $k=>$v)
  302. {
  303. //短信内容需要用urlencode编码,否则可能收到乱码
  304. $o.="$k=".urlencode($v).'&';
  305. }
  306. $post_data=substr($o,0,-1);
  307. $ch = curl_init();
  308. curl_setopt($ch, CURLOPT_POST, 1);
  309. curl_setopt($ch, CURLOPT_HEADER, 0);
  310. curl_setopt($ch, CURLOPT_URL,$url);
  311. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  312. //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //如果需要将结果直接返回到变量里,那加上这句。
  313. $result = curl_exec($ch);
  314. }
  315. function add(){
  316. $model=new SellerModel();
  317. if(IS_POST){
  318. $data=I('post.');
  319. $return=$model->add_seller_user($data);
  320. $this->osc_alert($return);
  321. }
  322. $this->crumbs='新增';
  323. $this->action=U('SellerManage/add');
  324. $this->display();
  325. }
  326. function info(){
  327. $model=new SellerModel();
  328. if(IS_POST){
  329. $data=I('post.');
  330. $info = M('Seller')->find($data['s_id']);
  331. $return=$model->edit_seller_user($data);
  332. $this->osc_alert($return);
  333. }
  334. $data = M('Seller')->find(I('id'));
  335. if(!empty($data['s_logo']))
  336. $data['thumb_logo'] = resize($data['s_logo'], 100, 100);
  337. $this->crumbs='编辑';
  338. $this->action=U('SellerManage/info');
  339. $this->data=$data;
  340. $this->display();
  341. }
  342. function store_bind_class()
  343. {
  344. $seller_id = intval($_GET['id']);
  345. $model= D('Admin/StoreBindClass');
  346. $data=$model->show_store_bind_class_page($seller_id);
  347. $goods_cate_model = D('Admin/GoodsCategory');
  348. foreach($data['list'] as $key=>$val)
  349. {
  350. if(!empty($val['class_1']))
  351. {
  352. $cate_info = $goods_cate_model->getInfoById($val['class_1'],"name");
  353. $val['cate1_name'] = empty($cate_info) ? '' : $cate_info['name'];
  354. }
  355. if(!empty($val['class_2']))
  356. {
  357. $cate_info = $goods_cate_model->getInfoById($val['class_2'],"name");
  358. $val['cate2_name'] = empty($cate_info) ? '' : $cate_info['name'];
  359. }
  360. if(!empty($val['class_3']))
  361. {
  362. $cate_info = $goods_cate_model->getInfoById($val['class_3'],"name");
  363. $val['cate3_name'] = empty($cate_info) ? '' : $cate_info['name'];
  364. }
  365. $data['list'][$key] = $val;
  366. }
  367. $this->assign('empty',$data['empty']);// 赋值数据集
  368. $this->assign('list',$data['list']);// 赋值数据集
  369. $this->assign('page',$data['page']);// 赋值分页输出
  370. $cate_data = $this->get_json_category_tree(0);
  371. $this->assign('cate_data',$cate_data);// 赋值数据集
  372. $this->assign('seller_id',$seller_id);// 赋值数据集
  373. $this->display();
  374. }
  375. function add_store_bind_class()
  376. {
  377. $id = intval($_POST['seller_id']);
  378. if(empty($_POST['class_1']))
  379. {
  380. $status = array('status'=>'fail','message'=>'请选择需要绑定的类目','jump'=>U('SellerManage/store_bind_class','id='.$id));
  381. $this->osc_alert($status);
  382. }
  383. if(empty($_POST['commis_rate']))
  384. {
  385. $status = array('status'=>'fail','message'=>'请填写佣金比例','jump'=>U('SellerManage/store_bind_class','id='.$id));
  386. $this->osc_alert($status);
  387. }
  388. $store_bind_class = D('Admin/StoreBindClass');
  389. $res = $store_bind_class->add_store_bind_class($_POST);
  390. if($res)
  391. {
  392. $status = array('status'=>'success','message'=>'添加成功','jump'=>U('SellerManage/store_bind_class','id='.$id));
  393. $this->osc_alert($status);
  394. } else {
  395. $status = array('status'=>'fail','message'=>'添加失败','jump'=>U('SellerManage/store_bind_class','id='.$id));
  396. $this->osc_alert($status);
  397. }
  398. }
  399. function delstorebind()
  400. {
  401. $id = intval($_GET['id']);
  402. $bid = intval($_GET['bid']);
  403. $store_bind_class = D('Admin/StoreBindClass');
  404. if($store_bind_class->add_bind_class($bid))
  405. {
  406. $status = array('status'=>'success','message'=>'删除成功','jump'=>U('SellerManage/store_bind_class','id='.$id));
  407. $this->osc_alert($status);
  408. } else {
  409. $status = array('status'=>'fail','message'=>'删除失败','jump'=>U('SellerManage/store_bind_class','id='.$id));
  410. $this->osc_alert($status);
  411. }
  412. }
  413. /**
  414. * Ajax 获取分类数据,pid一层层获取
  415. * @param number $pid
  416. */
  417. function get_json_category_tree($pid=0,$is_ajax=0)
  418. {
  419. if(isset($_GET['pid']) && isset($_GET['is_ajax']))
  420. {
  421. $is_ajax = intval($_GET['is_ajax']);
  422. $pid = intval($_GET['pid']);
  423. }
  424. $goods_category = D('Admin/GoodsCategory');
  425. $data = $goods_category->get_parent_cateory($pid);
  426. if($is_ajax == 0)
  427. {
  428. return $data;
  429. } else {
  430. $result = array();
  431. $result['code'] = empty($data) ? 0 : 1;
  432. $result['list'] = $data;
  433. echo json_encode($result);
  434. die();
  435. }
  436. }
  437. }
  438. ?>