Storemoney.php 14 KB

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