PublicRpcService.php 105 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643
  1. <?php
  2. namespace App\JsonRpc;
  3. use _PHPStan_62c6a0a8b\OndraM\CiDetector\Env;
  4. use App\Model\BlackWord;
  5. use App\Model\Department;
  6. use App\Model\District;
  7. use App\Model\LetterOfComplaint;
  8. use App\Model\LetterType;
  9. use App\Model\LevelUser;
  10. use App\Model\UserLevel;
  11. use App\Tools\Result;
  12. use Hyperf\DbConnection\Db;
  13. use Hyperf\Di\Annotation\Inject;
  14. use Hyperf\RpcServer\Annotation\RpcService;
  15. use App\Service\MinioService;
  16. use Hyperf\Redis\Redis;
  17. use Overtrue\ChineseCalendar\Calendar;
  18. use App\Model\TemplateClass;
  19. use App\Model\Template;
  20. use App\Model\WebsiteTemplate;
  21. use App\Model\WebsiteTemplateInfo;
  22. use App\Model\Sector;
  23. use App\Model\Component;
  24. use App\Model\Link;
  25. use App\Model\FooterCategory;
  26. use App\Model\Size;
  27. use function Hyperf\Support\retry;
  28. use Hyperf\Paginator\Paginator;
  29. use App\Model\User;
  30. use App\Model\Website;
  31. use App\Constants\ErrorCode;
  32. use GuzzleHttp\Client;
  33. use GuzzleHttp\Exception\GuzzleException;
  34. use App\Model\SectorPlace;
  35. use App\Model\ComponentType;
  36. use App\Model\Article;
  37. use App\Model\WebsiteCategory;
  38. use App\Model\AdPlace;
  39. use App\Model\WebsiteImg;
  40. use App\Model\SectorComponent;
  41. use App\Model\ComponentImg;
  42. #[RpcService(name: "PublicRpcService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  43. class PublicRpcService implements PublicRpcServiceInterface
  44. {
  45. #[Inject]
  46. protected Redis $redis;
  47. /**
  48. * @param array $data
  49. * @return array
  50. */
  51. public function getDistrictList(array $data): array
  52. {
  53. $where = [];
  54. if (isset($data['keyWord'])) {
  55. $where = [
  56. ['name', 'like', '%' . $data['keyWord'] . '%']
  57. ];
  58. }
  59. $result = [];
  60. if (isset($data['pageSize'])) {
  61. $rep = District::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("code", "asc")->get();
  62. $count = District::where($where)->count();
  63. $result = [
  64. 'rows' => $rep,
  65. 'count' => $count
  66. ];
  67. } else {
  68. $result = District::where($data)->orderBy("code", "asc")->get();
  69. }
  70. return $result ? Result::success($result) : Result::error("没有查到数据");
  71. }
  72. /**
  73. * @param array $data
  74. * @return array
  75. */
  76. public function getUserLevelList(array $data): array
  77. {
  78. $where = [];
  79. if (isset($data['keyWord'])) {
  80. $where = [
  81. ['name', 'like', '%' . $data['keyWord'] . '%'],
  82. ];
  83. }
  84. $result = [];
  85. if (isset($data['pageSize'])) {
  86. $rep = UserLevel::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("id", "asc")->get();
  87. $count = UserLevel::where($where)->count();
  88. $result = [
  89. 'rows' => $rep,
  90. 'count' => $count,
  91. ];
  92. } else {
  93. $result = UserLevel::orderBy("id", "asc")->get();
  94. }
  95. return $result ? Result::success($result) : Result::error("没有查到数据");
  96. }
  97. /**
  98. * 添加用户等级
  99. * @param array $data
  100. * @return array
  101. */
  102. public function addUserLevel(array $data): array
  103. {
  104. LevelUser::insertGetId($data);
  105. return Result::success([]);
  106. }
  107. /**
  108. * 更新等级
  109. * @param array $data
  110. * @return array
  111. */
  112. public function updateUserLevel(array $data): array
  113. {
  114. $result = LevelUser::where(['id' => $data['id']])->update($data);
  115. if ($result) {
  116. return Result::success($result);
  117. }
  118. return Result::error("更新失败");
  119. }
  120. /**
  121. * 删除等级
  122. * @param array $data
  123. * @return array
  124. */
  125. public function delUserLevel(array $data): array
  126. {
  127. $result = LevelUser::where(['id' => $data['id']])->delete();
  128. if ($result) {
  129. return Result::success($result);
  130. }
  131. return Result::error("删除失败");
  132. }
  133. /**
  134. * 查询投诉举报信息
  135. * @param array $data
  136. * @return array
  137. */
  138. public function getLetterOfComplaint(array $data = []): array
  139. {
  140. var_dump("====");
  141. $where = [];
  142. if (isset($data['user_id']) && !empty($data['user_id'])) {
  143. array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]);
  144. }
  145. if (isset($data['nature']) && !empty($data['nature'])) {
  146. array_push($where, ['letter_of_complaint.nature', '=', $data['nature']]);
  147. }
  148. if (isset($data['nature_level0']) && !empty($data['nature_level0'])) {
  149. array_push($where, ['letter_of_complaint.nature_level0', '=', $data['nature_level0']]);
  150. }
  151. if (isset($data['status']) && !empty($data['status'])) {
  152. array_push($where, ['letter_of_complaint.status', '=', $data['status']]);
  153. }
  154. $result = [];
  155. if (isset($data['pageSize'])) {
  156. $rep = LetterOfComplaint::where($where)
  157. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  158. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  159. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  160. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  161. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  162. ->select(
  163. "letter_of_complaint.*",
  164. "type_a.type_name as nature_name",
  165. "type_b.type_name as nature_name1",
  166. "type_c.type_name as nature_name0",
  167. "type_d.type_name as status_name",
  168. "type_e.type_name as nature_name3"
  169. )
  170. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("letter_of_complaint.id", "desc")->get();
  171. $count = LetterOfComplaint::where($where)->count();
  172. if ($rep) {
  173. foreach ($rep as $val) {
  174. if ($val['judgment']) {
  175. $val['judgment'] = json_decode($val['judgment']);
  176. }
  177. if ($val['audio_and_video']) {
  178. $val['audio_and_video'] = json_decode($val['audio_and_video']);
  179. }
  180. if ($val['contract']) {
  181. $val['contract'] = json_decode($val['contract']);
  182. }
  183. if ($val['qualifications']) {
  184. $val['qualifications'] = json_decode($val['qualifications']);
  185. }
  186. }
  187. }
  188. $result = [
  189. 'rows' => $rep,
  190. 'count' => $count,
  191. ];
  192. } else {
  193. $result = LetterOfComplaint::where($where)
  194. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  195. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  196. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  197. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  198. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  199. ->select(
  200. "letter_of_complaint.*",
  201. "type_a.type_name as nature_name",
  202. "type_b.type_name as nature_name1",
  203. "type_c.type_name as nature_name0",
  204. "type_d.type_name as status_name",
  205. "type_e.type_name as nature_name3"
  206. )
  207. ->orderBy("letter_of_complaint.id", "desc")->get();
  208. }
  209. return $result ? Result::success($result) : Result::error("没有查到数据");
  210. }
  211. /**
  212. * 添加投诉举报信息
  213. * @param array $data
  214. * @return array
  215. */
  216. public function addLetterOfComplaint(array $data): array
  217. {
  218. $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : '';
  219. $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : '';
  220. $data['contract'] = $data['contract'] ? json_encode($data['contract']) : '';
  221. $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : '';
  222. unset($data['id']);
  223. $result = LetterOfComplaint::insertGetId($data);
  224. if (empty($result)) {
  225. return Result::error("创建失败", 0);
  226. } else {
  227. return Result::success(["id" => $result]);
  228. }
  229. }
  230. /**
  231. * 用户端更新投诉举报
  232. * @param array $data
  233. * @return array
  234. */
  235. public function userUpLetterOfComplaint(array $data): array
  236. {
  237. $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : '';
  238. $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : '';
  239. $data['contract'] = $data['contract'] ? json_encode($data['contract']) : '';
  240. $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : '';
  241. $result = LetterOfComplaint::where(['id' => $data['id']])->update($data);
  242. if (empty($result)) {
  243. return Result::error("创建失败", 0);
  244. } else {
  245. return Result::success(["id" => $result]);
  246. }
  247. }
  248. /**
  249. * 管理后台更新投诉举报信息
  250. * @param array $data
  251. * @return array
  252. */
  253. public function upLetterOfComplaint(array $data): array
  254. {
  255. var_dump("admin:", $data);
  256. $where = [
  257. 'id' => $data['id'],
  258. ];
  259. $filtered_array = array_filter($data, function ($value) {
  260. return $value !== "" && $value !== null && $value !== false && !is_array($value) || !empty($value);
  261. });
  262. $filtered_array['judgment'] = isset($filtered_array['judgment']) ? json_encode($filtered_array['judgment']) : '';
  263. $filtered_array['audio_and_video'] = isset($filtered_array['audio_and_video']) ? json_encode($filtered_array['audio_and_video']) : '';
  264. $filtered_array['contract'] = isset($filtered_array['contract']) ? json_encode($filtered_array['contract']) : '';
  265. $filtered_array['qualifications'] = isset($filtered_array['qualifications']) ? json_encode($filtered_array['qualifications']) : '';
  266. unset($filtered_array['nature_name']);
  267. unset($filtered_array['type_name']);
  268. unset($filtered_array['nature_level_name']);
  269. unset($filtered_array['status_name']);
  270. unset($filtered_array['is_admin']);
  271. unset($filtered_array['type_level_name']);
  272. $result = LetterOfComplaint::where($where)->update($filtered_array);
  273. if ($result) {
  274. return Result::success($result);
  275. }
  276. return Result::error("更新失败", 0);
  277. }
  278. /**
  279. * 查询投诉举报记录
  280. * @param array $data
  281. * @return array
  282. */
  283. public function getLetterOfComplaintInfo(array $data): array
  284. {
  285. $where = [
  286. 'letter_of_complaint.id' => $data['id'],
  287. ];
  288. if (isset($data['user_id']) && !empty($data['user_id'])) {
  289. array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]);
  290. }
  291. $result = LetterOfComplaint::where($where)
  292. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  293. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  294. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  295. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  296. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  297. ->select(
  298. "letter_of_complaint.*",
  299. "type_a.type_name as nature_name",
  300. "type_b.type_name as nature_name1",
  301. "type_c.type_name as nature_name0",
  302. "type_d.type_name as status_name",
  303. "type_e.type_name as nature_name3"
  304. )
  305. ->first();
  306. return Result::success($result);
  307. }
  308. /**
  309. * 删除投诉举报信息
  310. * @param array $data
  311. * @return array
  312. */
  313. public function delLetterOfComplaint(array $data): array
  314. {
  315. $result = LetterOfComplaint::when($data, function ($query) use ($data) {
  316. if (isset($data['id']) && !empty($data['id'])) {
  317. $query->where(['id' => $data['id']]);
  318. }
  319. if (isset($data['user_id']) && !empty($data['user_id'])) {
  320. $query->where(['user_id' => $data['user_id']]);
  321. }
  322. })->delete();
  323. if (empty($result)) {
  324. return Result::error("删除失败", 0);
  325. } else {
  326. return Result::success();
  327. }
  328. }
  329. /**
  330. * 获取举报信息类型
  331. * @param array $data
  332. * @return array
  333. */
  334. public function getLetterType(array $data): array
  335. {
  336. $where = [];
  337. if (isset($data['type'])) {
  338. array_push($where, ['type', '=', $data['type']]);
  339. }
  340. if (isset($data['pid']) && $data['pid'] > 0) {
  341. array_push($where, ['pid', '=', $data['pid']]);
  342. }
  343. $result = LetterType::where($where)->orderBy('sort', 'asc')->get();
  344. return $result ? Result::success($result) : Result::error("没有查到数据");
  345. }
  346. /**
  347. * 更新举报类型
  348. * @param array $data
  349. * @return array
  350. */
  351. public function upLetterType(array $data): array
  352. {
  353. return [];
  354. }
  355. /**
  356. * 添加举报类型
  357. * @param array $data
  358. * @return array
  359. */
  360. public function addLetterType(array $data): array
  361. {
  362. $result = LetterType::insertGetId($data);
  363. if (empty($result)) {
  364. return Result::error("创建失败", 0);
  365. } else {
  366. return Result::success(["id" => $result]);
  367. }
  368. }
  369. /**
  370. * 删除举报类型
  371. * @param array $data
  372. * @return array
  373. */
  374. public function delLetterType(array $data): array
  375. {
  376. $result = LetterType::where('id', $data['id'])->delete();
  377. if (empty($result)) {
  378. return Result::error("删除失败", 0);
  379. } else {
  380. return Result::success();
  381. }
  382. }
  383. /**
  384. * 检测是否已经被接案
  385. * @param array $data
  386. * @return array
  387. */
  388. public function checkMeasure(array $data): array
  389. {
  390. $where = [
  391. 'id' => $data['id'],
  392. ];
  393. $letterOfComplaintInfo = LetterOfComplaint::where($where)->first();
  394. var_dump("查询数据:", $letterOfComplaintInfo['admin_id'], $data['user_id']);
  395. //操作人和当前登陆用户id 相等说明是当前人接收的案件
  396. if (($letterOfComplaintInfo['admin_id'] == $data['user_id']) || empty($letterOfComplaintInfo['admin_id'])) {
  397. return Result::success();
  398. } else {
  399. return Result::error("您不能处理其他人已经接过的案件", 0);
  400. }
  401. }
  402. /**
  403. * 后台获取职能部门
  404. * @param array $data
  405. * @return array
  406. */
  407. public function getZhinengbumenList(array $data): array
  408. {
  409. // 获取分页参数,默认每页 10 条记录
  410. $page = isset($data['page']) ? (int) $data['page'] : 1;
  411. $perPage = isset($data['pagesize']) ? (int) $data['pagesize'] : 10;
  412. // 查询数据并分页
  413. $query = Department::query();
  414. // 可以在这里添加更多的查询条件
  415. if (isset($data['search'])) {
  416. $query->where('name', 'like', '%' . $data['search'] . '%');
  417. }
  418. // 执行分页查询
  419. $result = $query->paginate($perPage, ['*'], 'page', $page);
  420. // 返回分页结果
  421. return Result::success([
  422. 'count' => $result->total(),
  423. 'current_page' => $result->currentPage(),
  424. 'last_page' => $result->lastPage(),
  425. 'pagesize' => $result->perPage(),
  426. 'rows' => $result->items(),
  427. ]);
  428. }
  429. /**
  430. * 添加获取职能部门
  431. * @param array $data
  432. * @return array
  433. */
  434. public function addZhinengbumen(array $data): array
  435. {
  436. $result = Department::insertGetId($data);
  437. if (empty($result)) {
  438. return Result::error("创建失败", 0);
  439. } else {
  440. return Result::success(["id" => $result]);
  441. }
  442. }
  443. public function delZhinengbumen(array $data): array
  444. {
  445. $result = Department::where('id', $data['id'])->delete();
  446. if (empty($result)) {
  447. return Result::error("删除失败", 0);
  448. } else {
  449. return Result::success();
  450. }
  451. }
  452. public function getZhinengbumen(array $data): array
  453. {
  454. $result = Department::where('id', $data['id'])
  455. ->orderBy('department', 'desc')
  456. ->first();
  457. return Result::success($result);
  458. }
  459. public function getPidZhinengbumen(array $data): array
  460. {
  461. if (empty($data['pid'])) {
  462. $data['pid'] = 0;
  463. }
  464. $result = Department::where('pid', $data['pid'])->get();
  465. return Result::success($result);
  466. }
  467. public function modZhinengbumen(array $data): array
  468. {
  469. $result = Department::where('id', $data['id'])->update($data);
  470. if (empty($result)) {
  471. return Result::error("修改失败", 0);
  472. } else {
  473. return Result::success();
  474. }
  475. }
  476. /**
  477. * 查询职能列表
  478. * @param array $data
  479. * @return array
  480. */
  481. public function getDepartment(array $data): array
  482. {
  483. $where = [];
  484. if (isset($data['pid'])) {
  485. $where = [
  486. 'pid' => $data['pid'] ?? 0
  487. ];
  488. }
  489. $result = Department::when(!empty($where), function ($query) use ($where) {
  490. $query->where($where);
  491. })->orderBy("sort", "desc")->get();
  492. if (empty($result)) {
  493. return Result::error("查询失败", 0);
  494. } else {
  495. return Result::success($result);
  496. }
  497. }
  498. /**
  499. * 获取所有的buckets
  500. * @param array $data
  501. * @return array
  502. */
  503. public function getBuckets(array $data): array
  504. {
  505. $result = new MinioService();
  506. // 调用服务层的方法获取存储桶列表
  507. $bucketsResponse = $result->listBuckets();
  508. // 直接返回服务层生成的响应
  509. return Result::success($bucketsResponse['data']);
  510. }
  511. /**
  512. * 上传文件
  513. * @param array $data
  514. * @return array
  515. */
  516. public function uploadFile(array $data): array
  517. {
  518. $result = new MinioService();
  519. $rep = $result->uploadFile($data);
  520. if ($rep['code'] == 200) {
  521. return Result::success($rep['data']);
  522. } else {
  523. return Result::error("上传失败!");
  524. }
  525. }
  526. /**
  527. * 黑名单管理
  528. * @param array $data
  529. * @return array
  530. */
  531. public function getBlackWordList(array $data): array
  532. {
  533. $result = BlackWord::when($data, function ($query) use ($data) {
  534. if (isset($data['name']) && $data['name']) {
  535. $query->where('black_word.name', 'like', '%' . $data['name'] . '%');
  536. }
  537. })->orderBy('black_word.id', 'desc')
  538. ->paginate(
  539. intval($data['pageSize']),
  540. [
  541. 'black_word.*',
  542. ],
  543. 'page',
  544. intval($data['page'])
  545. );
  546. $count = $result->total();
  547. $returnData = [
  548. 'rows' => $result->items(),
  549. 'count' => $count
  550. ];
  551. return Result::success($returnData);
  552. }
  553. /**
  554. * 添加黑名单
  555. * @param array $data
  556. * @return array
  557. */
  558. public function addBlackWord(array $data): array
  559. {
  560. Db::beginTransaction();
  561. try {
  562. $info = BlackWord::where(['name' => $data['name']])->first();
  563. if ($info) {
  564. Db::rollBack();
  565. return Result::error("该黑名单已存在", 0);
  566. }
  567. $data['type'] = 10;
  568. $result = BlackWord::insertGetId($data);
  569. $redisKey = 'black_word';
  570. $this->redis->sAdd($redisKey, $data['name']);
  571. Db::commit();
  572. return Result::success(["id" => $result]);
  573. } catch (\Exception $e) {
  574. Db::rollBack();
  575. return Result::error("创建失败" . $e->getMessage(), 0);
  576. }
  577. }
  578. /**
  579. * 删除黑名单
  580. * @param array $data
  581. * @return array
  582. */
  583. public function delBlackWord(array $data): array
  584. {
  585. Db::beginTransaction();
  586. try {
  587. BlackWord::where(['name' => $data['name']])->delete();
  588. $redisKey = 'black_word';
  589. $this->redis->sRem($redisKey, $data['name']);
  590. Db::commit();
  591. return Result::success([]);
  592. } catch (\Exception $e) {
  593. Db::rollBack();
  594. return Result::error("删除失败" . $e->getMessage(), 0);
  595. }
  596. }
  597. /**
  598. * 修改违禁词
  599. * @param array $data
  600. * @return array
  601. */
  602. public function upBlackWord(array $data): array
  603. {
  604. Db::beginTransaction();
  605. try {
  606. $checkInfo = BlackWord::where(['name' => $data['name']])->first();
  607. if ($checkInfo) {
  608. Db::rollBack();
  609. return Result::error("该违禁词已经存在", 0);
  610. }
  611. $blackWordInfo = BlackWord::where(['id' => $data['id']])->first();
  612. if ($blackWordInfo) {
  613. //先删除redis
  614. $blackWordInfo = $blackWordInfo->toArray();
  615. $redisKey = 'black_word';
  616. $this->redis->sRem($redisKey, $blackWordInfo['name']);
  617. $this->redis->sAdd($redisKey, $data['name']);
  618. BlackWord::where(['id' => $data['id']])->update(['name' => $data['name']]);
  619. Db::commit();
  620. return Result::success([]);
  621. } else {
  622. Db::rollBack();
  623. return Result::error("系统错误", 0);
  624. }
  625. } catch (\Exception $e) {
  626. Db::rollBack();
  627. return Result::error("修改失败" . $e->getMessage(), 0);
  628. }
  629. }
  630. /**
  631. * 获取风格
  632. * @return void
  633. */
  634. public function getTemplateClassList(array $data): array
  635. {
  636. $where = [];
  637. if (isset($data['name']) && $data['name']) {
  638. array_push($where, ['template_class.name', 'like', '%' . $data['name'] . '%']);
  639. }
  640. if (isset($data['keyword']) && $data['keyword']) {
  641. array_push($where, ['template_class.keyword', 'like', '%' . $data['keyword'] . '%']);
  642. }
  643. $template = TemplateClass::when($where, function ($query) use ($where) {
  644. $query->where($where);
  645. });
  646. $count = $template->count();
  647. // $countQuery = clone $template;
  648. $row = $template
  649. ->leftJoin('template', function ($join) {
  650. $join->on('template_class.class_id', '=', 'template.template_class_id');
  651. })
  652. ->select('template_class.*', DB::raw('COUNT(template.template_class_id) as template_count'))
  653. ->groupBy('template_class.id')
  654. ->orderBy('template_class.id', 'desc')
  655. ->offset(($data['page'] - 1) * $data['pageSize'])
  656. ->limit($data['pageSize'])
  657. ->get();
  658. $result = [
  659. 'rows' => $row,
  660. 'count' => $count,
  661. ];
  662. if ($row->isEmpty()) {
  663. return Result::error("暂无风格", 0);
  664. } else {
  665. return Result::success($result);
  666. }
  667. }
  668. /**
  669. * 添加风格
  670. * @param
  671. * @return void
  672. */
  673. public function addTemplateClass(array $data): array
  674. {
  675. $data['keyword'] = json_encode($data['keyword']);
  676. $template_class = TemplateClass::where('name', $data['name'])
  677. ->orWhere('class_id', $data['class_id'])
  678. ->first();
  679. if ($template_class) {
  680. return Result::error("风格名称或者风格编号已存在,不可添加!", 0);
  681. }
  682. $result = TemplateClass::insertGetId($data);
  683. if (empty($result)) {
  684. return Result::error("创建风格失败", 0);
  685. } else {
  686. return Result::success(["id" => $result]);
  687. }
  688. }
  689. /**
  690. * 更新风格
  691. * @param array $data
  692. * @return array
  693. */
  694. public function upTemplateClass(array $data): array
  695. {
  696. $where = [
  697. 'id' => $data['id'],
  698. ];
  699. $template_class = TemplateClass::where($where)->first();
  700. if (empty($template_class)) {
  701. return Result::error("未查询到风格", 0);
  702. }
  703. if ($template_class->type == 1) {
  704. return Result::error("默认风格不能修改", 0);
  705. }
  706. $template = TemplateClass::where('id', '!=', $data['id'])
  707. // ->where(['name' => $data['name']])
  708. // ->orWhere(['class_id' => $data['class_id']])
  709. ->where(function ($query) use ($data) {
  710. $query->where('name', $data['name'])
  711. ->orWhere('class_id', $data['class_id']);
  712. })
  713. ->first();
  714. if ($template) {
  715. return Result::error("风格名称或者风格编号已存在,不可编辑!", 0);
  716. }
  717. $updateData = [
  718. 'name' => $data['name'],
  719. 'keyword' => json_encode($data['keyword']),
  720. 'class_id' => $data['class_id'],
  721. ];
  722. $result = TemplateClass::where($where)->update($updateData);
  723. if (empty($result)) {
  724. return Result::error("更新失败", 0);
  725. } else {
  726. return Result::success($result);
  727. }
  728. }
  729. /**
  730. * 删除风格
  731. * @param array $data
  732. * @return array
  733. */
  734. public function delTemplateClass(array $data): array
  735. {
  736. $where = [
  737. 'id' => $data['id'],
  738. ];
  739. $template_class = TemplateClass::where($where)->first();
  740. if (empty($template_class)) {
  741. return Result::error("未查询到风格", 0);
  742. }
  743. if ($template_class->type == 1) {
  744. return Result::error("默认风格不能删除", 0);
  745. }
  746. $template = Template::where('template_class_id', $template_class['class_id'])->get();
  747. if (!empty($template->all())) {
  748. try {
  749. // 默认风格 1
  750. Db::beginTransaction();
  751. $template = Template::where('template_class_id', $template['class_id'])->update(['template_class_id' => 1]);
  752. if (empty($template)) {
  753. Db::rollBack();
  754. return Result::error("删除失败", 0);
  755. }
  756. $result = TemplateClass::where($where)->delete();
  757. } catch (\Exception $e) {
  758. return Result::error("删除失败" . $e->getMessage(), 0);
  759. }
  760. } else {
  761. $result = TemplateClass::where('id', $data['id'])->delete();
  762. }
  763. if (empty($result)) {
  764. return Result::error("删除失败", 0);
  765. }
  766. return Result::success($result);
  767. }
  768. /**
  769. * 根据风格名称-获取获取所有风格
  770. * @param array $data
  771. * @return array
  772. */
  773. public function getTemplateClass(array $data): array
  774. {
  775. $where = [];
  776. if (!empty($data['template_name'])) {
  777. $where['name'] = $data['template_name'];
  778. }
  779. $result = TemplateClass::where($where)->get();
  780. if (empty($result)) {
  781. return Result::error("暂无风格", 0);
  782. }
  783. return Result::success($result);
  784. }
  785. /**
  786. * 获取皮肤列表
  787. * @param array $data
  788. * @return array
  789. */
  790. public function getTemplateList(array $data): array
  791. {
  792. $where = [];
  793. if (!empty($data['template_class_id'])) {
  794. $where['template_class_id'] = $data['template_class_id'];
  795. }
  796. if (!empty($data['template_name'])) {
  797. array_push($where, ['template_name', 'like', '%' . $data['template_name'] . '%']);
  798. }
  799. if (!empty($data['template_keyword'])) {
  800. array_push($where, ['template_keyword', 'like', '%' . $data['template_keyword'] . '%']);
  801. }
  802. $result = Template::where($where)
  803. ->leftJoin('template_class', 'template.template_class_id', 'template_class.class_id')
  804. ->select('template.*', 'template_class.name as template_class_name')
  805. ->orderBy('template.id', 'desc')
  806. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  807. if (empty($result)) {
  808. return Result::error("暂无皮肤", 0);
  809. }
  810. return Result::success($result);
  811. }
  812. public function getTemplateInfo(array $data): array
  813. {
  814. $result = Template::where('template.id', $data['id'])
  815. ->leftJoin('template_class', 'template.template_class_id', 'template_class.class_id')
  816. ->select('template.*', 'template_class.name as template_class_name')
  817. ->first();
  818. if (empty($result)) {
  819. return Result::error("暂无皮肤", 0);
  820. }
  821. return Result::success($result);
  822. }
  823. /**
  824. * 添加皮肤
  825. * @param array $data
  826. * @return array
  827. */
  828. public function addTemplate(array $data): array
  829. {
  830. var_dump($data);
  831. unset($data['user_id']);
  832. $template = Template::where('template_name', $data['template_name'])
  833. ->orWhere('template_id', $data['template_id'])
  834. ->first();
  835. if ($template) {
  836. return Result::error("皮肤名称或者皮肤编号已存在,不可添加!", 0);
  837. }
  838. $data['template_keyword'] = json_encode($data['template_keyword']) ?? '';
  839. $page_type = json_decode($data['page_type'], true);
  840. $data['page_type'] = json_encode(array_values(array_unique($page_type)));
  841. $result = Template::insertGetId($data);
  842. if (empty($result)) {
  843. return Result::error("创建失败", 0);
  844. } else {
  845. return Result::success($result);
  846. }
  847. }
  848. /**
  849. * 删除皮肤
  850. * @param array $data
  851. * @return array
  852. */
  853. public function delTemplate(array $data): array
  854. {
  855. $rector = Sector::where('template_id', $data['id'])->first();
  856. if (!empty($rector)) {
  857. return Result::error("此皮肤已被绑定通栏,不可删除", 0);
  858. }
  859. $template = Template::where('id', $data['id'])->first();
  860. if(empty($template)){
  861. return Result::error("此皮肤不存在!", 0);
  862. }
  863. $web_template = WebsiteTemplateInfo::where('template_id', $template['template_id'])->first();
  864. if (!empty($web_template)) {
  865. return Result::error("此皮肤已被绑定网站,不可删除", 0);
  866. }
  867. if ($template->type == 1) {
  868. return Result::error("默认皮肤不能删除", 0);
  869. }
  870. $result = Template::where('id', $data['id'])->delete();
  871. var_dump($result, '-------------------delete');
  872. if ($result) {
  873. return Result::success($result);
  874. } else {
  875. return Result::error("删除失败", 0);
  876. }
  877. }
  878. /**
  879. * 更新皮肤
  880. * @param array $data
  881. * @return array
  882. */
  883. public function updateTemplate(array $data): array
  884. {
  885. unset($data['user_id']);
  886. $template = Template::where('id', $data['id'])
  887. ->first();
  888. if (empty($template)) {
  889. return Result::error("此皮肤不存在!", 0);
  890. }
  891. $template = Template::where('id', '!=', $data['id'])
  892. ->where(function ($query) use ($data) {
  893. $query->where('template_name', $data['template_name'])
  894. ->orWhere('template_id', $data['template_id']);
  895. })
  896. ->first();
  897. if ($template) {
  898. return Result::error("皮肤名称或者皮肤编号已存在,不可编辑!", 0);
  899. }
  900. $data['template_keyword'] = json_encode($data['template_keyword']) ?? '';
  901. $page_type = json_decode($data['page_type'], true);
  902. $data['page_type'] = json_encode(array_values(array_unique($page_type)));
  903. $result = Template::where('id', $data['id'])->update($data);
  904. var_dump($result, '-------------------update');
  905. if (!$result) {
  906. return Result::error("更新失败", 0);
  907. } else {
  908. return Result::success('更新成功');
  909. }
  910. }
  911. /**
  912. * 获取所有尺寸
  913. * @param array $data
  914. * @return array
  915. */
  916. public function getAllSize(array $data): array
  917. {
  918. if(isset($data['id']) && !empty($data['id'])){
  919. $result = Size::where('id', $data['id'])->get()->all();
  920. }else{
  921. $result = Size::get()->all();
  922. }
  923. if(empty($result)){
  924. return Result::error("暂无尺寸", 0);
  925. }
  926. return Result::success($result);
  927. }
  928. /**
  929. * 根据皮肤名称-获取所有皮肤
  930. * @param array $data
  931. * @return array
  932. */
  933. public function getAllTemplate(array $data): array
  934. {
  935. $where = [];
  936. if (isset($data['template_class_id']) && !empty($data['template_class_id'])) {
  937. $where[] = ['template_class_id', $data['template_class_id']];
  938. }
  939. if (isset($data['template_name']) && !empty($data['template_name'])) {
  940. $where[] = ['template_name', 'like', '%' . $data['template_name'] . '%'];
  941. }
  942. $result = Template::where($where)->get()->all();
  943. if (empty($result)) {
  944. return Result::error("暂无皮肤", 0);
  945. }
  946. return Result::success($result);
  947. }
  948. /**
  949. * 获取通栏列表
  950. * @param array $data
  951. * @return array
  952. */
  953. public function getSectorList(array $data): array
  954. {
  955. $where = [];
  956. if (isset($data['template_class_id']) && !empty($data['template_class_id'])) {
  957. $where['template.template_class_id'] = $data['template_class_id'];
  958. }
  959. if (isset($data['template_id']) && !empty($data['template_id'])) {
  960. array_push($where, ['template.template_id', $data['template_id']]);
  961. }
  962. if (isset($data['sector_name']) && !empty($data['sector_name'])) {
  963. array_push($where, ['sector.sector_name', 'like', '%' . $data['sector_name'] . '%']);
  964. }
  965. if (isset($data['width']) && !empty($data['width']) && isset($data['height']) && !empty($data['height'])) {
  966. $size_id = Size::where('width', 'like', '%' . $data['width'] . '%')->where('height', 'like', '%' . $data['height'] . '%')->pluck('id');
  967. } else if (isset($data['width']) && !empty($data['width'])) {
  968. $size_id = Size::where('width', 'like', '%' . $data['width'] . '%')->pluck('id');
  969. } else if (isset($data['height']) && !empty($data['height'])) {
  970. $size_id = Size::where('height', 'like', '%' . $data['height'] . '%')->pluck('id');
  971. } else {
  972. $size_id = [];
  973. }
  974. if(isset($data['page_type']) && !empty($data['page_type'])){
  975. array_push($where, ['sector.page_type', 'like', '%' . $data['page_type'] . '%']);
  976. }
  977. $result = Sector::when(!empty($size_id), function ($query) use ($size_id) {
  978. $query->whereIn('sector.size_id', $size_id);
  979. })
  980. ->leftJoin('size', 'size.id', '=', 'sector.size_id')
  981. ->leftJoin('template', 'template.template_id', '=', 'sector.template_id')
  982. ->leftJoin('template_class', 'template_class.class_id', '=', 'template.template_class_id')
  983. ->leftJoin('sector_place', 'sector_place.sector_type', '=', 'sector.place_type')
  984. ->where($where)
  985. ->where('sector_place.type_id', 1)
  986. ->select('sector.*', 'size.width', 'size.height', 'template_class.name as class_name', 'template_class.class_id', 'template.template_name',
  987. 'sector_place.name as place_name', 'sector_place.sector_img as place_img')
  988. ->orderBy('sector.id', 'desc')
  989. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  990. if(empty($result)){
  991. return Result::error('暂无通栏!');
  992. }
  993. return Result::success($result);
  994. }
  995. /**
  996. * 获取通栏详情
  997. * @param array $data
  998. * @return array
  999. */
  1000. public function getSectorInfo(array $data): array
  1001. {
  1002. // $where = [];
  1003. $where[] = ['sector.id', '=', $data['id']];
  1004. $result = Sector::where($where)
  1005. ->leftJoin('template', 'template.template_id', '=', 'sector.template_id')
  1006. ->select('sector.*','template.template_name','template.template_id')
  1007. ->orderBy('sector.id', 'desc')
  1008. ->first();
  1009. $result['component'] = SectorComponent::where('sector_component.sector_id', $data['id'])
  1010. ->leftJoin('component', 'component.component_type', '=', 'sector_component.component_id')
  1011. ->select('component.component_type','sector_component.sort_id','component.component_name')
  1012. ->get()->all();
  1013. // $sorts = array_values(array_unique(array_column($components, 'sort_id')));
  1014. // $result['component'] = $components;
  1015. $result['place'] = SectorPlace::where('sector_place.sector_type', $result['place_type'])
  1016. ->where('sector_place.type_id',1)
  1017. ->select('sector_place.sector_img','sector_place.map')
  1018. ->first();
  1019. // $key_num = 0;
  1020. // foreach($result['place'] as $key => $value){
  1021. // if($value['type_id'] == 1){
  1022. // $sector_place['sector_plate'] = $value;
  1023. // }else{
  1024. // $sector_place['component_place'][$key_num] = $value;
  1025. // $key_num++;
  1026. // }
  1027. // }
  1028. // $result['place'] = $sector_place;
  1029. if (empty($result)) {
  1030. return Result::error('此通栏不存在!');
  1031. }
  1032. return Result::success($result);
  1033. }
  1034. /**
  1035. * 获取经纬度信息
  1036. * @return void
  1037. */
  1038. public function getIpInfo(array $data): array
  1039. {
  1040. if (empty($data['ip'])) {
  1041. // 在RPC服务中,依赖$_SERVER是不可靠的,强制要求调用方传入IP
  1042. return Result::error('IP地址不能为空!');
  1043. }
  1044. $client_ip = $data['ip'];
  1045. try {
  1046. // 直接从容器获取 Guzzle 客户端实例
  1047. /** @var \GuzzleHttp\Client $client */
  1048. $client = \Hyperf\Context\ApplicationContext::getContainer()->get(Client::class);
  1049. // 使用新的 GeoJS API 地址
  1050. $api_url = "https://get.geojs.io/v1/ip/geo/{$client_ip}.json";
  1051. // 将 timeout 作为请求选项传递
  1052. $response = $client->get($api_url, ['timeout' => 5]);
  1053. if ($response->getStatusCode() !== 200) {
  1054. return Result::error('IP查询接口请求失败,状态码:' . $response->getStatusCode());
  1055. }
  1056. $ip_info = json_decode($response->getBody()->getContents(), true);
  1057. // GeoJS 的成功响应不包含 'status' 字段,直接检查关键数据是否存在
  1058. if ($ip_info && isset($ip_info['latitude']) && isset($ip_info['longitude'])) {
  1059. // GeoJS 返回的经纬度是字符串,转换为浮点数
  1060. $ip_info['latitude'] = floatval($ip_info['latitude']);
  1061. $ip_info['longitude'] = floatval($ip_info['longitude']);
  1062. return Result::success($ip_info);
  1063. }
  1064. // 如果返回的数据不符合预期,提供一个通用错误
  1065. $errorMessage = $ip_info['message'] ?? '获取IP地理位置信息失败';
  1066. return Result::error($errorMessage);
  1067. } catch (GuzzleException $e) {
  1068. // 这个异常会给出详细的网络错误信息,如超时、无法解析域名等
  1069. return Result::error('请求IP查询接口异常: ' . $e->getMessage());
  1070. } catch (\Throwable $e) {
  1071. return Result::error('获取IP信息时发生未知错误: ' . $e->getMessage());
  1072. }
  1073. }
  1074. /**
  1075. * 获取天气
  1076. * @param array $data
  1077. * @return array
  1078. */
  1079. public function getWeatherInfo(array $data): array
  1080. {
  1081. $month = $data['month'] ?? date('m');
  1082. $day = $data['day'] ?? date('d');
  1083. // 使用缓存键
  1084. $cacheKey = "tsbb_data_weather_{$month}_{$day}";
  1085. // 尝试从缓存获取数据
  1086. $container = \Hyperf\Context\ApplicationContext::getContainer();
  1087. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  1088. if ($cachedData = $cache->get($cacheKey)) {
  1089. return Result::success(unserialize($cachedData));
  1090. }
  1091. $location = $data['latitude'] . ":" . $data['longitude'];
  1092. $api_url = "https://api.seniverse.com/v3/weather/now.json?key=" . \Hyperf\Support\env('WEATHER_KEY') . "&location=" . $location . "&language=zh-Hans&unit=c";
  1093. $ch = curl_init($api_url);
  1094. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1095. $response = curl_exec($ch);
  1096. curl_close($ch);
  1097. // 解析 JSON 响应
  1098. $WeatherInfo = json_decode($response, true);
  1099. // 缓存结果,设置1小时过期
  1100. $cache->set($cacheKey, serialize($WeatherInfo), 3600);
  1101. if ($WeatherInfo) {
  1102. return Result::success($WeatherInfo);
  1103. } else {
  1104. return Result::error("获取天气失败", 0);
  1105. }
  1106. }
  1107. /**
  1108. * 获取农历信息
  1109. * @return void
  1110. */
  1111. public function getCalendar(array $data): array
  1112. {
  1113. $calendar = new Calendar();
  1114. $result = $calendar->solar($data['year'], $data['month'], $data['day'], $data['hour']); // 阳历
  1115. return Result::success($result);
  1116. }
  1117. /**
  1118. * 添加通栏
  1119. * @param array $data
  1120. * @return array
  1121. */
  1122. public function addSector(array $data): array
  1123. {
  1124. unset($data['user_id']);
  1125. // 对传入的 page_type 数组进行去重、转换为整数并重新索引
  1126. $data['page_type'] = array_values(array_unique(array_map('intval', $data['page_type'])));
  1127. $data['page_type'] = json_encode($data['page_type']);
  1128. $template = Template::where('template_id', $data['template_id'])
  1129. ->first();
  1130. if (empty($template)) {
  1131. return Result::error('皮肤不存在!');
  1132. }
  1133. $sector_id = Sector::where('sector_id',$data['sector_id'])->first();
  1134. if(!empty($sector_id)){
  1135. return Result::error('通栏编号已存在!');
  1136. }
  1137. $sector_place = SectorPlace::where('sector_type',$data['place_type'])->get();
  1138. if(empty($sector_place)){
  1139. return Result::error('位置不存在!');
  1140. }
  1141. $sort = json_decode($data['component_code'],true);
  1142. $kw = 0;
  1143. $flattened = [];
  1144. $component = [];
  1145. $sector_component = [];
  1146. foreach ($sort as $key => $subArray) {
  1147. foreach ($subArray as $k => $item) {
  1148. $component[] = $item;
  1149. $sector_component[] = [
  1150. 'sector_id' => $data['sector_id'],
  1151. 'component_id' => $item,
  1152. 'sort_id' => $key + 1,
  1153. 'place_id' => $data['place_type'],
  1154. ];
  1155. }
  1156. }
  1157. $component_num = count($component);
  1158. $count = count(array_unique($component));
  1159. // return Result::success($sector_component);
  1160. if(count($sort) != $data['component_num'] || $component_num != $count){
  1161. return Result::error('组件关联错误!');
  1162. }
  1163. // 通栏分类:1:资讯类:2:通栏广告类;3:混合类;4:头条类;5:轮播图类;
  1164. $sector_code = [
  1165. 'sectorName' => $data['sector_name'],
  1166. 'sectorId' => $data['sector_id'],
  1167. 'sectorType' => $data['sector_type'],
  1168. 'sectorPlace' => $data['place_type'],
  1169. ];
  1170. // return Result::success($sector_code);
  1171. $data['sector_code'] = json_encode($sector_code);
  1172. Db::beginTransaction();
  1173. try {
  1174. $com_sector = SectorComponent::insert($sector_component);
  1175. if(empty($com_sector)){
  1176. Db::rollBack();
  1177. return Result::error('通栏关联组件失败!');
  1178. }
  1179. // $up_component = Component::whereIn('component_type',$sector_component['component_id'])->update(['status' => 2]);
  1180. // if(empty($up_component)){
  1181. // Db::rollBack();
  1182. // return Result::error('通栏关联组件失败!');
  1183. // }
  1184. $result = Sector::insertGetId($data);
  1185. if (empty($result)) {
  1186. Db::rollBack();
  1187. return Result::error('添加失败');
  1188. }
  1189. Db::commit();
  1190. return Result::success($result);
  1191. } catch (\Exception $e) {
  1192. Db::rollBack();
  1193. return Result::error($e->getMessage());
  1194. }
  1195. }
  1196. /**
  1197. * 删除通栏
  1198. * @param array $data
  1199. * @return array
  1200. */
  1201. public function delSector(array $data): array
  1202. {
  1203. $sector = Sector::where('id', $data['id'])->first();
  1204. if (empty($sector)) {
  1205. return Result::error('通栏不存在!');
  1206. }
  1207. Db::beginTransaction();
  1208. try {
  1209. $component_id = SectorComponent::where('sector_id', $sector['sector_id'])->delete();
  1210. if (empty($component_id)) {
  1211. Db::rollBack();
  1212. return Result::error('解除相关组件关联关系失败!');
  1213. }
  1214. $result = Sector::where('id', $data['id'])->delete();
  1215. if (empty($result)) {
  1216. Db::rollBack();
  1217. return Result::error('通栏删除失败!');
  1218. }
  1219. Db::commit();
  1220. return Result::success('通栏删除成功!');
  1221. } catch (\Exception $e) {
  1222. Db::rollBack();
  1223. return Result::error($e->getMessage());
  1224. }
  1225. }
  1226. /**
  1227. * 修改通栏
  1228. * @param array $data
  1229. * @return array
  1230. */
  1231. public function updateSector(array $data): array
  1232. {
  1233. unset($data['user_id']);
  1234. $sector = Sector::where('id', $data['id'])->first();
  1235. if (empty($sector)) {
  1236. return Result::error('通栏不存在!');
  1237. }
  1238. if($sector['sector_id'] != $data['sector_id']){
  1239. $sector_id = Sector::where('sector_id',$data['sector_id'])->first();
  1240. if(!empty($sector_id)){
  1241. return Result::error('通栏编号已存在!');
  1242. }
  1243. }
  1244. $sector_code = [
  1245. 'sectorName' => strval($data['sector_name']),
  1246. 'sectorId' => intval($data['sector_id']),
  1247. 'sectorType' => intval($data['sector_type']),
  1248. 'sectorPlace' => intval($data['place_type']),
  1249. ];
  1250. // return Result::success($sector_code);
  1251. $data['sector_code'] = json_encode($sector_code);
  1252. // 对传入的 page_type 数组进行去重、转换为整数并重新索引
  1253. $data['page_type'] = array_values(array_unique(array_map('intval', $data['page_type'])));
  1254. $data['page_type'] = json_encode($data['page_type']);
  1255. $template = Template::where('template_id', $data['template_id'])
  1256. ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$data['page_type']])
  1257. ->first();
  1258. if (empty($template)) {
  1259. return Result::error('皮肤不存在!');
  1260. }
  1261. $sort = json_decode($data['component_code'],true);
  1262. $kw = 0;
  1263. $flattened = [];
  1264. $component = [];
  1265. $sector_component = [];
  1266. foreach ($sort as $key => $subArray) {
  1267. foreach ($subArray as $k => $item) {
  1268. $component[] = $item;
  1269. $sector_component[] = [
  1270. 'sector_id' => $data['sector_id'],
  1271. 'component_id' => $item,
  1272. 'sort_id' => $key + 1,
  1273. 'place_id' => $data['place_type'],
  1274. ];
  1275. }
  1276. }
  1277. // // 批量插入数据到 ComponentSector 表
  1278. // \App\Model\ComponentSector::insert($sector_component);
  1279. $component_num = count($component);
  1280. $count = count(array_unique($component));
  1281. // return Result::success($sector_component);
  1282. if(count($sort) != $data['component_num'] || $component_num != $count){
  1283. return Result::error('组件关联错误!');
  1284. }
  1285. $data['sector_code'] = json_encode($sector_code);
  1286. Db::beginTransaction();
  1287. try {
  1288. $com_sector = SectorComponent::where('sector_id', $sector['sector_id'])->pluck('component_id');
  1289. if(empty($com_sector)){
  1290. Db::rollBack();
  1291. return Result::error('通栏解除组件关联失败!');
  1292. }
  1293. // $up_component = Component::whereIn('component_type',$com_sector)->update(['status' => 1]);
  1294. // if(empty($up_component)){
  1295. // Db::rollBack();
  1296. // return Result::error('通栏解除组件关联失败!');
  1297. // }
  1298. $del_SectorComponent = SectorComponent::where('sector_id', $sector['sector_id'])->delete();
  1299. if(empty($del_SectorComponent)){
  1300. Db::rollBack();
  1301. return Result::error('通栏解除组件关联失败!');
  1302. }
  1303. $com_sector = SectorComponent::insert($sector_component);
  1304. if(empty($com_sector)){
  1305. Db::rollBack();
  1306. return Result::error('通栏关联组件失败!');
  1307. }
  1308. // $up_component = Component::whereIn('component_id',$sector_component['component_type'])
  1309. // ->update(['status' => 2,]);
  1310. // if(empty($up_component)){
  1311. // Db::rollBack();
  1312. // return Result::error('通栏关联组件失败!');
  1313. // }
  1314. $result = Sector::where('id', $data['id'])->update($data);
  1315. if (empty($result)) {
  1316. Db::rollBack();
  1317. return Result::error('修改失败');
  1318. }
  1319. Db::commit();
  1320. return Result::success($result);
  1321. } catch (\Exception $e) {
  1322. Db::rollBack();
  1323. return Result::error($e->getMessage());
  1324. }
  1325. }
  1326. public function getComponentList(array $data): array
  1327. {
  1328. $where = [];
  1329. if (isset($data['component_name']) && !empty($data['component_name'])) {
  1330. array_push($where, ['component.component_name', 'like', '%' . $data['component_name'] . '%']);
  1331. }
  1332. if (isset($data['width']) && !empty($data['width']) && isset($data['height']) && !empty($data['height'])) {
  1333. array_push($where, ['component.component_width', 'like', '%' . $data['width'] . '%']);
  1334. array_push($where, ['component.component_height', 'like', '%' . $data['height'] . '%']);
  1335. } else if (isset($data['width']) && !empty($data['width'])) {
  1336. array_push($where, ['component.component_width', 'like', '%' . $data['width'] . '%']);
  1337. } else if (isset($data['height']) && !empty($data['height'])) {
  1338. array_push($where, ['component.component_height', 'like', '%' . $data['height'] . '%']);
  1339. } else {
  1340. }
  1341. if(isset($data['type_id']) && !empty($data['type_id'])){
  1342. $where['component.type_id'] = $data['type_id'];
  1343. }
  1344. $result = Component::where($where)
  1345. ->leftJoin('component_type','component_type.id','=','component.type_id')
  1346. ->select( 'component.*', 'component_type.com_typename')
  1347. ->orderBy('component.updated_at', 'desc')
  1348. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  1349. if(empty($result)){
  1350. return Result::error('暂无数据');
  1351. }
  1352. return Result::success($result);
  1353. }
  1354. public function getComponentInfo(array $data): array
  1355. {
  1356. $where = ['component.id'=>$data['id']];
  1357. $result = Component::where($where)
  1358. ->leftJoin('component_type','component_type.id','=','component.type_id')
  1359. ->select( 'component.*','component_type.com_typename')
  1360. ->get();
  1361. if(empty($result)){
  1362. return Result::error('暂无数据');
  1363. }
  1364. return Result::success($result);
  1365. }
  1366. /*
  1367. 新增组件
  1368. */
  1369. public function addComponent(array $data): array
  1370. {
  1371. unset($data['user_id']);
  1372. $component_id = Component::where('component_type',$data['component_type'])->first();
  1373. if(!empty($component_id)){
  1374. return Result::error('组件编号已存在!');
  1375. }
  1376. $component_type = ComponentType::where('id',$data['type_id'])->first();
  1377. if(empty($component_type)){
  1378. return Result::error('组件分类不存在!');
  1379. }
  1380. // 组件分类:1:资讯-头条组件;2:资讯-轮播组件;3:资讯-推荐图类组件;4:资讯-最新类组件;5:资讯-推荐类;6:资讯-热点类组件;
  1381. // 7:资讯-栏目类组件;8:列表类组件;9:详情类组件;10:二级导航栏类组件;11:广告类;12:静态资源类;13:底部导航类;
  1382. $data['type_id'] = intval($data['type_id']);
  1383. $add_arr = [
  1384. // 'template_id' => intval($data['template_id']),
  1385. 'component_type' => intval($data['component_type']),
  1386. 'component_name' => $data['component_name'],
  1387. 'component_img' => $data['component_img'],
  1388. 'component_width' => $data['component_width'],
  1389. 'component_height' => $data['component_height'],
  1390. 'type_id' => intval($data['type_id']),
  1391. 'component_keyword' => $data['component_keyword'],
  1392. ];
  1393. $component_head_code = [
  1394. 'component_type' => $add_arr['component_type'],
  1395. 'type_id' => $add_arr['type_id'],
  1396. 'component_name' => $add_arr['component_name'],
  1397. ];
  1398. $add_arr['component_code'] = json_encode($component_head_code,true);
  1399. switch($data['type_id']){
  1400. case 1: //1:资讯-头条组件;
  1401. case 2: //2:资讯-轮播组件;
  1402. case 3: //3:资讯-推荐图类组件;
  1403. case 4: //4:资讯-最新类组件;
  1404. case 5: //5:资讯-推荐类组件;
  1405. case 6: //6:资讯-热点类组件;
  1406. $add_arr['level'] = $data['type_id'];
  1407. $add_arr['img_num'] = intval($data['img_num']);
  1408. $add_arr['text_num'] = intval($data['text_num']);
  1409. $component_data['componentData'] = [
  1410. 'category_id' => '',
  1411. 'level' => $add_arr['level'],
  1412. 'imgSize' => $data['img_num'] ?? '',
  1413. 'textSize' => $data['text_num'] ?? '',
  1414. 'child' => [
  1415. 'id' => '',
  1416. 'imgSize' => '',
  1417. 'textSize' => ''
  1418. ]
  1419. ];
  1420. $add_arr['component_data'] = json_encode($component_data, true);
  1421. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1422. break;
  1423. case 7: //7:资讯-栏目类组件;
  1424. $add_arr['img_num'] = intval($data['img_num']);
  1425. $add_arr['text_num'] = intval($data['text_num']);
  1426. $add_arr['child_imgnum'] = intval($data['child_imgnum'] ?? null);
  1427. $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
  1428. $component_data['componentData'] = [
  1429. 'category_id' => '',
  1430. 'level' => '',
  1431. 'imgSize' => $add_arr['img_num'] ?? '',
  1432. 'textSize' => $add_arr['text_num'] ?? '',
  1433. 'child' => [
  1434. 'id' => '',
  1435. 'imgSize' => $add_arr['child_imgnum'] ?? '',
  1436. 'textSize' => $add_arr['child_textnum'] ?? '',
  1437. ]
  1438. ];
  1439. $add_arr['component_data'] = json_encode($component_data,true);
  1440. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1441. break;
  1442. case 8: //8:列表类组件;
  1443. $add_arr['pageSize'] = intval($data['pageSize']);
  1444. $component_data['componentData'] = [
  1445. 'category_id' => '',
  1446. 'pageType' => [
  1447. 'page' => 1,
  1448. 'pageSize' => $add_arr['pageSize'] ?? '',
  1449. ]
  1450. ];
  1451. $add_arr['component_data'] = json_encode($component_data,true);
  1452. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1453. break;
  1454. case 9: //9:详情类组件;
  1455. $component_data['componentData'] = [
  1456. 'article_id' => '',
  1457. ];
  1458. $add_arr['component_data'] = json_encode($component_data,true);
  1459. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1460. break;
  1461. case 10: //10:二级导航类组件;
  1462. $add_arr['cate_place'] = 1;
  1463. $add_arr['num'] = intval($data['num']);
  1464. $component_data['componentData'] = [
  1465. 'pid' => '',
  1466. 'placeid' => 1,
  1467. 'num' => $add_arr['num'],
  1468. ];
  1469. $add_arr['component_data'] = json_encode($component_data,true);
  1470. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1471. break;
  1472. case 11: //11:广告类;
  1473. $add_arr['ad_width'] = intval($data['ad_width']);
  1474. $add_arr['ad_height'] = intval($data['ad_height']);
  1475. $add_arr['component_width'] = intval($data['ad_width']);
  1476. $add_arr['component_height'] = intval($data['ad_height']);
  1477. $add_arr['ad_type'] = intval($data['ad_type']);
  1478. $add_arr['ad_img'] = $data['ad_img'];
  1479. $ad = [
  1480. 'width' => $add_arr['ad_width'],
  1481. 'height' => $add_arr['ad_height'],
  1482. 'name' => '',
  1483. 'price' => '',
  1484. 'introduce' => '',
  1485. 'website_id' => '',
  1486. 'thumb' => $add_arr['ad_img'],
  1487. 'typeid' => $add_arr['ad_type'],
  1488. 'ad_tag' => '',
  1489. ];
  1490. $add_arr['ad'] = json_encode($ad,true);
  1491. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1492. $add_arr['adimg_info'] = $data['img_info'];
  1493. $ad_imginfo = json_decode($data['img_info'],true);
  1494. break;
  1495. case 13: //13:底部导航类;
  1496. $component_data['componentData'] = [
  1497. 'fcat_id' => '',
  1498. ];
  1499. $add_arr['component_data'] = json_encode($component_data,true);
  1500. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1501. break;
  1502. case 14:
  1503. $add_arr['ad_width'] = intval($data['ad_width']);
  1504. $add_arr['ad_height'] = intval($data['ad_height']);
  1505. $add_arr['component_width'] = intval($data['component_width']);
  1506. $add_arr['component_height'] = intval($data['component_height']);
  1507. $add_arr['ad_type'] = intval($data['ad_type']);
  1508. $add_arr['ad_img'] = $data['ad_img'];
  1509. $add_arr['img_num'] = intval($data['img_num']);
  1510. $add_arr['text_num'] = intval($data['text_num']);
  1511. $add_arr['child_imgnum'] = intval($data['child_imgnum'] ?? null);
  1512. $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
  1513. $component_data['componentData'] = [
  1514. 'category_id' => '',
  1515. 'level' => '',
  1516. 'imgSize' => $data['img_num'] ?? '',
  1517. 'textSize' => $data['text_num'] ?? '',
  1518. 'child' => [
  1519. 'id' => '',
  1520. 'imgSize' => $data['child_imgnum'] ?? '',
  1521. 'textSize' => $data['child_textnum'] ?? '',
  1522. ]
  1523. ];
  1524. $ad = [
  1525. 'width' => $add_arr['ad_width'],
  1526. 'height' => $add_arr['ad_height'],
  1527. 'name' => '',
  1528. 'price' => '',
  1529. 'introduce' => '',
  1530. 'website_id' => '',
  1531. 'thumb' => $add_arr['ad_img'],
  1532. 'typeid' => $add_arr['ad_type'],
  1533. 'ad_tag' => '',
  1534. ];
  1535. $add_arr['ad'] = json_encode($ad,true);
  1536. $add_arr['component_data'] = json_encode($component_data,true);
  1537. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1538. $add_arr['adimg_info'] = $data['img_info'];
  1539. $ad_imginfo = json_decode($data['img_info'],true);
  1540. break;
  1541. default:
  1542. break;
  1543. }
  1544. if($data['type_id'] == 11 || $data['type_id'] == 14){
  1545. Db::beginTransaction();
  1546. try{
  1547. $website_img = WebsiteImg::insertGetId($ad_imginfo);
  1548. var_dump($website_img);
  1549. $add_arr['ad_imgid'] = $website_img;
  1550. if(empty($website_img)){
  1551. Db::rollBack();
  1552. return Result::error('广告默认图上传失败!');
  1553. }
  1554. $result = Component::insertGetId($add_arr);
  1555. if(empty($result)){
  1556. Db::rollBack();
  1557. return Result::error('添加失败!');
  1558. }
  1559. Db::commit();
  1560. }catch(\Exception $e){
  1561. Db::rollback();
  1562. return Result::error('添加失败!');
  1563. }
  1564. }else{
  1565. $result = Component::insertGetId($add_arr);
  1566. if(empty($result)){
  1567. return Result::error('添加组件失败!');
  1568. }
  1569. }
  1570. return Result::success($result);
  1571. }
  1572. public function delComponent(array $data): array
  1573. {
  1574. $component = Component::where('id', $data['id'])->first();
  1575. if(empty($component)){
  1576. return Result::error('组件不存在!');
  1577. }
  1578. $component_id = SectorComponent::where('component_id', $component['component_type'])->first();
  1579. if (!empty($component_id)) {
  1580. return Result::error('请先解除相关组件关联关系!');
  1581. }
  1582. Db::beginTransaction();
  1583. try{
  1584. if($component['type_id'] == 11 || $component['type_id'] == 14){
  1585. $ad_img = WebsiteImg::where('id',$component['ad_imgid'])->first();
  1586. if(!empty($ad_img)){
  1587. $ad_img = WebsiteImg::where('id',$component['ad_imgid'])->delete();
  1588. if(empty($ad_img)){
  1589. Db::rollBack();
  1590. return Result::error('删除广告默认图失败!');
  1591. }
  1592. }
  1593. }
  1594. $result = Component::where('id',$data['id'])->delete();
  1595. if(empty($result)){
  1596. Db::rollBack();
  1597. return Result::error('删除失败!');
  1598. }
  1599. Db::commit();
  1600. return Result::success($result);
  1601. }catch(\Exception $e){
  1602. Db::rollback();
  1603. return Result::error('删除失败!');
  1604. }
  1605. }
  1606. public function updateComponent(array $data): array
  1607. {
  1608. unset($data['user_id']);
  1609. $id = $data['id'];
  1610. unset($data['id']);
  1611. $component_id = Component::where('id','!=',$id)->where('component_type',$data['component_type'])->first();
  1612. if(!empty($component_id) || $component_id != null){
  1613. return Result::error('组件编号已存在!');
  1614. }
  1615. $component_type = ComponentType::where('id',$data['type_id'])->first();
  1616. if(empty($component_type)){
  1617. return Result::error('组件分类不存在!');
  1618. }
  1619. $component = Component::where('id',$id)->first();
  1620. if(empty($component)){
  1621. return Result::error('组件不存在!');
  1622. }
  1623. // 组件分类:1:资讯-头条组件;2:资讯-轮播组件;3:资讯-推荐图类组件;4:资讯-最新类组件;5:资讯-推荐类;6:资讯-热点类组件;
  1624. // 7:资讯-栏目类组件;8:列表类组件;9:详情类组件;10:二级导航栏类组件;11:广告类;12:静态资源类;13:底部导航类;
  1625. $data['type_id'] = intval($data['type_id']);
  1626. $add_arr = [
  1627. // 'template_id' => intval($data['template_id']),
  1628. 'component_type' => intval($data['component_type']),
  1629. 'component_name' => $data['component_name'],
  1630. 'component_img' => $data['component_img'],
  1631. 'component_width' => $data['component_width'],
  1632. 'component_height' => $data['component_height'],
  1633. 'type_id' => intval($data['type_id']),
  1634. 'component_keyword' => $data['component_keyword'],
  1635. ];
  1636. $component_head_code = [
  1637. 'component_type' => $add_arr['component_type'],
  1638. 'type_id' => $add_arr['type_id'],
  1639. 'component_name' => $add_arr['component_name'],
  1640. ];
  1641. $add_arr['component_code'] = json_encode($component_head_code,true);
  1642. switch($data['type_id']){
  1643. case 1: //1:资讯-头条组件;
  1644. case 2: //2:资讯-轮播组件;
  1645. case 3: //3:资讯-推荐图类组件;
  1646. case 4: //4:资讯-最新类组件;
  1647. case 5: //5:资讯-推荐类组件;
  1648. case 6: //6:资讯-热点类组件;
  1649. $add_arr['level'] = $data['type_id'];
  1650. $add_arr['img_num'] = intval($data['img_num']);
  1651. $add_arr['text_num'] = intval($data['text_num']);
  1652. $component_data['componentData'] = [
  1653. 'category_id' => '',
  1654. 'level' => $add_arr['level'],
  1655. 'imgSize' => $data['img_num'] ?? '',
  1656. 'textSize' => $data['text_num'] ?? '',
  1657. 'child' => [
  1658. 'id' => '',
  1659. 'imgSize' => '',
  1660. 'textSize' => ''
  1661. ]
  1662. ];
  1663. $add_arr['component_data'] = json_encode($component_data, true);
  1664. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1665. break;
  1666. case 7: //7:资讯-栏目类组件;
  1667. $add_arr['img_num'] = intval($data['img_num']);
  1668. $add_arr['text_num'] = intval($data['text_num']);
  1669. $add_arr['child_imgnum'] = intval($data['child_imgnum'] ?? null);
  1670. $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
  1671. $component_data['componentData'] = [
  1672. 'category_id' => '',
  1673. 'level' => '',
  1674. 'imgSize' => $add_arr['img_num'] ?? '',
  1675. 'textSize' => $add_arr['text_num'] ?? '',
  1676. 'child' => [
  1677. 'id' => '',
  1678. 'imgSize' => $add_arr['child_imgnum'] ?? '',
  1679. 'textSize' => $add_arr['child_textnum'] ?? '',
  1680. ]
  1681. ];
  1682. $add_arr['component_data'] = json_encode($component_data,true);
  1683. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1684. break;
  1685. case 8: //8:列表类组件;
  1686. $add_arr['pageSize'] = intval($data['pageSize']);
  1687. $component_data['componentData'] = [
  1688. 'category_id' => '',
  1689. 'pageType' => [
  1690. 'page' => 1,
  1691. 'pageSize' => $add_arr['pageSize'] ?? '',
  1692. ]
  1693. ];
  1694. $add_arr['component_data'] = json_encode($component_data,true);
  1695. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1696. break;
  1697. case 9: //9:详情类组件;
  1698. $component_data['componentData'] = [
  1699. 'article_id' => '',
  1700. ];
  1701. $add_arr['component_data'] = json_encode($component_data,true);
  1702. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1703. break;
  1704. case 10: //10:二级导航类组件;
  1705. $add_arr['cate_place'] = 1;
  1706. $add_arr['num'] = intval($data['num']);
  1707. $component_data['componentData'] = [
  1708. 'pid' => '',
  1709. 'placeid' => 1,
  1710. 'num' => $add_arr['num'],
  1711. ];
  1712. $add_arr['component_data'] = json_encode($component_data,true);
  1713. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1714. break;
  1715. case 11: //11:广告类;
  1716. $add_arr['ad_width'] = intval($data['ad_width']);
  1717. $add_arr['ad_height'] = intval($data['ad_height']);
  1718. $add_arr['component_width'] = intval($data['ad_width']);
  1719. $add_arr['component_height'] = intval($data['ad_height']);
  1720. $add_arr['ad_type'] = intval($data['ad_type']);
  1721. $add_arr['ad_img'] = $data['ad_img'];
  1722. $ad = [
  1723. 'width' => $add_arr['ad_width'],
  1724. 'height' => $add_arr['ad_height'],
  1725. 'name' => '',
  1726. 'price' => '',
  1727. 'introduce' => '',
  1728. 'website_id' => '',
  1729. 'thumb' => $add_arr['ad_img'],
  1730. 'typeid' => $add_arr['ad_type'],
  1731. 'ad_tag' => '',
  1732. ];
  1733. $add_arr['ad'] = json_encode($ad,true);
  1734. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1735. $add_arr['adimg_info'] = $data['img_info'];
  1736. $ad_imginfo = json_decode($data['img_info'],true);
  1737. break;
  1738. case 13: //13:底部导航类;
  1739. $component_data['componentData'] = [
  1740. 'fcat_id' => '',
  1741. ];
  1742. $add_arr['component_data'] = json_encode($component_data,true);
  1743. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1744. break;
  1745. case 14:
  1746. $add_arr['ad_width'] = intval($data['ad_width']);
  1747. $add_arr['ad_height'] = intval($data['ad_height']);
  1748. $add_arr['component_width'] = intval($data['component_width']);
  1749. $add_arr['component_height'] = intval($data['component_height']);
  1750. $add_arr['ad_type'] = intval($data['ad_type']);
  1751. $add_arr['ad_img'] = $data['ad_img'];
  1752. $add_arr['img_num'] = intval($data['img_num']);
  1753. $add_arr['text_num'] = intval($data['text_num']);
  1754. $add_arr['child_imgnum'] = intval($data['child_imgnum'] ?? null);
  1755. $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
  1756. $component_data['componentData'] = [
  1757. 'category_id' => '',
  1758. 'level' => '',
  1759. 'imgSize' => $data['img_num'] ?? '',
  1760. 'textSize' => $data['text_num'] ?? '',
  1761. 'child' => [
  1762. 'id' => '',
  1763. 'imgSize' => $data['child_imgnum'] ?? '',
  1764. 'textSize' => $data['child_textnum'] ?? '',
  1765. ]
  1766. ];
  1767. $ad = [
  1768. 'width' => $add_arr['ad_width'],
  1769. 'height' => $add_arr['ad_height'],
  1770. 'name' => '',
  1771. 'price' => '',
  1772. 'introduce' => '',
  1773. 'website_id' => '',
  1774. 'thumb' => $add_arr['ad_img'],
  1775. 'typeid' => $add_arr['ad_type'],
  1776. 'ad_tag' => '',
  1777. ];
  1778. $add_arr['ad'] = json_encode($ad,true);
  1779. $add_arr['component_data'] = json_encode($component_data,true);
  1780. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1781. $add_arr['adimg_info'] = $data['img_info'];
  1782. $ad_imginfo = json_decode($data['img_info'],true);
  1783. break;
  1784. default:
  1785. break;
  1786. }
  1787. // var_dump("ad_imginfo:",$ad_imginfo);
  1788. $cll_column = [
  1789. 'img_num' => null,
  1790. 'text_num' => null,
  1791. 'child_imgnum' => null,
  1792. 'child_textnum' => null,
  1793. 'category_id' => null,
  1794. 'child_id' => null,
  1795. 'num' => null,
  1796. 'level' => null,
  1797. 'fcatid' => null,
  1798. 'article_id' => null,
  1799. 'cate_place' => null,
  1800. 'pageSize' => null,
  1801. 'ad_img' => null,
  1802. 'ad_width' => null,
  1803. 'ad_height' => null,
  1804. 'ad' => '',
  1805. 'ad_type' => null,
  1806. 'ad_imgid' => null,
  1807. 'adimg_info' => '[]',
  1808. ];
  1809. Db::beginTransaction();
  1810. try{
  1811. // return Result::success($add_arr);
  1812. if(($component['type_id'] == 11 || $component['type_id'] == 14) && ($data['type_id'] != 11 && $data['type_id'] != 14)){
  1813. $website_img = WebsiteImg::where('id',$component['ad_imgid'])->delete();
  1814. if(empty($website_img)){
  1815. Db::rollBack();
  1816. return Result::error('广告默认图删除失败!');
  1817. }
  1818. var_dump("删除",$website_img);
  1819. }
  1820. if(($data['type_id'] == 11 || $data['type_id'] == 14) && ($component['type_id'] != 11 && $component['type_id'] != 14)){
  1821. $website_img = WebsiteImg::insertGetId($ad_imginfo);
  1822. $add_arr['ad_imgid'] = $website_img;
  1823. if(empty($website_img)){
  1824. Db::rollBack();
  1825. return Result::error('广告默认图上传失败!');
  1826. }
  1827. var_dump("上传",$website_img);
  1828. }
  1829. if(($component['type_id'] == 11 || $component['type_id'] == 14) && ($data['type_id'] == 11 || $data['type_id'] == 14)){
  1830. $website_img = WebsiteImg::where('id',$component['ad_imgid'])->first();
  1831. if(empty($website_img)){
  1832. $website_img = WebsiteImg::insertGetId($ad_imginfo);
  1833. $add_arr['ad_imgid'] = $website_img;
  1834. }else{
  1835. $website_img = WebsiteImg::where('id',$component['ad_imgid'])->update($ad_imginfo);
  1836. $add_arr['ad_imgid'] = $component['ad_imgid'];
  1837. }
  1838. if(empty($website_img)){
  1839. Db::rollBack();
  1840. return Result::error('广告默认图修改失败!');
  1841. }
  1842. }
  1843. $add_arr = array_merge($cll_column,$add_arr);
  1844. $result = Component::where('id',$id)->update($add_arr);
  1845. if(empty($result)){
  1846. Db::rollBack();
  1847. return Result::error('修改失败!');
  1848. }
  1849. Db::commit();
  1850. }catch(\Exception $e){
  1851. Db::rollBack();
  1852. return Result::error('修改失败!');
  1853. }
  1854. return Result::success($result);
  1855. }
  1856. public function getWebsiteTemplateInfo(array $data)
  1857. {
  1858. $where = [];
  1859. if (isset($data['id'])) {
  1860. $where[] = ['id', '=', $data['id']];
  1861. }
  1862. $result = WebsiteTemplateInfo::where($where)
  1863. ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id')
  1864. ->leftJoin('website_template', 'website_template_info.template_id', '=', 'website_template.id')
  1865. ->select('website_template_info.*', 'website.website_name')
  1866. ->get();
  1867. if ($result) {
  1868. return Result::success($result);
  1869. } else {
  1870. return Result::error('暂无数据');
  1871. }
  1872. }
  1873. /**
  1874. * 自助建站----1.获取页面类型回显
  1875. * @param array $data
  1876. * @return array
  1877. */
  1878. public function getWebPageType(array $data): array
  1879. {
  1880. // 1:图片 2:文字 3:底部
  1881. $friend_link = Link::where('website_id', $data['website_id'])->where('type', 3)->get();
  1882. if (empty($friend_link->toArray())) {
  1883. return Result::error('暂无友情链接数据!');
  1884. }
  1885. $footer_category = FooterCategory::where('website_id', $data['website_id'])->get();
  1886. if (empty($footer_category->toArray())) {
  1887. return Result::error('暂无底部导航数据!');
  1888. }
  1889. $page_type = WebsiteTemplateInfo::where('website_id', $data['website_id'])->value('page_type');
  1890. if (empty($page_type)) {
  1891. $page_type = [];
  1892. } else {
  1893. $page_type = json_decode($page_type, true);
  1894. }
  1895. // '网站页面类型(存数组)1:首页 2:分类页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页
  1896. if (isset($page_type) && in_array(5, $page_type)) {
  1897. $page_type = 1;
  1898. } else {
  1899. $page_type = 0;
  1900. }
  1901. $result = [
  1902. 'friend_link' => $friend_link,
  1903. 'footer_category' => $footer_category,
  1904. 'page_type' => $page_type,
  1905. ];
  1906. return Result::success($result);
  1907. }
  1908. /**
  1909. * 自助建站----2.添加页面类型
  1910. * @param array $data
  1911. * @return array
  1912. */
  1913. public function addWebPageType(array $data): array
  1914. {
  1915. // return Result::success($data);
  1916. // 1:首页 2:频道页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页'
  1917. if ($data['is_search'] == 1) {
  1918. $page_type = json_encode([1,2,3,4,5,6,7]);
  1919. } else {
  1920. $page_type = json_encode([1,2,3,4,6,7]);
  1921. }
  1922. // 0:未构建;1:已填写基础信息;2:已选择模板; action_id
  1923. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1924. $website_template = WebsiteTemplate::where('website_id', $data['website_id'])->first();
  1925. Db::beginTransaction();
  1926. try{
  1927. if (empty($website_template_info)) {
  1928. $result['template_info'] = WebsiteTemplateInfo::create([
  1929. 'website_id' => $data['website_id'],
  1930. 'page_type' => $page_type,
  1931. 'user_id' => $data['user_id']
  1932. ])->id;
  1933. } else {
  1934. if ($website_template_info['status'] == 2) {
  1935. Db::rollBack();
  1936. return Result::error('网站已应用,不可再次修改!');
  1937. }
  1938. $result['template_info'] = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['page_type' => $page_type, 'action_id' => 1, 'user_id' => $data['user_id']]);
  1939. }
  1940. if (!$result['template_info']) {
  1941. Db::rollBack();
  1942. return Result::error('网站所选页面添加失败');
  1943. }
  1944. if(empty($website_template)){
  1945. $result['template'] = WebsiteTemplate::insertGetId([
  1946. 'website_id' => $data['website_id'],
  1947. 'page_type' => $page_type,
  1948. 'user_id' => $data['user_id'],
  1949. ]);
  1950. }else{
  1951. $result['template'] = WebsiteTemplate::where('website_id', $data['website_id'])->update([
  1952. 'page_type' => $page_type,
  1953. ]);
  1954. }
  1955. if(!$result['template']){
  1956. Db::rollBack();
  1957. return Result::error('添加网站预制模版信息失败!');
  1958. }
  1959. Db::commit();
  1960. return Result::success($result);
  1961. }catch(\Exception $e){
  1962. Db::rollBack();
  1963. return Result::error('添加失败');
  1964. }
  1965. }
  1966. /**
  1967. * 自助建站---流程---3.选择皮肤列表
  1968. * @param array $data
  1969. * @return array
  1970. */
  1971. public function getWebsiteTemplateList(array $data): array
  1972. {
  1973. $where = [];
  1974. if (isset($data['template_class_id']) && $data['template_class_id']) {
  1975. $where[] = ['template_class_id', '=', $data['template_class_id']];
  1976. }
  1977. // 0:未构建 1:未应用 2:已应用 status
  1978. $templste_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1979. if (empty($templste_info)) {
  1980. return Result::error('请先填写网站基础信息!');
  1981. }
  1982. if ($templste_info['status'] == 2) {
  1983. return Result::error('网站已应用,不可再次修改!');
  1984. }
  1985. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1986. if (is_array($data['keyword'])) {
  1987. // 拼接多个模糊查询条件
  1988. $query = Template::query();
  1989. foreach ($data['keyword'] as $kw) {
  1990. $escapedKw = addcslashes($kw, '%_'); // 转义通配符
  1991. $query->WhereRaw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?", ["%$escapedKw%"]);
  1992. }
  1993. } else {
  1994. $escapedKeyword = addcslashes($data['keyword'], '%_'); // 转义通配符
  1995. $where[] = [DB::raw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?"), "%$escapedKeyword%"];
  1996. }
  1997. } else {
  1998. $query = Template::where($where);
  1999. }
  2000. $template_id = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first(['template_id', 'page_type']);
  2001. // return Result::success($template_id);
  2002. if (!empty($template_id['page_type']) && $templste_info['page_type'] != '[]' && is_string($templste_info['page_type'])) {
  2003. $template_page = is_string($templste_info['page_type']) ? json_decode($templste_info['page_type'], true) : [];
  2004. } else {
  2005. $template_page = [];
  2006. }
  2007. if (!empty($template_id['template_id'])) {
  2008. $result['template_id'] = $templste_info['template_id'];
  2009. }
  2010. // 确保 $template_page 为有效数据,避免 SQL 注入风险,这里使用参数绑定
  2011. $template_page_str = json_encode($template_page);
  2012. $result['template'] = $query->where($where)
  2013. ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$template_page_str])
  2014. ->orderBy('updated_at', 'desc')
  2015. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  2016. if (empty($result['template'])) {
  2017. $result['template'] = Template::orderBy('updated_at', 'desc')
  2018. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  2019. }
  2020. $template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->value('template_id');
  2021. if ($template) {
  2022. $result['template_id'] = $template;
  2023. } else {
  2024. $result['template_id'] = 0;
  2025. }
  2026. return Result::success($result);
  2027. }
  2028. /**
  2029. * 自助建站---流程---4.选择皮肤
  2030. * @param array $data
  2031. * @return array
  2032. */
  2033. public function chooseWebsiteTemplate(array $data): array
  2034. {
  2035. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2036. if (empty($website_template_info)) {
  2037. return Result::error('请先填写网站基础信息!');
  2038. }
  2039. // 0:未构建 1:未应用 2:已应用 status
  2040. if ($website_template_info['status'] == 2) {
  2041. return Result::error('网站已应用,不可再次修改!');
  2042. }
  2043. $template = Template::where('template_id', $data['template_id'])->first();
  2044. if (empty($template)) {
  2045. return Result::error('未查询到皮肤!');
  2046. }
  2047. // 0:未构建;1:已填写基础信息;2:已选择模板; action_id
  2048. // 分别更新 WebsiteTemplateInfo 和 WebsiteTemplate 表
  2049. Db::beginTransaction();
  2050. try {
  2051. $reuslt['template_info'] = WebsiteTemplateInfo::where('website_id', $data['website_id'])
  2052. ->update(['template_id' => $data['template_id'],'action_id' => 2,'user_id'=> $data['user_id']]);
  2053. if(empty($reuslt['template_info'])){
  2054. Db::rollBack();
  2055. return Result::error('选择皮肤失败!');
  2056. }
  2057. $result['template'] = WebsiteTemplate::where('website_id', $data['website_id'])
  2058. ->update(['template_id' => $data['template_id'],'user_id'=> $data['user_id']]);
  2059. if(empty($result['template'])){
  2060. Db::rollBack();
  2061. return Result::error('网站模版选择皮肤失败!');
  2062. }
  2063. Db::commit();
  2064. return Result::success($result);
  2065. } catch (\Exception $e) {
  2066. Db::rollBack();
  2067. return Result::error('选择皮肤失败!');
  2068. }
  2069. }
  2070. /**
  2071. * 自助建站---流程---5.保存模版
  2072. * @param array $data
  2073. * @return array
  2074. */
  2075. public function saveWebsiteTemplate(array $data): array
  2076. {
  2077. // return Result::success($data);
  2078. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2079. if (empty($website_template_info) || empty($website_template_info->template_id) || empty($website_template_info->page_type)) {
  2080. return Result::error('请先填写网站基础信息!');
  2081. }
  2082. // 0:未构建 1:未应用 2:已应用 status
  2083. if ($website_template_info['status'] == 2) {
  2084. return Result::error('网站已应用,不可再次保存!');
  2085. }
  2086. if ($website_template_info['action_id'] != 2) {
  2087. return Result::error('请完成之前的步骤!');
  2088. }
  2089. $template_info = WebsiteTemplate::where('website_id', $data['website_id'])->first();
  2090. // var_dump($data['template_data']);
  2091. try {
  2092. Db::beginTransaction();
  2093. if (empty($template_info)) {
  2094. Db::rollback();
  2095. return Result::error('该网站不存在已保存的模版!');
  2096. } else {
  2097. $template = WebsiteTemplate::where('website_id', $data['website_id'])->update(
  2098. [
  2099. 'template_data' => $data['template_data'],
  2100. 'user_id' => $data['user_id'],
  2101. 'canvas_data' => $data['canvas_data'],
  2102. ]
  2103. );
  2104. }
  2105. if (empty($template)) {
  2106. Db::rollback();
  2107. return Result::error('保存失败!');
  2108. } else {
  2109. $tempalte_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['status' => 1]);
  2110. if (empty($tempalte_info)) {
  2111. Db::rollback();
  2112. return Result::error('网站搭建状态保存失败!');
  2113. }
  2114. Db::commit();
  2115. }
  2116. } catch (\Exception $e) {
  2117. return Result::error('模版数据格式错误!');
  2118. }
  2119. return Result::success($template);
  2120. }
  2121. /**
  2122. * 自助建站---流程---6.返显保存的模版
  2123. * @param array $data
  2124. * @return array
  2125. */
  2126. public function getWebsiteTemplate(array $data): array
  2127. {
  2128. $web = Website::where('id', $data['website_id'])->first();
  2129. if (empty($web)) {
  2130. return Result::error('未查询到网站信息!');
  2131. }
  2132. $template = WebsiteTemplate::where('website_id', $data['website_id'])
  2133. ->first(['website_id', 'template_id', 'page_type', 'template_data', 'canvas_data']);
  2134. if (empty($template)) {
  2135. return Result::error('未查询到模版!');
  2136. }
  2137. $template['page_type'] = json_decode($template['page_type'],true);
  2138. return Result::success($template);
  2139. }
  2140. /**
  2141. * 通栏版式管理-获取通栏版式列表
  2142. */
  2143. public function getSectorPlaceList(array $data): array
  2144. {
  2145. $where['sector_place.type_id'] = $data['type_id'];
  2146. if(isset($data['component_num']) && !empty($data['component_num'])){
  2147. $where['sector_place.component_num'] = $data['component_num'];
  2148. }
  2149. if(isset($data['sector_type']) && !empty($data['sector_type'])){
  2150. $where['sector_place.sector_type'] = $data['sector_type'];
  2151. }
  2152. // if(isset($data['component_type']) && !empty($data['component_type'])){
  2153. // $where['sector_place.component_type'] = $data['component_type'];
  2154. // }
  2155. if(isset($data['name']) && !empty($data['name'])){
  2156. array_push($where,['sector_place.name', 'like', '%'.$data['name'].'%']);
  2157. }
  2158. if (isset($data['width']) && !empty($data['width']) && isset($data['height']) && !empty($data['height'])){
  2159. array_push($where,['sector_place.width','like','%'.$data['width'].'%']);
  2160. array_push($where,['sector_place.height','like','%'.$data['height'].'%']);
  2161. } else if( isset($data['width']) && !empty($data['width'])){
  2162. array_push($where,['sector_place.width','like','%'.$data['width'].'%']);
  2163. }else if( isset($data['height']) && !empty($data['height'])){
  2164. array_push($where,['sector_place.height','like','%'.$data['height'].'%']);
  2165. }else{
  2166. $size_id = [];
  2167. }
  2168. $sector_place = SectorPlace::where($where)
  2169. // ->when(!empty($size_id), function ($query) use ($size_id) {
  2170. // $query->whereIn('sector_place.size_id', $size_id);
  2171. // })
  2172. // ->leftJoin('size','sector_place.size_id','=','size.id')
  2173. ->select('sector_place.*');
  2174. $result['count'] = $sector_place->count();
  2175. $result['row'] =$sector_place->paginate($data['page_size'], ['*'], 'page', $data['page']);
  2176. if(empty($result['count'])){
  2177. return Result::error("暂无相关版式数据!");
  2178. }
  2179. return Result::success($result);
  2180. }
  2181. /**
  2182. * 通栏版式管理-添加通栏版式
  2183. */
  2184. public function addSectorPlace(array $data): array
  2185. {
  2186. // 1:通栏;2:组件;
  2187. if($data['type_id'] == 1){
  2188. $sector_place = SectorPlace::where('sector_type', $data['type'])->first();
  2189. if(!empty($sector_place)){
  2190. return Result::error('通栏版式类别编号已存在!');
  2191. }
  2192. $data = [
  2193. 'name' => $data['name'],
  2194. 'component_num' => $data['component_num'],
  2195. 'size_id' => $data['size_id'],
  2196. 'sort_id' => 0,
  2197. 'sector_img' => $data['sector_img'],
  2198. 'sector_type' => $data['type'],
  2199. 'type_id' => $data['type_id'],
  2200. 'status' => 0,
  2201. ];
  2202. }else{
  2203. $sector_type = SectorPlace::where('sector_type', $data['sector_type'])->where('type_id',1)->first();
  2204. if(empty($sector_type)){
  2205. return Result::error('通栏版式类别不存在!');
  2206. }
  2207. // $com_query = SectorPlace::where('type_id',2);
  2208. // ->query(function($query) use ($data){
  2209. // $query->where('component_type', $data['type'])
  2210. // ->Subquery(function($subQuery) use ($data) {
  2211. // $subQuery->where('sector_type', $data['sector_type'])
  2212. // ->where('sort_id', $data['sort']);
  2213. // });
  2214. // }) //若是组件版式编号或者组件版式位置重复用此语句筛选
  2215. // ->where('sector_type',$data['sector_type']) //若是组件版式编号在同一个通栏版式下不重复就行,则启用此语句
  2216. $component = SectorPlace::where('type_id',2)->where('component_type',$data['type'])->first();
  2217. if(!empty($component)){
  2218. return Result::error('组件版式类别编号已存在!');
  2219. }
  2220. // $com_query = clone $com_query;
  2221. $com_num = SectorPlace::where('type_id',2)->where('sector_type',$data['sector_type'])->count('sort_id');
  2222. // return Result::success($com_num);
  2223. if($sector_type['component_num'] = $com_num){
  2224. $sector = SectorPlace::where('sector_type',$data['sector_type'])->where('type_id',1)->update(['status'=>1]);
  2225. if(empty($sector)){
  2226. return Result::error('通栏版式状态修改失败!');
  2227. }
  2228. }
  2229. $data = [
  2230. 'name' => $data['name'],
  2231. 'component_num' => 0,
  2232. 'size_id' => $data['size_id'],
  2233. 'sort_id' => $data['sort_id'],
  2234. 'sector_img' => $data['sector_img'],
  2235. 'component_type' => $data['type'],
  2236. 'type_id' => $data['type_id'],
  2237. 'sector_type' => $data['sector_type'],
  2238. ];
  2239. }
  2240. $result = SectorPlace::insertGetId($data);
  2241. if(empty($result)){
  2242. return Result::error('添加失败!');
  2243. }
  2244. return Result::success('添加成功!',$result);
  2245. }
  2246. /**
  2247. * 通栏版式管理-修改通栏版式
  2248. */
  2249. public function upSectorPlace(array $data): array
  2250. {
  2251. $id = $data['id'];
  2252. // 1:通栏;2:组件;
  2253. if($data['type_id'] == 1){
  2254. $sector_place = SectorPlace::where('id','!=',$id)->where('sector_type', $data['type'])->where('type_id',1)->first();
  2255. if(!empty($sector_place)){
  2256. return Result::error('通栏版式类别编号已存在!');
  2257. }
  2258. $data = [
  2259. 'name' => $data['name'],
  2260. 'component_num' => $data['component_num'],
  2261. 'size_id' => $data['size_id'],
  2262. 'sort_id' => 0,
  2263. 'sector_img' => $data['sector_img'],
  2264. 'sector_type' => $data['type'],
  2265. 'type_id' => $data['type_id'],
  2266. ];
  2267. }else{
  2268. $sector_type = SectorPlace::where('sector_type', $data['sector_type'])->where('type_id',1)->first();
  2269. if(empty($sector_type)){
  2270. return Result::error('通栏版式类别不存在!');
  2271. }
  2272. $component = SectorPlace::where('id','!=',$id)
  2273. ->where('component_type', $data['type'])
  2274. ->where('type_id',2)
  2275. ->first();
  2276. if(!empty($component)){
  2277. return Result::error('组件版式类别编号已存在!');
  2278. }
  2279. $data = [
  2280. 'name' => $data['name'],
  2281. 'component_num' => 0,
  2282. 'size_id' => $data['size_id'],
  2283. 'sort_id' => $data['sort_id'],
  2284. 'sector_img' => $data['sector_img'],
  2285. 'component_type' => $data['type'],
  2286. 'type_id' => $data['type_id'],
  2287. 'sector_type' => $data['sector_type'],
  2288. ];
  2289. }
  2290. $result = SectorPlace::where('id',$id)->update($data);
  2291. if(empty($result)){
  2292. return Result::error('修改失败!');
  2293. }
  2294. return Result::success('修改成功!',$result);
  2295. }
  2296. /**
  2297. * 通栏版式管理-删除通栏版式
  2298. */
  2299. public function delSectorPlace(array $data): array
  2300. {
  2301. $sector_place = SectorPlace::where('id',$data['id'])->first();
  2302. if(empty($sector_place)){
  2303. return Result::error('通栏版式不存在!');
  2304. }
  2305. if($sector_place['type_id'] == 1){
  2306. $sector = Sector::where('place_type', $sector_place['sector_type'])->first();
  2307. $component = SectorPlace::where('sector_type', $sector_place['sector_type'])
  2308. ->where('type_id',2)
  2309. ->first();
  2310. if(!empty($sector) || !empty($component)){
  2311. return Result::error('通栏版式分类已应用,暂不可删除!');
  2312. }
  2313. }else{
  2314. $sector = Component::where('place_type', $sector_place['component_type'])->first();
  2315. if(!empty($sector)){
  2316. return Result::error('组件版式分类已应用,暂不可删除!');
  2317. }
  2318. $component_num = SectorPlace::where('sector_type', $sector_place['sector_type'])
  2319. ->where('type_id',1)->update(['status'=> 0]);
  2320. if(empty($component_num)){
  2321. return Result::error('通栏版式状态修改失败!');
  2322. }
  2323. }
  2324. $result = SectorPlace::where('id',$data['id'])->delete();
  2325. if(empty($result)){
  2326. return Result::error('删除失败!');
  2327. }
  2328. return Result::success('删除成功!');
  2329. }
  2330. /**
  2331. * 自助建站-通栏版式管理-获取通栏版式详情
  2332. */
  2333. public function getSectorPlaceInfo(array $data): array
  2334. {
  2335. $result = SectorPlace::where('sector_place.id',$data['id'])
  2336. ->leftJoin('size','sector_place.size_id','=','size.id')
  2337. ->select('sector_place.*','size.width','size.height')
  2338. ->first();
  2339. if(empty($result)){
  2340. return Result::error('通栏版式不存在!');
  2341. }
  2342. return Result::success($result);
  2343. }
  2344. /**
  2345. * 自助建站-通栏版式管理-获取通栏版式列表
  2346. */
  2347. public function getSectorPlaceSort(array $data): array
  2348. {
  2349. $sector = SectorPlace::where('sector_type',$data['sector_type'])->first();
  2350. if(empty($sector)){
  2351. return Result::error('通栏版式不存在!');
  2352. }
  2353. $component = SectorPlace::where('type_id',2)->where('sector_type',$sector['sector_type'])->pluck('sort_id')->toArray();
  2354. if(count($component) < $sector['component_num']){
  2355. // 根据 $sector['component_num'] 的值生成对应元素数量的数组
  2356. if (isset($sector['component_num']) && is_numeric($sector['component_num'])) {
  2357. $num = intval($sector['component_num']);
  2358. if ($num > 0 && $num <= 10) {
  2359. // 使用 range 函数生成一个从 1 到 $num 的连续整数数组,存储到 $sector_arr 中
  2360. $sector_arr = range(1, $num);
  2361. } else {
  2362. $sector_arr = [];
  2363. }
  2364. } else {
  2365. $sector_arr = [];
  2366. }
  2367. // 获取 $sector_arr 中不在 $component 里的元素
  2368. $sort = array_diff($sector_arr, $component);
  2369. // return Result::success($sort);
  2370. }
  2371. if(!empty($sort)){
  2372. $sort = array_values(array_map(function($value) {
  2373. return ['id' => $value];
  2374. }, $sort));
  2375. }else{
  2376. return Result::error("组件版式数量已达上限!");
  2377. }
  2378. return Result::success($sort);
  2379. }
  2380. /**
  2381. * 获取所有通栏版式
  2382. */
  2383. public function getAllSectorPlace(array $data): array
  2384. {
  2385. $where['type_id'] = $data['type_id'];
  2386. // if($data['type_id'] == 1){
  2387. // $where['status'] = 1;
  2388. // }
  2389. if(isset($data['sector_type']) && !empty($data['sector_type'])){
  2390. $where['sector_type'] = $data['sector_type'];
  2391. }
  2392. if(isset($data['component_num']) && !empty($data['component_num'])){
  2393. $where['component_num'] = $data['component_num'];
  2394. }
  2395. $sector_place = SectorPlace::where($where)
  2396. ->when($data['type_id'] == 2, function($query) use($data){
  2397. $query->orderBy('sort_id','asc');
  2398. })
  2399. ->get()->all();
  2400. if($data['type_id'] == 2){
  2401. foreach($sector_place as $key => $value){
  2402. $sector_place[$key]['component'] = Component::where('type_id',$value['type'])
  2403. ->where('component_width',$value['width'])
  2404. ->where('component_height',$value['height'])
  2405. ->get()->all();
  2406. }
  2407. }
  2408. if(empty($sector_place)){
  2409. return Result::error('通栏版式不存在!');
  2410. }
  2411. return Result::success($sector_place);
  2412. }
  2413. /**
  2414. * 组件管理-获取组件类型
  2415. */
  2416. public function getComponentType(array $data): array
  2417. {
  2418. $where = [];
  2419. if(isset($data['id']) && !empty($data['id'])){
  2420. $where['id'] = $data['id'];
  2421. }
  2422. $component_type = ComponentType::where($where)->get()->all();
  2423. if(empty($component_type)){
  2424. return Result::error('组件类型不存在!');
  2425. }
  2426. if(count($component_type) == 1){
  2427. $all_code = json_decode($component_type[0]['com_code'] ?? '',true);
  2428. $component_type[0]['all_code'] = $all_code['listType'] ?? [];
  2429. $result = $component_type[0];
  2430. }else{
  2431. $result = $component_type;
  2432. }
  2433. if(empty($component_type)){
  2434. return Result::error('组件类型不存在!');
  2435. }
  2436. return Result::success($component_type);
  2437. }
  2438. /**
  2439. * 组件管理-获取所有组件
  2440. */
  2441. public function getAllComponent(array $data): array
  2442. {
  2443. $where = [];
  2444. if((isset($data['sector_id']) && !empty($data['sector_id'])) || (isset($data['sort_id']) && !empty($data['sort_id']))){
  2445. $sector['sector_component.sector_id'] = $data['sector_id'];
  2446. $sector['sector_component.sort_id'] = $data['sort_id'];
  2447. $where = SectorComponent::where($sector)->pluck('component_id')->toArray();
  2448. $component = Component::whereIn('component_type',$where)->get()->all();
  2449. }else{
  2450. if(isset($data['type_id']) && !empty($data['type_id'])){
  2451. $where['component.type_id'] = $data['type_id'];
  2452. }
  2453. if(isset($data['width']) && !empty($data['width'])){
  2454. $where['component.component_width'] = $data['width'];
  2455. }
  2456. if(isset($data['height']) && !empty($data['height'])){
  2457. $where['component.component_height'] = $data['height'];
  2458. }
  2459. $component = Component::where($where)
  2460. // ->leftJoin('size','component.size_id','=','size.id')
  2461. // ->select('component.*','size.width','size.height')
  2462. ->get()->all();
  2463. }
  2464. if(empty($component)){
  2465. return Result::error('组件不存在!');
  2466. }
  2467. return Result::success($component);
  2468. }
  2469. /**
  2470. * 自助建站-流程管理-获取所有通栏
  2471. */
  2472. public function getAllSector(array $data): array
  2473. {
  2474. $where = [];
  2475. if(isset($data['template_id']) && !empty($data['template_id'])){
  2476. $where['template_id'] = $data['template_id'];
  2477. }
  2478. if(isset($data['page_type']) && !empty($data['page_type'])){
  2479. array_push($where,['page_type', 'like', '%'.$data['page_type'].'%']);
  2480. }
  2481. $sector = Sector::where($where)
  2482. // ->leftJoin('size','sector.size_id','=','size.id')
  2483. ->select('sector.*')
  2484. ->get()->all();
  2485. if(empty($sector)){
  2486. return Result::error('通栏不存在!');
  2487. }
  2488. return Result::success($sector);
  2489. }
  2490. /**
  2491. * 自助建站-组件管理-获取组件预览图列表
  2492. */
  2493. public function getComponentImgList(array $data): array
  2494. {
  2495. $where['component_img.component_id'] = $data['component_id'];
  2496. if(isset($data['template_id']) && !empty($data['template_id'])){
  2497. $where['component_img.template_id'] = $data['template_id'];
  2498. }
  2499. $component_img = ComponentImg::where($where)
  2500. ->leftJoin('template','component_img.template_id','=','template.template_id')
  2501. ->leftJoin('component','component_img.component_id','=','component.component_type')
  2502. ->select('component_img.*','template.template_name','component.component_name')
  2503. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  2504. if(empty($component_img)){
  2505. return Result::error('组件预览图不存在!');
  2506. }
  2507. return Result::success($component_img);
  2508. }
  2509. /**
  2510. * 自助建站-组件管理-添加组件预览图
  2511. */
  2512. public function addComponentImg(array $data): array
  2513. {
  2514. unset($data['user_id']);
  2515. $img = ComponentImg::where('component_id',$data['component_id'])->where('template_id',$data['template_id'])->get()->all();
  2516. if(!empty($img)){
  2517. return Result::error('该组件已存在此皮肤的预览图!');
  2518. }
  2519. $component_img = ComponentImg::insertGetId($data);
  2520. if(empty($component_img)){
  2521. return Result::error('添加失败!');
  2522. }
  2523. return Result::success($component_img);
  2524. }
  2525. /**
  2526. * 自助建站-组件管理-删除组件预览图
  2527. */
  2528. public function delComponentImg(array $data): array
  2529. {
  2530. $component_img = ComponentImg::where('id',$data['id'])->delete();
  2531. if(empty($component_img)){
  2532. return Result::error('删除失败!');
  2533. }
  2534. return Result::success($component_img);
  2535. }
  2536. /**
  2537. * 自助建站-组件管理-更新组件预览图
  2538. */
  2539. public function updateComponentImg(array $data): array
  2540. {
  2541. $img = ComponentImg::where('id','!=',$data['id'])->where('component_id',$data['component_id'])->where('template_id',$data['template_id'])->get()->all();
  2542. if(!empty($img)){
  2543. return Result::error('该组件已存在此皮肤的预览图!');
  2544. }
  2545. unset($data['user_id']);
  2546. // unset($data['updated_at']);
  2547. $id = $data['id'];
  2548. unset($data['id']);
  2549. // return Result::success($data);
  2550. $component_img = ComponentImg::where('id',$id)->update($data);
  2551. if(empty($component_img)){
  2552. return Result::error('更新失败!');
  2553. }
  2554. return Result::success($component_img);
  2555. }
  2556. }