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