Sellermoney.php 13 KB

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