Sellermoney.php 8.1 KB

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