Sellerdeposit.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. /**
  3. * 预存款管理
  4. */
  5. namespace app\api\controller;
  6. use think\facade\Db;
  7. use think\facade\Lang;
  8. use app\common\model\Storedepositlog;
  9. use app\common\model\Storemoneylog;
  10. /**
  11. * ============================================================================
  12. *
  13. * ============================================================================
  14. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  15. * 网站地址: https://www.valimart.net/
  16. * ----------------------------------------------------------------------------
  17. *
  18. * ============================================================================
  19. * 店铺保证金控制器
  20. */
  21. class Sellerdeposit extends MobileSeller {
  22. public function initialize() {
  23. parent::initialize();
  24. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerdeposit.lang.php');
  25. }
  26. /**
  27. * @api {POST} api/Sellerdeposit/index 保证金变更日志
  28. * @apiVersion 1.0.0
  29. * @apiGroup Sellerdeposit
  30. *
  31. * @apiHeader {String} X-DS-KEY 卖家授权token
  32. *
  33. * @apiParam {String} query_start_date 开始时间 YYYY-MM-DD
  34. * @apiParam {String} query_end_date 结束时间 YYYY-MM-DD
  35. * @apiParam {String} storedepositlog_desc 日志详情
  36. * @apiParam {String} page 页码
  37. * @apiParam {String} pagesize 每页显示数量
  38. *
  39. * @apiSuccess {String} code 返回码,10000为成功
  40. * @apiSuccess {String} message 返回消息
  41. * @apiSuccess {Object} result 返回数据
  42. * @apiSuccess {Object[]} result.log_list 保证金列表 (返回字段参考storedepositlog表)
  43. * @apiSuccess {Int} result.page_total 总页数
  44. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  45. */
  46. public function index() {
  47. $condition = array(array('store_id', '=', $this->store_info['store_id']));
  48. $query_start_date = input('param.query_start_date');
  49. $query_end_date = input('param.query_end_date');
  50. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_date);
  51. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_date);
  52. $start_unixtime = $if_start_date ? strtotime($query_start_date) : null;
  53. $end_unixtime = $if_end_date ? (strtotime($query_end_date) + 86399) : null;
  54. if ($start_unixtime || $end_unixtime) {
  55. $condition[] = array('storedepositlog_add_time', 'between', array($start_unixtime, $end_unixtime));
  56. }
  57. $storedepositlog_desc = input('param.storedepositlog_desc');
  58. if ($storedepositlog_desc) {
  59. $condition[] = array('storedepositlog_desc', 'like', '%' . $storedepositlog_desc . '%');
  60. }
  61. $storedepositlog_model = model('storedepositlog');
  62. $log_list = $storedepositlog_model->getStoredepositlogList($condition, 10, '*', 'storedepositlog_id desc');
  63. $result = array_merge(array('log_list' => $log_list), mobile_page($storedepositlog_model->page_info));
  64. ds_json_encode(10000, lang('ds_common_op_succ'), $result);
  65. }
  66. /**
  67. * @api {POST} api/Sellerdeposit/withdraw_list 保证金提现列表
  68. * @apiVersion 1.0.0
  69. * @apiGroup Sellerdeposit
  70. *
  71. * @apiHeader {String} X-DS-KEY 卖家授权token
  72. *
  73. * @apiParam {Int} paystate_search 提现状态 0无效1有效2待审核3已同意4已拒绝5已缴纳6已取消
  74. * @apiParam {String} page 页码
  75. * @apiParam {String} pagesize 每页显示数量
  76. *
  77. * @apiSuccess {String} code 返回码,10000为成功
  78. * @apiSuccess {String} message 返回消息
  79. * @apiSuccess {Object} result 返回数据
  80. * @apiSuccess {Object[]} result.log_list 保证金列表 (返回字段参考storedepositlog表)
  81. * @apiSuccess {Int} result.page_total 总页数
  82. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  83. */
  84. public function withdraw_list() {
  85. $condition = array(
  86. array('store_id', '=', $this->store_info['store_id']),
  87. array('storedepositlog_type', 'in', [Storedepositlog::TYPE_WITHDRAW, Storedepositlog::TYPE_RECHARGE]),
  88. );
  89. $paystate_search = input('param.paystate_search');
  90. if (isset($paystate_search) && $paystate_search !== '') {
  91. $condition[] = array('storedepositlog_state', '=', intval($paystate_search));
  92. }
  93. $storedepositlog_model = model('storedepositlog');
  94. $log_list = $storedepositlog_model->getStoredepositlogList($condition, 10, '*', 'storedepositlog_id desc');
  95. $result = array_merge(array('log_list' => $log_list), mobile_page($storedepositlog_model->page_info));
  96. ds_json_encode(10000, lang('ds_common_op_succ'), $result);
  97. }
  98. /**
  99. * @api {POST} api/Sellerdeposit/recharge_add 补缴店铺保证金
  100. * @apiVersion 1.0.0
  101. * @apiGroup Sellerdeposit
  102. *
  103. * @apiHeader {String} X-DS-KEY 卖家授权token
  104. *
  105. * @apiParam {Float} pdc_amount 补缴金额
  106. *
  107. * @apiSuccess {String} code 返回码,10000为成功
  108. * @apiSuccess {String} message 返回消息
  109. * @apiSuccess {Object} result 返回数据
  110. */
  111. public function recharge_add() {
  112. $storedepositlog_model = model('storedepositlog');
  113. $money = abs(floatval(input('post.pdc_amount')));
  114. if (!$money) {
  115. ds_json_encode(10001, lang('param_error'));
  116. }
  117. try {
  118. Db::startTrans();
  119. $data = array(
  120. 'store_id' => $this->store_info['store_id'],
  121. 'store_name' => $this->store_info['store_name'],
  122. 'storedepositlog_type' => Storedepositlog::TYPE_PAY,
  123. 'storedepositlog_state' => Storedepositlog::STATE_VALID,
  124. 'storedepositlog_add_time' => TIMESTAMP,
  125. );
  126. $data['store_avaliable_deposit'] = $money;
  127. $data['storedepositlog_desc'] = lang('sellerdeposit_recharge_deposit');
  128. $storedepositlog_model->changeStoredeposit($data);
  129. //从店铺资金中扣除
  130. $storemoneylog_model = model('storemoneylog');
  131. $data2 = array(
  132. 'store_id' => $this->store_info['store_id'],
  133. 'store_name' => $this->store_info['store_name'],
  134. 'storemoneylog_type' => Storemoneylog::TYPE_DEPOSIT_IN,
  135. 'storemoneylog_state' => Storemoneylog::STATE_VALID,
  136. 'storemoneylog_add_time' => TIMESTAMP,
  137. 'store_avaliable_money' => -$money,
  138. 'storemoneylog_desc' => $data['storedepositlog_desc'],
  139. );
  140. $storemoneylog_model->changeStoremoney($data2);
  141. Db::commit();
  142. } catch (\Exception $e) {
  143. Db::rollback();
  144. ds_json_encode(10001, $e->getMessage());
  145. }
  146. $this->recordSellerlog(lang('sellerdeposit_recharge_deposit'));
  147. ds_json_encode(10000, lang('ds_common_op_succ'));
  148. }
  149. /**
  150. * @api {POST} api/Sellerdeposit/withdraw_add 申请保证金提现
  151. * @apiVersion 1.0.0
  152. * @apiGroup Sellerdeposit
  153. *
  154. * @apiHeader {String} X-DS-KEY 卖家授权token
  155. *
  156. * @apiParam {Float} pdc_amount 提现金额
  157. *
  158. * @apiSuccess {String} code 返回码,10000为成功
  159. * @apiSuccess {String} message 返回消息
  160. * @apiSuccess {Object} result 返回数据
  161. */
  162. public function withdraw_add() {
  163. $data = [
  164. 'pdc_amount' => floatval(input('post.pdc_amount')),
  165. ];
  166. $sellerdeposit_validate = ds_validate('sellerdeposit');
  167. if (!$sellerdeposit_validate->scene('withdraw_add')->check($data)) {
  168. ds_json_encode(10001, $sellerdeposit_validate->getError());
  169. }
  170. $pdc_amount = $data['pdc_amount'];
  171. $storedepositlog_model = model('storedepositlog');
  172. $data = array(
  173. 'store_id' => $this->store_info['store_id'],
  174. 'store_name' => $this->store_info['store_name'],
  175. 'storedepositlog_type' => Storedepositlog::TYPE_WITHDRAW,
  176. 'storedepositlog_state' => Storedepositlog::STATE_WAIT,
  177. 'storedepositlog_add_time' => TIMESTAMP,
  178. );
  179. $data['store_avaliable_deposit'] = -$pdc_amount;
  180. $data['store_freeze_deposit'] = $pdc_amount;
  181. $data['storedepositlog_desc'] = lang('sellerdeposit_apply_withdraw') . lang('sellerdeposit_avaliable_money');
  182. try {
  183. Db::startTrans();
  184. $storedepositlog_model->changeStoredeposit($data);
  185. Db::commit();
  186. $this->recordSellerlog(lang('sellerdeposit_apply_withdraw'));
  187. ds_json_encode(10000, lang('ds_common_op_succ'));
  188. } catch (\Exception $e) {
  189. Db::rollback();
  190. ds_json_encode(10001, $e->getMessage());
  191. }
  192. }
  193. }