Apply.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace app\shopapi\controller;
  11. use app\model\shop\ShopApply;
  12. use app\model\shop\ShopGroup as ShopGroupModel;
  13. use app\model\shop\ShopCategory as ShopCategoryModel;
  14. use app\model\shop\ShopApply as ShopApplyModel;
  15. use app\model\shop\Config as ConfigModel;
  16. use app\model\system\Address as AddressModel;
  17. use app\model\web\WebSite as WebsiteModel;
  18. use app\model\shop\ShopAccount as ShopaccountModel;
  19. use app\model\system\Promotion as PromotionModel;
  20. use addon\shopwithdraw\model\Config as ShopWithdrawConfig;
  21. use app\model\system\User as userModel;
  22. use think\facade\Cache;
  23. use think\facade\Session;
  24. class Apply extends BaseApi
  25. {
  26. public function __construct()
  27. {
  28. //执行父类构造函数
  29. parent::__construct();
  30. $token = $this->checkToken();
  31. if ($token[ 'code' ] < 0) {
  32. echo $this->response($token);
  33. exit;
  34. }
  35. }
  36. /**
  37. * 申请入驻首页
  38. * @return false|string
  39. */
  40. public function index()
  41. {
  42. //店铺主营行业
  43. $shop_category_model = new ShopCategoryModel();
  44. $shop_category = $shop_category_model->getCategoryList('', '*', 'sort asc', '');
  45. $data[ 'shop_category' ] = $shop_category[ 'data' ];
  46. //入驻协议
  47. $config_model = new ConfigModel();
  48. $shop_apply_agreement = $config_model->getShopApplyAgreement();
  49. $data[ 'shop_apply_agreement' ] = $shop_apply_agreement[ 'data' ];
  50. //查询省级数据列表
  51. $address_model = new AddressModel();
  52. $list = $address_model->getAreaList([ [ "pid", "=", 0 ], [ "level", "=", 1 ] ]);
  53. $data[ 'province_list' ] = $list[ "data" ];
  54. //获取申请完整信息
  55. $shop_apply_model = new ShopApplyModel();
  56. $condition[] = [ 'uid', '=', $this->uid ];
  57. $shop_apply_info = $shop_apply_model->getApplyDetail($condition);
  58. if ($shop_apply_info[ 'data' ] == null) {//未填写申请信息
  59. //第一步
  60. $procedure = 1;
  61. } else {//已填写申请信息
  62. //判断审核状态
  63. if ($shop_apply_info[ 'data' ][ 'apply_state' ] == 1) {
  64. $procedure = 2;//审核中
  65. } elseif ($shop_apply_info[ 'data' ][ 'apply_state' ] == 2) {
  66. if ($shop_apply_info[ 'data' ][ 'paying_money_certificate' ] != '') {
  67. $procedure = 3;//财务凭据审核中
  68. } else {
  69. $procedure = 6;//财务凭据提交中
  70. }
  71. } elseif ($shop_apply_info[ 'data' ][ 'apply_state' ] == 3) {
  72. $procedure = 5;//入驻成功
  73. } elseif ($shop_apply_info[ 'data' ][ 'apply_state' ] == -2) {
  74. $procedure = 7;//财务审核失败
  75. } else {
  76. $procedure = 4;//审核失败
  77. }
  78. }
  79. $data[ 'procedure' ] = $procedure;
  80. $data[ 'shop_apply_info' ] = $shop_apply_info[ "data" ];
  81. //收款信息
  82. $receivable_config = $config_model->getSystemBankAccount();
  83. $data[ 'receivable_config' ] = $receivable_config[ 'data' ];
  84. //平台配置信息
  85. $website_model = new WebsiteModel();
  86. $website_info = $website_model->getWebSite([ [ 'site_id', '=', 0 ] ], 'web_phone');
  87. $data[ 'website_info' ] = $website_info[ 'data' ];
  88. //快捷入驻
  89. $account_model = new ShopaccountModel();
  90. $config_info = $account_model->getShopWithdrawConfig();
  91. if (empty($config_info[ 'data' ])) {
  92. $id_experience = 0;
  93. } else {
  94. $id_experience = $config_info[ 'data' ][ 'value' ][ 'id_experience' ];
  95. }
  96. $data[ 'id_experience' ] = $id_experience;
  97. $promotion_model = new PromotionModel();
  98. //插件
  99. $promotions = $promotion_model->getPromotions();
  100. $promotions = $promotions[ 'shop' ];
  101. //店铺等级
  102. $shop_group_model = new ShopGroupModel();
  103. $shop_group = $shop_group_model->getGroupList([ [ 'is_own', '=', 0 ] ], '*', 'fee asc')[ 'data' ];
  104. foreach ($shop_group as $k => $v) {
  105. $addon_array = !empty($v[ 'addon_array' ]) ? explode(',', $v[ 'addon_array' ]) : [];
  106. foreach ($promotions as $key => &$promotion) {
  107. if (!empty($promotion[ 'is_developing' ])) {
  108. unset($promotions[ $key ]);
  109. continue;
  110. }
  111. $promotion[ 'is_checked' ] = 0;
  112. if (in_array($promotion[ 'name' ], $addon_array)) {
  113. $promotion[ 'is_checked' ] = 1;
  114. }
  115. $shop_group[ $k ][ 'promotion' ][] = $promotion;
  116. }
  117. array_multisort(array_column($shop_group[ $k ][ 'promotion' ], 'is_checked'), SORT_DESC, $shop_group[ $k ][ 'promotion' ]);
  118. }
  119. $data[ 'group_info' ] = $shop_group;
  120. //城市分站
  121. $is_city_addon = addon_is_exit('city');
  122. $data[ 'is_city' ] = $is_city_addon;
  123. if ($is_city_addon == 1) {
  124. //获取城市分站信息
  125. $city = $website_model->getWebsiteList([ [ 'site_id ', '>=', 0 ], [ 'status', '=', 1 ] ], 'site_id,site_area_id,site_area_name');
  126. $data[ 'web_city' ] = $city[ 'data' ];
  127. } else {
  128. $data[ 'web_city' ] = [];
  129. }
  130. $data[ 'support_transfer_type' ] = $this->getTransferType();
  131. return $this->response($this->success($data));
  132. }
  133. public function groupInfo()
  134. {
  135. $promotion_model = new PromotionModel();
  136. //插件
  137. $promotions = $promotion_model->getPromotions();
  138. $promotions = $promotions[ 'shop' ];
  139. //店铺等级
  140. $shop_group_model = new ShopGroupModel();
  141. $shop_group = $shop_group_model->getGroupList([ [ 'is_own', '=', 0 ] ], '*', 'fee asc')[ 'data' ];
  142. foreach ($shop_group as $k => $v) {
  143. $addon_array = !empty($v[ 'addon_array' ]) ? explode(',', $v[ 'addon_array' ]) : [];
  144. foreach ($promotions as $key => &$promotion) {
  145. if (!empty($promotion[ 'is_developing' ])) {
  146. unset($promotions[ $key ]);
  147. continue;
  148. }
  149. $promotion[ 'is_checked' ] = 0;
  150. if (in_array($promotion[ 'name' ], $addon_array)) {
  151. $promotion[ 'is_checked' ] = 1;
  152. }
  153. $shop_group[ $k ][ 'promotion' ][] = $promotion;
  154. }
  155. array_multisort(array_column($shop_group[ $k ][ 'promotion' ], 'is_checked'), SORT_DESC, $shop_group[ $k ][ 'promotion' ]);
  156. }
  157. return $this->response($this->success($shop_group));
  158. }
  159. /*
  160. * 申请入驻
  161. * */
  162. public function apply()
  163. {
  164. //申请信息
  165. $apply_data = [
  166. 'site_id' => isset($this->params[ 'site_id' ]) ? $this->params[ 'site_id' ] : 0,
  167. 'website_id' => isset($this->params[ 'website_id' ]) ? $this->params[ 'website_id' ] : 0,
  168. 'uid' => $this->uid,//用户ID
  169. 'username' => $this->user_info[ 'username' ],//账户
  170. 'shop_name' => isset($this->params[ 'shop_name' ]) ? $this->params[ 'shop_name' ] : '',//申请店铺名称
  171. 'apply_state' => 1,//审核状态(待审核)
  172. 'apply_year' => isset($this->params[ 'apply_year' ]) ? $this->params[ 'apply_year' ] : '',//入驻年长
  173. 'category_name' => isset($this->params[ 'category_name' ]) ? $this->params[ 'category_name' ] : '',//店铺分类名称
  174. 'category_id' => isset($this->params[ 'category_id' ]) ? $this->params[ 'category_id' ] : '',//店铺分类id
  175. 'group_name' => isset($this->params[ 'group_name' ]) ? $this->params[ 'group_name' ] : '',//开店套餐名称
  176. 'group_id' => isset($this->params[ 'group_id' ]) ? $this->params[ 'group_id' ] : ''// 开店套餐ID
  177. ];
  178. //认证信息
  179. $cert_type = isset($this->params[ 'cert_type' ]) ? $this->params[ 'cert_type' ] : '';//申请类型
  180. if ($cert_type == 1) {
  181. //个人
  182. $cert_data = [
  183. 'cert_type' => $cert_type,
  184. 'contacts_name' => isset($this->params[ 'contacts_name' ]) ? $this->params[ 'contacts_name' ] : '',//联系人姓名
  185. 'contacts_mobile' => isset($this->params[ 'contacts_mobile' ]) ? $this->params[ 'contacts_mobile' ] : '',//联系人手机
  186. 'contacts_card_no' => isset($this->params[ 'contacts_card_no' ]) ? $this->params[ 'contacts_card_no' ] : '',//联系人身份证
  187. 'contacts_card_electronic_2' => isset($this->params[ 'contacts_card_electronic_2' ]) ? $this->params[ 'contacts_card_electronic_2' ] : '',//申请人手持身份证正面
  188. 'contacts_card_electronic_3' => isset($this->params[ 'contacts_card_electronic_3' ]) ? $this->params[ 'contacts_card_electronic_3' ] : '',//申请人手持身份证反面
  189. 'bank_account_name' => isset($this->params[ 'bank_account_name' ]) ? $this->params[ 'bank_account_name' ] : '',//银行开户名
  190. 'bank_account_number' => isset($this->params[ 'bank_account_number' ]) ? $this->params[ 'bank_account_number' ] : '',//公司银行账号
  191. 'bank_name' => isset($this->params[ 'bank_name' ]) ? $this->params[ 'bank_name' ] : '',//联系人姓名
  192. 'bank_address' => isset($this->params[ 'bank_address' ]) ? $this->params[ 'bank_address' ] : '',//开户银行所在地
  193. 'bank_code' => isset($this->params[ 'bank_code' ]) ? $this->params[ 'bank_code' ] : '',//支行联行号
  194. 'bank_type' => isset($this->params[ 'bank_type' ]) ? $this->params[ 'bank_type' ] : '',//结算账户类型
  195. 'settlement_bank_account_name' => isset($this->params[ 'settlement_bank_account_name' ]) ? $this->params[ 'settlement_bank_account_name' ] : '',
  196. 'settlement_bank_account_number' => isset($this->params[ 'settlement_bank_account_number' ]) ? $this->params[ 'settlement_bank_account_number' ] : '',
  197. 'settlement_bank_name' => isset($this->params[ 'settlement_bank_name' ]) ? $this->params[ 'settlement_bank_name' ] : '',//结算开户银行支行名称
  198. 'settlement_bank_address' => isset($this->params[ 'settlement_bank_address' ]) ? $this->params[ 'settlement_bank_address' ] : ''//结算开户银行所在地
  199. ];
  200. } else {
  201. //公司
  202. $cert_data = [
  203. 'cert_type' => $cert_type,
  204. 'company_name' => isset($this->params[ 'company_name' ]) ? $this->params[ 'company_name' ] : '',//公司名称
  205. 'company_province_id' => isset($this->params[ 'company_province_id' ]) ? $this->params[ 'company_province_id' ] : '',//公司所在省
  206. 'company_city_id' => isset($this->params[ 'company_city_id' ]) ? $this->params[ 'company_city_id' ] : '',//公司所在市
  207. 'company_district_id' => isset($this->params[ 'company_district_id' ]) ? $this->params[ 'company_district_id' ] : '',//公司所在区/县
  208. 'company_address' => isset($this->params[ 'company_address' ]) ? $this->params[ 'company_address' ] : '',//公司地址
  209. 'company_full_address' => isset($this->params[ 'company_full_address' ]) ? $this->params[ 'company_full_address' ] : '',//公司完整地址
  210. 'business_licence_number' => isset($this->params[ 'business_licence_number' ]) ? $this->params[ 'business_licence_number' ] : '',//统一社会信用码
  211. 'business_licence_number_electronic' => isset($this->params[ 'business_licence_number_electronic' ]) ? $this->params[ 'business_licence_number_electronic' ] : '',//营业执照电子版
  212. 'business_sphere' => isset($this->params[ 'business_sphere' ]) ? $this->params[ 'business_sphere' ] : '',//法定经营范围
  213. 'contacts_name' => isset($this->params[ 'contacts_name' ]) ? $this->params[ 'contacts_name' ] : '',//联系人姓名
  214. 'contacts_mobile' => isset($this->params[ 'contacts_mobile' ]) ? $this->params[ 'contacts_mobile' ] : '',//联系人手机
  215. 'contacts_card_no' => isset($this->params[ 'contacts_card_no' ]) ? $this->params[ 'contacts_card_no' ] : '',//联系人身份证
  216. 'contacts_card_electronic_2' => isset($this->params[ 'contacts_card_electronic_2' ]) ? $this->params[ 'contacts_card_electronic_2' ] : '',//申请人手持身份证正面
  217. 'contacts_card_electronic_3' => isset($this->params[ 'contacts_card_electronic_3' ]) ? $this->params[ 'contacts_card_electronic_3' ] : '',//申请人手持身份证反面
  218. 'bank_account_name' => isset($this->params[ 'bank_account_name' ]) ? $this->params[ 'bank_account_name' ] : '',//银行开户名
  219. 'bank_account_number' => isset($this->params[ 'bank_account_number' ]) ? $this->params[ 'bank_account_number' ] : '',//公司银行账号
  220. 'bank_name' => isset($this->params[ 'bank_name' ]) ? $this->params[ 'bank_name' ] : '',//联系人姓名
  221. 'bank_address' => isset($this->params[ 'bank_address' ]) ? $this->params[ 'bank_address' ] : '',//开户银行所在地
  222. 'bank_code' => isset($this->params[ 'bank_code' ]) ? $this->params[ 'bank_code' ] : '',//支行联行号
  223. 'bank_type' => isset($this->params[ 'bank_type' ]) ? $this->params[ 'bank_type' ] : '',//结算账户类型
  224. 'settlement_bank_account_name' => isset($this->params[ 'settlement_bank_account_name' ]) ? $this->params[ 'settlement_bank_account_name' ] : '',
  225. 'settlement_bank_account_number' => isset($this->params[ 'settlement_bank_account_number' ]) ? $this->params[ 'settlement_bank_account_number' ] : '',
  226. 'settlement_bank_name' => isset($this->params[ 'settlement_bank_name' ]) ? $this->params[ 'settlement_bank_name' ] : '',//结算开户银行支行名称
  227. 'settlement_bank_address' => isset($this->params[ 'settlement_bank_address' ]) ? $this->params[ 'settlement_bank_address' ] : ''//结算开户银行所在地
  228. ];
  229. }
  230. $model = new ShopApplyModel();
  231. $result = $model->apply($apply_data, $cert_data);
  232. return $this->response($result);
  233. }
  234. /**
  235. * 判断店铺名称是否存在
  236. */
  237. public function shopNameExist()
  238. {
  239. $shop_name = isset($this->params[ 'shop_name' ]) ? $this->params[ 'shop_name' ] : '';
  240. $model = new ShopApplyModel();
  241. $res = $model->shopNameExist($shop_name);
  242. return $this->response($res);
  243. }
  244. /*
  245. * 获取申请金额
  246. * */
  247. public function getApplyMoney()
  248. {
  249. $apply_year = isset($this->params[ 'apply_year' ]) ? $this->params[ 'apply_year' ] : '';//入驻年长
  250. $category_id = isset($this->params[ 'category_id' ]) ? $this->params[ 'category_id' ] : '';//店铺分类id
  251. $group_id = isset($this->params[ 'group_id' ]) ? $this->params[ 'group_id' ] : '';//店铺等级ID
  252. $model = new ShopApplyModel();
  253. $result = $model->getApplyMoney($apply_year, $group_id, $category_id);
  254. return $this->response($result);
  255. }
  256. /*
  257. * 提交支付凭证
  258. **/
  259. public function editApply()
  260. {
  261. //申请信息
  262. $apply_data = [
  263. 'paying_money_certificate' => isset($this->params[ 'paying_money_certificate' ]) ? $this->params[ 'paying_money_certificate' ] : '',// 付款凭证
  264. 'paying_money_certificate_explain' => isset($this->params[ 'paying_money_certificate_explain' ]) ? $this->params[ 'paying_money_certificate_explain' ] : '',// 付款凭证说明
  265. 'apply_state' => 2
  266. ];
  267. $model = new ShopApplyModel();
  268. $condition[] = [ 'uid', '=', $this->uid ];
  269. $result = $model->editApply($apply_data, $condition);
  270. return $this->response($result);
  271. }
  272. /**
  273. * 体验入驻
  274. */
  275. public function experienceApply()
  276. {
  277. $shop_data = [
  278. 'site_name' => isset($this->params[ 'site_name' ]) ? $this->params[ 'site_name' ] : '', //店铺名称
  279. 'category_id' => isset($this->params[ 'category_id' ]) ? $this->params[ 'category_id' ] : '', //主营行业id
  280. 'category_name' => isset($this->params[ 'category_name' ]) ? $this->params[ 'category_name' ] : '', //主营行业名称
  281. 'website_id' => isset($this->params[ 'website_id' ]) ? $this->params[ 'website_id' ] : '',
  282. ];
  283. $model = new ShopApply();
  284. $res = $model->experienceApply($shop_data, $this->user_info);
  285. return $this->response($res);
  286. }
  287. /**
  288. * 判断结算类型
  289. */
  290. public function getTransferType()
  291. {
  292. $support_type = [];
  293. if (addon_is_exit("shopwithdraw")) {
  294. $config_model = new ShopWithdrawConfig();
  295. $config_result = $config_model->getConfig();
  296. $config = $config_result[ "data" ];
  297. if ($config[ "is_use" ]) {
  298. $support_type = explode(",", $config[ 'value' ][ "transfer_type" ]);
  299. } else {
  300. $support_type = [ "alipay", "bank" ];
  301. }
  302. } else {
  303. $support_type = [ "alipay", "bank" ];
  304. }
  305. return $this->response($support_type);
  306. }
  307. /**
  308. * 模拟登陆
  309. */
  310. public function simulatedLogin()
  311. {
  312. $user_model = new UserModel;
  313. $res = $user_model->simulatedLogin($this->user_info[ 'username' ], 'shop', 'shopapi');
  314. if ($res[ 'code' ] >= 0) {
  315. $token = $this->createToken($res[ 'data' ]);
  316. return $this->response($this->success([ 'token' => $token, 'site_id' => $res[ 'data' ][ 'site_id' ] ]));
  317. }
  318. return $this->response($res);
  319. }
  320. /**
  321. * 店铺绑定openid 二维码
  322. */
  323. public function shopBindQrcode()
  324. {
  325. $key = 'bing_shop_openid_' . md5(uniqid(null, true));
  326. $url = addon_url("wechat://api/auth/shopBindOpenid", [ "key" => $key ]);
  327. Session::set("bing_shop_openid", $key);
  328. Cache::tag("bing_shop_openid")->set($key, [], 600);
  329. $file_path = qrcode($url, "upload/qrcode/", date("Ymd") . 'qrcode');
  330. $file = $file_path;
  331. if ($fp = fopen($file, "rb", 0)) {
  332. $gambar = fread($fp, filesize($file_path));
  333. fclose($fp);
  334. $base64 = "data:image/jpg/png/gif;base64," . chunk_split(base64_encode($gambar));
  335. @unlink($file_path);
  336. $data = [
  337. 'key' => $key,
  338. 'qrcode' => $base64
  339. ];
  340. return $this->response($this->success($data));
  341. } else {
  342. return $this->response($this->error());
  343. }
  344. }
  345. /**
  346. * 验证店铺绑定情况(成功返回openid)
  347. */
  348. public function checkShopBind()
  349. {
  350. $key = isset($this->params[ 'key' ]) ? $this->params[ 'key' ] : '';
  351. $data = Cache::get($key);
  352. $shop_apply_model = new ShopApplyModel();
  353. if (!isset($data)) {
  354. return $this->response($shop_apply_model->error([ "is_expire" => 1 ], "二维码已过期"));
  355. }
  356. if (empty($data)) {
  357. return $this->response($shop_apply_model->error([ "is_expire" => 0 ], "二维码还没有被扫描"));
  358. }
  359. return $this->response($shop_apply_model->success($data));
  360. }
  361. /**
  362. * 获取店铺设置
  363. * @return false|string
  364. */
  365. public function getShopWithdrawConfig()
  366. {
  367. $account_model = new ShopaccountModel();
  368. $config_info = $account_model->getShopWithdrawConfig();
  369. return $this->response($this->success($config_info[ 'data' ][ 'value' ]));
  370. }
  371. }