Ownshop.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  10. * 网站地址: https://www.valimart.net/
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 控制器
  15. */
  16. class Ownshop extends AdminControl {
  17. public function initialize() {
  18. parent::initialize();
  19. Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/ownshop.lang.php');
  20. }
  21. public function index() {
  22. $condition = array();
  23. $condition[]=array('is_platform_store' ,'=', 1);
  24. $store_name = trim(input('get.store_name'));
  25. if (strlen($store_name) > 0) {
  26. $condition[]=array('store_name','like', "%$store_name%");
  27. View::assign('store_name', $store_name);
  28. }
  29. $ownshop_model = model('store');
  30. $storeList = $ownshop_model->getStoreList($condition,10);
  31. View::assign('store_list', $storeList);
  32. View::assign('show_page', $ownshop_model->page_info->render());
  33. $this->setAdminCurItem('index');
  34. return View::fetch('ownshop_list');
  35. }
  36. public function add() {
  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. $store_model = model('store');
  131. $store_id = intval(input('param.id'));
  132. $storeArray = $store_model->getStoreInfoByID($store_id);
  133. if (!$storeArray['is_platform_store']) {
  134. $this->error(lang('cannot_manage_no_ownshop'));
  135. }
  136. if (!request()->isPost()) {
  137. if (empty($storeArray))
  138. $this->error(lang('store_not_exist'));
  139. View::assign('store_array', $storeArray);
  140. //店铺分类
  141. $storeclass_model = model('storeclass');
  142. $parent_list = $storeclass_model->getStoreclassList(array(), '', false);
  143. View::assign('class_list', $parent_list);
  144. return View::fetch('ownshop_edit');
  145. }else {
  146. $saveArray = array();
  147. $saveArray['storeclass_id'] = intval(input('post.storeclass_id'));
  148. $saveArray['store_name'] = input('post.store_name');
  149. $saveArray['bind_all_gc'] = input('post.bind_all_gc') ? 1 : 0;
  150. $saveArray['store_state'] = input('post.store_state') ? 1 : 0;
  151. $saveArray['store_close_info'] = input('post.store_close_info');
  152. $goods_model = model('goods');
  153. $condition = array();
  154. $condition[] = array('store_id','=',$store_id);
  155. $goods_model->editProducesOffline($condition);
  156. $store_model->editStore($saveArray, $condition);
  157. if($storeArray['store_name']!=$saveArray['store_name']){
  158. $goods_model = model('goods');
  159. $goods_model->editGoodsCommon(array('store_name'=>$saveArray['store_name']), array('store_id'=>$store_id));
  160. $goods_model->editGoods(array('store_name'=>$saveArray['store_name']), array('store_id'=>$store_id));
  161. }
  162. // 删除自营店id缓存
  163. model('store')->dropCachedOwnShopIds();
  164. $this->log(lang('edit_ownshop').": {$saveArray['store_name']}");
  165. dsLayerOpenSuccess(lang('ds_common_op_succ'),(string)url('Ownshop/index'));
  166. }
  167. }
  168. /**
  169. * 编辑保存注册信息
  170. */
  171. public function storejoinin_edit() {
  172. if (request()->isPost()) {
  173. $member_id = input('post.member_id');
  174. if ($member_id <= 0) {
  175. $this->error(lang('param_error'));
  176. }
  177. $param = array();
  178. $param['company_name'] = input('post.company_name');
  179. $param['company_province_id'] = intval(input('post.province_id'));
  180. $param['company_address'] = input('post.company_address');
  181. $param['company_address_detail'] = input('post.company_address_detail');
  182. $param['company_registered_capital'] = intval(input('post.company_registered_capital'));
  183. $param['contacts_name'] = input('post.contacts_name');
  184. $param['contacts_phone'] = input('post.contacts_phone');
  185. $param['contacts_email'] = input('post.contacts_email');
  186. $param['business_licence_number'] = input('post.business_licence_number');
  187. $param['business_licence_address'] = input('post.business_licence_address');
  188. $param['business_licence_start'] = input('post.business_licence_start');
  189. $param['business_licence_end'] = input('post.business_licence_end');
  190. $param['business_sphere'] = input('post.business_sphere');
  191. if (!empty($_FILES['business_licence_number_electronic']['name'])) {
  192. $param['business_licence_number_electronic'] = $this->upload_image('business_licence_number_electronic');
  193. }
  194. $param['bank_account_name'] = input('post.bank_account_name');
  195. $param['bank_account_number'] = input('post.bank_account_number');
  196. $param['bank_name'] = input('post.bank_name');
  197. $param['bank_address'] = input('post.bank_address');
  198. $param['settlement_bank_account_name'] = input('post.settlement_bank_account_name');
  199. $param['settlement_bank_account_number'] = input('post.settlement_bank_account_number');
  200. $param['settlement_bank_name'] = input('post.settlement_bank_name');
  201. $param['settlement_bank_address'] = input('post.settlement_bank_address');
  202. $result = model('storejoinin')->editStorejoinin($param, array('member_id' => $member_id));
  203. if ($result >= 0) {
  204. //更新店铺信息
  205. $store_update = array();
  206. $store_update['store_company_name'] = $param['company_name'];
  207. $store_update['area_info'] = $param['company_address'];
  208. $store_update['store_address'] = $param['company_address_detail'];
  209. $store_model = model('store');
  210. $store_info = $store_model->getStoreInfo(array('member_id' => $member_id));
  211. if (!empty($store_info)) {
  212. $r = $store_model->editStore($store_update, array('member_id' => $member_id));
  213. $this->log('编辑店铺信息' . '[ID:' . $r . ']', 1);
  214. }
  215. $this->success(lang('ds_common_op_succ'), (string) url('Ownshop/index'));
  216. } else {
  217. $this->error(lang('ds_common_op_fail'));
  218. }
  219. }else{
  220. $store_model = model('store');
  221. $store_id = intval(input('param.id'));
  222. $storeArray = $store_model->getStoreInfoByID($store_id);
  223. $joinin_detail = model('storejoinin')->getOneStorejoinin(array('member_id' => $storeArray['member_id']));
  224. View::assign('joinin_detail', $joinin_detail);
  225. $this->setAdminCurItem('store_edit');
  226. return View::fetch('storejoinin_edit');
  227. }
  228. }
  229. public function check_seller_name() {
  230. $seller_name = input('get.seller_name');
  231. echo json_encode($this->checkSellerName($seller_name));
  232. exit;
  233. }
  234. private function checkSellerName($sellerName) {
  235. // 判断store_joinin是否存在记录
  236. $count = (int) model('storejoinin')->getStorejoininCount(array(
  237. 'seller_name' => $sellerName,
  238. ));
  239. if ($count > 0) {
  240. return FALSE;
  241. }
  242. $seller = model('seller')->getSellerInfo(array(
  243. 'seller_name' => $sellerName,
  244. ));
  245. if (!empty($seller)) {
  246. return FALSE;
  247. }
  248. return TRUE;
  249. }
  250. public function check_member_name() {
  251. $member_name = input('get.member_name');
  252. echo json_encode($this->checkMemberName($member_name));
  253. exit;
  254. }
  255. private function checkMemberName($member_name) {
  256. // 判断store_joinin是否存在记录
  257. $count = (int) model('storejoinin')->getStorejoininCount(array(
  258. 'member_name' => $member_name,
  259. ));
  260. if ($count > 0)
  261. return false;
  262. return !model('member')->getMemberCount(array(
  263. 'member_name' => $member_name,
  264. ));
  265. }
  266. public function bind_class() {
  267. $store_id = intval(input('param.id'));
  268. $store_model = model('store');
  269. $storebindclass_model = model('storebindclass');
  270. $goodsclass_model = model('goodsclass');
  271. $gc_list = $goodsclass_model->getGoodsclassListByParentId(0);
  272. View::assign('gc_list', $gc_list);
  273. $store_info = $store_model->getStoreInfoByID($store_id);
  274. if (empty($store_info)) {
  275. $this->error(lang('param_error'));
  276. }
  277. View::assign('store_info', $store_info);
  278. $store_bind_class_list = $storebindclass_model->getStorebindclassList(array('store_id' => $store_id), 30);
  279. $goods_class = model('goodsclass')->getGoodsclassIndexedListAll();
  280. for ($i = 0, $j = count($store_bind_class_list); $i < $j; $i++) {
  281. $store_bind_class_list[$i]['class_1_name'] = @$goods_class[$store_bind_class_list[$i]['class_1']]['gc_name'];
  282. $store_bind_class_list[$i]['class_2_name'] = @$goods_class[$store_bind_class_list[$i]['class_2']]['gc_name'];
  283. $store_bind_class_list[$i]['class_3_name'] = @$goods_class[$store_bind_class_list[$i]['class_3']]['gc_name'];
  284. }
  285. View::assign('store_bind_class_list', $store_bind_class_list);
  286. View::assign('showpage', $storebindclass_model->page_info->render());
  287. $this->setAdminCurItem('bind_class');
  288. return View::fetch('ownshop_bind_class');
  289. }
  290. /**
  291. * 添加经营类目
  292. */
  293. public function bind_class_add() {
  294. $store_id = intval(input('post.store_id'));
  295. $commis_rate = intval(input('post.commis_rate'));
  296. if ($commis_rate < 0 || $commis_rate > 100) {
  297. $this->error(lang('param_error'));
  298. }
  299. @list($class_1, $class_2, $class_3) = explode(',', input('post.goods_class'));
  300. $storebindclass_model = model('storebindclass');
  301. $goodsclass_model = model('goodsclass');
  302. $param = array();
  303. $param['store_id'] = $store_id;
  304. $param['class_1'] = $class_1;
  305. $param['storebindclass_state'] = 2;
  306. $param['commis_rate'] = $commis_rate;
  307. if (empty($class_2)) {
  308. //如果没选 二级
  309. $class_2_list = $goodsclass_model->getGoodsclassList(array('gc_parent_id' => $class_1));
  310. if (!empty($class_2_list)) {
  311. foreach ($class_2_list as $class_2_info) {
  312. $class_3_list = $goodsclass_model->getGoodsclassList(array('gc_parent_id' => $class_2_info['gc_id']));
  313. if (!empty($class_3_list)) {
  314. $param['class_2'] = $class_2_info['gc_id'];
  315. foreach ($class_3_list as $class_3_info) {
  316. $param['class_3'] = $class_3_info['gc_id'];
  317. $result = $this->_add_bind_class($param);
  318. }
  319. }
  320. }
  321. } else {
  322. //只有一级分类
  323. $param['class_2'] = $param['class_3'] = 0;
  324. $result = $this->_add_bind_class($param);
  325. }
  326. } else if (empty($class_3)) {
  327. //如果没选二没选三级
  328. $param['class_2'] = $class_2;
  329. $class_3_list = $goodsclass_model->getGoodsclassList(array('gc_parent_id' => $class_2));
  330. if (!empty($class_3_list)) {
  331. foreach ($class_3_list as $class_3_info) {
  332. $param['class_3'] = $class_3_info['gc_id'];
  333. // 检查类目是否已经存在
  334. $store_bind_class_info = $storebindclass_model->getStorebindclassInfo($param);
  335. if (empty($store_bind_class_info)) {
  336. $result = $this->_add_bind_class($param);
  337. }
  338. }
  339. } else {
  340. //二级就是最后一级
  341. $param['class_3'] = 0;
  342. $result = $this->_add_bind_class($param);
  343. }
  344. } else {
  345. $param['class_2'] = $class_2;
  346. $param['class_3'] = $class_3;
  347. $result = $this->_add_bind_class($param);
  348. }
  349. if ($result) {
  350. // 删除自营店id缓存
  351. model('store')->dropCachedOwnShopIds();
  352. $this->log('增加自营店铺经营类目,类目编号:' . $result . ',店铺编号:' . $store_id);
  353. $this->success(lang('ds_common_save_succ'));
  354. } else {
  355. $this->error(lang('ds_common_save_fail'));
  356. }
  357. }
  358. private function _add_bind_class($param) {
  359. $storebindclass_model = model('storebindclass');
  360. // 检查类目是否已经存在
  361. $store_bind_class_info = $storebindclass_model->getStorebindclassInfo($param);
  362. if (!empty($store_bind_class_info))
  363. return true;
  364. return $storebindclass_model->addStorebindclass($param);
  365. }
  366. /**
  367. * 删除经营类目
  368. */
  369. public function bind_class_del() {
  370. $bid = input('param.bid');
  371. $bid_array = ds_delete_param($bid);
  372. if ($bid_array == FALSE) {
  373. ds_json_encode('10001', lang('param_error'));
  374. }
  375. $storebindclass_model = model('storebindclass');
  376. foreach ($bid_array as $key => $bid) {
  377. $store_bind_class_info = $storebindclass_model->getStorebindclassInfo(array('storebindclass_id' => $bid));
  378. if (empty($store_bind_class_info)) {
  379. ds_json_encode('10001', lang('store_bind_class_drop_fail'));
  380. }
  381. /* 自营店不下架商品
  382. $goods_model = model('goods');
  383. // 商品下架
  384. $condition = array();
  385. $condition[] = array('store_id','=',$store_bind_class_info['store_id']);
  386. $gc_id = $store_bind_class_info['class_1'].','.$store_bind_class_info['class_2'].','.$store_bind_class_info['class_3'];
  387. $update = array();
  388. $update['goods_stateremark'] = '管理员删除经营类目';
  389. $condition[]=array('gc_id','in', rtrim($gc_id, ','));
  390. $goods_model->editProducesLockUp($update, $condition);
  391. */
  392. $result = $storebindclass_model->delStorebindclass(array('storebindclass_id' => $bid));
  393. if (!$result) {
  394. ds_json_encode('10001', lang('store_bind_class_drop_fail'));
  395. }
  396. // 删除自营店id缓存
  397. model('store')->dropCachedOwnShopIds();
  398. $this->log('删除自营店铺经营类目,类目编号:' . $bid . ',店铺编号:' . $store_bind_class_info['store_id']);
  399. }
  400. ds_json_encode('10000', lang('ds_common_del_succ'));
  401. }
  402. public function bind_class_update() {
  403. $bid = intval(input('param.id'));
  404. if ($bid <= 0) {
  405. echo json_encode(array('result' => FALSE, 'message' => lang('param_error')));
  406. die;
  407. }
  408. $new_commis_rate = intval(input('get.value'));
  409. if ($new_commis_rate < 0 || $new_commis_rate >= 100) {
  410. echo json_encode(array('result' => FALSE, 'message' => lang('param_error')));
  411. die;
  412. } else {
  413. $update = array('commis_rate' => $new_commis_rate);
  414. $condition = array('storebindclass_id' => $bid);
  415. $storebindclass_model = model('storebindclass');
  416. $result = $storebindclass_model->editStorebindclass($update, $condition);
  417. if ($result) {
  418. // 删除自营店id缓存
  419. model('store')->dropCachedOwnShopIds();
  420. $this->log('更新自营店铺经营类目,类目编号:' . $bid);
  421. echo json_encode(array('result' => TRUE));
  422. die;
  423. } else {
  424. echo json_encode(array('result' => FALSE, 'message' => lang('ds_common_op_fail')));
  425. die;
  426. }
  427. }
  428. }
  429. /**
  430. * 验证店铺名称是否存在
  431. */
  432. public function ckeck_store_name() {
  433. $store_name = trim(input('get.store_name'));
  434. if (empty($store_name)) {
  435. echo 'false';
  436. exit;
  437. }
  438. $where = array();
  439. $where[]=array('store_name','=',$store_name);
  440. $store_id = input('get.store_id');
  441. if (isset($store_id)) {
  442. $where[]=array('store_id','<>', $store_id);
  443. }
  444. $store_info = model('store')->getStoreInfo($where);
  445. if (!empty($store_info['store_name'])) {
  446. echo 'false';
  447. } else {
  448. echo 'true';
  449. }
  450. }
  451. //ajax操作
  452. public function ajax() {
  453. $store_model = model('store');
  454. switch (input('param.branch')) {
  455. /**
  456. * 品牌名称
  457. */
  458. case 'store_sort':
  459. $id = intval(input('param.id'));
  460. $result = $store_model->editStore(array('store_sort'=>trim(input('param.value'))), array('store_id' => $id));
  461. if($result){
  462. $this->log(lang('ds_edit').'自营店铺' . '[' . $id . ']', 1);
  463. }
  464. echo 'true';
  465. exit;
  466. break;
  467. }
  468. }
  469. /**
  470. * 获取卖家栏目列表,针对控制器下的栏目
  471. */
  472. protected function getAdminItemList() {
  473. $menu_array = array(
  474. array(
  475. 'name' => 'index',
  476. 'text' => lang('ds_manage'),
  477. 'url' => (string)url('Ownshop/index')
  478. ), array(
  479. 'name' => 'add',
  480. 'text' => lang('ds_new'),
  481. 'url' => "javascript:dsLayerOpen('".(string)url('Ownshop/add')."','".lang('ds_new')."')"
  482. )
  483. );
  484. if (request()->action() == 'bind_class') {
  485. $menu_array[] = array(
  486. 'name' => 'bind_class',
  487. 'text' => lang('bind_class'),
  488. 'url' => (string)url('Ownshop/bind_class')
  489. );
  490. }
  491. return $menu_array;
  492. }
  493. }