Storemoney.php 14 KB

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