Sellermoney.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. *
  15. * 控制器
  16. */
  17. class Sellermoney extends BaseSeller
  18. {
  19. public function initialize()
  20. {
  21. parent::initialize();
  22. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellermoney.lang.php');
  23. }
  24. /**
  25. * 预存款变更日志
  26. */
  27. public function index()
  28. {
  29. $condition = array(array('store_id', '=', session('store_id')));
  30. $query_start_date = input('param.query_start_date');
  31. $query_end_date = input('param.query_end_date');
  32. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_date);
  33. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_date);
  34. $start_unixtime = $if_start_date ? strtotime($query_start_date) : null;
  35. $end_unixtime = $if_end_date ? (strtotime($query_end_date) + 86399) : null;
  36. if ($start_unixtime) {
  37. $condition[] = array('storemoneylog_add_time', '>=', $start_unixtime);
  38. }
  39. if ($end_unixtime) {
  40. $condition[] = array('storemoneylog_add_time', '<=', $end_unixtime);
  41. }
  42. $storemoneylog_desc = input('param.storemoneylog_desc');
  43. if ($storemoneylog_desc) {
  44. $condition[] = array('storemoneylog_desc', 'like', '%' . $storemoneylog_desc . '%');
  45. }
  46. $storemoneylog_model = model('storemoneylog');
  47. $list_log = $storemoneylog_model->getStoremoneylogList($condition, 10, '*', 'storemoneylog_id desc');
  48. View::assign('show_page', $storemoneylog_model->page_info->render());
  49. View::assign('list_log', $list_log);
  50. /* 设置买家当前菜单 */
  51. $this->setSellerCurMenu('seller_money');;
  52. /* 设置买家当前栏目 */
  53. $this->setSellerCurItem('index');
  54. $store_info = Db::name('store')->where(array('store_id' => session('store_id')))->field('store_avaliable_money,store_freeze_money')->find();
  55. View::assign('store_info', $store_info);
  56. return View::fetch($this->template_dir . 'index');
  57. }
  58. /**
  59. * 会员余额充值店铺资金
  60. */
  61. public function add()
  62. {
  63. $member_info = model('member')->getMemberInfoByID(session('member_id'));
  64. if (request()->isPost()) {
  65. $amount = floatval(input('post.amount'));
  66. $storemoneylog_model = model('storemoneylog');
  67. $predeposit_model = model('predeposit');
  68. if ($amount > floatval($member_info['available_predeposit'])) {
  69. ds_json_encode(10001, lang('sellermoney_rechargew_money_max') . $member_info['available_predeposit'] . lang('currency_zh'));
  70. }
  71. $storedata = array(
  72. 'store_id' => $this->store_info['store_id'],
  73. 'store_name' => $this->store_info['store_name'],
  74. 'storemoneylog_type' => Storemoneylog::TYPE_MEMBER_IN,
  75. 'storemoneylog_state' => Storemoneylog::STATE_VALID,
  76. 'storemoneylog_add_time' => TIMESTAMP,
  77. 'store_avaliable_money' => $amount,
  78. 'storemoneylog_desc' => lang('sellermoney_member_money') . lang('sellermoney_rechargew') . ',' . lang('sellermoney_money') . ':' . $amount,
  79. );
  80. $order_sn = makePaySn($member_info['member_id']);
  81. $memberdata = array(
  82. 'member_id' => $member_info['member_id'],
  83. 'amount' => $amount,
  84. 'member_name' => $member_info['member_name'],
  85. 'order_sn' => $order_sn,
  86. );
  87. try {
  88. Db::startTrans();
  89. $storemoneylog_model->changeStoremoney($storedata);
  90. $predeposit_model->changePd('store_rechargew_pay', $memberdata);
  91. Db::commit();
  92. $this->recordSellerlog(lang('sellermoney_rechargew_money'));
  93. ds_json_encode(10000, lang('ds_common_op_succ'));
  94. } catch (\Exception $e) {
  95. Db::rollback();
  96. ds_json_encode(10001, $e->getMessage());
  97. }
  98. } else {
  99. View::assign('member_info', $member_info);
  100. return View::fetch($this->template_dir . 'add');
  101. }
  102. }
  103. /**
  104. * 店铺资金提现到会员余额
  105. */
  106. public function withdraw_member()
  107. {
  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. {
  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. {
  217. $condition = array();
  218. $condition[] = array('store_id', '=', session('store_id'));
  219. $condition[] = array('storemoneylog_type', '=', Storemoneylog::TYPE_WITHDRAW);
  220. $paystate_search = input('param.paystate_search');
  221. if (isset($paystate_search) && $paystate_search !== '') {
  222. $condition[] = array('storemoneylog_state', '=', intval($paystate_search));
  223. }
  224. $storemoneylog_model = model('storemoneylog');
  225. $withdraw_list = $storemoneylog_model->getStoremoneylogList($condition, 10, '*', 'storemoneylog_id desc');
  226. View::assign('show_page', $storemoneylog_model->page_info->render());
  227. View::assign('withdraw_list', $withdraw_list);
  228. /* 设置买家当前菜单 */
  229. $this->setSellerCurMenu('seller_money');;
  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. {
  241. $item_list = array(
  242. array(
  243. 'name' => 'index',
  244. 'text' => lang('sellermoney_log_list'),
  245. 'url' => (string) url('Sellermoney/index'),
  246. ),
  247. array(
  248. 'name' => 'withdraw_list',
  249. 'text' => lang('sellermoney_withdraw_list'),
  250. 'url' => (string) url('Sellermoney/withdraw_list'),
  251. ),
  252. );
  253. return $item_list;
  254. }
  255. }