Predeposit.php 16 KB

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