Storedeposit.php 16 KB

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