使用复选框值作为Codeigniter中的订单ID更新多个订单状态

时间:2019-09-13 07:26:54

标签: codeigniter codeigniter-2

我必须代表选中的复选框来更新订单状态。但我无法做到这一点。请帮助我,我的代码有什么问题。我在下面包含了我的代码。所有代码均在单独的部分中指出。示例:控制器,模型和视图。

我也想告诉您我的Codeigniter版本是1.3.1。

控制器代码:

public function order_selected_options_post()
{
    $order_id = $this->input->post('order_id', true);
    $option = $this->input->post('order_status', true);
    print_r($order_id);
    if ($option == "completed") {
        $this->order_admin_model->set_order_as_completed_multiple($order_id);
    } elseif ($option == "processing") {
        $this->order_admin_model->set_order_as_not_completed_multiple($order_id);
    }

    $this->session->set_flashdata('success', trans("msg_updated"));
    redirect($this->agent->referrer());
}

型号代码:

 public function set_order_as_not_completed_multiple($order_id)
{
    $order_ids = $this->get_order($order_id);
    if (!empty($order_ids)) {
        foreach ($order_ids as $order_id) {
            $data = array(
                'status' => 0,
                'updated_at' => date('Y-m-d H:i:s'),
            );
            $this->db->where('id', $order_id);
            $this->db->update('orders', $data);
        }
    }
}

查看代码:

                <div class="table-responsive">
                <?php echo form_open_multipart('order_admin_controller/order_selected_options_post'); ?>
                <table class="table table-bordered table-striped" role="grid">
                    <?php $this->load->view('admin/order/_filter_orders'); ?>
                    <div class="item-table-filter">
                        <label><?php echo trans("status"); ?></label>
                        <select name="order_status" class="form-control">
                            <option value="completed"><?php echo trans("completed"); ?></option>
                            <option value="processing"><?php echo trans("order_processing"); ?></option>
                        </select>
                    </div>
                    <div class="item-table-filter md-top-10" style="width: 65px; min-width: 65px;">
                        <label style="display: block">&nbsp;</label>
                        <button type="submit" class="btn bg-purple"><?php echo trans("update"); ?></button>
                    </div>
                    <thead>
                    <tr role="row">
                        <th>&nbsp;</th>
                        <th><?php echo trans('order'); ?></th>
                        <th><?php echo trans('buyer'); ?></th>
                        <th><?php echo trans('total'); ?></th>
                        <th><?php echo trans('currency'); ?></th>
                        <th><?php echo trans('status'); ?></th>
                        <th><?php echo trans('payment_status'); ?></th>
                        <th><?php echo trans('updated'); ?></th>
                        <th><?php echo trans('date'); ?></th>
                        <th class="max-width-120"><?php echo trans('options'); ?></th>
                    </tr>
                    </thead>
                    <tbody>

                    <?php foreach ($orders as $item): ?>
                        <tr>
                            <td>
                                <input type="checkbox" name="order_id[]" value="<?php echo $item->id ?>">
                            </td>
                            <td style="width: 120px;">
                                <a href="<?php echo admin_url(); ?>order-details/<?php echo html_escape($item->id); ?>"
                                   class="table-link">
                                    #<?php echo html_escape($item->order_number); ?>
                                </a>
                            </td>
                            <td>
                                <?php if ($item->buyer_id == 0): ?>
                                    <div class="table-orders-user">
                                        <img src="<?php echo get_user_avatar(null); ?>" alt="buyer"
                                             class="img-responsive" style="height: 50px;">
                                        <span><?php echo $item->shipping_first_name . " " . $item->shipping_last_name; ?></span>
                                        <label class="label bg-olive"
                                               style="position: absolute;top: 0; left: 0;"><?php echo trans("guest"); ?></label>
                                    </div>
                                <?php else:
                                    $buyer = get_user($item->buyer_id);
                                    if (!empty($buyer)):?>
                                        <div class="table-orders-user">
                                            <a href="<?php echo base_url(); ?>profile/<?php echo $buyer->slug; ?>"
                                               target="_blank">
                                                <img src="<?php echo get_user_avatar($buyer); ?>" alt="buyer"
                                                     class="img-responsive" style="height: 50px;">
                                                <?php echo html_escape($buyer->username); ?>
                                            </a>
                                        </div>
                                    <?php endif;
                                endif;
                                ?>
                            </td>
                            <td>
                                <strong><?php echo print_price($item->price_total, $item->price_currency); ?></strong>
                            </td>
                            <td><?php echo $item->price_currency; ?></td>
                            <td>
                                <?php if ($item->status == 1): ?>
                                    <label class="label label-success"><?php echo trans("completed"); ?></label>
                                <?php else: ?>
                                    <label class="label label-default"><?php echo trans("order_processing"); ?></label>
                                <?php endif; ?>
                            </td>
                            <td>
                                <?php echo trans($item->payment_status); ?>
                            </td>
                            <td><?php echo time_ago($item->updated_at); ?></td>
                            <td> <?php echo date("Y-m-d / h:i", strtotime($item->created_at)); ?></td>
                            <td>
                                <input type="hidden" name="id" value="<?php echo $item->id; ?>">
                                <div class="dropdown">
                                    <button class="btn bg-purple dropdown-toggle btn-select-option"
                                            type="button"
                                            data-toggle="dropdown"><?php echo trans('select_option'); ?>
                                        <span class="caret"></span>
                                    </button>
                                    <ul class="dropdown-menu options-dropdown" style="min-width: 190px;">
                                        <li>
                                            <a href="<?php echo admin_url(); ?>order-details/<?php echo html_escape($item->id); ?>"><i
                                                        class="fa fa-info option-icon"></i><?php echo trans('view_details'); ?>
                                            </a>
                                        </li>
                                        <li>
                                            <?php if ($item->status == 1): ?>
                                                <button type="submit" name="option" value="not_completed"
                                                        class="btn-list-button">
                                                    <i class="fa fa-times option-icon"></i><?php echo trans('order_processing'); ?>
                                                </button>
                                            <?php else: ?>
                                                <button type="submit" name="option" value="completed"
                                                        class="btn-list-button">
                                                    <i class="fa fa-check option-icon"></i><?php echo trans('completed'); ?>
                                                </button>
                                            <?php endif; ?>
                                        </li>
                                        <li>
                                            <?php if ($item->payment_status == 'payment_received'): ?>
                                                <button type="submit" name="option" value="payment_not_received"
                                                        class="btn-list-button">
                                                    <i class="fa fa-times option-icon"></i><?php echo trans('payment_not_received'); ?>
                                                </button>
                                            <?php else: ?>
                                                <button type="submit" name="option" value="payment_received"
                                                        class="btn-list-button">
                                                    <i class="fa fa-check option-icon"></i><?php echo trans('payment_received'); ?>
                                                </button>
                                            <?php endif; ?>
                                        </li>
                                        <li>
                                            <a href="javascript:void(0)"
                                               onclick="delete_item('order_admin_controller/delete_order_post','<?php echo $item->id; ?>','<?php echo trans("confirm_delete"); ?>');"><i
                                                        class="fa fa-trash option-icon"></i><?php echo trans('delete'); ?>
                                            </a>
                                        </li>
                                    </ul>
                                </div>
                            </td>
                        </tr>

                    <?php endforeach; ?>

                    </tbody>
                </table>
                <?php echo form_close(); ?><!-- form end -->
                <?php if (empty($orders)): ?>
                    <p class="text-center">
                        <?php echo trans("no_records_found"); ?>
                    </p>
                <?php endif; ?>
                <div class="col-sm-12 table-ft">
                    <div class="row">
                        <div class="pull-right">
                            <?php echo $this->pagination->create_links(); ?>
                        </div>
                    </div>
                </div>

            </div>

0 个答案:

没有答案