Storedeposit.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. use think\facade\Db;
  6. use app\common\model\Storedepositlog;
  7. use app\common\model\Storemoneylog;
  8. /**
  9. *
  10. *
  11. * ----------------------------------------------------------------------------
  12. *
  13. * 控制器
  14. */
  15. class Storedeposit extends AdminControl
  16. {
  17. public function initialize()
  18. {
  19. parent::initialize();
  20. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/storedeposit.lang.php');
  21. }
  22. /*
  23. * 资金明细
  24. */
  25. public function index()
  26. {
  27. $condition = array();
  28. $stime = input('get.stime');
  29. $etime = input('get.etime');
  30. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $stime);
  31. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $etime);
  32. $start_unixtime = $if_start_date ? strtotime($stime) : null;
  33. $end_unixtime = $if_end_date ? (strtotime($etime) + 86399) : null;
  34. if ($start_unixtime) {
  35. $condition[] = array('storedepositlog_add_time', '>=', $start_unixtime);
  36. }
  37. if ($end_unixtime) {
  38. $condition[] = array('storedepositlog_add_time', '<=', $end_unixtime);
  39. }
  40. $mname = input('get.mname');
  41. if (!empty($mname)) {
  42. $condition[] = array('store_name', 'like', '%' . $mname . '%');
  43. }
  44. $storedepositlog_model = model('storedepositlog');
  45. $list_log = $storedepositlog_model->getStoredepositlogList($condition, 10, '*', 'storedepositlog_id desc');
  46. View::assign('show_page', $storedepositlog_model->page_info->render());
  47. View::assign('list_log', $list_log);
  48. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  49. $this->setAdminCurItem('index');
  50. return View::fetch();
  51. }
  52. /*
  53. * 提现列表
  54. */
  55. public function withdraw_list()
  56. {
  57. $condition = array(array('storedepositlog_type', 'in', [Storedepositlog::TYPE_WITHDRAW, Storedepositlog::TYPE_RECHARGE]),);
  58. $paystate_search = input('param.paystate_search');
  59. if (isset($paystate_search) && $paystate_search !== '') {
  60. $condition[] = array('storedepositlog_state', '=', intval($paystate_search));
  61. }
  62. $storedepositlog_model = model('storedepositlog');
  63. $withdraw_list = $storedepositlog_model->getStoredepositlogList($condition, 10, '*', 'storedepositlog_id desc');
  64. View::assign('show_page', $storedepositlog_model->page_info->render());
  65. View::assign('withdraw_list', $withdraw_list);
  66. View::assign('filtered', input('get.') ? 1 : 0); //是否有查询条件
  67. $this->setAdminCurItem('withdraw_list');
  68. return View::fetch();
  69. }
  70. /**
  71. * 查看提现信息
  72. */
  73. public function withdraw_view()
  74. {
  75. $id = intval(input('param.id'));
  76. if ($id <= 0) {
  77. $this->error(lang('param_error'));
  78. }
  79. $storedepositlog_model = model('storedepositlog');
  80. $condition = array();
  81. $condition[] = array('storedepositlog_id', '=', $id);
  82. $info = $storedepositlog_model->getStoredepositlogInfo($condition);
  83. if (!is_array($info) || count($info) < 0) {
  84. $this->error(lang('admin_storedeposit_record_error'));
  85. }
  86. if (!request()->isPost()) {
  87. View::assign('info', $info);
  88. return View::fetch();
  89. } else {
  90. if (!input('param.verify_reason')) {
  91. $this->error(lang('ds_none_input') . lang('admin_storedeposit_remark'));
  92. }
  93. $data = array(
  94. 'store_id' => $info['store_id'],
  95. 'store_name' => $info['store_name'],
  96. 'storedepositlog_type' => Storedepositlog::TYPE_VERIFY,
  97. 'storedepositlog_state' => Storedepositlog::STATE_VALID,
  98. 'storedepositlog_add_time' => TIMESTAMP,
  99. );
  100. if (input('param.verify_state') == 1) { //通过
  101. $data['store_freeze_deposit'] = -$info['store_freeze_deposit'];
  102. $storedepositlog_state = Storedepositlog::STATE_AGREE;
  103. } else {
  104. $data['store_avaliable_deposit'] = $info['store_freeze_deposit'];
  105. $data['store_freeze_deposit'] = -$info['store_freeze_deposit'];
  106. $storedepositlog_state = Storedepositlog::STATE_REJECT;
  107. }
  108. $admininfo = $this->getAdminInfo();
  109. $data['storedepositlog_desc'] = lang('order_admin_operator') . "【" . $admininfo['admin_name'] . "】" . ((input('param.verify_state') == 1) ? lang('ds_pass') : lang('ds_refuse')) . lang('ds_seller_name') . "【" . $info['store_name'] . "】" . lang('admin_storedeposit_log_stage_cash') . ':' . input('param.verify_reason');
  110. try {
  111. Db::startTrans();
  112. $storedepositlog_model->changeStoredeposit($data);
  113. //修提现状态
  114. if (!$storedepositlog_model->editStoredepositlog(array('storedepositlog_id' => $id, 'storedepositlog_state' => Storedepositlog::STATE_WAIT), array('storedepositlog_state' => $storedepositlog_state))) {
  115. throw new \think\Exception(lang('admin_storedeposit_cash_edit_fail'), 10006);
  116. }
  117. //如果是通过取出保证金,则将保证金转换为店铺可用资金
  118. if (input('param.verify_state') == 1) {
  119. $storemoneylog_model = model('storemoneylog');
  120. $data2 = array(
  121. 'store_id' => $info['store_id'],
  122. 'store_name' => $info['store_name'],
  123. 'storemoneylog_type' => Storemoneylog::TYPE_DEPOSIT_OUT,
  124. 'storemoneylog_state' => Storemoneylog::STATE_VALID,
  125. 'storemoneylog_add_time' => TIMESTAMP,
  126. 'store_avaliable_money' => $info['store_freeze_deposit'],
  127. 'storemoneylog_desc' => $data['storedepositlog_desc'],
  128. );
  129. $storemoneylog_model->changeStoremoney($data2);
  130. }
  131. Db::commit();
  132. $this->log($data['storedepositlog_desc'], 1);
  133. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  134. } catch (\Exception $e) {
  135. Db::rollback();
  136. $this->log($data['storedepositlog_desc'], 0);
  137. $this->error($e->getMessage());
  138. }
  139. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  140. }
  141. }
  142. public function recharge_view()
  143. {
  144. $id = intval(input('param.id'));
  145. if ($id <= 0) {
  146. $this->error(lang('param_error'));
  147. }
  148. $storedepositlog_model = model('storedepositlog');
  149. $condition = array();
  150. $condition[] = array('storedepositlog_id', '=', $id);
  151. $info = $storedepositlog_model->getStoredepositlogInfo($condition);
  152. if (!is_array($info) || count($info) < 0) {
  153. $this->error(lang('admin_storedeposit_record_error'));
  154. }
  155. if (!request()->isPost()) {
  156. View::assign('info', $info);
  157. return View::fetch();
  158. } else {
  159. if (!input('param.verify_reason')) {
  160. $this->error(lang('ds_none_input') . lang('admin_storedeposit_remark'));
  161. }
  162. $data = array(
  163. 'store_id' => $info['store_id'],
  164. 'store_name' => $info['store_name'],
  165. 'storedepositlog_type' => Storedepositlog::TYPE_VIEW,
  166. 'storedepositlog_state' => Storedepositlog::STATE_VALID,
  167. 'storedepositlog_add_time' => TIMESTAMP,
  168. );
  169. if (input('param.verify_state') == 1) { //通过
  170. $data['store_avaliable_deposit'] = $info['store_payable_deposit'];
  171. $data['store_payable_deposit'] = -$info['store_payable_deposit'];
  172. $storedepositlog_state = Storedepositlog::STATE_PAYED;
  173. } else {
  174. $data['store_payable_deposit'] = -$info['store_payable_deposit'];
  175. $storedepositlog_state = Storedepositlog::STATE_CANCEL;
  176. }
  177. $admininfo = $this->getAdminInfo();
  178. $data['storedepositlog_desc'] = lang('order_admin_operator') . "【" . $admininfo['admin_name'] . "】" . lang('ds_update') . lang('ds_seller_name') . "【" . $info['store_name'] . "】" . lang('admin_storedeposit_pay_state') . ((input('param.verify_state') == 1) ? lang('admin_storedeposit_payed') : lang('admin_storedeposit_cancel')) . ':' . input('param.verify_reason');
  179. try {
  180. Db::startTrans();
  181. $storedepositlog_model->changeStoredeposit($data);
  182. //修提现状态
  183. if (!$storedepositlog_model->editStoredepositlog(array('storedepositlog_id' => $id, 'storedepositlog_state' => Storedepositlog::STATE_PAYING), array('storedepositlog_state' => $storedepositlog_state))) {
  184. throw new \think\Exception(lang('admin_storedeposit_pay_state') . lang('ds_update') . lang('ds_fail'), 10006);
  185. }
  186. Db::commit();
  187. $this->log($data['storedepositlog_desc'], 1);
  188. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  189. } catch (\Exception $e) {
  190. Db::rollback();
  191. $this->log($data['storedepositlog_desc'], 0);
  192. $this->error($e->getMessage());
  193. }
  194. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  195. }
  196. }
  197. /*
  198. * 调节资金
  199. */
  200. public function adjust()
  201. {
  202. if (!(request()->isPost())) {
  203. $store_id = intval(input('get.store_id'));
  204. if ($store_id > 0) {
  205. $condition = array();
  206. $condition[] = array('store_id', '=', $store_id);
  207. $store = model('store')->getStoreInfo($condition);
  208. if (!empty($store)) {
  209. View::assign('store_info', $store);
  210. }
  211. }
  212. return View::fetch();
  213. } else {
  214. $data = array(
  215. 'store_id' => input('post.store_id'),
  216. 'amount' => input('post.amount'),
  217. 'operatetype' => input('post.operatetype'),
  218. 'lg_desc' => input('post.lg_desc'),
  219. );
  220. $storedeposit_validate = ds_validate('storedeposit');
  221. if (!$storedeposit_validate->scene('adjust')->check($data)) {
  222. $this->error($storedeposit_validate->getError());
  223. }
  224. $money = abs(floatval(input('post.amount')));
  225. if ($money <= 0) {
  226. $this->error(lang('admin_storedeposit_artificial_pricemin_error'));
  227. }
  228. //查询店主信息
  229. $store_mod = model('store');
  230. $store_id = intval(input('post.store_id'));
  231. $operatetype = input('post.operatetype');
  232. $store_info = $store_mod->getStoreInfo(array('store_id' => $store_id));
  233. if (!is_array($store_info) || count($store_info) <= 0) {
  234. $this->error(lang('admin_storedeposit_userrecord_error'), 'Storedeposit/adjust');
  235. }
  236. $store_avaliable_deposit = floatval($store_info['store_avaliable_deposit']);
  237. $store_freeze_deposit = floatval($store_info['store_freeze_deposit']);
  238. if ($operatetype == 2 && $money > $store_avaliable_deposit) {
  239. $this->error(lang('admin_storedeposit_artificial_shortprice_error') . $store_avaliable_deposit, 'Storedeposit/adjust');
  240. }
  241. $storedepositlog_model = model('storedepositlog');
  242. #生成对应订单号
  243. $admininfo = $this->getAdminInfo();
  244. $data = array(
  245. 'store_id' => $store_info['store_id'],
  246. 'store_name' => $store_info['store_name'],
  247. 'storedepositlog_type' => Storedepositlog::TYPE_ADMIN,
  248. 'storedepositlog_state' => Storedepositlog::STATE_VALID,
  249. 'storedepositlog_add_time' => TIMESTAMP,
  250. );
  251. switch ($operatetype) {
  252. case 1:
  253. $data['store_avaliable_deposit'] = $money;
  254. $log_msg = lang('order_admin_operator') . "【" . $admininfo['admin_name'] . "】" . lang('ds_handle') . lang('ds_seller_name') . "【" . $store_info['store_name'] . "】" . lang('ds_store_deposit') . "【" . lang('admin_storedeposit_artificial_operatetype_add') . "】," . lang('admin_storedeposit_price') . $money;
  255. break;
  256. case 2:
  257. $data['store_avaliable_deposit'] = -$money;
  258. $log_msg = lang('order_admin_operator') . "【" . $admininfo['admin_name'] . "】" . lang('ds_handle') . lang('ds_seller_name') . "【" . $store_info['store_name'] . "】" . lang('ds_store_deposit') . "【" . lang('admin_storedeposit_artificial_operatetype_reduce') . "】," . lang('admin_storedeposit_price') . $money;
  259. break;
  260. default:
  261. $this->error(lang('ds_common_op_fail'), 'Storedeposit/index');
  262. break;
  263. }
  264. $data['storedepositlog_desc'] = $log_msg;
  265. try {
  266. Db::startTrans();
  267. $storedepositlog_model->changeStoredeposit($data);
  268. Db::commit();
  269. $this->log($log_msg, 1);
  270. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  271. } catch (\Exception $e) {
  272. Db::rollback();
  273. $this->log($log_msg, 0);
  274. $this->error($e->getMessage(), 'Storedeposit/index');
  275. }
  276. }
  277. }
  278. //取得店主信息
  279. public function checkseller()
  280. {
  281. $name = input('post.name');
  282. if (!$name) {
  283. exit(json_encode(array('id' => 0)));
  284. die;
  285. }
  286. $obj_store = model('store');
  287. $store_info = $obj_store->getStoreInfo(array('seller_name' => $name));
  288. if (is_array($store_info) && count($store_info) > 0) {
  289. exit(json_encode(array('id' => $store_info['store_id'], 'name' => $store_info['seller_name'], 'store_avaliable_deposit' => $store_info['store_avaliable_deposit'], 'store_freeze_deposit' => $store_info['store_freeze_deposit'])));
  290. } else {
  291. exit(json_encode(array('id' => 0)));
  292. }
  293. }
  294. /**
  295. * 获取卖家栏目列表,针对控制器下的栏目
  296. */
  297. protected function getAdminItemList()
  298. {
  299. $menu_array = array(
  300. array(
  301. 'name' => 'index',
  302. 'text' => lang('admin_storedeposit_loglist'),
  303. 'url' => (string)url('Storedeposit/index')
  304. ),
  305. array(
  306. 'name' => 'withdraw_list',
  307. 'text' => lang('admin_storedeposit_cashmanage'),
  308. 'url' => (string)url('Storedeposit/withdraw_list')
  309. ),
  310. array(
  311. 'name' => 'adjust',
  312. 'text' => lang('admin_storedeposit_adjust'),
  313. 'url' => "javascript:dsLayerOpen('" . (string)url('Storedeposit/adjust') . "','" . lang('admin_storedeposit_adjust') . "')"
  314. ),
  315. );
  316. return $menu_array;
  317. }
  318. }