Sellerdeposit.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. *
  16. * 控制器
  17. */
  18. class Sellerdeposit extends BaseSeller
  19. {
  20. public function initialize()
  21. {
  22. parent::initialize();
  23. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerdeposit.lang.php');
  24. }
  25. /**
  26. * 预存款变更日志
  27. */
  28. public function index()
  29. {
  30. $condition = array(array('store_id', '=', session('store_id')));
  31. $query_start_date = input('param.query_start_date');
  32. $query_end_date = input('param.query_end_date');
  33. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_date);
  34. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_date);
  35. $start_unixtime = $if_start_date ? strtotime($query_start_date) : null;
  36. $end_unixtime = $if_end_date ? (strtotime($query_end_date) + 86399) : null;
  37. if ($start_unixtime) {
  38. $condition[] = array('storedepositlog_add_time', '>=', $start_unixtime);
  39. }
  40. if ($end_unixtime) {
  41. $condition[] = array('storedepositlog_add_time', '<=', $end_unixtime);
  42. }
  43. $storedepositlog_desc = input('param.storedepositlog_desc');
  44. if ($storedepositlog_desc) {
  45. $condition[] = array('storedepositlog_desc', 'like', '%' . $storedepositlog_desc . '%');
  46. }
  47. $storedepositlog_model = model('storedepositlog');
  48. $list_log = $storedepositlog_model->getStoredepositlogList($condition, 10, '*', 'storedepositlog_id desc');
  49. View::assign('show_page', $storedepositlog_model->page_info->render());
  50. View::assign('list_log', $list_log);
  51. /* 设置买家当前菜单 */
  52. $this->setSellerCurMenu('seller_deposit');
  53. /* 设置买家当前栏目 */
  54. $this->setSellerCurItem('index');
  55. $store_info = Db::name('store')->where(array('store_id' => session('store_id')))->field('store_avaliable_deposit,store_freeze_deposit,store_payable_deposit')->find();
  56. View::assign('store_info', $store_info);
  57. return View::fetch($this->template_dir . 'index');
  58. }
  59. public function recharge_add()
  60. {
  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. {
  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. {
  151. $condition = array(
  152. array('store_id', '=', session('store_id')),
  153. array('storedepositlog_type', 'in', [Storedepositlog::TYPE_WITHDRAW, Storedepositlog::TYPE_RECHARGE]),
  154. );
  155. $paystate_search = input('param.paystate_search');
  156. if (isset($paystate_search) && $paystate_search !== '') {
  157. $condition[] = array('storedepositlog_state', '=', intval($paystate_search));
  158. }
  159. $storedepositlog_model = model('storedepositlog');
  160. $withdraw_list = $storedepositlog_model->getStoredepositlogList($condition, 10, '*', 'storedepositlog_id desc');
  161. View::assign('show_page', $storedepositlog_model->page_info->render());
  162. View::assign('withdraw_list', $withdraw_list);
  163. /* 设置买家当前菜单 */
  164. $this->setSellerCurMenu('seller_deposit');;
  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. {
  176. $item_list = array(
  177. array(
  178. 'name' => 'index',
  179. 'text' => lang('sellerdeposit_log_list'),
  180. 'url' => (string) url('Sellerdeposit/index'),
  181. ),
  182. array(
  183. 'name' => 'withdraw_list',
  184. 'text' => lang('sellerdeposit_withdraw_list'),
  185. 'url' => (string) url('Sellerdeposit/withdraw_list'),
  186. ),
  187. );
  188. return $item_list;
  189. }
  190. }