Recharge.php 15 KB

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