$params['type'], 'product_id' => $product_id, 'create_time' => $time, 'update_time' => $time, ]; } ActivityZone::insertAll($insert); Db::commit(); return true; } catch (\Throwable $e) { Db::rollback(); throw new BusinessException($e->getMessage()); } } /** * @notes 编辑 * @param array $params * @return bool * @author admin * @date 2024/12/20 10:52 */ public static function edit(array $params): bool { Db::startTrans(); try { ActivityZone::where('id', $params['id'])->update([ 'type' => $params['type'], 'product_id' => $params['product_id'], ]); Db::commit(); return true; } catch (\Throwable $e) { Db::rollback(); throw new BusinessException($e->getMessage()); } } /** * @notes 删除 * @param array $params * @return bool * @author admin * @date 2024/12/20 10:52 */ public static function delete(array $params): bool { return ActivityZone::destroy($params['id']); } /** * @notes 获取详情 * @param $params * @return array * @author admin * @date 2024/12/20 10:52 */ public static function detail($params): array { return ActivityZone::findOrEmpty($params['id'])->toArray(); } public static function export($params) { $service = new ActivityZoneService(); $products = ActivityZone::with('product')->field('id,product_id,type')->where('type', $params['type'])->select()->toArray(); $unitIds = array_unique(array_column($products, 'unit')); $unit = StoreProductUnit::whereIn('id', $unitIds)->field('id,name')->withTrashed()->select()->toArray(); $unit = reset_index($unit, 'id'); foreach ($products as &$item) { $item['unit_name'] = $unit[$item['unit']]['name'] ?? ''; unset($item['unit'], $item['product_id']); } $data = ConfigLogic::getDictByType('activity_zone'); foreach ($data['activity_zone'] as $value) { if ($value['value'] == $params['type']) { $typeName = $value['remark']; break; } } return $service->export($products, $typeName ?? '', $params['remark']); } }