Pub.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\BaseController;
  4. use app\model\api\Warehouse;
  5. use app\model\api\SystemCity;
  6. use app\model\system\Sys;
  7. use app\Request;
  8. use library\services\UtilService;
  9. use library\services\CacheService;
  10. class Pub extends BaseController
  11. {
  12. /**
  13. * 站点信息
  14. */
  15. public function siteResouce() {
  16. $info = Sys::where("id", 1)->find()->toArray();
  17. return app('json')->success($info);
  18. }
  19. /**
  20. * 获取图片base64
  21. * @param Request $request
  22. * @return mixed
  23. * @throws Exception
  24. */
  25. public function get_image_base64(Request $request)
  26. {
  27. list($imageUrl, $codeUrl) = UtilService::getMore([
  28. ['image', ''],
  29. ['code', ''],
  30. ], $request, true);
  31. try {
  32. $codeTmp = $code = $codeUrl ? image_to_base64($codeUrl) : false;
  33. if (!$codeTmp) {
  34. $putCodeUrl = put_image($codeUrl);
  35. $code = $putCodeUrl ? image_to_base64($_SERVER['HTTP_HOST'] . '/' . $putCodeUrl) : false;
  36. $code ?? unlink($_SERVER["DOCUMENT_ROOT"] . '/' . $putCodeUrl);
  37. }
  38. $imageTmp = $image = $imageUrl ? image_to_base64($imageUrl) : false;
  39. if (!$imageTmp) {
  40. $putImageUrl = put_image($imageUrl);
  41. $image = $putImageUrl ? image_to_base64($_SERVER['HTTP_HOST'] . '/' . $putImageUrl) : false;
  42. $image ?? unlink($_SERVER["DOCUMENT_ROOT"] . '/' . $putImageUrl);
  43. }
  44. return app('json')->successful(compact('code', 'image'));
  45. } catch (Exception $e) {
  46. return app('json')->fail($e->getMessage());
  47. }
  48. }
  49. /**
  50. * 获取仓库列表
  51. * @param Request $request
  52. */
  53. public function warehouse(Request $request) {
  54. [$isExp] = UtilService::getMore([
  55. ['isExp',''],
  56. ],$request,true);
  57. $warehouse = new Warehouse;
  58. $data = $warehouse->field("name,id,platform_ids")
  59. ->where("status",1)
  60. ->order("seq","desc")
  61. ->select()
  62. ->toArray();
  63. $platform = (new \app\model\system\Platform());
  64. foreach ($data as $k => $v) {
  65. $idsAr = explode(',',$v['platform_ids']);
  66. $platformAr = [];
  67. $data[$k]['platform'] = array_map(
  68. function ($item) use($platform){
  69. return $platform->getPlatformId($item,'*');
  70. },$idsAr);
  71. }
  72. return app('json')->success($data);
  73. }
  74. /**
  75. * 查找城市数据
  76. * @param Request $request
  77. * @return mixed
  78. * @throws \throwable
  79. */
  80. public function city_list(Request $request)
  81. {
  82. $list = CacheService::get('CITY_LIST', function () {
  83. $list = SystemCity::with('children')->field(['city_id', 'name', 'id', 'parent_id'])->where('parent_id', 0)->order('id asc')->select()->toArray();
  84. $data = [];
  85. foreach ($list as &$item) {
  86. $value = ['v' => $item['city_id'], 'n' => $item['name']];
  87. if ($item['children']) {
  88. foreach ($item['children'] as $key => &$child) {
  89. $value['c'][$key] = ['v' => $child['city_id'], 'n' => $child['name']];
  90. unset($child['id'], $child['area_code'], $child['merger_name'], $child['is_show'], $child['level'], $child['lng'], $child['lat'], $child['lat']);
  91. if (SystemCity::where('parent_id', $child['city_id'])->count()) {
  92. $child['children'] = SystemCity::where('parent_id', $child['city_id'])->field(['city_id', 'name', 'id', 'parent_id'])->select()->toArray();
  93. foreach ($child['children'] as $kk => $vv) {
  94. $value['c'][$key]['c'][$kk] = ['v' => $vv['city_id'], 'n' => $vv['name']];
  95. }
  96. }
  97. }
  98. }
  99. $data[] = $value;
  100. }
  101. return $data;
  102. }, 0);
  103. return app('json')->successful($list);
  104. }
  105. }