UserSynth.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  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\ActivityApplyItem;
  7. use app\common\model\ActivitySponsor;
  8. use app\common\model\ArticleIntro;
  9. use app\common\model\BillApply;
  10. use app\common\model\BillHeader;
  11. use app\common\model\DatumIntro;
  12. use app\common\model\DeliveryAddress;
  13. use app\common\model\SupplierGoods;
  14. use app\common\model\UserSearch;
  15. use app\common\model\UserVitality;
  16. use app\common\model\VideoIntro;
  17. use think\cache\driver\Redis;
  18. use think\Db;
  19. use Dm\Request\V20151123 as Dm;
  20. /**
  21. * 会员身综合管理
  22. * Class UserIdentity
  23. */
  24. class UserSynth extends SerBase
  25. {
  26. public static $ret_val = ['code' => 200 , 'msg'=>'ok','extend'=>''];
  27. // 会员活跃度
  28. public static function vitality($user_id,$type)
  29. {
  30. if($type === false) return false;
  31. $type++;
  32. $redis = new Redis();
  33. $check_key = date('Y-m-d').'_'.$user_id;
  34. // 当天是否登录
  35. if(!$redis->get($check_key)) {
  36. $redis->set($check_key,86400);
  37. $year = date('Y');
  38. $month = date('m');
  39. $day = date('d');
  40. $vitality_info= [
  41. 'user_id'=>$user_id,
  42. 'year'=>$year,
  43. 'month'=>$month,
  44. 'day'=>$day,
  45. 'day_time'=>date('Y-m-d'),
  46. 'create_at'=>date('Y-m-d H:i:s'),
  47. 'type'=>$type
  48. ];
  49. UserVitality::create($vitality_info);
  50. }
  51. }
  52. /**
  53. * 创建申请发票申请记录【申请开票】
  54. * @param $user_id
  55. * @param $order_id
  56. * @param $order_type 订单类型
  57. * @param $bill_info 发票抬头id||发票详情
  58. * @param $add_id 售货地址id
  59. * @param $send_type 物流类型1点子发票2纸质发票
  60. * @param $remark 备注
  61. * @param $order_pay 订单是否完成支付
  62. * @return array
  63. */
  64. public static function buildBillApply($user_id, $order_id, $order_type,$bill_info,$add_id,$send_type,$remark,$order_pay = 1)
  65. {
  66. $order_table = [
  67. 1=>'level_order',// 会员订单
  68. 2=>'store_order',// 商品订单
  69. 3=>'activity_apply',// 活动订单
  70. ];
  71. Db::startTrans();
  72. try {
  73. $apply_info = [
  74. 'order_id' => $order_id,
  75. 'table_name' => $order_table[$order_type],
  76. 'user_id' => $user_id,
  77. 'remark' => $remark,
  78. 'send_type' => $send_type,
  79. 'order_type' => $order_type,
  80. 'create_at' => date("Y-m-d H:i:s"),
  81. 'order_pay' => $order_pay,
  82. ];
  83. if($add_id) {
  84. $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();
  85. $apply_info['address_info'] = json_encode($add_info->toArray());
  86. }
  87. if(is_array($bill_info)){
  88. $apply_info['header'] = $bill_info['header'];
  89. $apply_info['type'] = $bill_info['type'];
  90. $apply_info['email'] =$bill_info['email'];
  91. // $apply_info['bank'] = $bill_info['bank'];
  92. // $apply_info['card_no'] = $bill_info['card_no'];
  93. // $apply_info['phone'] = $bill_info['phone'];
  94. $apply_info['identify_number'] = $bill_info['identify_number'];
  95. // $apply_info['address'] = $bill_info['address'];
  96. }else if($bill_info){
  97. $bill_header = BillHeader::where('id',$bill_info) ->where('user_id',$user_id)->find();
  98. if(empty($bill_header)) self::exception('发票抬头有误');
  99. $apply_info['header'] = $bill_header->header;
  100. $apply_info['email'] = $bill_header->email;
  101. $apply_info['type'] = $bill_header->type;
  102. $apply_info['identify_number'] = $bill_header->identify_number;
  103. }
  104. $order_info = Db::name($order_table[$order_type])
  105. ->where('user_id',$user_id)
  106. ->where('pay_state',1)
  107. ->where('id',$order_id)
  108. ->find();
  109. if(empty($order_info) && $order_type != 3)self::exception('订单有误');
  110. $check_info = BillApply::where('user_id',$user_id)
  111. ->where('order_id',$order_id)
  112. ->where('is_deleted',0)
  113. ->where('table_name',$order_table[$order_type])
  114. ->find();
  115. if(!empty($check_info) && $check_info->status == 1) self::exception('已开票');
  116. $apply_info = BillApply::create($apply_info);
  117. static::$ret_val['extend'] = $apply_info->id ;
  118. Db::commit();
  119. }catch (\Exception $e) {
  120. Db::rollback();
  121. static::$ret_val['code'] = 201 ;
  122. static::$ret_val['msg'] = $e->getMessage();
  123. }
  124. return static::$ret_val;
  125. }
  126. // 获取所有模块设置
  127. public static function getAllModuleTitle()
  128. {
  129. // 视频
  130. $video = VideoIntro::field('id,title,IF(id,\'video\',0) module')->with(['videoArr'=>function($query){
  131. return $query->field('id,title,video_id');
  132. }])->where(['is_deleted'=>0])->order('id desc')->select()->toArray();
  133. array_walk($video,function (&$v){
  134. $v['children'] = $v['video_arr'];
  135. unset($v['video_arr']);
  136. });
  137. // 资料
  138. $datum = DatumIntro::with(['urlArr'=>function($query){
  139. return $query->field('id,title,datum_id');
  140. }])->where(['is_deleted'=>0])->field('id,title,IF(id,\'datum\',0) module')->order('id desc')->select()->toArray();
  141. array_walk($datum,function (&$v){
  142. $v['children'] = $v['url_arr'];
  143. unset($v['url_arr']);
  144. });
  145. // 图文
  146. $article = ArticleIntro::with(['itemChildren'=>function($query){
  147. return $query->field('id,title,article_id');
  148. }])->field('id,title,IF(id,\'article\',0) module')->where(['is_deleted'=>0])->order('id asc')->select()->toArray();
  149. array_walk($article,function (&$v){
  150. $v['children'] = $v['item_children'];
  151. unset($v['item_children']);
  152. });
  153. $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])
  154. ->leftJoin('Supplier s', 's.id = g.supplier_id')->select()->toArray();
  155. return array_merge($video,$datum,$article,$supplier_goods);
  156. // return compact(['video','datum','article','supplier_goods']);
  157. }
  158. // 推荐
  159. public static function getRecommendList($user_id,$module,$page,$page_num)
  160. {
  161. $module_set = [
  162. 'press'=>[
  163. 'type'=> 4,
  164. 'table'=>'dd_press',
  165. 'index_field'=>'name',
  166. 'select_field'=>'a.id,a.title,a.label,a.images,a.read_num,a.transmit_num,a.user_id,a.create_at,IFNULL(is_recommend,0) is_recommend',
  167. ]
  168. ];
  169. $search_log = UserSearch::getSearchTitle($user_id,$module_set[$module]['type']);
  170. $search_arr = [];
  171. $where_str = 'b.id > 0';
  172. foreach ($search_log as $t){
  173. $search_arr[] = " b.$module_set[$module][\"index_field\"] like '".'%'.$t."%'" .' ';
  174. $search_arr[] = " b.label like '".'%'.$t."%'" .' ';
  175. }
  176. if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr);
  177. switch ($module)
  178. {
  179. case "press":
  180. break;
  181. }
  182. }
  183. // 短信发送
  184. public static function phoneMessageSend($phone,$key,$data)
  185. {
  186. $mud_arr = [];
  187. $mud_arr[0] = [
  188. 'name'=> '活动举办 会前1天',//模板名称
  189. 'tem_code'=> 'SMS_460985703',// 模板code
  190. 'param' => [
  191. 'ActivityName'=>isset($data['ActivityName']) ? $data['ActivityName'] : '' ,
  192. 'time'=>isset($data['time']) ? $data['time'] : '' ,
  193. 'adress'=>isset($data['adress']) ? $data['adress'] : '' ,
  194. 'url'=> isset($data['url']) ? $data['url'] : '' ,
  195. ]
  196. ];
  197. $mud_arr[1] = [
  198. 'name'=> '免费票有审核,审核成功',//模板名称
  199. 'tem_code'=> 'SMS_460970747',// 模板code
  200. 'param' => [
  201. 'ActivityName'=>isset($data['ActivityName']) ? $data['ActivityName'] : '' ,
  202. 'url'=> isset($data['url']) ? $data['url'] : '' ,
  203. ]
  204. ];
  205. $mud_arr[2] = [
  206. 'name'=> ' 后台主动修改时间地点短信短信通知',//模板名称
  207. 'tem_code'=> 'SMS_461030378',// 模板code
  208. 'param' => [
  209. 'ActivityName'=>isset($data['ActivityName']) ? $data['ActivityName'] : '' ,
  210. 'time'=>isset($data['time']) ? $data['time'] : '' ,
  211. 'adress'=>isset($data['adress']) ? $data['adress'] : '' ,
  212. ]
  213. ];
  214. AlibabaCloud::accessKeyClient('LTAI5tJ5p12drZegeWVG33xZ', '82UWAiY5e5wH8tSkRvMtqVoGO0h8SB')->regionId('cn-hangzhou')->asDefaultClient();
  215. try {
  216. $result = AlibabaCloud::rpc()
  217. ->product('Dysmsapi')
  218. ->version('2017-05-25')
  219. ->action('SendSms')
  220. ->method('POST')
  221. ->host('dysmsapi.aliyuncs.com')
  222. ->options([
  223. 'query' => [
  224. 'RegionId' => "cn-hangzhou",
  225. 'PhoneNumbers' => $phone,
  226. 'SignName' => "搞一下汽车电子",
  227. 'TemplateCode' => $mud_arr[$key]['tem_code'],
  228. 'TemplateParam' => json_encode($mud_arr[$key]['param']),
  229. ],
  230. ])->request();
  231. $result = $result->toArray();
  232. if($result['Code'] != "OK") return ['code'=>201,'msg'=>'发送失败'];
  233. } catch (ClientException $e) {
  234. return ['code'=>201,'msg'=>$e->getErrorMessage().PHP_EOL];
  235. } catch (ServerException $e) {
  236. return ['code'=>201,'msg'=>$e->getErrorMessage().PHP_EOL];
  237. }catch (\Exception $e){
  238. return ['code'=>201,'msg'=>$e->getMessage()];
  239. }
  240. return ['code'=>200,'msg'=>'发送成功'];
  241. }
  242. // 邮件推送
  243. public static function emailSend($email,$title)
  244. {
  245. require_once env('root_path').'vendor/aliyunmail/aliyun-php-sdk-core/Config.php';
  246. $iClientProfile = \DefaultProfile::getProfile("cn-hangzhou", "LTAI5tJ5p12drZegeWVG33xZ", "82UWAiY5e5wH8tSkRvMtqVoGO0h8SB");
  247. $client = new \DefaultAcsClient($iClientProfile);
  248. $request = new Dm\SingleSendMailRequest();
  249. $request->setAccountName("gyx@yzm.gyxqcdz.com");
  250. $request->setFromAlias("活动提示");
  251. $request->setAddressType(1);
  252. $request->setTagName("activity");
  253. $request->setReplyToAddress("true");
  254. $request->setToAddress($email);
  255. $request->setSubject("活动提示");
  256. $html_body = '您报名的活动'.$title.'已发生变更。';
  257. $request->setHtmlBody($html_body);
  258. $send_res = $client->getAcsResponse($request);
  259. return ['code'=>200,'msg'=>'发送成功'];
  260. }
  261. //门票邮件推送
  262. public static function ticketSend($ticket_id)
  263. {
  264. $ticket_info = ActivityApplyItem::where('id',$ticket_id)->find()->toArray();
  265. if(!$ticket_info['email'])['code'=>201,'msg'=>'邮件为空'];
  266. $email = $ticket_info['email'];
  267. $act_info = \app\common\model\Activity::where('id',$ticket_info['act_id'])->find()->toArray();
  268. $sponsor_info = ActivitySponsor::where('id',$act_info['sponsor_id'])->find();
  269. require_once env('root_path').'vendor/aliyunmail/aliyun-php-sdk-core/Config.php';
  270. $iClientProfile = \DefaultProfile::getProfile("cn-hangzhou", "LTAI5tJ5p12drZegeWVG33xZ", "82UWAiY5e5wH8tSkRvMtqVoGO0h8SB");
  271. $client = new \DefaultAcsClient($iClientProfile);
  272. $request = new Dm\SingleSendMailRequest();
  273. $request->setAccountName("gyx@yzm.gyxqcdz.com");
  274. $request->setFromAlias("活动提示");
  275. $request->setAddressType(1);
  276. $request->setTagName("activity");
  277. $request->setReplyToAddress("true");
  278. $request->setToAddress($email);
  279. $request->setSubject("活动提示");
  280. $act_title = $act_info['title'];
  281. $user_name =$ticket_info['name'];
  282. $qr_code = $ticket_info['qr_code'];
  283. $qr_content= $ticket_info['qr_content'];
  284. $server_url= 'https://'.$_SERVER['SERVER_NAME'].'static';
  285. $sponsor_name = $sponsor_info ? $sponsor_info->title : '官方主办';
  286. $time = $act_info['start_time'].'-'.$act_info['end_time'];
  287. $address = $act_info['province'].$act_info['city'].$act_info['county'].$act_info['address'];
  288. $html_body = "<html lang=\"en\">
  289. <head>
  290. <meta charset=\"UTF-8\">
  291. <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
  292. <title></title>
  293. <style>
  294. *{
  295. padding: 0;
  296. margin: 0;
  297. }
  298. .imgBox {
  299. text-align: center;
  300. position: relative;
  301. }
  302. .bottomInfo {
  303. background-color: #fff;
  304. padding: 20px 10px;
  305. }
  306. .bottomInfo .content {
  307. display: flex;
  308. align-items: center;
  309. line-height: 36px;
  310. font-size: 13px;
  311. }
  312. .bottomInfo .content img {
  313. width: 20px;
  314. height: 20px;
  315. margin-right: 10px;
  316. }
  317. .bottom {
  318. font-size: 13px;
  319. text-align: center;
  320. margin-top: 18px;
  321. }
  322. .signInfo {
  323. background-color: #fff;
  324. border-bottom: 1px dotted #222;
  325. padding: 20px 10px;
  326. }
  327. .signInfo .qrBox {
  328. display: flex;
  329. flex-direction: column;
  330. justify-content: center;
  331. align-items: center;
  332. }
  333. .signInfo .qrTitle {
  334. font-size: 16px;
  335. font-weight: bold;
  336. margin-bottom: 12px;
  337. }
  338. .signInfo .qrCode {
  339. width: 211px;
  340. height: 211px;
  341. }
  342. .signInfo .warn {
  343. font-size: 12px;
  344. color: #666666;
  345. }
  346. .signInfo .code {
  347. width: 151px;
  348. height: 40px;
  349. line-height: 40px;
  350. text-align: center;
  351. border-radius: 6px;
  352. border: 1px solid #2A63F3;
  353. font-size: 14px;
  354. color: #2A63F3;
  355. margin: 16px 0 16px;
  356. }
  357. .titleBox {
  358. margin: 10px 0;
  359. padding: 0 10px;
  360. line-height: 39px;
  361. background: #FFFFFF;
  362. border-radius: 10px;
  363. }
  364. .titleBox .title {
  365. font-size: 15px;
  366. font-weight: bold;
  367. }
  368. .tips img {
  369. width: 14px;
  370. height: 14px;
  371. margin-right: 2px;
  372. }
  373. button {
  374. font-size: 18px;
  375. color: #fff;
  376. font-weight: bold;
  377. position: fixed;
  378. bottom: 34px;
  379. left: 50%;
  380. transform: translateX(-50%);
  381. width: 351px;
  382. height: 48px;
  383. line-height: 48px;
  384. text-align: center;
  385. background: #2A63F3;
  386. border-radius: 24px;
  387. }
  388. .info {
  389. padding: 0 12px;
  390. }
  391. .wrap {
  392. width: 700px;
  393. min-height: 100vh;
  394. display: flex;
  395. flex-direction: column;
  396. /* padding: 44px 0 83px; */
  397. box-sizing: border-box;
  398. background-color: #f4f4f4;
  399. }
  400. /* 头部样式 */
  401. .header-wrap {
  402. width: 100%;
  403. height: 44px;
  404. display: flex;
  405. flex-direction: column;
  406. position: fixed;
  407. top: 0;
  408. left: 0;
  409. z-index: 500;
  410. background-color: #ffffff;
  411. }
  412. .header {
  413. width: 100%;
  414. height: 44px;
  415. display: flex;
  416. align-items: center;
  417. justify-content: center;
  418. background-color: #ffffff;
  419. z-index: 999;
  420. padding: 0 15px;
  421. position: relative;
  422. box-sizing: border-box;
  423. }
  424. .return-img {
  425. position: absolute;
  426. left: 15px;
  427. top: 50%;
  428. transform: translate(0, -50%);
  429. width: 20px;
  430. height: 20px;
  431. }
  432. .header-title {
  433. /* flex: 1; */
  434. display: -webkit-box;
  435. -webkit-line-clamp: 1;
  436. overflow: hidden;
  437. text-overflow: ellipsis;
  438. -webkit-box-orient: vertical;
  439. color: #333333;
  440. font-size: 18px;
  441. font-weight: bold;
  442. /* position: absolute;
  443. left: 40px;
  444. top: 50%;
  445. transform: translate(0, -50%); */
  446. /* padding-right: 120px; */
  447. box-sizing: border-box;
  448. }
  449. .header-btn-box {
  450. display: flex;
  451. align-items: center;
  452. position: absolute;
  453. right: 12px;
  454. top: 50%;
  455. transform: translate(0, -50%);
  456. }
  457. .header-btn-box>button {
  458. margin-right: 10px;
  459. }
  460. .header-btn-box>button:last-child {
  461. margin-right: 0;
  462. }
  463. .header-btn-box>button>img {
  464. height: 24px;
  465. }
  466. </style>
  467. </head>
  468. <body>
  469. <div class=\"wrap\">
  470. <div class=\"info\">
  471. <div class=\"titleBox\">
  472. <div class=\"title\">
  473. $act_title
  474. </div>
  475. <div class=\"person\">
  476. 参会者:$user_name
  477. </div>
  478. </div>
  479. <div class=\"signInfo\">
  480. <div class=\"qrBox\">
  481. <div class=\"qrTitle\">
  482. 签到码-用于现场签到
  483. </div>
  484. <div class=\"imgBox\">
  485. <img class=\"qrCode\" src=\"$qr_code\" alt=\"\">
  486. </div>
  487. <div class=\"code\">
  488. 签到码:$qr_content
  489. </div>
  490. <div class=\"warn\">
  491. 仅限本人使用
  492. </div>
  493. </div>
  494. </div>
  495. <div>
  496. <div class=\"bottomInfo\">
  497. <div class=\"content\">
  498. <img src=\"$server_url/read@2x.png\" alt=\"\">
  499. $sponsor_name
  500. </div>
  501. <div class=\"content\">
  502. <img src=\"$server_url/time@2x.png\" alt=\"\">
  503. $time
  504. </div>
  505. <div class=\"content\">
  506. <img src=\"$server_url/location@2x.png\" alt=\"\">
  507. $address
  508. </div>
  509. </div>
  510. </div>
  511. </div>
  512. <div class=\"bottom\">
  513. 此二维码用于现场签到,请携带至会场
  514. </div>
  515. </div>
  516. </body>
  517. </html>";
  518. $request->setHtmlBody($html_body);
  519. $send_res = $client->getAcsResponse($request);
  520. return ['code'=>200,'msg'=>'发送成功'];
  521. }
  522. }