| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930 |
- <?php
- namespace app\api\controller;
- use app\admin\model\EntrustLog;
- use app\common\controller\Api;
- use \think\Request;
- use \think\Db;
- /**
- * 产品管理接口
- */
- class Product extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * 首页
- *
- */
- public function index()
- {
- $this->success('请求成功');
- }
- /**
- * 获取产品资料
- *
- * @ApiMethod GET
- *@param string custom_code
- *@param string limit
- *@param string page
- */
- public function getProduct(){
- if (Request::instance()->isGet() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->param();
- $limit = $params['limit'];
- if (!isset($limit)){
- $limit = 15;
- }
- if (!isset($pages)){
- $pages = 0;
- }else{
- $pages = ($params['page']-1) * $limit;
- }
- $total = 0;
- if (isset($params['custom_code']) && !empty($params['custom_code'])){
- $customCode = $params['custom_code'];
- $sql = "SELECT rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称,客户料号,rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称,版本号,成品规格,
- rtrim(计量单位) as 计量单位,rtrim(产品类别) as 产品类别,生产类别,产品备注,投产日期,状态,U8UID,rtrim(Sys_id) as Sys_id,Sys_rq,Mod_rq,UniqID
- FROM `产品_基本资料` WHERE `客户编号` = '{$customCode}' ORDER BY CASE WHEN `状态` IS NULL THEN 0 ELSE 1 END,
- `客户编号`ASC,`状态` ASC,`产品编号` DESC LIMIT {$limit} OFFSET {$pages}";
- $total = db('产品_基本资料')->where('客户编号',$customCode)->count();
- }else{
- if (isset($params['search']) && !empty($params['search'])){
- $search = $params['search'];
- $sql = "SELECT rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称,客户料号,rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称,版本号,成品规格,
- rtrim(计量单位) as 计量单位,rtrim(产品类别) as 产品类别,生产类别,产品备注,投产日期,状态,U8UID,rtrim(Sys_id) as Sys_id,Sys_rq,Mod_rq,UniqID
- FROM `产品_基本资料` WHERE `产品名称` LIKE '%{$search}%' OR `产品编号` LIKE '%{$search}%' ORDER BY CASE WHEN `状态` IS NULL THEN 0 ELSE 1 END,
- `客户编号`ASC,`状态` ASC,`产品编号` DESC LIMIT {$limit} OFFSET {$pages}";
- $total = db('产品_基本资料')->where('产品名称','like','%'.$search.'%')->count();
- }else{
- $sql = "SELECT rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称,客户料号,rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称,版本号,成品规格,
- rtrim(计量单位) as 计量单位,rtrim(产品类别) as 产品类别,生产类别,产品备注,投产日期,状态,U8UID,rtrim(Sys_id) as Sys_id,Sys_rq,Mod_rq,UniqID
- FROM `产品_基本资料` ORDER BY CASE WHEN `状态` IS NULL THEN 0 ELSE 1 END,
- `客户编号`ASC,`状态` ASC,`产品编号` DESC LIMIT {$limit} OFFSET {$pages}";
- $total = db('产品_基本资料')->count();
- }
- }
- $list = Db::query($sql);
- foreach ($list as $key=>$value){
- $code = trim($value['产品编号']);
- $gd_sql = "SELECT `接单日期` FROM `工单_基本资料` WHERE `成品代号` = '{$code}' ORDER BY Uniqid DESC";
- $gdRes = Db::query($gd_sql);
- $list[$key]['receiveDate'] = '';
- if (!empty($gdRes)){
- $list[$key]['receiveDate'] = $gdRes[0]['接单日期'];
- }
- $gy_sql = "SELECT * FROM `产品_工艺资料` WHERE Gy0_cpdh = '{$code}'";
- $gyRes = Db::query($gy_sql);
- $list[$key]['gyData'] = '';
- if (empty($gyRes)){
- $list[$key]['gyData'] = '缺';
- }
- $yj_sql = "SELECT COUNT(*) as total FROM `产品_印件资料` WHERE `yj_cpdh` = '{$code}'";
- $yjRes = Db::query($yj_sql);
- $list[$key]['yjData'] = '无';
- if ($yjRes[0]['total'] > 0){
- $list[$key]['yjData'] = $yjRes[0]['total'];
- }
- }
- $data['data'] = $list;
- $data['total'] = $total;
- $this->success('请求成功',$data);
- }
- /**
- * 获取产品基础数据
- *
- * @ApiMethod POST
- *@param string product_code
- */
- public function getProductData(){
- if (Request::instance()->isGet() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->param();
- $code = $params['product_code'];
- if (!isset($code)){
- $this->error('参数不能为空');
- }
- $num = config('product_code_digit');
- //工艺资料
- $option['a.Gy0_cpdh'] = $code;
- $gy_field = 'rtrim(a.Gy0_方案) as 方案,a.Gy0_yjno,a.Gy0_gxh,rtrim(a.gy0_gxmc) as gy0_gxmc,rtrim(a.Add_gxmc) as add_gxmc,a.Gy0_Ks,a.Gy0_ls,rtrim(a.工序备注) as 备注,
- a.工价系数,a.损耗系数,a.Gy0_Ms,a.人工检_正品板,a.人工检_次品板,a.人工检_废检,a.机检_正品板,a.机检_次品板,a.机检_废检,rtrim(a.Gy0_sbmc) as Gy0_sbmc,rtrim(a.Sys_id) as Sys_id,
- a.Sys_rq,a.Mod_rq,b.sys_rate0 as 基础损耗,b.sys_rate1 as 损耗率,a.UniqID';
- $gyRes = db('产品_工艺资料')->alias('a')
- ->join('dic_lzsh b','a.Gy0_shdh = b.sys_bh','left')
- ->where($option)->field($gy_field)->order('a.Gy0_yjno asc,a.Gy0_gxh asc')->select();
- //印件资料
- $where['yj_cpdh'] = $code;
- $field = 'yj_yjno,rtrim(yj_yjdh) as yj_yjdh,yj_yjmc,rtrim(yj_zzdh) as yj_zzdh,rtrim(yj_zzmc) as yj_zzmc,rtrim(yj_tlgg) as yj_tlgg,
- rtrim(yj_klgg) as yj_klgg,yj_ks,yj_ls,rtrim(yj_desc) as yj_desc,rtrim(sys_id) as sys_id,sys_rq,mod_rq,UniqId';
- $yjRes = db('产品_印件资料')->where($where)->field($field)->select();
- //印版资料
- $filter['a.YB_Cpdh'] = $code;
- $yb_field = 'rtrim(a.YB_方案) as YB_方案,a.YB_Yjno,rtrim(a.存货编码) as 存货编码,a.考核印数,rtrim(a.Sys_id) as Sys_id,a.Mod_rq,rtrim(b.物料名称) as 印版名称,rtrim(c.名称) as 印版类别,a.UniqID';
- $ybRes = db('产品_印版资料')->alias('a')
- ->join('物料_存货编码 b','a.存货编码 = b.物料代码','left')
- ->join('物料_存货结构 c','LEFT(a.存货编码,'.$num.') = c.编号','left')
- ->where($filter)->field($yb_field)->order('a.YB_Yjno,a.存货编码')->select();
- //技术附件
- $jsRes = db('产品_技术附件')
- ->where('关联产品','like','%'.$code.'%')
- ->select();
- foreach ($jsRes as $key=>&$value){
- if(mb_detect_encoding($value['附件内容'])!='ASCII'){
- $value['附件内容'] = '';
- }
- }
- $list = [];
- $list['yjData'] = $yjRes;
- $list['gyData'] = $gyRes;
- $list['ybData'] = $ybRes;
- $list['jsData'] = $jsRes;
- $this->success('请求成功',$list);
- }
- /**
- * 4.获取单个工艺数据(排产参数调整)
- *
- * @ApiMethod GET
- *@param string product_code
- */
- public function getProductGy(){
- if (Request::instance()->isGet() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->param();
- $code = $params['product_code'];
- if (!isset($code)){
- $this->error('参数不能为空');
- }
- $option['a.Gy0_cpdh'] = $code;
- if (!empty($params['plan'])){
- $option['a.Gy0_方案'] = $params['plan'];
- }
- $gy_field = 'rtrim(a.Gy0_方案) as programme,a.Gy0_yjno,a.Gy0_gxh,rtrim(a.gy0_gxmc) as gy0_gxmc,a.A类产能 as A_power,rtrim(a.Gy0_shdh) as Gy0_shdh,rtrim(a.Gy0_sbbh) as Gy0_sbbh,
- a.工价系数 as difficulty_coe,a.损耗系数 as loss_coe,a.Gy0_Ms as ms_coe,a.Gy0_Ks,a.Gy0_ls,rtrim(a.Gy0_site) as Gy0_site,rtrim(a.Add_gxmc) as Add_gxmc,a.UniqID,a.Gy0_辅助工时,
- rtrim(a.工序备注) as remark,a.人工检_正品板 as artificial_zp,a.人工检_次品板 as artificial_cp,a.人工检_废检 as artificial_fj,a.机检_正品板 as machine_zp,a.机检_次品板 as machine_cp,
- a.机检_废检 as machine_fj,rtrim(b.客户名称) as custom_name,rtrim(b.产品名称) as product_name,a.UniqId';
- $gyRes = db('产品_工艺资料')->alias('a')
- ->join('产品_基本资料 b','a.Gy0_cpdh = b.产品编号','left')
- ->where($option)->field($gy_field)->order('a.Gy0_yjno asc,a.Gy0_gxh asc')->select();
- $this->success('请求成功',$gyRes);
- }
- /**
- * 修改工艺参数
- *
- * @ApiMethod
- * @params array data
- */
- public function editGy(){
- if (Request::instance()->isPost() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->post();
- if (!isset($params) || !isset($params[0]['UniqID'])){
- $this->error('参数不能为空');
- }
- $i = 0;
- foreach ($params as $key=>$value){
- $data = [];
- if (!empty($value['A_power'])){
- $data['A类产能'] = $value['A_power'];
- }
- if (!empty($value['shdh'])){
- $data['Gy0_shdh'] = $value['shdh'];
- }
- if (!empty($value['machine'])){
- $data['Gy0_sbbh'] = $value['machine'];
- }
- if (!empty($value['time'])){
- $data['Gy0_辅助工时'] = $value['time'];
- }
- if (!empty($value['difficulty_coe'])){
- $data['工价系数'] = $value['difficulty_coe'];
- }
- if (!empty($value['loss_coe'])){
- $data['损耗系数'] = $value['loss_coe'];
- }
- if (!empty($value['ms_coe'])){
- $data['Gy0_Ms'] = $value['ms_coe'];
- }
- $sql = db('产品_工艺资料')->where('UniqID',$value['UniqID'])->fetchSql(true)->update($data);
- $res = Db::query($sql);
- if ($res !== false){
- $i++;
- }
- }
- if ($i !== 0){
- $this->success('更新成功');
- }else{
- $this->error('更新失败');
- }
- }
- /**
- * 修改产品信息
- *
- * @ApiMethod POST
- *
- * @params object data
- */
- public function editProduct(){
- if (Request::instance()->isPost() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->post();
- if (empty($params)){
- $this->error('参数不能为空');
- }
- if (!isset($params['印品代号'])){
- $this->error('印品代号不能为空');
- }
- $code = $params['印品代号'];
- unset($params['印品代号']);
- $sql = db('产品_基本资料')->where('产品编号',$code)->fetchSql(true)->update($params);
- $res = Db::query($sql);
- if ($res !== false){
- $this->success('更新成功');
- }else{
- $this->error('更新失败');
- }
- }
- /**
- * 设置产品状态
- *
- * @ApiMethod POST
- * @params string status
- * @params string code
- */
- public function setProductStatus(){
- if (Request::instance()->isPost() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->post();
- if (empty($params['code']) || empty($params['status'])){
- $this->error('参数不能为空');
- }
- $code = $params['code'];
- $status = '';
- if ($params['status'] == 2){
- $status = '停产';
- }
- $sql = db('产品_基本资料')->where('产品编号',$code)->fetchSql(true)->setField('状态',$status);
- $res = Db::query($sql);
- if ($res !== false){
- $this->success('更新成功');
- }else{
- $this->error('更新失败');
- }
- }
- /**
- * 获取产品工艺数量
- *
- * @ApiMethod GET
- * @params string code
- */
- public function getGyTotal(){
- if (Request::instance()->isGet() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->param();
- $code = $params['code'];
- if (!isset($code)){
- $this->error('参数不能为空');
- }
- $res = db('产品_工艺资料')->where('Gy0_cpdh',$code)->distinct(true)->column('rtrim(Gy0_方案) as gy_plan');
- $data['gy'] = $res;
- $product = db('产品_基本资料')->where('产品编号',$code)->find();
- $data['name'] = rtrim($product['产品名称']);
- $this->success('请求成功',$data);
- }
- /**
- * 复制产品工艺信息
- *
- * @ApiMethod POST
- * @params string from_code
- * @params string from_pro
- * @params string to_code
- * @params string to_pro
- * @params int is_copy_gy
- */
- public function copyProductGy(){
- if (Request::instance()->isPost() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->post();
- if (empty($params['from_code']) || empty($params['from_pro']) || empty($params['to_code']) ){
- $this->error('参数不能为空');
- }
- if ($params['is_copy_gy'] == 1){
- if (empty($params['to_pro'])){
- $this->error('工艺方案不能为空');
- }
- //查出参考的工艺数据
- $where['Gy0_cpdh'] = $params['from_code'];
- $where['Gy0_方案'] = $params['from_pro'];
- $gyList = db('产品_工艺资料')->where($where)->select();
- if (empty($gyList)){
- $this->error('参考产品无工艺资料数据');
- }
- $UniqID = db('产品_工艺资料')->order('UniqID desc')->value('UniqID');
- foreach ($gyList as $key=>$value){
- unset($gyList[$key]['UniqID']);
- $UniqID ++;
- $gyList[$key]['Gy0_方案'] = $params['to_pro'];
- $gyList[$key]['Gy0_cpdh'] = $params['to_code'];
- $gyList[$key]['UniqID'] = $UniqID;
- }
- }
- if ($params['is_copy_yb'] == 1){
- $UniqId = db('产品_印版资料')->order('UniqID desc')->value('UniqID');
- $option['YB_Cpdh'] = $params['from_code'];
- $ybList = db('产品_印版资料')->where($option)->select();
- if (empty($ybList)){
- $this->error('参考产品无印版资料数据');
- }
- foreach ($ybList as $key=>$value){
- unset($ybList[$key]['UniqID']);
- $UniqId++;
- $ybList[$key]['YB_Cpdh'] = $params['to_code'];
- $ybList[$key]['UniqID'] = $UniqId;
- }
- }
- if ($params['is_copy_gy'] == 1 && $params['is_copy_yb'] == 1){
- $gyResult = db('产品_工艺资料')->insertAll($gyList);
- if (!$gyResult){
- $this->error('复制产品工艺资料数据失败');
- }
- $ybResult = db('产品_印版资料')->insertAll($ybList);
- if (!$ybResult){
- $this->error('复制产品印版资料数据失败');
- }
- }elseif ($params['is_copy_gy'] == 1 && $params['is_copy_yb'] == 0){
- $gyResult = db('产品_工艺资料')->insertAll($gyList);
- if (!$gyResult){
- $this->error('复制产品工艺资料数据失败');
- }
- }elseif ($params['is_copy_gy'] == 0 && $params['is_copy_yb'] == 1){
- $ybResult = db('产品_印版资料')->insertAll($ybList);
- if (!$ybResult){
- $this->error('复制产品印版资料数据失败');
- }
- }else{
- $this->success('工艺、印版至少选中一个');
- }
- $this->success('工艺复制成功');
- }
- /**
- * 工艺方案更名
- *
- * @ApiMethod POST
- * @params string code
- * @params string name
- */
- public function editGyName(){
- if (Request::instance()->isPost() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->post();
- if (empty($params['code']) || empty($params['old_name']) || empty($params['new_name'])){
- $this->error('参数不能为空');
- }
- $where['Gy0_cpdh'] = $params['code'];
- $where['Gy0_方案'] = $params['old_name'];
- $sql = db('产品_工艺资料')->where($where)->fetchSql(true)->setField('Gy0_方案',$params['new_name']);
- $res = Db::query($sql);
- if ($res !== false){
- $this->success('更新成功');
- }else{
- $this->error('更新失败');
- }
- }
- /**
- * 工艺方案附加
- *
- * @ApiMethod POST
- * @params object data
- */
- public function editGyNo(){
- if (Request::instance()->isPost() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->post();
- if (empty($params) || !isset($params[0]['UniqID'])){
- $this->error('参数不能为空');
- }
- $i = 0;
- foreach ($params as $key=>$value){
- $data = [];
- if (!empty($value['Gy0_yjno'])){
- $data['Gy0_yjno'] = $value['Gy0_yjno'];
- }
- if (!empty($value['Gy0_gxh'])){
- $data['Gy0_gxh'] = $value['Gy0_gxh'];
- }
- if (!empty($value['Gy0_Ks'])){
- $data['Gy0_Ks'] = $value['Gy0_Ks'];
- }
- if (!empty($value['Gy0_ls'])){
- $data['Gy0_ls'] = $value['Gy0_ls'];
- }
- $sql = db('产品_工艺资料')->where('UniqID',$value['UniqID'])->fetchSql(true)->update($data);
- $res = Db::query($sql);
- if ($res !== false){
- $i++;
- }
- }
- if ($i !== 0){
- $this->success('更新成功');
- }else{
- $this->error('更新失败');
- }
- }
- /**
- * 计损色数修正
- *
- * @ApiMethod POST
- * @params object data
- */
- public function editGyMs(){
- if (Request::instance()->isPost() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->post();
- if (empty($params) || !isset($params[0]['UniqID'])){
- $this->error('参数不能为空');
- }
- $i = 0;
- foreach ($params as $key=>$value){
- $data = [];
- if (!empty($value['Gy0_Ms'])){
- $data['Gy0_Ms'] = $value['Gy0_Ms'];
- }
- if (!empty($value['Gy0_Ks'])){
- $data['Gy0_Ks'] = $value['Gy0_Ks'];
- }
- if (!empty($value['Gy0_ls'])){
- $data['Gy0_ls'] = $value['Gy0_ls'];
- }
- $data['Add_gxmc'] = $value['Add_gxmc'];
- $data['工序备注'] = $value['remark'];
- $sql = db('产品_工艺资料')->where('UniqID',$value['UniqID'])->fetchSql(true)->update($data);
- $res = Db::query($sql);
- if ($res !== false){
- $i++;
- }
- }
- if ($i !== 0){
- $this->success('更新成功');
- }else{
- $this->error('更新失败');
- }
- }
- /**
- * 产品质检废品系数调整
- *
- * @ApiMethod POST
- * @params object data
- */
- public function editGyWaste(){
- if (Request::instance()->isPost() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->post();
- if (empty($params) || !isset($params[0]['UniqID'])){
- $this->error('参数不能为空');
- }
- $i = 0;
- foreach ($params as $key=>$value){
- $data = [];
- if (!empty($value['artificial_zp'])){
- $data['人工检_正品板'] = $value['artificial_zp'];
- }
- if (!empty($value['artificial_cp'])){
- $data['人工检_次品板'] = $value['artificial_cp'];
- }
- if (!empty($value['artificial_fj'])){
- $data['人工检_废检'] = $value['artificial_fj'];
- }
- if (!empty($value['machine_zp'])){
- $data['机检_正品板'] = $value['machine_zp'];
- }
- if (!empty($value['machine_cp'])){
- $data['机检_次品板'] = $value['machine_cp'];
- }
- if (!empty($value['machine_fj'])){
- $data['机检_废检'] = $value['machine_fj'];
- }
- $sql = db('产品_工艺资料')->where('UniqID',$value['UniqID'])->fetchSql(true)->update($data);
- $res = Db::query($sql);
- if ($res !== false){
- $i++;
- }
- }
- if ($i !== 0){
- $this->success('更新成功');
- }else{
- $this->error('更新失败');
- }
- }
- /**
- * 获取产品印件资料
- * @ApiMethod GET
- * @params string UniqId
- */
- public function getProductYjInfo(){
- if (Request::instance()->isGet() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->param();
- if (empty($params['UniqId']) || empty($params['UniqId'])){
- $this->error('参数错误');
- }
- $field = "yj_yjno,rtrim(yj_yjdh) as yj_yjdh,rtrim(yj_yjmc) as yj_yjmc,rtrim(yj_zzdh) as yj_zzdh,rtrim(yj_zzmc) as yj_zzmc,rtrim(yj_zzdh1) as yj_zzdh1,rtrim(yj_zzdh2) as yj_zzdh2,
- rtrim(yj_zzdh3) as yj_zzdh3,rtrim(yj_zzdh4) as yj_zzdh4,rtrim(yj_zzmc1) as yj_zzmc1,rtrim(yj_zzmc2) as yj_zzmc2,rtrim(yj_zzmc3) as yj_zzmc3,
- rtrim(yj_zzmc4) as yj_zzmc4,rtrim(yj_tlgg) as yj_tlgg,rtrim(yj_klgg) as yj_klgg,yj_ks,yj_ls,KgToPages,rtrim(yj_desc) as yj_desc,UniqId";
- $list = \db('产品_印件资料')->where('UniqId',$params['UniqId'])->field($field)->select();
- $this->success('请求成功',$list);
- }
- /**
- * 修改产品印件资料
- * @ApiMethod POST
- * @params array data
- */
- public function editProductYjInfo(){
- if (Request::instance()->isPost() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->post();
- if (empty($params) || !isset($params['UniqId'])){
- $this->error('参数不能为空');
- }
- $UniqId = $params['UniqId'];
- unset($params['UniqId']);
- $res = \db('产品_印件资料')->where('UniqId',$UniqId)->update($params);
- if ($res !== false){
- $this->success('更新成功');
- }else{
- $this->error('更新失败');
- }
- }
- /**
- * 新增产品印件资料
- * @ApiMethod POST
- * @params array data
- */
- public function addProductYjInfo(){
- if (Request::instance()->isPost() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->post();
- $UniqId = \db('产品_印件资料')->order('UniqId desc')->value('UniqId');
- if ($UniqId < 2000000){
- $UniqId = 2000000;
- }else{
- $UniqId = $UniqId + 1;
- }
- $params['UniqId'] = $UniqId;
- $params['sys_rq'] = date('Y-m-d H:i:s');
- $res = \db('产品_印件资料')->insert($params);
- if ($res !== false){
- $this->success('新增成功');
- }else{
- $this->error('新增失败');
- }
- }
- /**
- * 获取印件代码及名称
- * @ApiMethod GET
- *
- */
- public function getProductYjList(){
- if (Request::instance()->isGet() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->get();
- $search = $params['search'];
- $num = config('product_code_digit');
- if (!empty($search)){
- $sql = "SELECT DISTINCT rtrim(a.`物料代码`) AS `物料代码`,rtrim(a.`物料名称`) AS `物料名称`,rtrim(b.`客户编号`) AS `客户编号`,rtrim(b.`客户名称`) AS `客户名称` FROM
- `物料_存货编码` a
- JOIN `产品_基本资料` b ON LEFT(a.`物料代码`,$num) = LEFT(b.`客户编号`,$num)
- WHERE a.`物料名称` LIKE '%{$search}%' or a.物料代码 LIKE '%{$search}%'
- ORDER BY a.`物料代码` ASC";
- }else{
- $sql = "SELECT DISTINCT rtrim(a.`物料代码`) as `物料代码`, rtrim(a.`物料名称`) as `物料名称`,rtrim(b.客户编号) as 客户编号,rtrim(b.客户名称) as 客户名称
- FROM `物料_存货编码` a
- JOIN `产品_基本资料` b ON LEFT(a.`物料代码`,$num) = LEFT(b.`客户编号`,$num)
-
- ORDER BY a.`物料代码` ASC";
- }
- // halt($sql);
- $data = Db::query($sql);
- // 初始化一个关联数组,用于存储相同客户编号的数据
- $groupedData = [];
- foreach ($data as $row) {
- $customerCode = substr($row['物料代码'],0,$num).substr($row['客户编号'],2,2).'/'.$row['客户名称'];
- $materialCodePrefix = substr($row['物料代码'], 0, $num);
- if ($materialCodePrefix == 'Y1401' ){
- $materialCodePrefix = $materialCodePrefix.'/糊盒类产品(含贴码)';
- }else{
- $materialCodePrefix = $materialCodePrefix.'/直接领用产品';
- }
- // 如果关联数组中不存在该物料代码前四位的键,则创建一个空数组
- if (!isset($groupedData[$materialCodePrefix])) {
- $groupedData[$materialCodePrefix] = [];
- }
- // 如果物料代码前四位数组中不存在该客户编号的键,则创建一个空数组
- if (!isset($groupedData[$materialCodePrefix][$customerCode])) {
- $groupedData[$materialCodePrefix][$customerCode] = [];
- }
- // 去除客户编号和客户名称
- unset($row['客户编号']);
- unset($row['客户名称']);
- // 将当前行的数据添加到相应的物料代码前四位和客户编号的数组中
- $groupedData[$materialCodePrefix][$customerCode][] = $row;
- }
- $this->success('请求成功',$groupedData);
- }
- /**
- * 获取纸张代号及名称
- * @ApiMethod GET
- * @params string search
- */
- public function getProductZzList(){
- if (Request::instance()->isGet() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->get();
- $search = $params['search'];
- $num = config('product_code_digit');
- if (!empty($search)){
- $sql = "SELECT rtrim(a.`物料代码`) as 物料代码,rtrim(a.`物料名称`) as 物料名称,rtrim(a.`规格`) as 规格,rtrim(b.编号) as oneCode,rtrim(b.名称) as oneName,
- rtrim(c.`编号`) as twoCode,rtrim(c.`名称`) as twoName,rtrim(d.`编号`) as thrCode,rtrim(d.`名称`) as thrName
- FROM `物料_存货编码` a
- LEFT JOIN `物料_存货结构` b ON LEFT(a.物料代码,$num-2) = b.编号
- LEFT JOIN `物料_存货结构` c ON LEFT(a.物料代码,$num) = c.编号
- LEFT JOIN `物料_存货结构` d ON LEFT(a.物料代码,$num+2) = d.编号
- WHERE a.物料名称 LIKE '%{$search}%' AND (a.物料代码 LIKE 'J00%' or a.物料代码 LIKE 'J01%' or a.物料代码 LIKE 'J30%')";
- }else{
- $sql = "SELECT rtrim(a.`物料代码`) as 物料代码,rtrim(a.`物料名称`) as 物料名称,rtrim(a.`规格`) as 规格,rtrim(b.编号) as oneCode,rtrim(b.名称) as oneName,
- rtrim(c.`编号`) as twoCode,rtrim(c.`名称`) as twoName,rtrim(d.`编号`) as thrCode,rtrim(d.`名称`) as thrName
- FROM `物料_存货编码` a
- LEFT JOIN `物料_存货结构` b ON LEFT(a.物料代码,$num-2) = b.编号
- LEFT JOIN `物料_存货结构` c ON LEFT(a.物料代码,$num) = c.编号
- LEFT JOIN `物料_存货结构` d ON LEFT(a.物料代码,$num+2) = d.编号
- WHERE a.物料代码 LIKE 'J00%' or a.物料代码 LIKE 'J01%' or a.物料代码 LIKE 'J30%'";
- }
- $data = Db::query($sql);
- $mergedArray = [];
- foreach ($data as $item) {
- $oneCode = $item['oneCode'];
- $twoCode = $item['twoCode'];
- $thrCode = $item['thrCode'];
- $oneName = $item['oneName'];
- $twoName = $item['twoName'];
- $thrName = $item['thrName'];
- // Create a unique key using the combination of oneCode, twoCode, and thrCode
- $oneKey = "{$oneCode}/{$oneName}";
- $twoKey = "{$twoCode}/{$twoName}";
- $thrKey = "{$thrCode}/{$thrName}";
- // Initialize arrays if not already set
- if (!isset($mergedArray[$oneKey])) {
- $mergedArray[$oneKey] = [];
- }
- if (!isset($mergedArray[$oneKey][$twoKey])) {
- $mergedArray[$oneKey][$twoKey] = [];
- }
- // Append items to the arrays
- $mergedArray[$oneKey][$twoKey][$thrKey][] = $item;
- }
- $this->success('请求成功',$mergedArray);
- }
- /**
- *3.6工艺资料-获取产品工艺资料
- */
- public function getProductGyInfo(){
- if (Request::instance()->isGet() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->param();
- if (empty($params['UniqID']) || empty($params['UniqID'])){
- $this->error('参数错误');
- }
- $field = "rtrim(a.Gy0_方案) as Gy0_方案,a.Gy0_yjno,a.Gy0_gxh,a.Gy0_Ks,a.Gy0_ls,rtrim(a.Gy0_site) as Gy0_site,rtrim(a.gy0_gxmc) as gy0_gxmc,rtrim(a.Add_gxmc) as Add_gxmc,a.Gy0_Ms,
- rtrim(a.Gy0_sbbh) as Gy0_sbbh,rtrim(a.Gy0_shdh) as Gy0_shdh,rtrim(b.sys_mc) as sys_mc,b.sys_rate0,b.sys_rate1,a.工价系数,a.损耗系数,rtrim(a.工序备注) as 工序备注,
- rtrim(a.质量要求) as 质量要求,rtrim(a.质量隐患) as 质量隐患,a.UniqID";
- $data = \db('产品_工艺资料')->alias('a')
- ->join('dic_lzsh b','a.Gy0_shdh = b.sys_bh','left')
- ->where('a.UniqID',$params['UniqID'])
- ->field($field)
- ->find();
- $this->success('请求成功',$data);
- }
- /**
- * 3.7工艺资料-获取车间及工艺名称
- * @ApiMethod GET
- *
- */
- public function getDepartName(){
- if (Request::instance()->isGet() == false){
- $this->error('非法请求');
- }
- $data = \db('erp_常用字典')->where('分类','印刷工艺')->order('编号 asc')->column('名称');
- $resultArray = [];
- foreach ($data as $item) {
- $parts = explode('_', $item);
- // 使用第一个部分作为一级键,第二个部分作为二级键
- $firstKey = $parts[0];
- $secondKey = $parts[1];
- $thirdValue = $parts[2];
- $resultArray[$firstKey][$secondKey][] = $thirdValue;
- }
- $this->success('请求成功',$resultArray);
- }
- /**
- * 3.8工艺资料-新增产品工艺
- */
- public function addProductGyInfo(){
- if (Request::instance()->isPost() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->post();
- $UniqId = \db('产品_工艺资料')->order('UniqID desc')->value('UniqID');
- if ($UniqId < 2000000){
- $UniqId = 2000000;
- }else{
- $UniqId = $UniqId + 1;
- }
- $params['UniqID'] = $UniqId;
- $params['Sys_rq'] = date('Y-m-d H:i:s');
- $sql = \db('产品_工艺资料')->fetchSql(true)->insert($params);
- $res = Db::query($sql);
- if ($res !== false){
- $this->success('新增成功');
- }else{
- $this->error('新增失败');
- }
- }
- /**
- * 3.9印版资料-获取产品印版资料
- * @ApiMethod GET
- */
- public function getProductYbInfo(){
- if (Request::instance()->isGet() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->param();
- if (empty($params['UniqID']) || empty($params['UniqID'])){
- $this->error('参数错误');
- }
- $field = "rtrim(a.YB_方案) as YB_方案,a.YB_Yjno,a.YB_gxh,rtrim(a.存货编码) as 存货编码,rtrim(a.印版名称) as 印版名称,a.UniqID,rtrim(b.gy0_gxmc) as gy0_gxmc,
- rtrim(b.Add_gxmc) as Add_gxmc,rtrim(c.物料名称) as 物料名称,rtrim(a.YB_cpdh) as YB_cpdh";
- $data = \db('产品_印版资料')->alias('a')
- ->join('产品_工艺资料 b','a.YB_cpdh = b.Gy0_cpdh and a.YB_Yjno = b.Gy0_yjno and a.YB_gxh = b.Gy0_gxh','left')
- ->join('物料_存货编码 c','a.存货编码 = c.物料代码','left')
- ->where('a.UniqID',$params['UniqID'])->field($field)->order('存货编码')->find();
- $where['Gy0_site'] = [
- ['like','胶印%'],
- ['like','烫模%'],
- 'or'
- ];
- $option['Gy0_cpdh'] = $data['YB_cpdh'];
- $option['Gy0_gxh'] = ['<',10];
- $option['Gy0_sbbh'] = ['neq',''];
- $gyData = \db('产品_工艺资料')->where($option)->where($where)
- ->field('rtrim(Gy0_方案) as Gy0_方案,Gy0_yjno,Gy0_gxh,rtrim(gy0_gxmc) as gy0_gxmc,rtrim(Add_gxmc) as Add_gxmc')
- ->order('Gy0_yjno,Gy0_gxh')->select();
- $list = [];
- foreach ($gyData as $key=>$value){
- $yjno = $value['Gy0_yjno'] > 10 ? $value['Gy0_yjno'] : '0'.$value['Gy0_yjno'];
- $gxh = $value['Gy0_gxh'] > 10 ? $value['Gy0_gxh'] : '0'.$value['Gy0_gxh'];
- $list[$key]['gy'] = $value['Gy0_方案'].'-->'.$yjno.'-'.$gxh.' '.$value['gy0_gxmc'];
- $list[$key]['gxmc'] = $value['Add_gxmc'];
- }
- $data['gy_data'] = $list;
- $this->success('请求成功',$data);
- }
- /**
- * 3.10印版资料-修改产品印版资料
- * @ApiMethod POST
- * @params string UniqId
- */
- public function editProductYbInfo(){
- if (Request::instance()->isPost() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->post();
- if (empty($params) || !isset($params['UniqId'])){
- $this->error('参数不能为空');
- }
- $UniqId = $params['UniqId'];
- unset($params['UniqId']);
- $sql = \db('产品_印版资料')->where('UniqId',$UniqId)->fetchSql(true)->update($params);
- $res = Db::query($sql);
- if ($res !== false){
- $this->success('更新成功');
- }else{
- $this->error('更新失败');
- }
- }
- /**
- * 印版资料-获取物料名称
- * @ApiMethod GET
- *
- */
- public function getProductYbMaterialList(){
- if (Request::instance()->isGet() == false){
- $this->error('非法请求');
- }
- $sql = "SELECT rtrim(`编号`) as 编号, rtrim(`名称`) as 名称 FROM `物料_存货结构` WHERE `编号` IN ('0502','0503','0510','0511','0512','0513','0514','0520','0521','0523','0524','0525')";
- $data = Db::query($sql);
- $this->success('请求成功',$data);
- }
- /**
- *3.12印版资料-获取详细存货名称
- * @ApiMethod GET
- * @params string code
- */
- public function getProductYbMaterialDetail(){
- if (Request::instance()->isGet() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->get();
- if (empty($params) || !isset($params['code'])){
- $this->error('参数不能为空');
- }
- $code = $params['code'];
- $search = $params['search'];
- $num = config('product_code_digit');
- if (!empty($search)){
- $sql = "SELECT rtrim(a.`物料代码`) as 物料代码,rtrim(a.`物料名称`) as 物料名称,rtrim(a.`规格`) as 规格,
- rtrim(c.`编号`) as twoCode,rtrim(c.`名称`) as twoName,rtrim(d.`编号`) as thrCode,rtrim(d.`名称`) as thrName
- FROM `物料_存货编码` a
- LEFT JOIN `物料_存货结构` c ON LEFT(a.物料代码,$num) = c.编号
- LEFT JOIN `物料_存货结构` d ON LEFT(a.物料代码,$num+2) = d.编号
- WHERE a.物料代码 LIKE '{$code}%' AND a.物料名称 LIKE '%{$search}%'";
- }else{
- $sql = "SELECT rtrim(a.`物料代码`) as 物料代码,rtrim(a.`物料名称`) as 物料名称,rtrim(a.`规格`) as 规格,
- rtrim(c.`编号`) as twoCode,rtrim(c.`名称`) as twoName,rtrim(d.`编号`) as thrCode,rtrim(d.`名称`) as thrName
- FROM `物料_存货编码` a
- LEFT JOIN `物料_存货结构` c ON LEFT(a.物料代码,$num) = c.编号
- LEFT JOIN `物料_存货结构` d ON LEFT(a.物料代码,$num+2) = d.编号
- WHERE a.物料代码 LIKE '{$code}%'";
- }
- $data = Db::query($sql);
- $mergedArray = [];
- foreach ($data as $item) {
- $oneCode = '05';
- $twoCode = $item['twoCode'];
- $thrCode = $item['thrCode'];
- $oneName = '版材';
- $twoName = $item['twoName'];
- $thrName = $item['thrName'];
- $oneKey = "{$oneCode}/{$oneName}";
- $twoKey = "{$twoCode}/{$twoName}";
- $thrKey = "{$thrCode}/{$thrName}";
- if (!isset($mergedArray[$oneKey])) {
- $mergedArray[$oneKey] = [];
- }
- if (!isset($mergedArray[$oneKey][$twoKey])) {
- $mergedArray[$oneKey][$twoKey] = [];
- }
- $mergedArray[$oneKey][$twoKey][$thrKey][] = $item;
- }
- $this->success('请求成功',$mergedArray);
- }
- /**
- * 3.13印版资料-新增产品印版资料
- * @ApiMethod POST
- * @params array data
- */
- public function addProductYbInfo(){
- if (Request::instance()->isPost() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->post();
- $UniqId = \db('产品_印版资料')->order('UniqID desc')->value('UniqID');
- if ($UniqId < 2000000){
- $UniqId = 2000000;
- }else{
- $UniqId = $UniqId + 1;
- }
- $params['UniqID'] = $UniqId;
- $params['考核印数'] = '0.00';
- $params['Sys_rq'] = date('Y-m-d H:i:s');
- $sql = \db('产品_印版资料')->fetchSql(true)->insert($params);
- $res = Db::query($sql);
- if ($res !== false){
- $this->success('新增成功');
- }else{
- $this->error('新增失败');
- }
- }
- }
|