Recharge.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. use think\facade\Db;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 充值控制器
  11. */
  12. class Recharge extends MobileMember
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize();
  17. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/predeposit.lang.php');
  18. }
  19. /**
  20. * @api {POST} api/Recharge/index 新增充值信息
  21. * @apiVersion 1.0.0
  22. * @apiGroup Recharge
  23. *
  24. * @apiHeader {String} X-DS-KEY 用户授权token
  25. *
  26. * @apiParam {Float} pdr_amount 充值金额
  27. *
  28. * @apiSuccess {String} code 返回码,10000为成功
  29. * @apiSuccess {String} message 返回消息
  30. * @apiSuccess {Object} result 返回数据
  31. * @apiSuccess {String} result.pay_sn 支付单号
  32. */
  33. public function index()
  34. {
  35. $pdr_amount = abs(floatval(input('post.pdr_amount')));
  36. if ($pdr_amount <= 0) {
  37. ds_json_encode(10001, lang('param_error'));
  38. } else {
  39. $predeposit_model = model('predeposit');
  40. $data = array();
  41. $data['pdr_sn'] = $pay_sn = makePaySn($this->member_info['member_id']);
  42. $data['pdr_member_id'] = $this->member_info['member_id'];
  43. $data['pdr_member_name'] = $this->member_info['member_name'];
  44. $data['pdr_amount'] = $pdr_amount;
  45. $data['pdr_addtime'] = TIMESTAMP;
  46. $insert = $predeposit_model->addPdRecharge($data);
  47. if ($insert) {
  48. ds_json_encode(10000, '', array('pay_sn' => $pay_sn));
  49. } else {
  50. ds_json_encode(10001, lang('ds_common_op_fail'));
  51. }
  52. }
  53. }
  54. /**
  55. * @api {POST} api/Recharge/pd_cash_add 申请提现
  56. * @apiVersion 1.0.0
  57. * @apiGroup Recharge
  58. *
  59. * @apiHeader {String} X-DS-KEY 用户授权token
  60. *
  61. * @apiParam {String} pdc_bank_name 银行名称
  62. * @apiParam {String} pdc_bank_no 银行卡号
  63. * @apiParam {String} pdc_bank_user 银行用户名
  64. * @apiParam {String} password 支付密码
  65. * @apiParam {Float} pdc_amount 提现金额
  66. *
  67. * @apiSuccess {String} code 返回码,10000为成功
  68. * @apiSuccess {String} message 返回消息
  69. * @apiSuccess {Object} result 返回数据
  70. */
  71. public function pd_cash_add()
  72. {
  73. $pdc_amount = abs(floatval(input('post.pdc_amount')));
  74. $memberbank_id = intval(input('param.memberbank_id'));
  75. if ($memberbank_id > 0) {
  76. $memberbank = model('memberbank')->getMemberbankInfo(array('member_id' => session('member_id'), 'memberbank_id' => $memberbank_id));
  77. if (empty($memberbank)) {
  78. ds_json_encode(10001, lang('param_error'));
  79. }
  80. $pdc_bank_type = $memberbank['memberbank_type'];
  81. $pdc_bank_name = $memberbank['memberbank_type'] == 'alipay' ? lang('pay_method_alipay') : $memberbank['memberbank_name'];
  82. $pdc_bank_no = $memberbank['memberbank_no'];
  83. $pdc_bank_user = $memberbank['memberbank_truename'];
  84. } elseif ($memberbank_id == -1) { //使用微信
  85. $member_wxinfo = unserialize($this->member_info['member_wxinfo']);
  86. if (!empty($member_wxinfo) && is_array($member_wxinfo) && isset($member_wxinfo['member_wxopenid']) && $member_wxinfo['member_wxopenid']) {
  87. $pdc_bank_type = 'weixin';
  88. $pdc_bank_name = lang('pay_method_wechat');
  89. $pdc_bank_no = $member_wxinfo['member_wxopenid'];
  90. $pdc_bank_user = $member_wxinfo['nickname'];
  91. } else {
  92. ds_json_encode(10001, lang('param_error'));
  93. }
  94. } else {
  95. ds_json_encode(10001, lang('param_error'));
  96. }
  97. $data = [
  98. 'pdc_amount' => $pdc_amount,
  99. 'pdc_bank_type' => $pdc_bank_type,
  100. 'pdc_bank_name' => $pdc_bank_name,
  101. 'pdc_bank_no' => $pdc_bank_no,
  102. 'pdc_bank_user' => $pdc_bank_user,
  103. 'password' => input('post.password')
  104. ];
  105. $recharge_validate = ds_validate('predeposit');
  106. if (!$recharge_validate->scene('pd_cash_add')->check($data)) {
  107. ds_json_encode(10001, $recharge_validate->getError());
  108. }
  109. $predeposit_model = model('predeposit');
  110. $member_model = model('member');
  111. $memberinfo = $member_model->getMemberInfoByID($this->member_info['member_id']);
  112. //验证支付密码
  113. if (md5(input('post.password')) != $memberinfo['member_paypwd']) {
  114. ds_json_encode(10001, lang('payment_password_error'));
  115. }
  116. //验证金额是否足够
  117. if (floatval($memberinfo['available_predeposit']) < $pdc_amount) {
  118. ds_json_encode(10001, lang('predeposit_cash_shortprice_error'));
  119. }
  120. //是否超过提现周期
  121. $last_withdraw = $predeposit_model->getPdcashInfo(array(array('pdc_member_id', '=', $this->member_info['member_id']), array('pdc_payment_state', 'in', [0, 1]), array('pdc_addtime', '>', TIMESTAMP - intval(config('ds_config.member_withdraw_cycle')) * 86400)));
  122. if ($last_withdraw) {
  123. ds_json_encode(10001, lang('predeposit_last_withdraw_time_error') . date('Y-m-d', $last_withdraw['pdc_addtime'] + (intval(config('ds_config.member_withdraw_cycle')) * 86400)));
  124. }
  125. //是否不小于最低提现金额
  126. if ($pdc_amount < floatval(config('ds_config.member_withdraw_min'))) {
  127. ds_json_encode(10001, lang('predeposit_withdraw_min') . config('ds_config.member_withdraw_min') . lang('ds_yuan'));
  128. }
  129. //是否不超过最高提现金额
  130. if ($pdc_amount > floatval(config('ds_config.member_withdraw_max'))) {
  131. ds_json_encode(10001, lang('predeposit_withdraw_max') . config('ds_config.store_withdraw_max') . lang('ds_yuan'));
  132. }
  133. try {
  134. Db::startTrans();
  135. $pdc_sn = makePaySn($memberinfo['member_id']);
  136. $data = array();
  137. $data['pdc_sn'] = $pdc_sn;
  138. $data['pdc_member_id'] = $memberinfo['member_id'];
  139. $data['pdc_member_name'] = $memberinfo['member_name'];
  140. $data['pdc_bank_type'] = $pdc_bank_type;
  141. $data['pdc_amount'] = $pdc_amount;
  142. $data['pdc_bank_name'] = $pdc_bank_name;
  143. $data['pdc_bank_no'] = $pdc_bank_no;
  144. $data['pdc_bank_user'] = $pdc_bank_user;
  145. $data['pdc_addtime'] = TIMESTAMP;
  146. $data['pdc_payment_state'] = 0;
  147. $insert = $predeposit_model->addPdcash($data);
  148. if (!$insert) {
  149. throw new \think\Exception(lang('predeposit_cash_add_fail'), 10006);
  150. }
  151. //冻结可用预存款
  152. $data = array();
  153. $data['member_id'] = $memberinfo['member_id'];
  154. $data['member_name'] = $memberinfo['member_name'];
  155. $data['amount'] = $pdc_amount;
  156. $data['order_sn'] = $pdc_sn;
  157. $predeposit_model->changePd('cash_apply', $data);
  158. Db::commit();
  159. } catch (\Exception $e) {
  160. Db::rollback();
  161. ds_json_encode(10001, $e->getMessage());
  162. }
  163. ds_json_encode(10000, lang('ds_common_op_succ'), array('status' => 'ok'));
  164. }
  165. /**
  166. * @api {POST} api/Recharge/recharge_order 获取充值信息
  167. * @apiVersion 1.0.0
  168. * @apiGroup Recharge
  169. *
  170. * @apiHeader {String} X-DS-KEY 用户授权token
  171. *
  172. * @apiParam {String} paysn 充值单号
  173. *
  174. * @apiSuccess {String} code 返回码,10000为成功
  175. * @apiSuccess {String} message 返回消息
  176. * @apiSuccess {Object} result 返回数据
  177. * @apiSuccess {Object} result.payment_list 返回数据
  178. * @apiSuccess {String} result.payment_list.payment_code 支付方式代码
  179. * @apiSuccess {String} result.payment_list.payment_name 支付方式名称
  180. * @apiSuccess {Object} result.pdinfo 充值信息 (返回字段参考pdrecharge表)
  181. * @apiSuccess {Object} result.base_site_url 域名
  182. */
  183. public function recharge_order()
  184. {
  185. $pay_sn = input('param.paysn');
  186. if (!preg_match('/^\d{20}$/', $pay_sn)) {
  187. ds_json_encode(10001, lang('param_error'));
  188. exit();
  189. }
  190. //查询支付单信息
  191. $predeposit_model = model('predeposit');
  192. $pd_info = $predeposit_model->getPdRechargeInfo(array('pdr_sn' => $pay_sn, 'pdr_member_id' => $this->member_info['member_id']));
  193. if (empty($pd_info)) {
  194. ds_json_encode(10001, lang('recharge_info_not_exist'));
  195. exit();
  196. }
  197. if (intval($pd_info['pdr_payment_state'])) {
  198. ds_json_encode(10001, lang('payment_repeat'));
  199. exit();
  200. }
  201. $payment_model = model('payment');
  202. $condition = array();
  203. $condition[] = array('payment_platform', '=', 'h5');
  204. $payment_list = $payment_model->getPaymentOpenList($condition);
  205. $payment_array = array();
  206. if (!empty($payment_list)) {
  207. foreach ($payment_list as $value) {
  208. $payment_array[] = array('payment_code' => $value['payment_code'], 'payment_name' => $value['payment_name']);
  209. }
  210. } else {
  211. ds_json_encode(10001, lang('predeposit_payment_error'));
  212. exit();
  213. }
  214. unset($pd_info['pdr_payment_code']);
  215. unset($pd_info['pdr_trade_sn']);
  216. unset($pd_info['pdr_payment_state']);
  217. unset($pd_info['pdr_paymenttime']);
  218. unset($pd_info['pdr_admin']);
  219. ds_json_encode(10000, '', array('payment_list' => $payment_array, 'pdinfo' => $pd_info, 'base_site_url' => BASE_SITE_URL));
  220. }
  221. public function member_v()
  222. {
  223. $member_info = array();
  224. $member_info['user_name'] = $this->member_info['member_name'];
  225. $member_info['avator'] = get_member_avatar_for_id($this->member_info['member_id']);
  226. $member_info['point'] = $this->member_info['member_points'];
  227. $member_gradeinfo = model('member')->getOneMemberGrade(intval($this->member_info['member_exppoints']));
  228. $member_info['level_name'] = $member_gradeinfo['level_name'];
  229. $member_info['favorites_store'] = model('favorites')->getStoreFavoritesCountByMemberId($this->member_info['member_id']);
  230. $member_info['favorites_goods'] = model('favorites')->getGoodsFavoritesCountByMemberId($this->member_info['member_id']);
  231. $member_info['member_id'] = $this->member_info['member_id']; //
  232. $member_info['member_id_64'] = base64_encode(intval($this->member_info['member_id']) * 1); //
  233. $list_setting = rkcache('config', true);
  234. $member_info['vip_1fee'] = $list_setting['vip_1fee'];
  235. $member_info['vip_2fee'] = $list_setting['vip_2fee'];
  236. ds_json_encode(10000, '', array('member_info' => $member_info));
  237. }
  238. /**
  239. * 在线升级到会员级别
  240. */
  241. public function recharge_vip1()
  242. {
  243. $pdr_amount = abs(floatval(input('post.pdr_amount')));
  244. $list_setting = rkcache('config', true);
  245. if ($pdr_amount <= 0 || $pdr_amount != abs(floatval($list_setting['vip_1fee']))) {
  246. ds_json_encode(10001, lang('param_error'));
  247. exit();
  248. }
  249. $predeposit_model = model('predeposit');
  250. $data = array();
  251. $data['pdr_sn'] = $pay_sn = makePaySn($this->member_info['member_id']);
  252. $data['pdr_member_id'] = $this->member_info['member_id'];
  253. $data['pdr_member_name'] = $this->member_info['member_name'];
  254. $data['pdr_amount'] = $pdr_amount;
  255. $data['pdr_addtime'] = TIMESTAMP;
  256. $data['pdr_vipid'] = '1';
  257. $insert = $predeposit_model->addVipRecharge($data);
  258. if ($insert) {
  259. ds_json_encode(10000, '', array('pay_sn' => $pay_sn));
  260. } else {
  261. ds_json_encode(10001, lang('ds_common_op_fail'));
  262. }
  263. }
  264. public function recharge_vip2()
  265. {
  266. $pdr_amount = abs(floatval(input('post.pdr_amount')));
  267. $list_setting = rkcache('config', true);
  268. if ($pdr_amount <= 0 || $pdr_amount != abs(floatval($list_setting['vip_2fee']))) {
  269. ds_json_encode(10001, lang('param_error'));
  270. exit();
  271. }
  272. $predeposit_model = model('predeposit');
  273. $data = array();
  274. $data['pdr_sn'] = $pay_sn = makePaySn($this->member_info['member_id']);
  275. $data['pdr_member_id'] = $this->member_info['member_id'];
  276. $data['pdr_member_name'] = $this->member_info['member_name'];
  277. $data['pdr_amount'] = $pdr_amount;
  278. $data['pdr_addtime'] = TIMESTAMP;
  279. $data['pdr_vipid'] = '2';
  280. $insert = $predeposit_model->addVipRecharge($data);
  281. if ($insert) {
  282. ds_json_encode(10000, '', array('pay_sn' => $pay_sn));
  283. } else {
  284. ds_json_encode(10001, lang('ds_common_op_fail'));
  285. }
  286. }
  287. public function viprecharge_order()
  288. {
  289. $pay_sn = input('post.paysn');
  290. if (!preg_match('/^\d{20}$/', $pay_sn)) {
  291. ds_json_encode(10001, lang('param_error'));
  292. exit();
  293. }
  294. //查询支付单信息
  295. $predeposit_model = model('predeposit');
  296. $pd_info = $predeposit_model->getVipRechargeInfo(array('pdr_sn' => $pay_sn, 'pdr_member_id' => $this->member_info['member_id']));
  297. if (empty($pd_info)) {
  298. ds_json_encode(10001, lang('recharge_info_not_exist'));
  299. exit();
  300. }
  301. if (intval($pd_info['pdr_payment_state'])) {
  302. ds_json_encode(10001, lang('payment_repeat'));
  303. exit();
  304. }
  305. $payment_model = model('payment');
  306. $condition = array();
  307. $condition[] = array('payment_platform', '=', 'h5');
  308. $payment_list = $payment_model->getPaymentOpenList($condition);
  309. $payment_array = array();
  310. if (!empty($payment_list)) {
  311. foreach ($payment_list as $value) {
  312. $payment_array[] = array('payment_code' => $value['payment_code'], 'payment_name' => $value['payment_name']);
  313. }
  314. } else {
  315. ds_json_encode(10001, lang('predeposit_payment_error'));
  316. exit();
  317. }
  318. unset($pd_info['pdr_payment_code']);
  319. unset($pd_info['pdr_trade_sn']);
  320. unset($pd_info['pdr_payment_state']);
  321. unset($pd_info['pdr_paymenttime']);
  322. unset($pd_info['pdr_admin']);
  323. ds_json_encode(10000, '', array('payment_list' => $payment_array, 'pdinfo' => $pd_info));
  324. }
  325. }