From 429835252b5af41fba83a877d906b5784de53970 Mon Sep 17 00:00:00 2001 From: denghy Date: Tue, 9 Apr 2019 17:40:00 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B5=E8=AF=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Real/Commands/Sync/AddedOrderSync.php | 6 ++- .../Real/Commands/Sync/OrderBaseSync.php | 7 +++- app/helpers.php | 37 +++++++++++++++++++ ...4_164434_create_real_order_cards_table.php | 10 ++--- tests/ExampleTest.php | 2 - 5 files changed, 51 insertions(+), 11 deletions(-) diff --git a/app/Domains/Real/Commands/Sync/AddedOrderSync.php b/app/Domains/Real/Commands/Sync/AddedOrderSync.php index b3ea4be7..9e8029b3 100644 --- a/app/Domains/Real/Commands/Sync/AddedOrderSync.php +++ b/app/Domains/Real/Commands/Sync/AddedOrderSync.php @@ -88,7 +88,7 @@ class AddedOrderSync extends Command $starttime = $this->datetime->copy()->startOfMonth()->startOfDay(); $endtime = $this->datetime->copy()->endOfMonth()->endOfDay(); - $orders = DB::table($virtualTable)->selectRaw('sim,MAX(order_id)') + $orders = DB::table($virtualTable)->selectRaw('sim, MAX(order_id)') ->where('created_at', '>=', $starttime->format('Y-m-d H:i:s')) ->where('created_at', '<=', $endtime->format('Y-m-d H:i:s')) ->whereIn('sim', array_pluck($data, 'sim')) @@ -101,7 +101,9 @@ class AddedOrderSync extends Command MongoCardJob::dispatch(array_pluck($data, 'sim')); - DB::table($table)->upsert($data, ['sim', 'order_id']); + $only = ['company_id', 'package_id', 'counts', 'unit_price']; + + DB::table($table)->upsert($data, ['sim', 'order_id', 'deleted_at'], $only); } } diff --git a/app/Domains/Real/Commands/Sync/OrderBaseSync.php b/app/Domains/Real/Commands/Sync/OrderBaseSync.php index 5a53ca0c..635ee6a5 100644 --- a/app/Domains/Real/Commands/Sync/OrderBaseSync.php +++ b/app/Domains/Real/Commands/Sync/OrderBaseSync.php @@ -56,8 +56,11 @@ class OrderBaseSync extends Command MongoCardJob::dispatch(array_pluck($data, 'sim')); - DB::table('real_order_cards')->upsert($data, ['sim', 'deleted_at']); + $only = [ 'order_id', 'company_id', 'package_id', 'counts', 'unit_price']; + + DB::table('real_order_cards')->upsert($data, ['sim', 'deleted_at'], $only); } + app(OrderCardPartitionRepository::class)->forgetCached(); $this->line('插入订单关联数据成功'); }); @@ -122,7 +125,7 @@ class OrderBaseSync extends Command 'order_at' => Carbon::parse($item['o_create_date'])->format('Y-m-d H:i:s'), 'address' => $item['o_address'], 'contacts' => $item['o_contacts'], - 'mobile' => $item['o_contact_number'], + 'mobile' => substr(preg_replace('/[^0-9]+/', '', single_case($item['o_contact_number'])), 0, 11), 'remark' => $item['o_remark'], 'logistics_remark' => $item['o_logistics_content'], 'created_at' => date('Y-m-d H:i:s', $item['o_create_time']), diff --git a/app/helpers.php b/app/helpers.php index c06d35b5..d9e3c6d2 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -244,3 +244,40 @@ if (! function_exists('range_compare')) { return -1; } } + +if (! function_exists('single_case')) { + /** + * 将一个字串中含有全角的数字字符、字母、空格或'%+-()'字符转换为相应半角字符 + * + * @access public + * @param string $str 待转换字串 + * @return string + */ + function single_case($str) + { + $arr = array('0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4', + '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', + 'A' => 'A', 'B' => 'B', 'C' => 'C', 'D' => 'D', 'E' => 'E', + 'F' => 'F', 'G' => 'G', 'H' => 'H', 'I' => 'I', 'J' => 'J', + 'K' => 'K', 'L' => 'L', 'M' => 'M', 'N' => 'N', 'O' => 'O', + 'P' => 'P', 'Q' => 'Q', 'R' => 'R', 'S' => 'S', 'T' => 'T', + 'U' => 'U', 'V' => 'V', 'W' => 'W', 'X' => 'X', 'Y' => 'Y', + 'Z' => 'Z', 'a' => 'a', 'b' => 'b', 'c' => 'c', 'd' => 'd', + 'e' => 'e', 'f' => 'f', 'g' => 'g', 'h' => 'h', 'i' => 'i', + 'j' => 'j', 'k' => 'k', 'l' => 'l', 'm' => 'm', 'n' => 'n', + 'o' => 'o', 'p' => 'p', 'q' => 'q', 'r' => 'r', 's' => 's', + 't' => 't', 'u' => 'u', 'v' => 'v', 'w' => 'w', 'x' => 'x', + 'y' => 'y', 'z' => 'z', + '(' => '(', ')' => ')', '〔' => '[', '〕' => ']', '【' => '[', + '】' => ']', '〖' => '[', '〗' => ']', '“' => '[', '”' => ']', + '‘' => '[', '’' => ']', '{' => '{', '}' => '}', '《' => '<', + '》' => '>', + '%' => '%', '+' => '+', '—' => '-', '-' => '-', '~' => '-', + ':' => ':', '。' => '.', '、' => ',', ',' => '.', '、' => '.', + ';' => ',', '?' => '?', '!' => '!', '…' => '-', '‖' => '|', + '”' => '"', '’' => '`', '‘' => '`', '|' => '|', '〃' => '"', + ' ' => ' '); + + return strtr($str, $arr); + } +} diff --git a/database/migrations/2018_12_24_164434_create_real_order_cards_table.php b/database/migrations/2018_12_24_164434_create_real_order_cards_table.php index 12556436..a90aef55 100644 --- a/database/migrations/2018_12_24_164434_create_real_order_cards_table.php +++ b/database/migrations/2018_12_24_164434_create_real_order_cards_table.php @@ -48,23 +48,23 @@ class CreateRealOrderCardsTable extends Migration }); Schema::table('real_order_renewal_cards', function (Blueprint $table) { - $table->unique(['sim', 'order_id']); + $table->unique(['sim', 'order_id', 'deleted_at']); }); Schema::table('real_order_renewal_package_cards', function (Blueprint $table) { - $table->unique(['sim', 'order_id']); + $table->unique(['sim', 'order_id', 'deleted_at']); }); Schema::table('real_order_flows_package_cards', function (Blueprint $table) { - $table->unique(['sim', 'order_id']); + $table->unique(['sim', 'order_id', 'deleted_at']); }); Schema::table('real_order_optional_package_cards', function (Blueprint $table) { - $table->unique(['sim', 'order_id']); + $table->unique(['sim', 'order_id', 'deleted_at']); }); Schema::table('real_order_additional_package_cards', function (Blueprint $table) { - $table->unique(['sim', 'order_id']); + $table->unique(['sim', 'order_id', 'deleted_at']); }); } diff --git a/tests/ExampleTest.php b/tests/ExampleTest.php index 40781235..d2a2c73e 100644 --- a/tests/ExampleTest.php +++ b/tests/ExampleTest.php @@ -7,5 +7,3 @@ use Illuminate\Database\Schema\Blueprint; use App\Domains\Virtual\Services\OrderService; require_once realpath(dirname(__FILE__) . '/TestCase.php'); - -app(OrderService::class);