|
|
@@ -5,6 +5,8 @@ namespace app\admin\controller;
|
|
|
use app\common\controller\Backend;
|
|
|
use think\Session;
|
|
|
use think\Db;
|
|
|
+use think\Log;
|
|
|
+use pinyin\Pinyin;
|
|
|
|
|
|
/**
|
|
|
* 配方管理
|
|
|
@@ -459,14 +461,14 @@ class Formula extends Backend
|
|
|
$result = false;
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
- Db::name('order')->where('id',$params['oid'])->setField('status',2);
|
|
|
+// Db::name('order')->where('id',$params['oid'])->setField('status',2);
|
|
|
$result = Db::name('task')->insert($params);
|
|
|
//更改订单已完成数量,修改订单状态
|
|
|
$order_info = Db::name('order')->where('id',$params['oid'])->find();
|
|
|
if (empty($order_info['completed'])){
|
|
|
$new_completed = $params['number'];
|
|
|
$order_status = 2;//生产中
|
|
|
-// Db::name('order')->where('id',$params['oid'])->setField('status',2);
|
|
|
+ Db::name('order')->where('id',$params['oid'])->setField('status',$order_status);
|
|
|
}else{
|
|
|
$new_completed = $params['number'] + $order_info['completed'];
|
|
|
}
|
|
|
@@ -553,6 +555,7 @@ class Formula extends Backend
|
|
|
$this->error($e->getMessage());
|
|
|
}
|
|
|
if ($result){
|
|
|
+ $this->addFormulaChinese($ids);
|
|
|
$this->success('更新成功');
|
|
|
}else{
|
|
|
$this->error('审核失败');
|
|
|
@@ -619,4 +622,65 @@ class Formula extends Backend
|
|
|
// return array('status'=>1,'rows'=>$list);
|
|
|
return json($result);
|
|
|
}
|
|
|
+ public function addFormulaChinese($ids = null){
|
|
|
+ $date = date('Ymd',time());
|
|
|
+ if (!$ids){
|
|
|
+ Log::mylog('formula_log','id='.$ids.'未获取到',$date.'_01');
|
|
|
+ }
|
|
|
+ $formula = Db::name('formula')->where('id',$ids)->field('name')->find();
|
|
|
+ if (!$formula){
|
|
|
+ Log::mylog('formula_log','id='.$ids.'未获取到配方数据',$date.'_01');
|
|
|
+ }
|
|
|
+ $material = Db::name('formula_detail')->where('pid',$ids)->field('id,material')->select();
|
|
|
+ if (!$material){
|
|
|
+ Log::mylog('formula_log','pid='.$ids.'未获取到配方详情数据',$date.'_01');
|
|
|
+ }
|
|
|
+ $list = array();
|
|
|
+ $pinyin = new pinyin();
|
|
|
+ foreach ($material as $key=>$value){
|
|
|
+ if (preg_match("/[\x7f-\xff]/", $value['material'])){
|
|
|
+ $str = $value['material'];
|
|
|
+ $newStr = $pinyin->getpy($str,true,true);
|
|
|
+ $chinese = array();
|
|
|
+ for ($i=0;$i<strlen($newStr);$i++){
|
|
|
+ $string = substr($newStr,$i,1);
|
|
|
+ if (!preg_match_all('/\b([a-z]+)\b/', $string)){
|
|
|
+ $chinese[$i] = $string;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $list[$key]['f_id'] = $ids;
|
|
|
+ $list[$key]['f_name'] = $formula['name'];
|
|
|
+ $list[$key]['m_id'] = $value['id'];
|
|
|
+ $list[$key]['m_name'] = $value['material'];
|
|
|
+ $list[$key]['name'] = implode($chinese);
|
|
|
+ }
|
|
|
+ }
|
|
|
+// dump($list);die;
|
|
|
+ if (!empty($list)){
|
|
|
+ $result = true;
|
|
|
+ $is_has = Db::name('formula_material')->where('f_id',$ids)->select();
|
|
|
+ if ($is_has){
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ Db::name('formula_material')->where('f_id',$ids)->delete();
|
|
|
+ Db::name('formula_material')->insertAll($list);
|
|
|
+ Db::commit();
|
|
|
+ }catch (Exception $e){
|
|
|
+ $result = false;
|
|
|
+ Db::rollback();
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $res = Db::name('formula_material')->insertAll($list);
|
|
|
+ if (!$res){
|
|
|
+ $result = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!$result){
|
|
|
+ Log::mylog('formula_log','id='.$ids.'配方材料转换数据插入失败',$date.'_01');
|
|
|
+ }else{
|
|
|
+ Log::mylog('formula_log','id='.$ids.'配方材料转换数据插入成功',$date.'_01');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|