<?php

/**
 * +----------------------------------------------------------------------
 * | Created By PhpStorm
 * +----------------------------------------------------------------------
 * | DATE: 2021/8/25
 * +----------------------------------------------------------------------
 * | TIME: 11:12
 * +----------------------------------------------------------------------
 * | Author: YangXing(925032253@qq.com)
 * +----------------------------------------------------------------------
 * | Class: barcode
 * +----------------------------------------------------------------------
 */

namespace admin\action\pro;


use admin\action\baseAction;
use model\pro\barcode as code;
use model\pro\factory;
use model\pro\numidx;
use model\pro\pro;

class barcodeAction extends baseAction
{
    //生成条码
    public function index()
    {
		$factory = new factory();
		$list  = (new numidx())->getGspNumbersByPID(\mvc::$req['p_id']);
        \view::set('pId',\mvc::$req['p_id']);
        \view::set('list',$list);
        \view::put('pro/barcode/index');
    }

    /*public function index()
    {
        $factoryList = (new factory())->gspList();
        if(!empty($factoryList)){
            $barCodeLists = (new numidx())->gspFactory(array_column($factoryList,'pf_id'),\mvc::$req['p_id']);
            $barCodeList = [];
            if(!empty($barCodeLists)){
                foreach($barCodeLists as $value){
                    $barCodeList[$value['pn_pf_id'].'-'.$value['pn_ma_id']] = $value;
                }

                $pro = (new pro())->getRowByKey(\mvc::$req['p_id']);
                $isEdit = 0;
                if($pro['p_src'] == 'sample' || $pro['p_src_id'] > 0){
                    $isEdit = 1;
                }
                foreach ($factoryList as &$value)
                {
                    if(isset($barCodeList[$value['pf_id'].'-'.$value['pf_ma_id']])){
                        $value['pn_barcode'] = $barCodeList[$value['pf_id'].'-'.$value['pf_ma_id']]['pn_barcode'];
                        $value['pn_number'] = $barCodeList[$value['pf_id'].'-'.$value['pf_ma_id']]['pn_number'];
                    }else{
                        $value['pn_barcode'] = '';
                        $value['pn_number'] = '';
                    }
                    if(isset(GSP_BRANDS[$value['pf_name']])){
                        $value['pf_names'] = GSP_BRANDS[$value['pf_name']][LG_NAME];
                    }else{
                        $value['pf_names'] = '';
                    }
                    $value['is_edit'] = $isEdit;
                }

                unset($barCodeList);
            }
        }
        \view::set('pId',\mvc::$req['p_id']);
        \view::set('item',$factoryList);
        \view::put('pro/barcode/index');
    }*/

    public function create()
    {
        $barcode = new code();
        $code = $barcode->createBarCode(\mvc::$req);
        if($code === false) $this->msgJson($barcode->error);
        $this->successJson(['code' => $code]);
    }

    public function edit()
    {
        $barcode = new code();
        $barcode->edit(\mvc::$req);
        $this->successJson([]);
    }
}