UserSynth.php 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051
  1. <?php
  2. namespace app\common\service;
  3. use AlibabaCloud\Client\AlibabaCloud;
  4. use AlibabaCloud\Client\Exception\ClientException;
  5. use AlibabaCloud\Client\Exception\ServerException;
  6. use app\common\model\ActivityApply;
  7. use app\common\model\ActivityApplyItem;
  8. use app\common\model\ActivitySponsor;
  9. use app\common\model\ArticleIntro;
  10. use app\common\model\ArticleItem;
  11. use app\common\model\ArticleLike;
  12. use app\common\model\BillApply;
  13. use app\common\model\BillHeader;
  14. use app\common\model\DatumIntro;
  15. use app\common\model\DatumUrl;
  16. use app\common\model\DeliveryAddress;
  17. use app\common\model\ForumReply;
  18. use app\common\model\PlatformDemand;
  19. use app\common\model\PlatformLike;
  20. use app\common\model\Press;
  21. use app\common\model\PressComment;
  22. use app\common\model\Recruit;
  23. use app\common\model\SupplierGoods;
  24. use app\common\model\User;
  25. use app\common\model\UserCollect;
  26. use app\common\model\UserForum;
  27. use app\common\model\UserLearn;
  28. use app\common\model\UserLevelRank;
  29. use app\common\model\UserSearch;
  30. use app\common\model\UserVitality;
  31. use app\common\model\VideoIntro;
  32. use app\common\model\VideoUrl;
  33. use think\cache\driver\Redis;
  34. use think\Db;
  35. use Dm\Request\V20151123 as Dm;
  36. /**
  37. * 会员身综合管理
  38. * Class UserIdentity
  39. */
  40. class UserSynth extends SerBase
  41. {
  42. public static $ret_val = ['code' => 200 , 'msg'=>'ok','extend'=>''];
  43. // 会员活跃度
  44. public static function vitality($user_id,$type)
  45. {
  46. if($type === false) return false;
  47. $type++;
  48. $redis = new Redis();
  49. $check_key = date('Y-m-d').'_'.$user_id;
  50. // 当天是否登录
  51. if(!$redis->get($check_key)) {
  52. $redis->set($check_key,86400);
  53. $year = date('Y');
  54. $month = date('m');
  55. $day = date('d');
  56. $vitality_info= [
  57. 'user_id'=>$user_id,
  58. 'year'=>$year,
  59. 'month'=>$month,
  60. 'day'=>$day,
  61. 'day_time'=>date('Y-m-d'),
  62. 'create_at'=>date('Y-m-d H:i:s'),
  63. 'type'=>$type
  64. ];
  65. UserVitality::create($vitality_info);
  66. }
  67. }
  68. /**
  69. * 创建申请发票申请记录【申请开票】
  70. * @param $user_id
  71. * @param $order_id
  72. * @param $order_type 订单类型
  73. * @param $bill_info 发票抬头id||发票详情
  74. * @param $add_id 售货地址id
  75. * @param $send_type 物流类型1点子发票2纸质发票
  76. * @param $remark 备注
  77. * @param $order_pay 订单是否完成支付
  78. * @return array
  79. */
  80. public static function buildBillApply($user_id, $order_id, $order_type,$bill_info,$add_id,$send_type,$remark,$order_pay = 1)
  81. {
  82. $order_table = [
  83. 1=>'level_order',// 会员订单
  84. 2=>'store_order',// 商品订单
  85. 3=>'activity_apply',// 活动订单
  86. ];
  87. Db::startTrans();
  88. try {
  89. $apply_info = [
  90. 'order_id' => $order_id,
  91. 'table_name' => $order_table[$order_type],
  92. 'user_id' => $user_id,
  93. 'remark' => $remark,
  94. 'send_type' => $send_type,
  95. 'order_type' => $order_type,
  96. 'create_at' => date("Y-m-d H:i:s"),
  97. 'order_pay' => $order_pay,
  98. ];
  99. if($add_id) {
  100. $add_info = DeliveryAddress::field('id,pro_name,city_name,county_name,mer_name,detail,phone,name')->where('user_id',$user_id)->where('id',$add_id)->find();
  101. $apply_info['address_info'] = json_encode($add_info->toArray());
  102. }
  103. if(is_array($bill_info)){
  104. $apply_info['header'] = $bill_info['header'];
  105. $apply_info['type'] = $bill_info['type'];
  106. $apply_info['email'] =$bill_info['email'];
  107. // $apply_info['bank'] = $bill_info['bank'];
  108. // $apply_info['card_no'] = $bill_info['card_no'];
  109. // $apply_info['phone'] = $bill_info['phone'];
  110. $apply_info['identify_number'] = $bill_info['identify_number'];
  111. // $apply_info['address'] = $bill_info['address'];
  112. }else if($bill_info){
  113. $bill_header = BillHeader::where('id',$bill_info) ->where('user_id',$user_id)->find();
  114. if(empty($bill_header)) self::exception('发票抬头有误');
  115. $apply_info['header'] = $bill_header->header;
  116. $apply_info['email'] = $bill_header->email;
  117. $apply_info['type'] = $bill_header->type;
  118. $apply_info['identify_number'] = $bill_header->identify_number;
  119. }
  120. $order_info = Db::name($order_table[$order_type])
  121. ->where('user_id',$user_id)
  122. ->where('pay_state',1)
  123. ->where('id',$order_id)
  124. ->find();
  125. if(empty($order_info) && $order_type != 3)self::exception('订单有误');
  126. $check_info = BillApply::where('user_id',$user_id)
  127. ->where('order_id',$order_id)
  128. ->where('is_deleted',0)
  129. ->where('table_name',$order_table[$order_type])
  130. ->find();
  131. if(!empty($check_info) && $check_info->status == 1) self::exception('已开票');
  132. $apply_info = BillApply::create($apply_info);
  133. static::$ret_val['extend'] = $apply_info->id ;
  134. Db::commit();
  135. }catch (\Exception $e) {
  136. Db::rollback();
  137. static::$ret_val['code'] = 201 ;
  138. static::$ret_val['msg'] = $e->getMessage();
  139. }
  140. return static::$ret_val;
  141. }
  142. // 获取所有模块设置
  143. public static function getAllModuleTitle()
  144. {
  145. // 视频
  146. $video = VideoIntro::field('id,title,IF(id,\'video\',0) module')->with(['videoArr'=>function($query){
  147. return $query->field('id,title,video_id');
  148. }])->where(['is_deleted'=>0])->order('id desc')->select()->toArray();
  149. array_walk($video,function (&$v){
  150. $v['children'] = $v['video_arr'];
  151. unset($v['video_arr']);
  152. });
  153. // 资料
  154. $datum = DatumIntro::with(['urlArr'=>function($query){
  155. return $query->field('id,title,datum_id');
  156. }])->where(['is_deleted'=>0])->field('id,title,IF(id,\'datum\',0) module')->order('id desc')->select()->toArray();
  157. array_walk($datum,function (&$v){
  158. $v['children'] = $v['url_arr'];
  159. unset($v['url_arr']);
  160. });
  161. // 图文
  162. $article = ArticleIntro::with(['itemChildren'=>function($query){
  163. return $query->field('id,title,article_id');
  164. }])->field('id,title,IF(id,\'article\',0) module')->where(['is_deleted'=>0])->order('id asc')->select()->toArray();
  165. array_walk($article,function (&$v){
  166. $v['children'] = $v['item_children'];
  167. unset($v['item_children']);
  168. });
  169. $supplier_goods = SupplierGoods::alias('g')->field('g.id,g.supplier_id,g.name title,IF(g.id,\'supplier\',0) module')->where(['g.is_deleted'=>0])
  170. ->leftJoin('Supplier s', 's.id = g.supplier_id')->select()->toArray();
  171. // 新闻
  172. $press = Press::field('id,title,IF(id,\'press\',0) module')->where('status',1)->where('is_deleted',0)->select()->toArray();
  173. // 活动
  174. $activity = \app\common\model\Activity::field('id,title,IF(id,\'activity\',0) module')->where('status',1)->where('is_deleted',0)->select()->toArray();
  175. // 问答
  176. $forum = UserForum::field('id,title,IF(id,\'forum\',0) module')->where('status',1)->where('is_deleted',0)->select()->toArray();
  177. //需求
  178. $demand = PlatformDemand::field('id,title,IF(id,\'demand\',0) module')->where('status',1)->where('is_deleted',0)->select()->toArray();
  179. //招聘
  180. $recruit = Recruit::field('id,title,IF(id,\'recruit\',0) module')->where('status',1)->where('is_deleted',0)->select()->toArray();
  181. return array_merge($video,$datum,$article,$supplier_goods,$press,$forum,$activity,$demand,$recruit);
  182. // return compact(['video','datum','article','supplier_goods']);
  183. }
  184. // 推荐
  185. public static function getRecommendList($user_id,$module,$page,$page_num,$where_param =[],$sort_type= 0)
  186. {
  187. if(!$user_id) return['code'=>201,'msg'=>'会员id不能为空'];
  188. $redis = new Redis();
  189. $redis_time= 86400;
  190. $redis_set = [
  191. '0' => $module.'_'.$user_id.'_recommend_ids',// 全部推荐的id
  192. '1' => $module.'_'.$user_id.'_selected_recommend_ids',// 已查询过的推挤id
  193. '2' => $module.'_'.$user_id.'_un_recommend',// 非推荐的id
  194. '3' => $module.'_'.$user_id.'_selected_un_recommend',// 已查询过的非推荐的id
  195. '4' => $module.'_'.$user_id.'_total_num',// 总数量
  196. '5' => $module.'_'.$user_id.'_switch',// 时间段内是否是已经查询 【1已查询过】
  197. ];
  198. $switch = $redis->get($redis_set[5]);
  199. if(!$switch) $redis->set($redis_set[5],1,$redis_time);// 设置已查询状态
  200. // 第一页且没查询过数据
  201. if(!$switch) {
  202. $redis->set($redis_set[0],'',$redis_time);
  203. $redis->set($redis_set[1],'',$redis_time);
  204. $redis->set($redis_set[2],'',$redis_time);
  205. $redis->set($redis_set[3],'',$redis_time);
  206. $redis->set($redis_set[4],0,$redis_time);
  207. }
  208. $module_set = [
  209. 'video'=>[
  210. 'type'=> 1,
  211. 'table'=>'dd_video_url',
  212. 'index_field'=>'title',
  213. 'select_field'=>' a.id,a.title,a.cover,a.user_id,a.is_vip,a.create_at,a.ali_vid,a.video_id,a.duration ,a.release_time,a.read_num',
  214. ],
  215. 'article'=>[
  216. 'type'=> 2,
  217. 'table'=>'dd_article_item',
  218. 'index_field'=>'title',
  219. 'select_field'=>' a.id,a.title,a.cover,a.content_type,a.pdf,a.images,a.create_at,a.user_id,a.is_vip,a.read_num,a.article_id ,a.author,a.release_time,a.desc ',
  220. ],
  221. 'datum'=>[
  222. 'type'=> 3,
  223. 'table'=>'dd_datum_url',
  224. 'index_field'=>'title',
  225. 'select_field'=>' a.id,a.title,a.user_id,a.create_at,a.down_num,a.read_num,a.is_vip,a.datum_id,a.url ,a.is_encrypt,a.pdf_clear ,a.release_time ',
  226. ],
  227. 'forum'=>[
  228. 'type'=> 6,
  229. 'table'=>'dd_user_forum',
  230. 'index_field'=>'title',
  231. 'select_field'=>' a.id,a.title,a.content,a.label,a.level,a.browse_num,a.sort,a.create_at,u.name,u.headimg ,a.release_time',
  232. ],
  233. 'activity'=>[
  234. 'type'=> 11,
  235. 'table'=>'dd_activity',
  236. 'index_field'=>'title',
  237. 'select_field'=>' a.id,cover,a.user_id,a.province,a.city,a.county,a.address,title,a.status,address,a.read_num,a.label,a.start_time,a.end_time,a.release_time',
  238. ],
  239. 'demand'=>[
  240. 'type'=> 5,
  241. 'table'=>'dd_platform_demand',
  242. 'index_field'=>'title',
  243. 'select_field'=>' a.id,a.cover,a.money,a.user_id,a.label,a.title,a.read_num,a.is_over,a.content ,a.release_time',
  244. ],
  245. 'press'=>[
  246. 'type'=> 4,
  247. 'table'=>'dd_press',
  248. 'index_field'=>'title',
  249. 'select_field'=>'a.id,a.title,a.label,a.images,a.read_num,a.transmit_num,a.user_id,a.create_at,a.release_time',
  250. ],
  251. 'recruit'=>[
  252. 'type'=> 8,
  253. 'table'=>'dd_recruit',
  254. 'index_field'=>'title',
  255. 'select_field'=>'a.id,title,a.user_id,label,salary,principal,hr_headimg,address,price_min,price_max,company,education,experience_min,experience_max,welfare,province,city,county ,a.release_time,a.company_intro,a.is_ss,a.scale',
  256. ],
  257. "supplier"=>[
  258. 'type'=> 11,
  259. 'table'=>'dd_supplier_goods',
  260. 'index_field'=>'name',
  261. 'select_field'=>'a.id,a.supplier_id,a.name,a.label,a.cover,a.read_num,k.title supplier_name,k.logo supplier_logo,a.release_time',
  262. ],
  263. 'goods'=>[
  264. 'type'=> 7,
  265. 'table'=>'dd_store_goods',
  266. 'index_field'=>'name',
  267. 'select_field'=>'a.id,name,cover,low_price,a.label,a.release_time,sale_num,a.user_id',
  268. ]
  269. ];
  270. $search_log = UserSearch::getSearchTitle($user_id,$module_set[$module]['type']);
  271. $search_arr = [];
  272. $where_str = 'b.id > 0';
  273. foreach ($search_log as $t){
  274. $search_arr[] = " b.".$module_set[$module]["index_field"]." like '".'%'.$t."%'" .' ';
  275. $search_arr[] = " b.label like '".'%'.$t."%'" .' ';
  276. }
  277. if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr);
  278. $time_str = date("Y-m-d H:i:s");
  279. switch ($module) {
  280. case 'video':
  281. // 第一页查询 安排redis
  282. if(!$switch) {
  283. // 查询推荐id sql
  284. $recommend_query = "SELECT a.id FROM " .$module_set[$module]['table'] . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM ".$module_set[$module]['table']." b WHERE ( $where_str )) AS c ON c.id = a.id Left JOIN dd_video_intro as k ON a.video_id = k.id WHERE a.is_deleted = 0 AND a.release_time < '".$time_str."' AND a.status =1 AND k.is_deleted = 0 AND k.status = 1 ";
  285. $all_recommend = Db::query($recommend_query);
  286. $recommend_ids = array_column($all_recommend,'id');// 推荐的
  287. $un_recommend = VideoUrl::where([['a.status','=',1],['a.is_deleted','=',0],['a.id','not in',$recommend_ids],['a.release_time','< time',$time_str]])
  288. ->where(['k.status'=>1,'k.is_deleted'=>0])
  289. ->alias('a')
  290. ->leftJoin('video_intro k','k.id = a.video_id')
  291. ->column('a.id');
  292. $redis->set($redis_set[0],implode(',',$recommend_ids),$redis_time);
  293. $redis->set($redis_set[2],implode(',',$un_recommend),$redis_time);
  294. $redis->set($redis_set[4],count($recommend_ids) + count($un_recommend),$redis_time);
  295. }else{
  296. $recommend_ids = $redis->get($redis_set[0]);// 所有推荐的id
  297. $recommend_ids = $recommend_ids ? explode(',',$recommend_ids) : [];
  298. $un_recommend = $redis->get($redis_set[2]);// 所有非推荐的id
  299. $un_recommend = $un_recommend ? explode(',',$un_recommend) : [];
  300. }
  301. $list1 = VideoUrl::field($module_set[$module]['select_field'])->alias('a')->where('id','in',$recommend_ids)->orderRand('rand()')->limit($page_num)->select()->toArray();
  302. $num2 = $page_num - count($list1);
  303. $list2 = $num2 <=0 ? [] : VideoUrl::field($module_set[$module]['select_field'])->alias('a')->where('id','in',$un_recommend)->orderRand('rand()')->limit($num2)->select()->toArray();
  304. $list = array_merge($list1,$list2);
  305. array_walk($list,function (&$v,$k){
  306. $v['cover_type'] = $k%7 ? 0 : 1;
  307. $v['create_at'] = substr($v['create_at'],0,10);
  308. $info_auth = VideoUrl::getVideoAuth($v['user_id'],APPNAME,APPLOGO);
  309. $v['app_name'] = $info_auth['app_name'];
  310. $v['app_logo'] = $info_auth['app_logo'];
  311. $v['read_num'] = numTransform($v['read_num']);
  312. });
  313. break;
  314. case "article":
  315. if($page == 1) {
  316. // 查询推荐id sql
  317. $recommend_query = "SELECT a.id FROM " .$module_set[$module]['table'] . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM ".$module_set[$module]['table']." b WHERE ( $where_str )) AS c ON c.id = a.id Left JOIN dd_article_intro as k ON k.id = a.article_id WHERE a.is_deleted = 0 AND a.release_time < '".$time_str."' AND a.status =1 AND k.status = 1 AND k.is_deleted = 0 ";
  318. $all_recommend = Db::query($recommend_query);
  319. $recommend_ids = array_column($all_recommend,'id');// 推荐的
  320. $un_recommend = ArticleItem::where([['a.status','=',1],['a.is_deleted','=',0],['a.id','not in',$recommend_ids],['a.release_time','< time',$time_str]])
  321. ->where(['k.status'=>1,'k.is_deleted'=>0])
  322. ->alias('a')
  323. ->leftJoin('article_intro k','k.id = a.article_id')->column('a.id');
  324. $redis->set($redis_set[0],implode(',',$recommend_ids),$redis_time);
  325. $redis->set($redis_set[2],implode(',',$un_recommend),$redis_time);
  326. $redis->set($redis_set[4],count($recommend_ids) + count($un_recommend),$redis_time);
  327. }else{
  328. $recommend_ids = $redis->get($redis_set[0]);// 所有推荐的id
  329. $recommend_ids = $recommend_ids ? explode(',',$recommend_ids) : [];
  330. $un_recommend = $redis->get($redis_set[2]);// 所有非推荐的id
  331. $un_recommend = $un_recommend ? explode(',',$un_recommend) : [];
  332. }
  333. $list1 = ArticleItem::field($module_set[$module]['select_field'])->alias('a')->where('id','in',$recommend_ids)->orderRand('rand()')->limit($page_num)->select()->toArray();
  334. $num2 = $page_num - count($list1);
  335. $list2 = $num2 <=0 ? [] : ArticleItem::field($module_set[$module]['select_field'])->alias('a')->where('id','in',$un_recommend)->orderRand('rand()')->limit($num2)->select()->toArray();
  336. $list = array_merge($list1,$list2);
  337. array_walk($list,function (&$v,$k)use ($user_id){
  338. $v['read_num'] = numTransform($v['read_num']);
  339. $article_auth = ArticleItem::getArticleAuth($v['user_id'],APPNAME,APPLOGO);
  340. $v['app_name'] = $article_auth['app_name'];
  341. $v['app_logo'] = $article_auth['app_logo'];
  342. $v['images_arr'] = $v['images'] ? explode('|',$v['images']):null;
  343. $v['create_at'] = substr($v['create_at'],0,10);
  344. $v['is_release'] = UserLearn::checkRelease($user_id,3,$v['id']);
  345. $v['is_collect']= UserCollect::checkCollectByType($user_id,3,$v['article_id'],$v['id']);
  346. $v['is_like'] = ArticleLike::where(['user_id'=>$user_id,'article_id'=>$v['article_id'],'item_id'=>$v['id']])->count();
  347. $v['like_num'] = ArticleLike::where(['article_id'=>$v['article_id'],'item_id'=>$v['id']])->count();
  348. $v['collect_num'] = UserCollect::getCollectNum(3,$v['article_id'],$v['id']);
  349. });
  350. break;
  351. case "datum":
  352. if($page == 1) {
  353. // 查询推荐id sql
  354. $recommend_query = "SELECT a.id FROM " .$module_set[$module]['table'] . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM ".$module_set[$module]['table']." b WHERE ( $where_str )) AS c ON c.id = a.id Left JOIN dd_datum_intro as k ON k.id = a.datum_id WHERE a.is_deleted = 0 AND a.release_time < '".$time_str."' AND a.status =1 AND k.status = 1 AND k.is_deleted = 0 ";
  355. $all_recommend = Db::query($recommend_query);
  356. $recommend_ids = array_column($all_recommend,'id');// 推荐的
  357. $un_recommend = DatumUrl::where([['a.status','=',1],['a.is_deleted','=',0],['a.id','not in',$recommend_ids],['a.release_time','< time',$time_str]])
  358. ->where(['k.status'=>1,'k.is_deleted'=>0])
  359. ->alias('a')
  360. ->leftJoin('datum_intro k','k.id = a.datum_id')->column('a.id');
  361. $redis->set($redis_set[0],implode(',',$recommend_ids),$redis_time);
  362. $redis->set($redis_set[2],implode(',',$un_recommend),$redis_time);
  363. $redis->set($redis_set[4],count($recommend_ids) + count($un_recommend),$redis_time);
  364. }else{
  365. $recommend_ids = $redis->get($redis_set[0]);// 所有推荐的id
  366. $recommend_ids = $recommend_ids ? explode(',',$recommend_ids) : [];
  367. $un_recommend = $redis->get($redis_set[2]);// 所有非推荐的id
  368. $un_recommend = $un_recommend ? explode(',',$un_recommend) : [];
  369. }
  370. $list1 = DatumUrl::field($module_set[$module]['select_field'])->alias('a')->where('id','in',$recommend_ids)->orderRand('rand()')->limit($page_num)->select()->toArray();
  371. $num2 = $page_num - count($list1);
  372. $list2 = $num2 <=0 ? [] : DatumUrl::field($module_set[$module]['select_field'])->alias('a')->where('id','in',$un_recommend)->orderRand('rand()')->limit($num2)->select()->toArray();
  373. $list = array_merge($list1,$list2);
  374. array_walk($list,function (&$v,$k)use ($user_id){
  375. $v['down_num'] = numTransform($v['down_num']);
  376. $v['read_num'] = numTransform($v['read_num']);
  377. $datum_auth = ArticleItem::getArticleAuth($v['user_id'],APPNAME,APPLOGO);
  378. $v['app_name'] = $datum_auth['app_name'];
  379. $v['app_logo'] = $datum_auth['app_logo'];
  380. $v['create_at'] = substr($v['create_at'],0,10);
  381. $v['is_release'] = UserLearn::checkRelease($user_id,2,$v['id']);
  382. });
  383. break;
  384. case "forum":
  385. if($page == 1) {
  386. // 查询推荐id sql
  387. $recommend_query = "SELECT a.id FROM " .$module_set[$module]['table'] . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM ".$module_set[$module]['table']." b WHERE ( $where_str )) AS c ON c.id = a.id WHERE a.is_deleted = 0 AND a.status = 1 AND is_recommend = 1 AND a.release_time < '".$time_str."'";
  388. $all_recommend = Db::query($recommend_query);
  389. $recommend_ids = array_column($all_recommend,'id');// 推荐的
  390. $un_recommend = UserForum::where([['status','=',1],['is_deleted','=',0],['id','not in',$recommend_ids],['release_time','< time',$time_str]])->column('id');
  391. $redis->set($redis_set[0],implode(',',$recommend_ids),$redis_time);
  392. $redis->set($redis_set[2],implode(',',$un_recommend),$redis_time);
  393. $redis->set($redis_set[4],count($recommend_ids) + count($un_recommend),$redis_time);
  394. }else{
  395. $recommend_ids = $redis->get($redis_set[0]);// 所有推荐的id
  396. $recommend_ids = $recommend_ids ? explode(',',$recommend_ids) : [];
  397. $un_recommend = $redis->get($redis_set[2]);// 所有非推荐的id
  398. $un_recommend = $un_recommend ? explode(',',$un_recommend) : [];
  399. }
  400. $list1 = UserForum::field($module_set[$module]['select_field'])->alias('a')->where('a.id','in',$recommend_ids)->leftJoin('store_member u','u.id = a.user_id')->orderRand('rand()')->limit($page_num)->select()->toArray();
  401. $num2 = $page_num - count($list1);
  402. $list2 = $num2 <=0 ? [] : UserForum::field($module_set[$module]['select_field'])->alias('a')->where('a.id','in',$un_recommend)->leftJoin('store_member u','u.id = a.user_id')->orderRand('rand()')->limit($num2)->select()->toArray();
  403. $list = array_merge($list1,$list2);
  404. $user_level = UserLevelRank::getUserVip($user_id);
  405. array_walk($list, function (&$v, $k) use ($user_level) {
  406. $v['label_name'] = $v['label'] ? explode(',', trim($v['label'], ',')) : null;
  407. $reply_num = ForumReply::where(['forum_id' => $v['id']])->where('is_deleted', 0)->count();
  408. $v['reply_num'] = numTransform($reply_num);
  409. $v['browse_num'] = numTransform($v['browse_num']);
  410. if (!$v['name']) $v['name'] = APPNAME;
  411. if (!$v['headimg']) $v['headimg'] = APPLOGO;
  412. $v['open_vip'] = !$user_level && $v['level'] ? 1 : 0;
  413. });
  414. break;
  415. case "activity":
  416. if($page == 1) {
  417. // 查询推荐id sql
  418. $recommend_query = "SELECT a.id FROM " .$module_set[$module]['table'] . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM ".$module_set[$module]['table']." b WHERE ( $where_str )) AS c ON c.id = a.id WHERE a.is_deleted = 0 AND a.status = 1 AND is_recommend = 1 AND a.release_time < '".$time_str."'";
  419. $all_recommend = Db::query($recommend_query);
  420. $recommend_ids = array_column($all_recommend,'id');// 推荐的
  421. $un_recommend = \app\common\model\Activity::where([['status','=',1],['is_deleted','=',0],['id','not in',$recommend_ids],['release_time','< time',$time_str]])->column('id');
  422. $redis->set($redis_set[0],implode(',',$recommend_ids),$redis_time);
  423. $redis->set($redis_set[2],implode(',',$un_recommend),$redis_time);
  424. $redis->set($redis_set[4],count($recommend_ids) + count($un_recommend),$redis_time);
  425. }else{
  426. $recommend_ids = $redis->get($redis_set[0]);// 所有推荐的id
  427. $recommend_ids = $recommend_ids ? explode(',',$recommend_ids) : [];
  428. $un_recommend = $redis->get($redis_set[2]);// 所有非推荐的id
  429. $un_recommend = $un_recommend ? explode(',',$un_recommend) : [];
  430. }
  431. $list1 = \app\common\model\Activity::field($module_set[$module]['select_field'])->alias('a')->where('id','in',$recommend_ids)->orderRand('rand()')->limit($page_num)->select()->toArray();
  432. $num2 = $page_num - count($list1);
  433. $list2 = $num2 <=0 ? [] : \app\common\model\Activity::field($module_set[$module]['select_field'])->alias('a')->where('id','in',$un_recommend)->orderRand('rand()')->limit($num2)->select()->toArray();
  434. $list = array_merge($list1,$list2);
  435. array_walk($list,function (&$v,$k)use ($user_id){
  436. $v['read_num'] = numTransform( $v['read_num']);
  437. $v['cover_arr'] = $v['cover'] ? explode('|',$v['cover']) : null;
  438. $v['cover'] = $v['cover_arr'] ? $v['cover_arr'][0]:null;
  439. $v['is_apply'] = ActivityApply::checkApply($user_id,$v['id']);
  440. $v['label_name'] = $v['label'] ? explode(',',trim($v['label'],',')): null;
  441. });
  442. break;
  443. case "demand":
  444. if($page == 1) {
  445. // 查询推荐id sql
  446. $recommend_query = "SELECT a.id FROM " .$module_set[$module]['table'] . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM ".$module_set[$module]['table']." b WHERE ( $where_str )) AS c ON c.id = a.id WHERE a.is_deleted = 0 AND a.status = 1 AND is_recommend = 1 AND a.release_time < '".$time_str."'" . " AND is_over =" . $where_param['is_over'];
  447. $all_recommend = Db::query($recommend_query);
  448. $recommend_ids = array_column($all_recommend,'id');// 推荐的
  449. $un_recommend = PlatformDemand::where([['status','=',1],['is_deleted','=',0],['id','not in',$recommend_ids],['release_time','< time',$time_str],['is_over','=',$where_param['is_over']]])->column('id');
  450. $redis->set($redis_set[0],implode(',',$recommend_ids),$redis_time);
  451. $redis->set($redis_set[2],implode(',',$un_recommend),$redis_time);
  452. $redis->set($redis_set[4],count($recommend_ids) + count($un_recommend),$redis_time);
  453. }else{
  454. $recommend_ids = $redis->get($redis_set[0]);// 所有推荐的id
  455. $recommend_ids = $recommend_ids ? explode(',',$recommend_ids) : [];
  456. $un_recommend = $redis->get($redis_set[2]);// 所有非推荐的id
  457. $un_recommend = $un_recommend ? explode(',',$un_recommend) : [];
  458. }
  459. $list1 = PlatformDemand::field($module_set[$module]['select_field'])->alias('a')->where('id','in',$recommend_ids)->where('a.is_over',$where_param['is_over'])->orderRand('rand()')->limit($page_num)->select()->toArray();
  460. $num2 = $page_num - count($list1);
  461. $list2 = $num2 <=0 ? [] : PlatformDemand::field($module_set[$module]['select_field'])->alias('a')->where('id','in',$un_recommend)->where('a.is_over',$where_param['is_over'])->orderRand('rand()')->limit($num2)->select()->toArray();
  462. $list = array_merge($list1,$list2);
  463. array_walk($list,function (&$v,$k){
  464. $info_auth = PlatformDemand::getAuth($v['user_id'],APPNAME,APPLOGO);
  465. $v['app_name'] = $info_auth['app_name'];
  466. $v['app_logo'] = $info_auth['app_logo'];
  467. $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
  468. $v['cover_arr'] = explode('|',trim($v['cover'],'|'));
  469. $v['read_num'] = numTransform($v['read_num']);
  470. });
  471. break;
  472. case "press":
  473. // 第一页查询 安排redis
  474. if($page == 1) {
  475. // 查询推荐id sql
  476. $recommend_query = "SELECT a.id FROM " .$module_set[$module]['table'] . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM ".$module_set[$module]['table']." b WHERE ( $where_str )) AS c ON c.id = a.id WHERE a.is_deleted = 0 AND a.status = 1 AND is_recommend = 1 AND a.release_time < '".$time_str."'";
  477. $all_recommend = Db::query($recommend_query);
  478. $recommend_ids = array_column($all_recommend,'id');// 推荐的
  479. $un_recommend = Press::where([['status','=',1],['is_deleted','=',0],['id','not in',$recommend_ids],['release_time','< time',$time_str]])->column('id');
  480. $redis->set($redis_set[0],implode(',',$recommend_ids),$redis_time);
  481. $redis->set($redis_set[2],implode(',',$un_recommend),$redis_time);
  482. $redis->set($redis_set[4],count($recommend_ids) + count($un_recommend),$redis_time);
  483. }else{
  484. $recommend_ids = $redis->get($redis_set[0]);// 所有推荐的id
  485. $recommend_ids = $recommend_ids ? explode(',',$recommend_ids) : [];
  486. $un_recommend = $redis->get($redis_set[2]);// 所有非推荐的id
  487. $un_recommend = $un_recommend ? explode(',',$un_recommend) : [];
  488. }
  489. $list1 = Press::field($module_set[$module]['select_field'])->alias('a')->where('id','in',$recommend_ids)->orderRand('rand()')->limit($page_num)->select()->toArray();
  490. $num2 = $page_num - count($list1);
  491. $list2 = $num2 <=0 ? [] : Press::field($module_set[$module]['select_field'])->alias('a')->where('id','in',$un_recommend)->orderRand('rand()')->limit($num2)->select()->toArray();
  492. $list = array_merge($list1,$list2);
  493. array_walk($list,function (&$v,$k)use ($user_id){
  494. $v['read_num'] = numTransform($v['read_num']);
  495. $v['transmit_num'] = numTransform($v['transmit_num']);
  496. $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
  497. $v['images_arr'] = $v['images']? explode('|',trim($v['images'],'|')):null;
  498. $info_auth = \app\common\model\Press::getInfoAuth($v['user_id'],APPNAME,APPLOGO);
  499. $v['app_name'] = $info_auth['app_name'];
  500. $v['app_logo'] = $info_auth['app_logo'];
  501. $v['comment_num'] = PressComment::getCommentNum($v['id']);
  502. $v['is_collect'] = UserCollect::checkCollectByType($user_id,4,$v['id']);
  503. $v['collect_num'] = UserCollect::getCollectNum(4,$v['id']);
  504. $v['is_praise'] = PlatformLike::checkTags($user_id,$v['id'],1);
  505. $v['praise_num'] = PlatformLike::getPraiseNum($v['id'],1);
  506. });
  507. break;
  508. case "recruit":
  509. if($page == 1) {
  510. // 查询推荐id sql
  511. $recommend_query = "SELECT a.id FROM " .$module_set[$module]['table'] . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM ".$module_set[$module]['table']." b WHERE ( $where_str )) AS c ON c.id = a.id WHERE a.is_deleted = 0 AND a.status = 1 AND is_recommend = 1 AND a.release_time < '".$time_str."'";
  512. if(isset($where_param['city']) && $where_param['city']) $recommend_query .=" AND a.city LIKE '".'%'.$where_param['city']."%'" ;
  513. $all_recommend = Db::query($recommend_query);
  514. $recommend_ids = array_column($all_recommend,'id');// 推荐的
  515. $un_recommend = Recruit::where([['status','=',1],['is_deleted','=',0],['id','not in',$recommend_ids],['release_time','< time',$time_str]])
  516. ->when($where_param,function ($query)use ($where_param){
  517. if(isset($where_param['city']) && $where_param['city']) $query->where('city','like','%'.$where_param['city'].'%');
  518. })
  519. ->column('id');
  520. $redis->set($redis_set[0],implode(',',$recommend_ids),$redis_time);
  521. $redis->set($redis_set[2],implode(',',$un_recommend),$redis_time);
  522. $redis->set($redis_set[4],count($recommend_ids) + count($un_recommend),$redis_time);
  523. }else{
  524. $recommend_ids = $redis->get($redis_set[0]);// 所有推荐的id
  525. $recommend_ids = $recommend_ids ? explode(',',$recommend_ids) : [];
  526. $un_recommend = $redis->get($redis_set[2]);// 所有非推荐的id
  527. $un_recommend = $un_recommend ? explode(',',$un_recommend) : [];
  528. }
  529. $list1 = Recruit::field($module_set[$module]['select_field'])->alias('a')->where('id','in',$recommend_ids)
  530. ->when($where_param,function ($query)use ($where_param){
  531. if(isset($where_param['city']) && $where_param['city']) $query->where('a.city','like','%'.$where_param['city'].'%');
  532. })
  533. ->orderRand('rand()')->limit($page_num)->select()->toArray();
  534. $num2 = $page_num - count($list1);
  535. $list2 = $num2 <=0 ? [] : Recruit::field($module_set[$module]['select_field'])->alias('a')
  536. ->when($where_param,function ($query)use ($where_param){
  537. if(isset($where_param['city']) && $where_param['city']) $query->where('a.city','like','%'.$where_param['city'].'%');
  538. })
  539. ->where('id','in',$un_recommend)->orderRand('rand()')->limit($num2)->select()->toArray();
  540. $list = array_merge($list1,$list2);
  541. array_walk($list,function (&$v,$k){
  542. $auth_info = \app\common\model\Recruit::getAuth($v['user_id'],APPNAME,APPLOGO);
  543. $v['app_name'] = $auth_info['app_name'];
  544. $v['app_logo'] = $auth_info['app_logo'];
  545. $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
  546. $v['welfare_arr'] = explode(',',trim($v['welfare'],','));
  547. });
  548. break;
  549. case "supplier":
  550. if($page == 1) {
  551. // 查询推荐id sql
  552. $recommend_query = "SELECT a.id FROM " .$module_set[$module]['table'] . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM ".$module_set[$module]['table']." b WHERE ( $where_str )) AS c ON c.id = a.id LEFT JOIN dd_supplier as k ON a.supplier_id = k.id WHERE a.is_deleted = 0 AND a.status = 1 AND k.status =1 AND k.is_deleted = 0 AND a.release_time < '".$time_str."'";
  553. $all_recommend = Db::query($recommend_query);
  554. $recommend_ids = array_column($all_recommend,'id');// 推荐的
  555. $un_recommend = SupplierGoods::where([['a.status','=',1],['a.is_deleted','=',0],['a.id','not in',$recommend_ids],['a.release_time','< time',$time_str],['k.status','=',1],['k.is_deleted','=',0]])->leftJoin('Supplier k','k.id = a.supplier_id')->alias('a')->column('a.id');
  556. $redis->set($redis_set[0],implode(',',$recommend_ids),$redis_time);
  557. $redis->set($redis_set[2],implode(',',$un_recommend),$redis_time);
  558. $redis->set($redis_set[4],count($recommend_ids) + count($un_recommend),$redis_time);
  559. }else{
  560. $recommend_ids = $redis->get($redis_set[0]);// 所有推荐的id
  561. $recommend_ids = $recommend_ids ? explode(',',$recommend_ids) : [];
  562. $un_recommend = $redis->get($redis_set[2]);// 所有非推荐的id
  563. $un_recommend = $un_recommend ? explode(',',$un_recommend) : [];
  564. }
  565. switch ($sort_type) {
  566. case 1:
  567. $order = ['c.is_top'=>'desc','c.id'=>'desc','c.like_times'=>'desc'];
  568. break;
  569. case 2:
  570. $order = ['c.is_top'=>'desc','c.like_times'=>'desc','c.id'=>'asc'];
  571. break;
  572. }
  573. $list1 = SupplierGoods::field($module_set[$module]['select_field'])->alias('a')->where('a.id','in',$recommend_ids)->leftJoin('Supplier k','k.id = a.supplier_id')->orderRand('rand()')->limit($page_num)->select()->toArray();
  574. $num2 = $page_num - count($list1);
  575. $list2 = $num2 <=0 ? [] : SupplierGoods::field($module_set[$module]['select_field'])->alias('a')->where('a.id','in',$un_recommend)->leftJoin('Supplier k','k.id = a.supplier_id')->orderRand('rand()')->limit($num2)->select()->toArray();
  576. $list = array_merge($list1,$list2);
  577. array_walk($list,function (&$v,$k){
  578. $v['read_num'] = numTransform($v['read_num']);
  579. $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
  580. $v['cover_arr'] = $v['cover']? explode('|',trim($v['cover'],'|')):null;
  581. });
  582. break;
  583. case "goods":
  584. if($page == 1) {
  585. // 查询推荐id sql
  586. $recommend_query = "SELECT a.id FROM " .$module_set[$module]['table'] . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM ".$module_set[$module]['table']." b WHERE ( $where_str )) AS c ON c.id = a.id WHERE a.is_deleted = 0 AND a.status = 1 AND is_recommend = 1 AND a.release_time < '".$time_str."'";
  587. $all_recommend = Db::query($recommend_query);
  588. $recommend_ids = array_column($all_recommend,'id');// 推荐的
  589. $un_recommend = \app\common\model\StoreGoods::where([['status','=',1],['is_deleted','=',0],['id','not in',$recommend_ids],['release_time','< time',$time_str]])->column('id');
  590. $redis->set($redis_set[0],implode(',',$recommend_ids),$redis_time);
  591. $redis->set($redis_set[2],implode(',',$un_recommend),$redis_time);
  592. $redis->set($redis_set[4],count($recommend_ids) + count($un_recommend),$redis_time);
  593. }else{
  594. $recommend_ids = $redis->get($redis_set[0]);// 所有推荐的id
  595. $recommend_ids = $recommend_ids ? explode(',',$recommend_ids) : [];
  596. $un_recommend = $redis->get($redis_set[2]);// 所有非推荐的id
  597. $un_recommend = $un_recommend ? explode(',',$un_recommend) : [];
  598. }
  599. $list1 = \app\common\model\StoreGoods::field($module_set[$module]['select_field'])->alias('a')->where('id','in',$recommend_ids)->orderRand('rand()')->limit($page_num)->select()->toArray();
  600. $num2 = $page_num - count($list1);
  601. $list2 = $num2 <=0 ? [] : \app\common\model\StoreGoods::field($module_set[$module]['select_field'])->alias('a')->where('id','in',$un_recommend)->orderRand('rand()')->limit($num2)->select()->toArray();
  602. $list = array_merge($list1,$list2);
  603. array_walk($list,function (&$v,$k)use ($user_id){
  604. $v['label_name'] = $v['label'] ? explode(',',trim($v['label'],',')): null;
  605. });
  606. break;
  607. }
  608. if(!empty($list1)) {
  609. $select1 = array_column($list1,'id');// 本次查询出推荐的id
  610. $diff = array_diff($recommend_ids,$select1);
  611. $redis->set($redis_set[0],implode(',',$diff),$redis_time);// 更新推荐的redis缓存
  612. $has_sel_re = $redis->get($redis_set[1]);// 已查询过推荐的id
  613. $new_sel_re = array_merge($select1,explode(',',$has_sel_re));
  614. $redis->set($redis_set[1],implode(',',$new_sel_re),$redis_time);// 更新已经查询的推荐的id
  615. }
  616. if(!empty($list2)) {
  617. $select2 = array_column($list2,'id');// 本次查询出推荐的id
  618. $diff = array_diff($un_recommend,$select2);
  619. $redis->set($redis_set[2],implode(',',$diff),$redis_time);// 更新非推荐的redis缓存
  620. $has_sel_un = $redis->get($redis_set[3]);// 已查询过非推荐的id
  621. $new_sel_un = array_merge($select2,explode(',',$has_sel_un));
  622. $redis->set($redis_set[3],implode(',',$new_sel_un),$redis_time);// 更新已经查询的非推荐的id
  623. }
  624. // 查询数据不足
  625. if(count($list) < $page_num) {
  626. $redis->set($redis_set[5],0,$redis_time);// 设置已查询状态
  627. }else{
  628. $residue_recommend_ids = $redis->get($redis_set[0]);// 所有剩余推荐的id
  629. $residue_recommend_ids = $residue_recommend_ids ? explode(',',$residue_recommend_ids) : [];
  630. $residue_un_recommend = $redis->get($redis_set[2]);// 所有剩余非推荐的id
  631. $residue_un_recommend = $residue_un_recommend ? explode(',',$residue_un_recommend) : [];
  632. // 没有剩余数据
  633. if(count($residue_recommend_ids) + count($residue_un_recommend) == 0) {
  634. $redis->set($redis_set[5],0,$redis_time);// 设置已查询状态
  635. }
  636. }
  637. return ['code'=>200,'list'=>$list,'total_count'=>$redis->get($redis_set[4],0),'page_num'=>$page_num,'user_id'=>$user_id];
  638. }
  639. // 短信发送
  640. public static function phoneMessageSend($phone,$key,$data)
  641. {
  642. $mud_arr = [];
  643. $mud_arr[0] = [
  644. 'name'=> '会前1天',//模板名称
  645. 'tem_code'=> 'SMS_460985703',// 模板code
  646. 'param' => [
  647. 'ActivityName'=>isset($data['ActivityName']) ? $data['ActivityName'] : '' ,
  648. 'time'=>isset($data['time']) ? $data['time'] : '' ,
  649. 'adress'=>isset($data['adress']) ? $data['adress'] : '' ,
  650. 'url'=> isset($data['url']) ? $data['url'] : '' ,
  651. ]
  652. ];
  653. $mud_arr[1] = [
  654. 'name'=> '免费票有审核,审核成功',//模板名称
  655. 'tem_code'=> 'SMS_460970747',// 模板code
  656. 'param' => [
  657. 'ActivityName'=>isset($data['ActivityName']) ? $data['ActivityName'] : '' ,
  658. 'url'=> isset($data['url']) ? $data['url'] : '' ,
  659. ]
  660. ];
  661. $mud_arr[2] = [
  662. 'name'=> ' 后台主动修改时间地点短信短信通知',//模板名称
  663. 'tem_code'=> 'SMS_461030378',// 模板code
  664. 'param' => [
  665. 'ActivityName'=>isset($data['ActivityName']) ? $data['ActivityName'] : '' ,
  666. 'time'=>isset($data['time']) ? $data['time'] : '' ,
  667. 'adress'=>isset($data['adress']) ? $data['adress'] : '' ,
  668. ]
  669. ];
  670. AlibabaCloud::accessKeyClient('LTAI5tJ5p12drZegeWVG33xZ', '82UWAiY5e5wH8tSkRvMtqVoGO0h8SB')->regionId('cn-hangzhou')->asDefaultClient();
  671. try {
  672. $result = AlibabaCloud::rpc()
  673. ->product('Dysmsapi')
  674. ->version('2017-05-25')
  675. ->action('SendSms')
  676. ->method('POST')
  677. ->host('dysmsapi.aliyuncs.com')
  678. ->options([
  679. 'query' => [
  680. 'RegionId' => "cn-hangzhou",
  681. 'PhoneNumbers' => $phone,
  682. 'SignName' => "搞一下汽车电子",
  683. 'TemplateCode' => $mud_arr[$key]['tem_code'],
  684. 'TemplateParam' => json_encode($mud_arr[$key]['param']),
  685. ],
  686. ])->request();
  687. $result = $result->toArray();
  688. if($result['Code'] != "OK") return ['code'=>201,'msg'=>'发送失败'];
  689. } catch (ClientException $e) {
  690. return ['code'=>201,'msg'=>$e->getErrorMessage().PHP_EOL];
  691. } catch (ServerException $e) {
  692. return ['code'=>201,'msg'=>$e->getErrorMessage().PHP_EOL];
  693. }catch (\Exception $e){
  694. return ['code'=>201,'msg'=>$e->getMessage()];
  695. }
  696. return ['code'=>200,'msg'=>'发送成功'];
  697. }
  698. // 邮件推送
  699. public static function emailSend($email,$title)
  700. {
  701. if(!strpos($email,'@'))return ['code'=>201,'msg'=>'邮箱格式有误'];
  702. require_once env('root_path').'vendor/aliyunmail/aliyun-php-sdk-core/Config.php';
  703. $iClientProfile = \DefaultProfile::getProfile("cn-hangzhou", "LTAI5tJ5p12drZegeWVG33xZ", "82UWAiY5e5wH8tSkRvMtqVoGO0h8SB");
  704. $client = new \DefaultAcsClient($iClientProfile);
  705. $request = new Dm\SingleSendMailRequest();
  706. $request->setAccountName("gyx@yzm.gyxqcdz.com");
  707. $request->setFromAlias("活动提示");
  708. $request->setAddressType(1);
  709. $request->setTagName("activity");
  710. $request->setReplyToAddress("true");
  711. $request->setToAddress($email);
  712. $request->setSubject("活动提示");
  713. $html_body = '您报名的活动'.$title.'已发生变更。';
  714. $request->setHtmlBody($html_body);
  715. $send_res = $client->getAcsResponse($request);
  716. return ['code'=>200,'msg'=>'发送成功'];
  717. }
  718. //门票邮件推送
  719. public static function ticketSend($ticket_id)
  720. {
  721. $ticket_info = ActivityApplyItem::where('id',$ticket_id)->find()->toArray();
  722. if(!$ticket_info['email']) return ['code'=>201,'msg'=>'邮件为空'];
  723. if(!strpos($ticket_info['email'],'@'))return ['code'=>201,'msg'=>'邮箱格式有误'];
  724. $email = $ticket_info['email'];
  725. $act_info = \app\common\model\Activity::where('id',$ticket_info['act_id'])->find()->toArray();
  726. $sponsor_info = ActivitySponsor::where('id',$act_info['sponsor_id'])->find();
  727. require_once env('root_path').'vendor/aliyunmail/aliyun-php-sdk-core/Config.php';
  728. $iClientProfile = \DefaultProfile::getProfile("cn-hangzhou", "LTAI5tJ5p12drZegeWVG33xZ", "82UWAiY5e5wH8tSkRvMtqVoGO0h8SB");
  729. $client = new \DefaultAcsClient($iClientProfile);
  730. $request = new Dm\SingleSendMailRequest();
  731. $request->setAccountName("gyx@yzm.gyxqcdz.com");
  732. $request->setFromAlias("活动提示");
  733. $request->setAddressType(1);
  734. $request->setTagName("activity");
  735. $request->setReplyToAddress("true");
  736. $request->setToAddress($email);
  737. $request->setSubject("活动提示");
  738. $act_title = $act_info['title'];
  739. $user_name =$ticket_info['name'];
  740. $qr_code = $ticket_info['qr_code'];
  741. $qr_content= $ticket_info['qr_content'];
  742. $server_url1= 'https://'.$_SERVER['SERVER_NAME'].'/static/t1.png';
  743. $server_url2= 'https://'.$_SERVER['SERVER_NAME'].'/static/t2.png';
  744. $server_url3= 'https://'.$_SERVER['SERVER_NAME'].'/static/t3.png';
  745. $sponsor_name = $sponsor_info ? $sponsor_info->title : '官方主办';
  746. $time = $act_info['start_time'].'-'.$act_info['end_time'];
  747. $address = $act_info['province'].$act_info['city'].$act_info['county'].$act_info['address'];
  748. $html_body = "<html lang=\"en\">
  749. <head>
  750. <meta charset=\"UTF-8\">
  751. <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
  752. <title></title>
  753. <style>
  754. *{
  755. padding: 0;
  756. margin: 0;
  757. }
  758. .imgBox {
  759. text-align: center;
  760. position: relative;
  761. }
  762. .bottomInfo {
  763. background-color: #fff;
  764. padding: 20px 10px;
  765. }
  766. .bottomInfo .content {
  767. display: flex;
  768. align-items: center;
  769. line-height: 36px;
  770. font-size: 13px;
  771. }
  772. .bottomInfo .content img {
  773. width: 20px;
  774. height: 20px;
  775. margin-right: 10px;
  776. }
  777. .bottom {
  778. font-size: 13px;
  779. text-align: center;
  780. margin-top: 18px;
  781. }
  782. .signInfo {
  783. background-color: #fff;
  784. border-bottom: 1px dotted #222;
  785. padding: 20px 10px;
  786. }
  787. .signInfo .qrBox {
  788. display: flex;
  789. flex-direction: column;
  790. justify-content: center;
  791. align-items: center;
  792. }
  793. .signInfo .qrTitle {
  794. font-size: 16px;
  795. font-weight: bold;
  796. margin-bottom: 12px;
  797. }
  798. .signInfo .qrCode {
  799. width: 211px;
  800. height: 211px;
  801. }
  802. .signInfo .warn {
  803. font-size: 12px;
  804. color: #666666;
  805. }
  806. .signInfo .code {
  807. width: 151px;
  808. height: 40px;
  809. line-height: 40px;
  810. text-align: center;
  811. border-radius: 6px;
  812. border: 1px solid #2A63F3;
  813. font-size: 14px;
  814. color: #2A63F3;
  815. margin: 16px 0 16px;
  816. }
  817. .titleBox {
  818. margin: 10px 0;
  819. padding: 0 10px;
  820. line-height: 39px;
  821. background: #FFFFFF;
  822. border-radius: 10px;
  823. }
  824. .titleBox .title {
  825. font-size: 15px;
  826. font-weight: bold;
  827. }
  828. .tips img {
  829. width: 14px;
  830. height: 14px;
  831. margin-right: 2px;
  832. }
  833. button {
  834. font-size: 18px;
  835. color: #fff;
  836. font-weight: bold;
  837. position: fixed;
  838. bottom: 34px;
  839. left: 50%;
  840. transform: translateX(-50%);
  841. width: 351px;
  842. height: 48px;
  843. line-height: 48px;
  844. text-align: center;
  845. background: #2A63F3;
  846. border-radius: 24px;
  847. }
  848. .info {
  849. padding: 0 12px;
  850. }
  851. .wrap {
  852. width: 700px;
  853. min-height: 100vh;
  854. display: flex;
  855. flex-direction: column;
  856. /* padding: 44px 0 83px; */
  857. box-sizing: border-box;
  858. background-color: #f4f4f4;
  859. }
  860. /* 头部样式 */
  861. .header-wrap {
  862. width: 100%;
  863. height: 44px;
  864. display: flex;
  865. flex-direction: column;
  866. position: fixed;
  867. top: 0;
  868. left: 0;
  869. z-index: 500;
  870. background-color: #ffffff;
  871. }
  872. .header {
  873. width: 100%;
  874. height: 44px;
  875. display: flex;
  876. align-items: center;
  877. justify-content: center;
  878. background-color: #ffffff;
  879. z-index: 999;
  880. padding: 0 15px;
  881. position: relative;
  882. box-sizing: border-box;
  883. }
  884. .return-img {
  885. position: absolute;
  886. left: 15px;
  887. top: 50%;
  888. transform: translate(0, -50%);
  889. width: 20px;
  890. height: 20px;
  891. }
  892. .header-title {
  893. /* flex: 1; */
  894. display: -webkit-box;
  895. -webkit-line-clamp: 1;
  896. overflow: hidden;
  897. text-overflow: ellipsis;
  898. -webkit-box-orient: vertical;
  899. color: #333333;
  900. font-size: 18px;
  901. font-weight: bold;
  902. box-sizing: border-box;
  903. }
  904. .header-btn-box {
  905. display: flex;
  906. align-items: center;
  907. position: absolute;
  908. right: 12px;
  909. top: 50%;
  910. transform: translate(0, -50%);
  911. }
  912. .header-btn-box>button {
  913. margin-right: 10px;
  914. }
  915. .header-btn-box>button:last-child {
  916. margin-right: 0;
  917. }
  918. .header-btn-box>button>img {
  919. height: 24px;
  920. }
  921. </style>
  922. </head>
  923. <body>
  924. <div class=\"wrap\">
  925. <div class=\"info\">
  926. <div class=\"titleBox\">
  927. <div class=\"title\">
  928. $act_title
  929. </div>
  930. <div class=\"person\">
  931. 参会者:$user_name
  932. </div>
  933. </div>
  934. <div class=\"signInfo\">
  935. <div class=\"qrBox\">
  936. <div class=\"qrTitle\">
  937. 签到码-用于现场签到
  938. </div>
  939. <div class=\"imgBox\">
  940. <img class=\"qrCode\" src=\"$qr_code\" alt=\"\">
  941. </div>
  942. <div class=\"code\">
  943. 签到码:$qr_content
  944. </div>
  945. <div class=\"warn\">
  946. 仅限本人使用
  947. </div>
  948. </div>
  949. </div>
  950. <div>
  951. <div class=\"bottomInfo\">
  952. <div class=\"content\">
  953. <img src=\"$server_url1\" alt=\"\">
  954. $sponsor_name
  955. </div>
  956. <div class=\"content\">
  957. <img src=\"$server_url2\" alt=\"\">
  958. $time
  959. </div>
  960. <div class=\"content\">
  961. <img src=\"$server_url3\" alt=\"\">
  962. $address
  963. </div>
  964. </div>
  965. </div>
  966. </div>
  967. <div class=\"bottom\">
  968. 此二维码用于现场签到,请携带至会场
  969. </div>
  970. </div>
  971. </body>
  972. </html>";
  973. $request->setHtmlBody($html_body);
  974. $send_res = $client->getAcsResponse($request);
  975. return ['code'=>200,'msg'=>'发送成功'];
  976. }
  977. }