| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace App\Services;
- use App\MaterialBox;
- use Illuminate\Support\Collection;
- use Illuminate\Support\Facades\Cache;
- use App\Traits\ServiceAppAop;
- use Illuminate\Support\Facades\DB;
- class MaterialBoxService
- {
- use ServiceAppAop;
- protected $modelClass=MaterialBox::class;
- /**
- * 获取一个空料箱
- *
- * @return MaterialBox|null
- */
- public function getAnEmptyBox()
- {
- $id = 0;
- while (true){
- $boxes = MaterialBox::query()->select('id',"code")->where("id",">",$id)->where("code","like","IDE%")
- ->where("status",4)->limit(10)->orderBy("id")->get();
- if ($boxes->count()==0)break;
- $ides = [];
- $str = "(";
- for ($i=0;$i<count($boxes)-1;$i++){
- $str .= "'".$boxes[$i]->code."',";
- $ides[$boxes[$i]->code] = $boxes[$i];
- }
- $box = $boxes[count($boxes)-1];
- $ides[$box->code] = $box;
- $str .= "'".$box->code."')";
- $id = $box->id;
- $sql = <<<sql
- SELECT LOCATIONID,SUM(QTY+QTYPA) qty FROM INV_LOT_LOC_ID WHERE LOCATIONID IN {$str} GROUP BY LOCATIONID
- sql;
- foreach (DB::connection("oracle")->select(DB::raw($sql)) as $item){
- if ((int)$item->qty==0)return $ides[$item->locationid];
- unset($ides[$item->locationid]);
- }
- if ($ides)return current($ides);
- }
- return null;
- }
- }
|