Sellerinfo.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. *
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 控制器
  14. */
  15. class Sellerinfo extends BaseSeller
  16. {
  17. public function initialize()
  18. {
  19. parent::initialize();
  20. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerinfo.lang.php');
  21. }
  22. /**
  23. * 店铺信息
  24. */
  25. public function index()
  26. {
  27. $store_model = model('store');
  28. $storebindclass_model = model('storebindclass');
  29. $storeclass_model = model('storeclass');
  30. $storegrade_model = model('storegrade');
  31. // 店铺信息
  32. $store_info = $store_model->getStoreInfoByID(session('store_id'));
  33. View::assign('store_info', $store_info);
  34. // 店铺分类信息
  35. $store_class_info = $storeclass_model->getStoreclassInfo(array('storeclass_id' => $store_info['storeclass_id']));
  36. View::assign('store_class_name', $store_class_info['storeclass_name']);
  37. // 店铺等级信息
  38. $store_grade_info = $storegrade_model->getOneStoregrade($store_info['grade_id']);
  39. View::assign('store_grade_name', $store_grade_info['storegrade_name']);
  40. $storejoinin_model = model('storejoinin');
  41. $joinin_detail = $storejoinin_model->getOneStorejoinin(array('member_id' => $store_info['member_id']));
  42. View::assign('joinin_detail', $joinin_detail);
  43. $store_bind_class_list = $storebindclass_model->getStorebindclassList(array(
  44. array('store_id', '=', session('store_id')),
  45. array('storebindclass_state', 'in', array(1, 2))
  46. ), null);
  47. $goods_class = model('goodsclass')->getGoodsclassIndexedListAll();
  48. for ($i = 0, $j = count($store_bind_class_list); $i < $j; $i++) {
  49. $store_bind_class_list[$i]['class_1_name'] = @$goods_class[$store_bind_class_list[$i]['class_1']]['gc_name'];
  50. $store_bind_class_list[$i]['class_2_name'] = @$goods_class[$store_bind_class_list[$i]['class_2']]['gc_name'];
  51. $store_bind_class_list[$i]['class_3_name'] = @$goods_class[$store_bind_class_list[$i]['class_3']]['gc_name'];
  52. }
  53. View::assign('store_bind_class_list', $store_bind_class_list);
  54. $this->setSellerCurMenu('sellerinfo');
  55. $this->setSellerCurItem('index');
  56. return View::fetch($this->template_dir . 'index');
  57. }
  58. /**
  59. * 经营类目列表
  60. */
  61. public function bind_class()
  62. {
  63. $storebindclass_model = model('storebindclass');
  64. $store_bind_class_list = $storebindclass_model->getStorebindclassList(array('store_id' => session('store_id')), null);
  65. $goods_class = model('goodsclass')->getGoodsclassIndexedListAll();
  66. for ($i = 0, $j = count($store_bind_class_list); $i < $j; $i++) {
  67. $store_bind_class_list[$i]['class_1_name'] = @$goods_class[$store_bind_class_list[$i]['class_1']]['gc_name'];
  68. $store_bind_class_list[$i]['class_2_name'] = @$goods_class[$store_bind_class_list[$i]['class_2']]['gc_name'];
  69. $store_bind_class_list[$i]['class_3_name'] = @$goods_class[$store_bind_class_list[$i]['class_3']]['gc_name'];
  70. }
  71. View::assign('bind_list', $store_bind_class_list);
  72. $this->setSellerCurMenu('sellerinfo');
  73. $this->setSellerCurItem('bind_class');
  74. return View::fetch($this->template_dir . 'bind_class_index');
  75. }
  76. /**
  77. * 申请新的经营类目
  78. */
  79. public function bind_class_add()
  80. {
  81. $goodsclass_model = model('goodsclass');
  82. $gc_list = $goodsclass_model->getGoodsclassListByParentId(0);
  83. View::assign('gc_list', $gc_list);
  84. $this->setSellerCurMenu('sellerinfo');
  85. $this->setSellerCurItem('bind_class');
  86. return View::fetch($this->template_dir . 'bind_class_add');
  87. }
  88. /**
  89. * 申请新经营类目保存
  90. */
  91. public function bind_class_save()
  92. {
  93. if (!request()->isPost())
  94. exit();
  95. $goods_class_array = input('post.goods_class'); #获取数组
  96. if (preg_match('/^[\d,]+$/', $goods_class_array)) {
  97. @list($class_1, $class_2, $class_3) = explode(',', trim($goods_class_array));
  98. } else {
  99. ds_json_encode(10001, lang('ds_common_save_fail'));
  100. }
  101. $storebindclass_model = model('storebindclass');
  102. $param = array();
  103. $param['store_id'] = session('store_id');
  104. $param['storebindclass_state'] = 0;
  105. $param['class_1'] = $class_1;
  106. $last_gc_id = $class_1;
  107. if (!empty($class_2)) {
  108. $param['class_2'] = $class_2;
  109. $last_gc_id = $class_2;
  110. }
  111. if (!empty($class_3)) {
  112. $param['class_3'] = $class_3;
  113. $last_gc_id = $class_3;
  114. }
  115. // 检查类目是否已经存在
  116. $store_bind_class_info = $storebindclass_model->getStorebindclassInfo($param);
  117. if (!empty($store_bind_class_info)) {
  118. ds_json_encode(10001, lang('store_bind_class_exist'));
  119. }
  120. //取分佣比例
  121. $goods_class_info = model('goodsclass')->getGoodsclassInfoById($last_gc_id);
  122. $param['commis_rate'] = $goods_class_info['commis_rate'];
  123. $result = $storebindclass_model->addStorebindclass($param);
  124. if ($result) {
  125. ds_json_encode(10000, lang('apply_success'));
  126. } else {
  127. ds_json_encode(10001, lang('ds_common_save_fail'));
  128. }
  129. }
  130. /**
  131. * 删除申请的经营类目
  132. */
  133. public function bind_class_del()
  134. {
  135. $condition = array();
  136. $condition[] = array('storebindclass_id', '=', intval(input('param.bid')));
  137. $condition[] = array('store_id', '=', session('store_id'));
  138. $condition[] = array('storebindclass_state', '=', 0);
  139. $del = model('storebindclass')->delStorebindclass($condition);
  140. if ($del) {
  141. ds_json_encode(10000, lang('ds_common_del_succ'));
  142. } else {
  143. ds_json_encode(10001, lang('ds_common_del_fail'));
  144. }
  145. }
  146. /**
  147. * 店铺续签
  148. */
  149. public function reopen()
  150. {
  151. $storereopen_model = model('storereopen');
  152. $reopen_list = $storereopen_model->getStorereopenList(array('storereopen_store_id' => session('store_id')));
  153. View::assign('reopen_list', $reopen_list);
  154. $store_info = $this->store_info;
  155. if (intval($store_info['store_endtime']) > 0) {
  156. $store_info['store_endtime_text'] = date('Y-m-d', $store_info['store_endtime']);
  157. $reopen_time = $store_info['store_endtime'] - 3600 * 24 + 1 - TIMESTAMP;
  158. if (!check_platform_store() && $store_info['store_endtime'] - TIMESTAMP >= 0 && $reopen_time < 2592000) {
  159. //(<30天)
  160. $store_info['reopen'] = true;
  161. }
  162. $store_info['allow_applay_date'] = $store_info['store_endtime'] - 2592000;
  163. }
  164. if (!empty($reopen_list)) {
  165. $last = reset($reopen_list);
  166. $store_endtime = $store_info['store_endtime'];
  167. if (!check_platform_store() && $store_endtime - TIMESTAMP < 2592000 && $store_endtime - TIMESTAMP >= 0) {
  168. //(<30天)
  169. $store_info['reopen'] = true;
  170. } else {
  171. $store_info['reopen'] = false;
  172. }
  173. }
  174. View::assign('store_info', $store_info);
  175. //店铺等级
  176. $grade_list = rkcache('storegrade', true);
  177. View::assign('grade_list', $grade_list);
  178. //默认选中当前级别
  179. View::assign('current_grade_id', session('grade_id'));
  180. //如果存在有未上传凭证或审核中的信息,则不能再申请续签
  181. $condition = array();
  182. $condition[] = array('storereopen_state', 'in', array(0, 1));
  183. $condition[] = array('storereopen_store_id', '=', session('store_id'));
  184. $reopen_info = $storereopen_model->getStorereopenInfo($condition);
  185. if ($reopen_info) {
  186. if ($reopen_info['storereopen_state'] == '0') {
  187. View::assign('upload_cert', true);
  188. View::assign('reopen_info', $reopen_info);
  189. }
  190. } else {
  191. View::assign('applay_reopen', isset($store_info['reopen']) ? true : false);
  192. }
  193. $this->setSellerCurMenu('sellerinfo');
  194. $this->setSellerCurItem('reopen');
  195. return View::fetch($this->template_dir . 'reopen_index');
  196. }
  197. /**
  198. * 申请续签
  199. */
  200. public function reopen_add()
  201. {
  202. if (request()->isPost()) {
  203. $storereopen_grade_id = intval(input('post.storereopen_grade_id'));
  204. $storereopen_year = intval(input('post.storereopen_year'));
  205. if ($storereopen_grade_id <= 0 || $storereopen_year <= 0)
  206. exit();
  207. // 店铺信息
  208. $store_info = $this->store_info;
  209. if (empty($store_info['store_endtime'])) {
  210. ds_json_encode(10001, lang('store_endtime_no_limit'));
  211. }
  212. $storereopen_model = model('storereopen');
  213. //如果存在有未上传凭证或审核中的信息,则不能再申请续签
  214. $condition = array();
  215. $condition[] = array('storereopen_state', 'in', array(0, 1));
  216. $condition[] = array('storereopen_store_id', '=', session('store_id'));
  217. if ($storereopen_model->getStorereopenCount($condition)) {
  218. ds_json_encode(10001, lang('store_bind_class_repeat'));
  219. }
  220. $data = array();
  221. //取店铺等级信息
  222. $grade_list = rkcache('storegrade', true);
  223. if (empty($grade_list[$storereopen_grade_id])) {
  224. exit();
  225. }
  226. //取得店铺信息
  227. $data['storereopen_grade_id'] = $storereopen_grade_id;
  228. $data['storereopen_grade_name'] = $grade_list[$storereopen_grade_id]['storegrade_name'];
  229. $data['storereopen_grade_price'] = $grade_list[$storereopen_grade_id]['storegrade_price'];
  230. $data['storereopen_store_id'] = session('store_id');
  231. $data['storereopen_store_name'] = session('store_name');
  232. $data['storereopen_year'] = $storereopen_year;
  233. $data['storereopen_pay_amount'] = $data['storereopen_grade_price'] * $data['storereopen_year'];
  234. if ($data['storereopen_pay_amount'] == 0) {
  235. $data['storereopen_state'] = 1;
  236. }
  237. $insert = $storereopen_model->addStorereopen($data);
  238. if ($insert) {
  239. if ($data['storereopen_pay_amount'] == 0) {
  240. ds_json_encode(10000, lang('apply_success'));
  241. } else {
  242. ds_json_encode(10000, lang('ds_common_save_succ') . sprintf(lang('storereopen_pay_amount_notice'), ds_price_format($data['storereopen_pay_amount'])));
  243. }
  244. } else {
  245. ds_json_encode(10001, lang('ds_common_save_fail'));
  246. }
  247. }
  248. }
  249. //上传付款凭证
  250. public function reopen_upload()
  251. {
  252. if (!empty($_FILES['storereopen_pay_cert']['tmp_name'])) {
  253. $res = ds_upload_pic(ATTACH_PATH . DIRECTORY_SEPARATOR . 'store_joinin', 'storereopen_pay_cert');
  254. if ($res['code']) {
  255. $pic_name = $res['data']['file_name'];
  256. } else {
  257. $this->error($res['msg']);
  258. }
  259. }
  260. $data = array();
  261. $data['storereopen_pay_cert'] = $pic_name;
  262. $data['storereopen_pay_cert_explain'] = input('post.storereopen_pay_cert_explain');
  263. $data['storereopen_state'] = 1;
  264. $storereopen_model = model('storereopen');
  265. $update = $storereopen_model->editStorereopen($data, array('storereopen_id' => input('post.storereopen_id'), 'storereopen_state' => 0));
  266. if ($update) {
  267. $this->success(lang('upload_success'));
  268. } else {
  269. $this->error(lang('ds_common_save_fail'));
  270. }
  271. }
  272. /**
  273. * 删除未上传付款凭证的续签信息
  274. */
  275. public function reopen_del()
  276. {
  277. $storereopen_model = model('storereopen');
  278. $condition = array();
  279. $condition[] = array('storereopen_id', '=', intval(input('param.storereopen_id')));
  280. $condition[] = array('storereopen_state', '=', 0);
  281. $condition[] = array('storereopen_store_id', '=', session('store_id'));
  282. $del = $storereopen_model->delStorereopen($condition);
  283. if ($del) {
  284. ds_json_encode(10000, lang('ds_common_del_succ'));
  285. } else {
  286. ds_json_encode(10001, lang('ds_common_del_fail'));
  287. }
  288. }
  289. /**
  290. * 用户中心右边,小导航
  291. *
  292. * @param string $menu_type 导航类型
  293. * @param string $name 当前导航的name
  294. * @param array $array 附加菜单
  295. * @return
  296. */
  297. protected function getSellerItemList()
  298. {
  299. $menu_array = array();
  300. switch (request()->action()) {
  301. case 'index':
  302. $menu_array[] = array(
  303. 'name' => 'bind_class', 'text' => lang('ds_member_path_bind_class'),
  304. 'url' => (string) url('Sellerinfo/bind_class')
  305. );
  306. $menu_array[] = array(
  307. 'name' => 'index', 'text' => lang('ds_member_path_store_info'),
  308. 'url' => (string) url('Sellerinfo/index')
  309. );
  310. $menu_array[] = array(
  311. 'name' => 'reopen', 'text' => lang('ds_member_path_store_reopen'),
  312. 'url' => (string) url('Sellerinfo/reopen')
  313. );
  314. break;
  315. case 'bind_class':
  316. $menu_array[] = array(
  317. 'name' => 'bind_class', 'text' => lang('ds_member_path_bind_class'),
  318. 'url' => (string) url('Sellerinfo/bind_class')
  319. );
  320. if (!check_platform_store()) {
  321. $menu_array[] = array(
  322. 'name' => 'index', 'text' => lang('ds_member_path_store_info'),
  323. 'url' => (string) url('Sellerinfo/index')
  324. );
  325. $menu_array[] = array(
  326. 'name' => 'reopen', 'text' => lang('ds_member_path_store_reopen'),
  327. 'url' => (string) url('Sellerinfo/reopen')
  328. );
  329. }
  330. break;
  331. case 'reopen':
  332. $menu_array = array(
  333. array(
  334. 'name' => 'index', 'text' => lang('ds_member_path_bind_class'),
  335. 'url' => (string) url('Sellerinfo/bind_class')
  336. ), array(
  337. 'name' => 'index', 'text' => lang('ds_member_path_store_info'),
  338. 'url' => (string) url('Sellerinfo/index')
  339. ), array(
  340. 'name' => 'reopen', 'text' => lang('ds_member_path_store_reopen'),
  341. 'url' => (string) url('Sellerinfo/reopen')
  342. )
  343. );
  344. break;
  345. }
  346. if (!empty($array)) {
  347. $menu_array[] = $array;
  348. }
  349. return $menu_array;
  350. }
  351. }