ownshop.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. <?php
  2. /**
  3. * 自营店铺
  4. ***/
  5. defined('InShopNC') or exit('Access Invalid!');
  6. class ownshopControl extends SystemControl
  7. {
  8. public function __construct()
  9. {
  10. parent::__construct();
  11. }
  12. public function indexOp()
  13. {
  14. $this->listOp();
  15. }
  16. public function listOp()
  17. {
  18. $model = model('store');
  19. $condition = array(
  20. 'is_own_shop' => 1,
  21. );
  22. $storeName = trim($_GET['store_name']);
  23. if (strlen($storeName) > 0) {
  24. $condition['store_name'] = array('like', "%$storeName%");
  25. Tpl::output('store_name', $storeName);
  26. }
  27. $storeList = $model->where($condition)->page(10)->select();
  28. $storeIds = array();
  29. foreach ($storeList as $s)
  30. $storeIds[$s['store_id']] = null;
  31. $storeIds = array_keys($storeIds);
  32. $storesWithGoods = model('goods')->where(array(
  33. 'store_id' => array('in', $storeIds),
  34. ))->field('distinct store_id')->key('store_id')->select();
  35. Tpl::output('store_list', $storeList);
  36. Tpl::output('page', $model->showpage());
  37. Tpl::output('storesWithGoods', $storesWithGoods);
  38. Tpl::showpage('ownshop.list');
  39. }
  40. public function addOp()
  41. {
  42. if (chksubmit())
  43. {
  44. $memberName = $_POST['member_name'];
  45. $memberPasswd = (string) $_POST['member_passwd'];
  46. if (strlen($memberName) < 3 || strlen($memberName) > 15
  47. || strlen($_POST['seller_name']) < 3 || strlen($_POST['seller_name']) > 15)
  48. showMessage('账号名称必须是3~15位', '', 'html', 'error');
  49. if (strlen($memberPasswd) < 6)
  50. showMessage('登录密码不能短于6位', '', 'html', 'error');
  51. if (!$this->checkMemberName($memberName))
  52. showMessage('店主账号已被占用', '', 'html', 'error');
  53. if (!$this->checkSellerName($_POST['seller_name']))
  54. showMessage('店主卖家账号名称已被其它店铺占用', '', 'html', 'error');
  55. try
  56. {
  57. $memberId = model('member')->addMember(array(
  58. 'member_name' => $memberName,
  59. 'member_passwd' => $memberPasswd,
  60. 'member_email' => '',
  61. ));
  62. }
  63. catch (Exception $ex)
  64. {
  65. showMessage('店主账号新增失败', '', 'html', 'error');
  66. }
  67. $storeModel = model('store');
  68. $saveArray = array();
  69. $saveArray['store_name'] = $_POST['store_name'];
  70. $saveArray['member_id'] = $memberId;
  71. $saveArray['member_name'] = $memberName;
  72. $saveArray['seller_name'] = $_POST['seller_name'];
  73. $saveArray['bind_all_gc'] = 1;
  74. $saveArray['store_state'] = 1;
  75. $saveArray['store_time'] = time();
  76. $saveArray['is_own_shop'] = 1;
  77. $storeId = $storeModel->addStore($saveArray);
  78. model('seller')->addSeller(array(
  79. 'seller_name' => $_POST['seller_name'],
  80. 'member_id' => $memberId,
  81. 'store_id' => $storeId,
  82. 'seller_group_id' => 0,
  83. 'is_admin' => 1,
  84. ));
  85. // 添加相册默认
  86. $album_model = Model('album');
  87. $album_arr = array();
  88. $album_arr['aclass_name'] = '默认相册';
  89. $album_arr['store_id'] = $storeId;
  90. $album_arr['aclass_des'] = '';
  91. $album_arr['aclass_sort'] = '255';
  92. $album_arr['aclass_cover'] = '';
  93. $album_arr['upload_time'] = time();
  94. $album_arr['is_default'] = '1';
  95. $album_model->addClass($album_arr);
  96. //插入店铺扩展表
  97. $model = Model();
  98. $model->table('store_extend')->insert(array('store_id'=>$storeId));
  99. // 删除自营店id缓存
  100. Model('store')->dropCachedOwnShopIds();
  101. $this->log("新增自营店铺: {$saveArray['store_name']}");
  102. showMessage('操作成功', urlAdmin('ownshop', 'list'));
  103. return;
  104. }
  105. Tpl::showpage('ownshop.add');
  106. }
  107. public function delOp()
  108. {
  109. $storeId = (int) $_GET['id'];
  110. $storeModel = model('store');
  111. $storeArray = $storeModel->field('is_own_shop,store_name')->find($storeId);
  112. if (empty($storeArray)) {
  113. showMessage('自营店铺不存在', '', 'html', 'error');
  114. }
  115. if (!$storeArray['is_own_shop']) {
  116. showMessage('不能在此删除非自营店铺', '', 'html', 'error');
  117. }
  118. $condition = array(
  119. 'store_id' => $storeId,
  120. );
  121. if ((int) model('goods')->getGoodsCount($condition) > 0)
  122. showMessage('已经发布商品的自营店铺不能被删除', '', 'html', 'error');
  123. // 完全删除店铺
  124. $storeModel->delStoreEntirely($condition);
  125. // 删除自营店id缓存
  126. Model('store')->dropCachedOwnShopIds();
  127. $this->log("删除自营店铺: {$storeArray['store_name']}");
  128. showMessage('操作成功', getReferer());
  129. }
  130. public function editOp()
  131. {
  132. $storeModel = model('store');
  133. $storeArray = $storeModel->find($_GET['id']);
  134. if (!$storeArray['is_own_shop']) {
  135. showMessage('不能在此管理非自营店铺', '', 'html', 'error');
  136. }
  137. if (chksubmit()) {
  138. if (!$this->checkSellerName($_POST['seller_name'], $_GET['id']))
  139. showMessage('店主卖家账号名称已被其它店铺占用', '', 'html', 'error');
  140. $saveArray = array();
  141. $saveArray['store_name'] = $_POST['store_name'];
  142. $saveArray['seller_name'] = $_POST['seller_name'];
  143. $saveArray['bind_all_gc'] = $_POST['bind_all_gc'] ? 1 : 0;
  144. $saveArray['store_state'] = $_POST['store_state'] ? 1 : 0;
  145. $saveArray['store_close_info'] = $_POST['store_close_info'];
  146. $storeModel->editStore($saveArray, array(
  147. 'store_id' => $_GET['id'],
  148. ));
  149. if ($saveArray['seller_name'] != $storeArray['seller_name']) {
  150. model('seller')->editSeller(array(
  151. 'seller_name' => $_POST['seller_name'],
  152. ), array(
  153. 'store_id' => $_GET['id'],
  154. 'seller_group_id' => 0,
  155. 'is_admin' => 1,
  156. ));
  157. }
  158. /* 自营店不下架商品
  159. if ($storeArray['bind_all_gc'] == '1' && $saveArray['bind_all_gc'] == '0' && $_POST['offshelf'] == '1') {
  160. // 全部商品下架
  161. Model('goods')->editProducesLockUp(array(
  162. 'goods_stateremark' => '管理员编辑经营类目',
  163. ), array(
  164. 'store_id' => $_GET['id'],
  165. ));
  166. }
  167. */
  168. // 删除自营店id缓存
  169. Model('store')->dropCachedOwnShopIds();
  170. $this->log("编辑自营店铺: {$saveArray['store_name']}");
  171. showMessage('操作成功', urlAdmin('ownshop', 'list'));
  172. }
  173. if (empty($storeArray))
  174. showMessage('店铺不存在', '', 'html', 'error');
  175. Tpl::output('store_array', $storeArray);
  176. Tpl::showpage('ownshop.edit');
  177. }
  178. public function check_seller_nameOp()
  179. {
  180. echo json_encode($this->checkSellerName($_GET['seller_name'], $_GET['id']));
  181. exit;
  182. }
  183. private function checkSellerName($sellerName, $storeId = 0)
  184. {
  185. // 判断store_joinin是否存在记录
  186. $count = (int) Model('store_joinin')->getStoreJoininCount(array(
  187. 'seller_name' => $sellerName,
  188. ));
  189. if ($count > 0)
  190. return false;
  191. $seller = Model('seller')->getSellerInfo(array(
  192. 'seller_name' => $sellerName,
  193. ));
  194. if (empty($seller))
  195. return true;
  196. if (!$storeId)
  197. return false;
  198. if ($storeId == $seller['store_id'] && $seller['seller_group_id'] == 0 && $seller['is_admin'] == 1)
  199. return true;
  200. return false;
  201. }
  202. public function check_member_nameOp()
  203. {
  204. echo json_encode($this->checkMemberName($_GET['member_name']));
  205. exit;
  206. }
  207. private function checkMemberName($memberName)
  208. {
  209. // 判断store_joinin是否存在记录
  210. $count = (int) Model('store_joinin')->getStoreJoininCount(array(
  211. 'member_name' => $memberName,
  212. ));
  213. if ($count > 0)
  214. return false;
  215. return ! Model('member')->getMemberCount(array(
  216. 'member_name' => $memberName,
  217. ));
  218. }
  219. public function bind_classOp()
  220. {
  221. //批量删除分类
  222. if (chksubmit()) {
  223. if (!empty($_POST['bid'])) {
  224. foreach ($_POST['bid'] as $bid) {
  225. $this->_bind_class_del($bid);
  226. }
  227. }
  228. }
  229. $store_id = intval($_GET['id']);
  230. $model_store = Model('store');
  231. $model_store_bind_class = Model('store_bind_class');
  232. $model_goods_class = Model('goods_class');
  233. $gc_list = $model_goods_class->getGoodsClassListByParentId(0);
  234. Tpl::output('gc_list',$gc_list);
  235. $store_info = $model_store->getStoreInfoByID($store_id);
  236. if(empty($store_info)) {
  237. showMessage(L('param_error'),'','','error');
  238. }
  239. Tpl::output('store_info', $store_info);
  240. $store_bind_class_list = $model_store_bind_class->getStoreBindClassList(array('store_id'=>$store_id), 30);
  241. $goods_class = Model('goods_class')->getGoodsClassIndexedListAll();
  242. for($i = 0, $j = count($store_bind_class_list); $i < $j; $i++) {
  243. $store_bind_class_list[$i]['class_1_name'] = $goods_class[$store_bind_class_list[$i]['class_1']]['gc_name'];
  244. $store_bind_class_list[$i]['class_2_name'] = $goods_class[$store_bind_class_list[$i]['class_2']]['gc_name'];
  245. $store_bind_class_list[$i]['class_3_name'] = $goods_class[$store_bind_class_list[$i]['class_3']]['gc_name'];
  246. }
  247. Tpl::output('store_bind_class_list', $store_bind_class_list);
  248. Tpl::output('showpage',$model_store_bind_class->showpage());
  249. Tpl::showpage('ownshop.bind_class');
  250. }
  251. /**
  252. * 添加经营类目
  253. */
  254. public function bind_class_addOp()
  255. {
  256. $store_id = intval($_POST['store_id']);
  257. $commis_rate = intval($_POST['commis_rate']);
  258. if($commis_rate < 0 || $commis_rate > 100) {
  259. showMessage(L('param_error'), '');
  260. }
  261. list($class_1, $class_2, $class_3) = explode(',', $_POST['goods_class']);
  262. $model_store_bind_class = Model('store_bind_class');
  263. $model_goods_class = Model('goods_class');
  264. $param = array();
  265. $param['store_id'] = $store_id;
  266. $param['class_1'] = $class_1;
  267. $param['state'] = 2;
  268. $param['commis_rate'] = $commis_rate;
  269. if (empty($class_2)) {
  270. //如果没选 二级
  271. $class_2_list = $model_goods_class->getGoodsClassList(array('gc_parent_id'=>$class_1));
  272. if (!empty($class_2_list)) {
  273. foreach ($class_2_list as $class_2_info) {
  274. $class_3_list = $model_goods_class->getGoodsClassList(array('gc_parent_id'=>$class_2_info['gc_id']));
  275. if (!empty($class_3_list)) {
  276. $param['class_2'] = $class_2_info['gc_id'];
  277. foreach ($class_3_list as $class_3_info) {
  278. $param['class_3'] = $class_3_info['gc_id'];
  279. $result = $this->_add_bind_class($param);
  280. }
  281. }
  282. }
  283. } else {
  284. //只有一级分类
  285. $param['class_2'] = $param['class_3'] = 0;
  286. $result = $this->_add_bind_class($param);
  287. }
  288. } else if (empty($class_3)) {
  289. //如果没选二没选三级
  290. $param['class_2'] = $class_2;
  291. $class_3_list = $model_goods_class->getGoodsClassList(array('gc_parent_id'=>$class_2));
  292. if (!empty($class_3_list)) {
  293. foreach ($class_3_list as $class_3_info) {
  294. $param['class_3'] = $class_3_info['gc_id'];
  295. // 检查类目是否已经存在
  296. $store_bind_class_info = $model_store_bind_class->getStoreBindClassInfo($param);
  297. if(empty($store_bind_class_info)) {
  298. $result = $this->_add_bind_class($param);
  299. }
  300. }
  301. } else {
  302. //二级就是最后一级
  303. $param['class_3'] = 0;
  304. $result = $this->_add_bind_class($param);
  305. }
  306. } else {
  307. $param['class_2'] = $class_2;
  308. $param['class_3'] = $class_3;
  309. $result = $this->_add_bind_class($param);
  310. }
  311. if($result) {
  312. // 删除自营店id缓存
  313. Model('store')->dropCachedOwnShopIds();
  314. $this->log('增加自营店铺经营类目,类目编号:'.$result.',店铺编号:'.$store_id);
  315. showMessage(L('nc_common_save_succ'), '');
  316. } else {
  317. showMessage(L('nc_common_save_fail'), '');
  318. }
  319. }
  320. private function _add_bind_class($param) {
  321. $model_store_bind_class = Model('store_bind_class');
  322. // 检查类目是否已经存在
  323. $store_bind_class_info = $model_store_bind_class->getStoreBindClassInfo($param);
  324. if(!empty($store_bind_class_info)) return true;
  325. return $model_store_bind_class->addStoreBindClass($param);
  326. }
  327. /**
  328. * 删除经营类目
  329. */
  330. public function bind_class_delOp()
  331. {
  332. $bid = intval($_POST['bid']);
  333. $result = $this->_bind_class_del($bid);
  334. echo json_encode($result);
  335. }
  336. private function _bind_class_del($bid)
  337. {
  338. $data = array();
  339. $data['result'] = true;
  340. $model_store_bind_class = Model('store_bind_class');
  341. $model_goods = Model('goods');
  342. $store_bind_class_info = $model_store_bind_class->getStoreBindClassInfo(array('bid' => $bid));
  343. if(empty($store_bind_class_info)) {
  344. $data['result'] = false;
  345. $data['message'] = '经营类目删除失败';
  346. return $data;
  347. }
  348. /* 自营店不下架商品
  349. // 商品下架
  350. $condition = array();
  351. $condition['store_id'] = $store_bind_class_info['store_id'];
  352. $gc_id = $store_bind_class_info['class_1'].','.$store_bind_class_info['class_2'].','.$store_bind_class_info['class_3'];
  353. $update = array();
  354. $update['goods_stateremark'] = '管理员删除经营类目';
  355. $condition['gc_id'] = array('in', rtrim($gc_id, ','));
  356. $model_goods->editProducesLockUp($update, $condition);
  357. */
  358. $result = $model_store_bind_class->delStoreBindClass(array('bid'=>$bid));
  359. if(!$result) {
  360. $data['result'] = false;
  361. $data['message'] = '经营类目删除失败';
  362. }
  363. // 删除自营店id缓存
  364. Model('store')->dropCachedOwnShopIds();
  365. $this->log('删除自营店铺经营类目,类目编号:'.$bid.',店铺编号:'.$store_bind_class_info['store_id']);
  366. return $data;
  367. }
  368. public function bind_class_updateOp()
  369. {
  370. $bid = intval($_GET['id']);
  371. if($bid <= 0) {
  372. echo json_encode(array('result'=>FALSE,'message'=>Language::get('param_error')));
  373. die;
  374. }
  375. $new_commis_rate = intval($_GET['value']);
  376. if ($new_commis_rate < 0 || $new_commis_rate >= 100) {
  377. echo json_encode(array('result'=>FALSE,'message'=>Language::get('param_error')));
  378. die;
  379. } else {
  380. $update = array('commis_rate' => $new_commis_rate);
  381. $condition = array('bid' => $bid);
  382. $model_store_bind_class = Model('store_bind_class');
  383. $result = $model_store_bind_class->editStoreBindClass($update, $condition);
  384. if($result) {
  385. // 删除自营店id缓存
  386. Model('store')->dropCachedOwnShopIds();
  387. $this->log('更新自营店铺经营类目,类目编号:'.$bid);
  388. echo json_encode(array('result'=>TRUE));
  389. die;
  390. } else {
  391. echo json_encode(array('result'=>FALSE,'message'=>L('nc_common_op_fail')));
  392. die;
  393. }
  394. }
  395. }
  396. /**
  397. * 验证店铺名称是否存在
  398. */
  399. public function ckeck_store_nameOp() {
  400. /**
  401. * 实例化卖家模型
  402. */
  403. $where = array();
  404. $where['store_name'] = $_GET['store_name'];
  405. if (isset($_GET['store_id'])) {
  406. $where['store_id'] = array('neq', $_GET['store_id']);
  407. }
  408. $store_info = Model('store')->getStoreInfo($where);
  409. if(!empty($store_info['store_name'])) {
  410. echo 'false';
  411. } else {
  412. echo 'true';
  413. }
  414. }
  415. }