Sellermoney.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. /**
  3. * 预存款管理
  4. */
  5. namespace app\home\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. use app\common\model\Storemoneylog;
  9. use think\facade\Db;
  10. /**
  11. * ============================================================================
  12. * DSMall多用户商城
  13. * ============================================================================
  14. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  15. * 网站地址: http://www.csdeshang.com
  16. * ----------------------------------------------------------------------------
  17. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  18. * 不允许对程序代码以任何形式任何目的的再发布。
  19. * ============================================================================
  20. * 控制器
  21. */
  22. class Sellermoney extends BaseSeller {
  23. public function initialize() {
  24. parent::initialize();
  25. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellermoney.lang.php');
  26. }
  27. /**
  28. * 预存款变更日志
  29. */
  30. public function index() {
  31. $condition = array(array('store_id', '=', session('store_id')));
  32. $query_start_date = input('param.query_start_date');
  33. $query_end_date = input('param.query_end_date');
  34. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_date);
  35. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_date);
  36. $start_unixtime = $if_start_date ? strtotime($query_start_date) : null;
  37. $end_unixtime = $if_end_date ? (strtotime($query_end_date) + 86399) : null;
  38. if ($start_unixtime) {
  39. $condition[] = array('storemoneylog_add_time', '>=', $start_unixtime);
  40. }
  41. if ($end_unixtime) {
  42. $condition[] = array('storemoneylog_add_time', '<=', $end_unixtime);
  43. }
  44. $storemoneylog_desc = input('param.storemoneylog_desc');
  45. if ($storemoneylog_desc) {
  46. $condition[] = array('storemoneylog_desc', 'like', '%' . $storemoneylog_desc . '%');
  47. }
  48. $storemoneylog_model = model('storemoneylog');
  49. $list_log = $storemoneylog_model->getStoremoneylogList($condition, 10, '*', 'storemoneylog_id desc');
  50. View::assign('show_page', $storemoneylog_model->page_info->render());
  51. View::assign('list_log', $list_log);
  52. /* 设置买家当前菜单 */
  53. $this->setSellerCurMenu('seller_money');
  54. ;
  55. /* 设置买家当前栏目 */
  56. $this->setSellerCurItem('index');
  57. $store_info = Db::name('store')->where(array('store_id' => session('store_id')))->field('store_avaliable_money,store_freeze_money')->find();
  58. View::assign('store_info', $store_info);
  59. return View::fetch($this->template_dir . 'index');
  60. }
  61. /**
  62. * 申请提现
  63. */
  64. public function withdraw_add() {
  65. $store_info = Db::name('store')->where(array('store_id' => session('store_id')))->field('store_avaliable_money,store_freeze_money')->find();
  66. if (request()->isPost()) {
  67. $data = [
  68. 'pdc_amount' => floatval(input('post.pdc_amount')),
  69. ];
  70. $sellermoney_validate = ds_validate('sellermoney');
  71. if (!$sellermoney_validate->scene('withdraw_add')->check($data)) {
  72. ds_json_encode(10001, $sellermoney_validate->getError());
  73. }
  74. $pdc_amount = $data['pdc_amount'];
  75. $storemoneylog_model = model('storemoneylog');
  76. //是否超过提现周期
  77. $last_withdraw = $storemoneylog_model->getStoremoneylogInfo(array(array('store_id', '=', $this->store_info['store_id']), array('storemoneylog_state', 'in', [Storemoneylog::STATE_WAIT, Storemoneylog::STATE_AGREE]), array('storemoneylog_type', '=', Storemoneylog::TYPE_WITHDRAW), array('storemoneylog_add_time', '>', TIMESTAMP - intval(config('ds_config.store_withdraw_cycle')) * 86400)), 'storemoneylog_add_time');
  78. if ($last_withdraw) {
  79. ds_json_encode(10001, lang('sellermoney_last_withdraw_time_error') . date('Y-m-d', $last_withdraw['storemoneylog_add_time']));
  80. }
  81. //是否不小于最低提现金额
  82. if ($pdc_amount < floatval(config('ds_config.store_withdraw_min'))) {
  83. ds_json_encode(10001, lang('sellermoney_withdraw_min') . config('ds_config.store_withdraw_min') . lang('ds_yuan'));
  84. }
  85. //是否不超过最高提现金额
  86. if ($pdc_amount > floatval(config('ds_config.store_withdraw_max'))) {
  87. ds_json_encode(10001, lang('sellermoney_withdraw_max') . config('ds_config.store_withdraw_max') . lang('ds_yuan'));
  88. }
  89. $data = array(
  90. 'store_id' => $this->store_info['store_id'],
  91. 'store_name' => $this->store_info['store_name'],
  92. 'storemoneylog_type' => Storemoneylog::TYPE_WITHDRAW,
  93. 'storemoneylog_state' => Storemoneylog::STATE_WAIT,
  94. 'storemoneylog_add_time' => TIMESTAMP,
  95. );
  96. $data['store_avaliable_money'] = -$pdc_amount;
  97. $data['store_freeze_money'] = $pdc_amount;
  98. $storejoinin_info = Db::name('storejoinin')->where(array('member_id' => $this->store_info['member_id']))->field('settlement_bank_account_name,settlement_bank_account_number,settlement_bank_name,settlement_bank_address')->find();
  99. $joinin_detail = model('storejoinin')->getOneStorejoinin(array('member_id' => $this->store_info['member_id']));
  100. if ($joinin_detail['business_licence_address'] != '') {
  101. $sml_desc = lang('sellermoney_bank_user') . ':' . $storejoinin_info['settlement_bank_account_name'] . ',' . lang('sellermoney_bank_number') . ':' . $storejoinin_info['settlement_bank_account_number'] . ',' . lang('sellermoney_bank_sub_name') . ':' . $storejoinin_info['settlement_bank_name'] . ',' . lang('sellermoney_bank_name') . ':' . $storejoinin_info['settlement_bank_address'];
  102. } else {
  103. $sml_desc = lang('sellermoney_alipay_name') . ':' . $storejoinin_info['settlement_bank_account_name'] . ',' . lang('sellermoney_alipay_number') . ':' . $storejoinin_info['settlement_bank_account_number'];
  104. }
  105. $data['storemoneylog_desc'] = $sml_desc;
  106. try {
  107. Db::startTrans();
  108. $storemoneylog_model->changeStoremoney($data);
  109. Db::commit();
  110. $this->recordSellerlog(lang('sellermoney_apply_withdraw'));
  111. ds_json_encode(10000, lang('ds_common_op_succ'));
  112. } catch (\Exception $e) {
  113. Db::rollback();
  114. ds_json_encode(10001, $e->getMessage());
  115. }
  116. } else {
  117. View::assign('store_withdraw_cycle', config('ds_config.store_withdraw_cycle'));
  118. View::assign('store_withdraw_min', config('ds_config.store_withdraw_min'));
  119. View::assign('store_withdraw_max', config('ds_config.store_withdraw_max'));
  120. View::assign('store_info', $store_info);
  121. return View::fetch($this->template_dir . 'withdraw_add');
  122. }
  123. }
  124. /**
  125. * 提现列表
  126. */
  127. public function withdraw_list() {
  128. $condition = array();
  129. $condition[] = array('store_id','=',session('store_id'));
  130. $condition[] = array('storemoneylog_type','=',Storemoneylog::TYPE_WITHDRAW);
  131. $paystate_search = input('param.paystate_search');
  132. if (isset($paystate_search) && $paystate_search !== '') {
  133. $condition[] = array('storemoneylog_state','=',intval($paystate_search));
  134. }
  135. $storemoneylog_model = model('storemoneylog');
  136. $withdraw_list = $storemoneylog_model->getStoremoneylogList($condition, 10, '*', 'storemoneylog_id desc');
  137. View::assign('show_page', $storemoneylog_model->page_info->render());
  138. View::assign('withdraw_list', $withdraw_list);
  139. /* 设置买家当前菜单 */
  140. $this->setSellerCurMenu('seller_money');
  141. ;
  142. /* 设置买家当前栏目 */
  143. $this->setSellerCurItem('withdraw_list');
  144. $store_info = Db::name('store')->where(array('store_id' => session('store_id')))->field('store_avaliable_money,store_freeze_money')->find();
  145. View::assign('store_info', $store_info);
  146. return View::fetch($this->template_dir . 'withdraw_list');
  147. }
  148. /**
  149. * 栏目菜单
  150. */
  151. function getSellerItemList() {
  152. $item_list = array(
  153. array(
  154. 'name' => 'index',
  155. 'text' => lang('sellermoney_log_list'),
  156. 'url' => (string) url('Sellermoney/index'),
  157. ),
  158. array(
  159. 'name' => 'withdraw_list',
  160. 'text' => lang('sellermoney_withdraw_list'),
  161. 'url' => (string) url('Sellermoney/withdraw_list'),
  162. ),
  163. );
  164. return $item_list;
  165. }
  166. }