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