Ownshop.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 控制器
  11. */
  12. class Ownshop extends AdminControl
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize();
  17. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/ownshop.lang.php');
  18. }
  19. public function index()
  20. {
  21. $condition = array();
  22. $condition[] = array('is_platform_store', '=', 1);
  23. $store_name = trim(input('get.store_name'));
  24. if (strlen($store_name) > 0) {
  25. $condition[] = array('store_name', 'like', "%$store_name%");
  26. View::assign('store_name', $store_name);
  27. }
  28. $ownshop_model = model('store');
  29. $storeList = $ownshop_model->getStoreList($condition, 10);
  30. View::assign('store_list', $storeList);
  31. View::assign('show_page', $ownshop_model->page_info->render());
  32. $this->setAdminCurItem('index');
  33. return View::fetch('ownshop_list');
  34. }
  35. public function add()
  36. {
  37. if (!request()->isPost()) {
  38. return View::fetch('ownshop_add');
  39. } else {
  40. $member_name = input('post.member_name');
  41. $member_password = input('post.member_password');
  42. $store_name = input('post.store_name');
  43. if (strlen($member_name) < 3 || strlen($member_name) > 15)
  44. $this->error(lang('account_length_error'));
  45. if (strlen($member_password) < 6)
  46. $this->error(lang('password_length_error'));
  47. if (!$this->checkMemberName($member_name))
  48. $this->error(lang('member_name_remote'));
  49. try {
  50. $memberId = model('member')->addMember(array(
  51. 'member_name' => $member_name,
  52. 'member_password' => $member_password,
  53. ));
  54. } catch (Exception $ex) {
  55. $this->error(lang('account_add_fail'));
  56. }
  57. $store_model = model('store');
  58. $saveArray = array();
  59. $saveArray['store_name'] = $store_name;
  60. $saveArray['member_id'] = $memberId;
  61. $saveArray['member_name'] = $member_name;
  62. $saveArray['seller_name'] = $member_name;
  63. $saveArray['bind_all_gc'] = 1;
  64. $saveArray['store_state'] = 1;
  65. $saveArray['store_addtime'] = TIMESTAMP;
  66. $saveArray['is_platform_store'] = 1;
  67. $store_id = $store_model->addStore($saveArray);
  68. model('seller')->addSeller(array(
  69. 'seller_name' => $member_name,
  70. 'member_id' => $memberId,
  71. 'store_id' => $store_id,
  72. 'sellergroup_id' => 0,
  73. 'is_admin' => 1,
  74. ));
  75. model('storejoinin')->addStorejoinin(array(
  76. 'seller_name' => $member_name,
  77. 'store_name' => $store_name,
  78. 'member_name' => $member_name,
  79. 'member_id' => $memberId,
  80. 'joinin_state' => 40,
  81. 'company_province_id' => 0,
  82. 'storeclass_bail' => 0,
  83. 'joinin_year' => 1,
  84. ));
  85. // 添加相册默认
  86. $album_model = model('album');
  87. $album_arr = array();
  88. $album_arr['aclass_name'] = lang('default_album');
  89. $album_arr['store_id'] = $store_id;
  90. $album_arr['aclass_des'] = '';
  91. $album_arr['aclass_sort'] = '255';
  92. $album_arr['aclass_cover'] = '';
  93. $album_arr['aclass_uploadtime'] = TIMESTAMP;
  94. $album_arr['aclass_isdefault'] = '1';
  95. $album_model->addAlbumclass($album_arr);
  96. //插入店铺扩展表
  97. $store_model->addStoreextend(array('store_id' => $store_id));
  98. // 删除自营店id缓存
  99. model('store')->dropCachedOwnShopIds();
  100. $this->log(lang('add_ownshop') . ": {$saveArray['store_name']}");
  101. dsLayerOpenSuccess(lang('ds_common_op_succ'), (string)url('Ownshop/index'));
  102. }
  103. }
  104. /*
  105. // 删除自营店铺
  106. public function del() {
  107. $store_id = intval(input('param.id'));
  108. $store_model = model('store');
  109. $storeArray = $store_model->getOneStore(array('store_id'=>$store_id),'is_platform_store,store_name');
  110. if (empty($storeArray)) {
  111. $this->error('自营店铺不存在');
  112. }
  113. if (!$storeArray['is_platform_store']) {
  114. $this->error('不能在此删除非自营店铺');
  115. }
  116. $condition = array(
  117. 'store_id' => $store_id,
  118. );
  119. if (model('goods')->getGoodsCount($condition) > 0)
  120. $this->error('已经发布商品的自营店铺不能被删除');
  121. // 完全删除店铺
  122. $store_model->delStoreEntirely($condition);
  123. // 删除自营店id缓存
  124. model('store')->dropCachedOwnShopIds();
  125. $this->log("删除自营店铺: {$storeArray['store_name']}");
  126. ds_json_encode(10000, lang('ds_common_op_succ'));
  127. }
  128. */
  129. public function edit()
  130. {
  131. $store_model = model('store');
  132. $store_id = intval(input('param.id'));
  133. $storeArray = $store_model->getStoreInfoByID($store_id);
  134. if (!$storeArray['is_platform_store']) {
  135. $this->error(lang('cannot_manage_no_ownshop'));
  136. }
  137. if (!request()->isPost()) {
  138. if (empty($storeArray))
  139. $this->error(lang('store_not_exist'));
  140. View::assign('store_array', $storeArray);
  141. //店铺分类
  142. $storeclass_model = model('storeclass');
  143. $parent_list = $storeclass_model->getStoreclassList(array(), '', false);
  144. View::assign('class_list', $parent_list);
  145. return View::fetch('ownshop_edit');
  146. } else {
  147. $saveArray = array();
  148. $saveArray['storeclass_id'] = intval(input('post.storeclass_id'));
  149. $saveArray['store_name'] = input('post.store_name');
  150. $saveArray['bind_all_gc'] = input('post.bind_all_gc') ? 1 : 0;
  151. $saveArray['store_state'] = input('post.store_state') ? 1 : 0;
  152. $saveArray['store_close_info'] = input('post.store_close_info');
  153. $goods_model = model('goods');
  154. $condition = array();
  155. $condition[] = array('store_id', '=', $store_id);
  156. $goods_model->editProducesOffline($condition);
  157. $store_model->editStore($saveArray, $condition);
  158. if ($storeArray['store_name'] != $saveArray['store_name']) {
  159. $goods_model = model('goods');
  160. $goods_model->editGoodsCommon(array('store_name' => $saveArray['store_name']), array('store_id' => $store_id));
  161. $goods_model->editGoods(array('store_name' => $saveArray['store_name']), array('store_id' => $store_id));
  162. }
  163. // 删除自营店id缓存
  164. model('store')->dropCachedOwnShopIds();
  165. $this->log(lang('edit_ownshop') . ": {$saveArray['store_name']}");
  166. dsLayerOpenSuccess(lang('ds_common_op_succ'), (string)url('Ownshop/index'));
  167. }
  168. }
  169. /**
  170. * 编辑保存注册信息
  171. */
  172. public function storejoinin_edit()
  173. {
  174. if (request()->isPost()) {
  175. $member_id = input('post.member_id');
  176. if ($member_id <= 0) {
  177. $this->error(lang('param_error'));
  178. }
  179. $param = array();
  180. $param['company_name'] = input('post.company_name');
  181. $param['company_province_id'] = intval(input('post.province_id'));
  182. $param['company_address'] = input('post.company_address');
  183. $param['company_address_detail'] = input('post.company_address_detail');
  184. $param['company_registered_capital'] = intval(input('post.company_registered_capital'));
  185. $param['contacts_name'] = input('post.contacts_name');
  186. $param['contacts_phone'] = input('post.contacts_phone');
  187. $param['contacts_email'] = input('post.contacts_email');
  188. $param['business_licence_number'] = input('post.business_licence_number');
  189. $param['business_licence_address'] = input('post.business_licence_address');
  190. $param['business_licence_start'] = input('post.business_licence_start');
  191. $param['business_licence_end'] = input('post.business_licence_end');
  192. $param['business_sphere'] = input('post.business_sphere');
  193. if (!empty($_FILES['business_licence_number_electronic']['name'])) {
  194. $param['business_licence_number_electronic'] = $this->upload_image('business_licence_number_electronic');
  195. }
  196. $param['bank_account_name'] = input('post.bank_account_name');
  197. $param['bank_account_number'] = input('post.bank_account_number');
  198. $param['bank_name'] = input('post.bank_name');
  199. $param['bank_address'] = input('post.bank_address');
  200. $param['settlement_bank_account_name'] = input('post.settlement_bank_account_name');
  201. $param['settlement_bank_account_number'] = input('post.settlement_bank_account_number');
  202. $param['settlement_bank_name'] = input('post.settlement_bank_name');
  203. $param['settlement_bank_address'] = input('post.settlement_bank_address');
  204. $result = model('storejoinin')->editStorejoinin($param, array('member_id' => $member_id));
  205. if ($result >= 0) {
  206. //更新店铺信息
  207. $store_update = array();
  208. $store_update['store_company_name'] = $param['company_name'];
  209. $store_update['area_info'] = $param['company_address'];
  210. $store_update['store_address'] = $param['company_address_detail'];
  211. $store_model = model('store');
  212. $store_info = $store_model->getStoreInfo(array('member_id' => $member_id));
  213. if (!empty($store_info)) {
  214. $r = $store_model->editStore($store_update, array('member_id' => $member_id));
  215. $this->log('编辑店铺信息' . '[ID:' . $r . ']', 1);
  216. }
  217. $this->success(lang('ds_common_op_succ'), (string) url('Ownshop/index'));
  218. } else {
  219. $this->error(lang('ds_common_op_fail'));
  220. }
  221. } else {
  222. $store_model = model('store');
  223. $store_id = intval(input('param.id'));
  224. $storeArray = $store_model->getStoreInfoByID($store_id);
  225. $joinin_detail = model('storejoinin')->getOneStorejoinin(array('member_id' => $storeArray['member_id']));
  226. View::assign('joinin_detail', $joinin_detail);
  227. $this->setAdminCurItem('store_edit');
  228. return View::fetch('storejoinin_edit');
  229. }
  230. }
  231. public function check_seller_name()
  232. {
  233. $seller_name = input('get.seller_name');
  234. echo json_encode($this->checkSellerName($seller_name));
  235. exit;
  236. }
  237. private function checkSellerName($sellerName)
  238. {
  239. // 判断store_joinin是否存在记录
  240. $count = (int) model('storejoinin')->getStorejoininCount(array(
  241. 'seller_name' => $sellerName,
  242. ));
  243. if ($count > 0) {
  244. return FALSE;
  245. }
  246. $seller = model('seller')->getSellerInfo(array(
  247. 'seller_name' => $sellerName,
  248. ));
  249. if (!empty($seller)) {
  250. return FALSE;
  251. }
  252. return TRUE;
  253. }
  254. public function check_member_name()
  255. {
  256. $member_name = input('get.member_name');
  257. echo json_encode($this->checkMemberName($member_name));
  258. exit;
  259. }
  260. private function checkMemberName($member_name)
  261. {
  262. // 判断store_joinin是否存在记录
  263. $count = (int) model('storejoinin')->getStorejoininCount(array(
  264. 'member_name' => $member_name,
  265. ));
  266. if ($count > 0)
  267. return false;
  268. return !model('member')->getMemberCount(array(
  269. 'member_name' => $member_name,
  270. ));
  271. }
  272. public function bind_class()
  273. {
  274. $store_id = intval(input('param.id'));
  275. $store_model = model('store');
  276. $storebindclass_model = model('storebindclass');
  277. $goodsclass_model = model('goodsclass');
  278. $gc_list = $goodsclass_model->getGoodsclassListByParentId(0);
  279. View::assign('gc_list', $gc_list);
  280. $store_info = $store_model->getStoreInfoByID($store_id);
  281. if (empty($store_info)) {
  282. $this->error(lang('param_error'));
  283. }
  284. View::assign('store_info', $store_info);
  285. $store_bind_class_list = $storebindclass_model->getStorebindclassList(array('store_id' => $store_id), 30);
  286. $goods_class = model('goodsclass')->getGoodsclassIndexedListAll();
  287. for ($i = 0, $j = count($store_bind_class_list); $i < $j; $i++) {
  288. $store_bind_class_list[$i]['class_1_name'] = @$goods_class[$store_bind_class_list[$i]['class_1']]['gc_name'];
  289. $store_bind_class_list[$i]['class_2_name'] = @$goods_class[$store_bind_class_list[$i]['class_2']]['gc_name'];
  290. $store_bind_class_list[$i]['class_3_name'] = @$goods_class[$store_bind_class_list[$i]['class_3']]['gc_name'];
  291. }
  292. View::assign('store_bind_class_list', $store_bind_class_list);
  293. View::assign('showpage', $storebindclass_model->page_info->render());
  294. $this->setAdminCurItem('bind_class');
  295. return View::fetch('ownshop_bind_class');
  296. }
  297. /**
  298. * 添加经营类目
  299. */
  300. public function bind_class_add()
  301. {
  302. $store_id = intval(input('post.store_id'));
  303. $commis_rate = intval(input('post.commis_rate'));
  304. if ($commis_rate < 0 || $commis_rate > 100) {
  305. $this->error(lang('param_error'));
  306. }
  307. @list($class_1, $class_2, $class_3) = explode(',', input('post.goods_class'));
  308. $storebindclass_model = model('storebindclass');
  309. $goodsclass_model = model('goodsclass');
  310. $param = array();
  311. $param['store_id'] = $store_id;
  312. $param['class_1'] = $class_1;
  313. $param['storebindclass_state'] = 2;
  314. $param['commis_rate'] = $commis_rate;
  315. if (empty($class_2)) {
  316. //如果没选 二级
  317. $class_2_list = $goodsclass_model->getGoodsclassList(array('gc_parent_id' => $class_1));
  318. if (!empty($class_2_list)) {
  319. foreach ($class_2_list as $class_2_info) {
  320. $class_3_list = $goodsclass_model->getGoodsclassList(array('gc_parent_id' => $class_2_info['gc_id']));
  321. if (!empty($class_3_list)) {
  322. $param['class_2'] = $class_2_info['gc_id'];
  323. foreach ($class_3_list as $class_3_info) {
  324. $param['class_3'] = $class_3_info['gc_id'];
  325. $result = $this->_add_bind_class($param);
  326. }
  327. }
  328. }
  329. } else {
  330. //只有一级分类
  331. $param['class_2'] = $param['class_3'] = 0;
  332. $result = $this->_add_bind_class($param);
  333. }
  334. } else if (empty($class_3)) {
  335. //如果没选二没选三级
  336. $param['class_2'] = $class_2;
  337. $class_3_list = $goodsclass_model->getGoodsclassList(array('gc_parent_id' => $class_2));
  338. if (!empty($class_3_list)) {
  339. foreach ($class_3_list as $class_3_info) {
  340. $param['class_3'] = $class_3_info['gc_id'];
  341. // 检查类目是否已经存在
  342. $store_bind_class_info = $storebindclass_model->getStorebindclassInfo($param);
  343. if (empty($store_bind_class_info)) {
  344. $result = $this->_add_bind_class($param);
  345. }
  346. }
  347. } else {
  348. //二级就是最后一级
  349. $param['class_3'] = 0;
  350. $result = $this->_add_bind_class($param);
  351. }
  352. } else {
  353. $param['class_2'] = $class_2;
  354. $param['class_3'] = $class_3;
  355. $result = $this->_add_bind_class($param);
  356. }
  357. if ($result) {
  358. // 删除自营店id缓存
  359. model('store')->dropCachedOwnShopIds();
  360. $this->log('增加自营店铺经营类目,类目编号:' . $result . ',店铺编号:' . $store_id);
  361. $this->success(lang('ds_common_save_succ'));
  362. } else {
  363. $this->error(lang('ds_common_save_fail'));
  364. }
  365. }
  366. private function _add_bind_class($param)
  367. {
  368. $storebindclass_model = model('storebindclass');
  369. // 检查类目是否已经存在
  370. $store_bind_class_info = $storebindclass_model->getStorebindclassInfo($param);
  371. if (!empty($store_bind_class_info))
  372. return true;
  373. return $storebindclass_model->addStorebindclass($param);
  374. }
  375. /**
  376. * 删除经营类目
  377. */
  378. public function bind_class_del()
  379. {
  380. $bid = input('param.bid');
  381. $bid_array = ds_delete_param($bid);
  382. if ($bid_array == FALSE) {
  383. ds_json_encode('10001', lang('param_error'));
  384. }
  385. $storebindclass_model = model('storebindclass');
  386. foreach ($bid_array as $key => $bid) {
  387. $store_bind_class_info = $storebindclass_model->getStorebindclassInfo(array('storebindclass_id' => $bid));
  388. if (empty($store_bind_class_info)) {
  389. ds_json_encode('10001', lang('store_bind_class_drop_fail'));
  390. }
  391. /* 自营店不下架商品
  392. $goods_model = model('goods');
  393. // 商品下架
  394. $condition = array();
  395. $condition[] = array('store_id','=',$store_bind_class_info['store_id']);
  396. $gc_id = $store_bind_class_info['class_1'].','.$store_bind_class_info['class_2'].','.$store_bind_class_info['class_3'];
  397. $update = array();
  398. $update['goods_stateremark'] = '管理员删除经营类目';
  399. $condition[]=array('gc_id','in', rtrim($gc_id, ','));
  400. $goods_model->editProducesLockUp($update, $condition);
  401. */
  402. $result = $storebindclass_model->delStorebindclass(array('storebindclass_id' => $bid));
  403. if (!$result) {
  404. ds_json_encode('10001', lang('store_bind_class_drop_fail'));
  405. }
  406. // 删除自营店id缓存
  407. model('store')->dropCachedOwnShopIds();
  408. $this->log('删除自营店铺经营类目,类目编号:' . $bid . ',店铺编号:' . $store_bind_class_info['store_id']);
  409. }
  410. ds_json_encode('10000', lang('ds_common_del_succ'));
  411. }
  412. public function bind_class_update()
  413. {
  414. $bid = intval(input('param.id'));
  415. if ($bid <= 0) {
  416. echo json_encode(array('result' => FALSE, 'message' => lang('param_error')));
  417. die;
  418. }
  419. $new_commis_rate = intval(input('get.value'));
  420. if ($new_commis_rate < 0 || $new_commis_rate >= 100) {
  421. echo json_encode(array('result' => FALSE, 'message' => lang('param_error')));
  422. die;
  423. } else {
  424. $update = array('commis_rate' => $new_commis_rate);
  425. $condition = array('storebindclass_id' => $bid);
  426. $storebindclass_model = model('storebindclass');
  427. $result = $storebindclass_model->editStorebindclass($update, $condition);
  428. if ($result) {
  429. // 删除自营店id缓存
  430. model('store')->dropCachedOwnShopIds();
  431. $this->log('更新自营店铺经营类目,类目编号:' . $bid);
  432. echo json_encode(array('result' => TRUE));
  433. die;
  434. } else {
  435. echo json_encode(array('result' => FALSE, 'message' => lang('ds_common_op_fail')));
  436. die;
  437. }
  438. }
  439. }
  440. /**
  441. * 验证店铺名称是否存在
  442. */
  443. public function ckeck_store_name()
  444. {
  445. $store_name = trim(input('get.store_name'));
  446. if (empty($store_name)) {
  447. echo 'false';
  448. exit;
  449. }
  450. $where = array();
  451. $where[] = array('store_name', '=', $store_name);
  452. $store_id = input('get.store_id');
  453. if (isset($store_id)) {
  454. $where[] = array('store_id', '<>', $store_id);
  455. }
  456. $store_info = model('store')->getStoreInfo($where);
  457. if (!empty($store_info['store_name'])) {
  458. echo 'false';
  459. } else {
  460. echo 'true';
  461. }
  462. }
  463. //ajax操作
  464. public function ajax()
  465. {
  466. $store_model = model('store');
  467. switch (input('param.branch')) {
  468. /**
  469. * 品牌名称
  470. */
  471. case 'store_sort':
  472. $id = intval(input('param.id'));
  473. $result = $store_model->editStore(array('store_sort' => trim(input('param.value'))), array('store_id' => $id));
  474. if ($result) {
  475. $this->log(lang('ds_edit') . '自营店铺' . '[' . $id . ']', 1);
  476. }
  477. echo 'true';
  478. exit;
  479. break;
  480. }
  481. }
  482. /**
  483. * 获取卖家栏目列表,针对控制器下的栏目
  484. */
  485. protected function getAdminItemList()
  486. {
  487. $menu_array = array(
  488. array(
  489. 'name' => 'index',
  490. 'text' => lang('ds_manage'),
  491. 'url' => (string)url('Ownshop/index')
  492. ), array(
  493. 'name' => 'add',
  494. 'text' => lang('ds_new'),
  495. 'url' => "javascript:dsLayerOpen('" . (string)url('Ownshop/add') . "','" . lang('ds_new') . "')"
  496. )
  497. );
  498. if (request()->action() == 'bind_class') {
  499. $menu_array[] = array(
  500. 'name' => 'bind_class',
  501. 'text' => lang('bind_class'),
  502. 'url' => (string)url('Ownshop/bind_class')
  503. );
  504. }
  505. return $menu_array;
  506. }
  507. }