PostsController.php 147 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Jobs\CalculateFollowsNumJob;
  4. use App\Jobs\CalculateLikesNumJob;
  5. use App\Jobs\Circle\ForgetCircleUnreadCountJob;
  6. use App\Jobs\CreatePostSyncJob;
  7. use App\Jobs\ImitateCircleJoinStepJob;
  8. use App\Jobs\Posts\UpdatePosterGlassJob;
  9. use App\Jobs\Posts\UpdatePostFieldsJob;
  10. use App\Jobs\Posts\UpdatePostFilesIdJob;
  11. use App\Jobs\Posts\UpdatePostGoodsIdJob;
  12. use App\Jobs\Posts\UpdatePostOnlyTextJob;
  13. use App\Jobs\Posts\UpdatePostSoundsIdJob;
  14. use App\Jobs\Posts\UpdatePostTagIdJob;
  15. use App\Jobs\Posts\UpdatePostVideoIdJob;
  16. use App\Jobs\TopicImgJob;
  17. use App\Jobs\UpdateCommentCircleJob;
  18. use App\Jobs\UserInputSafeCheckJob;
  19. use App\Jobs\UserPublishedFollowJob;
  20. use App\Jobs\VideoSnapshotJob;
  21. use App\Lib\WeApp\WeApp;
  22. use App\Models\Posts\WxPost;
  23. use App\Models\Posts\WxPostsAddress;
  24. use App\Models\Posts\WxPostsField;
  25. use App\Models\Posts\WxPostsFile;
  26. use App\Models\Posts\WxPostsGoods;
  27. use App\Models\Posts\WxPostsImg;
  28. use App\Models\Posts\WxPostsSound;
  29. use App\Models\Posts\WxPostsVote;
  30. use App\Models\Posts\WxPostsWeightRefresh;
  31. use App\Models\Posts\WxTag;
  32. use App\Models\Circle\WxCircle;
  33. use App\Models\Posts\WxPostsPayContent;
  34. use App\Models\Posts\WxUserCircle;
  35. use App\Models\Shop\WxShopGoods;
  36. use App\Models\Used\WxUsedGood;
  37. use App\Models\Used\WxUsedNeed;
  38. use App\Models\User\WxUser;
  39. use App\Models\User\WxUserPay;
  40. use App\Models\User\WxUserStudentCertify;
  41. use App\Models\Voter\WxVoter;
  42. use App\Models\WxTenant;
  43. use App\Wen\Utils\BaiduUtils;
  44. use App\Wen\Utils\CircleUtils;
  45. use App\Wen\Utils\FieldUtils;
  46. use App\Wen\Utils\FileUtils;
  47. use App\Wen\Utils\GatewayUtils;
  48. use App\Wen\Utils\ImageUtils;
  49. use App\Wen\Utils\PostUtils;
  50. use App\Wen\Utils\SearchUtils;
  51. use App\Wen\Utils\Settings;
  52. use App\Wen\Utils\StrUtils;
  53. use App\Wen\Utils\UserUtils;
  54. use App\Wen\Utils\Utils;
  55. use App\Http\Controllers\Api\Repositories\PostsRepositores;
  56. use App\Http\Controllers\Api\Repositories\WxCircleRepositores;
  57. use App\Http\Controllers\Api\Repositories\WxCommentRepositores;
  58. use App\Http\Controllers\Api\Repositories\WxPlateRepositores;
  59. use App\Http\Controllers\Api\Repositories\WxTagsRepositories;
  60. use App\Http\Controllers\Api\Repositories\WxUserRepositores;
  61. use App\Http\Requests\Api\PostsRequests\CircleRequest;
  62. use App\Models\Posts\WxPost as Model;
  63. use App\Models\Posts\WxPostsTag;
  64. use App\Models\Posts\WxPostsVideo;
  65. use App\Models\WxExceptional;
  66. use Illuminate\Http\JsonResponse;
  67. use Illuminate\Http\Request;
  68. use Illuminate\Support\Carbon;
  69. use Illuminate\Support\Facades\Cache;
  70. use Illuminate\Support\Facades\DB;
  71. use Illuminate\Support\Facades\Redis;
  72. use Intervention\Image\Facades\Image;
  73. use SimpleSoftwareIO\QrCode\Facades\QrCode;
  74. class PostsController extends BaseController
  75. {
  76. /**
  77. * 板块选择
  78. */
  79. public function plateOptions()
  80. {
  81. $data = (new WxPlateRepositores())->options();
  82. return $this->success($data);
  83. }
  84. /**
  85. * 板块列表
  86. * @return \Illuminate\Http\JsonResponse
  87. */
  88. public function plateList()
  89. {
  90. return $this->success(WxPlateRepositores::list());
  91. }
  92. /**
  93. * 通过板块ID获取圈子列表
  94. * @param CircleRequest $request
  95. */
  96. public function getCircleByPlateId(CircleRequest $request)
  97. {
  98. $plateId = $request->plate_id;
  99. $uid = $request->uid;
  100. if($uid > 0){
  101. }else{
  102. $uid = 0;
  103. }
  104. $data = WxCircleRepositores::circleByPlateId($plateId, $uid);
  105. if($data){
  106. return $this->success($data);
  107. }else{
  108. return $this->fail(200003, [], '该分区没有'.env('circle_call', '圈子'));
  109. }
  110. }
  111. /**
  112. * 搜索圈子
  113. * @param Request $request
  114. * @return \Illuminate\Http\JsonResponse
  115. */
  116. public function searchCircle(Request $request)
  117. {
  118. $keyword = $request->keyword;
  119. return $this->success(WxCircleRepositores::searchCircle($keyword));
  120. }
  121. /**
  122. * 发帖时推荐的话题
  123. * @param Request $request
  124. * @return \Illuminate\Http\JsonResponse
  125. */
  126. public function recommendTags(Request $request)
  127. {
  128. $search = $request->search;
  129. if($search){
  130. $result = WxTag::where('tags_state', 0)->where('tags_name', 'like', $search.'%')->limit(20)->get()->map(function ($items) {
  131. $items->tags_number = WxPostsTag::where('tags_id', $items->id)->count();
  132. if(_empty_($items->head_portrait)){
  133. $items->head_portrait = Settings::get('img_default_topic_avatar');
  134. TopicImgJob::dispatch($items->id);
  135. }
  136. return $items;
  137. });
  138. return $this->success($result);
  139. }else{
  140. return $this->success(WxTagsRepositories::recommendTags());
  141. }
  142. }
  143. /**
  144. * 购买付费内容
  145. * @param Request $request
  146. * @return \Illuminate\Http\JsonResponse
  147. */
  148. public function pay(Request $request){
  149. $uid = $request->uid;
  150. $post_id = $request->post_id;
  151. $scene = $request->scene;
  152. if(_empty_($post_id) || _empty_($scene)){
  153. return $this->fail(200001);
  154. }
  155. $post_obj = WxPost::where('id', $post_id)->first(['user_id','pay_content_id', 'circle_id']);
  156. if(_empty_($post_obj)){
  157. return $this->fail(200003);
  158. }
  159. $post_user_id = $post_obj->user_id;
  160. $pay_content_id = $post_obj->pay_content_id;
  161. $circle_id = $post_obj->circle_id;
  162. if(_empty_($pay_content_id)){
  163. return $this->fail(200004);
  164. }
  165. if($uid == $post_user_id){
  166. return $this->fail(200038);
  167. }
  168. if(WxUserPay::where([
  169. ['user_id', '=', $uid],
  170. ['post_id', '=', $post_id],
  171. ['pay_content_id', '=', $pay_content_id]
  172. ])->exists()){
  173. return $this->fail(200035);
  174. }
  175. $pay_content_obj = WxPostsPayContent::find($pay_content_id);
  176. if(_empty_($pay_content_obj)){
  177. return $this->fail(200003);
  178. }
  179. try{
  180. DB::beginTransaction();
  181. $price = $pay_content_obj->price;
  182. $credit_type = $pay_content_obj->credit_type;
  183. $user = WxUser::find($uid);
  184. $user_name = $user->user_name;
  185. $is_vip = $user->is_member;
  186. $vip_discount = _between_(Settings::get('app_vip_paycontent_discount', 0), 0, 100);
  187. $vip_price_tip = '';
  188. if($vip_discount > 0 && $is_vip){
  189. if($credit_type == 0){
  190. $vip_price = (int)($price * ( (100 - $vip_discount) / 100));
  191. }else{
  192. $vip_price = round($price * ( (100 - $vip_discount) / 100), 2);
  193. }
  194. $vip_price_tip = '会员价';
  195. }else{
  196. $vip_price = $price;
  197. }
  198. if($credit_type == 0){
  199. $coins = UserUtils::user_coins($uid);
  200. if($coins < $vip_price){
  201. DB::rollBack();
  202. return $this->fail(200011);
  203. }
  204. $circle_user_reward = 0;
  205. $paycontent_division = 0;
  206. if($circle_id && $circle_id > 0){
  207. $circle_info = WxCircle::find($circle_id);
  208. $paycontent_division = $circle_info->circle_user_paycontent_division;
  209. $circle_user_id = $circle_info->user_id;
  210. $circle_user_reward = (int)($paycontent_division * $price);
  211. }
  212. $platform_division = _between_(Settings::get('app_paypost_platform_percent', 0), 0, 100);
  213. $platform_reward = (int)($platform_division * $price / 100);
  214. if($vip_price > 0){
  215. $r = UserUtils::update_user_coins($uid,1, -$vip_price, $vip_price_tip.'购买付费内容:'.Settings::get('app_coin_name', '硬币').'-'.$vip_price);
  216. }else{
  217. $r = true;
  218. }
  219. if($r){
  220. if($circle_user_reward > 0 || $platform_reward > 0){
  221. $author_reward = $price - $circle_user_reward - $platform_reward;
  222. if($author_reward > 0){
  223. $content_tip = '「<a href="/pages/user/user?id='.$uid.'">'.$user_name.'</a>」购买了您的付费内容(id:<a href="/pages/sticky/sticky?id='.$post_id.'">'.$post_id.'</a>),获得'.Settings::get('app_coin_name', '硬币').'+'.$author_reward.'('.env('circle_user_call', '圈主').'分成'.$circle_user_reward.Settings::get('app_coin_name', '硬币').',系统分成'.$platform_reward.Settings::get('app_coin_name', '硬币').')';
  224. UserUtils::update_user_coins($post_user_id,2, $author_reward, '付费内容被购买('.env('circle_user_call', '圈主').'分成'.($paycontent_division * 100).'%):'.Settings::get('app_coin_name', '硬币').'+'.$author_reward);
  225. UserUtils::add_user_notice(7003, $post_user_id,
  226. Settings::get('app_coin_name', '硬币').'到账', $content_tip
  227. , 100, $post_id);
  228. }
  229. if($circle_user_reward > 0){
  230. UserUtils::update_user_coins($circle_user_id,15, $circle_user_reward, env('circle_user_call', '圈主').'分成奖励:'.Settings::get('app_coin_name', '硬币').'+'.$circle_user_reward);
  231. UserUtils::add_user_notice(7004, $circle_user_id, env('circle_user_call', '圈主').'分成奖励', env('circle_call', '圈子').'成员的付费内容被购买,订单金额'.$price.'金币,您获得分成'.$circle_user_reward.'金币(分成比例:'.($paycontent_division * 100).'%)', 100);
  232. }
  233. }else{
  234. UserUtils::update_user_coins($post_user_id,2, $price, '付费内容被购买:'.Settings::get('app_coin_name', '硬币').'+'.$price);
  235. UserUtils::add_user_notice(7003, $post_user_id, Settings::get('app_coin_name', '硬币').'到账','「<a href="/pages/user/user?id='.$uid.'">'.$user_name.'</a>」购买了您的付费内容(id:<a href="/pages/sticky/sticky?id='.$post_id.'">'.$post_id.'</a>),获得金币+'.$price, 100, $post_id);
  236. }
  237. $user_pay = new WxUserPay();
  238. $user_pay->user_id = $uid;
  239. $user_pay->post_id = $post_id;
  240. $user_pay->pay_content_id = $pay_content_id;
  241. $user_pay->save();
  242. WxCommentRepositores::add($post_id, 0, 0, $uid, '💰'.$vip_price_tip.'购买了付费内容', '', 1);
  243. // 返回刷新内容
  244. $data = WxPost::where('id', $post_id)->get();
  245. $data = PostsRepositores::postsParame($data, $uid, $scene);
  246. DB::commit();
  247. return $this->success($data);
  248. }
  249. DB::rollBack();
  250. return $this->fail(200037);
  251. }else if($credit_type == 1){
  252. DB::rollBack();
  253. return $this->fail(200004, [], '该接口仅能购买'.Settings::get('app_coin_name', '硬币').'付费内容');
  254. }
  255. }catch (\Exception $e){
  256. DB::rollBack();
  257. _logger_(__file__, __line__, $e->getMessage());
  258. return $this->fail(200037);
  259. }
  260. }
  261. /**
  262. * 添加话题
  263. * @param Request $request
  264. * @return \Illuminate\Http\JsonResponse
  265. */
  266. public function addTag(Request $request)
  267. {
  268. $tags_name = $request->tags_name;
  269. $uid = $request->uid;
  270. _limit_user('add:tag', $uid, 16);
  271. if(mb_strlen($tags_name) > 20){
  272. return $this->fail(200018);
  273. }
  274. // 百度审核
  275. $need_manual_review = true;
  276. $is_audit_create_tag = Settings::get('is_audit_create_tag', 0);
  277. if ($is_audit_create_tag == 2) {
  278. $filter_result = BaiduUtils::text_filter($tags_name);
  279. if($filter_result){
  280. if($filter_result['hit_level'] == 2){
  281. // 不合规
  282. return $this->fail(200016, ['tip'=>$filter_result['tip_list'], 'hit_word'=>$filter_result['hit_word']]);
  283. }else if($filter_result['hit_level'] == 0){
  284. // 审核通过
  285. $need_manual_review = false;
  286. }
  287. }
  288. }else if($is_audit_create_tag == 0){
  289. $need_manual_review = true;
  290. }else{
  291. $need_manual_review = false;
  292. }
  293. // (0正常,1管理员隐藏)
  294. $tags_state = 0;
  295. if($need_manual_review){
  296. $tags_state = 1;
  297. }
  298. UserInputSafeCheckJob::dispatch($uid, $tags_name);
  299. $res = WxTagsRepositories::add($uid, $tags_name, $tags_state);
  300. return $this->success($res);
  301. }
  302. private function updatePost(Request &$request){
  303. $uid = $request->uid;
  304. $posts_id = _abs($request->posts_id);
  305. global $__MINI_GLOBAL_IP__,$__MINI_GLOBAL_TENANT_ID__;
  306. if(_empty_($posts_id)){
  307. return $this->fail(200001);
  308. }
  309. $the_post = WxPost::find($posts_id);
  310. if(_empty_($the_post)){
  311. return $this->fail(200003);
  312. }
  313. $is_admin = is_object_user_special($uid, $the_post->tenant_id);
  314. // 权限验证
  315. if(!$is_admin && !PostUtils::is_post_author($posts_id, $uid)){
  316. return $this->fail(200000);
  317. }
  318. if(!UserUtils::is_user_can_speak($uid)){
  319. return $this->fail(200043, [
  320. 'title' => '禁言中,无法言论',
  321. 'content' => '是否前往解除限制',
  322. 'confirmText' => '去解除',
  323. 'target_type' => 6,
  324. 'target_id' => '/pagesA/mine/unlock/unlock?user_id='.$uid
  325. ], '您当前处于禁言期间,无法言论');
  326. }
  327. $the_post = WxPost::find($posts_id);
  328. $post_author_id = $the_post->user_id;
  329. if($the_post->refer_id > 0 || $the_post->vote_id > 0){
  330. if($the_post->refer_id > 0){
  331. return $this->fail(200000, [], '转发笔记不能编辑');
  332. }
  333. if($the_post->vote_id > 0){
  334. return $this->fail(200000, [], '投票笔记不能编辑');
  335. }
  336. }
  337. $edit_need_coin = Settings::get('app_publish_edit_need_coin', ($__MINI_GLOBAL_TENANT_ID__ > 0 ? Settings::get('app_publish_edit_need_coin', 100) : 100), true);
  338. if($edit_need_coin > 0){
  339. // 判断金币是否足够
  340. if($post_author_id == $uid){
  341. if(UserUtils::user_coins($post_author_id) < $edit_need_coin){
  342. return $this->fail(200011, []);
  343. }
  344. }
  345. }
  346. $contents_all = $request->posts_content;
  347. $contents = trim($request->posts_content);
  348. $circle_id = $request->circle_id;
  349. if(_empty_($circle_id)){
  350. $circle_id = null;
  351. }
  352. $refer_id = $request->refer_id;
  353. $voter_id = _empty_default_($request->voter_id, 0);
  354. $editer = $request->editer ?? 'simple';
  355. $posts_title = _empty_default_($request->posts_title, '');
  356. $imagetext_content = trim($request->imagetext_content) ?? '';
  357. $image_state_change_list = [];
  358. // [["id" => 74,"tags_name" => "啦啦啦啦"],]
  359. $tags = $request->tags;
  360. // [ ["id" => 1045,"name" => "爬宠饲养盒","pic" => "url"], ]
  361. $goods = $request->goods;
  362. // [
  363. // "latitude" => 32.45217
  364. // "longitude" => 118.43575
  365. // "address_name" => "安徽省滁州市来安县东大街9号"
  366. // "address_detailed" => "来安县新安镇永阳社区综治中心(白云商厦东北)"
  367. // ]
  368. $address = $request->address;
  369. // [ ["url" => "url"], ]
  370. $image_urls = $request->image_urls;
  371. // null || video_url
  372. $video_urls = $request->video_url;
  373. // null || img_url
  374. $photo_url = $request->photo_url;
  375. $is_draft = _empty_default_($request->is_draft, 0);
  376. $videoThumbUrl = Utils::isImgUrl($request->video_thumb_url) ? $request->video_thumb_url : '';
  377. // 0 || 1080
  378. $video_width = $request->video_width;
  379. // 0 || 1080
  380. $video_height = $request->video_height;
  381. $useds = _empty_default_($request->useds, []);
  382. $bureaus = _empty_default_($request->bureaus, []);
  383. $sph_obj = null;
  384. $votes = [];
  385. $file_list = $request->file_list;
  386. $sounds_list = $request->sounds_list;
  387. $contact_phone = $request->contact_phone;
  388. $pay_obj = $request->pay_obj;
  389. $is_anonymous = _empty_default_($request->is_anonymous, 0) == 1 ? 1 : 0;
  390. $check_res = $this->checkPost($editer, $is_only_text, $request, $image_state_change_list, $posts_title, $contents, $imagetext_content,$image_urls,$video_urls, $videoThumbUrl,
  391. $refer_id, $useds, $bureaus, $votes, $sph_obj, $file_list, $sounds_list, $contact_phone, $pay_obj, $voter_id);
  392. if ($check_res instanceof JsonResponse) {
  393. return $check_res;
  394. }
  395. if($pay_obj && _array_key($pay_obj, 'price', 0) > 0){
  396. if(WxPostsPayContent::where('post_id', $posts_id)->exists()){
  397. }else{
  398. return $this->fail(200004, [], '笔记不能从免费变更成付费付费');
  399. }
  400. }
  401. // 圈子权限检验
  402. $circle = null;
  403. if(_empty_($refer_id) && $circle_id){
  404. $circle = WxCircle::find($circle_id);
  405. if(Settings::get('app_publish_circle_required', 0, true) == 1){
  406. if($circle){
  407. }else{
  408. return $this->fail(200004, [], '请选择一个'.env('circle_call', '圈子').'再发布吧');
  409. }
  410. }
  411. }
  412. if(!_empty_($refer_id)){
  413. $circle = null;
  414. $circle_id = null;
  415. }
  416. // 百度审核
  417. if(UserUtils::user_permissions_check_by_config($uid, 'audit_posts_white_list')){
  418. $need_manual_review = false;
  419. }else{
  420. $need_manual_review = true;
  421. $setting_is_audit_posts = Settings::get('is_audit_posts', 0);
  422. if ($setting_is_audit_posts == 2) {
  423. $filter_result = BaiduUtils::text_filter($contents);
  424. if($filter_result){
  425. if($filter_result['hit_level'] == 2){
  426. // 不合规
  427. return $this->fail(200016, ['tip'=>$filter_result['tip_list'], 'hit_word'=>$filter_result['hit_word']]);
  428. }else if($filter_result['hit_level'] == 0){
  429. // 审核通过
  430. $need_manual_review = false;
  431. }
  432. }
  433. }else if($setting_is_audit_posts == 0){
  434. $need_manual_review = true;
  435. } else{
  436. $need_manual_review = false;
  437. }
  438. }
  439. // (0待审核,1审核通过,2驳回)
  440. $is_examine = 1;
  441. if($need_manual_review){
  442. $is_examine = 0;
  443. }
  444. // 更新
  445. $contents = trim($contents);
  446. $post_conetnt = _mini_phone( _mini_emoji( _mini_aite_replace( $contents ) ) );
  447. $post_conetnt = $contents_all;
  448. $updates = [
  449. 'posts_content' => $post_conetnt,
  450. ];
  451. $updates['is_draft'] = $is_draft;
  452. if(!_empty_($posts_title)){
  453. $updates['posts_title'] = $posts_title;
  454. }
  455. $updates['is_examine'] = $is_examine;
  456. if($circle_id > 0){
  457. $updates['circle_id'] = $circle_id;
  458. $updates['circle_name'] = ($circle && !_empty_(_array_key($circle, 'circle_name', null))) ? $circle['circle_name'] : '广场';
  459. }
  460. if($sph_obj){
  461. $updates['is_wechat_sph'] = true;
  462. }
  463. if(!_empty_($useds)){
  464. $updates['useds'] = implode(',', $useds);
  465. }
  466. if($contact_phone){
  467. $updates['has_fields'] = 1;
  468. }
  469. if($voter_id > 0){
  470. $updates['voter_id'] = $voter_id;
  471. }else{
  472. $updates['voter_id'] = 0;
  473. }
  474. if (!_empty_($address) && _array_key($address, 'address_name', '')) {
  475. // 有地址
  476. $the_address = WxPostsAddress::updateOrCreate([
  477. 'longitude'=>$address['longitude'], 'latitude'=>$address['latitude']
  478. ], [
  479. 'address_name' => $address['address_name'],
  480. 'address_detailed' => $address['address_detailed'],
  481. ]);
  482. if($the_address){
  483. $updates['address_id'] = $the_address->id;
  484. }
  485. }else{
  486. $updates['address_id'] = 0;
  487. }
  488. WxPostsGoods::where('posts_id', $posts_id)->forceDelete();
  489. if (!_empty_($goods)) {
  490. $updates['goods_id'] = '0';
  491. }else{
  492. $updates['goods_id'] = '';
  493. }
  494. if (!_empty_($file_list)) {
  495. $updates['files_id'] = '0';
  496. }else{
  497. $updates['files_id'] = '';
  498. }
  499. if (!_empty_($sounds_list)) {
  500. $updates['sounds_id'] = '0';
  501. }else{
  502. $updates['sounds_id'] = '';
  503. }
  504. WxPostsTag::where('posts_id', $posts_id)->forceDelete();
  505. if (!_empty_($tags)) {
  506. $updates['goods_id'] = '0';
  507. }else{
  508. $updates['goods_id'] = '';
  509. }
  510. if(!_empty_($votes)){
  511. $updates['vote_id'] = null;
  512. }else{
  513. $updates['vote_id'] = 0;
  514. // WxPostsVote::where('posts_id', $posts_id)->forceDelete();
  515. }
  516. if($is_anonymous){
  517. if($is_anonymous == 1 && Settings::get('app_vip_anonymous_only', 0) == 1){
  518. if(!$is_admin){
  519. $post_author = WxUser::find($post_author_id);
  520. if($post_author && $post_author->is_member){
  521. }else{
  522. return $this->fail(200043, [
  523. 'title' => '仅会员可用',
  524. 'content' => '匿名属于会员特权,是否前往开通',
  525. 'confirmText' => '前往开通',
  526. 'target_type' => 6,
  527. 'target_id' => '/pagesA/mine/members/members'
  528. ], '仅会员可用');
  529. }
  530. }
  531. }
  532. $updates['is_anonymous'] = 1;
  533. }else{
  534. $updates['is_anonymous'] = 0;
  535. }
  536. DB::beginTransaction();
  537. try {
  538. // todo:
  539. $updates['is_only_text'] = null;
  540. $r = WxPost::where('id', $posts_id)->update($updates);
  541. if($r){
  542. if($edit_need_coin > 0){
  543. if($post_author_id == $uid){
  544. UserUtils::update_user_coins($post_author_id, 28, -$edit_need_coin, '重新编辑笔记(id: '.$posts_id.')花费了'.$edit_need_coin.Settings::get('app_coin_name', '硬币').'。');
  545. }
  546. }
  547. // 先检验是否顺序是一样的,或者是仅仅新添加了图片,未改变顺序
  548. if(true){
  549. $current_urls = [];
  550. $old_img_urls = WxPostsImg::where('posts_id', $posts_id)->pluck('img_url')->toArray();
  551. $image_urls_ = $image_urls;
  552. if (!_empty_($image_urls)) {
  553. foreach ($image_urls as $k => $v) {
  554. $current_urls[] = $v['url'];
  555. }
  556. }
  557. if(_empty_($old_img_urls) || _empty_($current_urls)){
  558. if(_empty_($current_urls)){
  559. WxPostsImg::where('posts_id', $posts_id)->forceDelete();
  560. }
  561. }else{
  562. $is_all_equal = false;
  563. $is_pre_equal = false;
  564. if(count($current_urls) == count($old_img_urls)){
  565. $is_all_equal = true;
  566. for ($i = 0; $i<count($current_urls); $i ++){
  567. if($current_urls[$i] != $old_img_urls[$i]){
  568. $is_all_equal = false;
  569. }
  570. }
  571. }else if(count($current_urls) > count($old_img_urls)){
  572. $is_pre_equal = true;
  573. for ($i = 0; $i<count($old_img_urls); $i ++){
  574. if($current_urls[$i] != $old_img_urls[$i]){
  575. $is_pre_equal = false;
  576. }
  577. }
  578. if($is_pre_equal){
  579. $image_urls_ = array_slice($image_urls_, count($old_img_urls));
  580. }
  581. }
  582. if($is_all_equal || $is_pre_equal){
  583. if($is_all_equal){
  584. $image_urls_ = [];
  585. }
  586. }else{
  587. WxPostsImg::where('posts_id', $posts_id)->forceDelete();
  588. }
  589. }
  590. if (!empty($photo_url)) {
  591. WxPostsImg::where('posts_id', $posts_id)->forceDelete();
  592. $postImages = new WxPostsImg();
  593. // $post_img['posts_id'] =$posts_id;
  594. // $post_img['user_id'] =$post_author_id;
  595. // $post_img['img_url'] =$photo_url;
  596. $postImages->posts_id = $posts_id;
  597. $postImages->user_id = $post_author_id;
  598. $postImages->img_url = $photo_url;
  599. // $postImages->add($post_img);
  600. $aas = $postImages->save();
  601. // var_dump($aas);exit;
  602. }
  603. if (!_empty_($image_urls_)) {
  604. $postImage = [];
  605. foreach ($image_urls_ as $k => $v) {
  606. $postImage[$k]['posts_id'] = $posts_id;
  607. $postImage[$k]['user_id'] = $post_author_id;
  608. $postImage[$k]['img_url'] = $v['url'];
  609. if(!StrUtils::endsWith($v['url'] ?? '', '.gif')){
  610. $img_info = ImageUtils::get_url_img_info($v['url']);
  611. if($img_info){
  612. $postImage[$k]['width'] = $img_info['width'];
  613. $postImage[$k]['height'] = $img_info['height'];
  614. }
  615. }else{
  616. $postImage[$k]['width'] = 0;
  617. $postImage[$k]['height'] = 0;
  618. }
  619. }
  620. $postImg = new WxPostsImg();
  621. $postImg->addAll($postImage);
  622. }
  623. }
  624. if(true){
  625. $current_urls = [];
  626. $old_file_urls = WxPostsFile::where('post_id', $posts_id)->pluck('url')->toArray();
  627. $files_ = $file_list;
  628. if (!_empty_($file_list)) {
  629. foreach ($file_list as $k => $v) {
  630. $current_urls[] = $v['url'];
  631. }
  632. }
  633. if(_empty_($old_file_urls) || _empty_($current_urls)){
  634. if(_empty_($current_urls)){
  635. WxPostsFile::where('post_id', $posts_id)->forceDelete();
  636. }
  637. }else{
  638. $is_all_equal = false;
  639. $is_pre_equal = false;
  640. if(count($current_urls) == count($old_file_urls)){
  641. $is_all_equal = true;
  642. for ($i = 0; $i<count($current_urls); $i ++){
  643. if($current_urls[$i] != $old_file_urls[$i]){
  644. $is_all_equal = false;
  645. }
  646. }
  647. }else if(count($current_urls) > count($old_file_urls)){
  648. $is_pre_equal = true;
  649. for ($i = 0; $i<count($old_file_urls); $i ++){
  650. if($current_urls[$i] != $old_file_urls[$i]){
  651. $is_pre_equal = false;
  652. }
  653. }
  654. if($is_pre_equal){
  655. $files_ = array_slice($files_, count($old_file_urls));
  656. }
  657. }
  658. if($is_all_equal || $is_pre_equal){
  659. if($is_all_equal){
  660. $files_ = [];
  661. }
  662. }else{
  663. WxPostsFile::where('post_id', $posts_id)->forceDelete();
  664. }
  665. }
  666. if(!_empty_($files_)){
  667. foreach ($files_ as $file){
  668. if($file['name'] && $file['url']){
  669. $file_model = new WxPostsFile();
  670. $file_model->name = $file['name'];
  671. $file_model->url = $file['url'];
  672. $file_model->size = _array_key($file, 'size', 0);
  673. $file_model->post_id = $posts_id;
  674. $file_model->save();
  675. }
  676. }
  677. }
  678. }
  679. if(true){
  680. $current_urls = [];
  681. $old_sound_urls = WxPostsSound::where('post_id', $posts_id)->pluck('url')->toArray();
  682. $sounds_list_ = $sounds_list;
  683. if (!_empty_($sounds_list)) {
  684. foreach ($sounds_list as $k => $v) {
  685. $current_urls[] = $v['url'];
  686. }
  687. }
  688. if(_empty_($old_sound_urls) || _empty_($current_urls)){
  689. if(_empty_($current_urls)){
  690. WxPostsSound::where('post_id', $posts_id)->forceDelete();
  691. }
  692. }else{
  693. $is_all_equal = false;
  694. $is_pre_equal = false;
  695. if(count($current_urls) == count($old_sound_urls)){
  696. $is_all_equal = true;
  697. for ($i = 0; $i<count($current_urls); $i ++){
  698. if($current_urls[$i] != $old_sound_urls[$i]){
  699. $is_all_equal = false;
  700. }
  701. }
  702. }else if(count($current_urls) > count($old_sound_urls)){
  703. $is_pre_equal = true;
  704. for ($i = 0; $i<count($old_sound_urls); $i ++){
  705. if($current_urls[$i] != $old_sound_urls[$i]){
  706. $is_pre_equal = false;
  707. }
  708. }
  709. if($is_pre_equal){
  710. $sounds_list_ = array_slice($sounds_list_, count($old_sound_urls));
  711. }
  712. }
  713. if($is_all_equal || $is_pre_equal){
  714. if($is_all_equal){
  715. $sounds_list_ = [];
  716. }
  717. }else{
  718. WxPostsSound::where('post_id', $posts_id)->forceDelete();
  719. }
  720. }
  721. if(!_empty_($sounds_list_)){
  722. foreach ($sounds_list_ as $sound){
  723. $sound_model = new WxPostsSound();
  724. $sound_model->name = $sound['name'];
  725. $sound_model->time = $sound['time'];
  726. $sound_model->url = $sound['url'];
  727. $sound_model->post_id = $posts_id;
  728. $sound_model->save();
  729. }
  730. }
  731. }
  732. if (!_empty_($video_urls)) {
  733. $video_updates = [
  734. 'video_url' => $video_urls,
  735. 'video_thumb_url' => $videoThumbUrl,
  736. 'video_width' => $video_width,
  737. 'video_height' => $video_height
  738. ];
  739. $attachment = FileUtils::get_url_attach($video_urls);
  740. if($attachment->state == 2){
  741. // 状态(0正常,1用户删除,2管理员下架, 3审核中 4冻结中 5已清理)
  742. $video_updates['posts_video_state'] = 5;
  743. }else if($attachment->state == 3 || $attachment->state == 4){
  744. $video_updates['posts_video_state'] = 4;
  745. }else if(in_array($attachment->cos_review, [3,4,5])){
  746. $video_updates['posts_video_state'] = 3;
  747. }
  748. WxPostsVideo::updateOrCreate(['posts_id'=>$posts_id, 'user_id'=>$post_author_id], $video_updates);
  749. }
  750. if(!_empty_($votes)){
  751. $vote_updates = [];
  752. foreach ([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] as $num){
  753. if(_array_key($votes, $num - 1, '')){
  754. $vote_updates['option'.$num] = _array_key($votes, $num - 1, '');
  755. }
  756. }
  757. WxPostsVote::updateOrCreate([
  758. 'post_id' => $posts_id
  759. ],$vote_updates);
  760. }
  761. Utils::image_state_change($image_state_change_list, 1);
  762. if($pay_obj && _array_key($pay_obj, 'price', 0) > 0){
  763. WxPostsPayContent::where('post_id', $posts_id)->update([
  764. 'words_percent' => _array_key($pay_obj, 'words_percent', 100),
  765. 'is_file' => _array_key($pay_obj, 'is_file', 0),
  766. 'is_img' => _array_key($pay_obj, 'is_img', 0),
  767. 'is_video' => _array_key($pay_obj, 'is_video', 0),
  768. 'is_sound' => 0,
  769. 'hidden' => _array_key($pay_obj, 'hidden', ''),
  770. 'price' => _array_key($pay_obj, 'price', 0),
  771. 'credit_type' => _array_key($pay_obj, 'credit_type', 0)
  772. ]);
  773. }
  774. if (!_empty_($goods)) {
  775. $postGoods = [];
  776. foreach ($goods as $k => $v) {
  777. $postGoods[$k]['posts_id'] = $posts_id;
  778. $postGoods[$k]['goods_id'] = $v['id'];
  779. Redis::sadd('realtime:others:set', json_encode([$v['id'], 3, 10]));
  780. }
  781. $goods = new WxPostsGoods();
  782. $goods->addAll($postGoods);
  783. }
  784. if (!_empty_($tags)) {
  785. $postTag = [];
  786. $tagsIds = [];
  787. foreach ($tags as $k => $v) {
  788. $postTag[$k]['posts_id'] = $posts_id;
  789. $postTag[$k]['tags_id'] = $v['id'];
  790. $tagsIds[] = $v['id'];
  791. Redis::sadd('realtime:others:set', json_encode([$v['id'], 5, 10]));
  792. }
  793. $tags = new WxPostsTag();
  794. $tags->addAll($postTag);
  795. WxTag::whereIn('id', $tagsIds)->increment('tags_number');
  796. if($circle_id > 0){
  797. CircleUtils::add_circle_tags($circle_id, $tagsIds);
  798. }
  799. }
  800. if(_array_key($updates, 'has_fields', 0) == 1){
  801. WxPostsField::updateOrCreate(['post_id'=>$posts_id],['contact_phone'=>$contact_phone]);
  802. }else{
  803. if(_empty_($contact_phone)){
  804. WxPostsField::updateOrCreate(['post_id'=>$posts_id],['contact_phone'=>null]);
  805. }
  806. }
  807. if($circle_id > 0){
  808. Redis::sadd('realtime:others:set', json_encode([$circle_id, 2, 10]));
  809. }
  810. Redis::sadd('realtime:others:set', json_encode([$post_author_id, 4, 10]));
  811. if(_array_key($updates, 'is_wechat_sph', false) == true){
  812. update_post_meta($posts_id, 'wechat_sph', $sph_obj, 'j');
  813. }
  814. if($circle_id){
  815. Cache::forget('circle:postCount:'.$circle_id);
  816. }
  817. Cache::forget('user:post:count:'.$post_author_id);
  818. // 视频封面
  819. if($video_urls && _empty_($videoThumbUrl)){
  820. VideoSnapshotJob::dispatch(WxPostsVideo::where('posts_id', $posts_id)->value('id'));
  821. }
  822. Cache::forget('posts:post_type:'.$posts_id);
  823. Cache::forget('get_the_title:'.$posts_id.':30');
  824. Cache::forget('get_the_title:'.$posts_id.':15');
  825. Cache::forget('get_the_title:'.$posts_id.':100');
  826. Cache::forget('get:post:goods:'.$posts_id);
  827. Cache::forget('get:post:tags:'.$posts_id);
  828. Cache::forget('get:post:files:'.$posts_id);
  829. Cache::forget('get:post:sounds:'.$posts_id);
  830. UpdatePostVideoIdJob::dispatch($posts_id);
  831. UpdatePostTagIdJob::dispatch($posts_id);
  832. UpdatePostOnlyTextJob::dispatch($posts_id);
  833. if($is_examine === 0){
  834. UserUtils::assistant_notice_review(101, $posts_id);
  835. }
  836. DB::commit();;
  837. return $this->success(['id'=>$posts_id, 'post_id'=>$posts_id, 'tip'=> '修改成功', 'ok' => Settings::get('app_publish_success_popup', 0) == 1 ? 1 : 2, 'target_type' => -6, 'target_id' => '/pages/sticky/sticky?id='.$posts_id, 'promotion' => 1]);
  838. }
  839. DB::rollBack();
  840. return $this->fail(200006);
  841. } catch (\Exception $e) {
  842. DB::rollBack();
  843. _logger_(__file__, __line__, $e->getMessage());
  844. return $this->fail(200006);
  845. }
  846. }
  847. private function checkPost(&$editer, &$is_only_text, &$request, &$image_state_change_list, &$posts_title, &$contents, &$imagetext_content, &$image_urls, &$video_urls, &$videoThumbUrl,
  848. &$refer_id, &$useds, &$bureaus, &$votes, &$sph_obj, &$file_list, &$sounds_list, &$contact_phone, &$pay_obj, $voter_id){
  849. // todo: 1
  850. if(true){
  851. if(_empty_($refer_id)){
  852. $refer_id = 0;
  853. }else{
  854. $refer_id = _abs($refer_id);
  855. }
  856. if($refer_id > 0){
  857. $refer_post_refer_id = WxPost::where('id', $refer_id)->value('refer_id');
  858. if($refer_post_refer_id > 0){
  859. return $this->fail(200010, [], '该笔记为转发内容,不能再次转发');
  860. }
  861. }
  862. if(_empty_($voter_id)){
  863. $voter_id = 0;
  864. }else{
  865. $voter_id = _abs($voter_id);
  866. }
  867. if($voter_id > 0){
  868. if(WxVoter::where('id', $voter_id)->exists()){
  869. }else{
  870. return $this->fail(200003, [], '鞋带的选票实际不存在');
  871. }
  872. }
  873. }
  874. // todo: 2
  875. if(true){
  876. if(!_empty_($useds)){
  877. $useds = explode(',', $useds);
  878. if(count(array_unique($useds)) != count($useds)){
  879. return $this->fail(200004, [], '闲置商品有重复');
  880. }
  881. if(WxUsedGood::whereIn('id', $useds)->count() != count($useds)){
  882. return $this->fail(200004, [], '闲置商品参数检验不合法');
  883. }
  884. }
  885. if(_empty_($useds)){
  886. $useds = [];
  887. }else{
  888. if(!is_array($useds)){
  889. return $this->fail(200004, [], '闲置商品参数检验不合法');
  890. }
  891. if(count($useds) > 5){
  892. return $this->fail(200004, [], '最多选择5个闲置商品');
  893. }
  894. $is_only_text = false;
  895. }
  896. }
  897. // todo: 4
  898. if(true){
  899. $vote_list = $request->vote_list;
  900. if($vote_list && count($vote_list) >= 2){
  901. foreach ($vote_list as $vote){
  902. if($vote['value']){
  903. $votes[] = $vote['value'];
  904. }
  905. }
  906. if(count($votes) != count($vote_list)){
  907. return $this->fail(200004);
  908. }
  909. }
  910. }
  911. // todo: 5
  912. if(true){
  913. $sph_video_feed_token = $request->sph_video_feed_token;
  914. $sph_image_urls = $request->sph_image_urls;
  915. if(_empty_($sph_video_feed_token) || strpos($sph_video_feed_token, 'token/') !== 0){
  916. $sph_video_feed_token = null;
  917. $sph_image_urls = null;
  918. }else{
  919. $sph_video_feed_token = trim($sph_video_feed_token);
  920. }
  921. if(_empty_($sph_image_urls)){
  922. $sph_image_urls = null;
  923. }
  924. $sph_img = '';
  925. if($sph_video_feed_token){
  926. if($sph_image_urls && _array_key($sph_image_urls[0], 'url', '')){
  927. $sph_img = $sph_image_urls[0]['url'];
  928. }
  929. $sph_obj = [
  930. 'type' => 'video',
  931. 'feed_token' => $sph_video_feed_token,
  932. 'img' => $sph_img
  933. ];
  934. if($sph_img){
  935. $image_state_change_list[] = $sph_img;
  936. }
  937. $is_only_text = false;
  938. }
  939. }
  940. // todo: 6
  941. if(true){
  942. if(!_empty_($file_list)){
  943. if(count($file_list) > Settings::get('app_upload_max_files', 5, true)){
  944. return $this->fail(200020);
  945. }
  946. foreach ($file_list as $file){
  947. if(_empty_(_array_key($file, 'name', '')) || _empty_(_array_key($file, 'url', ''))){
  948. return $this->fail(200019);
  949. }
  950. }
  951. }else{
  952. $file_list = [];
  953. }
  954. }
  955. // todo: 7
  956. if(true){
  957. if(!_empty_($sounds_list)){
  958. if(count($sounds_list) > Settings::get('app_upload_max_sounds', 1, true)){
  959. return $this->fail(200023);
  960. }
  961. foreach ($sounds_list as $sound){
  962. if(_empty_(_array_key($sound, 'name', '')) || _empty_(_array_key($sound, 'url', '')) || _empty_(_array_key($sound, 'time', ''))){
  963. return $this->fail(200024);
  964. }
  965. if(strpos($sound['url'], 'http') === false){
  966. return $this->fail(200024);
  967. }
  968. }
  969. }else{
  970. $sounds_list = [];
  971. }
  972. }
  973. // todo: 8
  974. if(true){
  975. if(!_empty_($contact_phone)){
  976. if(!StrUtils::is_phone_number($contact_phone)){
  977. return $this->fail(200004, [], '联系手机号不合法');
  978. }
  979. }else{
  980. $contact_phone = null;
  981. }
  982. }
  983. // todo: 9
  984. if(true){
  985. if($pay_obj && _array_key($pay_obj, 'price', 0) > 0){
  986. if(_array_key($pay_obj, 'words_percent', 100) == 100 && _array_key($pay_obj, 'is_file', 0) == 0 && _array_key($pay_obj, 'is_img', 0) == 0 && _array_key($pay_obj, 'is_video', 0) == 0 && _array_key($pay_obj, 'hidden', '') == '' ){
  987. return $this->fail(200029);
  988. }
  989. if(!in_array(_array_key($pay_obj, 'credit_type', 0), [0, 1])){
  990. return $this->fail(200004);
  991. }
  992. if(_array_key($pay_obj, 'credit_type', 0) == 0){
  993. if(_array_key($pay_obj, 'price', 0) > Settings::get('app_pay_max_coins', 10000)){
  994. return $this->fail(200030);
  995. }
  996. }else if(_array_key($pay_obj, 'credit_type', 0) == 1){
  997. if(_array_key($pay_obj, 'price', 0) > Settings::get('app_pay_max_balance', 1000)){
  998. return $this->fail(200030);
  999. }
  1000. }
  1001. if(_array_key($pay_obj, 'words_percent', 100) < 100){
  1002. if(_array_key($pay_obj, 'words_percent', 100) > 90 || _array_key($pay_obj, 'words_percent', 100) < 50){
  1003. return $this->fail(200032);
  1004. }
  1005. if(mb_strlen(strip_tags($contents)) < 50){
  1006. return $this->fail(200031, [], '若开启篇幅付费,笔记内容不能少于50字');
  1007. }
  1008. }
  1009. if(_array_key($pay_obj, 'is_file', 100) == 1 && count($file_list) <= 0){
  1010. return $this->fail(200004);
  1011. }
  1012. if(_array_key($pay_obj, 'is_img', 100) == 1 && count($image_urls) <= 0){
  1013. return $this->fail(200004);
  1014. }
  1015. if(_array_key($pay_obj, 'is_video', 100) == 1 && _empty_($video_urls)){
  1016. return $this->fail(200004);
  1017. }
  1018. $is_only_text = false;
  1019. }else{
  1020. $pay_obj = [];
  1021. }
  1022. }
  1023. if(true){
  1024. // 内容修正部分
  1025. if($editer == 'imagetext'){
  1026. $contents = $imagetext_content;
  1027. if(!preg_match('/<(img|video|table|audio|a)[^>]+>/is', $contents)){
  1028. $contents = strip_tags($contents, ['<a>', '<br>', '<p>']);
  1029. }else{
  1030. $is_only_text = false;
  1031. }
  1032. $image_urls = null;
  1033. $video_urls = null;
  1034. $videoThumbUrl = null;
  1035. $votes = null;
  1036. $posts_title = trim(strip_tags($posts_title));
  1037. if(_empty_($posts_title)){
  1038. // $posts_title = '';
  1039. }
  1040. }else{
  1041. // $posts_title = '';
  1042. }
  1043. if($refer_id > 0){
  1044. $contents = strip_tags($contents);
  1045. $is_only_text = false;
  1046. }
  1047. $contents = PostUtils::post_icon_inline_process($contents);
  1048. // 内容检测
  1049. if(mb_strlen(strip_tags($contents)) <= 0){
  1050. if($editer == 'imagetext'){
  1051. if(_empty_($posts_title)){
  1052. return $this->fail(200025);
  1053. }
  1054. }else{
  1055. return $this->fail(200025);
  1056. }
  1057. }else if(preg_match('$这是一段示例$', strip_tags($contents))){
  1058. return $this->fail(200026);
  1059. }
  1060. if($image_urls){
  1061. foreach ($image_urls as $img){
  1062. if(is_array($img)){
  1063. $image_state_change_list[] = $img['url'];
  1064. }else{
  1065. $image_state_change_list[] = $img;
  1066. }
  1067. }
  1068. $is_only_text = false;
  1069. }
  1070. if($video_urls){
  1071. $image_state_change_list[] = $video_urls;
  1072. $is_only_text = false;
  1073. }
  1074. if($videoThumbUrl){
  1075. $image_state_change_list[] = $videoThumbUrl;
  1076. }
  1077. if(!_empty_($file_list)){
  1078. foreach ($file_list as $file){
  1079. $image_state_change_list[] = $file['url'];
  1080. }
  1081. $is_only_text = false;
  1082. }
  1083. if(!_empty_($sounds_list)){
  1084. foreach ($sounds_list as $sound){
  1085. $image_state_change_list[] = $sound['url'];
  1086. }
  1087. $is_only_text = false;
  1088. }
  1089. preg_match_all("/<(img|video).*?src[^\'\"]+[\'\"]([^\"\']+)[^>]+>/is", $contents, $result);
  1090. $post_images_arr = $result[2];
  1091. if($post_images_arr){
  1092. foreach ($post_images_arr as $url){
  1093. $image_state_change_list[] = $url;
  1094. }
  1095. }
  1096. }
  1097. }
  1098. /**
  1099. * 发帖
  1100. * @param Request $request
  1101. * @return \Illuminate\Http\JsonResponse
  1102. */
  1103. public function addPost(Request $request)
  1104. {
  1105. global $__MINI_GLOBAL_TENANT_ID__,$__MINI_GLOBAL_CURRENT_PLAYER_ID__,$__MINI_GLOBAL_DEVICE__,$__MINI_GLOBAL_IS_ADMIN_SUPER__;
  1106. $uid = $request->uid;
  1107. $is_only_text = true;
  1108. $is_admin = UserUtils::is_mini_admin($uid);
  1109. if(true){
  1110. if(!UserUtils::is_user_can_speak($uid)){
  1111. return $this->fail(200043, [
  1112. 'title' => '禁言中,无法言论',
  1113. 'content' => '是否前往解除限制',
  1114. 'confirmText' => '去解除',
  1115. 'target_type' => 6,
  1116. 'target_id' => '/pagesA/mine/unlock/unlock?user_id='.$uid
  1117. ], '您当前处于禁言期间,无法言论');
  1118. }
  1119. if(!$is_admin && Cache::has('addPost:time:'.$__MINI_GLOBAL_TENANT_ID__.':'.$uid)){
  1120. return $this->fail(200027);
  1121. }
  1122. if(!$is_admin && !str_contains(env(_multi_key('APP_PUBLISH_POST_SPH_USER'), ''), $uid) && (WxPost::where('user_id', $uid)->where('tenant_id', $__MINI_GLOBAL_TENANT_ID__)->whereDate('created_at', current_time('day'))->count() >= Settings::get('app_publish_times_max', 3, true))){
  1123. return $this->fail(200028);
  1124. }
  1125. $arr = UserUtils::user_action_permissions_check($uid, 'publish_post');
  1126. if($arr['code'] == 0){
  1127. return $this->fail(200000, [], $arr['msg']);
  1128. }
  1129. $user = WxUser::find($uid);
  1130. // if(mb_strlen( str_replace( [Settings::get('default_user_name', '微信用户'), '微信用户', '普通用户'], '', $user->user_name )) != mb_strlen($user->user_name)){
  1131. // return $this->fail(200041);
  1132. // }
  1133. // 验证资料
  1134. if(Settings::get('app_publish_force_bind_phone', 0, true) == 1){
  1135. if(_empty_($user->phone) && _empty_($__MINI_GLOBAL_CURRENT_PLAYER_ID__)){
  1136. return $this->fail(200043, [
  1137. 'title' => '未绑定手机号',
  1138. 'content' => '前往绑定',
  1139. 'confirmText' => '去绑定',
  1140. 'target_type' => 6,
  1141. 'target_id' => '/pagesA/mine/editmine/editmine?phone=1'
  1142. ], '未绑定手机号');
  1143. }
  1144. }
  1145. if(Settings::get('app_publish_force_real_name', 0, true) == 1){
  1146. if(_empty_($user->real_name) && _empty_($__MINI_GLOBAL_CURRENT_PLAYER_ID__)){
  1147. return $this->fail(200043, [
  1148. 'title' => '未实名认证',
  1149. 'content' => '您还没有实名认证,是否前往认证',
  1150. 'confirmText' => '去认证',
  1151. 'target_type' => 6,
  1152. 'target_id' => '/pagesA/mine/realname/realname'
  1153. ], '未实名认证');
  1154. }
  1155. }
  1156. $force_university = Settings::get('app_publish_force_university', [], true);
  1157. if(!_empty_($force_university)){
  1158. if(_empty_($user->university)){
  1159. return $this->fail(200043, [
  1160. 'title' => '未学生认证',
  1161. 'content' => '您还没有学生认证,是否前往认证',
  1162. 'confirmText' => '去认证',
  1163. 'target_type' => 6,
  1164. 'target_id' => '/pagesA/attestation/attestation'
  1165. ], '未学生认证');
  1166. }else{
  1167. if(!in_array('-1', $force_university)) {
  1168. $student_certify = WxUserStudentCertify::find($user->id);
  1169. if ($student_certify) {
  1170. if (!in_array($student_certify->sid, $force_university)) {
  1171. return $this->fail(200000, [], '仅“' . Settings::get('app_publish_force_university_tip', '', true) . '”可发布');
  1172. }
  1173. }
  1174. }
  1175. }
  1176. }
  1177. if(Settings::get('app_publish_force_subscribe_mp', 0, true) == 1){
  1178. if(_empty_($user->weixin_mp_openid) && _empty_($__MINI_GLOBAL_CURRENT_PLAYER_ID__)){
  1179. $weapp = new WeApp('mp');
  1180. $mpServicer = $weapp->getMpServicer();
  1181. try {
  1182. $url = $mpServicer->getQrCodeWithPara(0, 'user:bind:'.$user->id);
  1183. }catch (\Exception $e){
  1184. return $this->fail(200006, [], '生成公众号二维码失败,请检查[全局配置-支付-微信-公众号]');
  1185. }
  1186. if($url){
  1187. $qrCode = QrCode::format('png')->size(300)->generate($url);
  1188. $image = Image::make($qrCode);
  1189. $image->resizeCanvas(300, 300 + 60, 'bottom', false, '#ffffff'); // 增加高度,保持宽高比,背景色为白色
  1190. $mp_app_name = Settings::get('mp_app_name', '');
  1191. $text_tip = '关注'.$mp_app_name.'公众号,可以更方便通知到您';
  1192. if(mb_strlen($mp_app_name) > 4){
  1193. $text_tip = '关注'.$mp_app_name.'公众号';
  1194. }
  1195. $image->text($text_tip, 150, 40, function($font){
  1196. $font->file(public_path('storage/font/DingTalk_JinBuTi_Regular.ttf')); // 字体文件路径
  1197. $font->size(13); // 字体大小
  1198. $font->color('#000000'); // 字体颜色
  1199. $font->align('center'); // 水平对齐
  1200. $font->valign('top'); // 垂直对齐
  1201. });
  1202. $base64 = 'data:image/png;base64,' . base64_encode($image->encode('png')->getEncoded());
  1203. return $this->fail(200043, [
  1204. 'title' => '未关注公众号,无法实时获取通知',
  1205. 'content' => '前往关注',
  1206. 'confirmText' => '去关注',
  1207. 'target_type' => 26,
  1208. 'target_id' => $base64
  1209. ], '未关注公众号');
  1210. }
  1211. }
  1212. }
  1213. }
  1214. $contents_all = $request->posts_content;
  1215. $contents = trim($request->posts_content);
  1216. $circle_id = $request->circle_id;
  1217. if(_empty_($circle_id)){
  1218. $circle_id = null;
  1219. }
  1220. $refer_id = _empty_default_($request->refer_id, 0);
  1221. $voter_id = _empty_default_($request->voter_id, 0);
  1222. $photo_url = _empty_default_($request->photo_url, 0);
  1223. $is_draft = _empty_default_($request->is_draft, 0);
  1224. $editer = $request->editer ?? 'simple';
  1225. $posts_title = _empty_default_($request->posts_title, '');
  1226. $imagetext_content = trim($request->imagetext_content) ?? '';
  1227. $image_state_change_list = [];
  1228. // [["id" => 74,"tags_name" => "啦啦啦啦"],]
  1229. $tags = $request->tags;
  1230. // [ ["id" => 1045,"name" => "爬宠饲养盒","pic" => "url"], ]
  1231. $goods = $request->goods;
  1232. // [
  1233. // "latitude" => 32.45217
  1234. // "longitude" => 118.43575
  1235. // "address_name" => "安徽省滁州市来安县东大街9号"
  1236. // "address_detailed" => "来安县新安镇永阳社区综治中心(白云商厦东北)"
  1237. // ]
  1238. $address = $request->address;
  1239. // [ ["url" => "url"], ]
  1240. $image_urls = $request->image_urls;
  1241. // null || video_url
  1242. $video_urls = $request->video_url;
  1243. // null || img_url
  1244. $videoThumbUrl = Utils::isImgUrl($request->video_thumb_url) ? $request->video_thumb_url : '';
  1245. // 0 || 1080
  1246. $video_width = $request->video_width;
  1247. // 0 || 1080
  1248. $video_height = $request->video_height;
  1249. $useds = _empty_default_($request->useds, []);
  1250. $bureaus = _empty_default_($request->bureaus, []);
  1251. $sph_obj = null;
  1252. $votes = [];
  1253. $file_list = $request->file_list;
  1254. $sounds_list = $request->sounds_list;
  1255. $contact_phone = $request->contact_phone;
  1256. $pay_obj = $request->pay_obj;
  1257. $is_anonymous = _empty_default_($request->is_anonymous, 0) == 1 ? 1 : 0;
  1258. if($is_anonymous == 1 && Settings::get('app_vip_anonymous_only', 0) == 1){
  1259. if($user->is_member){
  1260. }else{
  1261. return $this->fail(200043, [
  1262. 'title' => '仅会员可用',
  1263. 'content' => '匿名属于会员特权,是否前往开通',
  1264. 'confirmText' => '前往开通',
  1265. 'target_type' => 6,
  1266. 'target_id' => '/pagesA/mine/members/members'
  1267. ], '仅会员可用');
  1268. }
  1269. }
  1270. $check_res = $this->checkPost($editer, $is_only_text, $request, $image_state_change_list, $posts_title, $contents, $imagetext_content,$image_urls,$video_urls, $videoThumbUrl,
  1271. $refer_id, $useds, $bureaus, $votes, $sph_obj, $file_list, $sounds_list, $contact_phone, $pay_obj, $voter_id);
  1272. if ($check_res instanceof JsonResponse) {
  1273. return $check_res;
  1274. }
  1275. // 圈子权限检验
  1276. $circle = null;
  1277. if(_empty_($refer_id) && $circle_id){
  1278. $circle = WxCircle::find($circle_id);
  1279. if(Settings::get('app_publish_circle_required', 0, true) == 1){
  1280. if($circle){
  1281. }else{
  1282. return $this->fail(200004, [], '请选择一个'.env('circle_call', '圈子').'再发布吧');
  1283. }
  1284. }
  1285. }
  1286. if(!_empty_($refer_id)){
  1287. $circle = null;
  1288. $circle_id = null;
  1289. }
  1290. // 百度审核
  1291. if(UserUtils::user_permissions_check_by_config($uid, 'audit_posts_white_list')){
  1292. $need_manual_review = false;
  1293. }else if($sph_obj && !_empty_(_array_key($sph_obj, 'feed_token', '')) && str_contains(env(_multi_key('APP_PUBLISH_POST_SPH_USER'), ''), $uid)){
  1294. $need_manual_review = false;
  1295. }else{
  1296. $need_manual_review = true;
  1297. $setting_is_audit_posts = Settings::get('is_audit_posts', 0);
  1298. if ($setting_is_audit_posts == 2) {
  1299. $filter_result = BaiduUtils::text_filter($contents);
  1300. if($filter_result){
  1301. if($filter_result['hit_level'] == 2){
  1302. // 不合规
  1303. return $this->fail(200016, ['tip'=>$filter_result['tip_list'], 'hit_word'=>$filter_result['hit_word']]);
  1304. }else if($filter_result['hit_level'] == 0){
  1305. // 审核通过
  1306. $need_manual_review = false;
  1307. }
  1308. }
  1309. }else if($setting_is_audit_posts == 0){
  1310. $need_manual_review = true;
  1311. } else{
  1312. $need_manual_review = false;
  1313. }
  1314. }
  1315. // (0待审核,1审核通过,2驳回)
  1316. $is_examine = 1;
  1317. if($need_manual_review){
  1318. $is_examine = 0;
  1319. }
  1320. $pay_content_id = 0;
  1321. if($pay_obj && _array_key($pay_obj, 'price', 0) > 0){
  1322. $pay_content = new WxPostsPayContent();
  1323. $pay_content->post_id = -$uid;
  1324. $pay_content->words_percent = _array_key($pay_obj, 'words_percent', 100);
  1325. $pay_content->is_file = _array_key($pay_obj, 'is_file', 0);
  1326. $pay_content->is_img = _array_key($pay_obj, 'is_img', 0);
  1327. $pay_content->is_video = _array_key($pay_obj, 'is_video', 0);
  1328. $pay_content->is_sound = 0;
  1329. $pay_content->hidden = _array_key($pay_obj, 'hidden', '');
  1330. $pay_content->price = _array_key($pay_obj, 'price', 0);
  1331. $pay_content->credit_type = _array_key($pay_obj, 'credit_type', 0);
  1332. $pay_content->save();
  1333. $pay_content_id = $pay_content->id;
  1334. $is_only_text = false;
  1335. }
  1336. if(_empty_($refer_id) && $circle){
  1337. $res = CircleUtils::user_can_publish($user, $circle);
  1338. if($res['code'] == 0){
  1339. return $this->fail(200000, [], $res['tip']);
  1340. }else if($res['code'] == 200011 || $res['code'] == 200012){
  1341. return $this->fail($res['code'], [], $res['tip']);
  1342. }
  1343. }
  1344. if($image_state_change_list && count($image_state_change_list) > 0){
  1345. $is_only_text = false;
  1346. }
  1347. if($is_only_text){
  1348. if(Settings::get('app_publish_media_required', 0, true) == 1 && !$__MINI_GLOBAL_IS_ADMIN_SUPER__){
  1349. return $this->fail(200001, [], '笔记需要带上视频或图片哦');
  1350. }
  1351. }
  1352. if(Cache::has('lock:add:post:'.$uid)){
  1353. // return $this->fail(700003);
  1354. }
  1355. Cache::put('lock:add:post:'.$uid, 1, 60);
  1356. $post_id = PostsRepositores::add($uid, $is_examine, $posts_title, $contents_all, $circle_id, $tags, $goods, $image_urls, $video_urls, $address, $videoThumbUrl, $video_width, $video_height, $votes, $file_list, $sounds_list, $pay_content_id, $__MINI_GLOBAL_DEVICE__, $refer_id, $contact_phone, $sph_obj, $useds, $bureaus, $is_anonymous, $voter_id,$photo_url,$is_draft);
  1357. Cache::forget('lock:add:post:'.$uid);
  1358. if ($post_id) {
  1359. if(Settings::get('app_publish_frequency_min', 10, true) > 0){
  1360. Cache::put('addPost:time:'.$__MINI_GLOBAL_TENANT_ID__.':'.$uid, 1, 60 * Settings::get('app_publish_frequency_min', 10, true));
  1361. }
  1362. if($circle_id){
  1363. Cache::forget('circle:postCount:'.$circle_id);
  1364. ForgetCircleUnreadCountJob::dispatch($circle_id);
  1365. $online_user_ids = UserUtils::user_onlines(1);
  1366. if($online_user_ids && is_array($online_user_ids)){
  1367. if($online_user_ids > 100){
  1368. $online_user_ids = WxUserCircle::whereIn('user_id', $online_user_ids)->where('circle_id', $circle_id)->where('user_circle_state', 0)->pluck('user_id')->toArray();
  1369. }
  1370. if($online_user_ids && is_array($online_user_ids)){
  1371. foreach ($online_user_ids as $online_user){
  1372. Cache::forget('user_circle_unread_count:'.$online_user);
  1373. }
  1374. }
  1375. }
  1376. }
  1377. Cache::forget('user:post:count:'.$uid);
  1378. // 视频封面
  1379. if($video_urls && _empty_($videoThumbUrl)){
  1380. VideoSnapshotJob::dispatch(WxPostsVideo::where('posts_id', $post_id)->value('id'));
  1381. }
  1382. UserUtils::add_user_experience($uid, 1);
  1383. GatewayUtils::success('all', 6);
  1384. CreatePostSyncJob::dispatch($post_id, $uid, $contents, $circle_id, $tags, $goods, $image_urls, $video_urls, $address, $videoThumbUrl, $video_width, $video_height);
  1385. UserInputSafeCheckJob::dispatch($uid, $contents);
  1386. Utils::image_state_change($image_state_change_list, 1);
  1387. UserPublishedFollowJob::dispatch($uid, $circle_id, '')->delay(now()->addSeconds(5));
  1388. // 机器人点赞
  1389. CalculateLikesNumJob::dispatch($post_id);
  1390. UpdatePostVideoIdJob::dispatch($post_id);
  1391. UpdatePostTagIdJob::dispatch($post_id);
  1392. CalculateFollowsNumJob::dispatch($uid);
  1393. Redis::sadd('realtime:post:set', $post_id);
  1394. UpdatePostOnlyTextJob::dispatch(0);
  1395. if($circle_id > 0){
  1396. ImitateCircleJoinStepJob::dispatch($circle_id, mini_rand(1, 100) <= 60 ? mini_rand(1, 2) : 0)->delay(now()->addMinutes(mini_rand(1, 20)));
  1397. }
  1398. // 订阅消息id
  1399. $tmplIds = [];
  1400. if($__MINI_GLOBAL_DEVICE__ == 'mp'){
  1401. $comment_add_id = Settings::get('mini_template_message_comment_add', '');
  1402. if(!_empty_($comment_add_id)){
  1403. $tmplIds[] = $comment_add_id;
  1404. }
  1405. $exceptional_id = Settings::get('mini_template_message_exceptional', '');
  1406. if(!_empty_($exceptional_id)){
  1407. $tmplIds[] = $exceptional_id;
  1408. }
  1409. $beliked_id = Settings::get('mini_template_message_beliked', '');
  1410. if(!_empty_($beliked_id)){
  1411. $tmplIds[] = $beliked_id;
  1412. }
  1413. }
  1414. if($is_examine == 0){
  1415. // 待审核
  1416. //给对应圈子圈主发送待审核信息
  1417. if($circle){
  1418. UserUtils::assistant_notice($circle['user_id'], '您创建的'.env('circle_call', '圈子').'「' . '<a href="/pages/circle/list?id='.$circle['id'].'">'.$circle['circle_name'].'</a>' . '」有一篇新的内容等待您去审核哦,请务必在24小时内进行处理。');
  1419. // UserUtils::assistant_notice('admin', '圈子「' . '<a href="/pages/circle/list?id='.$circle['id'].'">'.$circle['circle_name'].'</a>' . '」有一篇新的笔记等待您去审核哦!');
  1420. UserUtils::assistant_notice_review(101, $post_id);
  1421. }else{
  1422. UserUtils::assistant_notice_review(101, $post_id);
  1423. }
  1424. }else{
  1425. // 审核通过
  1426. //给对应圈子圈主发送新内容信息
  1427. if($circle){
  1428. UserUtils::assistant_notice($circle['user_id'], '您创建的'.env('circle_call', '圈子').'「' . '<a href="/pages/circle/list?id='.$circle['id'].'">'.$circle['circle_name'].'</a>' . '」有一篇新的内容发布,您要好好把关哦。');
  1429. }
  1430. _mini_aite($uid, $contents, 1, false, $post_id);
  1431. $msg = UserUtils::reward_user_coin($uid, 'publish');
  1432. if($msg){
  1433. UserUtils::assistant_notice($uid, '您发表的笔记(id:<a href="/pages/sticky/sticky?id='.$post_id.'">'.$post_id.'</a>)已经审核通过,并获得发布奖励:'.$msg);
  1434. return $this->success(['post_id'=>$post_id, 'tip'=>'发布成功', 'tmplIds'=>$tmplIds, 'reward_coin'=>$msg, 'ok'=> Settings::get('app_publish_success_popup', 0) == 1 ? 1 : 2, 'target_type' => -6, 'target_id' => '/pages/sticky/sticky?id='.$post_id, 'promotion' => 1 ]);
  1435. }else{
  1436. UserUtils::assistant_notice($uid, '您发表的笔记(id:<a href="/pages/sticky/sticky?id='.$post_id.'">'.$post_id.'</a>)已经审核通过');
  1437. return $this->success( ['post_id'=>$post_id, 'tip'=>'发布成功', 'tmplIds'=>$tmplIds, 'ok' => Settings::get('app_publish_success_popup', 0) == 1 ? 1 : 2, 'target_type' => -6, 'target_id' => '/pages/sticky/sticky?id='.$post_id, 'promotion' => 1 ] );
  1438. }
  1439. }
  1440. return $this->success( ['post_id'=>$post_id, 'tip'=>'我们会以最快的速度为您审贴', 'tmplIds'=>$tmplIds, 'ok' => 0, 'target_type' => -6, 'target_id' => '/pages/sticky/sticky?id='.$post_id, 'promotion' => 1 ] );
  1441. } else {
  1442. if($pay_content_id > 0){
  1443. WxPostsPayContent::where('id', $pay_content_id)->forceDelete();
  1444. }
  1445. return $this->fail(416001, $post_id);
  1446. }
  1447. }
  1448. /**
  1449. * 视频滑动
  1450. * @param Request $request
  1451. * @return \Illuminate\Http\JsonResponse
  1452. */
  1453. public function videoSlide(Request $request){
  1454. $uid = $request->uid;
  1455. $post_id = $request->firstVideo;
  1456. $page = $request->page;
  1457. $limit = $request->limit;
  1458. if(_empty_($limit)){
  1459. $limit = 10;
  1460. }else{
  1461. $limit = _between_($limit, 1, 100);
  1462. }
  1463. _limit_user('video:slide', $uid, 30);
  1464. $data = WxPost::has('video')->where('is_examine', 1)->where('posts_state', 0)->inRandomOrder()->simplePaginate($limit);
  1465. if($data){
  1466. PostUtils::reset_loop();
  1467. $data->map(function ($v, $k) use ($uid){
  1468. return PostUtils::defaultProcess($k, $v,75);
  1469. });
  1470. if($page == 1 && $post_id){
  1471. $data2 = WxPost::where('id', $post_id)->get();
  1472. $data2->map(function ($v, $k) use ($uid){
  1473. return PostUtils::defaultProcess($k, $v, 75);
  1474. });
  1475. $data = json_decode($data->toJson(), true);
  1476. $data['data'] = $data2->concat($data['data']);
  1477. }
  1478. return $this->success($data);
  1479. }else{
  1480. return $this->fail(200003);
  1481. }
  1482. }
  1483. /**
  1484. * 点赞
  1485. * @param Request $request
  1486. * @return \Illuminate\Http\JsonResponse
  1487. */
  1488. public function like(Request $request)
  1489. {
  1490. $uid = $request->uid;
  1491. $posts_id = $request->posts_id;
  1492. if(_empty_($posts_id)){
  1493. return $this->fail(200001);
  1494. }
  1495. $posts_id = _abs($posts_id);
  1496. PostsRepositores::addLike($uid, $posts_id);
  1497. return $this->success();
  1498. }
  1499. /**
  1500. * 收藏
  1501. * @param Request $request
  1502. * @return \Illuminate\Http\JsonResponse
  1503. */
  1504. public function collect(Request $request)
  1505. {
  1506. $uid = $request->uid;
  1507. $posts_id = $request->posts_id;
  1508. if(_empty_($posts_id)){
  1509. return $this->fail(200001);
  1510. }
  1511. $posts_id = _abs($posts_id);
  1512. PostsRepositores::addCollect($uid, $posts_id);
  1513. update_user_visit($uid, 1, $posts_id);
  1514. return $this->success();
  1515. }
  1516. /** 图片不适
  1517. * @param Request $request
  1518. * @return \Illuminate\Http\JsonResponse
  1519. */
  1520. public function blur(Request $request){
  1521. $uid = $request->uid;
  1522. $posts_id = $request->posts_id;
  1523. if(_empty_($posts_id)){
  1524. return $this->fail(200001);
  1525. }
  1526. $posts_id = _abs($posts_id);
  1527. $post = WxPost::find($posts_id);
  1528. if(_empty_($post)){
  1529. return $this->fail(200003);
  1530. }
  1531. if(!is_object_user_special($uid, $post->tenant_id) && $post->user_id != $uid){
  1532. return $this->fail(200000);
  1533. }
  1534. if(PostsRepositores::addBlur($posts_id)){
  1535. return $this->success();
  1536. }else{
  1537. return $this->fail(200002);
  1538. }
  1539. }
  1540. /** 移动圈子
  1541. * @param Request $request
  1542. * @return \Illuminate\Http\JsonResponse
  1543. */
  1544. public function move(Request $request){
  1545. $uid = $request->uid;
  1546. $posts_id = $request->posts_id;
  1547. $circle_id = $request->circle_id;
  1548. if(_empty_($posts_id) || _empty_($circle_id)){
  1549. return $this->fail(200001);
  1550. }
  1551. $posts_id = _abs($posts_id);
  1552. $post = WxPost::find($posts_id);
  1553. if(_empty_($post)){
  1554. return $this->fail(200003);
  1555. }
  1556. if(!is_object_user_special($uid, $post->tenant_id)){
  1557. return $this->fail(200000);
  1558. }
  1559. $user_name = WxUser::where('id', $uid)->value('user_name');
  1560. $post_user_id = $post->user_id;
  1561. $post_circle_id = $post->circle_id;
  1562. $post_circle_name = $post->circle_name;
  1563. $circle = WxCircle::find($circle_id);
  1564. if($circle){
  1565. WxPost::where('id', $posts_id)->update(['circle_id'=>$circle->id, 'circle_name'=>$circle->circle_name]);
  1566. UpdateCommentCircleJob::dispatch([$posts_id]);
  1567. Cache::forget('get_post_circle_user_id:'.$posts_id);
  1568. UserUtils::add_user_notice(2002, $post_user_id, '笔记转移通知', '您的「<a href="/pages/sticky/sticky?id='.$post->id.'">笔记(id:'.$post->id.')</a>」已被管理员「<a href="/pages/user/user?id='.$uid.'">'.$user_name.'</a>」从「<a href="/pages/circle/list?id='.$post_circle_id.'">'.$post_circle_name.'</a>」'.env('circle_call', '圈子').'转移到「<a href="/pages/circle/list?id='.$circle->id.'">'.$circle->circle_name.'</a>」圈子', 100);
  1569. return $this->success();
  1570. }else{
  1571. return $this->fail(200003, [], '您选择的'.env('circle_call', '圈子').'不存在!');
  1572. }
  1573. }
  1574. /** 笔记审核
  1575. * @param Request $request
  1576. * @return \Illuminate\Http\JsonResponse
  1577. */
  1578. public function examine(Request $request){
  1579. $uid = $request->uid;
  1580. $posts_id = $request->posts_id;
  1581. global $__MINI_GLOBAL_TENANT_ID__;
  1582. if(_empty_($posts_id)){
  1583. return $this->fail(200001);
  1584. }
  1585. $posts_id = _abs($posts_id);
  1586. $flag = false;
  1587. $the_post = WxPost::find($posts_id);
  1588. if(_empty_($the_post)){
  1589. return $this->fail(200003);
  1590. }
  1591. $post_user_id = $the_post->user_id;
  1592. $circle_user_id = PostUtils::get_post_circle_user_id($posts_id);
  1593. $is_examine = $the_post->is_examine;
  1594. if(is_object_user_special($uid, $the_post->tenant_id)){
  1595. // 管理员特权
  1596. $flag = true;
  1597. }else if($circle_user_id == $uid){
  1598. // 圈主特权
  1599. $flag = true;
  1600. }else if($the_post->user_id == $uid){
  1601. // 已经通过状态下, 自己可以驳回
  1602. if($is_examine == 1){
  1603. $flag = true;
  1604. }
  1605. }
  1606. if(!$flag){
  1607. return $this->fail(200000);
  1608. }
  1609. $user_name = WxUser::where('id', $uid)->value('user_name');
  1610. $call_name = '管理员';
  1611. if($circle_user_id == $uid){
  1612. $call_name = env('circle_user_call', '圈主');
  1613. }else if($post_user_id == $uid){
  1614. $call_name = '自己';
  1615. }
  1616. if($is_examine == 0 || $is_examine == 2){
  1617. // 发送通知
  1618. WxPost::where('id',$posts_id)->update(['is_examine'=>1]);
  1619. UserUtils::assistant_notice($post_user_id, '审核通过,您发表的笔记(id:<a href="/pages/sticky/sticky?id='.$posts_id.'">'.$posts_id.'</a>)已被'.$call_name.'「<a href="/pages/user/user?id='.$uid.'">'.$user_name.'</a>」审核通过');
  1620. }else{
  1621. WxPost::where('id',$posts_id)->update(['is_examine'=>2]);
  1622. if($post_user_id != $uid){
  1623. UserUtils::assistant_notice($post_user_id, '您发表的笔记(id:<a href="/pages/sticky/sticky?id='.$posts_id.'">'.$posts_id.'</a>)被'.$call_name.'「<a href="/pages/user/user?id='.$uid.'">'.$user_name.'</a>」驳回了');
  1624. }
  1625. }
  1626. return $this->success();
  1627. }
  1628. /** 置顶
  1629. * @param Request $request
  1630. * @return \Illuminate\Http\JsonResponse
  1631. */
  1632. public function sticky(Request $request){
  1633. $uid = $request->uid;
  1634. $posts_id = $request->posts_id;
  1635. $scene = $request->scene;
  1636. global $__MINI_GLOBAL_IS_ADMIN_SUPER__;
  1637. if($scene != 1){
  1638. return $this->fail(700000);
  1639. }
  1640. if(_empty_($posts_id) || _empty_($scene)){
  1641. return $this->fail(200001);
  1642. }
  1643. $posts_id = _abs($posts_id);
  1644. if(!in_array($scene, [1, 5, 6, 8, 9, 10, 60001])){
  1645. return $this->fail(200014);
  1646. }
  1647. // 权限验证
  1648. // 圈主权限+管理员权限
  1649. if($scene == 5 || $scene == 8){
  1650. // 主页置顶
  1651. $post_author = PostUtils::is_post_author($posts_id, $uid);
  1652. if($post_author){
  1653. }else{
  1654. if(!$__MINI_GLOBAL_IS_ADMIN_SUPER__){
  1655. return $this->fail(200000);
  1656. }
  1657. }
  1658. }else if($scene == 6 || $scene == 60001){
  1659. // 管理员或圈子管理员
  1660. $circle_id = WxPost::where('id', $posts_id)->value('circle_id');
  1661. $the_circle = WxCircle::find($circle_id);
  1662. if(_empty_($the_circle)){
  1663. return $this->fail(200003);
  1664. }
  1665. // 不是管理 也不是圈主
  1666. if(!is_object_user_special($uid, $the_circle->tenant_id) && $the_circle->user_id != $uid){
  1667. return $this->fail(200000);
  1668. }
  1669. }else{
  1670. if(!$__MINI_GLOBAL_IS_ADMIN_SUPER__){
  1671. return $this->fail(200000);
  1672. }
  1673. }
  1674. if(PostsRepositores::addSticky($scene, $posts_id)){
  1675. return $this->success();
  1676. }else{
  1677. return $this->fail(200002);
  1678. }
  1679. }
  1680. public function posts_process(Request $request){
  1681. $type = _empty_default_($request->type, '');
  1682. if ($type == 'delete') {
  1683. return $this->deletePosts($request);
  1684. }else if ($type == 'sticky') {
  1685. // 置顶
  1686. return $this->sticky($request);
  1687. }else if ($type == 'examine') {
  1688. // 笔记审核
  1689. return $this->examine($request);
  1690. }else if ($type == 'move') {
  1691. // 移动圈子
  1692. return $this->move($request);
  1693. }else if ($type == 'blur') {
  1694. // 图片不适
  1695. return $this->blur($request);
  1696. }else if ($type == 'collect') {
  1697. // 收藏
  1698. return $this->collect($request);
  1699. }else if ($type == 'like') {
  1700. // 喜欢
  1701. return $this->like($request);
  1702. }else if ($type == 'add') {
  1703. // 发帖
  1704. return $this->addPost($request);
  1705. }else if ($type == 'echo') {
  1706. // 编辑回显
  1707. return $this->echoPost($request);
  1708. }else if ($type == 'update') {
  1709. // 更新
  1710. return $this->updatePost($request);
  1711. }else if ($type == 'limit') {
  1712. return $this->limit($request);
  1713. }else if ($type == 'promotion_refresh_list') {
  1714. return $this->promotion_refresh_list($request);
  1715. }else if ($type == 'promotion_refresh_stop') {
  1716. return $this->promotion_refresh_stop($request);
  1717. }else if ($type == 'promotion_coin_pay') {
  1718. return $this->promotion_coin_pay($request);
  1719. }
  1720. }
  1721. private function promotion_coin_pay(Request &$request){
  1722. $uid = $request->uid;
  1723. $is_promotion_refresh = false;
  1724. $post_id = _abs(_empty_default_($request->post_id, 0));
  1725. if(_empty_($post_id)){
  1726. return $this->fail(200004);
  1727. }
  1728. $time_list = _empty_default_($request->time_list, []);
  1729. $index_option = _empty_default_($request->index, 0);
  1730. if(_empty_default_($request->is_refresh, 0) == 1){
  1731. if(_empty_($time_list)){
  1732. return $this->fail(200004);
  1733. }
  1734. $is_promotion_refresh = true;
  1735. }else{
  1736. if(_empty_($index_option, true)){
  1737. return $this->fail(200004);
  1738. }
  1739. }
  1740. $the_post = WxPost::where('id', $post_id)->where([['is_examine' ,'=', 1], ['posts_state' , '=', 0]])->first();
  1741. if(!$the_post){
  1742. DB::rollBack();
  1743. return $this->fail(200004, [], '笔记不存在或非正常推送状态');
  1744. }
  1745. if($is_promotion_refresh){
  1746. if(!is_array($time_list)){
  1747. return $this->fail(200004);
  1748. }
  1749. $the_order_price = bcdiv(Settings::get('app_promoted_post_refresh_cost', 1.0, true) * count($time_list), 1, 2);
  1750. $order_info_des = '笔记推广自动刷新'.count($time_list).'次';
  1751. }else{
  1752. global $__MINI_GLOBAL_TENANT_ID__;
  1753. $tmp_tenant_id = -1;
  1754. if($__MINI_GLOBAL_TENANT_ID__ != $the_post->tenant_id){
  1755. $tmp_tenant_id = $__MINI_GLOBAL_TENANT_ID__;
  1756. $__MINI_GLOBAL_TENANT_ID__ = $the_post->tenant_id;
  1757. }
  1758. $post_options = Settings::get('app_promoted_post_options', [], true);
  1759. if($tmp_tenant_id > 0){
  1760. $__MINI_GLOBAL_TENANT_ID__ = $tmp_tenant_id;
  1761. }
  1762. if(_empty_($post_options) || !isset($post_options[$index_option])){
  1763. DB::rollBack();
  1764. return $this->fail(200004, [], '后台未配置index为'.$index_option.'的付费推广套餐');
  1765. }
  1766. $the_option = $post_options[$index_option];
  1767. if($the_option['credit_type'] != 1){
  1768. DB::rollBack();
  1769. return $this->fail(200004, [], '该接口只能进行余额付费推广');
  1770. }
  1771. $the_order_price = $the_option['price'];
  1772. $order_info_des = '笔记付费置顶'.$the_option['hour'].'小时';
  1773. }
  1774. $app_coin_pay_rate = Settings::get('app_coin_pay_rate', 100);
  1775. $order_coins_num = (int)($app_coin_pay_rate * $the_order_price);
  1776. DB::beginTransaction();
  1777. try {
  1778. // todo:
  1779. if($is_promotion_refresh){
  1780. $pay_res2 = UserUtils::update_user_coins($uid, 3, -$order_coins_num, '笔记(id: '.$post_id.')付费推广自动刷新'.count($time_list).'次('. $order_coins_num. Settings::get('app_coin_name', '硬币') . '抵扣了¥'.$the_order_price.'):金币-'.$order_coins_num);
  1781. if($pay_res2){
  1782. $insert_data = [];
  1783. sort($time_list);
  1784. foreach ($time_list as $timestap){
  1785. $insert_data[] = [
  1786. 'user_id' => $uid,
  1787. 'post_id' => $post_id,
  1788. 'expect_time' => Carbon::createFromTimestamp((int)($timestap / 1000)),
  1789. 'refresh_time' => null,
  1790. 'balance_cost' => 0,
  1791. 'coin_cost' => (int)($order_coins_num / count($time_list)),
  1792. 'status' => 0
  1793. ];
  1794. }
  1795. WxPostsWeightRefresh::insert($insert_data);
  1796. }else{
  1797. DB::rollBack();
  1798. return $this->fail(200011, [], Settings::get('app_coin_name', '硬币').'不足');
  1799. }
  1800. }else{
  1801. $pay_res2 = UserUtils::update_user_coins($uid, 3, -$order_coins_num, '笔记(id: '.$post_id.')付费推广'.$the_option['tip'].'('. $order_coins_num. Settings::get('app_coin_name', '硬币') . '抵扣了¥'.$the_order_price.'):金币-'.$order_coins_num);
  1802. if($pay_res2){
  1803. $the_weight = $the_post->weight;
  1804. if($the_weight < time()){
  1805. $the_weight = time();
  1806. }
  1807. $the_weight += $the_option['hour'] * 3600;
  1808. WxPost::withoutSyncingToSearch(function () use ($post_id, $the_weight) {
  1809. WxPost::where('id', $post_id)->update(['weight'=>timetostr($the_weight)]);
  1810. });
  1811. }else{
  1812. DB::rollBack();
  1813. return $this->fail(200011, [], Settings::get('app_coin_name', '硬币').'不足');
  1814. }
  1815. }
  1816. DB::commit();
  1817. return $this->success();
  1818. } catch (\Exception $e) {
  1819. DB::rollBack();
  1820. _logger_(__file__, __line__, $e->getMessage());
  1821. return $this->fail(200002);
  1822. }
  1823. }
  1824. private function promotion_refresh_stop(Request &$request){
  1825. $uid = $request->uid;
  1826. $posts_id = _abs(_empty_default_($request->posts_id, 0));
  1827. if(_empty_($posts_id) || _empty_($uid)){
  1828. return $this->fail(200001);
  1829. }
  1830. $the_post = WxPost::find($posts_id);
  1831. if(_empty_($the_post)){
  1832. return $this->fail(200003);
  1833. }
  1834. if($uid != $the_post->user_id && !is_object_user_special($uid, $the_post->tenant_id)){
  1835. return $this->fail(200000);
  1836. }
  1837. $ids = [];
  1838. $coin_total = 0;
  1839. $balance_total = 0;
  1840. $data = WxPostsWeightRefresh::where('user_id', $uid)->where('post_id', $posts_id)->where('status', 0)->get()->toArray();
  1841. if(_empty_($data)){
  1842. return $this->fail(200004, [], '已全部推广完成,无法中断');
  1843. }
  1844. foreach ($data as $item){
  1845. $ids[] = $item['id'];
  1846. $coin_total += $item['coin_cost'];
  1847. $balance_total += $item['balance_cost'];
  1848. }
  1849. $coin_total = (int)($coin_total * 0.7);
  1850. $balance_total = floor(($balance_total * 0.7 * 100)) / 100;
  1851. DB::beginTransaction();
  1852. try {
  1853. // todo:
  1854. WxPostsWeightRefresh::whereIn('id', $ids)->delete();
  1855. if($coin_total > 0){
  1856. UserUtils::update_user_coins($uid, 4, $coin_total, '收到「笔记 id: '.$the_post->id.'」自动刷新订单的金币抵扣退款' . Settings::get('app_coin_name', '硬币') . $coin_total);
  1857. }
  1858. if($balance_total >= 0.01){
  1859. UserUtils::update_user_financial($uid, 33, $balance_total, '收到「<a href="/pages/sticky/sticky?id='.$the_post->id.'">笔记 id: '.$the_post->id.'</a>」自动刷新订单的退款,扣掉平台分成30%,您获得'.$balance_total.'余额。');
  1860. }
  1861. DB::commit();
  1862. return $this->success();
  1863. } catch (\Exception $e) {
  1864. DB::rollBack();
  1865. _logger_(__file__, __line__, $e->getMessage());
  1866. return $this->fail(200006);
  1867. }
  1868. }
  1869. private function promotion_refresh_list(Request &$request){
  1870. $uid = $request->uid;
  1871. $posts_id = _abs(_empty_default_($request->posts_id, 0));
  1872. if(_empty_($posts_id) || _empty_($uid)){
  1873. return $this->fail(200001);
  1874. }
  1875. $the_post = WxPost::find($posts_id);
  1876. if(_empty_($the_post)){
  1877. return $this->fail(200003);
  1878. }
  1879. if($uid != $the_post->user_id && !is_object_user_special($uid, $the_post->tenant_id)){
  1880. return $this->fail(200000);
  1881. }
  1882. $data = WxPostsWeightRefresh::where('post_id', $posts_id)->orderBy('expect_time', 'asc')->get()->toArray();
  1883. if(_empty_($data)){
  1884. return $this->fail(200003);
  1885. }
  1886. $rest = 0;
  1887. foreach ($data as $item){
  1888. if($item['status'] === 0){
  1889. $rest += 1;
  1890. }
  1891. }
  1892. return $this->success(['list'=>$data, 'rest' => $rest, 'ok_count'=> count($data) - $rest, 'cancel' => ($the_post->user_id == $uid ? 1 : 0)]);
  1893. }
  1894. private function limit(Request &$request){
  1895. $uid = $request->uid;
  1896. $posts_id = _abs(_empty_default_($request->posts_id, 0));
  1897. $days = _abs(_empty_default_($request->days, 1));
  1898. $the_post = WxPost::find($posts_id);
  1899. if(_empty_($the_post)){
  1900. return $this->fail(200003);
  1901. }
  1902. if(!is_object_user_special($uid, $the_post->tenant_id)){
  1903. return $this->fail(200000);
  1904. }
  1905. $weight = $the_post->weight;
  1906. if($weight > time()){
  1907. $weight = time();
  1908. }
  1909. $weight -= 86400 * $days;
  1910. WxPost::withoutSyncingToSearch(function () use (&$the_post,$weight){
  1911. WxPost::where('id', $the_post->id)->update(['weight'=>timetostr($weight)]);
  1912. });
  1913. // UserUtils::assistant_notice($the_post->user_id, '您发表的「<a href="/pages/sticky/sticky?id='.$the_post->id.'">笔记 id:'.$the_post->id.'</a>」被管理员「<a href="/pages/user/user?id='.$uid.'">'.UserUtils::get_cached_user_name($uid).' id:'.$uid.'</a>」首页限流');
  1914. return $this->success();
  1915. }
  1916. private function echoPost(Request &$request){
  1917. $uid = $request->uid;
  1918. $posts_id = $request->posts_id;
  1919. $editor_name = _empty_default_($request->editor_name, 'default');
  1920. $the_post = WxPost::find($posts_id);
  1921. if(_empty_($the_post)){
  1922. return $this->fail(200003);
  1923. }
  1924. // 权限验证
  1925. if(!is_object_user_special($uid, $the_post->tenant_id) && $the_post->user_id != $uid){
  1926. return $this->fail(200000);
  1927. }
  1928. $the_post->posts_content_raw =html_entity_decode( _mini_phone(_mini_aite_replace(_mini_emoji($the_post->posts_content, true), true)) );
  1929. if($the_post->circle_id > 0){
  1930. $the_circle = WxCircle::find($the_post->circle_id);
  1931. }
  1932. if($the_post->video_id === Null){
  1933. $the_post->video = WxPostsVideo::where('posts_id', $the_post->id)->first();//视频
  1934. UpdatePostVideoIdJob::dispatch($the_post->id);
  1935. }else if($the_post->video_id > 0){
  1936. $the_post->video = WxPostsVideo::where('id', $the_post->video_id)->first();//视频
  1937. }else if($the_post === 0){
  1938. $the_post->video = null;
  1939. }
  1940. if($the_post->is_wechat_sph){
  1941. $the_post->wechat_sph = get_post_meta($the_post->id, 'wechat_sph', 'j');
  1942. }
  1943. if(!_empty_($the_post->useds)){
  1944. $the_post->used_goods = WxUsedGood::whereIn('id', $the_post->useds)->orderBy(DB::raw('FIND_IN_SET(id, "' . implode(",", $the_post->useds) . '"' . ")"))->get();
  1945. if($the_post->used_goods){
  1946. $the_post->used_goods->map(function ($used_good){
  1947. if($used_good->image_urls){
  1948. $used_good->pic = _array_key($used_good->image_urls[0], 'url', '') . '?imageMogr2/thumbnail/600x/format/webp/interlace/1';
  1949. $used_good->pic_width = _array_key($used_good->image_urls[0], 'width', '');
  1950. $used_good->pic_height = _array_key($used_good->image_urls[0], 'height', '');
  1951. if($used_good->pic_width >= 0){
  1952. $old_widht = $used_good->pic_width;
  1953. $used_good->pic_width = 363;
  1954. $used_good->pic_height = (int)( (363 * $used_good->pic_height) / $old_widht );
  1955. }
  1956. }
  1957. $used_good->needed_count = WxUsedNeed::where('used_good_id', $used_good->id)->where('status', 1)->count();
  1958. if(_empty_($used_good->needed_count)){
  1959. $used_good->needed_count = 0;
  1960. }
  1961. return $used_good;
  1962. });
  1963. }
  1964. }
  1965. if( !_empty_($the_post->tags_id) ){
  1966. $the_post->tags = WxTag::whereIn('id', explode(',', $the_post->tags_id))->get(['tags_name', 'id']);
  1967. }else if($the_post->tags_id === ''){
  1968. $the_post->tags = null;
  1969. }else if($the_post->tags_id === '0'){
  1970. $the_post->tags = PostsRepositores::getPostTags($the_post->id);
  1971. UpdatePostTagIdJob::dispatch($the_post->id);
  1972. }
  1973. if( !_empty_($the_post->goods_id) ){
  1974. $the_post->goods = WxShopGoods::whereIn('id', explode(',', $the_post->goods_id))->get(['id', 'pic', 'name', 'credit_type', 'intro', 'price', 'vip_price', 'tk_platform_id', 'buys']);
  1975. }else if($the_post->goods_id === ''){
  1976. $the_post->goods = null;
  1977. }else if($the_post->goods_id === '0'){
  1978. $the_post->goods = PostsRepositores::getPostGoods($the_post->id);
  1979. UpdatePostGoodsIdJob::dispatch($the_post->id);
  1980. }
  1981. if( !_empty_($the_post->sounds_id) ){
  1982. $the_post->sounds = WxPostsSound::whereIn('id', explode(',', $the_post->sounds_id))->get();
  1983. }else if($the_post->sounds_id === ''){
  1984. $the_post->sounds = null;
  1985. }else if($the_post->sounds_id === '0'){
  1986. $the_post->sounds = PostsRepositores::getPostSounds($the_post->id);
  1987. UpdatePostSoundsIdJob::dispatch($the_post->id);
  1988. }
  1989. $address_obj = [];
  1990. if($the_post->address_id > 0){
  1991. $address_obj = WxPostsAddress::where('id', $the_post->address_id)->first();
  1992. }
  1993. $pay_content_obj_ = [];
  1994. if($the_post->pay_content_id > 0){
  1995. $pay_content_obj_ = WxPostsPayContent::find($the_post->pay_content_id);
  1996. }
  1997. if( !_empty_($the_post->files_id) ){
  1998. $the_post->files = WxPostsFile::whereIn('id', explode(',', $the_post->files_id))->get();
  1999. }else if($the_post->files_id === ''){
  2000. $the_post->files = null;
  2001. }else if($the_post->files_id === '0'){
  2002. $the_post->files = PostsRepositores::getPostFiles($the_post->id);
  2003. UpdatePostFilesIdJob::dispatch($the_post->id);
  2004. }
  2005. if($the_post->has_fields === 1) {
  2006. $the_post->fields = WxPostsField::find($the_post->id);
  2007. }else if($the_post->has_fields === null){
  2008. $the_post->fields = WxPostsField::find($the_post->id);
  2009. UpdatePostFieldsJob::dispatch($the_post->id);
  2010. }
  2011. if($editor_name == 'default'){
  2012. $selectUseds = [];
  2013. $post_type = PostUtils::post_type($the_post);
  2014. if($post_type == 'single'){
  2015. }else{
  2016. $the_post->posts_content_raw = str_replace(['<br>', '<br/>'], "\n", $the_post->posts_content_raw);
  2017. }
  2018. $circle = [
  2019. 'id' => 0,
  2020. 'circle_name' => ''
  2021. ];
  2022. $tags = [];
  2023. $goods = [];
  2024. $address = [];
  2025. if($address_obj){
  2026. $address['latitude'] = $address_obj->latitude;
  2027. $address['longitude'] = $address_obj->longitude;
  2028. $address['address_name'] = $address_obj->address_name;
  2029. $address['address_detailed'] = $address_obj->address_detailed;
  2030. }
  2031. if(!_empty_($the_post->tags)){
  2032. $the_post->tags->map(function ($tag_obj) use (&$tags){
  2033. $tags[] = [
  2034. 'id' => $tag_obj->id,
  2035. 'tags_name' => $tag_obj->tags_name
  2036. ];
  2037. });
  2038. }
  2039. if($the_post->circle_id > 0){
  2040. $circle = [
  2041. 'id' => $the_circle->id,
  2042. 'circle_name' => $the_circle->circle_name
  2043. ];
  2044. }
  2045. $image_urls = [];
  2046. WxPostsImg::where('posts_id', $the_post->id)->get(['id','img_url', 'posts_id','width', 'height'])->map(function ($img_obj) use (&$image_urls){
  2047. $image_urls[] = [
  2048. 'url' => $img_obj->img_url
  2049. ];
  2050. });
  2051. // 处理二手
  2052. if($the_post->used_goods){
  2053. $the_post->used_goods->map(function ($used_good) use (&$selectUseds){
  2054. $selectUseds[] = [
  2055. 'id' => $used_good->id,
  2056. 'pic' => $used_good->pic,
  2057. 'title' => $used_good->title,
  2058. 'price' => $used_good->price,
  2059. 'needed_count' => $used_good->needed_count,
  2060. ];
  2061. });
  2062. }
  2063. if($the_post->goods){
  2064. $the_post->goods->map(function ($good_obj) use (&$goods){
  2065. $goods[] = [
  2066. 'id' => $good_obj->id,
  2067. 'name' => $good_obj->name,
  2068. 'pic' => $good_obj->pic ? $good_obj->pic[0] : []
  2069. ];
  2070. });
  2071. }
  2072. $pay_content_obj = [
  2073. 'words_percent' => 100,
  2074. 'is_file' => 0,
  2075. 'is_img' => 0,
  2076. 'is_video' => 0,
  2077. 'credit_type' => 0,
  2078. 'hidden' => '',
  2079. 'price' => 0,
  2080. 'id' => 0
  2081. ];
  2082. if($pay_content_obj_ && $pay_content_obj_->id > 0){
  2083. $pay_content_obj['id'] = $pay_content_obj_->id;
  2084. $pay_content_obj['words_percent'] = $pay_content_obj_->words_percent;
  2085. $pay_content_obj['is_file'] = $pay_content_obj_->is_file;
  2086. $pay_content_obj['is_img'] = $pay_content_obj_->is_img;
  2087. $pay_content_obj['is_video'] = $pay_content_obj_->is_video;
  2088. $pay_content_obj['credit_type'] = $pay_content_obj_->credit_type;
  2089. $pay_content_obj['hidden'] = $pay_content_obj_->hidden;
  2090. $pay_content_obj['price'] = $pay_content_obj_->price;
  2091. }
  2092. $video_url = '';
  2093. $video_thumb_url = '';
  2094. $video_height = 0;
  2095. $video_width = 0;
  2096. if($the_post->video){
  2097. $video_url = $the_post->video->video_url;
  2098. $video_thumb_url = $the_post->video->video_thumb_url;
  2099. $video_height = $the_post->video->video_height;
  2100. $video_width = $the_post->video->video_width;
  2101. }
  2102. $sph_video_feed_token = '';
  2103. $sph_image_urls = [];
  2104. if($the_post->wechat_sph && _array_key($the_post->wechat_sph, 'feed_token', '')){
  2105. $sph_video_feed_token = $the_post->wechat_sph['feed_token'];
  2106. $sph_image_urls = [['url'=>$the_post->wechat_sph['img']]];
  2107. }
  2108. $upload_files = [];
  2109. if($the_post->files){
  2110. $the_post->files->map(function ($file_obj) use (&$upload_files){
  2111. $upload_files[] = [
  2112. 'id' => $file_obj->id,
  2113. 'name' => $file_obj->name
  2114. ];
  2115. });
  2116. }
  2117. $sounds_files = [];
  2118. if($the_post->sounds){
  2119. $the_post->sounds->map(function ($sound_obj) use (&$sounds_files){
  2120. $sounds_files[] = [
  2121. 'id' => $sound_obj->id,
  2122. 'name' => $sound_obj->name
  2123. ];
  2124. });
  2125. }
  2126. $contact_phone = '';
  2127. if($the_post->fields){
  2128. $contact_phone = $the_post->fields->contact_phone;
  2129. }
  2130. $selectVoter = null;
  2131. if($the_post->voter_id > 0){
  2132. $selectVoter = WxVoter::where('id', $the_post->voter_id)->first(['id', 'user_id', 'master_user_avatar', 'master_user_name', 'title', 'banners']);
  2133. }
  2134. return $this->success([
  2135. 'id' => $the_post->id,
  2136. 'editer' => $post_type == 'single' ? 'imagetext' : 'simple',
  2137. 'posts_title' => $the_post->posts_title,
  2138. 'imagetext_content' => $post_type == 'single' ? $the_post->posts_content_raw : '',
  2139. 'textinput' => $post_type == 'single' ? '' : $the_post->posts_content_raw,
  2140. 'selectUseds' => $selectUseds,
  2141. 'image_urls' => $image_urls,
  2142. 'circle' => $circle,
  2143. 'tags' => $tags,
  2144. 'goods' => $goods,
  2145. 'location' => $address,
  2146. 'pay_content_obj' => $pay_content_obj,
  2147. 'video_url' => $video_url,
  2148. 'video_thumb_url' => $video_thumb_url,
  2149. 'video_height' => $video_height,
  2150. 'video_width' => $video_width,
  2151. 'sph_video_feed_token' => $sph_video_feed_token,
  2152. 'sph_image_urls' => $sph_image_urls,
  2153. 'upload_files' => $upload_files,
  2154. 'sounds_files' => $sounds_files,
  2155. 'contact_phone' => $contact_phone,
  2156. 'is_anonymous' => $the_post->is_anonymous,
  2157. 'selectVoter' => $selectVoter
  2158. ]);
  2159. }
  2160. }
  2161. /**
  2162. * 删除
  2163. * @param Request $request
  2164. * @return \Illuminate\Http\JsonResponse
  2165. */
  2166. public function deletePosts(Request $request)
  2167. {
  2168. $uid = $request->uid;
  2169. $posts_id = $request->posts_id;
  2170. global $__MINI_GLOBAL_TENANT_ID__, $__MINI_GLOBAL_IS_ADMIN_SUPER__;
  2171. if(_empty_($posts_id)){
  2172. return $this->fail(200001);
  2173. }
  2174. $posts_id = _abs($posts_id);
  2175. // $flag = false;
  2176. $flag = true;
  2177. $the_post = WxPost::find($posts_id);
  2178. if(_empty_($the_post)){
  2179. return $this->fail(200003);
  2180. }
  2181. if(is_object_user_special($uid, $the_post->tenant_id)){
  2182. // 管理特权
  2183. $flag = true;
  2184. }else if(PostUtils::get_post_circle_user_id($posts_id) == $uid){
  2185. // 圈主特权
  2186. $flag = true;
  2187. }else if($the_post->user_id == $uid){
  2188. // 自己删除
  2189. $flag = true;
  2190. }
  2191. if(!$flag){
  2192. return $this->fail(200000);
  2193. }
  2194. $r = PostsRepositores::deletePosts($posts_id, $the_post->user_id == $uid ? 1 : 2);
  2195. if($r){
  2196. if($the_post->circle_id){
  2197. Cache::forget('circle:postCount:'.$the_post->circle_id);
  2198. ForgetCircleUnreadCountJob::dispatch($the_post->circle_id);
  2199. }
  2200. // todo: 修改图片状态
  2201. return $this->success();
  2202. }else{
  2203. return $this->fail(200002);
  2204. }
  2205. }
  2206. /**
  2207. * 关注用户
  2208. * @param Request $request
  2209. * @return \Illuminate\Http\JsonResponse
  2210. */
  2211. public function followUser(Request $request)
  2212. {
  2213. $uid = $request->uid;
  2214. _limit_user('follow:user', $uid, 20);
  2215. $user_follow_id = $request->posts_user_id;
  2216. if(_empty_($user_follow_id)){
  2217. return $this->fail(200001);
  2218. }
  2219. $res = UserUtils::follow_user($uid, $user_follow_id);
  2220. if($res['code'] == 1){
  2221. return $this->success([], $res['message']);
  2222. }else{
  2223. return $this->fail($res['message']);
  2224. }
  2225. }
  2226. /**
  2227. * 笔记详情
  2228. * @param Request $request
  2229. * @return \Illuminate\Http\JsonResponse
  2230. */
  2231. public function postsDetail(Request $request)
  2232. {
  2233. $uid = $request->uid;
  2234. $posts_id = $request->posts_id;
  2235. if(_empty_($posts_id)){
  2236. return $this->fail(200001);
  2237. }
  2238. try{
  2239. $posts_id = _abs($posts_id);
  2240. }catch (\Exception $e){
  2241. _logger_(__file__, __line__, $e->getMessage().'||||'.$posts_id);
  2242. return $this->fail(200004);
  2243. }
  2244. $data = (new Model())->where('id', $posts_id)->get();
  2245. if($data->isEmpty()){
  2246. return $this->fail(200003);
  2247. }
  2248. $the_post = $data->get(0);
  2249. // 锁定或下架
  2250. if($the_post->posts_state == 1 || $the_post->posts_state == 2){
  2251. // 已经下架了
  2252. return $this->fail(416005);
  2253. }
  2254. // 待审或驳回
  2255. if($the_post->is_examine == 0 || $the_post->is_examine == 2){
  2256. if($uid == $the_post->user_id || is_object_user_special($uid, $the_post->tenant_id) || PostUtils::get_post_circle_user_id($posts_id) == $uid){
  2257. }else{
  2258. if($the_post->is_examine == 0){
  2259. // 待审核
  2260. return $this->fail(416006);
  2261. }else{
  2262. // 被驳回
  2263. $overrule_content = '笔记被驳回!无法查看';
  2264. if($the_post->overrule_content){
  2265. $overrule_content = '笔记被驳回,'.$the_post->overrule_content;
  2266. }
  2267. return $this->fail(416007, [], $overrule_content);
  2268. }
  2269. }
  2270. }
  2271. if($data){
  2272. $data = PostsRepositores::postsParame($data, $uid, 9);//文章详情
  2273. if($uid > 0){
  2274. update_user_visit($uid, 1, $posts_id);
  2275. }
  2276. // print_r('<pre>');
  2277. // print_r($data[0]);exit;
  2278. $data[0]['posts_content'] = $data[0]['posts_content_origin'];
  2279. // $data->posts_content = $data->posts_content_origin;
  2280. return $this->success($data);
  2281. }
  2282. return $this->fail(200003);
  2283. }
  2284. /**
  2285. * 相关笔记
  2286. * @param Request $request
  2287. * @return \Illuminate\Http\JsonResponse
  2288. */
  2289. public function postsRelevant(Request $request){
  2290. $posts_id = $request->posts_id;
  2291. $uid = $request->uid;
  2292. if(_empty_($posts_id)){
  2293. return $this->fail(200001);
  2294. }
  2295. $posts_id = _abs($posts_id);
  2296. if(!SearchUtils::is_use_es()){
  2297. return $this->fail(700000);
  2298. }
  2299. $data = PostsRepositores::relevantPosts($posts_id, $uid);
  2300. if($data){
  2301. return $this->success($data);
  2302. }else{
  2303. return $this->fail(200003);
  2304. }
  2305. }
  2306. /**
  2307. * 通过圈子获取笔记
  2308. * @param Request $request
  2309. * @return \Illuminate\Http\JsonResponse
  2310. */
  2311. public function postsByCircle(Request $request)
  2312. {
  2313. global $__MINI_GLOBAL_SCENE__;
  2314. $circle_id = _abs($request->circle_id);
  2315. $type = $request->type;
  2316. $limit = $request->input('limit', 10);
  2317. $uid = $request->uid;
  2318. $page = $request->page;
  2319. $tags = _empty_default_($request->tags, null);
  2320. $sort = _empty_default_($request->sort, 0);
  2321. $city = _empty_default_($request->city, '');
  2322. if(_empty_($city) || $city == '全国' || $city == '重新定位' || $city == '定位中'){
  2323. $city = '';
  2324. }
  2325. $is_tenant = _empty_default_($request->isTenant, 0);
  2326. if(_empty_($is_tenant)){
  2327. $is_tenant = false;
  2328. }else{
  2329. if($is_tenant == 2){
  2330. if($__MINI_GLOBAL_SCENE__ == 6){
  2331. $is_tenant = Cache::remember('circle:default:is:tenant:'.$circle_id, 36000, function () use (&$circle_id){
  2332. $circle = WxCircle::find($circle_id);
  2333. if($circle){
  2334. if($circle->tenant_show == -1 && $circle->is_tenant_select == 1){
  2335. return 1;
  2336. }
  2337. }
  2338. return 0;
  2339. }) == 1;
  2340. }else{
  2341. $is_tenant = false;
  2342. }
  2343. }else{
  2344. $is_tenant = true;
  2345. }
  2346. }
  2347. if(!in_array($sort, [0, 1, 2])){
  2348. $sort = 0;
  2349. }
  2350. if(!is_array($tags)){
  2351. $tags = json_decode($tags, true);
  2352. }
  2353. if(_empty_($tags)){
  2354. $tags = null;
  2355. }
  2356. return $this->success(PostsRepositores::postsByCircleId($circle_id, $type, $limit, $uid, $page, $tags, $sort, $city, $is_tenant));
  2357. }
  2358. /**
  2359. * 通过话题获取笔记列表(瀑布流用)
  2360. * @param Request $request
  2361. */
  2362. public function listByTagId(Request $request)
  2363. {
  2364. $tagId = $request->tag_id;
  2365. $page = $request->page;
  2366. $limit = 10;
  2367. $uid = $request->uid;
  2368. global $__MINI_GLOBAL_TENANT_ID__,$__MINI_GLOBAL_DEVICE__,$__MINI_GLOBAL_MODE__;
  2369. // 获取全部笔记
  2370. if (_empty_($tagId)) {
  2371. if(true){
  2372. $query = WxPost::where([['is_examine' ,'=', 1], ['posts_state' , '=', 0], ['img_count', '>', 0 ]]);
  2373. $query = $query->where('tenant_id', $__MINI_GLOBAL_TENANT_ID__);
  2374. // 控制视频隐藏
  2375. if($__MINI_GLOBAL_DEVICE__ != 'mp'){
  2376. global $__MINI_GLOBAL_FRONT_VERSION__;
  2377. // todo: 临时
  2378. if($__MINI_GLOBAL_FRONT_VERSION__ >= '1.2.2.24'){
  2379. }else {
  2380. $query = $query->where('is_wechat_sph', 0);
  2381. }
  2382. }
  2383. if($__MINI_GLOBAL_MODE__ == 'examine'){
  2384. $query = $query->where('post_type', '<>', 'video');
  2385. }
  2386. $data = $query->orderBy('degree', 'desc')->simplePaginate($limit);
  2387. }else{
  2388. $query = WxPost::where([['is_examine' ,'=', 1], ['posts_state' , '=', 0], ['img_count', '>', 0 ]]);
  2389. $query = $query->where('tenant_id', $__MINI_GLOBAL_TENANT_ID__);
  2390. // 控制视频隐藏
  2391. if($__MINI_GLOBAL_DEVICE__ != 'mp'){
  2392. global $__MINI_GLOBAL_FRONT_VERSION__;
  2393. // todo: 临时
  2394. if($__MINI_GLOBAL_FRONT_VERSION__ >= '1.2.2.24'){
  2395. }else {
  2396. $query = $query->where('is_wechat_sph', 0);
  2397. }
  2398. }
  2399. if($__MINI_GLOBAL_MODE__ == 'examine'){
  2400. $query = $query->where('post_type', '<>', 'video');
  2401. }
  2402. $data = $query->orderBy('id', 'desc')->simplePaginate($limit);
  2403. }
  2404. }else{
  2405. if(true){
  2406. $postIdsArr = WxPostsTag::where('tags_id', $tagId)->pluck('posts_id');
  2407. $query = WxPost::whereIn('id', $postIdsArr)->where([['is_examine' ,'=', 1], ['posts_state' , '=', 0], ['img_count', '>', 0 ]]);
  2408. $query = $query->where('tenant_id', $__MINI_GLOBAL_TENANT_ID__);
  2409. // 控制视频隐藏
  2410. if($__MINI_GLOBAL_DEVICE__ != 'mp'){
  2411. global $__MINI_GLOBAL_FRONT_VERSION__;
  2412. // todo: 临时
  2413. if($__MINI_GLOBAL_FRONT_VERSION__ >= '1.2.2.24'){
  2414. }else {
  2415. $query = $query->where('is_wechat_sph', 0);
  2416. }
  2417. }
  2418. if($__MINI_GLOBAL_MODE__ == 'examine'){
  2419. $query = $query->where('post_type', '<>', 'video');
  2420. }
  2421. $data = $query->orderBy('weight', 'desc')->simplePaginate($limit);
  2422. }else{
  2423. $postIdsArr = WxPostsTag::where('tags_id', $tagId)->pluck('posts_id');
  2424. $query = WxPost::whereIn('id', $postIdsArr)->where([['is_examine' ,'=', 1], ['posts_state' , '=', 0], ['img_count', '>', 0 ]]);
  2425. $query = $query->where('tenant_id', $__MINI_GLOBAL_TENANT_ID__);
  2426. // 控制视频隐藏
  2427. if($__MINI_GLOBAL_DEVICE__ != 'mp'){
  2428. global $__MINI_GLOBAL_FRONT_VERSION__;
  2429. // todo: 临时
  2430. if($__MINI_GLOBAL_FRONT_VERSION__ >= '1.2.2.24'){
  2431. }else {
  2432. $query = $query->where('is_wechat_sph', 0);
  2433. }
  2434. }
  2435. if($__MINI_GLOBAL_MODE__ == 'examine'){
  2436. $query = $query->where('post_type', '<>', 'video');
  2437. }
  2438. $data = $query->orderBy('id', 'desc')->simplePaginate($limit);
  2439. }
  2440. }
  2441. PostUtils::reset_loop();
  2442. $data->map(function ($v, $k) use ($uid){
  2443. return PostUtils::WaterfallProcess($k, $v,19);
  2444. });
  2445. return $this->success($data);
  2446. }
  2447. /**
  2448. * 通过话题获取笔记列表
  2449. * @param Request $request
  2450. * @return \Illuminate\Http\JsonResponse
  2451. */
  2452. public function listByTagIdV2(Request $request)
  2453. {
  2454. $tagId = $request->tag_id;
  2455. $page = $request->page;
  2456. $limit = 6;
  2457. $uid = $request->uid;
  2458. $sort_by = _empty_default_($request->sort_by, 'id');
  2459. if(!in_array($sort_by, ['id', 'hot'])){
  2460. return $this->fail(200004);
  2461. }
  2462. global $__MINI_GLOBAL_DEVICE__,$__MINI_GLOBAL_MODE__,$__MINI_GLOBAL_SCENE__,$__MINI_GLOBAL_TENANT_ID__;
  2463. $is_tenant = _empty_default_($request->isTenant, false);
  2464. if(_empty_($is_tenant)){
  2465. $is_tenant = false;
  2466. }else{
  2467. $is_tenant = true;
  2468. }
  2469. // 获取全部笔记
  2470. if (_empty_($tagId)) {
  2471. $data = (new Model())
  2472. ->where('is_examine', 1)
  2473. ->where('posts_state', 0);
  2474. if($is_tenant){
  2475. $data = $data->where('tenant_id', $__MINI_GLOBAL_TENANT_ID__);
  2476. }
  2477. $not_like_post_set = get_user_meta($uid, 'feedback:notlike:post:set', 'j');
  2478. $not_like_user_set = get_user_meta($uid, 'feedback:notlike:user:set', 'j');
  2479. if(!_empty_($not_like_user_set)){
  2480. $data = $data->whereNotIn('user_id', $not_like_user_set);
  2481. }
  2482. if(!_empty_($not_like_post_set)){
  2483. $data = $data->whereNotIn('id', $not_like_post_set);
  2484. }
  2485. // 控制视频隐藏
  2486. if($__MINI_GLOBAL_DEVICE__ != 'mp'){
  2487. global $__MINI_GLOBAL_FRONT_VERSION__;
  2488. // todo: 临时
  2489. if($__MINI_GLOBAL_FRONT_VERSION__ >= '1.2.2.24'){
  2490. }else {
  2491. $data = $data->where('is_wechat_sph', 0);
  2492. }
  2493. }
  2494. if($__MINI_GLOBAL_MODE__ == 'examine'){
  2495. $data = $data->where('post_type', '<>', 'video');
  2496. }
  2497. if($sort_by == 'id'){
  2498. $data = $data->orderBy('id', 'desc');
  2499. }else if($sort_by == 'hot'){
  2500. $data = $data->orderBy('degree', 'desc')->orderBy('id', 'desc');
  2501. }
  2502. $data = $data->simplePaginate($limit);
  2503. if($is_tenant){
  2504. PostUtils::$force_show_multi_site = false;
  2505. }
  2506. $data = PostsRepositores::postsParame($data, $uid);//文章详情
  2507. return $this->success($data);
  2508. }
  2509. $postIdsArr = WxPostsTag::where('tags_id', $tagId)->pluck('posts_id');
  2510. $data = (new Model())
  2511. ->where('is_examine', 1)
  2512. ->where('posts_state', 0)
  2513. ->whereIn('id', $postIdsArr);
  2514. if($is_tenant){
  2515. $data = $data->where('tenant_id', $__MINI_GLOBAL_TENANT_ID__);
  2516. }
  2517. $not_like_post_set = get_user_meta($uid, 'feedback:notlike:post:set', 'j');
  2518. $not_like_user_set = get_user_meta($uid, 'feedback:notlike:user:set', 'j');
  2519. if(!_empty_($not_like_user_set)){
  2520. $data = $data->whereNotIn('user_id', $not_like_user_set);
  2521. }
  2522. if(!_empty_($not_like_post_set)){
  2523. $data = $data->whereNotIn('id', $not_like_post_set);
  2524. }
  2525. // 控制视频隐藏
  2526. if($__MINI_GLOBAL_DEVICE__ != 'mp'){
  2527. global $__MINI_GLOBAL_FRONT_VERSION__;
  2528. // todo: 临时
  2529. if($__MINI_GLOBAL_FRONT_VERSION__ >= '1.2.2.24'){
  2530. }else {
  2531. $data = $data->where('is_wechat_sph', 0);
  2532. }
  2533. }
  2534. if($__MINI_GLOBAL_MODE__ == 'examine'){
  2535. $data = $data->where('post_type', '<>', 'video');
  2536. }
  2537. if($sort_by == 'id'){
  2538. $data = $data->orderBy('id', 'desc');
  2539. }else if($sort_by == 'hot'){
  2540. $data = $data->orderBy('degree', 'desc')->orderBy('id', 'desc');
  2541. }
  2542. $data = $data->simplePaginate($limit);
  2543. if($is_tenant){
  2544. PostUtils::$force_show_multi_site = false;
  2545. }
  2546. $data = PostsRepositores::postsParame($data, $uid, $__MINI_GLOBAL_SCENE__);//文章详情
  2547. return $this->success($data);
  2548. }
  2549. /**
  2550. * 审核笔记
  2551. * @param Request $request
  2552. */
  2553. public function auditPosts(Request $request)
  2554. {
  2555. $uid = $request->uid;
  2556. $postsId = $request->id;
  2557. $type = $request->type;
  2558. $reject_msg = $request->reject_msg;
  2559. if ($type == 0) {
  2560. $result = WxPost::where('id', $postsId)->update(['is_examine' => 1]);
  2561. if ($result) {
  2562. $userId = WxPost::where('id', $postsId)->value('user_id');
  2563. // 发送通知
  2564. UserUtils::assistant_notice($userId, '您发表的笔记(id:<a href="/pages/sticky/sticky?id='.$postsId.'">'.$postsId.'</a>)已经审核通过');
  2565. }
  2566. } elseif ($type == 1) {
  2567. $result = WxPost::where('id', $postsId)->update(['is_examine' => 2]);
  2568. if ($result) {
  2569. $userId = WxPost::where('id', $postsId)->value('user_id');
  2570. // 发送通知
  2571. UserUtils::assistant_notice($userId, '您发表的笔记(id:<a href="/pages/sticky/sticky?id='.$postsId.'">'.$postsId.'</a>)被驳回了,驳回原因:' . $reject_msg);
  2572. }
  2573. }
  2574. return $this->success();
  2575. }
  2576. /**
  2577. * 获取用户不喜欢的笔记
  2578. * @param Request $request
  2579. * @return \Illuminate\Http\JsonResponse
  2580. * @throws \Exception
  2581. */
  2582. public function userBlack(Request $request){
  2583. $uid = $request->uid;
  2584. $post_set = get_user_meta($uid, 'feedback:notlike:post:set', 'j');
  2585. if($post_set){
  2586. $post_set = array_reverse($post_set);
  2587. $data = WxPost::whereIn('id', $post_set)
  2588. ->orderBy(DB::raw('FIND_IN_SET(id, "' . implode(",", $post_set) . '"' . ")"))->simplePaginate(10, FieldUtils::postInfoColums());
  2589. PostUtils::reset_loop();
  2590. $data->map(function ($v, $k) use ($uid){
  2591. return PostUtils::WaterfallProcess($k, $v,80);
  2592. });
  2593. return $this->success($data);
  2594. }else{
  2595. return $this->fail(200003);
  2596. }
  2597. }
  2598. public function promotion(Request $request){
  2599. global $__MINI_GLOBAL_TENANT_ID__;
  2600. $uid = $request->uid;
  2601. $post_id = _empty_default_($request->post_id, 0);
  2602. if(_empty_($post_id)){
  2603. return $this->fail(200001);
  2604. }
  2605. $post_id = _abs((int)$post_id);
  2606. if (request()->method() === 'GET') {
  2607. // 处理GET请求
  2608. $post = WxPost::find($post_id);
  2609. $posts_content = _mini_phone(_mini_emoji(_mini_aite_replace($post->posts_content), true), true);
  2610. if($posts_content){
  2611. $s_content = preg_replace("/<(img|video).*?src[^\'\"]+[\'\"]([^\"\']+)[^>]+>/is", '', $posts_content);
  2612. $s_content =trim_all_space(strip_tags(html_entity_decode($s_content)), true);
  2613. }
  2614. $post_title = PostUtils::get_the_title($s_content, $post->id);
  2615. PostUtils::mediaProcess($post, $uid, 90004, 0, true);
  2616. global $__MINI_GLOBAL_TENANT_ID__;
  2617. $tmp_tenant_id = -1;
  2618. if($__MINI_GLOBAL_TENANT_ID__ != $post->tenant_id){
  2619. $tmp_tenant_id = $__MINI_GLOBAL_TENANT_ID__;
  2620. $__MINI_GLOBAL_TENANT_ID__ = $post->tenant_id;
  2621. }
  2622. $post_options = Settings::get('app_promoted_post_options', ($__MINI_GLOBAL_TENANT_ID__ > 0 ? Settings::get('app_promoted_post_options', []) : []), true);
  2623. if($tmp_tenant_id > 0){
  2624. $__MINI_GLOBAL_TENANT_ID__ = $tmp_tenant_id;
  2625. }
  2626. return $this->success(
  2627. [
  2628. 'title' => $post_title,
  2629. 'img' => $post->img,
  2630. 'created_at' => $post->created_at->format('Y-m-d H:i:s'),
  2631. 'author' => UserUtils::get_cached_user($post->user_id, false, false, $post->is_anonymous == 1),
  2632. 'is_promoted' => $post->weight > time(),
  2633. 'weight' => timetostr($post->weight),
  2634. 'selectList' => $post_options,
  2635. 'refreshCost' => Settings::get('app_promoted_post_refresh_cost', ($__MINI_GLOBAL_TENANT_ID__ > 0 ? Settings::get('app_promoted_post_refresh_cost', 1.0) : 1.0), true),
  2636. 'rest_coin' => UserUtils::user_coins($uid)
  2637. ]
  2638. );
  2639. } else{
  2640. }
  2641. }
  2642. /**
  2643. * 笔记反馈
  2644. * @param Request $request
  2645. * @return \Illuminate\Http\JsonResponse
  2646. * @throws \Exception
  2647. */
  2648. public function feedback(Request $request){
  2649. $uid = $request->uid;
  2650. $post_id = $request->posts_id;
  2651. // 1: 不喜欢该笔记 2:不喜欢该作者
  2652. $type = $request->type;
  2653. if(_empty_($post_id) || _empty_($type)){
  2654. return $this->fail(200001);
  2655. }
  2656. if(!in_array($type, [1, 2])){
  2657. return $this->fail(200004);
  2658. }
  2659. if($type == 1){
  2660. $post_set = get_user_meta($uid, 'feedback:notlike:post:set', 'j');
  2661. if(!in_array($post_id, $post_set)){
  2662. $post_set[] = $post_id;
  2663. update_user_meta($uid, 'feedback:notlike:post:set', array_unique($post_set), 'j');
  2664. return $this->success([], 200, '标记为不喜欢,将不再展示该笔记');
  2665. }else{
  2666. // 要删除的特定值
  2667. $post_set = array_filter($post_set, function ($value) use ($post_id) {
  2668. return $value != $post_id;
  2669. });
  2670. update_user_meta($uid, 'feedback:notlike:post:set', array_unique($post_set), 'j');
  2671. return $this->success([], 200010, '已取消标记');
  2672. }
  2673. }else if($type == 2){
  2674. $author_id = WxPost::where('id', $post_id)->value('user_id');
  2675. if($author_id){
  2676. $user_set = get_user_meta($uid, 'feedback:notlike:user:set', 'j');
  2677. if(!in_array($author_id, $user_set)){
  2678. $user_set[] = $author_id;
  2679. update_user_meta($uid, 'feedback:notlike:user:set', array_unique($user_set), 'j');
  2680. return $this->success(['post_user_id'=>$author_id], 200, '标记为不喜欢,将不再展示该作者');
  2681. }else{
  2682. // 要删除的特定值
  2683. $user_set = array_filter($user_set, function ($value) use ($author_id) {
  2684. return $value != $author_id;
  2685. });
  2686. update_user_meta($uid, 'feedback:notlike:user:set', array_unique($user_set), 'j');
  2687. return $this->success([], 200010, '已取消标记');
  2688. }
  2689. }else{
  2690. return $this->fail(200003, [], '不存在该篇笔记');
  2691. }
  2692. }
  2693. return $this->fail(200003, [], 'type参数错误');
  2694. }
  2695. /**
  2696. * 笔记分享
  2697. * @param Request $request
  2698. * @return \Illuminate\Http\JsonResponse
  2699. * @throws \Exception
  2700. */
  2701. public function share(Request $request){
  2702. $uid = $request->uid;
  2703. $posts_id_ = $request->posts_id;
  2704. global $__MINI_GLOBAL_DEVICE__;
  2705. if(is_string($posts_id_)){
  2706. $posts_id_ = (int)$posts_id_;
  2707. }
  2708. $post_id = _abs($posts_id_);
  2709. if(_empty_($post_id)){
  2710. return $this->fail(200001);
  2711. }
  2712. $post = WxPost::find($post_id);
  2713. $post_user_id = $post->user_id;
  2714. $refer_id = $post->refer_id;
  2715. $posts_content = $post->posts_content;
  2716. if($posts_content){
  2717. $s_content = preg_replace("/<(img|video).*?src[^\'\"]+[\'\"]([^\"\']+)[^>]+>/is", '', $posts_content);
  2718. $s_content =trim_all_space(strip_tags(html_entity_decode($s_content)), true);
  2719. }
  2720. $post_title = $post->posts_title ?: PostUtils::get_the_title($s_content, $post->id);
  2721. PostUtils::mediaProcess($post, $uid, 90003, 0, true);
  2722. $post->img = Utils::imgWithStyle($post->img, 0, false, true).'?imageMogr2/thumbnail/200x200/crop/200x200/gravity/center/format/jpg/interlace/0/quality/100';
  2723. $is_mini_admin = is_object_user_special($uid, $post->tenant_id);
  2724. $result = [
  2725. 'user' => [],
  2726. 'url' => '',
  2727. 'social' => [
  2728. ],
  2729. 'other' => [],
  2730. // 临时加下
  2731. 'current_page' => 1
  2732. ];
  2733. if($uid && $uid > 0){
  2734. if(!is_mini_examine_mode(11)){
  2735. $data = DB::table('wx_user')
  2736. ->whereIn('id', function ($query) use ($uid) {
  2737. $query->select('object_id')
  2738. ->from('wx_chat')
  2739. ->where('user_id', $uid)
  2740. ->groupBy('object_id')
  2741. ->orderByDesc('created_at');
  2742. })->simplePaginate(10, FieldUtils::userInfoColums());
  2743. if($data->isEmpty()){
  2744. $data = WxUser::where('is_official', 1)->simplePaginate(10, FieldUtils::userInfoColums());
  2745. }
  2746. $result['user'] = $data;
  2747. }
  2748. }
  2749. global $__MINI_GLOBAL_TENANT_ID__;
  2750. if(Settings::get('app_h5_home', '')){
  2751. $result['url'] = Settings::get('app_h5_home', '').'/#/pages/sticky/sticky?id='.$post_id . '&fph=1&from_user=' .$uid. '&tenant=' . $__MINI_GLOBAL_TENANT_ID__;
  2752. }else{
  2753. $result['url'] = env('APP_URL');
  2754. }
  2755. $the_only_path = '/pages/sticky/sticky?id=' . $post->id. '&fph=1&from_user=' .$uid. '&tenant=' . $__MINI_GLOBAL_TENANT_ID__;
  2756. $share_types = Settings::get('app_post_social_share_types', []);
  2757. foreach (['refer', 'wechat', 'timeline', 'qq', 'qzone', 'weibo'] as $key){
  2758. if(!in_array($key, $share_types)){
  2759. continue;
  2760. }
  2761. if($key == 'refer'){
  2762. if($refer_id > 0){
  2763. continue;
  2764. }else{
  2765. $result['social'][] = [
  2766. 'action' => 'refer',
  2767. 'color' => Settings::get('--color-primary', '#FC3A72'),
  2768. 'text' => '站内转发',
  2769. 'icon' => 'mini-icon mini-zhanneizhuanfa',
  2770. 'unicode' => 'e699'
  2771. ];
  2772. }
  2773. }else if($key == 'wechat'){
  2774. $result['social'][] = [
  2775. 'action' => 'wechat',
  2776. 'color' => '#57be6a',
  2777. 'text' => '微信好友',
  2778. 'icon' => 'mini-icon mini-weixin',
  2779. 'unicode' => 'e60b',
  2780. 'share' => json_encode([
  2781. 'provider' => 'weixin',
  2782. 'type' => _empty_(Settings::get('app_meta_appid', '')) ? 0 : 5,
  2783. 'title' => $post_title,
  2784. 'scene' => 'WXSceneSession',
  2785. 'href' => $result['url'],
  2786. 'imageUrl' => $post->img,
  2787. 'miniProgram' => [
  2788. 'id' => Settings::get('app_meta_appid', ''),
  2789. 'path' => $the_only_path,
  2790. 'type' => 0,
  2791. 'webUrl' => $result['url']
  2792. ]
  2793. ]),
  2794. ];
  2795. }else if($key == 'timeline'){
  2796. if($__MINI_GLOBAL_DEVICE__ != 'mp'){
  2797. $result['social'][] = [
  2798. 'action' => 'timeline',
  2799. 'color' => '#80cc46',
  2800. 'text' => '朋友圈',
  2801. 'icon' => 'mini-icon mini-pengyouquan1',
  2802. 'unicode' => 'e669',
  2803. 'share' => json_encode([
  2804. 'provider' => 'weixin',
  2805. 'type' => 0,
  2806. 'title' => $post_title,
  2807. 'summary' => $s_content,
  2808. 'scene' => 'WXSceneTimeline',
  2809. 'href' => $result['url'],
  2810. 'imageUrl' => $post->img,
  2811. 'miniProgram' => [
  2812. 'id' => Settings::get('app_meta_appid', ''),
  2813. 'path' => $the_only_path,
  2814. 'type' => 0,
  2815. 'webUrl' => $result['url']
  2816. ]
  2817. ])
  2818. ];
  2819. }
  2820. }else if($key == 'qq'){
  2821. if(!_empty_(Settings::get('app_qq_app_appid', ''))){
  2822. if($__MINI_GLOBAL_DEVICE__ != 'mp') {
  2823. $result['social'][] = [
  2824. 'action' => 'qq',
  2825. 'color' => '#54b4ef',
  2826. 'text' => 'QQ好友',
  2827. 'icon' => 'mini-icon mini-qq1',
  2828. 'unicode' => 'e66c',
  2829. 'share' => json_encode([
  2830. 'provider' => 'qq',
  2831. 'type' => 1,
  2832. 'title' => $post_title,
  2833. 'summary' => $s_content,
  2834. 'href' => $result['url'],
  2835. 'imageUrl' => $post->img
  2836. ])
  2837. ];
  2838. }
  2839. }
  2840. }else if($key == 'qzone'){
  2841. if(!_empty_(Settings::get('app_qq_app_appid', ''))){
  2842. if($__MINI_GLOBAL_DEVICE__ != 'mp') {
  2843. $result['social'][] = [
  2844. 'action' => 'qzone',
  2845. 'color' => '#f7cf46',
  2846. 'text' => 'QQ空间',
  2847. 'icon' => 'mini-icon mini-Rrl_s_112',
  2848. 'unicode' => 'e62a',
  2849. 'share' => json_encode([
  2850. 'provider' => 'qq',
  2851. 'type' => 1,
  2852. 'title' => $post_title,
  2853. 'href' => $result['url'],
  2854. 'imageUrl' => $post->img
  2855. ])
  2856. ];
  2857. }
  2858. }
  2859. }else if($key == 'weibo'){
  2860. if(!_empty_(Settings::get('app_weibo_app_appid', ''))){
  2861. if($__MINI_GLOBAL_DEVICE__ != 'mp') {
  2862. $result['social'][] = [
  2863. 'action' => 'weibo',
  2864. 'color' => '#d4382a',
  2865. 'text' => '微博',
  2866. 'icon' => 'mini-icon mini-weibo',
  2867. 'unicode' => 'e73c',
  2868. 'share' => json_encode([
  2869. 'provider' => 'sinaweibo',
  2870. 'type' => 0,
  2871. 'title' => $post_title,
  2872. 'href' => $result['url'],
  2873. 'imageUrl' => $post->img
  2874. ])
  2875. ];
  2876. }
  2877. }
  2878. }
  2879. }
  2880. $system_types = Settings::get('app_post_social_system_types', ['showCode', 'copyUrl', 'feedback-notlike-1', 'video-url','promotion', 'report' ]);
  2881. // promotion
  2882. foreach (['showCode', 'edit', 'copyUrl', 'feedback-notlike-1', 'video-url', 'promotion', 'report', 'poster2'] as $key){
  2883. if(!in_array($key, $system_types)){
  2884. continue;
  2885. }
  2886. if($key == 'showCode'){
  2887. $result['other'][] = [
  2888. 'text' => '生成海报',
  2889. 'icon' => 'mini-icon mini-shengchenghaibao',
  2890. 'action' => 'showCode',
  2891. 'unicode' => 'e697',
  2892. ];
  2893. }else if($key == 'poster2'){
  2894. $result['other'][] = [
  2895. 'text' => '小海报',
  2896. 'icon' => 'mini-icon mini-shengchenghaibao',
  2897. 'unicode' => 'e697',
  2898. 'action' => 'poster2'
  2899. ];
  2900. }else if($key == 'edit'){
  2901. if($refer_id > 0 || $post->vote_id > 0){
  2902. }else{
  2903. if(($post_user_id == $uid && $post->posts_state === 0) || $is_mini_admin) {
  2904. $result['other'][] = [
  2905. 'text' => '编辑',
  2906. 'icon' => 'mini-icon mini-xie',
  2907. 'unicode' => 'e6fd',
  2908. 'action' => 'slider',
  2909. 'target_type' => 6,
  2910. 'target_id' => '/pages/creat/index/creat?edit=' . $post_id
  2911. ];
  2912. }
  2913. }
  2914. }else if($key == 'video-url'){
  2915. if($post->post_type == 'video'){
  2916. $result['other'][] = [
  2917. 'text' => '视频下载',
  2918. 'icon' => 'mini-icon mini-xiazai2',
  2919. 'action' => 'video-url',
  2920. 'unicode' => 'e63c',
  2921. 'video_url' => $post->video['video_url']
  2922. ];
  2923. }
  2924. }else if($key == 'copyUrl'){
  2925. $result['other'][] = [
  2926. 'text' => '复制链接',
  2927. 'icon' => 'mini-icon mini-fuzhilianjie',
  2928. 'unicode' => 'e691',
  2929. 'action' => 'copyUrl'
  2930. ];
  2931. }else if($key == 'feedback-notlike-1'){
  2932. $result['other'][] = [
  2933. 'text' => '不喜欢',
  2934. 'icon' => 'mini-icon mini-buxihuan',
  2935. 'unicode' => 'e69d',
  2936. 'action' => 'feedback-notlike-1',
  2937. 'posts_id' => $post_id
  2938. ];
  2939. }else if($key == 'report'){
  2940. if($post_user_id != $uid){
  2941. $result['other'][] = [
  2942. 'text' => '举报',
  2943. 'icon' => 'mini-icon mini-jubao',
  2944. 'unicode' => 'e694',
  2945. 'action' => 'report'
  2946. ];
  2947. }
  2948. }else if($key == 'promotion'){
  2949. $result['other'][] = [
  2950. 'text' => '笔记推广',
  2951. 'icon' => 'mini-icon mini-fufeituiguang1',
  2952. 'unicode' => 'e6f3',
  2953. 'action' => 'promotion'
  2954. ];
  2955. }
  2956. }
  2957. if($post_user_id == $uid || $is_mini_admin){
  2958. $result['other'][] = [
  2959. 'text' => '删除',
  2960. 'icon' => 'mini-icon mini-shanchu211',
  2961. 'unicode' => 'e6f3',
  2962. 'action' => 'delete',
  2963. 'posts_id' => $post->id
  2964. ];
  2965. }
  2966. // _logger_(__file__, __line__, $result);
  2967. return $this->success($result);
  2968. }
  2969. /**
  2970. * 获取文章分享二维码
  2971. * @param Request $request
  2972. * @return \Illuminate\Http\JsonResponse
  2973. * @throws \Exception
  2974. */
  2975. public function makeShowQcode(Request $request)
  2976. {
  2977. $postsId = _abs($request->posts_id);
  2978. $uid = $request->uid;
  2979. global $__MINI_GLOBAL_DEVICE__;
  2980. if(_empty_($postsId)){
  2981. return $this->fail(200001);
  2982. }
  2983. $data = [];
  2984. $data['title'] = Settings::get('about_title', '');
  2985. $post = WxPost::find($postsId);
  2986. if(_empty_($post)){
  2987. return $this->fail(200003);
  2988. }
  2989. $post_user_id = $post->user_id;
  2990. $refer_id = $post->refer_id;
  2991. $posts_content = _mini_phone(_mini_emoji(_mini_aite_replace($post->posts_content), true), true);
  2992. if($posts_content){
  2993. $s_content = preg_replace("/<(img|video).*?src[^\'\"]+[\'\"]([^\"\']+)[^>]+>/is", '', $posts_content);
  2994. $s_content =trim_all_space(strip_tags(html_entity_decode($s_content)), true);
  2995. }
  2996. $post_title = PostUtils::get_the_title($s_content, $post->id, 50);
  2997. PostUtils::mediaProcess($post, $uid, 90004, 0, true);
  2998. // ['glass'=>'', 'theme'=>'black/white', 'attach_id'=>id]
  2999. $poster_glass = get_post_meta($post->id, 'post_poster_glass_obj', 'j');
  3000. if(_empty_($poster_glass)){
  3001. $attach_id = FileUtils::get_url_attach_id($post->img);
  3002. if($attach_id){
  3003. $post_poster_glass_obj = [
  3004. 'glass' => '',
  3005. 'theme' => '',
  3006. 'attach_id' => $attach_id
  3007. ];
  3008. $first_glasses = $post->img . '?imageMogr2/thumbnail/630x800/crop/630x800/gravity/center/format/png/interlace/0/blur/50x1';
  3009. $path = ImageUtils::upload_url_img($first_glasses);
  3010. if($path && $path['url']){
  3011. // 二次上传
  3012. $path2 = ImageUtils::upload_url_img($path['url']. '?imageMogr2/thumbnail/630x800/crop/630x800/gravity/center/format/png/interlace/0/blur/50x1');
  3013. if($path2 && $path2['url']){
  3014. // 三次上传
  3015. $path3 = ImageUtils::upload_url_img($path2['url']. '?imageMogr2/thumbnail/630x800/crop/630x800/gravity/center/format/png/interlace/0/blur/50x1');
  3016. if($path3 && $path3['url']){
  3017. // 四次上传
  3018. $path4 = ImageUtils::upload_url_img($path3['url']. '?imageMogr2/thumbnail/630x800/crop/630x800/gravity/center/format/png/interlace/0/blur/50x1');
  3019. if($path4 && $path4['url']){
  3020. $post_poster_glass_obj['glass'] = $path4['url'];
  3021. update_post_meta($post->id, 'post_poster_glass_obj', $post_poster_glass_obj, 'j');
  3022. FileUtils::force_del_url_file($path3['url']);
  3023. $data['glass'] = $path4['url'] . '?imageMogr2/thumbnail/630x800/crop/630x800/gravity/center/format/png/interlace/0/blur/50x1';
  3024. }else{
  3025. $post_poster_glass_obj['glass'] = $path3['url'];
  3026. update_post_meta($post->id, 'post_poster_glass_obj', $post_poster_glass_obj, 'j');
  3027. $data['glass'] = $path3['url'] . '?imageMogr2/thumbnail/630x800/crop/630x800/gravity/center/format/png/interlace/0/blur/50x1';
  3028. }
  3029. }else{
  3030. $post_poster_glass_obj['glass'] = $path2['url'];
  3031. update_post_meta($post->id, 'post_poster_glass_obj', $post_poster_glass_obj, 'j');
  3032. $data['glass'] = $path2['url'] . '?imageMogr2/thumbnail/630x800/crop/630x800/gravity/center/format/png/interlace/0/blur/50x1';
  3033. }
  3034. }else{
  3035. $post_poster_glass_obj['glass'] = $path['url'];
  3036. update_post_meta($post->id, 'post_poster_glass_obj', $post_poster_glass_obj, 'j');
  3037. $data['glass'] = $path['url'] . '?imageMogr2/thumbnail/630x800/crop/630x800/gravity/center/format/png/interlace/0/blur/50x1';
  3038. }
  3039. }else{
  3040. $data['glass'] = $post->img . '?imageMogr2/thumbnail/630x800/crop/630x800/gravity/center/format/png/interlace/0/blur/50x1';
  3041. }
  3042. UpdatePosterGlassJob::dispatch($post->id);
  3043. }
  3044. }else{
  3045. if(FileUtils::get_url_attach_id($post->img) == $poster_glass['attach_id']){
  3046. _logger_(__file__, __line__, $poster_glass['theme']);
  3047. if(_empty_($poster_glass['theme'])){
  3048. UpdatePosterGlassJob::dispatch($post->id);
  3049. }
  3050. $data['glass'] = $poster_glass['glass'] . '?imageMogr2/thumbnail/630x800/crop/630x800/gravity/center/format/png/interlace/0/blur/50x1';
  3051. }else{
  3052. update_post_meta($post->id, 'post_poster_glass_obj', null, 'j');
  3053. FileUtils::force_del_url_file($poster_glass['glass']);
  3054. }
  3055. }
  3056. $user = WxUser::where('id', $post_user_id)->first(FieldUtils::userInfoColums());
  3057. if($user){
  3058. }else{
  3059. $user = ['user_name'=>'未知用户'];
  3060. }
  3061. if($post->is_anonymous == 1){
  3062. $anonymous_info = UserUtils::get_anonymous_info($user);
  3063. if($anonymous_info){
  3064. $user['user_name'] = $anonymous_info['anonymous_name'];
  3065. $user['user_avatar'] = $anonymous_info['anonymous_avatar'];
  3066. }else{
  3067. $user['user_name'] = '匿名';
  3068. }
  3069. }
  3070. $data['user'] = $user;
  3071. if(empty($post->img)){
  3072. return $this->fail(200006, [], '请先配置“笔记海报默认图片”');
  3073. }
  3074. $page = 'pages/sticky/sticky';
  3075. $code_url = Utils::getMiniCode($page, 'id='.$postsId, $uid);
  3076. $data['qrcode'] = $code_url;
  3077. $data['img'] = $post->img.'?imageMogr2/quality/100/interlace/0/crop/630x800/gravity/center/thumbnail/x800';
  3078. $data['content'] = $post_title;
  3079. $data['tip'] = Settings::get('app_post_poster_bottom_tip', '❤ 扫一扫,找到你想要的生活');
  3080. if($poster_glass){
  3081. $data['tip_color'] = _array_key($poster_glass, 'theme', 'black') == 'white' ? '#333' : '#FFF';
  3082. }else{
  3083. $data['tip_color'] = '#FFF';
  3084. }
  3085. if(Settings::get('is_multi_site', 0) > 0){
  3086. $circle_tip = WxTenant::where('tenant_id', $post->tenant_id)->value('name');
  3087. }else{
  3088. if($post->circle_id > 0){
  3089. $circle_tip = WxCircle::where('id', $post->circle_id)->value('circle_name');
  3090. }else{
  3091. $circle_tip = '广场';
  3092. }
  3093. }
  3094. $data['poster2'] = [
  3095. 'content' => $post_title,
  3096. 'contentImg' => ($post->img == Settings::get('img_post_poster_default', '')) ? '' : ($post->img. '?imageMogr2/quality/100/interlace/0/crop/630x800/gravity/center/thumbnail/x800'),
  3097. 'avatar' => $user->user_avatar,
  3098. 'locationText' => $circle_tip,
  3099. 'locationImg' => env('APP_URL') . '/statics/images/playbill/post/ring.png',
  3100. 'userName' => $user->user_name,
  3101. 'code' => $code_url,
  3102. 'textImg' => env('APP_URL') . '/statics/images/playbill/post/poster-text.png'
  3103. ];
  3104. if(Settings::get('app_h5_home', '')){
  3105. $data['url'] = Settings::get('app_h5_home', '').'/#/pages/sticky/sticky?id='.$post->id;
  3106. }else{
  3107. $data['url'] = env('APP_URL');
  3108. }
  3109. $social = [];
  3110. $share_types = Settings::get('app_post_poster_share_types', []);
  3111. foreach (['wechat', 'timeline', 'qq', 'qzone', 'weibo', 'save'] as $key){
  3112. if(!in_array($key, $share_types)){
  3113. continue;
  3114. }
  3115. if($key == 'wechat'){
  3116. $social[] = [
  3117. 'action' => 'wechat',
  3118. 'color' => '#57be6a',
  3119. 'text' => '微信好友',
  3120. 'icon' => 'mini-icon mini-weixin',
  3121. 'share' => json_encode([
  3122. 'provider' => 'weixin',
  3123. 'type' => 2,
  3124. 'title' => $data['content'],
  3125. 'scene' => 'WXSceneSession',
  3126. 'href' => $data['url'],
  3127. 'imageUrl' => $data['img'],
  3128. 'miniProgram' => [
  3129. 'id' => Settings::get('app_meta_appid', ''),
  3130. 'path' => '/pages/sticky/sticky?id=' . $post->id,
  3131. 'type' => 0,
  3132. 'webUrl' => $data['url']
  3133. ]
  3134. ]),
  3135. ];
  3136. }else if($key == 'timeline'){
  3137. if($__MINI_GLOBAL_DEVICE__ != 'mp'){
  3138. $social[] = [
  3139. 'action' => 'timeline',
  3140. 'color' => '#80cc46',
  3141. 'text' => '朋友圈',
  3142. 'icon' => 'mini-icon mini-pengyouquan1',
  3143. 'share' => json_encode([
  3144. 'provider' => 'weixin',
  3145. 'type' => 2,
  3146. 'title' => $data['content'],
  3147. 'scene' => 'WXSceneTimeline',
  3148. 'href' => $data['url'],
  3149. 'imageUrl' => $data['img']
  3150. ])
  3151. ];
  3152. }
  3153. }else if($key == 'qq'){
  3154. if($__MINI_GLOBAL_DEVICE__ != 'mp') {
  3155. $social[] = [
  3156. 'action' => 'qq',
  3157. 'color' => '#54b4ef',
  3158. 'text' => 'QQ好友',
  3159. 'icon' => 'mini-icon mini-qq1',
  3160. 'share' => json_encode([
  3161. 'provider' => 'qq',
  3162. 'type' => 2,
  3163. 'title' => $data['content'],
  3164. 'summary' => $data['content'],
  3165. 'href' => $data['url'],
  3166. 'imageUrl' => $data['img']
  3167. ])
  3168. ];
  3169. }
  3170. }else if($key == 'qzone'){
  3171. if($__MINI_GLOBAL_DEVICE__ != 'mp') {
  3172. $social[] = [
  3173. 'action' => 'qzone',
  3174. 'color' => '#f7cf46',
  3175. 'text' => 'QQ空间',
  3176. 'icon' => 'mini-icon mini-Rrl_s_112',
  3177. 'share' => json_encode([
  3178. 'provider' => 'qq',
  3179. 'type' => 1,
  3180. 'title' => $data['content'],
  3181. 'href' => $data['url'],
  3182. 'imageUrl' => $data['img']
  3183. ])
  3184. ];
  3185. }
  3186. }else if($key == 'weibo'){
  3187. if($__MINI_GLOBAL_DEVICE__ != 'mp') {
  3188. $social[] = [
  3189. 'action' => 'weibo',
  3190. 'color' => '#d4382a',
  3191. 'text' => '微博',
  3192. 'icon' => 'mini-icon mini-weibo',
  3193. 'share' => json_encode([
  3194. 'provider' => 'sinaweibo',
  3195. 'type' => 0,
  3196. 'title' => $data['content'],
  3197. 'href' => $data['url'],
  3198. 'imageUrl' => $data['img']
  3199. ])
  3200. ];
  3201. }
  3202. }else if($key == 'save'){
  3203. $social[] = [
  3204. 'action' => 'save',
  3205. 'color' => '#999999',
  3206. 'text' => '保存到相册',
  3207. 'icon' => 'mini-icon mini-xiazai2',
  3208. ];
  3209. }
  3210. }
  3211. $data['social'] = $social;
  3212. if($code_url){
  3213. return $this->success($data);
  3214. }else{
  3215. return $this->fail(300001, $data);
  3216. }
  3217. }
  3218. /**
  3219. * 审核笔记
  3220. * @param Request $request
  3221. */
  3222. public function getExceptionalList(Request $request)
  3223. {
  3224. $postsId = $request->posts_id;
  3225. if(_empty_($postsId)){
  3226. return $this->fail(200001);
  3227. }
  3228. $postsId = _abs($postsId);
  3229. $data = WxExceptional::where('posts_id', $postsId)
  3230. ->orderBy('id', 'desc')
  3231. ->get();
  3232. $data->map(function ($v) {
  3233. $v->exceptional_date = format_datetime($v->created_at);
  3234. $v->user = WxUser::where('id', $v->user_id)->first(FieldUtils::userInfoColums());
  3235. });
  3236. return $this->success($data);
  3237. }
  3238. /** 视频推荐接口
  3239. * @param Request $request
  3240. */
  3241. public function recommendedVideos(Request $request){
  3242. $page = $request->page ?: 0;
  3243. $offset = $page * 10;
  3244. $post_id= $request->id;
  3245. if(_empty_($post_id)){
  3246. return $this->fail(200001);
  3247. }
  3248. $uid = $request->uid;
  3249. $data_res = [];
  3250. $post_videos = WxPost::Join('wx_posts_video', 'wx_posts.id', '=', 'wx_posts_video.posts_id')->where('wx_posts.posts_state', 0)->orwhere('wx_posts.id', $post_id)->inRandomOrder()
  3251. ->skip($offset)->take(10)->get(['wx_posts_video.posts_id', 'wx_posts_video.id', 'wx_posts.posts_content', 'wx_posts.user_id', 'wx_posts_video.video_url', 'wx_posts_video.video_thumb_url', 'wx_posts.created_at']);
  3252. $post_videos->map(function ($v) use ($uid, &$data_res, $post_id){
  3253. global $__MINI_GLOBAL_CURRENT_USER_ID__;
  3254. $v->user = WxUser::where('id', $v->user_id)
  3255. ->first(FieldUtils::userInfoColums());//发帖人
  3256. $v->like_count = PostsRepositores::likeCont($v->id); // 笔记喜欢数量
  3257. $v->is_my_posts = $__MINI_GLOBAL_CURRENT_USER_ID__ == $v->user_id; // 是否是我的笔记
  3258. $v->is_follow_user = WxPost::isFollowUser($uid, $v->user_id);// 是否关注该用户
  3259. $v->is_like = WxPost::isLike($uid, $v->id); // 是否喜欢
  3260. $v->is_collect = WxPost::isCollec($uid, $v->id); // 是否收藏
  3261. $v->comment = (new WxPost())
  3262. ->getComment($v->id, ['user_name', 'comment_content', 'user_id', 'posts_user_id', 'comment_img_url']); // 评论
  3263. $v->comment_count = WxCommentRepositores::commentCount($v->id);//评论数量
  3264. $item = [
  3265. 'src' => $v->video_url,
  3266. 'content' => $v->posts_content,
  3267. 'flag' => true,
  3268. 'check' => $v->is_like,
  3269. 'like' => $v->like_count,
  3270. 'isFollow' => $v->is_follow_user,
  3271. 'comment' => $v->comment_count,
  3272. 'avater'=> $v->user->user_avatar,
  3273. 'initialTime' => 0,
  3274. 'at' => $v->user->user_name,
  3275. 'duration' => 999,
  3276. 'uid' => $v->user->id,
  3277. 'pid' => $v->posts_id,
  3278. 'vid' => $v->id,
  3279. 'isAuthor' => $v->is_my_posts,
  3280. 'date' => $v->created_at->format('Y-m-d H:i:s')
  3281. ];
  3282. if($v->posts_id == $post_id){
  3283. array_unshift($data_res, $item);
  3284. }else{
  3285. $data_res[] = $item;
  3286. }
  3287. });
  3288. if($data_res){
  3289. return $this->success($data_res);
  3290. }else{
  3291. return $this->fail(200003);
  3292. }
  3293. }
  3294. }