| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace App\Services;
- use App\OracleBasCode;
- use App\StoreType;
- use Carbon\Carbon;
- Class StoreTypeService
- {
- public function getByWms($asnHerders)
- {
- $types = array_unique(data_get($asnHerders, '*.asntype'));
- $types = array_diff($types, [null, '', '*']);
- $storeTypes = StoreType::query()->whereIn('code', $types)->get();
- if ($storeTypes->count() < count($types)) {
- $types = array_diff($types, data_get($storeTypes, '*.code'));
- $storeType_list = $this->createStoreTypeByWms($types);
- $storeTypes=$storeTypes->concat($storeType_list);
- }
- return $storeTypes;
- }
- public function createStoreTypeByWms($codes){
- if(!$codes) {return [];}
- $basCodes = OracleBasCode::query()
- ->where('codeid','ASN_TYP')
- ->whereIn('code', $codes)
- ->get();
- $insert_params = [];
- $created_at = Carbon::now()->format('Y-m-d H:i:s');
- foreach ($basCodes as $item) {
- $insert_params[] = [
- 'code' => $item->code,
- 'name' => $item->codename_c,
- 'created_at' => $created_at,
- ];
- }
- try {
- if (count($insert_params) > 0) {
- $this->insert($insert_params);
- LogService::log(__METHOD__, __FUNCTION__, '批量创建 storeType success' . count($insert_params) . json_encode($insert_params) );
- }
- } catch (\Exception $e) {
- LogService::log(__METHOD__, __FUNCTION__, '批量创建 storeType error' . json_encode($insert_params) . '||' . $e->getMessage() . '||' . $e->getTraceAsString());
- } finally {
- return StoreType::query()->whereIn('code', $codes)->get();
- }
- }
- public function insert($fillables){
- return StoreType::query()->insert($fillables);
- }
- }
|