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