Sellerdeposit.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. *
  14. * ============================================================================
  15. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  16. * 网站地址: https://www.valimart.net/
  17. * ----------------------------------------------------------------------------
  18. *
  19. * ============================================================================
  20. * 控制器
  21. */
  22. class Sellerdeposit extends BaseSeller {
  23. public function initialize() {
  24. parent::initialize();
  25. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerdeposit.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('storedepositlog_add_time', '>=', $start_unixtime);
  40. }
  41. if ($end_unixtime) {
  42. $condition[] = array('storedepositlog_add_time', '<=', $end_unixtime);
  43. }
  44. $storedepositlog_desc = input('param.storedepositlog_desc');
  45. if ($storedepositlog_desc) {
  46. $condition[] = array('storedepositlog_desc', 'like', '%' . $storedepositlog_desc . '%');
  47. }
  48. $storedepositlog_model = model('storedepositlog');
  49. $list_log = $storedepositlog_model->getStoredepositlogList($condition, 10, '*', 'storedepositlog_id desc');
  50. View::assign('show_page', $storedepositlog_model->page_info->render());
  51. View::assign('list_log', $list_log);
  52. /* 设置买家当前菜单 */
  53. $this->setSellerCurMenu('seller_deposit');
  54. /* 设置买家当前栏目 */
  55. $this->setSellerCurItem('index');
  56. $store_info = Db::name('store')->where(array('store_id' => session('store_id')))->field('store_avaliable_deposit,store_freeze_deposit,store_payable_deposit')->find();
  57. View::assign('store_info', $store_info);
  58. return View::fetch($this->template_dir . 'index');
  59. }
  60. public function recharge_add() {
  61. $storedepositlog_model = model('storedepositlog');
  62. if (request()->isPost()) {
  63. $money = abs(floatval(input('post.pdc_amount')));
  64. if (!$money) {
  65. ds_json_encode(10001, lang('param_error'));
  66. }
  67. try {
  68. Db::startTrans();
  69. $data = array(
  70. 'store_id' => $this->store_info['store_id'],
  71. 'store_name' => $this->store_info['store_name'],
  72. 'storedepositlog_type' => Storedepositlog::TYPE_PAY,
  73. 'storedepositlog_state' => Storedepositlog::STATE_VALID,
  74. 'storedepositlog_add_time' => TIMESTAMP,
  75. );
  76. $data['store_avaliable_deposit'] = $money;
  77. $data['storedepositlog_desc'] = lang('sellerdeposit_recharge_deposit');
  78. $storedepositlog_model->changeStoredeposit($data);
  79. //从店铺资金中扣除
  80. $storemoneylog_model = model('storemoneylog');
  81. $data2 = array(
  82. 'store_id' => $this->store_info['store_id'],
  83. 'store_name' => $this->store_info['store_name'],
  84. 'storemoneylog_type' => Storemoneylog::TYPE_DEPOSIT_IN,
  85. 'storemoneylog_state' => Storemoneylog::STATE_VALID,
  86. 'storemoneylog_add_time' => TIMESTAMP,
  87. 'store_avaliable_money' => -$money,
  88. 'storemoneylog_desc' => $data['storedepositlog_desc'],
  89. );
  90. $storemoneylog_model->changeStoremoney($data2);
  91. Db::commit();
  92. } catch (\Exception $e) {
  93. Db::rollback();
  94. ds_json_encode(10001, $e->getMessage());
  95. }
  96. $this->recordSellerlog(lang('sellerdeposit_recharge_deposit'));
  97. ds_json_encode(10000, lang('ds_common_op_succ'));
  98. } else {
  99. return View::fetch($this->template_dir . 'recharge_add');
  100. }
  101. }
  102. /**
  103. * 申请提现
  104. */
  105. public function withdraw_add() {
  106. $store_info = Db::name('store')->where(array('store_id' => session('store_id')))->field('store_avaliable_deposit,store_freeze_deposit,store_payable_deposit')->find();
  107. if (request()->isPost()) {
  108. $data = [
  109. 'pdc_amount' => floatval(input('post.pdc_amount')),
  110. ];
  111. $sellerdeposit_validate = ds_validate('sellerdeposit');
  112. if (!$sellerdeposit_validate->scene('withdraw_add')->check($data)) {
  113. ds_json_encode(10001, $sellerdeposit_validate->getError());
  114. }
  115. $pdc_amount = $data['pdc_amount'];
  116. $storedepositlog_model = model('storedepositlog');
  117. $data = array(
  118. 'store_id' => $this->store_info['store_id'],
  119. 'store_name' => $this->store_info['store_name'],
  120. 'storedepositlog_type' => Storedepositlog::TYPE_WITHDRAW,
  121. 'storedepositlog_state' => Storedepositlog::STATE_WAIT,
  122. 'storedepositlog_add_time' => TIMESTAMP,
  123. );
  124. $data['store_avaliable_deposit'] = -$pdc_amount;
  125. $data['store_freeze_deposit'] = $pdc_amount;
  126. $data['storedepositlog_desc'] = lang('sellerdeposit_apply_withdraw') . lang('sellerdeposit_avaliable_money');
  127. try {
  128. Db::startTrans();
  129. $storedepositlog_model->changeStoredeposit($data);
  130. Db::commit();
  131. $this->recordSellerlog(lang('sellerdeposit_apply_withdraw'));
  132. ds_json_encode(10000, lang('ds_common_op_succ'));
  133. } catch (\Exception $e) {
  134. Db::rollback();
  135. ds_json_encode(10001, $e->getMessage());
  136. }
  137. } else {
  138. View::assign('store_withdraw_cycle', config('ds_config.store_withdraw_cycle'));
  139. View::assign('store_withdraw_min', config('ds_config.store_withdraw_min'));
  140. View::assign('store_withdraw_max', config('ds_config.store_withdraw_max'));
  141. View::assign('store_info', $store_info);
  142. return View::fetch($this->template_dir . 'withdraw_add');
  143. }
  144. }
  145. /**
  146. * 提现列表
  147. */
  148. public function withdraw_list() {
  149. $condition = array(
  150. array('store_id', '=', session('store_id')),
  151. array('storedepositlog_type', 'in', [Storedepositlog::TYPE_WITHDRAW, Storedepositlog::TYPE_RECHARGE]),
  152. );
  153. $paystate_search = input('param.paystate_search');
  154. if (isset($paystate_search) && $paystate_search !== '') {
  155. $condition[] = array('storedepositlog_state','=',intval($paystate_search));
  156. }
  157. $storedepositlog_model = model('storedepositlog');
  158. $withdraw_list = $storedepositlog_model->getStoredepositlogList($condition, 10, '*', 'storedepositlog_id desc');
  159. View::assign('show_page', $storedepositlog_model->page_info->render());
  160. View::assign('withdraw_list', $withdraw_list);
  161. /* 设置买家当前菜单 */
  162. $this->setSellerCurMenu('seller_deposit');
  163. ;
  164. /* 设置买家当前栏目 */
  165. $this->setSellerCurItem('withdraw_list');
  166. $store_info = Db::name('store')->where(array('store_id' => session('store_id')))->field('store_avaliable_deposit,store_freeze_deposit,store_payable_deposit')->find();
  167. View::assign('store_info', $store_info);
  168. return View::fetch($this->template_dir . 'withdraw_list');
  169. }
  170. /**
  171. * 栏目菜单
  172. */
  173. function getSellerItemList() {
  174. $item_list = array(
  175. array(
  176. 'name' => 'index',
  177. 'text' => lang('sellerdeposit_log_list'),
  178. 'url' => (string) url('Sellerdeposit/index'),
  179. ),
  180. array(
  181. 'name' => 'withdraw_list',
  182. 'text' => lang('sellerdeposit_withdraw_list'),
  183. 'url' => (string) url('Sellerdeposit/withdraw_list'),
  184. ),
  185. );
  186. return $item_list;
  187. }
  188. }