Vrrefund.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 控制器
  11. */
  12. class Vrrefund extends AdminControl
  13. {
  14. const EXPORT_SIZE = 1000;
  15. public function initialize()
  16. {
  17. parent::initialize();
  18. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/vrrefund.lang.php');
  19. $this->getRefundStateArray();
  20. }
  21. /**
  22. * 向模板页面输出退款状态
  23. *
  24. * @param
  25. * @return array
  26. */
  27. public function getRefundStateArray($type = 'all')
  28. {
  29. $admin_array = array(
  30. '1' => lang('refund_state_confirm'),
  31. '2' => lang('refund_state_yes'),
  32. '3' => lang('refund_state_no')
  33. ); //退款状态:1为待审核,2为同意,3为不同意
  34. View::assign('admin_array', $admin_array);
  35. $state_data = array(
  36. 'admin' => $admin_array
  37. );
  38. if ($type == 'all')
  39. return $state_data; //返回所有
  40. return $state_data[$type];
  41. }
  42. /**
  43. * 待处理列表
  44. */
  45. public function refund_manage()
  46. {
  47. $vrrefund_model = model('vrrefund');
  48. $condition = array();
  49. $condition[] = array('admin_state', '=', '1'); //状态:1为待审核,2为同意,3为不同意
  50. $keyword_type = array('order_sn', 'refund_sn', 'store_name', 'buyer_name', 'goods_name');
  51. $key = input('get.key');
  52. $type = input('get.type');
  53. if (trim($key) != '' && in_array($type, $keyword_type)) {
  54. $condition[] = array($type, 'like', '%' . $type . '%');
  55. }
  56. $add_time_from = trim(input('get.add_time_from'));
  57. $add_time_to = trim(input('get.add_time_to'));
  58. if ($add_time_from != '') {
  59. $add_time_from = strtotime($add_time_from);
  60. if ($add_time_from !== false) {
  61. $condition[] = array('add_time', '>=', $add_time_from);
  62. }
  63. }
  64. if ($add_time_to != '') {
  65. $add_time_to = strtotime($add_time_to);
  66. if ($add_time_to !== false) {
  67. $add_time_to = $add_time_to + 86399;
  68. $condition[] = array('add_time', '<=', $add_time_to);
  69. }
  70. }
  71. $refund_list = $vrrefund_model->getVrrefundList($condition, 10);
  72. View::assign('refund_list', $refund_list);
  73. View::assign('show_page', $vrrefund_model->page_info->render());
  74. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  75. $this->setAdminCurItem('refund_manage');
  76. return View::fetch('vr_refund_manage_list');
  77. }
  78. /**
  79. * 所有记录
  80. */
  81. public function refund_all()
  82. {
  83. $vrrefund_model = model('vrrefund');
  84. $condition = array();
  85. $keyword_type = array('order_sn', 'refund_sn', 'store_name', 'buyer_name', 'goods_name');
  86. $key = input('get.key');
  87. $type = input('get.type');
  88. if (trim($key) != '' && in_array($type, $keyword_type)) {
  89. $condition[] = array($type, 'like', '%' . $key . '%');
  90. }
  91. $add_time_from = trim(input('get.add_time_from'));
  92. $add_time_to = trim(input('get.add_time_to'));
  93. if ($add_time_from != '') {
  94. $add_time_from = strtotime($add_time_from);
  95. if ($add_time_from !== false) {
  96. $condition[] = array('add_time', '>=', $add_time_from);
  97. }
  98. }
  99. if ($add_time_to != '') {
  100. $add_time_to = strtotime($add_time_to);
  101. if ($add_time_to !== false) {
  102. $add_time_to = $add_time_to + 86399;
  103. $condition[] = array('add_time', '<=', $add_time_to);
  104. }
  105. }
  106. $refund_list = $vrrefund_model->getVrrefundList($condition, 10);
  107. View::assign('refund_list', $refund_list);
  108. View::assign('show_page', $vrrefund_model->page_info->render());
  109. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  110. $this->setAdminCurItem('refund_all');
  111. return View::fetch('vr_refund_all_list');
  112. }
  113. /**
  114. * 审核页
  115. *
  116. */
  117. public function edit()
  118. {
  119. $refund_id = intval(input('param.refund_id'));
  120. $vrrefund_model = model('vrrefund');
  121. $condition = array();
  122. $condition[] = array('refund_id', '=', $refund_id);
  123. $refund = $vrrefund_model->getOneVrrefund($condition);
  124. if (!(request()->isPost())) {
  125. View::assign('refund', $refund);
  126. $code_array = explode(',', $refund['redeemcode_sn']);
  127. View::assign('code_array', $code_array);
  128. return View::fetch('vr_refund_edit');
  129. } else {
  130. if ($refund['admin_state'] != '1') { //检查状态,防止页面刷新不及时造成数据错误
  131. $this->error(lang('ds_common_save_fail'));
  132. }
  133. $refund['admin_time'] = TIMESTAMP;
  134. $refund['admin_state'] = '2';
  135. if (input('post.admin_state') == '3') {
  136. $refund['admin_state'] = '3';
  137. }
  138. $refund['admin_message'] = input('post.admin_message');
  139. $state = $vrrefund_model->editVrorderRefund($refund);
  140. if ($state) {
  141. // 发送买家消息
  142. $param = array();
  143. $param['code'] = 'refund_return_notice';
  144. $param['member_id'] = $refund['buyer_id'];
  145. //阿里短信参数
  146. $param['ali_param'] = array(
  147. 'refund_sn' => $refund['refund_sn']
  148. );
  149. $param['ten_param'] = array(
  150. $refund['refund_sn']
  151. );
  152. $param['param'] = array_merge($param['ali_param'], array(
  153. 'refund_url' => HOME_SITE_URL . '/Membervrrefund/view?refund_id=' . $refund['refund_id'],
  154. ));
  155. //微信模板消息
  156. $param['weixin_param'] = array(
  157. 'url' => config('ds_config.h5_site_url') . '/pages/member/vrrefund/VrRefundView?refund_id=' . $refund['refund_id'],
  158. 'data' => array(
  159. "keyword1" => array(
  160. "value" => $refund['order_sn'],
  161. "color" => "#333"
  162. ),
  163. "keyword2" => array(
  164. "value" => $refund['refund_amount'],
  165. "color" => "#333"
  166. )
  167. ),
  168. );
  169. model('cron')->addCron(array('cron_exetime' => TIMESTAMP, 'cron_type' => 'sendMemberMsg', 'cron_value' => serialize($param)));
  170. $this->log('虚拟订单退款审核,退款编号' . $refund['refund_sn']);
  171. dsLayerOpenSuccess(lang('ds_common_save_succ'));
  172. } else {
  173. $this->error(lang('ds_common_save_fail'));
  174. }
  175. }
  176. }
  177. /**
  178. * 查看页
  179. *
  180. */
  181. public function view()
  182. {
  183. $vrrefund_model = model('vrrefund');
  184. $refund_id = intval(input('param.refund_id'));
  185. $condition = array();
  186. $condition[] = array('refund_id', '=', $refund_id);
  187. $refund = $vrrefund_model->getOneVrrefund($condition);
  188. View::assign('refund', $refund);
  189. $code_array = explode(',', $refund['redeemcode_sn']);
  190. View::assign('code_array', $code_array);
  191. return View::fetch('vr_refund_view');
  192. }
  193. /**
  194. * 导出
  195. *
  196. */
  197. public function export_step1()
  198. {
  199. $vrrefund_model = model('vrrefund');
  200. $condition = array();
  201. $keyword_type = array('order_sn', 'refund_sn', 'store_name', 'buyer_name', 'goods_name');
  202. $key = input('get.key');
  203. $type = input('get.type');
  204. if (trim($key) != '' && in_array($type, $keyword_type)) {
  205. $condition[] = array($type, 'like', '%' . $key . '%');
  206. }
  207. $add_time_from = trim(input('get.add_time_from'));
  208. $add_time_to = trim(input('get.add_time_to'));
  209. if ($add_time_from != '') {
  210. $add_time_from = strtotime($add_time_from);
  211. if ($add_time_from !== false) {
  212. $condition[] = array('add_time', '>=', $add_time_from);
  213. }
  214. }
  215. if ($add_time_to != '') {
  216. $add_time_to = strtotime($add_time_to);
  217. if ($add_time_to !== false) {
  218. $add_time_to = $add_time_to + 86399;
  219. $condition[] = array('add_time', '<=', $add_time_to);
  220. }
  221. }
  222. if (!is_numeric(input('param.page'))) {
  223. $count = $vrrefund_model->getVrrefundCount($condition);
  224. $export_list = array();
  225. if ($count > self::EXPORT_SIZE) { //显示下载链接
  226. $page = ceil($count / self::EXPORT_SIZE);
  227. for ($i = 1; $i <= $page; $i++) {
  228. $limit1 = ($i - 1) * self::EXPORT_SIZE + 1;
  229. $limit2 = $i * self::EXPORT_SIZE > $count ? $count : $i * self::EXPORT_SIZE;
  230. $export_list[$i] = $limit1 . ' ~ ' . $limit2;
  231. }
  232. View::assign('export_list', $export_list);
  233. return View::fetch('/public/excel');
  234. } else { //如果数量小,直接下载
  235. $data = $vrrefund_model->getVrrefundList($condition, '', '*', 'refund_id desc', self::EXPORT_SIZE);
  236. $this->createExcel($data);
  237. }
  238. } else { //下载
  239. $limit1 = (input('param.page') - 1) * self::EXPORT_SIZE;
  240. $limit2 = self::EXPORT_SIZE;
  241. $data = $vrrefund_model->getVrrefundList($condition, $limit2, '*', 'refund_id desc');
  242. $this->createExcel($data);
  243. }
  244. }
  245. /**
  246. * 生成excel
  247. *
  248. * @param array $data
  249. */
  250. private function createExcel($data = array())
  251. {
  252. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/export.lang.php');
  253. $excel_obj = new \excel\Excel();
  254. $excel_data = array();
  255. //设置样式
  256. $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
  257. //header
  258. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('ds_order_sn'));
  259. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('ds_refund_sn'));
  260. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('ds_store_name'));
  261. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('ds_goods_name'));
  262. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('ds_buyer_name'));
  263. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_xn_add_time'));
  264. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_xn_refund_amount'));
  265. //data
  266. foreach ((array) $data as $k => $v) {
  267. $tmp = array();
  268. $tmp[] = array('data' => 'DS' . $v['order_sn']);
  269. $tmp[] = array('data' => $v['refund_sn']);
  270. $tmp[] = array('data' => $v['store_name']);
  271. $tmp[] = array('data' => $v['goods_name']);
  272. $tmp[] = array('data' => $v['buyer_name']);
  273. $tmp[] = array('data' => date('Y-m-d H:i:s', $v['add_time']));
  274. $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['refund_amount']));
  275. $excel_data[] = $tmp;
  276. }
  277. $excel_data = $excel_obj->charset($excel_data, CHARSET);
  278. $excel_obj->addArray($excel_data);
  279. $excel_obj->addWorksheet($excel_obj->charset(lang('exp_xn_refund'), CHARSET));
  280. $excel_obj->generateXML($excel_obj->charset(lang('exp_xn_refund'), CHARSET) . input('param.page') . '-' . date('Y-m-d-H', TIMESTAMP));
  281. }
  282. /**
  283. * 获取卖家栏目列表,针对控制器下的栏目
  284. */
  285. protected function getAdminItemList()
  286. {
  287. $menu_array = array(
  288. array(
  289. 'name' => 'refund_manage',
  290. 'text' => lang('refund_state_confirm'),
  291. 'url' => (string)url('Vrrefund/refund_manage')
  292. ),
  293. array(
  294. 'name' => 'refund_all',
  295. 'text' => lang('refund_all'),
  296. 'url' => (string)url('Vrrefund/refund_all')
  297. ),
  298. );
  299. if (request()->action() == 'view') {
  300. $menu_array[] = array('name' => 'vr_refund_view', 'text' => lang('ds_view'), 'url' => 'javascript:void(0)');
  301. }
  302. return $menu_array;
  303. }
  304. }