Sellerjoinin.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 控制器
  10. */
  11. class Sellerjoinin extends MobileMember
  12. {
  13. private $joinin_detail = NULL;
  14. public function initialize()
  15. {
  16. parent::initialize();
  17. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerjoinin.lang.php');
  18. $storejoinin_model = model('storejoinin');
  19. $this->joinin_detail = $storejoinin_model->getOneStorejoinin(array('member_id' => $this->member_info['member_id']));
  20. $store_joinin_open = config('ds_config.store_joinin_open');
  21. if (!$this->joinin_detail || !$this->joinin_detail['joinin_state']) { //已经填写过入驻资料的则不跳转
  22. if ($store_joinin_open == 0) {
  23. ds_json_encode(10001, lang('store_joinin_close'));
  24. }
  25. }
  26. }
  27. /**
  28. * @api {POST} api/Sellerjoinin/get_info 获取入驻信息
  29. * @apiVersion 1.0.0
  30. * @apiGroup Sellerjoinin
  31. *
  32. * @apiHeader {String} X-DS-KEY 用户授权token
  33. *
  34. *
  35. * @apiSuccess {String} code 返回码,10000为成功
  36. * @apiSuccess {String} message 返回消息
  37. * @apiSuccess {Object} result 返回数据
  38. * @apiSuccess {Object} result.store_joinin 入驻信息(返回数据参考storejoinin表)
  39. */
  40. public function get_info()
  41. {
  42. $storejoinin_model = model('storejoinin');
  43. $joinin_detail = $this->joinin_detail;
  44. if ($joinin_detail) {
  45. $store_class_names = unserialize($joinin_detail['store_class_names']);
  46. $store_class_ids = unserialize($joinin_detail['store_class_ids']);
  47. $joinin_detail['store_class_names'] = $store_class_names ? $store_class_names : array();
  48. $joinin_detail['store_class_ids'] = $store_class_ids ? $store_class_ids : array();
  49. $joinin_detail['store_class_commis_rates'] = explode(',', $joinin_detail['store_class_commis_rates']);
  50. if ($joinin_detail['business_licence_number_electronic']) {
  51. $joinin_detail['business_licence_number_electronic_url'] = get_store_joinin_imageurl($joinin_detail['business_licence_number_electronic']);
  52. }
  53. if (!empty($joinin_detail['sg_info'])) {
  54. $store_grade_info = model('storegrade')->getOneStoregrade($joinin_detail['storegrade_id']);
  55. $joinin_detail['storegrade_price'] = $store_grade_info['storegrade_price'];
  56. } else {
  57. $joinin_detail['sg_info'] = @unserialize($joinin_detail['sg_info']);
  58. if (is_array($joinin_detail['sg_info'])) {
  59. $joinin_detail['storegrade_price'] = $joinin_detail['sg_info']['storegrade_price'];
  60. }
  61. }
  62. if ($joinin_detail['joinin_state'] == STORE_JOIN_STATE_VERIFY_SUCCESS) {
  63. $joinin_detail['member_available_pd'] = $this->member_info['available_predeposit'];
  64. $joinin_detail['member_available_rcb'] = $this->member_info['available_rc_balance'];
  65. $joinin_detail['member_paypwd'] = true;
  66. if (empty($this->member_info['member_paypwd'])) {
  67. $joinin_detail['member_paypwd'] = false;
  68. }
  69. $joinin_detail['pay_amount'] = round($joinin_detail['paying_amount'] - $joinin_detail['pd_amount'] - $joinin_detail['rcb_amount'], 2);
  70. }
  71. }
  72. ds_json_encode(10000, '', array('store_joinin' => $joinin_detail));
  73. }
  74. /**
  75. * @api {POST} api/Sellerjoinin/step2 商家入驻第二步
  76. * @apiVersion 1.0.0
  77. * @apiGroup Sellerjoinin
  78. *
  79. * @apiHeader {String} X-DS-KEY 用户授权token
  80. *
  81. * @apiParam {Int} store_type 入驻类型(0企业1个人)
  82. * @apiParam {String} company_name 公司名
  83. * @apiParam {String} store_longitude 店铺地址纬度
  84. * @apiParam {String} store_latitude 店铺地址经度
  85. * @apiParam {Int} company_province_id 地区id
  86. * @apiParam {String} company_address 公司地区名
  87. * @apiParam {String} company_address_detail 公司地址
  88. * @apiParam {String} company_registered_capital 注册资金
  89. * @apiParam {String} contacts_name 联系人姓名
  90. * @apiParam {String} contacts_phone 联系人电话
  91. * @apiParam {String} contacts_email 联系人邮箱
  92. * @apiParam {String} business_licence_number 营业执照号
  93. * @apiParam {String} business_licence_address 营业执照地区
  94. * @apiParam {String} business_licence_start 营业执照有效期起始
  95. * @apiParam {String} business_licence_end 营业执照有效期结束
  96. * @apiParam {String} business_sphere 营业范围
  97. * @apiParam {String} business_licence_number_electronic 营业执照图片
  98. *
  99. * @apiSuccess {String} code 返回码,10000为成功
  100. * @apiSuccess {String} message 返回消息
  101. * @apiSuccess {Object} result 返回数据
  102. */
  103. public function step2()
  104. {
  105. $param = array();
  106. $param['member_name'] = $this->member_info['member_name'];
  107. $param['store_type'] = input('post.store_type');
  108. $param['company_name'] = input('post.company_name');
  109. $param['store_longitude'] = input('post.store_longitude');
  110. $param['store_latitude'] = input('post.store_latitude');
  111. $param['company_province_id'] = intval(input('post.company_province_id'));
  112. $param['company_address'] = input('post.company_address');
  113. $param['company_address_detail'] = input('post.company_address_detail');
  114. $param['company_registered_capital'] = intval(input('post.company_registered_capital'));
  115. $param['contacts_name'] = input('post.contacts_name');
  116. $param['contacts_phone'] = input('post.contacts_phone');
  117. $param['contacts_email'] = input('post.contacts_email');
  118. $param['business_licence_number'] = input('post.business_licence_number');
  119. $param['business_licence_address'] = input('post.business_licence_address');
  120. $param['business_licence_start'] = input('post.business_licence_start');
  121. $param['business_licence_end'] = input('post.business_licence_end');
  122. $param['business_sphere'] = input('post.business_sphere');
  123. $param['business_licence_number_electronic'] = input('post.business_licence_number_electronic');
  124. $this->step2_save_valid($param);
  125. $storejoinin_model = model('storejoinin');
  126. if (empty($this->joinin_detail)) {
  127. $param['member_id'] = $this->member_info['member_id'];
  128. $storejoinin_model->addStorejoinin($param);
  129. } else {
  130. $storejoinin_model->editStorejoinin($param, array('member_id' => $this->member_info['member_id']));
  131. }
  132. ds_json_encode(10000);
  133. }
  134. private function step2_save_valid($param)
  135. {
  136. $sellerjoinin_validate = ds_validate('sellerjoinin');
  137. if (!$sellerjoinin_validate->scene(input('post.store_type') ? 'step2_save_valid2' : 'step2_save_valid')->check($param)) {
  138. ds_json_encode(10001, $sellerjoinin_validate->getError());
  139. }
  140. }
  141. /**
  142. * @api {POST} api/Sellerjoinin/step3 商家入驻第三步
  143. * @apiVersion 1.0.0
  144. * @apiGroup Sellerjoinin
  145. *
  146. * @apiHeader {String} X-DS-KEY 用户授权token
  147. *
  148. * @apiParam {Int} store_type 入驻类型(0企业1个人)
  149. * @apiParam {String} settlement_bank_account_name 结算银行账户名
  150. * @apiParam {Int} settlement_bank_account_number 结算银行账号
  151. * @apiParam {String} bank_account_name 银行账户名
  152. * @apiParam {String} bank_account_number 银行账号
  153. * @apiParam {String} bank_name 银行名
  154. * @apiParam {String} bank_address 银行地区名
  155. * @apiParam {String} is_settlement_account 是否结算银行同号(0否1是)
  156. * @apiParam {String} settlement_bank_name 结算银行名
  157. * @apiParam {String} settlement_bank_address 结算银行地区名
  158. *
  159. * @apiSuccess {String} code 返回码,10000为成功
  160. * @apiSuccess {String} message 返回消息
  161. * @apiSuccess {Object} result 返回数据
  162. */
  163. public function step3()
  164. {
  165. $param = array();
  166. if (input('post.store_type')) {
  167. $param['settlement_bank_account_name'] = input('post.settlement_bank_account_name');
  168. $param['settlement_bank_account_number'] = input('post.settlement_bank_account_number');
  169. } else {
  170. $param['bank_account_name'] = input('post.bank_account_name');
  171. $param['bank_account_number'] = input('post.bank_account_number');
  172. $param['bank_name'] = input('post.bank_name');
  173. $param['bank_address'] = input('post.bank_address');
  174. $is_settlement_account = input('post.is_settlement_account');
  175. if (!empty($is_settlement_account)) {
  176. $param['is_settlement_account'] = 1;
  177. $param['settlement_bank_account_name'] = input('post.bank_account_name');
  178. $param['settlement_bank_account_number'] = input('post.bank_account_number');
  179. $param['settlement_bank_name'] = input('post.bank_name');
  180. $param['settlement_bank_address'] = input('post.bank_address');
  181. } else {
  182. $param['is_settlement_account'] = 2;
  183. $param['settlement_bank_account_name'] = input('post.settlement_bank_account_name');
  184. $param['settlement_bank_account_number'] = input('post.settlement_bank_account_number');
  185. $param['settlement_bank_name'] = input('post.settlement_bank_name');
  186. $param['settlement_bank_address'] = input('post.settlement_bank_address');
  187. }
  188. }
  189. $this->step3_save_valid($param);
  190. $storejoinin_model = model('storejoinin');
  191. $storejoinin_model->editStorejoinin($param, array('member_id' => $this->member_info['member_id']));
  192. ds_json_encode(10000);
  193. }
  194. private function step3_save_valid($param)
  195. {
  196. $sellerjoinin_validate = ds_validate('sellerjoinin');
  197. if (!$sellerjoinin_validate->scene(input('post.store_type') ? 'step3_save_valid3' : 'step3_save_valid')->check($param)) {
  198. ds_json_encode(10001, $sellerjoinin_validate->getError());
  199. }
  200. }
  201. /**
  202. * @api {POST} api/Sellerjoinin/step4 商家入驻第四步
  203. * @apiVersion 1.0.0
  204. * @apiGroup Sellerjoinin
  205. *
  206. * @apiHeader {String} X-DS-KEY 用户授权token
  207. *
  208. * @apiParam {String} seller_name 账号名
  209. * @apiParam {Int[]} store_class_ids 经营分类id
  210. * @apiParam {String[]} store_class_names 经营分类名
  211. * @apiParam {String} store_name 店铺名
  212. * @apiParam {String} store_type 店铺类型
  213. * @apiParam {Int} joinin_year 入驻年限
  214. * @apiParam {String} storegrade_id 店铺等级
  215. * @apiParam {Int} storeclass_id 店铺分类id
  216. *
  217. * @apiSuccess {String} code 返回码,10000为成功
  218. * @apiSuccess {String} message 返回消息
  219. * @apiSuccess {Object} result 返回数据
  220. */
  221. public function step4()
  222. {
  223. $store_class_ids = array();
  224. $store_class_names = array();
  225. $store_class_ids_array = input('post.store_class_ids/a'); #获取数组
  226. if (!empty($store_class_ids_array)) {
  227. foreach ($store_class_ids_array as $value) {
  228. $store_class_ids[] = $value;
  229. }
  230. }
  231. $store_class_names_array = input('post.store_class_names/a'); #获取数组
  232. if (!empty($store_class_names_array)) {
  233. foreach ($store_class_names_array as $value) {
  234. if (empty($value)) {
  235. continue;
  236. } else {
  237. $store_class_names[] = $value;
  238. }
  239. }
  240. }
  241. //取最小级分类最新分佣比例
  242. $sc_ids = array();
  243. foreach ($store_class_ids as $v) {
  244. $v = explode(',', trim($v, ','));
  245. if (!empty($v) && is_array($v)) {
  246. $sc_ids[] = end($v);
  247. }
  248. }
  249. $store_class_commis_rates = array();
  250. if (!empty($sc_ids)) {
  251. $goods_class_list = model('goodsclass')->getGoodsclassListByIds($sc_ids);
  252. if (!empty($goods_class_list) && is_array($goods_class_list)) {
  253. $sc_ids = array();
  254. foreach ($goods_class_list as $v) {
  255. $store_class_commis_rates[] = $v['commis_rate'];
  256. }
  257. }
  258. }
  259. $param = array();
  260. $param['store_type'] = input('post.store_type');
  261. $param['seller_name'] = $this->member_info['member_name'];
  262. $param['store_name'] = trim(input('post.store_name'));
  263. $param['store_class_ids'] = serialize($store_class_ids);
  264. $param['store_class_names'] = serialize($store_class_names);
  265. $param['joinin_year'] = intval(input('post.joinin_year'));
  266. $param['joinin_state'] = STORE_JOIN_STATE_NEW;
  267. $param['store_class_commis_rates'] = implode(',', $store_class_commis_rates);
  268. //取店铺等级信息
  269. $grade_list = rkcache('storegrade', true);
  270. $storegrade_id = intval(input('post.storegrade_id'));
  271. if ($storegrade_id <= 0) {
  272. ds_json_encode(10001, lang('select_store_level'));
  273. }
  274. if (!empty($grade_list[$storegrade_id])) {
  275. $param['storegrade_id'] = $storegrade_id;
  276. $param['storegrade_name'] = $grade_list[$storegrade_id]['storegrade_name'];
  277. $param['sg_info'] = serialize(array('storegrade_price' => $grade_list[$storegrade_id]['storegrade_price']));
  278. }
  279. //取最新店铺分类信息
  280. $storeclass_id = intval(input('post.storeclass_id'));
  281. if ($storeclass_id <= 0) {
  282. ds_json_encode(10001, lang('select_store_category'));
  283. }
  284. $store_class_info = model('storeclass')->getStoreclassInfo(array('storeclass_id' => $storeclass_id));
  285. if ($store_class_info) {
  286. $param['storeclass_id'] = $store_class_info['storeclass_id'];
  287. $param['storeclass_name'] = $store_class_info['storeclass_name'];
  288. $param['storeclass_bail'] = $store_class_info['storeclass_bail'];
  289. }
  290. //店铺应付款
  291. $param['paying_amount'] = floatval($grade_list[$storegrade_id]['storegrade_price']) * $param['joinin_year'] + floatval($param['storeclass_bail']);
  292. $this->step4_save_valid($param);
  293. $storejoinin_model = model('storejoinin');
  294. $storejoinin_model->editStorejoinin($param, array('member_id' => $this->member_info['member_id']));
  295. ds_json_encode(10000);
  296. }
  297. private function step4_save_valid($param)
  298. {
  299. $sellerjoinin_validate = ds_validate('sellerjoinin');
  300. if (!$sellerjoinin_validate->scene(input('post.store_type') ? 'step4_save_valid4' : 'step4_save_valid')->check($param)) {
  301. ds_json_encode(10001, $sellerjoinin_validate->getError());
  302. }
  303. }
  304. /**
  305. * @api {POST} api/Sellerjoinin/pay_save 保存付款凭证
  306. * @apiVersion 1.0.0
  307. * @apiGroup Sellerjoinin
  308. *
  309. * @apiHeader {String} X-DS-KEY 用户授权token
  310. *
  311. * @apiParam {String} paying_money_certificate 付款截图
  312. * @apiParam {String} paying_money_certificate_explain 付款备注
  313. *
  314. * @apiSuccess {String} code 返回码,10000为成功
  315. * @apiSuccess {String} message 返回消息
  316. * @apiSuccess {Object} result 返回数据
  317. */
  318. public function pay_save()
  319. {
  320. $param = array();
  321. $param['paying_money_certificate'] = input('post.paying_money_certificate');
  322. $param['paying_money_certificate_explain'] = input('post.paying_money_certificate_explain');
  323. $param['joinin_state'] = STORE_JOIN_STATE_PAY;
  324. if (empty($param['paying_money_certificate'])) {
  325. ds_json_encode(10001, lang('paying_money_certificate_empty'));
  326. }
  327. $storejoinin_model = model('storejoinin');
  328. $storejoinin_model->editStorejoinin($param, array('member_id' => $this->member_info['member_id']));
  329. ds_json_encode(10000);
  330. }
  331. /**
  332. * @api {POST} api/Sellerjoinin/upload_image 上传图片
  333. * @apiVersion 1.0.0
  334. * @apiGroup Sellerjoinin
  335. *
  336. * @apiHeader {String} X-DS-KEY 用户授权token
  337. *
  338. * @apiParam {File} file 图片
  339. *
  340. * @apiSuccess {String} code 返回码,10000为成功
  341. * @apiSuccess {String} message 返回消息
  342. * @apiSuccess {Object} result 返回数据
  343. *
  344. */
  345. public function upload_image()
  346. {
  347. $file = 'file';
  348. //上传文件保存路径
  349. $pic_name = '';
  350. if (!empty($_FILES[$file]['name'])) {
  351. //设置特殊图片名称
  352. $file_name = $this->member_info['member_id'] . '_' . date('YmdHis') . rand(10000, 99999) . '.png';
  353. $res = ds_upload_pic('home' . DIRECTORY_SEPARATOR . 'store_joinin', $file, $file_name);
  354. if ($res['code']) {
  355. $pic_name = $res['data']['file_name'];
  356. } else {
  357. ds_json_encode(10001, $res['msg']);
  358. }
  359. }
  360. ds_json_encode(10000, '', array('path' => $pic_name, 'url' => get_store_joinin_imageurl($pic_name)));
  361. }
  362. }