DreamController.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. <?php
  2. namespace App\Http\Controllers\Api\V1;
  3. use App\Models\AccountLog;
  4. use App\Models\BaseSettingsModel;
  5. use App\Models\DreamImages;
  6. use App\Models\DreamInfoModel;
  7. use App\Models\InteractionInfo;
  8. use App\Models\SearchInfoModel;
  9. use App\Models\SupportDreamModel;
  10. use App\Models\SystemInfoModel;
  11. use App\Models\UserCareDream;
  12. use App\Models\UserCareUser;
  13. use App\Models\UserInfoModel;
  14. use Illuminate\Http\Request;
  15. use App\Services\Base\ErrorCode;
  16. class DreamController extends Controller
  17. {
  18. /**
  19. * @api {get} /api/dream/show 梦想详情
  20. * @apiDescription 梦想详情
  21. * @apiGroup Dream
  22. * @apiPermission Passport
  23. * @apiVersion 0.1.0
  24. * @apiParam {int} [type=home] home interaction paihang 默认all
  25. * @apiParam {int} id 梦想ID
  26. * @apiSuccessExample {json} Success-Response:
  27. * HTTP/1.1 200 OK
  28. * 主页
  29. {
  30. "status": true,
  31. "status_code": 0,
  32. "message": "",
  33. "data": {
  34. "id": 4,
  35. "user_id": 1,
  36. "a": 1, //支持乘数系数 后台配置
  37. "c": 1, //支持乘数系数 后台配置
  38. "name": "梦想标题1",
  39. "about": "梦想介绍",
  40. "coin": 2500,
  41. "time": 21,
  42. "get_coin": 600,
  43. "status": 0,
  44. "video": null,
  45. "score": 100079365,
  46. "sign": "",
  47. "created_at": "2017-06-25 11:47:45",
  48. "updated_at": "2017-06-25 15:10:50",
  49. "is_collection" : 1 1已收藏 0未收藏
  50. "show_button" : 1 1关注按钮显示 0不显示
  51. "top3user": [ 支持者前三
  52. {
  53. "id": 2,
  54. "phone": "13880642881",
  55. "nickname": "name2",
  56. "avatar": "https://timgsa.baidu.com/timg?imamb.224_0.jpeg",
  57. "score": 2399
  58. }
  59. ],
  60. "number": 1 支持乘数
  61. "imgs": [ 梦想图片
  62. {
  63. "title": "",
  64. "pic": "https://timgsa.ba0170524%2Feaca9092ca852e6e9c6ec46b7b14f12f.jpg"
  65. },
  66. {
  67. "title": "",
  68. "pic": "https://timgsa.baid524%2Feaca9092ca852e6e9c6ec46b7b14f12f.jpg"
  69. },
  70. {
  71. "title": "",
  72. "pic": "https://timgsa20170524%2Feaca9092ca852e6e9c6ec46b7b14f12f.jpg"
  73. }
  74. ],
  75. "user": { 梦想用户
  76. "id": 1,
  77. "phone": "13880642880",
  78. "nickname": "name1",
  79. "avatar": "https://timgsumb.224_0.jpeg",
  80. "birthday": "2000-06-21",
  81. "sign": 0,
  82. "money": 0,
  83. "coin": 1300,
  84. "sex": 1,
  85. "signture": "",
  86. "height": 170,
  87. "work": "",
  88. "emotion": 1,
  89. "address": "",
  90. "city": "",
  91. "detail_address": "",
  92. "status": 1,
  93. "wechat": "",
  94. "weibo": "",
  95. "remember_token": "",
  96. "created_at": "2017-06-25 10:27:08",
  97. "updated_at": "2017-06-25 15:20:11",
  98. "deleted_at": null
  99. }
  100. }
  101. }
  102. * @apiErrorExample {json} Error-Response:
  103. *HTTP/1.1 400 Bad Request
  104. *{
  105. * "status": false,
  106. * "status_code": 1105,
  107. * "message": "用户不存在",
  108. * "data": null
  109. * }
  110. */
  111. public function show(Request $request)
  112. {
  113. $user = $this->getUser();
  114. $type = $request->type; //类型
  115. $id = $request->id; //梦想ID
  116. $user_care_dream = UserCareDream::where('user_id',$user->id)->where('dream_id',$id)->first();
  117. $is_collection = empty($user_care_dream) ? 0 :1 ;
  118. if (empty($id)) return $this->error(ErrorCode::KEY_ERROR);
  119. $support_dream = SupportDreamModel::where('dream_id',$id)->get();
  120. $top = [] ;
  121. $topuser = []; //所有支持用户排行
  122. $top3user = []; // 支持用户排行前三
  123. foreach ($support_dream as $item) {
  124. if (!array_key_exists($item->user_id,$top)) {
  125. $top[$item->user_id] = $item->score;
  126. }else{
  127. $top[$item->user_id] += $item->score;
  128. }
  129. }
  130. arsort($top);
  131. foreach ($top as $user_id => $score){
  132. $user = UserInfoModel::find($user_id);
  133. $user->score = $score;
  134. $topuser[] = $user;
  135. if(count($top3user) <= 2) $top3user[] = $user ;
  136. }
  137. if ($type == 'paihang') return $this->api($topuser);
  138. $interactions = InteractionInfo::where('dream_id',$id)->orderBy('id','desc')->get();
  139. foreach ($interactions as $item) {
  140. $item->comments;
  141. foreach ($item->comments as $comment) {
  142. $comment->pic = UserInfoModel::find($comment->user_id)->pic;
  143. $comment->replay;
  144. foreach ($comment->replay as $k1 => $v1){
  145. $v1->pic = UserInfoModel::find($v1->user_id)->pic;
  146. }
  147. }
  148. }
  149. if ($type == 'interaction') return $this->api($interactions);
  150. // 梦想 图片 支持者前三 支持乘数参数 用户余额 梦想分数
  151. // $money = $user->money;
  152. $dream_info = DreamInfoModel::find($id);
  153. $setting = BaseSettingsModel::where('category','score')->select('key','value')->first();
  154. $a = count($setting) > 0 ? $setting->key : 0;
  155. $created_at = $dream_info ? $dream_info->created_at : 0;
  156. $b = intval((time()-strtotime($created_at))/60) ;
  157. $c = count($setting) > 0 ? $setting->value : 0;
  158. $number =round( -$a * $b + $c,1);
  159. if ($number <= 1) $number = 1;
  160. $dream = DreamInfoModel::with(['imgs','user'])->find($id);
  161. $dream->user_coin = $user->coin;
  162. $dream->topuser = $topuser;
  163. $dream->top3user = $top3user;
  164. $dream->interactions = $interactions;
  165. $dream->number = $number;
  166. $dream->is_collection = $is_collection;
  167. $dream->a = $a;
  168. $dream->c = $c;
  169. // 如果当前梦想用户就是当前登录用户就不显示关注按钮
  170. $show_button = $dream->user_id == $user->id ? '0' : '1';
  171. $dream->show_button = $show_button;
  172. return $this->api($dream);
  173. }
  174. /**
  175. * @api {post} /api/dream/support 支持梦想
  176. * @apiDescription 支持梦想
  177. * @apiGroup Dream
  178. * @apiPermission Passport
  179. * @apiVersion 0.1.0
  180. * @apiParam {int} coin 支持梦想币数量
  181. * @apiParam {int} id 梦想ID
  182. * @apiSuccessExample {json} Success-Response:
  183. * HTTP/1.1 200 OK
  184. {
  185. "status": true,
  186. "status_code": 0,
  187. "message": "",
  188. "data": {
  189. "id": 12,
  190. "user_id": 2,
  191. "name": "用户2梦想标题166",
  192. "about": "用户2梦想介绍666",
  193. "coin": 2500,
  194. "time": 21,
  195. "get_coin": 704,
  196. "status": 0,
  197. "video": null,
  198. "score": 158730,
  199. "mark": 158730,
  200. "sign": "",
  201. "created_at": "2017-06-25 13:10:56",
  202. "updated_at": "2017-06-27 18:16:02",
  203. "top3user": [ 支持者前三
  204. {
  205. "id": 1,
  206. "phone": "13880642880",
  207. "nickname": "name1",
  208. "avatar": "https://timgsa.bumb.224_0.jpeg",
  209. "birthday": "2000-06-21",
  210. "sign": 0,
  211. "money": 0,
  212. "coin": 596,
  213. "sex": 1,
  214. "signture": "我的个性签名1",
  215. "height": 170,
  216. "work": "网红",
  217. "emotion": 1,
  218. "address": "",
  219. "city": "上海",
  220. "detail_address": "",
  221. "status": 1,
  222. "wechat": "",
  223. "weibo": "",
  224. "remember_token": "",
  225. "created_at": "2017-06-25 10:27:08",
  226. "updated_at": "2017-06-27 18:16:02",
  227. "deleted_at": null,
  228. "score": 5062
  229. }
  230. ]
  231. "number": 4.8
  232. "is_collection" : 1 1已收藏 0未收藏
  233. }
  234. }
  235. * @apiErrorExample {json} Error-Response:
  236. *HTTP/1.1 400 Bad Request
  237. * {
  238. * "state": false,
  239. * "code": 1000,
  240. * "message": "传入参数不正确",
  241. * "data": null or []
  242. * }
  243. * 可能出现的代码
  244. * {
  245. * "status": false,
  246. * "status_code": 1303,
  247. * "message": "余额不足",
  248. * "data": null
  249. * }
  250. * {
  251. * "status": false,
  252. * "status_code": 1410,
  253. * "message": "支持已达上限",
  254. * "data": null
  255. * }
  256. *
  257. */
  258. public function support(Request $request)
  259. {
  260. $validator = \Validator::make($request->all(),
  261. [
  262. 'coin' => 'required',
  263. 'id' => 'required',
  264. ],
  265. [
  266. 'coin.required' => '梦想币不能为空',
  267. 'id.required' => '支持梦想id不能为空',
  268. ]
  269. );
  270. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  271. $user = $this->getUser();
  272. $dream_id = $request->id;
  273. $dream = DreamInfoModel::find($dream_id);
  274. $user_id = $dream->user_id;
  275. $coin = $request->coin;
  276. if ($dream->get_coin >= $dream->coin) {
  277. return $this->error(ErrorCode::SUP_TOP);
  278. } elseif($coin + $dream->get_coin > $dream->coin){
  279. $coin = $dream->coin - $dream->get_coin;
  280. }
  281. $user_care_dream = UserCareDream::where('user_id', $user->id)->where('dream_id', $dream_id)->first();
  282. $is_collection = empty($user_care_dream) ? 0 :1 ;
  283. $setting = BaseSettingsModel::where('category','score')->select('key','value')->first();
  284. $a = count($setting) > 0 ? $setting->key : '';
  285. $b = intval((time()-strtotime($dream->created_at))/60) ;
  286. $c = count($setting) > 0 ? $setting->value : '';
  287. //Todo 支持乘数目公式
  288. $number =round( -$a * $b + $c,1);
  289. if ($number <= 1) $number = 1;
  290. if ($user->coin < $coin) {
  291. return $this->error(ErrorCode::COIN_NOT_ENOUGH);
  292. }else{
  293. $user->coin -= $coin;
  294. $user->save();
  295. $dream->get_coin += $coin;
  296. $dream->mark += $coin*$number;
  297. $dream->save();
  298. // 梦想实现创建二维码
  299. if ($dream->coin == $dream->get_coin) {
  300. // 生成二维码
  301. $info['transaction_id'] = date('YmdHis') . mt_rand(1000, 9999);
  302. $info['code'] = 'WECHATPAY_' . $info['transaction_id'];
  303. $code_url = env('APP_URL').'/user/meet?dream_id='.$dream_id;
  304. $code_path = public_path('qrcodes/'.$info['code'].'.png');
  305. \QrCode::format('png')->size(500)->generate($code_url,$code_path);
  306. $code = env('APP_URL').'/qrcodes/'.$info['code'].'.png';
  307. DreamInfoModel::where('id',$dream_id)->update(compact('code'));
  308. }
  309. $data = [
  310. 'user_id'=>$user->id,
  311. 'dream_id'=>$dream_id,
  312. 'to_user_id'=>$user_id,
  313. 'coin'=>$coin,
  314. 'score'=>$coin*$number,
  315. ];
  316. $ok = SupportDreamModel::create($data);
  317. if (!$ok) {
  318. return $this->error(ErrorCode::MERCHANT_SERVICE_STATUS_INVALID);
  319. }
  320. // 记录充值记录 新增系统消息
  321. $data = [
  322. 'from_id' =>$user->id,
  323. 'to_id' => $user_id,
  324. 'from_amount' => $coin,
  325. 'to_amount' => $coin,
  326. 'from_type' => AccountLog::TYPE_COIN,
  327. 'to_type' => AccountLog::TYPE_COIN,
  328. 'op' => AccountLog::OP_SUPPORT,
  329. ];
  330. AccountLog::create($data);
  331. $message = UserInfoModel::find($user->id)->nickname.'为你的梦想捐赠'.$coin.'梦想币';
  332. $info = [
  333. 'user_id' => $user_id,
  334. 'message' => $message,
  335. ];
  336. SystemInfoModel::create($info);
  337. // 支持成功返回数据到当前页面 top3user
  338. $support_dream = SupportDreamModel::where('dream_id',$dream_id)->get();
  339. $top = [] ;
  340. $top3user = []; // 支持用户排行前三
  341. foreach ($support_dream as $item) {
  342. if (!array_key_exists($item->user_id,$top)) {
  343. $top[$item->user_id] = $item->score;
  344. }else{
  345. $top[$item->user_id] += $item->score;
  346. }
  347. }
  348. arsort($top);
  349. foreach ($top as $user_id => $score){
  350. $user = UserInfoModel::find($user_id);
  351. $user->score = $score;
  352. if(count($top3user) <= 2) $top3user[] = $user ;
  353. }
  354. // 梦想分 mark
  355. $dream->top3user = $top3user;
  356. $dream->is_collection = $is_collection;
  357. $user_coin = $user->coin;
  358. return $this->api(compact('dream','user_coin'));
  359. }
  360. }
  361. // 收藏关注梦想
  362. /**
  363. * @api {get} /api/dream/collection 收藏梦想
  364. * @apiDescription 收藏梦想
  365. * @apiGroup Dream
  366. * @apiPermission Passport
  367. * @apiVersion 0.1.0
  368. * @apiParam {int} id 梦想ID
  369. * @apiParam {int} is_collection 0取消关注 1关注
  370. * @apiSuccessExample {json} Success-Response:
  371. * HTTP/1.1 200 OK
  372. *{
  373. * "status": true,
  374. * "status_code": 0,
  375. * "message": "",
  376. * "data": {
  377. * "is_collection": 1 1已关注 0 未关注
  378. * }
  379. *}
  380. * @apiErrorExample {json} Error-Response:
  381. *HTTP/1.1 400 Bad Request
  382. * {
  383. * "state": false,
  384. * "code": 1000,
  385. * "message": "传入参数不正确",
  386. * "data": null or []
  387. * }
  388. *
  389. */
  390. public function collection(Request $request)
  391. {
  392. $validator = \Validator::make($request->all(),
  393. [
  394. 'id' => 'required',
  395. 'is_collection' => 'required',
  396. ],
  397. [
  398. 'id.required' => '收藏梦想id不能为空',
  399. 'is_collection.required' => '关注值不存在',
  400. ]
  401. );
  402. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  403. $user = $this->getUser();
  404. if(!$dream = DreamInfoModel::find($request->id)){
  405. $this->error(ErrorCode::CLIENT_WRONG_PARAMS);
  406. }
  407. $data = [
  408. 'user_id' =>$user->id,
  409. 'dream_id' =>$request->id,
  410. 'dream_user_id' =>$dream->user_id,
  411. ];
  412. $is_collection = $request->is_collection;
  413. $user_care_dream = UserCareDream::where('user_id',$user->id)->
  414. where('dream_id',$request->id)->first();
  415. if ($is_collection) {
  416. if (empty($user_care_dream)) {
  417. UserCareDream::create($data);
  418. }
  419. }else{
  420. UserCareDream::where('user_id',$user->id)->
  421. where('dream_id',$request->id)->delete();
  422. }
  423. // 并且同时会关注这个梦想者
  424. $array = [
  425. 'user_id' =>$user->id,
  426. 'other_user_id' =>$dream->user_id,
  427. ];
  428. $user_care_user = UserCareUser::where('user_id',$user->id)->
  429. where('other_user_id',$dream->user_id)->first();
  430. if (empty($user_care_user)) {
  431. UserCareUser::create($array);
  432. // 关注成功发送私信
  433. $message = BaseSettingsModel::where('category','message')->first();
  434. $message = empty($message) ? '' : $message->value;
  435. $info2 = [
  436. 'user_id'=>$request->id,
  437. 'to_user_id' => $dream->user_id,
  438. 'message' =>$message
  439. ];
  440. SystemInfoModel::create($info2);
  441. }
  442. return $this->api($is_collection);
  443. }
  444. /**
  445. * @api {get} /api/dream/search 梦想搜索
  446. * @apiDescription 梦想搜索)
  447. * @apiGroup Dream
  448. * @apiPermission none
  449. * @apiVersion 0.1.0
  450. * @apiParam {string} keyword 关键字
  451. * @apiSuccessExample {json} Success-Response:
  452. * HTTP/1.1 200 OK
  453. {
  454. "status": true,
  455. "status_code": 0,
  456. "message": "",
  457. "data": [
  458. {
  459. "id": 5,
  460. "user_id": 1,
  461. "name": "梦想标题1",
  462. "about": "梦想介绍",
  463. "coin": 2500,
  464. "time": 72000,
  465. "get_coin": 0,
  466. "mark": 0,
  467. "status": 0,
  468. "video": "url",
  469. "score": 100079365,
  470. "sign": "梦想达人",
  471. "created_at": "2017-06-25 12:45:22",
  472. "updated_at": "2017-06-28 15:50:41",
  473. "user": {},
  474. "imgs": []
  475. },
  476. ]
  477. }
  478. * @apiErrorExample {json} Error-Response:
  479. * HTTP/1.1 400 Bad Request
  480. */
  481. public function search(Request $request)
  482. {
  483. $user = $this->getUser();
  484. if (empty($request->keyword)) {
  485. return $this->api('');
  486. }
  487. $keyword ='%'.$request->keyword.'%';
  488. $data = DreamInfoModel::where('name','like',$keyword)->
  489. orWhere('sign','like',$keyword)->with(['user','img'])->get();
  490. foreach ($data as $k => $dream) {
  491. $info = UserCareDream::where('dream_id',$dream->id)->get();
  492. $dream->care_num = count($info);
  493. $dream->img = $dream->img?$dream->img->pic:'';
  494. }
  495. $this->insertSearchTable($user->id,$request->keyword);
  496. return $this->api($data);
  497. }
  498. public function insertSearchTable($id,$keyword)
  499. {
  500. $info = SearchInfoModel::where('user_id',$id)->
  501. where('search',trim($keyword))->first();
  502. if (count($info) == 0) {
  503. SearchInfoModel::create(['user_id'=>$id,'search'=>trim($keyword),'times'=>1]);
  504. }else{
  505. $info->times += 1;
  506. $info->save();
  507. }
  508. }
  509. /**
  510. * @api {post} /api/dream/store 发布梦想
  511. * @apiDescription 发布梦想
  512. * @apiParam {string} pics 梦想图片 数组
  513. * @apiParam {string} video 梦想视频
  514. * @apiParam {string} name 梦想标题
  515. * @apiParam {string} about 梦想介绍
  516. * @apiParam {int} coin 梦想币
  517. * @apiParam {int} time 实现时间默认21*3600
  518. * @apiGroup Dream
  519. * @apiPermission Passport
  520. * @apiVersion 0.1.0
  521. * @apiSuccessExample {json} Success-Response:
  522. * {
  523. * "status": true,
  524. * "status_code": 0,
  525. * "message": "",
  526. * "data": ""
  527. *}
  528. * HTTP/1.1 200 OK
  529. * @apiErrorExample {json} Error-Response:
  530. * {
  531. * "status": false,
  532. * "status_code": 1203,
  533. * "message": "附件不存在",
  534. * "data": null
  535. * }
  536. * HTTP/1.1 400 Bad Request
  537. */
  538. public function store(Request $request)
  539. {
  540. $user = $this->getUser();
  541. $validator = \Validator::make($request->all(),
  542. [
  543. 'name' => 'required',
  544. 'about' => 'required',
  545. 'coin' => 'required|integer',
  546. 'days' => 'required|integer',
  547. 'pics' => 'required|array',
  548. ],
  549. [
  550. 'name.required' => '梦想标题必填',
  551. 'about.required' => '梦想介绍必填',
  552. 'coin.required' => '梦想币必填',
  553. 'coin.integer' => '梦想币必须是正整数',
  554. 'days.required' => '实现时间必填',
  555. 'days.integer' => '实现时间必须是正整数',
  556. 'pics.required' => '至少上传一张图片',
  557. 'pics.array' => '至少上传一张图片数组',
  558. ]
  559. );
  560. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  561. \Log::debug($user);
  562. $data2 = $user->myCareNum;
  563. $care_num = count($data2);
  564. $setting = BaseSettingsModel::where('category','paihang')->first();
  565. $a = $setting?$setting->key:1;
  566. $b = $setting?$setting->value:1;
  567. $t = 21*3600 / 60;
  568. $days = $request->days;
  569. $data = $request->except('_token','pics','days');
  570. $data['user_id'] = $user->id;
  571. $data['end_time'] = date('Y-m-d H:i:s',strtotime('+'.$days.' days'));
  572. \Log::debug($data['end_time'].' care_num:'.$care_num.' a:'.$a.' b:'.$b.' t:'.$t);
  573. if ($care_num == 0) {
  574. $data['score'] = (($a/$t) + $b)*100000000 ;
  575. }else{
  576. $data['score'] = (log($care_num) + ($a/$t) + $b)*100000000 ;
  577. }
  578. $data['created_at'] = date('Y-m-d H:i:s');
  579. $data['updated_at'] = date('Y-m-d H:i:s');
  580. $dream_id = DreamInfoModel::insertGetId($data);
  581. if ($dream_id) {
  582. // 梦想创建成功 关联关系中最新动态+1
  583. /* $info = UserCareUser::where('other_user_id',$user->id)->paginate(20);
  584. foreach ($info as $item) {
  585. $item->dream_num += 1;
  586. $item->updated_at = date('Y-m-d H:i:s');
  587. $item->save();
  588. }*/
  589. $pics = $request->pics;
  590. $video = $request->video;
  591. if (!is_array($pics) && empty($pics) && empty($video)) {
  592. DreamInfoModel::destroy($dream_id);
  593. return $this->error(ErrorCode::ATTACHMENT_NOT_EXIST);
  594. }
  595. $data = [];
  596. if (is_array($pics)) {
  597. foreach ($pics as $v){
  598. $data[] = [
  599. 'dream_id'=>$dream_id,
  600. 'pic' => $v,
  601. 'created_at' =>date('Y-m-d H:i:s'),
  602. 'updated_at' =>date('Y-m-d H:i:s'),
  603. ];
  604. }
  605. DreamImages::insert($data);
  606. }
  607. // 梦想创建成功后所有关注我的梦想的人也会收到我最新梦想发布的消息
  608. $ids = UserCareDream::where('dream_user_id',$user->id)->select('user_id')->get()->toArray();
  609. $id_arrs = array_column($ids,'user_id');
  610. if (!empty($id_arrs)) {
  611. $arr = [] ;
  612. foreach ($id_arrs as $id){
  613. $arr[] = [
  614. 'to_user_id' => $id,
  615. 'user_id' => $user->id,
  616. 'message' => '关注的梦想有新的梦想动态'.$dream_id,
  617. ];
  618. }
  619. SystemInfoModel::insert($arr);
  620. }
  621. return $this->api('');
  622. }
  623. }
  624. }