Sellerdeposit.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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\Storedepositlog;
  9. use app\common\model\Storemoneylog;
  10. use think\facade\Db;
  11. /**
  12. * ============================================================================
  13. * DSMall多用户商城
  14. * ============================================================================
  15. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  16. * 网站地址: http://www.csdeshang.com
  17. * ----------------------------------------------------------------------------
  18. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  19. * 不允许对程序代码以任何形式任何目的的再发布。
  20. * ============================================================================
  21. * 控制器
  22. */
  23. class Sellerdeposit extends BaseSeller {
  24. public function initialize() {
  25. parent::initialize();
  26. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerdeposit.lang.php');
  27. }
  28. /**
  29. * 预存款变更日志
  30. */
  31. public function index() {
  32. $condition = array(array('store_id', '=', session('store_id')));
  33. $query_start_date = input('param.query_start_date');
  34. $query_end_date = input('param.query_end_date');
  35. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_date);
  36. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_date);
  37. $start_unixtime = $if_start_date ? strtotime($query_start_date) : null;
  38. $end_unixtime = $if_end_date ? (strtotime($query_end_date) + 86399) : null;
  39. if ($start_unixtime) {
  40. $condition[] = array('storedepositlog_add_time', '>=', $start_unixtime);
  41. }
  42. if ($end_unixtime) {
  43. $condition[] = array('storedepositlog_add_time', '<=', $end_unixtime);
  44. }
  45. $storedepositlog_desc = input('param.storedepositlog_desc');
  46. if ($storedepositlog_desc) {
  47. $condition[] = array('storedepositlog_desc', 'like', '%' . $storedepositlog_desc . '%');
  48. }
  49. $storedepositlog_model = model('storedepositlog');
  50. $list_log = $storedepositlog_model->getStoredepositlogList($condition, 10, '*', 'storedepositlog_id desc');
  51. View::assign('show_page', $storedepositlog_model->page_info->render());
  52. View::assign('list_log', $list_log);
  53. /* 设置买家当前菜单 */
  54. $this->setSellerCurMenu('seller_deposit');
  55. /* 设置买家当前栏目 */
  56. $this->setSellerCurItem('index');
  57. $store_info = Db::name('store')->where(array('store_id' => session('store_id')))->field('store_avaliable_deposit,store_freeze_deposit,store_payable_deposit')->find();
  58. View::assign('store_info', $store_info);
  59. return View::fetch($this->template_dir . 'index');
  60. }
  61. public function recharge_add() {
  62. $storedepositlog_model = model('storedepositlog');
  63. if (request()->isPost()) {
  64. $money = abs(floatval(input('post.pdc_amount')));
  65. if (!$money) {
  66. ds_json_encode(10001, lang('param_error'));
  67. }
  68. try {
  69. Db::startTrans();
  70. $data = array(
  71. 'store_id' => $this->store_info['store_id'],
  72. 'store_name' => $this->store_info['store_name'],
  73. 'storedepositlog_type' => Storedepositlog::TYPE_PAY,
  74. 'storedepositlog_state' => Storedepositlog::STATE_VALID,
  75. 'storedepositlog_add_time' => TIMESTAMP,
  76. );
  77. $data['store_avaliable_deposit'] = $money;
  78. $data['storedepositlog_desc'] = lang('sellerdeposit_recharge_deposit');
  79. $storedepositlog_model->changeStoredeposit($data);
  80. //从店铺资金中扣除
  81. $storemoneylog_model = model('storemoneylog');
  82. $data2 = array(
  83. 'store_id' => $this->store_info['store_id'],
  84. 'store_name' => $this->store_info['store_name'],
  85. 'storemoneylog_type' => Storemoneylog::TYPE_DEPOSIT_IN,
  86. 'storemoneylog_state' => Storemoneylog::STATE_VALID,
  87. 'storemoneylog_add_time' => TIMESTAMP,
  88. 'store_avaliable_money' => -$money,
  89. 'storemoneylog_desc' => $data['storedepositlog_desc'],
  90. );
  91. $storemoneylog_model->changeStoremoney($data2);
  92. Db::commit();
  93. } catch (\Exception $e) {
  94. Db::rollback();
  95. ds_json_encode(10001, $e->getMessage());
  96. }
  97. $this->recordSellerlog(lang('sellerdeposit_recharge_deposit'));
  98. ds_json_encode(10000, lang('ds_common_op_succ'));
  99. } else {
  100. return View::fetch($this->template_dir . 'recharge_add');
  101. }
  102. }
  103. /**
  104. * 申请提现
  105. */
  106. public function withdraw_add() {
  107. $store_info = Db::name('store')->where(array('store_id' => session('store_id')))->field('store_avaliable_deposit,store_freeze_deposit,store_payable_deposit')->find();
  108. if (request()->isPost()) {
  109. $data = [
  110. 'pdc_amount' => floatval(input('post.pdc_amount')),
  111. ];
  112. $sellerdeposit_validate = ds_validate('sellerdeposit');
  113. if (!$sellerdeposit_validate->scene('withdraw_add')->check($data)) {
  114. ds_json_encode(10001, $sellerdeposit_validate->getError());
  115. }
  116. $pdc_amount = $data['pdc_amount'];
  117. $storedepositlog_model = model('storedepositlog');
  118. $data = array(
  119. 'store_id' => $this->store_info['store_id'],
  120. 'store_name' => $this->store_info['store_name'],
  121. 'storedepositlog_type' => Storedepositlog::TYPE_WITHDRAW,
  122. 'storedepositlog_state' => Storedepositlog::STATE_WAIT,
  123. 'storedepositlog_add_time' => TIMESTAMP,
  124. );
  125. $data['store_avaliable_deposit'] = -$pdc_amount;
  126. $data['store_freeze_deposit'] = $pdc_amount;
  127. $data['storedepositlog_desc'] = lang('sellerdeposit_apply_withdraw') . lang('sellerdeposit_avaliable_money');
  128. try {
  129. Db::startTrans();
  130. $storedepositlog_model->changeStoredeposit($data);
  131. Db::commit();
  132. $this->recordSellerlog(lang('sellerdeposit_apply_withdraw'));
  133. ds_json_encode(10000, lang('ds_common_op_succ'));
  134. } catch (\Exception $e) {
  135. Db::rollback();
  136. ds_json_encode(10001, $e->getMessage());
  137. }
  138. } else {
  139. View::assign('store_withdraw_cycle', config('ds_config.store_withdraw_cycle'));
  140. View::assign('store_withdraw_min', config('ds_config.store_withdraw_min'));
  141. View::assign('store_withdraw_max', config('ds_config.store_withdraw_max'));
  142. View::assign('store_info', $store_info);
  143. return View::fetch($this->template_dir . 'withdraw_add');
  144. }
  145. }
  146. /**
  147. * 提现列表
  148. */
  149. public function withdraw_list() {
  150. $condition = array(
  151. array('store_id', '=', session('store_id')),
  152. array('storedepositlog_type', 'in', [Storedepositlog::TYPE_WITHDRAW, Storedepositlog::TYPE_RECHARGE]),
  153. );
  154. $paystate_search = input('param.paystate_search');
  155. if (isset($paystate_search) && $paystate_search !== '') {
  156. $condition[] = array('storedepositlog_state','=',intval($paystate_search));
  157. }
  158. $storedepositlog_model = model('storedepositlog');
  159. $withdraw_list = $storedepositlog_model->getStoredepositlogList($condition, 10, '*', 'storedepositlog_id desc');
  160. View::assign('show_page', $storedepositlog_model->page_info->render());
  161. View::assign('withdraw_list', $withdraw_list);
  162. /* 设置买家当前菜单 */
  163. $this->setSellerCurMenu('seller_deposit');
  164. ;
  165. /* 设置买家当前栏目 */
  166. $this->setSellerCurItem('withdraw_list');
  167. $store_info = Db::name('store')->where(array('store_id' => session('store_id')))->field('store_avaliable_deposit,store_freeze_deposit,store_payable_deposit')->find();
  168. View::assign('store_info', $store_info);
  169. return View::fetch($this->template_dir . 'withdraw_list');
  170. }
  171. /**
  172. * 栏目菜单
  173. */
  174. function getSellerItemList() {
  175. $item_list = array(
  176. array(
  177. 'name' => 'index',
  178. 'text' => lang('sellerdeposit_log_list'),
  179. 'url' => (string) url('Sellerdeposit/index'),
  180. ),
  181. array(
  182. 'name' => 'withdraw_list',
  183. 'text' => lang('sellerdeposit_withdraw_list'),
  184. 'url' => (string) url('Sellerdeposit/withdraw_list'),
  185. ),
  186. );
  187. return $item_list;
  188. }
  189. }