Vrrefund.php 13 KB

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