Store.php 45 KB

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