Changeset 3218578
- Timestamp:
- 01/07/2025 09:14:35 PM (15 months ago)
- Location:
- universam-demo/trunk
- Files:
-
- 7 edited
-
admin/assets/js/admin.js (modified) (3 diffs)
-
admin/form/edit-form-accumulative.php (modified) (9 diffs)
-
admin/includes/form-actions.class.php (modified) (1 diff)
-
includes/exchange/API/register_rest_route.php (modified) (4 diffs)
-
includes/exchange/API/rest_route/API.php (modified) (1 diff)
-
includes/option_data.php (modified) (1 diff)
-
includes/system_processes.class.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
universam-demo/trunk/admin/assets/js/admin.js
r3218365 r3218578 4934 4934 new Vue({ 4935 4935 el:'#edit_form_accumulative', 4936 data() { 4936 mixins:[formTools], 4937 data() { 4937 4938 return { 4938 4939 data:{}, … … 4941 4942 created() { 4942 4943 this.data = form_data; 4944 }, 4945 methods:{ 4946 deleteItem() { 4947 if (this.data.id) 4948 usam_api('accumulative/' + this.data.id, 'DELETE', this.afterDelete); 4949 }, 4950 saveForm() { 4951 var data = structuredClone(this.data); 4952 if( !data.layers.length ) 4953 { 4954 usam_notifi({text:'Заполните таблицу скидок', type:'error'}); 4955 return; 4956 } 4957 if (this.data.id) { 4958 usam_active_loader(); 4959 usam_api('accumulative/' + this.data.id, data, 'POST', usam_admin_notice); 4960 } 4961 else 4962 usam_api('accumulative', data, 'POST', this.afterAdding); 4963 } 4943 4964 } 4944 4965 }) … … 5752 5773 action_status_update(k, status) { 5753 5774 this.actions[k].status = status; 5754 usam_api('event/action/' + this.actions[k].id, { 5755 status:status, 5756 event_id:this.id 5757 }, 'POST'); 5775 usam_api('event/action/' + this.actions[k].id, {status:status, event_id:this.id}, 'POST'); 5758 5776 }, 5759 5777 add_action(e) { -
universam-demo/trunk/admin/form/edit-form-accumulative.php
r3218365 r3218578 3 3 class USAM_Form_accumulative extends USAM_Edit_Form 4 4 { 5 protected $vue = true; 5 6 protected function get_title_tab() 6 7 { 7 if ( $this->id != null ) 8 $title = sprintf( __('Изменить правило накопительных скидок «%s»','usam'), $this->data['name'] ); 9 else 10 $title = __('Добавить правило накопительных скидок', 'usam'); 11 return $title; 8 return '<span v-if="data.id>0">'.__('Изменить правило накопительных скидок','usam').'</span><span v-else>'.__('Добавить правило накопительных скидок', 'usam').'</span>'; 12 9 } 13 10 14 11 protected function get_data_tab( ) 15 12 { 16 $default = [' name' => '', 'active' => 0, 'method' => 'price', 'end' => 0, 'sort' => 100, 'layers' => [["discount" => 0, "sum" => 0]], 'type_prices' => [], 'period' => 'u','period_from' => 1, 'period_from_type' => 'y','start_date' => '', 'end_date' => '','start_calculation_date' => '', 'end_calculation_date' => ''];13 $default = ['id' => 0, 'name' => '', 'active' => 0, 'method' => 'price', 'end' => 0, 'sort' => 100, 'layers' => [], 'type_prices' => [], 'period' => 'u','period_from' => 1, 'period_from_type' => 'y','start_date' => '', 'end_date' => '','start_calculation_date' => '', 'end_calculation_date' => '']; 17 14 if ( $this->id != null ) 18 $this->data = usam_get_data($this->id, 'usam_accumulative_discount'); 19 $this->data = usam_format_data( $default, $this->data ); 20 if( !empty($this->data['start_date']) ) 15 $this->data = usam_get_data($this->id, 'usam_accumulative_discount'); 16 $this->data = usam_format_data( $default, $this->data ); 17 if( empty($this->data['layers']) ) 18 $this->data['layers'] = [["discount" => 0, "sum" => 0]]; 19 if( !empty($this->data['start_date']) ) 21 20 $this->data['start_date'] = get_date_from_gmt( $this->data['start_date'], "Y-m-d H:i" ); 22 21 if( !empty($this->data['end_date']) ) … … 34 33 <div class='event_form_head'> 35 34 <div class='event_form_head__title'> 36 <input type="text" name="name"v-model="data.name" placeholder="<?php _e('Название', 'usam') ?>" required class="titlebox show_internal_text" maxlength="255" autofocus>35 <input type="text" v-model="data.name" placeholder="<?php _e('Название', 'usam') ?>" required class="titlebox show_internal_text" maxlength="255" autofocus> 37 36 </div> 38 37 <div class='edit_form'> … … 41 40 <div class ="edit_form__item_option date_intervals"> 42 41 <datetime-picker v-model="data.start_date"></datetime-picker> - <datetime-picker v-model="data.end_date"></datetime-picker> 43 <input type="hidden" name="start_date" v-model="data.start_date"/>44 <input type="hidden" name="end_date" v-model="data.end_date"/>45 42 </div> 46 43 </div> … … 48 45 <div class ="edit_form__item_name"><label for='option_method'><?php esc_html_e( 'Тип скидки', 'usam'); ?>:</label></div> 49 46 <div class ="edit_form__item_option"> 50 <select id='option_method' name='method'v-model="data.method">47 <select id='option_method' v-model="data.method"> 51 48 <option value='price'><?php _e('Скидка к покупке','usam') ?></option> 52 <option value='bonus'><?php _e('Начислить бонусы','usam') ?></option> 49 <option value='bonus'><?php _e('Начислить бонусы','usam') ?></option> 53 50 </select> 54 51 </div> … … 57 54 <div class ="edit_form__item_name"><?php esc_html_e( 'Период для расчета скидок', 'usam'); ?>:</div> 58 55 <div class ="edit_form__item_option"> 59 <select id="option_period" name='period'v-model="data.period">56 <select id="option_period" v-model="data.period"> 60 57 <option value='u'><?php _e('За все время','usam') ?></option> 61 58 <option value='d'><?php _e('За период','usam') ?></option> … … 68 65 <div class ="edit_form__item_option date_intervals"> 69 66 <datetime-picker v-model="data.start_calculation_date"></datetime-picker> - <datetime-picker v-model="data.end_calculation_date"></datetime-picker> 70 <input type="hidden" name="start_calculation_date" v-model="data.start_calculation_date"/>71 <input type="hidden" name="end_calculation_date" v-model="data.end_calculation_date"/>72 67 </div> 73 68 </div> … … 75 70 <div class ="edit_form__item_name"><?php esc_html_e( 'Выбрать оплаченные заказы за последний(е)', 'usam'); ?>:</div> 76 71 <div class ="edit_form__item_option"> 77 <input type="text" name="period_from"class="interval" v-model="data.period_from" size="4">78 <select name='period_from_type'v-model="data.period_from_type" class="interval">72 <input type="text" class="interval" v-model="data.period_from" size="4"> 73 <select v-model="data.period_from_type" class="interval"> 79 74 <option value='d'><?php _e('День','usam') ?></option> 80 75 <option value='m'><?php _e('Месяц','usam') ?></option> … … 101 96 <template v-slot:tbody="slotProps"> 102 97 <td class="column_sum" draggable="true"> 103 <input :ref="'value'+slotProps.k" type="text" name="sum[]"v-model="slotProps.row.sum" size="4">98 <input :ref="'value'+slotProps.k" type="text" v-model="slotProps.row.sum" size="4"> 104 99 </td> 105 100 <td class="column_discount"> 106 <input type="text" name="discounts[]"v-model="slotProps.row.discount" size="4">101 <input type="text" v-model="slotProps.row.discount" size="4"> 107 102 </td> 108 103 <td class="column_actions"> 109 104 <?php usam_system_svg_icon("plus", ["@click" => "slotProps.add(slotProps.k)"]); ?> 110 <?php usam_system_svg_icon("minus", ["@click" => "slotProps.del(slotProps.k)" ]); ?>105 <?php usam_system_svg_icon("minus", ["@click" => "slotProps.del(slotProps.k)", "v-if" => "data.layers.length>1"]); ?> 111 106 </td> 112 107 </template> … … 119 114 function display_right() 120 115 { 121 $this->add_box_status_active( $this->data['active'] ); 122 usam_add_box( 'usam_prices', __('Типы цен','usam'), array( $this, 'selecting_type_prices' ) ); 116 ?> 117 <usam-box :id="'usam_status_active'" :title="'<?php _e( 'Статус активности', 'usam'); ?>'" :handle="false"> 118 <template v-slot:body> 119 <usam-checked v-model="data.active" :text="'<?php _e('Активно', 'usam'); ?>'"></usam-checked> 120 </template> 121 </usam-box> 122 <usam-box :id="'usam_prices'" :title="'<?php _e( 'Типы цен', 'usam'); ?>'" :handle="false"> 123 <template v-slot:body> 124 <select-list-api v-model="data.type_prices" route="type_prices" :multiple='1' :vars='{"type":"R"}'></select-list-api> 125 </template> 126 </usam-box> 127 <?php 123 128 } 124 129 } -
universam-demo/trunk/admin/includes/form-actions.class.php
r3218365 r3218578 2580 2580 } 2581 2581 } 2582 2583 private static function controller_accumulative() 2584 { 2585 switch( self::$action ) 2586 { 2587 case 'save': 2588 if ( ! isset(self::$request_data['sum'] ) || ! isset(self::$request_data['discounts'] ) ) 2589 return array( 'ready' => 0 ); 2590 $new_rule['name'] = sanitize_text_field( stripslashes(self::$request_data['name'])); 2591 $new_rule['active'] = !empty(self::$request_data['active'])?1:0; 2592 $new_rule['sort'] = isset(self::$request_data['sort'])?(int)self::$request_data['sort']:100; 2593 2594 $new_rule['method'] = isset(self::$request_data['method']) && self::$request_data['method'] == 'bonus'?'bonus':'price'; 2595 2596 $new_rule['type_prices'] = isset(self::$request_data['type_prices'])?self::$request_data['type_prices']:array(); 2597 $new_rule['start_date'] = ''; 2598 $new_rule['end_date'] = ''; 2599 if( !empty(self::$request_data['start_date']) ) 2600 $new_rule['start_date'] = get_gmt_from_date(self::$request_data['start_date'], "Y-m-d H:i:s"); 2601 if( !empty(self::$request_data['end_date']) ) 2602 $new_rule['end_date'] = get_gmt_from_date(self::$request_data['end_date'], "Y-m-d H:i:s"); 2603 2604 $new_rule['start_calculation_date'] = ''; 2605 $new_rule['end_date'] = ''; 2606 if( !empty(self::$request_data['start_calculation_date']) ) 2607 $new_rule['start_calculation_date'] = get_gmt_from_date(self::$request_data['start_calculation_date'], "Y-m-d H:i:s"); 2608 if( !empty(self::$request_data['end_calculation_date']) ) 2609 $new_rule['end_calculation_date'] = get_gmt_from_date(self::$request_data['end_calculation_date'], "Y-m-d H:i:s"); 2610 2611 $new_rule['period'] = isset(self::$request_data['period'])?substr(self::$request_data['period'], 0,1):'u'; 2612 $new_rule['period_from_type'] = isset(self::$request_data['period_from_type'])?substr(self::$request_data['period_from_type'], 0,1):'u'; 2613 $new_rule['period_from'] = isset(self::$request_data['period_from'])?(int)self::$request_data['period_from']:100; 2614 2615 $layers = (array) self::$request_data['sum']; 2616 $discounts = (array) self::$request_data['discounts']; 2617 $new_rule['layers'] = []; 2618 if ( !empty($discounts) ) 2619 { 2620 foreach( $discounts as $key => $discount) 2621 if ( is_numeric($discount) ) 2622 $new_rule['layers'][] = ['discount' => $discount, 'sum' => $layers[$key]]; 2623 uksort($new_rule['layers'], function($a, $b){ return ($a['sum'] - $b['sum']); }); 2624 } 2625 $calculation_accumulative = false; 2626 if ( self::$id != null ) 2627 { 2628 $rule = usam_get_data(self::$id, 'usam_accumulative_discount'); 2629 if ( $new_rule['active'] && $rule['active'] != $new_rule['active'] && $new_rule['method'] != $rule['method'] ) 2630 $calculation_accumulative = true; 2631 usam_edit_data( $new_rule, self::$id, 'usam_accumulative_discount' ); 2632 } 2633 else 2634 { 2635 if ( $new_rule['active'] ) 2636 $calculation_accumulative = true; 2637 $new_rule['date_insert'] = date( "Y-m-d H:i:s" ); 2638 self::$id = usam_add_data( $new_rule, 'usam_accumulative_discount' ); 2639 } 2640 if ( $calculation_accumulative ) 2641 { 2642 $user_ids = get_users(['fields' => ['ID']]); 2643 usam_create_system_process( __("Пересчет накопительной скидки", "usam" ), 1, 'calculation_accumulative_discount_customer', count($user_ids), 'calculation_accumulative_discount' ); 2644 } 2645 return ['id' => self::$id]; 2646 break; 2647 } 2648 } 2649 2582 2650 2583 private static function controller_certificate() 2651 2584 { -
universam-demo/trunk/includes/exchange/API/register_rest_route.php
r3218365 r3218578 2368 2368 2369 2369 register_rest_route( $this->namespace, '/coupon/rule/(?P<serviceid>\d+)', [ 2370 [ 2370 [ 2371 2371 'methods' => 'POST', 2372 2372 'callback' => ['USAM_API', 'update_rules_coupon'], … … 2428 2428 ], 2429 2429 ]); 2430 2431 register_rest_route( $this->namespace, '/accumulative', [ 2432 [ 2433 'methods' => 'POST', 2434 'callback' => ['USAM_API', 'insert_accumulative'], 2435 'args' => [ 2436 'name' => ['type' => 'string', 'required' => true, 'sanitize_callback' => ['USAM_Request_Processing', 'sanitize_text']], 2437 'active' => ['type' => 'boolean,integer', 'required' => false, 'sanitize_callback' => ['USAM_Request_Processing', 'sanitize_active'], 'default' => 0], 2438 'sort' => ['type' => 'integer', 'required' => false, 'default' => 100], 2439 'type_prices' => ['type' => 'array', 'required' => false, 'sanitize_callback' => ['USAM_Request_Processing', 'sanitize_array_string']], 2440 'start_date' => ['type' => 'string', 'required' => false, 'sanitize_callback' => ['USAM_Request_Processing', 'sanitize_date']], 2441 'end_date' => ['type' => 'string', 'required' => false, 'sanitize_callback' => ['USAM_Request_Processing', 'sanitize_date']], 2442 'start_calculation_date' => ['type' => 'string', 'required' => false, 'sanitize_callback' => ['USAM_Request_Processing', 'sanitize_date']], 2443 'end_calculation_date' => ['type' => 'string', 'required' => false, 'sanitize_callback' => ['USAM_Request_Processing', 'sanitize_date']], 2444 'method' => ['type' => 'string', 'required' => true, 'sanitize_callback' => ['USAM_Request_Processing', 'sanitize_text'], 'default' => 'price'], 2445 'period' => ['type' => 'string', 'required' => true, 'enum' => ['u','d','p']], 2446 'period_from' => ['type' => 'integer', 'required' => false], 2447 // 'period_from_type' => ['type' => 'integer', 'required' => false, 'enum' => ['d','m','y']], 2448 'layers' => ['type' => 'array', 'required' => false], 2449 ], 2450 'permission_callback' => function( $request ){ 2451 return current_user_can('universam_api') || current_user_can('view_accumulative'); 2452 } 2453 ] 2454 ]); 2455 register_rest_route( $this->namespace, '/accumulative/(?P<id>\d+)', [ 2456 [ // Получить 2457 'methods' => 'GET', 2458 'callback' => ['USAM_API', 'get_accumulative'], 2459 'permission_callback' => function( $request ){ 2460 return current_user_can('universam_api') || current_user_can('view_accumulative'); 2461 } 2462 ], 2463 [ // Сохранить 2464 'methods' => 'POST', 2465 'callback' => ['USAM_API', 'update_accumulative'], 2466 'args' => [ 2467 'name' => ['type' => 'string', 'required' => false, 'sanitize_callback' => ['USAM_Request_Processing', 'sanitize_text']], 2468 'active' => ['type' => 'boolean,integer', 'required' => false, 'sanitize_callback' => ['USAM_Request_Processing', 'sanitize_active'], 'default' => 0], 2469 'sort' => ['type' => 'integer', 'required' => false, 'default' => 100], 2470 'type_prices' => ['type' => 'array', 'required' => false, 'sanitize_callback' => ['USAM_Request_Processing', 'sanitize_array_string']], 2471 'start_date' => ['type' => 'string', 'required' => false, 'sanitize_callback' => ['USAM_Request_Processing', 'sanitize_date']], 2472 'end_date' => ['type' => 'string', 'required' => false, 'sanitize_callback' => ['USAM_Request_Processing', 'sanitize_date']], 2473 'start_calculation_date' => ['type' => 'string', 'required' => false, 'sanitize_callback' => ['USAM_Request_Processing', 'sanitize_date']], 2474 'end_calculation_date' => ['type' => 'string', 'required' => false, 'sanitize_callback' => ['USAM_Request_Processing', 'sanitize_date']], 2475 'method' => ['type' => 'string', 'required' => false, 'sanitize_callback' => ['USAM_Request_Processing', 'sanitize_text'], 'default' => 'price'], 2476 'period' => ['type' => 'string', 'required' => false, 'enum' => ['u','d','p']], 2477 'period_from' => ['type' => 'integer', 'required' => false], 2478 'period_from_type' => ['type' => 'string', 'required' => false, 'sanitize_callback' => ['USAM_Request_Processing', 'sanitize_text']], 2479 'layers' => ['type' => 'array', 'required' => false], 2480 ], 2481 'permission_callback' => function( $request ){ 2482 return current_user_can('universam_api') || current_user_can('view_accumulative'); 2483 } 2484 ], 2485 [ 2486 'methods' => 'DELETE', 2487 'callback' => ['USAM_API', 'delete_accumulative'], 2488 'permission_callback' => function( $request ){ 2489 return current_user_can('universam_api') || current_user_can('view_accumulative'); 2490 } 2491 ] 2492 ]); 2430 2493 register_rest_route( $this->namespace, '/oauth/(?P<type>\S+)', [ 2431 2494 [ … … 2448 2511 ], 2449 2512 'permission_callback' => function( $request ){ 2450 return current_user_can('universam_api') || current_user_can(' view_triggers');2513 return current_user_can('universam_api') || current_user_can('universam_settings'); 2451 2514 } 2452 2515 ] … … 2455 2518 [ // Получить 2456 2519 'methods' => 'GET', 2457 'callback' => ['USAM_API', 'get_t rigger'],2520 'callback' => ['USAM_API', 'get_tnved'], 2458 2521 'permission_callback' => function( $request ){ 2459 2522 return current_user_can('universam_api') || current_user_can('universam_settings'); -
universam-demo/trunk/includes/exchange/API/rest_route/API.php
r3218365 r3218578 4041 4041 return usam_edit_data( $parameters, $id, 'usam_tnved' ); 4042 4042 } 4043 4044 public static function delete_tnved( WP_REST_Request $request ) 4045 { 4046 $id = $request->get_param( 'id' ); 4047 return usam_delete_data( $id, 'usam_tnved' ); 4048 } 4049 4050 public static function get_accumulative( WP_REST_Request $request ) 4051 { 4052 $id = $request->get_param( 'id' ); 4053 return usam_get_data( $id, 'usam_accumulative_discount' ); 4054 } 4055 4056 public static function insert_accumulative( WP_REST_Request $request ) 4057 { 4058 $parameters = $request->get_json_params(); 4059 if ( !$parameters ) 4060 $parameters = $request->get_body_params(); 4061 4062 $parameters['date_insert'] = date( "Y-m-d H:i:s" ); 4063 usort($parameters['layers'], function($a, $b){ return ($a['sum'] - $b['sum']); }); 4064 $id = usam_add_data( $parameters, 'usam_accumulative_discount' ); 4065 if ( !empty($parameters['active']) ) 4066 { 4067 $user_ids = get_users(['fields' => ['ID']]); 4068 usam_create_system_process( __("Пересчет накопительной скидки", "usam" ), 1, 'calculation_accumulative_discount_customer', count($user_ids), 'calculation_accumulative_discount' ); 4069 } 4070 return $id; 4071 } 4072 4073 public static function update_accumulative( WP_REST_Request $request ) 4074 { 4075 $id = $request->get_param( 'id' ); 4076 $parameters = $request->get_json_params(); 4077 if ( !$parameters ) 4078 $parameters = $request->get_body_params(); 4079 if( !empty($parameters['layers']) ) 4080 usort($parameters['layers'], function($a, $b){ return ($a['sum'] - $b['sum']); }); 4081 $result = usam_edit_data( $parameters, $id, 'usam_accumulative_discount' ); 4082 if( $result ) 4083 { 4084 $rule = usam_get_data($id, 'usam_accumulative_discount'); 4085 if( $rule['active'] ) 4086 { 4087 $user_ids = get_users(['fields' => ['ID']]); 4088 usam_create_system_process( __("Пересчет накопительной скидки", "usam" ), 1, 'calculation_accumulative_discount_customer', count($user_ids), 'calculation_accumulative_discount' ); 4089 } 4090 } 4091 return $result; 4092 } 4093 4094 public static function delete_accumulative( WP_REST_Request $request ) 4095 { 4096 $id = $request->get_param( 'id' ); 4097 return usam_delete_data( $id, 'usam_accumulative_discount' ); 4098 } 4043 4099 } 4044 4100 ?> -
universam-demo/trunk/includes/option_data.php
r3133815 r3218578 39 39 $result = update_option($option_key, maybe_serialize($array) ); 40 40 } 41 return $result; 41 42 } 42 43 -
universam-demo/trunk/includes/system_processes.class.php
r3201974 r3218578 1057 1057 function controller_calculation_accumulative_discount_customer( ) 1058 1058 { 1059 $args = array( 'fields' => 'ID', 'number' => $this->number, 'paged' => $this->event['launch_number'], 'orderby' => 'ID' ); 1060 $user_ids = get_users( $args ); 1061 1059 $args = ['fields' => 'ID', 'number' => $this->number, 'paged' => $this->event['launch_number'], 'orderby' => 'ID']; 1060 $user_ids = get_users( $args ); 1062 1061 foreach ( $user_ids as $user_id ) 1063 1062 {
Note: See TracChangeset
for help on using the changeset viewer.