作者 赵彬吉

update

@@ -7,7 +7,10 @@ @@ -7,7 +7,10 @@
7 */ 7 */
8 namespace App\Models\Inquiry; 8 namespace App\Models\Inquiry;
9 9
  10 +use App\Helper\Translate;
10 use Illuminate\Database\Eloquent\Model; 11 use Illuminate\Database\Eloquent\Model;
  12 +use Illuminate\Support\Facades\Cache;
  13 +use Illuminate\Support\Facades\DB;
11 14
12 /** 15 /**
13 * 广告询盘表单内容 16 * 广告询盘表单内容
@@ -62,6 +65,10 @@ class ReInquiryForm extends Model @@ -62,6 +65,10 @@ class ReInquiryForm extends Model
62 */ 65 */
63 public static function createInquiry($id, $origin_id, $ad_set_id, $ad_set_name, $ad_id, $ad_name, $full_name, $email, $phone, $whatsapp, $message, $country, $inquiry_date) 66 public static function createInquiry($id, $origin_id, $ad_set_id, $ad_set_name, $ad_id, $ad_name, $full_name, $email, $phone, $whatsapp, $message, $country, $inquiry_date)
64 { 67 {
  68 + if($country){
  69 + $country_name = self::getCountryName($country);
  70 + }
  71 +
65 $self = self::where(['id' => $id])->first(); 72 $self = self::where(['id' => $id])->first();
66 if (empty($self)) { 73 if (empty($self)) {
67 $self = new self(); 74 $self = new self();
@@ -80,8 +87,29 @@ class ReInquiryForm extends Model @@ -80,8 +87,29 @@ class ReInquiryForm extends Model
80 $self->message = $message; 87 $self->message = $message;
81 $self->inquiry_date = $inquiry_date; 88 $self->inquiry_date = $inquiry_date;
82 $self->country = $country; 89 $self->country = $country;
  90 + $self->country_name = $country_name??'';
83 $self->save(); 91 $self->save();
84 return $self; 92 return $self;
85 } 93 }
86 94
87 -}  
  95 +
  96 + public static function getCountryName($country){
  97 + if (strlen($country) == 2) {
  98 + $country = self::getCountry($country);
  99 + } else {
  100 + $country = Translate::tran($country, 'zh');
  101 + }
  102 + return $country;
  103 + }
  104 +
  105 + public static function getCountry($code)
  106 + {
  107 + $cache_key = 'inquiry_world_country';
  108 + $country_code = Cache::get($cache_key, function () use ($cache_key) {
  109 + $country_code = DB::table('gl_world_country_city')->where(['pid' => 0])->pluck('chinese_name', 'iso2')->toArray();
  110 + Cache::put($cache_key, $country_code, 86400);
  111 + return $country_code;
  112 + });
  113 + return empty($country_code[$code]) ? '' : $country_code[$code];
  114 + }
  115 +}