Sellermoney.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Db;
  4. use think\facade\Lang;
  5. use app\common\model\Storemoneylog;
  6. /**
  7. * ============================================================================
  8. *
  9. * ============================================================================
  10. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  11. * 网站地址: https://www.valimart.net/
  12. * ----------------------------------------------------------------------------
  13. *
  14. * ============================================================================
  15. * 卖家资金控制器
  16. */
  17. class Sellermoney extends MobileSeller {
  18. public function initialize() {
  19. parent::initialize();
  20. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellermoney.lang.php');
  21. }
  22. /**
  23. * @api {POST} api/Sellermoney/index 店铺资金日志
  24. * @apiVersion 1.0.0
  25. * @apiGroup Sellermoney
  26. *
  27. * @apiHeader {String} X-DS-KEY 用户授权token
  28. *
  29. * @apiParam {Int} page 页码
  30. * @apiParam {Int} per_page 每页数量
  31. *
  32. * @apiSuccess {String} code 返回码,10000为成功
  33. * @apiSuccess {String} message 返回消息
  34. * @apiSuccess {Object} result 返回数据
  35. * @apiSuccess {Object[]} result.log_list 资金记录列表 (返回字段参考storemoneylog表)
  36. * @apiSuccess {Int} result.page_total 总页数
  37. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  38. */
  39. public function index() {
  40. $condition = array(array('store_id', '=', $this->store_info['store_id']));
  41. $query_start_date = input('param.query_start_date');
  42. $query_end_date = input('param.query_end_date');
  43. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_date);
  44. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_date);
  45. $start_unixtime = $if_start_date ? strtotime($query_start_date) : null;
  46. $end_unixtime = $if_end_date ? (strtotime($query_end_date) + 86399) : null;
  47. if ($start_unixtime || $end_unixtime) {
  48. $condition[] = array('storemoneylog_add_time', 'between', array($start_unixtime, $end_unixtime));
  49. }
  50. $storemoneylog_desc = input('param.storemoneylog_desc');
  51. if ($storemoneylog_desc) {
  52. $condition[] = array('storemoneylog_desc', 'like', '%' . $storemoneylog_desc . '%');
  53. }
  54. $storemoneylog_model = model('storemoneylog');
  55. $log_list = $storemoneylog_model->getStoremoneylogList($condition, 10, '*', 'storemoneylog_id desc');
  56. $result = array_merge(array('log_list' => $log_list), mobile_page($storemoneylog_model->page_info));
  57. ds_json_encode(10000, lang('ds_common_op_succ'), $result);
  58. }
  59. /**
  60. * @api {POST} api/Sellermoney/withdraw_list 提现列表
  61. * @apiVersion 1.0.0
  62. * @apiGroup Sellermoney
  63. *
  64. * @apiHeader {String} X-DS-KEY 用户授权token
  65. *
  66. * @apiParam {Int} page 页码
  67. * @apiParam {Int} per_page 每页数量
  68. *
  69. * @apiSuccess {String} code 返回码,10000为成功
  70. * @apiSuccess {String} message 返回消息
  71. * @apiSuccess {Object} result 返回数据
  72. * @apiSuccess {Object[]} result.log_list 资金记录列表 (返回字段参考storemoneylog表)
  73. * @apiSuccess {Int} result.page_total 总页数
  74. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  75. */
  76. public function withdraw_list() {
  77. $condition = array();
  78. $condition[] = array('store_id','=',$this->store_info['store_id']);
  79. $condition[] = array('storemoneylog_type','=',Storemoneylog::TYPE_WITHDRAW);
  80. $paystate_search = input('param.paystate_search');
  81. if (isset($paystate_search) && $paystate_search !== '') {
  82. $condition[] = array('storemoneylog_state','=',intval($paystate_search));
  83. }
  84. $storemoneylog_model = model('storemoneylog');
  85. $log_list = $storemoneylog_model->getStoremoneylogList($condition, 10, '*', 'storemoneylog_id desc');
  86. $result = array_merge(array('log_list' => $log_list), mobile_page($storemoneylog_model->page_info));
  87. ds_json_encode(10000, lang('ds_common_op_succ'), $result);
  88. }
  89. /**
  90. * @api {POST} api/Sellermoney/withdraw_add 申请提现
  91. * @apiVersion 1.0.0
  92. * @apiGroup Sellermoney
  93. *
  94. * @apiHeader {String} X-DS-KEY 用户授权token
  95. *
  96. * @apiParam {Float} pdc_amount 提现金额
  97. *
  98. * @apiSuccess {String} code 返回码,10000为成功
  99. * @apiSuccess {String} message 返回消息
  100. * @apiSuccess {Object} result 返回数据
  101. */
  102. public function withdraw_add() {
  103. $data = [
  104. 'pdc_amount' => floatval(input('post.pdc_amount')),
  105. ];
  106. $sellermoney_validate = ds_validate('sellermoney');
  107. if (!$sellermoney_validate->scene('withdraw_add')->check($data)) {
  108. ds_json_encode(10001, $sellermoney_validate->getError());
  109. }
  110. $pdc_amount = $data['pdc_amount'];
  111. $storemoneylog_model = model('storemoneylog');
  112. //是否超过提现周期
  113. $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');
  114. if ($last_withdraw) {
  115. ds_json_encode(10001, lang('sellermoney_last_withdraw_time_error') . date('Y-m-d', $last_withdraw['storemoneylog_add_time']));
  116. }
  117. //是否不小于最低提现金额
  118. if ($pdc_amount < floatval(config('ds_config.store_withdraw_min'))) {
  119. ds_json_encode(10001, lang('sellermoney_withdraw_min') . config('ds_config.store_withdraw_min') . lang('ds_yuan'));
  120. }
  121. //是否不超过最高提现金额
  122. if ($pdc_amount > floatval(config('ds_config.store_withdraw_max'))) {
  123. ds_json_encode(10001, lang('sellermoney_withdraw_max') . config('ds_config.store_withdraw_max') . lang('ds_yuan'));
  124. }
  125. $data = array(
  126. 'store_id' => $this->store_info['store_id'],
  127. 'store_name' => $this->store_info['store_name'],
  128. 'storemoneylog_type' => Storemoneylog::TYPE_WITHDRAW,
  129. 'storemoneylog_state' => Storemoneylog::STATE_WAIT,
  130. 'storemoneylog_add_time' => TIMESTAMP,
  131. );
  132. $data['store_avaliable_money'] = -$pdc_amount;
  133. $data['store_freeze_money'] = $pdc_amount;
  134. $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();
  135. $joinin_detail = model('storejoinin')->getOneStorejoinin(array('member_id' => $this->store_info['member_id']));
  136. if ($joinin_detail['business_licence_address'] != '') {
  137. $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'];
  138. } else {
  139. $sml_desc = lang('sellermoney_alipay_name') . ':' . $storejoinin_info['settlement_bank_account_name'] . ',' . lang('sellermoney_alipay_number') . ':' . $storejoinin_info['settlement_bank_account_number'];
  140. }
  141. $data['storemoneylog_desc'] = $sml_desc;
  142. try {
  143. Db::startTrans();
  144. $storemoneylog_model->changeStoremoney($data);
  145. Db::commit();
  146. $this->recordSellerlog(lang('sellermoney_apply_withdraw'));
  147. ds_json_encode(10000, lang('ds_common_op_succ'));
  148. } catch (\Exception $e) {
  149. Db::rollback();
  150. ds_json_encode(10001, $e->getMessage());
  151. }
  152. }
  153. }