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