Store.php 45 KB

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