123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- <?php
- /**
- * 预存款管理
- */
- namespace app\api\controller;
- use think\facade\Db;
- use think\facade\Lang;
- use app\common\model\Storedepositlog;
- use app\common\model\Storemoneylog;
- /**
-
- *
-
- *
- * ----------------------------------------------------------------------------
- *
-
- * 店铺保证金控制器
- */
- class Sellerdeposit extends MobileSeller
- {
- public function initialize()
- {
- parent::initialize();
- Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerdeposit.lang.php');
- }
- /**
- * @api {POST} api/Sellerdeposit/index 保证金变更日志
- * @apiVersion 1.0.0
- * @apiGroup Sellerdeposit
- *
- * @apiHeader {String} X-DS-KEY 卖家授权token
- *
- * @apiParam {String} query_start_date 开始时间 YYYY-MM-DD
- * @apiParam {String} query_end_date 结束时间 YYYY-MM-DD
- * @apiParam {String} storedepositlog_desc 日志详情
- * @apiParam {String} page 页码
- * @apiParam {String} pagesize 每页显示数量
- *
- * @apiSuccess {String} code 返回码,10000为成功
- * @apiSuccess {String} message 返回消息
- * @apiSuccess {Object} result 返回数据
- * @apiSuccess {Object[]} result.log_list 保证金列表 (返回字段参考storedepositlog表)
- * @apiSuccess {Int} result.page_total 总页数
- * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
- */
- public function index()
- {
- $condition = array(array('store_id', '=', $this->store_info['store_id']));
- $query_start_date = input('param.query_start_date');
- $query_end_date = input('param.query_end_date');
- $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_date);
- $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_date);
- $start_unixtime = $if_start_date ? strtotime($query_start_date) : null;
- $end_unixtime = $if_end_date ? (strtotime($query_end_date) + 86399) : null;
- if ($start_unixtime || $end_unixtime) {
- $condition[] = array('storedepositlog_add_time', 'between', array($start_unixtime, $end_unixtime));
- }
- $storedepositlog_desc = input('param.storedepositlog_desc');
- if ($storedepositlog_desc) {
- $condition[] = array('storedepositlog_desc', 'like', '%' . $storedepositlog_desc . '%');
- }
- $storedepositlog_model = model('storedepositlog');
- $log_list = $storedepositlog_model->getStoredepositlogList($condition, 10, '*', 'storedepositlog_id desc');
- $result = array_merge(array('log_list' => $log_list), mobile_page($storedepositlog_model->page_info));
- ds_json_encode(10000, lang('ds_common_op_succ'), $result);
- }
- /**
- * @api {POST} api/Sellerdeposit/withdraw_list 保证金提现列表
- * @apiVersion 1.0.0
- * @apiGroup Sellerdeposit
- *
- * @apiHeader {String} X-DS-KEY 卖家授权token
- *
- * @apiParam {Int} paystate_search 提现状态 0无效1有效2待审核3已同意4已拒绝5已缴纳6已取消
- * @apiParam {String} page 页码
- * @apiParam {String} pagesize 每页显示数量
- *
- * @apiSuccess {String} code 返回码,10000为成功
- * @apiSuccess {String} message 返回消息
- * @apiSuccess {Object} result 返回数据
- * @apiSuccess {Object[]} result.log_list 保证金列表 (返回字段参考storedepositlog表)
- * @apiSuccess {Int} result.page_total 总页数
- * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
- */
- public function withdraw_list()
- {
- $condition = array(
- array('store_id', '=', $this->store_info['store_id']),
- array('storedepositlog_type', 'in', [Storedepositlog::TYPE_WITHDRAW, Storedepositlog::TYPE_RECHARGE]),
- );
- $paystate_search = input('param.paystate_search');
- if (isset($paystate_search) && $paystate_search !== '') {
- $condition[] = array('storedepositlog_state', '=', intval($paystate_search));
- }
- $storedepositlog_model = model('storedepositlog');
- $log_list = $storedepositlog_model->getStoredepositlogList($condition, 10, '*', 'storedepositlog_id desc');
- $result = array_merge(array('log_list' => $log_list), mobile_page($storedepositlog_model->page_info));
- ds_json_encode(10000, lang('ds_common_op_succ'), $result);
- }
- /**
- * @api {POST} api/Sellerdeposit/recharge_add 补缴店铺保证金
- * @apiVersion 1.0.0
- * @apiGroup Sellerdeposit
- *
- * @apiHeader {String} X-DS-KEY 卖家授权token
- *
- * @apiParam {Float} pdc_amount 补缴金额
- *
- * @apiSuccess {String} code 返回码,10000为成功
- * @apiSuccess {String} message 返回消息
- * @apiSuccess {Object} result 返回数据
- */
- public function recharge_add()
- {
- $storedepositlog_model = model('storedepositlog');
- $money = abs(floatval(input('post.pdc_amount')));
- if (!$money) {
- ds_json_encode(10001, lang('param_error'));
- }
- try {
- Db::startTrans();
- $data = array(
- 'store_id' => $this->store_info['store_id'],
- 'store_name' => $this->store_info['store_name'],
- 'storedepositlog_type' => Storedepositlog::TYPE_PAY,
- 'storedepositlog_state' => Storedepositlog::STATE_VALID,
- 'storedepositlog_add_time' => TIMESTAMP,
- );
- $data['store_avaliable_deposit'] = $money;
- $data['storedepositlog_desc'] = lang('sellerdeposit_recharge_deposit');
- $storedepositlog_model->changeStoredeposit($data);
- //从店铺资金中扣除
- $storemoneylog_model = model('storemoneylog');
- $data2 = array(
- 'store_id' => $this->store_info['store_id'],
- 'store_name' => $this->store_info['store_name'],
- 'storemoneylog_type' => Storemoneylog::TYPE_DEPOSIT_IN,
- 'storemoneylog_state' => Storemoneylog::STATE_VALID,
- 'storemoneylog_add_time' => TIMESTAMP,
- 'store_avaliable_money' => -$money,
- 'storemoneylog_desc' => $data['storedepositlog_desc'],
- );
- $storemoneylog_model->changeStoremoney($data2);
- Db::commit();
- } catch (\Exception $e) {
- Db::rollback();
- ds_json_encode(10001, $e->getMessage());
- }
- $this->recordSellerlog(lang('sellerdeposit_recharge_deposit'));
- ds_json_encode(10000, lang('ds_common_op_succ'));
- }
- /**
- * @api {POST} api/Sellerdeposit/withdraw_add 申请保证金提现
- * @apiVersion 1.0.0
- * @apiGroup Sellerdeposit
- *
- * @apiHeader {String} X-DS-KEY 卖家授权token
- *
- * @apiParam {Float} pdc_amount 提现金额
- *
- * @apiSuccess {String} code 返回码,10000为成功
- * @apiSuccess {String} message 返回消息
- * @apiSuccess {Object} result 返回数据
- */
- public function withdraw_add()
- {
- $data = [
- 'pdc_amount' => floatval(input('post.pdc_amount')),
- ];
- $sellerdeposit_validate = ds_validate('sellerdeposit');
- if (!$sellerdeposit_validate->scene('withdraw_add')->check($data)) {
- ds_json_encode(10001, $sellerdeposit_validate->getError());
- }
- $pdc_amount = $data['pdc_amount'];
- $storedepositlog_model = model('storedepositlog');
- $data = array(
- 'store_id' => $this->store_info['store_id'],
- 'store_name' => $this->store_info['store_name'],
- 'storedepositlog_type' => Storedepositlog::TYPE_WITHDRAW,
- 'storedepositlog_state' => Storedepositlog::STATE_WAIT,
- 'storedepositlog_add_time' => TIMESTAMP,
- );
- $data['store_avaliable_deposit'] = -$pdc_amount;
- $data['store_freeze_deposit'] = $pdc_amount;
- $data['storedepositlog_desc'] = lang('sellerdeposit_apply_withdraw') . lang('sellerdeposit_avaliable_money');
- try {
- Db::startTrans();
- $storedepositlog_model->changeStoredeposit($data);
- Db::commit();
- $this->recordSellerlog(lang('sellerdeposit_apply_withdraw'));
- ds_json_encode(10000, lang('ds_common_op_succ'));
- } catch (\Exception $e) {
- Db::rollback();
- ds_json_encode(10001, $e->getMessage());
- }
- }
- }
|