Sellerjoinin.php 18 KB

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