Sellermoney.php 8.4 KB

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