Store.php 45 KB

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