Storedeposit.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  13. * 网站地址: https://www.valimart.net/
  14. * ----------------------------------------------------------------------------
  15. *
  16. * ============================================================================
  17. * 控制器
  18. */
  19. class Storedeposit extends AdminControl {
  20. public function initialize() {
  21. parent::initialize();
  22. Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/storedeposit.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('storedepositlog_add_time','>=', $start_unixtime);
  37. }
  38. if ($end_unixtime) {
  39. $condition[] = array('storedepositlog_add_time','<=', $end_unixtime);
  40. }
  41. $mname = input('get.mname');
  42. if (!empty($mname)) {
  43. $condition[]=array('store_name','like','%'.$mname.'%');
  44. }
  45. $storedepositlog_model = model('storedepositlog');
  46. $list_log = $storedepositlog_model->getStoredepositlogList($condition, 10, '*', 'storedepositlog_id desc');
  47. View::assign('show_page', $storedepositlog_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(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. $id = intval(input('param.id'));
  75. if ($id <= 0) {
  76. $this->error(lang('param_error'));
  77. }
  78. $storedepositlog_model = model('storedepositlog');
  79. $condition = array();
  80. $condition[] = array('storedepositlog_id','=',$id);
  81. $info = $storedepositlog_model->getStoredepositlogInfo($condition);
  82. if (!is_array($info) || count($info) < 0) {
  83. $this->error(lang('admin_storedeposit_record_error'));
  84. }
  85. if(!request()->isPost()){
  86. View::assign('info', $info);
  87. return View::fetch();
  88. }else{
  89. if(!input('param.verify_reason')){
  90. $this->error(lang('ds_none_input').lang('admin_storedeposit_remark'));
  91. }
  92. $data=array(
  93. 'store_id'=>$info['store_id'],
  94. 'store_name'=>$info['store_name'],
  95. 'storedepositlog_type'=>Storedepositlog::TYPE_VERIFY,
  96. 'storedepositlog_state'=>Storedepositlog::STATE_VALID,
  97. 'storedepositlog_add_time'=>TIMESTAMP,
  98. );
  99. if(input('param.verify_state')==1){//通过
  100. $data['store_freeze_deposit']=-$info['store_freeze_deposit'];
  101. $storedepositlog_state=Storedepositlog::STATE_AGREE;
  102. }else{
  103. $data['store_avaliable_deposit']=$info['store_freeze_deposit'];
  104. $data['store_freeze_deposit']=-$info['store_freeze_deposit'];
  105. $storedepositlog_state=Storedepositlog::STATE_REJECT;
  106. }
  107. $admininfo = $this->getAdminInfo();
  108. $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');
  109. try {
  110. Db::startTrans();
  111. $storedepositlog_model->changeStoredeposit($data);
  112. //修提现状态
  113. if(!$storedepositlog_model->editStoredepositlog(array('storedepositlog_id'=>$id,'storedepositlog_state'=>Storedepositlog::STATE_WAIT),array('storedepositlog_state'=>$storedepositlog_state))){
  114. throw new \think\Exception(lang('admin_storedeposit_cash_edit_fail'), 10006);
  115. }
  116. //如果是通过取出保证金,则将保证金转换为店铺可用资金
  117. if(input('param.verify_state')==1){
  118. $storemoneylog_model = model('storemoneylog');
  119. $data2=array(
  120. 'store_id'=>$info['store_id'],
  121. 'store_name'=>$info['store_name'],
  122. 'storemoneylog_type'=>Storemoneylog::TYPE_DEPOSIT_OUT,
  123. 'storemoneylog_state'=>Storemoneylog::STATE_VALID,
  124. 'storemoneylog_add_time'=>TIMESTAMP,
  125. 'store_avaliable_money'=>$info['store_freeze_deposit'],
  126. 'storemoneylog_desc'=>$data['storedepositlog_desc'],
  127. );
  128. $storemoneylog_model->changeStoremoney($data2);
  129. }
  130. Db::commit();
  131. $this->log($data['storedepositlog_desc'], 1);
  132. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  133. } catch (\Exception $e) {
  134. Db::rollback();
  135. $this->log($data['storedepositlog_desc'], 0);
  136. $this->error($e->getMessage());
  137. }
  138. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  139. }
  140. }
  141. public function recharge_view() {
  142. $id = intval(input('param.id'));
  143. if ($id <= 0) {
  144. $this->error(lang('param_error'));
  145. }
  146. $storedepositlog_model = model('storedepositlog');
  147. $condition = array();
  148. $condition[] = array('storedepositlog_id','=',$id);
  149. $info = $storedepositlog_model->getStoredepositlogInfo($condition);
  150. if (!is_array($info) || count($info) < 0) {
  151. $this->error(lang('admin_storedeposit_record_error'));
  152. }
  153. if(!request()->isPost()){
  154. View::assign('info', $info);
  155. return View::fetch();
  156. }else{
  157. if(!input('param.verify_reason')){
  158. $this->error(lang('ds_none_input').lang('admin_storedeposit_remark'));
  159. }
  160. $data=array(
  161. 'store_id'=>$info['store_id'],
  162. 'store_name'=>$info['store_name'],
  163. 'storedepositlog_type'=>Storedepositlog::TYPE_VIEW,
  164. 'storedepositlog_state'=>Storedepositlog::STATE_VALID,
  165. 'storedepositlog_add_time'=>TIMESTAMP,
  166. );
  167. if(input('param.verify_state')==1){//通过
  168. $data['store_avaliable_deposit']=$info['store_payable_deposit'];
  169. $data['store_payable_deposit']=-$info['store_payable_deposit'];
  170. $storedepositlog_state=Storedepositlog::STATE_PAYED;
  171. }else{
  172. $data['store_payable_deposit']=-$info['store_payable_deposit'];
  173. $storedepositlog_state=Storedepositlog::STATE_CANCEL;
  174. }
  175. $admininfo = $this->getAdminInfo();
  176. $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');
  177. try {
  178. Db::startTrans();
  179. $storedepositlog_model->changeStoredeposit($data);
  180. //修提现状态
  181. if(!$storedepositlog_model->editStoredepositlog(array('storedepositlog_id'=>$id,'storedepositlog_state'=>Storedepositlog::STATE_PAYING),array('storedepositlog_state'=>$storedepositlog_state))){
  182. throw new \think\Exception(lang('admin_storedeposit_pay_state').lang('ds_update').lang('ds_fail'), 10006);
  183. }
  184. Db::commit();
  185. $this->log($data['storedepositlog_desc'], 1);
  186. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  187. } catch (\Exception $e) {
  188. Db::rollback();
  189. $this->log($data['storedepositlog_desc'], 0);
  190. $this->error($e->getMessage());
  191. }
  192. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  193. }
  194. }
  195. /*
  196. * 调节资金
  197. */
  198. public function adjust() {
  199. if (!(request()->isPost())) {
  200. $store_id = intval(input('get.store_id'));
  201. if($store_id>0){
  202. $condition = array();
  203. $condition[] = array('store_id','=',$store_id);
  204. $store = model('store')->getStoreInfo($condition);
  205. if(!empty($store)){
  206. View::assign('store_info',$store);
  207. }
  208. }
  209. return View::fetch();
  210. } else {
  211. $data = array(
  212. 'store_id' => input('post.store_id'),
  213. 'amount' => input('post.amount'),
  214. 'operatetype' => input('post.operatetype'),
  215. 'lg_desc' => input('post.lg_desc'),
  216. );
  217. $storedeposit_validate = ds_validate('storedeposit');
  218. if (!$storedeposit_validate->scene('adjust')->check($data)){
  219. $this->error($storedeposit_validate->getError());
  220. }
  221. $money = abs(floatval(input('post.amount')));
  222. if ($money <= 0) {
  223. $this->error(lang('admin_storedeposit_artificial_pricemin_error'));
  224. }
  225. //查询店主信息
  226. $store_mod = model('store');
  227. $store_id = intval(input('post.store_id'));
  228. $operatetype = input('post.operatetype');
  229. $store_info = $store_mod->getStoreInfo(array('store_id' => $store_id));
  230. if (!is_array($store_info) || count($store_info) <= 0) {
  231. $this->error(lang('admin_storedeposit_userrecord_error'), 'Storedeposit/adjust');
  232. }
  233. $store_avaliable_deposit = floatval($store_info['store_avaliable_deposit']);
  234. $store_freeze_deposit = floatval($store_info['store_freeze_deposit']);
  235. if ($operatetype == 2 && $money > $store_avaliable_deposit) {
  236. $this->error(lang('admin_storedeposit_artificial_shortprice_error') . $store_avaliable_deposit, 'Storedeposit/adjust');
  237. }
  238. $storedepositlog_model = model('storedepositlog');
  239. #生成对应订单号
  240. $admininfo = $this->getAdminInfo();
  241. $data=array(
  242. 'store_id'=>$store_info['store_id'],
  243. 'store_name'=>$store_info['store_name'],
  244. 'storedepositlog_type'=>Storedepositlog::TYPE_ADMIN,
  245. 'storedepositlog_state'=>Storedepositlog::STATE_VALID,
  246. 'storedepositlog_add_time'=>TIMESTAMP,
  247. );
  248. switch ($operatetype) {
  249. case 1:
  250. $data['store_avaliable_deposit']=$money;
  251. $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;
  252. break;
  253. case 2:
  254. $data['store_avaliable_deposit']=-$money;
  255. $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;
  256. break;
  257. default:
  258. $this->error(lang('ds_common_op_fail'), 'Storedeposit/index');
  259. break;
  260. }
  261. $data['storedepositlog_desc']=$log_msg;
  262. try {
  263. Db::startTrans();
  264. $storedepositlog_model->changeStoredeposit($data);
  265. Db::commit();
  266. $this->log($log_msg, 1);
  267. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  268. } catch (\Exception $e) {
  269. Db::rollback();
  270. $this->log($log_msg, 0);
  271. $this->error($e->getMessage(), 'Storedeposit/index');
  272. }
  273. }
  274. }
  275. //取得店主信息
  276. public function checkseller() {
  277. $name = input('post.name');
  278. if (!$name) {
  279. exit(json_encode(array('id' => 0)));
  280. die;
  281. }
  282. $obj_store = model('store');
  283. $store_info = $obj_store->getStoreInfo(array('seller_name' => $name));
  284. if (is_array($store_info) && count($store_info) > 0) {
  285. 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'])));
  286. } else {
  287. exit(json_encode(array('id' => 0)));
  288. }
  289. }
  290. /**
  291. * 获取卖家栏目列表,针对控制器下的栏目
  292. */
  293. protected function getAdminItemList() {
  294. $menu_array = array(
  295. array(
  296. 'name' => 'index',
  297. 'text' => lang('admin_storedeposit_loglist'),
  298. 'url' => (string)url('Storedeposit/index')
  299. ),
  300. array(
  301. 'name' => 'withdraw_list',
  302. 'text' => lang('admin_storedeposit_cashmanage'),
  303. 'url' => (string)url('Storedeposit/withdraw_list')
  304. ),
  305. array(
  306. 'name' => 'adjust',
  307. 'text' => lang('admin_storedeposit_adjust'),
  308. 'url' => "javascript:dsLayerOpen('".(string)url('Storedeposit/adjust')."','".lang('admin_storedeposit_adjust')."')"
  309. ),
  310. );
  311. return $menu_array;
  312. }
  313. }
  314. ?>