Ownshop.php 23 KB

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