Predeposit.php 17 KB

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