Recharge.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. use think\facade\Db;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  10. * 网站地址: https://www.valimart.net/
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 充值控制器
  15. */
  16. class Recharge extends MobileMember {
  17. public function initialize() {
  18. parent::initialize();
  19. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/predeposit.lang.php');
  20. }
  21. /**
  22. * @api {POST} api/Recharge/index 新增充值信息
  23. * @apiVersion 1.0.0
  24. * @apiGroup Recharge
  25. *
  26. * @apiHeader {String} X-DS-KEY 用户授权token
  27. *
  28. * @apiParam {Float} pdr_amount 充值金额
  29. *
  30. * @apiSuccess {String} code 返回码,10000为成功
  31. * @apiSuccess {String} message 返回消息
  32. * @apiSuccess {Object} result 返回数据
  33. * @apiSuccess {String} result.pay_sn 支付单号
  34. */
  35. public function index() {
  36. $pdr_amount = abs(floatval(input('post.pdr_amount')));
  37. if ($pdr_amount <= 0) {
  38. ds_json_encode(10001, lang('param_error'));
  39. } else {
  40. $predeposit_model = model('predeposit');
  41. $data = array();
  42. $data['pdr_sn'] = $pay_sn = makePaySn($this->member_info['member_id']);
  43. $data['pdr_member_id'] = $this->member_info['member_id'];
  44. $data['pdr_member_name'] = $this->member_info['member_name'];
  45. $data['pdr_amount'] = $pdr_amount;
  46. $data['pdr_addtime'] = TIMESTAMP;
  47. $insert = $predeposit_model->addPdRecharge($data);
  48. if ($insert) {
  49. ds_json_encode(10000, '', array('pay_sn' => $pay_sn));
  50. } else {
  51. ds_json_encode(10001, lang('ds_common_op_fail'));
  52. }
  53. }
  54. }
  55. /**
  56. * @api {POST} api/Recharge/pd_cash_add 申请提现
  57. * @apiVersion 1.0.0
  58. * @apiGroup Recharge
  59. *
  60. * @apiHeader {String} X-DS-KEY 用户授权token
  61. *
  62. * @apiParam {String} pdc_bank_name 银行名称
  63. * @apiParam {String} pdc_bank_no 银行卡号
  64. * @apiParam {String} pdc_bank_user 银行用户名
  65. * @apiParam {String} password 支付密码
  66. * @apiParam {Float} pdc_amount 提现金额
  67. *
  68. * @apiSuccess {String} code 返回码,10000为成功
  69. * @apiSuccess {String} message 返回消息
  70. * @apiSuccess {Object} result 返回数据
  71. */
  72. public function pd_cash_add() {
  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. $pay_sn = input('param.paysn');
  185. if (!preg_match('/^\d{20}$/', $pay_sn)) {
  186. ds_json_encode(10001, lang('param_error'));
  187. exit();
  188. }
  189. //查询支付单信息
  190. $predeposit_model = model('predeposit');
  191. $pd_info = $predeposit_model->getPdRechargeInfo(array('pdr_sn' => $pay_sn, 'pdr_member_id' => $this->member_info['member_id']));
  192. if (empty($pd_info)) {
  193. ds_json_encode(10001, lang('recharge_info_not_exist'));
  194. exit();
  195. }
  196. if (intval($pd_info['pdr_payment_state'])) {
  197. ds_json_encode(10001, lang('payment_repeat'));
  198. exit();
  199. }
  200. $payment_model = model('payment');
  201. $condition = array();
  202. $condition[] = array('payment_platform','=','h5');
  203. $payment_list = $payment_model->getPaymentOpenList($condition);
  204. $payment_array = array();
  205. if (!empty($payment_list)) {
  206. foreach ($payment_list as $value) {
  207. $payment_array[] = array('payment_code' => $value['payment_code'], 'payment_name' => $value['payment_name']);
  208. }
  209. } else {
  210. ds_json_encode(10001, lang('predeposit_payment_error'));
  211. exit();
  212. }
  213. unset($pd_info['pdr_payment_code']);
  214. unset($pd_info['pdr_trade_sn']);
  215. unset($pd_info['pdr_payment_state']);
  216. unset($pd_info['pdr_paymenttime']);
  217. unset($pd_info['pdr_admin']);
  218. ds_json_encode(10000, '', array('payment_list' => $payment_array, 'pdinfo' => $pd_info, 'base_site_url' => BASE_SITE_URL));
  219. }
  220. public function member_v() {
  221. $member_info = array();
  222. $member_info['user_name'] = $this->member_info['member_name'];
  223. $member_info['avator'] = get_member_avatar_for_id($this->member_info['member_id']);
  224. $member_info['point'] = $this->member_info['member_points'];
  225. $member_gradeinfo = model('member')->getOneMemberGrade(intval($this->member_info['member_exppoints']));
  226. $member_info['level_name'] = $member_gradeinfo['level_name'];
  227. $member_info['favorites_store'] = model('favorites')->getStoreFavoritesCountByMemberId($this->member_info['member_id']);
  228. $member_info['favorites_goods'] = model('favorites')->getGoodsFavoritesCountByMemberId($this->member_info['member_id']);
  229. $member_info['member_id'] = $this->member_info['member_id']; //
  230. $member_info['member_id_64'] = base64_encode(intval($this->member_info['member_id']) * 1); //
  231. $list_setting = rkcache('config', true);
  232. $member_info['vip_1fee'] = $list_setting['vip_1fee'];
  233. $member_info['vip_2fee'] = $list_setting['vip_2fee'];
  234. ds_json_encode(10000, '', array('member_info' => $member_info));
  235. }
  236. /**
  237. * 在线升级到会员级别
  238. */
  239. public function recharge_vip1() {
  240. $pdr_amount = abs(floatval(input('post.pdr_amount')));
  241. $list_setting = rkcache('config', true);
  242. if ($pdr_amount <= 0 || $pdr_amount != abs(floatval($list_setting['vip_1fee']))) {
  243. ds_json_encode(10001, lang('param_error'));
  244. exit();
  245. }
  246. $predeposit_model = model('predeposit');
  247. $data = array();
  248. $data['pdr_sn'] = $pay_sn = makePaySn($this->member_info['member_id']);
  249. $data['pdr_member_id'] = $this->member_info['member_id'];
  250. $data['pdr_member_name'] = $this->member_info['member_name'];
  251. $data['pdr_amount'] = $pdr_amount;
  252. $data['pdr_addtime'] = TIMESTAMP;
  253. $data['pdr_vipid'] = '1';
  254. $insert = $predeposit_model->addVipRecharge($data);
  255. if ($insert) {
  256. ds_json_encode(10000, '', array('pay_sn' => $pay_sn));
  257. } else {
  258. ds_json_encode(10001, lang('ds_common_op_fail'));
  259. }
  260. }
  261. public function recharge_vip2() {
  262. $pdr_amount = abs(floatval(input('post.pdr_amount')));
  263. $list_setting = rkcache('config', true);
  264. if ($pdr_amount <= 0 || $pdr_amount != abs(floatval($list_setting['vip_2fee']))) {
  265. ds_json_encode(10001, lang('param_error'));
  266. exit();
  267. }
  268. $predeposit_model = model('predeposit');
  269. $data = array();
  270. $data['pdr_sn'] = $pay_sn = makePaySn($this->member_info['member_id']);
  271. $data['pdr_member_id'] = $this->member_info['member_id'];
  272. $data['pdr_member_name'] = $this->member_info['member_name'];
  273. $data['pdr_amount'] = $pdr_amount;
  274. $data['pdr_addtime'] = TIMESTAMP;
  275. $data['pdr_vipid'] = '2';
  276. $insert = $predeposit_model->addVipRecharge($data);
  277. if ($insert) {
  278. ds_json_encode(10000, '', array('pay_sn' => $pay_sn));
  279. } else {
  280. ds_json_encode(10001, lang('ds_common_op_fail'));
  281. }
  282. }
  283. public function viprecharge_order() {
  284. $pay_sn = input('post.paysn');
  285. if (!preg_match('/^\d{20}$/', $pay_sn)) {
  286. ds_json_encode(10001, lang('param_error'));
  287. exit();
  288. }
  289. //查询支付单信息
  290. $predeposit_model = model('predeposit');
  291. $pd_info = $predeposit_model->getVipRechargeInfo(array('pdr_sn' => $pay_sn, 'pdr_member_id' => $this->member_info['member_id']));
  292. if (empty($pd_info)) {
  293. ds_json_encode(10001, lang('recharge_info_not_exist'));
  294. exit();
  295. }
  296. if (intval($pd_info['pdr_payment_state'])) {
  297. ds_json_encode(10001, lang('payment_repeat'));
  298. exit();
  299. }
  300. $payment_model = model('payment');
  301. $condition = array();
  302. $condition[] = array('payment_platform','=','h5');
  303. $payment_list = $payment_model->getPaymentOpenList($condition);
  304. $payment_array = array();
  305. if (!empty($payment_list)) {
  306. foreach ($payment_list as $value) {
  307. $payment_array[] = array('payment_code' => $value['payment_code'], 'payment_name' => $value['payment_name']);
  308. }
  309. } else {
  310. ds_json_encode(10001, lang('predeposit_payment_error'));
  311. exit();
  312. }
  313. unset($pd_info['pdr_payment_code']);
  314. unset($pd_info['pdr_trade_sn']);
  315. unset($pd_info['pdr_payment_state']);
  316. unset($pd_info['pdr_paymenttime']);
  317. unset($pd_info['pdr_admin']);
  318. ds_json_encode(10000, '', array('payment_list' => $payment_array, 'pdinfo' => $pd_info));
  319. }
  320. }
  321. ?>