Store.php 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. use think\facade\Db;
  6. /**
  7. *
  8. *
  9. * ----------------------------------------------------------------------------
  10. *
  11. * 控制器
  12. */
  13. class Store extends AdminControl
  14. {
  15. public function initialize()
  16. {
  17. parent::initialize();
  18. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/store.lang.php');
  19. }
  20. /**
  21. * 店铺
  22. */
  23. public function store()
  24. {
  25. $store_model = model('store');
  26. $owner_and_name = input('get.owner_and_name');
  27. if (trim($owner_and_name) != '') {
  28. $condition[] = array('member_name', 'like', '%' . $owner_and_name . '%');
  29. }
  30. $store_name = input('get.store_name');
  31. if (trim($store_name) != '') {
  32. $condition[] = array('store_name', 'like', '%' . trim($store_name) . '%');
  33. }
  34. $grade_id = input('get.grade_id');
  35. if (intval($grade_id) > 0) {
  36. $condition[] = array('grade_id', '=', intval($grade_id));
  37. }
  38. $store_state = input('get.store_state');
  39. switch ($store_state) {
  40. case 'close':
  41. $condition[] = array('store_state', '=', 0);
  42. break;
  43. case 'open':
  44. $condition[] = array('store_state', '=', 1);
  45. break;
  46. case 'expired':
  47. $condition[] = array('store_endtime', 'between', array(1, TIMESTAMP));
  48. $condition[] = array('store_state', '=', 1);
  49. break;
  50. case 'expire':
  51. $condition[] = array('store_endtime', 'between', array(TIMESTAMP, TIMESTAMP + 864000));
  52. $condition[] = array('store_state', '=', 1);
  53. break;
  54. }
  55. // 默认店铺管理不包含自营店铺
  56. $condition[] = array('is_platform_store', '=', 0);
  57. //店铺列表
  58. $store_list = $store_model->getStoreList($condition, 10, 'store_id desc');
  59. //店铺等级
  60. $storegrade_model = model('storegrade');
  61. $grade_list = $storegrade_model->getStoregradeList();
  62. $search_grade_list = array();
  63. if (!empty($grade_list)) {
  64. $search_grade_list[0] = lang('no_select_grade');
  65. foreach ($grade_list as $k => $v) {
  66. $search_grade_list[$v['storegrade_id']] = $v['storegrade_name'];
  67. }
  68. }
  69. View::assign('search_grade_list', $search_grade_list);
  70. View::assign('grade_list', $grade_list);
  71. View::assign('store_list', $store_list);
  72. View::assign('store_state_list', $this->_get_store_state_array());
  73. View::assign('show_page', $store_model->page_info->render());
  74. $this->setAdminCurItem('store');
  75. return View::fetch('store');
  76. }
  77. private function _get_store_state_array()
  78. {
  79. return array(
  80. 'open' => lang('ds_open'),
  81. 'close' => lang('ds_close'),
  82. 'expire' => lang('about_to_expire'),
  83. 'expired' => lang('has_expired')
  84. );
  85. }
  86. /**
  87. * 店铺编辑
  88. */
  89. public function store_edit()
  90. {
  91. $store_id = input('param.store_id');
  92. $store_model = model('store');
  93. //取店铺信息
  94. $store_array = $store_model->getStoreInfoByID($store_id);
  95. if (empty($store_array)) {
  96. $this->error(lang('store_no_exist'));
  97. }
  98. //保存
  99. if (!request()->isPost()) {
  100. //整理店铺内容
  101. $store_array['store_endtime'] = $store_array['store_endtime'] ? date('Y-m-d', $store_array['store_endtime']) : '';
  102. //店铺分类
  103. $storeclass_model = model('storeclass');
  104. $parent_list = $storeclass_model->getStoreclassList(array(), '', false);
  105. //店铺等级
  106. $storegrade_model = model('storegrade');
  107. $grade_list = $storegrade_model->getStoregradeList();
  108. View::assign('grade_list', $grade_list);
  109. View::assign('class_list', $parent_list);
  110. View::assign('store_array', $store_array);
  111. $joinin_detail = model('storejoinin')->getOneStorejoinin(array('member_id' => $store_array['member_id']));
  112. View::assign('joinin_detail', $joinin_detail);
  113. $this->setAdminCurItem('store_edit');
  114. return View::fetch('store_edit');
  115. } else {
  116. //取店铺等级的审核
  117. $storegrade_model = model('storegrade');
  118. $grade_array = $storegrade_model->getOneStoregrade(intval(input('post.grade_id')));
  119. if (empty($grade_array)) {
  120. $this->error(lang('please_input_store_level'));
  121. }
  122. //结束时间
  123. $time = '';
  124. if (trim(input('post.end_time')) != '') {
  125. $time = strtotime(input('post.end_time'));
  126. }
  127. $update_array = array();
  128. $update_array['store_name'] = trim(input('post.store_name'));
  129. $update_array['storeclass_id'] = intval(input('post.storeclass_id'));
  130. $update_array['grade_id'] = intval(input('post.grade_id'));
  131. $update_array['store_endtime'] = $time;
  132. $update_array['store_state'] = intval(input('post.store_state'));
  133. $update_array['store_baozh'] = trim(input('post.store_baozh')); //保障服务开关
  134. $update_array['store_qtian'] = trim(input('post.store_qtian')); //保障服务-七天退换
  135. $update_array['store_zhping'] = trim(input('post.store_zhping')); //保障服务-正品保证
  136. $update_array['store_erxiaoshi'] = trim(input('post.store_erxiaoshi')); //保障服务-两小时发货
  137. $update_array['store_tuihuo'] = trim(input('post.store_tuihuo')); //保障服务-退货承诺
  138. $update_array['store_shiyong'] = trim(input('post.store_shiyong')); //保障服务-试用
  139. $update_array['store_xiaoxie'] = trim(input('post.store_xiaoxie')); //保障服务-消协
  140. $update_array['store_huodaofk'] = trim(input('post.store_huodaofk')); //保障服务-货到付款
  141. $update_array['store_shiti'] = trim(input('post.store_shiti')); //保障服务-实体店铺
  142. $data['store_type'] = input('post.store_type') == 1 ? 1 : 0;
  143. $condition = array();
  144. $condition[] = array('member_id', '=', intval(input('post.member_id')));
  145. if ($update_array['store_state'] == 0) {
  146. //根据店铺状态修改该店铺所有商品状态
  147. $goods_model = model('goods');
  148. $goods_model->editProducesOffline(array(array('store_id', '=', $store_id)));
  149. $update_array['store_close_info'] = trim(input('post.store_close_info'));
  150. $update_array['store_recommend'] = 0;
  151. } else {
  152. //店铺开启后商品不在自动上架,需要手动操作
  153. $update_array['store_close_info'] = '';
  154. }
  155. if ($update_array['store_name'] != $store_array['store_name']) {
  156. $goods_model = model('goods');
  157. $goods_model->editGoodsCommon(array('store_name' => $update_array['store_name']), array('store_id' => $store_id));
  158. $goods_model->editGoods(array('store_name' => $update_array['store_name']), array('store_id' => $store_id));
  159. }
  160. $result = $store_model->editStore($update_array, array('store_id' => $store_id));
  161. $store_type = model('Storejoinin')->editStorejoinin($data, $condition);
  162. if ($result || $store_type) {
  163. //店铺名称修改处理
  164. $store_name = trim(input('post.store_name'));
  165. $store_info = $store_model->getStoreInfoByID($store_id);
  166. if (!empty($store_name)) {
  167. $condition = array();
  168. $condition[] = array('store_id', '=', $store_id);
  169. $update = array();
  170. $update['store_name'] = $store_name;
  171. $bllGoods = $store_model->editGoodscommon($condition, $update);
  172. $bllGoods = $store_model->editGoods($condition, $update);
  173. }
  174. $this->log(lang('ds_edit') . lang('ds_store') . '[' . input('post.store_name') . ']', 1);
  175. $this->success(lang('ds_common_save_succ'), (string) url('Store/store'));
  176. } else {
  177. $this->log(lang('ds_edit') . lang('ds_store') . '[' . input('post.store_name') . ']', 1);
  178. $this->error(lang('ds_common_save_fail'));
  179. }
  180. }
  181. }
  182. /**
  183. * 编辑保存注册信息
  184. */
  185. public function edit_save_joinin()
  186. {
  187. if (request()->isPost()) {
  188. $member_id = input('post.member_id');
  189. if ($member_id <= 0) {
  190. $this->error(lang('param_error'));
  191. }
  192. $param = array();
  193. $param['company_name'] = input('post.company_name');
  194. $param['company_province_id'] = intval(input('post.province_id'));
  195. $param['company_address'] = input('post.company_address');
  196. $param['company_address_detail'] = input('post.company_address_detail');
  197. $param['company_registered_capital'] = intval(input('post.company_registered_capital'));
  198. $param['contacts_name'] = input('post.contacts_name');
  199. $param['contacts_phone'] = input('post.contacts_phone');
  200. $param['contacts_email'] = input('post.contacts_email');
  201. $param['business_licence_number'] = input('post.business_licence_number');
  202. $param['business_licence_address'] = input('post.business_licence_address');
  203. $param['business_licence_start'] = input('post.business_licence_start');
  204. $param['business_licence_end'] = input('post.business_licence_end');
  205. $param['business_sphere'] = input('post.business_sphere');
  206. if (!empty($_FILES['business_licence_number_electronic']['name'])) {
  207. $param['business_licence_number_electronic'] = $this->upload_image('business_licence_number_electronic');
  208. }
  209. $param['bank_account_name'] = input('post.bank_account_name');
  210. $param['bank_account_number'] = input('post.bank_account_number');
  211. $param['bank_name'] = input('post.bank_name');
  212. $param['bank_address'] = input('post.bank_address');
  213. $param['settlement_bank_account_name'] = input('post.settlement_bank_account_name');
  214. $param['settlement_bank_account_number'] = input('post.settlement_bank_account_number');
  215. $param['settlement_bank_name'] = input('post.settlement_bank_name');
  216. $param['settlement_bank_address'] = input('post.settlement_bank_address');
  217. $result = model('storejoinin')->editStorejoinin($param, array('member_id' => $member_id));
  218. if ($result >= 0) {
  219. //更新店铺信息
  220. $store_update = array();
  221. $store_update['store_company_name'] = $param['company_name'];
  222. $store_update['area_info'] = $param['company_address'];
  223. $store_update['store_address'] = $param['company_address_detail'];
  224. $store_model = model('store');
  225. $store_info = $store_model->getStoreInfo(array('member_id' => $member_id));
  226. if (!empty($store_info)) {
  227. $r = $store_model->editStore($store_update, array('member_id' => $member_id));
  228. $this->log('编辑店铺信息' . '[ID:' . $r . ']', 1);
  229. }
  230. $this->success(lang('ds_common_op_succ'), (string) url('Store/store'));
  231. } else {
  232. $this->error(lang('ds_common_op_fail'));
  233. }
  234. }
  235. }
  236. private function upload_image($file)
  237. {
  238. //上传文件保存路径
  239. $pic_name = '';
  240. if (!empty($_FILES[$file]['name'])) {
  241. //设置特殊图片名称
  242. $member_id = input('post.member_id');
  243. $file_name = $member_id . '_' . date('YmdHis') . rand(10000, 99999) . '.png';
  244. $res = ds_upload_pic('home' . DIRECTORY_SEPARATOR . 'store_joinin', $file, $file_name);
  245. if ($res['code']) {
  246. $pic_name = $res['data']['file_name'];
  247. } else {
  248. $this->error($res['msg']);
  249. }
  250. }
  251. return $pic_name;
  252. }
  253. /**
  254. * 店铺经营类目管理
  255. */
  256. public function store_bind_class()
  257. {
  258. $store_id = intval(input('param.store_id'));
  259. $store_model = model('store');
  260. $storebindclass_model = model('storebindclass');
  261. $goodsclass_model = model('goodsclass');
  262. $gc_list = $goodsclass_model->getGoodsclassListByParentId(0);
  263. View::assign('gc_list', $gc_list);
  264. $store_info = $store_model->getStoreInfoByID($store_id);
  265. if (empty($store_info)) {
  266. $this->error(lang('param_error'));
  267. }
  268. View::assign('store_info', $store_info);
  269. $store_bind_class_list = $storebindclass_model->getStorebindclassList(array(array('store_id', '=', $store_id), array('storebindclass_state', 'in', array(1, 2))), null);
  270. $goods_class = model('goodsclass')->getGoodsclassIndexedListAll();
  271. for ($i = 0, $j = count($store_bind_class_list); $i < $j; $i++) {
  272. $store_bind_class_list[$i]['class_1_name'] = @$goods_class[$store_bind_class_list[$i]['class_1']]['gc_name'];
  273. $store_bind_class_list[$i]['class_2_name'] = @$goods_class[$store_bind_class_list[$i]['class_2']]['gc_name'];
  274. $store_bind_class_list[$i]['class_3_name'] = @$goods_class[$store_bind_class_list[$i]['class_3']]['gc_name'];
  275. }
  276. View::assign('store_bind_class_list', $store_bind_class_list);
  277. $this->setAdminCurItem('store_bind_class');
  278. return View::fetch('store_bind_class');
  279. }
  280. /**
  281. * 添加经营类目
  282. */
  283. public function store_bind_class_add()
  284. {
  285. $store_id = intval(input('post.store_id'));
  286. $commis_rate = intval(input('post.commis_rate'));
  287. if ($commis_rate < 0 || $commis_rate > 100) {
  288. $this->error(lang('param_error'));
  289. }
  290. @list($class_1, $class_2, $class_3) = explode(',', input('post.goods_class'));
  291. $storebindclass_model = model('storebindclass');
  292. $param = array();
  293. $param['store_id'] = $store_id;
  294. $param['class_1'] = $class_1;
  295. $param['storebindclass_state'] = 1;
  296. if (!empty($class_2)) {
  297. $param['class_2'] = $class_2;
  298. }
  299. if (!empty($class_3)) {
  300. $param['class_3'] = $class_3;
  301. }
  302. // 检查类目是否已经存在
  303. $store_bind_class_info = $storebindclass_model->getStorebindclassInfo($param);
  304. if (!empty($store_bind_class_info)) {
  305. $this->error(lang('storeclass_has_exist'));
  306. }
  307. $param['commis_rate'] = $commis_rate;
  308. $result = $storebindclass_model->addStorebindclass($param);
  309. if ($result) {
  310. $this->log('新增店铺经营类目,类目编号:' . $result . ',店铺编号:' . $store_id);
  311. $this->success(lang('ds_common_save_succ'));
  312. } else {
  313. $this->error(lang('ds_common_save_fail'));
  314. }
  315. }
  316. /**
  317. * 删除经营类目
  318. */
  319. public function store_bind_class_del()
  320. {
  321. $bid = intval(input('param.bid'));
  322. $storebindclass_model = model('storebindclass');
  323. $goods_model = model('goods');
  324. $store_bind_class_info = $storebindclass_model->getStorebindclassInfo(array('storebindclass_id' => $bid));
  325. if (empty($store_bind_class_info)) {
  326. ds_json_encode('10001', lang('ds_common_del_fail'));
  327. }
  328. // 商品下架
  329. $condition = array();
  330. $condition[] = array('store_id', '=', $store_bind_class_info['store_id']);
  331. $gc_id = $store_bind_class_info['class_1'] . ',' . $store_bind_class_info['class_2'] . ',' . $store_bind_class_info['class_3'];
  332. $update = array();
  333. $update['goods_stateremark'] = lang('admin_delete_store_bind_class');
  334. $condition[] = array('gc_id', 'in', rtrim($gc_id, ','));
  335. $goods_model->editProducesLockUp($update, $condition);
  336. $result = $storebindclass_model->delStorebindclass(array('storebindclass_id' => $bid));
  337. if (!$result) {
  338. ds_json_encode('10001', lang('ds_common_del_fail'));
  339. } else {
  340. $this->log('删除店铺经营类目,类目编号:' . $bid . ',店铺编号:' . $store_bind_class_info['store_id']);
  341. ds_json_encode('10000', lang('ds_common_del_succ'));
  342. }
  343. }
  344. public function store_bind_class_update()
  345. {
  346. $bid = intval(input('param.id'));
  347. if ($bid <= 0) {
  348. echo json_encode(array('result' => FALSE, 'message' => lang('param_error')));
  349. die;
  350. }
  351. $new_commis_rate = intval(input('param.value'));
  352. if ($new_commis_rate < 0 || $new_commis_rate >= 100) {
  353. echo json_encode(array('result' => FALSE, 'message' => lang('param_error')));
  354. die;
  355. } else {
  356. $update = array('commis_rate' => $new_commis_rate);
  357. $condition = array('storebindclass_id' => $bid);
  358. $storebindclass_model = model('storebindclass');
  359. $result = $storebindclass_model->editStorebindclass($update, $condition);
  360. if ($result) {
  361. $this->log('更新店铺经营类目,类目编号:' . $bid);
  362. echo json_encode(array('result' => TRUE));
  363. die;
  364. } else {
  365. echo json_encode(array('result' => FALSE, 'message' => lang('ds_common_op_fail')));
  366. die;
  367. }
  368. }
  369. }
  370. /**
  371. * 店铺 待审核列表
  372. */
  373. public function store_joinin()
  374. {
  375. $condition = array();
  376. //店铺列表
  377. if (input('param.owner_and_name')) {
  378. $condition[] = array('member_name', 'like', '%' . input('param.owner_and_name') . '%');
  379. }
  380. if (input('param.store_name')) {
  381. $condition[] = array('store_name', 'like', '%' . input('param.store_name') . '%');
  382. }
  383. if (input('param.grade_id') && intval(input('param.grade_id')) > 0) {
  384. $condition[] = array('storegrade_id', '=', input('param.grade_id'));
  385. }
  386. if (input('param.joinin_state') && intval(input('param.joinin_state')) > 0) {
  387. $condition[] = array('joinin_state', '=', input('param.joinin_state'));
  388. } else {
  389. $condition[] = array('joinin_state', '>', 0);
  390. }
  391. $storejoinin_model = model('storejoinin');
  392. $store_list = $storejoinin_model->getStorejoininList($condition, 10, 'joinin_state asc');
  393. View::assign('store_list', $store_list);
  394. View::assign('joinin_state_array', $this->get_store_joinin_state());
  395. //店铺等级
  396. $storegrade_model = model('storegrade');
  397. $grade_list = $storegrade_model->getStoregradeList();
  398. View::assign('grade_list', $grade_list);
  399. View::assign('show_page', $storejoinin_model->page_info->render());
  400. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  401. $this->setAdminCurItem('store_joinin');
  402. return View::fetch('store_joinin');
  403. }
  404. /**
  405. * 经营类目申请列表
  406. */
  407. public function store_bind_class_applay_list()
  408. {
  409. $condition = array();
  410. // 不显示自营店铺绑定的类目
  411. $state = input('param.state');
  412. if ($state != '') {
  413. if (in_array($state, array('0', '1',))) {
  414. $condition[] = array('storebindclass_state', '=', intval($state));
  415. }
  416. } else {
  417. $condition[] = array('storebindclass_state', 'in', array('0', '1',));
  418. }
  419. $store_id = input('store_id');
  420. if (intval($store_id)) {
  421. $condition[] = array('store_id', '=', intval($store_id));
  422. }
  423. $storebindclass_model = model('storebindclass');
  424. $store_bind_class_list = $storebindclass_model->getStorebindclassList($condition, 15, 'storebindclass_state asc,storebindclass_id desc');
  425. $goods_class = model('goodsclass')->getGoodsclassIndexedListAll();
  426. $store_ids = array();
  427. for ($i = 0; $i < count($store_bind_class_list); $i++) {
  428. $store_bind_class_list[$i]['class_1_name'] = @$goods_class[$store_bind_class_list[$i]['class_1']]['gc_name'];
  429. $store_bind_class_list[$i]['class_2_name'] = @$goods_class[$store_bind_class_list[$i]['class_2']]['gc_name'];
  430. $store_bind_class_list[$i]['class_3_name'] = @$goods_class[$store_bind_class_list[$i]['class_3']]['gc_name'];
  431. $store_ids[] = $store_bind_class_list[$i]['store_id'];
  432. }
  433. //取店铺信息
  434. $store_model = model('store');
  435. $store_list = $store_model->getStoreList(array(array('store_id', 'in', $store_ids)), null);
  436. $bind_store_list = array();
  437. if (!empty($store_list) && is_array($store_list)) {
  438. foreach ($store_list as $k => $v) {
  439. $bind_store_list[$v['store_id']]['store_name'] = $v['store_name'];
  440. $bind_store_list[$v['store_id']]['seller_name'] = $v['seller_name'];
  441. }
  442. }
  443. View::assign('bind_list', $store_bind_class_list);
  444. View::assign('bind_store_list', $bind_store_list);
  445. View::assign('show_page', $storebindclass_model->page_info->render());
  446. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  447. $this->setAdminCurItem('store_bind_class_applay_list');
  448. return View::fetch('bind_class_applay_list');
  449. }
  450. /**
  451. * 审核经营类目申请
  452. */
  453. public function store_bind_class_applay_check()
  454. {
  455. $storebindclass_model = model('storebindclass');
  456. $condition = array();
  457. $condition[] = array('storebindclass_id', '=', intval(input('param.bid')));
  458. $condition[] = array('storebindclass_state', '=', 0);
  459. $update = $storebindclass_model->editStorebindclass(array('storebindclass_state' => 1), $condition);
  460. if ($update) {
  461. $this->log('审核新经营类目申请,店铺ID:' . input('param.store_id'), 1);
  462. ds_json_encode(10000, lang('ds_common_op_succ'));
  463. } else {
  464. $this->error(lang('ds_common_op_fail'), get_referer());
  465. }
  466. }
  467. /**
  468. * 删除经营类目申请
  469. */
  470. public function store_bind_class_applay_del()
  471. {
  472. $storebindclass_model = model('storebindclass');
  473. $condition = array();
  474. $condition[] = array('storebindclass_id', '=', intval(input('param.bid')));
  475. $del = $storebindclass_model->delStorebindclass($condition);
  476. if ($del) {
  477. $this->log('删除经营类目,店铺ID:' . input('param.store_id'), 1);
  478. ds_json_encode(10000, lang('ds_common_del_succ'));
  479. } else {
  480. $this->error(lang('ds_common_del_fail'), get_referer());
  481. }
  482. }
  483. private function get_store_joinin_state()
  484. {
  485. $joinin_state_array = array(
  486. STORE_JOIN_STATE_NEW => lang('store_join_state_new'),
  487. STORE_JOIN_STATE_PAY => lang('store_join_state_pay'),
  488. STORE_JOIN_STATE_VERIFY_SUCCESS => lang('storereopen_state_0'),
  489. STORE_JOIN_STATE_VERIFY_FAIL => lang('store_join_state_verify_fail'),
  490. STORE_JOIN_STATE_PAY_FAIL => lang('store_join_state_pay_fail'),
  491. STORE_JOIN_STATE_FINAL => lang('store_join_state_final'),
  492. );
  493. return $joinin_state_array;
  494. }
  495. /**
  496. * 店铺续签申请列表
  497. */
  498. public function reopen_list()
  499. {
  500. $condition = array();
  501. $store_id = input('get.store_id');
  502. if (intval($store_id)) {
  503. $condition[] = array('storereopen_store_id', '=', intval($store_id));
  504. }
  505. $store_name = input('get.store_name');
  506. if (!empty($store_name)) {
  507. $condition[] = array('storereopen_store_name', '=', $store_name);
  508. }
  509. $storereopen_state = input('get.storereopen_state');
  510. if ($storereopen_state != '') {
  511. $condition[] = array('storereopen_state', '=', intval($storereopen_state));
  512. }
  513. $storereopen_model = model('storereopen');
  514. $reopen_list = $storereopen_model->getStorereopenList($condition, 15);
  515. View::assign('reopen_list', $reopen_list);
  516. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  517. View::assign('show_page', $storereopen_model->page_info->render());
  518. $this->setAdminCurItem('reopen_list');
  519. return View::fetch('store_reopen_list');
  520. }
  521. /**
  522. * 审核店铺续签申请
  523. */
  524. public function reopen_check()
  525. {
  526. if (intval(input('param.storereopen_id')) <= 0)
  527. exit();
  528. $storereopen_model = model('storereopen');
  529. $condition = array();
  530. $condition[] = array('storereopen_id', '=', intval(input('param.storereopen_id')));
  531. $condition[] = array('storereopen_state', '=', 1);
  532. //取当前申请信息
  533. $reopen_info = $storereopen_model->getStorereopenInfo($condition);
  534. $data = array();
  535. $data['storereopen_state'] = 2;
  536. $update = $storereopen_model->editStorereopen($data, $condition);
  537. //取目前店铺有效截止日期
  538. $store_info = model('store')->getStoreInfoByID($reopen_info['storereopen_store_id']);
  539. $start_time = strtotime(date('Y-m-d 0:0:0', $store_info['store_endtime'])) + 24 * 3600;
  540. $new_store_endtime = strtotime(date('Y-m-d 23:59:59', $start_time) . " +" . intval($reopen_info['storereopen_year']) . " year");
  541. if ($update) {
  542. //更新店铺有效期
  543. model('store')->editStore(array('store_endtime' => $new_store_endtime), array('store_id' => $reopen_info['storereopen_store_id']));
  544. $msg = '审核通过店铺续签申请,店铺ID:' . $reopen_info['storereopen_store_id'];
  545. $this->log($msg, 1);
  546. ds_json_encode('10000', lang('ds_common_op_succ'));
  547. } else {
  548. ds_json_encode('10001', lang('ds_common_op_fail'));
  549. }
  550. }
  551. /**
  552. * 删除店铺续签申请
  553. */
  554. public function reopen_del()
  555. {
  556. $storereopen_model = model('storereopen');
  557. $condition = array();
  558. $condition[] = array('storereopen_id', '=', intval(input('param.storereopen_id')));
  559. $condition[] = array('storereopen_state', 'in', array(0, 1));
  560. //取当前申请信息
  561. $reopen_info = $storereopen_model->getStorereopenInfo($condition);
  562. $cert_file = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_STORE_JOININ . DIRECTORY_SEPARATOR . $reopen_info['storereopen_pay_cert'];
  563. $del = $storereopen_model->delStorereopen($condition);
  564. if ($del) {
  565. if (is_file($cert_file)) {
  566. unlink($cert_file);
  567. }
  568. $this->log('删除店铺续签目申请,店铺ID:' . input('param.storereopen_store_id'), 1);
  569. ds_json_encode('10000', lang('ds_common_del_succ'));
  570. } else {
  571. ds_json_encode('10001', lang('ds_common_del_fail'));
  572. }
  573. }
  574. /**
  575. * 审核详细页
  576. */
  577. public function store_joinin_detail()
  578. {
  579. $storejoinin_model = model('storejoinin');
  580. $member_id = input('param.member_id');
  581. $joinin_detail = $storejoinin_model->getOneStorejoinin(array('member_id' => $member_id));
  582. $joinin_detail_title = lang('ds_view');
  583. if (in_array(intval($joinin_detail['joinin_state']), array(STORE_JOIN_STATE_NEW, STORE_JOIN_STATE_PAY))) {
  584. $joinin_detail_title = lang('ds_verify');
  585. }
  586. if (!empty($joinin_detail['sg_info'])) {
  587. $store_grade_info = model('storegrade')->getOneStoregrade($joinin_detail['storegrade_id']);
  588. $joinin_detail['storegrade_price'] = $store_grade_info['storegrade_price'];
  589. } else {
  590. $joinin_detail['sg_info'] = @unserialize($joinin_detail['sg_info']);
  591. if (is_array($joinin_detail['sg_info'])) {
  592. $joinin_detail['storegrade_price'] = $joinin_detail['sg_info']['storegrade_price'];
  593. }
  594. }
  595. View::assign('joinin_detail_title', $joinin_detail_title);
  596. View::assign('joinin_detail', $joinin_detail);
  597. return View::fetch('store_joinin_detail');
  598. }
  599. /**
  600. * 审核
  601. */
  602. public function store_joinin_verify()
  603. {
  604. $storejoinin_model = model('storejoinin');
  605. $joinin_detail = $storejoinin_model->getOneStorejoinin(array('member_id' => input('param.member_id')));
  606. switch (intval($joinin_detail['joinin_state'])) {
  607. case STORE_JOIN_STATE_NEW:
  608. $this->store_joinin_verify_pass($joinin_detail);
  609. break;
  610. case STORE_JOIN_STATE_PAY:
  611. $this->store_joinin_verify_open($joinin_detail);
  612. break;
  613. default:
  614. $this->error(lang('param_error'));
  615. break;
  616. }
  617. }
  618. private function store_joinin_verify_pass($joinin_detail)
  619. {
  620. $param = array();
  621. $param['joinin_state'] = input('post.verify_type') === 'pass' ? STORE_JOIN_STATE_VERIFY_SUCCESS : STORE_JOIN_STATE_VERIFY_FAIL;
  622. $param['joinin_message'] = input('post.joinin_message');
  623. $param['paying_amount'] = abs(floatval(input('post.paying_amount')));
  624. $commis_rate_array = input('post.commis_rate/a'); #获取数组
  625. $param['store_class_commis_rates'] = is_array($commis_rate_array) ? implode(',', $commis_rate_array) : '';
  626. $storejoinin_model = model('storejoinin');
  627. $storejoinin_model->editStorejoinin($param, array('member_id' => input('post.member_id')));
  628. if ($param['paying_amount'] > 0) {
  629. dsLayerOpenSuccess(lang('store_join_verify_final'));
  630. } else {
  631. //如果开店支付费用为零,则审核通过后直接开通,无需再上传付款凭证
  632. $this->store_joinin_verify_open($joinin_detail);
  633. }
  634. }
  635. private function store_joinin_verify_open($joinin_detail)
  636. {
  637. $storejoinin_model = model('storejoinin');
  638. $store_model = model('store');
  639. $param = array();
  640. $param['joinin_state'] = input('post.verify_type') === 'pass' ? STORE_JOIN_STATE_FINAL : STORE_JOIN_STATE_PAY_FAIL;
  641. $param['joinin_message'] = input('post.joinin_message');
  642. if (input('post.verify_type') === 'pass') {
  643. Db::startTrans();
  644. try {
  645. $store_model->setStoreOpen($joinin_detail, $param);
  646. } catch (\Exception $e) {
  647. Db::rollback();
  648. $this->error($e->getMessage());
  649. }
  650. Db::commit();
  651. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  652. } else {
  653. Db::startTrans();
  654. try {
  655. $predeposit_model = model('predeposit');
  656. if ($joinin_detail['rcb_amount'] > 0) {
  657. $data_pd = array();
  658. $data_pd['member_id'] = $joinin_detail['member_id'];
  659. $data_pd['member_name'] = $joinin_detail['member_name'];
  660. $data_pd['amount'] = $joinin_detail['rcb_amount'];
  661. $data_pd['order_sn'] = $joinin_detail['pay_sn'];
  662. $predeposit_model->changeRcb('storejoinin_cancel', $data_pd);
  663. }
  664. if ($joinin_detail['pd_amount'] > 0) {
  665. $data_pd = array();
  666. $data_pd['member_id'] = $joinin_detail['member_id'];
  667. $data_pd['member_name'] = $joinin_detail['member_name'];
  668. $data_pd['amount'] = $joinin_detail['pd_amount'];
  669. $data_pd['order_sn'] = $joinin_detail['pay_sn'];
  670. $predeposit_model->changePd('storejoinin_cancel', $data_pd);
  671. }
  672. //改变店铺状态
  673. $storejoinin_model->editStorejoinin($param, array('member_id' => input('param.member_id')));
  674. } catch (\Exception $e) {
  675. Db::rollback();
  676. $this->error($e->getMessage());
  677. }
  678. Db::commit();
  679. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  680. // $this->error(lang('store_open_reject'));
  681. }
  682. }
  683. /**
  684. * 提醒续费
  685. */
  686. public function remind_renewal()
  687. {
  688. $store_id = intval(input('param.store_id'));
  689. $store_info = model('store')->getStoreInfoByID($store_id);
  690. if (!empty($store_info) && $store_info['store_endtime'] < (TIMESTAMP + 864000) && cookie('remindRenewal' . $store_id) == null) {
  691. // 发送商家消息
  692. $param = array();
  693. $param['code'] = 'store_expire';
  694. $param['store_id'] = intval(input('param.store_id'));
  695. $param['param'] = array();
  696. $param['ali_param'] = array();
  697. $param['ten_param'] = array();
  698. //微信模板消息
  699. $param['weixin_param'] = array(
  700. 'data' => array(
  701. "keyword1" => array(
  702. "value" => $store_info['store_name'],
  703. "color" => "#333"
  704. ),
  705. "keyword2" => array(
  706. "value" => date('Y-m-d', $store_info['store_endtime']),
  707. "color" => "#333"
  708. )
  709. ),
  710. );
  711. model('cron')->addCron(array('cron_exetime' => TIMESTAMP, 'cron_type' => 'sendStoremsg', 'cron_value' => serialize($param)));
  712. cookie('remindRenewal' . $store_id, 1, 86400 * 10); // 十天
  713. $this->success(lang('ds_common_op_succ'));
  714. }
  715. $this->error(lang('ds_common_op_fail'));
  716. }
  717. /*
  718. //删除店铺操作,暂时屏蔽
  719. public function del() {
  720. $store_id = intval(input('param.id'));
  721. $store_model = model('store');
  722. $storeArray = $store_model->field('is_platform_store,store_name')->find($store_id);
  723. if (empty($storeArray)) {
  724. ds_json_encode('10001', lang('外驻店铺不存在'));
  725. }
  726. if ($storeArray['is_platform_store']) {
  727. ds_json_encode('10001', lang('不能在此删除自营店铺'));
  728. }
  729. $condition = array(
  730. 'store_id' => $store_id,
  731. );
  732. if (model('goods')->getGoodsCount($condition) > 0){
  733. ds_json_encode('10001', lang('已经发布商品的外驻店铺不能被删除'));
  734. }
  735. // 完全删除店铺
  736. $store_model->delStoreEntirely($condition);
  737. //删除入驻相关
  738. $member_id = intval(input('param.member_id'));
  739. $store_joinin = model('storejoinin');
  740. $condition = array(
  741. 'member_id' => $member_id,
  742. );
  743. $store_joinin->delStorejoinin($condition);
  744. $this->log("删除外驻店铺: {$storeArray['store_name']}");
  745. ds_json_encode('10000', lang('ds_common_del_succ'));
  746. }
  747. *
  748. */
  749. //删除店铺操作
  750. public function del_join()
  751. {
  752. $member_id = (int) input('param.member_id');
  753. $store_joinin = model('storejoinin');
  754. $condition = array(
  755. 'member_id' => $member_id,
  756. );
  757. $mm = $store_joinin->getOneStorejoinin($condition);
  758. if (empty($mm)) {
  759. $this->error(lang('ds_common_op_fail'), get_referer());
  760. }
  761. if ($mm['joinin_state'] == '20') {
  762. }
  763. $store_name = $mm['store_name'];
  764. $store_model = model('store');
  765. $scount = $store_model->getStoreCount($condition);
  766. if ($scount > 0) {
  767. $this->error(lang('store_exist'), get_referer());
  768. }
  769. Db::startTrans();
  770. try {
  771. $predeposit_model = model('predeposit');
  772. if ($mm['rcb_amount'] > 0) {
  773. $data_pd = array();
  774. $data_pd['member_id'] = $mm['member_id'];
  775. $data_pd['member_name'] = $mm['member_name'];
  776. $data_pd['amount'] = $mm['rcb_amount'];
  777. $data_pd['order_sn'] = $mm['pay_sn'];
  778. $predeposit_model->changeRcb('storejoinin_cancel', $data_pd);
  779. }
  780. if ($mm['pd_amount'] > 0) {
  781. $data_pd = array();
  782. $data_pd['member_id'] = $mm['member_id'];
  783. $data_pd['member_name'] = $mm['member_name'];
  784. $data_pd['amount'] = $mm['pd_amount'];
  785. $data_pd['order_sn'] = $mm['pay_sn'];
  786. $predeposit_model->changePd('storejoinin_cancel', $data_pd);
  787. }
  788. // 完全删除店铺入驻
  789. $store_joinin->delStorejoinin($condition);
  790. } catch (\Exception $e) {
  791. Db::rollback();
  792. $this->error($e->getMessage());
  793. }
  794. Db::commit();
  795. $this->log(lang('del_store') . ":" . $store_name);
  796. ds_json_encode('10000', lang('ds_common_del_succ'));
  797. }
  798. public function newshop_add()
  799. {
  800. if (!request()->isPost()) {
  801. return View::fetch('store_newshop_add');
  802. } else {
  803. $member_name = input('post.member_name');
  804. $member_password = input('post.member_password');
  805. $seller_name = $member_name;
  806. $store_name = input('post.store_name');
  807. if (strlen($member_name) < 3 || strlen($member_name) > 15)
  808. $this->error(lang('name_length_error'));
  809. if (strlen($member_password) < 6)
  810. $this->error(lang('member_password_minlength'));
  811. if (!$this->checkMemberName($member_name))
  812. $this->error(lang('member_name_exist'));
  813. try {
  814. $memberId = model('member')->addMember(array(
  815. 'member_name' => $member_name,
  816. 'member_password' => $member_password,
  817. ));
  818. } catch (Exception $ex) {
  819. $this->error(lang('seller_account_add_fail'));
  820. }
  821. $store_model = model('store');
  822. $saveArray = array();
  823. $saveArray['store_name'] = $store_name;
  824. $saveArray['member_id'] = $memberId;
  825. $saveArray['member_name'] = $member_name;
  826. $saveArray['seller_name'] = $seller_name;
  827. $saveArray['bind_all_gc'] = 1;
  828. $saveArray['store_state'] = 1;
  829. $saveArray['store_addtime'] = TIMESTAMP;
  830. $saveArray['is_platform_store'] = 0;
  831. $saveArray['grade_id'] = 1;
  832. $storeId = $store_model->addStore($saveArray);
  833. model('seller')->addSeller(array(
  834. 'seller_name' => $seller_name,
  835. 'member_id' => $memberId,
  836. 'store_id' => $storeId,
  837. 'sellergroup_id' => 0,
  838. 'is_admin' => 1,
  839. ));
  840. model('storejoinin')->addStorejoinin(array(
  841. 'seller_name' => $seller_name,
  842. 'store_name' => $store_name,
  843. 'member_name' => $member_name,
  844. 'member_id' => $memberId,
  845. 'joinin_state' => 40,
  846. 'company_province_id' => 0,
  847. 'storeclass_bail' => 0,
  848. 'joinin_year' => 1,
  849. ));
  850. // 添加相册默认
  851. $album_model = model('album');
  852. $album_arr = array();
  853. $album_arr['aclass_name'] = lang('store_save_defaultalbumclass_name');
  854. $album_arr['store_id'] = $storeId;
  855. $album_arr['aclass_des'] = '';
  856. $album_arr['aclass_sort'] = '255';
  857. $album_arr['aclass_cover'] = '';
  858. $album_arr['aclass_uploadtime'] = TIMESTAMP;
  859. $album_arr['aclass_isdefault'] = '1';
  860. $album_model->addAlbumclass($album_arr);
  861. //插入店铺扩展表
  862. $store_model->addStoreextend(array('store_id' => $storeId));
  863. // 删除自营店id缓存
  864. model('store')->dropCachedOwnShopIds();
  865. $this->log(lang('add_store') . ": {$saveArray['store_name']}");
  866. $this->success(lang('add_store_bind_class'), (string) url('Store/store_bind_class', ['store_id' => $storeId]));
  867. }
  868. }
  869. public function check_seller_name()
  870. {
  871. echo json_encode($this->checkSellerName(input('param.seller_name')));
  872. exit;
  873. }
  874. private function checkSellerName($sellerName)
  875. {
  876. // 判断store_joinin是否存在记录
  877. $count = (int) model('storejoinin')->getStorejoininCount(array(
  878. 'seller_name' => $sellerName,
  879. ));
  880. if ($count > 0)
  881. return false;
  882. $seller = model('seller')->getSellerInfo(array(
  883. 'seller_name' => $sellerName,
  884. ));
  885. if (!empty($seller)) {
  886. return false;
  887. }
  888. return TRUE;
  889. }
  890. public function check_member_name()
  891. {
  892. echo json_encode($this->checkMemberName(input('param.member_name')));
  893. exit;
  894. }
  895. private function checkMemberName($member_name)
  896. {
  897. // 判断store_joinin是否存在记录
  898. $count = (int) model('storejoinin')->getStorejoininCount(array(
  899. 'member_name' => $member_name,
  900. ));
  901. if ($count > 0)
  902. return false;
  903. return !model('member')->getMemberCount(array(
  904. 'member_name' => $member_name,
  905. ));
  906. }
  907. /**
  908. * 验证店铺名称是否存在
  909. */
  910. public function ckeck_store_name()
  911. {
  912. $where = array();
  913. $where[] = array('store_name', '=', input('param.store_name'));
  914. $where[] = array('store_id', '<>', input('param.store_id'));
  915. $store_info = model('store')->getStoreInfo($where);
  916. if (!empty($store_info['store_name'])) {
  917. echo 'false';
  918. } else {
  919. echo 'true';
  920. }
  921. }
  922. /**
  923. * 验证店铺名称是否存在
  924. */
  925. private function ckeckStoreName($store_name)
  926. {
  927. $condition = array();
  928. $condition[] = array('store_name', '=', $store_name);
  929. $store_info = model('store')->getStoreInfo($condition);
  930. if (!empty($store_info['store_name'])) {
  931. return false;
  932. } else {
  933. return true;
  934. }
  935. }
  936. //ajax操作
  937. public function ajax()
  938. {
  939. $store_model = model('store');
  940. switch (input('param.branch')) {
  941. /**
  942. * 品牌名称
  943. */
  944. case 'store_sort':
  945. $id = intval(input('param.id'));
  946. $result = $store_model->editStore(array('store_sort' => trim(input('param.value'))), array('store_id' => $id));
  947. if ($result) {
  948. $this->log(lang('ds_edit') . lang('ds_store') . '[' . $id . ']', 1);
  949. }
  950. echo 'true';
  951. exit;
  952. break;
  953. }
  954. }
  955. /**
  956. * 获取卖家栏目列表,针对控制器下的栏目
  957. */
  958. protected function getAdminItemList()
  959. {
  960. $menu_array = array(
  961. array(
  962. 'name' => 'store',
  963. 'text' => lang('ds_manage'),
  964. 'url' => (string) url('Store/store')
  965. ), array(
  966. 'name' => 'store_joinin',
  967. 'text' => lang('pending'),
  968. 'url' => (string) url('Store/store_joinin')
  969. ), array(
  970. 'name' => 'reopen_list',
  971. 'text' => lang('reopen_list'),
  972. 'url' => (string) url('Store/reopen_list')
  973. ), array(
  974. 'name' => 'store_bind_class_applay_list',
  975. 'text' => lang('store_bind_class_apply'),
  976. 'url' => (string) url('Store/store_bind_class_applay_list')
  977. ), array(
  978. 'name' => 'newshop_add',
  979. 'text' => lang('add_store'),
  980. 'url' => "javascript:dsLayerOpen('" . (string) url('Store/newshop_add') . "','" . lang('add_store') . "')"
  981. )
  982. );
  983. if (request()->action() == 'store_bind_class') {
  984. $menu_array[] = [
  985. 'name' => 'store_bind_class', 'text' => lang('ds_edit') . lang('store_bind_class'), 'url' => '#'
  986. ];
  987. }
  988. return $menu_array;
  989. }
  990. }