Sellermoney.php 7.9 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. class Sellermoney extends MobileSeller
  14. {
  15. public function initialize()
  16. {
  17. parent::initialize();
  18. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellermoney.lang.php');
  19. }
  20. /**
  21. * @api {POST} api/Sellermoney/index 店铺资金日志
  22. * @apiVersion 1.0.0
  23. * @apiGroup Sellermoney
  24. *
  25. * @apiHeader {String} X-DS-KEY 用户授权token
  26. *
  27. * @apiParam {Int} page 页码
  28. * @apiParam {Int} per_page 每页数量
  29. *
  30. * @apiSuccess {String} code 返回码,10000为成功
  31. * @apiSuccess {String} message 返回消息
  32. * @apiSuccess {Object} result 返回数据
  33. * @apiSuccess {Object[]} result.log_list 资金记录列表 (返回字段参考storemoneylog表)
  34. * @apiSuccess {Int} result.page_total 总页数
  35. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  36. */
  37. public function index()
  38. {
  39. $condition = array(array('store_id', '=', $this->store_info['store_id']));
  40. $query_start_date = input('param.query_start_date');
  41. $query_end_date = input('param.query_end_date');
  42. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_date);
  43. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_date);
  44. $start_unixtime = $if_start_date ? strtotime($query_start_date) : null;
  45. $end_unixtime = $if_end_date ? (strtotime($query_end_date) + 86399) : null;
  46. if ($start_unixtime || $end_unixtime) {
  47. $condition[] = array('storemoneylog_add_time', 'between', array($start_unixtime, $end_unixtime));
  48. }
  49. $storemoneylog_desc = input('param.storemoneylog_desc');
  50. if ($storemoneylog_desc) {
  51. $condition[] = array('storemoneylog_desc', 'like', '%' . $storemoneylog_desc . '%');
  52. }
  53. $storemoneylog_model = model('storemoneylog');
  54. $log_list = $storemoneylog_model->getStoremoneylogList($condition, 10, '*', 'storemoneylog_id desc');
  55. $result = array_merge(array('log_list' => $log_list), mobile_page($storemoneylog_model->page_info));
  56. ds_json_encode(10000, lang('ds_common_op_succ'), $result);
  57. }
  58. /**
  59. * @api {POST} api/Sellermoney/withdraw_list 提现列表
  60. * @apiVersion 1.0.0
  61. * @apiGroup Sellermoney
  62. *
  63. * @apiHeader {String} X-DS-KEY 用户授权token
  64. *
  65. * @apiParam {Int} page 页码
  66. * @apiParam {Int} per_page 每页数量
  67. *
  68. * @apiSuccess {String} code 返回码,10000为成功
  69. * @apiSuccess {String} message 返回消息
  70. * @apiSuccess {Object} result 返回数据
  71. * @apiSuccess {Object[]} result.log_list 资金记录列表 (返回字段参考storemoneylog表)
  72. * @apiSuccess {Int} result.page_total 总页数
  73. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  74. */
  75. public function withdraw_list()
  76. {
  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. {
  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. }