<?php
# CmsEasy Enterprise Content Management System
# Copyright (C) CmsEasy Co.,Ltd (https://www.CmsEasy.cn). All rights reserved.
if (!defined('ROOT')) exit('Can\'t Access !');

class productcode extends table {
    public $name='product_code';
    static $me;
    public static function getInstance() {
        if (!self::$me) {
            $class=new productcode();
            self::$me=$class;
        }
        return self::$me;
    }

    function getcols($act) {
        return '*';
    }

    //产品码分发
    function product($oid){
        $orders_data=orders::getInstance()->getrow(array("oid"=>$oid));
        $productcode=productcode::getInstance()->getrows("status=1", 0,"id desc",'shopid');
        if (is_array($orders_data)){
            //重新编辑aid  取出key
            $product="";
            $aid_data = explode("#",$orders_data['aid']);
            foreach ($aid_data as $val) {
                $source = explode(",", trim($val));
                $aid = $source[0];
                if (is_array($productcode)) {
                    $productcode_data = array();
                    foreach ($productcode as $key => $val) {
                        $productcode_data[] = $val['shopid'];
                    }
                    if (in_array($aid, $productcode_data)) {
                        $count_data = productcode::getInstance()->getrows("status=1", 0, "id desc");
                        for ($i = 0; $i < $source[1]; $i++) {
                            if ($product == "") $product = $count_data[$i]['product']; else $product .= "," . $count_data[$i]['product'];
                            productcode::getInstance()->rec_update("status=0", array("product" => $count_data[$i]['product']));
                        }
                    }
                }
            }
            orders::getInstance()->rec_update(array("product"=>$product), array("oid"=>$oid));
        }
    }

    function get_form() {
        return array(
            'status'=>array(
                'selecttype'=>'select',
                'select'=>form::arraytoselect(array(0=>lang_admin('used'),1=>lang_admin('not_used'))),
                'default'=>1
            ),
        );
    }

}
# This program is an open source system, commercial use, please consciously to purchase commercial license.
# Copyright (C) CmsEasy Co., Ltd. (https://www.CmsEasy.cn). All rights reserved.