Vrrefund.php 13 KB

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