Shop.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 山西牛酷信息科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com.cn
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace app\admin\controller;
  13. use app\model\shop\Shop as ShopModel;
  14. use app\model\shop\ShopAccount;
  15. use app\model\shop\ShopCategory as ShopCategoryModel;
  16. use app\model\shop\ShopExport;
  17. use app\model\shop\ShopGroup as ShopGroupModel;
  18. use app\model\member\Member as MemberModel;
  19. use app\model\order\OrderCommon;
  20. use app\model\shop\ShopDeposit;
  21. use app\model\web\WebSite;
  22. use phpoffice\phpexcel\Classes\PHPExcel;
  23. use phpoffice\phpexcel\Classes\PHPExcel\Writer\Excel2007;
  24. use think\Db;
  25. /**
  26. * 商家管理 控制器
  27. */
  28. class Shop extends BaseAdmin
  29. {
  30. /******************************* 商家列表及相关操作 ***************************/
  31. /**
  32. * 商家列表
  33. */
  34. public function lists()
  35. {
  36. if (request()->isAjax()) {
  37. $page = input('page', 1);
  38. $page_size = input('page_size', PAGE_LIST_ROWS);
  39. $search_text = input('search_text', '');
  40. $category_id = input('category_id', 0);
  41. $group_id = input('group_id', 0);
  42. $shop_status = input('shop_status', '');
  43. $cert_id = input('cert_id', '');
  44. $is_own = input('is_own', '');
  45. $start_time = input("start_time", '');
  46. $end_time = input("end_time", '');
  47. $condition = [];
  48. if($search_text){
  49. $condition[] = ['site_name', 'like', '%' . $search_text . '%'];
  50. }
  51. //商家分类
  52. if ($category_id != 0) {
  53. $condition[] = ['category_id', '=', $category_id];
  54. }
  55. //店铺等级
  56. if ($group_id != 0) {
  57. $condition[] = ['group_id', '=', $group_id];
  58. }
  59. //商家状态
  60. if ($shop_status != '') {
  61. $condition[] = ['shop_status', '=', $shop_status];
  62. }
  63. if($cert_id){
  64. switch($cert_id){
  65. case 1: //未认证
  66. $condition[] = ['cert_id', '=', 0];
  67. break;
  68. case 2: //已认证
  69. $condition[] = ['cert_id', '>', 0];
  70. break;
  71. }
  72. }
  73. if($is_own != '')
  74. {
  75. $condition[] = ['is_own', '=', $is_own];
  76. }
  77. if(!empty($start_time) && empty($end_time)){
  78. $condition[] = ['expire_time', '>=', strtotime($start_time)];
  79. } elseif (empty($start_time) && !empty($end_time)) {
  80. $condition[] = ["expire_time", "<=", strtotime($end_time)];
  81. } elseif (!empty($start_time) && !empty($end_time)) {
  82. $condition[] = ["expire_time", ">=", strtotime($start_time)];
  83. $condition[] = ["expire_time", "<=", strtotime($end_time)];
  84. }
  85. $order = 'site_id desc';
  86. $field = '*';
  87. $shop_model = new ShopModel();
  88. // 商家名称site_name 商家分类category_name 店铺等级group_name 是否自营is_own 1:是 0:否 商家状态shop_status 1:正常 0:锁定 有效期
  89. return $shop_model->getShopPageList($condition, $page, $page_size, $order, $field);
  90. } else {
  91. //商家主营行业
  92. $shop_category_model = new ShopCategoryModel();
  93. $shop_category_list = $shop_category_model->getCategoryList([], 'category_id, category_name', 'sort asc');
  94. $this->assign('shop_category_list', $shop_category_list['data']);
  95. //商家主营分组
  96. $shop_group_model = new ShopGroupModel();
  97. $shop_group_list = $shop_group_model->getGroupList([['is_own','=',0]], 'group_id,is_own,group_name,fee,remark', 'is_own asc,fee asc');
  98. $this->assign('shop_group_list', $shop_group_list['data']);
  99. $is_addon_city = addon_is_exit('city');
  100. $this->assign('is_addon_city',$is_addon_city);
  101. if($is_addon_city == 1){
  102. $website_model = new WebSite();
  103. $website_list = $website_model->getWebsiteList([],'site_id,site_area_name');
  104. $this->assign('website_list',$website_list['data']);
  105. }
  106. return $this->fetch('shop/lists');
  107. }
  108. }
  109. /**
  110. * 商家详情
  111. */
  112. public function shopDetail()
  113. {
  114. $site_id = input('site_id', 0);
  115. $shop_model = new ShopModel();
  116. //商家信息
  117. $shop_info = $shop_model->getShopInfo([['site_id', '=', $site_id]]);
  118. $this->assign('shop_info', $shop_info);
  119. //认证信息
  120. $cert_info = $shop_model->getShopCert([['site_id', '=', $site_id]]);
  121. $this->assign('cert_info', $cert_info);
  122. return $this->fetch('shop/shop_detail');
  123. }
  124. /**
  125. * 商家添加
  126. */
  127. public function addShop()
  128. {
  129. if (request()->isAjax()) {
  130. //店铺信息
  131. $shop_data = [
  132. 'site_name' => input('site_name', ''),//店铺名称
  133. 'category_id' => input('category_id', 0),//分类id
  134. 'category_name' => input('category_name', ''),//分类名称
  135. 'group_id' => input('group_id', 0),//组id
  136. 'group_name' => input('group_name', ''),//组名称
  137. 'is_own' => input('is_own', 0),//是否自营
  138. 'member_id' => input('member_id', 0),//关联会员 用于前台登陆和相关商家操作
  139. 'year' => input('year', 0),//入驻时长 1 2 3 4 5 下拉选择
  140. ];
  141. //认证信息
  142. $cert_data = [
  143. /* 申请类型 */
  144. 'cert_type' => input('cert_type', 1),//申请类型1.个人店铺 2.企业店铺
  145. /* 公司信息 只有公司类型有 */
  146. 'company_name' => input('company_name', ''),//公司名称
  147. 'company_province_id' => input('company_province_id', ''),//公司所在省
  148. 'company_city_id' => input('company_city_id', ''),//公司所在市
  149. 'company_district_id' => input('company_district_id', ''),//公司所在区/县
  150. 'company_address' => input('company_address', ''),//公司地址
  151. 'company_full_address' => input('company_full_address', ''),//公司完整地址
  152. /* 联系人手机号身份证 公司、个人类型都有 */
  153. 'contacts_name' => input('contacts_name', ''),//联系人姓名
  154. 'contacts_mobile' => input('contacts_mobile', ''),//联系人手机
  155. 'contacts_card_no' => input('contacts_card_no', ''),//联系人身份证
  156. 'contacts_card_electronic_1' => input('contacts_card_electronic_1', ''),//申请人手持身份证电子版
  157. 'contacts_card_electronic_2' => input('contacts_card_electronic_2', ''),//申请人身份证正面
  158. 'contacts_card_electronic_3' => input('contacts_card_electronic_3', ''),//申请人身份证反面
  159. /* 营业执照 税务 只有公司类型有 */
  160. 'business_licence_number' => input('business_licence_number', ''),//统一社会信用码 input
  161. 'business_licence_number_electronic' => input('business_licence_number_electronic', ''),//营业执照电子版
  162. 'business_sphere' => input('business_sphere', ''),//法定经营范围 textarea
  163. 'tax_registration_certificate' => input('tax_registration_certificate', ''),//税务登记证号
  164. 'tax_registration_certificate_electronic' => input('tax_registration_certificate_electronic', ''),//税务登记证号电子版
  165. /* 对公账户信息 只有公司类型有 */
  166. 'bank_account_name' => input('bank_account_name', ''),//银行开户名
  167. 'bank_account_number' => input('bank_account_number', ''),//公司银行账号
  168. 'bank_name' => input('bank_name', ''),//开户银行支行名称
  169. 'bank_address' => input('bank_address', ''),//开户银行所在地 用三级地址选择省市区 传递拼在一起的名字 如山西省太原市小店区
  170. /* 结算信息 公司、个人类型都有 */
  171. 'bank_type' => input('bank_type', 1),//结算账户类型 1银行卡 2 支付宝
  172. 'settlement_bank_account_name' => input('settlement_bank_account_name', 0),//结算银行开户名
  173. 'settlement_bank_account_number' => input('settlement_bank_account_number', 0),//结算公司银行账号
  174. 'settlement_bank_name' => input('settlement_bank_name', 0),//结算开户银行支行名称
  175. 'settlement_bank_address' => input('settlement_bank_address', 0),//结算开户银行所在地 用三级地址选择省市区 传递拼在一起的名字 如山西省太原市小店区
  176. ];
  177. //个人信息
  178. $user_info = [
  179. 'username' => input('username', ''),
  180. 'password' => data_md5(input('password', '')),
  181. ];
  182. $shop_model = new ShopModel();
  183. $this->addLog("添加商家:" . $shop_data['site_name']);
  184. return $shop_model->addShop($shop_data, $cert_data, $user_info);
  185. } else {
  186. //商家主营行业
  187. $shop_category_model = new ShopCategoryModel();
  188. $shop_category_list = $shop_category_model->getCategoryList([], 'category_id, category_name', 'sort asc');
  189. $this->assign('shop_category_list', $shop_category_list['data']);
  190. //商家主营行业
  191. $shop_group_model = new ShopGroupModel();
  192. $shop_group_list = $shop_group_model->getGroupList([['is_own','=',0]], 'group_id,is_own,group_name,fee,remark', 'is_own asc,fee asc');
  193. $this->assign('shop_group_list', $shop_group_list['data']);
  194. //商家自营等级
  195. $shop_own_group = $shop_group_model->getGroupList([['is_own','=',1]], 'group_id,is_own,group_name,fee,remark', 'fee asc');
  196. $this->assign('shop_own_group', $shop_own_group['data']);
  197. return $this->fetch('shop/add_shop');
  198. }
  199. }
  200. /**
  201. * 基本信息
  202. */
  203. public function basicInfo()
  204. {
  205. $shop_model = new ShopModel();
  206. if (request()->isAjax()) {
  207. $site_id = input('site_id', 0);
  208. $data = [
  209. 'site_name' => input('site_name', ''),//商家名称
  210. 'expire_time' => input('expire_time') ? strtotime(input('expire_time')) : 0,//到期时间(0表示无限期)
  211. //待定
  212. 'is_own' => input('is_own', 0),//是否自营
  213. 'category_id' => input('category_id', 0),//店铺分类id
  214. 'category_name' => input('category_name', ''),//店铺类别名称
  215. //待定
  216. 'group_id' => input('group_id', 0),//分组id
  217. 'group_name' => input('group_name', ''),//分组名称
  218. 'member_id' => input('member_id', 0),//关联前台会员id
  219. 'shop_status' => input('shop_status', ''),//店铺经营状态(0.关闭,1正常)
  220. 'sort' => input('sort', 0),//排序号
  221. 'logo' => input('logo', ''),//店铺logo
  222. 'avatar' => input('avatar', ''),//店铺头像(大图)
  223. 'banner' => input('banner', ''),//店铺条幅
  224. 'seo_keywords' => input('seo_keywords', ''),//店铺关键字
  225. 'seo_description' => input('seo_description', ''),//店铺简介
  226. 'telephone' => input('telephone', ''),//联系电话
  227. 'is_recommend' => input('is_recommend', 0),//是否推荐 1是 0否
  228. 'shop_qtian' => input('shop_qtian', 0),//七天退货 1是 0否
  229. 'shop_zhping' => input('shop_zhping', 0),//正品保障 1是 0否
  230. 'shop_erxiaoshi' => input('shop_erxiaoshi', 0),//两小时发货 1是 0否
  231. 'shop_tuihuo' => input('shop_tuihuo', 0),//退货承诺 1是 0否
  232. 'shop_shiyong' => input('shop_shiyong', 0),//试用中心 1是 0否
  233. 'shop_shiti' => input('shop_shiti', 0),//实体验证 1是 0否
  234. 'shop_xiaoxie' => input('shop_xiaoxie', 0),//消协保证 1是 0否
  235. ];
  236. return $shop_model->editShop($data, [['site_id', '=', $site_id]]);
  237. } else {
  238. //商家信息
  239. $site_id = input('site_id', 22);
  240. $shop_info = $shop_model->getShopInfo([['site_id', '=', $site_id]]);
  241. $this->assign('shop_info', $shop_info['data']);
  242. //关联前台会员信息
  243. if (!empty($shop_info['data']['member_id'])) {
  244. $member_id = $shop_info['data']['member_id'];
  245. $member_model = new MemberModel();
  246. $member_info = $member_model->getMemberInfo([['member_id', '=', $member_id]]);
  247. $this->assign('member_info', $member_info['data']);
  248. }
  249. //商家主营行业
  250. $shop_category_model = new ShopCategoryModel();
  251. $shop_category_list = $shop_category_model->getCategoryList([], 'category_id, category_name', 'sort asc');
  252. $this->assign('shop_category_list', $shop_category_list['data']);
  253. //商家开店套餐(非自营)
  254. $shop_group_model = new ShopGroupModel();
  255. $shop_group_list = $shop_group_model->getGroupList([['is_own','=',0]], 'group_id,is_own,group_name,fee,remark', 'is_own asc,fee asc');
  256. $this->assign('shop_group_list', $shop_group_list['data']);
  257. //商家开店套餐(自营)
  258. $shop_group_model = new ShopGroupModel();
  259. $shop_own_group_list = $shop_group_model->getGroupList([['is_own','=',1]], 'group_id,is_own,group_name,fee,remark', 'is_own asc,fee asc');
  260. $this->assign('shop_own_group_list', $shop_own_group_list['data']);
  261. //四级菜单
  262. $this->forthMenu(['site_id' => $site_id]);
  263. return $this->fetch('shop/basic_info');
  264. }
  265. }
  266. /**
  267. * 认证信息
  268. */
  269. public function certInfo()
  270. {
  271. $shop_model = new ShopModel();
  272. if (request()->isAjax()) {
  273. $site_id = input('site_id', 0);
  274. $shop = new ShopModel();
  275. $info = $shop->getShopInfo(['site_id'=>$site_id]);
  276. dump($info);die;
  277. //认证信息
  278. $data = [
  279. /* 公司信息 只有公司类型有 */
  280. 'company_name' => input('company_name', ''),//公司名称
  281. 'company_province_id' => input('company_province_id', 0),//公司所在省
  282. 'company_city_id' => input('company_city_id', 0),//公司所在市
  283. 'company_district_id' => input('company_district_id', 0),//公司所在区/县
  284. 'company_address' => input('company_address', ''),//公司地址
  285. /* 联系人手机号身份证 公司、个人类型都有 */
  286. 'contacts_name' => input('contacts_name', ''),//联系人姓名
  287. 'contacts_mobile' => input('contacts_mobile', ''),//联系人手机
  288. 'contacts_card_no' => input('contacts_card_no', ''),//联系人身份证
  289. 'contacts_card_electronic_1' => input('contacts_card_electronic_1', ''),//申请人手持身份证电子版
  290. 'contacts_card_electronic_2' => input('contacts_card_electronic_2', ''),//申请人身份证正面
  291. 'contacts_card_electronic_3' => input('contacts_card_electronic_3', ''),//申请人身份证反面
  292. /* 营业执照 税务 只有公司类型有 */
  293. 'business_licence_number' => input('business_licence_number', ''),//统一社会信用码 input
  294. 'business_licence_number_electronic' => input('business_licence_number_electronic', ''),//营业执照电子版
  295. 'business_sphere' => input('business_sphere', ''),//法定经营范围 textarea
  296. 'tax_registration_certificate' => input('tax_registration_certificate', ''),//税务登记证号
  297. 'tax_registration_certificate_electronic' => input('tax_registration_certificate_electronic', ''),//税务登记证号电子版
  298. /* 对公账户信息 只有公司类型有 */
  299. 'bank_account_name' => input('bank_account_name', ''),//银行开户名
  300. 'bank_account_number' => input('bank_account_number', ''),//公司银行账号
  301. 'bank_name' => input('bank_name', ''),//开户银行支行名称
  302. 'bank_address' => input('bank_address', ''),//开户银行所在地 用三级地址选择省市区 传递拼在一起的名字 如山西省太原市小店区
  303. ];
  304. $shop_model->editShop(['cert_id'=>1,'shop_status'=>1],['site_id'=>$site_id]);
  305. return $shop_model->editShopCert($data, [['site_id', '=', $site_id]]);
  306. } else {
  307. $site_id = input('site_id', 0);
  308. $cert_info = $shop_model->getShopCert([['site_id', '=', $site_id]]);
  309. $this->assign('cert_info', $cert_info['data']);
  310. //四级菜单
  311. $this->forthMenu(['site_id' => $site_id]);
  312. return $this->fetch('shop/cert_info');
  313. }
  314. }
  315. /**
  316. * 结算信息
  317. */
  318. public function settlementInfo()
  319. {
  320. $shop_model = new ShopModel();
  321. if (request()->isAjax()) {
  322. $site_id = input('site_id', 0);
  323. //结算账户信息
  324. $cert_data = [
  325. /* 结算信息 公司、个人类型都有 */
  326. 'bank_type' => input('bank_type', 0),//结算账户类型 1银行卡 2 支付宝
  327. 'settlement_bank_name' => input('settlement_bank_name', 0),//结算开户银行支行名称
  328. 'settlement_bank_address' => input('settlement_bank_address', 0),//结算开户银行所在地 用三级地址选择省市区 传递拼在一起的名字 如山西省太原市小店区
  329. ];
  330. $cert_data['settlement_bank_account_name'] = input('settlement_bank_account_name', 0);//结算银行开户名
  331. $cert_data['settlement_bank_account_number'] = input('settlement_bank_account_number', 0);//结算公司银行账号
  332. return $shop_model->editShopCert($cert_data, [['site_id', '=', $site_id]]);
  333. } else {
  334. $site_id = input('site_id', 0);
  335. //获取商家结算账户信息
  336. $cert_info = $shop_model->getShopCert([['site_id', '=', $site_id]]);
  337. $this->assign('cert_info', $cert_info['data']);
  338. //四级菜单
  339. $this->forthMenu(['site_id' => $site_id]);
  340. return $this->fetch('shop/settlement_info');
  341. }
  342. }
  343. /**
  344. * 账户信息
  345. */
  346. public function accountInfo()
  347. {
  348. $site_id = input('site_id', 0);
  349. //四级菜单
  350. $this->forthMenu(['site_id' => $site_id]);
  351. $shop_model = new ShopModel();
  352. $condition = [
  353. ['site_id', '=', $site_id]
  354. ];
  355. $account_info = $shop_model->getShopInfo($condition);
  356. $account = $account_info['data']['account'] - $account_info['data']['account_withdraw_apply'];
  357. $this->assign('account',number_format($account,2, '.' , ''));
  358. $this->assign('account_info', $account_info['data']);
  359. $this->assign('order_calc', 0);//待结算
  360. return $this->fetch('shop/account_info');
  361. }
  362. /**
  363. * 获取待结算列表
  364. */
  365. public function getOrderCalc()
  366. {
  367. if (request()->isAjax()) {
  368. $order_common = new OrderCommon();
  369. $site_id = input('site_id', 0);
  370. $page = input('page', 1);
  371. $page_size = input('page_size', PAGE_LIST_ROWS);
  372. $order = input("order", "create_time desc");
  373. $is_refund = input("is_refund", '');
  374. $order_no = input("order_no", '');
  375. $condition = array(
  376. ['site_id', "=", $site_id],
  377. ['is_settlement', "=", 0],
  378. ['order_status', "not in", '0,-1'],
  379. );
  380. if($order_no){
  381. $condition[] = ['order_no', 'like', '%'. $order_no .'%'];
  382. }
  383. if ($is_refund !== '') {
  384. $condition[] = ['refund_status', '=', $is_refund];
  385. }
  386. $list = $order_common->getOrderPageList($condition, $page, $page_size, $order, $field = 'order_id,order_no,order_type_name,order_status_name,order_money,shop_money,platform_money,is_settlement,create_time,refund_status,order_type');
  387. return $list;
  388. }
  389. }
  390. /**
  391. * 获取账户流水
  392. */
  393. public function getShopAccount()
  394. {
  395. if (request()->isAjax()) {
  396. $site_id = input('site_id', 0);
  397. $account_model = new ShopAccount();
  398. $page = input('page', 1);
  399. $page_size = input('page_size', PAGE_LIST_ROWS);
  400. $condition[] = ['site_id','=',$site_id];
  401. $type = input('type','');//收支类型(1收入 2支出)
  402. if(!empty($type)){
  403. switch($type){
  404. case 1:
  405. $condition[] = ['account_data','>',0];
  406. break;
  407. case 2:
  408. $condition[] = ['account_data','<',0];
  409. break;
  410. }
  411. }
  412. $start_time = input('start_time','');
  413. $end_time = input('end_time','');
  414. if(!empty($start_time) && empty($end_time)){
  415. $condition[] = ['create_time','>=',$start_time];
  416. }elseif(empty($start_time) && !empty($end_time)){
  417. $condition[] = ['create_time','<=',$end_time];
  418. }elseif(!empty($start_time) && !empty($end_time)){
  419. $condition[] = ['create_time','between',[$start_time,$end_time]];
  420. }
  421. return $account_model->getAccountPageList($condition,$page,$page_size,'id desc');
  422. }
  423. }
  424. /**
  425. * 获取提现记录
  426. */
  427. public function getShopWithdraw()
  428. {
  429. if (request()->isAjax()) {
  430. $site_id = input('site_id', 0);
  431. $account_model = new ShopAccount();
  432. $page = input('page', 1);
  433. $page_size = input('page_size', PAGE_LIST_ROWS);
  434. $order = input("order", "id desc");
  435. $search_text = input("search_text", "");
  436. $condition = array(
  437. ['site_id', "=", $site_id],
  438. );
  439. if (!empty($search_text)) {
  440. $condition[] = ['withdraw_no|settlement_bank_account_name|mobile', 'like', '%' . $search_text . '%'];
  441. }
  442. $list = $account_model->getShopWithdrawPageList($condition, $page, $page_size, $order);
  443. return $list;
  444. }
  445. }
  446. /**
  447. * 获取保证金记录
  448. */
  449. public function getShopDeposit()
  450. {
  451. if (request()->isAjax()) {
  452. $shop_deposit_model = new ShopDeposit();
  453. $site_id = input('site_id', 0);
  454. $page = input('page', 1);
  455. $page_size = input('page_size', PAGE_LIST_ROWS);
  456. $order = input("order", "id desc");
  457. $search_text = input("search_text", "");
  458. $condition = array(
  459. ['site_id', "=", $site_id],
  460. );
  461. if (!empty($search_text)) {
  462. $condition[] = ['pay_no|pay_account_name', 'like', '%' . $search_text . '%'];
  463. }
  464. $list = $shop_deposit_model->getShopDepositPageList($condition, $page, $page_size, $order);
  465. return $list;
  466. }
  467. }
  468. /**
  469. * 商家锁定
  470. */
  471. public function lockShop()
  472. {
  473. }
  474. /**
  475. * 商家解锁
  476. */
  477. public function unlockShop()
  478. {
  479. }
  480. /**
  481. * 商家导出
  482. */
  483. public function exportShop()
  484. {
  485. $search_text = input('search_text', '');
  486. $category_id = input('category_id', 0);
  487. $group_id = input('group_id', 0);
  488. $shop_status = input('shop_status', '');
  489. $condition = [];
  490. if ($search_text) {
  491. $condition[] = ['site_name', 'like', '%' . $search_text . '%'];
  492. }
  493. //商家分类
  494. if ($category_id != 0) {
  495. $condition[] = ['category_id', '=', $category_id];
  496. }
  497. //店铺等级
  498. if ($group_id != 0) {
  499. $condition[] = ['group_id', '=', $group_id];
  500. }
  501. //商家状态
  502. if ($shop_status != '') {
  503. $condition[] = ['shop_status', '=', $shop_status];
  504. }
  505. $order = 's.site_id desc';
  506. $shop_model = new ShopModel();
  507. $shop = $shop_model->getShopCertList($condition, $order);
  508. $header_arr = array(
  509. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  510. 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ',
  511. 'BA', 'BB', 'BC', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BK', 'BL', 'BM', 'BN', 'BO', 'BP', 'BQ', 'BR', 'BS', 'BT', 'BU', 'BV', 'BW', 'BX', 'BY', 'BZ',
  512. );
  513. $shop_export_model = new ShopExport();
  514. //导出所有字段
  515. $field = array_merge($shop_export_model->shop_field, $shop_export_model->shop_cert_field);
  516. //接收需要展示的字段
  517. $input_field = input('field', implode(',',array_keys($field)));
  518. $input_field = explode(',', $input_field);
  519. //处理数据
  520. if (!empty($shop['data'])) {
  521. $shop_list = $shop_export_model->handleData($shop['data'], $input_field);
  522. }
  523. $count = count($input_field);
  524. // 实例化excel
  525. $phpExcel = new \PHPExcel();
  526. $phpExcel->getProperties()->setTitle("店铺信息");
  527. $phpExcel->getProperties()->setSubject("店铺信息");
  528. //单独添加列名称
  529. $phpExcel->setActiveSheetIndex(0);
  530. for ($i = 0; $i < $count; $i++) {
  531. $phpExcel->getActiveSheet()->setCellValue($header_arr[$i] . '1', $field[$input_field[$i]]);
  532. }
  533. if (!empty($shop_list)) {
  534. foreach ($shop_list as $k => $v) {
  535. $start = $k + 2;
  536. for ($i = 0; $i < $count; $i++) {
  537. $phpExcel->getActiveSheet()->setCellValue($header_arr[$i] . $start, $v[$input_field[$i]]);
  538. }
  539. }
  540. }
  541. // 重命名工作sheet
  542. $phpExcel->getActiveSheet()->setTitle('店铺信息');
  543. // 设置第一个sheet为工作的sheet
  544. $phpExcel->setActiveSheetIndex(0);
  545. // 保存Excel 2007格式文件,保存路径为当前路径,名字为export.xlsx
  546. $objWriter = \PHPExcel_IOFactory::createWriter($phpExcel, 'Excel2007');
  547. $file = date('Y年m月d日-店铺信息表', time()) . '.xlsx';
  548. $objWriter->save($file);
  549. header("Content-type:application/octet-stream");
  550. $filename = basename($file);
  551. header("Content-Disposition:attachment;filename = " . $filename);
  552. header("Accept-ranges:bytes");
  553. header("Accept-length:" . filesize($file));
  554. readfile($file);
  555. unlink($file);
  556. exit;
  557. }
  558. /**
  559. * 导出字段
  560. * @return array
  561. */
  562. public function getPrintingField()
  563. {
  564. $model = new ShopExport();
  565. $field = array_merge($model->shop_field, $model->shop_cert_field);
  566. return success('1', '', $field);
  567. }
  568. }