Bläddra i källkod

后台客户列表和详情展示 customer source。

Co-authored-by: Cursor <cursoragent@cursor.com>
chengwl 4 dagar sedan
förälder
incheckning
b701c23166

+ 10 - 0
packages/Webkul/Admin/src/DataGrids/Customers/CustomerDataGrid.php

@@ -49,6 +49,7 @@ class CustomerDataGrid extends DataGrid
                 'customers.is_suspended',
                 'customer_groups.name as group',
                 'customers.channel_id',
+                'customers.customer_source',
             )
             ->addSelect(DB::raw('COUNT(DISTINCT '.$tablePrefix.'addresses.id) as address_count'))
             ->addSelect(DB::raw('COUNT(DISTINCT '.$tablePrefix.'orders.id) as order_count'))
@@ -60,6 +61,7 @@ class CustomerDataGrid extends DataGrid
         $this->addFilter('email', 'customers.email');
         $this->addFilter('full_name', DB::raw('CONCAT('.$tablePrefix.'customers.first_name, " ", '.$tablePrefix.'customers.last_name)'));
         $this->addFilter('group', 'customer_groups.name');
+        $this->addFilter('customer_source', 'customers.customer_source');
         $this->addFilter('phone', 'customers.phone');
         $this->addFilter('status', 'customers.status');
 
@@ -153,6 +155,14 @@ class CustomerDataGrid extends DataGrid
             'filterable_options' => $this->customerGroupRepository->all(['name as label', 'name as value'])->toArray(),
         ]);
 
+        $this->addColumn([
+            'index'      => 'customer_source',
+            'label'      => trans('admin::app.customers.customers.index.datagrid.source'),
+            'type'       => 'string',
+            'filterable' => true,
+            'sortable'   => true,
+        ]);
+
         $this->addColumn([
             'index'    => 'is_suspended',
             'label'    => trans('admin::app.customers.customers.index.datagrid.suspended'),

+ 2 - 0
packages/Webkul/Admin/src/Resources/lang/en/app.php

@@ -1826,6 +1826,7 @@ return [
                     'partial-action' => 'Some actions were not performed due restricted system constraints on :resource',
                     'phone'          => 'Contact Number',
                     'revenue'        => 'Revenue',
+                    'source'         => 'Customer Source',
                     'status'         => 'Status',
                     'suspended'      => 'Suspended',
                     'update-status'  => 'Update Status',
@@ -1874,6 +1875,7 @@ return [
                 'order-create-confirmation'   => 'Are you sure you want to create order for this customer?',
                 'phone'                       => 'Phone - :phone',
                 'set-as-default'              => 'Set as Default',
+                'source'                      => 'Source - :source',
                 'suspended'                   => 'Suspended',
                 'title'                       => 'Customer View',
 

+ 2 - 0
packages/Webkul/Admin/src/Resources/lang/zh_CN/app.php

@@ -1706,6 +1706,7 @@ return [
                     'partial-action' => '由于 :resource 上的受限制的系统约束,未执行一些操作',
                     'phone'          => '联系号码',
                     'revenue'        => '收入',
+                    'source'         => '客户来源',
                     'status'         => '状态',
                     'suspended'      => '已暂停',
                     'update-status'  => '更新状态',
@@ -1754,6 +1755,7 @@ return [
                 'order-create-confirmation'   => '您确定要为此客户创建订单吗?',
                 'phone'                       => '电话 - :phone',
                 'set-as-default'              => '设为默认',
+                'source'                      => '来源 - :source',
                 'suspended'                   => '已暂停',
                 'title'                       => '客户视图',
 

+ 5 - 1
packages/Webkul/Admin/src/Resources/views/customers/customers/index.blade.php

@@ -64,7 +64,7 @@
                 <div class="row grid grid-cols-1 md:grid-cols-[2fr_1fr_1fr] grid-rows-1 gap-1 items-center border-b px-4 py-2.5 dark:border-gray-800 min-w-full">
                     <div
                         class="flex select-none items-center gap-2.5"
-                        v-for="(columnGroup, index) in [['full_name', 'email', 'phone'], ['status', 'gender', 'group', 'customer_id'], ['revenue', 'order_count', 'address_count']]"
+                        v-for="(columnGroup, index) in [['full_name', 'email', 'phone'], ['status', 'gender', 'group', 'customer_source', 'customer_id'], ['revenue', 'order_count', 'address_count']]"
                     >
                         @if ($hasPermission)
                             <label
@@ -201,6 +201,10 @@
                             @{{ record.group ?? 'N/A' }}
                         </p>
 
+                        <p class="text-gray-600 dark:text-gray-300">
+                            @{{ record.customer_source ?? 'N/A' }}
+                        </p>
+
                         <p class="text-gray-600 dark:text-gray-300">
                             @{{ "@lang('admin::app.customers.customers.index.datagrid.id-value')".replace(':id', record.customer_id) }}
                         </p>

+ 4 - 0
packages/Webkul/Admin/src/Resources/views/customers/customers/view.blade.php

@@ -218,6 +218,10 @@
                                     <p class="text-gray-600 dark:text-gray-300">
                                         @{{ "@lang('admin::app.customers.customers.view.group')".replace(':group_code', customer.group?.name ?? 'N/A') }}
                                     </p>
+
+                                    <p class="text-gray-600 dark:text-gray-300">
+                                        @{{ "@lang('admin::app.customers.customers.view.source')".replace(':source', customer.customer_source ?? 'N/A') }}
+                                    </p>
                                 </div>
                             </x-slot:content>
                         </x-admin::accordion>

+ 7 - 3
packages/Webkul/Admin/tests/Feature/Customers/CustomersTest.php

@@ -27,7 +27,8 @@ it('should returns the customers page', function () {
 it('should return listing items of customers', function () {
     // Arrange.
     $customer = (new CustomerFaker)->factory()->create([
-        'password' => Hash::make('admin123'),
+        'password'        => Hash::make('admin123'),
+        'customer_source' => 'popup',
     ]);
 
     // Act and Assert.
@@ -39,13 +40,15 @@ it('should return listing items of customers', function () {
         ->assertOk()
         ->assertJsonPath('records.0.customer_id', $customer->id)
         ->assertJsonPath('records.0.email', $customer->email)
-        ->assertJsonPath('records.0.full_name', $customer->name);
+        ->assertJsonPath('records.0.full_name', $customer->name)
+        ->assertJsonPath('records.0.customer_source', 'popup');
 });
 
 it('should return the view page of customer', function () {
     // Arrange.
     $customer = (new CustomerFaker)->factory()->create([
-        'password' => Hash::make('admin123'),
+        'password'        => Hash::make('admin123'),
+        'customer_source' => 'popup',
     ]);
 
     // Act and Assert.
@@ -58,6 +61,7 @@ it('should return the view page of customer', function () {
         ->assertSeeText($customer->gender)
         ->assertSeeText($customer->email)
         ->assertSeeText($customer->phone)
+        ->assertSeeText('popup')
         ->assertSeeText(trans('admin::app.customers.customers.view.title'));
 });