1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- /**
- * ${CARET}
- * @file:CpService.php
- * @Created by gnitif
- * @Date: 2023/3/21
- * @Time: 20:24
- */
- namespace Modules\ContentManage\Services\CpManage;
- use GuzzleHttp\Client;
- use Illuminate\Contracts\Pagination\LengthAwarePaginator;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- use Modules\ContentManage\Models\Book;
- use Modules\ContentManage\Models\Cp\Cps;
- use function Symfony\Component\Translation\t;
- class CpService
- {
- public static function reportCpUser($user)
- {
- $params = [
- 'username' => $user['cp_name'],
- 'is_enabled' => 1,
- 'is_show_total_amount' => $user['is_show_total_amount'] ?? 0,
- 'is_union_sign' => $user['is_union_sign'] ?? 0,
- 'timestamp' => time(),
- ];
- $params['sign'] = self::getSign($params['timestamp']);
- $url = config('contentManage.zhushuyunpublicapi.public_domain', 'https://pubapi.zhuishuyun.com') . '/inapi/cpUers/createUser';
- $client = new Client(['base_uri' => $url,'timeout' => 2]);
- $response = $client->request('post','',['query' => $params]);
- $result = $response->getBody()->getContents();
- $result = json_decode($result, true);
- if (!isset($result['code']) || $result['code'] != 0) {
- Log::error("cp创建用户接口请求异常,请求结果为:" . var_export($result, true));
- throw new \Exception("cp创建用户接口请求异常");
- }
- return true;
- }
- private static function getSign(mixed $timestamp)
- {
- $key = config('contentManage.zhushuyunpublicapi.external_private_key', 'ZSY_2021!KEY');
- $string = md5($timestamp . $key) . $key;
- return md5($string);
- }
- public static function selectOptions($cpName = "")
- {
- $list = Cps::select('cp_id','cp_name','cp_nick','cp_company');
- if (!empty($cpName)){
- $list->where('cp_name','like',"%{$cpName}%");
- }
- return $list->get();
- }
- /**
- * 查询产品列表
- * name: getCpList
- * @param $where
- * @param int $pageSize
- * @return LengthAwarePaginator
- * date 2023/03/22 20:49
- */
- public static function getCpList($where , int $pageSize = 20)
- {
- $list = DB::table('cps')->where($where)->orderBy('cp_id','desc')->paginate($pageSize);
- if(!$list->isEmpty()){
- foreach ($list as $value){
- $value->book_count = Book::where('cp_id', $value->cp_id)->count();
- }
- }
- return $list;
- }
- }
|