Ownshop.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Ownshop extends AdminControl {
  18. public function initialize() {
  19. parent::initialize();
  20. Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/ownshop.lang.php');
  21. }
  22. public function index() {
  23. $condition = array();
  24. $condition[]=array('is_platform_store' ,'=', 1);
  25. $store_name = trim(input('get.store_name'));
  26. if (strlen($store_name) > 0) {
  27. $condition[]=array('store_name','like', "%$store_name%");
  28. View::assign('store_name', $store_name);
  29. }
  30. $ownshop_model = model('store');
  31. $storeList = $ownshop_model->getStoreList($condition,10);
  32. View::assign('store_list', $storeList);
  33. View::assign('show_page', $ownshop_model->page_info->render());
  34. $this->setAdminCurItem('index');
  35. return View::fetch('ownshop_list');
  36. }
  37. public function add() {
  38. if (!request()->isPost()) {
  39. return View::fetch('ownshop_add');
  40. } else {
  41. $member_name = input('post.member_name');
  42. $member_password = input('post.member_password');
  43. if (strlen($member_name) < 3 || strlen($member_name) > 15 || strlen(input('post.seller_name')) < 3 || strlen(input('post.seller_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. if (!$this->checkSellerName(input('post.seller_name')))
  50. $this->error(lang('seller_name_remote'));
  51. try {
  52. $memberId = model('member')->addMember(array(
  53. 'member_name' => $member_name,
  54. 'member_password' => $member_password,
  55. ));
  56. } catch (Exception $ex) {
  57. $this->error(lang('account_add_fail'));
  58. }
  59. $store_model = model('store');
  60. $saveArray = array();
  61. $saveArray['store_name'] = input('post.store_name');
  62. $saveArray['member_id'] = $memberId;
  63. $saveArray['member_name'] = $member_name;
  64. $saveArray['seller_name'] = input('post.seller_name');
  65. $saveArray['bind_all_gc'] = 1;
  66. $saveArray['store_state'] = 1;
  67. $saveArray['store_addtime'] = TIMESTAMP;
  68. $saveArray['is_platform_store'] = 1;
  69. $store_id = $store_model->addStore($saveArray);
  70. model('seller')->addSeller(array(
  71. 'seller_name' => input('post.seller_name'),
  72. 'member_id' => $memberId,
  73. 'store_id' => $store_id,
  74. 'sellergroup_id' => 0,
  75. 'is_admin' => 1,
  76. ));
  77. // 添加相册默认
  78. $album_model = model('album');
  79. $album_arr = array();
  80. $album_arr['aclass_name'] = lang('default_album');
  81. $album_arr['store_id'] = $store_id;
  82. $album_arr['aclass_des'] = '';
  83. $album_arr['aclass_sort'] = '255';
  84. $album_arr['aclass_cover'] = '';
  85. $album_arr['aclass_uploadtime'] = TIMESTAMP;
  86. $album_arr['aclass_isdefault'] = '1';
  87. $album_model->addAlbumclass($album_arr);
  88. //插入店铺扩展表
  89. $store_model->addStoreextend(array('store_id' => $store_id));
  90. // 删除自营店id缓存
  91. model('store')->dropCachedOwnShopIds();
  92. $this->log(lang('add_ownshop').": {$saveArray['store_name']}");
  93. dsLayerOpenSuccess(lang('ds_common_op_succ'),(string)url('Ownshop/index'));
  94. }
  95. }
  96. /*
  97. // 删除自营店铺
  98. public function del() {
  99. $store_id = intval(input('param.id'));
  100. $store_model = model('store');
  101. $storeArray = $store_model->getOneStore(array('store_id'=>$store_id),'is_platform_store,store_name');
  102. if (empty($storeArray)) {
  103. $this->error('自营店铺不存在');
  104. }
  105. if (!$storeArray['is_platform_store']) {
  106. $this->error('不能在此删除非自营店铺');
  107. }
  108. $condition = array(
  109. 'store_id' => $store_id,
  110. );
  111. if (model('goods')->getGoodsCount($condition) > 0)
  112. $this->error('已经发布商品的自营店铺不能被删除');
  113. // 完全删除店铺
  114. $store_model->delStoreEntirely($condition);
  115. // 删除自营店id缓存
  116. model('store')->dropCachedOwnShopIds();
  117. $this->log("删除自营店铺: {$storeArray['store_name']}");
  118. ds_json_encode(10000, lang('ds_common_op_succ'));
  119. }
  120. */
  121. public function edit() {
  122. $store_model = model('store');
  123. $store_id = intval(input('param.id'));
  124. $storeArray = $store_model->getStoreInfoByID($store_id);
  125. if (!$storeArray['is_platform_store']) {
  126. $this->error(lang('cannot_manage_no_ownshop'));
  127. }
  128. if (!request()->isPost()) {
  129. if (empty($storeArray))
  130. $this->error(lang('store_not_exist'));
  131. View::assign('store_array', $storeArray);
  132. //店铺分类
  133. $storeclass_model = model('storeclass');
  134. $parent_list = $storeclass_model->getStoreclassList(array(), '', false);
  135. View::assign('class_list', $parent_list);
  136. return View::fetch('ownshop_edit');
  137. }else {
  138. $saveArray = array();
  139. $saveArray['storeclass_id'] = intval(input('post.storeclass_id'));
  140. $saveArray['store_name'] = input('post.store_name');
  141. $saveArray['bind_all_gc'] = input('post.bind_all_gc') ? 1 : 0;
  142. $saveArray['store_state'] = input('post.store_state') ? 1 : 0;
  143. $saveArray['store_close_info'] = input('post.store_close_info');
  144. $goods_model = model('goods');
  145. $condition = array();
  146. $condition[] = array('store_id','=',$store_id);
  147. $goods_model->editProducesOffline($condition);
  148. $store_model->editStore($saveArray, $condition);
  149. if($storeArray['store_name']!=$saveArray['store_name']){
  150. $goods_model = model('goods');
  151. $goods_model->editGoodsCommon(array('store_name'=>$saveArray['store_name']), array('store_id'=>$store_id));
  152. $goods_model->editGoods(array('store_name'=>$saveArray['store_name']), array('store_id'=>$store_id));
  153. }
  154. // 删除自营店id缓存
  155. model('store')->dropCachedOwnShopIds();
  156. $this->log(lang('edit_ownshop').": {$saveArray['store_name']}");
  157. dsLayerOpenSuccess(lang('ds_common_op_succ'),(string)url('Ownshop/index'));
  158. }
  159. }
  160. public function check_seller_name() {
  161. $seller_name = input('get.seller_name');
  162. echo json_encode($this->checkSellerName($seller_name));
  163. exit;
  164. }
  165. private function checkSellerName($sellerName) {
  166. // 判断store_joinin是否存在记录
  167. $count = (int) model('storejoinin')->getStorejoininCount(array(
  168. 'seller_name' => $sellerName,
  169. ));
  170. if ($count > 0) {
  171. return FALSE;
  172. }
  173. $seller = model('seller')->getSellerInfo(array(
  174. 'seller_name' => $sellerName,
  175. ));
  176. if (!empty($seller)) {
  177. return FALSE;
  178. }
  179. return TRUE;
  180. }
  181. public function check_member_name() {
  182. $member_name = input('get.member_name');
  183. echo json_encode($this->checkMemberName($member_name));
  184. exit;
  185. }
  186. private function checkMemberName($member_name) {
  187. // 判断store_joinin是否存在记录
  188. $count = (int) model('storejoinin')->getStorejoininCount(array(
  189. 'member_name' => $member_name,
  190. ));
  191. if ($count > 0)
  192. return false;
  193. return !model('member')->getMemberCount(array(
  194. 'member_name' => $member_name,
  195. ));
  196. }
  197. public function bind_class() {
  198. $store_id = intval(input('param.id'));
  199. $store_model = model('store');
  200. $storebindclass_model = model('storebindclass');
  201. $goodsclass_model = model('goodsclass');
  202. $gc_list = $goodsclass_model->getGoodsclassListByParentId(0);
  203. View::assign('gc_list', $gc_list);
  204. $store_info = $store_model->getStoreInfoByID($store_id);
  205. if (empty($store_info)) {
  206. $this->error(lang('param_error'));
  207. }
  208. View::assign('store_info', $store_info);
  209. $store_bind_class_list = $storebindclass_model->getStorebindclassList(array('store_id' => $store_id), 30);
  210. $goods_class = model('goodsclass')->getGoodsclassIndexedListAll();
  211. for ($i = 0, $j = count($store_bind_class_list); $i < $j; $i++) {
  212. $store_bind_class_list[$i]['class_1_name'] = @$goods_class[$store_bind_class_list[$i]['class_1']]['gc_name'];
  213. $store_bind_class_list[$i]['class_2_name'] = @$goods_class[$store_bind_class_list[$i]['class_2']]['gc_name'];
  214. $store_bind_class_list[$i]['class_3_name'] = @$goods_class[$store_bind_class_list[$i]['class_3']]['gc_name'];
  215. }
  216. View::assign('store_bind_class_list', $store_bind_class_list);
  217. View::assign('showpage', $storebindclass_model->page_info->render());
  218. $this->setAdminCurItem('bind_class');
  219. return View::fetch('ownshop_bind_class');
  220. }
  221. /**
  222. * 添加经营类目
  223. */
  224. public function bind_class_add() {
  225. $store_id = intval(input('post.store_id'));
  226. $commis_rate = intval(input('post.commis_rate'));
  227. if ($commis_rate < 0 || $commis_rate > 100) {
  228. $this->error(lang('param_error'));
  229. }
  230. @list($class_1, $class_2, $class_3) = explode(',', input('post.goods_class'));
  231. $storebindclass_model = model('storebindclass');
  232. $goodsclass_model = model('goodsclass');
  233. $param = array();
  234. $param['store_id'] = $store_id;
  235. $param['class_1'] = $class_1;
  236. $param['storebindclass_state'] = 2;
  237. $param['commis_rate'] = $commis_rate;
  238. if (empty($class_2)) {
  239. //如果没选 二级
  240. $class_2_list = $goodsclass_model->getGoodsclassList(array('gc_parent_id' => $class_1));
  241. if (!empty($class_2_list)) {
  242. foreach ($class_2_list as $class_2_info) {
  243. $class_3_list = $goodsclass_model->getGoodsclassList(array('gc_parent_id' => $class_2_info['gc_id']));
  244. if (!empty($class_3_list)) {
  245. $param['class_2'] = $class_2_info['gc_id'];
  246. foreach ($class_3_list as $class_3_info) {
  247. $param['class_3'] = $class_3_info['gc_id'];
  248. $result = $this->_add_bind_class($param);
  249. }
  250. }
  251. }
  252. } else {
  253. //只有一级分类
  254. $param['class_2'] = $param['class_3'] = 0;
  255. $result = $this->_add_bind_class($param);
  256. }
  257. } else if (empty($class_3)) {
  258. //如果没选二没选三级
  259. $param['class_2'] = $class_2;
  260. $class_3_list = $goodsclass_model->getGoodsclassList(array('gc_parent_id' => $class_2));
  261. if (!empty($class_3_list)) {
  262. foreach ($class_3_list as $class_3_info) {
  263. $param['class_3'] = $class_3_info['gc_id'];
  264. // 检查类目是否已经存在
  265. $store_bind_class_info = $storebindclass_model->getStorebindclassInfo($param);
  266. if (empty($store_bind_class_info)) {
  267. $result = $this->_add_bind_class($param);
  268. }
  269. }
  270. } else {
  271. //二级就是最后一级
  272. $param['class_3'] = 0;
  273. $result = $this->_add_bind_class($param);
  274. }
  275. } else {
  276. $param['class_2'] = $class_2;
  277. $param['class_3'] = $class_3;
  278. $result = $this->_add_bind_class($param);
  279. }
  280. if ($result) {
  281. // 删除自营店id缓存
  282. model('store')->dropCachedOwnShopIds();
  283. $this->log('增加自营店铺经营类目,类目编号:' . $result . ',店铺编号:' . $store_id);
  284. $this->success(lang('ds_common_save_succ'));
  285. } else {
  286. $this->error(lang('ds_common_save_fail'));
  287. }
  288. }
  289. private function _add_bind_class($param) {
  290. $storebindclass_model = model('storebindclass');
  291. // 检查类目是否已经存在
  292. $store_bind_class_info = $storebindclass_model->getStorebindclassInfo($param);
  293. if (!empty($store_bind_class_info))
  294. return true;
  295. return $storebindclass_model->addStorebindclass($param);
  296. }
  297. /**
  298. * 删除经营类目
  299. */
  300. public function bind_class_del() {
  301. $bid = input('param.bid');
  302. $bid_array = ds_delete_param($bid);
  303. if ($bid_array == FALSE) {
  304. ds_json_encode('10001', lang('param_error'));
  305. }
  306. $storebindclass_model = model('storebindclass');
  307. foreach ($bid_array as $key => $bid) {
  308. $store_bind_class_info = $storebindclass_model->getStorebindclassInfo(array('storebindclass_id' => $bid));
  309. if (empty($store_bind_class_info)) {
  310. ds_json_encode('10001', lang('store_bind_class_drop_fail'));
  311. }
  312. /* 自营店不下架商品
  313. $goods_model = model('goods');
  314. // 商品下架
  315. $condition = array();
  316. $condition[] = array('store_id','=',$store_bind_class_info['store_id']);
  317. $gc_id = $store_bind_class_info['class_1'].','.$store_bind_class_info['class_2'].','.$store_bind_class_info['class_3'];
  318. $update = array();
  319. $update['goods_stateremark'] = '管理员删除经营类目';
  320. $condition[]=array('gc_id','in', rtrim($gc_id, ','));
  321. $goods_model->editProducesLockUp($update, $condition);
  322. */
  323. $result = $storebindclass_model->delStorebindclass(array('storebindclass_id' => $bid));
  324. if (!$result) {
  325. ds_json_encode('10001', lang('store_bind_class_drop_fail'));
  326. }
  327. // 删除自营店id缓存
  328. model('store')->dropCachedOwnShopIds();
  329. $this->log('删除自营店铺经营类目,类目编号:' . $bid . ',店铺编号:' . $store_bind_class_info['store_id']);
  330. }
  331. ds_json_encode('10000', lang('ds_common_del_succ'));
  332. }
  333. public function bind_class_update() {
  334. $bid = intval(input('param.id'));
  335. if ($bid <= 0) {
  336. echo json_encode(array('result' => FALSE, 'message' => lang('param_error')));
  337. die;
  338. }
  339. $new_commis_rate = intval(input('get.value'));
  340. if ($new_commis_rate < 0 || $new_commis_rate >= 100) {
  341. echo json_encode(array('result' => FALSE, 'message' => lang('param_error')));
  342. die;
  343. } else {
  344. $update = array('commis_rate' => $new_commis_rate);
  345. $condition = array('storebindclass_id' => $bid);
  346. $storebindclass_model = model('storebindclass');
  347. $result = $storebindclass_model->editStorebindclass($update, $condition);
  348. if ($result) {
  349. // 删除自营店id缓存
  350. model('store')->dropCachedOwnShopIds();
  351. $this->log('更新自营店铺经营类目,类目编号:' . $bid);
  352. echo json_encode(array('result' => TRUE));
  353. die;
  354. } else {
  355. echo json_encode(array('result' => FALSE, 'message' => lang('ds_common_op_fail')));
  356. die;
  357. }
  358. }
  359. }
  360. /**
  361. * 验证店铺名称是否存在
  362. */
  363. public function ckeck_store_name() {
  364. $store_name = trim(input('get.store_name'));
  365. if (empty($store_name)) {
  366. echo 'false';
  367. exit;
  368. }
  369. $where = array();
  370. $where[]=array('store_name','=',$store_name);
  371. $store_id = input('get.store_id');
  372. if (isset($store_id)) {
  373. $where[]=array('store_id','<>', $store_id);
  374. }
  375. $store_info = model('store')->getStoreInfo($where);
  376. if (!empty($store_info['store_name'])) {
  377. echo 'false';
  378. } else {
  379. echo 'true';
  380. }
  381. }
  382. //ajax操作
  383. public function ajax() {
  384. $store_model = model('store');
  385. switch (input('param.branch')) {
  386. /**
  387. * 品牌名称
  388. */
  389. case 'store_sort':
  390. $id = intval(input('param.id'));
  391. $result = $store_model->editStore(array('store_sort'=>trim(input('param.value'))), array('store_id' => $id));
  392. if($result){
  393. $this->log(lang('ds_edit').'自营店铺' . '[' . $id . ']', 1);
  394. }
  395. echo 'true';
  396. exit;
  397. break;
  398. }
  399. }
  400. /**
  401. * 获取卖家栏目列表,针对控制器下的栏目
  402. */
  403. protected function getAdminItemList() {
  404. $menu_array = array(
  405. array(
  406. 'name' => 'index',
  407. 'text' => lang('ds_manage'),
  408. 'url' => (string)url('Ownshop/index')
  409. ), array(
  410. 'name' => 'add',
  411. 'text' => lang('ds_new'),
  412. 'url' => "javascript:dsLayerOpen('".(string)url('Ownshop/add')."','".lang('ds_new')."')"
  413. )
  414. );
  415. if (request()->action() == 'bind_class') {
  416. $menu_array[] = array(
  417. 'name' => 'bind_class',
  418. 'text' => lang('bind_class'),
  419. 'url' => (string)url('Ownshop/bind_class')
  420. );
  421. }
  422. return $menu_array;
  423. }
  424. }