Shop.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  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. $infodata = $info['data'];
  277. print_r($infodata);die;
  278. //认证信息
  279. $data = [
  280. /* 公司信息 只有公司类型有 */
  281. 'company_name' => input('company_name', ''),//公司名称
  282. 'company_province_id' => input('company_province_id', 0),//公司所在省
  283. 'company_city_id' => input('company_city_id', 0),//公司所在市
  284. 'company_district_id' => input('company_district_id', 0),//公司所在区/县
  285. 'company_address' => input('company_address', ''),//公司地址
  286. /* 联系人手机号身份证 公司、个人类型都有 */
  287. 'contacts_name' => input('contacts_name', ''),//联系人姓名
  288. 'contacts_mobile' => input('contacts_mobile', ''),//联系人手机
  289. 'contacts_card_no' => input('contacts_card_no', ''),//联系人身份证
  290. 'contacts_card_electronic_1' => input('contacts_card_electronic_1', ''),//申请人手持身份证电子版
  291. 'contacts_card_electronic_2' => input('contacts_card_electronic_2', ''),//申请人身份证正面
  292. 'contacts_card_electronic_3' => input('contacts_card_electronic_3', ''),//申请人身份证反面
  293. /* 营业执照 税务 只有公司类型有 */
  294. 'business_licence_number' => input('business_licence_number', ''),//统一社会信用码 input
  295. 'business_licence_number_electronic' => input('business_licence_number_electronic', ''),//营业执照电子版
  296. 'business_sphere' => input('business_sphere', ''),//法定经营范围 textarea
  297. 'tax_registration_certificate' => input('tax_registration_certificate', ''),//税务登记证号
  298. 'tax_registration_certificate_electronic' => input('tax_registration_certificate_electronic', ''),//税务登记证号电子版
  299. /* 对公账户信息 只有公司类型有 */
  300. 'bank_account_name' => input('bank_account_name', ''),//银行开户名
  301. 'bank_account_number' => input('bank_account_number', ''),//公司银行账号
  302. 'bank_name' => input('bank_name', ''),//开户银行支行名称
  303. 'bank_address' => input('bank_address', ''),//开户银行所在地 用三级地址选择省市区 传递拼在一起的名字 如山西省太原市小店区
  304. ];
  305. $shop_model->editShop(['cert_id'=>1,'shop_status'=>1],['site_id'=>$site_id]);
  306. return $shop_model->editShopCert($data, [['site_id', '=', $site_id]]);
  307. } else {
  308. $site_id = input('site_id', 0);
  309. $cert_info = $shop_model->getShopCert([['site_id', '=', $site_id]]);
  310. $this->assign('cert_info', $cert_info['data']);
  311. //四级菜单
  312. $this->forthMenu(['site_id' => $site_id]);
  313. return $this->fetch('shop/cert_info');
  314. }
  315. }
  316. /**
  317. * 结算信息
  318. */
  319. public function settlementInfo()
  320. {
  321. $shop_model = new ShopModel();
  322. if (request()->isAjax()) {
  323. $site_id = input('site_id', 0);
  324. //结算账户信息
  325. $cert_data = [
  326. /* 结算信息 公司、个人类型都有 */
  327. 'bank_type' => input('bank_type', 0),//结算账户类型 1银行卡 2 支付宝
  328. 'settlement_bank_name' => input('settlement_bank_name', 0),//结算开户银行支行名称
  329. 'settlement_bank_address' => input('settlement_bank_address', 0),//结算开户银行所在地 用三级地址选择省市区 传递拼在一起的名字 如山西省太原市小店区
  330. ];
  331. $cert_data['settlement_bank_account_name'] = input('settlement_bank_account_name', 0);//结算银行开户名
  332. $cert_data['settlement_bank_account_number'] = input('settlement_bank_account_number', 0);//结算公司银行账号
  333. return $shop_model->editShopCert($cert_data, [['site_id', '=', $site_id]]);
  334. } else {
  335. $site_id = input('site_id', 0);
  336. //获取商家结算账户信息
  337. $cert_info = $shop_model->getShopCert([['site_id', '=', $site_id]]);
  338. $this->assign('cert_info', $cert_info['data']);
  339. //四级菜单
  340. $this->forthMenu(['site_id' => $site_id]);
  341. return $this->fetch('shop/settlement_info');
  342. }
  343. }
  344. /**
  345. * 账户信息
  346. */
  347. public function accountInfo()
  348. {
  349. $site_id = input('site_id', 0);
  350. //四级菜单
  351. $this->forthMenu(['site_id' => $site_id]);
  352. $shop_model = new ShopModel();
  353. $condition = [
  354. ['site_id', '=', $site_id]
  355. ];
  356. $account_info = $shop_model->getShopInfo($condition);
  357. $account = $account_info['data']['account'] - $account_info['data']['account_withdraw_apply'];
  358. $this->assign('account',number_format($account,2, '.' , ''));
  359. $this->assign('account_info', $account_info['data']);
  360. $this->assign('order_calc', 0);//待结算
  361. return $this->fetch('shop/account_info');
  362. }
  363. /**
  364. * 获取待结算列表
  365. */
  366. public function getOrderCalc()
  367. {
  368. if (request()->isAjax()) {
  369. $order_common = new OrderCommon();
  370. $site_id = input('site_id', 0);
  371. $page = input('page', 1);
  372. $page_size = input('page_size', PAGE_LIST_ROWS);
  373. $order = input("order", "create_time desc");
  374. $is_refund = input("is_refund", '');
  375. $order_no = input("order_no", '');
  376. $condition = array(
  377. ['site_id', "=", $site_id],
  378. ['is_settlement', "=", 0],
  379. ['order_status', "not in", '0,-1'],
  380. );
  381. if($order_no){
  382. $condition[] = ['order_no', 'like', '%'. $order_no .'%'];
  383. }
  384. if ($is_refund !== '') {
  385. $condition[] = ['refund_status', '=', $is_refund];
  386. }
  387. $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');
  388. return $list;
  389. }
  390. }
  391. /**
  392. * 获取账户流水
  393. */
  394. public function getShopAccount()
  395. {
  396. if (request()->isAjax()) {
  397. $site_id = input('site_id', 0);
  398. $account_model = new ShopAccount();
  399. $page = input('page', 1);
  400. $page_size = input('page_size', PAGE_LIST_ROWS);
  401. $condition[] = ['site_id','=',$site_id];
  402. $type = input('type','');//收支类型(1收入 2支出)
  403. if(!empty($type)){
  404. switch($type){
  405. case 1:
  406. $condition[] = ['account_data','>',0];
  407. break;
  408. case 2:
  409. $condition[] = ['account_data','<',0];
  410. break;
  411. }
  412. }
  413. $start_time = input('start_time','');
  414. $end_time = input('end_time','');
  415. if(!empty($start_time) && empty($end_time)){
  416. $condition[] = ['create_time','>=',$start_time];
  417. }elseif(empty($start_time) && !empty($end_time)){
  418. $condition[] = ['create_time','<=',$end_time];
  419. }elseif(!empty($start_time) && !empty($end_time)){
  420. $condition[] = ['create_time','between',[$start_time,$end_time]];
  421. }
  422. return $account_model->getAccountPageList($condition,$page,$page_size,'id desc');
  423. }
  424. }
  425. /**
  426. * 获取提现记录
  427. */
  428. public function getShopWithdraw()
  429. {
  430. if (request()->isAjax()) {
  431. $site_id = input('site_id', 0);
  432. $account_model = new ShopAccount();
  433. $page = input('page', 1);
  434. $page_size = input('page_size', PAGE_LIST_ROWS);
  435. $order = input("order", "id desc");
  436. $search_text = input("search_text", "");
  437. $condition = array(
  438. ['site_id', "=", $site_id],
  439. );
  440. if (!empty($search_text)) {
  441. $condition[] = ['withdraw_no|settlement_bank_account_name|mobile', 'like', '%' . $search_text . '%'];
  442. }
  443. $list = $account_model->getShopWithdrawPageList($condition, $page, $page_size, $order);
  444. return $list;
  445. }
  446. }
  447. /**
  448. * 获取保证金记录
  449. */
  450. public function getShopDeposit()
  451. {
  452. if (request()->isAjax()) {
  453. $shop_deposit_model = new ShopDeposit();
  454. $site_id = input('site_id', 0);
  455. $page = input('page', 1);
  456. $page_size = input('page_size', PAGE_LIST_ROWS);
  457. $order = input("order", "id desc");
  458. $search_text = input("search_text", "");
  459. $condition = array(
  460. ['site_id', "=", $site_id],
  461. );
  462. if (!empty($search_text)) {
  463. $condition[] = ['pay_no|pay_account_name', 'like', '%' . $search_text . '%'];
  464. }
  465. $list = $shop_deposit_model->getShopDepositPageList($condition, $page, $page_size, $order);
  466. return $list;
  467. }
  468. }
  469. /**
  470. * 商家锁定
  471. */
  472. public function lockShop()
  473. {
  474. }
  475. /**
  476. * 商家解锁
  477. */
  478. public function unlockShop()
  479. {
  480. }
  481. /**
  482. * 商家导出
  483. */
  484. public function exportShop()
  485. {
  486. $search_text = input('search_text', '');
  487. $category_id = input('category_id', 0);
  488. $group_id = input('group_id', 0);
  489. $shop_status = input('shop_status', '');
  490. $condition = [];
  491. if ($search_text) {
  492. $condition[] = ['site_name', 'like', '%' . $search_text . '%'];
  493. }
  494. //商家分类
  495. if ($category_id != 0) {
  496. $condition[] = ['category_id', '=', $category_id];
  497. }
  498. //店铺等级
  499. if ($group_id != 0) {
  500. $condition[] = ['group_id', '=', $group_id];
  501. }
  502. //商家状态
  503. if ($shop_status != '') {
  504. $condition[] = ['shop_status', '=', $shop_status];
  505. }
  506. $order = 's.site_id desc';
  507. $shop_model = new ShopModel();
  508. $shop = $shop_model->getShopCertList($condition, $order);
  509. $header_arr = array(
  510. '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',
  511. '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',
  512. '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',
  513. );
  514. $shop_export_model = new ShopExport();
  515. //导出所有字段
  516. $field = array_merge($shop_export_model->shop_field, $shop_export_model->shop_cert_field);
  517. //接收需要展示的字段
  518. $input_field = input('field', implode(',',array_keys($field)));
  519. $input_field = explode(',', $input_field);
  520. //处理数据
  521. if (!empty($shop['data'])) {
  522. $shop_list = $shop_export_model->handleData($shop['data'], $input_field);
  523. }
  524. $count = count($input_field);
  525. // 实例化excel
  526. $phpExcel = new \PHPExcel();
  527. $phpExcel->getProperties()->setTitle("店铺信息");
  528. $phpExcel->getProperties()->setSubject("店铺信息");
  529. //单独添加列名称
  530. $phpExcel->setActiveSheetIndex(0);
  531. for ($i = 0; $i < $count; $i++) {
  532. $phpExcel->getActiveSheet()->setCellValue($header_arr[$i] . '1', $field[$input_field[$i]]);
  533. }
  534. if (!empty($shop_list)) {
  535. foreach ($shop_list as $k => $v) {
  536. $start = $k + 2;
  537. for ($i = 0; $i < $count; $i++) {
  538. $phpExcel->getActiveSheet()->setCellValue($header_arr[$i] . $start, $v[$input_field[$i]]);
  539. }
  540. }
  541. }
  542. // 重命名工作sheet
  543. $phpExcel->getActiveSheet()->setTitle('店铺信息');
  544. // 设置第一个sheet为工作的sheet
  545. $phpExcel->setActiveSheetIndex(0);
  546. // 保存Excel 2007格式文件,保存路径为当前路径,名字为export.xlsx
  547. $objWriter = \PHPExcel_IOFactory::createWriter($phpExcel, 'Excel2007');
  548. $file = date('Y年m月d日-店铺信息表', time()) . '.xlsx';
  549. $objWriter->save($file);
  550. header("Content-type:application/octet-stream");
  551. $filename = basename($file);
  552. header("Content-Disposition:attachment;filename = " . $filename);
  553. header("Accept-ranges:bytes");
  554. header("Accept-length:" . filesize($file));
  555. readfile($file);
  556. unlink($file);
  557. exit;
  558. }
  559. /**
  560. * 导出字段
  561. * @return array
  562. */
  563. public function getPrintingField()
  564. {
  565. $model = new ShopExport();
  566. $field = array_merge($model->shop_field, $model->shop_cert_field);
  567. return success('1', '', $field);
  568. }
  569. }