Sellermoney.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <?php
  2. /**
  3. * 预存款管理
  4. */
  5. namespace app\home\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. use app\common\model\Storemoneylog;
  9. use think\facade\Db;
  10. /**
  11. * ============================================================================
  12. * DSMall多用户商城
  13. * ============================================================================
  14. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  15. * 网站地址: http://www.csdeshang.com
  16. * ----------------------------------------------------------------------------
  17. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  18. * 不允许对程序代码以任何形式任何目的的再发布。
  19. * ============================================================================
  20. * 控制器
  21. */
  22. class Sellermoney extends BaseSeller {
  23. public function initialize() {
  24. parent::initialize();
  25. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellermoney.lang.php');
  26. }
  27. /**
  28. * 预存款变更日志
  29. */
  30. public function index() {
  31. $condition = array(array('store_id', '=', session('store_id')));
  32. $query_start_date = input('param.query_start_date');
  33. $query_end_date = input('param.query_end_date');
  34. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_date);
  35. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_date);
  36. $start_unixtime = $if_start_date ? strtotime($query_start_date) : null;
  37. $end_unixtime = $if_end_date ? (strtotime($query_end_date) + 86399) : null;
  38. if ($start_unixtime) {
  39. $condition[] = array('storemoneylog_add_time', '>=', $start_unixtime);
  40. }
  41. if ($end_unixtime) {
  42. $condition[] = array('storemoneylog_add_time', '<=', $end_unixtime);
  43. }
  44. $storemoneylog_desc = input('param.storemoneylog_desc');
  45. if ($storemoneylog_desc) {
  46. $condition[] = array('storemoneylog_desc', 'like', '%' . $storemoneylog_desc . '%');
  47. }
  48. $storemoneylog_model = model('storemoneylog');
  49. $list_log = $storemoneylog_model->getStoremoneylogList($condition, 10, '*', 'storemoneylog_id desc');
  50. View::assign('show_page', $storemoneylog_model->page_info->render());
  51. View::assign('list_log', $list_log);
  52. /* 设置买家当前菜单 */
  53. $this->setSellerCurMenu('seller_money');
  54. ;
  55. /* 设置买家当前栏目 */
  56. $this->setSellerCurItem('index');
  57. $store_info = Db::name('store')->where(array('store_id' => session('store_id')))->field('store_avaliable_money,store_freeze_money')->find();
  58. View::assign('store_info', $store_info);
  59. return View::fetch($this->template_dir . 'index');
  60. }
  61. /**
  62. * 会员余额充值店铺资金
  63. */
  64. public function add() {
  65. $member_info = model('member')->getMemberInfoByID(session('member_id'));
  66. if (request()->isPost()) {
  67. $amount = floatval(input('post.amount'));
  68. $storemoneylog_model = model('storemoneylog');
  69. $predeposit_model = model('predeposit');
  70. if($amount>floatval($member_info['available_predeposit'])){
  71. ds_json_encode(10001,lang('sellermoney_rechargew_money_max').$member_info['available_predeposit'].lang('currency_zh'));
  72. }
  73. $storedata=array(
  74. 'store_id'=>$this->store_info['store_id'],
  75. 'store_name'=>$this->store_info['store_name'],
  76. 'storemoneylog_type'=>Storemoneylog::TYPE_MEMBER_IN,
  77. 'storemoneylog_state'=>Storemoneylog::STATE_VALID,
  78. 'storemoneylog_add_time'=>TIMESTAMP,
  79. 'store_avaliable_money'=>$amount,
  80. 'storemoneylog_desc' => lang('sellermoney_member_money').lang('sellermoney_rechargew').','.lang('sellermoney_money').':'. $amount,
  81. );
  82. $order_sn = makePaySn($member_info['member_id']);
  83. $memberdata = array(
  84. 'member_id' => $member_info['member_id'],
  85. 'amount' => $amount,
  86. 'member_name' => $member_info['member_name'],
  87. 'order_sn' => $order_sn,
  88. );
  89. try {
  90. Db::startTrans();
  91. $storemoneylog_model->changeStoremoney($storedata);
  92. $predeposit_model->changePd('store_rechargew_pay', $memberdata);
  93. Db::commit();
  94. $this->recordSellerlog(lang('sellermoney_rechargew_money'));
  95. ds_json_encode(10000,lang('ds_common_op_succ'));
  96. } catch (\Exception $e) {
  97. Db::rollback();
  98. ds_json_encode(10001,$e->getMessage());
  99. }
  100. } else {
  101. View::assign('member_info', $member_info);
  102. return View::fetch($this->template_dir . 'add');
  103. }
  104. }
  105. /**
  106. * 店铺资金提现到会员余额
  107. */
  108. public function withdraw_member() {
  109. $member_info = model('member')->getMemberInfoByID(session('member_id'));
  110. if (request()->isPost()) {
  111. $amount = floatval(input('post.amount'));
  112. $storemoneylog_model = model('storemoneylog');
  113. $predeposit_model = model('predeposit');
  114. if($amount>floatval($this->store_info['store_avaliable_money'])){
  115. ds_json_encode(10001,lang('sellermoney_withdraw_money_max').$this->store_info['store_avaliable_money'].lang('currency_zh'));
  116. }
  117. $storedata=array(
  118. 'store_id'=>$this->store_info['store_id'],
  119. 'store_name'=>$this->store_info['store_name'],
  120. 'storemoneylog_type'=>Storemoneylog::TYPE_MEMBER_OUT,
  121. 'storemoneylog_state'=>Storemoneylog::STATE_VALID,
  122. 'storemoneylog_add_time'=>TIMESTAMP,
  123. 'store_avaliable_money'=>-$amount,
  124. 'storemoneylog_desc' => lang('sellermoney_withdraw_member').','.lang('sellermoney_money').':'. $amount,
  125. );
  126. $order_sn = makePaySn($member_info['member_id']);
  127. $memberdata = array(
  128. 'member_id' => $member_info['member_id'],
  129. 'amount' => $amount,
  130. 'member_name' => $member_info['member_name'],
  131. 'order_sn' => $order_sn,
  132. );
  133. try {
  134. Db::startTrans();
  135. $storemoneylog_model->changeStoremoney($storedata);
  136. $predeposit_model->changePd('store_withdraw', $memberdata);
  137. Db::commit();
  138. $this->recordSellerlog(lang('sellermoney_apply_withdraw'));
  139. ds_json_encode(10000,lang('ds_common_op_succ'));
  140. } catch (\Exception $e) {
  141. Db::rollback();
  142. ds_json_encode(10001,$e->getMessage());
  143. }
  144. } else {
  145. View::assign('store_avaliable_money', $this->store_info['store_avaliable_money']);
  146. return View::fetch($this->template_dir . 'member');
  147. }
  148. }
  149. /**
  150. * 申请提现
  151. */
  152. public function withdraw_add() {
  153. $store_info = Db::name('store')->where(array('store_id' => session('store_id')))->field('store_avaliable_money,store_freeze_money')->find();
  154. if (request()->isPost()) {
  155. $data = [
  156. 'pdc_amount' => floatval(input('post.pdc_amount')),
  157. ];
  158. $sellermoney_validate = ds_validate('sellermoney');
  159. if (!$sellermoney_validate->scene('withdraw_add')->check($data)) {
  160. ds_json_encode(10001, $sellermoney_validate->getError());
  161. }
  162. $pdc_amount = $data['pdc_amount'];
  163. $storemoneylog_model = model('storemoneylog');
  164. //是否超过提现周期
  165. $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');
  166. if ($last_withdraw) {
  167. ds_json_encode(10001, lang('sellermoney_last_withdraw_time_error') . date('Y-m-d', $last_withdraw['storemoneylog_add_time']));
  168. }
  169. //是否不小于最低提现金额
  170. if ($pdc_amount < floatval(config('ds_config.store_withdraw_min'))) {
  171. ds_json_encode(10001, lang('sellermoney_withdraw_min') . config('ds_config.store_withdraw_min') . lang('ds_yuan'));
  172. }
  173. //是否不超过最高提现金额
  174. if ($pdc_amount > floatval(config('ds_config.store_withdraw_max'))) {
  175. ds_json_encode(10001, lang('sellermoney_withdraw_max') . config('ds_config.store_withdraw_max') . lang('ds_yuan'));
  176. }
  177. $data = array(
  178. 'store_id' => $this->store_info['store_id'],
  179. 'store_name' => $this->store_info['store_name'],
  180. 'storemoneylog_type' => Storemoneylog::TYPE_WITHDRAW,
  181. 'storemoneylog_state' => Storemoneylog::STATE_WAIT,
  182. 'storemoneylog_add_time' => TIMESTAMP,
  183. );
  184. $data['store_avaliable_money'] = -$pdc_amount;
  185. $data['store_freeze_money'] = $pdc_amount;
  186. $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();
  187. $joinin_detail = model('storejoinin')->getOneStorejoinin(array('member_id' => $this->store_info['member_id']));
  188. if ($joinin_detail['business_licence_address'] != '') {
  189. $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'];
  190. } else {
  191. $sml_desc = lang('sellermoney_alipay_name') . ':' . $storejoinin_info['settlement_bank_account_name'] . ',' . lang('sellermoney_alipay_number') . ':' . $storejoinin_info['settlement_bank_account_number'];
  192. }
  193. $data['storemoneylog_desc'] = $sml_desc;
  194. try {
  195. Db::startTrans();
  196. $storemoneylog_model->changeStoremoney($data);
  197. Db::commit();
  198. $this->recordSellerlog(lang('sellermoney_apply_withdraw'));
  199. ds_json_encode(10000, lang('ds_common_op_succ'));
  200. } catch (\Exception $e) {
  201. Db::rollback();
  202. ds_json_encode(10001, $e->getMessage());
  203. }
  204. } else {
  205. View::assign('store_withdraw_cycle', config('ds_config.store_withdraw_cycle'));
  206. View::assign('store_withdraw_min', config('ds_config.store_withdraw_min'));
  207. View::assign('store_withdraw_max', config('ds_config.store_withdraw_max'));
  208. View::assign('store_info', $store_info);
  209. return View::fetch($this->template_dir . 'withdraw_add');
  210. }
  211. }
  212. /**
  213. * 提现列表
  214. */
  215. public function withdraw_list() {
  216. $condition = array();
  217. $condition[] = array('store_id','=',session('store_id'));
  218. $condition[] = array('storemoneylog_type','=',Storemoneylog::TYPE_WITHDRAW);
  219. $paystate_search = input('param.paystate_search');
  220. if (isset($paystate_search) && $paystate_search !== '') {
  221. $condition[] = array('storemoneylog_state','=',intval($paystate_search));
  222. }
  223. $storemoneylog_model = model('storemoneylog');
  224. $withdraw_list = $storemoneylog_model->getStoremoneylogList($condition, 10, '*', 'storemoneylog_id desc');
  225. View::assign('show_page', $storemoneylog_model->page_info->render());
  226. View::assign('withdraw_list', $withdraw_list);
  227. /* 设置买家当前菜单 */
  228. $this->setSellerCurMenu('seller_money');
  229. ;
  230. /* 设置买家当前栏目 */
  231. $this->setSellerCurItem('withdraw_list');
  232. $store_info = Db::name('store')->where(array('store_id' => session('store_id')))->field('store_avaliable_money,store_freeze_money')->find();
  233. View::assign('store_info', $store_info);
  234. return View::fetch($this->template_dir . 'withdraw_list');
  235. }
  236. /**
  237. * 栏目菜单
  238. */
  239. function getSellerItemList() {
  240. $item_list = array(
  241. array(
  242. 'name' => 'index',
  243. 'text' => lang('sellermoney_log_list'),
  244. 'url' => (string) url('Sellermoney/index'),
  245. ),
  246. array(
  247. 'name' => 'withdraw_list',
  248. 'text' => lang('sellermoney_withdraw_list'),
  249. 'url' => (string) url('Sellermoney/withdraw_list'),
  250. ),
  251. );
  252. return $item_list;
  253. }
  254. }