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