Predeposit.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. <?php
  2. /**
  3. * 预存款管理
  4. */
  5. namespace app\home\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. use think\facade\Db;
  9. /**
  10. * ============================================================================
  11. *
  12. * ============================================================================
  13. *
  14. * ----------------------------------------------------------------------------
  15. *
  16. * ============================================================================
  17. * 控制器
  18. */
  19. class Predeposit extends BaseMember
  20. {
  21. public function initialize()
  22. {
  23. parent::initialize();
  24. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/predeposit.lang.php');
  25. }
  26. /**
  27. * 充值添加
  28. */
  29. public function recharge_add()
  30. {
  31. if (!request()->isPost()) {
  32. /* 设置买家当前菜单 */
  33. $this->setMemberCurMenu('predeposit');
  34. /* 设置买家当前栏目 */
  35. $this->setMemberCurItem('recharge_add');
  36. return View::fetch($this->template_dir . 'pd_recharge_add');
  37. } else {
  38. $pdr_amount = abs(floatval(input('post.pdr_amount')));
  39. if ($pdr_amount <= 0) {
  40. $this->error(lang('predeposit_recharge_add_pricemin_error'));
  41. }
  42. $predeposit_model = model('predeposit');
  43. $data = array();
  44. $data['pdr_sn'] = $pay_sn = makePaySn(session('member_id'));
  45. $data['pdr_member_id'] = session('member_id');
  46. $data['pdr_member_name'] = session('member_name');
  47. $data['pdr_amount'] = $pdr_amount;
  48. $data['pdr_addtime'] = TIMESTAMP;
  49. $insert = $predeposit_model->addPdRecharge($data);
  50. if ($insert) {
  51. //转向到商城支付页面
  52. $this->redirect((string)url('Buy/pd_pay', ['pay_sn' => $pay_sn]));
  53. }
  54. }
  55. }
  56. /**
  57. * 平台充值卡
  58. */
  59. public function rechargecard_add()
  60. {
  61. if (!request()->isPost()) {
  62. /* 设置买家当前菜单 */
  63. $this->setMemberCurMenu('predeposit');
  64. /* 设置买家当前栏目 */
  65. $this->setMemberCurItem('rechargecard_add');
  66. return View::fetch($this->template_dir . 'rechargecard_add');
  67. } else {
  68. $sn = (string) input('post.rc_sn');
  69. if (!$sn || strlen($sn) > 50) {
  70. $this->error(lang('platform_recharge_card_number_cannot_empty'));
  71. exit;
  72. }
  73. try {
  74. $res = model('predeposit')->addRechargecard($sn, $this->member_info);
  75. if ($res['message']) {
  76. $this->error($res['message']);
  77. }
  78. } catch (Exception $e) {
  79. $this->error($e->getMessage());
  80. }
  81. $this->success(lang('platform_recharge_card_successfully_used'), (string)url('Predeposit/rcb_log_list'));
  82. }
  83. }
  84. /**
  85. * 充值列表
  86. */
  87. public function index()
  88. {
  89. $condition = array();
  90. $condition[] = array('pdr_member_id', '=', session('member_id'));
  91. $pdr_sn = input('pdr_sn');
  92. if (!empty($pdr_sn)) {
  93. $condition[] = array('pdr_sn', '=', $pdr_sn);
  94. }
  95. $predeposit_model = model('predeposit');
  96. $predeposit_list = $predeposit_model->getPdRechargeList($condition, 10, '*', 'pdr_id desc');
  97. View::assign('predeposit_list', $predeposit_list);
  98. View::assign('show_page', $predeposit_model->page_info->render());
  99. /* 设置买家当前菜单 */
  100. $this->setMemberCurMenu('predeposit');
  101. /* 设置买家当前栏目 */
  102. $this->setMemberCurItem('recharge_list');
  103. return View::fetch($this->template_dir . 'pd_recharge_list');
  104. }
  105. /**
  106. * 查看充值详细
  107. *
  108. */
  109. public function recharge_show()
  110. {
  111. $pdr_id = intval(input('param.id'));
  112. if ($pdr_id <= 0) {
  113. $this->error(lang('predeposit_parameter_error'));
  114. }
  115. $predeposit_model = model('predeposit');
  116. $condition = array();
  117. $condition[] = array('pdr_member_id', '=', session('member_id'));
  118. $condition[] = array('pdr_id', '=', $pdr_id);
  119. $condition[] = array('pdr_payment_state', '=', 1);
  120. $info = $predeposit_model->getPdRechargeInfo($condition);
  121. if (!$info) {
  122. $this->error(lang('predeposit_record_error'));
  123. }
  124. View::assign('info', $info);
  125. /* 设置买家当前菜单 */
  126. $this->setMemberCurMenu('predeposit');
  127. /* 设置买家当前栏目 */
  128. $this->setMemberCurItem('recharge_show');
  129. return View::fetch($this->template_dir . 'recharge_show');
  130. }
  131. /**
  132. * 删除充值记录
  133. *
  134. */
  135. public function recharge_del()
  136. {
  137. $pdr_id = intval(input('param.id'));
  138. if ($pdr_id <= 0) {
  139. ds_json_encode(10001, lang('predeposit_parameter_error'));
  140. }
  141. $predeposit_model = model('predeposit');
  142. $condition = array();
  143. $condition[] = array('pdr_member_id', '=', session('member_id'));
  144. $condition[] = array('pdr_id', '=', $pdr_id);
  145. $condition[] = array('pdr_payment_state', '=', 0);
  146. $result = $predeposit_model->delPdRecharge($condition);
  147. if ($result) {
  148. ds_json_encode(10000, lang('ds_common_del_succ'));
  149. } else {
  150. ds_json_encode(10001, lang('ds_common_del_fail'));
  151. }
  152. }
  153. /**
  154. * 预存款变更日志
  155. */
  156. public function pd_log_list()
  157. {
  158. $condition = array();
  159. $condition[] = array('lg_member_id', '=', session('member_id'));
  160. $predeposit_model = model('predeposit');
  161. $predeposit_list = $predeposit_model->getPdLogList($condition, 10, '*', 'lg_id desc');
  162. View::assign('show_page', $predeposit_model->page_info->render());
  163. View::assign('predeposit_list', $predeposit_list);
  164. /* 设置买家当前菜单 */
  165. $this->setMemberCurMenu('predeposit');
  166. /* 设置买家当前栏目 */
  167. $this->setMemberCurItem('loglist');
  168. return View::fetch($this->template_dir . 'pd_log_list');
  169. }
  170. /**
  171. * 充值卡余额变更日志
  172. */
  173. public function rcb_log_list()
  174. {
  175. $rcblog_model = model('rcblog');
  176. $rcblog_list = $rcblog_model->getRechargecardBalanceLogList(array('member_id' => session('member_id')), 10, 'rcblog_id desc');
  177. /* 设置买家当前菜单 */
  178. $this->setMemberCurMenu('predeposit');
  179. /* 设置买家当前栏目 */
  180. $this->setMemberCurItem('rcb_log_list');
  181. View::assign('show_page', $rcblog_model->page_info->render());
  182. View::assign('rcblog_list', $rcblog_list);
  183. return View::fetch($this->template_dir . 'rcb_log_list');
  184. }
  185. /**
  186. * 申请提现
  187. */
  188. public function pd_cash_add()
  189. {
  190. if (request()->isPost()) {
  191. $pdc_amount = abs(floatval(input('post.pdc_amount')));
  192. $memberbank_id = intval(input('param.memberbank_id'));
  193. if ($memberbank_id > 0) {
  194. $memberbank = model('memberbank')->getMemberbankInfo(array('member_id' => session('member_id'), 'memberbank_id' => $memberbank_id));
  195. if (empty($memberbank)) {
  196. ds_json_encode(10001, lang('param_error'));
  197. }
  198. $pdc_bank_type = $memberbank['memberbank_type'];
  199. $pdc_bank_name = $memberbank['memberbank_type'] == 'alipay' ? lang('pay_method_alipay') : $memberbank['memberbank_name'];
  200. $pdc_bank_no = $memberbank['memberbank_no'];
  201. $pdc_bank_user = $memberbank['memberbank_truename'];
  202. } elseif ($memberbank_id == -1) { //使用微信
  203. $member_wxinfo = unserialize($this->member_info['member_wxinfo']);
  204. if (!empty($member_wxinfo) && is_array($member_wxinfo) && isset($member_wxinfo['member_wxopenid']) && $member_wxinfo['member_wxopenid']) {
  205. $pdc_bank_type = 'weixin';
  206. $pdc_bank_name = lang('pay_method_wechat');
  207. $pdc_bank_no = $member_wxinfo['member_wxopenid'];
  208. $pdc_bank_user = $member_wxinfo['nickname'];
  209. } else {
  210. ds_json_encode(10001, lang('param_error'));
  211. }
  212. } else {
  213. ds_json_encode(10001, lang('param_error'));
  214. }
  215. $data = [
  216. 'pdc_amount' => $pdc_amount,
  217. 'pdc_bank_type' => $pdc_bank_type,
  218. 'pdc_bank_name' => $pdc_bank_name,
  219. 'pdc_bank_no' => $pdc_bank_no,
  220. 'pdc_bank_user' => $pdc_bank_user,
  221. 'password' => input('post.password')
  222. ];
  223. $predeposit_validate = ds_validate('predeposit');
  224. if (!$predeposit_validate->scene('pd_cash_add')->check($data)) {
  225. ds_json_encode(10001, $predeposit_validate->getError());
  226. }
  227. $predeposit_model = model('predeposit');
  228. $member_model = model('member');
  229. $member_info = $member_model->getMemberInfoByID(session('member_id'));
  230. //验证支付密码
  231. if (md5(input('post.password')) != $member_info['member_paypwd']) {
  232. ds_json_encode(10001, lang('payment_password_error'));
  233. }
  234. //验证金额是否足够
  235. if (floatval($member_info['available_predeposit']) < $pdc_amount) {
  236. ds_json_encode(10001, lang('predeposit_cash_shortprice_error'));
  237. }
  238. //是否超过提现周期
  239. $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)));
  240. if ($last_withdraw) {
  241. ds_json_encode(10001, lang('predeposit_last_withdraw_time_error') . date('Y-m-d', $last_withdraw['member_withdraw_cycle']));
  242. }
  243. //是否不小于最低提现金额
  244. if ($pdc_amount < floatval(config('ds_config.member_withdraw_min'))) {
  245. ds_json_encode(10001, lang('predeposit_withdraw_min') . config('ds_config.member_withdraw_min') . lang('ds_yuan'));
  246. }
  247. //是否不超过最高提现金额
  248. if ($pdc_amount > floatval(config('ds_config.member_withdraw_max'))) {
  249. ds_json_encode(10001, lang('predeposit_withdraw_max') . config('ds_config.store_withdraw_max') . lang('ds_yuan'));
  250. }
  251. try {
  252. Db::startTrans();
  253. $pdc_sn = makePaySn(session('member_id'));
  254. $data = array();
  255. $data['pdc_sn'] = $pdc_sn;
  256. $data['pdc_member_id'] = session('member_id');
  257. $data['pdc_member_name'] = session('member_name');
  258. $data['pdc_bank_type'] = $pdc_bank_type;
  259. $data['pdc_amount'] = $pdc_amount;
  260. $data['pdc_bank_name'] = $pdc_bank_name;
  261. $data['pdc_bank_no'] = $pdc_bank_no;
  262. $data['pdc_bank_user'] = $pdc_bank_user;
  263. $data['pdc_addtime'] = TIMESTAMP;
  264. $data['pdc_payment_state'] = 0;
  265. $insert = $predeposit_model->addPdcash($data);
  266. if (!$insert) {
  267. ds_json_encode(10001, lang('predeposit_cash_add_fail'));
  268. }
  269. //冻结可用预存款
  270. $data = array();
  271. $data['member_id'] = $member_info['member_id'];
  272. $data['member_name'] = $member_info['member_name'];
  273. $data['amount'] = $pdc_amount;
  274. $data['order_sn'] = $pdc_sn;
  275. $predeposit_model->changePd('cash_apply', $data);
  276. Db::commit();
  277. ds_json_encode(10000, lang('predeposit_cash_add_success'));
  278. } catch (Exception $e) {
  279. Db::rollback();
  280. ds_json_encode(10001, $e->getMessage());
  281. }
  282. }
  283. }
  284. /**
  285. * 提现列表
  286. */
  287. public function pd_cash_list()
  288. {
  289. $condition = array();
  290. $condition[] = array('pdc_member_id', '=', session('member_id'));
  291. $sn_search = input('post.sn_search');
  292. if (!empty($sn_search)) {
  293. $condition[] = array('pdc_sn', '=', $sn_search);
  294. }
  295. $paystate_search = input('post.paystate_search');
  296. if (isset($paystate_search)) {
  297. $condition[] = array('pdc_payment_state', '=', intval($paystate_search));
  298. }
  299. $pdcash_list = Db::name('pdcash')->where($condition)->order('pdc_id desc')->paginate();
  300. View::assign('pdcash_list', $pdcash_list);
  301. View::assign('show_page', $pdcash_list->render());
  302. /* 设置买家当前菜单 */
  303. $this->setMemberCurMenu('predeposit');
  304. /* 设置买家当前栏目 */
  305. $this->setMemberCurItem('cashlist');
  306. return View::fetch($this->template_dir . 'pd_cash_list');
  307. }
  308. /**
  309. * 提现记录详细
  310. */
  311. public function pd_cash_info()
  312. {
  313. $pdc_id = intval(input('param.id'));
  314. if ($pdc_id <= 0) {
  315. $this->error(lang('predeposit_parameter_error'), 'home/predeposit/pd_cash_list');
  316. }
  317. $predeposit_model = model('predeposit');
  318. $condition = array();
  319. $condition[] = array('pdc_member_id', '=', session('member_id'));
  320. $condition[] = array('pdc_id', '=', $pdc_id);
  321. $info = $predeposit_model->getPdcashInfo($condition);
  322. if (empty($info)) {
  323. $this->error(lang('predeposit_record_error'), 'home/predeposit/pd_cash_list');
  324. }
  325. $this->setMemberCurItem('cashinfo');
  326. $this->setMemberCurMenu('predeposit');
  327. View::assign('info', $info);
  328. return View::fetch($this->template_dir . 'pd_cash_info');
  329. }
  330. /**
  331. * 栏目菜单
  332. */
  333. function getMemberItemList()
  334. {
  335. $item_list = array(
  336. array(
  337. 'name' => 'loglist',
  338. 'text' => lang('detail_list'),
  339. 'url' => (string)url('Predeposit/pd_log_list'),
  340. ),
  341. array(
  342. 'name' => 'recharge_list',
  343. 'text' => lang('prepaid_phone_list'),
  344. 'url' => (string)url('Predeposit/index'),
  345. ),
  346. array(
  347. 'name' => 'cashlist',
  348. 'text' => lang('withdrawal_list'),
  349. 'url' => (string)url('Predeposit/pd_cash_list'),
  350. ),
  351. array(
  352. 'name' => 'rcb_log_list',
  353. 'text' => lang('balance_recharge_card'),
  354. 'url' => (string)url('Predeposit/rcb_log_list'),
  355. ),
  356. );
  357. if (request()->action() == 'rechargeinfo') {
  358. $item_list[] = array(
  359. 'name' => 'rechargeinfo',
  360. 'text' => lang('ds_member_path_predeposit_rechargeinfo'),
  361. 'url' => (string)url('Predeposit/rechargeinfo'),
  362. );
  363. }
  364. if (request()->action() == 'recharge_add') {
  365. $item_list[] = array(
  366. 'name' => 'recharge_add',
  367. 'text' => lang('predeposit_online_recharge'),
  368. 'url' => (string)url('Predeposit/recharge_add'),
  369. );
  370. }
  371. if (request()->action() == 'rechargecard_add') {
  372. $item_list[] = array(
  373. 'name' => 'rechargecard_add',
  374. 'text' => lang('predeposit_recharge_card_recharge'),
  375. 'url' => (string)url('Predeposit/rechargecard_add'),
  376. );
  377. }
  378. if (request()->action() == 'cashadd') {
  379. $item_list[] = array(
  380. 'name' => 'cashadd',
  381. 'text' => lang('ds_member_path_predeposit_cashadd'),
  382. 'url' => (string)url('Predeposit/cashadd'),
  383. );
  384. }
  385. if (request()->action() == 'cashinfo') {
  386. $item_list[] = array(
  387. 'name' => 'cashinfo',
  388. 'text' => lang('ds_member_path_predeposit_cashinfo'),
  389. 'url' => (string)url('Predeposit/cashinfo'),
  390. );
  391. }
  392. return $item_list;
  393. }
  394. }