123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- namespace app\api\controller\v1;
- use app\BaseController;
- use app\model\api\Warehouse;
- use app\model\api\SystemCity;
- use app\model\system\Sys;
- use app\Request;
- use library\services\UtilService;
- use library\services\CacheService;
- class Pub extends BaseController
- {
- /**
- * 站点信息
- */
- public function siteResouce() {
- $info = Sys::where("id", 1)->find()->toArray();
- return app('json')->success($info);
- }
- /**
- * 获取图片base64
- * @param Request $request
- * @return mixed
- * @throws Exception
- */
- public function get_image_base64(Request $request)
- {
- list($imageUrl, $codeUrl) = UtilService::getMore([
- ['image', ''],
- ['code', ''],
- ], $request, true);
- try {
- $codeTmp = $code = $codeUrl ? image_to_base64($codeUrl) : false;
- if (!$codeTmp) {
- $putCodeUrl = put_image($codeUrl);
- $code = $putCodeUrl ? image_to_base64($_SERVER['HTTP_HOST'] . '/' . $putCodeUrl) : false;
- $code ?? unlink($_SERVER["DOCUMENT_ROOT"] . '/' . $putCodeUrl);
- }
- $imageTmp = $image = $imageUrl ? image_to_base64($imageUrl) : false;
- if (!$imageTmp) {
- $putImageUrl = put_image($imageUrl);
- $image = $putImageUrl ? image_to_base64($_SERVER['HTTP_HOST'] . '/' . $putImageUrl) : false;
- $image ?? unlink($_SERVER["DOCUMENT_ROOT"] . '/' . $putImageUrl);
- }
- return app('json')->successful(compact('code', 'image'));
- } catch (Exception $e) {
- return app('json')->fail($e->getMessage());
- }
- }
- /**
- * 获取仓库列表
- * @param Request $request
- */
- public function warehouse(Request $request) {
- [$isExp] = UtilService::getMore([
- ['isExp',''],
- ],$request,true);
- $warehouse = new Warehouse;
- $data = $warehouse->field("name,id,platform_ids")
- ->where("status",1)
- ->order("seq","desc")
- ->select()
- ->toArray();
- $platform = (new \app\model\system\Platform());
- foreach ($data as $k => $v) {
- $idsAr = explode(',',$v['platform_ids']);
- $platformAr = [];
- $data[$k]['platform'] = array_map(
- function ($item) use($platform){
- return $platform->getPlatformId($item,'*');
- },$idsAr);
- }
- return app('json')->success($data);
- }
- /**
- * 查找城市数据
- * @param Request $request
- * @return mixed
- * @throws \throwable
- */
- public function city_list(Request $request)
- {
- $list = CacheService::get('CITY_LIST', function () {
- $list = SystemCity::with('children')->field(['city_id', 'name', 'id', 'parent_id'])->where('parent_id', 0)->order('id asc')->select()->toArray();
- $data = [];
- foreach ($list as &$item) {
- $value = ['v' => $item['city_id'], 'n' => $item['name']];
- if ($item['children']) {
- foreach ($item['children'] as $key => &$child) {
- $value['c'][$key] = ['v' => $child['city_id'], 'n' => $child['name']];
- unset($child['id'], $child['area_code'], $child['merger_name'], $child['is_show'], $child['level'], $child['lng'], $child['lat'], $child['lat']);
- if (SystemCity::where('parent_id', $child['city_id'])->count()) {
- $child['children'] = SystemCity::where('parent_id', $child['city_id'])->field(['city_id', 'name', 'id', 'parent_id'])->select()->toArray();
- foreach ($child['children'] as $kk => $vv) {
- $value['c'][$key]['c'][$kk] = ['v' => $vv['city_id'], 'n' => $vv['name']];
- }
- }
- }
- }
- $data[] = $value;
- }
- return $data;
- }, 0);
- return app('json')->successful($list);
- }
- }
|