Sellerdeposit.php 9.1 KB

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