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