Storemoney.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. * DSMall多用户商城
  10. * ============================================================================
  11. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  12. * 网站地址: http://www.csdeshang.com
  13. * ----------------------------------------------------------------------------
  14. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  15. * 不允许对程序代码以任何形式任何目的的再发布。
  16. * ============================================================================
  17. * 控制器
  18. */
  19. class Storemoney extends AdminControl {
  20. public function initialize() {
  21. parent::initialize();
  22. Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/storemoney.lang.php');
  23. }
  24. /*
  25. * 资金明细
  26. */
  27. public function index() {
  28. $condition = array();
  29. $stime = input('get.stime');
  30. $etime = input('get.etime');
  31. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $stime);
  32. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $etime);
  33. $start_unixtime = $if_start_date ? strtotime($stime) : null;
  34. $end_unixtime = $if_end_date ? (strtotime($etime)+86399) : null;
  35. if ($start_unixtime) {
  36. $condition[] = array('storemoneylog_add_time','>=', $start_unixtime);
  37. }
  38. if ($end_unixtime) {
  39. $condition[] = array('storemoneylog_add_time','<=', $end_unixtime);
  40. }
  41. $mname = input('get.mname');
  42. if (!empty($mname)) {
  43. $condition[]=array('store_name','like','%'.$mname.'%');
  44. }
  45. $storemoneylog_model = model('storemoneylog');
  46. $list_log = $storemoneylog_model->getStoremoneylogList($condition, 10, '*', 'storemoneylog_id desc');
  47. View::assign('show_page', $storemoneylog_model->page_info->render());
  48. View::assign('list_log', $list_log);
  49. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  50. $this->setAdminCurItem('index');
  51. return View::fetch();
  52. }
  53. /*
  54. * 提现列表
  55. */
  56. public function withdraw_list() {
  57. $condition = array();
  58. $condition[] = array('storemoneylog_type','=',Storemoneylog::TYPE_WITHDRAW);
  59. $paystate_search = input('param.paystate_search');
  60. if (isset($paystate_search) && $paystate_search !== '') {
  61. $condition[] = array('storemoneylog_state','=',intval($paystate_search));
  62. }
  63. $storemoneylog_model = model('storemoneylog');
  64. $withdraw_list = $storemoneylog_model->getStoremoneylogList($condition, 10, '*', 'storemoneylog_id desc');
  65. View::assign('show_page', $storemoneylog_model->page_info->render());
  66. View::assign('withdraw_list', $withdraw_list);
  67. View::assign('filtered', input('get.') ? 1 : 0); //是否有查询条件
  68. $this->setAdminCurItem('withdraw_list');
  69. return View::fetch();
  70. }
  71. /*
  72. * 提现设置
  73. */
  74. public function withdraw_set(){
  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. $id = intval(input('param.id'));
  101. if ($id <= 0) {
  102. $this->error(lang('param_error'));
  103. }
  104. $storemoneylog_model = model('storemoneylog');
  105. $condition = array();
  106. $condition[] = array('storemoneylog_id','=',$id);
  107. $info = $storemoneylog_model->getStoremoneylogInfo($condition);
  108. if (!is_array($info) || count($info) < 0) {
  109. $this->error(lang('admin_storemoney_record_error'));
  110. }
  111. if(!request()->isPost()){
  112. View::assign('info', $info);
  113. return View::fetch();
  114. }else{
  115. if(!input('param.verify_reason')){
  116. $this->error(lang('ds_none_input').lang('admin_storemoney_remark'));
  117. }
  118. $data=array(
  119. 'store_id'=>$info['store_id'],
  120. 'store_name'=>$info['store_name'],
  121. 'storemoneylog_type'=>Storemoneylog::TYPE_VERIFY,
  122. 'storemoneylog_state'=>Storemoneylog::STATE_VALID,
  123. 'storemoneylog_add_time'=>TIMESTAMP,
  124. );
  125. if(input('param.verify_state')==1){//通过
  126. $data['store_freeze_money']=-$info['store_freeze_money'];
  127. $storemoneylog_state=Storemoneylog::STATE_AGREE;
  128. }else{
  129. $data['store_avaliable_money']=$info['store_freeze_money'];
  130. $data['store_freeze_money']=-$info['store_freeze_money'];
  131. $storemoneylog_state=Storemoneylog::STATE_REJECT;
  132. }
  133. $admininfo = $this->getAdminInfo();
  134. $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');
  135. try {
  136. Db::startTrans();
  137. $storemoneylog_model->changeStoremoney($data);
  138. //修提现状态
  139. if(!$storemoneylog_model->editStoremoneylog(array('storemoneylog_id'=>$id,'storemoneylog_state'=>Storemoneylog::STATE_WAIT),array('storemoneylog_state'=>$storemoneylog_state))){
  140. throw new \think\Exception(lang('admin_storemoney_cash_edit_fail'), 10006);
  141. }
  142. Db::commit();
  143. $this->log($data['storemoneylog_desc'], 1);
  144. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  145. } catch (\Exception $e) {
  146. Db::rollback();
  147. $this->log($data['storemoneylog_desc'], 0);
  148. $this->error($e->getMessage());
  149. }
  150. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  151. }
  152. }
  153. /*
  154. * 调节资金
  155. */
  156. public function adjust() {
  157. if (!(request()->isPost())) {
  158. $store_id = intval(input('get.store_id'));
  159. if($store_id>0){
  160. $condition = array();
  161. $condition[] = array('store_id','=',$store_id);
  162. $store = model('store')->getStoreInfo($condition);
  163. if(!empty($store)){
  164. View::assign('store_info',$store);
  165. }
  166. }
  167. return View::fetch();
  168. } else {
  169. $data = array(
  170. 'store_id' => input('post.store_id'),
  171. 'amount' => input('post.amount'),
  172. 'operatetype' => input('post.operatetype'),
  173. 'lg_desc' => input('post.lg_desc'),
  174. );
  175. $storedeposit_validate = ds_validate('storedeposit');
  176. if (!$storedeposit_validate->scene('adjust')->check($data)){
  177. $this->error($storedeposit_validate->getError());
  178. }
  179. $money = abs(floatval(input('post.amount')));
  180. if ($money <= 0) {
  181. $this->error(lang('admin_storemoney_artificial_pricemin_error'));
  182. }
  183. //查询店主信息
  184. $store_mod = model('store');
  185. $store_id = intval(input('post.store_id'));
  186. $operatetype = input('post.operatetype');
  187. $store_info = $store_mod->getStoreInfo(array('store_id' => $store_id));
  188. if (!is_array($store_info) || count($store_info) <= 0) {
  189. $this->error(lang('admin_storemoney_userrecord_error'), 'Storemoney/adjust');
  190. }
  191. $store_avaliable_money = floatval($store_info['store_avaliable_money']);
  192. $store_freeze_money = floatval($store_info['store_freeze_money']);
  193. if ($operatetype == 2 && $money > $store_avaliable_money) {
  194. $this->error(lang('admin_storemoney_artificial_shortprice_error') . $store_avaliable_money, 'Storemoney/adjust');
  195. }
  196. if ($operatetype == 3 && $money > $store_avaliable_money) {
  197. $this->error(lang('admin_storemoney_artificial_shortfreezeprice_error') . $store_avaliable_money, 'Storemoney/adjust');
  198. }
  199. if ($operatetype == 4 && $money > $store_freeze_money) {
  200. $this->error(lang('admin_storemoney_artificial_shortfreezeprice_error') . $store_freeze_money, 'Storemoney/adjust');
  201. }
  202. $storemoneylog_model = model('storemoneylog');
  203. #生成对应订单号
  204. $admininfo = $this->getAdminInfo();
  205. $data=array(
  206. 'store_id'=>$store_info['store_id'],
  207. 'store_name'=>$store_info['store_name'],
  208. 'storemoneylog_type'=>Storemoneylog::TYPE_ADMIN,
  209. 'storemoneylog_state'=>Storemoneylog::STATE_VALID,
  210. 'storemoneylog_add_time'=>TIMESTAMP,
  211. );
  212. switch ($operatetype) {
  213. case 1:
  214. $data['store_avaliable_money']=$money;
  215. $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;
  216. break;
  217. case 2:
  218. $data['store_avaliable_money']=-$money;
  219. $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;
  220. break;
  221. case 3:
  222. $data['store_avaliable_money']=-$money;
  223. $data['store_freeze_money']=$money;
  224. $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;
  225. break;
  226. case 4:
  227. $data['store_avaliable_money']=$money;
  228. $data['store_freeze_money']=-$money;
  229. $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;
  230. break;
  231. default:
  232. $this->error(lang('ds_common_op_fail'), 'Storemoney/index');
  233. break;
  234. }
  235. $data['storemoneylog_desc']=$log_msg;
  236. try {
  237. Db::startTrans();
  238. $storemoneylog_model->changeStoremoney($data);
  239. Db::commit();
  240. $this->log($log_msg, 1);
  241. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  242. } catch (\Exception $e) {
  243. Db::rollback();
  244. $this->log($log_msg, 0);
  245. $this->error($e->getMessage(), 'Storemoney/index');
  246. }
  247. }
  248. }
  249. //取得店主信息
  250. public function checkseller() {
  251. $name = input('post.name');
  252. if (!$name) {
  253. exit(json_encode(array('id' => 0)));
  254. die;
  255. }
  256. $obj_store = model('store');
  257. $store_info = $obj_store->getStoreInfo(array('seller_name' => $name));
  258. if (is_array($store_info) && count($store_info) > 0) {
  259. 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'])));
  260. } else {
  261. exit(json_encode(array('id' => 0)));
  262. }
  263. }
  264. /**
  265. * 获取卖家栏目列表,针对控制器下的栏目
  266. */
  267. protected function getAdminItemList() {
  268. $menu_array = array(
  269. array(
  270. 'name' => 'index',
  271. 'text' => lang('admin_storemoney_loglist'),
  272. 'url' => (string)url('Storemoney/index')
  273. ),
  274. array(
  275. 'name' => 'withdraw_list',
  276. 'text' => lang('admin_storemoney_cashmanage'),
  277. 'url' => (string)url('Storemoney/withdraw_list')
  278. ),
  279. array(
  280. 'name' => 'withdraw_set',
  281. 'text' => lang('admin_storemoney_withdraw_set'),
  282. 'url' => (string)url('Storemoney/withdraw_set')
  283. ),
  284. array(
  285. 'name' => 'adjust',
  286. 'text' => lang('admin_storemoney_adjust'),
  287. 'url' => "javascript:dsLayerOpen('".(string)url('Storemoney/adjust')."','".lang('admin_storemoney_adjust')."')"
  288. ),
  289. );
  290. return $menu_array;
  291. }
  292. }
  293. ?>