EventSignUp.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\model\ump;
  12. use traits\ModelTrait;
  13. use basic\ModelBasic;
  14. use think\Db;
  15. use app\admin\model\user\User;
  16. use service\PHPExcelService;
  17. class EventSignUp extends ModelBasic
  18. {
  19. use ModelTrait;
  20. public static function getUserSignUpAll($where){
  21. $model = new self;
  22. $model = $model->where('activity_id',$where['id']);
  23. if($where['real_name']!='') $model = $model->where('order_id','like',"%$where[real_name]%");
  24. $model = self::statusByWhere($where['status'],$model);
  25. $model = $model->where('is_del',0);
  26. $model = $model->order('add_time DESC');
  27. if (isset($where['excel']) && $where['excel'] == 1) {
  28. $data = ($data = $model->select()) && count($data) ? $data->toArray() : [];
  29. } else {
  30. $data = $model->page((int)$where['page'],(int)$where['limit'])->select();
  31. $data = count($data) ? $data->toArray() : [];
  32. }
  33. foreach ($data as &$v){
  34. $v['addTime']=date('Y-m-d H:i:s',$v['add_time']);
  35. $v['is_fill']=EventRegistration::where('id',$v['activity_id'])->value('is_fill');
  36. if($v['pay_type']=='weixin'){
  37. $v['pay_type']='微信支付';
  38. }elseif ($v['pay_type']=='zhifubao'){
  39. $v['pay_type']='支付宝支付';
  40. }elseif ($v['pay_type']=='yue'){
  41. $v['pay_type']='余额支付';
  42. }else{
  43. $v['pay_type']='其他支付';
  44. }
  45. if($v['status']){
  46. $v['write_off']='已核销';
  47. }else{
  48. $v['write_off']='未核销';
  49. }
  50. if($v['user_info'] && $v['is_fill']){
  51. $user_info=json_decode($v['user_info']);
  52. if($user_info->sex==1){
  53. $sex='男';
  54. }elseif($user_info->sex==2){
  55. $sex='女';
  56. }else{
  57. $sex='保密';
  58. }
  59. $v['userInfo']=<<<HTML
  60. <b >姓名:$user_info->name</b><br/>
  61. <b >电话:$user_info->phone</b><br/>
  62. <b >性别:$sex</b><br/>
  63. <b >年龄:$user_info->age</b><br/>
  64. <b >公司:$user_info->company</b><br/>
  65. <b >备注:$user_info->remarks</b><br/>
  66. HTML;
  67. }else{
  68. $v['userInfo']='无';
  69. }
  70. }
  71. if (isset($where['excel']) && $where['excel'] == 1) {
  72. self::SaveExcel($data);
  73. }
  74. $count = self::where('activity_id',$where['id'])->where('is_del',0)->count();
  75. return compact('data','count');
  76. }
  77. public static function statusByWhere($status,$model = null,$alert='')
  78. {
  79. if($model == null) $model = new self;
  80. if('' === $status)
  81. return $model->where($alert.'paid',1);
  82. else if($status == 1)//已支付 未核销
  83. return $model->where($alert.'paid',1)->where($alert.'status',0);
  84. else if($status == 2)//已支付 已核销
  85. return $model->where($alert.'paid',1)->where($alert.'status',1);
  86. else
  87. return $model->where($alert.'paid',1);
  88. }
  89. /**
  90. * 保存并下载excel
  91. * $list array
  92. * return
  93. */
  94. public static function SaveExcel($list)
  95. {
  96. $export = [];
  97. foreach ($list as $index => $item) {
  98. $title =EventRegistration::where('id',$item['activity_id'])->value('title');
  99. if($item['user_info'] && $item['is_fill']){
  100. $user_info=json_decode($item['user_info']);
  101. if($user_info->sex==1){
  102. $sex='男';
  103. }elseif($user_info->sex==2){
  104. $sex='女';
  105. }else{
  106. $sex='保密';
  107. }
  108. $userInfo='姓名:'.$user_info->name."\n"
  109. .'电话:'.$user_info->phone."\n"
  110. .'性别:'.$sex."\n"
  111. .'年龄:'.$user_info->age."\n"
  112. .'公司:'.$user_info->company."\n"
  113. .'备注:'.$user_info->remarks;
  114. }else{
  115. $userInfo='无';
  116. }
  117. $export[] = [
  118. $item['order_id'],
  119. $title,
  120. $userInfo,
  121. $item['pay_type'],
  122. $item['pay_price'],
  123. $item['status'] == 1 ? '已核销' : '未核销',
  124. date('Y/md H:i', $item['add_time'])
  125. ];
  126. }
  127. PHPExcelService::setExcelHeader(['订单号','活动标题','报名信息','支付方式','支付金额', '状态', '报名时间'])
  128. ->setExcelTile('报名导出', '报名信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time()))
  129. ->setExcelContent($export)
  130. ->ExcelSave();
  131. }
  132. public static function getBadge($where)
  133. {
  134. $price = self::getOrderPrice($where);
  135. return [
  136. [
  137. 'name' => '订单数量',
  138. 'field' => '件',
  139. 'count' => $price['order_sum'],
  140. 'background_color' => 'layui-bg-blue',
  141. 'col' => 2
  142. ],
  143. [
  144. 'name' => '订单总金额',
  145. 'field' => '元',
  146. 'count' => $price['pay_price'],
  147. 'background_color' => 'layui-bg-blue',
  148. 'col' => 2
  149. ],
  150. [
  151. 'name' => '微信支付金额',
  152. 'field' => '元',
  153. 'count' => $price['pay_price_wx'],
  154. 'background_color' => 'layui-bg-blue',
  155. 'col' => 2
  156. ],
  157. [
  158. 'name' => '余额支付金额',
  159. 'field' => '元',
  160. 'count' => $price['pay_price_yue'],
  161. 'background_color' => 'layui-bg-blue',
  162. 'col' => 2
  163. ],
  164. [
  165. 'name' => '支付宝支付金额',
  166. 'field' => '元',
  167. 'count' => $price['pay_price_zhifubao'],
  168. 'background_color' => 'layui-bg-blue',
  169. 'col' => 2
  170. ]
  171. ];
  172. }
  173. /**
  174. * 处理订单金额
  175. * @param $where
  176. * @return array
  177. */
  178. public static function getOrderPrice($where)
  179. {
  180. $model = new self;
  181. $price = array();
  182. $price['pay_price'] = 0;//支付金额
  183. $price['pay_price_wx'] = 0;//微信支付金额
  184. $price['pay_price_yue'] = 0;//余额支付金额
  185. $price['pay_price_zhifubao'] = 0;//支付宝支付金额
  186. $list = self::statusByWhere($where, $model)->where('activity_id',$where['id'])->field([
  187. 'sum(pay_price) as pay_price'])->find()->toArray();
  188. $price['pay_price'] = $list['pay_price'];//支付金额
  189. $list = self::statusByWhere($where, $model)->where('activity_id',$where['id'])->field('sum(pay_price) as pay_price,pay_type')->group('pay_type')->select()->toArray();
  190. foreach ($list as $v) {
  191. if ($v['pay_type'] == 'weixin') {
  192. $price['pay_price_wx'] = $v['pay_price'];
  193. } elseif ($v['pay_type'] == 'yue') {
  194. $price['pay_price_yue'] = $v['pay_price'];
  195. } elseif ($v['pay_type'] == 'zhifubao') {
  196. $price['pay_price_zhifubao'] = $v['pay_price'];
  197. }
  198. }
  199. $price['order_sum'] =self::statusByWhere($where, $model)->where('activity_id',$where['id'])->count();
  200. return $price;
  201. }
  202. }