store.php 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445
  1. <?php
  2. /**
  3. * 店铺管理界面
  4. *
  5. **by 好商城V3 www.33hao.com 运营版*/
  6. ini_set('auto_detect_line_endings', 1);
  7. defined('InShopNC') or exit('Access Invalid!');
  8. class storeControl extends SystemControl{
  9. const EXPORT_SIZE = 1000;
  10. public function __construct(){
  11. parent::__construct();
  12. Language::read('store,store_grade');
  13. }
  14. /**
  15. * 店铺
  16. */
  17. public function storeOp(){
  18. $lang = Language::getLangContent();
  19. $model_store = Model('store');
  20. if(trim($_GET['owner_and_name']) != ''){
  21. $condition['member_name'] = array('like', '%'.$_GET['owner_and_name'].'%');
  22. Tpl::output('owner_and_name',$_GET['owner_and_name']);
  23. }
  24. if(trim($_GET['store_name']) != ''){
  25. $condition['store_name'] = array('like', '%'.trim($_GET['store_name']).'%');
  26. Tpl::output('store_name',$_GET['store_name']);
  27. }
  28. if(intval($_GET['grade_id']) > 0){
  29. $condition['grade_id'] = intval($_GET['grade_id']);
  30. Tpl::output('grade_id',intval($_GET['grade_id']));
  31. }
  32. switch ($_GET['store_type']) {
  33. case 'close':
  34. $condition['store_state'] = 0;
  35. break;
  36. case 'open':
  37. $condition['store_state'] = 1;
  38. break;
  39. case 'expired':
  40. $condition['store_end_time'] = array('between', array(1, time()));
  41. $condition['store_state'] = 1;
  42. break;
  43. case 'expire':
  44. $condition['store_end_time'] = array('between', array(time(), time() + 864000));
  45. $condition['store_state'] = 1;
  46. break;
  47. }
  48. // 默认店铺管理不包含自营店铺
  49. $condition['is_own_shop'] = 0;
  50. //店铺列表
  51. $store_list = $model_store->getStoreList($condition, 10,'store_id desc');
  52. //店铺等级
  53. $model_grade = Model('store_grade');
  54. $grade_list = $model_grade->getGradeList($condition);
  55. if (!empty($grade_list)){
  56. $search_grade_list = array();
  57. foreach ($grade_list as $k => $v){
  58. $search_grade_list[$v['sg_id']] = $v['sg_name'];
  59. }
  60. }
  61. Tpl::output('search_grade_list', $search_grade_list);
  62. Tpl::output('grade_list',$grade_list);
  63. Tpl::output('store_list',$store_list);
  64. Tpl::output('store_type', $this->_get_store_type_array());
  65. Tpl::output('page',$model_store->showpage('2'));
  66. Tpl::showpage('store.index');
  67. }
  68. private function _get_store_type_array() {
  69. return array(
  70. 'open' => '开启',
  71. 'close' => '关闭',
  72. 'expire' => '即将到期',
  73. 'expired' => '已到期'
  74. );
  75. }
  76. /**
  77. * 店铺编辑
  78. */
  79. public function store_editOp(){
  80. $lang = Language::getLangContent();
  81. $model_store = Model('store');
  82. //保存
  83. if (chksubmit()){
  84. //取店铺等级的审核
  85. $model_grade = Model('store_grade');
  86. $grade_array = $model_grade->getOneGrade(intval($_POST['grade_id']));
  87. if (empty($grade_array)){
  88. showMessage($lang['please_input_store_level']);
  89. }
  90. //结束时间
  91. $time = '';
  92. if(trim($_POST['end_time']) != ''){
  93. $time = strtotime($_POST['end_time']);
  94. }
  95. $update_array = array();
  96. $update_array['store_name'] = trim($_POST['store_name']);
  97. $update_array['sc_id'] = intval($_POST['sc_id']);
  98. $update_array['grade_id'] = intval($_POST['grade_id']);
  99. $update_array['store_end_time'] = $time;
  100. $update_array['store_state'] = intval($_POST['store_state']);
  101. $update_array['store_baozh'] = trim($_POST['store_baozh']);//保障服务开关
  102. $update_array['store_baozhopen'] = trim($_POST['store_baozhopen']);//保证金显示开关
  103. $update_array['store_baozhrmb'] = trim($_POST['store_baozhrmb']);//新加保证金-金额
  104. $update_array['store_qtian'] = trim($_POST['store_qtian']);//保障服务-七天退换
  105. $update_array['store_zhping'] = trim($_POST['store_zhping']);//保障服务-正品保证
  106. $update_array['store_erxiaoshi'] = trim($_POST['store_erxiaoshi']);//保障服务-两小时发货
  107. $update_array['store_tuihuo'] = trim($_POST['store_tuihuo']);//保障服务-退货承诺
  108. $update_array['store_shiyong'] = trim($_POST['store_shiyong']);//保障服务-试用
  109. $update_array['store_xiaoxie'] = trim($_POST['store_xiaoxie']);//保障服务-消协
  110. $update_array['store_huodaofk'] = trim($_POST['store_huodaofk']);//保障服务-货到付款
  111. $update_array['store_shiti'] = trim($_POST['store_shiti']);//保障服务-实体店铺
  112. $update_array['store_type'] = intval($_POST['store_type']);//商家类型
  113. if ($update_array['store_state'] == 0){
  114. //根据店铺状态修改该店铺所有商品状态
  115. $model_goods = Model('goods');
  116. $model_goods->editProducesOffline(array('store_id' => $_POST['store_id']));
  117. $update_array['store_close_info'] = trim($_POST['store_close_info']);
  118. $update_array['store_recommend'] = 0;
  119. }else {
  120. //店铺开启后商品不在自动上架,需要手动操作
  121. $update_array['store_close_info'] = '';
  122. $update_array['store_recommend'] = intval($_POST['store_recommend']);
  123. }
  124. $result = $model_store->editStore($update_array, array('store_id' => $_POST['store_id']));
  125. if ($result){
  126. $url = array(
  127. array(
  128. 'url'=>'index.php?act=store&op=store',
  129. 'msg'=>$lang['back_store_list'],
  130. ),
  131. array(
  132. 'url'=>'index.php?act=store&op=store_edit&store_id='.intval($_POST['store_id']),
  133. 'msg'=>$lang['countinue_add_store'],
  134. ),
  135. );
  136. $this->log(L('nc_edit,store').'['.$_POST['store_name'].']',1);
  137. showMessage($lang['nc_common_save_succ'],$url);
  138. }else {
  139. $this->log(L('nc_edit,store').'['.$_POST['store_name'].']',1);
  140. showMessage($lang['nc_common_save_fail']);
  141. }
  142. }
  143. //取店铺信息
  144. $store_array = $model_store->getStoreInfoByID($_GET['store_id']);
  145. if (empty($store_array)){
  146. showMessage($lang['store_no_exist']);
  147. }
  148. //整理店铺内容
  149. $store_array['store_end_time'] = $store_array['store_end_time']?date('Y-m-d',$store_array['store_end_time']):'';
  150. //店铺分类
  151. $model_store_class = Model('store_class');
  152. $parent_list = $model_store_class->getStoreClassList(array(),'',false);
  153. //店铺等级
  154. $model_grade = Model('store_grade');
  155. $grade_list = $model_grade->getGradeList();
  156. Tpl::output('grade_list',$grade_list);
  157. Tpl::output('class_list',$parent_list);
  158. Tpl::output('store_array',$store_array);
  159. $joinin_detail = Model('store_joinin')->getOne(array('member_id'=>$store_array['member_id']));
  160. Tpl::output('joinin_detail', $joinin_detail);
  161. Tpl::showpage('store.edit');
  162. }
  163. /**
  164. * 编辑保存注册信息
  165. */
  166. public function edit_save_joininOp() {
  167. if (chksubmit()) {
  168. $member_id = $_POST['member_id'];
  169. if ($member_id <= 0) {
  170. showMessage(L('param_error'));
  171. }
  172. $param = array();
  173. $param['company_name'] = $_POST['company_name'];
  174. $province_id = intval($_POST['province_id']);
  175. $city_id = intval($_POST['city_id']);
  176. if($province_id > 0) {
  177. $param['company_province_id'] = $province_id;
  178. }
  179. if($city_id > 0) {
  180. $param['company_city_id'] = $city_id;
  181. }
  182. $param['company_address'] = $_POST['company_address'];
  183. $param['company_address_detail'] = $_POST['company_address_detail'];
  184. $param['company_phone'] = $_POST['company_phone'];
  185. $param['company_employee_count'] = intval($_POST['company_employee_count']);
  186. $param['company_registered_capital'] = intval($_POST['company_registered_capital']);
  187. $param['contacts_name'] = $_POST['contacts_name'];
  188. $param['contacts_phone'] = $_POST['contacts_phone'];
  189. $param['contacts_email'] = $_POST['contacts_email'];
  190. $param['business_licence_number'] = $_POST['business_licence_number'];
  191. $param['business_licence_address'] = $_POST['business_licence_address'];
  192. $param['business_licence_start'] = $_POST['business_licence_start'];
  193. $param['business_licence_end'] = $_POST['business_licence_end'];
  194. $param['business_sphere'] = $_POST['business_sphere'];
  195. if ($_FILES['business_licence_number_electronic']['name'] != '') {
  196. $param['business_licence_number_electronic'] = $this->upload_image('business_licence_number_electronic');
  197. }
  198. $param['organization_code'] = $_POST['organization_code'];
  199. if ($_FILES['organization_code_electronic']['name'] != '') {
  200. $param['organization_code_electronic'] = $this->upload_image('organization_code_electronic');
  201. }
  202. if ($_FILES['general_taxpayer']['name'] != '') {
  203. $param['general_taxpayer'] = $this->upload_image('general_taxpayer');
  204. }
  205. $param['bank_account_name'] = $_POST['bank_account_name'];
  206. $param['bank_account_number'] = $_POST['bank_account_number'];
  207. $param['bank_name'] = $_POST['bank_name'];
  208. $param['bank_code'] = $_POST['bank_code'];
  209. $param['bank_address'] = $_POST['bank_address'];
  210. if ($_FILES['bank_licence_electronic']['name'] != '') {
  211. $param['bank_licence_electronic'] = $this->upload_image('bank_licence_electronic');
  212. }
  213. $param['settlement_bank_account_name'] = $_POST['settlement_bank_account_name'];
  214. $param['settlement_bank_account_number'] = $_POST['settlement_bank_account_number'];
  215. $param['settlement_bank_name'] = $_POST['settlement_bank_name'];
  216. $param['settlement_bank_code'] = $_POST['settlement_bank_code'];
  217. $param['settlement_bank_address'] = $_POST['settlement_bank_address'];
  218. $param['tax_registration_certificate'] = $_POST['tax_registration_certificate'];
  219. $param['taxpayer_id'] = $_POST['taxpayer_id'];
  220. if ($_FILES['tax_registration_certificate_electronic']['name'] != '') {
  221. $param['tax_registration_certificate_electronic'] = $this->upload_image('tax_registration_certificate_electronic');
  222. }
  223. $result = Model('store_joinin')->editStoreJoinin(array('member_id' => $member_id), $param);
  224. if ($result) {
  225. //好商城V3-B11 更新店铺信息
  226. $store_update = array();
  227. $store_update['store_company_name']=$param['company_name'];
  228. $store_update['area_info']=$param['company_address'];
  229. $store_update['store_address']=$param['company_address_detail'];
  230. if(isset($param['company_province_id'])) {
  231. $store_update['province_id'] = $param['company_province_id'];
  232. }
  233. if(isset($param['company_city_id'])) {
  234. $store_update['city_id'] = $param['company_city_id'];
  235. }
  236. $model_store = Model('store');
  237. $store_info = $model_store->getStoreInfo(array('member_id'=>$member_id));
  238. if(!empty($store_info)) {
  239. $r=$model_store->editStore($store_update, array('member_id'=>$member_id));
  240. $this->log('编辑店铺信息' . '[ID:' . $r. ']', 1);
  241. }
  242. showMessage(L('nc_common_op_succ'), 'index.php?act=store&op=store');
  243. } else {
  244. showMessage(L('nc_common_op_fail'));
  245. }
  246. }
  247. }
  248. private function upload_image($file) {
  249. $pic_name = '';
  250. $upload = new UploadFile();
  251. $uploaddir = ATTACH_PATH.DS.'store_joinin'.DS;
  252. $upload->set('default_dir',$uploaddir);
  253. $upload->set('allow_type',array('jpg','jpeg','gif','png'));
  254. if (!empty($_FILES[$file]['name'])){
  255. $result = $upload->upfile($file);
  256. if ($result){
  257. $pic_name = $upload->file_name;
  258. $upload->file_name = '';
  259. }
  260. }
  261. return $pic_name;
  262. }
  263. /**
  264. * 店铺经营类目管理
  265. */
  266. public function store_bind_classOp() {
  267. $store_id = intval($_GET['store_id']);
  268. $model_store = Model('store');
  269. $model_store_bind_class = Model('store_bind_class');
  270. $model_goods_class = Model('goods_class');
  271. $gc_list = $model_goods_class->getGoodsClassListByParentId(0);
  272. Tpl::output('gc_list',$gc_list);
  273. $store_info = $model_store->getStoreInfoByID($store_id);
  274. if(empty($store_info)) {
  275. showMessage(L('param_error'),'','','error');
  276. }
  277. Tpl::output('store_info', $store_info);
  278. $store_bind_class_list = $model_store_bind_class->getStoreBindClassList(array('store_id'=>$store_id,'state'=>array('in',array(1,2))), null);
  279. $goods_class = Model('goods_class')->getGoodsClassIndexedListAll();
  280. for($i = 0, $j = count($store_bind_class_list); $i < $j; $i++) {
  281. $store_bind_class_list[$i]['class_1_name'] = $goods_class[$store_bind_class_list[$i]['class_1']]['gc_name'];
  282. $store_bind_class_list[$i]['class_2_name'] = $goods_class[$store_bind_class_list[$i]['class_2']]['gc_name'];
  283. $store_bind_class_list[$i]['class_3_name'] = $goods_class[$store_bind_class_list[$i]['class_3']]['gc_name'];
  284. }
  285. Tpl::output('store_bind_class_list', $store_bind_class_list);
  286. Tpl::showpage('store_bind_class');
  287. }
  288. /**
  289. * 添加经营类目
  290. */
  291. public function store_bind_class_addOp() {
  292. $store_id = intval($_POST['store_id']);
  293. $commis_rate = intval($_POST['commis_rate']);
  294. if($commis_rate < 0 || $commis_rate > 100) {
  295. showMessage(L('param_error'), '');
  296. }
  297. list($class_1, $class_2, $class_3) = explode(',', $_POST['goods_class']);
  298. $model_store_bind_class = Model('store_bind_class');
  299. $param = array();
  300. $param['store_id'] = $store_id;
  301. $param['class_1'] = $class_1;
  302. $param['state'] = 1;
  303. if(!empty($class_2)) {
  304. $param['class_2'] = $class_2;
  305. }
  306. if(!empty($class_3)) {
  307. $param['class_3'] = $class_3;
  308. }
  309. // 检查类目是否已经存在
  310. $store_bind_class_info = $model_store_bind_class->getStoreBindClassInfo($param);
  311. if(!empty($store_bind_class_info)) {
  312. showMessage('该类目已经存在','','','error');
  313. }
  314. $param['commis_rate'] = $commis_rate;
  315. $result = $model_store_bind_class->addStoreBindClass($param);
  316. if($result) {
  317. $this->log('删除店铺经营类目,类目编号:'.$result.',店铺编号:'.$store_id);
  318. showMessage(L('nc_common_save_succ'), '');
  319. } else {
  320. showMessage(L('nc_common_save_fail'), '');
  321. }
  322. }
  323. /**
  324. * 删除经营类目
  325. */
  326. public function store_bind_class_delOp() {
  327. $bid = intval($_POST['bid']);
  328. $data = array();
  329. $data['result'] = true;
  330. $model_store_bind_class = Model('store_bind_class');
  331. $model_goods = Model('goods');
  332. $store_bind_class_info = $model_store_bind_class->getStoreBindClassInfo(array('bid' => $bid));
  333. if(empty($store_bind_class_info)) {
  334. $data['result'] = false;
  335. $data['message'] = '经营类目删除失败';
  336. echo json_encode($data);die;
  337. }
  338. // 商品下架
  339. $condition = array();
  340. $condition['store_id'] = $store_bind_class_info['store_id'];
  341. $gc_id = $store_bind_class_info['class_1'].','.$store_bind_class_info['class_2'].','.$store_bind_class_info['class_3'];
  342. $update = array();
  343. $update['goods_stateremark'] = '管理员删除经营类目';
  344. $condition['gc_id'] = array('in', rtrim($gc_id, ','));
  345. $model_goods->editProducesLockUp($update, $condition);
  346. $result = $model_store_bind_class->delStoreBindClass(array('bid'=>$bid));
  347. if(!$result) {
  348. $data['result'] = false;
  349. $data['message'] = '经营类目删除失败';
  350. }
  351. $this->log('删除店铺经营类目,类目编号:'.$bid.',店铺编号:'.$store_bind_class_info['store_id']);
  352. echo json_encode($data);die;
  353. }
  354. public function store_bind_class_updateOp() {
  355. $bid = intval($_GET['id']);
  356. if($bid <= 0) {
  357. echo json_encode(array('result'=>FALSE,'message'=>Language::get('param_error')));
  358. die;
  359. }
  360. $new_commis_rate = intval($_GET['value']);
  361. if ($new_commis_rate < 0 || $new_commis_rate >= 100) {
  362. echo json_encode(array('result'=>FALSE,'message'=>Language::get('param_error')));
  363. die;
  364. } else {
  365. $update = array('commis_rate' => $new_commis_rate);
  366. $condition = array('bid' => $bid);
  367. $model_store_bind_class = Model('store_bind_class');
  368. $result = $model_store_bind_class->editStoreBindClass($update, $condition);
  369. if($result) {
  370. $this->log('更新店铺经营类目,类目编号:'.$bid);
  371. echo json_encode(array('result'=>TRUE));
  372. die;
  373. } else {
  374. echo json_encode(array('result'=>FALSE,'message'=>L('nc_common_op_fail')));
  375. die;
  376. }
  377. }
  378. }
  379. /**
  380. * 店铺 待审核列表
  381. */
  382. public function store_joininOp(){
  383. //店铺列表
  384. if(!empty($_GET['owner_and_name'])) {
  385. $condition['member_name'] = array('like','%'.$_GET['owner_and_name'].'%');
  386. }
  387. if(!empty($_GET['store_name'])) {
  388. $condition['store_name'] = array('like','%'.$_GET['store_name'].'%');
  389. }
  390. if(!empty($_GET['grade_id']) && intval($_GET['grade_id']) > 0) {
  391. $condition['sg_id'] = $_GET['grade_id'];
  392. }
  393. if(!empty($_GET['joinin_state']) && intval($_GET['joinin_state']) > 0) {
  394. $condition['joinin_state'] = $_GET['joinin_state'] ;
  395. } else {
  396. $condition['joinin_state'] = array('gt',0);
  397. }
  398. $model_store_joinin = Model('store_joinin');
  399. $store_list = $model_store_joinin->getList($condition, 10, 'joinin_state asc');
  400. Tpl::output('store_list', $store_list);
  401. Tpl::output('joinin_state_array', $this->get_store_joinin_state());
  402. //店铺等级
  403. $model_grade = Model('store_grade');
  404. $grade_list = $model_grade->getGradeList();
  405. Tpl::output('grade_list', $grade_list);
  406. Tpl::output('page',$model_store_joinin->showpage('2'));
  407. Tpl::showpage('store_joinin');
  408. }
  409. /**
  410. * 经营类目申请列表
  411. */
  412. public function store_bind_class_applay_listOp(){
  413. $condition = array();
  414. // 不显示自营店铺绑定的类目
  415. if ($_GET['state'] != '') {
  416. $condition['state'] = intval($_GET['state']);
  417. if (!in_array($condition['state'], array('0', '1', )))
  418. unset($condition['state']);
  419. } else {
  420. $condition['state'] = array('in', array('0', '1', ));
  421. }
  422. if(intval($_GET['store_id'])) {
  423. $condition['store_id'] = intval($_GET['store_id']);
  424. }
  425. $model_store_bind_class = Model('store_bind_class');
  426. $store_bind_class_list = $model_store_bind_class->getStoreBindClassList($condition, 15,'state asc,bid desc');
  427. $goods_class = Model('goods_class')->getGoodsClassIndexedListAll();
  428. $store_ids = array();
  429. for($i = 0, $j = count($store_bind_class_list); $i < $j; $i++) {
  430. $store_bind_class_list[$i]['class_1_name'] = $goods_class[$store_bind_class_list[$i]['class_1']]['gc_name'];
  431. $store_bind_class_list[$i]['class_2_name'] = $goods_class[$store_bind_class_list[$i]['class_2']]['gc_name'];
  432. $store_bind_class_list[$i]['class_3_name'] = $goods_class[$store_bind_class_list[$i]['class_3']]['gc_name'];
  433. $store_ids[] = $store_bind_class_list[$i]['store_id'];
  434. }
  435. //取店铺信息
  436. $model_store = Model('store');
  437. $store_list = $model_store->getStoreList(array('store_id'=>array('in',$store_ids)),null);
  438. $bind_store_list = array();
  439. if (!empty($store_list) && is_array($store_list)) {
  440. foreach ($store_list as $k => $v) {
  441. $bind_store_list[$v['store_id']]['store_name'] = $v['store_name'];
  442. $bind_store_list[$v['store_id']]['seller_name'] = $v['seller_name'];
  443. }
  444. }
  445. Tpl::output('bind_list', $store_bind_class_list);
  446. Tpl::output('bind_store_list',$bind_store_list);
  447. Tpl::output('page',$model_store_bind_class->showpage('2'));
  448. Tpl::showpage('store_bind_class_applay.list');
  449. }
  450. /**
  451. * 审核经营类目申请
  452. */
  453. public function store_bind_class_applay_checkOp() {
  454. $model_store_bind_class = Model('store_bind_class');
  455. $condition = array();
  456. $condition['bid'] = intval($_GET['bid']);
  457. $condition['state'] = 0;
  458. $update = $model_store_bind_class->editStoreBindClass(array('state'=>1),$condition);
  459. if ($update) {
  460. $this->log('审核新经营类目申请,店铺ID:'.$_GET['store_id'],1);
  461. showMessage('审核成功',getReferer());
  462. } else {
  463. showMessage('审核失败',getReferer(),'html','error');
  464. }
  465. }
  466. /**
  467. * 删除经营类目申请
  468. */
  469. public function store_bind_class_applay_delOp() {
  470. $model_store_bind_class = Model('store_bind_class');
  471. $condition = array();
  472. $condition['bid'] = intval($_GET['bid']);
  473. $del = $model_store_bind_class->delStoreBindClass($condition);
  474. if ($del) {
  475. $this->log('删除经营类目,店铺ID:'.$_GET['store_id'],1);
  476. showMessage('删除成功',getReferer());
  477. } else {
  478. showMessage('删除失败',getReferer(),'html','error');
  479. }
  480. }
  481. private function get_store_joinin_state() {
  482. $joinin_state_array = array(
  483. STORE_JOIN_STATE_NEW => '新申请',
  484. STORE_JOIN_STATE_PAY => '已付款',
  485. STORE_JOIN_STATE_VERIFY_SUCCESS => '待付款',
  486. STORE_JOIN_STATE_VERIFY_FAIL => '审核失败',
  487. STORE_JOIN_STATE_PAY_FAIL => '付款审核失败',
  488. STORE_JOIN_STATE_FINAL => '开店成功',
  489. );
  490. return $joinin_state_array;
  491. }
  492. /**
  493. * 店铺续签申请列表
  494. */
  495. public function reopen_listOp(){
  496. $condition = array();
  497. if(intval($_GET['store_id'])) {
  498. $condition['re_store_id'] = intval($_GET['store_id']);
  499. }
  500. if(!empty($_GET['store_name'])) {
  501. $condition['re_store_name'] = $_GET['store_name'];
  502. }
  503. if ($_GET['re_state'] != '') {
  504. $condition['re_state'] = intval($_GET['re_state']);
  505. }
  506. $model_store_reopen = Model('store_reopen');
  507. $reopen_list = $model_store_reopen->getStoreReopenList($condition, 15);
  508. Tpl::output('reopen_list', $reopen_list);
  509. Tpl::output('page',$model_store_reopen->showpage('2'));
  510. Tpl::showpage('store_reopen.list');
  511. }
  512. /**
  513. * 审核店铺续签申请
  514. */
  515. public function reopen_checkOp() {
  516. if (intval($_GET['re_id']) <= 0) exit();
  517. $model_store_reopen = Model('store_reopen');
  518. $condition = array();
  519. $condition['re_id'] = intval($_GET['re_id']);
  520. $condition['re_state'] = 1;
  521. //取当前申请信息
  522. $reopen_info = $model_store_reopen->getStoreReopenInfo($condition);
  523. //取目前店铺有效截止日期
  524. $store_info = Model('store')->getStoreInfoByID($reopen_info['re_store_id']);
  525. $data = array();
  526. $data['re_start_time'] = strtotime(date('Y-m-d 0:0:0',$store_info['store_end_time']))+24*3600;
  527. $data['re_end_time'] = strtotime(date('Y-m-d 23:59:59', $data['re_start_time'])." +".intval($reopen_info['re_year'])." year");
  528. $data['re_state'] = 2;
  529. $update = $model_store_reopen->editStoreReopen($data,$condition);
  530. if ($update) {
  531. //更新店铺有效期
  532. Model('store')->editStore(array('store_end_time'=>$data['re_end_time']),array('store_id'=>$reopen_info['re_store_id']));
  533. $msg = '审核通过店铺续签申请,店铺ID:'.$reopen_info['re_store_id'].',续签时间段:'.date('Y-m-d',$data['re_start_time']).' - '.date('Y-m-d',$data['re_end_time']);
  534. $this->log($msg,1);
  535. showMessage('续签成功,店铺有效成功延续到了'.date('Y-m-d',$data['re_end_time']).'日',getReferer());
  536. } else {
  537. showMessage('审核失败',getReferer(),'html','error');
  538. }
  539. }
  540. /**
  541. * 删除店铺续签申请
  542. */
  543. public function reopen_delOp() {
  544. $model_store_reopen = Model('store_reopen');
  545. $condition = array();
  546. $condition['re_id'] = intval($_GET['re_id']);
  547. $condition['re_state'] = array('in',array(0,1));
  548. //取当前申请信息
  549. $reopen_info = $model_store_reopen->getStoreReopenInfo($condition);
  550. $cert_file = BASE_UPLOAD_PATH.DS.ATTACH_STORE_JOININ.DS.$reopen_info['re_pay_cert'];
  551. $del = $model_store_reopen->delStoreReopen($condition);
  552. if ($del) {
  553. if (is_file($cert_file)) {
  554. unlink($cert_file);
  555. }
  556. $this->log('删除店铺续签目申请,店铺ID:'.$_GET['re_store_id'],1);
  557. showMessage('删除成功',getReferer());
  558. } else {
  559. showMessage('删除失败',getReferer(),'html','error');
  560. }
  561. }
  562. /**
  563. * 审核详细页
  564. */
  565. public function store_joinin_detailOp(){
  566. $model_store_joinin = Model('store_joinin');
  567. $joinin_detail = $model_store_joinin->getOne(array('member_id'=>$_GET['member_id']));
  568. $joinin_detail_title = '查看';
  569. if(in_array(intval($joinin_detail['joinin_state']), array(STORE_JOIN_STATE_NEW, STORE_JOIN_STATE_PAY))) {
  570. $joinin_detail_title = '审核';
  571. }
  572. if (!empty($joinin_detail['sg_info'])) {
  573. $store_grade_info = Model('store_grade')->getOneGrade($joinin_detail['sg_id']);
  574. $joinin_detail['sg_price'] = $store_grade_info['sg_price'];
  575. } else {
  576. $joinin_detail['sg_info'] = @unserialize($joinin_detail['sg_info']);
  577. if (is_array($joinin_detail['sg_info'])) {
  578. $joinin_detail['sg_price'] = $joinin_detail['sg_info']['sg_price'];
  579. }
  580. }
  581. Tpl::output('joinin_detail_title', $joinin_detail_title);
  582. Tpl::output('joinin_detail', $joinin_detail);
  583. Tpl::showpage('store_joinin.detail');
  584. }
  585. /**
  586. * 审核
  587. */
  588. public function store_joinin_verifyOp() {
  589. $model_store_joinin = Model('store_joinin');
  590. $joinin_detail = $model_store_joinin->getOne(array('member_id'=>$_POST['member_id']));
  591. switch (intval($joinin_detail['joinin_state'])) {
  592. case STORE_JOIN_STATE_NEW:
  593. $this->store_joinin_verify_pass($joinin_detail);
  594. break;
  595. case STORE_JOIN_STATE_PAY:
  596. $this->store_joinin_verify_open($joinin_detail);
  597. break;
  598. default:
  599. showMessage('参数错误','');
  600. break;
  601. }
  602. }
  603. private function store_joinin_verify_pass($joinin_detail) {
  604. $param = array();
  605. $param['joinin_state'] = $_POST['verify_type'] === 'pass' ? STORE_JOIN_STATE_VERIFY_SUCCESS : STORE_JOIN_STATE_VERIFY_FAIL;
  606. $param['joinin_message'] = $_POST['joinin_message'];
  607. $param['paying_amount'] = abs(floatval($_POST['paying_amount']));
  608. $param['store_class_commis_rates'] = implode(',', $_POST['commis_rate']);
  609. $model_store_joinin = Model('store_joinin');
  610. $model_store_joinin->modify($param, array('member_id'=>$_POST['member_id']));
  611. if ($param['paying_amount'] > 0) {
  612. showMessage('店铺入驻申请审核完成','index.php?act=store&op=store_joinin');
  613. } else {
  614. //如果开店支付费用为零,则审核通过后直接开通,无需再上传付款凭证
  615. $this->store_joinin_verify_open($joinin_detail);
  616. }
  617. }
  618. private function store_joinin_verify_open($joinin_detail) {
  619. $model_store_joinin = Model('store_joinin');
  620. $model_store = Model('store');
  621. $model_seller = Model('seller');
  622. //验证卖家用户名是否已经存在
  623. if($model_seller->isSellerExist(array('seller_name' => $joinin_detail['seller_name']))) {
  624. showMessage('卖家用户名已存在','');
  625. }
  626. $param = array();
  627. $param['joinin_state'] = $_POST['verify_type'] === 'pass' ? STORE_JOIN_STATE_FINAL : STORE_JOIN_STATE_PAY_FAIL;
  628. $param['joinin_message'] = $_POST['joinin_message'];
  629. $model_store_joinin->modify($param, array('member_id'=>$_POST['member_id']));
  630. if($_POST['verify_type'] === 'pass') {
  631. //开店
  632. $shop_array = array();
  633. $shop_array['member_id'] = $joinin_detail['member_id'];
  634. $shop_array['member_name'] = $joinin_detail['member_name'];
  635. $shop_array['seller_name'] = $joinin_detail['seller_name'];
  636. $shop_array['grade_id'] = $joinin_detail['sg_id'];
  637. $shop_array['store_name'] = $joinin_detail['store_name'];
  638. $shop_array['sc_id'] = $joinin_detail['sc_id'];
  639. $shop_array['store_company_name'] = $joinin_detail['company_name'];
  640. $shop_array['province_id'] = $joinin_detail['company_province_id'];
  641. $shop_array['city_id'] = $joinin_detail['company_city_id'];
  642. $shop_array['area_info'] = $joinin_detail['company_address'];
  643. $shop_array['store_address']= $joinin_detail['company_address_detail'];
  644. $shop_array['store_zip'] = '';
  645. $shop_array['store_zy'] = '';
  646. $shop_array['store_state'] = 1;
  647. $shop_array['store_time'] = time();
  648. $shop_array['store_end_time'] = strtotime(date('Y-m-d 23:59:59', strtotime('+1 day'))." +".intval($joinin_detail['joinin_year'])." year");
  649. $shop_array['bind_all_gc'] = 1;
  650. $store_id = $model_store->addStore($shop_array);
  651. QueueClient::push('UpdateSotreLocation',['store_id' => $store_id]);
  652. if($store_id) {
  653. //写入卖家账号
  654. $seller_array = array();
  655. $seller_array['seller_name'] = $joinin_detail['seller_name'];
  656. $seller_array['member_id'] = $joinin_detail['member_id'];
  657. $seller_array['seller_group_id'] = 0;
  658. $seller_array['store_id'] = $store_id;
  659. $seller_array['is_admin'] = 1;
  660. $state = $model_seller->addSeller($seller_array);
  661. }
  662. if($state) {
  663. // 添加相册默认
  664. $album_model = Model('album');
  665. $album_arr = array();
  666. $album_arr['aclass_name'] = Language::get('store_save_defaultalbumclass_name');
  667. $album_arr['store_id'] = $store_id;
  668. $album_arr['aclass_des'] = '';
  669. $album_arr['aclass_sort'] = '255';
  670. $album_arr['aclass_cover'] = '';
  671. $album_arr['upload_time'] = time();
  672. $album_arr['is_default'] = '1';
  673. $album_model->addClass($album_arr);
  674. $model = Model();
  675. //插入店铺扩展表
  676. $model->table('store_extend')->insert(array('store_id'=>$store_id));
  677. $msg = Language::get('store_save_create_success');
  678. //插入店铺绑定分类表
  679. $store_bind_class_array = array();
  680. $store_bind_class = unserialize($joinin_detail['store_class_ids']);
  681. $store_bind_commis_rates = explode(',', $joinin_detail['store_class_commis_rates']);
  682. for($i=0, $length=count($store_bind_class); $i<$length; $i++) {
  683. list($class1, $class2, $class3) = explode(',', $store_bind_class[$i]);
  684. $store_bind_class_array[] = array(
  685. 'store_id' => $store_id,
  686. 'commis_rate' => $store_bind_commis_rates[$i],
  687. 'class_1' => $class1,
  688. 'class_2' => $class2,
  689. 'class_3' => $class3,
  690. 'state' => 1
  691. );
  692. }
  693. $model_store_bind_class = Model('store_bind_class');
  694. $model_store_bind_class->addStoreBindClassAll($store_bind_class_array);
  695. showMessage('店铺开店成功','index.php?act=store&op=store_joinin');
  696. } else {
  697. showMessage('店铺开店失败','index.php?act=store&op=store_joinin');
  698. }
  699. } else {
  700. showMessage('店铺开店拒绝','index.php?act=store&op=store_joinin');
  701. }
  702. }
  703. /**
  704. * 提醒续费
  705. */
  706. public function remind_renewalOp() {
  707. $store_id = intval($_GET['store_id']);
  708. $store_info = Model('store')->getStoreInfoByID($store_id);
  709. if (!empty($store_info) && $store_info['store_end_time'] < (time() + 864000) && cookie('remindRenewal'.$store_id) == null) {
  710. // 发送商家消息
  711. $param = array();
  712. $param['code'] = 'store_expire';
  713. $param['store_id'] = intval($_GET['store_id']);
  714. $param['param'] = array();
  715. QueueClient::push('sendStoreMsg', $param);
  716. setNcCookie('remindRenewal'.$store_id, 1, 86400 * 10); // 十天
  717. showMessage('消息发送成功');
  718. }
  719. showMessage('消息发送失败');
  720. }
  721. public function delOp()
  722. {
  723. $storeId = (int) $_GET['id'];
  724. $storeModel = model('store');
  725. $storeArray = $storeModel->field('is_own_shop,store_name')->find($storeId);
  726. if (empty($storeArray)) {
  727. showMessage('外驻店铺不存在', '', 'html', 'error');
  728. }
  729. if ($storeArray['is_own_shop']) {
  730. showMessage('不能在此删除自营店铺', '', 'html', 'error');
  731. }
  732. $condition = array(
  733. 'store_id' => $storeId,
  734. );
  735. if ((int) model('goods')->getGoodsCount($condition) > 0)
  736. showMessage('已经发布商品的外驻店铺不能被删除', '', 'html', 'error');
  737. // 完全删除店铺
  738. $storeModel->delStoreEntirely($condition);
  739. $this->log("删除外驻店铺: {$storeArray['store_name']}");
  740. showMessage('操作成功', getReferer());
  741. }
  742. public function newshop_addOp()
  743. {
  744. if (chksubmit())
  745. {
  746. $memberName = $_POST['member_name'];
  747. $memberPasswd = (string) $_POST['member_passwd'];
  748. if (strlen($memberName) < 3 || strlen($memberName) > 15
  749. || strlen($_POST['seller_name']) < 3 || strlen($_POST['seller_name']) > 15)
  750. showMessage('账号名称必须是3~15位', '', 'html', 'error');
  751. if (strlen($memberPasswd) < 6)
  752. showMessage('登录密码不能短于6位', '', 'html', 'error');
  753. if (!$this->checkMemberName($memberName))
  754. showMessage('店主账号已被占用', '', 'html', 'error');
  755. if (!$this->checkSellerName($_POST['seller_name']))
  756. showMessage('店主卖家账号名称已被其它店铺占用', '', 'html', 'error');
  757. try
  758. {
  759. $memberId = model('member')->addMember(array(
  760. 'member_name' => $memberName,
  761. 'member_passwd' => $memberPasswd,
  762. 'member_email' => '',
  763. ));
  764. }
  765. catch (Exception $ex)
  766. {
  767. showMessage('店主账号新增失败', '', 'html', 'error');
  768. }
  769. $storeModel = model('store');
  770. $saveArray = array();
  771. $saveArray['store_name'] = $_POST['store_name'];
  772. $saveArray['member_id'] = $memberId;
  773. $saveArray['member_name'] = $memberName;
  774. $saveArray['seller_name'] = $_POST['seller_name'];
  775. $saveArray['bind_all_gc'] = 1;
  776. $saveArray['store_state'] = 1;
  777. $saveArray['store_time'] = time();
  778. $saveArray['is_own_shop'] = 0;
  779. $storeId = $storeModel->addStore($saveArray);
  780. QueueClient::push('UpdateSotreLocation',['store_id' => $storeId]);
  781. model('seller')->addSeller(array(
  782. 'seller_name' => $_POST['seller_name'],
  783. 'member_id' => $memberId,
  784. 'store_id' => $storeId,
  785. 'seller_group_id' => 0,
  786. 'is_admin' => 1,
  787. ));
  788. model('store_joinin')->save(array(
  789. 'seller_name' => $_POST['seller_name'],
  790. 'store_name' => $_POST['store_name'],
  791. 'member_name' => $memberName,
  792. 'member_id' => $memberId,
  793. 'joinin_state' => 40,
  794. 'company_province_id' => 0,
  795. 'sc_bail' => 0,
  796. 'joinin_year' => 1,
  797. ));
  798. // 添加相册默认
  799. $album_model = Model('album');
  800. $album_arr = array();
  801. $album_arr['aclass_name'] = '默认相册';
  802. $album_arr['store_id'] = $storeId;
  803. $album_arr['aclass_des'] = '';
  804. $album_arr['aclass_sort'] = '255';
  805. $album_arr['aclass_cover'] = '';
  806. $album_arr['upload_time'] = time();
  807. $album_arr['is_default'] = '1';
  808. $album_model->addClass($album_arr);
  809. //插入店铺扩展表
  810. $model = Model();
  811. $model->table('store_extend')->insert(array('store_id'=>$storeId));
  812. // 删除自营店id缓存
  813. Model('store')->dropCachedOwnShopIds();
  814. $this->log("新增外驻店铺: {$saveArray['store_name']}");
  815. showMessage('操作成功', urlAdmin('store', 'store'));
  816. return;
  817. }
  818. Tpl::showpage('store.newshop.add');
  819. }
  820. public function check_seller_nameOp()
  821. {
  822. echo json_encode($this->checkSellerName($_GET['seller_name'], $_GET['id']));
  823. exit;
  824. }
  825. private function checkSellerName($sellerName, $storeId = 0)
  826. {
  827. // 判断store_joinin是否存在记录
  828. $count = (int) Model('store_joinin')->getStoreJoininCount(array(
  829. 'seller_name' => $sellerName,
  830. ));
  831. if ($count > 0)
  832. return false;
  833. $seller = Model('seller')->getSellerInfo(array(
  834. 'seller_name' => $sellerName,
  835. ));
  836. if (empty($seller))
  837. return true;
  838. if (!$storeId)
  839. return false;
  840. if ($storeId == $seller['store_id'] && $seller['seller_group_id'] == 0 && $seller['is_admin'] == 1)
  841. return true;
  842. return false;
  843. }
  844. public function check_member_nameOp()
  845. {
  846. echo json_encode($this->checkMemberName($_GET['member_name']));
  847. exit;
  848. }
  849. private function checkMemberName($memberName)
  850. {
  851. // 判断store_joinin是否存在记录
  852. $count = (int) Model('store_joinin')->getStoreJoininCount(array(
  853. 'member_name' => $memberName,
  854. ));
  855. if ($count > 0)
  856. return false;
  857. return ! Model('member')->getMemberCount(array(
  858. 'member_name' => $memberName,
  859. ));
  860. }
  861. /**
  862. * 验证店铺名称是否存在
  863. */
  864. public function ckeck_store_nameOp() {
  865. /**
  866. * 实例化卖家模型
  867. */
  868. $where = array();
  869. $where['store_name'] = $_GET['store_name'];
  870. $where['store_id'] = array('neq', $_GET['store_id']);
  871. $store_info = Model('store')->getStoreInfo($where);
  872. if(!empty($store_info['store_name'])) {
  873. echo 'false';
  874. } else {
  875. echo 'true';
  876. }
  877. }
  878. /**
  879. * 验证店铺名称是否存在
  880. */
  881. private function ckeckStoreName($store_name) {
  882. /**
  883. * 实例化卖家模型
  884. */
  885. $where = array();
  886. $where['store_name'] = $store_name;
  887. $store_info = Model('store')->getStoreInfo($where);
  888. if(!empty($store_info['store_name'])) {
  889. return false;
  890. } else {
  891. return true;
  892. }
  893. }
  894. public function store_importOp(){
  895. Tpl::showpage('store_import');
  896. }
  897. public function store_import_csv_xOp()
  898. {
  899. if (isset($_POST['import']))
  900. {
  901. $file = $_FILES['csv_stores'];
  902. $file_type = substr(strstr($file['name'], '.'), 1);
  903. //上传文件存在判断
  904. if(empty($file['name'])){
  905. showMessage('请选择要上传csv的文件!','','html','error');
  906. }
  907. // 检查文件格式
  908. if ($file_type != 'csv') {
  909. showMessage('文件格式不对,请重新上传!','','html','error');
  910. exit;
  911. }
  912. $delimiter = ";";
  913. if(isset($_POST['delimiter'])) $delimiter=trim(strval($_POST['delimiter']));
  914. $handle = @fopen($file['tmp_name'], "r");
  915. $encoding = $this->get_str_encoding(file_get_contents($file['tmp_name']));
  916. $result = $this->read_csv($handle, $encoding, $delimiter);
  917. $rows = count($result);
  918. if($rows == 0){
  919. showMessage('没有任何数据!','','html','error');
  920. exit;
  921. }
  922. $scounter = 0;
  923. for ($i = 0; $i < $rows; $i++) {
  924. //循环获取各字段值
  925. $store_name = $result[$i][0];
  926. $member_name = $result[$i][1];
  927. $seller_name = $result[$i][2];
  928. $password = $result[$i][3];
  929. $store_company_name = $result[$i][4];
  930. $store_area = $result[$i][5];
  931. $store_address = $result[$i][6];
  932. $store_phone = $result[$i][7];
  933. $store_type = intval($result[$i][8]);
  934. if(!$this->ckeckStoreName($store_name))
  935. {
  936. showMessage("店铺名称 {$member_name} 已存在", '', 'html', 'error');
  937. return;
  938. }
  939. if(!$this->checkMemberName($member_name))
  940. {
  941. showMessage("店主账号 {$member_name} 已存在", '', 'html', 'error');
  942. return;
  943. }
  944. if(!$this->checkSellerName($seller_name))
  945. {
  946. showMessage("卖家账号 {$member_name} 已存在", '', 'html', 'error');
  947. return;
  948. }
  949. //批量导入数据的所在省份/城市校验
  950. $pattern = '/(\S+)[\s]*(\S+)*/u';
  951. $result = preg_match_all($pattern, $store_area, $matches);
  952. if(!$result) {
  953. showMessage("{$store_company_name}所在省份/城市无法识别!",'','html','error');
  954. exit;
  955. }
  956. if(count($matches) !== 3) {
  957. showMessage("{$store_company_name}所在省份/城市识别错误!",'','html','error');
  958. exit;
  959. }
  960. if(empty($match[2][0])) {
  961. $city_name = $matches[1][0];
  962. }
  963. else {
  964. $city_name = $matches[2][0];
  965. }
  966. if($city_name == '北京' || $city_name == '上海' || $city_name == '天津' || $city_name == '重庆') {
  967. $city_name = $city_name. "市";
  968. }
  969. $mod_area = Model('area');
  970. $info = $mod_area->getAreaInfo(['area_name' => $city_name]);
  971. if(empty($info)) {
  972. showMessage("{$store_company_name}所在省份/城市无法识别!",'','html','error');
  973. exit;
  974. }
  975. $city_id = intval($info['area_id']);
  976. $province_id = intval($info['area_parent_id']);
  977. try
  978. {
  979. $memberId = model('member')->addMember(array(
  980. 'member_name' => $member_name,
  981. 'member_passwd' => $password,
  982. 'member_email' => '',
  983. ));
  984. }
  985. catch (Exception $ex)
  986. {
  987. showMessage("店主账号{$member_name}新增失败", '', 'html', 'error');
  988. return;
  989. }
  990. $storeModel = model('store');
  991. $saveArray = array();
  992. $saveArray['store_name'] = $store_name;
  993. $saveArray['grade_id'] = 1;
  994. $saveArray['member_id'] = $memberId;
  995. $saveArray['member_name'] = $member_name;
  996. $saveArray['seller_name'] = $seller_name;
  997. $saveArray['bind_all_gc'] = 1;
  998. $saveArray['store_state'] = 1;
  999. $saveArray['store_time'] = time();
  1000. $saveArray['store_company_name'] = $store_company_name;
  1001. $saveArray['province_id'] = $province_id;
  1002. $saveArray['city_id'] = $city_id;
  1003. $saveArray['area_info'] = $store_area;
  1004. $saveArray['store_address'] = $store_address;
  1005. $saveArray['store_type'] = $store_type;
  1006. $storeId = $storeModel->addStore($saveArray);
  1007. QueueClient::push('UpdateSotreLocation',['store_id' => $storeId]);
  1008. model('seller')->addSeller(array(
  1009. 'seller_name' => $seller_name,
  1010. 'member_id' => $memberId,
  1011. 'store_id' => $storeId,
  1012. 'seller_group_id' => 0,
  1013. 'is_admin' => 1,
  1014. ));
  1015. $store_joinModel = model('store_joinin');
  1016. $save_joinArray = array();
  1017. $save_joinArray['member_id'] = $memberId;
  1018. $save_joinArray['member_name'] = $member_name;
  1019. $save_joinArray['seller_name'] = $seller_name;
  1020. $save_joinArray['store_name'] = $store_name;
  1021. $save_joinArray['company_name'] = $store_company_name;
  1022. $save_joinArray['company_address'] = $store_address;
  1023. $save_joinArray['company_address_detail'] = $store_address;
  1024. $save_joinArray['company_phone']= $store_phone;
  1025. $save_joinArray['store_type'] = $store_type;
  1026. $save_joinArray['joinin_state'] = 40;
  1027. $save_joinArray['company_name'] = $store_company_name;
  1028. $save_joinArray['company_province_id'] = $province_id;
  1029. $save_joinArray['company_city_id'] = $city_id;
  1030. $store_joinModel->save($save_joinArray);
  1031. // 添加相册默认
  1032. $album_model = Model('album');
  1033. $album_arr = array();
  1034. $album_arr['aclass_name'] = '默认相册';
  1035. $album_arr['store_id'] = $storeId;
  1036. $album_arr['aclass_des'] = '';
  1037. $album_arr['aclass_sort'] = '255';
  1038. $album_arr['aclass_cover'] = '';
  1039. $album_arr['upload_time'] = time();
  1040. $album_arr['is_default'] = '1';
  1041. $album_model->addClass($album_arr);
  1042. //插入店铺扩展表
  1043. $model = Model();
  1044. $model->table('store_extend')->insert(array('store_id'=>$storeId));
  1045. $scounter++;
  1046. }
  1047. @fclose($handle); //关闭指针
  1048. showMessage('操作成功,成功导入 '.strval($scounter).' 条数据' , urlAdmin('store', 'store'));
  1049. return;
  1050. }
  1051. }
  1052. public function store_import_csvOp()
  1053. {
  1054. if (isset($_POST['import'])) {
  1055. $file = $_FILES['csv_stores'];
  1056. $file_type = substr(strstr($file['name'], '.'), 1);
  1057. //上传文件存在判断
  1058. if(empty($file['name'])){
  1059. showMessage('请选择要上传csv的文件!','','html','error');
  1060. }
  1061. // 检查文件格式
  1062. if ($file_type != 'csv') {
  1063. showMessage('文件格式不对,请重新上传!','','html','error');
  1064. exit;
  1065. }
  1066. $handle = fopen($file['tmp_name'], "r");
  1067. $result = $this->input_csv($handle); //解析csv
  1068. $rows = count($result);
  1069. if($rows == 0){
  1070. showMessage('没有任何数据!','','html','error');
  1071. exit;
  1072. }
  1073. $scounter = 0;
  1074. $storeModel = model('store');
  1075. for ($i = 1; $i < $rows; $i++) {
  1076. //循环获取各字段值
  1077. $store_name = iconv('gb2312', 'utf-8', $result[$i][0]);
  1078. $member_name = iconv('gb2312', 'utf-8', $result[$i][1]);
  1079. $seller_name = iconv('gb2312', 'utf-8', $result[$i][2]);
  1080. $password = iconv('gb2312', 'utf-8', $result[$i][3]);
  1081. $store_company_name = iconv('gb2312', 'utf-8', $result[$i][4]);
  1082. $company_name = iconv('gb2312', 'utf-8', $result[$i][5]);
  1083. $company_address = iconv('gb2312', 'utf-8', $result[$i][6]);
  1084. $store_address = iconv('gb2312', 'utf-8', $result[$i][7]);
  1085. $store_zip = iconv('gb2312', 'utf-8', $result[$i][8]);
  1086. $store_qq = iconv('gb2312', 'utf-8', $result[$i][9]);
  1087. $store_ww = iconv('gb2312', 'utf-8', $result[$i][10]);
  1088. $store_phone = iconv('gb2312', 'utf-8', $result[$i][11]);
  1089. $company_employee_count = iconv('gb2312', 'utf-8', $result[$i][12]);
  1090. $company_registered_capital = iconv('gb2312', 'utf-8', $result[$i][13]);
  1091. $contacts_name = iconv('gb2312', 'utf-8', $result[$i][14]);
  1092. $contacts_phone = iconv('gb2312', 'utf-8', $result[$i][15]);
  1093. $contacts_email = iconv('gb2312', 'utf-8', $result[$i][16]);
  1094. $business_licence_number = iconv('gb2312', 'utf-8', $result[$i][17]);
  1095. $business_licence_address = iconv('gb2312', 'utf-8', $result[$i][18]);
  1096. $business_licence_start = iconv('gb2312', 'utf-8', $result[$i][19]);
  1097. $business_licence_end = iconv('gb2312', 'utf-8', $result[$i][20]);
  1098. $business_sphere = iconv('gb2312', 'utf-8', $result[$i][21]);
  1099. $organization_code = iconv('gb2312', 'utf-8', $result[$i][22]);
  1100. $bank_account_name = iconv('gb2312', 'utf-8', $result[$i][23]);
  1101. $bank_account_number = iconv('gb2312', 'utf-8', $result[$i][24]);
  1102. $bank_name = iconv('gb2312', 'utf-8', $result[$i][25]);
  1103. $bank_code = iconv('gb2312', 'utf-8', $result[$i][26]);
  1104. $bank_address = iconv('gb2312', 'utf-8', $result[$i][27]);
  1105. $is_settlement_account = iconv('gb2312', 'utf-8', $result[$i][28]);
  1106. $settlement_bank_account_name = iconv('gb2312', 'utf-8', $result[$i][29]);
  1107. $settlement_bank_account_number = iconv('gb2312', 'utf-8', $result[$i][30]);
  1108. $settlement_bank_name = iconv('gb2312', 'utf-8', $result[$i][31]);
  1109. $settlement_bank_code = iconv('gb2312', 'utf-8', $result[$i][32]);
  1110. $settlement_bank_address = iconv('gb2312', 'utf-8', $result[$i][33]);
  1111. $tax_registration_certificate = iconv('gb2312', 'utf-8', $result[$i][34]);
  1112. $taxpayer_id = iconv('gb2312', 'utf-8', $result[$i][35]);
  1113. $joinin_year = iconv('gb2312', 'utf-8', $result[$i][36]);
  1114. if(!$this->ckeckStoreName($store_name))
  1115. {
  1116. continue;
  1117. }
  1118. if(!$this->checkMemberName($member_name))
  1119. {
  1120. continue;
  1121. }
  1122. if(!$this->checkSellerName($seller_name))
  1123. {
  1124. continue;
  1125. }
  1126. try
  1127. {
  1128. $memberId = model('member')->addMember(array(
  1129. 'member_name' => $member_name,
  1130. 'member_passwd' => $password,
  1131. 'member_email' => '',
  1132. ));
  1133. }
  1134. catch (Exception $ex)
  1135. {
  1136. showMessage('店主账号新增失败', '', 'html', 'error');
  1137. }
  1138. $storeModel = model('store');
  1139. $saveArray = array();
  1140. $saveArray['store_name'] = $store_name;
  1141. $saveArray['grade_id'] = 1;
  1142. $saveArray['member_id'] = $memberId;
  1143. $saveArray['member_name'] = $member_name;
  1144. $saveArray['seller_name'] = $seller_name;
  1145. $saveArray['bind_all_gc'] = 0;
  1146. $saveArray['store_state'] = 1;
  1147. $saveArray['store_time'] = time();
  1148. $saveArray['store_company_name'] = $store_company_name;
  1149. $saveArray['store_address'] = $store_address;
  1150. $saveArray['store_zip'] = $store_zip;
  1151. $saveArray['store_qq'] = $store_qq;
  1152. $saveArray['store_ww'] = $store_ww;
  1153. $saveArray['store_phone'] = $store_phone;
  1154. $storeId = $storeModel->addStore($saveArray);
  1155. QueueClient::push('UpdateSotreLocation',['store_id' => $storeId]);
  1156. model('seller')->addSeller(array(
  1157. 'seller_name' => $seller_name,
  1158. 'member_id' => $memberId,
  1159. 'store_id' => $storeId,
  1160. 'seller_group_id' => 0,
  1161. 'is_admin' => 1,
  1162. ));
  1163. $store_joinModel = model('store_joinin');
  1164. $save_joinArray = array();
  1165. $save_joinArray['member_id'] = $memberId;
  1166. $save_joinArray['member_name'] = $member_name;
  1167. $save_joinArray['company_name'] = $company_name;
  1168. $save_joinArray['company_address'] = $company_address;
  1169. $save_joinArray['company_address_detail'] = $store_address;
  1170. $save_joinArray['company_phone'] = $store_phone;
  1171. $save_joinArray['company_employee_count'] = $company_employee_count;
  1172. $save_joinArray['company_registered_capital'] = $company_registered_capita;
  1173. $save_joinArray['contacts_name'] = $contacts_name;
  1174. $save_joinArray['contacts_phone'] = $contacts_phone;
  1175. $save_joinArray['contacts_email'] = $contacts_email;
  1176. $save_joinArray['business_licence_number'] = $business_licence_number;
  1177. $save_joinArray['business_licence_address'] = $business_licence_address;
  1178. $save_joinArray['business_licence_start'] = $business_licence_start;
  1179. $save_joinArray['business_licence_end'] = $business_licence_end;
  1180. $save_joinArray['business_sphere'] = $business_sphere;
  1181. $save_joinArray['organization_code'] = $organization_code;
  1182. $save_joinArray['general_taxpayer'] = $general_taxpayer;
  1183. $save_joinArray['bank_account_name'] = $bank_account_name;
  1184. $save_joinArray['bank_account_number'] = $bank_account_number;
  1185. $save_joinArray['bank_name'] = $bank_name;
  1186. $save_joinArray['bank_code'] = $bank_code;
  1187. $save_joinArray['bank_address'] = $bank_address;
  1188. $save_joinArray['is_settlement_account'] = $is_settlement_account;
  1189. if($is_settlement_account == '是')
  1190. {
  1191. //2独立
  1192. $save_joinArray['is_settlement_account'] = 2;
  1193. $save_joinArray['settlement_bank_account_name'] = $settlement_bank_account_name;
  1194. $save_joinArray['settlement_bank_account_number'] = $settlement_bank_account_number;
  1195. $save_joinArray['settlement_bank_name'] = $settlement_bank_name;
  1196. $save_joinArray['settlement_bank_code'] = $settlement_bank_code;
  1197. $save_joinArray['settlement_bank_address'] = $settlement_bank_address;
  1198. }
  1199. else
  1200. {
  1201. //1非独立
  1202. $save_joinArray['is_settlement_account'] = 1;
  1203. $save_joinArray['settlement_bank_account_name'] = $bank_account_name;
  1204. $save_joinArray['settlement_bank_account_number'] = $bank_account_number;
  1205. $save_joinArray['settlement_bank_name'] = $bank_name;
  1206. $save_joinArray['settlement_bank_code'] = $bank_code;
  1207. $save_joinArray['settlement_bank_address'] = $bank_address;
  1208. }
  1209. $save_joinArray['tax_registration_certificate'] = $tax_registration_certificate;
  1210. $save_joinArray['taxpayer_id'] = $taxpayer_id;
  1211. $save_joinArray['seller_name'] = $seller_name;
  1212. $save_joinArray['store_name'] = $store_name;
  1213. $save_joinArray['joinin_state'] = 40;
  1214. $save_joinArray['joinin_year'] = $joinin_year;
  1215. $save_joinArray['company_name'] = $company_name;
  1216. $save_joinArray['company_name'] = $company_name;
  1217. $store_joinModel->save($save_joinArray);
  1218. // 添加相册默认
  1219. $album_model = Model('album');
  1220. $album_arr = array();
  1221. $album_arr['aclass_name'] = '默认相册';
  1222. $album_arr['store_id'] = $storeId;
  1223. $album_arr['aclass_des'] = '';
  1224. $album_arr['aclass_sort'] = '255';
  1225. $album_arr['aclass_cover'] = '';
  1226. $album_arr['upload_time'] = time();
  1227. $album_arr['is_default'] = '1';
  1228. $album_model->addClass($album_arr);
  1229. //插入店铺扩展表
  1230. $model = Model();
  1231. $model->table('store_extend')->insert(array('store_id'=>$storeId));
  1232. $scounter++;
  1233. }
  1234. //$data_values = substr($data_values,0,-1); //去掉最后一个逗号
  1235. fclose($handle); //关闭指针
  1236. showMessage('操作成功,成功导入 '.strval($scounter).' 条数据' , urlAdmin('store', 'store'));
  1237. return;
  1238. /*
  1239. $row = 0;
  1240. while ($data = fgetcsv($handle, 10000)) {
  1241. $row++;
  1242. if ($row == 1) continue;
  1243. $num = count($data);
  1244. for ($i = 0; $i < $num; $i++) {
  1245. $t=iconv('gb2312', 'utf-8', $data[$i]);
  1246. echo $t.
  1247. "<br>";
  1248. }
  1249. }
  1250. fclose($handle);
  1251. */
  1252. }
  1253. }
  1254. /*
  1255. * 解析csv
  1256. */
  1257. private function input_csv($handle) {
  1258. $out = array ();
  1259. $n = 0;
  1260. while ($data = fgetcsv($handle, 10000)) {
  1261. $num = count($data);
  1262. for ($i = 0; $i < $num; $i++) {
  1263. $out[$n][$i] = $data[$i];
  1264. }
  1265. $n++;
  1266. }
  1267. return $out;
  1268. }
  1269. /**
  1270. * 汽车类商家批量导入解析csv
  1271. */
  1272. private function read_csv($handle, $encoding, $delimeter=";")
  1273. {
  1274. $out = [];
  1275. $n = 0;
  1276. while ($line = @fgets($handle))
  1277. {
  1278. if($n == 0) {
  1279. $n++;
  1280. continue;
  1281. }else{
  1282. $out[] = explode($delimeter, iconv($encoding,'utf-8',trim($line)));
  1283. $n++;
  1284. }
  1285. }
  1286. return $out;
  1287. }
  1288. private function get_str_encoding($str)
  1289. {
  1290. $encoding = mb_detect_encoding($str, ['GB2312','GBK','UTF-16','UCS-2','UTF-8','BIG5','ASCII']);
  1291. return $encoding;
  1292. }
  1293. }