Storemoney.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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\Storemoneylog;
  7. /**
  8. *
  9. *
  10. * ----------------------------------------------------------------------------
  11. *
  12. * 控制器
  13. */
  14. class Storemoney extends AdminControl
  15. {
  16. public function initialize()
  17. {
  18. parent::initialize();
  19. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/storemoney.lang.php');
  20. }
  21. /*
  22. * 资金明细
  23. */
  24. public function index()
  25. {
  26. $condition = array();
  27. $stime = input('get.stime');
  28. $etime = input('get.etime');
  29. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $stime);
  30. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $etime);
  31. $start_unixtime = $if_start_date ? strtotime($stime) : null;
  32. $end_unixtime = $if_end_date ? (strtotime($etime) + 86399) : null;
  33. if ($start_unixtime) {
  34. $condition[] = array('storemoneylog_add_time', '>=', $start_unixtime);
  35. }
  36. if ($end_unixtime) {
  37. $condition[] = array('storemoneylog_add_time', '<=', $end_unixtime);
  38. }
  39. $mname = input('get.mname');
  40. if (!empty($mname)) {
  41. $condition[] = array('store_name', 'like', '%' . $mname . '%');
  42. }
  43. $storemoneylog_model = model('storemoneylog');
  44. $list_log = $storemoneylog_model->getStoremoneylogList($condition, 10, '*', 'storemoneylog_id desc');
  45. View::assign('show_page', $storemoneylog_model->page_info->render());
  46. View::assign('list_log', $list_log);
  47. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  48. $this->setAdminCurItem('index');
  49. return View::fetch();
  50. }
  51. /*
  52. * 提现列表
  53. */
  54. public function withdraw_list()
  55. {
  56. $condition = array();
  57. $condition[] = array('storemoneylog_type', '=', Storemoneylog::TYPE_WITHDRAW);
  58. $paystate_search = input('param.paystate_search');
  59. if (isset($paystate_search) && $paystate_search !== '') {
  60. $condition[] = array('storemoneylog_state', '=', intval($paystate_search));
  61. }
  62. $storemoneylog_model = model('storemoneylog');
  63. $withdraw_list = $storemoneylog_model->getStoremoneylogList($condition, 10, '*', 'storemoneylog_id desc');
  64. View::assign('show_page', $storemoneylog_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_set()
  74. {
  75. $config_model = model('config');
  76. if (!request()->isPost()) {
  77. $list_setting = rkcache('config', true);
  78. View::assign('list_setting', $list_setting);
  79. $this->setAdminCurItem('withdraw_set');
  80. return View::fetch();
  81. } else {
  82. $update_array = array(
  83. 'store_withdraw_min' => abs(round(input('post.store_withdraw_min'), 2)),
  84. 'store_withdraw_max' => abs(round(input('post.store_withdraw_max'), 2)),
  85. 'store_withdraw_cycle' => abs(intval(input('post.store_withdraw_cycle'))),
  86. );
  87. $result = $config_model->editConfig($update_array);
  88. if ($result) {
  89. $this->log(lang('ds_update') . lang('admin_storemoney_withdraw_set'), 1);
  90. $this->success(lang('ds_common_op_succ'), 'Storemoney/withdraw_set');
  91. } else {
  92. $this->log(lang('ds_update') . lang('admin_storemoney_withdraw_set'), 0);
  93. }
  94. }
  95. }
  96. /**
  97. * 查看提现信息
  98. */
  99. public function withdraw_view()
  100. {
  101. $id = intval(input('param.id'));
  102. if ($id <= 0) {
  103. $this->error(lang('param_error'));
  104. }
  105. $storemoneylog_model = model('storemoneylog');
  106. $condition = array();
  107. $condition[] = array('storemoneylog_id', '=', $id);
  108. $info = $storemoneylog_model->getStoremoneylogInfo($condition);
  109. if (!is_array($info) || count($info) < 0) {
  110. $this->error(lang('admin_storemoney_record_error'));
  111. }
  112. if (!request()->isPost()) {
  113. View::assign('info', $info);
  114. return View::fetch();
  115. } else {
  116. if (!input('param.verify_reason')) {
  117. $this->error(lang('ds_none_input') . lang('admin_storemoney_remark'));
  118. }
  119. $data = array(
  120. 'store_id' => $info['store_id'],
  121. 'store_name' => $info['store_name'],
  122. 'storemoneylog_type' => Storemoneylog::TYPE_VERIFY,
  123. 'storemoneylog_state' => Storemoneylog::STATE_VALID,
  124. 'storemoneylog_add_time' => TIMESTAMP,
  125. );
  126. if (input('param.verify_state') == 1) { //通过
  127. $data['store_freeze_money'] = -$info['store_freeze_money'];
  128. $storemoneylog_state = Storemoneylog::STATE_AGREE;
  129. } else {
  130. $data['store_avaliable_money'] = $info['store_freeze_money'];
  131. $data['store_freeze_money'] = -$info['store_freeze_money'];
  132. $storemoneylog_state = Storemoneylog::STATE_REJECT;
  133. }
  134. $admininfo = $this->getAdminInfo();
  135. $data['storemoneylog_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_storemoney_log_stage_cash') . ':' . input('param.verify_reason');
  136. try {
  137. Db::startTrans();
  138. $storemoneylog_model->changeStoremoney($data);
  139. //修提现状态
  140. if (!$storemoneylog_model->editStoremoneylog(array('storemoneylog_id' => $id, 'storemoneylog_state' => Storemoneylog::STATE_WAIT), array('storemoneylog_state' => $storemoneylog_state))) {
  141. throw new \think\Exception(lang('admin_storemoney_cash_edit_fail'), 10006);
  142. }
  143. Db::commit();
  144. $this->log($data['storemoneylog_desc'], 1);
  145. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  146. } catch (\Exception $e) {
  147. Db::rollback();
  148. $this->log($data['storemoneylog_desc'], 0);
  149. $this->error($e->getMessage());
  150. }
  151. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  152. }
  153. }
  154. /*
  155. * 调节资金
  156. */
  157. public function adjust()
  158. {
  159. if (!(request()->isPost())) {
  160. $store_id = intval(input('get.store_id'));
  161. if ($store_id > 0) {
  162. $condition = array();
  163. $condition[] = array('store_id', '=', $store_id);
  164. $store = model('store')->getStoreInfo($condition);
  165. if (!empty($store)) {
  166. View::assign('store_info', $store);
  167. }
  168. }
  169. return View::fetch();
  170. } else {
  171. $data = array(
  172. 'store_id' => input('post.store_id'),
  173. 'amount' => input('post.amount'),
  174. 'operatetype' => input('post.operatetype'),
  175. 'lg_desc' => input('post.lg_desc'),
  176. );
  177. $storedeposit_validate = ds_validate('storedeposit');
  178. if (!$storedeposit_validate->scene('adjust')->check($data)) {
  179. $this->error($storedeposit_validate->getError());
  180. }
  181. $money = abs(floatval(input('post.amount')));
  182. if ($money <= 0) {
  183. $this->error(lang('admin_storemoney_artificial_pricemin_error'));
  184. }
  185. //查询店主信息
  186. $store_mod = model('store');
  187. $store_id = intval(input('post.store_id'));
  188. $operatetype = input('post.operatetype');
  189. $store_info = $store_mod->getStoreInfo(array('store_id' => $store_id));
  190. if (!is_array($store_info) || count($store_info) <= 0) {
  191. $this->error(lang('admin_storemoney_userrecord_error'), 'Storemoney/adjust');
  192. }
  193. $store_avaliable_money = floatval($store_info['store_avaliable_money']);
  194. $store_freeze_money = floatval($store_info['store_freeze_money']);
  195. if ($operatetype == 2 && $money > $store_avaliable_money) {
  196. $this->error(lang('admin_storemoney_artificial_shortprice_error') . $store_avaliable_money, 'Storemoney/adjust');
  197. }
  198. if ($operatetype == 3 && $money > $store_avaliable_money) {
  199. $this->error(lang('admin_storemoney_artificial_shortfreezeprice_error') . $store_avaliable_money, 'Storemoney/adjust');
  200. }
  201. if ($operatetype == 4 && $money > $store_freeze_money) {
  202. $this->error(lang('admin_storemoney_artificial_shortfreezeprice_error') . $store_freeze_money, 'Storemoney/adjust');
  203. }
  204. $storemoneylog_model = model('storemoneylog');
  205. #生成对应订单号
  206. $admininfo = $this->getAdminInfo();
  207. $data = array(
  208. 'store_id' => $store_info['store_id'],
  209. 'store_name' => $store_info['store_name'],
  210. 'storemoneylog_type' => Storemoneylog::TYPE_ADMIN,
  211. 'storemoneylog_state' => Storemoneylog::STATE_VALID,
  212. 'storemoneylog_add_time' => TIMESTAMP,
  213. );
  214. switch ($operatetype) {
  215. case 1:
  216. $data['store_avaliable_money'] = $money;
  217. $log_msg = lang('order_admin_operator') . "【" . $admininfo['admin_name'] . "】" . lang('ds_handle') . lang('ds_seller_name') . "【" . $store_info['store_name'] . "】" . lang('ds_store_money') . "【" . lang('admin_storemoney_artificial_operatetype_add') . "】," . lang('admin_storemoney_price') . $money;
  218. break;
  219. case 2:
  220. $data['store_avaliable_money'] = -$money;
  221. $log_msg = lang('order_admin_operator') . "【" . $admininfo['admin_name'] . "】" . lang('ds_handle') . lang('ds_seller_name') . "【" . $store_info['store_name'] . "】" . lang('ds_store_money') . "【" . lang('admin_storemoney_artificial_operatetype_reduce') . "】," . lang('admin_storemoney_price') . $money;
  222. break;
  223. case 3:
  224. $data['store_avaliable_money'] = -$money;
  225. $data['store_freeze_money'] = $money;
  226. $log_msg = lang('order_admin_operator') . "【" . $admininfo['admin_name'] . "】" . lang('ds_handle') . lang('ds_seller_name') . "【" . $store_info['store_name'] . "】" . lang('ds_store_money') . "【" . lang('admin_storemoney_artificial_operatetype_freeze') . "】," . lang('admin_storemoney_price') . $money;
  227. break;
  228. case 4:
  229. $data['store_avaliable_money'] = $money;
  230. $data['store_freeze_money'] = -$money;
  231. $log_msg = lang('order_admin_operator') . "【" . $admininfo['admin_name'] . "】" . lang('ds_handle') . lang('ds_seller_name') . "【" . $store_info['store_name'] . "】" . lang('ds_store_money') . "【" . lang('admin_storemoney_artificial_operatetype_unfreeze') . "】," . lang('admin_storemoney_price') . $money;
  232. break;
  233. default:
  234. $this->error(lang('ds_common_op_fail'), 'Storemoney/index');
  235. break;
  236. }
  237. $data['storemoneylog_desc'] = $log_msg;
  238. try {
  239. Db::startTrans();
  240. $storemoneylog_model->changeStoremoney($data);
  241. Db::commit();
  242. $this->log($log_msg, 1);
  243. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  244. } catch (\Exception $e) {
  245. Db::rollback();
  246. $this->log($log_msg, 0);
  247. $this->error($e->getMessage(), 'Storemoney/index');
  248. }
  249. }
  250. }
  251. //取得店主信息
  252. public function checkseller()
  253. {
  254. $name = input('post.name');
  255. if (!$name) {
  256. exit(json_encode(array('id' => 0)));
  257. die;
  258. }
  259. $obj_store = model('store');
  260. $store_info = $obj_store->getStoreInfo(array('seller_name' => $name));
  261. if (is_array($store_info) && count($store_info) > 0) {
  262. exit(json_encode(array('id' => $store_info['store_id'], 'name' => $store_info['seller_name'], 'store_avaliable_money' => $store_info['store_avaliable_money'], 'store_freeze_money' => $store_info['store_freeze_money'])));
  263. } else {
  264. exit(json_encode(array('id' => 0)));
  265. }
  266. }
  267. /**
  268. * 获取卖家栏目列表,针对控制器下的栏目
  269. */
  270. protected function getAdminItemList()
  271. {
  272. $menu_array = array(
  273. array(
  274. 'name' => 'index',
  275. 'text' => lang('admin_storemoney_loglist'),
  276. 'url' => (string)url('Storemoney/index')
  277. ),
  278. array(
  279. 'name' => 'withdraw_list',
  280. 'text' => lang('admin_storemoney_cashmanage'),
  281. 'url' => (string)url('Storemoney/withdraw_list')
  282. ),
  283. array(
  284. 'name' => 'withdraw_set',
  285. 'text' => lang('admin_storemoney_withdraw_set'),
  286. 'url' => (string)url('Storemoney/withdraw_set')
  287. ),
  288. array(
  289. 'name' => 'adjust',
  290. 'text' => lang('admin_storemoney_adjust'),
  291. 'url' => "javascript:dsLayerOpen('" . (string)url('Storemoney/adjust') . "','" . lang('admin_storemoney_adjust') . "')"
  292. ),
  293. );
  294. return $menu_array;
  295. }
  296. }