123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <?php
- namespace App\Distributor\Controllers;
- use App\Distributor\Repositories\DistProduct;
- use App\Distributor\Repositories\DistProductCategory;
- use App\Distributor\Repositories\DistVideo;
- use App\Distributor\Repositories\DistVideoCategory;
- use App\Distributor\Repositories\SitePages;
- use App\Distributor\Repositories\SitePagesTag;
- use App\Distributor\Repositories\SmmPostLog;
- use App\Distributor\Repositories\SmmUserAccount;
- use Illuminate\Http\Request;
- use Illuminate\Routing\Controller;
- class ApiController extends Controller
- {
- /**
- * 产品下接API,默认返回50个最新的产品
- */
- public function products(Request $request)
- {
- $q = $request->get('q');
- if ($q != null) {
- // 模糊搜索
- $obj = new DistProduct();
- return $obj->model()->where('title', 'like', "%$q%")->where('dist_id', getDistributorId())->where('status', 2)->paginate(null, ['id', 'title as text']);
- } else {
- // 获取最新的N个
- $selectOptionsNew = DistProduct::selectOptionsNew();
- return $this->changeOptions($selectOptionsNew);
- }
- }
- public function pages(Request $request)
- {
- $q = $request->get('q');
- if ($q != null) {
- // 模糊搜索
- $obj = new SitePages();
- return $obj->model()->where('title', 'like', "%$q%")->where('dist_id', getDistributorId())->where('page_type', 0)->paginate(null, ['id', 'title as text']);
- } else {
- // 获取最新的N个
- $selectOptionsNew = SitePages::selectOptionsNew(30,0);
- return $this->changeOptions($selectOptionsNew);
- }
- }
- public function landingPages(Request $request)
- {
- $q = $request->get('q');
- if ($q != null) {
- // 模糊搜索
- $obj = new SitePages();
- return $obj->model()->where('title', 'like', "%$q%")->where('dist_id', getDistributorId())->where('page_type', 1)->paginate(null, ['id', 'title as text']);
- } else {
- // 获取最新的N个
- $selectOptionsNew = SitePages::selectOptionsNew(30,1);
- return $this->changeOptions($selectOptionsNew);
- }
- }
- public function videos(Request $request)
- {
- $q = $request->get('q');
- if ($q != null) {
- // 模糊搜索
- $obj = new DistVideo();
- return $obj->model()->where('title', 'like', "%$q%")->where('dist_id', getDistributorId())->paginate(null, ['id', 'title as text']);
- } else {
- // 获取最新的N个
- $selectOptionsNew = DistVideo::selectOptionsNew(30);
- return $this->changeOptions($selectOptionsNew);
- }
- }
- public function tag(Request $request)
- {
- $q = $request->get('q');
- if ($q != null) {
- // 模糊搜索
- $obj = new SitePagesTag();
- return $obj->model()->where('name', 'like', "%$q%")->where('dist_id', getDistributorId())->paginate(null, ['id', 'name as text']);
- } else {
- // 获取最新的N个
- $selectOptionsNew = SitePagesTag::selectOptionsNew();
- return $this->changeOptions($selectOptionsNew);
- }
- }
- public function generateSlug(Request $request)
- {
- $model = $request->get('model');
- $title = $request->get('title');
- $result = null;
- switch ($model) {
- case 'pages':
- $obj = new SitePages();
- $result = $obj->generateSlug($title);
- break;
- case 'productCategory':
- $obj = new DistProductCategory();
- $result = $obj->generateSlug($title);
- break;
- case 'videoCategory':
- $obj = new DistVideoCategory();
- $result = $obj->generateSlug($title);
- break;
- case 'pagesTag':
- $obj = new SitePagesTag();
- $result = $obj->generateSlug($title);
- break;
- }
- return ['slug' => $result];
- }
- /*
- * 把数据转换成select需要的格式
- */
- private function changeOptions($data) {
- // 初始化结果数组
- $result = [];
- // 遍历原始数据并转换格式
- foreach ($data as $id => $text) {
- $result[] = [
- 'id' => (int)$id, // 将字符串转换为整数
- 'text' => $text
- ];
- }
- return $result;
- }
- /*
- * 得到要发送的日志(社发爬虫工具使用)
- */
- public function ssmGetSendLog(){
- $result = SmmPostLog::getSendLogDist();
- return response()->json(['status' => 1,'data' => $result]);
- }
- /*
- * 更新发送日志状态(社发爬虫工具使用)
- */
- public function ssmUpdateSendLog(Request $request)
- {
- $id = $request->input('id');
- $status = $request->input('status');
- $request_count = $request->input('request_count');
- $remark = $request->input('remark');
- SmmPostLog::updateSendLogDist($id, $status, $request_count, $remark);
- return response()->json(['status' => 1,'msg' => '更新成功']);
- }
- public function ssmSaveAccount(Request $request){
- $mediaName = $request->input('media_name') ? $request->input('media_name') : '';
- $accountId = $request->input('account_id') ? $request->input('account_id') : '';
- $accountName = $request->input('account_name') ? $request->input('account_name') : '';
- $cookieId = $request->input('cookie_id') ? $request->input('cookie_id') : '';
- $cookieData = $request->input('cookie_data') ? $request->input('cookie_data') : '';
- SmmUserAccount::createAccountIfMediaExistsCookie($mediaName, $accountId,$accountName, $cookieId,$cookieData);
- return response()->json(['status' => 1,'msg' => '更新成功']);
- }
- }
|